@ai-sdk/workflow 1.0.0-beta.26 → 1.0.0-beta.27

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,39 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.0-beta.27
4
+
5
+ ### Patch Changes
6
+
7
+ - 29d8cf4: feat(ai): rename the core-event types
8
+ - a0ca584: fix (workflow): preserve invalid tool calls as errors instead of emitting synthetic success results
9
+ - Updated dependencies [785fe16]
10
+ - Updated dependencies [5f3749c]
11
+ - Updated dependencies [0a51f7d]
12
+ - Updated dependencies [71d3022]
13
+ - Updated dependencies [67df0a0]
14
+ - Updated dependencies [4181cfe]
15
+ - Updated dependencies [51ce232]
16
+ - Updated dependencies [cf93359]
17
+ - Updated dependencies [befb78c]
18
+ - Updated dependencies [29d8cf4]
19
+ - Updated dependencies [0458559]
20
+ - Updated dependencies [58a2ad7]
21
+ - Updated dependencies [5852c0a]
22
+ - Updated dependencies [37d69b2]
23
+ - Updated dependencies [1043274]
24
+ - Updated dependencies [7f59f04]
25
+ - Updated dependencies [7677c1e]
26
+ - Updated dependencies [116c89f]
27
+ - Updated dependencies [f58f9bc]
28
+ - Updated dependencies [e1bfb9c]
29
+ - Updated dependencies [e87d71b]
30
+ - Updated dependencies [9d486aa]
31
+ - Updated dependencies [9b0bc8a]
32
+ - Updated dependencies [fc92055]
33
+ - Updated dependencies [4e095b0]
34
+ - @ai-sdk/provider-utils@5.0.0-beta.27
35
+ - ai@7.0.0-beta.112
36
+
3
37
  ## 1.0.0-beta.26
4
38
 
5
39
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LanguageModelV4, SharedV4ProviderOptions, LanguageModelV4CallOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart } from '@ai-sdk/provider';
2
- import { ToolSet, LanguageModel, SystemModelMessage, ToolChoice, StopCondition, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, StepResult, StreamTextOnStepFinishCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
2
+ import { ToolSet, LanguageModel, SystemModelMessage, ToolChoice, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, StepResult, GenerateTextOnStepFinishCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
3
3
  export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, ToolCallRepairFunction } from 'ai';
4
4
 
5
5
  /**
@@ -15,10 +15,10 @@ type CompatibleLanguageModel = LanguageModelV4;
15
15
 
16
16
  /**
17
17
  * Callback function to be called after each step completes.
18
- * Alias for the AI SDK's StreamTextOnStepFinishCallback, using
18
+ * Alias for the AI SDK's GenerateTextOnStepFinishCallback, using
19
19
  * WorkflowAgent-consistent naming.
20
20
  */
21
- type WorkflowAgentOnStepFinishCallback<TTools extends ToolSet = ToolSet> = StreamTextOnStepFinishCallback<TTools, any>;
21
+ type WorkflowAgentOnStepFinishCallback<TTools extends ToolSet = ToolSet> = GenerateTextOnStepFinishCallback<TTools, any>;
22
22
  /**
23
23
  * Infer the type of the tools of a workflow agent.
24
24
  */
@@ -337,7 +337,7 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
337
337
  *
338
338
  * Per-stream `activeTools` values passed to `stream()` override this default.
339
339
  */
340
- activeTools?: Array<keyof NoInfer<TTools>>;
340
+ activeTools?: ActiveTools<NoInfer<TTools>>;
341
341
  /**
342
342
  * Default output specification for structured outputs.
343
343
  * Use `Output.object({ schema })` for structured output or `Output.text()` for text output.
@@ -577,7 +577,7 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, OUTPUT = never
577
577
  * Limits the tools that are available for the model to call without
578
578
  * changing the tool call and result types in the result.
579
579
  */
580
- activeTools?: Array<keyof NoInfer<TTools>>;
580
+ activeTools?: ActiveTools<NoInfer<TTools>>;
581
581
  /**
582
582
  * Optional telemetry configuration.
583
583
  */
package/dist/index.mjs CHANGED
@@ -28,12 +28,14 @@ import Ajv from "ajv";
28
28
  function serializeToolSet(tools) {
29
29
  return Object.fromEntries(
30
30
  Object.entries(tools).map(([name, t]) => {
31
+ var _a;
31
32
  const def = {
32
33
  description: t.description,
33
34
  inputSchema: asSchema(t.inputSchema).jsonSchema
34
35
  };
35
36
  if (t.type === "provider") {
36
37
  def.type = "provider";
38
+ def.isProviderExecuted = (_a = t.isProviderExecuted) != null ? _a : false;
37
39
  def.id = t.id;
38
40
  def.args = t.args;
39
41
  }
@@ -45,7 +47,7 @@ function resolveSerializableTools(tools) {
45
47
  const ajv = new Ajv();
46
48
  return Object.fromEntries(
47
49
  Object.entries(tools).map(([name, t]) => {
48
- var _a;
50
+ var _a, _b;
49
51
  if (t.type === "provider") {
50
52
  return [
51
53
  name,
@@ -53,6 +55,7 @@ function resolveSerializableTools(tools) {
53
55
  type: "provider",
54
56
  id: t.id,
55
57
  args: (_a = t.args) != null ? _a : {},
58
+ isProviderExecuted: (_b = t.isProviderExecuted) != null ? _b : false,
56
59
  inputSchema: jsonSchema(t.inputSchema)
57
60
  })
58
61
  ];
@@ -91,6 +94,7 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
91
94
  // pre-converted LanguageModelV4Prompt. standardizePrompt inside
92
95
  // streamModelCall handles both formats.
93
96
  messages: conversationPrompt,
97
+ allowSystemInMessages: true,
94
98
  tools,
95
99
  toolChoice: options == null ? void 0 : options.toolChoice,
96
100
  includeRawChunks: options == null ? void 0 : options.includeRawChunks,
@@ -644,6 +648,8 @@ var WorkflowAgent = class {
644
648
  }
645
649
  const prompt = await standardizePrompt({
646
650
  system: effectiveInstructions,
651
+ allowSystemInMessages: true,
652
+ // TODO: consider exposing this as a parameter
647
653
  ...effectivePrompt != null ? { prompt: effectivePrompt } : { messages: effectiveMessages }
648
654
  });
649
655
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovalsFromMessages(prompt.messages);
@@ -929,10 +935,14 @@ var WorkflowAgent = class {
929
935
  experimentalContext = context;
930
936
  }
931
937
  if (toolCalls.length > 0) {
932
- const nonProviderToolCalls = toolCalls.filter(
938
+ const invalidToolCalls = toolCalls.filter((tc) => tc.invalid === true);
939
+ const validToolCalls = toolCalls.filter((tc) => tc.invalid !== true);
940
+ const nonProviderToolCalls = validToolCalls.filter(
933
941
  (tc) => !tc.providerExecuted
934
942
  );
935
- const providerToolCalls = toolCalls.filter((tc) => tc.providerExecuted);
943
+ const providerToolCalls = validToolCalls.filter(
944
+ (tc) => tc.providerExecuted
945
+ );
936
946
  const approvalNeeded = await Promise.all(
937
947
  nonProviderToolCalls.map(async (tc) => {
938
948
  const tool2 = effectiveTools[tc.toolName];
@@ -973,14 +983,22 @@ var WorkflowAgent = class {
973
983
  providerExecutedToolResults
974
984
  )
975
985
  );
976
- const resolvedResults = [...executableResults, ...providerResults];
986
+ const continuationInvalidResults = invalidToolCalls.map(
987
+ createInvalidToolResult
988
+ );
989
+ const resolvedResults = [
990
+ ...executableResults,
991
+ ...providerResults,
992
+ ...continuationInvalidResults
993
+ ];
994
+ const executedResults = [...executableResults, ...providerResults];
977
995
  const allToolCalls = toolCalls.map((tc) => ({
978
996
  type: "tool-call",
979
997
  toolCallId: tc.toolCallId,
980
998
  toolName: tc.toolName,
981
999
  input: tc.input
982
1000
  }));
983
- const allToolResults = resolvedResults.map((r) => {
1001
+ const allToolResults = executedResults.map((r) => {
984
1002
  var _a2;
985
1003
  return {
986
1004
  type: "tool-result",
@@ -1055,26 +1073,31 @@ var WorkflowAgent = class {
1055
1073
  const providerToolResults = providerToolCalls.map(
1056
1074
  (toolCall) => resolveProviderToolResult(toolCall, providerExecutedToolResults)
1057
1075
  );
1058
- const toolResults = toolCalls.map((tc) => {
1076
+ const continuationInvalidToolResults = invalidToolCalls.map(
1077
+ createInvalidToolResult
1078
+ );
1079
+ const continuationToolResults = toolCalls.flatMap((tc) => {
1080
+ const invalidResult = continuationInvalidToolResults.find(
1081
+ (r) => r.toolCallId === tc.toolCallId
1082
+ );
1083
+ if (invalidResult) return [invalidResult];
1059
1084
  const clientResult = clientToolResults.find(
1060
1085
  (r) => r.toolCallId === tc.toolCallId
1061
1086
  );
1062
- if (clientResult) return clientResult;
1087
+ if (clientResult) return [clientResult];
1063
1088
  const providerResult = providerToolResults.find(
1064
1089
  (r) => r.toolCallId === tc.toolCallId
1065
1090
  );
1066
- if (providerResult) return providerResult;
1067
- return {
1068
- type: "tool-result",
1069
- toolCallId: tc.toolCallId,
1070
- toolName: tc.toolName,
1071
- output: { type: "text", value: "" }
1072
- };
1091
+ if (providerResult) return [providerResult];
1092
+ return [];
1073
1093
  });
1094
+ const executedToolResults = continuationToolResults.filter(
1095
+ (result2) => !invalidToolCalls.some((tc) => tc.toolCallId === result2.toolCallId)
1096
+ );
1074
1097
  if (options.writable) {
1075
1098
  await writeToolResultsWithStepBoundary(
1076
1099
  options.writable,
1077
- toolResults.map((r) => {
1100
+ executedToolResults.map((r) => {
1078
1101
  var _a2;
1079
1102
  return {
1080
1103
  toolCallId: r.toolCallId,
@@ -1091,7 +1114,7 @@ var WorkflowAgent = class {
1091
1114
  toolName: tc.toolName,
1092
1115
  input: tc.input
1093
1116
  }));
1094
- lastStepToolResults = toolResults.map((r) => {
1117
+ lastStepToolResults = executedToolResults.map((r) => {
1095
1118
  var _a2;
1096
1119
  return {
1097
1120
  type: "tool-result",
@@ -1101,7 +1124,7 @@ var WorkflowAgent = class {
1101
1124
  output: "value" in r.output ? r.output.value : void 0
1102
1125
  };
1103
1126
  });
1104
- result = await iterator.next(toolResults);
1127
+ result = await iterator.next(continuationToolResults);
1105
1128
  } else {
1106
1129
  lastStepToolCalls = [];
1107
1130
  lastStepToolResults = [];
@@ -1313,6 +1336,17 @@ function resolveProviderToolResult(toolCall, providerExecutedToolResults) {
1313
1336
  }
1314
1337
  };
1315
1338
  }
1339
+ function createInvalidToolResult(toolCall) {
1340
+ return {
1341
+ type: "tool-result",
1342
+ toolCallId: toolCall.toolCallId,
1343
+ toolName: toolCall.toolName,
1344
+ output: {
1345
+ type: "error-text",
1346
+ value: getErrorMessage(toolCall.error)
1347
+ }
1348
+ };
1349
+ }
1316
1350
  async function executeTool(toolCall, tools, messages, experimentalContext) {
1317
1351
  const tool2 = tools[toolCall.toolName];
1318
1352
  if (!tool2) throw new Error(`Tool "${toolCall.toolName}" not found`);