ai 3.0.18 → 3.0.20
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/anthropic/dist/index.d.mts +66 -34
- package/anthropic/dist/index.d.ts +66 -34
- package/anthropic/dist/index.js +98 -94
- package/anthropic/dist/index.js.map +1 -1
- package/anthropic/dist/index.mjs +98 -94
- package/anthropic/dist/index.mjs.map +1 -1
- package/dist/index.d.mts +119 -45
- package/dist/index.d.ts +119 -45
- package/dist/index.js +83 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -153
- package/dist/index.mjs.map +1 -1
- package/google/dist/index.d.mts +65 -31
- package/google/dist/index.d.ts +65 -31
- package/google/dist/index.js +47 -43
- package/google/dist/index.js.map +1 -1
- package/google/dist/index.mjs +47 -43
- package/google/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +65 -31
- package/mistral/dist/index.d.ts +65 -31
- package/mistral/dist/index.js +6 -21
- package/mistral/dist/index.js.map +1 -1
- package/mistral/dist/index.mjs +6 -21
- package/mistral/dist/index.mjs.map +1 -1
- package/openai/dist/index.d.mts +65 -31
- package/openai/dist/index.d.ts +65 -31
- package/openai/dist/index.js +9 -29
- package/openai/dist/index.js.map +1 -1
- package/openai/dist/index.mjs +9 -29
- package/openai/dist/index.mjs.map +1 -1
- package/package.json +5 -3
- package/react/dist/index.d.mts +8 -4
- package/react/dist/index.d.ts +12 -6
- package/react/dist/index.js +23 -105
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +22 -105
- package/react/dist/index.mjs.map +1 -1
- package/react/dist/index.server.d.mts +4 -2
- package/react/dist/index.server.d.ts +4 -2
- package/react/dist/index.server.js.map +1 -1
- package/react/dist/index.server.mjs.map +1 -1
- package/rsc/dist/rsc-server.mjs +6 -16
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/solid/dist/index.js +19 -104
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +19 -104
- package/solid/dist/index.mjs.map +1 -1
- package/spec/dist/index.d.mts +112 -40
- package/spec/dist/index.d.ts +112 -40
- package/spec/dist/index.js +71 -13
- package/spec/dist/index.js.map +1 -1
- package/spec/dist/index.mjs +69 -13
- package/spec/dist/index.mjs.map +1 -1
- package/svelte/dist/index.js +19 -104
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +19 -104
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.js +19 -104
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +19 -104
- package/vue/dist/index.mjs.map +1 -1
package/dist/index.js
CHANGED
@@ -37,7 +37,7 @@ __export(streams_exports, {
|
|
37
37
|
AWSBedrockLlama2Stream: () => AWSBedrockLlama2Stream,
|
38
38
|
AWSBedrockStream: () => AWSBedrockStream,
|
39
39
|
AnthropicStream: () => AnthropicStream,
|
40
|
-
|
40
|
+
AssistantResponse: () => AssistantResponse,
|
41
41
|
CohereStream: () => CohereStream,
|
42
42
|
GenerateObjectResult: () => GenerateObjectResult,
|
43
43
|
GenerateTextResult: () => GenerateTextResult,
|
@@ -48,6 +48,7 @@ __export(streams_exports, {
|
|
48
48
|
MistralStream: () => MistralStream,
|
49
49
|
OpenAIStream: () => OpenAIStream,
|
50
50
|
ReplicateStream: () => ReplicateStream,
|
51
|
+
StreamData: () => StreamData,
|
51
52
|
StreamObjectResult: () => StreamObjectResult,
|
52
53
|
StreamTextResult: () => StreamTextResult,
|
53
54
|
StreamingTextResponse: () => StreamingTextResponse,
|
@@ -74,9 +75,6 @@ __export(streams_exports, {
|
|
74
75
|
});
|
75
76
|
module.exports = __toCommonJS(streams_exports);
|
76
77
|
|
77
|
-
// core/generate-object/generate-object.ts
|
78
|
-
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
79
|
-
|
80
78
|
// spec/errors/api-call-error.ts
|
81
79
|
var APICallError = class extends Error {
|
82
80
|
constructor({
|
@@ -373,20 +371,26 @@ var NoTextGeneratedError = class extends Error {
|
|
373
371
|
|
374
372
|
// spec/errors/no-such-tool-error.ts
|
375
373
|
var NoSuchToolError = class extends Error {
|
376
|
-
constructor({
|
374
|
+
constructor({
|
375
|
+
toolName,
|
376
|
+
availableTools = void 0,
|
377
|
+
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
378
|
+
}) {
|
377
379
|
super(message);
|
378
380
|
this.name = "AI_NoSuchToolError";
|
379
381
|
this.toolName = toolName;
|
382
|
+
this.availableTools = availableTools;
|
380
383
|
}
|
381
384
|
static isNoSuchToolError(error) {
|
382
|
-
return error instanceof Error && error.name === "AI_NoSuchToolError" &&
|
385
|
+
return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
|
383
386
|
}
|
384
387
|
toJSON() {
|
385
388
|
return {
|
386
389
|
name: this.name,
|
387
390
|
message: this.message,
|
388
391
|
stack: this.stack,
|
389
|
-
toolName: this.toolName
|
392
|
+
toolName: this.toolName,
|
393
|
+
availableTools: this.availableTools
|
390
394
|
};
|
391
395
|
}
|
392
396
|
};
|
@@ -701,6 +705,12 @@ function prepareCallSettings({
|
|
701
705
|
};
|
702
706
|
}
|
703
707
|
|
708
|
+
// core/util/convert-zod-to-json-schema.ts
|
709
|
+
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
710
|
+
function convertZodToJSONSchema(zodSchema) {
|
711
|
+
return (0, import_zod_to_json_schema.default)(zodSchema);
|
712
|
+
}
|
713
|
+
|
704
714
|
// core/util/delay.ts
|
705
715
|
async function delay(delayInMs) {
|
706
716
|
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
@@ -792,7 +802,7 @@ async function experimental_generateObject({
|
|
792
802
|
}) {
|
793
803
|
var _a, _b;
|
794
804
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
795
|
-
const jsonSchema = (
|
805
|
+
const jsonSchema = convertZodToJSONSchema(schema);
|
796
806
|
if (mode === "auto" || mode == null) {
|
797
807
|
mode = model.defaultObjectGenerationMode;
|
798
808
|
}
|
@@ -910,9 +920,6 @@ var GenerateObjectResult = class {
|
|
910
920
|
}
|
911
921
|
};
|
912
922
|
|
913
|
-
// core/generate-object/stream-object.ts
|
914
|
-
var import_zod_to_json_schema2 = __toESM(require("zod-to-json-schema"));
|
915
|
-
|
916
923
|
// core/util/async-iterable-stream.ts
|
917
924
|
function createAsyncIterableStream(source, transformer) {
|
918
925
|
const transformedStream = source.pipeThrough(
|
@@ -1315,7 +1322,7 @@ async function experimental_streamObject({
|
|
1315
1322
|
...settings
|
1316
1323
|
}) {
|
1317
1324
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1318
|
-
const jsonSchema = (
|
1325
|
+
const jsonSchema = convertZodToJSONSchema(schema);
|
1319
1326
|
if (mode === "auto" || mode == null) {
|
1320
1327
|
mode = model.defaultObjectGenerationMode;
|
1321
1328
|
}
|
@@ -1456,9 +1463,6 @@ var StreamObjectResult = class {
|
|
1456
1463
|
}
|
1457
1464
|
};
|
1458
1465
|
|
1459
|
-
// core/generate-text/generate-text.ts
|
1460
|
-
var import_zod_to_json_schema3 = __toESM(require("zod-to-json-schema"));
|
1461
|
-
|
1462
1466
|
// core/generate-text/tool-call.ts
|
1463
1467
|
function parseToolCall({
|
1464
1468
|
toolCall,
|
@@ -1466,16 +1470,13 @@ function parseToolCall({
|
|
1466
1470
|
}) {
|
1467
1471
|
const toolName = toolCall.toolName;
|
1468
1472
|
if (tools == null) {
|
1469
|
-
throw new NoSuchToolError({
|
1470
|
-
message: `Tool ${toolCall.toolName} not found (no tools provided).`,
|
1471
|
-
toolName: toolCall.toolName
|
1472
|
-
});
|
1473
|
+
throw new NoSuchToolError({ toolName: toolCall.toolName });
|
1473
1474
|
}
|
1474
1475
|
const tool2 = tools[toolName];
|
1475
1476
|
if (tool2 == null) {
|
1476
1477
|
throw new NoSuchToolError({
|
1477
|
-
|
1478
|
-
|
1478
|
+
toolName: toolCall.toolName,
|
1479
|
+
availableTools: Object.keys(tools)
|
1479
1480
|
});
|
1480
1481
|
}
|
1481
1482
|
const parseResult = safeParseJSON({
|
@@ -1490,6 +1491,7 @@ function parseToolCall({
|
|
1490
1491
|
});
|
1491
1492
|
}
|
1492
1493
|
return {
|
1494
|
+
type: "tool-call",
|
1493
1495
|
toolCallId: toolCall.toolCallId,
|
1494
1496
|
toolName,
|
1495
1497
|
args: parseResult.value
|
@@ -1518,7 +1520,7 @@ async function experimental_generateText({
|
|
1518
1520
|
type: "function",
|
1519
1521
|
name,
|
1520
1522
|
description: tool2.description,
|
1521
|
-
parameters: (
|
1523
|
+
parameters: convertZodToJSONSchema(tool2.parameters)
|
1522
1524
|
}))
|
1523
1525
|
},
|
1524
1526
|
...prepareCallSettings(settings),
|
@@ -1578,9 +1580,6 @@ var GenerateTextResult = class {
|
|
1578
1580
|
}
|
1579
1581
|
};
|
1580
1582
|
|
1581
|
-
// core/generate-text/stream-text.ts
|
1582
|
-
var import_zod_to_json_schema4 = __toESM(require("zod-to-json-schema"));
|
1583
|
-
|
1584
1583
|
// shared/generate-id.ts
|
1585
1584
|
var import_non_secure = require("nanoid/non-secure");
|
1586
1585
|
var generateId = (0, import_non_secure.customAlphabet)(
|
@@ -1615,10 +1614,7 @@ function runToolsTransformation({
|
|
1615
1614
|
if (tools == null) {
|
1616
1615
|
toolResultsStreamController.enqueue({
|
1617
1616
|
type: "error",
|
1618
|
-
error: new NoSuchToolError({
|
1619
|
-
message: `Tool ${chunk.toolName} not found (no tools provided).`,
|
1620
|
-
toolName: chunk.toolName
|
1621
|
-
})
|
1617
|
+
error: new NoSuchToolError({ toolName: chunk.toolName })
|
1622
1618
|
});
|
1623
1619
|
break;
|
1624
1620
|
}
|
@@ -1627,8 +1623,8 @@ function runToolsTransformation({
|
|
1627
1623
|
toolResultsStreamController.enqueue({
|
1628
1624
|
type: "error",
|
1629
1625
|
error: new NoSuchToolError({
|
1630
|
-
|
1631
|
-
|
1626
|
+
toolName: chunk.toolName,
|
1627
|
+
availableTools: Object.keys(tools)
|
1632
1628
|
})
|
1633
1629
|
});
|
1634
1630
|
break;
|
@@ -1638,18 +1634,15 @@ function runToolsTransformation({
|
|
1638
1634
|
toolCall: chunk,
|
1639
1635
|
tools
|
1640
1636
|
});
|
1641
|
-
controller.enqueue(
|
1642
|
-
type: "tool-call",
|
1643
|
-
...toolCall
|
1644
|
-
});
|
1637
|
+
controller.enqueue(toolCall);
|
1645
1638
|
if (tool2.execute != null) {
|
1646
1639
|
const toolExecutionId = generateId();
|
1647
1640
|
outstandingToolCalls.add(toolExecutionId);
|
1648
1641
|
tool2.execute(toolCall.args).then(
|
1649
1642
|
(result) => {
|
1650
1643
|
toolResultsStreamController.enqueue({
|
1651
|
-
type: "tool-result",
|
1652
1644
|
...toolCall,
|
1645
|
+
type: "tool-result",
|
1653
1646
|
result
|
1654
1647
|
});
|
1655
1648
|
outstandingToolCalls.delete(toolExecutionId);
|
@@ -1751,7 +1744,7 @@ async function experimental_streamText({
|
|
1751
1744
|
type: "function",
|
1752
1745
|
name,
|
1753
1746
|
description: tool2.description,
|
1754
|
-
parameters: (
|
1747
|
+
parameters: convertZodToJSONSchema(tool2.parameters)
|
1755
1748
|
}))
|
1756
1749
|
},
|
1757
1750
|
...prepareCallSettings(settings),
|
@@ -1823,9 +1816,7 @@ var StreamTextResult = class {
|
|
1823
1816
|
@returns an `AIStream` object.
|
1824
1817
|
*/
|
1825
1818
|
toAIStream(callbacks) {
|
1826
|
-
return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
1827
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
1828
|
-
);
|
1819
|
+
return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
1829
1820
|
}
|
1830
1821
|
};
|
1831
1822
|
|
@@ -2030,7 +2021,6 @@ function createChunkDecoder(complex) {
|
|
2030
2021
|
};
|
2031
2022
|
}
|
2032
2023
|
var isStreamStringEqualToType = (type, value) => value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith("\n");
|
2033
|
-
var COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
2034
2024
|
|
2035
2025
|
// streams/ai-stream.ts
|
2036
2026
|
var import_eventsource_parser = require("eventsource-parser");
|
@@ -2155,7 +2145,7 @@ function readableFromAsyncIterable(iterable) {
|
|
2155
2145
|
}
|
2156
2146
|
|
2157
2147
|
// streams/stream-data.ts
|
2158
|
-
var
|
2148
|
+
var StreamData = class {
|
2159
2149
|
constructor() {
|
2160
2150
|
this.encoder = new TextEncoder();
|
2161
2151
|
this.controller = null;
|
@@ -2241,14 +2231,7 @@ var experimental_StreamData = class {
|
|
2241
2231
|
this.messageAnnotations.push(value);
|
2242
2232
|
}
|
2243
2233
|
};
|
2244
|
-
function createStreamDataTransformer(
|
2245
|
-
if (!experimental_streamData) {
|
2246
|
-
return new TransformStream({
|
2247
|
-
transform: async (chunk, controller) => {
|
2248
|
-
controller.enqueue(chunk);
|
2249
|
-
}
|
2250
|
-
});
|
2251
|
-
}
|
2234
|
+
function createStreamDataTransformer() {
|
2252
2235
|
const encoder = new TextEncoder();
|
2253
2236
|
const decoder = new TextDecoder();
|
2254
2237
|
return new TransformStream({
|
@@ -2258,6 +2241,8 @@ function createStreamDataTransformer(experimental_streamData) {
|
|
2258
2241
|
}
|
2259
2242
|
});
|
2260
2243
|
}
|
2244
|
+
var experimental_StreamData = class extends StreamData {
|
2245
|
+
};
|
2261
2246
|
|
2262
2247
|
// streams/anthropic-stream.ts
|
2263
2248
|
function parseAnthropicStream() {
|
@@ -2297,16 +2282,16 @@ async function* streamable(stream) {
|
|
2297
2282
|
}
|
2298
2283
|
function AnthropicStream(res, cb) {
|
2299
2284
|
if (Symbol.asyncIterator in res) {
|
2300
|
-
return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(
|
2285
|
+
return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
|
2301
2286
|
} else {
|
2302
2287
|
return AIStream(res, parseAnthropicStream(), cb).pipeThrough(
|
2303
|
-
createStreamDataTransformer(
|
2288
|
+
createStreamDataTransformer()
|
2304
2289
|
);
|
2305
2290
|
}
|
2306
2291
|
}
|
2307
2292
|
|
2308
2293
|
// streams/assistant-response.ts
|
2309
|
-
function
|
2294
|
+
function AssistantResponse({ threadId, messageId }, process2) {
|
2310
2295
|
const stream = new ReadableStream({
|
2311
2296
|
async start(controller) {
|
2312
2297
|
var _a;
|
@@ -2397,6 +2382,7 @@ function experimental_AssistantResponse({ threadId, messageId }, process2) {
|
|
2397
2382
|
}
|
2398
2383
|
});
|
2399
2384
|
}
|
2385
|
+
var experimental_AssistantResponse = AssistantResponse;
|
2400
2386
|
|
2401
2387
|
// streams/aws-bedrock-stream.ts
|
2402
2388
|
async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
@@ -2424,16 +2410,7 @@ function AWSBedrockAnthropicStream(response, callbacks) {
|
|
2424
2410
|
return AWSBedrockStream(response, callbacks, (chunk) => chunk.completion);
|
2425
2411
|
}
|
2426
2412
|
function AWSBedrockCohereStream(response, callbacks) {
|
2427
|
-
return AWSBedrockStream(
|
2428
|
-
response,
|
2429
|
-
callbacks,
|
2430
|
-
// As of 2023-11-17, Bedrock does not support streaming for Cohere,
|
2431
|
-
// so we take the full generation:
|
2432
|
-
(chunk) => {
|
2433
|
-
var _a, _b;
|
2434
|
-
return (_b = (_a = chunk.generations) == null ? void 0 : _a[0]) == null ? void 0 : _b.text;
|
2435
|
-
}
|
2436
|
-
);
|
2413
|
+
return AWSBedrockStream(response, callbacks, (chunk) => chunk == null ? void 0 : chunk.text);
|
2437
2414
|
}
|
2438
2415
|
function AWSBedrockLlama2Stream(response, callbacks) {
|
2439
2416
|
return AWSBedrockStream(response, callbacks, (chunk) => chunk.generation);
|
@@ -2441,9 +2418,7 @@ function AWSBedrockLlama2Stream(response, callbacks) {
|
|
2441
2418
|
function AWSBedrockStream(response, callbacks, extractTextDeltaFromChunk) {
|
2442
2419
|
return readableFromAsyncIterable(
|
2443
2420
|
asDeltaIterable(response, extractTextDeltaFromChunk)
|
2444
|
-
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2445
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2446
|
-
);
|
2421
|
+
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2447
2422
|
}
|
2448
2423
|
|
2449
2424
|
// streams/cohere-stream.ts
|
@@ -2498,13 +2473,9 @@ async function* streamable2(stream) {
|
|
2498
2473
|
}
|
2499
2474
|
function CohereStream(reader, callbacks) {
|
2500
2475
|
if (Symbol.asyncIterator in reader) {
|
2501
|
-
return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2502
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2503
|
-
);
|
2476
|
+
return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2504
2477
|
} else {
|
2505
|
-
return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2506
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2507
|
-
);
|
2478
|
+
return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2508
2479
|
}
|
2509
2480
|
}
|
2510
2481
|
|
@@ -2523,7 +2494,7 @@ async function* streamable3(response) {
|
|
2523
2494
|
}
|
2524
2495
|
}
|
2525
2496
|
function GoogleGenerativeAIStream(response, cb) {
|
2526
|
-
return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(
|
2497
|
+
return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
|
2527
2498
|
}
|
2528
2499
|
|
2529
2500
|
// streams/huggingface-stream.ts
|
@@ -2551,9 +2522,7 @@ function createParser3(res) {
|
|
2551
2522
|
});
|
2552
2523
|
}
|
2553
2524
|
function HuggingFaceStream(res, callbacks) {
|
2554
|
-
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2555
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2556
|
-
);
|
2525
|
+
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2557
2526
|
}
|
2558
2527
|
|
2559
2528
|
// streams/inkeep-stream.ts
|
@@ -2590,7 +2559,7 @@ function InkeepStream(res, callbacks) {
|
|
2590
2559
|
}
|
2591
2560
|
};
|
2592
2561
|
return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
|
2593
|
-
createStreamDataTransformer(
|
2562
|
+
createStreamDataTransformer()
|
2594
2563
|
);
|
2595
2564
|
}
|
2596
2565
|
|
@@ -2615,9 +2584,7 @@ function LangChainStream(callbacks) {
|
|
2615
2584
|
}
|
2616
2585
|
};
|
2617
2586
|
return {
|
2618
|
-
stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2619
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2620
|
-
),
|
2587
|
+
stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer()),
|
2621
2588
|
writer,
|
2622
2589
|
handlers: {
|
2623
2590
|
handleLLMNewToken: async (token) => {
|
@@ -2668,9 +2635,7 @@ async function* streamable4(stream) {
|
|
2668
2635
|
}
|
2669
2636
|
function MistralStream(response, callbacks) {
|
2670
2637
|
const stream = readableFromAsyncIterable(streamable4(response));
|
2671
|
-
return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2672
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2673
|
-
);
|
2638
|
+
return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2674
2639
|
}
|
2675
2640
|
|
2676
2641
|
// streams/openai-stream.ts
|
@@ -2814,9 +2779,7 @@ function OpenAIStream(res, callbacks) {
|
|
2814
2779
|
const functionCallTransformer = createFunctionCallTransformer(cb);
|
2815
2780
|
return stream.pipeThrough(functionCallTransformer);
|
2816
2781
|
} else {
|
2817
|
-
return stream.pipeThrough(
|
2818
|
-
createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
|
2819
|
-
);
|
2782
|
+
return stream.pipeThrough(createStreamDataTransformer());
|
2820
2783
|
}
|
2821
2784
|
}
|
2822
2785
|
function createFunctionCallTransformer(callbacks) {
|
@@ -2826,7 +2789,6 @@ function createFunctionCallTransformer(callbacks) {
|
|
2826
2789
|
let aggregatedFinalCompletionResponse = "";
|
2827
2790
|
let isFunctionStreamingIn = false;
|
2828
2791
|
let functionCallMessages = callbacks[__internal__OpenAIFnMessagesSymbol] || [];
|
2829
|
-
const isComplexMode = callbacks == null ? void 0 : callbacks.experimental_streamData;
|
2830
2792
|
const decode = createChunkDecoder();
|
2831
2793
|
return new TransformStream({
|
2832
2794
|
async transform(chunk, controller) {
|
@@ -2841,7 +2803,7 @@ function createFunctionCallTransformer(callbacks) {
|
|
2841
2803
|
}
|
2842
2804
|
if (!isFunctionStreamingIn) {
|
2843
2805
|
controller.enqueue(
|
2844
|
-
|
2806
|
+
textEncoder.encode(formatStreamPart("text", message))
|
2845
2807
|
);
|
2846
2808
|
return;
|
2847
2809
|
} else {
|
@@ -2952,17 +2914,17 @@ function createFunctionCallTransformer(callbacks) {
|
|
2952
2914
|
if (!functionResponse) {
|
2953
2915
|
controller.enqueue(
|
2954
2916
|
textEncoder.encode(
|
2955
|
-
|
2917
|
+
formatStreamPart(
|
2956
2918
|
payload.function_call ? "function_call" : "tool_calls",
|
2957
2919
|
// parse to prevent double-encoding:
|
2958
2920
|
JSON.parse(aggregatedResponse)
|
2959
|
-
)
|
2921
|
+
)
|
2960
2922
|
)
|
2961
2923
|
);
|
2962
2924
|
return;
|
2963
2925
|
} else if (typeof functionResponse === "string") {
|
2964
2926
|
controller.enqueue(
|
2965
|
-
|
2927
|
+
textEncoder.encode(formatStreamPart("text", functionResponse))
|
2966
2928
|
);
|
2967
2929
|
aggregatedFinalCompletionResponse = functionResponse;
|
2968
2930
|
return;
|
@@ -3012,7 +2974,7 @@ async function ReplicateStream(res, cb, options) {
|
|
3012
2974
|
}
|
3013
2975
|
});
|
3014
2976
|
return AIStream(eventStream, void 0, cb).pipeThrough(
|
3015
|
-
createStreamDataTransformer(
|
2977
|
+
createStreamDataTransformer()
|
3016
2978
|
);
|
3017
2979
|
}
|
3018
2980
|
|
@@ -3173,74 +3135,41 @@ async function parseComplexResponse({
|
|
3173
3135
|
// streams/streaming-react-response.ts
|
3174
3136
|
var experimental_StreamingReactResponse = class {
|
3175
3137
|
constructor(res, options) {
|
3176
|
-
var _a;
|
3138
|
+
var _a, _b;
|
3177
3139
|
let resolveFunc = () => {
|
3178
3140
|
};
|
3179
3141
|
let next = new Promise((resolve) => {
|
3180
3142
|
resolveFunc = resolve;
|
3181
3143
|
});
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
3185
|
-
)
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3144
|
+
const processedStream = (options == null ? void 0 : options.data) != null ? res.pipeThrough((_a = options == null ? void 0 : options.data) == null ? void 0 : _a.stream) : res;
|
3145
|
+
let lastPayload = void 0;
|
3146
|
+
parseComplexResponse({
|
3147
|
+
reader: processedStream.getReader(),
|
3148
|
+
update: (merged, data) => {
|
3149
|
+
var _a2, _b2, _c;
|
3150
|
+
const content = (_b2 = (_a2 = merged[0]) == null ? void 0 : _a2.content) != null ? _b2 : "";
|
3151
|
+
const ui = ((_c = options == null ? void 0 : options.ui) == null ? void 0 : _c.call(options, { content, data })) || content;
|
3152
|
+
const payload = { ui, content };
|
3153
|
+
const resolvePrevious = resolveFunc;
|
3154
|
+
const nextRow = new Promise((resolve) => {
|
3155
|
+
resolveFunc = resolve;
|
3156
|
+
});
|
3157
|
+
resolvePrevious({
|
3158
|
+
next: nextRow,
|
3159
|
+
...payload
|
3160
|
+
});
|
3161
|
+
lastPayload = payload;
|
3162
|
+
},
|
3163
|
+
generateId: (_b = options == null ? void 0 : options.generateId) != null ? _b : generateId,
|
3164
|
+
onFinish: () => {
|
3165
|
+
if (lastPayload !== void 0) {
|
3166
|
+
resolveFunc({
|
3167
|
+
next: null,
|
3168
|
+
...lastPayload
|
3201
3169
|
});
|
3202
|
-
lastPayload = payload;
|
3203
|
-
},
|
3204
|
-
generateId: (_a = options.generateId) != null ? _a : generateId,
|
3205
|
-
onFinish: () => {
|
3206
|
-
if (lastPayload !== void 0) {
|
3207
|
-
resolveFunc({
|
3208
|
-
next: null,
|
3209
|
-
...lastPayload
|
3210
|
-
});
|
3211
|
-
}
|
3212
3170
|
}
|
3213
|
-
});
|
3214
|
-
return next;
|
3215
|
-
}
|
3216
|
-
let content = "";
|
3217
|
-
const decode = createChunkDecoder();
|
3218
|
-
const reader = res.getReader();
|
3219
|
-
async function readChunk() {
|
3220
|
-
var _a2;
|
3221
|
-
const { done, value } = await reader.read();
|
3222
|
-
if (!done) {
|
3223
|
-
content += decode(value);
|
3224
|
-
}
|
3225
|
-
const ui = ((_a2 = options == null ? void 0 : options.ui) == null ? void 0 : _a2.call(options, { content })) || content;
|
3226
|
-
const payload = {
|
3227
|
-
ui,
|
3228
|
-
content
|
3229
|
-
};
|
3230
|
-
const resolvePrevious = resolveFunc;
|
3231
|
-
const nextRow = done ? null : new Promise((resolve) => {
|
3232
|
-
resolveFunc = resolve;
|
3233
|
-
});
|
3234
|
-
resolvePrevious({
|
3235
|
-
next: nextRow,
|
3236
|
-
...payload
|
3237
|
-
});
|
3238
|
-
if (done) {
|
3239
|
-
return;
|
3240
3171
|
}
|
3241
|
-
|
3242
|
-
}
|
3243
|
-
readChunk();
|
3172
|
+
});
|
3244
3173
|
return next;
|
3245
3174
|
}
|
3246
3175
|
};
|
@@ -3257,7 +3186,6 @@ var StreamingTextResponse = class extends Response {
|
|
3257
3186
|
status: 200,
|
3258
3187
|
headers: {
|
3259
3188
|
"Content-Type": "text/plain; charset=utf-8",
|
3260
|
-
[COMPLEX_HEADER]: data ? "true" : "false",
|
3261
3189
|
...init == null ? void 0 : init.headers
|
3262
3190
|
}
|
3263
3191
|
});
|
@@ -3290,7 +3218,7 @@ function streamToResponse(res, response, init) {
|
|
3290
3218
|
AWSBedrockLlama2Stream,
|
3291
3219
|
AWSBedrockStream,
|
3292
3220
|
AnthropicStream,
|
3293
|
-
|
3221
|
+
AssistantResponse,
|
3294
3222
|
CohereStream,
|
3295
3223
|
GenerateObjectResult,
|
3296
3224
|
GenerateTextResult,
|
@@ -3301,6 +3229,7 @@ function streamToResponse(res, response, init) {
|
|
3301
3229
|
MistralStream,
|
3302
3230
|
OpenAIStream,
|
3303
3231
|
ReplicateStream,
|
3232
|
+
StreamData,
|
3304
3233
|
StreamObjectResult,
|
3305
3234
|
StreamTextResult,
|
3306
3235
|
StreamingTextResponse,
|