@dexto/core 1.16.6 → 1.17.0-beta.5
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/agent/DextoAgent.cjs +2 -1
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +2 -1
- package/dist/agent/schemas.d.ts +2 -2
- package/dist/approval/index.cjs +4 -0
- package/dist/approval/index.d.ts +1 -1
- package/dist/approval/index.d.ts.map +1 -1
- package/dist/approval/index.js +4 -0
- package/dist/events/index.cjs +2 -3
- package/dist/events/index.d.ts +6 -23
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +2 -3
- package/dist/llm/error-codes.cjs +1 -0
- package/dist/llm/error-codes.d.ts +1 -0
- package/dist/llm/error-codes.d.ts.map +1 -1
- package/dist/llm/error-codes.js +1 -0
- package/dist/llm/executor/provider-error.cjs +14 -0
- package/dist/llm/executor/provider-error.d.ts.map +1 -1
- package/dist/llm/executor/provider-error.js +14 -0
- package/dist/llm/executor/turn-executor.cjs +4 -0
- package/dist/llm/executor/turn-executor.d.ts +5 -5
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +4 -0
- package/dist/llm/index.cjs +6 -0
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +4 -0
- package/dist/llm/private-address.cjs +88 -0
- package/dist/llm/private-address.d.ts +3 -0
- package/dist/llm/private-address.d.ts.map +1 -0
- package/dist/llm/private-address.js +65 -0
- package/dist/llm/providers/codex-app-server.cjs +3 -3
- package/dist/llm/providers/codex-app-server.js +3 -3
- package/dist/llm/providers/local/errors.cjs +4 -4
- package/dist/llm/providers/local/errors.js +4 -4
- package/dist/llm/safe-download.cjs +159 -0
- package/dist/llm/safe-download.d.ts +21 -0
- package/dist/llm/safe-download.d.ts.map +1 -0
- package/dist/llm/safe-download.js +126 -0
- package/dist/logger/logger.cjs +12 -9
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +12 -9
- package/dist/logger/v2/dexto-logger.cjs +3 -2
- package/dist/logger/v2/dexto-logger.d.ts.map +1 -1
- package/dist/logger/v2/dexto-logger.js +3 -2
- package/dist/mcp/mcp-client.cjs +17 -8
- package/dist/mcp/mcp-client.d.ts +4 -2
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +17 -8
- package/dist/mcp/schemas.cjs +3 -0
- package/dist/mcp/schemas.d.ts +3 -0
- package/dist/mcp/schemas.d.ts.map +1 -1
- package/dist/mcp/schemas.js +3 -0
- package/dist/resources/handlers/filesystem-handler.cjs +7 -6
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.js +7 -6
- package/dist/session/session-manager.cjs +2 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +2 -0
- package/dist/systemPrompt/schemas.d.ts +3 -3
- package/dist/telemetry/decorators.cjs +2 -2
- package/dist/telemetry/decorators.js +2 -2
- package/dist/tools/activity.cjs +0 -16
- package/dist/tools/activity.d.ts +0 -2
- package/dist/tools/activity.d.ts.map +1 -1
- package/dist/tools/activity.js +0 -16
- package/dist/tools/tool-call-metadata.cjs +0 -12
- package/dist/tools/tool-call-metadata.d.ts +0 -3
- package/dist/tools/tool-call-metadata.d.ts.map +1 -1
- package/dist/tools/tool-call-metadata.js +0 -12
- package/dist/tools/tool-manager.cjs +10 -93
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +10 -93
- package/dist/utils/env.cjs +0 -5
- package/dist/utils/env.d.ts +0 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +0 -4
- package/dist/utils/index.cjs +3 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/metadata-address.cjs +138 -0
- package/dist/utils/metadata-address.d.ts +24 -0
- package/dist/utils/metadata-address.d.ts.map +1 -0
- package/dist/utils/metadata-address.js +113 -0
- package/dist/utils/path.cjs +0 -15
- package/dist/utils/path.d.ts +0 -6
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js +0 -14
- package/dist/utils/redactor.cjs +242 -34
- package/dist/utils/redactor.d.ts +15 -0
- package/dist/utils/redactor.d.ts.map +1 -1
- package/dist/utils/redactor.js +238 -34
- package/dist/workspace/index.cjs +7 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +4 -1
- package/dist/workspace/shell-environment.cjs +96 -0
- package/dist/workspace/shell-environment.d.ts +18 -0
- package/dist/workspace/shell-environment.d.ts.map +1 -0
- package/dist/workspace/shell-environment.js +72 -0
- package/dist/workspace/types.d.ts +9 -0
- package/dist/workspace/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/llm/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from './validation.js';
|
|
|
6
6
|
export * from './usage-metadata.js';
|
|
7
7
|
export * from './usage-scope.js';
|
|
8
8
|
export * from './usage-summary.js';
|
|
9
|
+
export { isPrivateAddress } from './private-address.js';
|
|
10
|
+
export { createSafeDownload, type SafeDownloadOptions } from './safe-download.js';
|
|
9
11
|
export type { LlmAuthResolver, LlmRequestAuth, LlmRuntimeAuthOverrides, ResolveLlmRuntimeAuthInput, } from './auth/index.js';
|
|
10
12
|
export * from './services/index.js';
|
|
11
13
|
export * from './executor/index.js';
|
package/dist/llm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,YAAY,EACR,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,0BAA0B,GAC7B,MAAM,iBAAiB,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,OAAO,EACH,iCAAiC,EACjC,qBAAqB,EACrB,8BAA8B,EAC9B,2BAA2B,EAC3B,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,EACtB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GAC3B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACH,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,EACd,iBAAiB,EACjB,KAAK,aAAa,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACnB,KAAK,sBAAsB,GAC9B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACH,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,8BAA8B,EAC9B,KAAK,2BAA2B,GACnC,MAAM,2BAA2B,CAAC;AAGnC,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAClF,YAAY,EACR,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,0BAA0B,GAC7B,MAAM,iBAAiB,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,OAAO,EACH,iCAAiC,EACjC,qBAAqB,EACrB,8BAA8B,EAC9B,2BAA2B,EAC3B,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,EACtB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GAC3B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACH,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,EACd,iBAAiB,EACjB,KAAK,aAAa,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACnB,KAAK,sBAAsB,GAC9B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACH,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,8BAA8B,EAC9B,KAAK,2BAA2B,GACnC,MAAM,2BAA2B,CAAC;AAGnC,cAAc,4BAA4B,CAAC"}
|
package/dist/llm/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export * from "./validation.js";
|
|
|
7
7
|
export * from "./usage-metadata.js";
|
|
8
8
|
export * from "./usage-scope.js";
|
|
9
9
|
export * from "./usage-summary.js";
|
|
10
|
+
import { isPrivateAddress } from "./private-address.js";
|
|
11
|
+
import { createSafeDownload } from "./safe-download.js";
|
|
10
12
|
export * from "./services/index.js";
|
|
11
13
|
export * from "./executor/index.js";
|
|
12
14
|
export * from "./schemas.js";
|
|
@@ -41,6 +43,7 @@ export {
|
|
|
41
43
|
CodexAppServerClient,
|
|
42
44
|
createCodexBaseURL,
|
|
43
45
|
createCodexLanguageModel,
|
|
46
|
+
createSafeDownload,
|
|
44
47
|
getCachedOpenRouterModelsWithInfo,
|
|
45
48
|
getCodexAuthModeLabel,
|
|
46
49
|
getCodexProviderDisplayName,
|
|
@@ -49,6 +52,7 @@ export {
|
|
|
49
52
|
getOpenRouterModelContextLength,
|
|
50
53
|
getOpenRouterModelInfo,
|
|
51
54
|
isCodexBaseURL,
|
|
55
|
+
isPrivateAddress,
|
|
52
56
|
loadLlmRegistryCache,
|
|
53
57
|
lookupOpenRouterModel,
|
|
54
58
|
parseCodexBaseURL,
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var private_address_exports = {};
|
|
20
|
+
__export(private_address_exports, {
|
|
21
|
+
isPrivateAddress: () => isPrivateAddress
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(private_address_exports);
|
|
24
|
+
var import_node_net = require("node:net");
|
|
25
|
+
function isPrivateIpv4Octets(a, b, c) {
|
|
26
|
+
if (a === 0) return true;
|
|
27
|
+
if (a === 10) return true;
|
|
28
|
+
if (a === 127) return true;
|
|
29
|
+
if (a === 169 && b === 254) return true;
|
|
30
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
31
|
+
if (a === 192 && b === 168) return true;
|
|
32
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
33
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
34
|
+
if (a === 192 && b === 0 && c === 2) return true;
|
|
35
|
+
if (a === 198 && b === 51 && c === 100) return true;
|
|
36
|
+
if (a === 203 && b === 0 && c === 113) return true;
|
|
37
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
38
|
+
if (a >= 224) return true;
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
function isPrivateIpv4(ip) {
|
|
42
|
+
const [a, b, c, d, ...rest] = ip.split(".").map((part) => Number(part));
|
|
43
|
+
if (a === void 0 || b === void 0 || c === void 0 || d === void 0) return false;
|
|
44
|
+
if (rest.length > 0 || [a, b, c, d].some((part) => Number.isNaN(part))) return false;
|
|
45
|
+
return isPrivateIpv4Octets(a, b, c);
|
|
46
|
+
}
|
|
47
|
+
function isPrivateEmbeddedIpv4(high, low) {
|
|
48
|
+
return isPrivateIpv4Octets(high >> 8, high & 255, low >> 8);
|
|
49
|
+
}
|
|
50
|
+
function ipv6Groups(ip) {
|
|
51
|
+
const canonical = new URL(`http://[${ip.split("%")[0]}]/`).hostname.slice(1, -1);
|
|
52
|
+
const [head = "", tail] = canonical.split("::");
|
|
53
|
+
const headGroups = head === "" ? [] : head.split(":");
|
|
54
|
+
const tailGroups = tail === void 0 || tail === "" ? [] : tail.split(":");
|
|
55
|
+
const missing = tail === void 0 ? 0 : 8 - headGroups.length - tailGroups.length;
|
|
56
|
+
return [...headGroups, ...Array(missing).fill("0"), ...tailGroups].map(
|
|
57
|
+
(group) => Number.parseInt(group, 16)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function isPrivateIpv6(ip) {
|
|
61
|
+
const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] = ipv6Groups(ip);
|
|
62
|
+
const upperZero = g0 + g1 + g2 + g3 === 0;
|
|
63
|
+
if (upperZero && g4 + g5 + g6 === 0 && (g7 === 0 || g7 === 1)) return true;
|
|
64
|
+
if (upperZero && g4 === 0 && g5 === 65535) return isPrivateEmbeddedIpv4(g6, g7);
|
|
65
|
+
if (upperZero && g4 === 65535 && g5 === 0) return isPrivateEmbeddedIpv4(g6, g7);
|
|
66
|
+
if (upperZero && g4 === 0 && g5 === 0) return isPrivateEmbeddedIpv4(g6, g7);
|
|
67
|
+
if (g0 === 100 && g1 === 65435) {
|
|
68
|
+
if (g2 + g3 + g4 + g5 === 0) return isPrivateEmbeddedIpv4(g6, g7);
|
|
69
|
+
if (g2 === 1) return true;
|
|
70
|
+
}
|
|
71
|
+
if (g0 === 8194) return isPrivateEmbeddedIpv4(g1, g2);
|
|
72
|
+
if ((g0 & 65472) === 65152) return true;
|
|
73
|
+
if ((g0 & 65472) === 65216) return true;
|
|
74
|
+
if ((g0 & 65024) === 64512) return true;
|
|
75
|
+
if ((g0 & 65280) === 65280) return true;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
function isPrivateAddress(ip) {
|
|
79
|
+
const address = ip.startsWith("[") && ip.endsWith("]") ? ip.slice(1, -1) : ip;
|
|
80
|
+
const version = (0, import_node_net.isIP)(address.split("%")[0] ?? address);
|
|
81
|
+
if (version === 4) return isPrivateIpv4(address);
|
|
82
|
+
if (version === 6) return isPrivateIpv6(address);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
isPrivateAddress
|
|
88
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-address.d.ts","sourceRoot":"","sources":["../../src/llm/private-address.ts"],"names":[],"mappings":"AA2EA,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAMpD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import "../chunk-C6A6W6XS.js";
|
|
2
|
+
import { isIP } from "node:net";
|
|
3
|
+
function isPrivateIpv4Octets(a, b, c) {
|
|
4
|
+
if (a === 0) return true;
|
|
5
|
+
if (a === 10) return true;
|
|
6
|
+
if (a === 127) return true;
|
|
7
|
+
if (a === 169 && b === 254) return true;
|
|
8
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
9
|
+
if (a === 192 && b === 168) return true;
|
|
10
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
11
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
12
|
+
if (a === 192 && b === 0 && c === 2) return true;
|
|
13
|
+
if (a === 198 && b === 51 && c === 100) return true;
|
|
14
|
+
if (a === 203 && b === 0 && c === 113) return true;
|
|
15
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
16
|
+
if (a >= 224) return true;
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
function isPrivateIpv4(ip) {
|
|
20
|
+
const [a, b, c, d, ...rest] = ip.split(".").map((part) => Number(part));
|
|
21
|
+
if (a === void 0 || b === void 0 || c === void 0 || d === void 0) return false;
|
|
22
|
+
if (rest.length > 0 || [a, b, c, d].some((part) => Number.isNaN(part))) return false;
|
|
23
|
+
return isPrivateIpv4Octets(a, b, c);
|
|
24
|
+
}
|
|
25
|
+
function isPrivateEmbeddedIpv4(high, low) {
|
|
26
|
+
return isPrivateIpv4Octets(high >> 8, high & 255, low >> 8);
|
|
27
|
+
}
|
|
28
|
+
function ipv6Groups(ip) {
|
|
29
|
+
const canonical = new URL(`http://[${ip.split("%")[0]}]/`).hostname.slice(1, -1);
|
|
30
|
+
const [head = "", tail] = canonical.split("::");
|
|
31
|
+
const headGroups = head === "" ? [] : head.split(":");
|
|
32
|
+
const tailGroups = tail === void 0 || tail === "" ? [] : tail.split(":");
|
|
33
|
+
const missing = tail === void 0 ? 0 : 8 - headGroups.length - tailGroups.length;
|
|
34
|
+
return [...headGroups, ...Array(missing).fill("0"), ...tailGroups].map(
|
|
35
|
+
(group) => Number.parseInt(group, 16)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
function isPrivateIpv6(ip) {
|
|
39
|
+
const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] = ipv6Groups(ip);
|
|
40
|
+
const upperZero = g0 + g1 + g2 + g3 === 0;
|
|
41
|
+
if (upperZero && g4 + g5 + g6 === 0 && (g7 === 0 || g7 === 1)) return true;
|
|
42
|
+
if (upperZero && g4 === 0 && g5 === 65535) return isPrivateEmbeddedIpv4(g6, g7);
|
|
43
|
+
if (upperZero && g4 === 65535 && g5 === 0) return isPrivateEmbeddedIpv4(g6, g7);
|
|
44
|
+
if (upperZero && g4 === 0 && g5 === 0) return isPrivateEmbeddedIpv4(g6, g7);
|
|
45
|
+
if (g0 === 100 && g1 === 65435) {
|
|
46
|
+
if (g2 + g3 + g4 + g5 === 0) return isPrivateEmbeddedIpv4(g6, g7);
|
|
47
|
+
if (g2 === 1) return true;
|
|
48
|
+
}
|
|
49
|
+
if (g0 === 8194) return isPrivateEmbeddedIpv4(g1, g2);
|
|
50
|
+
if ((g0 & 65472) === 65152) return true;
|
|
51
|
+
if ((g0 & 65472) === 65216) return true;
|
|
52
|
+
if ((g0 & 65024) === 64512) return true;
|
|
53
|
+
if ((g0 & 65280) === 65280) return true;
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
function isPrivateAddress(ip) {
|
|
57
|
+
const address = ip.startsWith("[") && ip.endsWith("]") ? ip.slice(1, -1) : ip;
|
|
58
|
+
const version = isIP(address.split("%")[0] ?? address);
|
|
59
|
+
if (version === 4) return isPrivateIpv4(address);
|
|
60
|
+
if (version === 6) return isPrivateIpv6(address);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
isPrivateAddress
|
|
65
|
+
};
|
|
@@ -612,7 +612,7 @@ function enforceAuthMode(authMode, accountState) {
|
|
|
612
612
|
if (accountState.requiresOpenaiAuth) {
|
|
613
613
|
throw import_errors.LLMError.missingConfig(
|
|
614
614
|
"openai-compatible",
|
|
615
|
-
"Codex authentication (run `codex login`
|
|
615
|
+
"Codex authentication (run `codex login`)"
|
|
616
616
|
);
|
|
617
617
|
}
|
|
618
618
|
return;
|
|
@@ -623,13 +623,13 @@ function enforceAuthMode(authMode, accountState) {
|
|
|
623
623
|
if (authMode === "chatgpt" && accountState.account.type !== "chatgpt") {
|
|
624
624
|
throw import_errors.LLMError.missingConfig(
|
|
625
625
|
"openai-compatible",
|
|
626
|
-
"a ChatGPT-backed Codex login (run `codex logout` and sign in with ChatGPT
|
|
626
|
+
"a ChatGPT-backed Codex login (run `codex logout` and sign in with ChatGPT)"
|
|
627
627
|
);
|
|
628
628
|
}
|
|
629
629
|
if (authMode === "apikey" && accountState.account.type !== "apiKey") {
|
|
630
630
|
throw import_errors.LLMError.missingConfig(
|
|
631
631
|
"openai-compatible",
|
|
632
|
-
"an API key-backed Codex login (run `codex login --with-api-key`
|
|
632
|
+
"an API key-backed Codex login (run `codex login --with-api-key`)"
|
|
633
633
|
);
|
|
634
634
|
}
|
|
635
635
|
}
|
|
@@ -579,7 +579,7 @@ function enforceAuthMode(authMode, accountState) {
|
|
|
579
579
|
if (accountState.requiresOpenaiAuth) {
|
|
580
580
|
throw LLMError.missingConfig(
|
|
581
581
|
"openai-compatible",
|
|
582
|
-
"Codex authentication (run `codex login`
|
|
582
|
+
"Codex authentication (run `codex login`)"
|
|
583
583
|
);
|
|
584
584
|
}
|
|
585
585
|
return;
|
|
@@ -590,13 +590,13 @@ function enforceAuthMode(authMode, accountState) {
|
|
|
590
590
|
if (authMode === "chatgpt" && accountState.account.type !== "chatgpt") {
|
|
591
591
|
throw LLMError.missingConfig(
|
|
592
592
|
"openai-compatible",
|
|
593
|
-
"a ChatGPT-backed Codex login (run `codex logout` and sign in with ChatGPT
|
|
593
|
+
"a ChatGPT-backed Codex login (run `codex logout` and sign in with ChatGPT)"
|
|
594
594
|
);
|
|
595
595
|
}
|
|
596
596
|
if (authMode === "apikey" && accountState.account.type !== "apiKey") {
|
|
597
597
|
throw LLMError.missingConfig(
|
|
598
598
|
"openai-compatible",
|
|
599
|
-
"an API key-backed Codex login (run `codex login --with-api-key`
|
|
599
|
+
"an API key-backed Codex login (run `codex login --with-api-key`)"
|
|
600
600
|
);
|
|
601
601
|
}
|
|
602
602
|
}
|
|
@@ -32,9 +32,9 @@ const LocalModelError = {
|
|
|
32
32
|
import_error_codes.LocalModelErrorCode.NODE_LLAMA_NOT_INSTALLED,
|
|
33
33
|
SCOPE,
|
|
34
34
|
import_types.ErrorType.NOT_FOUND,
|
|
35
|
-
|
|
35
|
+
"node-llama-cpp is not installed. Choose a local model with /model in the interactive CLI to install it.",
|
|
36
36
|
{},
|
|
37
|
-
|
|
37
|
+
"Choose a local model with /model in the interactive CLI to install local model support"
|
|
38
38
|
);
|
|
39
39
|
},
|
|
40
40
|
nodeLlamaInstallFailed(error) {
|
|
@@ -118,7 +118,7 @@ const LocalModelError = {
|
|
|
118
118
|
import_types.ErrorType.NOT_FOUND,
|
|
119
119
|
`Model '${modelId}' not found in local model registry`,
|
|
120
120
|
{ modelId },
|
|
121
|
-
|
|
121
|
+
"Use /model in the interactive CLI to see available local models"
|
|
122
122
|
);
|
|
123
123
|
},
|
|
124
124
|
modelNotDownloaded(modelId) {
|
|
@@ -128,7 +128,7 @@ const LocalModelError = {
|
|
|
128
128
|
import_types.ErrorType.NOT_FOUND,
|
|
129
129
|
`Model '${modelId}' is not downloaded. Download it first.`,
|
|
130
130
|
{ modelId },
|
|
131
|
-
|
|
131
|
+
"Use /model in the interactive CLI to download local models"
|
|
132
132
|
);
|
|
133
133
|
},
|
|
134
134
|
modelLoadFailed(modelId, error) {
|
|
@@ -10,9 +10,9 @@ const LocalModelError = {
|
|
|
10
10
|
LocalModelErrorCode.NODE_LLAMA_NOT_INSTALLED,
|
|
11
11
|
SCOPE,
|
|
12
12
|
ErrorType.NOT_FOUND,
|
|
13
|
-
|
|
13
|
+
"node-llama-cpp is not installed. Choose a local model with /model in the interactive CLI to install it.",
|
|
14
14
|
{},
|
|
15
|
-
|
|
15
|
+
"Choose a local model with /model in the interactive CLI to install local model support"
|
|
16
16
|
);
|
|
17
17
|
},
|
|
18
18
|
nodeLlamaInstallFailed(error) {
|
|
@@ -96,7 +96,7 @@ const LocalModelError = {
|
|
|
96
96
|
ErrorType.NOT_FOUND,
|
|
97
97
|
`Model '${modelId}' not found in local model registry`,
|
|
98
98
|
{ modelId },
|
|
99
|
-
|
|
99
|
+
"Use /model in the interactive CLI to see available local models"
|
|
100
100
|
);
|
|
101
101
|
},
|
|
102
102
|
modelNotDownloaded(modelId) {
|
|
@@ -106,7 +106,7 @@ const LocalModelError = {
|
|
|
106
106
|
ErrorType.NOT_FOUND,
|
|
107
107
|
`Model '${modelId}' is not downloaded. Download it first.`,
|
|
108
108
|
{ modelId },
|
|
109
|
-
|
|
109
|
+
"Use /model in the interactive CLI to download local models"
|
|
110
110
|
);
|
|
111
111
|
},
|
|
112
112
|
modelLoadFailed(modelId, error) {
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var safe_download_exports = {};
|
|
30
|
+
__export(safe_download_exports, {
|
|
31
|
+
createSafeDownload: () => createSafeDownload
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(safe_download_exports);
|
|
34
|
+
var import_node_dns = require("node:dns");
|
|
35
|
+
var import_node_http = __toESM(require("node:http"), 1);
|
|
36
|
+
var import_node_https = __toESM(require("node:https"), 1);
|
|
37
|
+
var import_ai = require("ai");
|
|
38
|
+
var import_metadata_address = require("../utils/metadata-address.js");
|
|
39
|
+
var import_private_address = require("./private-address.js");
|
|
40
|
+
const MAX_DOWNLOAD_BYTES = 100 * 1024 * 1024;
|
|
41
|
+
const MAX_REDIRECTS = 10;
|
|
42
|
+
const DOWNLOAD_TIMEOUT_MS = 6e4;
|
|
43
|
+
const DOWNLOAD_HEADERS = { "user-agent": "@dexto/core", accept: "*/*" };
|
|
44
|
+
function blockedDownloadMessage(hostname) {
|
|
45
|
+
return `Download from ${hostname} is blocked`;
|
|
46
|
+
}
|
|
47
|
+
function createCheckedLookup(dnsLookup, isBlockedAddress) {
|
|
48
|
+
return (hostname, options, callback) => {
|
|
49
|
+
dnsLookup(hostname, { all: true, verbatim: true }).then(
|
|
50
|
+
(records) => {
|
|
51
|
+
const blocked = records.find(
|
|
52
|
+
(record) => (0, import_metadata_address.isMetadataHost)(record.address) || isBlockedAddress(record.address)
|
|
53
|
+
);
|
|
54
|
+
if (blocked) {
|
|
55
|
+
callback(new Error(blockedDownloadMessage(hostname)), []);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const [first] = records;
|
|
59
|
+
if (!first) {
|
|
60
|
+
callback(new Error(`Failed to resolve ${hostname}`), []);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (options.all) {
|
|
64
|
+
callback(null, records);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
callback(null, first.address, first.family);
|
|
68
|
+
},
|
|
69
|
+
(error) => callback(error, [])
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function requestOnce(url, lookup, signal) {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const request = (url.protocol === "https:" ? import_node_https.default : import_node_http.default).request(
|
|
76
|
+
url,
|
|
77
|
+
{ method: "GET", lookup, signal, headers: DOWNLOAD_HEADERS },
|
|
78
|
+
resolve
|
|
79
|
+
);
|
|
80
|
+
request.on("error", reject);
|
|
81
|
+
request.end();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async function readLimited(response, url) {
|
|
85
|
+
const chunks = [];
|
|
86
|
+
let total = 0;
|
|
87
|
+
for await (const chunk of response) {
|
|
88
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
89
|
+
total += buffer.length;
|
|
90
|
+
if (total > MAX_DOWNLOAD_BYTES) {
|
|
91
|
+
response.destroy();
|
|
92
|
+
throw new import_ai.DownloadError({
|
|
93
|
+
url,
|
|
94
|
+
message: `Download of ${url} exceeded maximum size of ${MAX_DOWNLOAD_BYTES} bytes.`
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
chunks.push(buffer);
|
|
98
|
+
}
|
|
99
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
100
|
+
}
|
|
101
|
+
function createSafeDownload(options = {}) {
|
|
102
|
+
const isBlockedAddress = options.isBlockedAddress ?? import_private_address.isPrivateAddress;
|
|
103
|
+
const lookup = createCheckedLookup(
|
|
104
|
+
options.dnsLookup ?? ((hostname, lookupOptions) => import_node_dns.promises.lookup(hostname, lookupOptions)),
|
|
105
|
+
isBlockedAddress
|
|
106
|
+
);
|
|
107
|
+
async function download(first) {
|
|
108
|
+
const signal = AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS);
|
|
109
|
+
let url = first;
|
|
110
|
+
for (let redirects = 0; redirects <= MAX_REDIRECTS; redirects++) {
|
|
111
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
112
|
+
throw new import_ai.DownloadError({
|
|
113
|
+
url: url.toString(),
|
|
114
|
+
message: `URL scheme must be http or https, got ${url.protocol}`
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if ((0, import_metadata_address.isMetadataHost)(url.hostname) || isBlockedAddress(url.hostname)) {
|
|
118
|
+
throw new import_ai.DownloadError({
|
|
119
|
+
url: url.toString(),
|
|
120
|
+
message: blockedDownloadMessage(url.hostname)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const response = await requestOnce(url, lookup, signal).catch((cause) => {
|
|
124
|
+
throw new import_ai.DownloadError({ url: url.toString(), cause });
|
|
125
|
+
});
|
|
126
|
+
const location = response.headers.location;
|
|
127
|
+
const status = response.statusCode ?? 0;
|
|
128
|
+
if (status >= 300 && status < 400 && location) {
|
|
129
|
+
response.resume();
|
|
130
|
+
url = new URL(location, url);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (status < 200 || status >= 300) {
|
|
134
|
+
response.resume();
|
|
135
|
+
throw new import_ai.DownloadError({
|
|
136
|
+
url: url.toString(),
|
|
137
|
+
statusCode: status,
|
|
138
|
+
statusText: response.statusMessage ?? ""
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const data = await readLimited(response, url.toString());
|
|
142
|
+
const contentType = response.headers["content-type"]?.split(";")[0]?.trim();
|
|
143
|
+
return { data, mediaType: contentType || void 0 };
|
|
144
|
+
}
|
|
145
|
+
throw new import_ai.DownloadError({
|
|
146
|
+
url: first.toString(),
|
|
147
|
+
message: `Too many redirects (max ${MAX_REDIRECTS})`
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return (requests) => Promise.all(
|
|
151
|
+
requests.map(
|
|
152
|
+
({ url, isUrlSupportedByModel }) => isUrlSupportedByModel ? null : download(url)
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
+
0 && (module.exports = {
|
|
158
|
+
createSafeDownload
|
|
159
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type LookupAddress } from 'node:dns';
|
|
2
|
+
import { type Experimental_DownloadFunction as DownloadFunction } from 'ai';
|
|
3
|
+
type DnsLookup = (hostname: string, options: {
|
|
4
|
+
all: true;
|
|
5
|
+
verbatim: true;
|
|
6
|
+
}) => Promise<LookupAddress[]>;
|
|
7
|
+
export interface SafeDownloadOptions {
|
|
8
|
+
/** Resolves a host name to every address it has. Replaced in tests. */
|
|
9
|
+
dnsLookup?: DnsLookup;
|
|
10
|
+
/** Decides which resolved addresses are refused. Replaced in tests. */
|
|
11
|
+
isBlockedAddress?: (address: string) => boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The AI SDK downloads the URLs of images and files in a prompt itself, and its own check looks
|
|
15
|
+
* at the host name text only, so a name that resolves to a private address is fetched. This
|
|
16
|
+
* downloader resolves the host, refuses private answers, connects to the address it checked and
|
|
17
|
+
* checks every redirect the same way. URLs the model fetches itself are left to the model.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSafeDownload(options?: SafeDownloadOptions): DownloadFunction;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=safe-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-download.d.ts","sourceRoot":"","sources":["../../src/llm/safe-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAsB,MAAM,UAAU,CAAC;AAGnF,OAAO,EAAiB,KAAK,6BAA6B,IAAI,gBAAgB,EAAE,MAAM,IAAI,CAAC;AAU3F,KAAK,SAAS,GAAG,CACb,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;IAAE,GAAG,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAA;CAAE,KACrC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;AAE9B,MAAM,WAAW,mBAAmB;IAChC,uEAAuE;IACvE,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;CACnD;AAuFD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,gBAAgB,CA0DtF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import "../chunk-C6A6W6XS.js";
|
|
2
|
+
import { promises as dns } from "node:dns";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import https from "node:https";
|
|
5
|
+
import { DownloadError } from "ai";
|
|
6
|
+
import { isMetadataHost } from "../utils/metadata-address.js";
|
|
7
|
+
import { isPrivateAddress } from "./private-address.js";
|
|
8
|
+
const MAX_DOWNLOAD_BYTES = 100 * 1024 * 1024;
|
|
9
|
+
const MAX_REDIRECTS = 10;
|
|
10
|
+
const DOWNLOAD_TIMEOUT_MS = 6e4;
|
|
11
|
+
const DOWNLOAD_HEADERS = { "user-agent": "@dexto/core", accept: "*/*" };
|
|
12
|
+
function blockedDownloadMessage(hostname) {
|
|
13
|
+
return `Download from ${hostname} is blocked`;
|
|
14
|
+
}
|
|
15
|
+
function createCheckedLookup(dnsLookup, isBlockedAddress) {
|
|
16
|
+
return (hostname, options, callback) => {
|
|
17
|
+
dnsLookup(hostname, { all: true, verbatim: true }).then(
|
|
18
|
+
(records) => {
|
|
19
|
+
const blocked = records.find(
|
|
20
|
+
(record) => isMetadataHost(record.address) || isBlockedAddress(record.address)
|
|
21
|
+
);
|
|
22
|
+
if (blocked) {
|
|
23
|
+
callback(new Error(blockedDownloadMessage(hostname)), []);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const [first] = records;
|
|
27
|
+
if (!first) {
|
|
28
|
+
callback(new Error(`Failed to resolve ${hostname}`), []);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (options.all) {
|
|
32
|
+
callback(null, records);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
callback(null, first.address, first.family);
|
|
36
|
+
},
|
|
37
|
+
(error) => callback(error, [])
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function requestOnce(url, lookup, signal) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const request = (url.protocol === "https:" ? https : http).request(
|
|
44
|
+
url,
|
|
45
|
+
{ method: "GET", lookup, signal, headers: DOWNLOAD_HEADERS },
|
|
46
|
+
resolve
|
|
47
|
+
);
|
|
48
|
+
request.on("error", reject);
|
|
49
|
+
request.end();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function readLimited(response, url) {
|
|
53
|
+
const chunks = [];
|
|
54
|
+
let total = 0;
|
|
55
|
+
for await (const chunk of response) {
|
|
56
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
57
|
+
total += buffer.length;
|
|
58
|
+
if (total > MAX_DOWNLOAD_BYTES) {
|
|
59
|
+
response.destroy();
|
|
60
|
+
throw new DownloadError({
|
|
61
|
+
url,
|
|
62
|
+
message: `Download of ${url} exceeded maximum size of ${MAX_DOWNLOAD_BYTES} bytes.`
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
chunks.push(buffer);
|
|
66
|
+
}
|
|
67
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
68
|
+
}
|
|
69
|
+
function createSafeDownload(options = {}) {
|
|
70
|
+
const isBlockedAddress = options.isBlockedAddress ?? isPrivateAddress;
|
|
71
|
+
const lookup = createCheckedLookup(
|
|
72
|
+
options.dnsLookup ?? ((hostname, lookupOptions) => dns.lookup(hostname, lookupOptions)),
|
|
73
|
+
isBlockedAddress
|
|
74
|
+
);
|
|
75
|
+
async function download(first) {
|
|
76
|
+
const signal = AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS);
|
|
77
|
+
let url = first;
|
|
78
|
+
for (let redirects = 0; redirects <= MAX_REDIRECTS; redirects++) {
|
|
79
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
80
|
+
throw new DownloadError({
|
|
81
|
+
url: url.toString(),
|
|
82
|
+
message: `URL scheme must be http or https, got ${url.protocol}`
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (isMetadataHost(url.hostname) || isBlockedAddress(url.hostname)) {
|
|
86
|
+
throw new DownloadError({
|
|
87
|
+
url: url.toString(),
|
|
88
|
+
message: blockedDownloadMessage(url.hostname)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const response = await requestOnce(url, lookup, signal).catch((cause) => {
|
|
92
|
+
throw new DownloadError({ url: url.toString(), cause });
|
|
93
|
+
});
|
|
94
|
+
const location = response.headers.location;
|
|
95
|
+
const status = response.statusCode ?? 0;
|
|
96
|
+
if (status >= 300 && status < 400 && location) {
|
|
97
|
+
response.resume();
|
|
98
|
+
url = new URL(location, url);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (status < 200 || status >= 300) {
|
|
102
|
+
response.resume();
|
|
103
|
+
throw new DownloadError({
|
|
104
|
+
url: url.toString(),
|
|
105
|
+
statusCode: status,
|
|
106
|
+
statusText: response.statusMessage ?? ""
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const data = await readLimited(response, url.toString());
|
|
110
|
+
const contentType = response.headers["content-type"]?.split(";")[0]?.trim();
|
|
111
|
+
return { data, mediaType: contentType || void 0 };
|
|
112
|
+
}
|
|
113
|
+
throw new DownloadError({
|
|
114
|
+
url: first.toString(),
|
|
115
|
+
message: `Too many redirects (max ${MAX_REDIRECTS})`
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return (requests) => Promise.all(
|
|
119
|
+
requests.map(
|
|
120
|
+
({ url, isUrlSupportedByModel }) => isUrlSupportedByModel ? null : download(url)
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
createSafeDownload
|
|
126
|
+
};
|