assistant-stream 0.3.25 → 0.3.26
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/README.md +4 -1
- package/dist/core/AssistantStream.d.ts +0 -1
- package/dist/core/AssistantStream.d.ts.map +1 -1
- package/dist/core/AssistantStreamChunk.d.ts +24 -12
- package/dist/core/AssistantStreamChunk.d.ts.map +1 -1
- package/dist/core/accumulators/AssistantMessageStream.d.ts +0 -1
- package/dist/core/accumulators/AssistantMessageStream.d.ts.map +1 -1
- package/dist/core/accumulators/TimingTracker.d.ts +0 -1
- package/dist/core/accumulators/TimingTracker.d.ts.map +1 -1
- package/dist/core/accumulators/assistant-message-accumulator.d.ts +3 -9
- package/dist/core/accumulators/assistant-message-accumulator.d.ts.map +1 -1
- package/dist/core/accumulators/assistant-message-accumulator.js +6 -1
- package/dist/core/accumulators/assistant-message-accumulator.js.map +1 -1
- package/dist/core/converters/toGenericMessages.d.ts.map +1 -1
- package/dist/core/converters/toGenericMessages.js +2 -1
- package/dist/core/converters/toGenericMessages.js.map +1 -1
- package/dist/core/modules/assistant-stream.d.ts +13 -7
- package/dist/core/modules/assistant-stream.d.ts.map +1 -1
- package/dist/core/modules/text.d.ts +0 -1
- package/dist/core/modules/text.d.ts.map +1 -1
- package/dist/core/modules/tool-call.d.ts +0 -1
- package/dist/core/modules/tool-call.d.ts.map +1 -1
- package/dist/core/object/ObjectStreamAccumulator.d.ts +1 -1
- package/dist/core/object/ObjectStreamAccumulator.d.ts.map +1 -1
- package/dist/core/object/ObjectStreamResponse.d.ts +0 -1
- package/dist/core/object/ObjectStreamResponse.d.ts.map +1 -1
- package/dist/core/object/ObjectStreamResponse.js +1 -1
- package/dist/core/object/ObjectStreamResponse.js.map +1 -1
- package/dist/core/object/createObjectStream.d.ts +2 -5
- package/dist/core/object/createObjectStream.d.ts.map +1 -1
- package/dist/core/object/types.d.ts +1 -0
- package/dist/core/object/types.d.ts.map +1 -1
- package/dist/core/serialization/PlainText.d.ts +0 -1
- package/dist/core/serialization/PlainText.d.ts.map +1 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.d.ts +0 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.d.ts.map +1 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.js +2 -52
- package/dist/core/serialization/assistant-transport/AssistantTransport.js.map +1 -1
- package/dist/core/serialization/data-stream/DataStream.d.ts +0 -1
- package/dist/core/serialization/data-stream/DataStream.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/chunk-types.d.ts +1 -2
- package/dist/core/serialization/data-stream/chunk-types.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/serialization.d.ts +0 -1
- package/dist/core/serialization/data-stream/serialization.d.ts.map +1 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts +0 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts.map +1 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.js +66 -53
- package/dist/core/serialization/ui-message-stream/UIMessageStream.js.map +1 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.d.ts +0 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.d.ts.map +1 -1
- package/dist/core/tool/ToolCallReader.d.ts +1 -0
- package/dist/core/tool/ToolCallReader.d.ts.map +1 -1
- package/dist/core/tool/ToolExecutionStream.d.ts +0 -1
- package/dist/core/tool/ToolExecutionStream.d.ts.map +1 -1
- package/dist/core/tool/ToolResponse.d.ts +6 -4
- package/dist/core/tool/ToolResponse.d.ts.map +1 -1
- package/dist/core/tool/schema-utils.d.ts +0 -1
- package/dist/core/tool/schema-utils.d.ts.map +1 -1
- package/dist/core/tool/tool-types.d.ts +71 -33
- package/dist/core/tool/tool-types.d.ts.map +1 -1
- package/dist/core/tool/toolResultStream.d.ts +3 -2
- package/dist/core/tool/toolResultStream.d.ts.map +1 -1
- package/dist/core/tool/type-path-utils.d.ts +2 -2
- package/dist/core/tool/type-path-utils.d.ts.map +1 -1
- package/dist/core/utils/Counter.d.ts.map +1 -1
- package/dist/core/utils/generateId.d.ts.map +1 -1
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts +0 -1
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/AssistantTransformStream.d.ts +0 -1
- package/dist/core/utils/stream/AssistantTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/LineDecoderStream.d.ts +1 -0
- package/dist/core/utils/stream/LineDecoderStream.d.ts.map +1 -1
- package/dist/core/utils/stream/LineDecoderStream.js +19 -6
- package/dist/core/utils/stream/LineDecoderStream.js.map +1 -1
- package/dist/core/utils/stream/PipeableTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/SSE.d.ts +0 -1
- package/dist/core/utils/stream/SSE.d.ts.map +1 -1
- package/dist/core/utils/stream/SSE.js +2 -52
- package/dist/core/utils/stream/SSE.js.map +1 -1
- package/dist/core/utils/stream/SSEEventDecoder.d.ts +27 -0
- package/dist/core/utils/stream/SSEEventDecoder.d.ts.map +1 -0
- package/dist/core/utils/stream/SSEEventDecoder.js +84 -0
- package/dist/core/utils/stream/SSEEventDecoder.js.map +1 -0
- package/dist/core/utils/stream/SSEEventDecoderStream.d.ts +13 -0
- package/dist/core/utils/stream/SSEEventDecoderStream.d.ts.map +1 -0
- package/dist/core/utils/stream/SSEEventDecoderStream.js +24 -0
- package/dist/core/utils/stream/SSEEventDecoderStream.js.map +1 -0
- package/dist/core/utils/stream/UnderlyingReadable.d.ts.map +1 -1
- package/dist/core/utils/stream/merge.d.ts +0 -1
- package/dist/core/utils/stream/merge.d.ts.map +1 -1
- package/dist/core/utils/stream/path-utils.d.ts +0 -1
- package/dist/core/utils/stream/path-utils.d.ts.map +1 -1
- package/dist/core/utils/types.d.ts +16 -8
- package/dist/core/utils/types.d.ts.map +1 -1
- package/dist/core/utils/withPromiseOrValue.d.ts.map +1 -1
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts +3 -3
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts.map +1 -1
- package/dist/resumable/ResumableStreamContext.d.ts +0 -1
- package/dist/resumable/ResumableStreamContext.d.ts.map +1 -1
- package/dist/resumable/constants.d.ts.map +1 -1
- package/dist/resumable/createResumableAssistantStreamResponse.d.ts +6 -4
- package/dist/resumable/createResumableAssistantStreamResponse.d.ts.map +1 -1
- package/dist/resumable/errors.d.ts.map +1 -1
- package/dist/resumable/stores/InMemoryResumableStreamStore.d.ts +0 -1
- package/dist/resumable/stores/InMemoryResumableStreamStore.d.ts.map +1 -1
- package/dist/resumable/stores/InMemoryResumableStreamStore.js +2 -1
- package/dist/resumable/stores/InMemoryResumableStreamStore.js.map +1 -1
- package/dist/resumable/stores/ioredis.d.ts +0 -1
- package/dist/resumable/stores/ioredis.d.ts.map +1 -1
- package/dist/resumable/stores/redis-impl.d.ts +2 -2
- package/dist/resumable/stores/redis-impl.d.ts.map +1 -1
- package/dist/resumable/stores/redis.d.ts +0 -1
- package/dist/resumable/stores/redis.d.ts.map +1 -1
- package/dist/resumable/types.d.ts.map +1 -1
- package/dist/utils/AsyncIterableStream.d.ts.map +1 -1
- package/dist/utils/json/fix-json.d.ts.map +1 -1
- package/dist/utils/json/json-value.d.ts.map +1 -1
- package/dist/utils/json/parse-partial-json-object.d.ts +0 -1
- package/dist/utils/json/parse-partial-json-object.d.ts.map +1 -1
- package/dist/utils/promiseWithResolvers.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +2 -1
- package/package.json +5 -5
- package/src/core/AssistantStreamChunk.ts +2 -0
- package/src/core/accumulators/assistant-message-accumulator.test.ts +63 -0
- package/src/core/accumulators/assistant-message-accumulator.ts +15 -1
- package/src/core/object/ObjectStream.test.ts +20 -0
- package/src/core/object/ObjectStreamResponse.test.ts +32 -0
- package/src/core/object/ObjectStreamResponse.ts +6 -1
- package/src/core/serialization/assistant-transport/AssistantTransport.test.ts +41 -0
- package/src/core/serialization/assistant-transport/AssistantTransport.ts +6 -70
- package/src/core/serialization/ui-message-stream/UIMessageStream.test.ts +212 -4
- package/src/core/serialization/ui-message-stream/UIMessageStream.ts +62 -71
- package/src/core/utils/stream/LineDecoderStream.test.ts +26 -2
- package/src/core/utils/stream/LineDecoderStream.ts +21 -11
- package/src/core/utils/stream/SSE.ts +6 -70
- package/src/core/utils/stream/SSEEventDecoder.test.ts +146 -0
- package/src/core/utils/stream/SSEEventDecoder.ts +109 -0
- package/src/core/utils/stream/SSEEventDecoderStream.test.ts +42 -0
- package/src/core/utils/stream/SSEEventDecoderStream.ts +34 -0
- package/src/utils.ts +4 -0
- package/dist/utils/json/is-json.d.ts +0 -9
- package/dist/utils/json/is-json.d.ts.map +0 -1
- package/dist/utils/json/is-json.js +0 -17
- package/dist/utils/json/is-json.js.map +0 -1
- package/src/utils/json/is-json.ts +0 -43
|
@@ -2,20 +2,25 @@ import { AsyncIterableStream } from "../../utils/AsyncIterableStream.js";
|
|
|
2
2
|
import { JSONSchema7 } from "../../node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.js";
|
|
3
3
|
import { DeepPartial, TypeAtPath, TypePath } from "./type-path-utils.js";
|
|
4
4
|
import { ToolResponse } from "./ToolResponse.js";
|
|
5
|
+
import "../../utils.js";
|
|
5
6
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
-
|
|
7
7
|
//#region src/core/tool/tool-types.d.ts
|
|
8
8
|
type ToolModelContentPart = {
|
|
9
|
-
/** A text content part returned to the model after a tool call. */
|
|
9
|
+
/** A text content part returned to the model after a tool call. */
|
|
10
|
+
readonly type: "text";
|
|
11
|
+
/** Text that should be included in the model-visible tool result. */
|
|
10
12
|
readonly text: string;
|
|
11
13
|
} | {
|
|
12
|
-
/** A file content part returned to the model after a tool call. */
|
|
14
|
+
/** A file content part returned to the model after a tool call. */
|
|
15
|
+
readonly type: "file";
|
|
13
16
|
/**
|
|
14
17
|
* File payload encoded as a provider-compatible string, commonly base64
|
|
15
18
|
* for binary data.
|
|
16
19
|
*/
|
|
17
|
-
readonly data: string;
|
|
18
|
-
|
|
20
|
+
readonly data: string;
|
|
21
|
+
/** MIME type for the file payload. */
|
|
22
|
+
readonly mediaType: string;
|
|
23
|
+
/** Optional display filename for the file payload. */
|
|
19
24
|
readonly filename?: string;
|
|
20
25
|
};
|
|
21
26
|
/**
|
|
@@ -44,8 +49,11 @@ type ToolModelContentPart = {
|
|
|
44
49
|
* ```
|
|
45
50
|
*/
|
|
46
51
|
type ToolModelOutputFunction<TArgs, TResult> = (options: {
|
|
47
|
-
/** Stable identifier for the tool call being converted. */
|
|
48
|
-
|
|
52
|
+
/** Stable identifier for the tool call being converted. */
|
|
53
|
+
toolCallId: string;
|
|
54
|
+
/** Arguments supplied by the model for this tool call. */
|
|
55
|
+
input: TArgs;
|
|
56
|
+
/** Value returned by the tool's {@link ToolExecuteFunction}. */
|
|
49
57
|
output: TResult;
|
|
50
58
|
}) => readonly ToolModelContentPart[] | Promise<readonly ToolModelContentPart[]>;
|
|
51
59
|
/**
|
|
@@ -101,7 +109,9 @@ interface ToolCallReader<TArgs extends Record<string, unknown> = Record<string,
|
|
|
101
109
|
};
|
|
102
110
|
}
|
|
103
111
|
type ToolExecutionContext = {
|
|
104
|
-
/** Stable identifier for the tool call being executed. */
|
|
112
|
+
/** Stable identifier for the tool call being executed. */
|
|
113
|
+
toolCallId: string;
|
|
114
|
+
/** Signal that is aborted when the current run is cancelled. */
|
|
105
115
|
abortSignal: AbortSignal;
|
|
106
116
|
/**
|
|
107
117
|
* From inside a frontend tool's execute function, request human input from
|
|
@@ -159,7 +169,8 @@ type ToolBase<TArgs extends Record<string, unknown> = Record<string, unknown>, T
|
|
|
159
169
|
display?: ToolDisplay;
|
|
160
170
|
};
|
|
161
171
|
type BackendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
162
|
-
/** Tool that is executed by the backend rather than in the browser. */
|
|
172
|
+
/** Tool that is executed by the backend rather than in the browser. */
|
|
173
|
+
type: "backend";
|
|
163
174
|
description?: undefined;
|
|
164
175
|
parameters?: undefined;
|
|
165
176
|
disabled?: undefined;
|
|
@@ -176,30 +187,48 @@ type BackendTool<TArgs extends Record<string, unknown> = Record<string, unknown>
|
|
|
176
187
|
* server adapter rather than the shared {@link Tool} shape.
|
|
177
188
|
*/
|
|
178
189
|
type BackendToolDeclaration<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
179
|
-
type: "backend";
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
190
|
+
type: "backend";
|
|
191
|
+
/** Natural-language description shown to the model when selecting tools. */
|
|
192
|
+
description?: string | undefined;
|
|
193
|
+
/** Schema for the arguments the model must provide when calling the tool. */
|
|
194
|
+
parameters?: StandardSchemaV1<TArgs> | JSONSchema7 | undefined;
|
|
195
|
+
/** Prevents the tool from being exposed to the model while true. */
|
|
196
|
+
disabled?: boolean;
|
|
197
|
+
/** Executes the tool on the server after the model provides valid arguments. */
|
|
198
|
+
execute?: ToolExecuteFunction<TArgs, TResult>;
|
|
199
|
+
/** Converts the execution result into model-visible output. */
|
|
200
|
+
toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
|
|
201
|
+
/** Handles invalid tool arguments when schema validation fails. */
|
|
185
202
|
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
|
|
186
203
|
providerOptions?: ProviderOptions;
|
|
187
204
|
};
|
|
188
205
|
type FrontendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
189
|
-
/** Tool that is executed in the frontend runtime. */
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
206
|
+
/** Tool that is executed in the frontend runtime. */
|
|
207
|
+
type: "frontend";
|
|
208
|
+
/** Natural-language description shown to the model when selecting tools. */
|
|
209
|
+
description?: string | undefined;
|
|
210
|
+
/** Schema for the arguments the model must provide when calling the tool. */
|
|
211
|
+
parameters: StandardSchemaV1<TArgs> | JSONSchema7;
|
|
212
|
+
/** Prevents the tool from being exposed to the model while true. */
|
|
213
|
+
disabled?: boolean;
|
|
214
|
+
/** Executes the tool after the model provides valid arguments. */
|
|
215
|
+
execute?: ToolExecuteFunction<TArgs, TResult>;
|
|
216
|
+
/** Converts the execution result into model-visible output. */
|
|
217
|
+
toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
|
|
218
|
+
/** Handles invalid tool arguments when schema validation fails. */
|
|
195
219
|
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
|
|
196
220
|
providerOptions?: ProviderOptions;
|
|
197
221
|
};
|
|
198
222
|
type HumanTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
199
|
-
/** Tool that pauses the run until a user or UI supplies a result. */
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
/** Tool that pauses the run until a user or UI supplies a result. */
|
|
224
|
+
type: "human";
|
|
225
|
+
/** Natural-language description shown to the model when selecting tools. */
|
|
226
|
+
description?: string | undefined;
|
|
227
|
+
/** Schema for the arguments the model must provide when requesting input. */
|
|
228
|
+
parameters: StandardSchemaV1<TArgs> | JSONSchema7;
|
|
229
|
+
/** Prevents the tool from being exposed to the model while true. */
|
|
230
|
+
disabled?: boolean;
|
|
231
|
+
/** Human tools are always surfaced standalone and cannot opt out. */
|
|
203
232
|
display?: "standalone";
|
|
204
233
|
execute?: undefined;
|
|
205
234
|
toModelOutput?: undefined;
|
|
@@ -207,9 +236,13 @@ type HumanTool<TArgs extends Record<string, unknown> = Record<string, unknown>,
|
|
|
207
236
|
providerOptions?: ProviderOptions;
|
|
208
237
|
};
|
|
209
238
|
type ProviderTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
210
|
-
/** Tool executed by the LLM provider rather than assistant-ui. */
|
|
211
|
-
|
|
212
|
-
|
|
239
|
+
/** Tool executed by the LLM provider rather than assistant-ui. */
|
|
240
|
+
type: "provider";
|
|
241
|
+
/** Provider-defined tool identifier, e.g. `openai.web_search_preview`. */
|
|
242
|
+
providerId: `${string}.${string}`;
|
|
243
|
+
/** Schema used by adapters for validation and type plumbing. */
|
|
244
|
+
parameters?: StandardSchemaV1<TArgs> | JSONSchema7 | undefined;
|
|
245
|
+
/** Provider-specific configuration for this tool. */
|
|
213
246
|
args: Record<string, unknown>;
|
|
214
247
|
/**
|
|
215
248
|
* Whether provider results may arrive after the originating response turn.
|
|
@@ -223,21 +256,26 @@ type ProviderTool<TArgs extends Record<string, unknown> = Record<string, unknown
|
|
|
223
256
|
providerOptions?: ProviderOptions;
|
|
224
257
|
};
|
|
225
258
|
type McpServerConfig = {
|
|
226
|
-
/** Connect to an MCP server over Streamable HTTP or server-sent events. */
|
|
259
|
+
/** Connect to an MCP server over Streamable HTTP or server-sent events. */
|
|
260
|
+
type: "http" | "sse";
|
|
227
261
|
url: string;
|
|
228
262
|
headers?: Record<string, string>;
|
|
229
|
-
redirect?: "follow" | "error";
|
|
263
|
+
redirect?: "follow" | "error";
|
|
264
|
+
/** Optional timeout in milliseconds for client creation and tool listing. */
|
|
230
265
|
connectionTimeout?: number | undefined;
|
|
231
266
|
} | {
|
|
232
|
-
/** Start and connect to a local MCP server over stdio. */
|
|
267
|
+
/** Start and connect to a local MCP server over stdio. */
|
|
268
|
+
type: "stdio";
|
|
233
269
|
command: string;
|
|
234
270
|
args?: readonly string[];
|
|
235
271
|
env?: Record<string, string>;
|
|
236
|
-
cwd?: string;
|
|
272
|
+
cwd?: string;
|
|
273
|
+
/** Optional timeout in milliseconds for client creation and tool listing. */
|
|
237
274
|
connectionTimeout?: number | undefined;
|
|
238
275
|
};
|
|
239
276
|
type McpTool = ToolBase<Record<string, unknown>, unknown> & {
|
|
240
|
-
/** Tools loaded from an MCP server by a server adapter. */
|
|
277
|
+
/** Tools loaded from an MCP server by a server adapter. */
|
|
278
|
+
type: "mcp";
|
|
241
279
|
server: McpServerConfig;
|
|
242
280
|
description?: undefined;
|
|
243
281
|
parameters?: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-types.d.ts","names":[],"sources":["../../../src/core/tool/tool-types.ts"],"mappings":";;;;;;;KAMY
|
|
1
|
+
{"version":3,"file":"tool-types.d.ts","names":[],"sources":["../../../src/core/tool/tool-types.ts"],"mappings":"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"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Tool } from "./tool-types.js";
|
|
2
2
|
import { AssistantMessage } from "../utils/types.js";
|
|
3
3
|
import { ToolExecutionStream } from "./ToolExecutionStream.js";
|
|
4
|
-
|
|
5
4
|
//#region src/core/tool/toolResultStream.d.ts
|
|
6
5
|
declare function unstable_runPendingTools(message: AssistantMessage, tools: Record<string, Tool> | undefined, abortSignal: AbortSignal, human: (toolCallId: string, payload: unknown) => Promise<unknown>): Promise<AssistantMessage>;
|
|
7
6
|
type ToolResultStreamOptions = {
|
|
8
|
-
/** Called immediately before a frontend tool's `execute` function runs. */
|
|
7
|
+
/** Called immediately before a frontend tool's `execute` function runs. */
|
|
8
|
+
onExecutionStart?: (toolCallId: string, toolName: string) => void;
|
|
9
|
+
/** Called after frontend tool execution finishes or fails. */
|
|
9
10
|
onExecutionEnd?: (toolCallId: string, toolName: string) => void;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolResultStream.d.ts","names":[],"sources":["../../../src/core/tool/toolResultStream.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"toolResultStream.d.ts","names":[],"sources":["../../../src/core/tool/toolResultStream.ts"],"mappings":";;;;iBA6IsB,yBACpB,SAAS,kBACT,OAAO,eAAe,mBACtB,aAAa,aACb,QAAQ,oBAAoB,qBAAqB,mBAAgB,QAAA;KAsEvD;;EAEV,oBAAoB,oBAAoB;;EAExC,kBAAkB,oBAAoB;;;;;;;;;;;;;;;iBAgBxB,iBACd,OACI,eAAe,eACR,eAAe,gCAE1B,aAAa,qBAAqB,cAClC,QAAQ,oBAAoB,qBAAqB,kBACjD,UAAU,0BAAuB"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
type AsNumber<K> = K extends `${infer N extends number}` ? N | K : never;
|
|
3
3
|
type TupleIndex<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;
|
|
4
4
|
type ObjectKey<T> = keyof T & (string | number);
|
|
5
|
-
type TypePath<T> = [] | (0 extends 1 & T ? any[] : T extends object ? T extends readonly any[] ? number extends T["length"] ? { [K in TupleIndex<T>]: [AsNumber<K>, ...TypePath<T[K]>] }[TupleIndex<T>] : [number, ...TypePath<T[number]>] : { [K in ObjectKey<T>]: [K, ...TypePath<T[K]>] }[ObjectKey<T>] : []);
|
|
5
|
+
type TypePath<T> = [] | (0 extends 1 & T ? any[] : T extends object ? T extends readonly any[] ? number extends T["length"] ? { [K in TupleIndex<T>]: [AsNumber<K>, ...TypePath<T[K]>]; }[TupleIndex<T>] : [number, ...TypePath<T[number]>] : { [K in ObjectKey<T>]: [K, ...TypePath<T[K]>]; }[ObjectKey<T>] : []);
|
|
6
6
|
type TypeAtPath<T, P extends readonly any[]> = P extends [infer Head, ...infer Rest] ? Head extends keyof T ? TypeAtPath<T[Head], Rest> : never : T;
|
|
7
7
|
type DeepPartial<T> = T extends readonly any[] ? readonly DeepPartial<T[number]>[] : T extends {
|
|
8
8
|
[key: string]: any;
|
|
9
|
-
} ? { readonly [K in keyof T]?: DeepPartial<T[K]
|
|
9
|
+
} ? { readonly [K in keyof T]?: DeepPartial<T[K]>; } : T;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { DeepPartial, TypeAtPath, TypePath };
|
|
12
12
|
//# sourceMappingURL=type-path-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-path-utils.d.ts","names":[],"sources":["../../../src/core/tool/type-path-utils.ts"],"mappings":";KAAK,
|
|
1
|
+
{"version":3,"file":"type-path-utils.d.ts","names":[],"sources":["../../../src/core/tool/type-path-utils.ts"],"mappings":";KAAK,SAAS,KAAK,mBAAmB,qBAAqB,IAAI;KAC1D,WAAW,4BAA4B,cAAc;KACrD,UAAU,WAAW;KAEd,SAAS,yBAEF,YAEX,mBACE,0CACiB,iBAGV,KAAK,WAAW,MAAM,SAAS,OAAO,SAAS,EAAE,QAClD,WAAW,kBAED,SAAS,iBAEpB,KAAK,UAAU,MAAM,MAAM,SAAS,EAAE,QAAO,UAAU;KAI1D,WAAW,GAAG,4BAA4B,iBAC9C,eACG,QAEP,mBAAmB,IACjB,WAAW,EAAE,OAAO,gBAEtB;KAEQ,YAAY,KAAK,oCAChB,YAAY,eACrB;GAAa;gBACC,WAAW,KAAK,YAAY,EAAE,SAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Counter.d.ts","names":[],"sources":["../../../src/core/utils/Counter.ts"],"mappings":";cAAa
|
|
1
|
+
{"version":3,"file":"Counter.d.ts","names":[],"sources":["../../../src/core/utils/Counter.ts"],"mappings":";cAAa;EACJ;EAEP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateId.d.ts","names":[],"sources":["../../../src/core/utils/generateId.ts"],"mappings":";cAEa,
|
|
1
|
+
{"version":3,"file":"generateId.d.ts","names":[],"sources":["../../../src/core/utils/generateId.ts"],"mappings":";cAEa,aAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantMetaTransformStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/AssistantMetaTransformStream.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AssistantMetaTransformStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/AssistantMetaTransformStream.ts"],"mappings":";;;;;;KASY,4BACP;EACC;EACA,MAAM;MAEP;EACC;EACA,MAAM;IAAa;;MAEpB;EACC,MAAM,QACJ;;cAIK,qCAAqC,gBAChD,sBACA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AssistantStreamController } from "../../modules/assistant-stream.js";
|
|
2
2
|
import { AssistantStreamChunk } from "../../AssistantStreamChunk.js";
|
|
3
|
-
|
|
4
3
|
//#region src/core/utils/stream/AssistantTransformStream.d.ts
|
|
5
4
|
type AssistantTransformerFlushCallback = (controller: AssistantStreamController) => void | PromiseLike<void>;
|
|
6
5
|
type AssistantTransformerStartCallback = (controller: AssistantStreamController) => void | PromiseLike<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantTransformStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/AssistantTransformStream.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AssistantTransformStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/AssistantTransformStream.ts"],"mappings":";;;KAMK,qCACH,YAAY,qCACF;KAEP,qCACH,YAAY,qCACF;KAEP,sCAAsC,MACzC,OAAO,GACP,YAAY,qCACF;KAEP,qBAAqB;EACxB,QAAQ;EACR,QAAQ;EACR,YAAY,sCAAsC;;cAGvC,yBAAyB,WAAW,gBAC/C,GACA;cAGE,aAAa,qBAAqB,IAClC,mBAAmB,gBAAgB,IACnC,mBAAmB,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineDecoderStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/LineDecoderStream.ts"],"mappings":";cAAa,
|
|
1
|
+
{"version":3,"file":"LineDecoderStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/LineDecoderStream.ts"],"mappings":";cAAa,0BAA0B;UAC7B;UACA"}
|
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
//#region src/core/utils/stream/LineDecoderStream.ts
|
|
2
2
|
var LineDecoderStream = class extends TransformStream {
|
|
3
3
|
buffer = "";
|
|
4
|
+
skipNextLineFeed = false;
|
|
4
5
|
constructor() {
|
|
5
6
|
super({
|
|
6
7
|
transform: (chunk, controller) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let lineStart = 0;
|
|
9
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
10
|
+
const character = chunk[i];
|
|
11
|
+
if (this.skipNextLineFeed) {
|
|
12
|
+
this.skipNextLineFeed = false;
|
|
13
|
+
if (character === "\n") {
|
|
14
|
+
lineStart = i + 1;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (character === "\n" || character === "\r") {
|
|
19
|
+
this.buffer += chunk.slice(lineStart, i);
|
|
20
|
+
controller.enqueue(this.buffer);
|
|
21
|
+
this.buffer = "";
|
|
22
|
+
this.skipNextLineFeed = character === "\r";
|
|
23
|
+
lineStart = i + 1;
|
|
24
|
+
}
|
|
12
25
|
}
|
|
13
|
-
this.buffer
|
|
26
|
+
this.buffer += chunk.slice(lineStart);
|
|
14
27
|
},
|
|
15
28
|
flush: () => {
|
|
16
29
|
if (this.buffer) throw new Error(`Stream ended with an incomplete line: "${this.buffer}"`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineDecoderStream.js","names":[],"sources":["../../../../src/core/utils/stream/LineDecoderStream.ts"],"sourcesContent":["export class LineDecoderStream extends TransformStream<string, string> {\n private buffer = \"\";\n\n constructor() {\n super({\n transform: (chunk, controller) => {\n
|
|
1
|
+
{"version":3,"file":"LineDecoderStream.js","names":[],"sources":["../../../../src/core/utils/stream/LineDecoderStream.ts"],"sourcesContent":["export class LineDecoderStream extends TransformStream<string, string> {\n private buffer = \"\";\n private skipNextLineFeed = false;\n\n constructor() {\n super({\n transform: (chunk, controller) => {\n let lineStart = 0;\n\n for (let i = 0; i < chunk.length; i++) {\n const character = chunk[i]!;\n\n if (this.skipNextLineFeed) {\n this.skipNextLineFeed = false;\n if (character === \"\\n\") {\n lineStart = i + 1;\n continue;\n }\n }\n\n if (character === \"\\n\" || character === \"\\r\") {\n this.buffer += chunk.slice(lineStart, i);\n controller.enqueue(this.buffer);\n this.buffer = \"\";\n this.skipNextLineFeed = character === \"\\r\";\n lineStart = i + 1;\n }\n }\n\n this.buffer += chunk.slice(lineStart);\n },\n flush: () => {\n if (this.buffer) {\n throw new Error(\n `Stream ended with an incomplete line: \"${this.buffer}\"`,\n );\n }\n },\n });\n }\n}\n"],"mappings":";AAAA,IAAa,oBAAb,cAAuC,gBAAgC;CACrE,SAAiB;CACjB,mBAA2B;CAE3B,cAAc;EACZ,MAAM;GACJ,YAAY,OAAO,eAAe;IAChC,IAAI,YAAY;IAEhB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;KACrC,MAAM,YAAY,MAAM;KAExB,IAAI,KAAK,kBAAkB;MACzB,KAAK,mBAAmB;MACxB,IAAI,cAAc,MAAM;OACtB,YAAY,IAAI;OAChB;MACF;KACF;KAEA,IAAI,cAAc,QAAQ,cAAc,MAAM;MAC5C,KAAK,UAAU,MAAM,MAAM,WAAW,CAAC;MACvC,WAAW,QAAQ,KAAK,MAAM;MAC9B,KAAK,SAAS;MACd,KAAK,mBAAmB,cAAc;MACtC,YAAY,IAAI;KAClB;IACF;IAEA,KAAK,UAAU,MAAM,MAAM,SAAS;GACtC;GACA,aAAa;IACX,IAAI,KAAK,QACP,MAAM,IAAI,MACR,0CAA0C,KAAK,OAAO,EACxD;GAEJ;EACF,CAAC;CACH;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PipeableTransformStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/PipeableTransformStream.ts"],"mappings":";cAAa,
|
|
1
|
+
{"version":3,"file":"PipeableTransformStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/PipeableTransformStream.ts"],"mappings":";cAAa,wBAAwB,GAAG,WAAW,gBAAgB,GAAG;cACxD,YAAY,UAAU,eAAe,OAAO,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSE.d.ts","names":[],"sources":["../../../../src/core/utils/stream/SSE.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SSE.d.ts","names":[],"sources":["../../../../src/core/utils/stream/SSE.ts"],"mappings":";;cAMa,WAAW,WAAW,wBACjC,GACA,WAAW;kBAEK,SAAO;EAMvB,SAAO;;;cAiBI,WAAW,WAAW,wBACjC,WAAW,cACX"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PipeableTransformStream } from "./PipeableTransformStream.js";
|
|
2
|
-
import {
|
|
2
|
+
import { SSEEventDecoderStream } from "./SSEEventDecoderStream.js";
|
|
3
3
|
//#region src/core/utils/stream/SSE.ts
|
|
4
4
|
var SSEEncoder = class SSEEncoder extends PipeableTransformStream {
|
|
5
5
|
static headers = new Headers({
|
|
@@ -14,59 +14,9 @@ var SSEEncoder = class SSEEncoder extends PipeableTransformStream {
|
|
|
14
14
|
} })).pipeThrough(new TextEncoderStream()));
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
var SSEEventStream = class extends TransformStream {
|
|
18
|
-
constructor() {
|
|
19
|
-
let eventBuffer = {};
|
|
20
|
-
let dataLines = [];
|
|
21
|
-
super({
|
|
22
|
-
start() {
|
|
23
|
-
eventBuffer = {};
|
|
24
|
-
dataLines = [];
|
|
25
|
-
},
|
|
26
|
-
transform(line, controller) {
|
|
27
|
-
if (line.startsWith(":")) return;
|
|
28
|
-
if (line === "") {
|
|
29
|
-
if (dataLines.length > 0) controller.enqueue({
|
|
30
|
-
event: eventBuffer.event || "message",
|
|
31
|
-
data: dataLines.join("\n"),
|
|
32
|
-
id: eventBuffer.id,
|
|
33
|
-
retry: eventBuffer.retry
|
|
34
|
-
});
|
|
35
|
-
eventBuffer = {};
|
|
36
|
-
dataLines = [];
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const [field, ...rest] = line.split(":");
|
|
40
|
-
const value = rest.join(":").trimStart();
|
|
41
|
-
switch (field) {
|
|
42
|
-
case "event":
|
|
43
|
-
eventBuffer.event = value;
|
|
44
|
-
break;
|
|
45
|
-
case "data":
|
|
46
|
-
dataLines.push(value);
|
|
47
|
-
break;
|
|
48
|
-
case "id":
|
|
49
|
-
eventBuffer.id = value;
|
|
50
|
-
break;
|
|
51
|
-
case "retry":
|
|
52
|
-
eventBuffer.retry = Number(value);
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
flush(controller) {
|
|
57
|
-
if (dataLines.length > 0) controller.enqueue({
|
|
58
|
-
event: eventBuffer.event || "message",
|
|
59
|
-
data: dataLines.join("\n"),
|
|
60
|
-
id: eventBuffer.id,
|
|
61
|
-
retry: eventBuffer.retry
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
17
|
var SSEDecoder = class extends PipeableTransformStream {
|
|
68
18
|
constructor() {
|
|
69
|
-
super((readable) => readable.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
19
|
+
super((readable) => readable.pipeThrough(new TextDecoderStream()).pipeThrough(new SSEEventDecoderStream()).pipeThrough(new TransformStream({ transform(event, controller) {
|
|
70
20
|
switch (event.event) {
|
|
71
21
|
case "message":
|
|
72
22
|
controller.enqueue(JSON.parse(event.data));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSE.js","names":[],"sources":["../../../../src/core/utils/stream/SSE.ts"],"sourcesContent":["import { PipeableTransformStream } from \"./PipeableTransformStream\";\nimport {
|
|
1
|
+
{"version":3,"file":"SSE.js","names":[],"sources":["../../../../src/core/utils/stream/SSE.ts"],"sourcesContent":["import { PipeableTransformStream } from \"./PipeableTransformStream\";\nimport {\n SSEEventDecoderStream,\n type PipelineSSEEvent,\n} from \"./SSEEventDecoderStream\";\n\nexport class SSEEncoder<T> extends PipeableTransformStream<\n T,\n Uint8Array<ArrayBuffer>\n> {\n static readonly headers = new Headers({\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n });\n\n headers = SSEEncoder.headers;\n\n constructor() {\n super((readable) =>\n readable\n .pipeThrough(\n new TransformStream<T, string>({\n transform(chunk, controller) {\n controller.enqueue(`data: ${JSON.stringify(chunk)}\\n\\n`);\n },\n }),\n )\n .pipeThrough(new TextEncoderStream()),\n );\n }\n}\n\nexport class SSEDecoder<T> extends PipeableTransformStream<\n Uint8Array<ArrayBuffer>,\n T\n> {\n constructor() {\n super((readable) =>\n readable\n .pipeThrough(new TextDecoderStream())\n .pipeThrough(new SSEEventDecoderStream())\n .pipeThrough(\n new TransformStream<PipelineSSEEvent, T>({\n transform(event, controller) {\n switch (event.event) {\n case \"message\":\n controller.enqueue(JSON.parse(event.data));\n break;\n default:\n throw new Error(`Unknown SSE event type: ${event.event}`);\n }\n },\n }),\n ),\n );\n }\n}\n"],"mappings":";;;AAMA,IAAa,aAAb,MAAa,mBAAsB,wBAGjC;CACA,OAAgB,UAAU,IAAI,QAAQ;EACpC,gBAAgB;EAChB,iBAAiB;EACjB,YAAY;CACd,CAAC;CAED,UAAU,WAAW;CAErB,cAAc;EACZ,OAAO,aACL,SACG,YACC,IAAI,gBAA2B,EAC7B,UAAU,OAAO,YAAY;GAC3B,WAAW,QAAQ,SAAS,KAAK,UAAU,KAAK,EAAE,KAAK;EACzD,EACF,CAAC,CACH,CAAC,CACA,YAAY,IAAI,kBAAkB,CAAC,CACxC;CACF;AACF;AAEA,IAAa,aAAb,cAAmC,wBAGjC;CACA,cAAc;EACZ,OAAO,aACL,SACG,YAAY,IAAI,kBAAkB,CAAC,CAAC,CACpC,YAAY,IAAI,sBAAsB,CAAC,CAAC,CACxC,YACC,IAAI,gBAAqC,EACvC,UAAU,OAAO,YAAY;GAC3B,QAAQ,MAAM,OAAd;IACE,KAAK;KACH,WAAW,QAAQ,KAAK,MAAM,MAAM,IAAI,CAAC;KACzC;IACF,SACE,MAAM,IAAI,MAAM,2BAA2B,MAAM,OAAO;GAC5D;EACF,EACF,CAAC,CACH,CACJ;CACF;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/core/utils/stream/SSEEventDecoder.d.ts
|
|
2
|
+
type SSEEvent = {
|
|
3
|
+
event?: string;
|
|
4
|
+
data: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
retry?: number;
|
|
7
|
+
};
|
|
8
|
+
declare class SSEEventDecoder {
|
|
9
|
+
private lineBuffer;
|
|
10
|
+
private dataLines;
|
|
11
|
+
private eventName;
|
|
12
|
+
private lastEventId;
|
|
13
|
+
private retry;
|
|
14
|
+
private pendingLF;
|
|
15
|
+
private readonly trailing;
|
|
16
|
+
constructor(options?: {
|
|
17
|
+
trailing?: "drop" | "dispatch";
|
|
18
|
+
});
|
|
19
|
+
push(text: string): SSEEvent[];
|
|
20
|
+
flush(): SSEEvent | null;
|
|
21
|
+
private processLine;
|
|
22
|
+
private dispatchEvent;
|
|
23
|
+
private resetFrame;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { SSEEvent, SSEEventDecoder };
|
|
27
|
+
//# sourceMappingURL=SSEEventDecoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SSEEventDecoder.d.ts","names":[],"sources":["../../../../src/core/utils/stream/SSEEventDecoder.ts"],"mappings":";KAAY;EACV;EACA;EACA;EACA;;cAGW;UACH;UACA;UACA;UACA;UACA;UACA;mBACS;cAEL;IAAY;;EAIxB,KAAK,eAAe;EAsBpB,SAAS;UAiBD;UA+BA;UAcA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//#region src/core/utils/stream/SSEEventDecoder.ts
|
|
2
|
+
var SSEEventDecoder = class {
|
|
3
|
+
lineBuffer = "";
|
|
4
|
+
dataLines = [];
|
|
5
|
+
eventName;
|
|
6
|
+
lastEventId;
|
|
7
|
+
retry;
|
|
8
|
+
pendingLF = false;
|
|
9
|
+
trailing;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.trailing = options?.trailing ?? "drop";
|
|
12
|
+
}
|
|
13
|
+
push(text) {
|
|
14
|
+
const events = [];
|
|
15
|
+
if (text === "") return events;
|
|
16
|
+
if (this.pendingLF && text.startsWith("\n")) text = text.slice(1);
|
|
17
|
+
this.pendingLF = text.endsWith("\r");
|
|
18
|
+
this.lineBuffer += text;
|
|
19
|
+
const lines = this.lineBuffer.split(/\r\n|\r|\n/);
|
|
20
|
+
this.lineBuffer = lines.pop();
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
const event = this.processLine(line);
|
|
23
|
+
if (event) events.push(event);
|
|
24
|
+
}
|
|
25
|
+
return events;
|
|
26
|
+
}
|
|
27
|
+
flush() {
|
|
28
|
+
if (this.trailing === "drop") {
|
|
29
|
+
this.resetFrame();
|
|
30
|
+
this.lineBuffer = "";
|
|
31
|
+
this.pendingLF = false;
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (this.lineBuffer.length > 0) this.processLine(this.lineBuffer);
|
|
35
|
+
this.lineBuffer = "";
|
|
36
|
+
this.pendingLF = false;
|
|
37
|
+
return this.dispatchEvent();
|
|
38
|
+
}
|
|
39
|
+
processLine(line) {
|
|
40
|
+
if (line === "") return this.dispatchEvent();
|
|
41
|
+
if (line.startsWith(":")) return null;
|
|
42
|
+
const separator = line.indexOf(":");
|
|
43
|
+
const field = separator === -1 ? line : line.slice(0, separator);
|
|
44
|
+
let value = separator === -1 ? "" : line.slice(separator + 1);
|
|
45
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
46
|
+
switch (field) {
|
|
47
|
+
case "data":
|
|
48
|
+
this.dataLines.push(value);
|
|
49
|
+
break;
|
|
50
|
+
case "event":
|
|
51
|
+
this.eventName = value;
|
|
52
|
+
break;
|
|
53
|
+
case "id":
|
|
54
|
+
if (!value.includes("\0")) this.lastEventId = value;
|
|
55
|
+
break;
|
|
56
|
+
case "retry": {
|
|
57
|
+
const retry = Number(value);
|
|
58
|
+
if (/^\d+$/.test(value) && Number.isSafeInteger(retry)) this.retry = retry;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
dispatchEvent() {
|
|
65
|
+
if (this.dataLines.length === 0) {
|
|
66
|
+
this.resetFrame();
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const event = { data: this.dataLines.join("\n") };
|
|
70
|
+
if (this.eventName !== void 0) event.event = this.eventName;
|
|
71
|
+
if (this.lastEventId !== void 0) event.id = this.lastEventId;
|
|
72
|
+
if (this.retry !== void 0) event.retry = this.retry;
|
|
73
|
+
this.resetFrame();
|
|
74
|
+
return event;
|
|
75
|
+
}
|
|
76
|
+
resetFrame() {
|
|
77
|
+
this.dataLines = [];
|
|
78
|
+
this.eventName = void 0;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { SSEEventDecoder };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=SSEEventDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SSEEventDecoder.js","names":[],"sources":["../../../../src/core/utils/stream/SSEEventDecoder.ts"],"sourcesContent":["export type SSEEvent = {\n event?: string;\n data: string;\n id?: string;\n retry?: number;\n};\n\nexport class SSEEventDecoder {\n private lineBuffer = \"\";\n private dataLines: string[] = [];\n private eventName: string | undefined;\n private lastEventId: string | undefined;\n private retry: number | undefined;\n private pendingLF = false;\n private readonly trailing: \"drop\" | \"dispatch\";\n\n constructor(options?: { trailing?: \"drop\" | \"dispatch\" }) {\n this.trailing = options?.trailing ?? \"drop\";\n }\n\n push(text: string): SSEEvent[] {\n const events: SSEEvent[] = [];\n if (text === \"\") return events;\n\n // Lines end with LF, CRLF, or CR. A chunk-trailing \"\\r\" terminates its\n // line immediately; pendingLF then swallows the leading \"\\n\" of the next\n // chunk so a CRLF split across chunks is not counted twice.\n if (this.pendingLF && text.startsWith(\"\\n\")) text = text.slice(1);\n this.pendingLF = text.endsWith(\"\\r\");\n\n this.lineBuffer += text;\n const lines = this.lineBuffer.split(/\\r\\n|\\r|\\n/);\n this.lineBuffer = lines.pop()!;\n\n for (const line of lines) {\n const event = this.processLine(line);\n if (event) events.push(event);\n }\n\n return events;\n }\n\n flush(): SSEEvent | null {\n if (this.trailing === \"drop\") {\n this.resetFrame();\n this.lineBuffer = \"\";\n this.pendingLF = false;\n return null;\n }\n\n if (this.lineBuffer.length > 0) {\n this.processLine(this.lineBuffer);\n }\n\n this.lineBuffer = \"\";\n this.pendingLF = false;\n return this.dispatchEvent();\n }\n\n private processLine(line: string): SSEEvent | null {\n if (line === \"\") return this.dispatchEvent();\n if (line.startsWith(\":\")) return null;\n\n const separator = line.indexOf(\":\");\n const field = separator === -1 ? line : line.slice(0, separator);\n let value = separator === -1 ? \"\" : line.slice(separator + 1);\n if (value.startsWith(\" \")) value = value.slice(1);\n\n switch (field) {\n case \"data\":\n this.dataLines.push(value);\n break;\n case \"event\":\n this.eventName = value;\n break;\n case \"id\":\n if (!value.includes(\"\\u0000\")) this.lastEventId = value;\n break;\n case \"retry\": {\n const retry = Number(value);\n if (/^\\d+$/.test(value) && Number.isSafeInteger(retry)) {\n this.retry = retry;\n }\n break;\n }\n }\n\n return null;\n }\n\n private dispatchEvent(): SSEEvent | null {\n if (this.dataLines.length === 0) {\n this.resetFrame();\n return null;\n }\n\n const event: SSEEvent = { data: this.dataLines.join(\"\\n\") };\n if (this.eventName !== undefined) event.event = this.eventName;\n if (this.lastEventId !== undefined) event.id = this.lastEventId;\n if (this.retry !== undefined) event.retry = this.retry;\n this.resetFrame();\n return event;\n }\n\n private resetFrame() {\n this.dataLines = [];\n this.eventName = undefined;\n }\n}\n"],"mappings":";AAOA,IAAa,kBAAb,MAA6B;CAC3B,aAAqB;CACrB,YAA8B,CAAC;CAC/B;CACA;CACA;CACA,YAAoB;CACpB;CAEA,YAAY,SAA8C;EACxD,KAAK,WAAW,SAAS,YAAY;CACvC;CAEA,KAAK,MAA0B;EAC7B,MAAM,SAAqB,CAAC;EAC5B,IAAI,SAAS,IAAI,OAAO;EAKxB,IAAI,KAAK,aAAa,KAAK,WAAW,IAAI,GAAG,OAAO,KAAK,MAAM,CAAC;EAChE,KAAK,YAAY,KAAK,SAAS,IAAI;EAEnC,KAAK,cAAc;EACnB,MAAM,QAAQ,KAAK,WAAW,MAAM,YAAY;EAChD,KAAK,aAAa,MAAM,IAAI;EAE5B,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,QAAQ,KAAK,YAAY,IAAI;GACnC,IAAI,OAAO,OAAO,KAAK,KAAK;EAC9B;EAEA,OAAO;CACT;CAEA,QAAyB;EACvB,IAAI,KAAK,aAAa,QAAQ;GAC5B,KAAK,WAAW;GAChB,KAAK,aAAa;GAClB,KAAK,YAAY;GACjB,OAAO;EACT;EAEA,IAAI,KAAK,WAAW,SAAS,GAC3B,KAAK,YAAY,KAAK,UAAU;EAGlC,KAAK,aAAa;EAClB,KAAK,YAAY;EACjB,OAAO,KAAK,cAAc;CAC5B;CAEA,YAAoB,MAA+B;EACjD,IAAI,SAAS,IAAI,OAAO,KAAK,cAAc;EAC3C,IAAI,KAAK,WAAW,GAAG,GAAG,OAAO;EAEjC,MAAM,YAAY,KAAK,QAAQ,GAAG;EAClC,MAAM,QAAQ,cAAc,KAAK,OAAO,KAAK,MAAM,GAAG,SAAS;EAC/D,IAAI,QAAQ,cAAc,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;EAC5D,IAAI,MAAM,WAAW,GAAG,GAAG,QAAQ,MAAM,MAAM,CAAC;EAEhD,QAAQ,OAAR;GACE,KAAK;IACH,KAAK,UAAU,KAAK,KAAK;IACzB;GACF,KAAK;IACH,KAAK,YAAY;IACjB;GACF,KAAK;IACH,IAAI,CAAC,MAAM,SAAS,IAAQ,GAAG,KAAK,cAAc;IAClD;GACF,KAAK,SAAS;IACZ,MAAM,QAAQ,OAAO,KAAK;IAC1B,IAAI,QAAQ,KAAK,KAAK,KAAK,OAAO,cAAc,KAAK,GACnD,KAAK,QAAQ;IAEf;GACF;EACF;EAEA,OAAO;CACT;CAEA,gBAAyC;EACvC,IAAI,KAAK,UAAU,WAAW,GAAG;GAC/B,KAAK,WAAW;GAChB,OAAO;EACT;EAEA,MAAM,QAAkB,EAAE,MAAM,KAAK,UAAU,KAAK,IAAI,EAAE;EAC1D,IAAI,KAAK,cAAc,KAAA,GAAW,MAAM,QAAQ,KAAK;EACrD,IAAI,KAAK,gBAAgB,KAAA,GAAW,MAAM,KAAK,KAAK;EACpD,IAAI,KAAK,UAAU,KAAA,GAAW,MAAM,QAAQ,KAAK;EACjD,KAAK,WAAW;EAChB,OAAO;CACT;CAEA,aAAqB;EACnB,KAAK,YAAY,CAAC;EAClB,KAAK,YAAY,KAAA;CACnB;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/core/utils/stream/SSEEventDecoderStream.d.ts
|
|
2
|
+
type PipelineSSEEvent = {
|
|
3
|
+
event: string;
|
|
4
|
+
data: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
retry?: number;
|
|
7
|
+
};
|
|
8
|
+
declare class SSEEventDecoderStream extends TransformStream<string, PipelineSSEEvent> {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { PipelineSSEEvent, SSEEventDecoderStream };
|
|
13
|
+
//# sourceMappingURL=SSEEventDecoderStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SSEEventDecoderStream.d.ts","names":[],"sources":["../../../../src/core/utils/stream/SSEEventDecoderStream.ts"],"mappings":";KAGY;EACV;EACA;EACA;EACA;;cAGW,8BAA8B,wBAEzC"}
|