@ai-sdk/workflow 1.0.0-beta.2 → 1.0.0-beta.4

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,17 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - ai@7.0.0-beta.92
8
+
9
+ ## 1.0.0-beta.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 0e462a7: Use `LanguageModel` type for model parameter, aligning with `ToolLoopAgent`. Remove async factory model form. Rename callback types to use `WorkflowAgentOn*` prefix.
14
+
3
15
  ## 1.0.0-beta.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LanguageModelV4, SharedV4ProviderOptions, LanguageModelV4Prompt, LanguageModelV4CallOptions, LanguageModelV4StreamPart } from '@ai-sdk/provider';
2
- import { ToolSet, SystemModelMessage, ToolChoice, StepResult, StreamTextOnStepFinishCallback, ModelMessage, FinishReason, LanguageModelUsage, Experimental_LanguageModelStreamPart, StopCondition, LanguageModelResponseMetadata, ToolCallRepairFunction, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
2
+ import { ToolSet, LanguageModel, SystemModelMessage, ToolChoice, StepResult, StreamTextOnStepFinishCallback, ModelMessage, FinishReason, LanguageModelUsage, Experimental_LanguageModelStreamPart, StopCondition, LanguageModelResponseMetadata, ToolCallRepairFunction, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
3
3
  export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, ToolCallRepairFunction } from 'ai';
4
4
 
5
5
  /**
@@ -13,6 +13,12 @@ export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, To
13
13
  */
14
14
  type CompatibleLanguageModel = LanguageModelV4;
15
15
 
16
+ /**
17
+ * Callback function to be called after each step completes.
18
+ * Alias for the AI SDK's StreamTextOnStepFinishCallback, using
19
+ * WorkflowAgent-consistent naming.
20
+ */
21
+ type WorkflowAgentOnStepFinishCallback<TTools extends ToolSet = ToolSet> = StreamTextOnStepFinishCallback<TTools, any>;
16
22
  /**
17
23
  * Infer the type of the tools of a workflow agent.
18
24
  */
@@ -181,7 +187,7 @@ interface PrepareStepInfo<TTools extends ToolSet = ToolSet> {
181
187
  * The current model configuration (string or function).
182
188
  * The function should return a LanguageModelV4 instance.
183
189
  */
184
- model: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>);
190
+ model: LanguageModel;
185
191
  /**
186
192
  * The current step number (0-indexed).
187
193
  */
@@ -207,9 +213,8 @@ interface PrepareStepInfo<TTools extends ToolSet = ToolSet> {
207
213
  interface PrepareStepResult extends Partial<GenerationSettings> {
208
214
  /**
209
215
  * Override the model for this step.
210
- * The function should return a LanguageModelV4 instance.
211
216
  */
212
- model?: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>);
217
+ model?: LanguageModel;
213
218
  /**
214
219
  * Override the system message for this step.
215
220
  */
@@ -243,7 +248,7 @@ type PrepareStepCallback<TTools extends ToolSet = ToolSet> = (info: PrepareStepI
243
248
  * Options passed to the prepareCall callback.
244
249
  */
245
250
  interface PrepareCallOptions<TTools extends ToolSet = ToolSet> extends Partial<GenerationSettings> {
246
- model: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>);
251
+ model: LanguageModel;
247
252
  tools: TTools;
248
253
  instructions?: string | SystemModelMessage | Array<SystemModelMessage>;
249
254
  toolChoice?: ToolChoice<TTools>;
@@ -270,9 +275,9 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
270
275
  * The model provider to use for the agent.
271
276
  *
272
277
  * This should be a string compatible with the Vercel AI Gateway (e.g., 'anthropic/claude-opus'),
273
- * or a step function that returns a LanguageModelV4 instance.
278
+ * or a LanguageModelV4 instance from a provider.
274
279
  */
275
- model: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>);
280
+ model: LanguageModel;
276
281
  /**
277
282
  * A set of tools available to the agent.
278
283
  * Tools can be implemented as workflow steps for automatic retries and persistence,
@@ -316,11 +321,11 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
316
321
  /**
317
322
  * Callback function to be called after each step completes.
318
323
  */
319
- onStepFinish?: StreamTextOnStepFinishCallback<ToolSet, any>;
324
+ onStepFinish?: WorkflowAgentOnStepFinishCallback<ToolSet>;
320
325
  /**
321
326
  * Callback that is called when the LLM response and all request tool executions are finished.
322
327
  */
323
- onFinish?: StreamTextOnFinishCallback<ToolSet>;
328
+ onFinish?: WorkflowAgentOnFinishCallback<ToolSet>;
324
329
  /**
325
330
  * Callback called when the agent starts streaming, before any LLM calls.
326
331
  */
@@ -347,7 +352,7 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
347
352
  /**
348
353
  * Callback that is called when the LLM response and all request tool executions are finished.
349
354
  */
350
- type StreamTextOnFinishCallback<TTools extends ToolSet = ToolSet, OUTPUT = never> = (event: {
355
+ type WorkflowAgentOnFinishCallback<TTools extends ToolSet = ToolSet, OUTPUT = never> = (event: {
351
356
  /**
352
357
  * Details for all steps.
353
358
  */
@@ -381,13 +386,13 @@ type StreamTextOnFinishCallback<TTools extends ToolSet = ToolSet, OUTPUT = never
381
386
  /**
382
387
  * Callback that is invoked when an error occurs during streaming.
383
388
  */
384
- type StreamTextOnErrorCallback = (event: {
389
+ type WorkflowAgentOnErrorCallback = (event: {
385
390
  error: unknown;
386
391
  }) => PromiseLike<void> | void;
387
392
  /**
388
393
  * Callback that is set using the `onAbort` option.
389
394
  */
390
- type StreamTextOnAbortCallback<TTools extends ToolSet = ToolSet> = (event: {
395
+ type WorkflowAgentOnAbortCallback<TTools extends ToolSet = ToolSet> = (event: {
391
396
  /**
392
397
  * Details for all previously finished steps.
393
398
  */
@@ -398,7 +403,7 @@ type StreamTextOnAbortCallback<TTools extends ToolSet = ToolSet> = (event: {
398
403
  */
399
404
  type WorkflowAgentOnStartCallback = (event: {
400
405
  /** The model being used */
401
- readonly model: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>);
406
+ readonly model: LanguageModel;
402
407
  /** The messages being sent */
403
408
  readonly messages: ModelMessage[];
404
409
  }) => PromiseLike<void> | void;
@@ -409,7 +414,7 @@ type WorkflowAgentOnStepStartCallback = (event: {
409
414
  /** The current step number (0-based) */
410
415
  readonly stepNumber: number;
411
416
  /** The model being used for this step */
412
- readonly model: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>);
417
+ readonly model: LanguageModel;
413
418
  /** The messages being sent for this step */
414
419
  readonly messages: ModelMessage[];
415
420
  }) => PromiseLike<void> | void;
@@ -546,21 +551,21 @@ interface WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, OUTPUT =
546
551
  /**
547
552
  * Callback function to be called after each step completes.
548
553
  */
549
- onStepFinish?: StreamTextOnStepFinishCallback<TTools, any>;
554
+ onStepFinish?: WorkflowAgentOnStepFinishCallback<TTools>;
550
555
  /**
551
556
  * Callback that is invoked when an error occurs during streaming.
552
557
  * You can use it to log errors.
553
558
  */
554
- onError?: StreamTextOnErrorCallback;
559
+ onError?: WorkflowAgentOnErrorCallback;
555
560
  /**
556
561
  * Callback that is called when the LLM response and all request tool executions
557
562
  * (for tools that have an `execute` function) are finished.
558
563
  */
559
- onFinish?: StreamTextOnFinishCallback<TTools, OUTPUT>;
564
+ onFinish?: WorkflowAgentOnFinishCallback<TTools, OUTPUT>;
560
565
  /**
561
566
  * Callback that is called when the operation is aborted.
562
567
  */
563
- onAbort?: StreamTextOnAbortCallback<TTools>;
568
+ onAbort?: WorkflowAgentOnAbortCallback<TTools>;
564
569
  /**
565
570
  * Callback called when the agent starts streaming, before any LLM calls.
566
571
  */
@@ -901,4 +906,4 @@ declare class WorkflowChatTransport<UI_MESSAGE extends UIMessage> implements Cha
901
906
  private onFinish;
902
907
  }
903
908
 
904
- export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextOnAbortCallback, type StreamTextOnErrorCallback, type StreamTextOnFinishCallback, type StreamTextTransform, type TelemetrySettings, WorkflowAgent, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolCallFinishCallback, type WorkflowAgentOnToolCallStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, createModelCallToUIChunkTransform, toUIMessageChunk };
909
+ export { type CompatibleLanguageModel, type DownloadFunction, type GenerationSettings, type InferWorkflowAgentTools, type InferWorkflowAgentUIMessage, type OutputSpecification, type PrepareCallCallback, type PrepareCallOptions, type PrepareCallResult, type PrepareStepCallback, type PrepareStepInfo, type PrepareStepResult, type ProviderOptions, type ReconnectToStreamOptions, type SendMessagesOptions, type StreamTextTransform, type TelemetrySettings, WorkflowAgent, type WorkflowAgentOnAbortCallback, type WorkflowAgentOnErrorCallback, type WorkflowAgentOnFinishCallback, type WorkflowAgentOnStartCallback, type WorkflowAgentOnStepFinishCallback, type WorkflowAgentOnStepStartCallback, type WorkflowAgentOnToolCallFinishCallback, type WorkflowAgentOnToolCallStartCallback, type WorkflowAgentOptions, type WorkflowAgentStreamOptions, type WorkflowAgentStreamResult, WorkflowChatTransport, type WorkflowChatTransportOptions, createModelCallToUIChunkTransform, toUIMessageChunk };
package/dist/index.mjs CHANGED
@@ -77,18 +77,7 @@ function resolveSerializableTools(tools) {
77
77
  async function doStreamStep(conversationPrompt, modelInit, writable, serializedTools, options) {
78
78
  "use step";
79
79
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
80
- let model;
81
- if (typeof modelInit === "string") {
82
- model = gateway.languageModel(modelInit);
83
- } else if (typeof modelInit === "function") {
84
- model = await modelInit();
85
- } else if (typeof modelInit === "object" && modelInit !== null && "modelId" in modelInit) {
86
- model = modelInit;
87
- } else {
88
- throw new Error(
89
- 'Invalid "model initialization" argument. Must be a string, a LanguageModel instance, or a function that returns a LanguageModel instance.'
90
- );
91
- }
80
+ const model = typeof modelInit === "string" ? gateway.languageModel(modelInit) : modelInit;
92
81
  const tools = serializedTools ? resolveSerializableTools(serializedTools) : void 0;
93
82
  const { stream: modelStream } = await streamModelCall({
94
83
  model,