ai 7.0.122 → 7.0.124
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 +29 -0
- package/dist/index.d.ts +7598 -7268
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19555 -22545
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2235 -2004
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +3261 -3921
- package/dist/internal/index.js.map +1 -1
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/test/index.d.ts +294 -273
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +325 -469
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/03-prompts.mdx +3 -1
- package/docs/02-foundations/06-provider-options.mdx +1 -1
- package/docs/02-getting-started/06-nodejs.mdx +4 -4
- package/docs/02-getting-started/08-tanstack-start.mdx +1 -1
- package/docs/03-agents/05-configuring-call-options.mdx +1 -1
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +1 -1
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +3 -0
- package/docs/03-ai-sdk-core/17-mcp-apps.mdx +5 -5
- package/docs/03-ai-sdk-core/36-transcription.mdx +36 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +22 -1
- package/docs/03-ai-sdk-core/42-batch.mdx +1 -1
- package/docs/03-ai-sdk-core/60-telemetry.mdx +51 -3
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +24 -0
- package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +12 -12
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +9 -7
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +2 -2
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +7 -9
- package/docs/04-ai-sdk-ui/05-completion.mdx +1 -1
- package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +2 -2
- package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +8 -7
- package/docs/05-ai-sdk-rsc/06-loading-state.mdx +19 -10
- package/docs/05-ai-sdk-rsc/08-error-handling.mdx +2 -0
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +4 -3
- package/docs/06-advanced/02-stopping-streams.mdx +2 -2
- package/docs/06-advanced/04-caching.mdx +9 -5
- package/docs/06-advanced/05-multiple-streamables.mdx +1 -1
- package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +16 -16
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/11-stream-transcribe.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/14-upload-file.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/14-upload-skill.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +1 -4
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +5 -4
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +3 -2
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +7 -0
- package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +7 -0
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +2 -2
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +2 -2
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +1 -1
- package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +4 -5
- package/docs/08-migration-guides/26-migration-guide-5-0.mdx +2 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +4 -4
- package/docs/08-migration-guides/38-migration-guide-3-2.mdx +1 -1
- package/docs/08-migration-guides/39-migration-guide-3-1.mdx +1 -1
- package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +8 -6
- package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +6 -6
- package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +1 -1
- package/package.json +17 -17
- package/src/agent/create-agent-ui-stream-response.ts +3 -0
- package/src/agent/pipe-agent-ui-stream-to-response.ts +3 -0
- package/src/generate-speech/generate-speech.ts +163 -38
- package/src/generate-speech/index.ts +4 -0
- package/src/generate-speech/speech-events.ts +91 -0
- package/src/generate-text/prune-messages.ts +1 -1
- package/src/middleware/extract-reasoning-middleware.ts +27 -11
- package/src/telemetry/create-telemetry-dispatcher.ts +18 -5
- package/src/telemetry/telemetry.ts +38 -6
- package/src/telemetry/tracing-channel.ts +3 -0
- package/src/transcribe/index.ts +6 -0
- package/src/transcribe/stream-transcribe.ts +182 -31
- package/src/transcribe/transcribe.ts +186 -33
- package/src/transcribe/transcription-events.ts +111 -0
- package/src/ui/convert-to-model-messages.ts +18 -6
- package/src/ui-message-stream/create-sse-stream-with-keep-alive.ts +89 -0
- package/src/ui-message-stream/create-ui-message-stream-response.ts +7 -1
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +7 -1
- package/src/ui-message-stream/ui-message-stream-response-init.ts +7 -0
package/dist/test/index.js
CHANGED
|
@@ -1,512 +1,368 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, delay } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { convertArrayToAsyncIterable, convertArrayToReadableStream, convertReadableStreamToArray, mockId } from "@ai-sdk/provider-utils/test";
|
|
3
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
4
|
+
//#region src/util/simulate-readable-stream.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a ReadableStream that emits the provided values with an optional delay between each value.
|
|
7
|
+
*
|
|
8
|
+
* @param options - The configuration options
|
|
9
|
+
* @param options.chunks - Array of values to be emitted by the stream
|
|
10
|
+
* @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
|
11
|
+
* @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
|
12
|
+
* @returns A ReadableStream that emits the provided values
|
|
13
|
+
*/
|
|
14
|
+
function simulateReadableStream$1({ chunks, initialDelayInMs = 0, chunkDelayInMs = 0, _internal }) {
|
|
15
|
+
const delay$1 = _internal?.delay ?? delay;
|
|
16
|
+
let index = 0;
|
|
17
|
+
return new ReadableStream({ async pull(controller) {
|
|
18
|
+
if (index < chunks.length) {
|
|
19
|
+
await delay$1(index === 0 ? initialDelayInMs : chunkDelayInMs);
|
|
20
|
+
controller.enqueue(chunks[index++]);
|
|
21
|
+
} else controller.close();
|
|
22
|
+
} });
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
convertArrayToAsyncIterable,
|
|
26
|
-
convertArrayToReadableStream,
|
|
27
|
-
convertReadableStreamToArray,
|
|
28
|
-
mockId
|
|
29
|
-
} from "@ai-sdk/provider-utils/test";
|
|
30
|
-
|
|
31
|
-
// src/test/not-implemented.ts
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/test/not-implemented.ts
|
|
32
26
|
function notImplemented() {
|
|
33
|
-
|
|
27
|
+
throw new Error("Not implemented");
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/test/mock-embedding-model-v3.ts
|
|
37
31
|
var MockEmbeddingModelV3 = class {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.doEmbedCalls.push(options);
|
|
53
|
-
if (typeof doEmbed === "function") {
|
|
54
|
-
return doEmbed(options);
|
|
55
|
-
} else if (Array.isArray(doEmbed)) {
|
|
56
|
-
return doEmbed[this.doEmbedCalls.length - 1];
|
|
57
|
-
} else {
|
|
58
|
-
return doEmbed;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
32
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", maxEmbeddingsPerCall = 1, supportsParallelCalls = false, doEmbed = notImplemented } = {}) {
|
|
33
|
+
this.specificationVersion = "v3";
|
|
34
|
+
this.doEmbedCalls = [];
|
|
35
|
+
this.provider = provider;
|
|
36
|
+
this.modelId = modelId;
|
|
37
|
+
this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? void 0;
|
|
38
|
+
this.supportsParallelCalls = supportsParallelCalls;
|
|
39
|
+
this.doEmbed = async (options) => {
|
|
40
|
+
this.doEmbedCalls.push(options);
|
|
41
|
+
if (typeof doEmbed === "function") return doEmbed(options);
|
|
42
|
+
else if (Array.isArray(doEmbed)) return doEmbed[this.doEmbedCalls.length - 1];
|
|
43
|
+
else return doEmbed;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
62
46
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL } from "@ai-sdk/provider-utils";
|
|
66
|
-
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/test/mock-embedding-model-v4.ts
|
|
67
49
|
var MockEmbeddingModelV4 = class {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.doEmbed = async (options) => {
|
|
84
|
-
this.doEmbedCalls.push(options);
|
|
85
|
-
if (typeof doEmbed === "function") {
|
|
86
|
-
return doEmbed(options);
|
|
87
|
-
} else if (Array.isArray(doEmbed)) {
|
|
88
|
-
return doEmbed[this.doEmbedCalls.length - 1];
|
|
89
|
-
} else {
|
|
90
|
-
return doEmbed;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
50
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", maxEmbeddingsPerCall = 1, maxInputBytesPerCall, supportsParallelCalls = false, doEmbed = notImplemented } = {}) {
|
|
51
|
+
this.specificationVersion = "v4";
|
|
52
|
+
this.doEmbedCalls = [];
|
|
53
|
+
this.provider = provider;
|
|
54
|
+
this.modelId = modelId;
|
|
55
|
+
this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? void 0;
|
|
56
|
+
this[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL] = maxInputBytesPerCall;
|
|
57
|
+
this.supportsParallelCalls = supportsParallelCalls;
|
|
58
|
+
this.doEmbed = async (options) => {
|
|
59
|
+
this.doEmbedCalls.push(options);
|
|
60
|
+
if (typeof doEmbed === "function") return doEmbed(options);
|
|
61
|
+
else if (Array.isArray(doEmbed)) return doEmbed[this.doEmbedCalls.length - 1];
|
|
62
|
+
else return doEmbed;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
94
65
|
};
|
|
95
|
-
|
|
96
|
-
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/test/evaluation-mock-model-v4.ts
|
|
97
68
|
var EvaluationMockModelV4 = class {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
69
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", supportedQuestionTypes = [
|
|
70
|
+
"choice",
|
|
71
|
+
"score",
|
|
72
|
+
"boolean"
|
|
73
|
+
], doEvaluate = notImplemented } = {}) {
|
|
74
|
+
this.specificationVersion = "v4";
|
|
75
|
+
this.provider = provider;
|
|
76
|
+
this.modelId = modelId;
|
|
77
|
+
this.supportedQuestionTypes = supportedQuestionTypes;
|
|
78
|
+
this.doEvaluate = doEvaluate;
|
|
79
|
+
}
|
|
110
80
|
};
|
|
111
|
-
|
|
112
|
-
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/test/mock-image-model-v3.ts
|
|
113
83
|
var MockImageModelV3 = class {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.provider = provider;
|
|
122
|
-
this.modelId = modelId;
|
|
123
|
-
this.maxImagesPerCall = maxImagesPerCall;
|
|
124
|
-
this.doGenerate = doGenerate;
|
|
125
|
-
}
|
|
84
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", maxImagesPerCall = 1, doGenerate = notImplemented } = {}) {
|
|
85
|
+
this.specificationVersion = "v3";
|
|
86
|
+
this.provider = provider;
|
|
87
|
+
this.modelId = modelId;
|
|
88
|
+
this.maxImagesPerCall = maxImagesPerCall;
|
|
89
|
+
this.doGenerate = doGenerate;
|
|
90
|
+
}
|
|
126
91
|
};
|
|
127
|
-
|
|
128
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/test/mock-image-model-v4.ts
|
|
129
94
|
var MockImageModelV4 = class {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.provider = provider;
|
|
140
|
-
this.modelId = modelId;
|
|
141
|
-
this.maxImagesPerCall = maxImagesPerCall;
|
|
142
|
-
this.supportsFileInputs = supportsFileInputs;
|
|
143
|
-
this.supportsMaskInputs = supportsMaskInputs;
|
|
144
|
-
this.doGenerate = doGenerate;
|
|
145
|
-
}
|
|
95
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", maxImagesPerCall = 1, supportsFileInputs, supportsMaskInputs, doGenerate = notImplemented } = {}) {
|
|
96
|
+
this.specificationVersion = "v4";
|
|
97
|
+
this.provider = provider;
|
|
98
|
+
this.modelId = modelId;
|
|
99
|
+
this.maxImagesPerCall = maxImagesPerCall;
|
|
100
|
+
this.supportsFileInputs = supportsFileInputs;
|
|
101
|
+
this.supportsMaskInputs = supportsMaskInputs;
|
|
102
|
+
this.doGenerate = doGenerate;
|
|
103
|
+
}
|
|
146
104
|
};
|
|
147
|
-
|
|
148
|
-
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/test/mock-language-model-v3.ts
|
|
149
107
|
var MockLanguageModelV3 = class {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.doStreamCalls.push(options);
|
|
174
|
-
if (typeof doStream === "function") {
|
|
175
|
-
return await doStream(options);
|
|
176
|
-
} else if (Array.isArray(doStream)) {
|
|
177
|
-
return doStream[this.doStreamCalls.length - 1];
|
|
178
|
-
} else {
|
|
179
|
-
return doStream;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
this._supportedUrls = typeof supportedUrls === "function" ? supportedUrls : async () => await supportedUrls;
|
|
183
|
-
}
|
|
184
|
-
get supportedUrls() {
|
|
185
|
-
return this._supportedUrls();
|
|
186
|
-
}
|
|
108
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", supportedUrls = {}, doGenerate = notImplemented, doStream = notImplemented } = {}) {
|
|
109
|
+
this.specificationVersion = "v3";
|
|
110
|
+
this.doGenerateCalls = [];
|
|
111
|
+
this.doStreamCalls = [];
|
|
112
|
+
this.provider = provider;
|
|
113
|
+
this.modelId = modelId;
|
|
114
|
+
this.doGenerate = async (options) => {
|
|
115
|
+
this.doGenerateCalls.push(options);
|
|
116
|
+
if (typeof doGenerate === "function") return await doGenerate(options);
|
|
117
|
+
else if (Array.isArray(doGenerate)) return doGenerate[this.doGenerateCalls.length - 1];
|
|
118
|
+
else return doGenerate;
|
|
119
|
+
};
|
|
120
|
+
this.doStream = async (options) => {
|
|
121
|
+
this.doStreamCalls.push(options);
|
|
122
|
+
if (typeof doStream === "function") return await doStream(options);
|
|
123
|
+
else if (Array.isArray(doStream)) return doStream[this.doStreamCalls.length - 1];
|
|
124
|
+
else return doStream;
|
|
125
|
+
};
|
|
126
|
+
this._supportedUrls = typeof supportedUrls === "function" ? supportedUrls : async () => await supportedUrls;
|
|
127
|
+
}
|
|
128
|
+
get supportedUrls() {
|
|
129
|
+
return this._supportedUrls();
|
|
130
|
+
}
|
|
187
131
|
};
|
|
188
|
-
|
|
189
|
-
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/test/mock-language-model-v4.ts
|
|
190
134
|
var MockLanguageModelV4 = class {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
this.doStreamCalls.push(options);
|
|
215
|
-
if (typeof doStream === "function") {
|
|
216
|
-
return await doStream(options);
|
|
217
|
-
} else if (Array.isArray(doStream)) {
|
|
218
|
-
return doStream[this.doStreamCalls.length - 1];
|
|
219
|
-
} else {
|
|
220
|
-
return doStream;
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
this._supportedUrls = typeof supportedUrls === "function" ? supportedUrls : async () => await supportedUrls;
|
|
224
|
-
}
|
|
225
|
-
get supportedUrls() {
|
|
226
|
-
return this._supportedUrls();
|
|
227
|
-
}
|
|
135
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", supportedUrls = {}, doGenerate = notImplemented, doStream = notImplemented } = {}) {
|
|
136
|
+
this.specificationVersion = "v4";
|
|
137
|
+
this.doGenerateCalls = [];
|
|
138
|
+
this.doStreamCalls = [];
|
|
139
|
+
this.provider = provider;
|
|
140
|
+
this.modelId = modelId;
|
|
141
|
+
this.doGenerate = async (options) => {
|
|
142
|
+
this.doGenerateCalls.push(options);
|
|
143
|
+
if (typeof doGenerate === "function") return await doGenerate(options);
|
|
144
|
+
else if (Array.isArray(doGenerate)) return doGenerate[this.doGenerateCalls.length - 1];
|
|
145
|
+
else return doGenerate;
|
|
146
|
+
};
|
|
147
|
+
this.doStream = async (options) => {
|
|
148
|
+
this.doStreamCalls.push(options);
|
|
149
|
+
if (typeof doStream === "function") return await doStream(options);
|
|
150
|
+
else if (Array.isArray(doStream)) return doStream[this.doStreamCalls.length - 1];
|
|
151
|
+
else return doStream;
|
|
152
|
+
};
|
|
153
|
+
this._supportedUrls = typeof supportedUrls === "function" ? supportedUrls : async () => await supportedUrls;
|
|
154
|
+
}
|
|
155
|
+
get supportedUrls() {
|
|
156
|
+
return this._supportedUrls();
|
|
157
|
+
}
|
|
228
158
|
};
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
import {
|
|
232
|
-
NoSuchModelError
|
|
233
|
-
} from "@ai-sdk/provider";
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/test/mock-provider-v3.ts
|
|
234
161
|
var MockProviderV3 = class {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
this.rerankingModel = (modelId) => {
|
|
281
|
-
if (!rerankingModels?.[modelId]) {
|
|
282
|
-
throw new NoSuchModelError({ modelId, modelType: "rerankingModel" });
|
|
283
|
-
}
|
|
284
|
-
return rerankingModels[modelId];
|
|
285
|
-
};
|
|
286
|
-
}
|
|
162
|
+
constructor({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels } = {}) {
|
|
163
|
+
this.specificationVersion = "v3";
|
|
164
|
+
this.languageModel = (modelId) => {
|
|
165
|
+
if (!languageModels?.[modelId]) throw new NoSuchModelError({
|
|
166
|
+
modelId,
|
|
167
|
+
modelType: "languageModel"
|
|
168
|
+
});
|
|
169
|
+
return languageModels[modelId];
|
|
170
|
+
};
|
|
171
|
+
this.embeddingModel = (modelId) => {
|
|
172
|
+
if (!embeddingModels?.[modelId]) throw new NoSuchModelError({
|
|
173
|
+
modelId,
|
|
174
|
+
modelType: "embeddingModel"
|
|
175
|
+
});
|
|
176
|
+
return embeddingModels[modelId];
|
|
177
|
+
};
|
|
178
|
+
this.imageModel = (modelId) => {
|
|
179
|
+
if (!imageModels?.[modelId]) throw new NoSuchModelError({
|
|
180
|
+
modelId,
|
|
181
|
+
modelType: "imageModel"
|
|
182
|
+
});
|
|
183
|
+
return imageModels[modelId];
|
|
184
|
+
};
|
|
185
|
+
this.transcriptionModel = (modelId) => {
|
|
186
|
+
if (!transcriptionModels?.[modelId]) throw new NoSuchModelError({
|
|
187
|
+
modelId,
|
|
188
|
+
modelType: "transcriptionModel"
|
|
189
|
+
});
|
|
190
|
+
return transcriptionModels[modelId];
|
|
191
|
+
};
|
|
192
|
+
this.speechModel = (modelId) => {
|
|
193
|
+
if (!speechModels?.[modelId]) throw new NoSuchModelError({
|
|
194
|
+
modelId,
|
|
195
|
+
modelType: "speechModel"
|
|
196
|
+
});
|
|
197
|
+
return speechModels[modelId];
|
|
198
|
+
};
|
|
199
|
+
this.rerankingModel = (modelId) => {
|
|
200
|
+
if (!rerankingModels?.[modelId]) throw new NoSuchModelError({
|
|
201
|
+
modelId,
|
|
202
|
+
modelType: "rerankingModel"
|
|
203
|
+
});
|
|
204
|
+
return rerankingModels[modelId];
|
|
205
|
+
};
|
|
206
|
+
}
|
|
287
207
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
import {
|
|
291
|
-
NoSuchModelError as NoSuchModelError2
|
|
292
|
-
} from "@ai-sdk/provider";
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/test/mock-provider-v4.ts
|
|
293
210
|
var MockProviderV4 = class {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
this.rerankingModel = (modelId) => {
|
|
340
|
-
if (!rerankingModels?.[modelId]) {
|
|
341
|
-
throw new NoSuchModelError2({ modelId, modelType: "rerankingModel" });
|
|
342
|
-
}
|
|
343
|
-
return rerankingModels[modelId];
|
|
344
|
-
};
|
|
345
|
-
}
|
|
211
|
+
constructor({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels } = {}) {
|
|
212
|
+
this.specificationVersion = "v4";
|
|
213
|
+
this.languageModel = (modelId) => {
|
|
214
|
+
if (!languageModels?.[modelId]) throw new NoSuchModelError({
|
|
215
|
+
modelId,
|
|
216
|
+
modelType: "languageModel"
|
|
217
|
+
});
|
|
218
|
+
return languageModels[modelId];
|
|
219
|
+
};
|
|
220
|
+
this.embeddingModel = (modelId) => {
|
|
221
|
+
if (!embeddingModels?.[modelId]) throw new NoSuchModelError({
|
|
222
|
+
modelId,
|
|
223
|
+
modelType: "embeddingModel"
|
|
224
|
+
});
|
|
225
|
+
return embeddingModels[modelId];
|
|
226
|
+
};
|
|
227
|
+
this.imageModel = (modelId) => {
|
|
228
|
+
if (!imageModels?.[modelId]) throw new NoSuchModelError({
|
|
229
|
+
modelId,
|
|
230
|
+
modelType: "imageModel"
|
|
231
|
+
});
|
|
232
|
+
return imageModels[modelId];
|
|
233
|
+
};
|
|
234
|
+
this.transcriptionModel = (modelId) => {
|
|
235
|
+
if (!transcriptionModels?.[modelId]) throw new NoSuchModelError({
|
|
236
|
+
modelId,
|
|
237
|
+
modelType: "transcriptionModel"
|
|
238
|
+
});
|
|
239
|
+
return transcriptionModels[modelId];
|
|
240
|
+
};
|
|
241
|
+
this.speechModel = (modelId) => {
|
|
242
|
+
if (!speechModels?.[modelId]) throw new NoSuchModelError({
|
|
243
|
+
modelId,
|
|
244
|
+
modelType: "speechModel"
|
|
245
|
+
});
|
|
246
|
+
return speechModels[modelId];
|
|
247
|
+
};
|
|
248
|
+
this.rerankingModel = (modelId) => {
|
|
249
|
+
if (!rerankingModels?.[modelId]) throw new NoSuchModelError({
|
|
250
|
+
modelId,
|
|
251
|
+
modelType: "rerankingModel"
|
|
252
|
+
});
|
|
253
|
+
return rerankingModels[modelId];
|
|
254
|
+
};
|
|
255
|
+
}
|
|
346
256
|
};
|
|
347
|
-
|
|
348
|
-
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/test/mock-speech-model-v3.ts
|
|
349
259
|
var MockSpeechModelV3 = class {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.provider = provider;
|
|
357
|
-
this.modelId = modelId;
|
|
358
|
-
this.doGenerate = doGenerate;
|
|
359
|
-
}
|
|
260
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented } = {}) {
|
|
261
|
+
this.specificationVersion = "v3";
|
|
262
|
+
this.provider = provider;
|
|
263
|
+
this.modelId = modelId;
|
|
264
|
+
this.doGenerate = doGenerate;
|
|
265
|
+
}
|
|
360
266
|
};
|
|
361
|
-
|
|
362
|
-
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/test/mock-speech-model-v4.ts
|
|
363
269
|
var MockSpeechModelV4 = class {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
this.provider = provider;
|
|
371
|
-
this.modelId = modelId;
|
|
372
|
-
this.doGenerate = doGenerate;
|
|
373
|
-
}
|
|
270
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented } = {}) {
|
|
271
|
+
this.specificationVersion = "v4";
|
|
272
|
+
this.provider = provider;
|
|
273
|
+
this.modelId = modelId;
|
|
274
|
+
this.doGenerate = doGenerate;
|
|
275
|
+
}
|
|
374
276
|
};
|
|
375
|
-
|
|
376
|
-
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/test/mock-speech-translation-model-v4.ts
|
|
377
279
|
var MockSpeechTranslationModelV4 = class {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
this.provider = provider;
|
|
385
|
-
this.modelId = modelId;
|
|
386
|
-
this.doStream = doStream;
|
|
387
|
-
}
|
|
280
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", doStream = notImplemented } = {}) {
|
|
281
|
+
this.specificationVersion = "v4";
|
|
282
|
+
this.provider = provider;
|
|
283
|
+
this.modelId = modelId;
|
|
284
|
+
this.doStream = doStream;
|
|
285
|
+
}
|
|
388
286
|
};
|
|
389
|
-
|
|
390
|
-
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/test/mock-transcription-model-v3.ts
|
|
391
289
|
var MockTranscriptionModelV3 = class {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
this.provider = provider;
|
|
399
|
-
this.modelId = modelId;
|
|
400
|
-
this.doGenerate = doGenerate;
|
|
401
|
-
}
|
|
290
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented } = {}) {
|
|
291
|
+
this.specificationVersion = "v3";
|
|
292
|
+
this.provider = provider;
|
|
293
|
+
this.modelId = modelId;
|
|
294
|
+
this.doGenerate = doGenerate;
|
|
295
|
+
}
|
|
402
296
|
};
|
|
403
|
-
|
|
404
|
-
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/test/mock-transcription-model-v4.ts
|
|
405
299
|
var MockTranscriptionModelV4 = class {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
this.provider = provider;
|
|
414
|
-
this.modelId = modelId;
|
|
415
|
-
this.doGenerate = doGenerate;
|
|
416
|
-
this.doStream = doStream;
|
|
417
|
-
}
|
|
300
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented, doStream } = {}) {
|
|
301
|
+
this.specificationVersion = "v4";
|
|
302
|
+
this.provider = provider;
|
|
303
|
+
this.modelId = modelId;
|
|
304
|
+
this.doGenerate = doGenerate;
|
|
305
|
+
this.doStream = doStream;
|
|
306
|
+
}
|
|
418
307
|
};
|
|
419
|
-
|
|
420
|
-
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/test/mock-reranking-model-v3.ts
|
|
421
310
|
var MockRerankingModelV3 = class {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
this.provider = provider;
|
|
429
|
-
this.modelId = modelId;
|
|
430
|
-
this.doRerank = doRerank;
|
|
431
|
-
}
|
|
311
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", doRerank = notImplemented } = {}) {
|
|
312
|
+
this.specificationVersion = "v3";
|
|
313
|
+
this.provider = provider;
|
|
314
|
+
this.modelId = modelId;
|
|
315
|
+
this.doRerank = doRerank;
|
|
316
|
+
}
|
|
432
317
|
};
|
|
433
|
-
|
|
434
|
-
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/test/mock-reranking-model-v4.ts
|
|
435
320
|
var MockRerankingModelV4 = class {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
this.provider = provider;
|
|
443
|
-
this.modelId = modelId;
|
|
444
|
-
this.doRerank = doRerank;
|
|
445
|
-
}
|
|
321
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", doRerank = notImplemented } = {}) {
|
|
322
|
+
this.specificationVersion = "v4";
|
|
323
|
+
this.provider = provider;
|
|
324
|
+
this.modelId = modelId;
|
|
325
|
+
this.doRerank = doRerank;
|
|
326
|
+
}
|
|
446
327
|
};
|
|
447
|
-
|
|
448
|
-
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/test/mock-video-model-v3.ts
|
|
449
330
|
var MockVideoModelV3 = class {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
this.provider = provider;
|
|
458
|
-
this.modelId = modelId;
|
|
459
|
-
this.maxVideosPerCall = maxVideosPerCall;
|
|
460
|
-
this.doGenerate = doGenerate;
|
|
461
|
-
}
|
|
331
|
+
constructor({ provider = "mock-provider", modelId = "mock-model-id", maxVideosPerCall = 1, doGenerate = notImplemented } = {}) {
|
|
332
|
+
this.specificationVersion = "v3";
|
|
333
|
+
this.provider = provider;
|
|
334
|
+
this.modelId = modelId;
|
|
335
|
+
this.maxVideosPerCall = maxVideosPerCall;
|
|
336
|
+
this.doGenerate = doGenerate;
|
|
337
|
+
}
|
|
462
338
|
};
|
|
463
|
-
|
|
464
|
-
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/test/mock-video-model-v4.ts
|
|
465
341
|
var MockVideoModelV4 = class {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
342
|
+
constructor(options = {}) {
|
|
343
|
+
this.specificationVersion = "v4";
|
|
344
|
+
this.provider = options.provider ?? "mock-provider";
|
|
345
|
+
this.modelId = options.modelId ?? "mock-model-id";
|
|
346
|
+
this.maxVideosPerCall = options.maxVideosPerCall ?? 1;
|
|
347
|
+
this.doGenerate = "doGenerate" in options ? options.doGenerate : notImplemented;
|
|
348
|
+
this.handleWebhookOption = options.handleWebhookOption;
|
|
349
|
+
this.doStart = options.doStart;
|
|
350
|
+
this.doStatus = options.doStatus;
|
|
351
|
+
}
|
|
476
352
|
};
|
|
477
|
-
|
|
478
|
-
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/test/mock-values.ts
|
|
479
355
|
function mockValues(...values) {
|
|
480
|
-
|
|
481
|
-
|
|
356
|
+
let counter = 0;
|
|
357
|
+
return () => values[counter++] ?? values[values.length - 1];
|
|
482
358
|
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region test/index.ts
|
|
361
|
+
/**
|
|
362
|
+
* @deprecated Use `simulateReadableStream` from `ai` instead.
|
|
363
|
+
*/
|
|
364
|
+
const simulateReadableStream = simulateReadableStream$1;
|
|
365
|
+
//#endregion
|
|
366
|
+
export { EvaluationMockModelV4 as Experimental_EvaluationMockModelV4, MockSpeechTranslationModelV4 as Experimental_MockSpeechTranslationModelV4, MockEmbeddingModelV3, MockEmbeddingModelV4, MockImageModelV3, MockImageModelV4, MockLanguageModelV3, MockLanguageModelV4, MockProviderV3, MockProviderV4, MockRerankingModelV3, MockRerankingModelV4, MockSpeechModelV3, MockSpeechModelV4, MockTranscriptionModelV3, MockTranscriptionModelV4, MockVideoModelV3, MockVideoModelV4, convertArrayToAsyncIterable, convertArrayToReadableStream, convertReadableStreamToArray, mockId, mockValues, simulateReadableStream };
|
|
483
367
|
|
|
484
|
-
// test/index.ts
|
|
485
|
-
var simulateReadableStream2 = simulateReadableStream;
|
|
486
|
-
export {
|
|
487
|
-
EvaluationMockModelV4 as Experimental_EvaluationMockModelV4,
|
|
488
|
-
MockSpeechTranslationModelV4 as Experimental_MockSpeechTranslationModelV4,
|
|
489
|
-
MockEmbeddingModelV3,
|
|
490
|
-
MockEmbeddingModelV4,
|
|
491
|
-
MockImageModelV3,
|
|
492
|
-
MockImageModelV4,
|
|
493
|
-
MockLanguageModelV3,
|
|
494
|
-
MockLanguageModelV4,
|
|
495
|
-
MockProviderV3,
|
|
496
|
-
MockProviderV4,
|
|
497
|
-
MockRerankingModelV3,
|
|
498
|
-
MockRerankingModelV4,
|
|
499
|
-
MockSpeechModelV3,
|
|
500
|
-
MockSpeechModelV4,
|
|
501
|
-
MockTranscriptionModelV3,
|
|
502
|
-
MockTranscriptionModelV4,
|
|
503
|
-
MockVideoModelV3,
|
|
504
|
-
MockVideoModelV4,
|
|
505
|
-
convertArrayToAsyncIterable,
|
|
506
|
-
convertArrayToReadableStream,
|
|
507
|
-
convertReadableStreamToArray,
|
|
508
|
-
mockId,
|
|
509
|
-
mockValues,
|
|
510
|
-
simulateReadableStream2 as simulateReadableStream
|
|
511
|
-
};
|
|
512
368
|
//# sourceMappingURL=index.js.map
|