@ai-sdk/code-mode 1.0.20 → 1.0.22
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/README.md +1 -1
- package/dist/continuation-capability.js +5 -0
- package/dist/continuation-capability.js.map +1 -1
- package/dist/errors.js +1 -136
- package/dist/errors.js.map +1 -1
- package/dist/host-interrupt.js +2 -14
- package/dist/host-interrupt.js.map +1 -1
- package/dist/index.d.ts +14 -44
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interrupt-continuation.js +3 -8
- package/dist/interrupt-continuation.js.map +1 -1
- package/dist/run-code-mode.js +543 -2
- package/dist/run-code-mode.js.map +1 -1
- package/dist/tool-invocation.js +9 -23
- package/dist/tool-invocation.js.map +1 -1
- package/dist/utils/serialization.js +4 -0
- package/dist/utils/serialization.js.map +1 -1
- package/package.json +8 -7
- package/src/continuation-capability.ts +18 -0
- package/src/errors.ts +0 -190
- package/src/host-interrupt.ts +2 -31
- package/src/index.ts +1 -1
- package/src/interrupt-continuation.ts +13 -15
- package/src/run-code-mode.ts +706 -3
- package/src/tool-invocation.ts +9 -23
- package/src/types.ts +38 -68
- package/src/utils/serialization.ts +4 -0
- package/dist/runtime/guest-sources.js +0 -350
- package/dist/runtime/guest-sources.js.map +0 -1
- package/dist/runtime/manager.js +0 -794
- package/dist/runtime/manager.js.map +0 -1
- package/dist/runtime/max-workers.js +0 -40
- package/dist/runtime/max-workers.js.map +0 -1
- package/dist/runtime/protocol.js +0 -1
- package/dist/runtime/protocol.js.map +0 -1
- package/dist/runtime/worker-source.d.ts +0 -11
- package/dist/runtime/worker-source.js +0 -2
- package/dist/utils/options.js +0 -76
- package/dist/utils/options.js.map +0 -1
- package/dist/utils/source-cache.js +0 -77
- package/dist/utils/source-cache.js.map +0 -1
- package/src/runtime/guest-sources.ts +0 -351
- package/src/runtime/manager.ts +0 -963
- package/src/runtime/max-workers.ts +0 -65
- package/src/runtime/protocol.ts +0 -74
- package/src/runtime/worker-source.ts +0 -10
- package/src/runtime/worker.ts +0 -607
- package/src/utils/options.ts +0 -83
- package/src/utils/source-cache.ts +0 -91
package/dist/utils/options.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
2
|
-
const DEFAULT_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
3
|
-
const DEFAULT_STACK_LIMIT_BYTES = 2 * 1024 * 1024;
|
|
4
|
-
const DEFAULT_MAX_RESULT_BYTES = 1024 * 1024;
|
|
5
|
-
const DEFAULT_MAX_CONSOLE_OUTPUT_BYTES = 64 * 1024;
|
|
6
|
-
const DEFAULT_MAX_SOURCE_BYTES = 256 * 1024;
|
|
7
|
-
const DEFAULT_MAX_TOOL_INPUT_BYTES = 1024 * 1024;
|
|
8
|
-
const DEFAULT_MAX_TOOL_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
9
|
-
const DEFAULT_MAX_BRIDGE_REQUESTS = 256;
|
|
10
|
-
const DEFAULT_MAX_IN_FLIGHT_BRIDGE_REQUESTS = 32;
|
|
11
|
-
function normalizeOptions(options = {}) {
|
|
12
|
-
const executionPolicy = options.executionPolicy ?? {};
|
|
13
|
-
return {
|
|
14
|
-
timeoutMs: positiveInteger(
|
|
15
|
-
executionPolicy.timeoutMs,
|
|
16
|
-
DEFAULT_TIMEOUT_MS,
|
|
17
|
-
"executionPolicy.timeoutMs"
|
|
18
|
-
),
|
|
19
|
-
memoryLimitBytes: positiveInteger(
|
|
20
|
-
executionPolicy.memoryLimitBytes,
|
|
21
|
-
DEFAULT_MEMORY_LIMIT_BYTES,
|
|
22
|
-
"executionPolicy.memoryLimitBytes"
|
|
23
|
-
),
|
|
24
|
-
maxStackSizeBytes: positiveInteger(
|
|
25
|
-
executionPolicy.maxStackSizeBytes,
|
|
26
|
-
DEFAULT_STACK_LIMIT_BYTES,
|
|
27
|
-
"executionPolicy.maxStackSizeBytes"
|
|
28
|
-
),
|
|
29
|
-
maxResultBytes: positiveInteger(
|
|
30
|
-
executionPolicy.maxResultBytes,
|
|
31
|
-
DEFAULT_MAX_RESULT_BYTES,
|
|
32
|
-
"executionPolicy.maxResultBytes"
|
|
33
|
-
),
|
|
34
|
-
maxConsoleOutputBytes: positiveInteger(
|
|
35
|
-
executionPolicy.maxConsoleOutputBytes,
|
|
36
|
-
DEFAULT_MAX_CONSOLE_OUTPUT_BYTES,
|
|
37
|
-
"executionPolicy.maxConsoleOutputBytes"
|
|
38
|
-
),
|
|
39
|
-
maxSourceBytes: positiveInteger(
|
|
40
|
-
executionPolicy.maxSourceBytes,
|
|
41
|
-
DEFAULT_MAX_SOURCE_BYTES,
|
|
42
|
-
"executionPolicy.maxSourceBytes"
|
|
43
|
-
),
|
|
44
|
-
maxToolInputBytes: positiveInteger(
|
|
45
|
-
executionPolicy.maxToolInputBytes,
|
|
46
|
-
DEFAULT_MAX_TOOL_INPUT_BYTES,
|
|
47
|
-
"executionPolicy.maxToolInputBytes"
|
|
48
|
-
),
|
|
49
|
-
maxToolOutputBytes: positiveInteger(
|
|
50
|
-
executionPolicy.maxToolOutputBytes,
|
|
51
|
-
DEFAULT_MAX_TOOL_OUTPUT_BYTES,
|
|
52
|
-
"executionPolicy.maxToolOutputBytes"
|
|
53
|
-
),
|
|
54
|
-
maxBridgeRequests: positiveInteger(
|
|
55
|
-
executionPolicy.maxBridgeRequests,
|
|
56
|
-
DEFAULT_MAX_BRIDGE_REQUESTS,
|
|
57
|
-
"executionPolicy.maxBridgeRequests"
|
|
58
|
-
),
|
|
59
|
-
maxInFlightBridgeRequests: positiveInteger(
|
|
60
|
-
executionPolicy.maxInFlightBridgeRequests,
|
|
61
|
-
DEFAULT_MAX_IN_FLIGHT_BRIDGE_REQUESTS,
|
|
62
|
-
"executionPolicy.maxInFlightBridgeRequests"
|
|
63
|
-
)
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function positiveInteger(value, fallback, path) {
|
|
67
|
-
const resolved = value ?? fallback;
|
|
68
|
-
if (!Number.isInteger(resolved) || resolved <= 0) {
|
|
69
|
-
throw new TypeError(`${path} must be a positive integer.`);
|
|
70
|
-
}
|
|
71
|
-
return resolved;
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
normalizeOptions
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/options.ts"],"sourcesContent":["import type { CodeModeOptions, NormalizedCodeModeOptions } from '../types.js';\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst DEFAULT_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;\nconst DEFAULT_STACK_LIMIT_BYTES = 2 * 1024 * 1024;\nconst DEFAULT_MAX_RESULT_BYTES = 1024 * 1024;\nconst DEFAULT_MAX_CONSOLE_OUTPUT_BYTES = 64 * 1024;\nconst DEFAULT_MAX_SOURCE_BYTES = 256 * 1024;\nconst DEFAULT_MAX_TOOL_INPUT_BYTES = 1024 * 1024;\nconst DEFAULT_MAX_TOOL_OUTPUT_BYTES = 4 * 1024 * 1024;\nconst DEFAULT_MAX_BRIDGE_REQUESTS = 256;\nconst DEFAULT_MAX_IN_FLIGHT_BRIDGE_REQUESTS = 32;\n\nexport function normalizeOptions(\n options: CodeModeOptions = {},\n): NormalizedCodeModeOptions {\n const executionPolicy = options.executionPolicy ?? {};\n\n return {\n timeoutMs: positiveInteger(\n executionPolicy.timeoutMs,\n DEFAULT_TIMEOUT_MS,\n 'executionPolicy.timeoutMs',\n ),\n memoryLimitBytes: positiveInteger(\n executionPolicy.memoryLimitBytes,\n DEFAULT_MEMORY_LIMIT_BYTES,\n 'executionPolicy.memoryLimitBytes',\n ),\n maxStackSizeBytes: positiveInteger(\n executionPolicy.maxStackSizeBytes,\n DEFAULT_STACK_LIMIT_BYTES,\n 'executionPolicy.maxStackSizeBytes',\n ),\n maxResultBytes: positiveInteger(\n executionPolicy.maxResultBytes,\n DEFAULT_MAX_RESULT_BYTES,\n 'executionPolicy.maxResultBytes',\n ),\n maxConsoleOutputBytes: positiveInteger(\n executionPolicy.maxConsoleOutputBytes,\n DEFAULT_MAX_CONSOLE_OUTPUT_BYTES,\n 'executionPolicy.maxConsoleOutputBytes',\n ),\n maxSourceBytes: positiveInteger(\n executionPolicy.maxSourceBytes,\n DEFAULT_MAX_SOURCE_BYTES,\n 'executionPolicy.maxSourceBytes',\n ),\n maxToolInputBytes: positiveInteger(\n executionPolicy.maxToolInputBytes,\n DEFAULT_MAX_TOOL_INPUT_BYTES,\n 'executionPolicy.maxToolInputBytes',\n ),\n maxToolOutputBytes: positiveInteger(\n executionPolicy.maxToolOutputBytes,\n DEFAULT_MAX_TOOL_OUTPUT_BYTES,\n 'executionPolicy.maxToolOutputBytes',\n ),\n maxBridgeRequests: positiveInteger(\n executionPolicy.maxBridgeRequests,\n DEFAULT_MAX_BRIDGE_REQUESTS,\n 'executionPolicy.maxBridgeRequests',\n ),\n maxInFlightBridgeRequests: positiveInteger(\n executionPolicy.maxInFlightBridgeRequests,\n DEFAULT_MAX_IN_FLIGHT_BRIDGE_REQUESTS,\n 'executionPolicy.maxInFlightBridgeRequests',\n ),\n };\n}\n\nfunction positiveInteger(\n value: number | undefined,\n fallback: number,\n path: string,\n): number {\n const resolved = value ?? fallback;\n if (!Number.isInteger(resolved) || resolved <= 0) {\n throw new TypeError(`${path} must be a positive integer.`);\n }\n return resolved;\n}\n"],"mappings":"AAEA,MAAM,qBAAqB;AAC3B,MAAM,6BAA6B,KAAK,OAAO;AAC/C,MAAM,4BAA4B,IAAI,OAAO;AAC7C,MAAM,2BAA2B,OAAO;AACxC,MAAM,mCAAmC,KAAK;AAC9C,MAAM,2BAA2B,MAAM;AACvC,MAAM,+BAA+B,OAAO;AAC5C,MAAM,gCAAgC,IAAI,OAAO;AACjD,MAAM,8BAA8B;AACpC,MAAM,wCAAwC;AAEvC,SAAS,iBACd,UAA2B,CAAC,GACD;AAC3B,QAAM,kBAAkB,QAAQ,mBAAmB,CAAC;AAEpD,SAAO;AAAA,IACL,WAAW;AAAA,MACT,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,kBAAkB;AAAA,MAChB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,gBAAgB;AAAA,MACd,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,uBAAuB;AAAA,MACrB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,gBAAgB;AAAA,MACd,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,oBAAoB;AAAA,MAClB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,IACA,2BAA2B;AAAA,MACzB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,gBACP,OACA,UACA,MACQ;AACR,QAAM,WAAW,SAAS;AAC1B,MAAI,CAAC,OAAO,UAAU,QAAQ,KAAK,YAAY,GAAG;AAChD,UAAM,IAAI,UAAU,GAAG,IAAI,8BAA8B;AAAA,EAC3D;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { stripTypeScriptTypes } from "node:module";
|
|
3
|
-
import { CodeModeSourceTooLargeError } from "../errors.js";
|
|
4
|
-
const MAX_CACHE_ENTRIES = 256;
|
|
5
|
-
const MAX_CACHE_BYTES = 4 * 1024 * 1024;
|
|
6
|
-
const MAX_CACHE_ENTRY_BYTES = 64 * 1024;
|
|
7
|
-
const transformedSourceCache = /* @__PURE__ */ new Map();
|
|
8
|
-
let transformedSourceCacheBytes = 0;
|
|
9
|
-
function assertSourceSize(source, maxSourceBytes) {
|
|
10
|
-
const bytes = byteLength(source);
|
|
11
|
-
if (bytes > maxSourceBytes) {
|
|
12
|
-
throw new CodeModeSourceTooLargeError(bytes, maxSourceBytes);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function transformSource(source) {
|
|
16
|
-
const hash = createHash("sha256").update("strip:").update(source).digest("hex");
|
|
17
|
-
const cached = transformedSourceCache.get(hash);
|
|
18
|
-
if (cached !== void 0) {
|
|
19
|
-
transformedSourceCache.delete(hash);
|
|
20
|
-
transformedSourceCache.set(hash, cached);
|
|
21
|
-
return cached.source;
|
|
22
|
-
}
|
|
23
|
-
const transformed = stripSnippetTypes(source);
|
|
24
|
-
const transformedBytes = byteLength(transformed);
|
|
25
|
-
if (transformedBytes <= MAX_CACHE_ENTRY_BYTES) {
|
|
26
|
-
transformedSourceCache.set(hash, {
|
|
27
|
-
source: transformed,
|
|
28
|
-
bytes: transformedBytes
|
|
29
|
-
});
|
|
30
|
-
transformedSourceCacheBytes += transformedBytes;
|
|
31
|
-
evictTransformedSourceCache();
|
|
32
|
-
}
|
|
33
|
-
return transformed;
|
|
34
|
-
}
|
|
35
|
-
function getTransformedSourceCacheStats() {
|
|
36
|
-
return {
|
|
37
|
-
entries: transformedSourceCache.size,
|
|
38
|
-
bytes: transformedSourceCacheBytes,
|
|
39
|
-
maxEntries: MAX_CACHE_ENTRIES,
|
|
40
|
-
maxBytes: MAX_CACHE_BYTES,
|
|
41
|
-
maxEntryBytes: MAX_CACHE_ENTRY_BYTES
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function clearTransformedSourceCache() {
|
|
45
|
-
transformedSourceCache.clear();
|
|
46
|
-
transformedSourceCacheBytes = 0;
|
|
47
|
-
}
|
|
48
|
-
function stripSnippetTypes(source) {
|
|
49
|
-
const prefix = "async function __codeModeUser__(){\n";
|
|
50
|
-
const suffix = "\n}";
|
|
51
|
-
const stripped = stripTypeScriptTypes(`${prefix}${source}${suffix}`);
|
|
52
|
-
if (!stripped.startsWith(prefix) || !stripped.endsWith(suffix)) {
|
|
53
|
-
return source;
|
|
54
|
-
}
|
|
55
|
-
return stripped.slice(prefix.length, -suffix.length);
|
|
56
|
-
}
|
|
57
|
-
function evictTransformedSourceCache() {
|
|
58
|
-
while (transformedSourceCache.size > MAX_CACHE_ENTRIES || transformedSourceCacheBytes > MAX_CACHE_BYTES) {
|
|
59
|
-
const oldest = transformedSourceCache.keys().next().value;
|
|
60
|
-
if (oldest === void 0) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const entry = transformedSourceCache.get(oldest);
|
|
64
|
-
transformedSourceCache.delete(oldest);
|
|
65
|
-
transformedSourceCacheBytes -= entry?.bytes ?? 0;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function byteLength(value) {
|
|
69
|
-
return new TextEncoder().encode(value).byteLength;
|
|
70
|
-
}
|
|
71
|
-
export {
|
|
72
|
-
assertSourceSize,
|
|
73
|
-
clearTransformedSourceCache,
|
|
74
|
-
getTransformedSourceCacheStats,
|
|
75
|
-
transformSource
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=source-cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/source-cache.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { stripTypeScriptTypes } from 'node:module';\nimport { CodeModeSourceTooLargeError } from '../errors.js';\n\nconst MAX_CACHE_ENTRIES = 256;\nconst MAX_CACHE_BYTES = 4 * 1024 * 1024;\nconst MAX_CACHE_ENTRY_BYTES = 64 * 1024;\nconst transformedSourceCache = new Map<\n string,\n {\n source: string;\n bytes: number;\n }\n>();\nlet transformedSourceCacheBytes = 0;\n\nexport function assertSourceSize(source: string, maxSourceBytes: number): void {\n const bytes = byteLength(source);\n if (bytes > maxSourceBytes) {\n throw new CodeModeSourceTooLargeError(bytes, maxSourceBytes);\n }\n}\n\nexport function transformSource(source: string): string {\n const hash = createHash('sha256')\n .update('strip:')\n .update(source)\n .digest('hex');\n const cached = transformedSourceCache.get(hash);\n if (cached !== undefined) {\n transformedSourceCache.delete(hash);\n transformedSourceCache.set(hash, cached);\n return cached.source;\n }\n\n const transformed = stripSnippetTypes(source);\n const transformedBytes = byteLength(transformed);\n if (transformedBytes <= MAX_CACHE_ENTRY_BYTES) {\n transformedSourceCache.set(hash, {\n source: transformed,\n bytes: transformedBytes,\n });\n transformedSourceCacheBytes += transformedBytes;\n evictTransformedSourceCache();\n }\n return transformed;\n}\n\nexport function getTransformedSourceCacheStats() {\n return {\n entries: transformedSourceCache.size,\n bytes: transformedSourceCacheBytes,\n maxEntries: MAX_CACHE_ENTRIES,\n maxBytes: MAX_CACHE_BYTES,\n maxEntryBytes: MAX_CACHE_ENTRY_BYTES,\n };\n}\n\nexport function clearTransformedSourceCache(): void {\n transformedSourceCache.clear();\n transformedSourceCacheBytes = 0;\n}\n\nfunction stripSnippetTypes(source: string): string {\n const prefix = 'async function __codeModeUser__(){\\n';\n const suffix = '\\n}';\n const stripped = stripTypeScriptTypes(`${prefix}${source}${suffix}`);\n if (!stripped.startsWith(prefix) || !stripped.endsWith(suffix)) {\n return source;\n }\n return stripped.slice(prefix.length, -suffix.length);\n}\n\nfunction evictTransformedSourceCache(): void {\n while (\n transformedSourceCache.size > MAX_CACHE_ENTRIES ||\n transformedSourceCacheBytes > MAX_CACHE_BYTES\n ) {\n const oldest = transformedSourceCache.keys().next().value;\n if (oldest === undefined) {\n return;\n }\n const entry = transformedSourceCache.get(oldest);\n transformedSourceCache.delete(oldest);\n transformedSourceCacheBytes -= entry?.bytes ?? 0;\n }\n}\n\nfunction byteLength(value: string): number {\n return new TextEncoder().encode(value).byteLength;\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,4BAA4B;AACrC,SAAS,mCAAmC;AAE5C,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB,IAAI,OAAO;AACnC,MAAM,wBAAwB,KAAK;AACnC,MAAM,yBAAyB,oBAAI,IAMjC;AACF,IAAI,8BAA8B;AAE3B,SAAS,iBAAiB,QAAgB,gBAA8B;AAC7E,QAAM,QAAQ,WAAW,MAAM;AAC/B,MAAI,QAAQ,gBAAgB;AAC1B,UAAM,IAAI,4BAA4B,OAAO,cAAc;AAAA,EAC7D;AACF;AAEO,SAAS,gBAAgB,QAAwB;AACtD,QAAM,OAAO,WAAW,QAAQ,EAC7B,OAAO,QAAQ,EACf,OAAO,MAAM,EACb,OAAO,KAAK;AACf,QAAM,SAAS,uBAAuB,IAAI,IAAI;AAC9C,MAAI,WAAW,QAAW;AACxB,2BAAuB,OAAO,IAAI;AAClC,2BAAuB,IAAI,MAAM,MAAM;AACvC,WAAO,OAAO;AAAA,EAChB;AAEA,QAAM,cAAc,kBAAkB,MAAM;AAC5C,QAAM,mBAAmB,WAAW,WAAW;AAC/C,MAAI,oBAAoB,uBAAuB;AAC7C,2BAAuB,IAAI,MAAM;AAAA,MAC/B,QAAQ;AAAA,MACR,OAAO;AAAA,IACT,CAAC;AACD,mCAA+B;AAC/B,gCAA4B;AAAA,EAC9B;AACA,SAAO;AACT;AAEO,SAAS,iCAAiC;AAC/C,SAAO;AAAA,IACL,SAAS,uBAAuB;AAAA,IAChC,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AAEO,SAAS,8BAAoC;AAClD,yBAAuB,MAAM;AAC7B,gCAA8B;AAChC;AAEA,SAAS,kBAAkB,QAAwB;AACjD,QAAM,SAAS;AACf,QAAM,SAAS;AACf,QAAM,WAAW,qBAAqB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE;AACnE,MAAI,CAAC,SAAS,WAAW,MAAM,KAAK,CAAC,SAAS,SAAS,MAAM,GAAG;AAC9D,WAAO;AAAA,EACT;AACA,SAAO,SAAS,MAAM,OAAO,QAAQ,CAAC,OAAO,MAAM;AACrD;AAEA,SAAS,8BAAoC;AAC3C,SACE,uBAAuB,OAAO,qBAC9B,8BAA8B,iBAC9B;AACA,UAAM,SAAS,uBAAuB,KAAK,EAAE,KAAK,EAAE;AACpD,QAAI,WAAW,QAAW;AACxB;AAAA,IACF;AACA,UAAM,QAAQ,uBAAuB,IAAI,MAAM;AAC/C,2BAAuB,OAAO,MAAM;AACpC,mCAA+B,OAAO,SAAS;AAAA,EACjD;AACF;AAEA,SAAS,WAAW,OAAuB;AACzC,SAAO,IAAI,YAAY,EAAE,OAAO,KAAK,EAAE;AACzC;","names":[]}
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
const HARDENING_SOURCE = `
|
|
2
|
-
(function() {
|
|
3
|
-
try { delete globalThis.crypto; } catch {}
|
|
4
|
-
if ('crypto' in globalThis) {
|
|
5
|
-
Object.defineProperty(globalThis, 'crypto', {
|
|
6
|
-
value: undefined,
|
|
7
|
-
writable: false,
|
|
8
|
-
configurable: false,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
try { delete globalThis.performance; } catch {}
|
|
12
|
-
if ('performance' in globalThis) {
|
|
13
|
-
Object.defineProperty(globalThis, 'performance', {
|
|
14
|
-
value: undefined,
|
|
15
|
-
writable: false,
|
|
16
|
-
configurable: false,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(globalThis, 'eval', {
|
|
21
|
-
value: undefined,
|
|
22
|
-
writable: false,
|
|
23
|
-
configurable: false,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const OriginalFunction = Function;
|
|
27
|
-
const BlockedFunction = function() {
|
|
28
|
-
throw new TypeError('Function constructor is not allowed');
|
|
29
|
-
};
|
|
30
|
-
BlockedFunction.prototype = OriginalFunction.prototype;
|
|
31
|
-
|
|
32
|
-
const AsyncFunction = (async function(){}).constructor;
|
|
33
|
-
const GeneratorFunction = (function*(){}).constructor;
|
|
34
|
-
const AsyncGeneratorFunction = (async function*(){}).constructor;
|
|
35
|
-
for (const proto of [
|
|
36
|
-
OriginalFunction.prototype,
|
|
37
|
-
AsyncFunction.prototype,
|
|
38
|
-
GeneratorFunction.prototype,
|
|
39
|
-
AsyncGeneratorFunction.prototype,
|
|
40
|
-
]) {
|
|
41
|
-
Object.defineProperty(proto, 'constructor', {
|
|
42
|
-
value: BlockedFunction,
|
|
43
|
-
writable: false,
|
|
44
|
-
configurable: false,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
Object.defineProperty(globalThis, 'Function', {
|
|
48
|
-
value: BlockedFunction,
|
|
49
|
-
writable: false,
|
|
50
|
-
configurable: false,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const g = globalThis;
|
|
54
|
-
const toFreeze = [
|
|
55
|
-
Object, Object.prototype,
|
|
56
|
-
OriginalFunction, OriginalFunction.prototype,
|
|
57
|
-
AsyncFunction, AsyncFunction.prototype,
|
|
58
|
-
GeneratorFunction, GeneratorFunction.prototype,
|
|
59
|
-
AsyncGeneratorFunction, AsyncGeneratorFunction.prototype,
|
|
60
|
-
Array, Array.prototype,
|
|
61
|
-
String, String.prototype,
|
|
62
|
-
Number, Number.prototype,
|
|
63
|
-
g.BigInt, g.BigInt && g.BigInt.prototype,
|
|
64
|
-
Boolean, Boolean.prototype,
|
|
65
|
-
g.Symbol, g.Symbol && g.Symbol.prototype,
|
|
66
|
-
RegExp, RegExp.prototype,
|
|
67
|
-
Date, Date.prototype,
|
|
68
|
-
Map, Map.prototype,
|
|
69
|
-
Set, Set.prototype,
|
|
70
|
-
WeakMap, WeakMap.prototype,
|
|
71
|
-
WeakSet, WeakSet.prototype,
|
|
72
|
-
Promise, Promise.prototype,
|
|
73
|
-
ArrayBuffer, ArrayBuffer.prototype,
|
|
74
|
-
g.DataView, g.DataView && g.DataView.prototype,
|
|
75
|
-
JSON, Math, g.Reflect, g.Proxy,
|
|
76
|
-
];
|
|
77
|
-
for (const name of [
|
|
78
|
-
'Int8Array','Uint8Array','Uint8ClampedArray',
|
|
79
|
-
'Int16Array','Uint16Array','Int32Array','Uint32Array',
|
|
80
|
-
'Float32Array','Float64Array',
|
|
81
|
-
'BigInt64Array','BigUint64Array',
|
|
82
|
-
]) {
|
|
83
|
-
if (g[name]) toFreeze.push(g[name], g[name].prototype);
|
|
84
|
-
}
|
|
85
|
-
for (const obj of toFreeze) {
|
|
86
|
-
if (obj != null) {
|
|
87
|
-
try { Object.freeze(obj); } catch {}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
})();
|
|
91
|
-
`;
|
|
92
|
-
|
|
93
|
-
const DETERMINISTIC_APIS_SOURCE = `
|
|
94
|
-
var __codeModeResetDateNow = (function(config) {
|
|
95
|
-
var OriginalDate = Date;
|
|
96
|
-
var dateNowMs = Number(config && config.dateNowMs);
|
|
97
|
-
if (!Number.isFinite(dateNowMs)) dateNowMs = 0;
|
|
98
|
-
|
|
99
|
-
function resetDateNow(value) {
|
|
100
|
-
var next = Number(value);
|
|
101
|
-
if (Number.isFinite(next)) dateNowMs = Math.trunc(next);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function nextDateMs() {
|
|
105
|
-
var value = dateNowMs;
|
|
106
|
-
dateNowMs += 1;
|
|
107
|
-
return value;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function CodeModeDate() {
|
|
111
|
-
if (new.target) {
|
|
112
|
-
if (arguments.length === 0) return new OriginalDate(nextDateMs());
|
|
113
|
-
return Reflect.construct(OriginalDate, arguments, new.target);
|
|
114
|
-
}
|
|
115
|
-
return new OriginalDate(nextDateMs()).toString();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
Object.defineProperty(CodeModeDate, 'prototype', {
|
|
119
|
-
value: OriginalDate.prototype,
|
|
120
|
-
writable: false,
|
|
121
|
-
configurable: false,
|
|
122
|
-
});
|
|
123
|
-
Object.defineProperty(OriginalDate.prototype, 'constructor', {
|
|
124
|
-
value: CodeModeDate,
|
|
125
|
-
writable: false,
|
|
126
|
-
configurable: false,
|
|
127
|
-
});
|
|
128
|
-
Object.defineProperty(CodeModeDate, 'now', {
|
|
129
|
-
value: nextDateMs,
|
|
130
|
-
writable: false,
|
|
131
|
-
configurable: false,
|
|
132
|
-
});
|
|
133
|
-
Object.defineProperty(CodeModeDate, 'parse', {
|
|
134
|
-
value: OriginalDate.parse,
|
|
135
|
-
writable: false,
|
|
136
|
-
configurable: false,
|
|
137
|
-
});
|
|
138
|
-
Object.defineProperty(CodeModeDate, 'UTC', {
|
|
139
|
-
value: OriginalDate.UTC,
|
|
140
|
-
writable: false,
|
|
141
|
-
configurable: false,
|
|
142
|
-
});
|
|
143
|
-
Object.defineProperty(globalThis, 'Date', {
|
|
144
|
-
value: CodeModeDate,
|
|
145
|
-
writable: false,
|
|
146
|
-
configurable: false,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
var randomSeed = String(config && config.randomSeed || '');
|
|
150
|
-
var mask64 = (1n << 64n) - 1n;
|
|
151
|
-
function readSeedPart(offset, fallback) {
|
|
152
|
-
var part = randomSeed.slice(offset, offset + 16);
|
|
153
|
-
return /^[0-9a-fA-F]{16}$/.test(part) ? BigInt('0x' + part) : fallback;
|
|
154
|
-
}
|
|
155
|
-
var randomState0 = readSeedPart(0, 0x243f6a8885a308d3n);
|
|
156
|
-
var randomState1 = readSeedPart(16, 0x13198a2e03707344n);
|
|
157
|
-
if ((randomState0 | randomState1) === 0n) {
|
|
158
|
-
randomState1 = 0x9e3779b97f4a7c15n;
|
|
159
|
-
}
|
|
160
|
-
function nextRandom64() {
|
|
161
|
-
var s1 = randomState0;
|
|
162
|
-
var s0 = randomState1;
|
|
163
|
-
randomState0 = s0;
|
|
164
|
-
s1 = (s1 ^ ((s1 << 23n) & mask64)) & mask64;
|
|
165
|
-
randomState1 = (s1 ^ s0 ^ (s1 >> 17n) ^ (s0 >> 26n)) & mask64;
|
|
166
|
-
return (randomState1 + s0) & mask64;
|
|
167
|
-
}
|
|
168
|
-
Object.defineProperty(Math, 'random', {
|
|
169
|
-
value: function() {
|
|
170
|
-
return Number(nextRandom64() >> 11n) / 9007199254740992;
|
|
171
|
-
},
|
|
172
|
-
writable: false,
|
|
173
|
-
configurable: false,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
return resetDateNow;
|
|
177
|
-
})(__codeModeDeterminism);
|
|
178
|
-
`;
|
|
179
|
-
|
|
180
|
-
const BRIDGE_TRACKING_SOURCE = `
|
|
181
|
-
(function() {
|
|
182
|
-
var nextRecordId = 0;
|
|
183
|
-
var records = [];
|
|
184
|
-
|
|
185
|
-
function detachedError(message, record) {
|
|
186
|
-
var error = new Error(message);
|
|
187
|
-
error.name = 'CodeModeDetachedBridgeRequestError';
|
|
188
|
-
error.code = 'CODE_MODE_DETACHED_BRIDGE_REQUEST';
|
|
189
|
-
error.details = {
|
|
190
|
-
id: record.id,
|
|
191
|
-
kind: record.kind,
|
|
192
|
-
name: record.name,
|
|
193
|
-
status: record.status
|
|
194
|
-
};
|
|
195
|
-
return error;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
Object.defineProperty(globalThis, '__codeModeCreateBridgePromise', {
|
|
199
|
-
value: function(kind, name, start) {
|
|
200
|
-
var record = {
|
|
201
|
-
id: ++nextRecordId,
|
|
202
|
-
kind: String(kind),
|
|
203
|
-
name: String(name || ''),
|
|
204
|
-
observed: false,
|
|
205
|
-
status: 'idle'
|
|
206
|
-
};
|
|
207
|
-
var promise;
|
|
208
|
-
records.push(record);
|
|
209
|
-
|
|
210
|
-
function getPromise() {
|
|
211
|
-
record.observed = true;
|
|
212
|
-
if (!promise) {
|
|
213
|
-
record.status = 'pending';
|
|
214
|
-
promise = Promise.resolve().then(start).then(
|
|
215
|
-
function(value) {
|
|
216
|
-
record.status = 'fulfilled';
|
|
217
|
-
return value;
|
|
218
|
-
},
|
|
219
|
-
function(error) {
|
|
220
|
-
record.status = 'rejected';
|
|
221
|
-
throw error;
|
|
222
|
-
}
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
return promise;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return Object.freeze({
|
|
229
|
-
then: function(onFulfilled, onRejected) {
|
|
230
|
-
return getPromise().then(onFulfilled, onRejected);
|
|
231
|
-
},
|
|
232
|
-
catch: function(onRejected) {
|
|
233
|
-
return getPromise().catch(onRejected);
|
|
234
|
-
},
|
|
235
|
-
finally: function(onFinally) {
|
|
236
|
-
return getPromise().finally(onFinally);
|
|
237
|
-
},
|
|
238
|
-
get [Symbol.toStringTag]() {
|
|
239
|
-
return 'Promise';
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
},
|
|
243
|
-
writable: false,
|
|
244
|
-
configurable: false
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
Object.defineProperty(globalThis, '__codeModeAssertNoDetachedBridgeCalls', {
|
|
248
|
-
value: function() {
|
|
249
|
-
for (var i = 0; i < records.length; i++) {
|
|
250
|
-
var record = records[i];
|
|
251
|
-
if (!record.observed) {
|
|
252
|
-
throw detachedError(
|
|
253
|
-
'Code mode created an unawaited ' + record.kind + ' bridge request: ' + record.name + '.',
|
|
254
|
-
record
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
if (record.status === 'pending') {
|
|
258
|
-
throw detachedError(
|
|
259
|
-
'Code mode returned while a ' + record.kind + ' bridge request was still pending: ' + record.name + '.',
|
|
260
|
-
record
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
writable: false,
|
|
266
|
-
configurable: false
|
|
267
|
-
});
|
|
268
|
-
})();
|
|
269
|
-
`;
|
|
270
|
-
|
|
271
|
-
const TOOLS_PROXY_SOURCE = `
|
|
272
|
-
(function(invokeTool) {
|
|
273
|
-
globalThis.tools = (function makeProxy(path) {
|
|
274
|
-
return new Proxy(function(){}, {
|
|
275
|
-
get: function(_target, prop) {
|
|
276
|
-
if (prop === 'then' || typeof prop === 'symbol') return undefined;
|
|
277
|
-
return makeProxy(path.concat([String(prop)]));
|
|
278
|
-
},
|
|
279
|
-
apply: function(_target, _thisArg, args) {
|
|
280
|
-
var toolPath = path.join('.');
|
|
281
|
-
if (!toolPath) throw new Error('Tool path missing in invocation');
|
|
282
|
-
var inputJson = args.length > 0 ? JSON.stringify(args[0]) : '';
|
|
283
|
-
if (inputJson === undefined) {
|
|
284
|
-
throw new Error('Tool input must be JSON-serializable');
|
|
285
|
-
}
|
|
286
|
-
return globalThis.__codeModeCreateBridgePromise('tool', toolPath, async function() {
|
|
287
|
-
var resultJson = await invokeTool(toolPath, inputJson);
|
|
288
|
-
return resultJson === '' ? undefined : JSON.parse(resultJson);
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
})([]);
|
|
293
|
-
})(__codeModeInvokeTool);
|
|
294
|
-
`;
|
|
295
|
-
|
|
296
|
-
const SERIALIZATION_GUARD_SOURCE = `
|
|
297
|
-
(function() {
|
|
298
|
-
function serializeJsonPayload(value) {
|
|
299
|
-
if (typeof globalThis.__codeModeAssertNoDetachedBridgeCalls === 'function') {
|
|
300
|
-
globalThis.__codeModeAssertNoDetachedBridgeCalls();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (value === undefined) {
|
|
304
|
-
return '';
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
var encoded;
|
|
308
|
-
try {
|
|
309
|
-
encoded = JSON.stringify(value);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
var message = error && error.message ? String(error.message) : String(error);
|
|
312
|
-
throw new TypeError('Code mode result is not JSON-serializable: ' + message);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (encoded === undefined) {
|
|
316
|
-
throw new TypeError('Code mode result is not JSON-serializable.');
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return encoded;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
Object.defineProperty(globalThis, '__codeModeSerializeJsonPayload', {
|
|
323
|
-
value: serializeJsonPayload,
|
|
324
|
-
writable: false,
|
|
325
|
-
configurable: false,
|
|
326
|
-
});
|
|
327
|
-
})();
|
|
328
|
-
`;
|
|
329
|
-
|
|
330
|
-
export function buildGuestRuntimeSetupSource(): string {
|
|
331
|
-
return `
|
|
332
|
-
(function(__codeModeInvokeTool, __codeModeDeterminism) {
|
|
333
|
-
${DETERMINISTIC_APIS_SOURCE}
|
|
334
|
-
${HARDENING_SOURCE}
|
|
335
|
-
${BRIDGE_TRACKING_SOURCE}
|
|
336
|
-
${TOOLS_PROXY_SOURCE}
|
|
337
|
-
${SERIALIZATION_GUARD_SOURCE}
|
|
338
|
-
return Object.freeze({
|
|
339
|
-
resetDateNow: __codeModeResetDateNow,
|
|
340
|
-
});
|
|
341
|
-
})
|
|
342
|
-
`;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
export function wrapUserCode(js: string): string {
|
|
346
|
-
return `
|
|
347
|
-
globalThis.__codeModeResult = (async () => {
|
|
348
|
-
${js}
|
|
349
|
-
})();
|
|
350
|
-
`;
|
|
351
|
-
}
|