ai 6.0.268 → 6.0.270
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/CHANGELOG.md +17 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +151 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/test/index.d.mts +4 -1
- package/dist/test/index.d.ts +4 -1
- package/dist/test/index.js +6 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +6 -0
- package/dist/test/index.mjs.map +1 -1
- package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +6 -2
- package/package.json +3 -3
- package/src/embed/embed-many.ts +75 -6
- package/src/middleware/wrap-embedding-model.ts +8 -1
- package/src/model/get-embedding-model-max-input-bytes-per-call.ts +15 -0
- package/src/test/mock-embedding-model-v3.ts +9 -0
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +1 -0
- package/src/util/create-stitchable-stream.ts +35 -3
|
@@ -25,9 +25,14 @@ export function createStitchableStream<T>(): {
|
|
|
25
25
|
}> = [];
|
|
26
26
|
let controller: ReadableStreamDefaultController<T> | null = null;
|
|
27
27
|
let isClosed = false;
|
|
28
|
+
let isCancelled = false;
|
|
28
29
|
let waitForNewStream = createResolvablePromise<void>();
|
|
29
30
|
|
|
30
31
|
const terminate = () => {
|
|
32
|
+
if (isCancelled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
isClosed = true;
|
|
32
37
|
waitForNewStream.resolve();
|
|
33
38
|
|
|
@@ -40,6 +45,10 @@ export function createStitchableStream<T>(): {
|
|
|
40
45
|
};
|
|
41
46
|
|
|
42
47
|
const processPull = async () => {
|
|
48
|
+
if (isCancelled) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
// Case 1: Outer stream is closed and no more inner streams
|
|
44
53
|
if (isClosed && innerStreams.length === 0) {
|
|
45
54
|
controller?.close();
|
|
@@ -54,8 +63,14 @@ export function createStitchableStream<T>(): {
|
|
|
54
63
|
return processPull();
|
|
55
64
|
}
|
|
56
65
|
|
|
66
|
+
const currentStream = innerStreams[0];
|
|
67
|
+
|
|
57
68
|
try {
|
|
58
|
-
const { value, done } = await
|
|
69
|
+
const { value, done } = await currentStream.reader.read();
|
|
70
|
+
|
|
71
|
+
if (isCancelled) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
59
74
|
|
|
60
75
|
if (done) {
|
|
61
76
|
// Case 3: Current inner stream is done
|
|
@@ -73,8 +88,12 @@ export function createStitchableStream<T>(): {
|
|
|
73
88
|
controller?.enqueue(value);
|
|
74
89
|
}
|
|
75
90
|
} catch (error) {
|
|
91
|
+
if (isCancelled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
76
95
|
// Case 5: Current inner stream throws an error
|
|
77
|
-
|
|
96
|
+
currentStream.onError?.(error);
|
|
78
97
|
controller?.error(error);
|
|
79
98
|
innerStreams.shift(); // Remove the errored stream
|
|
80
99
|
terminate(); // we have errored, terminate all streams
|
|
@@ -88,12 +107,15 @@ export function createStitchableStream<T>(): {
|
|
|
88
107
|
},
|
|
89
108
|
pull: processPull,
|
|
90
109
|
async cancel() {
|
|
110
|
+
isCancelled = true;
|
|
111
|
+
isClosed = true;
|
|
112
|
+
waitForNewStream.resolve();
|
|
113
|
+
|
|
91
114
|
for (const { reader, onCancel } of innerStreams) {
|
|
92
115
|
onCancel?.();
|
|
93
116
|
await reader.cancel();
|
|
94
117
|
}
|
|
95
118
|
innerStreams = [];
|
|
96
|
-
isClosed = true;
|
|
97
119
|
},
|
|
98
120
|
}),
|
|
99
121
|
addStream: (
|
|
@@ -103,6 +125,12 @@ export function createStitchableStream<T>(): {
|
|
|
103
125
|
onCancel?: () => void;
|
|
104
126
|
},
|
|
105
127
|
) => {
|
|
128
|
+
if (isCancelled) {
|
|
129
|
+
callbacks?.onCancel?.();
|
|
130
|
+
void innerStream.cancel().catch(() => {});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
106
134
|
if (isClosed) {
|
|
107
135
|
throw new Error('Cannot add inner stream: outer stream is closed');
|
|
108
136
|
}
|
|
@@ -119,6 +147,10 @@ export function createStitchableStream<T>(): {
|
|
|
119
147
|
* finish processing and then close the outer stream.
|
|
120
148
|
*/
|
|
121
149
|
close: () => {
|
|
150
|
+
if (isCancelled) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
122
154
|
isClosed = true;
|
|
123
155
|
waitForNewStream.resolve();
|
|
124
156
|
|