@ai-sdk/workflow 2.0.23 → 2.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 2.0.25
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a4ba394]
8
+ - Updated dependencies [36b3364]
9
+ - Updated dependencies [45099da]
10
+ - Updated dependencies [9e1d1b2]
11
+ - Updated dependencies [a495511]
12
+ - ai@7.0.94
13
+ - @ai-sdk/provider@4.0.11
14
+ - @ai-sdk/provider-utils@5.0.37
15
+
16
+ ## 2.0.24
17
+
18
+ ### Patch Changes
19
+
20
+ - 3204ab6: fix(workflow): preserve per-tool types in execution callbacks and export the callback event types
21
+ - Updated dependencies [df6c009]
22
+ - Updated dependencies [6ee74a3]
23
+ - Updated dependencies [f13d371]
24
+ - Updated dependencies [d4485fe]
25
+ - Updated dependencies [4f201cc]
26
+ - Updated dependencies [8cdb2a7]
27
+ - Updated dependencies [0f2281e]
28
+ - Updated dependencies [fc8e8ac]
29
+ - Updated dependencies [ee8391e]
30
+ - ai@7.0.93
31
+
3
32
  ## 2.0.23
4
33
 
5
34
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LanguageModelV4, LanguageModelV4CallOptions, SharedV4ProviderOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart } from '@ai-sdk/provider';
2
- import { Context, HasRequiredKey, InferToolSetContext } from '@ai-sdk/provider-utils';
2
+ import { Context, HasRequiredKey, InferToolSetContext, InferToolInput, InferToolContext, InferToolOutput } from '@ai-sdk/provider-utils';
3
3
  import { ToolSet, Experimental_LanguageModelStreamPart, LanguageModel, Instructions, ToolChoice, TelemetryOptions as TelemetryOptions$1, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, Experimental_SandboxSession, ModelMessage, StepResult, GenerateTextOnStepEndCallback, UIMessage, InferUITools, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
4
4
  export { Output, ToolCallRepairFunction } from 'ai';
5
5
 
@@ -588,57 +588,90 @@ type WorkflowAgentOnStepStartCallback<TTools extends ToolSet = ToolSet, TRuntime
588
588
  /** Per-tool context map for this step */
589
589
  readonly toolsContext: InferToolSetContext<TTools>;
590
590
  }) => PromiseLike<void> | void;
591
+ type WorkflowToolContext<TOOL extends ToolSet[keyof ToolSet]> = [
592
+ InferToolContext<TOOL>
593
+ ] extends [never] ? undefined : InferToolContext<TOOL>;
594
+ type WorkflowToolCall<TTools extends ToolSet, NAME extends keyof TTools> = ToolCall & {
595
+ readonly toolName: NAME & string;
596
+ readonly input: InferToolInput<TTools[NAME]>;
597
+ };
591
598
  /**
592
- * Callback that is called before a tool's execute function runs.
599
+ * Event passed to a WorkflowAgent tool-execution-start callback.
600
+ *
601
+ * For a concrete tool set, each union member correlates the tool call with that
602
+ * tool's context. TypeScript narrows the nested tool call directly; use
603
+ * `Extract` or a user-defined type guard to narrow correlated sibling fields.
593
604
  */
594
- type WorkflowAgentOnToolExecutionStartCallback<TTools extends ToolSet = ToolSet> = (event: {
595
- /** The tool call being executed */
605
+ type WorkflowAgentToolExecutionStartEvent<TTools extends ToolSet = ToolSet> = [ToolSet] extends [TTools] ? {
596
606
  readonly toolCall: ToolCall;
597
- /** The current step number (0-based) */
598
607
  readonly stepNumber: number;
599
- /** Messages sent to the language model for the step that produced the call */
600
608
  readonly messages: ModelMessage[];
601
- /** Tool-specific context passed to the tool */
602
- readonly toolContext: InferToolSetContext<TTools>[keyof InferToolSetContext<TTools>] | undefined;
603
- }) => PromiseLike<void> | void;
609
+ readonly toolContext: unknown;
610
+ } : {
611
+ [NAME in keyof TTools]: {
612
+ readonly toolCall: WorkflowToolCall<TTools, NAME>;
613
+ readonly stepNumber: number;
614
+ readonly messages: ModelMessage[];
615
+ readonly toolContext: WorkflowToolContext<TTools[NAME]>;
616
+ };
617
+ }[keyof TTools];
604
618
  /**
605
- * Callback that is called after a tool execution completes.
606
- * Uses a discriminated union pattern: check `success` to determine
607
- * whether `output` or `error` is available.
619
+ * Callback that is called before a tool's execute function runs.
620
+ */
621
+ type WorkflowAgentOnToolExecutionStartCallback<TTools extends ToolSet = ToolSet> = (event: WorkflowAgentToolExecutionStartEvent<TTools>) => PromiseLike<void> | void;
622
+ /**
623
+ * Event passed to a WorkflowAgent tool-execution-end callback.
624
+ *
625
+ * For a concrete tool set, each union member correlates the tool call with that
626
+ * tool's context and successful output. Check `success` to distinguish output
627
+ * and error events. Use `Extract` or a user-defined type guard to narrow
628
+ * correlated sibling fields by tool name.
608
629
  */
609
- type WorkflowAgentOnToolExecutionEndCallback<TTools extends ToolSet = ToolSet> = (event: {
610
- /** The tool call that was executed */
630
+ type WorkflowAgentToolExecutionEndEvent<TTools extends ToolSet = ToolSet> = [ToolSet] extends [TTools] ? {
611
631
  readonly toolCall: ToolCall;
612
- /** The current step number (0-based) */
613
632
  readonly stepNumber: number;
614
- /** Execution time in milliseconds */
615
633
  readonly durationMs: number;
616
- /** Messages sent to the language model for the step that produced the call */
617
634
  readonly messages: ModelMessage[];
618
- /** Tool-specific context passed to the tool */
619
- readonly toolContext: InferToolSetContext<TTools>[keyof InferToolSetContext<TTools>] | undefined;
620
- /** Whether the tool call succeeded */
635
+ readonly toolContext: unknown;
621
636
  readonly success: true;
622
- /** The tool result */
623
637
  readonly output: unknown;
624
638
  readonly error?: never;
625
639
  } | {
626
- /** The tool call that was executed */
627
640
  readonly toolCall: ToolCall;
628
- /** The current step number (0-based) */
629
641
  readonly stepNumber: number;
630
- /** Execution time in milliseconds */
631
642
  readonly durationMs: number;
632
- /** Messages sent to the language model for the step that produced the call */
633
643
  readonly messages: ModelMessage[];
634
- /** Tool-specific context passed to the tool */
635
- readonly toolContext: InferToolSetContext<TTools>[keyof InferToolSetContext<TTools>] | undefined;
636
- /** Whether the tool call succeeded */
644
+ readonly toolContext: unknown;
637
645
  readonly success: false;
638
- /** The error that occurred */
639
646
  readonly error: unknown;
640
647
  readonly output?: never;
641
- }) => PromiseLike<void> | void;
648
+ } : {
649
+ [NAME in keyof TTools]: {
650
+ readonly toolCall: WorkflowToolCall<TTools, NAME>;
651
+ readonly stepNumber: number;
652
+ readonly durationMs: number;
653
+ readonly messages: ModelMessage[];
654
+ readonly toolContext: WorkflowToolContext<TTools[NAME]>;
655
+ readonly success: true;
656
+ readonly output: InferToolOutput<TTools[NAME]>;
657
+ readonly error?: never;
658
+ } | {
659
+ readonly toolCall: WorkflowToolCall<TTools, NAME>;
660
+ readonly stepNumber: number;
661
+ readonly durationMs: number;
662
+ readonly messages: ModelMessage[];
663
+ readonly toolContext: WorkflowToolContext<TTools[NAME]>;
664
+ readonly success: false;
665
+ readonly error: unknown;
666
+ readonly output?: never;
667
+ };
668
+ }[keyof TTools];
669
+ /**
670
+ * Callback that is called after a tool execution completes.
671
+ * Uses a discriminated union pattern: check `success` to determine
672
+ * whether `output` or `error` is available.
673
+ */
674
+ type WorkflowAgentOnToolExecutionEndCallback<TTools extends ToolSet = ToolSet> = (event: WorkflowAgentToolExecutionEndEvent<TTools>) => PromiseLike<void> | void;
642
675
  /**
643
676
  * Options for the {@link WorkflowAgent.stream} method.
644
677
  */
@@ -1290,4 +1323,4 @@ declare class WorkflowChatTransport<UI_MESSAGE extends UIMessage> implements Cha
1290
1323
  */
1291
1324
  declare function normalizeUIMessageStreamParts(source: AsyncIterable<UIMessageChunk>): AsyncGenerator<UIMessageChunk>;
1292
1325
 
1293
- export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type ModelCallStreamPart, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextTransform, type TelemetryOptions, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnEndCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepEndCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolExecutionEndCallback, type WorkflowAgentOnToolExecutionStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, type WorkflowToolApprovalSecret, createModelCallToUIChunkTransform, normalizeUIMessageStreamParts, toUIMessageChunk };
1326
+ export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type ModelCallStreamPart, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextTransform, type TelemetryOptions, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnEndCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepEndCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolExecutionEndCallback, type WorkflowAgentOnToolExecutionStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, type WorkflowAgentToolExecutionEndEvent, type WorkflowAgentToolExecutionStartEvent, WorkflowChatTransport, type WorkflowChatTransportOptions, type WorkflowToolApprovalSecret, createModelCallToUIChunkTransform, normalizeUIMessageStreamParts, toUIMessageChunk };