@mastra/server 1.84.0-alpha.2 → 1.84.0-alpha.4
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/_types/@mastra_schema-compat@1.4.0/dist/_types/@internal_ai-sdk-v5@0.0.96/dist/index.d.ts +61 -2
- package/dist/_types/@mastra_schema-compat@1.4.0/dist/_types/@internal_ai-v6@0.0.96/dist/index.d.ts +9 -1
- package/dist/{a2a-CY85JalK.js → a2a-By6Kef65.js} +2 -2
- package/dist/{a2a-CY85JalK.js.map → a2a-By6Kef65.js.map} +1 -1
- package/dist/{a2a-Bz7vRGfF.cjs → a2a-CCYYdrZ1.cjs} +2 -2
- package/dist/{a2a-Bz7vRGfF.cjs.map → a2a-CCYYdrZ1.cjs.map} +1 -1
- package/dist/{agent-builder-CMAT5xu8.cjs → agent-builder-2Ogqa9-3.cjs} +3 -3
- package/dist/{agent-builder-CMAT5xu8.cjs.map → agent-builder-2Ogqa9-3.cjs.map} +1 -1
- package/dist/{agent-builder-DYu--54x.js → agent-builder-Dc6cRAxh.js} +3 -3
- package/dist/{agent-builder-DYu--54x.js.map → agent-builder-Dc6cRAxh.js.map} +1 -1
- package/dist/{agents-BgaBbcwb.cjs → agents-2HNpgTlJ.cjs} +7 -2
- package/dist/agents-2HNpgTlJ.cjs.map +1 -0
- package/dist/{agents-BjlUjmb1.js → agents-CEgQ1Sj5.js} +7 -2
- package/dist/agents-CEgQ1Sj5.js.map +1 -0
- package/dist/{api-schema-manifest-DyOyIk-C.cjs → api-schema-manifest-BdpqONHU.cjs} +2 -2
- package/dist/{api-schema-manifest-DyOyIk-C.cjs.map → api-schema-manifest-BdpqONHU.cjs.map} +1 -1
- package/dist/{api-schema-manifest-MtnJy994.js → api-schema-manifest-CAXT81dM.js} +2 -2
- package/dist/{api-schema-manifest-MtnJy994.js.map → api-schema-manifest-CAXT81dM.js.map} +1 -1
- package/dist/{catalogue-oK_QSBRh.cjs → catalogue-Cnb2A1bK.cjs} +8 -8
- package/dist/{catalogue-oK_QSBRh.cjs.map → catalogue-Cnb2A1bK.cjs.map} +1 -1
- package/dist/{catalogue-BdR5h6fv.js → catalogue-CpTFH24l.js} +8 -8
- package/dist/{catalogue-BdR5h6fv.js.map → catalogue-CpTFH24l.js.map} +1 -1
- package/dist/{conversations-DYqwqCWH.js → conversations-C9yLrQnn.js} +2 -2
- package/dist/{conversations-DYqwqCWH.js.map → conversations-C9yLrQnn.js.map} +1 -1
- package/dist/{conversations-Bvk5VVVJ.cjs → conversations-Cqyw1vjS.cjs} +2 -2
- package/dist/{conversations-Bvk5VVVJ.cjs.map → conversations-Cqyw1vjS.cjs.map} +1 -1
- package/dist/{dist-p7VXVmE_.cjs → dist-BgMRdBmR.cjs} +857 -283
- package/dist/dist-BgMRdBmR.cjs.map +1 -0
- package/dist/{dist-4o3EGZcG.js → dist-BoE65ceB.js} +857 -284
- package/dist/dist-BoE65ceB.js.map +1 -0
- package/dist/{dist-DXhZqfZZ.cjs → dist-D4zWd2g_.cjs} +1 -1
- package/dist/dist-DLdEfrDl.js +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-server-mcp.md +2 -2
- package/dist/docs/references/reference-server-builtin-mcp-tools.md +13 -13
- package/dist/{editor-builder-CGM0scw2.js → editor-builder-Dd10fik0.js} +2 -2
- package/dist/{editor-builder-CGM0scw2.js.map → editor-builder-Dd10fik0.js.map} +1 -1
- package/dist/{editor-builder-SP_ledm3.cjs → editor-builder-apReuKyj.cjs} +2 -2
- package/dist/{editor-builder-SP_ledm3.cjs.map → editor-builder-apReuKyj.cjs.map} +1 -1
- package/dist/{memory-0jB2EOKx.js → memory-DS2tEXzG.js} +29 -23
- package/dist/memory-DS2tEXzG.js.map +1 -0
- package/dist/{memory-Dd7TpDfi.cjs → memory-HiP-vUvS.cjs} +28 -22
- package/dist/memory-HiP-vUvS.cjs.map +1 -0
- package/dist/{plans-BemJO4-7.js → plans-ByaTWRem.js} +2 -2
- package/dist/{plans-BemJO4-7.js.map → plans-ByaTWRem.js.map} +1 -1
- package/dist/{plans-CffjV2_6.cjs → plans-CE83TVnK.cjs} +2 -2
- package/dist/{plans-CffjV2_6.cjs.map → plans-CE83TVnK.cjs.map} +1 -1
- package/dist/{probe-image-size-IIGl_zRY.js → probe-image-size-Bu_nsmG7.js} +2 -2
- package/dist/{probe-image-size-IIGl_zRY.js.map → probe-image-size-Bu_nsmG7.js.map} +1 -1
- package/dist/{probe-image-size-DmttstPc.cjs → probe-image-size-CIvA48eX.cjs} +2 -2
- package/dist/{probe-image-size-DmttstPc.cjs.map → probe-image-size-CIvA48eX.cjs.map} +1 -1
- package/dist/{responses-D0mb5ubj.cjs → responses-3F7qAgFF.cjs} +2 -2
- package/dist/{responses-D0mb5ubj.cjs.map → responses-3F7qAgFF.cjs.map} +1 -1
- package/dist/{responses-BofWEQYg.js → responses-kWHiEbrl.js} +2 -2
- package/dist/{responses-BofWEQYg.js.map → responses-kWHiEbrl.js.map} +1 -1
- package/dist/{routes-DAnFdADa.js → routes-8_3X8t-L.js} +14 -14
- package/dist/{routes-DAnFdADa.js.map → routes-8_3X8t-L.js.map} +1 -1
- package/dist/{routes-6lsEmZwB.cjs → routes-C76k7FKk.cjs} +14 -14
- package/dist/{routes-6lsEmZwB.cjs.map → routes-C76k7FKk.cjs.map} +1 -1
- package/dist/{scores-CVssMyoQ.js → scores-B6h7rEBJ.js} +2 -2
- package/dist/{scores-CVssMyoQ.js.map → scores-B6h7rEBJ.js.map} +1 -1
- package/dist/{scores-0MyV08tL.cjs → scores-BuAYv1Gi.cjs} +2 -2
- package/dist/{scores-0MyV08tL.cjs.map → scores-BuAYv1Gi.cjs.map} +1 -1
- package/dist/server/handlers/a2a.cjs +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +1 -1
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/conversations.cjs +1 -1
- package/dist/server/handlers/conversations.js +1 -1
- package/dist/server/handlers/editor-builder.cjs +1 -1
- package/dist/server/handlers/editor-builder.js +1 -1
- package/dist/server/handlers/favorites-enrichment.cjs +1 -1
- package/dist/server/handlers/favorites-enrichment.js +1 -1
- package/dist/server/handlers/gateway-memory-client.cjs +26 -4
- package/dist/server/handlers/gateway-memory-client.cjs.map +1 -1
- package/dist/server/handlers/gateway-memory-client.d.ts +14 -2
- package/dist/server/handlers/gateway-memory-client.d.ts.map +1 -1
- package/dist/server/handlers/gateway-memory-client.js +26 -5
- package/dist/server/handlers/gateway-memory-client.js.map +1 -1
- package/dist/server/handlers/memory.cjs +1 -1
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/plans.cjs +1 -1
- package/dist/server/handlers/plans.js +1 -1
- package/dist/server/handlers/responses.cjs +1 -1
- package/dist/server/handlers/responses.js +1 -1
- package/dist/server/handlers/scores.cjs +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/stored-agent-favorites.cjs +1 -1
- package/dist/server/handlers/stored-agent-favorites.js +1 -1
- package/dist/server/handlers/stored-agents.cjs +1 -1
- package/dist/server/handlers/stored-agents.js +1 -1
- package/dist/server/handlers/stored-skill-favorites.cjs +1 -1
- package/dist/server/handlers/stored-skill-favorites.js +1 -1
- package/dist/server/handlers/stored-skills.cjs +1 -1
- package/dist/server/handlers/stored-skills.js +1 -1
- package/dist/server/handlers/system.cjs +1 -1
- package/dist/server/handlers/system.js +1 -1
- package/dist/server/handlers/tools.cjs +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/voice.cjs +1 -1
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +1 -1
- package/dist/server/handlers/workflows.d.ts +2 -0
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +11 -11
- package/dist/server/handlers.js +11 -11
- package/dist/server/server-adapter/index.cjs +2 -2
- package/dist/server/server-adapter/index.js +2 -2
- package/dist/server/server-adapter/routes/workflows.d.ts +2 -0
- package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -1
- package/dist/{server-adapter-Dgy-iIqA.js → server-adapter-BCeL96pF.js} +2 -2
- package/dist/{server-adapter-Dgy-iIqA.js.map → server-adapter-BCeL96pF.js.map} +1 -1
- package/dist/{server-adapter-CbxRgDBh.cjs → server-adapter-BhDR1wnp.cjs} +2 -2
- package/dist/{server-adapter-CbxRgDBh.cjs.map → server-adapter-BhDR1wnp.cjs.map} +1 -1
- package/dist/{tools-oHRh4msa.js → tools-BuFpB7Lk.js} +2 -2
- package/dist/{tools-oHRh4msa.js.map → tools-BuFpB7Lk.js.map} +1 -1
- package/dist/{tools-CawMeeZg.cjs → tools-C_6yXAww.cjs} +2 -2
- package/dist/{tools-CawMeeZg.cjs.map → tools-C_6yXAww.cjs.map} +1 -1
- package/dist/{voice-Dk0O5mVD.cjs → voice-ByiFiTmK.cjs} +2 -2
- package/dist/{voice-Dk0O5mVD.cjs.map → voice-ByiFiTmK.cjs.map} +1 -1
- package/dist/{voice-C6bAqs79.js → voice-DOV0tU_V.js} +2 -2
- package/dist/{voice-C6bAqs79.js.map → voice-DOV0tU_V.js.map} +1 -1
- package/dist/{workflows-B-QJ0Tnv.js → workflows-9Q28sHTz.js} +5 -3
- package/dist/{workflows-B-QJ0Tnv.js.map → workflows-9Q28sHTz.js.map} +1 -1
- package/dist/{workflows-CwkEHIKW.cjs → workflows-DhmriYvN.cjs} +5 -3
- package/dist/{workflows-CwkEHIKW.cjs.map → workflows-DhmriYvN.cjs.map} +1 -1
- package/package.json +5 -5
- package/dist/agents-BgaBbcwb.cjs.map +0 -1
- package/dist/agents-BjlUjmb1.js.map +0 -1
- package/dist/dist-4o3EGZcG.js.map +0 -1
- package/dist/dist-CecsVJCw.js +0 -1
- package/dist/dist-p7VXVmE_.cjs.map +0 -1
- package/dist/memory-0jB2EOKx.js.map +0 -1
- package/dist/memory-Dd7TpDfi.cjs.map +0 -1
|
@@ -27,6 +27,8 @@ let path = require("path");
|
|
|
27
27
|
let crypto$1 = require("crypto");
|
|
28
28
|
let module$1 = require("module");
|
|
29
29
|
let zod_v4_core = require("zod/v4/core");
|
|
30
|
+
let zod_v4_locales_en_js = require("zod/v4/locales/en.js");
|
|
31
|
+
zod_v4_locales_en_js = require_rolldown_runtime.__toESM(zod_v4_locales_en_js, 1);
|
|
30
32
|
let diagnostics_channel = require("diagnostics_channel");
|
|
31
33
|
let async_hooks = require("async_hooks");
|
|
32
34
|
let child_process = require("child_process");
|
|
@@ -8654,7 +8656,7 @@ function splitLines(text) {
|
|
|
8654
8656
|
else result.push(result.pop().slice(0, -1));
|
|
8655
8657
|
return result;
|
|
8656
8658
|
}
|
|
8657
|
-
// ../memory/dist/src-
|
|
8659
|
+
// ../memory/dist/src-BkElV36S.js
|
|
8658
8660
|
var __defProp$3 = Object.defineProperty;
|
|
8659
8661
|
var __exportAll = (all, no_symbols) => {
|
|
8660
8662
|
let target = {};
|
|
@@ -11407,8 +11409,8 @@ var UnsupportedModelVersionError$3 = class extends AISDKError$3 {
|
|
|
11407
11409
|
}
|
|
11408
11410
|
};
|
|
11409
11411
|
var name$21 = "AI_InvalidArgumentError";
|
|
11410
|
-
var marker$
|
|
11411
|
-
var symbol$
|
|
11412
|
+
var marker$20 = `vercel.ai.error.${name$21}`;
|
|
11413
|
+
var symbol$24 = Symbol.for(marker$20);
|
|
11412
11414
|
var _a$6;
|
|
11413
11415
|
var InvalidArgumentError$6 = class extends AISDKError$3 {
|
|
11414
11416
|
constructor({ parameter, value, message }) {
|
|
@@ -11421,10 +11423,10 @@ var InvalidArgumentError$6 = class extends AISDKError$3 {
|
|
|
11421
11423
|
this.value = value;
|
|
11422
11424
|
}
|
|
11423
11425
|
static isInstance(error) {
|
|
11424
|
-
return AISDKError$3.hasMarker(error, marker$
|
|
11426
|
+
return AISDKError$3.hasMarker(error, marker$20);
|
|
11425
11427
|
}
|
|
11426
11428
|
};
|
|
11427
|
-
_a$6 = symbol$
|
|
11429
|
+
_a$6 = symbol$24;
|
|
11428
11430
|
var name2$6 = "AI_RetryError";
|
|
11429
11431
|
var marker2$6 = `vercel.ai.error.${name2$6}`;
|
|
11430
11432
|
var symbol2$6 = Symbol.for(marker2$6);
|
|
@@ -12314,11 +12316,11 @@ function trimStartOfStream() {
|
|
|
12314
12316
|
return text2;
|
|
12315
12317
|
};
|
|
12316
12318
|
}
|
|
12317
|
-
var marker$1$
|
|
12318
|
-
var symbol$1$
|
|
12319
|
+
var marker$1$11 = "vercel.ai.error";
|
|
12320
|
+
var symbol$1$21 = Symbol.for(marker$1$11);
|
|
12319
12321
|
var _a$1$2;
|
|
12320
12322
|
var _b$1$4;
|
|
12321
|
-
var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
|
|
12323
|
+
var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$21, _b$1$4) {
|
|
12322
12324
|
/**
|
|
12323
12325
|
* Creates an AI SDK Error.
|
|
12324
12326
|
*
|
|
@@ -12339,22 +12341,22 @@ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
|
|
|
12339
12341
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
12340
12342
|
*/
|
|
12341
12343
|
static isInstance(error) {
|
|
12342
|
-
return _AISDKError.hasMarker(error, marker$1$
|
|
12344
|
+
return _AISDKError.hasMarker(error, marker$1$11);
|
|
12343
12345
|
}
|
|
12344
12346
|
static hasMarker(error, marker15) {
|
|
12345
12347
|
const markerSymbol = Symbol.for(marker15);
|
|
12346
12348
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
12347
12349
|
}
|
|
12348
12350
|
};
|
|
12349
|
-
var name$1$
|
|
12350
|
-
var marker2$5 = `vercel.ai.error.${name$1$
|
|
12351
|
+
var name$1$19 = "AI_APICallError";
|
|
12352
|
+
var marker2$5 = `vercel.ai.error.${name$1$19}`;
|
|
12351
12353
|
var symbol2$5 = Symbol.for(marker2$5);
|
|
12352
12354
|
var _a2$5;
|
|
12353
12355
|
var _b2$3;
|
|
12354
12356
|
var APICallError$2 = class extends (_b2$3 = AISDKError$2, _a2$5 = symbol2$5, _b2$3) {
|
|
12355
12357
|
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
|
|
12356
12358
|
super({
|
|
12357
|
-
name: name$1$
|
|
12359
|
+
name: name$1$19,
|
|
12358
12360
|
message,
|
|
12359
12361
|
cause
|
|
12360
12362
|
});
|
|
@@ -12693,15 +12695,15 @@ function createAbortError$2() {
|
|
|
12693
12695
|
function extractResponseHeaders$2(response) {
|
|
12694
12696
|
return Object.fromEntries([...response.headers]);
|
|
12695
12697
|
}
|
|
12696
|
-
var name$
|
|
12697
|
-
var marker$
|
|
12698
|
-
var symbol$
|
|
12698
|
+
var name$20 = "AI_DownloadError";
|
|
12699
|
+
var marker$17 = `vercel.ai.error.${name$20}`;
|
|
12700
|
+
var symbol$22 = Symbol.for(marker$17);
|
|
12699
12701
|
var _a$5;
|
|
12700
12702
|
var _b$5;
|
|
12701
|
-
var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$
|
|
12703
|
+
var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$22, _b$5) {
|
|
12702
12704
|
constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
|
|
12703
12705
|
super({
|
|
12704
|
-
name: name$
|
|
12706
|
+
name: name$20,
|
|
12705
12707
|
message,
|
|
12706
12708
|
cause
|
|
12707
12709
|
});
|
|
@@ -12711,7 +12713,7 @@ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5
|
|
|
12711
12713
|
this.statusText = statusText;
|
|
12712
12714
|
}
|
|
12713
12715
|
static isInstance(error) {
|
|
12714
|
-
return AISDKError$2.hasMarker(error, marker$
|
|
12716
|
+
return AISDKError$2.hasMarker(error, marker$17);
|
|
12715
12717
|
}
|
|
12716
12718
|
};
|
|
12717
12719
|
var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL$2 = /* @__PURE__ */ Symbol.for("vercel.ai.embeddingModel.maxInputBytesPerCall");
|
|
@@ -12721,6 +12723,247 @@ async function cancelResponseBody$2(response) {
|
|
|
12721
12723
|
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
12722
12724
|
} catch (e) {}
|
|
12723
12725
|
}
|
|
12726
|
+
function isBrowserRuntime$2(globalThisAny = globalThis) {
|
|
12727
|
+
return globalThisAny.window != null;
|
|
12728
|
+
}
|
|
12729
|
+
function isSameOrigin$2(url, baseUrl) {
|
|
12730
|
+
try {
|
|
12731
|
+
return new URL(url).origin === new URL(baseUrl).origin;
|
|
12732
|
+
} catch (e) {
|
|
12733
|
+
return false;
|
|
12734
|
+
}
|
|
12735
|
+
}
|
|
12736
|
+
function validateDownloadUrl$2(url) {
|
|
12737
|
+
let parsed;
|
|
12738
|
+
try {
|
|
12739
|
+
parsed = new URL(url);
|
|
12740
|
+
} catch (e) {
|
|
12741
|
+
throw new DownloadError$2({
|
|
12742
|
+
url,
|
|
12743
|
+
message: `Invalid URL: ${url}`
|
|
12744
|
+
});
|
|
12745
|
+
}
|
|
12746
|
+
if (parsed.protocol === "data:") return;
|
|
12747
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new DownloadError$2({
|
|
12748
|
+
url,
|
|
12749
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
12750
|
+
});
|
|
12751
|
+
const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
|
|
12752
|
+
if (!hostname) throw new DownloadError$2({
|
|
12753
|
+
url,
|
|
12754
|
+
message: `URL must have a hostname`
|
|
12755
|
+
});
|
|
12756
|
+
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost") || hostname.endsWith(".internal")) throw new DownloadError$2({
|
|
12757
|
+
url,
|
|
12758
|
+
message: `URL with hostname ${hostname} is not allowed`
|
|
12759
|
+
});
|
|
12760
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
12761
|
+
if (isPrivateIPv6$2(hostname.slice(1, -1))) throw new DownloadError$2({
|
|
12762
|
+
url,
|
|
12763
|
+
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
12764
|
+
});
|
|
12765
|
+
return;
|
|
12766
|
+
}
|
|
12767
|
+
if (isIPv4$2(hostname)) {
|
|
12768
|
+
if (isPrivateIPv4$2(hostname)) throw new DownloadError$2({
|
|
12769
|
+
url,
|
|
12770
|
+
message: `URL with IP address ${hostname} is not allowed`
|
|
12771
|
+
});
|
|
12772
|
+
}
|
|
12773
|
+
}
|
|
12774
|
+
function validateDownloadAddress$1({ address, family, hostname }) {
|
|
12775
|
+
if (family === 4 ? !isIPv4$2(address) || isPrivateIPv4$2(address) : family === 6 ? isPrivateIPv6$2(address) : true) throw new DownloadError$2({
|
|
12776
|
+
url: hostname,
|
|
12777
|
+
message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
|
|
12778
|
+
});
|
|
12779
|
+
}
|
|
12780
|
+
function isIPv4$2(hostname) {
|
|
12781
|
+
const parts = hostname.split(".");
|
|
12782
|
+
if (parts.length !== 4) return false;
|
|
12783
|
+
return parts.every((part) => {
|
|
12784
|
+
const num = Number(part);
|
|
12785
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
12786
|
+
});
|
|
12787
|
+
}
|
|
12788
|
+
function isPrivateIPv4$2(ip) {
|
|
12789
|
+
const [a, b, c] = ip.split(".").map(Number);
|
|
12790
|
+
if (a === 0) return true;
|
|
12791
|
+
if (a === 10) return true;
|
|
12792
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
12793
|
+
if (a === 127) return true;
|
|
12794
|
+
if (a === 169 && b === 254) return true;
|
|
12795
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
12796
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
12797
|
+
if (a === 192 && b === 168) return true;
|
|
12798
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
12799
|
+
if (a >= 240) return true;
|
|
12800
|
+
return false;
|
|
12801
|
+
}
|
|
12802
|
+
function parseIPv6$2(ip) {
|
|
12803
|
+
let address = ip.toLowerCase();
|
|
12804
|
+
const zoneIndex = address.indexOf("%");
|
|
12805
|
+
if (zoneIndex !== -1) address = address.slice(0, zoneIndex);
|
|
12806
|
+
const halves = address.split("::");
|
|
12807
|
+
if (halves.length > 2) return null;
|
|
12808
|
+
const toGroups = (segment) => {
|
|
12809
|
+
if (segment === "") return [];
|
|
12810
|
+
const groups = [];
|
|
12811
|
+
const parts = segment.split(":");
|
|
12812
|
+
for (let i = 0; i < parts.length; i++) {
|
|
12813
|
+
const part = parts[i];
|
|
12814
|
+
if (part.includes(".")) {
|
|
12815
|
+
if (i !== parts.length - 1 || !isIPv4$2(part)) return null;
|
|
12816
|
+
const [a, b, c, d] = part.split(".").map(Number);
|
|
12817
|
+
groups.push(a << 8 | b, c << 8 | d);
|
|
12818
|
+
continue;
|
|
12819
|
+
}
|
|
12820
|
+
if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
|
|
12821
|
+
groups.push(parseInt(part, 16));
|
|
12822
|
+
}
|
|
12823
|
+
return groups;
|
|
12824
|
+
};
|
|
12825
|
+
const head = toGroups(halves[0]);
|
|
12826
|
+
if (head === null) return null;
|
|
12827
|
+
if (halves.length === 2) {
|
|
12828
|
+
const tail = toGroups(halves[1]);
|
|
12829
|
+
if (tail === null) return null;
|
|
12830
|
+
const fill = 8 - head.length - tail.length;
|
|
12831
|
+
if (fill < 0) return null;
|
|
12832
|
+
return [
|
|
12833
|
+
...head,
|
|
12834
|
+
...new Array(fill).fill(0),
|
|
12835
|
+
...tail
|
|
12836
|
+
];
|
|
12837
|
+
}
|
|
12838
|
+
return head.length === 8 ? head : null;
|
|
12839
|
+
}
|
|
12840
|
+
function isPrivateIPv6$2(ip) {
|
|
12841
|
+
const groups = parseIPv6$2(ip);
|
|
12842
|
+
if (groups === null) return true;
|
|
12843
|
+
const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
12844
|
+
if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
|
|
12845
|
+
if ((groups[0] & 65024) === 64512) return true;
|
|
12846
|
+
if ((groups[0] & 65472) === 65152) return true;
|
|
12847
|
+
if ((groups[0] & 65472) === 65216) return true;
|
|
12848
|
+
if ((groups[0] & 65280) === 65280) return true;
|
|
12849
|
+
if (topZero(6) || topZero(5) && groups[5] === 65535 || topZero(4) && groups[4] === 65535 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return isPrivateIPv4$2(`${groups[6] >> 8 & 255}.${groups[6] & 255}.${groups[7] >> 8 & 255}.${groups[7] & 255}`);
|
|
12850
|
+
return false;
|
|
12851
|
+
}
|
|
12852
|
+
function createSafeLookup$1(lookup) {
|
|
12853
|
+
return ((hostname, options, callback) => {
|
|
12854
|
+
lookup(hostname, {
|
|
12855
|
+
...options,
|
|
12856
|
+
all: true
|
|
12857
|
+
}, (error, addresses) => {
|
|
12858
|
+
if (error) {
|
|
12859
|
+
callback(error);
|
|
12860
|
+
return;
|
|
12861
|
+
}
|
|
12862
|
+
try {
|
|
12863
|
+
const [firstAddress] = addresses;
|
|
12864
|
+
if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
|
|
12865
|
+
for (const { address, family } of addresses) validateDownloadAddress$1({
|
|
12866
|
+
address,
|
|
12867
|
+
family,
|
|
12868
|
+
hostname
|
|
12869
|
+
});
|
|
12870
|
+
if (options.all === true) callback(null, addresses);
|
|
12871
|
+
else callback(null, firstAddress.address, firstAddress.family);
|
|
12872
|
+
} catch (error2) {
|
|
12873
|
+
callback(error2 instanceof Error ? error2 : new Error(String(error2)));
|
|
12874
|
+
}
|
|
12875
|
+
});
|
|
12876
|
+
});
|
|
12877
|
+
}
|
|
12878
|
+
var safeNodeFetchPromise$1;
|
|
12879
|
+
function isNodeRuntime$2() {
|
|
12880
|
+
var _a2, _b2, _c;
|
|
12881
|
+
const runtimeProcess = globalThis.process;
|
|
12882
|
+
return ((_a2 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a2.name) === "node" && ((_b2 = runtimeProcess.versions) == null ? void 0 : _b2.bun) == null && ((_c = runtimeProcess.versions) == null ? void 0 : _c.deno) == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
|
|
12883
|
+
}
|
|
12884
|
+
async function getDefaultDownloadFetch$1() {
|
|
12885
|
+
if (!isNodeRuntime$2()) return globalThis.fetch;
|
|
12886
|
+
return safeNodeFetchPromise$1 != null ? safeNodeFetchPromise$1 : safeNodeFetchPromise$1 = createSafeNodeFetch$1();
|
|
12887
|
+
}
|
|
12888
|
+
async function createSafeNodeFetch$1() {
|
|
12889
|
+
const [module, { lookup }] = await Promise.all([loadNodeModule$1("node:module"), loadNodeModule$1("node:dns")]);
|
|
12890
|
+
const { Agent, fetch } = module.createRequire(getCurrentModulePath$1())("undici");
|
|
12891
|
+
const dispatcher = new Agent({ connect: { lookup: createSafeLookup$1(lookup) } });
|
|
12892
|
+
return ((input, init) => fetch(input, {
|
|
12893
|
+
...init,
|
|
12894
|
+
dispatcher
|
|
12895
|
+
}));
|
|
12896
|
+
}
|
|
12897
|
+
async function loadNodeModule$1(id) {
|
|
12898
|
+
var _a2;
|
|
12899
|
+
const processWithBuiltins = globalThis.process;
|
|
12900
|
+
const builtinModule = (_a2 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a2.call(processWithBuiltins, id);
|
|
12901
|
+
return builtinModule == null ? await importNodeModule(id) : builtinModule;
|
|
12902
|
+
}
|
|
12903
|
+
function importNodeModule(id) {
|
|
12904
|
+
return import(id);
|
|
12905
|
+
}
|
|
12906
|
+
function getCurrentModulePath$1() {
|
|
12907
|
+
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
12908
|
+
try {
|
|
12909
|
+
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
12910
|
+
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
12911
|
+
Error.captureStackTrace(error, getCurrentModulePath$1);
|
|
12912
|
+
const [caller] = error.stack;
|
|
12913
|
+
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
12914
|
+
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
12915
|
+
return fileName;
|
|
12916
|
+
} finally {
|
|
12917
|
+
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
12918
|
+
}
|
|
12919
|
+
}
|
|
12920
|
+
var MAX_DOWNLOAD_REDIRECTS$2 = 10;
|
|
12921
|
+
async function getValidatedFetch$1(customFetch) {
|
|
12922
|
+
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch$1() : customFetch;
|
|
12923
|
+
}
|
|
12924
|
+
async function fetchWithValidatedRedirects$2({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$2, fetch: customFetch, trustedOrigin }) {
|
|
12925
|
+
var _a2;
|
|
12926
|
+
let currentHeaders = headers === void 0 ? void 0 : new Headers(headers);
|
|
12927
|
+
const perHopInit = (redirect) => ({
|
|
12928
|
+
signal: abortSignal,
|
|
12929
|
+
redirect,
|
|
12930
|
+
...currentHeaders === void 0 ? {} : { headers: new Headers(currentHeaders) }
|
|
12931
|
+
});
|
|
12932
|
+
let currentUrl = url;
|
|
12933
|
+
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
12934
|
+
const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$2(currentUrl, trustedOrigin);
|
|
12935
|
+
if (!isTrustedHop) validateDownloadUrl$2(currentUrl);
|
|
12936
|
+
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch$1(customFetch);
|
|
12937
|
+
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
12938
|
+
if (response.type === "opaqueredirect") {
|
|
12939
|
+
if (!isBrowserRuntime$2()) throw new DownloadError$2({
|
|
12940
|
+
url,
|
|
12941
|
+
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
12942
|
+
});
|
|
12943
|
+
return await fetch(currentUrl, perHopInit("follow"));
|
|
12944
|
+
}
|
|
12945
|
+
const location = (_a2 = response.headers) == null ? void 0 : _a2.get("location");
|
|
12946
|
+
if (response.status >= 300 && response.status < 400 && location) {
|
|
12947
|
+
cancelResponseBody$2(response);
|
|
12948
|
+
const nextUrl = new URL(location, currentUrl).toString();
|
|
12949
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$2({
|
|
12950
|
+
url,
|
|
12951
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
12952
|
+
});
|
|
12953
|
+
if (currentHeaders !== void 0 && !isSameOrigin$2(nextUrl, currentUrl)) {
|
|
12954
|
+
const userAgent = currentHeaders.get("user-agent");
|
|
12955
|
+
currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
|
|
12956
|
+
}
|
|
12957
|
+
currentUrl = nextUrl;
|
|
12958
|
+
continue;
|
|
12959
|
+
}
|
|
12960
|
+
return response;
|
|
12961
|
+
}
|
|
12962
|
+
throw new DownloadError$2({
|
|
12963
|
+
url,
|
|
12964
|
+
message: `Too many redirects (max ${maxRedirects})`
|
|
12965
|
+
});
|
|
12966
|
+
}
|
|
12724
12967
|
var DEFAULT_MAX_DOWNLOAD_SIZE$2 = 2147483648;
|
|
12725
12968
|
async function readResponseWithSizeLimit$2({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE$2 }) {
|
|
12726
12969
|
const contentLength = response.headers.get("content-length");
|
|
@@ -12874,13 +13117,21 @@ function withUserAgentSuffix$2(headers, ...userAgentSuffixParts) {
|
|
|
12874
13117
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
12875
13118
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
12876
13119
|
}
|
|
12877
|
-
var VERSION$8 = "3.0.
|
|
13120
|
+
var VERSION$8 = "3.0.46";
|
|
12878
13121
|
var getOriginalFetch$3 = () => globalThis.fetch;
|
|
12879
|
-
var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch
|
|
13122
|
+
var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
|
|
12880
13123
|
try {
|
|
12881
|
-
const
|
|
13124
|
+
const requestFetch = fetch != null ? fetch : getOriginalFetch$3();
|
|
13125
|
+
const requestHeaders = withUserAgentSuffix$2(credentialedOrigin !== void 0 && !isSameOrigin$2(url, credentialedOrigin) ? {} : headers, `ai-sdk/provider-utils/${VERSION$8}`, getRuntimeEnvironmentUserAgent$2());
|
|
13126
|
+
const response = validateUrl ? await fetchWithValidatedRedirects$2({
|
|
13127
|
+
url,
|
|
13128
|
+
headers: requestHeaders,
|
|
13129
|
+
abortSignal,
|
|
13130
|
+
fetch,
|
|
13131
|
+
trustedOrigin
|
|
13132
|
+
}) : await requestFetch(url, {
|
|
12882
13133
|
method: "GET",
|
|
12883
|
-
headers:
|
|
13134
|
+
headers: requestHeaders,
|
|
12884
13135
|
signal: abortSignal
|
|
12885
13136
|
});
|
|
12886
13137
|
const responseHeaders = extractResponseHeaders$2(response);
|
|
@@ -14322,10 +14573,10 @@ async function getVercelOidcToken$2() {
|
|
|
14322
14573
|
if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
|
|
14323
14574
|
throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
|
|
14324
14575
|
}
|
|
14325
|
-
var symbol$
|
|
14576
|
+
var symbol$21 = Symbol.for("vercel.ai.gateway.error");
|
|
14326
14577
|
var _a$4;
|
|
14327
14578
|
var _b$3;
|
|
14328
|
-
var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$
|
|
14579
|
+
var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$21, _b$3) {
|
|
14329
14580
|
constructor({ message, statusCode = 500, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
|
|
14330
14581
|
super(message);
|
|
14331
14582
|
this[_a$4] = true;
|
|
@@ -14342,11 +14593,11 @@ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15
|
|
|
14342
14593
|
return _GatewayError.hasMarker(error);
|
|
14343
14594
|
}
|
|
14344
14595
|
static hasMarker(error) {
|
|
14345
|
-
return typeof error === "object" && error !== null && symbol$
|
|
14596
|
+
return typeof error === "object" && error !== null && symbol$21 in error && error[symbol$21] === true;
|
|
14346
14597
|
}
|
|
14347
14598
|
};
|
|
14348
|
-
var name$
|
|
14349
|
-
var marker2$4 = `vercel.ai.gateway.error.${name$
|
|
14599
|
+
var name$19 = "GatewayAuthenticationError";
|
|
14600
|
+
var marker2$4 = `vercel.ai.gateway.error.${name$19}`;
|
|
14350
14601
|
var symbol2$4 = Symbol.for(marker2$4);
|
|
14351
14602
|
var _a2$4;
|
|
14352
14603
|
var _b2$2;
|
|
@@ -14358,7 +14609,7 @@ var GatewayAuthenticationError$2 = class _GatewayAuthenticationError extends (_b
|
|
|
14358
14609
|
cause
|
|
14359
14610
|
});
|
|
14360
14611
|
this[_a2$4] = true;
|
|
14361
|
-
this.name = name$
|
|
14612
|
+
this.name = name$19;
|
|
14362
14613
|
this.type = "authentication_error";
|
|
14363
14614
|
}
|
|
14364
14615
|
static isInstance(error) {
|
|
@@ -17234,11 +17485,11 @@ var object$2 = ({ schema: inputSchema }) => {
|
|
|
17234
17485
|
}
|
|
17235
17486
|
};
|
|
17236
17487
|
};
|
|
17237
|
-
var marker$1$
|
|
17238
|
-
var symbol$1$
|
|
17488
|
+
var marker$1$10 = "vercel.ai.error";
|
|
17489
|
+
var symbol$1$13 = Symbol.for(marker$1$10);
|
|
17239
17490
|
var _a$1$1;
|
|
17240
17491
|
var _b$1$1;
|
|
17241
|
-
var AISDKError$1 = class _AISDKError extends (_b$1$1 = Error, _a$1$1 = symbol$1$
|
|
17492
|
+
var AISDKError$1 = class _AISDKError extends (_b$1$1 = Error, _a$1$1 = symbol$1$13, _b$1$1) {
|
|
17242
17493
|
/**
|
|
17243
17494
|
* Creates an AI SDK Error.
|
|
17244
17495
|
*
|
|
@@ -17259,22 +17510,22 @@ var AISDKError$1 = class _AISDKError extends (_b$1$1 = Error, _a$1$1 = symbol$1$
|
|
|
17259
17510
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
17260
17511
|
*/
|
|
17261
17512
|
static isInstance(error) {
|
|
17262
|
-
return _AISDKError.hasMarker(error, marker$1$
|
|
17513
|
+
return _AISDKError.hasMarker(error, marker$1$10);
|
|
17263
17514
|
}
|
|
17264
17515
|
static hasMarker(error, marker15) {
|
|
17265
17516
|
const markerSymbol = Symbol.for(marker15);
|
|
17266
17517
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
17267
17518
|
}
|
|
17268
17519
|
};
|
|
17269
|
-
var name$1$
|
|
17270
|
-
var marker2$2 = `vercel.ai.error.${name$1$
|
|
17520
|
+
var name$1$10 = "AI_APICallError";
|
|
17521
|
+
var marker2$2 = `vercel.ai.error.${name$1$10}`;
|
|
17271
17522
|
var symbol2$2 = Symbol.for(marker2$2);
|
|
17272
17523
|
var _a2$2;
|
|
17273
17524
|
var _b2$1;
|
|
17274
17525
|
var APICallError$1 = class extends (_b2$1 = AISDKError$1, _a2$2 = symbol2$2, _b2$1) {
|
|
17275
17526
|
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
|
|
17276
17527
|
super({
|
|
17277
|
-
name: name$1$
|
|
17528
|
+
name: name$1$10,
|
|
17278
17529
|
message,
|
|
17279
17530
|
cause
|
|
17280
17531
|
});
|
|
@@ -17657,15 +17908,15 @@ async function cancelResponseBody$1(response) {
|
|
|
17657
17908
|
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
17658
17909
|
} catch (e) {}
|
|
17659
17910
|
}
|
|
17660
|
-
var name$
|
|
17661
|
-
var marker$
|
|
17662
|
-
var symbol$
|
|
17911
|
+
var name$14 = "AI_DownloadError";
|
|
17912
|
+
var marker$13 = `vercel.ai.error.${name$14}`;
|
|
17913
|
+
var symbol$17 = Symbol.for(marker$13);
|
|
17663
17914
|
var _a$2;
|
|
17664
17915
|
var _b$2;
|
|
17665
|
-
var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$
|
|
17916
|
+
var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$17, _b$2) {
|
|
17666
17917
|
constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
|
|
17667
17918
|
super({
|
|
17668
|
-
name: name$
|
|
17919
|
+
name: name$14,
|
|
17669
17920
|
message,
|
|
17670
17921
|
cause
|
|
17671
17922
|
});
|
|
@@ -17675,7 +17926,7 @@ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2
|
|
|
17675
17926
|
this.statusText = statusText;
|
|
17676
17927
|
}
|
|
17677
17928
|
static isInstance(error) {
|
|
17678
|
-
return AISDKError$1.hasMarker(error, marker$
|
|
17929
|
+
return AISDKError$1.hasMarker(error, marker$13);
|
|
17679
17930
|
}
|
|
17680
17931
|
};
|
|
17681
17932
|
function isBrowserRuntime$1(globalThisAny = globalThis) {
|
|
@@ -17726,7 +17977,7 @@ function validateDownloadUrl$1(url) {
|
|
|
17726
17977
|
});
|
|
17727
17978
|
}
|
|
17728
17979
|
}
|
|
17729
|
-
function validateDownloadAddress
|
|
17980
|
+
function validateDownloadAddress({ address, family, hostname }) {
|
|
17730
17981
|
if (family === 4 ? !isIPv4$1(address) || isPrivateIPv4$1(address) : family === 6 ? isPrivateIPv6$1(address) : true) throw new DownloadError$1({
|
|
17731
17982
|
url: hostname,
|
|
17732
17983
|
message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
|
|
@@ -17804,7 +18055,7 @@ function isPrivateIPv6$1(ip) {
|
|
|
17804
18055
|
if (topZero(6) || topZero(5) && groups[5] === 65535 || topZero(4) && groups[4] === 65535 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return isPrivateIPv4$1(`${groups[6] >> 8 & 255}.${groups[6] & 255}.${groups[7] >> 8 & 255}.${groups[7] & 255}`);
|
|
17805
18056
|
return false;
|
|
17806
18057
|
}
|
|
17807
|
-
function createSafeLookup
|
|
18058
|
+
function createSafeLookup(lookup) {
|
|
17808
18059
|
return ((hostname, options, callback) => {
|
|
17809
18060
|
lookup(hostname, {
|
|
17810
18061
|
...options,
|
|
@@ -17817,7 +18068,7 @@ function createSafeLookup$1(lookup) {
|
|
|
17817
18068
|
try {
|
|
17818
18069
|
const [firstAddress] = addresses;
|
|
17819
18070
|
if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
|
|
17820
|
-
for (const { address, family } of addresses) validateDownloadAddress
|
|
18071
|
+
for (const { address, family } of addresses) validateDownloadAddress({
|
|
17821
18072
|
address,
|
|
17822
18073
|
family,
|
|
17823
18074
|
hostname
|
|
@@ -17830,20 +18081,20 @@ function createSafeLookup$1(lookup) {
|
|
|
17830
18081
|
});
|
|
17831
18082
|
});
|
|
17832
18083
|
}
|
|
17833
|
-
var safeNodeFetchPromise
|
|
17834
|
-
function isNodeRuntime$
|
|
18084
|
+
var safeNodeFetchPromise;
|
|
18085
|
+
function isNodeRuntime$1() {
|
|
17835
18086
|
var _a2, _b2, _c;
|
|
17836
18087
|
const runtimeProcess = globalThis.process;
|
|
17837
18088
|
return ((_a2 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a2.name) === "node" && ((_b2 = runtimeProcess.versions) == null ? void 0 : _b2.bun) == null && ((_c = runtimeProcess.versions) == null ? void 0 : _c.deno) == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
|
|
17838
18089
|
}
|
|
17839
|
-
async function getDefaultDownloadFetch
|
|
17840
|
-
if (!isNodeRuntime$
|
|
17841
|
-
return safeNodeFetchPromise
|
|
18090
|
+
async function getDefaultDownloadFetch() {
|
|
18091
|
+
if (!isNodeRuntime$1()) return globalThis.fetch;
|
|
18092
|
+
return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = createSafeNodeFetch();
|
|
17842
18093
|
}
|
|
17843
|
-
async function createSafeNodeFetch
|
|
18094
|
+
async function createSafeNodeFetch() {
|
|
17844
18095
|
const [module, { lookup }] = await Promise.all([loadNodeModule("node:module"), loadNodeModule("node:dns")]);
|
|
17845
|
-
const { Agent, fetch } = module.createRequire(getCurrentModulePath
|
|
17846
|
-
const dispatcher = new Agent({ connect: { lookup: createSafeLookup
|
|
18096
|
+
const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
|
|
18097
|
+
const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
|
|
17847
18098
|
return ((input, init) => fetch(input, {
|
|
17848
18099
|
...init,
|
|
17849
18100
|
dispatcher
|
|
@@ -17856,12 +18107,12 @@ async function loadNodeModule(id) {
|
|
|
17856
18107
|
if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
|
|
17857
18108
|
return builtinModule;
|
|
17858
18109
|
}
|
|
17859
|
-
function getCurrentModulePath
|
|
18110
|
+
function getCurrentModulePath() {
|
|
17860
18111
|
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
17861
18112
|
try {
|
|
17862
18113
|
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
17863
18114
|
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
17864
|
-
Error.captureStackTrace(error, getCurrentModulePath
|
|
18115
|
+
Error.captureStackTrace(error, getCurrentModulePath);
|
|
17865
18116
|
const [caller] = error.stack;
|
|
17866
18117
|
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
17867
18118
|
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
@@ -17905,8 +18156,8 @@ var REDIRECT_STATUS_CODES$1 = /* @__PURE__ */ new Set([
|
|
|
17905
18156
|
307,
|
|
17906
18157
|
308
|
|
17907
18158
|
]);
|
|
17908
|
-
async function getValidatedFetch
|
|
17909
|
-
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch
|
|
18159
|
+
async function getValidatedFetch(customFetch) {
|
|
18160
|
+
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
|
|
17910
18161
|
}
|
|
17911
18162
|
async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$1, fetch: customFetch, trustedOrigin }) {
|
|
17912
18163
|
var _a2;
|
|
@@ -17923,7 +18174,7 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
|
|
|
17923
18174
|
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
17924
18175
|
const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$1(currentUrl, trustedOrigin);
|
|
17925
18176
|
if (!isTrustedHop) validateDownloadUrl$1(currentUrl);
|
|
17926
|
-
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch
|
|
18177
|
+
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
|
|
17927
18178
|
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
17928
18179
|
if (response.type === "opaqueredirect") {
|
|
17929
18180
|
if (!isBrowserRuntime$1()) throw new DownloadError$1({
|
|
@@ -17936,6 +18187,10 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
|
|
|
17936
18187
|
if (REDIRECT_STATUS_CODES$1.has(response.status) && location) {
|
|
17937
18188
|
cancelResponseBody$1(response);
|
|
17938
18189
|
const nextUrl = new URL(location, currentUrl).toString();
|
|
18190
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$1({
|
|
18191
|
+
url,
|
|
18192
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
18193
|
+
});
|
|
17939
18194
|
if (currentHeaders !== void 0 && !isSameOrigin$1(nextUrl, currentUrl)) {
|
|
17940
18195
|
const userAgent = currentHeaders.get("user-agent");
|
|
17941
18196
|
currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
|
|
@@ -18105,7 +18360,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
|
|
|
18105
18360
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
18106
18361
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
18107
18362
|
}
|
|
18108
|
-
var VERSION$5 = "4.0.
|
|
18363
|
+
var VERSION$5 = "4.0.66";
|
|
18109
18364
|
var getOriginalFetch$1 = () => globalThis.fetch;
|
|
18110
18365
|
var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
|
|
18111
18366
|
try {
|
|
@@ -19588,10 +19843,10 @@ async function getVercelOidcToken$1() {
|
|
|
19588
19843
|
if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
|
|
19589
19844
|
throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
|
|
19590
19845
|
}
|
|
19591
|
-
var symbol$
|
|
19846
|
+
var symbol$14 = Symbol.for("vercel.ai.gateway.error");
|
|
19592
19847
|
var _a$1$3;
|
|
19593
19848
|
var _b;
|
|
19594
|
-
var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1$3 = symbol$
|
|
19849
|
+
var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1$3 = symbol$14, _b) {
|
|
19595
19850
|
constructor({ message, statusCode = 500, cause, generationId, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
|
|
19596
19851
|
super(generationId ? `${message} [${generationId}]` : message);
|
|
19597
19852
|
this[_a$1$3] = true;
|
|
@@ -19609,11 +19864,11 @@ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1$3 = symbol$20
|
|
|
19609
19864
|
return _GatewayError.hasMarker(error);
|
|
19610
19865
|
}
|
|
19611
19866
|
static hasMarker(error) {
|
|
19612
|
-
return typeof error === "object" && error !== null && symbol$
|
|
19867
|
+
return typeof error === "object" && error !== null && symbol$14 in error && error[symbol$14] === true;
|
|
19613
19868
|
}
|
|
19614
19869
|
};
|
|
19615
|
-
var name$
|
|
19616
|
-
var marker2$1 = `vercel.ai.gateway.error.${name$
|
|
19870
|
+
var name$13 = "GatewayAuthenticationError";
|
|
19871
|
+
var marker2$1 = `vercel.ai.gateway.error.${name$13}`;
|
|
19617
19872
|
var symbol2$1 = Symbol.for(marker2$1);
|
|
19618
19873
|
var _a2$1;
|
|
19619
19874
|
var _b2;
|
|
@@ -19626,7 +19881,7 @@ var GatewayAuthenticationError$1 = class _GatewayAuthenticationError extends (_b
|
|
|
19626
19881
|
generationId
|
|
19627
19882
|
});
|
|
19628
19883
|
this[_a2$1] = true;
|
|
19629
|
-
this.name = name$
|
|
19884
|
+
this.name = name$13;
|
|
19630
19885
|
this.type = "authentication_error";
|
|
19631
19886
|
}
|
|
19632
19887
|
static isInstance(error) {
|
|
@@ -22554,14 +22809,14 @@ var __export$3 = (target, all) => {
|
|
|
22554
22809
|
enumerable: true
|
|
22555
22810
|
});
|
|
22556
22811
|
};
|
|
22557
|
-
var name$
|
|
22558
|
-
var marker$
|
|
22559
|
-
var symbol$
|
|
22812
|
+
var name$10 = "AI_InvalidArgumentError";
|
|
22813
|
+
var marker$10 = `vercel.ai.error.${name$10}`;
|
|
22814
|
+
var symbol$13 = Symbol.for(marker$10);
|
|
22560
22815
|
var _a;
|
|
22561
22816
|
var InvalidArgumentError$2 = class extends AISDKError$1 {
|
|
22562
22817
|
constructor({ parameter, value, message }) {
|
|
22563
22818
|
super({
|
|
22564
|
-
name: name$
|
|
22819
|
+
name: name$10,
|
|
22565
22820
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
22566
22821
|
});
|
|
22567
22822
|
this[_a] = true;
|
|
@@ -22569,10 +22824,10 @@ var InvalidArgumentError$2 = class extends AISDKError$1 {
|
|
|
22569
22824
|
this.value = value;
|
|
22570
22825
|
}
|
|
22571
22826
|
static isInstance(error) {
|
|
22572
|
-
return AISDKError$1.hasMarker(error, marker$
|
|
22827
|
+
return AISDKError$1.hasMarker(error, marker$10);
|
|
22573
22828
|
}
|
|
22574
22829
|
};
|
|
22575
|
-
_a = symbol$
|
|
22830
|
+
_a = symbol$13;
|
|
22576
22831
|
var name9 = "AI_NoObjectGeneratedError";
|
|
22577
22832
|
var marker9 = `vercel.ai.error.${name9}`;
|
|
22578
22833
|
var symbol9 = Symbol.for(marker9);
|
|
@@ -23908,8 +24163,8 @@ createIdGenerator$1({
|
|
|
23908
24163
|
* Symbol used for identifying AI SDK Error instances.
|
|
23909
24164
|
* Enables checking if an error is an instance of AISDKError across package versions.
|
|
23910
24165
|
*/
|
|
23911
|
-
const marker$
|
|
23912
|
-
const symbol$
|
|
24166
|
+
const marker$18 = "vercel.ai.error";
|
|
24167
|
+
const symbol$18 = Symbol.for(marker$18);
|
|
23913
24168
|
/**
|
|
23914
24169
|
* Custom error class for AI SDK related errors.
|
|
23915
24170
|
* @extends Error
|
|
@@ -23925,7 +24180,7 @@ var AISDKError$4 = class AISDKError extends Error {
|
|
|
23925
24180
|
*/
|
|
23926
24181
|
constructor({ name, message, cause }) {
|
|
23927
24182
|
super(message);
|
|
23928
|
-
this[symbol$
|
|
24183
|
+
this[symbol$18] = true;
|
|
23929
24184
|
this.name = name;
|
|
23930
24185
|
this.cause = cause;
|
|
23931
24186
|
}
|
|
@@ -23935,24 +24190,24 @@ var AISDKError$4 = class AISDKError extends Error {
|
|
|
23935
24190
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
23936
24191
|
*/
|
|
23937
24192
|
static isInstance(error) {
|
|
23938
|
-
return AISDKError.hasMarker(error, marker$
|
|
24193
|
+
return AISDKError.hasMarker(error, marker$18);
|
|
23939
24194
|
}
|
|
23940
24195
|
static hasMarker(error, marker) {
|
|
23941
24196
|
const markerSymbol = Symbol.for(marker);
|
|
23942
24197
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
23943
24198
|
}
|
|
23944
24199
|
};
|
|
23945
|
-
const name$
|
|
23946
|
-
const marker$
|
|
23947
|
-
const symbol$
|
|
24200
|
+
const name$16 = "AI_APICallError";
|
|
24201
|
+
const marker$16 = `vercel.ai.error.${name$16}`;
|
|
24202
|
+
const symbol$16 = Symbol.for(marker$16);
|
|
23948
24203
|
var APICallError = class extends AISDKError$4 {
|
|
23949
24204
|
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
|
|
23950
24205
|
super({
|
|
23951
|
-
name: name$
|
|
24206
|
+
name: name$16,
|
|
23952
24207
|
message,
|
|
23953
24208
|
cause
|
|
23954
24209
|
});
|
|
23955
|
-
this[symbol$
|
|
24210
|
+
this[symbol$16] = true;
|
|
23956
24211
|
this.url = url;
|
|
23957
24212
|
this.requestBodyValues = requestBodyValues;
|
|
23958
24213
|
this.statusCode = statusCode;
|
|
@@ -23962,22 +24217,22 @@ var APICallError = class extends AISDKError$4 {
|
|
|
23962
24217
|
this.data = data;
|
|
23963
24218
|
}
|
|
23964
24219
|
static isInstance(error) {
|
|
23965
|
-
return AISDKError$4.hasMarker(error, marker$
|
|
24220
|
+
return AISDKError$4.hasMarker(error, marker$16);
|
|
23966
24221
|
}
|
|
23967
24222
|
};
|
|
23968
|
-
const name$
|
|
23969
|
-
const marker$
|
|
23970
|
-
const symbol$
|
|
24223
|
+
const name$15 = "AI_EmptyResponseBodyError";
|
|
24224
|
+
const marker$15 = `vercel.ai.error.${name$15}`;
|
|
24225
|
+
const symbol$15 = Symbol.for(marker$15);
|
|
23971
24226
|
var EmptyResponseBodyError = class extends AISDKError$4 {
|
|
23972
24227
|
constructor({ message = "Empty response body" } = {}) {
|
|
23973
24228
|
super({
|
|
23974
|
-
name: name$
|
|
24229
|
+
name: name$15,
|
|
23975
24230
|
message
|
|
23976
24231
|
});
|
|
23977
|
-
this[symbol$
|
|
24232
|
+
this[symbol$15] = true;
|
|
23978
24233
|
}
|
|
23979
24234
|
static isInstance(error) {
|
|
23980
|
-
return AISDKError$4.hasMarker(error, marker$
|
|
24235
|
+
return AISDKError$4.hasMarker(error, marker$15);
|
|
23981
24236
|
}
|
|
23982
24237
|
};
|
|
23983
24238
|
function getErrorMessage(error) {
|
|
@@ -24105,20 +24360,20 @@ var TypeValidationError$4 = class TypeValidationError extends AISDKError$4 {
|
|
|
24105
24360
|
});
|
|
24106
24361
|
}
|
|
24107
24362
|
};
|
|
24108
|
-
const name$
|
|
24109
|
-
const marker$
|
|
24110
|
-
const symbol$
|
|
24363
|
+
const name$18 = "AI_UnsupportedFunctionalityError";
|
|
24364
|
+
const marker$19 = `vercel.ai.error.${name$18}`;
|
|
24365
|
+
const symbol$19 = Symbol.for(marker$19);
|
|
24111
24366
|
var UnsupportedFunctionalityError = class extends AISDKError$4 {
|
|
24112
24367
|
constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
|
|
24113
24368
|
super({
|
|
24114
|
-
name: name$
|
|
24369
|
+
name: name$18,
|
|
24115
24370
|
message
|
|
24116
24371
|
});
|
|
24117
|
-
this[symbol$
|
|
24372
|
+
this[symbol$19] = true;
|
|
24118
24373
|
this.functionality = functionality;
|
|
24119
24374
|
}
|
|
24120
24375
|
static isInstance(error) {
|
|
24121
|
-
return AISDKError$4.hasMarker(error, marker$
|
|
24376
|
+
return AISDKError$4.hasMarker(error, marker$19);
|
|
24122
24377
|
}
|
|
24123
24378
|
};
|
|
24124
24379
|
var ParseError = class extends Error {
|
|
@@ -24604,7 +24859,7 @@ function handleFetchError({ error, url, requestBodyValues }) {
|
|
|
24604
24859
|
}
|
|
24605
24860
|
return error;
|
|
24606
24861
|
}
|
|
24607
|
-
const VERSION$2 = "5.0.
|
|
24862
|
+
const VERSION$2 = "5.0.81";
|
|
24608
24863
|
/**
|
|
24609
24864
|
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
24610
24865
|
* Entries with `undefined` or `null` values are removed.
|
|
@@ -24707,11 +24962,54 @@ function isSameOrigin(url, baseUrl) {
|
|
|
24707
24962
|
}
|
|
24708
24963
|
}
|
|
24709
24964
|
/**
|
|
24965
|
+
* Request headers stripped before fetching an untrusted URL: host/virtual-host
|
|
24966
|
+
* routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
|
|
24967
|
+
* transport headers (RFC 7230 §6.1).
|
|
24968
|
+
*
|
|
24969
|
+
* `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
|
|
24970
|
+
* are intentionally not listed because trusted provider requests may need
|
|
24971
|
+
* them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
|
|
24972
|
+
* explicit allowlist of non-credential request metadata. Both it and
|
|
24973
|
+
* `fetchWithValidatedRedirects` drop all caller headers except the user-agent
|
|
24974
|
+
* on a cross-origin redirect.
|
|
24975
|
+
*/
|
|
24976
|
+
const BLOCKED_REQUEST_HEADERS = [
|
|
24977
|
+
"connection",
|
|
24978
|
+
"keep-alive",
|
|
24979
|
+
"te",
|
|
24980
|
+
"trailer",
|
|
24981
|
+
"transfer-encoding",
|
|
24982
|
+
"upgrade",
|
|
24983
|
+
"host",
|
|
24984
|
+
"forwarded",
|
|
24985
|
+
"proxy-authorization",
|
|
24986
|
+
"via",
|
|
24987
|
+
"x-forwarded-for",
|
|
24988
|
+
"x-forwarded-host",
|
|
24989
|
+
"x-forwarded-proto",
|
|
24990
|
+
"x-real-ip",
|
|
24991
|
+
"metadata",
|
|
24992
|
+
"metadata-flavor",
|
|
24993
|
+
"x-aws-ec2-metadata-token",
|
|
24994
|
+
"x-metadata-token",
|
|
24995
|
+
"cookie",
|
|
24996
|
+
"set-cookie"
|
|
24997
|
+
];
|
|
24998
|
+
/**
|
|
24999
|
+
* Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
|
|
25000
|
+
* removed. The input is never mutated.
|
|
25001
|
+
*/
|
|
25002
|
+
function sanitizeRequestHeaders(input) {
|
|
25003
|
+
const headers = new Headers(input);
|
|
25004
|
+
for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
|
|
25005
|
+
return headers;
|
|
25006
|
+
}
|
|
25007
|
+
/**
|
|
24710
25008
|
* Validates that a URL is safe to download from, blocking private/internal addresses
|
|
24711
25009
|
* to prevent SSRF attacks.
|
|
24712
25010
|
*
|
|
24713
|
-
*
|
|
24714
|
-
*
|
|
25011
|
+
* This function performs string/literal-IP checks only. DNS validation must
|
|
25012
|
+
* be provided by the fetch transport or network egress controls.
|
|
24715
25013
|
*
|
|
24716
25014
|
* @param url - The URL string to validate.
|
|
24717
25015
|
* @throws DownloadError if the URL is unsafe.
|
|
@@ -24754,16 +25052,6 @@ function validateDownloadUrl(url) {
|
|
|
24754
25052
|
});
|
|
24755
25053
|
}
|
|
24756
25054
|
}
|
|
24757
|
-
/**
|
|
24758
|
-
* Validates an address returned by DNS before it is used to open a socket.
|
|
24759
|
-
* This is intentionally not exported from the package entry point.
|
|
24760
|
-
*/
|
|
24761
|
-
function validateDownloadAddress({ address, family, hostname }) {
|
|
24762
|
-
if (family === 4 ? !isIPv4(address) || isPrivateIPv4(address) : family === 6 ? isPrivateIPv6(address) : true) throw new DownloadError({
|
|
24763
|
-
url: hostname,
|
|
24764
|
-
message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
|
|
24765
|
-
});
|
|
24766
|
-
}
|
|
24767
25055
|
function isIPv4(hostname) {
|
|
24768
25056
|
const parts = hostname.split(".");
|
|
24769
25057
|
if (parts.length !== 4) return false;
|
|
@@ -24847,119 +25135,6 @@ function isPrivateIPv6(ip) {
|
|
|
24847
25135
|
if (topZero(6) || topZero(5) && groups[5] === 65535 || topZero(4) && groups[4] === 65535 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return isPrivateIPv4(`${groups[6] >> 8 & 255}.${groups[6] & 255}.${groups[7] >> 8 & 255}.${groups[7] & 255}`);
|
|
24848
25136
|
return false;
|
|
24849
25137
|
}
|
|
24850
|
-
/**
|
|
24851
|
-
* Creates a DNS lookup hook that validates every returned address before
|
|
24852
|
-
* returning the callback shape requested by the HTTP connector. Because
|
|
24853
|
-
* resolution and validation happen inside the connector, the socket is pinned
|
|
24854
|
-
* to the validated result and DNS rebinding cannot introduce a second lookup.
|
|
24855
|
-
*/
|
|
24856
|
-
function createSafeLookup(lookup) {
|
|
24857
|
-
return ((hostname, options, callback) => {
|
|
24858
|
-
lookup(hostname, {
|
|
24859
|
-
...options,
|
|
24860
|
-
all: true
|
|
24861
|
-
}, (error, addresses) => {
|
|
24862
|
-
if (error) {
|
|
24863
|
-
callback(error);
|
|
24864
|
-
return;
|
|
24865
|
-
}
|
|
24866
|
-
try {
|
|
24867
|
-
const [firstAddress] = addresses;
|
|
24868
|
-
if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
|
|
24869
|
-
for (const { address, family } of addresses) validateDownloadAddress({
|
|
24870
|
-
address,
|
|
24871
|
-
family,
|
|
24872
|
-
hostname
|
|
24873
|
-
});
|
|
24874
|
-
if (options.all === true) callback(null, addresses);
|
|
24875
|
-
else callback(null, firstAddress.address, firstAddress.family);
|
|
24876
|
-
} catch (error) {
|
|
24877
|
-
callback(error instanceof Error ? error : new Error(String(error)));
|
|
24878
|
-
}
|
|
24879
|
-
});
|
|
24880
|
-
});
|
|
24881
|
-
}
|
|
24882
|
-
let safeNodeFetchPromise;
|
|
24883
|
-
function isNodeRuntime$1() {
|
|
24884
|
-
const runtimeProcess = globalThis.process;
|
|
24885
|
-
return runtimeProcess?.release?.name === "node" && runtimeProcess.versions?.bun == null && runtimeProcess.versions?.deno == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
|
|
24886
|
-
}
|
|
24887
|
-
async function getDefaultDownloadFetch() {
|
|
24888
|
-
if (!isNodeRuntime$1()) return globalThis.fetch;
|
|
24889
|
-
return safeNodeFetchPromise ??= Promise.resolve().then(createSafeNodeFetch);
|
|
24890
|
-
}
|
|
24891
|
-
function createSafeNodeFetch() {
|
|
24892
|
-
const module = loadBuiltinModule$1("node:module");
|
|
24893
|
-
const { lookup } = loadBuiltinModule$1("node:dns");
|
|
24894
|
-
const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
|
|
24895
|
-
const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
|
|
24896
|
-
return ((input, init) => fetch(input, {
|
|
24897
|
-
...init,
|
|
24898
|
-
dispatcher
|
|
24899
|
-
}));
|
|
24900
|
-
}
|
|
24901
|
-
function loadBuiltinModule$1(id) {
|
|
24902
|
-
const builtinModule = globalThis.process?.getBuiltinModule?.(id);
|
|
24903
|
-
if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
|
|
24904
|
-
return builtinModule;
|
|
24905
|
-
}
|
|
24906
|
-
function getCurrentModulePath() {
|
|
24907
|
-
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
24908
|
-
try {
|
|
24909
|
-
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
24910
|
-
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
24911
|
-
Error.captureStackTrace(error, getCurrentModulePath);
|
|
24912
|
-
const [caller] = error.stack;
|
|
24913
|
-
const fileName = caller?.getFileName();
|
|
24914
|
-
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
24915
|
-
return fileName;
|
|
24916
|
-
} finally {
|
|
24917
|
-
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
24918
|
-
}
|
|
24919
|
-
}
|
|
24920
|
-
/**
|
|
24921
|
-
* Request headers stripped before fetching an untrusted URL: host/virtual-host
|
|
24922
|
-
* routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
|
|
24923
|
-
* transport headers (RFC 7230 §6.1).
|
|
24924
|
-
*
|
|
24925
|
-
* `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
|
|
24926
|
-
* are intentionally not listed because trusted provider requests may need
|
|
24927
|
-
* them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
|
|
24928
|
-
* explicit allowlist of non-credential request metadata. Both it and
|
|
24929
|
-
* `fetchWithValidatedRedirects` drop all caller headers except the user-agent
|
|
24930
|
-
* on a cross-origin redirect.
|
|
24931
|
-
*/
|
|
24932
|
-
const BLOCKED_REQUEST_HEADERS = [
|
|
24933
|
-
"connection",
|
|
24934
|
-
"keep-alive",
|
|
24935
|
-
"te",
|
|
24936
|
-
"trailer",
|
|
24937
|
-
"transfer-encoding",
|
|
24938
|
-
"upgrade",
|
|
24939
|
-
"host",
|
|
24940
|
-
"forwarded",
|
|
24941
|
-
"proxy-authorization",
|
|
24942
|
-
"via",
|
|
24943
|
-
"x-forwarded-for",
|
|
24944
|
-
"x-forwarded-host",
|
|
24945
|
-
"x-forwarded-proto",
|
|
24946
|
-
"x-real-ip",
|
|
24947
|
-
"metadata",
|
|
24948
|
-
"metadata-flavor",
|
|
24949
|
-
"x-aws-ec2-metadata-token",
|
|
24950
|
-
"x-metadata-token",
|
|
24951
|
-
"cookie",
|
|
24952
|
-
"set-cookie"
|
|
24953
|
-
];
|
|
24954
|
-
/**
|
|
24955
|
-
* Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
|
|
24956
|
-
* removed. The input is never mutated.
|
|
24957
|
-
*/
|
|
24958
|
-
function sanitizeRequestHeaders(input) {
|
|
24959
|
-
const headers = new Headers(input);
|
|
24960
|
-
for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
|
|
24961
|
-
return headers;
|
|
24962
|
-
}
|
|
24963
25138
|
const MAX_DOWNLOAD_REDIRECTS = 10;
|
|
24964
25139
|
const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
24965
25140
|
301,
|
|
@@ -24968,9 +25143,6 @@ const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
|
24968
25143
|
307,
|
|
24969
25144
|
308
|
|
24970
25145
|
]);
|
|
24971
|
-
async function getValidatedFetch(customFetch) {
|
|
24972
|
-
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
|
|
24973
|
-
}
|
|
24974
25146
|
/**
|
|
24975
25147
|
* Fetches a URL while enforcing the download guard on every hop.
|
|
24976
25148
|
*
|
|
@@ -24980,6 +25152,9 @@ async function getValidatedFetch(customFetch) {
|
|
|
24980
25152
|
* target (e.g. an internal address) before we ever see its URL, defeating the
|
|
24981
25153
|
* guard.
|
|
24982
25154
|
*
|
|
25155
|
+
* Manually followed redirects from HTTPS to HTTP are rejected before requesting
|
|
25156
|
+
* the target.
|
|
25157
|
+
*
|
|
24983
25158
|
* Request headers are also protected: {@link sanitizeRequestHeaders} strips
|
|
24984
25159
|
* proxy/metadata/cookie/hop-by-hop headers before the first request, and all
|
|
24985
25160
|
* caller headers except `User-Agent` are dropped on a cross-origin redirect.
|
|
@@ -25009,11 +25184,8 @@ async function getValidatedFetch(customFetch) {
|
|
|
25009
25184
|
* The returned response is the final (non-redirect) response. The caller is
|
|
25010
25185
|
* responsible for checking `response.ok` and reading the body.
|
|
25011
25186
|
*
|
|
25012
|
-
*
|
|
25013
|
-
*
|
|
25014
|
-
* hostname-to-private-IP and DNS-rebinding bypasses. An injected fetch is
|
|
25015
|
-
* responsible for equivalent connect-time validation. Other runtimes should
|
|
25016
|
-
* constrain egress at the network layer when handling untrusted URLs.
|
|
25187
|
+
* URL validation does not resolve DNS. Use guarded-fetch on Node.js
|
|
25188
|
+
* for connection-time DNS validation, or enforce network egress restrictions.
|
|
25017
25189
|
*
|
|
25018
25190
|
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
25019
25191
|
* a redirect cannot be validated on a non-browser runtime.
|
|
@@ -25030,9 +25202,8 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
|
|
|
25030
25202
|
};
|
|
25031
25203
|
let currentUrl = url;
|
|
25032
25204
|
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
25033
|
-
|
|
25034
|
-
|
|
25035
|
-
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
|
|
25205
|
+
if (!(trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin))) validateDownloadUrl(currentUrl);
|
|
25206
|
+
const fetch = customFetch ?? globalThis.fetch;
|
|
25036
25207
|
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
25037
25208
|
if (response.type === "opaqueredirect") {
|
|
25038
25209
|
if (!isBrowserRuntime()) throw new DownloadError({
|
|
@@ -25045,6 +25216,10 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
|
|
|
25045
25216
|
if (REDIRECT_STATUS_CODES.has(response.status) && location) {
|
|
25046
25217
|
cancelResponseBody(response);
|
|
25047
25218
|
const nextUrl = new URL(location, currentUrl).toString();
|
|
25219
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError({
|
|
25220
|
+
url,
|
|
25221
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
25222
|
+
});
|
|
25048
25223
|
if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
|
|
25049
25224
|
const userAgent = currentHeaders.get("user-agent");
|
|
25050
25225
|
currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
|
|
@@ -25081,10 +25256,13 @@ const DEFAULT_MAX_DOWNLOAD_SIZE = 2147483648;
|
|
|
25081
25256
|
* @param response - The fetch Response to read.
|
|
25082
25257
|
* @param url - The URL being downloaded (used in error messages).
|
|
25083
25258
|
* @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
|
|
25259
|
+
* @param onChunk - Optional. Receives each chunk instead of the chunks being
|
|
25260
|
+
* collected, so the body is not held in memory, and the returned array is empty.
|
|
25261
|
+
* The chunk may be a view on a larger buffer, copy what you keep.
|
|
25084
25262
|
* @returns A Uint8Array containing the response body.
|
|
25085
25263
|
* @throws DownloadError if the response exceeds maxBytes.
|
|
25086
25264
|
*/
|
|
25087
|
-
async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE }) {
|
|
25265
|
+
async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE, onChunk }) {
|
|
25088
25266
|
const contentLength = response.headers.get("content-length");
|
|
25089
25267
|
if (contentLength != null) {
|
|
25090
25268
|
const length = parseInt(contentLength, 10);
|
|
@@ -25110,6 +25288,10 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
|
|
|
25110
25288
|
url,
|
|
25111
25289
|
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
25112
25290
|
});
|
|
25291
|
+
if (onChunk != null) {
|
|
25292
|
+
onChunk(value);
|
|
25293
|
+
continue;
|
|
25294
|
+
}
|
|
25113
25295
|
chunks.push(value.byteLength < value.buffer.byteLength ? new Uint8Array(value) : value);
|
|
25114
25296
|
}
|
|
25115
25297
|
} finally {
|
|
@@ -25119,7 +25301,7 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
|
|
|
25119
25301
|
reader.releaseLock();
|
|
25120
25302
|
}
|
|
25121
25303
|
}
|
|
25122
|
-
const result = new Uint8Array(totalBytes);
|
|
25304
|
+
const result = new Uint8Array(onChunk != null ? 0 : totalBytes);
|
|
25123
25305
|
let offset = 0;
|
|
25124
25306
|
for (const chunk of chunks) {
|
|
25125
25307
|
result.set(chunk, offset);
|
|
@@ -26284,6 +26466,7 @@ function zod3Schema$3(zodSchema, options) {
|
|
|
26284
26466
|
} });
|
|
26285
26467
|
}
|
|
26286
26468
|
function zod4Schema$3(zodSchema, options) {
|
|
26469
|
+
if (!(0, zod_v4_core.config)().localeError) (0, zod_v4_core.config)((0, zod_v4_locales_en_js.default)());
|
|
26287
26470
|
const useReferences = options?.useReferences ?? false;
|
|
26288
26471
|
return jsonSchema$4(() => addAdditionalPropertiesToJsonSchema$3((0, zod_v4_core.toJSONSchema)(zodSchema, {
|
|
26289
26472
|
target: "draft-7",
|
|
@@ -26515,12 +26698,27 @@ const postToApi = async ({ url, headers = {}, body, successfulResponseHandler, f
|
|
|
26515
26698
|
function tool(tool) {
|
|
26516
26699
|
return tool;
|
|
26517
26700
|
}
|
|
26518
|
-
|
|
26701
|
+
const telemetryRedaction = Symbol.for("vercel.ai.telemetry.redact");
|
|
26702
|
+
/**
|
|
26703
|
+
* Attach a provider-owned telemetry view without changing the original value.
|
|
26704
|
+
* The annotation is not serialized or included in enumerable application data.
|
|
26705
|
+
* Keep the annotated object when forwarding tool arguments or provider metadata.
|
|
26706
|
+
*/
|
|
26707
|
+
function withTelemetryRedaction(value, redact) {
|
|
26708
|
+
return Object.create(Object.getPrototypeOf(value), {
|
|
26709
|
+
...Object.getOwnPropertyDescriptors(value),
|
|
26710
|
+
[telemetryRedaction]: {
|
|
26711
|
+
value: redact,
|
|
26712
|
+
configurable: true
|
|
26713
|
+
}
|
|
26714
|
+
});
|
|
26715
|
+
}
|
|
26716
|
+
function createProviderExecutedToolFactory({ id, inputSchema, outputSchema, supportsDeferredResults, redactArgs }) {
|
|
26519
26717
|
return ({ onInputStart, onInputDelta, onInputAvailable, ...args }) => tool({
|
|
26520
26718
|
type: "provider",
|
|
26521
26719
|
isProviderExecuted: true,
|
|
26522
26720
|
id,
|
|
26523
|
-
args,
|
|
26721
|
+
args: redactArgs == null ? args : withTelemetryRedaction(args, redactArgs),
|
|
26524
26722
|
inputSchema,
|
|
26525
26723
|
outputSchema,
|
|
26526
26724
|
onInputStart,
|
|
@@ -26586,6 +26784,286 @@ async function retryWithExponentialBackoffInternal(f, { maxRetries, delayInMs, b
|
|
|
26586
26784
|
});
|
|
26587
26785
|
}
|
|
26588
26786
|
}
|
|
26787
|
+
/**
|
|
26788
|
+
* Streaming extraction of large base64 strings from a JSON response body.
|
|
26789
|
+
*
|
|
26790
|
+
* A JSON response that carries an image or a file is mostly one very long
|
|
26791
|
+
* base64 string. The regular pipeline (collect chunks, concatenate, decode to
|
|
26792
|
+
* text, `JSON.parse`, decode base64) holds about four copies of that string at
|
|
26793
|
+
* once. The scanner reads the body chunk by chunk instead: strings at the
|
|
26794
|
+
* configured paths are decoded to bytes while they stream in, and the text that
|
|
26795
|
+
* is handed to `JSON.parse` (the "skeleton") holds a short placeholder in their
|
|
26796
|
+
* place.
|
|
26797
|
+
*
|
|
26798
|
+
* - The skeleton is the original body except for the extracted strings, so
|
|
26799
|
+
* `secureJsonParse` still sees every key (a base64 string cannot contain a
|
|
26800
|
+
* quote, so it cannot hide one).
|
|
26801
|
+
* - A string is extracted only if it is canonical standard-alphabet base64
|
|
26802
|
+
* (length divisible by 4, `=` only as the final padding, zero trailing bits,
|
|
26803
|
+
* no escape sequences or whitespace). The bytes are then exactly what `atob`
|
|
26804
|
+
* gives for it. Everything else stays a string. What was decoded before a
|
|
26805
|
+
* string turned out not to qualify is encoded back, which gives the original
|
|
26806
|
+
* characters.
|
|
26807
|
+
*/
|
|
26808
|
+
/** Strings that decode to fewer bytes stay strings. */
|
|
26809
|
+
const DEFAULT_BINARY_FIELD_MIN_BYTES = 65536;
|
|
26810
|
+
const QUOTE = 34;
|
|
26811
|
+
const BACKSLASH = 92;
|
|
26812
|
+
const EQUALS = 61;
|
|
26813
|
+
const COMMA = 44;
|
|
26814
|
+
const COLON = 58;
|
|
26815
|
+
const LEFT_BRACE = 123;
|
|
26816
|
+
const RIGHT_BRACE = 125;
|
|
26817
|
+
const LEFT_BRACKET = 91;
|
|
26818
|
+
const RIGHT_BRACKET = 93;
|
|
26819
|
+
const OUTSIDE = 0;
|
|
26820
|
+
const KEY = 1;
|
|
26821
|
+
const SKIP = 2;
|
|
26822
|
+
const BLOB = 3;
|
|
26823
|
+
/**
|
|
26824
|
+
* Compiles paths such as `images[*]` or `content[*].data.data`: plain object
|
|
26825
|
+
* keys (letters, digits, `_` and `-`) joined by `.`, and `[*]` for every
|
|
26826
|
+
* element of an array. Keys are compared with the raw bytes of the key in the
|
|
26827
|
+
* body, so a key written with an escape sequence never matches.
|
|
26828
|
+
*/
|
|
26829
|
+
function compileBinaryFieldPaths(paths) {
|
|
26830
|
+
const root = /* @__PURE__ */ new Map();
|
|
26831
|
+
for (const path of paths) {
|
|
26832
|
+
if (!/^(?:[\w-]+|\[\*])(?:\.[\w-]+|\[\*])*$/.test(path)) throw new InvalidArgumentError$1({
|
|
26833
|
+
argument: "experimental_binaryFields",
|
|
26834
|
+
message: `Invalid binary field path "${path}"`
|
|
26835
|
+
});
|
|
26836
|
+
let node = root;
|
|
26837
|
+
for (const segment of path.match(/\[\*]|[\w-]+/g)) {
|
|
26838
|
+
const edges = segment === "[*]" ? [null] : new TextEncoder().encode(`${segment}"`);
|
|
26839
|
+
for (const edge of edges) {
|
|
26840
|
+
let next = node.get(edge);
|
|
26841
|
+
if (next === void 0) node.set(edge, next = /* @__PURE__ */ new Map());
|
|
26842
|
+
node = next;
|
|
26843
|
+
}
|
|
26844
|
+
}
|
|
26845
|
+
node.set(true, node);
|
|
26846
|
+
}
|
|
26847
|
+
return root;
|
|
26848
|
+
}
|
|
26849
|
+
function join$1(parts, length) {
|
|
26850
|
+
const bytes = new Uint8Array(length);
|
|
26851
|
+
let at = 0;
|
|
26852
|
+
for (const part of parts) {
|
|
26853
|
+
bytes.set(part, at);
|
|
26854
|
+
at += part.length;
|
|
26855
|
+
}
|
|
26856
|
+
return bytes;
|
|
26857
|
+
}
|
|
26858
|
+
function createJsonBinaryFieldScanner(paths, minBytes = DEFAULT_BINARY_FIELD_MIN_BYTES) {
|
|
26859
|
+
const sextet = (/* @__PURE__ */ new Uint8Array(256)).fill(64);
|
|
26860
|
+
for (let index = 0; index < 64; index++) sextet["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(index)] = index;
|
|
26861
|
+
const encoder = new TextEncoder();
|
|
26862
|
+
const pieces = [];
|
|
26863
|
+
let piece = /* @__PURE__ */ new Uint8Array(65536);
|
|
26864
|
+
let pieceLength = 0;
|
|
26865
|
+
let size = 0;
|
|
26866
|
+
const binaries = /* @__PURE__ */ new Map();
|
|
26867
|
+
const frames = [];
|
|
26868
|
+
let skipped = 0;
|
|
26869
|
+
let mode = OUTSIDE;
|
|
26870
|
+
let escaped = false;
|
|
26871
|
+
let last = 0;
|
|
26872
|
+
let key;
|
|
26873
|
+
let segments = [];
|
|
26874
|
+
let segment = /* @__PURE__ */ new Uint8Array(0);
|
|
26875
|
+
let at = 0;
|
|
26876
|
+
let total = 0;
|
|
26877
|
+
let bits = 0;
|
|
26878
|
+
let chars = 0;
|
|
26879
|
+
let padding = 0;
|
|
26880
|
+
const add = (bytes) => {
|
|
26881
|
+
for (let offset = 0; offset < bytes.length;) {
|
|
26882
|
+
const length = Math.min(piece.length - pieceLength, bytes.length - offset);
|
|
26883
|
+
piece.set(bytes.subarray(offset, offset + length), pieceLength);
|
|
26884
|
+
pieceLength += length;
|
|
26885
|
+
offset += length;
|
|
26886
|
+
size += length;
|
|
26887
|
+
if (pieceLength === piece.length) {
|
|
26888
|
+
pieces.push(piece);
|
|
26889
|
+
piece = /* @__PURE__ */ new Uint8Array(65536);
|
|
26890
|
+
pieceLength = 0;
|
|
26891
|
+
}
|
|
26892
|
+
}
|
|
26893
|
+
};
|
|
26894
|
+
const emit = (chunk, start, end) => add(chunk.subarray(start, end));
|
|
26895
|
+
const reset = () => {
|
|
26896
|
+
segments = [];
|
|
26897
|
+
segment = /* @__PURE__ */ new Uint8Array(0);
|
|
26898
|
+
at = 0;
|
|
26899
|
+
total = 0;
|
|
26900
|
+
bits = 0;
|
|
26901
|
+
chars = 0;
|
|
26902
|
+
padding = 0;
|
|
26903
|
+
};
|
|
26904
|
+
const grow = () => {
|
|
26905
|
+
if (at > 0) segments.push(segment.subarray(0, at));
|
|
26906
|
+
segment = new Uint8Array(Math.min(Math.max(total, 4096), 4 << 20));
|
|
26907
|
+
at = 0;
|
|
26908
|
+
};
|
|
26909
|
+
const rest = () => bits << (4 - chars) * 6;
|
|
26910
|
+
const restore = () => {
|
|
26911
|
+
for (const part of [...segments, segment.subarray(0, at)]) add(encoder.encode(convertUint8ArrayToBase64(part)));
|
|
26912
|
+
const group = rest();
|
|
26913
|
+
add(encoder.encode(convertUint8ArrayToBase64(Uint8Array.of(group >> 16, group >> 8, group)).slice(0, chars) + "=".repeat(padding)));
|
|
26914
|
+
reset();
|
|
26915
|
+
};
|
|
26916
|
+
const closeBlob = () => {
|
|
26917
|
+
mode = OUTSIDE;
|
|
26918
|
+
const tail = chars && chars - 1;
|
|
26919
|
+
if (padding === (4 - chars) % 4 && !(bits & (1 << (4 - chars) * 2) - 1) && total + tail >= minBytes) {
|
|
26920
|
+
const group = rest();
|
|
26921
|
+
const bytes = join$1([...segments, segment.subarray(0, at)], total + tail);
|
|
26922
|
+
for (let index = 0; index < tail; index++) bytes[total + index] = group >> 16 - 8 * index;
|
|
26923
|
+
const placeholder = `[binary data: ${bytes.length} bytes; ref ${crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(2)).join("-")}]`;
|
|
26924
|
+
binaries.set(placeholder, bytes);
|
|
26925
|
+
add(encoder.encode(placeholder));
|
|
26926
|
+
reset();
|
|
26927
|
+
} else restore();
|
|
26928
|
+
};
|
|
26929
|
+
const push = (chunk) => {
|
|
26930
|
+
let from = 0;
|
|
26931
|
+
const { length } = chunk;
|
|
26932
|
+
for (let index = 0; index < length; index++) {
|
|
26933
|
+
let byte = chunk[index];
|
|
26934
|
+
if (mode === BLOB) {
|
|
26935
|
+
if (padding === 0) {
|
|
26936
|
+
let pending = bits;
|
|
26937
|
+
let count = chars;
|
|
26938
|
+
for (let value; index < length && (value = sextet[chunk[index]]) < 64; index++) {
|
|
26939
|
+
pending = pending << 6 | value;
|
|
26940
|
+
if (++count === 4) {
|
|
26941
|
+
if (at + 3 > segment.length) grow();
|
|
26942
|
+
segment[at++] = pending >> 16;
|
|
26943
|
+
segment[at++] = pending >> 8;
|
|
26944
|
+
segment[at++] = pending;
|
|
26945
|
+
total += 3;
|
|
26946
|
+
pending = 0;
|
|
26947
|
+
count = 0;
|
|
26948
|
+
}
|
|
26949
|
+
}
|
|
26950
|
+
bits = pending;
|
|
26951
|
+
chars = count;
|
|
26952
|
+
}
|
|
26953
|
+
if (index >= length) break;
|
|
26954
|
+
byte = chunk[index];
|
|
26955
|
+
if (byte === QUOTE) {
|
|
26956
|
+
closeBlob();
|
|
26957
|
+
from = index;
|
|
26958
|
+
} else if (byte === EQUALS && chars > 1 && padding < 4 - chars) padding++;
|
|
26959
|
+
else {
|
|
26960
|
+
restore();
|
|
26961
|
+
mode = SKIP;
|
|
26962
|
+
from = index--;
|
|
26963
|
+
}
|
|
26964
|
+
} else if (mode !== OUTSIDE) {
|
|
26965
|
+
if (mode === KEY) key = key?.get(byte);
|
|
26966
|
+
if (escaped) escaped = false;
|
|
26967
|
+
else if (byte === BACKSLASH) escaped = true;
|
|
26968
|
+
else if (byte === QUOTE) {
|
|
26969
|
+
if (mode === KEY) frames.at(-1).next = key;
|
|
26970
|
+
mode = OUTSIDE;
|
|
26971
|
+
}
|
|
26972
|
+
} else if (byte === QUOTE) {
|
|
26973
|
+
const frame = frames.at(-1);
|
|
26974
|
+
if (skipped > 0) mode = SKIP;
|
|
26975
|
+
else if (frame?.keys && (last === LEFT_BRACE || last === COMMA)) {
|
|
26976
|
+
mode = KEY;
|
|
26977
|
+
key = frame.keys;
|
|
26978
|
+
} else if ((frame ? frame.next : paths)?.get(true)) {
|
|
26979
|
+
mode = BLOB;
|
|
26980
|
+
emit(chunk, from, index + 1);
|
|
26981
|
+
} else mode = SKIP;
|
|
26982
|
+
} else if (byte === LEFT_BRACE || byte === LEFT_BRACKET) {
|
|
26983
|
+
last = byte;
|
|
26984
|
+
const frame = frames.at(-1);
|
|
26985
|
+
const node = skipped > 0 ? void 0 : frame ? frame.next : paths;
|
|
26986
|
+
const items = node?.get(null);
|
|
26987
|
+
if (byte === LEFT_BRACE && node) frames.push({ keys: node });
|
|
26988
|
+
else if (byte === LEFT_BRACKET && items) frames.push({
|
|
26989
|
+
keys: null,
|
|
26990
|
+
next: items
|
|
26991
|
+
});
|
|
26992
|
+
else skipped++;
|
|
26993
|
+
} else if (byte === RIGHT_BRACE || byte === RIGHT_BRACKET) {
|
|
26994
|
+
if (skipped > 0) skipped--;
|
|
26995
|
+
else frames.pop();
|
|
26996
|
+
} else if (byte === COMMA || byte === COLON) last = byte;
|
|
26997
|
+
}
|
|
26998
|
+
if (mode !== BLOB) emit(chunk, from, length);
|
|
26999
|
+
};
|
|
27000
|
+
const finish = () => {
|
|
27001
|
+
if (mode === BLOB) restore();
|
|
27002
|
+
return {
|
|
27003
|
+
text: new TextDecoder().decode(join$1([...pieces, piece.subarray(0, pieceLength)], size)),
|
|
27004
|
+
binaries
|
|
27005
|
+
};
|
|
27006
|
+
};
|
|
27007
|
+
return {
|
|
27008
|
+
push,
|
|
27009
|
+
finish
|
|
27010
|
+
};
|
|
27011
|
+
}
|
|
27012
|
+
/**
|
|
27013
|
+
* Replaces the placeholders in a parsed value with the bytes they stand for.
|
|
27014
|
+
* Objects and arrays are copied, the parsed value is not modified. A
|
|
27015
|
+
* placeholder holds a random number, so a string that equals one is ours.
|
|
27016
|
+
*/
|
|
27017
|
+
function replaceBinaryFieldPlaceholders(value, binaries) {
|
|
27018
|
+
if (typeof value === "string") return binaries.get(value) ?? value;
|
|
27019
|
+
if (Array.isArray(value)) return value.map((item) => replaceBinaryFieldPlaceholders(item, binaries));
|
|
27020
|
+
if (value != null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, replaceBinaryFieldPlaceholders(item, binaries)]));
|
|
27021
|
+
return value;
|
|
27022
|
+
}
|
|
27023
|
+
/**
|
|
27024
|
+
* Makes `JSON.stringify` give the placeholder for each of the arrays, instead
|
|
27025
|
+
* of `{"0":…,"1":…}` with an entry for every byte: 24 MiB of bytes would
|
|
27026
|
+
* become a string of more than 300 MB. That is what a validator, or the code
|
|
27027
|
+
* that reports its issues, does with a value it puts into an error message.
|
|
27028
|
+
* The property is not enumerable, so the arrays look the same otherwise.
|
|
27029
|
+
* Returns the function that removes it again.
|
|
27030
|
+
*/
|
|
27031
|
+
function maskBinariesInJson(binaries) {
|
|
27032
|
+
for (const [placeholder, bytes] of binaries) Object.defineProperty(bytes, "toJSON", {
|
|
27033
|
+
value: () => placeholder,
|
|
27034
|
+
configurable: true
|
|
27035
|
+
});
|
|
27036
|
+
return () => {
|
|
27037
|
+
for (const bytes of binaries.values()) Reflect.deleteProperty(bytes, "toJSON");
|
|
27038
|
+
};
|
|
27039
|
+
}
|
|
27040
|
+
/**
|
|
27041
|
+
* Wraps a schema so that it validates the extracted bytes in place of their
|
|
27042
|
+
* placeholders. The value parsed from the skeleton, and the value of the
|
|
27043
|
+
* validation error of the response, keep the placeholders: reporting an error
|
|
27044
|
+
* never prints the bytes.
|
|
27045
|
+
*
|
|
27046
|
+
* The errors of the schema itself may hold the bytes: a Standard Schema
|
|
27047
|
+
* validator wraps the value it was given into an error, and the issues it
|
|
27048
|
+
* reports may carry the offending input. So that their messages do not grow
|
|
27049
|
+
* with the image, the arrays stringify as their placeholders, and keep doing
|
|
27050
|
+
* so as long as an error can refer to them. When the validation succeeds the
|
|
27051
|
+
* arrays are plain again, for whoever receives them.
|
|
27052
|
+
*/
|
|
27053
|
+
function withBinaryFields(schema, binaries) {
|
|
27054
|
+
if (binaries.size === 0) return schema;
|
|
27055
|
+
const actualSchema = asSchema$4(schema);
|
|
27056
|
+
return jsonSchema$4({}, { validate: async (value) => {
|
|
27057
|
+
const replaced = replaceBinaryFieldPlaceholders(value, binaries);
|
|
27058
|
+
const unmask = maskBinariesInJson(binaries);
|
|
27059
|
+
const result = actualSchema.validate ? await actualSchema.validate(replaced) : {
|
|
27060
|
+
success: true,
|
|
27061
|
+
value: replaced
|
|
27062
|
+
};
|
|
27063
|
+
if (result.success) unmask();
|
|
27064
|
+
return result;
|
|
27065
|
+
} });
|
|
27066
|
+
}
|
|
26589
27067
|
const textDecoder = new TextDecoder();
|
|
26590
27068
|
const DEFAULT_MAX_JSON_LINE_BYTES = 67108864;
|
|
26591
27069
|
function wrapResponseBodyStream({ stream, url, requestBodyValues, statusCode, responseHeaders }) {
|
|
@@ -26708,29 +27186,45 @@ const createEventSourceResponseHandler = (chunkSchema) => async ({ response, url
|
|
|
26708
27186
|
})
|
|
26709
27187
|
};
|
|
26710
27188
|
};
|
|
26711
|
-
const createJsonResponseHandler = (responseSchema
|
|
26712
|
-
const
|
|
26713
|
-
|
|
26714
|
-
|
|
26715
|
-
|
|
26716
|
-
|
|
26717
|
-
|
|
26718
|
-
|
|
26719
|
-
|
|
26720
|
-
|
|
26721
|
-
|
|
26722
|
-
|
|
26723
|
-
|
|
26724
|
-
|
|
26725
|
-
|
|
26726
|
-
|
|
26727
|
-
|
|
26728
|
-
|
|
26729
|
-
|
|
26730
|
-
|
|
26731
|
-
|
|
26732
|
-
|
|
26733
|
-
|
|
27189
|
+
const createJsonResponseHandler = (responseSchema, { experimental_binaryFields } = {}) => {
|
|
27190
|
+
const binaryFieldPaths = experimental_binaryFields?.length ? compileBinaryFieldPaths(experimental_binaryFields) : void 0;
|
|
27191
|
+
return async ({ response, url, requestBodyValues }) => {
|
|
27192
|
+
let responseBody;
|
|
27193
|
+
let schema = responseSchema;
|
|
27194
|
+
if (binaryFieldPaths == null) responseBody = await readResponseBodyAsText({
|
|
27195
|
+
response,
|
|
27196
|
+
url
|
|
27197
|
+
});
|
|
27198
|
+
else {
|
|
27199
|
+
const scanner = createJsonBinaryFieldScanner(binaryFieldPaths);
|
|
27200
|
+
await readResponseWithSizeLimit({
|
|
27201
|
+
response,
|
|
27202
|
+
url,
|
|
27203
|
+
onChunk: scanner.push
|
|
27204
|
+
});
|
|
27205
|
+
const scanned = scanner.finish();
|
|
27206
|
+
responseBody = scanned.text;
|
|
27207
|
+
schema = withBinaryFields(responseSchema, scanned.binaries);
|
|
27208
|
+
}
|
|
27209
|
+
const parsedResult = await safeParseJSON$4({
|
|
27210
|
+
text: responseBody,
|
|
27211
|
+
schema
|
|
27212
|
+
});
|
|
27213
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
27214
|
+
if (!parsedResult.success) throw new APICallError({
|
|
27215
|
+
message: "Invalid JSON response",
|
|
27216
|
+
cause: parsedResult.error,
|
|
27217
|
+
statusCode: response.status,
|
|
27218
|
+
responseHeaders,
|
|
27219
|
+
responseBody,
|
|
27220
|
+
url,
|
|
27221
|
+
requestBodyValues
|
|
27222
|
+
});
|
|
27223
|
+
return {
|
|
27224
|
+
responseHeaders,
|
|
27225
|
+
value: parsedResult.value,
|
|
27226
|
+
rawValue: parsedResult.rawValue
|
|
27227
|
+
};
|
|
26734
27228
|
};
|
|
26735
27229
|
};
|
|
26736
27230
|
const createJsonLinesResponseHandler = (responseSchema, { maxLineBytes = DEFAULT_MAX_JSON_LINE_BYTES } = {}) => {
|
|
@@ -26814,20 +27308,20 @@ function isJSONSerializable(value) {
|
|
|
26814
27308
|
if (Object.getPrototypeOf(value) === Object.prototype) return Object.values(value).every(isJSONSerializable);
|
|
26815
27309
|
return false;
|
|
26816
27310
|
}
|
|
26817
|
-
const name$
|
|
26818
|
-
const marker$
|
|
26819
|
-
const symbol$
|
|
27311
|
+
const name$12 = "AI_SerializationError";
|
|
27312
|
+
const marker$12 = `vercel.ai.error.${name$12}`;
|
|
27313
|
+
const symbol$12 = Symbol.for(marker$12);
|
|
26820
27314
|
var SerializationError = class extends AISDKError$4 {
|
|
26821
27315
|
constructor({ message = "Failed to serialize value.", cause } = {}) {
|
|
26822
27316
|
super({
|
|
26823
|
-
name: name$
|
|
27317
|
+
name: name$12,
|
|
26824
27318
|
message,
|
|
26825
27319
|
cause
|
|
26826
27320
|
});
|
|
26827
|
-
this[symbol$
|
|
27321
|
+
this[symbol$12] = true;
|
|
26828
27322
|
}
|
|
26829
27323
|
static isInstance(error) {
|
|
26830
|
-
return AISDKError$4.hasMarker(error, marker$
|
|
27324
|
+
return AISDKError$4.hasMarker(error, marker$12);
|
|
26831
27325
|
}
|
|
26832
27326
|
};
|
|
26833
27327
|
/**
|
|
@@ -36785,7 +37279,7 @@ async function resolveImageDimensionsAsync(part) {
|
|
|
36785
37279
|
const url = resolveHttpAssetUrl(getObjectValue(part, "image") ?? getObjectValue(part, "data"));
|
|
36786
37280
|
if (!url) return existing;
|
|
36787
37281
|
try {
|
|
36788
|
-
const probeImageSize = (await Promise.resolve().then(() => /* @__PURE__ */ require_rolldown_runtime.__toESM(require("./probe-image-size-
|
|
37282
|
+
const probeImageSize = (await Promise.resolve().then(() => /* @__PURE__ */ require_rolldown_runtime.__toESM(require("./probe-image-size-CIvA48eX.cjs").default, 1))).default;
|
|
36789
37283
|
const probed = await probeImageSize(url, {
|
|
36790
37284
|
open_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
|
|
36791
37285
|
response_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
|
|
@@ -48155,12 +48649,25 @@ function getOmObservabilityContext(args) {
|
|
|
48155
48649
|
metrics: args.metrics
|
|
48156
48650
|
};
|
|
48157
48651
|
}
|
|
48158
|
-
/** Key used to store gateway
|
|
48159
|
-
const GATEWAY_STATE_KEY = "
|
|
48652
|
+
/** Key used to store whether the gateway manages memory for the current step in per-processor state. */
|
|
48653
|
+
const GATEWAY_STATE_KEY = "__isGatewayMemoryManaged";
|
|
48160
48654
|
/** Step number OM last recovered from a context-overflow error, so each step retries at most once. */
|
|
48161
48655
|
const CONTEXT_OVERFLOW_STEP_KEY = "__omContextOverflowStep";
|
|
48162
|
-
/**
|
|
48163
|
-
|
|
48656
|
+
/**
|
|
48657
|
+
* Whether the Mastra gateway serves Observational Memory for this step's model.
|
|
48658
|
+
*
|
|
48659
|
+
* Gateway models only get memory from the gateway when the credential is a Gateway project
|
|
48660
|
+
* key. Organization keys (`msk-gateway-…`, `mskv2_…`) are served by a gateway without the
|
|
48661
|
+
* memory API, so memory has to stay local. Newer `@mastra/core` exposes that decision on the
|
|
48662
|
+
* router model; when it is absent (older core, or a plain model) fall back to the historical
|
|
48663
|
+
* `mastra/` prefix check so gateway-side memory is never double-processed.
|
|
48664
|
+
*
|
|
48665
|
+
* A model that fails the check is not treated as local. Core answers `false` only for a model
|
|
48666
|
+
* that isn't on the gateway, and throws when the credential can't be resolved — including when it
|
|
48667
|
+
* is missing; letting that through keeps the two sides in agreement.
|
|
48668
|
+
*/
|
|
48669
|
+
async function isGatewayMemoryManaged(model) {
|
|
48670
|
+
if (typeof model === "object" && model !== null && typeof model.isGatewayMemoryManaged === "function") return Boolean(await model.isGatewayMemoryManaged());
|
|
48164
48671
|
return typeof model === "object" && model !== null && "gatewayId" in model && model.gatewayId === "mastra";
|
|
48165
48672
|
}
|
|
48166
48673
|
function injectObservationContextMessages({ messageList, systemMessages, continuationMessage, hasObservations, threadId, resourceId }) {
|
|
@@ -48226,6 +48733,34 @@ var ObservationalMemoryProcessor = class {
|
|
|
48226
48733
|
this.memory = memory;
|
|
48227
48734
|
this.temporalMarkers = options?.temporalMarkers ?? false;
|
|
48228
48735
|
}
|
|
48736
|
+
/**
|
|
48737
|
+
* End any locally started turn without leaving it dangling.
|
|
48738
|
+
*
|
|
48739
|
+
* A gateway-managed step short-circuits both processor phases, so a turn started on an
|
|
48740
|
+
* earlier step of the same run — a delegation run whose model changed, or a run whose key
|
|
48741
|
+
* changed — would otherwise never be ended and its messages never persisted. `end()` with
|
|
48742
|
+
* no arguments flushes what the turn already tracked; finalization passes the accepted
|
|
48743
|
+
* terminal list for the same reason the regular output path does.
|
|
48744
|
+
*
|
|
48745
|
+
* A rejected write is not swallowed. `end()` marks the turn ended before it persists, so a
|
|
48746
|
+
* failed write leaves the turn unusable and its messages would be lost silently while the run
|
|
48747
|
+
* reported success. The drain persists those messages directly and rethrows, so a storage
|
|
48748
|
+
* failure surfaces instead of dropping the turn.
|
|
48749
|
+
*/
|
|
48750
|
+
async endActiveTurn(state, messageList) {
|
|
48751
|
+
const activeTurn = asLiveTurn(state.__omTurn) ?? this.turn;
|
|
48752
|
+
this.turn = void 0;
|
|
48753
|
+
state.__omTurn = void 0;
|
|
48754
|
+
if (!activeTurn || activeTurn.ended) return;
|
|
48755
|
+
const terminalList = messageList ?? activeTurn.messageList;
|
|
48756
|
+
const unsavedMessages = [...terminalList.get.input.db(), ...terminalList.get.response.db()];
|
|
48757
|
+
try {
|
|
48758
|
+
await activeTurn.end(terminalList);
|
|
48759
|
+
} catch (error) {
|
|
48760
|
+
if (unsavedMessages.length > 0) await this.engine.persistMessages(unsavedMessages, activeTurn.threadId, activeTurn.resourceId).catch(() => {});
|
|
48761
|
+
throw error;
|
|
48762
|
+
}
|
|
48763
|
+
}
|
|
48229
48764
|
async processInputStep(args) {
|
|
48230
48765
|
const { messageList, requestContext, stepNumber, state: _state, writer, model, abortSignal, abort, messageId, rotateResponseMessageId } = args;
|
|
48231
48766
|
const state = _state ?? {};
|
|
@@ -48235,9 +48770,11 @@ var ObservationalMemoryProcessor = class {
|
|
|
48235
48770
|
omDebug(`[OM:processInputStep:NO-CONTEXT] getThreadContext returned null — returning early`);
|
|
48236
48771
|
return messageList;
|
|
48237
48772
|
}
|
|
48238
|
-
|
|
48239
|
-
|
|
48240
|
-
|
|
48773
|
+
const gatewayMemoryManaged = await isGatewayMemoryManaged(model);
|
|
48774
|
+
state[GATEWAY_STATE_KEY] = gatewayMemoryManaged;
|
|
48775
|
+
if (gatewayMemoryManaged) {
|
|
48776
|
+
await this.endActiveTurn(state);
|
|
48777
|
+
omDebug(`[OM:processInputStep:GATEWAY] gateway manages memory — skipping local processing`);
|
|
48241
48778
|
return messageList;
|
|
48242
48779
|
}
|
|
48243
48780
|
const { threadId, resourceId } = context;
|
|
@@ -48427,7 +48964,10 @@ var ObservationalMemoryProcessor = class {
|
|
|
48427
48964
|
const state = _state ?? {};
|
|
48428
48965
|
const context = this.engine.getThreadContext(requestContext, messageList);
|
|
48429
48966
|
if (!context) return messageList;
|
|
48430
|
-
if (state[GATEWAY_STATE_KEY])
|
|
48967
|
+
if (state[GATEWAY_STATE_KEY]) {
|
|
48968
|
+
await this.endActiveTurn(state, messageList.cloneForPersistence());
|
|
48969
|
+
return messageList;
|
|
48970
|
+
}
|
|
48431
48971
|
state.__omObservabilityContext = getOmObservabilityContext(args);
|
|
48432
48972
|
return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
|
|
48433
48973
|
if ((0, _mastra_core_memory.parseMemoryRequestContext)(requestContext)?.memoryConfig?.readOnly) return messageList;
|
|
@@ -48900,7 +49440,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
|
|
|
48900
49440
|
}
|
|
48901
49441
|
}
|
|
48902
49442
|
const threshold = (typeof config.semanticRecall === "object" ? config.semanticRecall : void 0)?.threshold;
|
|
48903
|
-
const filteredVectorResults =
|
|
49443
|
+
const filteredVectorResults = vectorResults.filter((r) => (threshold === void 0 || r.score >= threshold) && (resourceScope ? r.metadata?.resource_id === resourceId : r.metadata?.thread_id === threadId));
|
|
48904
49444
|
const memoryStore = await this.getMemoryStore();
|
|
48905
49445
|
const include = filteredVectorResults.map((r) => ({
|
|
48906
49446
|
id: r.metadata?.message_id,
|
|
@@ -48964,6 +49504,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
|
|
|
48964
49504
|
rawMessages = shouldGetNewestAndReverse ? paginatedResult.messages.reverse() : paginatedResult.messages;
|
|
48965
49505
|
({total, page: resultPage, perPage: resultPerPage, hasMore} = paginatedResult);
|
|
48966
49506
|
}
|
|
49507
|
+
if (include.length) rawMessages = rawMessages.filter((message) => message.threadId === threadId || resourceScope && message.resourceId === resourceId);
|
|
48967
49508
|
const messages = filterSystemReminderMessages(new _mastra_core_agent.MessageList({
|
|
48968
49509
|
threadId,
|
|
48969
49510
|
resourceId
|
|
@@ -49314,42 +49855,74 @@ ${workingMemory}`;
|
|
|
49314
49855
|
this.embeddingCache.set(key, result);
|
|
49315
49856
|
return result;
|
|
49316
49857
|
}
|
|
49858
|
+
chunkEmbeddingCache = new I({ max: DEFAULT_EMBEDDING_CACHE_MAX_SIZE });
|
|
49859
|
+
chunkEmbeddingCacheOwner = {};
|
|
49860
|
+
/**
|
|
49861
|
+
* Embeds one message's chunks, reusing vectors already produced for the same chunks. Usage is
|
|
49862
|
+
* returned only for a call that reached the embedder.
|
|
49863
|
+
*/
|
|
49864
|
+
async embedMessageChunks(chunks) {
|
|
49865
|
+
const producer = {
|
|
49866
|
+
embedder: this.embedder,
|
|
49867
|
+
embedderOptions: this.embedderOptions
|
|
49868
|
+
};
|
|
49869
|
+
const key = (await this.hasher).h64(JSON.stringify(chunks));
|
|
49870
|
+
if (producer.embedder !== this.embedder || producer.embedderOptions !== this.embedderOptions) return this.embedValues(chunks, producer);
|
|
49871
|
+
const owner = this.chunkEmbeddingCacheOwner;
|
|
49872
|
+
if (owner.embedder !== producer.embedder || owner.embedderOptions !== producer.embedderOptions) {
|
|
49873
|
+
this.chunkEmbeddingCache.clear();
|
|
49874
|
+
this.chunkEmbeddingCacheOwner = producer;
|
|
49875
|
+
}
|
|
49876
|
+
const cached = this.chunkEmbeddingCache.get(key);
|
|
49877
|
+
if (cached) return { embeddings: await cached };
|
|
49878
|
+
const result = this.embedValues(chunks, producer);
|
|
49879
|
+
const embeddings = result.then(({ embeddings }) => {
|
|
49880
|
+
if (embeddings.length !== chunks.length) evict();
|
|
49881
|
+
return embeddings;
|
|
49882
|
+
});
|
|
49883
|
+
const evict = () => {
|
|
49884
|
+
if (this.chunkEmbeddingCache.get(key) === embeddings) this.chunkEmbeddingCache.delete(key);
|
|
49885
|
+
};
|
|
49886
|
+
embeddings.catch(evict);
|
|
49887
|
+
this.chunkEmbeddingCache.set(key, embeddings);
|
|
49888
|
+
return result;
|
|
49889
|
+
}
|
|
49317
49890
|
/** Sends texts to the embedder through the AI SDK version that matches its spec. */
|
|
49318
|
-
async embedValues(values) {
|
|
49319
|
-
if (typeof
|
|
49320
|
-
const isFastEmbed =
|
|
49891
|
+
async embedValues(values, { embedder, embedderOptions } = this) {
|
|
49892
|
+
if (typeof embedder === `undefined`) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
49893
|
+
const isFastEmbed = embedder.provider === `fastembed`;
|
|
49321
49894
|
if (isFastEmbed && this.firstEmbed instanceof Promise) await this.firstEmbed;
|
|
49322
49895
|
const options = {
|
|
49323
49896
|
values,
|
|
49324
49897
|
maxRetries: 3
|
|
49325
49898
|
};
|
|
49326
|
-
const model =
|
|
49899
|
+
const model = embedder;
|
|
49327
49900
|
let promise;
|
|
49328
49901
|
switch (model.specificationVersion) {
|
|
49329
49902
|
case "v4":
|
|
49330
49903
|
promise = embedMany({
|
|
49331
49904
|
...options,
|
|
49332
|
-
...
|
|
49905
|
+
...embedderOptions,
|
|
49333
49906
|
model
|
|
49334
49907
|
});
|
|
49335
49908
|
break;
|
|
49336
49909
|
case "v3":
|
|
49337
49910
|
promise = embedMany$1({
|
|
49338
49911
|
...options,
|
|
49339
|
-
...
|
|
49912
|
+
...embedderOptions,
|
|
49340
49913
|
model
|
|
49341
49914
|
});
|
|
49342
49915
|
break;
|
|
49343
49916
|
case "v2":
|
|
49344
49917
|
promise = embedMany$2({
|
|
49345
49918
|
...options,
|
|
49346
|
-
...
|
|
49919
|
+
...embedderOptions,
|
|
49347
49920
|
model
|
|
49348
49921
|
});
|
|
49349
49922
|
break;
|
|
49350
49923
|
default: promise = embedMany$3({
|
|
49351
49924
|
...options,
|
|
49352
|
-
...
|
|
49925
|
+
...embedderOptions,
|
|
49353
49926
|
model
|
|
49354
49927
|
});
|
|
49355
49928
|
}
|
|
@@ -49391,7 +49964,7 @@ ${workingMemory}`;
|
|
|
49391
49964
|
if (!this.embedder && !this.isSelfEmbedding) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
49392
49965
|
return (0, _mastra_core_memory.buildMessageEmbeddingRows)({
|
|
49393
49966
|
items,
|
|
49394
|
-
embed: this.isSelfEmbedding ? void 0 : (chunks) => this.
|
|
49967
|
+
embed: this.isSelfEmbedding ? void 0 : (chunks) => this.embedMessageChunks(chunks),
|
|
49395
49968
|
maxChunkChars: (0, _mastra_core_memory.resolveMaxChunkChars)({
|
|
49396
49969
|
maxChunkChars: this.configuredMaxChunkChars,
|
|
49397
49970
|
embedder: this.embedder
|
|
@@ -49977,6 +50550,7 @@ Notes:
|
|
|
49977
50550
|
});
|
|
49978
50551
|
for (const r of results) {
|
|
49979
50552
|
if (!r.metadata?.thread_id) continue;
|
|
50553
|
+
if (r.metadata.resource_id !== resourceId || filter?.threadId && r.metadata.thread_id !== filter.threadId) continue;
|
|
49980
50554
|
const groupId = typeof r.metadata.group_id === "string" ? r.metadata.group_id : void 0;
|
|
49981
50555
|
if (!groupId) continue;
|
|
49982
50556
|
queryResults.push({
|
|
@@ -52026,7 +52600,7 @@ const createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
52026
52600
|
try {
|
|
52027
52601
|
const providerFn = version === `v1` ? { v1: {
|
|
52028
52602
|
openai: async () => {
|
|
52029
|
-
const { openai } = await Promise.resolve().then(() => require("./dist-
|
|
52603
|
+
const { openai } = await Promise.resolve().then(() => require("./dist-D4zWd2g_.cjs"));
|
|
52030
52604
|
return openai(modelId);
|
|
52031
52605
|
},
|
|
52032
52606
|
anthropic: async () => {
|
|
@@ -59856,4 +60430,4 @@ Object.defineProperty(exports, "require_webp", {
|
|
|
59856
60430
|
}
|
|
59857
60431
|
});
|
|
59858
60432
|
|
|
59859
|
-
//# sourceMappingURL=dist-
|
|
60433
|
+
//# sourceMappingURL=dist-BgMRdBmR.cjs.map
|