assistant-stream 0.3.14 → 0.3.16
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 +6 -4
- package/dist/core/AssistantStream.d.ts +50 -9
- package/dist/core/AssistantStream.d.ts.map +1 -1
- package/dist/core/AssistantStream.js +39 -15
- package/dist/core/AssistantStream.js.map +1 -1
- package/dist/core/AssistantStreamChunk.d.ts +84 -61
- package/dist/core/AssistantStreamChunk.d.ts.map +1 -1
- package/dist/core/AssistantStreamChunk.js +0 -2
- package/dist/core/accumulators/AssistantMessageStream.d.ts +15 -11
- package/dist/core/accumulators/AssistantMessageStream.d.ts.map +1 -1
- package/dist/core/accumulators/AssistantMessageStream.js +52 -48
- package/dist/core/accumulators/AssistantMessageStream.js.map +1 -1
- package/dist/core/accumulators/TimingTracker.d.ts +15 -11
- package/dist/core/accumulators/TimingTracker.d.ts.map +1 -1
- package/dist/core/accumulators/TimingTracker.js +36 -43
- package/dist/core/accumulators/TimingTracker.js.map +1 -1
- package/dist/core/accumulators/assistant-message-accumulator.d.ts +21 -11
- package/dist/core/accumulators/assistant-message-accumulator.d.ts.map +1 -1
- package/dist/core/accumulators/assistant-message-accumulator.js +349 -390
- package/dist/core/accumulators/assistant-message-accumulator.js.map +1 -1
- package/dist/core/converters/toGenericMessages.d.ts +49 -47
- package/dist/core/converters/toGenericMessages.d.ts.map +1 -1
- package/dist/core/converters/toGenericMessages.js +122 -136
- package/dist/core/converters/toGenericMessages.js.map +1 -1
- package/dist/core/modules/assistant-stream.d.ts +92 -28
- package/dist/core/modules/assistant-stream.d.ts.map +1 -1
- package/dist/core/modules/assistant-stream.js +177 -162
- package/dist/core/modules/assistant-stream.js.map +1 -1
- package/dist/core/modules/text.d.ts +11 -7
- package/dist/core/modules/text.d.ts.map +1 -1
- package/dist/core/modules/text.js +45 -45
- package/dist/core/modules/text.js.map +1 -1
- package/dist/core/modules/tool-call.d.ts +15 -11
- package/dist/core/modules/tool-call.d.ts.map +1 -1
- package/dist/core/modules/tool-call.js +81 -96
- package/dist/core/modules/tool-call.js.map +1 -1
- package/dist/core/object/ObjectStreamAccumulator.d.ts +13 -9
- package/dist/core/object/ObjectStreamAccumulator.d.ts.map +1 -1
- package/dist/core/object/ObjectStreamAccumulator.js +44 -52
- package/dist/core/object/ObjectStreamAccumulator.js.map +1 -1
- package/dist/core/object/ObjectStreamResponse.d.ts +12 -8
- package/dist/core/object/ObjectStreamResponse.d.ts.map +1 -1
- package/dist/core/object/ObjectStreamResponse.js +52 -71
- package/dist/core/object/ObjectStreamResponse.js.map +1 -1
- package/dist/core/object/createObjectStream.d.ts +14 -8
- package/dist/core/object/createObjectStream.d.ts.map +1 -1
- package/dist/core/object/createObjectStream.js +50 -47
- package/dist/core/object/createObjectStream.js.map +1 -1
- package/dist/core/object/types.d.ts +14 -11
- package/dist/core/object/types.d.ts.map +1 -1
- package/dist/core/object/types.js +0 -2
- package/dist/core/serialization/PlainText.d.ts +11 -7
- package/dist/core/serialization/PlainText.d.ts.map +1 -1
- package/dist/core/serialization/PlainText.js +40 -48
- package/dist/core/serialization/PlainText.js.map +1 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.d.ts +11 -7
- package/dist/core/serialization/assistant-transport/AssistantTransport.d.ts.map +1 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.js +102 -117
- package/dist/core/serialization/assistant-transport/AssistantTransport.js.map +1 -1
- package/dist/core/serialization/data-stream/DataStream.d.ts +11 -7
- package/dist/core/serialization/data-stream/DataStream.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/DataStream.js +320 -371
- package/dist/core/serialization/data-stream/DataStream.js.map +1 -1
- package/dist/core/serialization/data-stream/chunk-types.d.ts +101 -100
- package/dist/core/serialization/data-stream/chunk-types.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/chunk-types.js +27 -23
- package/dist/core/serialization/data-stream/chunk-types.js.map +1 -1
- package/dist/core/serialization/data-stream/serialization.d.ts +9 -5
- package/dist/core/serialization/data-stream/serialization.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/serialization.js +23 -24
- package/dist/core/serialization/data-stream/serialization.js.map +1 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts +15 -12
- package/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts.map +1 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.js +205 -228
- package/dist/core/serialization/ui-message-stream/UIMessageStream.js.map +1 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.d.ts +68 -65
- package/dist/core/serialization/ui-message-stream/chunk-types.d.ts.map +1 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.js +0 -2
- package/dist/core/tool/ToolCallReader.d.ts +34 -30
- package/dist/core/tool/ToolCallReader.d.ts.map +1 -1
- package/dist/core/tool/ToolCallReader.js +264 -317
- package/dist/core/tool/ToolCallReader.js.map +1 -1
- package/dist/core/tool/ToolExecutionStream.d.ts +20 -17
- package/dist/core/tool/ToolExecutionStream.d.ts.map +1 -1
- package/dist/core/tool/ToolExecutionStream.js +123 -146
- package/dist/core/tool/ToolExecutionStream.js.map +1 -1
- package/dist/core/tool/ToolResponse.d.ts +60 -19
- package/dist/core/tool/ToolResponse.d.ts.map +1 -1
- package/dist/core/tool/ToolResponse.js +51 -34
- package/dist/core/tool/ToolResponse.js.map +1 -1
- package/dist/core/tool/schema-utils.d.ts +19 -15
- package/dist/core/tool/schema-utils.d.ts.map +1 -1
- package/dist/core/tool/schema-utils.js +50 -84
- package/dist/core/tool/schema-utils.js.map +1 -1
- package/dist/core/tool/tool-types.d.ts +173 -92
- package/dist/core/tool/tool-types.d.ts.map +1 -1
- package/dist/core/tool/tool-types.js +0 -2
- package/dist/core/tool/toolResultStream.d.ts +24 -7
- package/dist/core/tool/toolResultStream.d.ts.map +1 -1
- package/dist/core/tool/toolResultStream.js +128 -145
- package/dist/core/tool/toolResultStream.js.map +1 -1
- package/dist/core/tool/type-path-utils.d.ts +8 -19
- package/dist/core/tool/type-path-utils.d.ts.map +1 -1
- package/dist/core/tool/type-path-utils.js +0 -2
- package/dist/core/utils/Counter.d.ts +6 -3
- package/dist/core/utils/Counter.d.ts.map +1 -1
- package/dist/core/utils/Counter.js +10 -6
- package/dist/core/utils/Counter.js.map +1 -1
- package/dist/core/utils/generateId.d.ts +4 -1
- package/dist/core/utils/generateId.d.ts.map +1 -1
- package/dist/core/utils/generateId.js +5 -1
- package/dist/core/utils/generateId.js.map +1 -1
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts +15 -11
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/AssistantMetaTransformStream.js +38 -42
- package/dist/core/utils/stream/AssistantMetaTransformStream.js.map +1 -1
- package/dist/core/utils/stream/AssistantTransformStream.d.ts +11 -8
- package/dist/core/utils/stream/AssistantTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/AssistantTransformStream.js +37 -35
- package/dist/core/utils/stream/AssistantTransformStream.js.map +1 -1
- package/dist/core/utils/stream/LineDecoderStream.d.ts +6 -3
- package/dist/core/utils/stream/LineDecoderStream.d.ts.map +1 -1
- package/dist/core/utils/stream/LineDecoderStream.js +23 -26
- package/dist/core/utils/stream/LineDecoderStream.js.map +1 -1
- package/dist/core/utils/stream/PipeableTransformStream.d.ts +5 -2
- package/dist/core/utils/stream/PipeableTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/PipeableTransformStream.js +14 -10
- package/dist/core/utils/stream/PipeableTransformStream.js.map +1 -1
- package/dist/core/utils/stream/SSE.d.ts +10 -6
- package/dist/core/utils/stream/SSE.d.ts.map +1 -1
- package/dist/core/utils/stream/SSE.js +79 -91
- package/dist/core/utils/stream/SSE.js.map +1 -1
- package/dist/core/utils/stream/UnderlyingReadable.d.ts +7 -4
- package/dist/core/utils/stream/UnderlyingReadable.d.ts.map +1 -1
- package/dist/core/utils/stream/UnderlyingReadable.js +0 -2
- package/dist/core/utils/stream/merge.d.ts +11 -7
- package/dist/core/utils/stream/merge.d.ts.map +1 -1
- package/dist/core/utils/stream/merge.js +68 -170
- package/dist/core/utils/stream/merge.js.map +1 -1
- package/dist/core/utils/stream/path-utils.d.ts +11 -7
- package/dist/core/utils/stream/path-utils.d.ts.map +1 -1
- package/dist/core/utils/stream/path-utils.js +46 -52
- package/dist/core/utils/stream/path-utils.js.map +1 -1
- package/dist/core/utils/types.d.ts +109 -113
- package/dist/core/utils/types.d.ts.map +1 -1
- package/dist/core/utils/types.js +0 -2
- package/dist/core/utils/withPromiseOrValue.d.ts +4 -1
- package/dist/core/utils/withPromiseOrValue.d.ts.map +1 -1
- package/dist/core/utils/withPromiseOrValue.js +12 -15
- package/dist/core/utils/withPromiseOrValue.js.map +1 -1
- package/dist/index.d.ts +23 -24
- package/dist/index.js +16 -16
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts +141 -0
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts.map +1 -0
- package/dist/resumable/ResumableStreamContext.d.ts +28 -24
- package/dist/resumable/ResumableStreamContext.d.ts.map +1 -1
- package/dist/resumable/ResumableStreamContext.js +99 -114
- package/dist/resumable/ResumableStreamContext.js.map +1 -1
- package/dist/resumable/constants.d.ts +4 -1
- package/dist/resumable/constants.d.ts.map +1 -1
- package/dist/resumable/constants.js +5 -1
- package/dist/resumable/constants.js.map +1 -1
- package/dist/resumable/createResumableAssistantStreamResponse.d.ts +22 -21
- package/dist/resumable/createResumableAssistantStreamResponse.d.ts.map +1 -1
- package/dist/resumable/createResumableAssistantStreamResponse.js +25 -32
- package/dist/resumable/createResumableAssistantStreamResponse.js.map +1 -1
- package/dist/resumable/errors.d.ts +8 -5
- package/dist/resumable/errors.d.ts.map +1 -1
- package/dist/resumable/errors.js +14 -12
- package/dist/resumable/errors.js.map +1 -1
- package/dist/resumable/index.d.ts +7 -7
- package/dist/resumable/index.js +5 -5
- package/dist/resumable/stores/InMemoryResumableStreamStore.d.ts +14 -10
- package/dist/resumable/stores/InMemoryResumableStreamStore.d.ts.map +1 -1
- package/dist/resumable/stores/InMemoryResumableStreamStore.js +159 -193
- package/dist/resumable/stores/InMemoryResumableStreamStore.js.map +1 -1
- package/dist/resumable/stores/ioredis.d.ts +9 -5
- package/dist/resumable/stores/ioredis.d.ts.map +1 -1
- package/dist/resumable/stores/ioredis.js +70 -82
- package/dist/resumable/stores/ioredis.js.map +1 -1
- package/dist/resumable/stores/redis-impl.d.ts +51 -48
- package/dist/resumable/stores/redis-impl.d.ts.map +1 -1
- package/dist/resumable/stores/redis-impl.js +176 -176
- package/dist/resumable/stores/redis-impl.js.map +1 -1
- package/dist/resumable/stores/redis.d.ts +31 -28
- package/dist/resumable/stores/redis.d.ts.map +1 -1
- package/dist/resumable/stores/redis.js +87 -95
- package/dist/resumable/stores/redis.js.map +1 -1
- package/dist/resumable/types.d.ts +29 -26
- package/dist/resumable/types.d.ts.map +1 -1
- package/dist/resumable/types.js +0 -2
- package/dist/utils/AsyncIterableStream.d.ts +5 -2
- package/dist/utils/AsyncIterableStream.d.ts.map +1 -1
- package/dist/utils/AsyncIterableStream.js +17 -16
- package/dist/utils/AsyncIterableStream.js.map +1 -1
- package/dist/utils/json/fix-json.d.ts +4 -1
- package/dist/utils/json/fix-json.d.ts.map +1 -1
- package/dist/utils/json/fix-json.js +286 -380
- package/dist/utils/json/fix-json.js.map +1 -1
- package/dist/utils/json/is-json.d.ts +8 -4
- package/dist/utils/json/is-json.d.ts.map +1 -1
- package/dist/utils/json/is-json.js +13 -21
- package/dist/utils/json/is-json.js.map +1 -1
- package/dist/utils/json/json-value.d.ts +7 -4
- package/dist/utils/json/json-value.d.ts.map +1 -1
- package/dist/utils/json/json-value.js +0 -2
- package/dist/utils/json/parse-partial-json-object.d.ts +11 -8
- package/dist/utils/json/parse-partial-json-object.d.ts.map +1 -1
- package/dist/utils/json/parse-partial-json-object.js +50 -62
- package/dist/utils/json/parse-partial-json-object.js.map +1 -1
- package/dist/utils/promiseWithResolvers.d.ts +7 -4
- package/dist/utils/promiseWithResolvers.d.ts.map +1 -1
- package/dist/utils/promiseWithResolvers.js +17 -10
- package/dist/utils/promiseWithResolvers.js.map +1 -1
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +5 -5
- package/package.json +5 -4
- package/src/core/AssistantStream.ts +37 -0
- package/src/core/AssistantStreamChunk.ts +30 -0
- package/src/core/modules/assistant-stream.ts +68 -0
- package/src/core/tool/ToolResponse.ts +45 -1
- package/src/core/tool/tool-types.ts +102 -2
- package/src/core/tool/toolResultStream.ts +15 -0
- package/dist/core/AssistantStreamChunk.js.map +0 -1
- package/dist/core/object/types.js.map +0 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.js.map +0 -1
- package/dist/core/tool/tool-types.js.map +0 -1
- package/dist/core/tool/type-path-utils.js.map +0 -1
- package/dist/core/utils/stream/UnderlyingReadable.js.map +0 -1
- package/dist/core/utils/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/resumable/index.d.ts.map +0 -1
- package/dist/resumable/index.js.map +0 -1
- package/dist/resumable/types.js.map +0 -1
- package/dist/utils/json/json-value.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -1,377 +1,326 @@
|
|
|
1
1
|
import { AssistantTransformStream } from "../../utils/stream/AssistantTransformStream.js";
|
|
2
2
|
import { PipeableTransformStream } from "../../utils/stream/PipeableTransformStream.js";
|
|
3
|
-
import
|
|
3
|
+
import "./chunk-types.js";
|
|
4
4
|
import { LineDecoderStream } from "../../utils/stream/LineDecoderStream.js";
|
|
5
|
-
import { DataStreamChunkDecoder, DataStreamChunkEncoder
|
|
6
|
-
import { AssistantMetaTransformStream
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
case "update-state": {
|
|
160
|
-
controller.enqueue({
|
|
161
|
-
type: DataStreamStreamChunkType.AuiUpdateStateOperations,
|
|
162
|
-
value: chunk.operations,
|
|
163
|
-
});
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
// TODO ignore for now
|
|
167
|
-
// in the future, we should create a handler that waits for text parts to finish before continuing
|
|
168
|
-
case "tool-call-args-text-finish":
|
|
169
|
-
case "part-finish":
|
|
170
|
-
break;
|
|
171
|
-
default: {
|
|
172
|
-
const exhaustiveCheck = type;
|
|
173
|
-
throw new Error(`Unsupported chunk type: ${exhaustiveCheck}`);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
return readable
|
|
179
|
-
.pipeThrough(new AssistantMetaTransformStream())
|
|
180
|
-
.pipeThrough(transform)
|
|
181
|
-
.pipeThrough(new DataStreamChunkEncoder())
|
|
182
|
-
.pipeThrough(new TextEncoderStream());
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
5
|
+
import { DataStreamChunkDecoder, DataStreamChunkEncoder } from "./serialization.js";
|
|
6
|
+
import { AssistantMetaTransformStream } from "../../utils/stream/AssistantMetaTransformStream.js";
|
|
7
|
+
//#region src/core/serialization/data-stream/DataStream.ts
|
|
8
|
+
var DataStreamEncoder = class extends PipeableTransformStream {
|
|
9
|
+
headers = new Headers({
|
|
10
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
11
|
+
"x-vercel-ai-data-stream": "v1"
|
|
12
|
+
});
|
|
13
|
+
constructor() {
|
|
14
|
+
super((readable) => {
|
|
15
|
+
const transform = new TransformStream({ transform(chunk, controller) {
|
|
16
|
+
const type = chunk.type;
|
|
17
|
+
switch (type) {
|
|
18
|
+
case "part-start": {
|
|
19
|
+
const part = chunk.part;
|
|
20
|
+
if (part.type === "tool-call") {
|
|
21
|
+
const { type, ...value } = part;
|
|
22
|
+
controller.enqueue({
|
|
23
|
+
type: "b",
|
|
24
|
+
value
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (part.type === "source") {
|
|
28
|
+
const { type, ...value } = part;
|
|
29
|
+
controller.enqueue({
|
|
30
|
+
type: "h",
|
|
31
|
+
value
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (part.type === "data") {
|
|
35
|
+
const { type, ...value } = part;
|
|
36
|
+
controller.enqueue({
|
|
37
|
+
type: "aui-data",
|
|
38
|
+
value
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "text-delta": {
|
|
44
|
+
const part = chunk.meta;
|
|
45
|
+
switch (part.type) {
|
|
46
|
+
case "text":
|
|
47
|
+
if (part.parentId) controller.enqueue({
|
|
48
|
+
type: "aui-text-delta",
|
|
49
|
+
value: {
|
|
50
|
+
textDelta: chunk.textDelta,
|
|
51
|
+
parentId: part.parentId
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
else controller.enqueue({
|
|
55
|
+
type: "0",
|
|
56
|
+
value: chunk.textDelta
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
case "reasoning":
|
|
60
|
+
if (part.parentId) controller.enqueue({
|
|
61
|
+
type: "aui-reasoning-delta",
|
|
62
|
+
value: {
|
|
63
|
+
reasoningDelta: chunk.textDelta,
|
|
64
|
+
parentId: part.parentId
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
else controller.enqueue({
|
|
68
|
+
type: "g",
|
|
69
|
+
value: chunk.textDelta
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
72
|
+
case "tool-call":
|
|
73
|
+
controller.enqueue({
|
|
74
|
+
type: "c",
|
|
75
|
+
value: {
|
|
76
|
+
toolCallId: part.toolCallId,
|
|
77
|
+
argsTextDelta: chunk.textDelta
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
break;
|
|
81
|
+
default: throw new Error(`Unsupported part type for text-delta: ${part.type}`);
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case "result": {
|
|
86
|
+
const part = chunk.meta;
|
|
87
|
+
if (part.type !== "tool-call") throw new Error(`Result chunk on non-tool-call part not supported: ${part.type}`);
|
|
88
|
+
controller.enqueue({
|
|
89
|
+
type: "a",
|
|
90
|
+
value: {
|
|
91
|
+
toolCallId: part.toolCallId,
|
|
92
|
+
result: chunk.result,
|
|
93
|
+
artifact: chunk.artifact,
|
|
94
|
+
...chunk.isError ? { isError: chunk.isError } : {}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case "step-start": {
|
|
100
|
+
const { type, ...value } = chunk;
|
|
101
|
+
controller.enqueue({
|
|
102
|
+
type: "f",
|
|
103
|
+
value
|
|
104
|
+
});
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "step-finish": {
|
|
108
|
+
const { type, ...value } = chunk;
|
|
109
|
+
controller.enqueue({
|
|
110
|
+
type: "e",
|
|
111
|
+
value
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case "message-finish": {
|
|
116
|
+
const { type, ...value } = chunk;
|
|
117
|
+
controller.enqueue({
|
|
118
|
+
type: "d",
|
|
119
|
+
value
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case "error":
|
|
124
|
+
controller.enqueue({
|
|
125
|
+
type: "3",
|
|
126
|
+
value: chunk.error
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
case "annotations":
|
|
130
|
+
controller.enqueue({
|
|
131
|
+
type: "8",
|
|
132
|
+
value: chunk.annotations
|
|
133
|
+
});
|
|
134
|
+
break;
|
|
135
|
+
case "data":
|
|
136
|
+
controller.enqueue({
|
|
137
|
+
type: "2",
|
|
138
|
+
value: chunk.data
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
case "update-state":
|
|
142
|
+
controller.enqueue({
|
|
143
|
+
type: "aui-state",
|
|
144
|
+
value: chunk.operations
|
|
145
|
+
});
|
|
146
|
+
break;
|
|
147
|
+
case "tool-call-args-text-finish":
|
|
148
|
+
case "part-finish": break;
|
|
149
|
+
default: throw new Error(`Unsupported chunk type: ${type}`);
|
|
150
|
+
}
|
|
151
|
+
} });
|
|
152
|
+
return readable.pipeThrough(new AssistantMetaTransformStream()).pipeThrough(transform).pipeThrough(new DataStreamChunkEncoder()).pipeThrough(new TextEncoderStream());
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
186
156
|
const TOOL_CALL_ARGS_CLOSING_CHUNKS = [
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
157
|
+
"b",
|
|
158
|
+
"9",
|
|
159
|
+
"0",
|
|
160
|
+
"g",
|
|
161
|
+
"h",
|
|
162
|
+
"3",
|
|
163
|
+
"e",
|
|
164
|
+
"d",
|
|
165
|
+
"aui-text-delta",
|
|
166
|
+
"aui-reasoning-delta",
|
|
167
|
+
"aui-data"
|
|
198
168
|
];
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const exhaustiveCheck = type;
|
|
357
|
-
throw new Error(`unsupported chunk type: ${exhaustiveCheck}`);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
flush() {
|
|
362
|
-
activeToolCallArgsText?.close();
|
|
363
|
-
activeToolCallArgsText = undefined;
|
|
364
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
365
|
-
toolCallControllers.forEach((controller) => controller.close());
|
|
366
|
-
toolCallControllers.clear();
|
|
367
|
-
},
|
|
368
|
-
});
|
|
369
|
-
return readable
|
|
370
|
-
.pipeThrough(new TextDecoderStream())
|
|
371
|
-
.pipeThrough(new LineDecoderStream())
|
|
372
|
-
.pipeThrough(new DataStreamChunkDecoder())
|
|
373
|
-
.pipeThrough(transform);
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
169
|
+
var DataStreamDecoder = class extends PipeableTransformStream {
|
|
170
|
+
constructor() {
|
|
171
|
+
super((readable) => {
|
|
172
|
+
const toolCallControllers = /* @__PURE__ */ new Map();
|
|
173
|
+
let activeToolCallArgsText;
|
|
174
|
+
const transform = new AssistantTransformStream({
|
|
175
|
+
transform(chunk, controller) {
|
|
176
|
+
const { type, value } = chunk;
|
|
177
|
+
if (TOOL_CALL_ARGS_CLOSING_CHUNKS.includes(type)) {
|
|
178
|
+
activeToolCallArgsText?.close();
|
|
179
|
+
activeToolCallArgsText = void 0;
|
|
180
|
+
}
|
|
181
|
+
switch (type) {
|
|
182
|
+
case "g":
|
|
183
|
+
controller.appendReasoning(value);
|
|
184
|
+
break;
|
|
185
|
+
case "0":
|
|
186
|
+
controller.appendText(value);
|
|
187
|
+
break;
|
|
188
|
+
case "aui-text-delta":
|
|
189
|
+
controller.withParentId(value.parentId).appendText(value.textDelta);
|
|
190
|
+
break;
|
|
191
|
+
case "aui-reasoning-delta":
|
|
192
|
+
controller.withParentId(value.parentId).appendReasoning(value.reasoningDelta);
|
|
193
|
+
break;
|
|
194
|
+
case "b": {
|
|
195
|
+
const { toolCallId, toolName, parentId } = value;
|
|
196
|
+
const ctrl = parentId ? controller.withParentId(parentId) : controller;
|
|
197
|
+
if (toolCallControllers.has(toolCallId)) throw new Error(`Encountered duplicate tool call id: ${toolCallId}`);
|
|
198
|
+
const toolCallController = ctrl.addToolCallPart({
|
|
199
|
+
toolCallId,
|
|
200
|
+
toolName
|
|
201
|
+
});
|
|
202
|
+
toolCallControllers.set(toolCallId, toolCallController);
|
|
203
|
+
activeToolCallArgsText = toolCallController.argsText;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case "c": {
|
|
207
|
+
const { toolCallId, argsTextDelta } = value;
|
|
208
|
+
const toolCallController = toolCallControllers.get(toolCallId);
|
|
209
|
+
if (!toolCallController) throw new Error(`Encountered tool call with unknown id: ${toolCallId}`);
|
|
210
|
+
toolCallController.argsText.append(argsTextDelta);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "a": {
|
|
214
|
+
const { toolCallId, artifact, result, isError } = value;
|
|
215
|
+
const toolCallController = toolCallControllers.get(toolCallId);
|
|
216
|
+
if (!toolCallController) throw new Error(`Encountered tool call result with unknown id: ${toolCallId}`);
|
|
217
|
+
toolCallController.setResponse({
|
|
218
|
+
artifact,
|
|
219
|
+
result,
|
|
220
|
+
isError
|
|
221
|
+
});
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "9": {
|
|
225
|
+
const { toolCallId, toolName, args } = value;
|
|
226
|
+
let toolCallController = toolCallControllers.get(toolCallId);
|
|
227
|
+
if (toolCallController) toolCallController.argsText.close();
|
|
228
|
+
else {
|
|
229
|
+
toolCallController = controller.addToolCallPart({
|
|
230
|
+
toolCallId,
|
|
231
|
+
toolName,
|
|
232
|
+
args
|
|
233
|
+
});
|
|
234
|
+
toolCallControllers.set(toolCallId, toolCallController);
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
case "d":
|
|
239
|
+
controller.enqueue({
|
|
240
|
+
type: "message-finish",
|
|
241
|
+
path: [],
|
|
242
|
+
...value
|
|
243
|
+
});
|
|
244
|
+
break;
|
|
245
|
+
case "f":
|
|
246
|
+
controller.enqueue({
|
|
247
|
+
type: "step-start",
|
|
248
|
+
path: [],
|
|
249
|
+
...value
|
|
250
|
+
});
|
|
251
|
+
break;
|
|
252
|
+
case "e":
|
|
253
|
+
controller.enqueue({
|
|
254
|
+
type: "step-finish",
|
|
255
|
+
path: [],
|
|
256
|
+
...value
|
|
257
|
+
});
|
|
258
|
+
break;
|
|
259
|
+
case "2":
|
|
260
|
+
controller.enqueue({
|
|
261
|
+
type: "data",
|
|
262
|
+
path: [],
|
|
263
|
+
data: value
|
|
264
|
+
});
|
|
265
|
+
break;
|
|
266
|
+
case "8":
|
|
267
|
+
controller.enqueue({
|
|
268
|
+
type: "annotations",
|
|
269
|
+
path: [],
|
|
270
|
+
annotations: value
|
|
271
|
+
});
|
|
272
|
+
break;
|
|
273
|
+
case "h": {
|
|
274
|
+
const { parentId, ...sourceData } = value;
|
|
275
|
+
(parentId ? controller.withParentId(parentId) : controller).appendSource({
|
|
276
|
+
type: "source",
|
|
277
|
+
...sourceData
|
|
278
|
+
});
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case "3":
|
|
282
|
+
controller.enqueue({
|
|
283
|
+
type: "error",
|
|
284
|
+
path: [],
|
|
285
|
+
error: value
|
|
286
|
+
});
|
|
287
|
+
break;
|
|
288
|
+
case "k":
|
|
289
|
+
controller.appendFile({
|
|
290
|
+
type: "file",
|
|
291
|
+
...value
|
|
292
|
+
});
|
|
293
|
+
break;
|
|
294
|
+
case "aui-data":
|
|
295
|
+
controller.appendData({
|
|
296
|
+
type: "data",
|
|
297
|
+
...value
|
|
298
|
+
});
|
|
299
|
+
break;
|
|
300
|
+
case "aui-state":
|
|
301
|
+
controller.enqueue({
|
|
302
|
+
type: "update-state",
|
|
303
|
+
path: [],
|
|
304
|
+
operations: value
|
|
305
|
+
});
|
|
306
|
+
break;
|
|
307
|
+
case "j":
|
|
308
|
+
case "i": break;
|
|
309
|
+
default: throw new Error(`unsupported chunk type: ${type}`);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
flush() {
|
|
313
|
+
activeToolCallArgsText?.close();
|
|
314
|
+
activeToolCallArgsText = void 0;
|
|
315
|
+
toolCallControllers.forEach((controller) => controller.close());
|
|
316
|
+
toolCallControllers.clear();
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
return readable.pipeThrough(new TextDecoderStream()).pipeThrough(new LineDecoderStream()).pipeThrough(new DataStreamChunkDecoder()).pipeThrough(transform);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
//#endregion
|
|
324
|
+
export { DataStreamDecoder, DataStreamEncoder };
|
|
325
|
+
|
|
377
326
|
//# sourceMappingURL=DataStream.js.map
|