ai 5.0.0-canary.1 → 5.0.0-canary.3
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 +16 -0
- package/dist/index.d.mts +10 -5
- package/dist/index.d.ts +10 -5
- package/dist/index.js +74 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/rsc/dist/rsc-server.mjs +21 -24
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 5.0.0-canary.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [c57e248]
|
8
|
+
- Updated dependencies [33f4a6a]
|
9
|
+
- @ai-sdk/provider@2.0.0-canary.1
|
10
|
+
- @ai-sdk/provider-utils@3.0.0-canary.2
|
11
|
+
- @ai-sdk/ui-utils@2.0.0-canary.2
|
12
|
+
|
13
|
+
## 5.0.0-canary.2
|
14
|
+
|
15
|
+
### Patch Changes
|
16
|
+
|
17
|
+
- bd398e4: fix (core): improve error handling in streamText's consumeStream method
|
18
|
+
|
3
19
|
## 5.0.0-canary.1
|
4
20
|
|
5
21
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
@@ -2,7 +2,7 @@ import { IDGenerator } from '@ai-sdk/provider-utils';
|
|
2
2
|
export { CoreToolCall, CoreToolResult, IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
|
3
3
|
import { DataStreamString, Message, Schema, DeepPartial, JSONValue as JSONValue$1 } from '@ai-sdk/ui-utils';
|
4
4
|
export { Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UIMessage, formatDataStreamPart, jsonSchema, parseDataStreamPart, processDataStream, processTextStream, zodSchema } from '@ai-sdk/ui-utils';
|
5
|
-
import { LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2LogProbs, LanguageModelV2CallWarning, LanguageModelV2Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV2ProviderMetadata, LanguageModelV2CallOptions, AISDKError, LanguageModelV2FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
5
|
+
import { LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2LogProbs, LanguageModelV2CallWarning, LanguageModelV2Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV2ProviderMetadata, LanguageModelV2CallOptions, AISDKError, LanguageModelV2FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2ProviderOptions, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
6
6
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Prompt, LanguageModelV2StreamPart, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
7
7
|
import { ServerResponse } from 'node:http';
|
8
8
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
@@ -2539,6 +2539,9 @@ type DataStreamOptions = {
|
|
2539
2539
|
*/
|
2540
2540
|
experimental_sendStart?: boolean;
|
2541
2541
|
};
|
2542
|
+
type ConsumeStreamOptions = {
|
2543
|
+
onError?: (error: unknown) => void;
|
2544
|
+
};
|
2542
2545
|
/**
|
2543
2546
|
A result object for accessing different stream types and additional information.
|
2544
2547
|
*/
|
@@ -2659,8 +2662,10 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
2659
2662
|
This is useful to force the stream to finish.
|
2660
2663
|
It effectively removes the backpressure and allows the stream to finish,
|
2661
2664
|
triggering the `onFinish` callback and the promise resolution.
|
2665
|
+
|
2666
|
+
If an error occurs, it is passed to the optional `onError` callback.
|
2662
2667
|
*/
|
2663
|
-
consumeStream(): Promise<void>;
|
2668
|
+
consumeStream(options?: ConsumeStreamOptions): Promise<void>;
|
2664
2669
|
/**
|
2665
2670
|
Converts the result to a data stream.
|
2666
2671
|
|
@@ -3792,7 +3797,7 @@ Callback that is called when the LLM response and the final object validation ar
|
|
3792
3797
|
*/
|
3793
3798
|
declare function defaultSettingsMiddleware({ settings, }: {
|
3794
3799
|
settings: Partial<LanguageModelV2CallOptions & {
|
3795
|
-
|
3800
|
+
providerOptions?: LanguageModelV2ProviderOptions;
|
3796
3801
|
}>;
|
3797
3802
|
}): LanguageModelV2Middleware;
|
3798
3803
|
|
@@ -4249,7 +4254,7 @@ The following streams are supported:
|
|
4249
4254
|
- `LangChainAIMessageChunk` streams (LangChain `model.stream` output)
|
4250
4255
|
- `string` streams (LangChain `StringOutputParser` output)
|
4251
4256
|
*/
|
4252
|
-
declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array
|
4257
|
+
declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
4253
4258
|
declare function toDataStreamResponse$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, options?: {
|
4254
4259
|
init?: ResponseInit;
|
4255
4260
|
data?: StreamData;
|
@@ -4271,7 +4276,7 @@ declare namespace langchainAdapter {
|
|
4271
4276
|
type EngineResponse = {
|
4272
4277
|
delta: string;
|
4273
4278
|
};
|
4274
|
-
declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array
|
4279
|
+
declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
4275
4280
|
declare function toDataStreamResponse(stream: AsyncIterable<EngineResponse>, options?: {
|
4276
4281
|
init?: ResponseInit;
|
4277
4282
|
data?: StreamData;
|
package/dist/index.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { IDGenerator } from '@ai-sdk/provider-utils';
|
|
2
2
|
export { CoreToolCall, CoreToolResult, IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
|
3
3
|
import { DataStreamString, Message, Schema, DeepPartial, JSONValue as JSONValue$1 } from '@ai-sdk/ui-utils';
|
4
4
|
export { Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UIMessage, formatDataStreamPart, jsonSchema, parseDataStreamPart, processDataStream, processTextStream, zodSchema } from '@ai-sdk/ui-utils';
|
5
|
-
import { LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2LogProbs, LanguageModelV2CallWarning, LanguageModelV2Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV2ProviderMetadata, LanguageModelV2CallOptions, AISDKError, LanguageModelV2FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
5
|
+
import { LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2LogProbs, LanguageModelV2CallWarning, LanguageModelV2Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV2ProviderMetadata, LanguageModelV2CallOptions, AISDKError, LanguageModelV2FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2ProviderOptions, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
6
6
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Prompt, LanguageModelV2StreamPart, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
7
7
|
import { ServerResponse } from 'node:http';
|
8
8
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
@@ -2539,6 +2539,9 @@ type DataStreamOptions = {
|
|
2539
2539
|
*/
|
2540
2540
|
experimental_sendStart?: boolean;
|
2541
2541
|
};
|
2542
|
+
type ConsumeStreamOptions = {
|
2543
|
+
onError?: (error: unknown) => void;
|
2544
|
+
};
|
2542
2545
|
/**
|
2543
2546
|
A result object for accessing different stream types and additional information.
|
2544
2547
|
*/
|
@@ -2659,8 +2662,10 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
2659
2662
|
This is useful to force the stream to finish.
|
2660
2663
|
It effectively removes the backpressure and allows the stream to finish,
|
2661
2664
|
triggering the `onFinish` callback and the promise resolution.
|
2665
|
+
|
2666
|
+
If an error occurs, it is passed to the optional `onError` callback.
|
2662
2667
|
*/
|
2663
|
-
consumeStream(): Promise<void>;
|
2668
|
+
consumeStream(options?: ConsumeStreamOptions): Promise<void>;
|
2664
2669
|
/**
|
2665
2670
|
Converts the result to a data stream.
|
2666
2671
|
|
@@ -3792,7 +3797,7 @@ Callback that is called when the LLM response and the final object validation ar
|
|
3792
3797
|
*/
|
3793
3798
|
declare function defaultSettingsMiddleware({ settings, }: {
|
3794
3799
|
settings: Partial<LanguageModelV2CallOptions & {
|
3795
|
-
|
3800
|
+
providerOptions?: LanguageModelV2ProviderOptions;
|
3796
3801
|
}>;
|
3797
3802
|
}): LanguageModelV2Middleware;
|
3798
3803
|
|
@@ -4249,7 +4254,7 @@ The following streams are supported:
|
|
4249
4254
|
- `LangChainAIMessageChunk` streams (LangChain `model.stream` output)
|
4250
4255
|
- `string` streams (LangChain `StringOutputParser` output)
|
4251
4256
|
*/
|
4252
|
-
declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array
|
4257
|
+
declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
4253
4258
|
declare function toDataStreamResponse$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, options?: {
|
4254
4259
|
init?: ResponseInit;
|
4255
4260
|
data?: StreamData;
|
@@ -4271,7 +4276,7 @@ declare namespace langchainAdapter {
|
|
4271
4276
|
type EngineResponse = {
|
4272
4277
|
delta: string;
|
4273
4278
|
};
|
4274
|
-
declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array
|
4279
|
+
declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
4275
4280
|
declare function toDataStreamResponse(stream: AsyncIterable<EngineResponse>, options?: {
|
4276
4281
|
init?: ResponseInit;
|
4277
4282
|
data?: StreamData;
|
package/dist/index.js
CHANGED
@@ -1321,7 +1321,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1321
1321
|
return {
|
1322
1322
|
role: "system",
|
1323
1323
|
content: message.content,
|
1324
|
-
|
1324
|
+
providerOptions: (_a17 = message.providerOptions) != null ? _a17 : message.experimental_providerMetadata
|
1325
1325
|
};
|
1326
1326
|
}
|
1327
1327
|
case "user": {
|
@@ -1329,13 +1329,13 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1329
1329
|
return {
|
1330
1330
|
role: "user",
|
1331
1331
|
content: [{ type: "text", text: message.content }],
|
1332
|
-
|
1332
|
+
providerOptions: (_b = message.providerOptions) != null ? _b : message.experimental_providerMetadata
|
1333
1333
|
};
|
1334
1334
|
}
|
1335
1335
|
return {
|
1336
1336
|
role: "user",
|
1337
1337
|
content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
1338
|
-
|
1338
|
+
providerOptions: (_c = message.providerOptions) != null ? _c : message.experimental_providerMetadata
|
1339
1339
|
};
|
1340
1340
|
}
|
1341
1341
|
case "assistant": {
|
@@ -1343,7 +1343,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1343
1343
|
return {
|
1344
1344
|
role: "assistant",
|
1345
1345
|
content: [{ type: "text", text: message.content }],
|
1346
|
-
|
1346
|
+
providerOptions: (_d = message.providerOptions) != null ? _d : message.experimental_providerMetadata
|
1347
1347
|
};
|
1348
1348
|
}
|
1349
1349
|
return {
|
@@ -1361,7 +1361,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1361
1361
|
data: part.data instanceof URL ? part.data : convertDataContentToBase64String(part.data),
|
1362
1362
|
filename: part.filename,
|
1363
1363
|
mimeType: part.mimeType,
|
1364
|
-
|
1364
|
+
providerOptions
|
1365
1365
|
};
|
1366
1366
|
}
|
1367
1367
|
case "reasoning": {
|
@@ -1369,21 +1369,21 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1369
1369
|
type: "reasoning",
|
1370
1370
|
text: part.text,
|
1371
1371
|
signature: part.signature,
|
1372
|
-
|
1372
|
+
providerOptions
|
1373
1373
|
};
|
1374
1374
|
}
|
1375
1375
|
case "redacted-reasoning": {
|
1376
1376
|
return {
|
1377
1377
|
type: "redacted-reasoning",
|
1378
1378
|
data: part.data,
|
1379
|
-
|
1379
|
+
providerOptions
|
1380
1380
|
};
|
1381
1381
|
}
|
1382
1382
|
case "text": {
|
1383
1383
|
return {
|
1384
1384
|
type: "text",
|
1385
1385
|
text: part.text,
|
1386
|
-
|
1386
|
+
providerOptions
|
1387
1387
|
};
|
1388
1388
|
}
|
1389
1389
|
case "tool-call": {
|
@@ -1392,12 +1392,12 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1392
1392
|
toolCallId: part.toolCallId,
|
1393
1393
|
toolName: part.toolName,
|
1394
1394
|
args: part.args,
|
1395
|
-
|
1395
|
+
providerOptions
|
1396
1396
|
};
|
1397
1397
|
}
|
1398
1398
|
}
|
1399
1399
|
}),
|
1400
|
-
|
1400
|
+
providerOptions: (_e = message.providerOptions) != null ? _e : message.experimental_providerMetadata
|
1401
1401
|
};
|
1402
1402
|
}
|
1403
1403
|
case "tool": {
|
@@ -1412,10 +1412,10 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1412
1412
|
result: part.result,
|
1413
1413
|
content: part.experimental_content,
|
1414
1414
|
isError: part.isError,
|
1415
|
-
|
1415
|
+
providerOptions: (_a18 = part.providerOptions) != null ? _a18 : part.experimental_providerMetadata
|
1416
1416
|
};
|
1417
1417
|
}),
|
1418
|
-
|
1418
|
+
providerOptions: (_f = message.providerOptions) != null ? _f : message.experimental_providerMetadata
|
1419
1419
|
};
|
1420
1420
|
}
|
1421
1421
|
default: {
|
@@ -1453,7 +1453,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1453
1453
|
return {
|
1454
1454
|
type: "text",
|
1455
1455
|
text: part.text,
|
1456
|
-
|
1456
|
+
providerOptions: (_a17 = part.providerOptions) != null ? _a17 : part.experimental_providerMetadata
|
1457
1457
|
};
|
1458
1458
|
}
|
1459
1459
|
let mimeType = part.mimeType;
|
@@ -1507,7 +1507,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1507
1507
|
type: "image",
|
1508
1508
|
image: normalizedData,
|
1509
1509
|
mimeType,
|
1510
|
-
|
1510
|
+
providerOptions: (_c = part.providerOptions) != null ? _c : part.experimental_providerMetadata
|
1511
1511
|
};
|
1512
1512
|
}
|
1513
1513
|
case "file": {
|
@@ -1519,7 +1519,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1519
1519
|
data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
|
1520
1520
|
filename: part.filename,
|
1521
1521
|
mimeType,
|
1522
|
-
|
1522
|
+
providerOptions: (_d = part.providerOptions) != null ? _d : part.experimental_providerMetadata
|
1523
1523
|
};
|
1524
1524
|
}
|
1525
1525
|
}
|
@@ -2758,8 +2758,8 @@ async function generateObject({
|
|
2758
2758
|
fn: async (span2) => {
|
2759
2759
|
var _a18, _b2, _c2, _d2, _e, _f;
|
2760
2760
|
const result2 = await model.doGenerate({
|
2761
|
-
|
2762
|
-
type: "
|
2761
|
+
responseFormat: {
|
2762
|
+
type: "json",
|
2763
2763
|
schema: outputStrategy.jsonSchema,
|
2764
2764
|
name: schemaName,
|
2765
2765
|
description: schemaDescription
|
@@ -2767,7 +2767,7 @@ async function generateObject({
|
|
2767
2767
|
...prepareCallSettings(settings),
|
2768
2768
|
inputFormat: standardizedPrompt.type,
|
2769
2769
|
prompt: promptMessages,
|
2770
|
-
|
2770
|
+
providerOptions,
|
2771
2771
|
abortSignal,
|
2772
2772
|
headers
|
2773
2773
|
});
|
@@ -2864,19 +2864,19 @@ async function generateObject({
|
|
2864
2864
|
fn: async (span2) => {
|
2865
2865
|
var _a18, _b2, _c2, _d2, _e, _f, _g, _h;
|
2866
2866
|
const result2 = await model.doGenerate({
|
2867
|
-
|
2868
|
-
|
2869
|
-
tool: {
|
2867
|
+
tools: [
|
2868
|
+
{
|
2870
2869
|
type: "function",
|
2871
2870
|
name: schemaName != null ? schemaName : "json",
|
2872
2871
|
description: schemaDescription != null ? schemaDescription : "Respond with a JSON object.",
|
2873
2872
|
parameters: outputStrategy.jsonSchema
|
2874
2873
|
}
|
2875
|
-
|
2874
|
+
],
|
2875
|
+
toolChoice: { type: "required" },
|
2876
2876
|
...prepareCallSettings(settings),
|
2877
2877
|
inputFormat,
|
2878
2878
|
prompt: promptMessages,
|
2879
|
-
|
2879
|
+
providerOptions,
|
2880
2880
|
abortSignal,
|
2881
2881
|
headers
|
2882
2882
|
});
|
@@ -3339,8 +3339,8 @@ var DefaultStreamObjectResult = class {
|
|
3339
3339
|
tools: void 0
|
3340
3340
|
});
|
3341
3341
|
callOptions = {
|
3342
|
-
|
3343
|
-
type: "
|
3342
|
+
responseFormat: {
|
3343
|
+
type: "json",
|
3344
3344
|
schema: outputStrategy.jsonSchema,
|
3345
3345
|
name: schemaName,
|
3346
3346
|
description: schemaDescription
|
@@ -3353,7 +3353,7 @@ var DefaultStreamObjectResult = class {
|
|
3353
3353
|
modelSupportsUrl: (_a17 = model.supportsUrl) == null ? void 0 : _a17.bind(model)
|
3354
3354
|
// support 'this' context
|
3355
3355
|
}),
|
3356
|
-
|
3356
|
+
providerOptions,
|
3357
3357
|
abortSignal,
|
3358
3358
|
headers
|
3359
3359
|
};
|
@@ -3379,15 +3379,15 @@ var DefaultStreamObjectResult = class {
|
|
3379
3379
|
tools: void 0
|
3380
3380
|
});
|
3381
3381
|
callOptions = {
|
3382
|
-
|
3383
|
-
|
3384
|
-
tool: {
|
3382
|
+
tools: [
|
3383
|
+
{
|
3385
3384
|
type: "function",
|
3386
3385
|
name: schemaName != null ? schemaName : "json",
|
3387
3386
|
description: schemaDescription != null ? schemaDescription : "Respond with a JSON object.",
|
3388
3387
|
parameters: outputStrategy.jsonSchema
|
3389
3388
|
}
|
3390
|
-
|
3389
|
+
],
|
3390
|
+
toolChoice: { type: "required" },
|
3391
3391
|
...prepareCallSettings(settings),
|
3392
3392
|
inputFormat: standardizedPrompt.type,
|
3393
3393
|
prompt: await convertToLanguageModelPrompt({
|
@@ -3396,7 +3396,7 @@ var DefaultStreamObjectResult = class {
|
|
3396
3396
|
modelSupportsUrl: (_b = model.supportsUrl) == null ? void 0 : _b.bind(model)
|
3397
3397
|
// support 'this' context,
|
3398
3398
|
}),
|
3399
|
-
|
3399
|
+
providerOptions,
|
3400
3400
|
abortSignal,
|
3401
3401
|
headers
|
3402
3402
|
};
|
@@ -4153,8 +4153,7 @@ async function generateText({
|
|
4153
4153
|
tracer,
|
4154
4154
|
fn: async (span) => {
|
4155
4155
|
var _a18, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
4156
|
-
const
|
4157
|
-
type: "regular",
|
4156
|
+
const toolsAndToolChoice = {
|
4158
4157
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
4159
4158
|
};
|
4160
4159
|
const callSettings = prepareCallSettings(settings);
|
@@ -4208,11 +4207,11 @@ async function generateText({
|
|
4208
4207
|
// convert the language model level tools:
|
4209
4208
|
input: () => {
|
4210
4209
|
var _a19;
|
4211
|
-
return (_a19 =
|
4210
|
+
return (_a19 = toolsAndToolChoice.tools) == null ? void 0 : _a19.map((tool2) => JSON.stringify(tool2));
|
4212
4211
|
}
|
4213
4212
|
},
|
4214
4213
|
"ai.prompt.toolChoice": {
|
4215
|
-
input: () =>
|
4214
|
+
input: () => toolsAndToolChoice.toolChoice != null ? JSON.stringify(toolsAndToolChoice.toolChoice) : void 0
|
4216
4215
|
},
|
4217
4216
|
// standardized gen-ai llm span attributes:
|
4218
4217
|
"gen_ai.system": model.provider,
|
@@ -4230,12 +4229,12 @@ async function generateText({
|
|
4230
4229
|
fn: async (span2) => {
|
4231
4230
|
var _a19, _b2, _c2, _d2, _e2, _f2;
|
4232
4231
|
const result = await model.doGenerate({
|
4233
|
-
mode,
|
4234
4232
|
...callSettings,
|
4233
|
+
...toolsAndToolChoice,
|
4235
4234
|
inputFormat: promptFormat,
|
4236
4235
|
responseFormat: output == null ? void 0 : output.responseFormat({ model }),
|
4237
4236
|
prompt: promptMessages,
|
4238
|
-
|
4237
|
+
providerOptions,
|
4239
4238
|
abortSignal,
|
4240
4239
|
headers
|
4241
4240
|
});
|
@@ -4751,6 +4750,25 @@ function asArray(value) {
|
|
4751
4750
|
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
4752
4751
|
}
|
4753
4752
|
|
4753
|
+
// util/consume-stream.ts
|
4754
|
+
async function consumeStream({
|
4755
|
+
stream,
|
4756
|
+
onError
|
4757
|
+
}) {
|
4758
|
+
const reader = stream.getReader();
|
4759
|
+
try {
|
4760
|
+
while (true) {
|
4761
|
+
const { done } = await reader.read();
|
4762
|
+
if (done)
|
4763
|
+
break;
|
4764
|
+
}
|
4765
|
+
} catch (error) {
|
4766
|
+
onError == null ? void 0 : onError(error);
|
4767
|
+
} finally {
|
4768
|
+
reader.releaseLock();
|
4769
|
+
}
|
4770
|
+
}
|
4771
|
+
|
4754
4772
|
// core/util/merge-streams.ts
|
4755
4773
|
function mergeStreams(stream1, stream2) {
|
4756
4774
|
const reader1 = stream1.getReader();
|
@@ -5506,8 +5524,7 @@ var DefaultStreamTextResult = class {
|
|
5506
5524
|
modelSupportsUrl: (_a18 = model.supportsUrl) == null ? void 0 : _a18.bind(model)
|
5507
5525
|
// support 'this' context
|
5508
5526
|
});
|
5509
|
-
const
|
5510
|
-
type: "regular",
|
5527
|
+
const toolsAndToolChoice = {
|
5511
5528
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
5512
5529
|
};
|
5513
5530
|
const {
|
@@ -5535,11 +5552,13 @@ var DefaultStreamTextResult = class {
|
|
5535
5552
|
// convert the language model level tools:
|
5536
5553
|
input: () => {
|
5537
5554
|
var _a19;
|
5538
|
-
return (_a19 =
|
5555
|
+
return (_a19 = toolsAndToolChoice.tools) == null ? void 0 : _a19.map(
|
5556
|
+
(tool2) => JSON.stringify(tool2)
|
5557
|
+
);
|
5539
5558
|
}
|
5540
5559
|
},
|
5541
5560
|
"ai.prompt.toolChoice": {
|
5542
|
-
input: () =>
|
5561
|
+
input: () => toolsAndToolChoice.toolChoice != null ? JSON.stringify(toolsAndToolChoice.toolChoice) : void 0
|
5543
5562
|
},
|
5544
5563
|
// standardized gen-ai llm span attributes:
|
5545
5564
|
"gen_ai.system": model.provider,
|
@@ -5560,12 +5579,12 @@ var DefaultStreamTextResult = class {
|
|
5560
5579
|
// get before the call
|
5561
5580
|
doStreamSpan: doStreamSpan2,
|
5562
5581
|
result: await model.doStream({
|
5563
|
-
mode,
|
5564
5582
|
...prepareCallSettings(settings),
|
5583
|
+
...toolsAndToolChoice,
|
5565
5584
|
inputFormat: promptFormat,
|
5566
5585
|
responseFormat: output == null ? void 0 : output.responseFormat({ model }),
|
5567
5586
|
prompt: promptMessages,
|
5568
|
-
|
5587
|
+
providerOptions,
|
5569
5588
|
abortSignal,
|
5570
5589
|
headers
|
5571
5590
|
})
|
@@ -5992,9 +6011,15 @@ var DefaultStreamTextResult = class {
|
|
5992
6011
|
)
|
5993
6012
|
);
|
5994
6013
|
}
|
5995
|
-
async consumeStream() {
|
5996
|
-
|
5997
|
-
|
6014
|
+
async consumeStream(options) {
|
6015
|
+
var _a17;
|
6016
|
+
try {
|
6017
|
+
await consumeStream({
|
6018
|
+
stream: this.fullStream,
|
6019
|
+
onError: options == null ? void 0 : options.onError
|
6020
|
+
});
|
6021
|
+
} catch (error) {
|
6022
|
+
(_a17 = options == null ? void 0 : options.onError) == null ? void 0 : _a17.call(options, error);
|
5998
6023
|
}
|
5999
6024
|
}
|
6000
6025
|
get experimental_partialOutputStream() {
|
@@ -6309,9 +6334,9 @@ function defaultSettingsMiddleware({
|
|
6309
6334
|
return {
|
6310
6335
|
...settings,
|
6311
6336
|
...params,
|
6312
|
-
|
6313
|
-
settings.
|
6314
|
-
params.
|
6337
|
+
providerOptions: mergeObjects(
|
6338
|
+
settings.providerOptions,
|
6339
|
+
params.providerOptions
|
6315
6340
|
),
|
6316
6341
|
// special case for temperature 0
|
6317
6342
|
// TODO remove when temperature defaults to undefined
|