assistant-stream 0.0.18 → 0.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/dist/AssistantStream-dm_T4K6d.d.mts +28 -0
- package/dist/AssistantStream-dm_T4K6d.d.ts +28 -0
- package/dist/ai-sdk.d.mts +4 -4
- package/dist/ai-sdk.d.ts +4 -4
- package/dist/ai-sdk.js +9 -32
- package/dist/ai-sdk.js.map +1 -1
- package/dist/ai-sdk.mjs +8 -8
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/chunk-ZSSWV6GU.mjs +11 -0
- package/dist/chunk-ZSSWV6GU.mjs.map +1 -0
- package/dist/index.d.mts +26 -5
- package/dist/index.d.ts +26 -5
- package/dist/index.js +250 -242
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +258 -228
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/AssistantStream-BvnjeSxd.d.mts +0 -30
- package/dist/AssistantStream-BvnjeSxd.d.ts +0 -30
- package/dist/chunk-K4MZ4HSJ.mjs +0 -36
- package/dist/chunk-K4MZ4HSJ.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,197 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AssistantStream,
|
|
3
2
|
generateId
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZSSWV6GU.mjs";
|
|
4
|
+
|
|
5
|
+
// src/core/AssistantStream.ts
|
|
6
|
+
var AssistantStream = {
|
|
7
|
+
toResponse(stream, transformer) {
|
|
8
|
+
return new Response(AssistantStream.toByteStream(stream, transformer));
|
|
9
|
+
},
|
|
10
|
+
fromResponse(response, transformer) {
|
|
11
|
+
return AssistantStream.fromByteStream(response.body, transformer);
|
|
12
|
+
},
|
|
13
|
+
toByteStream(stream, transformer) {
|
|
14
|
+
return stream.pipeThrough(transformer);
|
|
15
|
+
},
|
|
16
|
+
fromByteStream(readable, transformer) {
|
|
17
|
+
return readable.pipeThrough(transformer);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/core/utils/PipeableTransformStream.ts
|
|
22
|
+
var PipeableTransformStream = class extends TransformStream {
|
|
23
|
+
constructor(transform) {
|
|
24
|
+
super();
|
|
25
|
+
const readable = transform(super.readable);
|
|
26
|
+
Object.defineProperty(this, "readable", {
|
|
27
|
+
value: readable,
|
|
28
|
+
writable: false
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/core/serialization/DataStream.ts
|
|
34
|
+
var DataStreamEncoder = class {
|
|
35
|
+
_transformStream;
|
|
36
|
+
get writable() {
|
|
37
|
+
return this._transformStream.writable;
|
|
38
|
+
}
|
|
39
|
+
get readable() {
|
|
40
|
+
return this._transformStream.readable;
|
|
41
|
+
}
|
|
42
|
+
constructor() {
|
|
43
|
+
this._transformStream = new PipeableTransformStream((readable) => {
|
|
44
|
+
const transform = new TransformStream({
|
|
45
|
+
transform(chunk, controller) {
|
|
46
|
+
const type = chunk.type;
|
|
47
|
+
switch (type) {
|
|
48
|
+
case "text-delta":
|
|
49
|
+
controller.enqueue("0:" + JSON.stringify(chunk.textDelta) + "\n");
|
|
50
|
+
break;
|
|
51
|
+
case "tool-call-begin":
|
|
52
|
+
controller.enqueue(
|
|
53
|
+
"b:" + JSON.stringify({
|
|
54
|
+
toolCallId: chunk.toolCallId,
|
|
55
|
+
toolName: chunk.toolName
|
|
56
|
+
}) + "\n"
|
|
57
|
+
);
|
|
58
|
+
break;
|
|
59
|
+
case "tool-call-delta":
|
|
60
|
+
controller.enqueue(
|
|
61
|
+
"c:" + JSON.stringify({
|
|
62
|
+
toolCallId: chunk.toolCallId,
|
|
63
|
+
argsTextDelta: chunk.argsTextDelta
|
|
64
|
+
}) + "\n"
|
|
65
|
+
);
|
|
66
|
+
break;
|
|
67
|
+
case "tool-result":
|
|
68
|
+
controller.enqueue(
|
|
69
|
+
"a:" + JSON.stringify({
|
|
70
|
+
toolCallId: chunk.toolCallId,
|
|
71
|
+
result: chunk.result
|
|
72
|
+
}) + "\n"
|
|
73
|
+
);
|
|
74
|
+
break;
|
|
75
|
+
case "error":
|
|
76
|
+
controller.enqueue(`3:${JSON.stringify(chunk.error)}
|
|
77
|
+
`);
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
const exhaustiveCheck = type;
|
|
81
|
+
throw new Error(`unsupported chunk type: ${exhaustiveCheck}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return readable.pipeThrough(transform).pipeThrough(new TextEncoderStream());
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var decodeStreamPart = (part) => {
|
|
90
|
+
const index = part.indexOf(":");
|
|
91
|
+
if (index === -1) throw new Error("Invalid stream part");
|
|
92
|
+
return {
|
|
93
|
+
type: part.slice(0, index),
|
|
94
|
+
value: JSON.parse(part.slice(index + 1))
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
var DataStreamDecoder = class {
|
|
98
|
+
_transformStream;
|
|
99
|
+
get writable() {
|
|
100
|
+
return this._transformStream.writable;
|
|
101
|
+
}
|
|
102
|
+
get readable() {
|
|
103
|
+
return this._transformStream.readable;
|
|
104
|
+
}
|
|
105
|
+
constructor() {
|
|
106
|
+
this._transformStream = new PipeableTransformStream((readable) => {
|
|
107
|
+
const transform = new TransformStream({
|
|
108
|
+
transform(chunk, controller) {
|
|
109
|
+
const { type, value } = decodeStreamPart(chunk);
|
|
110
|
+
switch (type) {
|
|
111
|
+
case "0":
|
|
112
|
+
controller.enqueue({
|
|
113
|
+
type: "text-delta",
|
|
114
|
+
textDelta: value
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
case "b": {
|
|
118
|
+
const { toolCallId, toolName } = value;
|
|
119
|
+
controller.enqueue({
|
|
120
|
+
type: "tool-call-begin",
|
|
121
|
+
toolCallId,
|
|
122
|
+
toolName
|
|
123
|
+
});
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case "c": {
|
|
127
|
+
const { toolCallId, argsTextDelta } = value;
|
|
128
|
+
controller.enqueue({
|
|
129
|
+
type: "tool-call-delta",
|
|
130
|
+
toolCallId,
|
|
131
|
+
argsTextDelta
|
|
132
|
+
});
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case "a": {
|
|
136
|
+
const { toolCallId, result } = value;
|
|
137
|
+
controller.enqueue({
|
|
138
|
+
type: "tool-result",
|
|
139
|
+
toolCallId,
|
|
140
|
+
result
|
|
141
|
+
});
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case "9": {
|
|
145
|
+
const { toolCallId, args } = value;
|
|
146
|
+
controller.enqueue({
|
|
147
|
+
type: "tool-call-begin",
|
|
148
|
+
toolCallId,
|
|
149
|
+
toolName: toolCallId
|
|
150
|
+
});
|
|
151
|
+
controller.enqueue({
|
|
152
|
+
type: "tool-call-delta",
|
|
153
|
+
toolCallId,
|
|
154
|
+
argsTextDelta: JSON.stringify(args)
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case "2":
|
|
159
|
+
case "3":
|
|
160
|
+
case "8":
|
|
161
|
+
case "d":
|
|
162
|
+
case "e": {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
default:
|
|
166
|
+
const exhaustiveCheck = type;
|
|
167
|
+
throw new Error(`unsupported chunk type: ${exhaustiveCheck}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return readable.pipeThrough(new TextDecoderStream()).pipeThrough(new ChunkByLineStream()).pipeThrough(transform);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var ChunkByLineStream = class extends TransformStream {
|
|
176
|
+
buffer = "";
|
|
177
|
+
constructor() {
|
|
178
|
+
super({
|
|
179
|
+
transform: (chunk, controller) => {
|
|
180
|
+
this.buffer += chunk;
|
|
181
|
+
const lines = this.buffer.split("\n");
|
|
182
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
183
|
+
controller.enqueue(lines[i]);
|
|
184
|
+
}
|
|
185
|
+
this.buffer = lines[lines.length - 1];
|
|
186
|
+
},
|
|
187
|
+
flush: (controller) => {
|
|
188
|
+
if (this.buffer) {
|
|
189
|
+
controller.enqueue(this.buffer);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
5
195
|
|
|
6
196
|
// src/core/modules/text.ts
|
|
7
197
|
var TextStreamControllerImpl = class {
|
|
@@ -21,19 +211,17 @@ var TextStreamControllerImpl = class {
|
|
|
21
211
|
}
|
|
22
212
|
};
|
|
23
213
|
var createTextStream = (readable) => {
|
|
24
|
-
return new
|
|
25
|
-
|
|
26
|
-
start(c)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
pull(c)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
cancel(c)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
);
|
|
214
|
+
return new ReadableStream({
|
|
215
|
+
start(c) {
|
|
216
|
+
return readable.start?.(new TextStreamControllerImpl(c));
|
|
217
|
+
},
|
|
218
|
+
pull(c) {
|
|
219
|
+
return readable.pull?.(new TextStreamControllerImpl(c));
|
|
220
|
+
},
|
|
221
|
+
cancel(c) {
|
|
222
|
+
return readable.cancel?.(c);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
37
225
|
};
|
|
38
226
|
|
|
39
227
|
// src/core/modules/tool-call.ts
|
|
@@ -51,7 +239,7 @@ var ToolCallStreamControllerImpl = class {
|
|
|
51
239
|
this._argsTextController = c;
|
|
52
240
|
}
|
|
53
241
|
});
|
|
54
|
-
stream.
|
|
242
|
+
stream.pipeTo(
|
|
55
243
|
new WritableStream({
|
|
56
244
|
write: (chunk) => {
|
|
57
245
|
if (chunk.type !== "text-delta")
|
|
@@ -91,19 +279,17 @@ var createToolCallStream = (readable) => {
|
|
|
91
279
|
toolCallId: readable.toolCallId,
|
|
92
280
|
toolName: readable.toolName
|
|
93
281
|
};
|
|
94
|
-
return new
|
|
95
|
-
|
|
96
|
-
start(c)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
pull(c)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
cancel(c)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
})
|
|
106
|
-
);
|
|
282
|
+
return new ReadableStream({
|
|
283
|
+
start(c) {
|
|
284
|
+
return readable.start?.(new ToolCallStreamControllerImpl(c, options));
|
|
285
|
+
},
|
|
286
|
+
pull(c) {
|
|
287
|
+
return readable.pull?.(new ToolCallStreamControllerImpl(c, options));
|
|
288
|
+
},
|
|
289
|
+
cancel(c) {
|
|
290
|
+
return readable.cancel?.(c);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
107
293
|
};
|
|
108
294
|
|
|
109
295
|
// src/core/modules/runs.ts
|
|
@@ -176,7 +362,7 @@ var createMergeStream = () => {
|
|
|
176
362
|
throw new Error(
|
|
177
363
|
"Cannot add streams after the run callback has settled."
|
|
178
364
|
);
|
|
179
|
-
const item = { reader: stream.
|
|
365
|
+
const item = { reader: stream.getReader() };
|
|
180
366
|
list.push(item);
|
|
181
367
|
if (list.length === 1) {
|
|
182
368
|
handlePull(item);
|
|
@@ -194,7 +380,7 @@ var RunControllerImpl = class {
|
|
|
194
380
|
this._merge.seal();
|
|
195
381
|
this._textPartController?.close();
|
|
196
382
|
}
|
|
197
|
-
|
|
383
|
+
merge(stream) {
|
|
198
384
|
this._merge.addStream(stream);
|
|
199
385
|
}
|
|
200
386
|
appendText(textDelta) {
|
|
@@ -210,225 +396,68 @@ var RunControllerImpl = class {
|
|
|
210
396
|
controller = c;
|
|
211
397
|
}
|
|
212
398
|
});
|
|
213
|
-
this.
|
|
399
|
+
this.merge(textStream);
|
|
214
400
|
return controller;
|
|
215
401
|
}
|
|
216
402
|
addToolCallPart(options) {
|
|
217
|
-
const opt = typeof options === "string" ? { toolName: options
|
|
403
|
+
const opt = typeof options === "string" ? { toolName: options } : options;
|
|
218
404
|
let controller;
|
|
219
405
|
const toolCallStream = createToolCallStream({
|
|
220
|
-
toolCallId: opt.toolCallId,
|
|
406
|
+
toolCallId: opt.toolCallId ?? generateId(),
|
|
221
407
|
toolName: opt.toolName,
|
|
222
408
|
start(c) {
|
|
223
409
|
controller = c;
|
|
224
410
|
}
|
|
225
411
|
});
|
|
226
|
-
this.
|
|
412
|
+
this.merge(toolCallStream);
|
|
413
|
+
if (opt.args !== void 0) {
|
|
414
|
+
controller.argsText.append(JSON.stringify(opt.args));
|
|
415
|
+
controller.argsText.close();
|
|
416
|
+
}
|
|
417
|
+
if (opt !== void 0) {
|
|
418
|
+
controller.setResult(opt.result);
|
|
419
|
+
}
|
|
227
420
|
return controller;
|
|
228
421
|
}
|
|
229
422
|
addError(error) {
|
|
230
423
|
this._merge.addStream(
|
|
231
|
-
new
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
})
|
|
240
|
-
)
|
|
424
|
+
new ReadableStream({
|
|
425
|
+
start(c) {
|
|
426
|
+
c.enqueue({
|
|
427
|
+
type: "error",
|
|
428
|
+
error
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
})
|
|
241
432
|
);
|
|
242
433
|
}
|
|
243
434
|
};
|
|
244
|
-
function
|
|
435
|
+
function createAssistantStream(callback) {
|
|
245
436
|
const controller = new RunControllerImpl();
|
|
246
437
|
const promiseOrVoid = callback(controller);
|
|
247
438
|
if (promiseOrVoid instanceof Promise) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
439
|
+
const runTask = async () => {
|
|
440
|
+
try {
|
|
441
|
+
await promiseOrVoid;
|
|
442
|
+
} catch (e) {
|
|
443
|
+
controller.addError(e instanceof Error ? e.message : String(e));
|
|
444
|
+
throw e;
|
|
445
|
+
} finally {
|
|
446
|
+
controller.close();
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
runTask();
|
|
252
450
|
} else {
|
|
253
451
|
controller.close();
|
|
254
452
|
}
|
|
255
|
-
return
|
|
453
|
+
return controller.getReadable();
|
|
454
|
+
}
|
|
455
|
+
function createAssistantStreamResponse(callback) {
|
|
456
|
+
return AssistantStream.toResponse(
|
|
457
|
+
createAssistantStream(callback),
|
|
458
|
+
new DataStreamEncoder()
|
|
459
|
+
);
|
|
256
460
|
}
|
|
257
|
-
|
|
258
|
-
// src/core/utils/PipeableTransformStream.ts
|
|
259
|
-
var PipeableTransformStream = class extends TransformStream {
|
|
260
|
-
constructor(transform) {
|
|
261
|
-
super();
|
|
262
|
-
const readable = transform(super.readable);
|
|
263
|
-
Object.defineProperty(this, "readable", {
|
|
264
|
-
value: readable,
|
|
265
|
-
writable: false
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
// src/core/serialization/DataStream.ts
|
|
271
|
-
var DataStreamEncoder = class {
|
|
272
|
-
_transformStream;
|
|
273
|
-
get writable() {
|
|
274
|
-
return this._transformStream.writable;
|
|
275
|
-
}
|
|
276
|
-
get readable() {
|
|
277
|
-
return this._transformStream.readable;
|
|
278
|
-
}
|
|
279
|
-
constructor() {
|
|
280
|
-
this._transformStream = new PipeableTransformStream((readable) => {
|
|
281
|
-
const transform = new TransformStream({
|
|
282
|
-
transform(chunk, controller) {
|
|
283
|
-
const type = chunk.type;
|
|
284
|
-
switch (type) {
|
|
285
|
-
case "text-delta":
|
|
286
|
-
controller.enqueue("0:" + JSON.stringify(chunk.textDelta) + "\n");
|
|
287
|
-
break;
|
|
288
|
-
case "tool-call-begin":
|
|
289
|
-
controller.enqueue(
|
|
290
|
-
"b:" + JSON.stringify({
|
|
291
|
-
toolCallId: chunk.toolCallId,
|
|
292
|
-
toolName: chunk.toolName
|
|
293
|
-
}) + "\n"
|
|
294
|
-
);
|
|
295
|
-
break;
|
|
296
|
-
case "tool-call-delta":
|
|
297
|
-
controller.enqueue(
|
|
298
|
-
"c:" + JSON.stringify({
|
|
299
|
-
toolCallId: chunk.toolCallId,
|
|
300
|
-
argsTextDelta: chunk.argsTextDelta
|
|
301
|
-
}) + "\n"
|
|
302
|
-
);
|
|
303
|
-
break;
|
|
304
|
-
case "tool-result":
|
|
305
|
-
controller.enqueue(
|
|
306
|
-
"a:" + JSON.stringify({
|
|
307
|
-
toolCallId: chunk.toolCallId,
|
|
308
|
-
result: chunk.result
|
|
309
|
-
}) + "\n"
|
|
310
|
-
);
|
|
311
|
-
break;
|
|
312
|
-
case "error":
|
|
313
|
-
controller.enqueue(`3:${JSON.stringify(chunk.error)}
|
|
314
|
-
`);
|
|
315
|
-
break;
|
|
316
|
-
default:
|
|
317
|
-
const exhaustiveCheck = type;
|
|
318
|
-
throw new Error(`unsupported chunk type: ${exhaustiveCheck}`);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
return readable.pipeThrough(transform).pipeThrough(new TextEncoderStream());
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
var decodeStreamPart = (part) => {
|
|
327
|
-
const index = part.indexOf(":");
|
|
328
|
-
if (index === -1) throw new Error("Invalid stream part");
|
|
329
|
-
return {
|
|
330
|
-
type: part.slice(0, index),
|
|
331
|
-
value: JSON.parse(part.slice(index + 1))
|
|
332
|
-
};
|
|
333
|
-
};
|
|
334
|
-
var DataStreamDecoder = class {
|
|
335
|
-
_transformStream;
|
|
336
|
-
get writable() {
|
|
337
|
-
return this._transformStream.writable;
|
|
338
|
-
}
|
|
339
|
-
get readable() {
|
|
340
|
-
return this._transformStream.readable;
|
|
341
|
-
}
|
|
342
|
-
constructor() {
|
|
343
|
-
this._transformStream = new PipeableTransformStream((readable) => {
|
|
344
|
-
const transform = new TransformStream({
|
|
345
|
-
transform(chunk, controller) {
|
|
346
|
-
const { type, value } = decodeStreamPart(chunk);
|
|
347
|
-
switch (type) {
|
|
348
|
-
case "0":
|
|
349
|
-
controller.enqueue({
|
|
350
|
-
type: "text-delta",
|
|
351
|
-
textDelta: value
|
|
352
|
-
});
|
|
353
|
-
break;
|
|
354
|
-
case "b": {
|
|
355
|
-
const { toolCallId, toolName } = value;
|
|
356
|
-
controller.enqueue({
|
|
357
|
-
type: "tool-call-begin",
|
|
358
|
-
toolCallId,
|
|
359
|
-
toolName
|
|
360
|
-
});
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
case "c": {
|
|
364
|
-
const { toolCallId, argsTextDelta } = value;
|
|
365
|
-
controller.enqueue({
|
|
366
|
-
type: "tool-call-delta",
|
|
367
|
-
toolCallId,
|
|
368
|
-
argsTextDelta
|
|
369
|
-
});
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
case "a": {
|
|
373
|
-
const { toolCallId, result } = value;
|
|
374
|
-
controller.enqueue({
|
|
375
|
-
type: "tool-result",
|
|
376
|
-
toolCallId,
|
|
377
|
-
result
|
|
378
|
-
});
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
case "9": {
|
|
382
|
-
const { toolCallId, args } = value;
|
|
383
|
-
controller.enqueue({
|
|
384
|
-
type: "tool-call-begin",
|
|
385
|
-
toolCallId,
|
|
386
|
-
toolName: toolCallId
|
|
387
|
-
});
|
|
388
|
-
controller.enqueue({
|
|
389
|
-
type: "tool-call-delta",
|
|
390
|
-
toolCallId,
|
|
391
|
-
argsTextDelta: JSON.stringify(args)
|
|
392
|
-
});
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
case "2":
|
|
396
|
-
case "3":
|
|
397
|
-
case "8":
|
|
398
|
-
case "d":
|
|
399
|
-
case "e": {
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
default:
|
|
403
|
-
const exhaustiveCheck = type;
|
|
404
|
-
throw new Error(`unsupported chunk type: ${exhaustiveCheck}`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
return readable.pipeThrough(new TextDecoderStream()).pipeThrough(new ChunkByLineStream()).pipeThrough(transform);
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
var ChunkByLineStream = class extends TransformStream {
|
|
413
|
-
buffer = "";
|
|
414
|
-
constructor() {
|
|
415
|
-
super({
|
|
416
|
-
transform: (chunk, controller) => {
|
|
417
|
-
this.buffer += chunk;
|
|
418
|
-
const lines = this.buffer.split("\n");
|
|
419
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
420
|
-
controller.enqueue(lines[i]);
|
|
421
|
-
}
|
|
422
|
-
this.buffer = lines[lines.length - 1];
|
|
423
|
-
},
|
|
424
|
-
flush: (controller) => {
|
|
425
|
-
if (this.buffer) {
|
|
426
|
-
controller.enqueue(this.buffer);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
461
|
|
|
433
462
|
// src/core/serialization/PlainText.ts
|
|
434
463
|
var PlainTextEncoder = class {
|
|
@@ -981,7 +1010,7 @@ var AssistantMessageStream = class _AssistantMessageStream {
|
|
|
981
1010
|
}
|
|
982
1011
|
static fromAssistantStream(stream) {
|
|
983
1012
|
return new _AssistantMessageStream(
|
|
984
|
-
stream.
|
|
1013
|
+
stream.pipeThrough(assistantMessageAccumulator())
|
|
985
1014
|
);
|
|
986
1015
|
}
|
|
987
1016
|
async unstable_result() {
|
|
@@ -1026,6 +1055,7 @@ export {
|
|
|
1026
1055
|
DataStreamEncoder,
|
|
1027
1056
|
PlainTextDecoder,
|
|
1028
1057
|
PlainTextEncoder,
|
|
1029
|
-
|
|
1058
|
+
createAssistantStream,
|
|
1059
|
+
createAssistantStreamResponse
|
|
1030
1060
|
};
|
|
1031
1061
|
//# sourceMappingURL=index.mjs.map
|