@ai-sdk/provider-utils 3.0.12 → 3.0.14
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 +12 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +43 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ function combineHeaders(...headers) {
|
|
|
11
11
|
|
|
12
12
|
// src/convert-async-iterator-to-readable-stream.ts
|
|
13
13
|
function convertAsyncIteratorToReadableStream(iterator) {
|
|
14
|
+
let cancelled = false;
|
|
14
15
|
return new ReadableStream({
|
|
15
16
|
/**
|
|
16
17
|
* Called when the consumer wants to pull more data from the stream.
|
|
@@ -19,6 +20,7 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
19
20
|
* @returns {Promise<void>}
|
|
20
21
|
*/
|
|
21
22
|
async pull(controller) {
|
|
23
|
+
if (cancelled) return;
|
|
22
24
|
try {
|
|
23
25
|
const { value, done } = await iterator.next();
|
|
24
26
|
if (done) {
|
|
@@ -33,7 +35,14 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
33
35
|
/**
|
|
34
36
|
* Called when the consumer cancels the stream.
|
|
35
37
|
*/
|
|
36
|
-
cancel() {
|
|
38
|
+
async cancel(reason) {
|
|
39
|
+
cancelled = true;
|
|
40
|
+
if (iterator.return) {
|
|
41
|
+
try {
|
|
42
|
+
await iterator.return(reason);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
37
46
|
}
|
|
38
47
|
});
|
|
39
48
|
}
|
|
@@ -172,29 +181,42 @@ function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
|
172
181
|
return "runtime/unknown";
|
|
173
182
|
}
|
|
174
183
|
|
|
175
|
-
// src/
|
|
176
|
-
function
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
184
|
+
// src/normalize-headers.ts
|
|
185
|
+
function normalizeHeaders(headers) {
|
|
186
|
+
if (headers == null) {
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
const normalized = {};
|
|
190
|
+
if (headers instanceof Headers) {
|
|
191
|
+
headers.forEach((value, key) => {
|
|
192
|
+
normalized[key.toLowerCase()] = value;
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
if (!Array.isArray(headers)) {
|
|
196
|
+
headers = Object.entries(headers);
|
|
197
|
+
}
|
|
198
|
+
for (const [key, value] of headers) {
|
|
199
|
+
if (value != null) {
|
|
200
|
+
normalized[key.toLowerCase()] = value;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return normalized;
|
|
180
205
|
}
|
|
181
206
|
|
|
182
207
|
// src/with-user-agent-suffix.ts
|
|
183
208
|
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
184
|
-
const
|
|
185
|
-
headers != null ? headers : {}
|
|
186
|
-
);
|
|
187
|
-
const normalizedHeaders = new Headers(cleanedHeaders);
|
|
209
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
188
210
|
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
189
211
|
normalizedHeaders.set(
|
|
190
212
|
"user-agent",
|
|
191
213
|
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
192
214
|
);
|
|
193
|
-
return Object.fromEntries(normalizedHeaders);
|
|
215
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
194
216
|
}
|
|
195
217
|
|
|
196
218
|
// src/version.ts
|
|
197
|
-
var VERSION = true ? "3.0.
|
|
219
|
+
var VERSION = true ? "3.0.14" : "0.0.0-test";
|
|
198
220
|
|
|
199
221
|
// src/get-from-api.ts
|
|
200
222
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -815,6 +837,13 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
815
837
|
});
|
|
816
838
|
}
|
|
817
839
|
|
|
840
|
+
// src/remove-undefined-entries.ts
|
|
841
|
+
function removeUndefinedEntries(record) {
|
|
842
|
+
return Object.fromEntries(
|
|
843
|
+
Object.entries(record).filter(([_key, value]) => value != null)
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
|
|
818
847
|
// src/resolve.ts
|
|
819
848
|
async function resolve(value) {
|
|
820
849
|
if (typeof value === "function") {
|
|
@@ -2350,6 +2379,7 @@ export {
|
|
|
2350
2379
|
loadOptionalSetting,
|
|
2351
2380
|
loadSetting,
|
|
2352
2381
|
mediaTypeToExtension,
|
|
2382
|
+
normalizeHeaders,
|
|
2353
2383
|
parseJSON,
|
|
2354
2384
|
parseJsonEventStream,
|
|
2355
2385
|
parseProviderOptions,
|