ai 3.0.19 → 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 +44 -10
- package/anthropic/dist/index.d.ts +44 -10
- package/anthropic/dist/index.js +17 -31
- package/anthropic/dist/index.js.map +1 -1
- package/anthropic/dist/index.mjs +17 -31
- package/anthropic/dist/index.mjs.map +1 -1
- package/dist/index.d.mts +97 -24
- package/dist/index.d.ts +97 -24
- package/dist/index.js +55 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -117
- package/dist/index.mjs.map +1 -1
- package/google/dist/index.d.mts +44 -10
- package/google/dist/index.d.ts +44 -10
- 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 +44 -10
- package/mistral/dist/index.d.ts +44 -10
- 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 +44 -10
- package/openai/dist/index.d.ts +44 -10
- 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 +1 -1
- 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 +48 -20
- package/spec/dist/index.d.ts +48 -20
- package/spec/dist/index.js +4 -14
- package/spec/dist/index.js.map +1 -1
- package/spec/dist/index.mjs +4 -14
- 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.mjs
CHANGED
@@ -1739,9 +1739,7 @@ var StreamTextResult = class {
|
|
1739
1739
|
@returns an `AIStream` object.
|
1740
1740
|
*/
|
1741
1741
|
toAIStream(callbacks) {
|
1742
|
-
return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
1743
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
1744
|
-
);
|
1742
|
+
return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
1745
1743
|
}
|
1746
1744
|
};
|
1747
1745
|
|
@@ -1946,7 +1944,6 @@ function createChunkDecoder(complex) {
|
|
1946
1944
|
};
|
1947
1945
|
}
|
1948
1946
|
var isStreamStringEqualToType = (type, value) => value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith("\n");
|
1949
|
-
var COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
1950
1947
|
|
1951
1948
|
// streams/ai-stream.ts
|
1952
1949
|
import {
|
@@ -2073,7 +2070,7 @@ function readableFromAsyncIterable(iterable) {
|
|
2073
2070
|
}
|
2074
2071
|
|
2075
2072
|
// streams/stream-data.ts
|
2076
|
-
var
|
2073
|
+
var StreamData = class {
|
2077
2074
|
constructor() {
|
2078
2075
|
this.encoder = new TextEncoder();
|
2079
2076
|
this.controller = null;
|
@@ -2159,14 +2156,7 @@ var experimental_StreamData = class {
|
|
2159
2156
|
this.messageAnnotations.push(value);
|
2160
2157
|
}
|
2161
2158
|
};
|
2162
|
-
function createStreamDataTransformer(
|
2163
|
-
if (!experimental_streamData) {
|
2164
|
-
return new TransformStream({
|
2165
|
-
transform: async (chunk, controller) => {
|
2166
|
-
controller.enqueue(chunk);
|
2167
|
-
}
|
2168
|
-
});
|
2169
|
-
}
|
2159
|
+
function createStreamDataTransformer() {
|
2170
2160
|
const encoder = new TextEncoder();
|
2171
2161
|
const decoder = new TextDecoder();
|
2172
2162
|
return new TransformStream({
|
@@ -2176,6 +2166,8 @@ function createStreamDataTransformer(experimental_streamData) {
|
|
2176
2166
|
}
|
2177
2167
|
});
|
2178
2168
|
}
|
2169
|
+
var experimental_StreamData = class extends StreamData {
|
2170
|
+
};
|
2179
2171
|
|
2180
2172
|
// streams/anthropic-stream.ts
|
2181
2173
|
function parseAnthropicStream() {
|
@@ -2215,16 +2207,16 @@ async function* streamable(stream) {
|
|
2215
2207
|
}
|
2216
2208
|
function AnthropicStream(res, cb) {
|
2217
2209
|
if (Symbol.asyncIterator in res) {
|
2218
|
-
return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(
|
2210
|
+
return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
|
2219
2211
|
} else {
|
2220
2212
|
return AIStream(res, parseAnthropicStream(), cb).pipeThrough(
|
2221
|
-
createStreamDataTransformer(
|
2213
|
+
createStreamDataTransformer()
|
2222
2214
|
);
|
2223
2215
|
}
|
2224
2216
|
}
|
2225
2217
|
|
2226
2218
|
// streams/assistant-response.ts
|
2227
|
-
function
|
2219
|
+
function AssistantResponse({ threadId, messageId }, process2) {
|
2228
2220
|
const stream = new ReadableStream({
|
2229
2221
|
async start(controller) {
|
2230
2222
|
var _a;
|
@@ -2315,6 +2307,7 @@ function experimental_AssistantResponse({ threadId, messageId }, process2) {
|
|
2315
2307
|
}
|
2316
2308
|
});
|
2317
2309
|
}
|
2310
|
+
var experimental_AssistantResponse = AssistantResponse;
|
2318
2311
|
|
2319
2312
|
// streams/aws-bedrock-stream.ts
|
2320
2313
|
async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
@@ -2342,16 +2335,7 @@ function AWSBedrockAnthropicStream(response, callbacks) {
|
|
2342
2335
|
return AWSBedrockStream(response, callbacks, (chunk) => chunk.completion);
|
2343
2336
|
}
|
2344
2337
|
function AWSBedrockCohereStream(response, callbacks) {
|
2345
|
-
return AWSBedrockStream(
|
2346
|
-
response,
|
2347
|
-
callbacks,
|
2348
|
-
// As of 2023-11-17, Bedrock does not support streaming for Cohere,
|
2349
|
-
// so we take the full generation:
|
2350
|
-
(chunk) => {
|
2351
|
-
var _a, _b;
|
2352
|
-
return (_b = (_a = chunk.generations) == null ? void 0 : _a[0]) == null ? void 0 : _b.text;
|
2353
|
-
}
|
2354
|
-
);
|
2338
|
+
return AWSBedrockStream(response, callbacks, (chunk) => chunk == null ? void 0 : chunk.text);
|
2355
2339
|
}
|
2356
2340
|
function AWSBedrockLlama2Stream(response, callbacks) {
|
2357
2341
|
return AWSBedrockStream(response, callbacks, (chunk) => chunk.generation);
|
@@ -2359,9 +2343,7 @@ function AWSBedrockLlama2Stream(response, callbacks) {
|
|
2359
2343
|
function AWSBedrockStream(response, callbacks, extractTextDeltaFromChunk) {
|
2360
2344
|
return readableFromAsyncIterable(
|
2361
2345
|
asDeltaIterable(response, extractTextDeltaFromChunk)
|
2362
|
-
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2363
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2364
|
-
);
|
2346
|
+
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2365
2347
|
}
|
2366
2348
|
|
2367
2349
|
// streams/cohere-stream.ts
|
@@ -2416,13 +2398,9 @@ async function* streamable2(stream) {
|
|
2416
2398
|
}
|
2417
2399
|
function CohereStream(reader, callbacks) {
|
2418
2400
|
if (Symbol.asyncIterator in reader) {
|
2419
|
-
return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2420
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2421
|
-
);
|
2401
|
+
return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2422
2402
|
} else {
|
2423
|
-
return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2424
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2425
|
-
);
|
2403
|
+
return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2426
2404
|
}
|
2427
2405
|
}
|
2428
2406
|
|
@@ -2441,7 +2419,7 @@ async function* streamable3(response) {
|
|
2441
2419
|
}
|
2442
2420
|
}
|
2443
2421
|
function GoogleGenerativeAIStream(response, cb) {
|
2444
|
-
return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(
|
2422
|
+
return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
|
2445
2423
|
}
|
2446
2424
|
|
2447
2425
|
// streams/huggingface-stream.ts
|
@@ -2469,9 +2447,7 @@ function createParser3(res) {
|
|
2469
2447
|
});
|
2470
2448
|
}
|
2471
2449
|
function HuggingFaceStream(res, callbacks) {
|
2472
|
-
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2473
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2474
|
-
);
|
2450
|
+
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2475
2451
|
}
|
2476
2452
|
|
2477
2453
|
// streams/inkeep-stream.ts
|
@@ -2508,7 +2484,7 @@ function InkeepStream(res, callbacks) {
|
|
2508
2484
|
}
|
2509
2485
|
};
|
2510
2486
|
return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
|
2511
|
-
createStreamDataTransformer(
|
2487
|
+
createStreamDataTransformer()
|
2512
2488
|
);
|
2513
2489
|
}
|
2514
2490
|
|
@@ -2533,9 +2509,7 @@ function LangChainStream(callbacks) {
|
|
2533
2509
|
}
|
2534
2510
|
};
|
2535
2511
|
return {
|
2536
|
-
stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2537
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2538
|
-
),
|
2512
|
+
stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer()),
|
2539
2513
|
writer,
|
2540
2514
|
handlers: {
|
2541
2515
|
handleLLMNewToken: async (token) => {
|
@@ -2586,9 +2560,7 @@ async function* streamable4(stream) {
|
|
2586
2560
|
}
|
2587
2561
|
function MistralStream(response, callbacks) {
|
2588
2562
|
const stream = readableFromAsyncIterable(streamable4(response));
|
2589
|
-
return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2590
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2591
|
-
);
|
2563
|
+
return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2592
2564
|
}
|
2593
2565
|
|
2594
2566
|
// streams/openai-stream.ts
|
@@ -2732,9 +2704,7 @@ function OpenAIStream(res, callbacks) {
|
|
2732
2704
|
const functionCallTransformer = createFunctionCallTransformer(cb);
|
2733
2705
|
return stream.pipeThrough(functionCallTransformer);
|
2734
2706
|
} else {
|
2735
|
-
return stream.pipeThrough(
|
2736
|
-
createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
|
2737
|
-
);
|
2707
|
+
return stream.pipeThrough(createStreamDataTransformer());
|
2738
2708
|
}
|
2739
2709
|
}
|
2740
2710
|
function createFunctionCallTransformer(callbacks) {
|
@@ -2744,7 +2714,6 @@ function createFunctionCallTransformer(callbacks) {
|
|
2744
2714
|
let aggregatedFinalCompletionResponse = "";
|
2745
2715
|
let isFunctionStreamingIn = false;
|
2746
2716
|
let functionCallMessages = callbacks[__internal__OpenAIFnMessagesSymbol] || [];
|
2747
|
-
const isComplexMode = callbacks == null ? void 0 : callbacks.experimental_streamData;
|
2748
2717
|
const decode = createChunkDecoder();
|
2749
2718
|
return new TransformStream({
|
2750
2719
|
async transform(chunk, controller) {
|
@@ -2759,7 +2728,7 @@ function createFunctionCallTransformer(callbacks) {
|
|
2759
2728
|
}
|
2760
2729
|
if (!isFunctionStreamingIn) {
|
2761
2730
|
controller.enqueue(
|
2762
|
-
|
2731
|
+
textEncoder.encode(formatStreamPart("text", message))
|
2763
2732
|
);
|
2764
2733
|
return;
|
2765
2734
|
} else {
|
@@ -2870,17 +2839,17 @@ function createFunctionCallTransformer(callbacks) {
|
|
2870
2839
|
if (!functionResponse) {
|
2871
2840
|
controller.enqueue(
|
2872
2841
|
textEncoder.encode(
|
2873
|
-
|
2842
|
+
formatStreamPart(
|
2874
2843
|
payload.function_call ? "function_call" : "tool_calls",
|
2875
2844
|
// parse to prevent double-encoding:
|
2876
2845
|
JSON.parse(aggregatedResponse)
|
2877
|
-
)
|
2846
|
+
)
|
2878
2847
|
)
|
2879
2848
|
);
|
2880
2849
|
return;
|
2881
2850
|
} else if (typeof functionResponse === "string") {
|
2882
2851
|
controller.enqueue(
|
2883
|
-
|
2852
|
+
textEncoder.encode(formatStreamPart("text", functionResponse))
|
2884
2853
|
);
|
2885
2854
|
aggregatedFinalCompletionResponse = functionResponse;
|
2886
2855
|
return;
|
@@ -2930,7 +2899,7 @@ async function ReplicateStream(res, cb, options) {
|
|
2930
2899
|
}
|
2931
2900
|
});
|
2932
2901
|
return AIStream(eventStream, void 0, cb).pipeThrough(
|
2933
|
-
createStreamDataTransformer(
|
2902
|
+
createStreamDataTransformer()
|
2934
2903
|
);
|
2935
2904
|
}
|
2936
2905
|
|
@@ -3091,74 +3060,41 @@ async function parseComplexResponse({
|
|
3091
3060
|
// streams/streaming-react-response.ts
|
3092
3061
|
var experimental_StreamingReactResponse = class {
|
3093
3062
|
constructor(res, options) {
|
3094
|
-
var _a;
|
3063
|
+
var _a, _b;
|
3095
3064
|
let resolveFunc = () => {
|
3096
3065
|
};
|
3097
3066
|
let next = new Promise((resolve) => {
|
3098
3067
|
resolveFunc = resolve;
|
3099
3068
|
});
|
3100
|
-
|
3101
|
-
|
3102
|
-
|
3103
|
-
)
|
3104
|
-
|
3105
|
-
|
3106
|
-
|
3107
|
-
|
3108
|
-
|
3109
|
-
|
3110
|
-
|
3111
|
-
|
3112
|
-
|
3113
|
-
|
3114
|
-
|
3115
|
-
|
3116
|
-
|
3117
|
-
|
3118
|
-
|
3069
|
+
const processedStream = (options == null ? void 0 : options.data) != null ? res.pipeThrough((_a = options == null ? void 0 : options.data) == null ? void 0 : _a.stream) : res;
|
3070
|
+
let lastPayload = void 0;
|
3071
|
+
parseComplexResponse({
|
3072
|
+
reader: processedStream.getReader(),
|
3073
|
+
update: (merged, data) => {
|
3074
|
+
var _a2, _b2, _c;
|
3075
|
+
const content = (_b2 = (_a2 = merged[0]) == null ? void 0 : _a2.content) != null ? _b2 : "";
|
3076
|
+
const ui = ((_c = options == null ? void 0 : options.ui) == null ? void 0 : _c.call(options, { content, data })) || content;
|
3077
|
+
const payload = { ui, content };
|
3078
|
+
const resolvePrevious = resolveFunc;
|
3079
|
+
const nextRow = new Promise((resolve) => {
|
3080
|
+
resolveFunc = resolve;
|
3081
|
+
});
|
3082
|
+
resolvePrevious({
|
3083
|
+
next: nextRow,
|
3084
|
+
...payload
|
3085
|
+
});
|
3086
|
+
lastPayload = payload;
|
3087
|
+
},
|
3088
|
+
generateId: (_b = options == null ? void 0 : options.generateId) != null ? _b : generateId,
|
3089
|
+
onFinish: () => {
|
3090
|
+
if (lastPayload !== void 0) {
|
3091
|
+
resolveFunc({
|
3092
|
+
next: null,
|
3093
|
+
...lastPayload
|
3119
3094
|
});
|
3120
|
-
lastPayload = payload;
|
3121
|
-
},
|
3122
|
-
generateId: (_a = options.generateId) != null ? _a : generateId,
|
3123
|
-
onFinish: () => {
|
3124
|
-
if (lastPayload !== void 0) {
|
3125
|
-
resolveFunc({
|
3126
|
-
next: null,
|
3127
|
-
...lastPayload
|
3128
|
-
});
|
3129
|
-
}
|
3130
3095
|
}
|
3131
|
-
});
|
3132
|
-
return next;
|
3133
|
-
}
|
3134
|
-
let content = "";
|
3135
|
-
const decode = createChunkDecoder();
|
3136
|
-
const reader = res.getReader();
|
3137
|
-
async function readChunk() {
|
3138
|
-
var _a2;
|
3139
|
-
const { done, value } = await reader.read();
|
3140
|
-
if (!done) {
|
3141
|
-
content += decode(value);
|
3142
3096
|
}
|
3143
|
-
|
3144
|
-
const payload = {
|
3145
|
-
ui,
|
3146
|
-
content
|
3147
|
-
};
|
3148
|
-
const resolvePrevious = resolveFunc;
|
3149
|
-
const nextRow = done ? null : new Promise((resolve) => {
|
3150
|
-
resolveFunc = resolve;
|
3151
|
-
});
|
3152
|
-
resolvePrevious({
|
3153
|
-
next: nextRow,
|
3154
|
-
...payload
|
3155
|
-
});
|
3156
|
-
if (done) {
|
3157
|
-
return;
|
3158
|
-
}
|
3159
|
-
await readChunk();
|
3160
|
-
}
|
3161
|
-
readChunk();
|
3097
|
+
});
|
3162
3098
|
return next;
|
3163
3099
|
}
|
3164
3100
|
};
|
@@ -3175,7 +3111,6 @@ var StreamingTextResponse = class extends Response {
|
|
3175
3111
|
status: 200,
|
3176
3112
|
headers: {
|
3177
3113
|
"Content-Type": "text/plain; charset=utf-8",
|
3178
|
-
[COMPLEX_HEADER]: data ? "true" : "false",
|
3179
3114
|
...init == null ? void 0 : init.headers
|
3180
3115
|
}
|
3181
3116
|
});
|
@@ -3207,7 +3142,7 @@ export {
|
|
3207
3142
|
AWSBedrockLlama2Stream,
|
3208
3143
|
AWSBedrockStream,
|
3209
3144
|
AnthropicStream,
|
3210
|
-
|
3145
|
+
AssistantResponse,
|
3211
3146
|
CohereStream,
|
3212
3147
|
GenerateObjectResult,
|
3213
3148
|
GenerateTextResult,
|
@@ -3218,6 +3153,7 @@ export {
|
|
3218
3153
|
MistralStream,
|
3219
3154
|
OpenAIStream,
|
3220
3155
|
ReplicateStream,
|
3156
|
+
StreamData,
|
3221
3157
|
StreamObjectResult,
|
3222
3158
|
StreamTextResult,
|
3223
3159
|
StreamingTextResponse,
|