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.d.ts
CHANGED
@@ -80,13 +80,13 @@ type LanguageModelV1CallSettings = {
|
|
80
80
|
};
|
81
81
|
|
82
82
|
/**
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
83
|
+
A prompt is a list of messages.
|
84
|
+
|
85
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
86
|
+
tool calls. The validation happens at runtime.
|
87
|
+
|
88
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
89
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
90
90
|
*/
|
91
91
|
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
92
92
|
type LanguageModelV1Message = {
|
@@ -102,35 +102,69 @@ type LanguageModelV1Message = {
|
|
102
102
|
role: 'tool';
|
103
103
|
content: Array<LanguageModelV1ToolResultPart>;
|
104
104
|
};
|
105
|
+
/**
|
106
|
+
Text content part of a prompt. It contains a string of text.
|
107
|
+
*/
|
105
108
|
interface LanguageModelV1TextPart {
|
106
109
|
type: 'text';
|
107
110
|
/**
|
108
|
-
|
111
|
+
The text content.
|
109
112
|
*/
|
110
113
|
text: string;
|
111
114
|
}
|
115
|
+
/**
|
116
|
+
Image content part of a prompt. It contains an image.
|
117
|
+
*/
|
112
118
|
interface LanguageModelV1ImagePart {
|
113
119
|
type: 'image';
|
114
120
|
/**
|
115
|
-
|
121
|
+
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
116
122
|
*/
|
117
123
|
image: Uint8Array | URL;
|
118
124
|
/**
|
119
|
-
|
125
|
+
Optional mime type of the image.
|
120
126
|
*/
|
121
127
|
mimeType?: string;
|
122
128
|
}
|
129
|
+
/**
|
130
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
131
|
+
*/
|
123
132
|
interface LanguageModelV1ToolCallPart {
|
124
133
|
type: 'tool-call';
|
134
|
+
/**
|
135
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
136
|
+
*/
|
125
137
|
toolCallId: string;
|
138
|
+
/**
|
139
|
+
Name of the tool that is being called.
|
140
|
+
*/
|
126
141
|
toolName: string;
|
142
|
+
/**
|
143
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
144
|
+
*/
|
127
145
|
args: unknown;
|
128
146
|
}
|
147
|
+
/**
|
148
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
149
|
+
*/
|
129
150
|
interface LanguageModelV1ToolResultPart {
|
130
151
|
type: 'tool-result';
|
152
|
+
/**
|
153
|
+
ID of the tool call that this result is associated with.
|
154
|
+
*/
|
131
155
|
toolCallId: string;
|
156
|
+
/**
|
157
|
+
Name of the tool that generated this result.
|
158
|
+
*/
|
132
159
|
toolName: string;
|
160
|
+
/**
|
161
|
+
Result of the tool call. This is a JSON-serializable object.
|
162
|
+
*/
|
133
163
|
result: unknown;
|
164
|
+
/**
|
165
|
+
Optional flag if the result is an error or an error message.
|
166
|
+
*/
|
167
|
+
isError?: boolean;
|
134
168
|
}
|
135
169
|
|
136
170
|
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
@@ -470,6 +504,10 @@ interface ToolResultPart {
|
|
470
504
|
Result of the tool call. This is a JSON-serializable object.
|
471
505
|
*/
|
472
506
|
result: unknown;
|
507
|
+
/**
|
508
|
+
Optional flag if the result is an error or an error message.
|
509
|
+
*/
|
510
|
+
isError?: boolean;
|
473
511
|
}
|
474
512
|
|
475
513
|
/**
|
@@ -1350,10 +1388,6 @@ declare function createChunkDecoder(complex?: boolean): (chunk: Uint8Array | und
|
|
1350
1388
|
|
1351
1389
|
declare const isStreamStringEqualToType: (type: keyof typeof StreamStringPrefixes, value: string) => value is `0:${string}\n` | `1:${string}\n` | `2:${string}\n` | `3:${string}\n` | `4:${string}\n` | `5:${string}\n` | `6:${string}\n` | `7:${string}\n` | `8:${string}\n`;
|
1352
1390
|
type StreamString = `${(typeof StreamStringPrefixes)[keyof typeof StreamStringPrefixes]}:${string}\n`;
|
1353
|
-
/**
|
1354
|
-
* A header sent to the client so it knows how to handle parsing the stream (as a deprecated text response or using the new prefixed protocol)
|
1355
|
-
*/
|
1356
|
-
declare const COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
1357
1391
|
|
1358
1392
|
declare interface AzureChatCompletions {
|
1359
1393
|
id: string;
|
@@ -1607,10 +1641,8 @@ interface AIStreamCallbacksAndOptions {
|
|
1607
1641
|
/** `onText`: Called for each text chunk. */
|
1608
1642
|
onText?: (text: string) => Promise<void> | void;
|
1609
1643
|
/**
|
1610
|
-
*
|
1611
|
-
*
|
1612
|
-
*
|
1613
|
-
* When StreamData is rolled out, this will be removed and the new protocol will be used by default.
|
1644
|
+
* @deprecated This flag is no longer used and only retained for backwards compatibility.
|
1645
|
+
* You can remove it from your code.
|
1614
1646
|
*/
|
1615
1647
|
experimental_streamData?: boolean;
|
1616
1648
|
}
|
@@ -1797,18 +1829,54 @@ interface MessageStopEvent {
|
|
1797
1829
|
*/
|
1798
1830
|
declare function AnthropicStream(res: Response | AsyncIterable<CompletionChunk> | AsyncIterable<MessageStreamEvent>, cb?: AIStreamCallbacksAndOptions): ReadableStream;
|
1799
1831
|
|
1832
|
+
/**
|
1833
|
+
You can pass the thread and the latest message into the `AssistantResponse`. This establishes the context for the response.
|
1834
|
+
*/
|
1800
1835
|
type AssistantResponseSettings = {
|
1836
|
+
/**
|
1837
|
+
The thread ID that the response is associated with.
|
1838
|
+
*/
|
1801
1839
|
threadId: string;
|
1840
|
+
/**
|
1841
|
+
The ID of the latest message that the response is associated with.
|
1842
|
+
*/
|
1802
1843
|
messageId: string;
|
1803
1844
|
};
|
1845
|
+
/**
|
1846
|
+
The process parameter is a callback in which you can run the assistant on threads, and send messages and data messages to the client.
|
1847
|
+
*/
|
1804
1848
|
type AssistantResponseCallback = (options: {
|
1849
|
+
/**
|
1850
|
+
@deprecated use variable from outer scope instead.
|
1851
|
+
*/
|
1805
1852
|
threadId: string;
|
1853
|
+
/**
|
1854
|
+
@deprecated use variable from outer scope instead.
|
1855
|
+
*/
|
1806
1856
|
messageId: string;
|
1857
|
+
/**
|
1858
|
+
Forwards an assistant message (non-streaming) to the client.
|
1859
|
+
*/
|
1807
1860
|
sendMessage: (message: AssistantMessage) => void;
|
1861
|
+
/**
|
1862
|
+
Send a data message to the client. You can use this to provide information for rendering custom UIs while the assistant is processing the thread.
|
1863
|
+
*/
|
1808
1864
|
sendDataMessage: (message: DataMessage) => void;
|
1865
|
+
/**
|
1866
|
+
Forwards the assistant response stream to the client. Returns the `Run` object after it completes, or when it requires an action.
|
1867
|
+
*/
|
1809
1868
|
forwardStream: (stream: AssistantStream) => Promise<Run | undefined>;
|
1810
1869
|
}) => Promise<void>;
|
1811
|
-
|
1870
|
+
/**
|
1871
|
+
The `AssistantResponse` allows you to send a stream of assistant update to `useAssistant`.
|
1872
|
+
It is designed to facilitate streaming assistant responses to the `useAssistant` hook.
|
1873
|
+
It receives an assistant thread and a current message, and can send messages and data messages to the client.
|
1874
|
+
*/
|
1875
|
+
declare function AssistantResponse({ threadId, messageId }: AssistantResponseSettings, process: AssistantResponseCallback): Response;
|
1876
|
+
/**
|
1877
|
+
@deprecated Use `AssistantResponse` instead.
|
1878
|
+
*/
|
1879
|
+
declare const experimental_AssistantResponse: typeof AssistantResponse;
|
1812
1880
|
|
1813
1881
|
interface AWSBedrockResponse {
|
1814
1882
|
body?: AsyncIterable<{
|
@@ -1933,7 +2001,7 @@ declare function ReplicateStream(res: Prediction, cb?: AIStreamCallbacksAndOptio
|
|
1933
2001
|
/**
|
1934
2002
|
* A stream wrapper to send custom JSON-encoded data back to the client.
|
1935
2003
|
*/
|
1936
|
-
declare class
|
2004
|
+
declare class StreamData {
|
1937
2005
|
private encoder;
|
1938
2006
|
private controller;
|
1939
2007
|
stream: TransformStream<Uint8Array, Uint8Array>;
|
@@ -1951,7 +2019,12 @@ declare class experimental_StreamData {
|
|
1951
2019
|
* A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
|
1952
2020
|
* This assumes every chunk is a 'text' chunk.
|
1953
2021
|
*/
|
1954
|
-
declare function createStreamDataTransformer(
|
2022
|
+
declare function createStreamDataTransformer(): TransformStream<any, any>;
|
2023
|
+
/**
|
2024
|
+
@deprecated Use `StreamData` instead.
|
2025
|
+
*/
|
2026
|
+
declare class experimental_StreamData extends StreamData {
|
2027
|
+
}
|
1955
2028
|
|
1956
2029
|
/**
|
1957
2030
|
* This is a naive implementation of the streaming React response API.
|
@@ -1980,7 +2053,7 @@ declare class experimental_StreamingReactResponse {
|
|
1980
2053
|
content: string;
|
1981
2054
|
data?: JSONValue[];
|
1982
2055
|
}) => UINode | Promise<UINode>;
|
1983
|
-
data?:
|
2056
|
+
data?: StreamData;
|
1984
2057
|
generateId?: IdGenerator;
|
1985
2058
|
});
|
1986
2059
|
}
|
@@ -1989,7 +2062,7 @@ declare class experimental_StreamingReactResponse {
|
|
1989
2062
|
* A utility class for streaming text responses.
|
1990
2063
|
*/
|
1991
2064
|
declare class StreamingTextResponse extends Response {
|
1992
|
-
constructor(res: ReadableStream, init?: ResponseInit, data?:
|
2065
|
+
constructor(res: ReadableStream, init?: ResponseInit, data?: StreamData);
|
1993
2066
|
}
|
1994
2067
|
/**
|
1995
2068
|
* A utility function to stream a ReadableStream to a Node.js response-like object.
|
@@ -1999,4 +2072,4 @@ declare function streamToResponse(res: ReadableStream, response: ServerResponse,
|
|
1999
2072
|
status?: number;
|
2000
2073
|
}): void;
|
2001
2074
|
|
2002
|
-
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantMessage,
|
2075
|
+
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantMessage, AssistantResponse, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataContent, DataMessage, DeepPartial, ErrorStreamPart, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamData, StreamObjectResult, StreamString, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, Tool, ToolCall, ToolCallHandler, ToolCallPart, ToolCallPayload, ToolChoice, ToolContent, ToolResultPart, UseChatOptions, UseCompletionOptions, UserContent, convertDataContentToBase64String, convertDataContentToUint8Array, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, isStreamStringEqualToType, generateId as nanoid, readableFromAsyncIterable, streamToResponse, tool, trimStartOfStreamHelper };
|
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,
|
@@ -1815,9 +1816,7 @@ var StreamTextResult = class {
|
|
1815
1816
|
@returns an `AIStream` object.
|
1816
1817
|
*/
|
1817
1818
|
toAIStream(callbacks) {
|
1818
|
-
return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
1819
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
1820
|
-
);
|
1819
|
+
return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
1821
1820
|
}
|
1822
1821
|
};
|
1823
1822
|
|
@@ -2022,7 +2021,6 @@ function createChunkDecoder(complex) {
|
|
2022
2021
|
};
|
2023
2022
|
}
|
2024
2023
|
var isStreamStringEqualToType = (type, value) => value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith("\n");
|
2025
|
-
var COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
2026
2024
|
|
2027
2025
|
// streams/ai-stream.ts
|
2028
2026
|
var import_eventsource_parser = require("eventsource-parser");
|
@@ -2147,7 +2145,7 @@ function readableFromAsyncIterable(iterable) {
|
|
2147
2145
|
}
|
2148
2146
|
|
2149
2147
|
// streams/stream-data.ts
|
2150
|
-
var
|
2148
|
+
var StreamData = class {
|
2151
2149
|
constructor() {
|
2152
2150
|
this.encoder = new TextEncoder();
|
2153
2151
|
this.controller = null;
|
@@ -2233,14 +2231,7 @@ var experimental_StreamData = class {
|
|
2233
2231
|
this.messageAnnotations.push(value);
|
2234
2232
|
}
|
2235
2233
|
};
|
2236
|
-
function createStreamDataTransformer(
|
2237
|
-
if (!experimental_streamData) {
|
2238
|
-
return new TransformStream({
|
2239
|
-
transform: async (chunk, controller) => {
|
2240
|
-
controller.enqueue(chunk);
|
2241
|
-
}
|
2242
|
-
});
|
2243
|
-
}
|
2234
|
+
function createStreamDataTransformer() {
|
2244
2235
|
const encoder = new TextEncoder();
|
2245
2236
|
const decoder = new TextDecoder();
|
2246
2237
|
return new TransformStream({
|
@@ -2250,6 +2241,8 @@ function createStreamDataTransformer(experimental_streamData) {
|
|
2250
2241
|
}
|
2251
2242
|
});
|
2252
2243
|
}
|
2244
|
+
var experimental_StreamData = class extends StreamData {
|
2245
|
+
};
|
2253
2246
|
|
2254
2247
|
// streams/anthropic-stream.ts
|
2255
2248
|
function parseAnthropicStream() {
|
@@ -2289,16 +2282,16 @@ async function* streamable(stream) {
|
|
2289
2282
|
}
|
2290
2283
|
function AnthropicStream(res, cb) {
|
2291
2284
|
if (Symbol.asyncIterator in res) {
|
2292
|
-
return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(
|
2285
|
+
return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
|
2293
2286
|
} else {
|
2294
2287
|
return AIStream(res, parseAnthropicStream(), cb).pipeThrough(
|
2295
|
-
createStreamDataTransformer(
|
2288
|
+
createStreamDataTransformer()
|
2296
2289
|
);
|
2297
2290
|
}
|
2298
2291
|
}
|
2299
2292
|
|
2300
2293
|
// streams/assistant-response.ts
|
2301
|
-
function
|
2294
|
+
function AssistantResponse({ threadId, messageId }, process2) {
|
2302
2295
|
const stream = new ReadableStream({
|
2303
2296
|
async start(controller) {
|
2304
2297
|
var _a;
|
@@ -2389,6 +2382,7 @@ function experimental_AssistantResponse({ threadId, messageId }, process2) {
|
|
2389
2382
|
}
|
2390
2383
|
});
|
2391
2384
|
}
|
2385
|
+
var experimental_AssistantResponse = AssistantResponse;
|
2392
2386
|
|
2393
2387
|
// streams/aws-bedrock-stream.ts
|
2394
2388
|
async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
@@ -2416,16 +2410,7 @@ function AWSBedrockAnthropicStream(response, callbacks) {
|
|
2416
2410
|
return AWSBedrockStream(response, callbacks, (chunk) => chunk.completion);
|
2417
2411
|
}
|
2418
2412
|
function AWSBedrockCohereStream(response, callbacks) {
|
2419
|
-
return AWSBedrockStream(
|
2420
|
-
response,
|
2421
|
-
callbacks,
|
2422
|
-
// As of 2023-11-17, Bedrock does not support streaming for Cohere,
|
2423
|
-
// so we take the full generation:
|
2424
|
-
(chunk) => {
|
2425
|
-
var _a, _b;
|
2426
|
-
return (_b = (_a = chunk.generations) == null ? void 0 : _a[0]) == null ? void 0 : _b.text;
|
2427
|
-
}
|
2428
|
-
);
|
2413
|
+
return AWSBedrockStream(response, callbacks, (chunk) => chunk == null ? void 0 : chunk.text);
|
2429
2414
|
}
|
2430
2415
|
function AWSBedrockLlama2Stream(response, callbacks) {
|
2431
2416
|
return AWSBedrockStream(response, callbacks, (chunk) => chunk.generation);
|
@@ -2433,9 +2418,7 @@ function AWSBedrockLlama2Stream(response, callbacks) {
|
|
2433
2418
|
function AWSBedrockStream(response, callbacks, extractTextDeltaFromChunk) {
|
2434
2419
|
return readableFromAsyncIterable(
|
2435
2420
|
asDeltaIterable(response, extractTextDeltaFromChunk)
|
2436
|
-
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2437
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2438
|
-
);
|
2421
|
+
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2439
2422
|
}
|
2440
2423
|
|
2441
2424
|
// streams/cohere-stream.ts
|
@@ -2490,13 +2473,9 @@ async function* streamable2(stream) {
|
|
2490
2473
|
}
|
2491
2474
|
function CohereStream(reader, callbacks) {
|
2492
2475
|
if (Symbol.asyncIterator in reader) {
|
2493
|
-
return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2494
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2495
|
-
);
|
2476
|
+
return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2496
2477
|
} else {
|
2497
|
-
return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2498
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2499
|
-
);
|
2478
|
+
return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2500
2479
|
}
|
2501
2480
|
}
|
2502
2481
|
|
@@ -2515,7 +2494,7 @@ async function* streamable3(response) {
|
|
2515
2494
|
}
|
2516
2495
|
}
|
2517
2496
|
function GoogleGenerativeAIStream(response, cb) {
|
2518
|
-
return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(
|
2497
|
+
return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
|
2519
2498
|
}
|
2520
2499
|
|
2521
2500
|
// streams/huggingface-stream.ts
|
@@ -2543,9 +2522,7 @@ function createParser3(res) {
|
|
2543
2522
|
});
|
2544
2523
|
}
|
2545
2524
|
function HuggingFaceStream(res, callbacks) {
|
2546
|
-
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2547
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2548
|
-
);
|
2525
|
+
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2549
2526
|
}
|
2550
2527
|
|
2551
2528
|
// streams/inkeep-stream.ts
|
@@ -2582,7 +2559,7 @@ function InkeepStream(res, callbacks) {
|
|
2582
2559
|
}
|
2583
2560
|
};
|
2584
2561
|
return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
|
2585
|
-
createStreamDataTransformer(
|
2562
|
+
createStreamDataTransformer()
|
2586
2563
|
);
|
2587
2564
|
}
|
2588
2565
|
|
@@ -2607,9 +2584,7 @@ function LangChainStream(callbacks) {
|
|
2607
2584
|
}
|
2608
2585
|
};
|
2609
2586
|
return {
|
2610
|
-
stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2611
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2612
|
-
),
|
2587
|
+
stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer()),
|
2613
2588
|
writer,
|
2614
2589
|
handlers: {
|
2615
2590
|
handleLLMNewToken: async (token) => {
|
@@ -2660,9 +2635,7 @@ async function* streamable4(stream) {
|
|
2660
2635
|
}
|
2661
2636
|
function MistralStream(response, callbacks) {
|
2662
2637
|
const stream = readableFromAsyncIterable(streamable4(response));
|
2663
|
-
return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
|
2664
|
-
createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
|
2665
|
-
);
|
2638
|
+
return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
2666
2639
|
}
|
2667
2640
|
|
2668
2641
|
// streams/openai-stream.ts
|
@@ -2806,9 +2779,7 @@ function OpenAIStream(res, callbacks) {
|
|
2806
2779
|
const functionCallTransformer = createFunctionCallTransformer(cb);
|
2807
2780
|
return stream.pipeThrough(functionCallTransformer);
|
2808
2781
|
} else {
|
2809
|
-
return stream.pipeThrough(
|
2810
|
-
createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
|
2811
|
-
);
|
2782
|
+
return stream.pipeThrough(createStreamDataTransformer());
|
2812
2783
|
}
|
2813
2784
|
}
|
2814
2785
|
function createFunctionCallTransformer(callbacks) {
|
@@ -2818,7 +2789,6 @@ function createFunctionCallTransformer(callbacks) {
|
|
2818
2789
|
let aggregatedFinalCompletionResponse = "";
|
2819
2790
|
let isFunctionStreamingIn = false;
|
2820
2791
|
let functionCallMessages = callbacks[__internal__OpenAIFnMessagesSymbol] || [];
|
2821
|
-
const isComplexMode = callbacks == null ? void 0 : callbacks.experimental_streamData;
|
2822
2792
|
const decode = createChunkDecoder();
|
2823
2793
|
return new TransformStream({
|
2824
2794
|
async transform(chunk, controller) {
|
@@ -2833,7 +2803,7 @@ function createFunctionCallTransformer(callbacks) {
|
|
2833
2803
|
}
|
2834
2804
|
if (!isFunctionStreamingIn) {
|
2835
2805
|
controller.enqueue(
|
2836
|
-
|
2806
|
+
textEncoder.encode(formatStreamPart("text", message))
|
2837
2807
|
);
|
2838
2808
|
return;
|
2839
2809
|
} else {
|
@@ -2944,17 +2914,17 @@ function createFunctionCallTransformer(callbacks) {
|
|
2944
2914
|
if (!functionResponse) {
|
2945
2915
|
controller.enqueue(
|
2946
2916
|
textEncoder.encode(
|
2947
|
-
|
2917
|
+
formatStreamPart(
|
2948
2918
|
payload.function_call ? "function_call" : "tool_calls",
|
2949
2919
|
// parse to prevent double-encoding:
|
2950
2920
|
JSON.parse(aggregatedResponse)
|
2951
|
-
)
|
2921
|
+
)
|
2952
2922
|
)
|
2953
2923
|
);
|
2954
2924
|
return;
|
2955
2925
|
} else if (typeof functionResponse === "string") {
|
2956
2926
|
controller.enqueue(
|
2957
|
-
|
2927
|
+
textEncoder.encode(formatStreamPart("text", functionResponse))
|
2958
2928
|
);
|
2959
2929
|
aggregatedFinalCompletionResponse = functionResponse;
|
2960
2930
|
return;
|
@@ -3004,7 +2974,7 @@ async function ReplicateStream(res, cb, options) {
|
|
3004
2974
|
}
|
3005
2975
|
});
|
3006
2976
|
return AIStream(eventStream, void 0, cb).pipeThrough(
|
3007
|
-
createStreamDataTransformer(
|
2977
|
+
createStreamDataTransformer()
|
3008
2978
|
);
|
3009
2979
|
}
|
3010
2980
|
|
@@ -3165,74 +3135,41 @@ async function parseComplexResponse({
|
|
3165
3135
|
// streams/streaming-react-response.ts
|
3166
3136
|
var experimental_StreamingReactResponse = class {
|
3167
3137
|
constructor(res, options) {
|
3168
|
-
var _a;
|
3138
|
+
var _a, _b;
|
3169
3139
|
let resolveFunc = () => {
|
3170
3140
|
};
|
3171
3141
|
let next = new Promise((resolve) => {
|
3172
3142
|
resolveFunc = resolve;
|
3173
3143
|
});
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
)
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
3185
|
-
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
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
|
3193
3169
|
});
|
3194
|
-
lastPayload = payload;
|
3195
|
-
},
|
3196
|
-
generateId: (_a = options.generateId) != null ? _a : generateId,
|
3197
|
-
onFinish: () => {
|
3198
|
-
if (lastPayload !== void 0) {
|
3199
|
-
resolveFunc({
|
3200
|
-
next: null,
|
3201
|
-
...lastPayload
|
3202
|
-
});
|
3203
|
-
}
|
3204
3170
|
}
|
3205
|
-
});
|
3206
|
-
return next;
|
3207
|
-
}
|
3208
|
-
let content = "";
|
3209
|
-
const decode = createChunkDecoder();
|
3210
|
-
const reader = res.getReader();
|
3211
|
-
async function readChunk() {
|
3212
|
-
var _a2;
|
3213
|
-
const { done, value } = await reader.read();
|
3214
|
-
if (!done) {
|
3215
|
-
content += decode(value);
|
3216
3171
|
}
|
3217
|
-
|
3218
|
-
const payload = {
|
3219
|
-
ui,
|
3220
|
-
content
|
3221
|
-
};
|
3222
|
-
const resolvePrevious = resolveFunc;
|
3223
|
-
const nextRow = done ? null : new Promise((resolve) => {
|
3224
|
-
resolveFunc = resolve;
|
3225
|
-
});
|
3226
|
-
resolvePrevious({
|
3227
|
-
next: nextRow,
|
3228
|
-
...payload
|
3229
|
-
});
|
3230
|
-
if (done) {
|
3231
|
-
return;
|
3232
|
-
}
|
3233
|
-
await readChunk();
|
3234
|
-
}
|
3235
|
-
readChunk();
|
3172
|
+
});
|
3236
3173
|
return next;
|
3237
3174
|
}
|
3238
3175
|
};
|
@@ -3249,7 +3186,6 @@ var StreamingTextResponse = class extends Response {
|
|
3249
3186
|
status: 200,
|
3250
3187
|
headers: {
|
3251
3188
|
"Content-Type": "text/plain; charset=utf-8",
|
3252
|
-
[COMPLEX_HEADER]: data ? "true" : "false",
|
3253
3189
|
...init == null ? void 0 : init.headers
|
3254
3190
|
}
|
3255
3191
|
});
|
@@ -3282,7 +3218,7 @@ function streamToResponse(res, response, init) {
|
|
3282
3218
|
AWSBedrockLlama2Stream,
|
3283
3219
|
AWSBedrockStream,
|
3284
3220
|
AnthropicStream,
|
3285
|
-
|
3221
|
+
AssistantResponse,
|
3286
3222
|
CohereStream,
|
3287
3223
|
GenerateObjectResult,
|
3288
3224
|
GenerateTextResult,
|
@@ -3293,6 +3229,7 @@ function streamToResponse(res, response, init) {
|
|
3293
3229
|
MistralStream,
|
3294
3230
|
OpenAIStream,
|
3295
3231
|
ReplicateStream,
|
3232
|
+
StreamData,
|
3296
3233
|
StreamObjectResult,
|
3297
3234
|
StreamTextResult,
|
3298
3235
|
StreamingTextResponse,
|