invokeAction
function invokeAction<TInput, TOutput>(action, input): NLPActionExecute;Defined in: core/src/nlp/nlp.invoke-action.ts:31
Builds an NLPAction execute that invokes an existing Action,
for the cases where an action really is the right target for a phrase.
defineNLPAction({ name: 'Turn lights on', utterances: [utterance`Turn on the ${room} light`], execute: invokeAction(turnOnLight, ({ entities }) => ({ rooms: entities.get(room).map((entry) => entry.id), })),});The two surfaces are deliberately not defined in terms of each other — an
action takes arguments composed against a schema, an intent takes the spans a
phrase happened to fill — so bridging them means saying explicitly how one
becomes the other. input is that mapping, and keeping it at the call site is
the whole point: it is per-intent, not per-action, and the same action can be
reached by several intents that fill it differently.
The action’s return value is discarded, since an intent has no output channel
yet. Write execute by hand when the intent needs to do something with it.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TInput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> |
TOutput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
action |
Action<TInput, TOutput> |
- |
input |
(context) => output<TInput> | Promise<output<TInput>> |
Builds the action’s input from what the phrase filled. The result is validated against the action’s own input schema, so a mapping that does not fit fails loudly with an ActionInputValidationError naming the offending field rather than reaching execute malformed. |