@ai-sdk/workflow 1.0.0-canary.83 → 1.0.0-canary.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/workflow",
3
- "version": "1.0.0-canary.83",
3
+ "version": "1.0.0-canary.85",
4
4
  "description": "WorkflowAgent for building AI agents with AI SDK",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "ajv": "^8.20.0",
30
30
  "@ai-sdk/provider": "4.0.0-canary.18",
31
31
  "@ai-sdk/provider-utils": "5.0.0-canary.46",
32
- "ai": "7.0.0-canary.166"
32
+ "ai": "7.0.0-canary.168"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "22.19.19",
@@ -0,0 +1,85 @@
1
+ import type { LanguageModelV4ToolResultOutput } from '@ai-sdk/provider';
2
+ import type { Tool } from '@ai-sdk/provider-utils';
3
+ import type { ModelMessage } from 'ai';
4
+ import {
5
+ createDefaultDownloadFunction,
6
+ createToolModelOutput,
7
+ downloadAssets,
8
+ mapToolResultOutput,
9
+ type DownloadFunction,
10
+ } from 'ai/internal';
11
+
12
+ /**
13
+ * Converts a single tool result into a provider-level
14
+ * `LanguageModelV4ToolResultOutput`, honoring the tool's optional
15
+ * `toModelOutput` hook.
16
+ *
17
+ * Unlike `generateText`/`streamText`, `WorkflowAgent` assembles the
18
+ * `LanguageModelV4` prompt incrementally — appending one tool result at a time
19
+ * — instead of building AI-level `ModelMessage`s and converting the whole
20
+ * prompt once via `convertToLanguageModelPrompt`. This helper performs the
21
+ * equivalent per-result conversion using the shared `ai/internal` primitives:
22
+ *
23
+ * 1. `createToolModelOutput` — applies `tool.toModelOutput` (or the
24
+ * text/json/error fallback).
25
+ * 2. `downloadAssets` — for `content`-type outputs, downloads any file/image
26
+ * assets so URLs become bytes the provider can consume.
27
+ * 3. `mapToolResultOutput` — maps the AI-level `ToolResultOutput` to the
28
+ * provider-level output and converts legacy file types.
29
+ */
30
+ export async function createLanguageModelToolResultOutput({
31
+ toolCallId,
32
+ toolName,
33
+ input,
34
+ output,
35
+ tool,
36
+ errorMode,
37
+ supportedUrls,
38
+ download = createDefaultDownloadFunction(),
39
+ provider,
40
+ }: {
41
+ toolCallId: string;
42
+ toolName: string;
43
+ input: unknown;
44
+ output: unknown;
45
+ tool: Tool | undefined;
46
+ errorMode: 'none' | 'text' | 'json';
47
+ supportedUrls: Record<string, RegExp[]>;
48
+ download?: DownloadFunction;
49
+ provider?: string;
50
+ }): Promise<LanguageModelV4ToolResultOutput> {
51
+ const modelOutput = await createToolModelOutput({
52
+ toolCallId,
53
+ input,
54
+ output,
55
+ tool,
56
+ errorMode,
57
+ });
58
+
59
+ const downloadedAssets =
60
+ modelOutput.type === 'content'
61
+ ? await downloadAssets(
62
+ [
63
+ {
64
+ role: 'tool',
65
+ content: [
66
+ {
67
+ type: 'tool-result',
68
+ toolCallId,
69
+ toolName,
70
+ output: modelOutput,
71
+ },
72
+ ],
73
+ } satisfies ModelMessage,
74
+ ],
75
+ download,
76
+ supportedUrls,
77
+ )
78
+ : {};
79
+
80
+ return mapToolResultOutput({
81
+ output: modelOutput,
82
+ provider,
83
+ downloadedAssets,
84
+ });
85
+ }