@uns-kit/assistant-workflow 3.0.2 → 3.0.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.
Files changed (43) hide show
  1. package/API_STABILITY.md +38 -0
  2. package/README.md +40 -0
  3. package/dist/definition-diagnostics.d.ts +1 -1
  4. package/dist/definition-diagnostics.d.ts.map +1 -1
  5. package/dist/definition-diagnostics.js +62 -0
  6. package/dist/definition-diagnostics.js.map +1 -1
  7. package/dist/definition-diff.d.ts +13 -1
  8. package/dist/definition-diff.d.ts.map +1 -1
  9. package/dist/definition-diff.js +49 -2
  10. package/dist/definition-diff.js.map +1 -1
  11. package/dist/definition.d.ts +5 -0
  12. package/dist/definition.d.ts.map +1 -1
  13. package/dist/definition.js +38 -0
  14. package/dist/definition.js.map +1 -1
  15. package/dist/execution-budget.d.ts +38 -0
  16. package/dist/execution-budget.d.ts.map +1 -0
  17. package/dist/execution-budget.js +65 -0
  18. package/dist/execution-budget.js.map +1 -0
  19. package/dist/execution-plan.d.ts +8 -0
  20. package/dist/execution-plan.d.ts.map +1 -1
  21. package/dist/execution-plan.js +47 -1
  22. package/dist/execution-plan.js.map +1 -1
  23. package/dist/execution-policy.d.ts +9 -0
  24. package/dist/execution-policy.d.ts.map +1 -0
  25. package/dist/execution-policy.js +21 -0
  26. package/dist/execution-policy.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/planning.d.ts +1 -0
  32. package/dist/planning.d.ts.map +1 -1
  33. package/dist/planning.js +1 -0
  34. package/dist/planning.js.map +1 -1
  35. package/dist/tool-executor.d.ts +7 -0
  36. package/dist/tool-executor.d.ts.map +1 -1
  37. package/dist/tool-executor.js +180 -55
  38. package/dist/tool-executor.js.map +1 -1
  39. package/dist/tool-invocations.d.ts +7 -0
  40. package/dist/tool-invocations.d.ts.map +1 -1
  41. package/dist/tool-invocations.js +43 -2
  42. package/dist/tool-invocations.js.map +1 -1
  43. package/package.json +11 -2
@@ -1 +1 @@
1
- {"version":3,"file":"tool-executor.d.ts","sourceRoot":"","sources":["../src/tool-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sCAAsC,EACtC,yCAAyC,EACzC,6BAA6B,EAC9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,+BAA+B,EAC/B,oCAAoC,EACrC,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,+BAA+B,EAC/B,oCAAoC,GACrC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAML,KAAK,2BAA2B,EAChC,KAAK,kCAAkC,EACxC,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,oCAAoC,GAAG;IACjD,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,oCAAoC,CAAC,QAAQ,CAAC,CAAC;IAC5D,IAAI,EAAE,mCAAmC,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEpF,MAAM,MAAM,uCAAuC,GAAG,QAAQ,CAC5D,MAAM,CAAC,MAAM,EAAE,mCAAmC,CAAC,CACpD,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,CAC1C,UAAU,EAAE,+BAA+B,EAC3C,OAAO,EAAE,oCAAoC,KAC1C,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,MAAM,MAAM,0CAA0C,CACpD,SAAS,SAAS,6BAA6B,GAAG,6BAA6B,IAC7E,IAAI,CAAC,+BAA+B,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC,GAAG;IACjF,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,EAAE,yCAAyC,GAAG;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC;IAChF,OAAO,EAAE,OAAO,CAAC,sC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AClD,OAAO,CAAC,oCAAoC,CAAC,CAyJ/C;AAED,wBAAgB,+CAA+C,CAC7D,MAAM,EAAE,oCAAoC,GAC3C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzB;AAED,wBAAgB,oDAAoD,CAClE,KAAK,EAAE,mCAAmC,GACzC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAezB"}
@@ -1,3 +1,5 @@
1
+ import { buildAssistantWorkflowExecutionBudgetAssessment, buildAssistantWorkflowExecutionBudgetTracePayload, formatAssistantWorkflowExecutionBudgetViolation, } from "./execution-budget.js";
2
+ import { resolveAssistantWorkflowExecutionPolicy } from "./execution-policy.js";
1
3
  import { assistantWorkflowToolError, assistantWorkflowToolSkipped, assistantWorkflowToolSuccess, buildAssistantWorkflowToolResultsTracePayload, summarizeAssistantWorkflowToolResults, } from "./tool-results.js";
2
4
  /**
3
5
  * Adapts provider-specific integrations to the generic invocation executor.
@@ -19,75 +21,141 @@ export function createAssistantWorkflowToolProviderExecutor(executors, options =
19
21
  }
20
22
  export async function executeAssistantWorkflowToolInvocationQueue(queue, executor, options = {}) {
21
23
  const results = [];
22
- const continueOnError = options.continueOnError === true;
23
24
  const now = options.now ?? (() => Date.now());
25
+ const executionPolicy = queue.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy();
26
+ const continueIndependent = options.continueOnError !== undefined
27
+ ? options.continueOnError
28
+ : executionPolicy.failureMode === "continue-independent";
29
+ const executionBudget = options.executionBudget ?? queue.executionBudget ?? null;
30
+ const preflightBudgetAssessment = executionBudget
31
+ ? buildAssistantWorkflowExecutionBudgetAssessment(executionBudget, {
32
+ toolCallCount: queue.invocations.reduce((count, invocation) => count + normalizeMaxAttempts(invocation.maxAttempts), 0),
33
+ })
34
+ : null;
35
+ if (preflightBudgetAssessment?.status === "blocked") {
36
+ appendBudgetBlockedResults(results, queue.invocations, preflightBudgetAssessment, 0, queue.status, options.onEvent);
37
+ return buildExecutionReport(queue, results, preflightBudgetAssessment);
38
+ }
39
+ const executionStartedAt = executionBudget ? now() : null;
40
+ let startedToolCallCount = 0;
41
+ let elapsedMs = 0;
42
+ const failedStepIds = new Set();
24
43
  for (const [invocationIndex, invocation] of queue.invocations.entries()) {
25
- const startedAt = now();
26
- emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({
27
- phase: "started",
28
- invocation,
29
- invocationIndex,
30
- queueStatus: queue.status,
31
- }));
32
- try {
33
- const output = await executor(invocation, {
34
- invocationIndex,
35
- queueStatus: queue.status,
36
- args: readInvocationArgs(options.argsByInvocationId, invocation.id),
37
- });
38
- const durationMs = now() - startedAt;
39
- results.push(assistantWorkflowToolSuccess({
40
- invocationId: invocation.id,
41
- toolName: invocation.toolName,
42
- stepId: invocation.stepId,
43
- provider: invocation.provider,
44
- output,
45
- durationMs,
46
- }));
47
- emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({
48
- phase: "succeeded",
49
- invocation,
50
- invocationIndex,
51
- queueStatus: queue.status,
52
- durationMs,
53
- }));
44
+ const failedDependencyId = (invocation.dependsOnStepIds ?? []).find((stepId) => failedStepIds.has(stepId));
45
+ if (failedDependencyId) {
46
+ const errorMessage = `dependency step failed: ${failedDependencyId}`;
47
+ appendSkippedInvocation(results, invocation, errorMessage, invocationIndex, queue.status, options.onEvent);
48
+ failedStepIds.add(invocation.stepId);
49
+ continue;
54
50
  }
55
- catch (error) {
56
- const durationMs = now() - startedAt;
57
- const errorMessage = getErrorMessage(error);
58
- const retryable = options.retryableOnError === true;
59
- results.push(assistantWorkflowToolError({
60
- invocationId: invocation.id,
61
- toolName: invocation.toolName,
62
- stepId: invocation.stepId,
63
- provider: invocation.provider,
64
- errorMessage,
65
- retryable,
66
- durationMs,
67
- }));
51
+ const maxAttempts = normalizeMaxAttempts(invocation.maxAttempts);
52
+ const invocationStartedAt = now();
53
+ let invocationFailed = false;
54
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
55
+ const attemptStartedAt = attempt === 1 ? invocationStartedAt : now();
56
+ if (executionBudget && executionStartedAt !== null) {
57
+ elapsedMs = Math.max(0, attemptStartedAt - executionStartedAt);
58
+ const assessment = buildAssistantWorkflowExecutionBudgetAssessment(executionBudget, {
59
+ toolCallCount: startedToolCallCount,
60
+ elapsedMs,
61
+ });
62
+ if (assessment.status === "blocked") {
63
+ appendBudgetBlockedResults(results, queue.invocations.slice(invocationIndex), assessment, invocationIndex, queue.status, options.onEvent);
64
+ return buildExecutionReport(queue, results, assessment);
65
+ }
66
+ }
67
+ startedToolCallCount += 1;
68
68
  emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({
69
- phase: "failed",
69
+ phase: "started",
70
70
  invocation,
71
71
  invocationIndex,
72
72
  queueStatus: queue.status,
73
- durationMs,
74
- errorMessage,
75
- retryable,
73
+ attempt,
74
+ maxAttempts,
76
75
  }));
77
- if (!continueOnError) {
78
- appendSkippedAfterFailure(results, queue.invocations.slice(invocationIndex + 1), invocation.id, invocationIndex + 1, queue.status, options.onEvent);
76
+ try {
77
+ const output = await executor(invocation, {
78
+ invocationIndex,
79
+ queueStatus: queue.status,
80
+ args: readInvocationArgs(options.argsByInvocationId, invocation.id),
81
+ attempt,
82
+ maxAttempts,
83
+ });
84
+ const completedAt = now();
85
+ const durationMs = completedAt - invocationStartedAt;
86
+ if (executionStartedAt !== null)
87
+ elapsedMs = Math.max(0, completedAt - executionStartedAt);
88
+ results.push(assistantWorkflowToolSuccess({
89
+ invocationId: invocation.id,
90
+ toolName: invocation.toolName,
91
+ stepId: invocation.stepId,
92
+ provider: invocation.provider,
93
+ output,
94
+ durationMs,
95
+ }));
96
+ emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({
97
+ phase: "succeeded",
98
+ invocation,
99
+ invocationIndex,
100
+ queueStatus: queue.status,
101
+ durationMs: completedAt - attemptStartedAt,
102
+ attempt,
103
+ maxAttempts,
104
+ }));
79
105
  break;
80
106
  }
107
+ catch (error) {
108
+ const completedAt = now();
109
+ const errorMessage = getErrorMessage(error);
110
+ const retryable = attempt < maxAttempts || options.retryableOnError === true;
111
+ if (executionStartedAt !== null)
112
+ elapsedMs = Math.max(0, completedAt - executionStartedAt);
113
+ emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({
114
+ phase: "failed",
115
+ invocation,
116
+ invocationIndex,
117
+ queueStatus: queue.status,
118
+ durationMs: completedAt - attemptStartedAt,
119
+ errorMessage,
120
+ retryable,
121
+ attempt,
122
+ maxAttempts,
123
+ }));
124
+ if (attempt < maxAttempts)
125
+ continue;
126
+ results.push(assistantWorkflowToolError({
127
+ invocationId: invocation.id,
128
+ toolName: invocation.toolName,
129
+ stepId: invocation.stepId,
130
+ provider: invocation.provider,
131
+ errorMessage,
132
+ retryable: options.retryableOnError === true,
133
+ durationMs: completedAt - invocationStartedAt,
134
+ }));
135
+ invocationFailed = true;
136
+ failedStepIds.add(invocation.stepId);
137
+ }
138
+ }
139
+ if (invocationFailed && !continueIndependent) {
140
+ appendSkippedAfterFailure(results, queue.invocations.slice(invocationIndex + 1), invocation.id, invocationIndex + 1, queue.status, options.onEvent);
141
+ break;
81
142
  }
82
143
  }
83
- return {
84
- queue,
85
- results,
86
- summary: summarizeAssistantWorkflowToolResults(queue, results),
87
- };
144
+ const budgetAssessment = executionBudget
145
+ ? buildAssistantWorkflowExecutionBudgetAssessment(executionBudget, {
146
+ toolCallCount: startedToolCallCount,
147
+ elapsedMs,
148
+ })
149
+ : null;
150
+ return buildExecutionReport(queue, results, budgetAssessment);
88
151
  }
89
152
  export function buildAssistantWorkflowToolExecutionTracePayload(report) {
90
- return buildAssistantWorkflowToolResultsTracePayload(report.queue, report.results);
153
+ return {
154
+ ...buildAssistantWorkflowToolResultsTracePayload(report.queue, report.results),
155
+ budgetAssessment: report.budgetAssessment
156
+ ? buildAssistantWorkflowExecutionBudgetTracePayload(report.budgetAssessment)
157
+ : null,
158
+ };
91
159
  }
92
160
  export function buildAssistantWorkflowToolExecutionEventTracePayload(event) {
93
161
  return {
@@ -101,6 +169,8 @@ export function buildAssistantWorkflowToolExecutionEventTracePayload(event) {
101
169
  durationMs: event.durationMs,
102
170
  errorMessage: event.errorMessage,
103
171
  retryable: event.retryable,
172
+ ...(event.attempt !== undefined ? { attempt: event.attempt } : {}),
173
+ ...(event.maxAttempts !== undefined ? { maxAttempts: event.maxAttempts } : {}),
104
174
  };
105
175
  }
106
176
  function appendSkippedAfterFailure(results, invocations, failedInvocationId, invocationIndex, queueStatus, onEvent) {
@@ -122,6 +192,39 @@ function appendSkippedAfterFailure(results, invocations, failedInvocationId, inv
122
192
  }));
123
193
  }
124
194
  }
195
+ function appendBudgetBlockedResults(results, invocations, assessment, invocationIndex, queueStatus, onEvent) {
196
+ const [blockedInvocation, ...remainingInvocations] = invocations;
197
+ if (!blockedInvocation)
198
+ return;
199
+ const errorMessage = formatAssistantWorkflowExecutionBudgetViolation(assessment.violations[0]);
200
+ results.push(assistantWorkflowToolError({
201
+ invocationId: blockedInvocation.id,
202
+ toolName: blockedInvocation.toolName,
203
+ stepId: blockedInvocation.stepId,
204
+ provider: blockedInvocation.provider,
205
+ errorMessage,
206
+ retryable: false,
207
+ durationMs: 0,
208
+ }));
209
+ emitToolExecutionEvent(onEvent, createToolExecutionEvent({
210
+ phase: "failed",
211
+ invocation: blockedInvocation,
212
+ invocationIndex,
213
+ queueStatus,
214
+ durationMs: 0,
215
+ errorMessage,
216
+ retryable: false,
217
+ }));
218
+ appendSkippedAfterFailure(results, remainingInvocations, blockedInvocation.id, invocationIndex + 1, queueStatus, onEvent);
219
+ }
220
+ function buildExecutionReport(queue, results, budgetAssessment) {
221
+ return {
222
+ queue,
223
+ results,
224
+ summary: summarizeAssistantWorkflowToolResults(queue, results),
225
+ budgetAssessment,
226
+ };
227
+ }
125
228
  function createToolExecutionEvent(input) {
126
229
  return {
127
230
  phase: input.phase,
@@ -134,8 +237,30 @@ function createToolExecutionEvent(input) {
134
237
  durationMs: input.durationMs ?? null,
135
238
  errorMessage: input.errorMessage ?? null,
136
239
  retryable: input.retryable ?? null,
240
+ ...(input.maxAttempts !== undefined && input.maxAttempts > 1
241
+ ? { attempt: input.attempt ?? 1, maxAttempts: input.maxAttempts }
242
+ : {}),
137
243
  };
138
244
  }
245
+ function appendSkippedInvocation(results, invocation, errorMessage, invocationIndex, queueStatus, onEvent) {
246
+ results.push(assistantWorkflowToolSkipped({
247
+ invocationId: invocation.id,
248
+ toolName: invocation.toolName,
249
+ stepId: invocation.stepId,
250
+ provider: invocation.provider,
251
+ errorMessage,
252
+ }));
253
+ emitToolExecutionEvent(onEvent, createToolExecutionEvent({
254
+ phase: "skipped",
255
+ invocation,
256
+ invocationIndex,
257
+ queueStatus,
258
+ errorMessage,
259
+ }));
260
+ }
261
+ function normalizeMaxAttempts(value) {
262
+ return value === 2 || value === 3 ? value : 1;
263
+ }
139
264
  function emitToolExecutionEvent(observer, event) {
140
265
  if (!observer)
141
266
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-executor.js","sourceRoot":"","sources":["../src/tool-executor.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,4BAA4B,EAC5B,6CAA6C,EAC7C,qCAAqC,GAGtC,MAAM,mBAAmB,CAAC;AA2E3B;;;;GAIG;AACH,MAAM,UAAU,2CAA2C,CACzD,SAAiD,EACjD,UAAwD,EAAE;IAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE;QACnC,MAAM,gBAAgB,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,CAEzC,CAAC;QACd,IAAI,gBAAgB,EAAE,CAAC;YACrB,mCAAmC,CAAC,UAAU,CAAC,CAAC;YAChD,OAAO,MAAM,gBAAgB,CAC3B,UAAwD,EACxD,OAAO,CACR,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,MAAM,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,MAAM,IAAI,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EAAE,CAAC,YAAY,CAAC,CAAC;IACnD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,0BAA0B,CAAC;IAC1D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,mCAAmC,CAAC,UAA2C;IACtF,IAAI,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CACb,0CAA0C,UAAU,CAAC,QAAQ,oCAAoC,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,CAChI,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CACb,0CAA0C,UAAU,CAAC,QAAQ,uCAAuC,UAAU,CAAC,UAAU,CAAC,QAAQ,GAAG,CACtI,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,0BAA0B,GAAwC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC","sourcesContent":["import type {\n AssistantWorkflowToolBindingDefinition,\n AssistantWorkflowToolCapabilityDefinition,\n AssistantWorkflowToolProvider,\n} from \"./definition.js\";\nimport type {\n AssistantWorkflowToolInvocation,\n AssistantWorkflowToolInvocationQueue,\n} from \"./tool-invocations.js\";\n\nexport type {\n AssistantWorkflowToolInvocation,\n AssistantWorkflowToolInvocationQueue,\n} from \"./tool-invocations.js\";\nimport {\n assistantWorkflowToolError,\n assistantWorkflowToolSkipped,\n assistantWorkflowToolSuccess,\n buildAssistantWorkflowToolResultsTracePayload,\n summarizeAssistantWorkflowToolResults,\n type AssistantWorkflowToolResult,\n type AssistantWorkflowToolResultSummary,\n} from \"./tool-results.js\";\n\nexport type AssistantWorkflowToolExecutorContext = {\n invocationIndex: number;\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"];\n args: AssistantWorkflowToolInvocationArgs;\n};\n\nexport type AssistantWorkflowToolInvocationArgs = Readonly<Record<string, unknown>>;\n\nexport type AssistantWorkflowToolInvocationArgsById = Readonly<\n Record<string, AssistantWorkflowToolInvocationArgs>\n>;\n\nexport type AssistantWorkflowToolExecutor = (\n invocation: AssistantWorkflowToolInvocation,\n context: AssistantWorkflowToolExecutorContext,\n) => unknown | Promise<unknown>;\n\nexport type AssistantWorkflowToolInvocationForProvider<\n TProvider extends AssistantWorkflowToolProvider = AssistantWorkflowToolProvider,\n> = Omit<AssistantWorkflowToolInvocation, \"provider\" | \"capability\" | \"binding\"> & {\n provider: TProvider;\n capability: AssistantWorkflowToolCapabilityDefinition & { provider: TProvider };\n binding: Extract<AssistantWorkflowToolBindingDefinition, { provider: TProvider }>;\n};\n\nexport type AssistantWorkflowToolProviderExecutor<\n TProvider extends AssistantWorkflowToolProvider = AssistantWorkflowToolProvider,\n> = (\n invocation: AssistantWorkflowToolInvocationForProvider<TProvider>,\n context: AssistantWorkflowToolExecutorContext,\n) => unknown | Promise<unknown>;\n\nexport type AssistantWorkflowToolProviderExecutors = {\n [TProvider in AssistantWorkflowToolProvider]?: AssistantWorkflowToolProviderExecutor<TProvider>;\n};\n\nexport type AssistantWorkflowToolProviderExecutorOptions = {\n fallback?: AssistantWorkflowToolExecutor;\n};\n\nexport type AssistantWorkflowToolExecutionEventPhase =\n | \"started\"\n | \"succeeded\"\n | \"failed\"\n | \"skipped\";\n\nexport type AssistantWorkflowToolExecutionEvent = {\n phase: AssistantWorkflowToolExecutionEventPhase;\n invocationId: string;\n toolName: string;\n stepId: string;\n provider: AssistantWorkflowToolProvider;\n invocationIndex: number;\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"];\n durationMs: number | null;\n errorMessage: string | null;\n retryable: boolean | null;\n};\n\nexport type AssistantWorkflowToolExecutionOptions = {\n continueOnError?: boolean;\n retryableOnError?: boolean;\n now?: () => number;\n argsByInvocationId?: AssistantWorkflowToolInvocationArgsById;\n onEvent?: (event: AssistantWorkflowToolExecutionEvent) => void;\n};\n\nexport type AssistantWorkflowToolExecutionReport = {\n queue: AssistantWorkflowToolInvocationQueue;\n results: AssistantWorkflowToolResult[];\n summary: AssistantWorkflowToolResultSummary;\n};\n\n/**\n * Adapts provider-specific integrations to the generic invocation executor.\n * Applications can add local, HTTP, hosted, MCP, or REPL executors without\n * making queue execution depend on their transport SDKs.\n */\nexport function createAssistantWorkflowToolProviderExecutor(\n executors: AssistantWorkflowToolProviderExecutors,\n options: AssistantWorkflowToolProviderExecutorOptions = {},\n): AssistantWorkflowToolExecutor {\n return async (invocation, context) => {\n const providerExecutor = executors[invocation.provider] as\n | AssistantWorkflowToolProviderExecutor\n | undefined;\n if (providerExecutor) {\n assertInvocationProviderConsistency(invocation);\n return await providerExecutor(\n invocation as AssistantWorkflowToolInvocationForProvider,\n context,\n );\n }\n if (options.fallback) {\n return await options.fallback(invocation, context);\n }\n throw new Error(`No executor configured for assistant workflow tool provider: ${invocation.provider}.`);\n };\n}\n\nexport async function executeAssistantWorkflowToolInvocationQueue(\n queue: AssistantWorkflowToolInvocationQueue,\n executor: AssistantWorkflowToolExecutor,\n options: AssistantWorkflowToolExecutionOptions = {},\n): Promise<AssistantWorkflowToolExecutionReport> {\n const results: AssistantWorkflowToolResult[] = [];\n const continueOnError = options.continueOnError === true;\n const now = options.now ?? (() => Date.now());\n\n for (const [invocationIndex, invocation] of queue.invocations.entries()) {\n const startedAt = now();\n emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({\n phase: \"started\",\n invocation,\n invocationIndex,\n queueStatus: queue.status,\n }));\n try {\n const output = await executor(invocation, {\n invocationIndex,\n queueStatus: queue.status,\n args: readInvocationArgs(options.argsByInvocationId, invocation.id),\n });\n const durationMs = now() - startedAt;\n results.push(\n assistantWorkflowToolSuccess({\n invocationId: invocation.id,\n toolName: invocation.toolName,\n stepId: invocation.stepId,\n provider: invocation.provider,\n output,\n durationMs,\n }),\n );\n emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({\n phase: \"succeeded\",\n invocation,\n invocationIndex,\n queueStatus: queue.status,\n durationMs,\n }));\n } catch (error) {\n const durationMs = now() - startedAt;\n const errorMessage = getErrorMessage(error);\n const retryable = options.retryableOnError === true;\n results.push(\n assistantWorkflowToolError({\n invocationId: invocation.id,\n toolName: invocation.toolName,\n stepId: invocation.stepId,\n provider: invocation.provider,\n errorMessage,\n retryable,\n durationMs,\n }),\n );\n emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({\n phase: \"failed\",\n invocation,\n invocationIndex,\n queueStatus: queue.status,\n durationMs,\n errorMessage,\n retryable,\n }));\n if (!continueOnError) {\n appendSkippedAfterFailure(\n results,\n queue.invocations.slice(invocationIndex + 1),\n invocation.id,\n invocationIndex + 1,\n queue.status,\n options.onEvent,\n );\n break;\n }\n }\n }\n\n return {\n queue,\n results,\n summary: summarizeAssistantWorkflowToolResults(queue, results),\n };\n}\n\nexport function buildAssistantWorkflowToolExecutionTracePayload(\n report: AssistantWorkflowToolExecutionReport,\n): Record<string, unknown> {\n return buildAssistantWorkflowToolResultsTracePayload(report.queue, report.results);\n}\n\nexport function buildAssistantWorkflowToolExecutionEventTracePayload(\n event: AssistantWorkflowToolExecutionEvent,\n): Record<string, unknown> {\n return {\n phase: event.phase,\n invocationId: event.invocationId,\n toolName: event.toolName,\n stepId: event.stepId,\n provider: event.provider,\n invocationIndex: event.invocationIndex,\n queueStatus: event.queueStatus,\n durationMs: event.durationMs,\n errorMessage: event.errorMessage,\n retryable: event.retryable,\n };\n}\n\nfunction appendSkippedAfterFailure(\n results: AssistantWorkflowToolResult[],\n invocations: readonly AssistantWorkflowToolInvocation[],\n failedInvocationId: string,\n invocationIndex: number,\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"],\n onEvent: AssistantWorkflowToolExecutionOptions[\"onEvent\"],\n): void {\n for (const [offset, invocation] of invocations.entries()) {\n const errorMessage = `previous invocation failed: ${failedInvocationId}`;\n results.push(\n assistantWorkflowToolSkipped({\n invocationId: invocation.id,\n toolName: invocation.toolName,\n stepId: invocation.stepId,\n provider: invocation.provider,\n errorMessage,\n }),\n );\n emitToolExecutionEvent(onEvent, createToolExecutionEvent({\n phase: \"skipped\",\n invocation,\n invocationIndex: invocationIndex + offset,\n queueStatus,\n errorMessage,\n }));\n }\n}\n\nfunction createToolExecutionEvent(input: {\n phase: AssistantWorkflowToolExecutionEventPhase;\n invocation: AssistantWorkflowToolInvocation;\n invocationIndex: number;\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"];\n durationMs?: number;\n errorMessage?: string;\n retryable?: boolean;\n}): AssistantWorkflowToolExecutionEvent {\n return {\n phase: input.phase,\n invocationId: input.invocation.id,\n toolName: input.invocation.toolName,\n stepId: input.invocation.stepId,\n provider: input.invocation.provider,\n invocationIndex: input.invocationIndex,\n queueStatus: input.queueStatus,\n durationMs: input.durationMs ?? null,\n errorMessage: input.errorMessage ?? null,\n retryable: input.retryable ?? null,\n };\n}\n\nfunction emitToolExecutionEvent(\n observer: AssistantWorkflowToolExecutionOptions[\"onEvent\"],\n event: AssistantWorkflowToolExecutionEvent,\n): void {\n if (!observer) return;\n try {\n observer(Object.freeze(event));\n } catch {\n // Instrumentation must not alter the tool execution result.\n }\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (error instanceof Error && error.message.trim().length) {\n return error.message.trim();\n }\n if (typeof error === \"string\" && error.trim().length) {\n return error.trim();\n }\n return \"tool invocation failed\";\n}\n\nfunction readInvocationArgs(\n argsByInvocationId: AssistantWorkflowToolInvocationArgsById | undefined,\n invocationId: string,\n): AssistantWorkflowToolInvocationArgs {\n const rawArgs = argsByInvocationId?.[invocationId];\n if (!isRecord(rawArgs)) return EMPTY_TOOL_INVOCATION_ARGS;\n return Object.freeze({ ...rawArgs });\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction assertInvocationProviderConsistency(invocation: AssistantWorkflowToolInvocation): void {\n if (invocation.provider !== invocation.binding.provider) {\n throw new Error(\n `Assistant workflow invocation provider ${invocation.provider} does not match binding provider ${invocation.binding.provider}.`,\n );\n }\n if (invocation.provider !== invocation.capability.provider) {\n throw new Error(\n `Assistant workflow invocation provider ${invocation.provider} does not match capability provider ${invocation.capability.provider}.`,\n );\n }\n}\n\nconst EMPTY_TOOL_INVOCATION_ARGS: AssistantWorkflowToolInvocationArgs = Object.freeze({});\n"]}
1
+ {"version":3,"file":"tool-executor.js","sourceRoot":"","sources":["../src/tool-executor.ts"],"names":[],"mappings":"AASA,OAAO,EACL,+CAA+C,EAC/C,iDAAiD,EACjD,+CAA+C,GAGhD,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,uCAAuC,EAAE,MAAM,uBAAuB,CAAC;AAMhF,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,4BAA4B,EAC5B,6CAA6C,EAC7C,qCAAqC,GAGtC,MAAM,mBAAmB,CAAC;AAiF3B;;;;GAIG;AACH,MAAM,UAAU,2CAA2C,CACzD,SAAiD,EACjD,UAAwD,EAAE;IAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE;QACnC,MAAM,gBAAgB,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,CAEzC,CAAC;QACd,IAAI,gBAAgB,EAAE,CAAC;YACrB,mCAAmC,CAAC,UAAU,CAAC,CAAC;YAChD,OAAO,MAAM,gBAAgB,CAC3B,UAAwD,EACxD,OAAO,CACR,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,MAAM,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,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AI,KAAK,CACb,0CAA0C,UAAU,CAAC,QAAQ,oCAAoC,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,CAChI,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CACb,0CAA0C,UAAU,CAAC,QAAQ,uCAAuC,UAAU,CAAC,UAAU,CAAC,QAAQ,GAAG,CACtI,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,0BAA0B,GAAwC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC","sourcesContent":["import type {\n AssistantWorkflowToolBindingDefinition,\n AssistantWorkflowToolCapabilityDefinition,\n AssistantWorkflowToolProvider,\n} from \"./definition.js\";\nimport type {\n AssistantWorkflowToolInvocation,\n AssistantWorkflowToolInvocationQueue,\n} from \"./tool-invocations.js\";\nimport {\n buildAssistantWorkflowExecutionBudgetAssessment,\n buildAssistantWorkflowExecutionBudgetTracePayload,\n formatAssistantWorkflowExecutionBudgetViolation,\n type AssistantWorkflowExecutionBudget,\n type AssistantWorkflowExecutionBudgetAssessment,\n} from \"./execution-budget.js\";\nimport { resolveAssistantWorkflowExecutionPolicy } from \"./execution-policy.js\";\n\nexport type {\n AssistantWorkflowToolInvocation,\n AssistantWorkflowToolInvocationQueue,\n} from \"./tool-invocations.js\";\nimport {\n assistantWorkflowToolError,\n assistantWorkflowToolSkipped,\n assistantWorkflowToolSuccess,\n buildAssistantWorkflowToolResultsTracePayload,\n summarizeAssistantWorkflowToolResults,\n type AssistantWorkflowToolResult,\n type AssistantWorkflowToolResultSummary,\n} from \"./tool-results.js\";\n\nexport type AssistantWorkflowToolExecutorContext = {\n invocationIndex: number;\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"];\n args: AssistantWorkflowToolInvocationArgs;\n attempt?: number;\n maxAttempts?: number;\n};\n\nexport type AssistantWorkflowToolInvocationArgs = Readonly<Record<string, unknown>>;\n\nexport type AssistantWorkflowToolInvocationArgsById = Readonly<\n Record<string, AssistantWorkflowToolInvocationArgs>\n>;\n\nexport type AssistantWorkflowToolExecutor = (\n invocation: AssistantWorkflowToolInvocation,\n context: AssistantWorkflowToolExecutorContext,\n) => unknown | Promise<unknown>;\n\nexport type AssistantWorkflowToolInvocationForProvider<\n TProvider extends AssistantWorkflowToolProvider = AssistantWorkflowToolProvider,\n> = Omit<AssistantWorkflowToolInvocation, \"provider\" | \"capability\" | \"binding\"> & {\n provider: TProvider;\n capability: AssistantWorkflowToolCapabilityDefinition & { provider: TProvider };\n binding: Extract<AssistantWorkflowToolBindingDefinition, { provider: TProvider }>;\n};\n\nexport type AssistantWorkflowToolProviderExecutor<\n TProvider extends AssistantWorkflowToolProvider = AssistantWorkflowToolProvider,\n> = (\n invocation: AssistantWorkflowToolInvocationForProvider<TProvider>,\n context: AssistantWorkflowToolExecutorContext,\n) => unknown | Promise<unknown>;\n\nexport type AssistantWorkflowToolProviderExecutors = {\n [TProvider in AssistantWorkflowToolProvider]?: AssistantWorkflowToolProviderExecutor<TProvider>;\n};\n\nexport type AssistantWorkflowToolProviderExecutorOptions = {\n fallback?: AssistantWorkflowToolExecutor;\n};\n\nexport type AssistantWorkflowToolExecutionEventPhase =\n | \"started\"\n | \"succeeded\"\n | \"failed\"\n | \"skipped\";\n\nexport type AssistantWorkflowToolExecutionEvent = {\n phase: AssistantWorkflowToolExecutionEventPhase;\n invocationId: string;\n toolName: string;\n stepId: string;\n provider: AssistantWorkflowToolProvider;\n invocationIndex: number;\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"];\n durationMs: number | null;\n errorMessage: string | null;\n retryable: boolean | null;\n attempt?: number;\n maxAttempts?: number;\n};\n\nexport type AssistantWorkflowToolExecutionOptions = {\n continueOnError?: boolean;\n retryableOnError?: boolean;\n now?: () => number;\n argsByInvocationId?: AssistantWorkflowToolInvocationArgsById;\n onEvent?: (event: AssistantWorkflowToolExecutionEvent) => void;\n executionBudget?: AssistantWorkflowExecutionBudget;\n};\n\nexport type AssistantWorkflowToolExecutionReport = {\n queue: AssistantWorkflowToolInvocationQueue;\n results: AssistantWorkflowToolResult[];\n summary: AssistantWorkflowToolResultSummary;\n budgetAssessment?: AssistantWorkflowExecutionBudgetAssessment | null;\n};\n\n/**\n * Adapts provider-specific integrations to the generic invocation executor.\n * Applications can add local, HTTP, hosted, MCP, or REPL executors without\n * making queue execution depend on their transport SDKs.\n */\nexport function createAssistantWorkflowToolProviderExecutor(\n executors: AssistantWorkflowToolProviderExecutors,\n options: AssistantWorkflowToolProviderExecutorOptions = {},\n): AssistantWorkflowToolExecutor {\n return async (invocation, context) => {\n const providerExecutor = executors[invocation.provider] as\n | AssistantWorkflowToolProviderExecutor\n | undefined;\n if (providerExecutor) {\n assertInvocationProviderConsistency(invocation);\n return await providerExecutor(\n invocation as AssistantWorkflowToolInvocationForProvider,\n context,\n );\n }\n if (options.fallback) {\n return await options.fallback(invocation, context);\n }\n throw new Error(`No executor configured for assistant workflow tool provider: ${invocation.provider}.`);\n };\n}\n\nexport async function executeAssistantWorkflowToolInvocationQueue(\n queue: AssistantWorkflowToolInvocationQueue,\n executor: AssistantWorkflowToolExecutor,\n options: AssistantWorkflowToolExecutionOptions = {},\n): Promise<AssistantWorkflowToolExecutionReport> {\n const results: AssistantWorkflowToolResult[] = [];\n const now = options.now ?? (() => Date.now());\n const executionPolicy = queue.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy();\n const continueIndependent = options.continueOnError !== undefined\n ? options.continueOnError\n : executionPolicy.failureMode === \"continue-independent\";\n const executionBudget = options.executionBudget ?? queue.executionBudget ?? null;\n const preflightBudgetAssessment = executionBudget\n ? buildAssistantWorkflowExecutionBudgetAssessment(executionBudget, {\n toolCallCount: queue.invocations.reduce(\n (count, invocation) => count + normalizeMaxAttempts(invocation.maxAttempts),\n 0,\n ),\n })\n : null;\n if (preflightBudgetAssessment?.status === \"blocked\") {\n appendBudgetBlockedResults(\n results,\n queue.invocations,\n preflightBudgetAssessment,\n 0,\n queue.status,\n options.onEvent,\n );\n return buildExecutionReport(queue, results, preflightBudgetAssessment);\n }\n\n const executionStartedAt = executionBudget ? now() : null;\n let startedToolCallCount = 0;\n let elapsedMs = 0;\n const failedStepIds = new Set<string>();\n\n for (const [invocationIndex, invocation] of queue.invocations.entries()) {\n const failedDependencyId = (invocation.dependsOnStepIds ?? []).find((stepId) => failedStepIds.has(stepId));\n if (failedDependencyId) {\n const errorMessage = `dependency step failed: ${failedDependencyId}`;\n appendSkippedInvocation(results, invocation, errorMessage, invocationIndex, queue.status, options.onEvent);\n failedStepIds.add(invocation.stepId);\n continue;\n }\n\n const maxAttempts = normalizeMaxAttempts(invocation.maxAttempts);\n const invocationStartedAt = now();\n let invocationFailed = false;\n for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {\n const attemptStartedAt = attempt === 1 ? invocationStartedAt : now();\n if (executionBudget && executionStartedAt !== null) {\n elapsedMs = Math.max(0, attemptStartedAt - executionStartedAt);\n const assessment = buildAssistantWorkflowExecutionBudgetAssessment(executionBudget, {\n toolCallCount: startedToolCallCount,\n elapsedMs,\n });\n if (assessment.status === \"blocked\") {\n appendBudgetBlockedResults(\n results,\n queue.invocations.slice(invocationIndex),\n assessment,\n invocationIndex,\n queue.status,\n options.onEvent,\n );\n return buildExecutionReport(queue, results, assessment);\n }\n }\n startedToolCallCount += 1;\n emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({\n phase: \"started\",\n invocation,\n invocationIndex,\n queueStatus: queue.status,\n attempt,\n maxAttempts,\n }));\n try {\n const output = await executor(invocation, {\n invocationIndex,\n queueStatus: queue.status,\n args: readInvocationArgs(options.argsByInvocationId, invocation.id),\n attempt,\n maxAttempts,\n });\n const completedAt = now();\n const durationMs = completedAt - invocationStartedAt;\n if (executionStartedAt !== null) elapsedMs = Math.max(0, completedAt - executionStartedAt);\n results.push(assistantWorkflowToolSuccess({\n invocationId: invocation.id,\n toolName: invocation.toolName,\n stepId: invocation.stepId,\n provider: invocation.provider,\n output,\n durationMs,\n }));\n emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({\n phase: \"succeeded\",\n invocation,\n invocationIndex,\n queueStatus: queue.status,\n durationMs: completedAt - attemptStartedAt,\n attempt,\n maxAttempts,\n }));\n break;\n } catch (error) {\n const completedAt = now();\n const errorMessage = getErrorMessage(error);\n const retryable = attempt < maxAttempts || options.retryableOnError === true;\n if (executionStartedAt !== null) elapsedMs = Math.max(0, completedAt - executionStartedAt);\n emitToolExecutionEvent(options.onEvent, createToolExecutionEvent({\n phase: \"failed\",\n invocation,\n invocationIndex,\n queueStatus: queue.status,\n durationMs: completedAt - attemptStartedAt,\n errorMessage,\n retryable,\n attempt,\n maxAttempts,\n }));\n if (attempt < maxAttempts) continue;\n results.push(assistantWorkflowToolError({\n invocationId: invocation.id,\n toolName: invocation.toolName,\n stepId: invocation.stepId,\n provider: invocation.provider,\n errorMessage,\n retryable: options.retryableOnError === true,\n durationMs: completedAt - invocationStartedAt,\n }));\n invocationFailed = true;\n failedStepIds.add(invocation.stepId);\n }\n }\n if (invocationFailed && !continueIndependent) {\n appendSkippedAfterFailure(\n results,\n queue.invocations.slice(invocationIndex + 1),\n invocation.id,\n invocationIndex + 1,\n queue.status,\n options.onEvent,\n );\n break;\n }\n }\n\n const budgetAssessment = executionBudget\n ? buildAssistantWorkflowExecutionBudgetAssessment(executionBudget, {\n toolCallCount: startedToolCallCount,\n elapsedMs,\n })\n : null;\n return buildExecutionReport(queue, results, budgetAssessment);\n}\n\nexport function buildAssistantWorkflowToolExecutionTracePayload(\n report: AssistantWorkflowToolExecutionReport,\n): Record<string, unknown> {\n return {\n ...buildAssistantWorkflowToolResultsTracePayload(report.queue, report.results),\n budgetAssessment: report.budgetAssessment\n ? buildAssistantWorkflowExecutionBudgetTracePayload(report.budgetAssessment)\n : null,\n };\n}\n\nexport function buildAssistantWorkflowToolExecutionEventTracePayload(\n event: AssistantWorkflowToolExecutionEvent,\n): Record<string, unknown> {\n return {\n phase: event.phase,\n invocationId: event.invocationId,\n toolName: event.toolName,\n stepId: event.stepId,\n provider: event.provider,\n invocationIndex: event.invocationIndex,\n queueStatus: event.queueStatus,\n durationMs: event.durationMs,\n errorMessage: event.errorMessage,\n retryable: event.retryable,\n ...(event.attempt !== undefined ? { attempt: event.attempt } : {}),\n ...(event.maxAttempts !== undefined ? { maxAttempts: event.maxAttempts } : {}),\n };\n}\n\nfunction appendSkippedAfterFailure(\n results: AssistantWorkflowToolResult[],\n invocations: readonly AssistantWorkflowToolInvocation[],\n failedInvocationId: string,\n invocationIndex: number,\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"],\n onEvent: AssistantWorkflowToolExecutionOptions[\"onEvent\"],\n): void {\n for (const [offset, invocation] of invocations.entries()) {\n const errorMessage = `previous invocation failed: ${failedInvocationId}`;\n results.push(\n assistantWorkflowToolSkipped({\n invocationId: invocation.id,\n toolName: invocation.toolName,\n stepId: invocation.stepId,\n provider: invocation.provider,\n errorMessage,\n }),\n );\n emitToolExecutionEvent(onEvent, createToolExecutionEvent({\n phase: \"skipped\",\n invocation,\n invocationIndex: invocationIndex + offset,\n queueStatus,\n errorMessage,\n }));\n }\n}\n\nfunction appendBudgetBlockedResults(\n results: AssistantWorkflowToolResult[],\n invocations: readonly AssistantWorkflowToolInvocation[],\n assessment: AssistantWorkflowExecutionBudgetAssessment,\n invocationIndex: number,\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"],\n onEvent: AssistantWorkflowToolExecutionOptions[\"onEvent\"],\n): void {\n const [blockedInvocation, ...remainingInvocations] = invocations;\n if (!blockedInvocation) return;\n const errorMessage = formatAssistantWorkflowExecutionBudgetViolation(assessment.violations[0]!);\n results.push(assistantWorkflowToolError({\n invocationId: blockedInvocation.id,\n toolName: blockedInvocation.toolName,\n stepId: blockedInvocation.stepId,\n provider: blockedInvocation.provider,\n errorMessage,\n retryable: false,\n durationMs: 0,\n }));\n emitToolExecutionEvent(onEvent, createToolExecutionEvent({\n phase: \"failed\",\n invocation: blockedInvocation,\n invocationIndex,\n queueStatus,\n durationMs: 0,\n errorMessage,\n retryable: false,\n }));\n appendSkippedAfterFailure(\n results,\n remainingInvocations,\n blockedInvocation.id,\n invocationIndex + 1,\n queueStatus,\n onEvent,\n );\n}\n\nfunction buildExecutionReport(\n queue: AssistantWorkflowToolInvocationQueue,\n results: AssistantWorkflowToolResult[],\n budgetAssessment: AssistantWorkflowExecutionBudgetAssessment | null,\n): AssistantWorkflowToolExecutionReport {\n return {\n queue,\n results,\n summary: summarizeAssistantWorkflowToolResults(queue, results),\n budgetAssessment,\n };\n}\n\nfunction createToolExecutionEvent(input: {\n phase: AssistantWorkflowToolExecutionEventPhase;\n invocation: AssistantWorkflowToolInvocation;\n invocationIndex: number;\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"];\n durationMs?: number;\n errorMessage?: string;\n retryable?: boolean;\n attempt?: number;\n maxAttempts?: number;\n}): AssistantWorkflowToolExecutionEvent {\n return {\n phase: input.phase,\n invocationId: input.invocation.id,\n toolName: input.invocation.toolName,\n stepId: input.invocation.stepId,\n provider: input.invocation.provider,\n invocationIndex: input.invocationIndex,\n queueStatus: input.queueStatus,\n durationMs: input.durationMs ?? null,\n errorMessage: input.errorMessage ?? null,\n retryable: input.retryable ?? null,\n ...(input.maxAttempts !== undefined && input.maxAttempts > 1\n ? { attempt: input.attempt ?? 1, maxAttempts: input.maxAttempts }\n : {}),\n };\n}\n\nfunction appendSkippedInvocation(\n results: AssistantWorkflowToolResult[],\n invocation: AssistantWorkflowToolInvocation,\n errorMessage: string,\n invocationIndex: number,\n queueStatus: AssistantWorkflowToolInvocationQueue[\"status\"],\n onEvent: AssistantWorkflowToolExecutionOptions[\"onEvent\"],\n): void {\n results.push(assistantWorkflowToolSkipped({\n invocationId: invocation.id,\n toolName: invocation.toolName,\n stepId: invocation.stepId,\n provider: invocation.provider,\n errorMessage,\n }));\n emitToolExecutionEvent(onEvent, createToolExecutionEvent({\n phase: \"skipped\",\n invocation,\n invocationIndex,\n queueStatus,\n errorMessage,\n }));\n}\n\nfunction normalizeMaxAttempts(value: number | undefined): number {\n return value === 2 || value === 3 ? value : 1;\n}\n\nfunction emitToolExecutionEvent(\n observer: AssistantWorkflowToolExecutionOptions[\"onEvent\"],\n event: AssistantWorkflowToolExecutionEvent,\n): void {\n if (!observer) return;\n try {\n observer(Object.freeze(event));\n } catch {\n // Instrumentation must not alter the tool execution result.\n }\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (error instanceof Error && error.message.trim().length) {\n return error.message.trim();\n }\n if (typeof error === \"string\" && error.trim().length) {\n return error.trim();\n }\n return \"tool invocation failed\";\n}\n\nfunction readInvocationArgs(\n argsByInvocationId: AssistantWorkflowToolInvocationArgsById | undefined,\n invocationId: string,\n): AssistantWorkflowToolInvocationArgs {\n const rawArgs = argsByInvocationId?.[invocationId];\n if (!isRecord(rawArgs)) return EMPTY_TOOL_INVOCATION_ARGS;\n return Object.freeze({ ...rawArgs });\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction assertInvocationProviderConsistency(invocation: AssistantWorkflowToolInvocation): void {\n if (invocation.provider !== invocation.binding.provider) {\n throw new Error(\n `Assistant workflow invocation provider ${invocation.provider} does not match binding provider ${invocation.binding.provider}.`,\n );\n }\n if (invocation.provider !== invocation.capability.provider) {\n throw new Error(\n `Assistant workflow invocation provider ${invocation.provider} does not match capability provider ${invocation.capability.provider}.`,\n );\n }\n}\n\nconst EMPTY_TOOL_INVOCATION_ARGS: AssistantWorkflowToolInvocationArgs = Object.freeze({});\n"]}
@@ -1,15 +1,19 @@
1
1
  import type { AssistantWorkflowDefinition, AssistantWorkflowPlanningStepKind, AssistantWorkflowToolBindingDefinition, AssistantWorkflowToolCapabilityDefinition, AssistantWorkflowToolProvider } from "./definition.js";
2
2
  import type { AssistantWorkflowExecutionPlan, AssistantWorkflowExecutionPlanStatus } from "./execution-plan.js";
3
+ import { type AssistantWorkflowExecutionBudget, type AssistantWorkflowExecutionBudgetAssessment } from "./execution-budget.js";
4
+ import { type AssistantWorkflowExecutionPolicy } from "./execution-policy.js";
3
5
  export type AssistantWorkflowToolInvocationQueueStatus = "ready" | "partial" | "blocked" | "empty";
4
6
  export type AssistantWorkflowToolInvocation = {
5
7
  id: string;
6
8
  stepId: string;
7
9
  stepKind: AssistantWorkflowPlanningStepKind;
10
+ dependsOnStepIds?: string[];
8
11
  toolName: string;
9
12
  required: boolean;
10
13
  provider: AssistantWorkflowToolProvider;
11
14
  capability: AssistantWorkflowToolCapabilityDefinition;
12
15
  binding: AssistantWorkflowToolBindingDefinition;
16
+ maxAttempts?: number;
13
17
  };
14
18
  export type AssistantWorkflowToolInvocationQueue = {
15
19
  status: AssistantWorkflowToolInvocationQueueStatus;
@@ -17,6 +21,9 @@ export type AssistantWorkflowToolInvocationQueue = {
17
21
  skippedStepIds: string[];
18
22
  blockingReasons: string[];
19
23
  warnings: string[];
24
+ executionBudget?: AssistantWorkflowExecutionBudget | null;
25
+ budgetAssessment?: AssistantWorkflowExecutionBudgetAssessment | null;
26
+ executionPolicy?: AssistantWorkflowExecutionPolicy;
20
27
  };
21
28
  export type AssistantWorkflowToolInvocationQueueOptions = {
22
29
  includeOptional?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-invocations.d.ts","sourceRoot":"","sources":["../src/tool-invocations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,iCAAiC,EACjC,sCAAsC,EACtC,yCAAyC,EACzC,6BAA6B,EAC9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,8BAA8B,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC;AAMhH,MAAM,MAAM,0CAA0C,GAClD,OAAO,GACP,SAAS,GACT,SAAS,GACT,OAAO,CAAC;AAEZ,MAAM,MAAM,+BAA+B,GAAG;IAC5C,EAAE,EAAE,M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C;AAEF,wBAAgB,yCAAyC,CACvD,QAAQ,EAAE,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACrE,GAAG,EAAE,kCAAkC,EACvC,OAAO,GAAE,2CAAgD,GACxD,oCAAoC,CAyEtC;AAED,wBAAgB,qDAAqD,CACnE,KAAK,EAAE,oCAAoC,GAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0BzB"}
@@ -1,4 +1,6 @@
1
1
  import { resolveAssistantWorkflowTools, } from "./tool-bindings.js";
2
+ import { buildAssistantWorkflowExecutionBudgetAssessment, buildAssistantWorkflowExecutionBudgetTracePayload, formatAssistantWorkflowExecutionBudgetViolation, } from "./execution-budget.js";
3
+ import { resolveAssistantWorkflowExecutionPolicy, } from "./execution-policy.js";
2
4
  export function buildAssistantWorkflowToolInvocationQueue(workflow, run, options = {}) {
3
5
  const includeOptional = options.includeOptional !== false;
4
6
  const blocked = run.status === "blocked" || run.status === "needs-clarification";
@@ -9,9 +11,13 @@ export function buildAssistantWorkflowToolInvocationQueue(workflow, run, options
9
11
  skippedStepIds: run.executionPlan.steps.map((step) => step.id),
10
12
  blockingReasons: [...run.executionPlan.blockingReasons],
11
13
  warnings: [...run.executionPlan.warnings],
14
+ executionBudget: run.executionPlan.executionBudget ?? null,
15
+ budgetAssessment: run.executionPlan.budgetAssessment ?? null,
16
+ executionPolicy: run.executionPlan.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy(),
12
17
  };
13
18
  }
14
19
  const invocations = [];
20
+ const executionPolicy = run.executionPlan.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy(workflow.executionPolicy);
15
21
  const skippedStepIds = [];
16
22
  for (const step of run.executionPlan.steps) {
17
23
  if (step.status === "blocked" || step.status === "optional-skipped") {
@@ -23,12 +29,33 @@ export function buildAssistantWorkflowToolInvocationQueue(workflow, run, options
23
29
  : step.readyToolNames.filter((toolName) => step.requiredToolNames.includes(toolName));
24
30
  const resolutions = resolveAssistantWorkflowTools(workflow, readyToolNames).resolutions;
25
31
  for (const resolution of resolutions) {
26
- const invocation = buildInvocation(step.id, step.kind, step.requiredToolNames.includes(resolution.toolName), resolution);
32
+ const invocation = buildInvocation(step.id, step.kind, step.dependsOnStepIds, step.requiredToolNames.includes(resolution.toolName), resolution, executionPolicy);
27
33
  if (invocation) {
28
34
  invocations.push(invocation);
29
35
  }
30
36
  }
31
37
  }
38
+ const budgetAssessment = workflow.executionBudget
39
+ ? buildAssistantWorkflowExecutionBudgetAssessment(workflow.executionBudget, {
40
+ planningStepCount: run.executionPlan.steps.length,
41
+ toolCallCount: invocations.reduce((count, invocation) => count + (invocation.maxAttempts ?? 1), 0),
42
+ })
43
+ : null;
44
+ if (budgetAssessment?.status === "blocked") {
45
+ return {
46
+ status: "blocked",
47
+ invocations: [],
48
+ skippedStepIds: run.executionPlan.steps.map((step) => step.id),
49
+ blockingReasons: [
50
+ ...run.executionPlan.blockingReasons,
51
+ ...budgetAssessment.violations.map(formatAssistantWorkflowExecutionBudgetViolation),
52
+ ],
53
+ warnings: [...run.executionPlan.warnings],
54
+ executionBudget: { ...budgetAssessment.budget },
55
+ budgetAssessment,
56
+ executionPolicy,
57
+ };
58
+ }
32
59
  return {
33
60
  status: invocations.length === 0
34
61
  ? "empty"
@@ -39,6 +66,9 @@ export function buildAssistantWorkflowToolInvocationQueue(workflow, run, options
39
66
  skippedStepIds,
40
67
  blockingReasons: [...run.executionPlan.blockingReasons],
41
68
  warnings: [...run.executionPlan.warnings],
69
+ executionBudget: workflow.executionBudget ? { ...workflow.executionBudget } : null,
70
+ budgetAssessment,
71
+ executionPolicy,
42
72
  };
43
73
  }
44
74
  export function buildAssistantWorkflowToolInvocationQueueTracePayload(queue) {
@@ -49,19 +79,26 @@ export function buildAssistantWorkflowToolInvocationQueueTracePayload(queue) {
49
79
  id: invocation.id,
50
80
  stepId: invocation.stepId,
51
81
  stepKind: invocation.stepKind,
82
+ dependsOnStepIds: invocation.dependsOnStepIds ?? [],
52
83
  toolName: invocation.toolName,
53
84
  required: invocation.required,
54
85
  provider: invocation.provider,
55
86
  effect: invocation.capability.effect,
56
87
  outputKinds: invocation.capability.outputKinds,
57
88
  bindingProvider: invocation.binding.provider,
89
+ maxAttempts: invocation.maxAttempts ?? 1,
58
90
  })),
59
91
  skippedStepIds: queue.skippedStepIds,
60
92
  blockingReasons: queue.blockingReasons,
61
93
  warnings: queue.warnings,
94
+ executionBudget: queue.executionBudget ?? null,
95
+ budgetAssessment: queue.budgetAssessment
96
+ ? buildAssistantWorkflowExecutionBudgetTracePayload(queue.budgetAssessment)
97
+ : null,
98
+ executionPolicy: queue.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy(),
62
99
  };
63
100
  }
64
- function buildInvocation(stepId, stepKind, required, resolution) {
101
+ function buildInvocation(stepId, stepKind, dependsOnStepIds, required, resolution, executionPolicy) {
65
102
  if (resolution.status !== "ready" || !resolution.capability || !resolution.binding || !resolution.provider) {
66
103
  return null;
67
104
  }
@@ -69,11 +106,15 @@ function buildInvocation(stepId, stepKind, required, resolution) {
69
106
  id: `${stepId}:${resolution.toolName}`,
70
107
  stepId,
71
108
  stepKind,
109
+ dependsOnStepIds: [...dependsOnStepIds],
72
110
  toolName: resolution.toolName,
73
111
  required,
74
112
  provider: resolution.provider,
75
113
  capability: resolution.capability,
76
114
  binding: resolution.binding,
115
+ maxAttempts: resolution.capability.retryClass === "never"
116
+ ? 1
117
+ : executionPolicy.maxAttemptsPerTool,
77
118
  };
78
119
  }
79
120
  //# sourceMappingURL=tool-invocations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-invocations.js","sourceRoot":"","sources":["../src/tool-invocations.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,6BAA6B,GAE9B,MAAM,oBAAoB,CAAC;AAqC5B,MAAM,UAAU,yCAAyC,CACvD,QAAqE,EACrE,GAAuC,EACvC,UAAuD,EAAE;IAEzD,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,KA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,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CACtB,MAAc,EACd,QAA2C,EAC3C,QAAiB,EACjB,UAA2C;IAE3C,IAAI,UAAU,CAAC,MAAM,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC3G,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,EAAE,EAAE,GAAG,MAAM,IAAI,UAAU,CAAC,QAAQ,EAAE;QACtC,MAAM;QACN,QAAQ;QACR,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,QAAQ;QACR,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,OAAO,EAAE,UAAU,CAAC,OAAO;KAC5B,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AssistantWorkflowDefinition,\n AssistantWorkflowPlanningStepKind,\n AssistantWorkflowToolBindingDefinition,\n AssistantWorkflowToolCapabilityDefinition,\n AssistantWorkflowToolProvider,\n} from \"./definition.js\";\nimport type { AssistantWorkflowExecutionPlan, AssistantWorkflowExecutionPlanStatus } from \"./execution-plan.js\";\nimport {\n resolveAssistantWorkflowTools,\n type AssistantWorkflowToolResolution,\n} from \"./tool-bindings.js\";\n\nexport type AssistantWorkflowToolInvocationQueueStatus =\n | \"ready\"\n | \"partial\"\n | \"blocked\"\n | \"empty\";\n\nexport type AssistantWorkflowToolInvocation = {\n id: string;\n stepId: string;\n stepKind: AssistantWorkflowPlanningStepKind;\n toolName: string;\n required: boolean;\n provider: AssistantWorkflowToolProvider;\n capability: AssistantWorkflowToolCapabilityDefinition;\n binding: AssistantWorkflowToolBindingDefinition;\n};\n\nexport type AssistantWorkflowToolInvocationQueue = {\n status: AssistantWorkflowToolInvocationQueueStatus;\n invocations: AssistantWorkflowToolInvocation[];\n skippedStepIds: string[];\n blockingReasons: string[];\n warnings: string[];\n};\n\nexport type AssistantWorkflowToolInvocationQueueOptions = {\n includeOptional?: boolean;\n allowWhenBlocked?: boolean;\n};\n\nexport type AssistantWorkflowToolInvocationRun = {\n status: AssistantWorkflowExecutionPlanStatus;\n executionPlan: AssistantWorkflowExecutionPlan;\n};\n\nexport function buildAssistantWorkflowToolInvocationQueue(\n workflow: AssistantWorkflowDefinition<string, string, string, string>,\n run: AssistantWorkflowToolInvocationRun,\n options: AssistantWorkflowToolInvocationQueueOptions = {},\n): AssistantWorkflowToolInvocationQueue {\n const includeOptional = options.includeOptional !== false;\n const blocked = run.status === \"blocked\" || run.status === \"needs-clarification\";\n if (blocked && options.allowWhenBlocked !== true) {\n return {\n status: \"blocked\",\n invocations: [],\n skippedStepIds: run.executionPlan.steps.map((step) => step.id),\n blockingReasons: [...run.executionPlan.blockingReasons],\n warnings: [...run.executionPlan.warnings],\n };\n }\n\n const invocations: AssistantWorkflowToolInvocation[] = [];\n const skippedStepIds: string[] = [];\n for (const step of run.executionPlan.steps) {\n if (step.status === \"blocked\" || step.status === \"optional-skipped\") {\n skippedStepIds.push(step.id);\n continue;\n }\n const readyToolNames = includeOptional\n ? step.readyToolNames\n : step.readyToolNames.filter((toolName) => step.requiredToolNames.includes(toolName));\n const resolutions = resolveAssistantWorkflowTools(workflow, readyToolNames).resolutions;\n for (const resolution of resolutions) {\n const invocation = buildInvocation(step.id, step.kind, step.requiredToolNames.includes(resolution.toolName), resolution);\n if (invocation) {\n invocations.push(invocation);\n }\n }\n }\n\n return {\n status:\n invocations.length === 0\n ? \"empty\"\n : run.status === \"partial\"\n ? \"partial\"\n : \"ready\",\n invocations,\n skippedStepIds,\n blockingReasons: [...run.executionPlan.blockingReasons],\n warnings: [...run.executionPlan.warnings],\n };\n}\n\nexport function buildAssistantWorkflowToolInvocationQueueTracePayload(\n queue: AssistantWorkflowToolInvocationQueue,\n): Record<string, unknown> {\n return {\n status: queue.status,\n invocationCount: queue.invocations.length,\n invocations: queue.invocations.map((invocation) => ({\n id: invocation.id,\n stepId: invocation.stepId,\n stepKind: invocation.stepKind,\n toolName: invocation.toolName,\n required: invocation.required,\n provider: invocation.provider,\n effect: invocation.capability.effect,\n outputKinds: invocation.capability.outputKinds,\n bindingProvider: invocation.binding.provider,\n })),\n skippedStepIds: queue.skippedStepIds,\n blockingReasons: queue.blockingReasons,\n warnings: queue.warnings,\n };\n}\n\nfunction buildInvocation(\n stepId: string,\n stepKind: AssistantWorkflowPlanningStepKind,\n required: boolean,\n resolution: AssistantWorkflowToolResolution,\n): AssistantWorkflowToolInvocation | null {\n if (resolution.status !== \"ready\" || !resolution.capability || !resolution.binding || !resolution.provider) {\n return null;\n }\n return {\n id: `${stepId}:${resolution.toolName}`,\n stepId,\n stepKind,\n toolName: resolution.toolName,\n required,\n provider: resolution.provider,\n capability: resolution.capability,\n binding: resolution.binding,\n };\n}\n"]}
1
+ {"version":3,"file":"tool-invocations.js","sourceRoot":"","sources":["../src/tool-invocations.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,6BAA6B,GAE9B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,+CAA+C,EAC/C,iDAAiD,EACjD,+CAA+C,GAGhD,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uCAAuC,GAExC,MAAM,uBAAuB,CAAC;AA0C/B,MAAM,UAAU,yCAAyC,CACvD,QAAqE,EACrE,GAAuC,EACvC,UAAuD,EAAE;IAEzD,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,KAAK,KAAK,CAAC;IAC1D,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,qBAAqB,CAAC;IACjF,IAAI,OAAO,IAAI,OAAO,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACjD,OAAO;YACL,MA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AssistantWorkflowToolCapabilityDefinition,\n AssistantWorkflowToolProvider,\n} from \"./definition.js\";\nimport type { AssistantWorkflowExecutionPlan, AssistantWorkflowExecutionPlanStatus } from \"./execution-plan.js\";\nimport {\n resolveAssistantWorkflowTools,\n type AssistantWorkflowToolResolution,\n} from \"./tool-bindings.js\";\nimport {\n buildAssistantWorkflowExecutionBudgetAssessment,\n buildAssistantWorkflowExecutionBudgetTracePayload,\n formatAssistantWorkflowExecutionBudgetViolation,\n type AssistantWorkflowExecutionBudget,\n type AssistantWorkflowExecutionBudgetAssessment,\n} from \"./execution-budget.js\";\nimport {\n resolveAssistantWorkflowExecutionPolicy,\n type AssistantWorkflowExecutionPolicy,\n} from \"./execution-policy.js\";\n\nexport type AssistantWorkflowToolInvocationQueueStatus =\n | \"ready\"\n | \"partial\"\n | \"blocked\"\n | \"empty\";\n\nexport type AssistantWorkflowToolInvocation = {\n id: string;\n stepId: string;\n stepKind: AssistantWorkflowPlanningStepKind;\n dependsOnStepIds?: string[];\n toolName: string;\n required: boolean;\n provider: AssistantWorkflowToolProvider;\n capability: AssistantWorkflowToolCapabilityDefinition;\n binding: AssistantWorkflowToolBindingDefinition;\n maxAttempts?: number;\n};\n\nexport type AssistantWorkflowToolInvocationQueue = {\n status: AssistantWorkflowToolInvocationQueueStatus;\n invocations: AssistantWorkflowToolInvocation[];\n skippedStepIds: string[];\n blockingReasons: string[];\n warnings: string[];\n executionBudget?: AssistantWorkflowExecutionBudget | null;\n budgetAssessment?: AssistantWorkflowExecutionBudgetAssessment | null;\n executionPolicy?: AssistantWorkflowExecutionPolicy;\n};\n\nexport type AssistantWorkflowToolInvocationQueueOptions = {\n includeOptional?: boolean;\n allowWhenBlocked?: boolean;\n};\n\nexport type AssistantWorkflowToolInvocationRun = {\n status: AssistantWorkflowExecutionPlanStatus;\n executionPlan: AssistantWorkflowExecutionPlan;\n};\n\nexport function buildAssistantWorkflowToolInvocationQueue(\n workflow: AssistantWorkflowDefinition<string, string, string, string>,\n run: AssistantWorkflowToolInvocationRun,\n options: AssistantWorkflowToolInvocationQueueOptions = {},\n): AssistantWorkflowToolInvocationQueue {\n const includeOptional = options.includeOptional !== false;\n const blocked = run.status === \"blocked\" || run.status === \"needs-clarification\";\n if (blocked && options.allowWhenBlocked !== true) {\n return {\n status: \"blocked\",\n invocations: [],\n skippedStepIds: run.executionPlan.steps.map((step) => step.id),\n blockingReasons: [...run.executionPlan.blockingReasons],\n warnings: [...run.executionPlan.warnings],\n executionBudget: run.executionPlan.executionBudget ?? null,\n budgetAssessment: run.executionPlan.budgetAssessment ?? null,\n executionPolicy: run.executionPlan.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy(),\n };\n }\n\n const invocations: AssistantWorkflowToolInvocation[] = [];\n const executionPolicy = run.executionPlan.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy(workflow.executionPolicy);\n const skippedStepIds: string[] = [];\n for (const step of run.executionPlan.steps) {\n if (step.status === \"blocked\" || step.status === \"optional-skipped\") {\n skippedStepIds.push(step.id);\n continue;\n }\n const readyToolNames = includeOptional\n ? step.readyToolNames\n : step.readyToolNames.filter((toolName) => step.requiredToolNames.includes(toolName));\n const resolutions = resolveAssistantWorkflowTools(workflow, readyToolNames).resolutions;\n for (const resolution of resolutions) {\n const invocation = buildInvocation(step.id, step.kind, step.dependsOnStepIds, step.requiredToolNames.includes(resolution.toolName), resolution, executionPolicy);\n if (invocation) {\n invocations.push(invocation);\n }\n }\n }\n\n const budgetAssessment = workflow.executionBudget\n ? buildAssistantWorkflowExecutionBudgetAssessment(workflow.executionBudget, {\n planningStepCount: run.executionPlan.steps.length,\n toolCallCount: invocations.reduce((count, invocation) => count + (invocation.maxAttempts ?? 1), 0),\n })\n : null;\n if (budgetAssessment?.status === \"blocked\") {\n return {\n status: \"blocked\",\n invocations: [],\n skippedStepIds: run.executionPlan.steps.map((step) => step.id),\n blockingReasons: [\n ...run.executionPlan.blockingReasons,\n ...budgetAssessment.violations.map(formatAssistantWorkflowExecutionBudgetViolation),\n ],\n warnings: [...run.executionPlan.warnings],\n executionBudget: { ...budgetAssessment.budget },\n budgetAssessment,\n executionPolicy,\n };\n }\n\n return {\n status:\n invocations.length === 0\n ? \"empty\"\n : run.status === \"partial\"\n ? \"partial\"\n : \"ready\",\n invocations,\n skippedStepIds,\n blockingReasons: [...run.executionPlan.blockingReasons],\n warnings: [...run.executionPlan.warnings],\n executionBudget: workflow.executionBudget ? { ...workflow.executionBudget } : null,\n budgetAssessment,\n executionPolicy,\n };\n}\n\nexport function buildAssistantWorkflowToolInvocationQueueTracePayload(\n queue: AssistantWorkflowToolInvocationQueue,\n): Record<string, unknown> {\n return {\n status: queue.status,\n invocationCount: queue.invocations.length,\n invocations: queue.invocations.map((invocation) => ({\n id: invocation.id,\n stepId: invocation.stepId,\n stepKind: invocation.stepKind,\n dependsOnStepIds: invocation.dependsOnStepIds ?? [],\n toolName: invocation.toolName,\n required: invocation.required,\n provider: invocation.provider,\n effect: invocation.capability.effect,\n outputKinds: invocation.capability.outputKinds,\n bindingProvider: invocation.binding.provider,\n maxAttempts: invocation.maxAttempts ?? 1,\n })),\n skippedStepIds: queue.skippedStepIds,\n blockingReasons: queue.blockingReasons,\n warnings: queue.warnings,\n executionBudget: queue.executionBudget ?? null,\n budgetAssessment: queue.budgetAssessment\n ? buildAssistantWorkflowExecutionBudgetTracePayload(queue.budgetAssessment)\n : null,\n executionPolicy: queue.executionPolicy ?? resolveAssistantWorkflowExecutionPolicy(),\n };\n}\n\nfunction buildInvocation(\n stepId: string,\n stepKind: AssistantWorkflowPlanningStepKind,\n dependsOnStepIds: readonly string[],\n required: boolean,\n resolution: AssistantWorkflowToolResolution,\n executionPolicy: AssistantWorkflowExecutionPolicy,\n): AssistantWorkflowToolInvocation | null {\n if (resolution.status !== \"ready\" || !resolution.capability || !resolution.binding || !resolution.provider) {\n return null;\n }\n return {\n id: `${stepId}:${resolution.toolName}`,\n stepId,\n stepKind,\n dependsOnStepIds: [...dependsOnStepIds],\n toolName: resolution.toolName,\n required,\n provider: resolution.provider,\n capability: resolution.capability,\n binding: resolution.binding,\n maxAttempts: resolution.capability.retryClass === \"never\"\n ? 1\n : executionPolicy.maxAttemptsPerTool,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/assistant-workflow",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "Typed, provider-neutral workflow definitions, policies, execution plans, and trace helpers for assistants.",
5
5
  "author": "Aljosa Vister",
6
6
  "license": "MIT",
@@ -177,6 +177,14 @@
177
177
  "types": "./dist/execution-plan.d.ts",
178
178
  "default": "./dist/execution-plan.js"
179
179
  },
180
+ "./execution-budget": {
181
+ "types": "./dist/execution-budget.d.ts",
182
+ "default": "./dist/execution-budget.js"
183
+ },
184
+ "./execution-policy": {
185
+ "types": "./dist/execution-policy.d.ts",
186
+ "default": "./dist/execution-policy.js"
187
+ },
180
188
  "./hosted-tool-policy": {
181
189
  "types": "./dist/hosted-tool-policy.d.ts",
182
190
  "default": "./dist/hosted-tool-policy.js"
@@ -328,7 +336,8 @@
328
336
  },
329
337
  "files": [
330
338
  "dist",
331
- "README.md"
339
+ "README.md",
340
+ "API_STABILITY.md"
332
341
  ],
333
342
  "devDependencies": {
334
343
  "@types/node": "^22.19.1",