@ai-sdk/workflow 2.0.58 → 2.0.60
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 +27 -0
- package/dist/index.d.ts +61 -43
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +686 -305
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/build-model-step-result.ts +329 -0
- package/src/do-generate-step.ts +212 -0
- package/src/do-stream-step.ts +50 -179
- package/src/index.ts +3 -0
- package/src/{stream-text-iterator.ts → model-call-iterator.ts} +117 -297
- package/src/model-call.ts +196 -0
- package/src/providers/mock-function-wrapper.ts +32 -0
- package/src/test/agent-e2e-workflows.ts +60 -1
- package/src/test/approval-workflows.ts +105 -0
- package/src/test/generation-boundary-model.ts +115 -0
- package/src/test/generation-boundary-workflows.ts +106 -0
- package/src/test/model-call-payload-workflow.ts +132 -0
- package/src/to-model-response-messages.ts +28 -0
- package/src/workflow-agent.ts +521 -206
- package/src/workflow-execution-result.ts +55 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ToolSet, GenerateTextResult } from 'ai';
|
|
2
|
+
import type { WorkflowAgentStreamResult } from './workflow-agent.js';
|
|
3
|
+
|
|
4
|
+
/** Reconstructed workflow data, never the payload of a durable model step. */
|
|
5
|
+
export type WorkflowExecutionData<TOOLS extends ToolSet, OUTPUT> = Omit<
|
|
6
|
+
WorkflowAgentStreamResult<TOOLS, OUTPUT>,
|
|
7
|
+
'error'
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Presence is explicit so even `throw undefined` remains a failure. Stream
|
|
12
|
+
* errors resolve with data, while execution errors reject; generation can
|
|
13
|
+
* interpret the same outcomes without duplicating orchestration.
|
|
14
|
+
*/
|
|
15
|
+
export type WorkflowExecutionOutcome =
|
|
16
|
+
| { status: 'completed' }
|
|
17
|
+
| { status: 'aborted'; rejection?: { value: unknown } }
|
|
18
|
+
| {
|
|
19
|
+
status: 'failed';
|
|
20
|
+
source: 'model-stream' | 'execution';
|
|
21
|
+
error: unknown;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface WorkflowExecutionResult<TOOLS extends ToolSet, OUTPUT> {
|
|
25
|
+
initialResponseMessages?: GenerateTextResult<
|
|
26
|
+
TOOLS,
|
|
27
|
+
any,
|
|
28
|
+
any
|
|
29
|
+
>['responseMessages'];
|
|
30
|
+
data: WorkflowExecutionData<TOOLS, OUTPUT>;
|
|
31
|
+
outcome: WorkflowExecutionOutcome;
|
|
32
|
+
/** Preserved for generate(), while stream() retains its resolved abort contract. */
|
|
33
|
+
abortReason?: { value: unknown };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function resolveWorkflowStreamResult<TOOLS extends ToolSet, OUTPUT>({
|
|
37
|
+
data,
|
|
38
|
+
outcome,
|
|
39
|
+
}: WorkflowExecutionResult<TOOLS, OUTPUT>): WorkflowAgentStreamResult<
|
|
40
|
+
TOOLS,
|
|
41
|
+
OUTPUT
|
|
42
|
+
> {
|
|
43
|
+
if (outcome.status === 'failed') {
|
|
44
|
+
if (outcome.source === 'execution') {
|
|
45
|
+
throw outcome.error;
|
|
46
|
+
}
|
|
47
|
+
return { ...data, error: outcome.error };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (outcome.status === 'aborted' && outcome.rejection != null) {
|
|
51
|
+
throw outcome.rejection.value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return data;
|
|
55
|
+
}
|