wildcrane-runner 0.6.78 → 0.6.80
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 +5 -1
- package/dist/akb/dist/kanban.mjs +92 -142
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +1 -1
- package/dist/codex-proxy.mjs +1082 -680
- package/dist/{codex-service-main.mjs → codex-retained.mjs} +402 -2499
- package/dist/flow-worker-main.mjs +403 -428
- package/dist/launcher.mjs +849 -813
- package/dist/plugin.mjs +1115 -1079
- package/dist/runner.mjs +1091 -921
- package/dist/settings.mjs +1042 -1006
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// wildcrane-runner 0.6.
|
|
1
|
+
// wildcrane-runner 0.6.80 — built by runner/scripts/build.mjs. Do not edit.
|
|
2
2
|
import { createRequire as __ai4kanbanRequire } from 'node:module'
|
|
3
3
|
const require = __ai4kanbanRequire(import.meta.url)
|
|
4
4
|
var __create = Object.create;
|
|
@@ -1034,7 +1034,7 @@ var require_util = __commonJS({
|
|
|
1034
1034
|
var { kDestroyed, kBodyUsed, kListeners, kBody } = require_symbols();
|
|
1035
1035
|
var { IncomingMessage } = __require("node:http");
|
|
1036
1036
|
var stream = __require("node:stream");
|
|
1037
|
-
var
|
|
1037
|
+
var net = __require("node:net");
|
|
1038
1038
|
var { stringify } = __require("node:querystring");
|
|
1039
1039
|
var { EventEmitter: EE } = __require("node:events");
|
|
1040
1040
|
var timers = require_timers();
|
|
@@ -1146,14 +1146,14 @@ var require_util = __commonJS({
|
|
|
1146
1146
|
}
|
|
1147
1147
|
const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
|
|
1148
1148
|
let origin = url.origin != null ? url.origin : `${url.protocol || ""}//${url.hostname || ""}:${port}`;
|
|
1149
|
-
let
|
|
1149
|
+
let path6 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
|
|
1150
1150
|
if (origin[origin.length - 1] === "/") {
|
|
1151
1151
|
origin = origin.slice(0, origin.length - 1);
|
|
1152
1152
|
}
|
|
1153
|
-
if (
|
|
1154
|
-
|
|
1153
|
+
if (path6 && path6[0] !== "/") {
|
|
1154
|
+
path6 = `/${path6}`;
|
|
1155
1155
|
}
|
|
1156
|
-
return new URL(`${origin}${
|
|
1156
|
+
return new URL(`${origin}${path6}`);
|
|
1157
1157
|
}
|
|
1158
1158
|
if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) {
|
|
1159
1159
|
throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`.");
|
|
@@ -1183,7 +1183,7 @@ var require_util = __commonJS({
|
|
|
1183
1183
|
}
|
|
1184
1184
|
assert(typeof host === "string");
|
|
1185
1185
|
const servername = getHostname(host);
|
|
1186
|
-
if (
|
|
1186
|
+
if (net.isIP(servername)) {
|
|
1187
1187
|
return "";
|
|
1188
1188
|
}
|
|
1189
1189
|
return servername;
|
|
@@ -1988,9 +1988,9 @@ var require_diagnostics = __commonJS({
|
|
|
1988
1988
|
"undici:client:sendHeaders",
|
|
1989
1989
|
(evt) => {
|
|
1990
1990
|
const {
|
|
1991
|
-
request: { method, path:
|
|
1991
|
+
request: { method, path: path6, origin }
|
|
1992
1992
|
} = evt;
|
|
1993
|
-
debugLog("sending request to %s %s%s", method, origin,
|
|
1993
|
+
debugLog("sending request to %s %s%s", method, origin, path6);
|
|
1994
1994
|
}
|
|
1995
1995
|
);
|
|
1996
1996
|
}
|
|
@@ -2008,14 +2008,14 @@ var require_diagnostics = __commonJS({
|
|
|
2008
2008
|
"undici:request:headers",
|
|
2009
2009
|
(evt) => {
|
|
2010
2010
|
const {
|
|
2011
|
-
request: { method, path:
|
|
2011
|
+
request: { method, path: path6, origin },
|
|
2012
2012
|
response: { statusCode }
|
|
2013
2013
|
} = evt;
|
|
2014
2014
|
debugLog(
|
|
2015
2015
|
"received response to %s %s%s - HTTP %d",
|
|
2016
2016
|
method,
|
|
2017
2017
|
origin,
|
|
2018
|
-
|
|
2018
|
+
path6,
|
|
2019
2019
|
statusCode
|
|
2020
2020
|
);
|
|
2021
2021
|
}
|
|
@@ -2024,23 +2024,23 @@ var require_diagnostics = __commonJS({
|
|
|
2024
2024
|
"undici:request:trailers",
|
|
2025
2025
|
(evt) => {
|
|
2026
2026
|
const {
|
|
2027
|
-
request: { method, path:
|
|
2027
|
+
request: { method, path: path6, origin }
|
|
2028
2028
|
} = evt;
|
|
2029
|
-
debugLog("trailers received from %s %s%s", method, origin,
|
|
2029
|
+
debugLog("trailers received from %s %s%s", method, origin, path6);
|
|
2030
2030
|
}
|
|
2031
2031
|
);
|
|
2032
2032
|
diagnosticsChannel.subscribe(
|
|
2033
2033
|
"undici:request:error",
|
|
2034
2034
|
(evt) => {
|
|
2035
2035
|
const {
|
|
2036
|
-
request: { method, path:
|
|
2036
|
+
request: { method, path: path6, origin },
|
|
2037
2037
|
error
|
|
2038
2038
|
} = evt;
|
|
2039
2039
|
debugLog(
|
|
2040
2040
|
"request to %s %s%s errored - %s",
|
|
2041
2041
|
method,
|
|
2042
2042
|
origin,
|
|
2043
|
-
|
|
2043
|
+
path6,
|
|
2044
2044
|
error.message
|
|
2045
2045
|
);
|
|
2046
2046
|
}
|
|
@@ -2155,7 +2155,7 @@ var require_request = __commonJS({
|
|
|
2155
2155
|
var kHandler = /* @__PURE__ */ Symbol("handler");
|
|
2156
2156
|
var Request = class {
|
|
2157
2157
|
constructor(origin, {
|
|
2158
|
-
path:
|
|
2158
|
+
path: path6,
|
|
2159
2159
|
method,
|
|
2160
2160
|
body,
|
|
2161
2161
|
headers,
|
|
@@ -2172,11 +2172,11 @@ var require_request = __commonJS({
|
|
|
2172
2172
|
maxRedirections,
|
|
2173
2173
|
typeOfService
|
|
2174
2174
|
}, handler) {
|
|
2175
|
-
if (typeof
|
|
2175
|
+
if (typeof path6 !== "string") {
|
|
2176
2176
|
throw new InvalidArgumentError("path must be a string");
|
|
2177
|
-
} else if (
|
|
2177
|
+
} else if (path6[0] !== "/" && !(path6.startsWith("http://") || path6.startsWith("https://")) && method !== "CONNECT") {
|
|
2178
2178
|
throw new InvalidArgumentError("path must be an absolute URL or start with a slash");
|
|
2179
|
-
} else if (invalidPathRegex.test(
|
|
2179
|
+
} else if (invalidPathRegex.test(path6)) {
|
|
2180
2180
|
throw new InvalidArgumentError("invalid request path");
|
|
2181
2181
|
}
|
|
2182
2182
|
if (typeof method !== "string") {
|
|
@@ -2251,7 +2251,7 @@ var require_request = __commonJS({
|
|
|
2251
2251
|
this.completed = false;
|
|
2252
2252
|
this.aborted = false;
|
|
2253
2253
|
this.upgrade = upgrade || null;
|
|
2254
|
-
this.path = query ? serializePathWithQuery(
|
|
2254
|
+
this.path = query ? serializePathWithQuery(path6, query) : path6;
|
|
2255
2255
|
this.origin = origin;
|
|
2256
2256
|
this.protocol = getProtocolFromUrlString(origin);
|
|
2257
2257
|
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
|
|
@@ -2443,11 +2443,11 @@ var require_request = __commonJS({
|
|
|
2443
2443
|
} else if (typeof val[i] === "object") {
|
|
2444
2444
|
throw new InvalidArgumentError(`invalid ${key} header`);
|
|
2445
2445
|
} else {
|
|
2446
|
-
const
|
|
2447
|
-
if (!isValidHeaderValue(
|
|
2446
|
+
const str2 = `${val[i]}`;
|
|
2447
|
+
if (!isValidHeaderValue(str2)) {
|
|
2448
2448
|
throw new InvalidArgumentError(`invalid ${key} header`);
|
|
2449
2449
|
}
|
|
2450
|
-
arr.push(
|
|
2450
|
+
arr.push(str2);
|
|
2451
2451
|
}
|
|
2452
2452
|
}
|
|
2453
2453
|
val = arr;
|
|
@@ -2888,7 +2888,7 @@ var require_dispatcher_base = __commonJS({
|
|
|
2888
2888
|
var require_connect = __commonJS({
|
|
2889
2889
|
"node_modules/undici/lib/core/connect.js"(exports, module) {
|
|
2890
2890
|
"use strict";
|
|
2891
|
-
var
|
|
2891
|
+
var net = __require("node:net");
|
|
2892
2892
|
var assert = __require("node:assert");
|
|
2893
2893
|
var util = require_util();
|
|
2894
2894
|
var { InvalidArgumentError } = require_errors();
|
|
@@ -2975,7 +2975,7 @@ var require_connect = __commonJS({
|
|
|
2975
2975
|
} else {
|
|
2976
2976
|
assert(!httpSocket, "httpSocket can only be sent on TLS update");
|
|
2977
2977
|
port = port || 80;
|
|
2978
|
-
socket =
|
|
2978
|
+
socket = net.connect({
|
|
2979
2979
|
highWaterMark: 64 * 1024,
|
|
2980
2980
|
// Same as nodejs fs streams.
|
|
2981
2981
|
...options,
|
|
@@ -3990,8 +3990,8 @@ var require_infra = __commonJS({
|
|
|
3990
3990
|
}
|
|
3991
3991
|
var ASCII_WHITESPACE_REPLACE_REGEX = /[\u0009\u000A\u000C\u000D\u0020]/g;
|
|
3992
3992
|
var nonASCIIRegex = /[^\x00-\x7F]/;
|
|
3993
|
-
function asciiLowercase(
|
|
3994
|
-
return nonASCIIRegex.test(
|
|
3993
|
+
function asciiLowercase(str2) {
|
|
3994
|
+
return nonASCIIRegex.test(str2) ? str2.replace(/[A-Z]+/g, (upper) => upper.toLowerCase()) : str2.toLowerCase();
|
|
3995
3995
|
}
|
|
3996
3996
|
function forgivingBase64(data) {
|
|
3997
3997
|
data = data.replace(ASCII_WHITESPACE_REPLACE_REGEX, "");
|
|
@@ -4041,22 +4041,22 @@ var require_infra = __commonJS({
|
|
|
4041
4041
|
assert(!invalidIsomorphicEncodeValueRegex.test(input));
|
|
4042
4042
|
return input;
|
|
4043
4043
|
}
|
|
4044
|
-
function parseJSONFromBytes(
|
|
4045
|
-
return JSON.parse(utf8DecodeBytes(
|
|
4044
|
+
function parseJSONFromBytes(bytes) {
|
|
4045
|
+
return JSON.parse(utf8DecodeBytes(bytes));
|
|
4046
4046
|
}
|
|
4047
|
-
function removeASCIIWhitespace(
|
|
4048
|
-
return removeChars(
|
|
4047
|
+
function removeASCIIWhitespace(str2, leading = true, trailing = true) {
|
|
4048
|
+
return removeChars(str2, leading, trailing, isASCIIWhitespace);
|
|
4049
4049
|
}
|
|
4050
|
-
function removeChars(
|
|
4050
|
+
function removeChars(str2, leading, trailing, predicate) {
|
|
4051
4051
|
let lead = 0;
|
|
4052
|
-
let trail =
|
|
4052
|
+
let trail = str2.length - 1;
|
|
4053
4053
|
if (leading) {
|
|
4054
|
-
while (lead <
|
|
4054
|
+
while (lead < str2.length && predicate(str2.charCodeAt(lead))) lead++;
|
|
4055
4055
|
}
|
|
4056
4056
|
if (trailing) {
|
|
4057
|
-
while (trail > 0 && predicate(
|
|
4057
|
+
while (trail > 0 && predicate(str2.charCodeAt(trail))) trail--;
|
|
4058
4058
|
}
|
|
4059
|
-
return lead === 0 && trail ===
|
|
4059
|
+
return lead === 0 && trail === str2.length - 1 ? str2 : str2.slice(lead, trail + 1);
|
|
4060
4060
|
}
|
|
4061
4061
|
function serializeJavascriptValueToJSONString(value) {
|
|
4062
4062
|
const result = JSON.stringify(value);
|
|
@@ -4142,8 +4142,8 @@ var require_data_url = __commonJS({
|
|
|
4142
4142
|
return serialized;
|
|
4143
4143
|
}
|
|
4144
4144
|
function stringPercentDecode(input) {
|
|
4145
|
-
const
|
|
4146
|
-
return percentDecode(
|
|
4145
|
+
const bytes = encoder.encode(input);
|
|
4146
|
+
return percentDecode(bytes);
|
|
4147
4147
|
}
|
|
4148
4148
|
function isHexCharByte(byte) {
|
|
4149
4149
|
return byte >= 48 && byte <= 57 || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102;
|
|
@@ -4308,8 +4308,8 @@ var require_data_url = __commonJS({
|
|
|
4308
4308
|
function isHTTPWhiteSpace(char) {
|
|
4309
4309
|
return char === 13 || char === 10 || char === 9 || char === 32;
|
|
4310
4310
|
}
|
|
4311
|
-
function removeHTTPWhitespace(
|
|
4312
|
-
return removeChars(
|
|
4311
|
+
function removeHTTPWhitespace(str2, leading = true, trailing = true) {
|
|
4312
|
+
return removeChars(str2, leading, trailing, isHTTPWhiteSpace);
|
|
4313
4313
|
}
|
|
4314
4314
|
function minimizeSupportedMimeType(mimeType) {
|
|
4315
4315
|
switch (mimeType.essence) {
|
|
@@ -4468,7 +4468,7 @@ var require_webidl = __commonJS({
|
|
|
4468
4468
|
"node_modules/undici/lib/web/webidl/index.js"(exports, module) {
|
|
4469
4469
|
"use strict";
|
|
4470
4470
|
var assert = __require("node:assert");
|
|
4471
|
-
var { types, inspect
|
|
4471
|
+
var { types, inspect } = __require("node:util");
|
|
4472
4472
|
var { runtimeFeatures } = require_runtime_features();
|
|
4473
4473
|
var UNDEFINED = 1;
|
|
4474
4474
|
var BOOLEAN = 2;
|
|
@@ -4660,7 +4660,7 @@ var require_webidl = __commonJS({
|
|
|
4660
4660
|
case SYMBOL:
|
|
4661
4661
|
return `Symbol(${V.description})`;
|
|
4662
4662
|
case OBJECT:
|
|
4663
|
-
return
|
|
4663
|
+
return inspect(V);
|
|
4664
4664
|
case STRING:
|
|
4665
4665
|
return `"${V}"`;
|
|
4666
4666
|
case BIGINT:
|
|
@@ -4829,10 +4829,10 @@ var require_webidl = __commonJS({
|
|
|
4829
4829
|
if (jsArrayBuffer.detached) {
|
|
4830
4830
|
return new Uint8Array(0);
|
|
4831
4831
|
}
|
|
4832
|
-
const
|
|
4832
|
+
const bytes = new Uint8Array(length);
|
|
4833
4833
|
const view = new Uint8Array(jsArrayBuffer, offset, length);
|
|
4834
|
-
|
|
4835
|
-
return
|
|
4834
|
+
bytes.set(view);
|
|
4835
|
+
return bytes;
|
|
4836
4836
|
};
|
|
4837
4837
|
webidl.converters.DOMString = function(V, prefix, argument, flags) {
|
|
4838
4838
|
if (V === null && webidl.util.HasFlag(flags, webidl.attributes.LegacyNullToEmptyString)) {
|
|
@@ -5548,19 +5548,19 @@ var require_util2 = __commonJS({
|
|
|
5548
5548
|
}
|
|
5549
5549
|
async function readAllBytes(reader, successSteps, failureSteps) {
|
|
5550
5550
|
try {
|
|
5551
|
-
const
|
|
5551
|
+
const bytes = [];
|
|
5552
5552
|
let byteLength = 0;
|
|
5553
5553
|
do {
|
|
5554
5554
|
const { done, value: chunk } = await reader.read();
|
|
5555
5555
|
if (done) {
|
|
5556
|
-
successSteps(Buffer.concat(
|
|
5556
|
+
successSteps(Buffer.concat(bytes, byteLength));
|
|
5557
5557
|
return;
|
|
5558
5558
|
}
|
|
5559
5559
|
if (!isUint8Array(chunk)) {
|
|
5560
5560
|
failureSteps(new TypeError("Received non-Uint8Array chunk"));
|
|
5561
5561
|
return;
|
|
5562
5562
|
}
|
|
5563
|
-
|
|
5563
|
+
bytes.push(chunk);
|
|
5564
5564
|
byteLength += chunk.length;
|
|
5565
5565
|
} while (true);
|
|
5566
5566
|
} catch (e) {
|
|
@@ -6430,7 +6430,7 @@ var require_body = __commonJS({
|
|
|
6430
6430
|
const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, "0")}`;
|
|
6431
6431
|
const prefix = `--${boundary}\r
|
|
6432
6432
|
Content-Disposition: form-data`;
|
|
6433
|
-
const formdataEscape = (
|
|
6433
|
+
const formdataEscape = (str2) => str2.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
|
|
6434
6434
|
const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, "\r\n");
|
|
6435
6435
|
const blobParts = [];
|
|
6436
6436
|
const rn = new Uint8Array([13, 10]);
|
|
@@ -6519,19 +6519,19 @@ Content-Type: ${value.type || "application/octet-stream"}\r
|
|
|
6519
6519
|
function bodyMixinMethods(instance, getInternalState) {
|
|
6520
6520
|
const methods = {
|
|
6521
6521
|
blob() {
|
|
6522
|
-
return consumeBody(this, (
|
|
6522
|
+
return consumeBody(this, (bytes) => {
|
|
6523
6523
|
let mimeType = bodyMimeType(getInternalState(this));
|
|
6524
6524
|
if (mimeType === null) {
|
|
6525
6525
|
mimeType = "";
|
|
6526
6526
|
} else if (mimeType) {
|
|
6527
6527
|
mimeType = serializeAMimeType(mimeType);
|
|
6528
6528
|
}
|
|
6529
|
-
return new Blob([
|
|
6529
|
+
return new Blob([bytes], { type: mimeType });
|
|
6530
6530
|
}, instance, getInternalState);
|
|
6531
6531
|
},
|
|
6532
6532
|
arrayBuffer() {
|
|
6533
|
-
return consumeBody(this, (
|
|
6534
|
-
return new Uint8Array(
|
|
6533
|
+
return consumeBody(this, (bytes) => {
|
|
6534
|
+
return new Uint8Array(bytes).buffer;
|
|
6535
6535
|
}, instance, getInternalState);
|
|
6536
6536
|
},
|
|
6537
6537
|
text() {
|
|
@@ -6567,8 +6567,8 @@ Content-Type: ${value.type || "application/octet-stream"}\r
|
|
|
6567
6567
|
}, instance, getInternalState);
|
|
6568
6568
|
},
|
|
6569
6569
|
bytes() {
|
|
6570
|
-
return consumeBody(this, (
|
|
6571
|
-
return new Uint8Array(
|
|
6570
|
+
return consumeBody(this, (bytes) => {
|
|
6571
|
+
return new Uint8Array(bytes);
|
|
6572
6572
|
}, instance, getInternalState);
|
|
6573
6573
|
}
|
|
6574
6574
|
};
|
|
@@ -7495,7 +7495,7 @@ var require_client_h1 = __commonJS({
|
|
|
7495
7495
|
}
|
|
7496
7496
|
}
|
|
7497
7497
|
function writeH1(client, request) {
|
|
7498
|
-
const { method, path:
|
|
7498
|
+
const { method, path: path6, host, upgrade, blocking, reset } = request;
|
|
7499
7499
|
let { body, headers, contentLength } = request;
|
|
7500
7500
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
|
|
7501
7501
|
if (util.isFormDataLike(body)) {
|
|
@@ -7571,7 +7571,7 @@ var require_client_h1 = __commonJS({
|
|
|
7571
7571
|
socket[kBlocking] = true;
|
|
7572
7572
|
}
|
|
7573
7573
|
setTypeOfService(socket, request);
|
|
7574
|
-
let header = `${method} ${
|
|
7574
|
+
let header = `${method} ${path6} HTTP/1.1\r
|
|
7575
7575
|
`;
|
|
7576
7576
|
if (typeof host === "string") {
|
|
7577
7577
|
header += `host: ${host}\r
|
|
@@ -8248,7 +8248,7 @@ var require_client_h2 = __commonJS({
|
|
|
8248
8248
|
const headersTimeout = request.headersTimeout ?? client[kHeadersTimeout];
|
|
8249
8249
|
const bodyTimeout = request.bodyTimeout ?? client[kBodyTimeout];
|
|
8250
8250
|
const session = client[kHTTP2Session];
|
|
8251
|
-
const { method, path:
|
|
8251
|
+
const { method, path: path6, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request;
|
|
8252
8252
|
let { body } = request;
|
|
8253
8253
|
if (upgrade != null && upgrade !== "websocket") {
|
|
8254
8254
|
util.errorRequest(client, request, new InvalidArgumentError(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
|
|
@@ -8317,7 +8317,7 @@ var require_client_h2 = __commonJS({
|
|
|
8317
8317
|
}
|
|
8318
8318
|
headers[HTTP2_HEADER_METHOD] = "CONNECT";
|
|
8319
8319
|
headers[HTTP2_HEADER_PROTOCOL] = "websocket";
|
|
8320
|
-
headers[HTTP2_HEADER_PATH] =
|
|
8320
|
+
headers[HTTP2_HEADER_PATH] = path6;
|
|
8321
8321
|
if (protocol === "ws:" || protocol === "wss:") {
|
|
8322
8322
|
headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
|
|
8323
8323
|
} else {
|
|
@@ -8369,7 +8369,7 @@ var require_client_h2 = __commonJS({
|
|
|
8369
8369
|
stream.setTimeout(headersTimeout);
|
|
8370
8370
|
return true;
|
|
8371
8371
|
}
|
|
8372
|
-
headers[HTTP2_HEADER_PATH] =
|
|
8372
|
+
headers[HTTP2_HEADER_PATH] = path6;
|
|
8373
8373
|
headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
|
|
8374
8374
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
8375
8375
|
if (body && typeof body.read === "function") {
|
|
@@ -8688,7 +8688,7 @@ var require_client = __commonJS({
|
|
|
8688
8688
|
"node_modules/undici/lib/dispatcher/client.js"(exports, module) {
|
|
8689
8689
|
"use strict";
|
|
8690
8690
|
var assert = __require("node:assert");
|
|
8691
|
-
var
|
|
8691
|
+
var net = __require("node:net");
|
|
8692
8692
|
var http = __require("node:http");
|
|
8693
8693
|
var util = require_util();
|
|
8694
8694
|
var { ClientStats } = require_stats();
|
|
@@ -8844,7 +8844,7 @@ var require_client = __commonJS({
|
|
|
8844
8844
|
if (maxRequestsPerClient != null && (!Number.isInteger(maxRequestsPerClient) || maxRequestsPerClient < 0)) {
|
|
8845
8845
|
throw new InvalidArgumentError("maxRequestsPerClient must be a positive number");
|
|
8846
8846
|
}
|
|
8847
|
-
if (localAddress != null && (typeof localAddress !== "string" ||
|
|
8847
|
+
if (localAddress != null && (typeof localAddress !== "string" || net.isIP(localAddress) === 0)) {
|
|
8848
8848
|
throw new InvalidArgumentError("localAddress must be valid string IP address");
|
|
8849
8849
|
}
|
|
8850
8850
|
if (maxResponseSize != null && (!Number.isInteger(maxResponseSize) || maxResponseSize < -1)) {
|
|
@@ -9024,7 +9024,7 @@ var require_client = __commonJS({
|
|
|
9024
9024
|
const idx = hostname.indexOf("]");
|
|
9025
9025
|
assert(idx !== -1);
|
|
9026
9026
|
const ip = hostname.substring(1, idx);
|
|
9027
|
-
assert(
|
|
9027
|
+
assert(net.isIPv6(ip));
|
|
9028
9028
|
hostname = ip;
|
|
9029
9029
|
}
|
|
9030
9030
|
client[kConnecting] = true;
|
|
@@ -9851,7 +9851,7 @@ var require_agent = __commonJS({
|
|
|
9851
9851
|
function defaultFactory(origin, opts) {
|
|
9852
9852
|
return opts && opts.connections === 1 ? new Client(origin, opts) : new Pool(origin, opts);
|
|
9853
9853
|
}
|
|
9854
|
-
var
|
|
9854
|
+
var Agent2 = class extends DispatcherBase {
|
|
9855
9855
|
constructor({ factory = defaultFactory, maxOrigins = Infinity, connect: connect2, tls, ...options } = {}) {
|
|
9856
9856
|
if (typeof factory !== "function") {
|
|
9857
9857
|
throw new InvalidArgumentError("factory must be a function.");
|
|
@@ -9963,7 +9963,7 @@ var require_agent = __commonJS({
|
|
|
9963
9963
|
return allClientStats;
|
|
9964
9964
|
}
|
|
9965
9965
|
};
|
|
9966
|
-
module.exports =
|
|
9966
|
+
module.exports = Agent2;
|
|
9967
9967
|
}
|
|
9968
9968
|
});
|
|
9969
9969
|
|
|
@@ -9972,10 +9972,10 @@ var require_socks5_utils = __commonJS({
|
|
|
9972
9972
|
"node_modules/undici/lib/core/socks5-utils.js"(exports, module) {
|
|
9973
9973
|
"use strict";
|
|
9974
9974
|
var { Buffer: Buffer2 } = __require("node:buffer");
|
|
9975
|
-
var
|
|
9975
|
+
var net = __require("node:net");
|
|
9976
9976
|
var { InvalidArgumentError } = require_errors();
|
|
9977
9977
|
function parseAddress(address) {
|
|
9978
|
-
if (
|
|
9978
|
+
if (net.isIPv4(address)) {
|
|
9979
9979
|
const parts = address.split(".").map(Number);
|
|
9980
9980
|
return {
|
|
9981
9981
|
type: 1,
|
|
@@ -9983,7 +9983,7 @@ var require_socks5_utils = __commonJS({
|
|
|
9983
9983
|
buffer: Buffer2.from(parts)
|
|
9984
9984
|
};
|
|
9985
9985
|
}
|
|
9986
|
-
if (
|
|
9986
|
+
if (net.isIPv6(address)) {
|
|
9987
9987
|
return {
|
|
9988
9988
|
type: 4,
|
|
9989
9989
|
// IPv6
|
|
@@ -10006,7 +10006,7 @@ var require_socks5_utils = __commonJS({
|
|
|
10006
10006
|
if (address.includes(".")) {
|
|
10007
10007
|
const lastColonIndex = address.lastIndexOf(":");
|
|
10008
10008
|
const ipv4Part = address.slice(lastColonIndex + 1);
|
|
10009
|
-
if (
|
|
10009
|
+
if (net.isIPv4(ipv4Part)) {
|
|
10010
10010
|
const octets = ipv4Part.split(".").map(Number);
|
|
10011
10011
|
const high = (octets[0] << 8 | octets[1]).toString(16);
|
|
10012
10012
|
const low = (octets[2] << 8 | octets[3]).toString(16);
|
|
@@ -10669,7 +10669,7 @@ var require_proxy_agent = __commonJS({
|
|
|
10669
10669
|
"node_modules/undici/lib/dispatcher/proxy-agent.js"(exports, module) {
|
|
10670
10670
|
"use strict";
|
|
10671
10671
|
var { kProxy, kClose, kDestroy, kDispatch } = require_symbols();
|
|
10672
|
-
var
|
|
10672
|
+
var Agent2 = require_agent();
|
|
10673
10673
|
var Pool = require_pool();
|
|
10674
10674
|
var DispatcherBase = require_dispatcher_base();
|
|
10675
10675
|
var { InvalidArgumentError, RequestAbortedError, SecureProxyConnectionError } = require_errors();
|
|
@@ -10725,10 +10725,10 @@ var require_proxy_agent = __commonJS({
|
|
|
10725
10725
|
};
|
|
10726
10726
|
const {
|
|
10727
10727
|
origin,
|
|
10728
|
-
path:
|
|
10728
|
+
path: path6 = "/",
|
|
10729
10729
|
headers = {}
|
|
10730
10730
|
} = opts;
|
|
10731
|
-
opts.path = origin +
|
|
10731
|
+
opts.path = origin + path6;
|
|
10732
10732
|
if (!("host" in headers) && !("Host" in headers)) {
|
|
10733
10733
|
const { host } = new URL(origin);
|
|
10734
10734
|
headers.host = host;
|
|
@@ -10800,7 +10800,7 @@ var require_proxy_agent = __commonJS({
|
|
|
10800
10800
|
} else {
|
|
10801
10801
|
this[kClient] = clientFactory(url, { connect: connect2 });
|
|
10802
10802
|
}
|
|
10803
|
-
this[kAgent] = new
|
|
10803
|
+
this[kAgent] = new Agent2({
|
|
10804
10804
|
...opts,
|
|
10805
10805
|
factory,
|
|
10806
10806
|
connect: async (opts2, callback) => {
|
|
@@ -10928,7 +10928,7 @@ var require_env_http_proxy_agent = __commonJS({
|
|
|
10928
10928
|
var DispatcherBase = require_dispatcher_base();
|
|
10929
10929
|
var { kClose, kDestroy, kClosed, kDestroyed, kDispatch, kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent } = require_symbols();
|
|
10930
10930
|
var ProxyAgent = require_proxy_agent();
|
|
10931
|
-
var
|
|
10931
|
+
var Agent2 = require_agent();
|
|
10932
10932
|
var DEFAULT_PORTS = {
|
|
10933
10933
|
"http:": 80,
|
|
10934
10934
|
"https:": 443
|
|
@@ -10941,7 +10941,7 @@ var require_env_http_proxy_agent = __commonJS({
|
|
|
10941
10941
|
super();
|
|
10942
10942
|
this.#opts = opts;
|
|
10943
10943
|
const { httpProxy, httpsProxy, noProxy, ...agentOpts } = opts;
|
|
10944
|
-
this[kNoProxyAgent] = new
|
|
10944
|
+
this[kNoProxyAgent] = new Agent2(agentOpts);
|
|
10945
10945
|
const HTTP_PROXY = httpProxy ?? process.env.http_proxy ?? process.env.HTTP_PROXY;
|
|
10946
10946
|
if (HTTP_PROXY) {
|
|
10947
10947
|
this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTP_PROXY });
|
|
@@ -12327,7 +12327,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12327
12327
|
var {
|
|
12328
12328
|
Readable,
|
|
12329
12329
|
Duplex,
|
|
12330
|
-
PassThrough
|
|
12330
|
+
PassThrough: PassThrough2
|
|
12331
12331
|
} = __require("node:stream");
|
|
12332
12332
|
var assert = __require("node:assert");
|
|
12333
12333
|
var { AsyncResource } = __require("node:async_hooks");
|
|
@@ -12514,7 +12514,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12514
12514
|
this.dispatch({ ...opts, body: pipelineHandler.req }, pipelineHandler);
|
|
12515
12515
|
return pipelineHandler.ret;
|
|
12516
12516
|
} catch (err) {
|
|
12517
|
-
return new
|
|
12517
|
+
return new PassThrough2().destroy(err);
|
|
12518
12518
|
}
|
|
12519
12519
|
}
|
|
12520
12520
|
module.exports = pipeline;
|
|
@@ -12888,20 +12888,20 @@ var require_mock_utils = __commonJS({
|
|
|
12888
12888
|
}
|
|
12889
12889
|
return normalizedQp;
|
|
12890
12890
|
}
|
|
12891
|
-
function safeUrl(
|
|
12892
|
-
if (typeof
|
|
12893
|
-
return
|
|
12891
|
+
function safeUrl(path6) {
|
|
12892
|
+
if (typeof path6 !== "string") {
|
|
12893
|
+
return path6;
|
|
12894
12894
|
}
|
|
12895
|
-
const pathSegments =
|
|
12895
|
+
const pathSegments = path6.split("?", 3);
|
|
12896
12896
|
if (pathSegments.length !== 2) {
|
|
12897
|
-
return
|
|
12897
|
+
return path6;
|
|
12898
12898
|
}
|
|
12899
12899
|
const qp = new URLSearchParams(pathSegments.pop());
|
|
12900
12900
|
qp.sort();
|
|
12901
12901
|
return [...pathSegments, qp.toString()].join("?");
|
|
12902
12902
|
}
|
|
12903
|
-
function matchKey(mockDispatch2, { path:
|
|
12904
|
-
const pathMatch = matchValue(mockDispatch2.path,
|
|
12903
|
+
function matchKey(mockDispatch2, { path: path6, method, body, headers }) {
|
|
12904
|
+
const pathMatch = matchValue(mockDispatch2.path, path6);
|
|
12905
12905
|
const methodMatch = matchValue(mockDispatch2.method, method);
|
|
12906
12906
|
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
|
|
12907
12907
|
const headersMatch = matchHeaders(mockDispatch2, headers);
|
|
@@ -12926,8 +12926,8 @@ var require_mock_utils = __commonJS({
|
|
|
12926
12926
|
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
|
|
12927
12927
|
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
|
|
12928
12928
|
const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
|
|
12929
|
-
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path:
|
|
12930
|
-
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(
|
|
12929
|
+
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path6, ignoreTrailingSlash }) => {
|
|
12930
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path6)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path6), resolvedPath);
|
|
12931
12931
|
});
|
|
12932
12932
|
if (matchedMockDispatches.length === 0) {
|
|
12933
12933
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
@@ -12966,19 +12966,19 @@ var require_mock_utils = __commonJS({
|
|
|
12966
12966
|
mockDispatches.splice(index, 1);
|
|
12967
12967
|
}
|
|
12968
12968
|
}
|
|
12969
|
-
function removeTrailingSlash(
|
|
12970
|
-
while (
|
|
12971
|
-
|
|
12969
|
+
function removeTrailingSlash(path6) {
|
|
12970
|
+
while (path6.endsWith("/")) {
|
|
12971
|
+
path6 = path6.slice(0, -1);
|
|
12972
12972
|
}
|
|
12973
|
-
if (
|
|
12974
|
-
|
|
12973
|
+
if (path6.length === 0) {
|
|
12974
|
+
path6 = "/";
|
|
12975
12975
|
}
|
|
12976
|
-
return
|
|
12976
|
+
return path6;
|
|
12977
12977
|
}
|
|
12978
12978
|
function buildKey(opts) {
|
|
12979
|
-
const { path:
|
|
12979
|
+
const { path: path6, method, body, headers, query } = opts;
|
|
12980
12980
|
return {
|
|
12981
|
-
path:
|
|
12981
|
+
path: path6,
|
|
12982
12982
|
method,
|
|
12983
12983
|
body,
|
|
12984
12984
|
headers,
|
|
@@ -13668,10 +13668,10 @@ var require_pending_interceptors_formatter = __commonJS({
|
|
|
13668
13668
|
}
|
|
13669
13669
|
format(pendingInterceptors) {
|
|
13670
13670
|
const withPrettyHeaders = pendingInterceptors.map(
|
|
13671
|
-
({ method, path:
|
|
13671
|
+
({ method, path: path6, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
13672
13672
|
Method: method,
|
|
13673
13673
|
Origin: origin,
|
|
13674
|
-
Path:
|
|
13674
|
+
Path: path6,
|
|
13675
13675
|
"Status code": statusCode,
|
|
13676
13676
|
Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
|
|
13677
13677
|
Invocations: timesInvoked,
|
|
@@ -13690,7 +13690,7 @@ var require_mock_agent = __commonJS({
|
|
|
13690
13690
|
"node_modules/undici/lib/mock/mock-agent.js"(exports, module) {
|
|
13691
13691
|
"use strict";
|
|
13692
13692
|
var { kClients } = require_symbols();
|
|
13693
|
-
var
|
|
13693
|
+
var Agent2 = require_agent();
|
|
13694
13694
|
var {
|
|
13695
13695
|
kAgent,
|
|
13696
13696
|
kMockAgentSet,
|
|
@@ -13728,7 +13728,7 @@ var require_mock_agent = __commonJS({
|
|
|
13728
13728
|
if (opts?.agent && typeof opts.agent.dispatch !== "function") {
|
|
13729
13729
|
throw new InvalidArgumentError("Argument opts.agent must implement Agent");
|
|
13730
13730
|
}
|
|
13731
|
-
const agent = opts?.agent ? opts.agent : new
|
|
13731
|
+
const agent = opts?.agent ? opts.agent : new Agent2(opts);
|
|
13732
13732
|
this[kAgent] = agent;
|
|
13733
13733
|
this[kClients] = agent[kClients];
|
|
13734
13734
|
this[kOptions] = mockOptions;
|
|
@@ -13753,9 +13753,9 @@ var require_mock_agent = __commonJS({
|
|
|
13753
13753
|
const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
|
|
13754
13754
|
const dispatchOpts = { ...opts };
|
|
13755
13755
|
if (acceptNonStandardSearchParameters && dispatchOpts.path) {
|
|
13756
|
-
const [
|
|
13756
|
+
const [path6, searchParams] = dispatchOpts.path.split("?");
|
|
13757
13757
|
const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
|
|
13758
|
-
dispatchOpts.path = `${
|
|
13758
|
+
dispatchOpts.path = `${path6}?${normalizedSearchParams}`;
|
|
13759
13759
|
}
|
|
13760
13760
|
return this[kAgent].dispatch(dispatchOpts, handler);
|
|
13761
13761
|
}
|
|
@@ -13883,8 +13883,8 @@ var require_snapshot_utils = __commonJS({
|
|
|
13883
13883
|
match: new Set(matchHeaders.map((header) => caseSensitive ? header : header.toLowerCase()))
|
|
13884
13884
|
};
|
|
13885
13885
|
}
|
|
13886
|
-
var
|
|
13887
|
-
var hashId =
|
|
13886
|
+
var crypto2 = runtimeFeatures.has("crypto") ? __require("node:crypto") : null;
|
|
13887
|
+
var hashId = crypto2?.hash ? (value) => crypto2.hash("sha256", value, "base64url") : (value) => Buffer.from(value).toString("base64url");
|
|
13888
13888
|
function isUndiciHeaders(headers) {
|
|
13889
13889
|
return Array.isArray(headers) && (headers.length & 1) === 0;
|
|
13890
13890
|
}
|
|
@@ -14156,12 +14156,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
14156
14156
|
* @return {Promise<void>} - Resolves when snapshots are loaded
|
|
14157
14157
|
*/
|
|
14158
14158
|
async loadSnapshots(filePath) {
|
|
14159
|
-
const
|
|
14160
|
-
if (!
|
|
14159
|
+
const path6 = filePath || this.#snapshotPath;
|
|
14160
|
+
if (!path6) {
|
|
14161
14161
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
14162
14162
|
}
|
|
14163
14163
|
try {
|
|
14164
|
-
const data = await readFile(resolve(
|
|
14164
|
+
const data = await readFile(resolve(path6), "utf8");
|
|
14165
14165
|
const parsed = JSON.parse(data);
|
|
14166
14166
|
if (Array.isArray(parsed)) {
|
|
14167
14167
|
this.#snapshots.clear();
|
|
@@ -14175,7 +14175,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
14175
14175
|
if (error.code === "ENOENT") {
|
|
14176
14176
|
this.#snapshots.clear();
|
|
14177
14177
|
} else {
|
|
14178
|
-
throw new UndiciError(`Failed to load snapshots from ${
|
|
14178
|
+
throw new UndiciError(`Failed to load snapshots from ${path6}`, { cause: error });
|
|
14179
14179
|
}
|
|
14180
14180
|
}
|
|
14181
14181
|
}
|
|
@@ -14186,11 +14186,11 @@ var require_snapshot_recorder = __commonJS({
|
|
|
14186
14186
|
* @returns {Promise<void>} - Resolves when snapshots are saved
|
|
14187
14187
|
*/
|
|
14188
14188
|
async saveSnapshots(filePath) {
|
|
14189
|
-
const
|
|
14190
|
-
if (!
|
|
14189
|
+
const path6 = filePath || this.#snapshotPath;
|
|
14190
|
+
if (!path6) {
|
|
14191
14191
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
14192
14192
|
}
|
|
14193
|
-
const resolvedPath = resolve(
|
|
14193
|
+
const resolvedPath = resolve(path6);
|
|
14194
14194
|
await mkdir(dirname(resolvedPath), { recursive: true });
|
|
14195
14195
|
const data = Array.from(this.#snapshots.entries()).map(([hash, snapshot]) => ({
|
|
14196
14196
|
hash,
|
|
@@ -14335,7 +14335,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
14335
14335
|
var require_snapshot_agent = __commonJS({
|
|
14336
14336
|
"node_modules/undici/lib/mock/snapshot-agent.js"(exports, module) {
|
|
14337
14337
|
"use strict";
|
|
14338
|
-
var
|
|
14338
|
+
var Agent2 = require_agent();
|
|
14339
14339
|
var MockAgent = require_mock_agent();
|
|
14340
14340
|
var { SnapshotRecorder } = require_snapshot_recorder();
|
|
14341
14341
|
var WrapHandler = require_wrap_handler();
|
|
@@ -14386,7 +14386,7 @@ var require_snapshot_agent = __commonJS({
|
|
|
14386
14386
|
});
|
|
14387
14387
|
this[kSnapshotLoaded] = false;
|
|
14388
14388
|
if (this[kSnapshotMode] === "record" || this[kSnapshotMode] === "update" || this[kSnapshotMode] === "playback" && opts.excludeUrls && opts.excludeUrls.length > 0) {
|
|
14389
|
-
this[kRealAgent] = new
|
|
14389
|
+
this[kRealAgent] = new Agent2(opts);
|
|
14390
14390
|
}
|
|
14391
14391
|
if ((this[kSnapshotMode] === "playback" || this[kSnapshotMode] === "update") && this[kSnapshotPath]) {
|
|
14392
14392
|
this.loadSnapshots().catch(() => {
|
|
@@ -14625,9 +14625,9 @@ var require_global2 = __commonJS({
|
|
|
14625
14625
|
var globalDispatcher = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.2");
|
|
14626
14626
|
var legacyGlobalDispatcher = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1");
|
|
14627
14627
|
var { InvalidArgumentError } = require_errors();
|
|
14628
|
-
var
|
|
14628
|
+
var Agent2 = require_agent();
|
|
14629
14629
|
if (getGlobalDispatcher() === void 0) {
|
|
14630
|
-
setGlobalDispatcher2(new
|
|
14630
|
+
setGlobalDispatcher2(new Agent2());
|
|
14631
14631
|
}
|
|
14632
14632
|
function setGlobalDispatcher2(agent) {
|
|
14633
14633
|
if (!agent || typeof agent.dispatch !== "function") {
|
|
@@ -14831,15 +14831,15 @@ var require_redirect_handler = __commonJS({
|
|
|
14831
14831
|
receivedAt: Date.now()
|
|
14832
14832
|
});
|
|
14833
14833
|
const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
|
|
14834
|
-
const
|
|
14835
|
-
const redirectUrlString = `${origin}${
|
|
14834
|
+
const path6 = search ? `${pathname}${search}` : pathname;
|
|
14835
|
+
const redirectUrlString = `${origin}${path6}`;
|
|
14836
14836
|
for (const historyUrl of this.history) {
|
|
14837
14837
|
if (historyUrl.toString() === redirectUrlString) {
|
|
14838
14838
|
throw new InvalidArgumentError(`Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.`);
|
|
14839
14839
|
}
|
|
14840
14840
|
}
|
|
14841
14841
|
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
|
|
14842
|
-
this.opts.path =
|
|
14842
|
+
this.opts.path = path6;
|
|
14843
14843
|
this.opts.origin = origin;
|
|
14844
14844
|
this.opts.query = null;
|
|
14845
14845
|
}
|
|
@@ -15688,14 +15688,14 @@ var require_cache = __commonJS({
|
|
|
15688
15688
|
}
|
|
15689
15689
|
function appendHeader(headers, key, val) {
|
|
15690
15690
|
const headerName = key.toLowerCase();
|
|
15691
|
-
const
|
|
15691
|
+
const current = headers[headerName];
|
|
15692
15692
|
const values = Array.isArray(val) ? val : [val];
|
|
15693
|
-
if (
|
|
15693
|
+
if (current === void 0) {
|
|
15694
15694
|
headers[headerName] = Array.isArray(val) ? val.slice() : val;
|
|
15695
|
-
} else if (Array.isArray(
|
|
15696
|
-
|
|
15695
|
+
} else if (Array.isArray(current)) {
|
|
15696
|
+
current.push(...values);
|
|
15697
15697
|
} else {
|
|
15698
|
-
headers[headerName] = [
|
|
15698
|
+
headers[headerName] = [current, ...values];
|
|
15699
15699
|
}
|
|
15700
15700
|
}
|
|
15701
15701
|
function normalizeHeaders(opts) {
|
|
@@ -16656,10 +16656,10 @@ var require_cache_handler = __commonJS({
|
|
|
16656
16656
|
}
|
|
16657
16657
|
return locationUrl.pathname + locationUrl.search;
|
|
16658
16658
|
}
|
|
16659
|
-
function deleteCachedUri(store, cacheKey,
|
|
16659
|
+
function deleteCachedUri(store, cacheKey, path6) {
|
|
16660
16660
|
deleteCachedValue(store, {
|
|
16661
16661
|
...cacheKey,
|
|
16662
|
-
path:
|
|
16662
|
+
path: path6
|
|
16663
16663
|
});
|
|
16664
16664
|
for (let i = 0; i < util.safeHTTPMethods.length; i++) {
|
|
16665
16665
|
const method = util.safeHTTPMethods[i];
|
|
@@ -16667,7 +16667,7 @@ var require_cache_handler = __commonJS({
|
|
|
16667
16667
|
deleteCachedValue(store, {
|
|
16668
16668
|
...cacheKey,
|
|
16669
16669
|
method,
|
|
16670
|
-
path:
|
|
16670
|
+
path: path6
|
|
16671
16671
|
});
|
|
16672
16672
|
}
|
|
16673
16673
|
}
|
|
@@ -16678,9 +16678,9 @@ var require_cache_handler = __commonJS({
|
|
|
16678
16678
|
}
|
|
16679
16679
|
const values = Array.isArray(headerValue) ? headerValue : [headerValue];
|
|
16680
16680
|
for (let i = 0; i < values.length; i++) {
|
|
16681
|
-
const
|
|
16682
|
-
if (
|
|
16683
|
-
deleteCachedUri(store, cacheKey,
|
|
16681
|
+
const path6 = getSameOriginPath(cacheKey, values[i]);
|
|
16682
|
+
if (path6 !== void 0) {
|
|
16683
|
+
deleteCachedUri(store, cacheKey, path6);
|
|
16684
16684
|
}
|
|
16685
16685
|
}
|
|
16686
16686
|
}
|
|
@@ -17317,7 +17317,7 @@ var require_cache_handler = __commonJS({
|
|
|
17317
17317
|
var require_memory_cache_store = __commonJS({
|
|
17318
17318
|
"node_modules/undici/lib/cache/memory-cache-store.js"(exports, module) {
|
|
17319
17319
|
"use strict";
|
|
17320
|
-
var { Writable } = __require("node:stream");
|
|
17320
|
+
var { Writable: Writable2 } = __require("node:stream");
|
|
17321
17321
|
var { EventEmitter } = __require("node:events");
|
|
17322
17322
|
var { assertCacheKey, assertCacheValue } = require_cache();
|
|
17323
17323
|
var MemoryCacheStore = class extends EventEmitter {
|
|
@@ -17407,7 +17407,7 @@ var require_memory_cache_store = __commonJS({
|
|
|
17407
17407
|
const topLevelKey = `${key.origin}:${key.path}`;
|
|
17408
17408
|
const store = this;
|
|
17409
17409
|
const entry = { ...key, ...val, body: [], size: 0 };
|
|
17410
|
-
return new
|
|
17410
|
+
return new Writable2({
|
|
17411
17411
|
write(chunk, encoding, callback) {
|
|
17412
17412
|
if (typeof chunk === "string") {
|
|
17413
17413
|
chunk = Buffer.from(chunk, encoding);
|
|
@@ -19075,7 +19075,7 @@ var require_deduplicate = __commonJS({
|
|
|
19075
19075
|
var require_sqlite_cache_store = __commonJS({
|
|
19076
19076
|
"node_modules/undici/lib/cache/sqlite-cache-store.js"(exports, module) {
|
|
19077
19077
|
"use strict";
|
|
19078
|
-
var { Writable } = __require("node:stream");
|
|
19078
|
+
var { Writable: Writable2 } = __require("node:stream");
|
|
19079
19079
|
var { assertCacheKey, assertCacheValue } = require_cache();
|
|
19080
19080
|
var DatabaseSync;
|
|
19081
19081
|
var VERSION = 4;
|
|
@@ -19319,7 +19319,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
19319
19319
|
let size = 0;
|
|
19320
19320
|
const body = [];
|
|
19321
19321
|
const store = this;
|
|
19322
|
-
return new
|
|
19322
|
+
return new Writable2({
|
|
19323
19323
|
decodeStrings: true,
|
|
19324
19324
|
write(chunk, encoding, callback) {
|
|
19325
19325
|
size += chunk.byteLength;
|
|
@@ -19513,13 +19513,13 @@ var require_headers = __commonJS({
|
|
|
19513
19513
|
return headersList.sortedMap;
|
|
19514
19514
|
}
|
|
19515
19515
|
const headers = [];
|
|
19516
|
-
const
|
|
19516
|
+
const names = headersList.toSortedArray();
|
|
19517
19517
|
const cookies = headersList.cookies;
|
|
19518
19518
|
if (cookies === null || cookies.length === 1) {
|
|
19519
|
-
return headersList.sortedMap =
|
|
19519
|
+
return headersList.sortedMap = names;
|
|
19520
19520
|
}
|
|
19521
|
-
for (let i = 0; i <
|
|
19522
|
-
const { 0: name, 1: value } =
|
|
19521
|
+
for (let i = 0; i < names.length; ++i) {
|
|
19522
|
+
const { 0: name, 1: value } = names[i];
|
|
19523
19523
|
if (name === "set-cookie") {
|
|
19524
19524
|
for (let j = 0; j < cookies.length; ++j) {
|
|
19525
19525
|
headers.push([name, cookies[j]]);
|
|
@@ -19937,10 +19937,10 @@ var require_response = __commonJS({
|
|
|
19937
19937
|
if (init !== null) {
|
|
19938
19938
|
init = webidl.converters.ResponseInit(init);
|
|
19939
19939
|
}
|
|
19940
|
-
const
|
|
19940
|
+
const bytes = textEncoder.encode(
|
|
19941
19941
|
serializeJavascriptValueToJSONString(data)
|
|
19942
19942
|
);
|
|
19943
|
-
const body = extractBody(
|
|
19943
|
+
const body = extractBody(bytes);
|
|
19944
19944
|
const responseObject = fromInnerResponse(makeResponse({}), "response");
|
|
19945
19945
|
initializeResponse(responseObject, init, { body: body[0], type: "application/json" });
|
|
19946
19946
|
return responseObject;
|
|
@@ -21082,10 +21082,10 @@ var require_subresource_integrity = __commonJS({
|
|
|
21082
21082
|
var { runtimeFeatures } = require_runtime_features();
|
|
21083
21083
|
var { asciiLowercase } = require_infra();
|
|
21084
21084
|
var validSRIHashAlgorithmTokenSet = /* @__PURE__ */ new Map([["sha256", 0], ["sha384", 1], ["sha512", 2]]);
|
|
21085
|
-
var
|
|
21085
|
+
var crypto2;
|
|
21086
21086
|
if (runtimeFeatures.has("crypto")) {
|
|
21087
|
-
|
|
21088
|
-
const cryptoHashes =
|
|
21087
|
+
crypto2 = __require("node:crypto");
|
|
21088
|
+
const cryptoHashes = crypto2.getHashes();
|
|
21089
21089
|
if (cryptoHashes.length === 0) {
|
|
21090
21090
|
validSRIHashAlgorithmTokenSet.clear();
|
|
21091
21091
|
}
|
|
@@ -21104,7 +21104,7 @@ var require_subresource_integrity = __commonJS({
|
|
|
21104
21104
|
)
|
|
21105
21105
|
);
|
|
21106
21106
|
var isValidSRIHashAlgorithm = (algorithm) => validSRIHashAlgorithmTokenSet.has(asciiLowercase(algorithm));
|
|
21107
|
-
var bytesMatch = runtimeFeatures.has("crypto") === false || validSRIHashAlgorithmTokenSet.size === 0 ? () => true : (
|
|
21107
|
+
var bytesMatch = runtimeFeatures.has("crypto") === false || validSRIHashAlgorithmTokenSet.size === 0 ? () => true : (bytes, metadataList) => {
|
|
21108
21108
|
const parsedMetadata = parseMetadata(metadataList);
|
|
21109
21109
|
if (parsedMetadata.length === 0) {
|
|
21110
21110
|
return true;
|
|
@@ -21113,7 +21113,7 @@ var require_subresource_integrity = __commonJS({
|
|
|
21113
21113
|
for (const item of metadata) {
|
|
21114
21114
|
const algorithm = item.alg;
|
|
21115
21115
|
const expectedValue = item.val;
|
|
21116
|
-
const actualValue = applyAlgorithmToBytes(algorithm,
|
|
21116
|
+
const actualValue = applyAlgorithmToBytes(algorithm, bytes);
|
|
21117
21117
|
if (caseSensitiveMatch(actualValue, expectedValue)) {
|
|
21118
21118
|
return true;
|
|
21119
21119
|
}
|
|
@@ -21172,8 +21172,8 @@ var require_subresource_integrity = __commonJS({
|
|
|
21172
21172
|
}
|
|
21173
21173
|
return result;
|
|
21174
21174
|
}
|
|
21175
|
-
var applyAlgorithmToBytes = (algorithm,
|
|
21176
|
-
return
|
|
21175
|
+
var applyAlgorithmToBytes = (algorithm, bytes) => {
|
|
21176
|
+
return crypto2.hash(algorithm, bytes, "base64");
|
|
21177
21177
|
};
|
|
21178
21178
|
function caseSensitiveMatch(actualValue, expectedValue) {
|
|
21179
21179
|
let actualValueLength = actualValue.length;
|
|
@@ -21318,7 +21318,7 @@ var require_fetch = __commonJS({
|
|
|
21318
21318
|
function handleFetchDone(response) {
|
|
21319
21319
|
finalizeAndReportTiming(response, "fetch");
|
|
21320
21320
|
}
|
|
21321
|
-
function
|
|
21321
|
+
function fetch(input, init = void 0) {
|
|
21322
21322
|
webidl.argumentLengthCheck(arguments, 1, "globalThis.fetch");
|
|
21323
21323
|
let p = createDeferredPromise();
|
|
21324
21324
|
let requestObject;
|
|
@@ -21584,12 +21584,12 @@ var require_fetch = __commonJS({
|
|
|
21584
21584
|
processBodyError(response.error);
|
|
21585
21585
|
return;
|
|
21586
21586
|
}
|
|
21587
|
-
const processBody = (
|
|
21588
|
-
if (!bytesMatch(
|
|
21587
|
+
const processBody = (bytes) => {
|
|
21588
|
+
if (!bytesMatch(bytes, request.integrity)) {
|
|
21589
21589
|
processBodyError("integrity mismatch");
|
|
21590
21590
|
return;
|
|
21591
21591
|
}
|
|
21592
|
-
response.body = safelyExtractBody(
|
|
21592
|
+
response.body = safelyExtractBody(bytes)[0];
|
|
21593
21593
|
fetchFinale(fetchParams, response);
|
|
21594
21594
|
};
|
|
21595
21595
|
fullyReadBody(response.body, processBody, processBodyError);
|
|
@@ -22032,12 +22032,12 @@ var require_fetch = __commonJS({
|
|
|
22032
22032
|
if (request.body == null && fetchParams.processRequestEndOfBody) {
|
|
22033
22033
|
queueMicrotask(() => fetchParams.processRequestEndOfBody());
|
|
22034
22034
|
} else if (request.body != null) {
|
|
22035
|
-
const processBodyChunk = async function* (
|
|
22035
|
+
const processBodyChunk = async function* (bytes) {
|
|
22036
22036
|
if (isCancelled(fetchParams)) {
|
|
22037
22037
|
return;
|
|
22038
22038
|
}
|
|
22039
|
-
yield
|
|
22040
|
-
fetchParams.processRequestBodyChunkLength?.(
|
|
22039
|
+
yield bytes;
|
|
22040
|
+
fetchParams.processRequestBodyChunkLength?.(bytes.byteLength);
|
|
22041
22041
|
};
|
|
22042
22042
|
const processEndOfBody = () => {
|
|
22043
22043
|
if (isCancelled(fetchParams)) {
|
|
@@ -22059,8 +22059,8 @@ var require_fetch = __commonJS({
|
|
|
22059
22059
|
};
|
|
22060
22060
|
requestBody = (async function* () {
|
|
22061
22061
|
try {
|
|
22062
|
-
for await (const
|
|
22063
|
-
yield* processBodyChunk(
|
|
22062
|
+
for await (const bytes of request.body.stream) {
|
|
22063
|
+
yield* processBodyChunk(bytes);
|
|
22064
22064
|
}
|
|
22065
22065
|
processEndOfBody();
|
|
22066
22066
|
} catch (err) {
|
|
@@ -22108,33 +22108,33 @@ var require_fetch = __commonJS({
|
|
|
22108
22108
|
}
|
|
22109
22109
|
fetchParams.controller.resume = async () => {
|
|
22110
22110
|
while (true) {
|
|
22111
|
-
let
|
|
22111
|
+
let bytes;
|
|
22112
22112
|
let isFailure;
|
|
22113
22113
|
try {
|
|
22114
22114
|
const { done, value } = await fetchParams.controller.next();
|
|
22115
22115
|
if (isAborted(fetchParams)) {
|
|
22116
22116
|
break;
|
|
22117
22117
|
}
|
|
22118
|
-
|
|
22118
|
+
bytes = done ? void 0 : value;
|
|
22119
22119
|
} catch (err) {
|
|
22120
22120
|
if (fetchParams.controller.ended && !timingInfo.encodedBodySize) {
|
|
22121
|
-
|
|
22121
|
+
bytes = void 0;
|
|
22122
22122
|
} else {
|
|
22123
|
-
|
|
22123
|
+
bytes = err;
|
|
22124
22124
|
isFailure = true;
|
|
22125
22125
|
}
|
|
22126
22126
|
}
|
|
22127
|
-
if (
|
|
22127
|
+
if (bytes === void 0) {
|
|
22128
22128
|
readableStreamClose(fetchParams.controller.controller);
|
|
22129
22129
|
finalizeResponse(fetchParams, response);
|
|
22130
22130
|
return;
|
|
22131
22131
|
}
|
|
22132
|
-
timingInfo.decodedBodySize +=
|
|
22132
|
+
timingInfo.decodedBodySize += bytes?.byteLength ?? 0;
|
|
22133
22133
|
if (isFailure) {
|
|
22134
|
-
fetchParams.controller.terminate(
|
|
22134
|
+
fetchParams.controller.terminate(bytes);
|
|
22135
22135
|
return;
|
|
22136
22136
|
}
|
|
22137
|
-
const buffer = new Uint8Array(
|
|
22137
|
+
const buffer = new Uint8Array(bytes);
|
|
22138
22138
|
if (buffer.byteLength) {
|
|
22139
22139
|
fetchParams.controller.controller.enqueue(buffer);
|
|
22140
22140
|
}
|
|
@@ -22168,11 +22168,11 @@ var require_fetch = __commonJS({
|
|
|
22168
22168
|
function dispatch({ body }) {
|
|
22169
22169
|
const url = requestCurrentURL(request);
|
|
22170
22170
|
const agent = fetchParams.controller.dispatcher;
|
|
22171
|
-
const
|
|
22171
|
+
const path6 = url.pathname + url.search;
|
|
22172
22172
|
const hasTrailingQuestionMark = url.search.length === 0 && url.href[url.href.length - url.hash.length - 1] === "?";
|
|
22173
22173
|
return new Promise((resolve, reject) => agent.dispatch(
|
|
22174
22174
|
{
|
|
22175
|
-
path: hasTrailingQuestionMark ? `${
|
|
22175
|
+
path: hasTrailingQuestionMark ? `${path6}?` : path6,
|
|
22176
22176
|
origin: url.origin,
|
|
22177
22177
|
method: request.method,
|
|
22178
22178
|
body: agent.isMockActive ? request.body && (request.body.source || request.body.stream) : body,
|
|
@@ -22274,9 +22274,9 @@ var require_fetch = __commonJS({
|
|
|
22274
22274
|
if (fetchParams.controller.dump) {
|
|
22275
22275
|
return;
|
|
22276
22276
|
}
|
|
22277
|
-
const
|
|
22278
|
-
timingInfo.encodedBodySize +=
|
|
22279
|
-
return this.body.push(
|
|
22277
|
+
const bytes = chunk;
|
|
22278
|
+
timingInfo.encodedBodySize += bytes.byteLength;
|
|
22279
|
+
return this.body.push(bytes);
|
|
22280
22280
|
},
|
|
22281
22281
|
onComplete() {
|
|
22282
22282
|
if (this.abort) {
|
|
@@ -22348,7 +22348,7 @@ var require_fetch = __commonJS({
|
|
|
22348
22348
|
}
|
|
22349
22349
|
}
|
|
22350
22350
|
module.exports = {
|
|
22351
|
-
fetch
|
|
22351
|
+
fetch,
|
|
22352
22352
|
Fetch,
|
|
22353
22353
|
fetching,
|
|
22354
22354
|
finalizeAndReportTiming
|
|
@@ -22607,9 +22607,9 @@ var require_cache3 = __commonJS({
|
|
|
22607
22607
|
// 16.
|
|
22608
22608
|
};
|
|
22609
22609
|
operations.push(operation);
|
|
22610
|
-
const
|
|
22610
|
+
const bytes = await bodyReadPromise.promise;
|
|
22611
22611
|
if (clonedResponse.body != null) {
|
|
22612
|
-
clonedResponse.body.source =
|
|
22612
|
+
clonedResponse.body.source = bytes;
|
|
22613
22613
|
}
|
|
22614
22614
|
const cacheJobPromise = createDeferredPromise();
|
|
22615
22615
|
let errorData = null;
|
|
@@ -23119,9 +23119,9 @@ var require_util4 = __commonJS({
|
|
|
23119
23119
|
}
|
|
23120
23120
|
}
|
|
23121
23121
|
}
|
|
23122
|
-
function validateCookiePath(
|
|
23123
|
-
for (let i = 0; i <
|
|
23124
|
-
const code =
|
|
23122
|
+
function validateCookiePath(path6) {
|
|
23123
|
+
for (let i = 0; i < path6.length; ++i) {
|
|
23124
|
+
const code = path6.charCodeAt(i);
|
|
23125
23125
|
if (code < 32 || // exclude CTLs (0-31)
|
|
23126
23126
|
code > 126 || // exclude DEL and non-ascii
|
|
23127
23127
|
code === 59) {
|
|
@@ -23460,9 +23460,9 @@ var require_cookies = __commonJS({
|
|
|
23460
23460
|
webidl.argumentLengthCheck(arguments, 2, "setCookie");
|
|
23461
23461
|
brandChecks(headers);
|
|
23462
23462
|
cookie = webidl.converters.Cookie(cookie);
|
|
23463
|
-
const
|
|
23464
|
-
if (
|
|
23465
|
-
headers.append("set-cookie",
|
|
23463
|
+
const str2 = stringify(cookie);
|
|
23464
|
+
if (str2) {
|
|
23465
|
+
headers.append("set-cookie", str2, true);
|
|
23466
23466
|
}
|
|
23467
23467
|
}
|
|
23468
23468
|
webidl.converters.DeleteCookieAttributes = webidl.dictionaryConverter([
|
|
@@ -24161,7 +24161,7 @@ var require_connection = __commonJS({
|
|
|
24161
24161
|
var { WebsocketFrameSend } = require_frame();
|
|
24162
24162
|
var assert = __require("node:assert");
|
|
24163
24163
|
var { runtimeFeatures } = require_runtime_features();
|
|
24164
|
-
var
|
|
24164
|
+
var crypto2 = runtimeFeatures.has("crypto") ? __require("node:crypto") : null;
|
|
24165
24165
|
var warningEmitted = false;
|
|
24166
24166
|
function establishWebSocketConnection(url, protocols, client, handler, options) {
|
|
24167
24167
|
const requestURL = url;
|
|
@@ -24181,7 +24181,7 @@ var require_connection = __commonJS({
|
|
|
24181
24181
|
const headersList = getHeadersList(new Headers(options.headers));
|
|
24182
24182
|
request.headersList = headersList;
|
|
24183
24183
|
}
|
|
24184
|
-
const keyValue =
|
|
24184
|
+
const keyValue = crypto2.randomBytes(16).toString("base64");
|
|
24185
24185
|
request.headersList.append("sec-websocket-key", keyValue, true);
|
|
24186
24186
|
request.headersList.append("sec-websocket-version", "13", true);
|
|
24187
24187
|
for (const protocol of protocols) {
|
|
@@ -24221,7 +24221,7 @@ var require_connection = __commonJS({
|
|
|
24221
24221
|
return;
|
|
24222
24222
|
}
|
|
24223
24223
|
const secWSAccept = response.headersList.get("Sec-WebSocket-Accept");
|
|
24224
|
-
const digest =
|
|
24224
|
+
const digest = crypto2.hash("sha1", keyValue + uid, "base64");
|
|
24225
24225
|
if (secWSAccept !== digest) {
|
|
24226
24226
|
failHandshake(handler, response, 1002, "Incorrect hash received in Sec-WebSocket-Accept header.");
|
|
24227
24227
|
return;
|
|
@@ -24396,7 +24396,7 @@ var require_permessage_deflate = __commonJS({
|
|
|
24396
24396
|
var require_receiver = __commonJS({
|
|
24397
24397
|
"node_modules/undici/lib/web/websocket/receiver.js"(exports, module) {
|
|
24398
24398
|
"use strict";
|
|
24399
|
-
var { Writable } = __require("node:stream");
|
|
24399
|
+
var { Writable: Writable2 } = __require("node:stream");
|
|
24400
24400
|
var assert = __require("node:assert");
|
|
24401
24401
|
var { parserStates, opcodes, states, emptyBuffer, sentCloseFrameState } = require_constants5();
|
|
24402
24402
|
var {
|
|
@@ -24412,7 +24412,7 @@ var require_receiver = __commonJS({
|
|
|
24412
24412
|
var { WebsocketFrameSend } = require_frame();
|
|
24413
24413
|
var { PerMessageDeflate } = require_permessage_deflate();
|
|
24414
24414
|
var { MessageSizeExceededError } = require_errors();
|
|
24415
|
-
var ByteParser = class extends
|
|
24415
|
+
var ByteParser = class extends Writable2 {
|
|
24416
24416
|
#buffers = [];
|
|
24417
24417
|
#fragmentsBytes = 0;
|
|
24418
24418
|
#byteOffset = 0;
|
|
@@ -26484,7 +26484,7 @@ var require_undici = __commonJS({
|
|
|
26484
26484
|
var Pool = require_pool();
|
|
26485
26485
|
var BalancedPool = require_balanced_pool();
|
|
26486
26486
|
var RoundRobinPool = require_round_robin_pool();
|
|
26487
|
-
var
|
|
26487
|
+
var Agent2 = require_agent();
|
|
26488
26488
|
var ProxyAgent = require_proxy_agent();
|
|
26489
26489
|
var Socks5ProxyAgent = require_socks5_proxy_agent();
|
|
26490
26490
|
var EnvHttpProxyAgent2 = require_env_http_proxy_agent();
|
|
@@ -26511,7 +26511,7 @@ var require_undici = __commonJS({
|
|
|
26511
26511
|
module.exports.Pool = Pool;
|
|
26512
26512
|
module.exports.BalancedPool = BalancedPool;
|
|
26513
26513
|
module.exports.RoundRobinPool = RoundRobinPool;
|
|
26514
|
-
module.exports.Agent =
|
|
26514
|
+
module.exports.Agent = Agent2;
|
|
26515
26515
|
module.exports.ProxyAgent = ProxyAgent;
|
|
26516
26516
|
module.exports.Socks5ProxyAgent = Socks5ProxyAgent;
|
|
26517
26517
|
module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent2;
|
|
@@ -26557,11 +26557,11 @@ var require_undici = __commonJS({
|
|
|
26557
26557
|
if (typeof opts.path !== "string") {
|
|
26558
26558
|
throw new InvalidArgumentError("invalid opts.path");
|
|
26559
26559
|
}
|
|
26560
|
-
let
|
|
26560
|
+
let path6 = opts.path;
|
|
26561
26561
|
if (!opts.path.startsWith("/")) {
|
|
26562
|
-
|
|
26562
|
+
path6 = `/${path6}`;
|
|
26563
26563
|
}
|
|
26564
|
-
url = new URL(util.parseOrigin(url).origin +
|
|
26564
|
+
url = new URL(util.parseOrigin(url).origin + path6);
|
|
26565
26565
|
} else {
|
|
26566
26566
|
if (!opts) {
|
|
26567
26567
|
opts = typeof url === "object" ? url : {};
|
|
@@ -26602,7 +26602,7 @@ var require_undici = __commonJS({
|
|
|
26602
26602
|
err.stack = stack ? `${stack}
|
|
26603
26603
|
${captureLines}` : capture.stack;
|
|
26604
26604
|
}
|
|
26605
|
-
module.exports.fetch = function
|
|
26605
|
+
module.exports.fetch = function fetch(init, options = void 0) {
|
|
26606
26606
|
return fetchImpl(init, options).catch((err) => {
|
|
26607
26607
|
if (currentFilename) {
|
|
26608
26608
|
appendFetchStackTrace(err, currentFilename);
|
|
@@ -26670,753 +26670,32 @@ ${captureLines}` : capture.stack;
|
|
|
26670
26670
|
}
|
|
26671
26671
|
});
|
|
26672
26672
|
|
|
26673
|
-
//
|
|
26674
|
-
|
|
26675
|
-
"node_modules/smol-toml/dist/index.cjs"(exports) {
|
|
26676
|
-
"use strict";
|
|
26677
|
-
Object.defineProperties(exports, {
|
|
26678
|
-
__esModule: { value: true },
|
|
26679
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
26680
|
-
});
|
|
26681
|
-
function getLineColFromPtr(string, ptr) {
|
|
26682
|
-
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
26683
|
-
return [lines.length, lines.pop().length + 1];
|
|
26684
|
-
}
|
|
26685
|
-
function makeCodeBlock(string, line, column) {
|
|
26686
|
-
let lines = string.split(/\r?\n/);
|
|
26687
|
-
let codeblock = "";
|
|
26688
|
-
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
26689
|
-
for (let i = line - 1; i <= line + 1; i++) {
|
|
26690
|
-
let l = lines[i - 1];
|
|
26691
|
-
if (!l) continue;
|
|
26692
|
-
codeblock += i.toString().padEnd(numberLen, " ");
|
|
26693
|
-
codeblock += ": ";
|
|
26694
|
-
codeblock += l;
|
|
26695
|
-
codeblock += "\n";
|
|
26696
|
-
if (i === line) {
|
|
26697
|
-
codeblock += " ".repeat(numberLen + column + 2);
|
|
26698
|
-
codeblock += "^\n";
|
|
26699
|
-
}
|
|
26700
|
-
}
|
|
26701
|
-
return codeblock;
|
|
26702
|
-
}
|
|
26703
|
-
var TomlError = class TomlError2 extends Error {
|
|
26704
|
-
line;
|
|
26705
|
-
column;
|
|
26706
|
-
codeblock;
|
|
26707
|
-
constructor(message, options) {
|
|
26708
|
-
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
26709
|
-
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
26710
|
-
super(`Invalid TOML document: ${message}
|
|
26673
|
+
// src/codex-retained.ts
|
|
26674
|
+
import fs5 from "node:fs";
|
|
26711
26675
|
|
|
26712
|
-
|
|
26713
|
-
|
|
26714
|
-
|
|
26715
|
-
|
|
26716
|
-
|
|
26717
|
-
|
|
26718
|
-
|
|
26719
|
-
|
|
26720
|
-
|
|
26721
|
-
|
|
26722
|
-
|
|
26723
|
-
|
|
26724
|
-
|
|
26725
|
-
function parseString(ctx) {
|
|
26726
|
-
let startPtr = ctx.p;
|
|
26727
|
-
let c = ctx.s.charCodeAt(ctx.p++);
|
|
26728
|
-
let first = c;
|
|
26729
|
-
let isLiteral = c === 39;
|
|
26730
|
-
let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
|
|
26731
|
-
if (isMultiline) {
|
|
26732
|
-
if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10) ctx.p++;
|
|
26733
|
-
else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) ctx.p += 2;
|
|
26734
|
-
}
|
|
26735
|
-
let parsed = "";
|
|
26736
|
-
let sliceStart = ctx.p;
|
|
26737
|
-
let state = 0;
|
|
26738
|
-
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
26739
|
-
c = ctx.s.charCodeAt(ctx.p);
|
|
26740
|
-
if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) state = state && 3;
|
|
26741
|
-
else if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in strings", ctx);
|
|
26742
|
-
else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
|
|
26743
|
-
if (isMultiline) {
|
|
26744
|
-
if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
|
|
26745
|
-
if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
|
|
26746
|
-
}
|
|
26747
|
-
if (!state) {
|
|
26748
|
-
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
26749
|
-
parsed = parsed ? parsed + s : s;
|
|
26750
|
-
}
|
|
26751
|
-
ctx.p += isMultiline ? 3 : 1;
|
|
26752
|
-
return parsed;
|
|
26753
|
-
} else if (!state) {
|
|
26754
|
-
if (!isLiteral && c === 92) {
|
|
26755
|
-
parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
|
|
26756
|
-
state = 1;
|
|
26757
|
-
}
|
|
26758
|
-
} else if (state === 1) {
|
|
26759
|
-
if (c === 120 || c === 117 || c === 85) {
|
|
26760
|
-
let errPtr = ctx.p++ - 1;
|
|
26761
|
-
let value = 0;
|
|
26762
|
-
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
26763
|
-
for (let j = 0; j < len; j++, ctx.p++) {
|
|
26764
|
-
let hex = ctx.s.charCodeAt(ctx.p);
|
|
26765
|
-
let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
|
|
26766
|
-
if (digit < 0) TomlError.x("invalid non-hex character in unicode escape", ctx);
|
|
26767
|
-
value = value << 4 | digit;
|
|
26768
|
-
}
|
|
26769
|
-
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) TomlError.x("invalid unicode escape", ctx, errPtr);
|
|
26770
|
-
parsed += String.fromCodePoint(value);
|
|
26771
|
-
sliceStart = ctx.p--;
|
|
26772
|
-
state = 0;
|
|
26773
|
-
} else if (isMultiline && (c === 32 || c === 9)) state = 2;
|
|
26774
|
-
else {
|
|
26775
|
-
if (c === 98) parsed += "\b";
|
|
26776
|
-
else if (c === 116) parsed += " ";
|
|
26777
|
-
else if (c === 110) parsed += "\n";
|
|
26778
|
-
else if (c === 102) parsed += "\f";
|
|
26779
|
-
else if (c === 114) parsed += "\r";
|
|
26780
|
-
else if (c === 101) parsed += "\x1B";
|
|
26781
|
-
else if (c === 34) parsed += '"';
|
|
26782
|
-
else if (c === 92) parsed += "\\";
|
|
26783
|
-
else TomlError.x("unrecognised escape sequence", ctx);
|
|
26784
|
-
sliceStart = ctx.p + 1;
|
|
26785
|
-
state = 0;
|
|
26786
|
-
}
|
|
26787
|
-
} else if (c !== 32 && c !== 9) {
|
|
26788
|
-
if (state === 2) TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
|
|
26789
|
-
state = !isLiteral && c === 92 ? 1 : 0;
|
|
26790
|
-
sliceStart = ctx.p;
|
|
26791
|
-
}
|
|
26792
|
-
}
|
|
26793
|
-
TomlError.x("unfinished string", ctx, startPtr);
|
|
26794
|
-
}
|
|
26795
|
-
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
26796
|
-
var TomlDate = class TomlDate2 extends Date {
|
|
26797
|
-
#hasDate = false;
|
|
26798
|
-
#hasTime = false;
|
|
26799
|
-
#offset = null;
|
|
26800
|
-
constructor(date, fasttype, unsafeDelim) {
|
|
26801
|
-
let hasDate = true;
|
|
26802
|
-
let hasTime = true;
|
|
26803
|
-
let offset = "Z";
|
|
26804
|
-
let c;
|
|
26805
|
-
if (typeof date === "string") {
|
|
26806
|
-
if (fasttype) prep: {
|
|
26807
|
-
if (fasttype < 3) {
|
|
26808
|
-
if (+date.slice(11, 13) > 23) {
|
|
26809
|
-
date = "";
|
|
26810
|
-
break prep;
|
|
26811
|
-
}
|
|
26812
|
-
if (fasttype === 2) {
|
|
26813
|
-
offset = null;
|
|
26814
|
-
date += "Z";
|
|
26815
|
-
} else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) offset = date.slice(date.length - 6);
|
|
26816
|
-
if (unsafeDelim) date = date.slice(0, 10) + "T" + date.slice(11);
|
|
26817
|
-
} else if (fasttype === 4) date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
|
|
26818
|
-
hasDate = fasttype !== 4;
|
|
26819
|
-
hasTime = fasttype !== 3;
|
|
26820
|
-
}
|
|
26821
|
-
else {
|
|
26822
|
-
let match = date.match(DATE_TIME_RE);
|
|
26823
|
-
if (match) {
|
|
26824
|
-
if (!match[1]) {
|
|
26825
|
-
hasDate = false;
|
|
26826
|
-
date = `0000-01-01T${date}`;
|
|
26827
|
-
}
|
|
26828
|
-
hasTime = !!match[2];
|
|
26829
|
-
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
26830
|
-
if (match[2] && +match[2] > 23) date = "";
|
|
26831
|
-
else {
|
|
26832
|
-
offset = match[3] || null;
|
|
26833
|
-
if (!offset && hasTime) date += "Z";
|
|
26834
|
-
}
|
|
26835
|
-
} else date = "";
|
|
26836
|
-
}
|
|
26837
|
-
}
|
|
26838
|
-
super(date);
|
|
26839
|
-
if (!isNaN(this.getTime())) {
|
|
26840
|
-
this.#hasDate = hasDate;
|
|
26841
|
-
this.#hasTime = hasTime;
|
|
26842
|
-
this.#offset = offset;
|
|
26843
|
-
}
|
|
26844
|
-
}
|
|
26845
|
-
isDateTime() {
|
|
26846
|
-
return this.#hasDate && this.#hasTime;
|
|
26847
|
-
}
|
|
26848
|
-
isLocal() {
|
|
26849
|
-
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
26850
|
-
}
|
|
26851
|
-
isDate() {
|
|
26852
|
-
return this.#hasDate && !this.#hasTime;
|
|
26853
|
-
}
|
|
26854
|
-
isTime() {
|
|
26855
|
-
return this.#hasTime && !this.#hasDate;
|
|
26856
|
-
}
|
|
26857
|
-
isValid() {
|
|
26858
|
-
return this.#hasDate || this.#hasTime;
|
|
26859
|
-
}
|
|
26860
|
-
toISOString() {
|
|
26861
|
-
let iso = super.toISOString();
|
|
26862
|
-
if (this.isDate()) return iso.slice(0, 10);
|
|
26863
|
-
if (this.isTime()) return iso.slice(11, 23);
|
|
26864
|
-
if (this.#offset === null) return iso.slice(0, -1);
|
|
26865
|
-
if (this.#offset === "Z" || this.#offset === "z") return iso;
|
|
26866
|
-
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
26867
|
-
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
26868
|
-
return (/* @__PURE__ */ new Date(this.getTime() - offset * 6e4)).toISOString().slice(0, -1) + this.#offset;
|
|
26869
|
-
}
|
|
26870
|
-
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
26871
|
-
let date = new TomlDate2(jsDate);
|
|
26872
|
-
date.#offset = offset;
|
|
26873
|
-
return date;
|
|
26874
|
-
}
|
|
26875
|
-
static wrapAsLocalDateTime(jsDate) {
|
|
26876
|
-
let date = new TomlDate2(jsDate);
|
|
26877
|
-
date.#offset = null;
|
|
26878
|
-
return date;
|
|
26879
|
-
}
|
|
26880
|
-
static wrapAsLocalDate(jsDate) {
|
|
26881
|
-
let date = new TomlDate2(jsDate);
|
|
26882
|
-
date.#hasTime = false;
|
|
26883
|
-
date.#offset = null;
|
|
26884
|
-
return date;
|
|
26885
|
-
}
|
|
26886
|
-
static wrapAsLocalTime(jsDate) {
|
|
26887
|
-
let date = new TomlDate2(jsDate);
|
|
26888
|
-
date.#hasDate = false;
|
|
26889
|
-
date.#offset = null;
|
|
26890
|
-
return date;
|
|
26891
|
-
}
|
|
26892
|
-
};
|
|
26893
|
-
function isDigit(char, base = 10) {
|
|
26894
|
-
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
26895
|
-
}
|
|
26896
|
-
function isEndOfValue(char, delim) {
|
|
26897
|
-
return char === 32 || char === 9 || char === 10 || char === 13 || delim && (char === delim || char === 44) || char === 35;
|
|
26898
|
-
}
|
|
26899
|
-
function extractValue(ctx, end) {
|
|
26900
|
-
let errPtr = ctx.p;
|
|
26901
|
-
let c = ctx.s.charCodeAt(ctx.p);
|
|
26902
|
-
if (c === 91 || c === 123) {
|
|
26903
|
-
ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
|
|
26904
|
-
let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
|
|
26905
|
-
ctx.d++;
|
|
26906
|
-
return value;
|
|
26907
|
-
}
|
|
26908
|
-
if (c === 34 || c === 39) return parseString(ctx);
|
|
26909
|
-
if (c === 116) {
|
|
26910
|
-
if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
|
|
26911
|
-
return ctx.p++, true;
|
|
26912
|
-
}
|
|
26913
|
-
if (c === 102) {
|
|
26914
|
-
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
|
|
26915
|
-
return ctx.p++, false;
|
|
26916
|
-
}
|
|
26917
|
-
if (c === 43 || c === 45) return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
|
|
26918
|
-
if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) return parseDate(ctx, c, end);
|
|
26919
|
-
if (ctx.s.charCodeAt(ctx.p + 2) === 58) return parseTime(ctx, c, end);
|
|
26920
|
-
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
26921
|
-
}
|
|
26922
|
-
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
26923
|
-
let c = startChr;
|
|
26924
|
-
let state = 0;
|
|
26925
|
-
let hasUnderscores = false;
|
|
26926
|
-
if (c === 105) {
|
|
26927
|
-
if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102) TomlError.x("invalid value", ctx, startPtr);
|
|
26928
|
-
return ctx.p++, (sign || 1) / 0;
|
|
26929
|
-
}
|
|
26930
|
-
if (c === 110) {
|
|
26931
|
-
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110) TomlError.x("invalid value", ctx, startPtr);
|
|
26932
|
-
return ctx.p++, NaN;
|
|
26933
|
-
}
|
|
26934
|
-
if (c === 48) {
|
|
26935
|
-
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr)) return ctx.bi === true ? 0n : 0;
|
|
26936
|
-
if (!sign) {
|
|
26937
|
-
if (c === 120) return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
26938
|
-
else if (c === 98) return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
26939
|
-
else if (c === 111) return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
26940
|
-
}
|
|
26941
|
-
if (c === 46) state = 2;
|
|
26942
|
-
else if (c === 101 || c === 69) state = 4;
|
|
26943
|
-
else TomlError.x("illegal leading zero", ctx, startPtr);
|
|
26944
|
-
} else if (!isDigit(c)) TomlError.x("invalid value", ctx, startPtr);
|
|
26945
|
-
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
26946
|
-
if (!state) state = 1;
|
|
26947
|
-
if (c === 95) {
|
|
26948
|
-
if (!(state & 1)) TomlError.x("illegal underscore", ctx);
|
|
26949
|
-
state += 11;
|
|
26950
|
-
hasUnderscores = true;
|
|
26951
|
-
} else if (state === 1 && c === 46) state = 2;
|
|
26952
|
-
else if ((state === 1 || state === 3) && (c === 101 || c === 69)) state = 4;
|
|
26953
|
-
else if (state === 4 && (c === 43 || c === 45)) state = 6;
|
|
26954
|
-
else if (!isDigit(c)) TomlError.x(`illegal character in numeric literal`, ctx);
|
|
26955
|
-
else if (state > 9) state -= 11;
|
|
26956
|
-
else if (!(state & 1)) state++;
|
|
26957
|
-
}
|
|
26958
|
-
if (!state) {
|
|
26959
|
-
let val = (startChr - 48) * (sign || 1);
|
|
26960
|
-
return ctx.bi === true ? BigInt(val) : val;
|
|
26961
|
-
}
|
|
26962
|
-
if (!(state & 1)) TomlError.x("unfinished numeric value", ctx, startPtr);
|
|
26963
|
-
let str3 = ctx.s.slice(startPtr, ctx.p);
|
|
26964
|
-
if (hasUnderscores) str3 = str3.replaceAll("_", "");
|
|
26965
|
-
return state > 1 ? parseFloat(str3) : parseInteger(ctx, str3, 10, startPtr);
|
|
26966
|
-
}
|
|
26967
|
-
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
26968
|
-
let c, underscore = 1;
|
|
26969
|
-
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) if (c === 95) {
|
|
26970
|
-
if (underscore & 1) TomlError.x("illegal underscore", ctx);
|
|
26971
|
-
underscore = 3;
|
|
26972
|
-
} else if (!isDigit(c, base)) TomlError.x(`illegal character in numeric literal`, ctx);
|
|
26973
|
-
else if (underscore & 1) underscore--;
|
|
26974
|
-
if (underscore & 1) TomlError.x("unfinished numeric value", ctx);
|
|
26975
|
-
let str3 = ctx.s.slice(startPtr + 2, ctx.p);
|
|
26976
|
-
if (underscore) str3 = str3.replaceAll("_", "");
|
|
26977
|
-
return parseInteger(ctx, str3, base, startPtr);
|
|
26978
|
-
}
|
|
26979
|
-
function parseInteger(ctx, str3, base, startPtr) {
|
|
26980
|
-
if (ctx.bi !== true) int: {
|
|
26981
|
-
let val = parseInt(str3, base);
|
|
26982
|
-
if (!Number.isSafeInteger(val)) {
|
|
26983
|
-
if (ctx.bi) break int;
|
|
26984
|
-
TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
|
|
26985
|
-
}
|
|
26986
|
-
return val;
|
|
26987
|
-
}
|
|
26988
|
-
return base === 10 ? BigInt(str3) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str3);
|
|
26989
|
-
}
|
|
26990
|
-
function parseDate(ctx, c, endChr) {
|
|
26991
|
-
let startPtr = ctx.p++, unsafeSeparator;
|
|
26992
|
-
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
26993
|
-
ctx.p += 5;
|
|
26994
|
-
if (!isDigit(ctx.s.charCodeAt(ctx.p++))) TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
26995
|
-
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 3, false, startPtr);
|
|
26996
|
-
if (ctx.s.charCodeAt(ctx.p += 3) !== 58) TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
26997
|
-
if (ctx.s.charCodeAt(ctx.p += 3) === 58) ctx.p += 3;
|
|
26998
|
-
if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p))) ;
|
|
26999
|
-
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
27000
|
-
if (c === 90 || c === 122) return readDate(ctx, ctx.s.slice(startPtr, ++ctx.p), 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
27001
|
-
if (c === 43 || c === 45) return readDate(ctx, ctx.s.slice(startPtr, ctx.p += 6), 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
27002
|
-
}
|
|
27003
|
-
return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 2, unsafeSeparator, startPtr);
|
|
27004
|
-
}
|
|
27005
|
-
function parseTime(ctx, c, endChr) {
|
|
27006
|
-
let start = ctx.p;
|
|
27007
|
-
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
27008
|
-
if (ctx.s.charCodeAt(ctx.p += 4) === 58) ctx.p += 3;
|
|
27009
|
-
if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p))) ;
|
|
27010
|
-
return readDate(ctx, ctx.s.slice(start, ctx.p), 4, false, start);
|
|
27011
|
-
}
|
|
27012
|
-
function readDate(ctx, str3, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
27013
|
-
if (ctx.ld) {
|
|
27014
|
-
let date = new TomlDate(str3, type, unsafeDelim);
|
|
27015
|
-
if (!date.isValid()) TomlError.x("invalid date", ctx, errPtr);
|
|
27016
|
-
return date;
|
|
27017
|
-
}
|
|
27018
|
-
try {
|
|
27019
|
-
if (temporalSuffix) str3 += temporalSuffix;
|
|
27020
|
-
switch (type) {
|
|
27021
|
-
case 1:
|
|
27022
|
-
return Temporal.ZonedDateTime.from(str3);
|
|
27023
|
-
case 2:
|
|
27024
|
-
return Temporal.PlainDateTime.from(str3);
|
|
27025
|
-
case 3:
|
|
27026
|
-
return Temporal.PlainDate.from(str3);
|
|
27027
|
-
case 4:
|
|
27028
|
-
return Temporal.PlainTime.from(str3);
|
|
27029
|
-
}
|
|
27030
|
-
} catch (e) {
|
|
27031
|
-
TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
|
|
27032
|
-
}
|
|
27033
|
-
}
|
|
27034
|
-
function skipComment(ctx) {
|
|
27035
|
-
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
27036
|
-
let c = ctx.s.charCodeAt(ctx.p);
|
|
27037
|
-
if (c === 10) break;
|
|
27038
|
-
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
27039
|
-
ctx.p++;
|
|
27040
|
-
break;
|
|
27041
|
-
}
|
|
27042
|
-
if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in comments", ctx);
|
|
27043
|
-
}
|
|
27044
|
-
}
|
|
27045
|
-
function skipVoid(ctx, banNewLines, banComments) {
|
|
27046
|
-
let c;
|
|
27047
|
-
while (ctx.p < ctx.s.length) {
|
|
27048
|
-
while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10))) ctx.p++;
|
|
27049
|
-
if (banComments || c !== 35) break;
|
|
27050
|
-
skipComment(ctx);
|
|
27051
|
-
}
|
|
27052
|
-
}
|
|
27053
|
-
function parseKey(ctx, end = 61) {
|
|
27054
|
-
let startPtr;
|
|
27055
|
-
let state = 0;
|
|
27056
|
-
let parsed = [];
|
|
27057
|
-
let sliceStart;
|
|
27058
|
-
let c = ctx.s.charCodeAt(startPtr = ctx.p);
|
|
27059
|
-
do
|
|
27060
|
-
if (c === end) {
|
|
27061
|
-
if (!state) TomlError.x("unexpected end of key", ctx);
|
|
27062
|
-
if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
27063
|
-
return ctx.p++, parsed;
|
|
27064
|
-
} else if (c === 46) {
|
|
27065
|
-
if (!state) TomlError.x("illegal empty bare key", ctx);
|
|
27066
|
-
if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
27067
|
-
state = 0;
|
|
27068
|
-
} else if (!state && (c === 34 || c === 39)) {
|
|
27069
|
-
if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2)) TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
|
|
27070
|
-
parsed.push(parseString(ctx));
|
|
27071
|
-
state = 2;
|
|
27072
|
-
ctx.p--;
|
|
27073
|
-
} else if (c === 32 || c === 9) {
|
|
27074
|
-
if (state === 1) {
|
|
27075
|
-
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
27076
|
-
state = 2;
|
|
27077
|
-
}
|
|
27078
|
-
} else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) TomlError.x("illegal character in key", ctx);
|
|
27079
|
-
else if (!state) {
|
|
27080
|
-
state = 1;
|
|
27081
|
-
sliceStart = ctx.p;
|
|
27082
|
-
}
|
|
27083
|
-
while (c = ctx.s.charCodeAt(++ctx.p));
|
|
27084
|
-
TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
|
|
27085
|
-
}
|
|
27086
|
-
function parseInlineTable(ctx) {
|
|
27087
|
-
let startPtr = ctx.p++;
|
|
27088
|
-
let res = /* @__PURE__ */ Object.create(null);
|
|
27089
|
-
let seen = /* @__PURE__ */ new Set();
|
|
27090
|
-
let c;
|
|
27091
|
-
while (ctx.p < ctx.s.length) {
|
|
27092
|
-
skipVoid(ctx);
|
|
27093
|
-
if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
|
|
27094
|
-
ctx.p++;
|
|
27095
|
-
return res;
|
|
27096
|
-
}
|
|
27097
|
-
let k;
|
|
27098
|
-
let t = res;
|
|
27099
|
-
let hasOwn = false;
|
|
27100
|
-
let errPtr = ctx.p;
|
|
27101
|
-
let key = parseKey(ctx);
|
|
27102
|
-
for (let i = 0; i < key.length; i++) {
|
|
27103
|
-
if (i) t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
27104
|
-
k = key[i];
|
|
27105
|
-
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
27106
|
-
let unsafe = k === "__proto__";
|
|
27107
|
-
if (ctx.uk && (unsafe || k === "constructor")) {
|
|
27108
|
-
t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
|
|
27109
|
-
break;
|
|
27110
|
-
}
|
|
27111
|
-
if (!hasOwn && unsafe) Object.defineProperty(t, k, {
|
|
27112
|
-
enumerable: true,
|
|
27113
|
-
configurable: true,
|
|
27114
|
-
writable: true
|
|
27115
|
-
});
|
|
27116
|
-
}
|
|
27117
|
-
if (hasOwn) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
27118
|
-
skipVoid(ctx, true, true);
|
|
27119
|
-
let value = extractValue(ctx, 125);
|
|
27120
|
-
if (t && typeof (t[k] = value) === "object") seen.add(value);
|
|
27121
|
-
skipVoid(ctx);
|
|
27122
|
-
if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) return res;
|
|
27123
|
-
if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
27124
|
-
}
|
|
27125
|
-
TomlError.x("unfinished table", ctx, startPtr);
|
|
27126
|
-
}
|
|
27127
|
-
function parseArray(ctx) {
|
|
27128
|
-
let startPtr = ctx.p++;
|
|
27129
|
-
let res = [];
|
|
27130
|
-
let c;
|
|
27131
|
-
while (ctx.p < ctx.s.length) {
|
|
27132
|
-
skipVoid(ctx);
|
|
27133
|
-
if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
|
|
27134
|
-
ctx.p++;
|
|
27135
|
-
return res;
|
|
27136
|
-
}
|
|
27137
|
-
res.push(extractValue(ctx, 93));
|
|
27138
|
-
skipVoid(ctx);
|
|
27139
|
-
if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) return res;
|
|
27140
|
-
if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
27141
|
-
}
|
|
27142
|
-
TomlError.x("unfinished array", ctx, startPtr);
|
|
27143
|
-
}
|
|
27144
|
-
function peekTable(ctx, key, table, meta, type) {
|
|
27145
|
-
let t = table;
|
|
27146
|
-
let m = meta;
|
|
27147
|
-
let k;
|
|
27148
|
-
let hasOwn = false;
|
|
27149
|
-
let state;
|
|
27150
|
-
for (let i = 0; i < key.length; i++) {
|
|
27151
|
-
if (i) {
|
|
27152
|
-
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
27153
|
-
m = (state = m[k]).c;
|
|
27154
|
-
if (type === 0 && (state.t === 1 || state.t === 2)) return null;
|
|
27155
|
-
if (state.t === 2) {
|
|
27156
|
-
let l = t.length - 1;
|
|
27157
|
-
t = t[l];
|
|
27158
|
-
m = m[l].c;
|
|
27159
|
-
}
|
|
27160
|
-
}
|
|
27161
|
-
k = key[i];
|
|
27162
|
-
if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) return null;
|
|
27163
|
-
if (!hasOwn) {
|
|
27164
|
-
let unsafe = k === "__proto__";
|
|
27165
|
-
if (ctx.uk && (unsafe || k === "constructor")) return false;
|
|
27166
|
-
if (unsafe) {
|
|
27167
|
-
Object.defineProperty(t, k, {
|
|
27168
|
-
enumerable: true,
|
|
27169
|
-
configurable: true,
|
|
27170
|
-
writable: true
|
|
27171
|
-
});
|
|
27172
|
-
Object.defineProperty(m, k, {
|
|
27173
|
-
enumerable: true,
|
|
27174
|
-
configurable: true,
|
|
27175
|
-
writable: true
|
|
27176
|
-
});
|
|
27177
|
-
}
|
|
27178
|
-
m[k] = {
|
|
27179
|
-
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
27180
|
-
d: false,
|
|
27181
|
-
i: 0,
|
|
27182
|
-
c: /* @__PURE__ */ Object.create(null)
|
|
27183
|
-
};
|
|
27184
|
-
}
|
|
27185
|
-
}
|
|
27186
|
-
state = m[k];
|
|
27187
|
-
if (state.t !== type && !(type === 1 && state.t === 3)) return null;
|
|
27188
|
-
if (type === 2) {
|
|
27189
|
-
if (!state.d) {
|
|
27190
|
-
state.d = true;
|
|
27191
|
-
t[k] = [];
|
|
27192
|
-
}
|
|
27193
|
-
t[k].push(t = /* @__PURE__ */ Object.create(null));
|
|
27194
|
-
state.c[state.i++] = state = {
|
|
27195
|
-
t: 1,
|
|
27196
|
-
d: false,
|
|
27197
|
-
i: 0,
|
|
27198
|
-
c: /* @__PURE__ */ Object.create(null)
|
|
27199
|
-
};
|
|
27200
|
-
}
|
|
27201
|
-
if (state.d) return null;
|
|
27202
|
-
state.d = true;
|
|
27203
|
-
if (type === 1) t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
27204
|
-
else if (type === 0 && hasOwn) return null;
|
|
27205
|
-
return [
|
|
27206
|
-
k,
|
|
27207
|
-
t,
|
|
27208
|
-
state.c
|
|
27209
|
-
];
|
|
27210
|
-
}
|
|
27211
|
-
function validateTablePeek(ctx, peek, ptr) {
|
|
27212
|
-
if (peek === null || ctx.uk === 2) TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
|
|
27213
|
-
}
|
|
27214
|
-
function parse2(toml, options = {}) {
|
|
27215
|
-
let ctx = {
|
|
27216
|
-
s: toml,
|
|
27217
|
-
p: 0,
|
|
27218
|
-
d: options.maxDepth ?? 1e3,
|
|
27219
|
-
bi: options.integersAsBigInt ?? false,
|
|
27220
|
-
ld: options.useLegacyDate ?? true,
|
|
27221
|
-
uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
|
|
27222
|
-
};
|
|
27223
|
-
let res = /* @__PURE__ */ Object.create(null);
|
|
27224
|
-
let meta = /* @__PURE__ */ Object.create(null);
|
|
27225
|
-
let tmp;
|
|
27226
|
-
let skipping = false;
|
|
27227
|
-
let tbl = res;
|
|
27228
|
-
let m = meta;
|
|
27229
|
-
if (toml.charCodeAt(0) === 65279) ctx.p++;
|
|
27230
|
-
skipVoid(ctx);
|
|
27231
|
-
while (ctx.p < toml.length) {
|
|
27232
|
-
if (toml.charCodeAt(ctx.p) === 91) {
|
|
27233
|
-
let isTableArray = toml.charCodeAt(++ctx.p) === 91;
|
|
27234
|
-
tmp = ctx.p += +isTableArray;
|
|
27235
|
-
skipping = false;
|
|
27236
|
-
let k = parseKey(ctx, 93);
|
|
27237
|
-
if (isTableArray) {
|
|
27238
|
-
if (toml.charCodeAt(ctx.p) !== 93) TomlError.x("expected end of table array declaration", ctx);
|
|
27239
|
-
ctx.p++;
|
|
27240
|
-
}
|
|
27241
|
-
let p = peekTable(ctx, k, res, meta, isTableArray ? 2 : 1);
|
|
27242
|
-
if (!p) {
|
|
27243
|
-
validateTablePeek(ctx, p, tmp);
|
|
27244
|
-
skipping = true;
|
|
27245
|
-
} else {
|
|
27246
|
-
m = p[2];
|
|
27247
|
-
tbl = p[1];
|
|
27248
|
-
}
|
|
27249
|
-
} else {
|
|
27250
|
-
tmp = ctx.p;
|
|
27251
|
-
let p = peekTable(ctx, parseKey(ctx), tbl, m, 0);
|
|
27252
|
-
if (!p && !skipping) validateTablePeek(ctx, p, tmp);
|
|
27253
|
-
skipVoid(ctx, true, true);
|
|
27254
|
-
let v = extractValue(ctx, void 0);
|
|
27255
|
-
if (p && !skipping) p[1][p[0]] = v;
|
|
27256
|
-
}
|
|
27257
|
-
skipVoid(ctx, true);
|
|
27258
|
-
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
|
|
27259
|
-
skipVoid(ctx);
|
|
27260
|
-
}
|
|
27261
|
-
return res;
|
|
27262
|
-
}
|
|
27263
|
-
var BARE_KEY = /^[a-z0-9-_]+$/i;
|
|
27264
|
-
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
27265
|
-
function extendedTypeOf(obj2) {
|
|
27266
|
-
let type = typeof obj2;
|
|
27267
|
-
if (type === "object") {
|
|
27268
|
-
if (Array.isArray(obj2)) return "array";
|
|
27269
|
-
if (typeof obj2.getUTCDate === "function" && obj2 instanceof Date) return "date";
|
|
27270
|
-
if (globalThis.Temporal) {
|
|
27271
|
-
if (obj2.until) {
|
|
27272
|
-
if (obj2 instanceof Temporal.ZonedDateTime) return "temporal/tz+uc";
|
|
27273
|
-
if (obj2 instanceof Temporal.PlainDateTime || obj2 instanceof Temporal.PlainDate) return "temporal/uc";
|
|
27274
|
-
if (obj2 instanceof Temporal.PlainTime || obj2 instanceof Temporal.Instant) return "temporal";
|
|
27275
|
-
if (obj2 instanceof Temporal.PlainYearMonth) return "temporal/x";
|
|
27276
|
-
} else if (obj2.toPlainDate && obj2 instanceof Temporal.PlainMonthDay || obj2.negated && obj2 instanceof Temporal.Duration) return "temporal/x";
|
|
27277
|
-
}
|
|
27278
|
-
}
|
|
27279
|
-
return type;
|
|
27280
|
-
}
|
|
27281
|
-
function isArrayOfTables(obj2) {
|
|
27282
|
-
for (let i = 0; i < obj2.length; i++) if (extendedTypeOf(obj2[i]) !== "object") return false;
|
|
27283
|
-
return obj2.length != 0;
|
|
27284
|
-
}
|
|
27285
|
-
function formatWellFormedStringUnchecked(s) {
|
|
27286
|
-
return JSON.stringify(s).replaceAll("\x7F", "\\u007f");
|
|
27287
|
-
}
|
|
27288
|
-
function formatString(s) {
|
|
27289
|
-
return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
|
|
27290
|
-
}
|
|
27291
|
-
function formatKey(s) {
|
|
27292
|
-
if (BARE_KEY.test(s)) return s;
|
|
27293
|
-
if (HAS_WELLFORMED && !s.isWellFormed()) throw new RangeError("key contains illegal lone surrogates");
|
|
27294
|
-
return formatWellFormedStringUnchecked(s);
|
|
27295
|
-
}
|
|
27296
|
-
function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
|
|
27297
|
-
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
27298
|
-
switch (type) {
|
|
27299
|
-
case "number":
|
|
27300
|
-
if (isNaN(val)) return "nan";
|
|
27301
|
-
if (val === Infinity) return "inf";
|
|
27302
|
-
if (val === -Infinity) return "-inf";
|
|
27303
|
-
if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val))) return val.toFixed(1);
|
|
27304
|
-
case "bigint":
|
|
27305
|
-
case "boolean":
|
|
27306
|
-
case "temporal":
|
|
27307
|
-
return val.toString();
|
|
27308
|
-
case "string":
|
|
27309
|
-
return formatString(val);
|
|
27310
|
-
case "date":
|
|
27311
|
-
if (isNaN(val.getTime())) throw new TypeError("cannot serialize invalid date");
|
|
27312
|
-
return val.toISOString();
|
|
27313
|
-
case "object":
|
|
27314
|
-
return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
|
|
27315
|
-
case "array":
|
|
27316
|
-
return stringifyArray(val, depth, numberAsFloat, strictTemporal);
|
|
27317
|
-
case "temporal/tz+uc":
|
|
27318
|
-
if (strictTemporal) {
|
|
27319
|
-
let tz = val.timeZoneId;
|
|
27320
|
-
let tzc = tz.charCodeAt(0);
|
|
27321
|
-
if (tzc !== 43 && tzc !== 45 && (tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || tz !== "UTC" && tz !== "UCT" && tz !== "Universal" && tz !== "Zulu" && !tz.startsWith("GMT") && tz !== "Greenwich" && !tz.startsWith("Etc/"))) throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
|
|
27322
|
-
}
|
|
27323
|
-
case "temporal/uc":
|
|
27324
|
-
if (strictTemporal && val.calendarId !== "iso8601") throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
|
|
27325
|
-
return val.toString({
|
|
27326
|
-
calendarName: "never",
|
|
27327
|
-
timeZoneName: "never"
|
|
27328
|
-
});
|
|
27329
|
-
case "temporal/x":
|
|
27330
|
-
throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
|
|
27331
|
-
}
|
|
27332
|
-
}
|
|
27333
|
-
function stringifyInlineTable(obj2, depth, numberAsFloat, strictTemporal) {
|
|
27334
|
-
let keys = Object.keys(obj2);
|
|
27335
|
-
if (keys.length === 0) return "{}";
|
|
27336
|
-
let res = "{ ";
|
|
27337
|
-
for (let i = 0; i < keys.length; i++) {
|
|
27338
|
-
let k = keys[i];
|
|
27339
|
-
if (i) res += ", ";
|
|
27340
|
-
res += formatKey(k) + " = " + stringifyValue(obj2[k], extendedTypeOf(obj2[k]), depth - 1, numberAsFloat, strictTemporal);
|
|
27341
|
-
}
|
|
27342
|
-
return res + " }";
|
|
27343
|
-
}
|
|
27344
|
-
function stringifyArray(array, depth, numberAsFloat, strictTemporal) {
|
|
27345
|
-
if (array.length === 0) return "[]";
|
|
27346
|
-
let res = "[ ";
|
|
27347
|
-
for (let i = 0; i < array.length; i++) {
|
|
27348
|
-
if (i) res += ", ";
|
|
27349
|
-
if (array[i] === null || array[i] === void 0) throw new TypeError("arrays cannot contain null or undefined values");
|
|
27350
|
-
res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat, strictTemporal);
|
|
27351
|
-
}
|
|
27352
|
-
return res + " ]";
|
|
27353
|
-
}
|
|
27354
|
-
function stringifyArrayTable(array, key, depth, numberAsFloat, strictTemporal) {
|
|
27355
|
-
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
27356
|
-
let res = "";
|
|
27357
|
-
for (let i = 0; i < array.length; i++) {
|
|
27358
|
-
res += `${res && "\n"}[[${key}]]
|
|
27359
|
-
`;
|
|
27360
|
-
res += stringifyTable(0, array[i], key, depth, numberAsFloat, strictTemporal);
|
|
27361
|
-
}
|
|
27362
|
-
return res;
|
|
27363
|
-
}
|
|
27364
|
-
function stringifyTable(tableKey, obj2, prefix, depth, numberAsFloat, strictTemporal) {
|
|
27365
|
-
if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
27366
|
-
let preamble = "";
|
|
27367
|
-
let tables = "";
|
|
27368
|
-
let keys = Object.keys(obj2);
|
|
27369
|
-
for (let i = 0; i < keys.length; i++) {
|
|
27370
|
-
let k = keys[i];
|
|
27371
|
-
if (obj2[k] !== null && obj2[k] !== void 0) {
|
|
27372
|
-
let type = extendedTypeOf(obj2[k]);
|
|
27373
|
-
if (type === "symbol" || type === "function") throw new TypeError(`cannot serialize values of type '${type}'`);
|
|
27374
|
-
let key = formatKey(k);
|
|
27375
|
-
if (type === "array" && isArrayOfTables(obj2[k])) tables += (tables && "\n") + stringifyArrayTable(obj2[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
|
|
27376
|
-
else if (type === "object") {
|
|
27377
|
-
let tblKey = prefix ? `${prefix}.${key}` : key;
|
|
27378
|
-
tables += (tables && "\n") + stringifyTable(tblKey, obj2[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
|
|
27379
|
-
} else {
|
|
27380
|
-
preamble += key;
|
|
27381
|
-
preamble += " = ";
|
|
27382
|
-
preamble += stringifyValue(obj2[k], type, depth, numberAsFloat, strictTemporal);
|
|
27383
|
-
preamble += "\n";
|
|
27384
|
-
}
|
|
27385
|
-
}
|
|
27386
|
-
}
|
|
27387
|
-
if (tableKey && (preamble || !tables)) preamble = preamble ? `[${tableKey}]
|
|
27388
|
-
${preamble}` : `[${tableKey}]`;
|
|
27389
|
-
return preamble && tables ? `${preamble}
|
|
27390
|
-
${tables}` : preamble || tables;
|
|
27391
|
-
}
|
|
27392
|
-
function stringify(obj2, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
|
|
27393
|
-
if (extendedTypeOf(obj2) !== "object") throw new TypeError("stringify can only be called with an object");
|
|
27394
|
-
let str3 = stringifyTable(0, obj2, "", maxDepth, numbersAsFloat, strictTemporal);
|
|
27395
|
-
if (str3[str3.length - 1] !== "\n") return str3 + "\n";
|
|
27396
|
-
return str3;
|
|
27397
|
-
}
|
|
27398
|
-
var src_default = {
|
|
27399
|
-
parse: parse2,
|
|
27400
|
-
stringify,
|
|
27401
|
-
TomlDate,
|
|
27402
|
-
TomlError
|
|
27403
|
-
};
|
|
27404
|
-
exports.TomlDate = TomlDate;
|
|
27405
|
-
exports.TomlError = TomlError;
|
|
27406
|
-
exports.default = src_default;
|
|
27407
|
-
exports.parse = parse2;
|
|
27408
|
-
exports.stringify = stringify;
|
|
27409
|
-
}
|
|
27410
|
-
});
|
|
26676
|
+
// ../cli/src/lib/shared/conversation.ts
|
|
26677
|
+
function bounded(work, ms, reason) {
|
|
26678
|
+
return new Promise((resolve, reject) => {
|
|
26679
|
+
const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
|
|
26680
|
+
work.then((value) => {
|
|
26681
|
+
clearTimeout(timer);
|
|
26682
|
+
resolve(value);
|
|
26683
|
+
}, (error) => {
|
|
26684
|
+
clearTimeout(timer);
|
|
26685
|
+
reject(error);
|
|
26686
|
+
});
|
|
26687
|
+
});
|
|
26688
|
+
}
|
|
27411
26689
|
|
|
27412
|
-
// src/codex-
|
|
27413
|
-
import
|
|
27414
|
-
import
|
|
26690
|
+
// src/codex-native.ts
|
|
26691
|
+
import crypto from "node:crypto";
|
|
26692
|
+
import fs3 from "node:fs";
|
|
26693
|
+
var import_undici2 = __toESM(require_undici(), 1);
|
|
26694
|
+
import path4 from "node:path";
|
|
26695
|
+
import { PassThrough, Writable } from "node:stream";
|
|
27415
26696
|
|
|
27416
|
-
// ../cli/src/lib/
|
|
27417
|
-
import {
|
|
27418
|
-
import fs2 from "node:fs";
|
|
27419
|
-
import path3 from "node:path";
|
|
26697
|
+
// ../cli/src/lib/agent/connection-process.ts
|
|
26698
|
+
import { spawnSync } from "node:child_process";
|
|
27420
26699
|
|
|
27421
26700
|
// ../cli/src/lib/paths.ts
|
|
27422
26701
|
import path2 from "node:path";
|
|
@@ -27459,12 +26738,12 @@ function rootAbove(board) {
|
|
|
27459
26738
|
const parent = path.dirname(board);
|
|
27460
26739
|
return ["docs", ".akb"].includes(path.basename(parent)) ? path.dirname(parent) : parent;
|
|
27461
26740
|
}
|
|
27462
|
-
function projectStateDir(board,
|
|
27463
|
-
const relative = path.relative(realPathOf(
|
|
26741
|
+
function projectStateDir(board, root = stateRootOf(board)) {
|
|
26742
|
+
const relative = path.relative(realPathOf(root), realPathOf(board));
|
|
27464
26743
|
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
27465
26744
|
throw new Error("The board must be inside its project root.");
|
|
27466
26745
|
}
|
|
27467
|
-
return path.join(realPathOf(
|
|
26746
|
+
return path.join(realPathOf(root), ".akb", "boards", relative || "_root");
|
|
27468
26747
|
}
|
|
27469
26748
|
|
|
27470
26749
|
// ../cli/src/lib/paths.ts
|
|
@@ -27505,14 +26784,14 @@ var SIGNALS_OLD_INBOX = "";
|
|
|
27505
26784
|
var SIGNALS_OLD_HANDLED = "";
|
|
27506
26785
|
var AKB_DIR = "";
|
|
27507
26786
|
var ROOT_GITIGNORE = "";
|
|
27508
|
-
function boardLockName(kanban,
|
|
27509
|
-
const from = path2.relative(
|
|
26787
|
+
function boardLockName(kanban, root) {
|
|
26788
|
+
const from = path2.relative(root, kanban);
|
|
27510
26789
|
const name = from && !from.startsWith("..") ? from : path2.basename(kanban);
|
|
27511
26790
|
return `${name.split(path2.sep).join("-")}.lock`;
|
|
27512
26791
|
}
|
|
27513
26792
|
var BOARD_FLAG = "";
|
|
27514
|
-
function setBoard(kanban,
|
|
27515
|
-
REPO_ROOT = path2.resolve(
|
|
26793
|
+
function setBoard(kanban, root, flag) {
|
|
26794
|
+
REPO_ROOT = path2.resolve(root);
|
|
27516
26795
|
KANBAN = path2.resolve(kanban);
|
|
27517
26796
|
BOARD_FLAG = flag;
|
|
27518
26797
|
TODO = path2.join(KANBAN, "todo");
|
|
@@ -27553,1141 +26832,23 @@ function setBoard(kanban, root2, flag) {
|
|
|
27553
26832
|
LOCK = path2.join(AKB_DIR, boardLockName(KANBAN, REPO_ROOT));
|
|
27554
26833
|
return REPO_ROOT;
|
|
27555
26834
|
}
|
|
27556
|
-
function setBoardRoot(
|
|
27557
|
-
const project = path2.resolve(
|
|
26835
|
+
function setBoardRoot(root, named = false) {
|
|
26836
|
+
const project = path2.resolve(root);
|
|
27558
26837
|
return setBoard(path2.join(project, "docs", "kanban"), project, named ? ` --dir ${project}` : "");
|
|
27559
26838
|
}
|
|
27560
26839
|
setBoardRoot(process.cwd());
|
|
27561
26840
|
|
|
27562
|
-
// ../cli/src/lib/
|
|
27563
|
-
function
|
|
27564
|
-
|
|
27565
|
-
|
|
27566
|
-
process.kill(pid, 0);
|
|
27567
|
-
return true;
|
|
27568
|
-
} catch (e) {
|
|
27569
|
-
return e.code === "EPERM";
|
|
27570
|
-
}
|
|
27571
|
-
}
|
|
27572
|
-
function removeClaim(dir, token) {
|
|
27573
|
-
if (token) {
|
|
27574
|
-
try {
|
|
27575
|
-
fs2.unlinkSync(path3.join(dir, token));
|
|
27576
|
-
} catch (err) {
|
|
27577
|
-
if (err.code !== "ENOENT") throw err;
|
|
27578
|
-
}
|
|
27579
|
-
}
|
|
27580
|
-
try {
|
|
27581
|
-
fs2.rmdirSync(dir);
|
|
27582
|
-
return true;
|
|
27583
|
-
} catch (err) {
|
|
27584
|
-
const code = err.code;
|
|
27585
|
-
if (code === "ENOENT") return true;
|
|
27586
|
-
if (code === "ENOTEMPTY" || code === "EEXIST") return false;
|
|
27587
|
-
throw err;
|
|
27588
|
-
}
|
|
27589
|
-
}
|
|
27590
|
-
function tryLock(dir) {
|
|
27591
|
-
fs2.mkdirSync(path3.dirname(dir), { recursive: true });
|
|
27592
|
-
const token = `${process.pid}-${randomUUID()}`;
|
|
27593
|
-
const candidate = fs2.mkdtempSync(`${dir}.`);
|
|
27594
|
-
try {
|
|
27595
|
-
fs2.writeFileSync(path3.join(candidate, token), "");
|
|
27596
|
-
for (; ; ) {
|
|
27597
|
-
try {
|
|
27598
|
-
fs2.renameSync(candidate, dir);
|
|
27599
|
-
return () => {
|
|
27600
|
-
removeClaim(dir, token);
|
|
27601
|
-
};
|
|
27602
|
-
} catch (err) {
|
|
27603
|
-
const code = err.code;
|
|
27604
|
-
if (code !== "ENOTEMPTY" && code !== "EEXIST") throw err;
|
|
27605
|
-
}
|
|
27606
|
-
let entries;
|
|
27607
|
-
try {
|
|
27608
|
-
entries = fs2.readdirSync(dir);
|
|
27609
|
-
} catch (err) {
|
|
27610
|
-
if (err.code === "ENOENT") continue;
|
|
27611
|
-
throw err;
|
|
27612
|
-
}
|
|
27613
|
-
if (entries.length) {
|
|
27614
|
-
if (entries.length !== 1 || !/^\d+-[a-f0-9-]{36}$/.test(entries[0])) return void 0;
|
|
27615
|
-
const owner = Number(entries[0].split("-")[0]);
|
|
27616
|
-
if (pidAlive(owner)) return void 0;
|
|
27617
|
-
}
|
|
27618
|
-
if (!removeClaim(dir, entries[0])) return void 0;
|
|
27619
|
-
}
|
|
27620
|
-
} finally {
|
|
27621
|
-
fs2.rmSync(candidate, { recursive: true, force: true });
|
|
27622
|
-
}
|
|
27623
|
-
}
|
|
27624
|
-
|
|
27625
|
-
// src/cache.ts
|
|
27626
|
-
import crypto2 from "node:crypto";
|
|
27627
|
-
import fs11 from "node:fs";
|
|
27628
|
-
import path13 from "node:path";
|
|
27629
|
-
|
|
27630
|
-
// ../cli/src/lib/agent/cloud-studios.ts
|
|
27631
|
-
import fs8 from "node:fs";
|
|
27632
|
-
import path10 from "node:path";
|
|
27633
|
-
|
|
27634
|
-
// ../cli/src/lib/shared/file-limits.ts
|
|
27635
|
-
var BOARD_FILE_LIMIT = 10 * 1024 * 1024;
|
|
27636
|
-
var ASSET_FILE_LIMIT = 100 * 1024 * 1024;
|
|
27637
|
-
|
|
27638
|
-
// ../cli/src/lib/shared/board-files.ts
|
|
27639
|
-
var studioFolder = (id) => id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
27640
|
-
var studioName = (id) => id.startsWith("wf_builtin_") ? id.slice("wf_builtin_".length).replace(/_/g, "-") : studioFolder(id);
|
|
27641
|
-
|
|
27642
|
-
// ../official/pack.ts
|
|
27643
|
-
import crypto from "node:crypto";
|
|
27644
|
-
import fs4 from "node:fs";
|
|
27645
|
-
import path5 from "node:path";
|
|
27646
|
-
import { fileURLToPath } from "node:url";
|
|
27647
|
-
|
|
27648
|
-
// ../cli/src/lib/agents/icon.ts
|
|
27649
|
-
var ICON_NAMES = [
|
|
27650
|
-
"file",
|
|
27651
|
-
"text",
|
|
27652
|
-
"article",
|
|
27653
|
-
"outline",
|
|
27654
|
-
"script",
|
|
27655
|
-
"prompt",
|
|
27656
|
-
"email",
|
|
27657
|
-
"image",
|
|
27658
|
-
"post-image",
|
|
27659
|
-
"social-image",
|
|
27660
|
-
"cover",
|
|
27661
|
-
"carousel",
|
|
27662
|
-
"carousel-outline",
|
|
27663
|
-
"slides",
|
|
27664
|
-
"wireframe",
|
|
27665
|
-
"screen",
|
|
27666
|
-
"video",
|
|
27667
|
-
"storyboard",
|
|
27668
|
-
"template",
|
|
27669
|
-
"shots",
|
|
27670
|
-
"api",
|
|
27671
|
-
"schema",
|
|
27672
|
-
"compare",
|
|
27673
|
-
"stack",
|
|
27674
|
-
"studio",
|
|
27675
|
-
"code",
|
|
27676
|
-
"checklist",
|
|
27677
|
-
"card",
|
|
27678
|
-
"plan",
|
|
27679
|
-
"proposal",
|
|
27680
|
-
"dismissed",
|
|
27681
|
-
"inbox",
|
|
27682
|
-
"notebook",
|
|
27683
|
-
"squeeze",
|
|
27684
|
-
"folder",
|
|
27685
|
-
"reply",
|
|
27686
|
-
"feedback",
|
|
27687
|
-
"software",
|
|
27688
|
-
"product-video",
|
|
27689
|
-
"social-post",
|
|
27690
|
-
"blog",
|
|
27691
|
-
"deck",
|
|
27692
|
-
"video-clone",
|
|
27693
|
-
"studio-kit"
|
|
27694
|
-
];
|
|
27695
|
-
var ICON_COLORS = ["k", "w", "c", "g", "o", "p", "s", "m", "l", "r", "y"];
|
|
27696
|
-
var PATH = /^[MmLlHhVvCcSsQqTtAaZz0-9.,\s-]+$/;
|
|
27697
|
-
var isColor = (v) => ICON_COLORS.includes(v);
|
|
27698
|
-
function readIcon(raw) {
|
|
27699
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
27700
|
-
if (typeof raw === "string") return ICON_NAMES.includes(raw.trim()) ? raw.trim() : { problem: `"${raw}" is not a glyph name` };
|
|
27701
|
-
if (!Array.isArray(raw) || !raw.length || raw.length > 12) return { problem: "the value is neither a glyph name nor a list of 1 to 12 parts" };
|
|
27702
|
-
const parts = [];
|
|
27703
|
-
for (const [i, item] of raw.entries()) {
|
|
27704
|
-
const at = `part ${i + 1}`;
|
|
27705
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) return { problem: `${at} is not a map of \`d\`, \`f\`, \`o\`, \`s\`, \`w\`` };
|
|
27706
|
-
const { d, f, o, s, w, ...extra } = item;
|
|
27707
|
-
if (Object.keys(extra).length) return { problem: `${at} has \`${Object.keys(extra).join("`, `")}\`` };
|
|
27708
|
-
if (typeof d !== "string" || !PATH.test(d)) return { problem: `${at} has no \`d\` of SVG path commands and numbers` };
|
|
27709
|
-
const part = { d: d.trim() };
|
|
27710
|
-
for (const [key, value] of [["f", f], ["s", s]]) {
|
|
27711
|
-
if (value === void 0) continue;
|
|
27712
|
-
if (typeof value !== "string" || !isColor(value)) return { problem: `${at} colours \`${key}\` with "${String(value)}"` };
|
|
27713
|
-
part[key] = value;
|
|
27714
|
-
}
|
|
27715
|
-
if (o !== void 0) {
|
|
27716
|
-
if (o !== "true") return { problem: `${at} has \`o: ${String(o)}\`, not \`true\`` };
|
|
27717
|
-
part.o = true;
|
|
27718
|
-
}
|
|
27719
|
-
if (w !== void 0) {
|
|
27720
|
-
const width = typeof w === "string" ? Number(w) : NaN;
|
|
27721
|
-
if (!(width > 0 && width <= 3)) return { problem: `${at} has \`w: ${String(w)}\`, not above 0 and up to 3` };
|
|
27722
|
-
part.w = width;
|
|
27723
|
-
}
|
|
27724
|
-
parts.push(part);
|
|
27725
|
-
}
|
|
27726
|
-
return parts;
|
|
27727
|
-
}
|
|
27728
|
-
|
|
27729
|
-
// ../cli/src/lib/yaml.ts
|
|
27730
|
-
function unquote(v) {
|
|
27731
|
-
const text2 = String(v).trim();
|
|
27732
|
-
if (text2.startsWith('"') && text2.endsWith('"')) {
|
|
27733
|
-
try {
|
|
27734
|
-
return JSON.parse(text2);
|
|
27735
|
-
} catch {
|
|
27736
|
-
return text2.slice(1, -1);
|
|
27737
|
-
}
|
|
27738
|
-
}
|
|
27739
|
-
if (text2.startsWith("'") && text2.endsWith("'")) return text2.slice(1, -1);
|
|
27740
|
-
return text2;
|
|
27741
|
-
}
|
|
27742
|
-
|
|
27743
|
-
// ../cli/src/lib/agents/yaml.ts
|
|
27744
|
-
function stripComment(value) {
|
|
27745
|
-
let from = 0;
|
|
27746
|
-
const quote = value[0];
|
|
27747
|
-
if (quote === '"' || quote === "'") {
|
|
27748
|
-
let i = 1;
|
|
27749
|
-
while (i < value.length) {
|
|
27750
|
-
if (quote === '"' && value[i] === "\\") i += 2;
|
|
27751
|
-
else if (value[i] === quote && quote === "'" && value[i + 1] === "'") i += 2;
|
|
27752
|
-
else if (value[i] === quote) break;
|
|
27753
|
-
else i++;
|
|
27754
|
-
}
|
|
27755
|
-
from = i + 1;
|
|
27756
|
-
}
|
|
27757
|
-
const hash = value.slice(from).search(/(^|[ \t])#/);
|
|
27758
|
-
return hash < 0 ? value : value.slice(0, from + hash).trim();
|
|
27759
|
-
}
|
|
27760
|
-
var readLines = (text2) => text2.split("\n").map((raw) => ({ indent: raw.match(/^[ \t]*/)[0].length, text: raw.trim() })).filter((line) => line.text && !line.text.startsWith("#"));
|
|
27761
|
-
function parseYamlBlock(text2) {
|
|
27762
|
-
const [map2] = readMap(readLines(text2), 0, 0);
|
|
27763
|
-
return map2;
|
|
27764
|
-
}
|
|
27765
|
-
function readMap(lines, start, indent) {
|
|
27766
|
-
const out = {};
|
|
27767
|
-
let i = start;
|
|
27768
|
-
while (i < lines.length && lines[i].indent >= indent) {
|
|
27769
|
-
const line = lines[i];
|
|
27770
|
-
if (line.indent > indent) {
|
|
27771
|
-
i++;
|
|
27772
|
-
continue;
|
|
27773
|
-
}
|
|
27774
|
-
if (line.text.startsWith("-")) break;
|
|
27775
|
-
const match = line.text.match(/^([^:]+):\s*(.*)$/);
|
|
27776
|
-
if (!match) {
|
|
27777
|
-
i++;
|
|
27778
|
-
continue;
|
|
27779
|
-
}
|
|
27780
|
-
const key = match[1].trim();
|
|
27781
|
-
const inline = stripComment(match[2].trim());
|
|
27782
|
-
i++;
|
|
27783
|
-
if (inline) {
|
|
27784
|
-
out[key] = readScalar(inline);
|
|
27785
|
-
continue;
|
|
27786
|
-
}
|
|
27787
|
-
const [value, next] = readBlock(lines, i, indent);
|
|
27788
|
-
out[key] = value;
|
|
27789
|
-
i = next;
|
|
27790
|
-
}
|
|
27791
|
-
return [out, i];
|
|
27792
|
-
}
|
|
27793
|
-
function readScalar(value) {
|
|
27794
|
-
if (value.startsWith("{") && value.endsWith("}")) {
|
|
27795
|
-
const entries = value.slice(1, -1).match(/(?:[^,"']|"(?:\\.|[^"\\])*"|'(?:''|[^'])*')+/g) ?? [];
|
|
27796
|
-
const out = {};
|
|
27797
|
-
for (const entry of entries) {
|
|
27798
|
-
const pair = /^\s*([^:]+):\s*(.+)$/.exec(entry);
|
|
27799
|
-
if (!pair) return value;
|
|
27800
|
-
out[unquote(pair[1].trim())] = readScalar(pair[2].trim());
|
|
27801
|
-
}
|
|
27802
|
-
return out;
|
|
27803
|
-
}
|
|
27804
|
-
const flow = value.match(/^\[(.*)\]$/);
|
|
27805
|
-
if (!flow) return unquote(value);
|
|
27806
|
-
return flow[1].split(",").map((item) => unquote(item.trim())).filter(Boolean);
|
|
27807
|
-
}
|
|
27808
|
-
function readBlock(lines, start, parentIndent) {
|
|
27809
|
-
if (start >= lines.length || lines[start].indent <= parentIndent) return ["", start];
|
|
27810
|
-
const indent = lines[start].indent;
|
|
27811
|
-
if (lines[start].text.startsWith("-")) return readList(lines, start, indent);
|
|
27812
|
-
return readMap(lines, start, indent);
|
|
27813
|
-
}
|
|
27814
|
-
function readList(lines, start, indent) {
|
|
27815
|
-
const out = [];
|
|
27816
|
-
let i = start;
|
|
27817
|
-
while (i < lines.length && lines[i].indent === indent && lines[i].text.startsWith("-")) {
|
|
27818
|
-
const line = lines[i];
|
|
27819
|
-
const rest = line.text.replace(/^-\s*/, "");
|
|
27820
|
-
const keyIndent = indent + (line.text.length - rest.length);
|
|
27821
|
-
i++;
|
|
27822
|
-
if (!stripComment(rest)) {
|
|
27823
|
-
const [value, next2] = readBlock(lines, i, indent);
|
|
27824
|
-
out.push(value);
|
|
27825
|
-
i = next2;
|
|
27826
|
-
continue;
|
|
27827
|
-
}
|
|
27828
|
-
const match = rest.match(/^([^:]+):\s*(.*)$/);
|
|
27829
|
-
if (!match || /^\[.*\]$/.test(stripComment(rest))) {
|
|
27830
|
-
out.push(readScalar(stripComment(rest)));
|
|
27831
|
-
continue;
|
|
27832
|
-
}
|
|
27833
|
-
const item = {};
|
|
27834
|
-
const inline = stripComment(match[2].trim());
|
|
27835
|
-
if (inline) item[match[1].trim()] = unquote(inline);
|
|
27836
|
-
else {
|
|
27837
|
-
const [value, next2] = readBlock(lines, i, keyIndent);
|
|
27838
|
-
item[match[1].trim()] = value;
|
|
27839
|
-
i = next2;
|
|
27840
|
-
}
|
|
27841
|
-
const [rest_, next] = readMap(lines, i, keyIndent);
|
|
27842
|
-
Object.assign(item, rest_);
|
|
27843
|
-
i = next;
|
|
27844
|
-
out.push(item);
|
|
27845
|
-
}
|
|
27846
|
-
return [out, i];
|
|
27847
|
-
}
|
|
27848
|
-
function splitFrontmatter(text2) {
|
|
27849
|
-
const lines = text2.replace(/^/, "").split("\n");
|
|
27850
|
-
if (lines[0]?.trim() !== "---") return { meta: null, body: text2 };
|
|
27851
|
-
let i = 1;
|
|
27852
|
-
while (i < lines.length && lines[i].trim() !== "---") i++;
|
|
27853
|
-
if (i >= lines.length) return { meta: null, body: text2 };
|
|
27854
|
-
return { meta: lines.slice(1, i).join("\n"), body: lines.slice(i + 1).join("\n") };
|
|
27855
|
-
}
|
|
27856
|
-
|
|
27857
|
-
// ../cli/src/lib/agents/parse.ts
|
|
27858
|
-
var OLD_ROLE_KEYS = ["lead", "hook", "stage", "kind"];
|
|
27859
|
-
var AGENT_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
27860
|
-
var SCHEDULE_READS = ["archived-cards", "chats", "dismissals"];
|
|
27861
|
-
var isScheduleReads = (value) => SCHEDULE_READS.includes(value);
|
|
27862
|
-
function parseSpecAgent(text2, from, file, builtIn = false, list = () => []) {
|
|
27863
|
-
let named = "";
|
|
27864
|
-
const bad = (why, old2) => ({
|
|
27865
|
-
problem: `${from}: ${why}`,
|
|
27866
|
-
...named ? { name: named } : {},
|
|
27867
|
-
...old2 ? { old: old2 } : {}
|
|
27868
|
-
});
|
|
27869
|
-
const { meta, body } = splitFrontmatter(text2);
|
|
27870
|
-
if (meta === null) return bad("no `---` frontmatter, so it declares no name or description");
|
|
27871
|
-
const front = parseYamlBlock(meta);
|
|
27872
|
-
const name = str(front.name);
|
|
27873
|
-
if (!name) return bad("its frontmatter has no `name`");
|
|
27874
|
-
if (!AGENT_NAME.test(name)) return bad(`"${name}" is not a usable agent name \u2014 use lower-case words joined by "-"`);
|
|
27875
|
-
named = name;
|
|
27876
|
-
const description = str(front.description);
|
|
27877
|
-
if (!description) return bad(`\`${name}\` has no \`description\`, which says what it does`);
|
|
27878
|
-
const akb = map(front.akb) ?? {};
|
|
27879
|
-
const old = OLD_ROLE_KEYS.filter((key) => akb[key] !== void 0);
|
|
27880
|
-
if (old.length) {
|
|
27881
|
-
return bad(
|
|
27882
|
-
`\`${name}\` declares ${old.map((key) => `\`akb.${key}\``).join(", ")}, which the board no longer reads \u2014 remove ${old.length > 1 ? "them" : "it"}, and list the agent in its studio's \`STUDIO.md\` under \`previews\`, \`land\` or \`scheduled\` (\`akb guide write-agent\`), or ask the Studio builder to rewrite it`,
|
|
27883
|
-
{ keys: old }
|
|
27884
|
-
);
|
|
27885
|
-
}
|
|
27886
|
-
const declaredReads = str(akb.reads);
|
|
27887
|
-
if (declaredReads && !isScheduleReads(declaredReads)) {
|
|
27888
|
-
return bad(`\`${name}\` declares \`akb.reads: ${declaredReads}\` \u2014 it is \`${SCHEDULE_READS.join("` or `")}\``);
|
|
27889
|
-
}
|
|
27890
|
-
const when = str(akb.when);
|
|
27891
|
-
const after = names(akb.after);
|
|
27892
|
-
const declaredSession = str(akb.session);
|
|
27893
|
-
if (declaredSession && declaredSession !== "new") {
|
|
27894
|
-
return bad(`\`${name}\` declares \`akb.session: ${declaredSession}\` \u2014 use \`new\` to recommend a separate session, or omit the preference`);
|
|
27895
|
-
}
|
|
27896
|
-
let stages;
|
|
27897
|
-
if (akb.stages !== void 0) {
|
|
27898
|
-
if (!Array.isArray(akb.stages) || !akb.stages.length || akb.stages.length > 50) return bad("`akb.stages` must contain 1 to 50 stages");
|
|
27899
|
-
stages = [];
|
|
27900
|
-
for (const value of akb.stages) {
|
|
27901
|
-
const row = map(value);
|
|
27902
|
-
const id = str(row?.id);
|
|
27903
|
-
const title = map(row?.title);
|
|
27904
|
-
const instructions2 = str(row?.instructions);
|
|
27905
|
-
if (!row || Object.keys(row).some((key) => !["id", "title", "instructions", "when"].includes(key)) || !AGENT_NAME.test(id) || stages.some((stage) => stage.id === id)) return bad("`akb.stages` needs unique stage IDs and only id, title, instructions and optional when");
|
|
27906
|
-
if (!title || !str(title.en) || Object.values(title).some((text3) => typeof text3 !== "string" || !text3.trim())) return bad(`stage ${id} needs a title map with en`);
|
|
27907
|
-
if (!instructions2.endsWith(".md") || instructions2.startsWith("/") || instructions2.includes("\\") || instructions2.split("/").some((part) => !part || part === ".." || part === ".") || !file(instructions2)?.trim()) return bad(`stage ${id} needs an existing agent-relative instructions file`);
|
|
27908
|
-
if (row.when !== void 0 && !str(row.when)) return bad(`stage ${id} needs nonempty when text, or omit when for a required stage`);
|
|
27909
|
-
stages.push({ id, title: Object.fromEntries(Object.entries(title).map(([lang, text3]) => [lang, str(text3)])), instructions: instructions2, ...str(row.when) ? { when: str(row.when) } : {} });
|
|
27910
|
-
}
|
|
27911
|
-
}
|
|
27912
|
-
const components = akb.components === void 0 ? ["Asset"] : akb.components;
|
|
27913
|
-
if (!Array.isArray(components) || components.some((value) => typeof value !== "string" || !value.trim())) {
|
|
27914
|
-
return bad(`\`${name}\` declares \`akb.components\` that is not a list of component IDs`);
|
|
27915
|
-
}
|
|
27916
|
-
const icon = readIcon(akb.icon);
|
|
27917
|
-
if (icon && typeof icon === "object" && "problem" in icon) {
|
|
27918
|
-
return bad(
|
|
27919
|
-
`\`${name}\` declares an \`akb.icon\` where ${icon.problem} \u2014 use one of ${ICON_NAMES.join(", ")}, or 1 to 12 parts \`{ d, f?, o?: true, s?, w? }\` coloured with ${ICON_COLORS.join(", ")}`
|
|
27920
|
-
);
|
|
27921
|
-
}
|
|
27922
|
-
const workspace = memoryPaths(akb.memoryFiles);
|
|
27923
|
-
if (typeof workspace === "string") return bad(`\`${name}\` declares ${workspace}`);
|
|
27924
|
-
const instructions = body.trim();
|
|
27925
|
-
if (!instructions) return bad(`\`${name}\` has frontmatter but no instructions under it`);
|
|
27926
|
-
return {
|
|
27927
|
-
agent: {
|
|
27928
|
-
name,
|
|
27929
|
-
description,
|
|
27930
|
-
...when ? { when } : {},
|
|
27931
|
-
after,
|
|
27932
|
-
...stages ? { stages } : {},
|
|
27933
|
-
components: [...new Set(components.map((value) => value.trim()))],
|
|
27934
|
-
...icon ? { icon } : {},
|
|
27935
|
-
...akb.merges === "true" ? { merges: true } : {},
|
|
27936
|
-
i18n: readTranslations(akb.i18n),
|
|
27937
|
-
...declaredReads ? { reads: declaredReads } : {},
|
|
27938
|
-
...declaredSession ? { session: "new" } : {},
|
|
27939
|
-
memory: names(akb.memory),
|
|
27940
|
-
memoryFiles: { workspace },
|
|
27941
|
-
files: list(),
|
|
27942
|
-
body: instructions,
|
|
27943
|
-
from,
|
|
27944
|
-
builtIn,
|
|
27945
|
-
file
|
|
27946
|
-
}
|
|
27947
|
-
};
|
|
27948
|
-
}
|
|
27949
|
-
function readTranslations(raw) {
|
|
27950
|
-
const block = map(raw);
|
|
27951
|
-
if (!block) return {};
|
|
27952
|
-
const out = {};
|
|
27953
|
-
for (const [tag, value] of Object.entries(block)) {
|
|
27954
|
-
const said = map(value);
|
|
27955
|
-
if (!said) continue;
|
|
27956
|
-
const lines = {
|
|
27957
|
-
...str(said.title) ? { title: str(said.title) } : {},
|
|
27958
|
-
...str(said.description) ? { description: str(said.description) } : {},
|
|
27959
|
-
...str(said.when) ? { when: str(said.when) } : {}
|
|
27960
|
-
};
|
|
27961
|
-
if (Object.keys(lines).length) out[tag] = lines;
|
|
27962
|
-
}
|
|
27963
|
-
return out;
|
|
26841
|
+
// ../cli/src/lib/agent/connection-process.ts
|
|
26842
|
+
function connectionIdentity(pid) {
|
|
26843
|
+
const result = process.platform === "win32" ? spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CreationDate.ToUniversalTime().ToString('o')`], { encoding: "utf8", timeout: 2e3, windowsHide: true }) : spawnSync("ps", ["-p", String(pid), "-o", "lstart="], { encoding: "utf8", timeout: 2e3, env: { ...process.env, LC_ALL: "C" } });
|
|
26844
|
+
return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
|
|
27964
26845
|
}
|
|
27965
|
-
function memoryPaths(raw, folder = "memory/agents/<name>/") {
|
|
27966
|
-
if (raw === void 0) return [];
|
|
27967
|
-
const block = map(raw);
|
|
27968
|
-
const extra = block ? Object.keys(block).filter((key) => key !== "workspace") : [];
|
|
27969
|
-
if (!block || extra.length) return `\`akb.memoryFiles\` with ${block ? `\`${extra.join("`, `")}\`` : "no `workspace:` list"} \u2014 it holds only \`workspace: [<path>, ...]\``;
|
|
27970
|
-
const list = block.workspace;
|
|
27971
|
-
if (list === void 0) return [];
|
|
27972
|
-
if (!Array.isArray(list) || list.some((v) => typeof v !== "string" || !v.trim())) {
|
|
27973
|
-
return "`akb.memoryFiles.workspace` that is not a list of paths \u2014 write `workspace: [style.md]`";
|
|
27974
|
-
}
|
|
27975
|
-
const paths = [...new Set(list.map((v) => v.trim()))];
|
|
27976
|
-
const outside = paths.find((p) => p.startsWith("/") || p.includes("\\") || p.split("/").some((part) => part === ".." || part === "."));
|
|
27977
|
-
if (outside) return `\`akb.memoryFiles.workspace: ${outside}\`, which is outside its memory folder \u2014 use a path inside \`${folder}\``;
|
|
27978
|
-
return paths;
|
|
27979
|
-
}
|
|
27980
|
-
var names = (value) => [...new Set((Array.isArray(value) ? value : [value]).map((v) => str(v)).filter(Boolean))];
|
|
27981
|
-
var str = (value) => typeof value === "string" ? value.trim() : "";
|
|
27982
|
-
var map = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
27983
|
-
|
|
27984
|
-
// ../cli/src/lib/agent/studio-def.ts
|
|
27985
|
-
var STUDIO_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
27986
|
-
var OLD_KEYS = ["stages", "delivers", "helpers", "every"];
|
|
27987
|
-
var box = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27988
|
-
var text = (value) => typeof value === "string" ? value.trim() : "";
|
|
27989
|
-
function readAgent(item) {
|
|
27990
|
-
const row = typeof item === "string" ? { agent: item } : box(item);
|
|
27991
|
-
const agent = text(row.agent);
|
|
27992
|
-
if (!agent) return null;
|
|
27993
|
-
return { agent, extra: typeof row.extra === "string" ? row.extra : "", ...text(row.off) === "true" ? { off: true } : {} };
|
|
27994
|
-
}
|
|
27995
|
-
var readGroup = (value) => (Array.isArray(value) ? value : []).map(readAgent).filter((h) => !!h);
|
|
27996
|
-
function readPreviews(value) {
|
|
27997
|
-
if (value === void 0 || value === "") return [];
|
|
27998
|
-
if (!Array.isArray(value)) return "`previews` is a list of agents";
|
|
27999
|
-
if (value.some(Array.isArray)) {
|
|
28000
|
-
return "`previews` is one list of agents, not a list of lists \u2014 flatten it, and give an agent `after` to make it wait on another's approval";
|
|
28001
|
-
}
|
|
28002
|
-
return readGroup(value);
|
|
28003
|
-
}
|
|
28004
|
-
function parseStudioFile(id, source, from) {
|
|
28005
|
-
if (!STUDIO_ID.test(id)) return { problem: `${from}: \`${id}\` is not a studio id \u2014 use lowercase letters, digits and dashes` };
|
|
28006
|
-
const { meta, body } = splitFrontmatter(source);
|
|
28007
|
-
if (meta === null) return { problem: `${from}: no \`---\` frontmatter` };
|
|
28008
|
-
const raw = parseYamlBlock(meta);
|
|
28009
|
-
const name = text(raw.name).replace(/\s+/g, " ");
|
|
28010
|
-
if (!name) return { problem: `${from}: its frontmatter has no \`name\`` };
|
|
28011
|
-
const old = OLD_KEYS.filter((key) => key in raw);
|
|
28012
|
-
if (old.length) {
|
|
28013
|
-
return {
|
|
28014
|
-
problem: `${from}: \`${old.join("`, `")}\` ${old.length > 1 ? "are" : "is"} no longer read \u2014 list the agents under \`previews\`, \`land\` and \`scheduled\` instead (\`akb guide write-agent\`), or ask the Studio builder to rewrite it`
|
|
28015
|
-
};
|
|
28016
|
-
}
|
|
28017
|
-
const icon = readIcon(raw.icon);
|
|
28018
|
-
if (icon && typeof icon === "object" && "problem" in icon) {
|
|
28019
|
-
return {
|
|
28020
|
-
problem: `${from}: its \`icon\` is wrong \u2014 ${icon.problem}; use one of ${ICON_NAMES.join(", ")}, or 1 to 12 parts \`{ d, f?, o?: true, s?, w? }\` coloured with ${ICON_COLORS.join(", ")}`
|
|
28021
|
-
};
|
|
28022
|
-
}
|
|
28023
|
-
const previews = readPreviews(raw.previews);
|
|
28024
|
-
if (typeof previews === "string") return { problem: `${from}: ${previews}` };
|
|
28025
|
-
const land = readGroup(raw.land);
|
|
28026
|
-
const seen = /* @__PURE__ */ new Set();
|
|
28027
|
-
for (const { agent } of [...previews, ...land]) {
|
|
28028
|
-
if (seen.has(agent)) return { problem: `${from}: \`${agent}\` is listed more than once \u2014 list an agent once` };
|
|
28029
|
-
seen.add(agent);
|
|
28030
|
-
}
|
|
28031
|
-
const scheduled = [];
|
|
28032
|
-
for (const item of Array.isArray(raw.scheduled) ? raw.scheduled : []) {
|
|
28033
|
-
const row = typeof item === "string" ? { agent: item } : box(item);
|
|
28034
|
-
const agent = text(row.agent);
|
|
28035
|
-
if (!agent || scheduled.some((s) => s.agent === agent)) continue;
|
|
28036
|
-
scheduled.push({ agent, ...text(row.cadence) ? { cadence: text(row.cadence) } : {} });
|
|
28037
|
-
}
|
|
28038
|
-
const workspace = memoryPaths(raw.memoryFiles, `memory/studios/${id}/`);
|
|
28039
|
-
if (typeof workspace === "string") return { problem: `${from}: declares ${workspace}` };
|
|
28040
|
-
const names2 = Object.fromEntries(Object.entries(box(raw.names)).map(([lang, said]) => [lang, text(said)]).filter(([, said]) => said));
|
|
28041
|
-
return {
|
|
28042
|
-
def: {
|
|
28043
|
-
id,
|
|
28044
|
-
name,
|
|
28045
|
-
...Object.keys(names2).length ? { names: names2 } : {},
|
|
28046
|
-
description: text(raw.description),
|
|
28047
|
-
when: text(raw.when),
|
|
28048
|
-
needsArtifact: text(raw.needsArtifact) === "true",
|
|
28049
|
-
...icon ? { icon } : {},
|
|
28050
|
-
previews,
|
|
28051
|
-
land,
|
|
28052
|
-
scheduled,
|
|
28053
|
-
...workspace.length ? { memoryFiles: { workspace } } : {},
|
|
28054
|
-
rules: body.trim()
|
|
28055
|
-
}
|
|
28056
|
-
};
|
|
28057
|
-
}
|
|
28058
|
-
|
|
28059
|
-
// ../cli/src/lib/agent/studio-folder.ts
|
|
28060
|
-
import fs3 from "node:fs";
|
|
28061
|
-
import path4 from "node:path";
|
|
28062
|
-
|
|
28063
|
-
// ../cli/src/lib/shared/studio-files.ts
|
|
28064
|
-
var STUDIO_FILE = "STUDIO.md";
|
|
28065
|
-
var MCP_FILE = "mcp.json";
|
|
28066
|
-
var CARD_TEMPLATE_FILE = "CARD.md";
|
|
28067
|
-
var SHARED_DIR = "shared/";
|
|
28068
|
-
var VERSION_FILE = "version.json";
|
|
28069
|
-
var KB = 1024;
|
|
28070
|
-
var FILE_LIMITS = { file: 2 * KB * KB, total: 2 * KB * KB, count: 500, path: 512 };
|
|
28071
|
-
var officialId = (folder) => `wf_builtin_${folder.replace(/-/g, "_")}`;
|
|
28072
|
-
var hashInput = (files) => JSON.stringify(Object.entries(files).sort(([a], [b]) => a < b ? -1 : 1));
|
|
28073
|
-
var landsOf = (def) => ({ lands: def.land.some((h) => !h.off) });
|
|
28074
|
-
var SEGMENT = /^[\w.-]+$/;
|
|
28075
|
-
var isAboutFile = (file) => /^ABOUT(\.[a-z]{2})?\.md$/.test(file) || /^screenshots\/[\w.-]+\.(png|jpe?g|webp)$/.test(file);
|
|
28076
|
-
var bytes = (text2) => new TextEncoder().encode(text2).length;
|
|
28077
|
-
var isSharedFile = (file) => {
|
|
28078
|
-
const parts = file.split("/");
|
|
28079
|
-
return parts.length > 1 && parts[0] === "shared" && parts.slice(1).every((p) => SEGMENT.test(p) && p !== "." && p !== "..");
|
|
28080
|
-
};
|
|
28081
|
-
function folderPath(file, top) {
|
|
28082
|
-
const parts = file.split("/");
|
|
28083
|
-
if (parts.length < 3 || parts[0] !== top || !AGENT_NAME.test(parts[1])) return null;
|
|
28084
|
-
if (parts.slice(2).some((p) => !SEGMENT.test(p) || p === "." || p === "..")) return null;
|
|
28085
|
-
return [parts[1], parts.slice(2).join("/")];
|
|
28086
|
-
}
|
|
28087
|
-
function mcpProblem(text2) {
|
|
28088
|
-
let read;
|
|
28089
|
-
try {
|
|
28090
|
-
read = JSON.parse(text2);
|
|
28091
|
-
} catch {
|
|
28092
|
-
return "is not JSON";
|
|
28093
|
-
}
|
|
28094
|
-
const servers = read?.mcpServers;
|
|
28095
|
-
if (!servers || typeof servers !== "object" || Array.isArray(servers)) return "must hold `mcpServers`, an object of name \u2192 server";
|
|
28096
|
-
for (const [name, server] of Object.entries(servers)) {
|
|
28097
|
-
const { command, args, ...rest } = server ?? {};
|
|
28098
|
-
if (!AGENT_NAME.test(name)) return `names a server \`${name}\`; use lowercase letters, digits and dashes`;
|
|
28099
|
-
if (typeof command !== "string" || !command) return `server \`${name}\` needs a \`command\``;
|
|
28100
|
-
if (args !== void 0 && !(Array.isArray(args) && args.every((a) => typeof a === "string"))) return `server \`${name}\`: \`args\` must be a list of strings`;
|
|
28101
|
-
if (Object.keys(rest).length) return `server \`${name}\` takes only \`command\` and \`args\``;
|
|
28102
|
-
}
|
|
28103
|
-
return null;
|
|
28104
|
-
}
|
|
28105
|
-
function checkStudioFiles(value, official = false) {
|
|
28106
|
-
const read = inspect(value, official);
|
|
28107
|
-
const first = read.problems[0];
|
|
28108
|
-
return first ? { ok: false, ...first } : { ok: true, def: read.def, files: read.files };
|
|
28109
|
-
}
|
|
28110
|
-
function inspect(value, official) {
|
|
28111
|
-
const problems = [];
|
|
28112
|
-
const fail = (file, reason, tooLarge = false) => {
|
|
28113
|
-
problems.push({ file, reason, ...tooLarge ? { tooLarge } : {} });
|
|
28114
|
-
return { problems };
|
|
28115
|
-
};
|
|
28116
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return fail("files", "must be an object of path \u2192 text");
|
|
28117
|
-
const files = Object.fromEntries(Object.entries(value).filter(([file]) => file !== VERSION_FILE));
|
|
28118
|
-
const entries = Object.entries(files);
|
|
28119
|
-
if (entries.length > FILE_LIMITS.count) return fail("files", `holds at most ${FILE_LIMITS.count} files`, true);
|
|
28120
|
-
let total = 0;
|
|
28121
|
-
const folders = /* @__PURE__ */ new Map();
|
|
28122
|
-
const skills = /* @__PURE__ */ new Set();
|
|
28123
|
-
for (const [file, text2] of entries) {
|
|
28124
|
-
if (typeof text2 !== "string" || text2.includes("\0")) {
|
|
28125
|
-
fail(file, "is not a text file");
|
|
28126
|
-
continue;
|
|
28127
|
-
}
|
|
28128
|
-
if (file.length > FILE_LIMITS.path) {
|
|
28129
|
-
fail(file, `the path is longer than ${FILE_LIMITS.path} characters`);
|
|
28130
|
-
continue;
|
|
28131
|
-
}
|
|
28132
|
-
const size = bytes(text2);
|
|
28133
|
-
if (size > FILE_LIMITS.file) return fail(file, `is larger than ${FILE_LIMITS.file / KB} KB`, true);
|
|
28134
|
-
total += size;
|
|
28135
|
-
if (total > FILE_LIMITS.total) return fail("files", `are larger than ${FILE_LIMITS.total / KB / KB} MB together`, true);
|
|
28136
|
-
if (file === STUDIO_FILE || file === CARD_TEMPLATE_FILE) continue;
|
|
28137
|
-
if (official && file === MCP_FILE) {
|
|
28138
|
-
const problem = mcpProblem(text2);
|
|
28139
|
-
if (problem) fail(file, problem);
|
|
28140
|
-
continue;
|
|
28141
|
-
}
|
|
28142
|
-
if (official && isAboutFile(file)) continue;
|
|
28143
|
-
if (official && file.startsWith("skills/")) {
|
|
28144
|
-
if (!folderPath(file, "skills")) fail(file, "is not inside skills/<name>/");
|
|
28145
|
-
else skills.add(file.split("/")[1]);
|
|
28146
|
-
continue;
|
|
28147
|
-
}
|
|
28148
|
-
if (isSharedFile(file)) continue;
|
|
28149
|
-
const at = folderPath(file, "agents");
|
|
28150
|
-
if (!at) {
|
|
28151
|
-
fail(file, `is neither ${STUDIO_FILE}, ${CARD_TEMPLATE_FILE}, shared/ nor inside agents/<name>/`);
|
|
28152
|
-
continue;
|
|
28153
|
-
}
|
|
28154
|
-
if (!folders.has(at[0])) folders.set(at[0], /* @__PURE__ */ new Map());
|
|
28155
|
-
folders.get(at[0]).set(at[1], text2);
|
|
28156
|
-
}
|
|
28157
|
-
for (const name of skills) {
|
|
28158
|
-
if (files[`skills/${name}/SKILL.md`] === void 0) fail(`skills/${name}/SKILL.md`, "is missing");
|
|
28159
|
-
}
|
|
28160
|
-
const source = files[STUDIO_FILE];
|
|
28161
|
-
const read = typeof source === "string" ? parseStudioFile("studio", source, STUDIO_FILE) : null;
|
|
28162
|
-
if (!read) fail(STUDIO_FILE, "is missing");
|
|
28163
|
-
else if ("problem" in read) fail(STUDIO_FILE, read.problem.replace(`${STUDIO_FILE}: `, ""));
|
|
28164
|
-
const agents = /* @__PURE__ */ new Map();
|
|
28165
|
-
for (const [name, own] of folders) {
|
|
28166
|
-
const from = `agents/${name}/AGENT.md`;
|
|
28167
|
-
const text2 = own.get("AGENT.md");
|
|
28168
|
-
if (text2 === void 0) {
|
|
28169
|
-
fail(from, "is missing");
|
|
28170
|
-
continue;
|
|
28171
|
-
}
|
|
28172
|
-
const parsed = parseSpecAgent(text2, from, (p) => own.get(p) ?? null, false, () => [...own.keys()].filter((p) => p !== "AGENT.md"));
|
|
28173
|
-
if ("problem" in parsed) fail(from, parsed.problem.replace(`${from}: `, ""));
|
|
28174
|
-
else if (parsed.agent.name !== name) fail(from, `calls itself \`${parsed.agent.name}\`; it must match its folder`);
|
|
28175
|
-
else agents.set(name, parsed.agent);
|
|
28176
|
-
}
|
|
28177
|
-
if (!read || "problem" in read) return { problems };
|
|
28178
|
-
const def = read.def;
|
|
28179
|
-
const named = [
|
|
28180
|
-
...def.previews.map((h) => [h.agent, "it previews with"]),
|
|
28181
|
-
...def.land.map((h) => [h.agent, "it lands with"]),
|
|
28182
|
-
...def.scheduled.map((s) => [s.agent, "it schedules"])
|
|
28183
|
-
];
|
|
28184
|
-
for (const { agent } of [...def.land, ...def.scheduled]) {
|
|
28185
|
-
if (agents.get(agent)?.stages) fail(`agents/${agent}/AGENT.md`, "`akb.stages` is only supported for preview agents");
|
|
28186
|
-
}
|
|
28187
|
-
for (const [name, why] of named) {
|
|
28188
|
-
if (!agents.has(name) && !folders.has(name)) fail(STUDIO_FILE, `${why} \`${name}\`, which has no agents/${name}/AGENT.md`);
|
|
28189
|
-
}
|
|
28190
|
-
return { problems, def, files };
|
|
28191
|
-
}
|
|
28192
|
-
|
|
28193
|
-
// ../cli/src/lib/agent/studio-folder.ts
|
|
28194
|
-
var MIME = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp" };
|
|
28195
|
-
function filesOf(dir, base = dir) {
|
|
28196
|
-
return fs3.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".")).flatMap((e) => {
|
|
28197
|
-
const full = path4.join(dir, e.name);
|
|
28198
|
-
return e.isDirectory() ? filesOf(full, base) : [path4.relative(base, full).split(path4.sep).join("/")];
|
|
28199
|
-
});
|
|
28200
|
-
}
|
|
28201
|
-
function readStudioFile(dir, file) {
|
|
28202
|
-
const full = path4.join(dir, file);
|
|
28203
|
-
return isAboutFile(file) && !file.endsWith(".md") ? `data:${MIME[path4.extname(file)]};base64,${fs3.readFileSync(full).toString("base64")}` : fs3.readFileSync(full, "utf8");
|
|
28204
|
-
}
|
|
28205
|
-
var readStudioFolder = (dir) => Object.fromEntries(filesOf(dir).sort().map((f) => [f, readStudioFile(dir, f)]));
|
|
28206
|
-
|
|
28207
|
-
// ../official/pack.ts
|
|
28208
|
-
var OFFICIAL = path5.dirname(fileURLToPath(import.meta.url));
|
|
28209
|
-
var dirs = (dir) => fs4.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
28210
|
-
var hashOf = (files) => crypto.createHash("sha256").update(hashInput(files)).digest("hex");
|
|
28211
|
-
function packOfficial(root2 = OFFICIAL, loose = false) {
|
|
28212
|
-
const agentsDir = path5.join(root2, "agents");
|
|
28213
|
-
const agentFiles = Object.fromEntries(dirs(agentsDir).map((name) => {
|
|
28214
|
-
const dir = path5.join(agentsDir, name);
|
|
28215
|
-
return [name, readStudioFolder(dir)];
|
|
28216
|
-
}));
|
|
28217
|
-
for (const [name, own] of Object.entries(loose ? {} : agentFiles)) {
|
|
28218
|
-
const read = parseSpecAgent(own["AGENT.md"] ?? "", `official/agents/${name}/AGENT.md`, (p) => own[p] ?? null, true);
|
|
28219
|
-
if ("problem" in read) throw new Error(read.problem);
|
|
28220
|
-
}
|
|
28221
|
-
const studiosDir = path5.join(root2, "studios");
|
|
28222
|
-
return dirs(studiosDir).map((folder) => {
|
|
28223
|
-
const dir = path5.join(studiosDir, folder);
|
|
28224
|
-
const files = {};
|
|
28225
|
-
for (const f of filesOf(dir).sort()) {
|
|
28226
|
-
if (f === STUDIO_FILE || f === CARD_TEMPLATE_FILE || f === MCP_FILE || f.startsWith("skills/") || f.startsWith(SHARED_DIR) || isAboutFile(f)) files[f] = readStudioFile(dir, f);
|
|
28227
|
-
}
|
|
28228
|
-
const read = checkStudioFiles({ [STUDIO_FILE]: files[STUDIO_FILE], ...Object.fromEntries(
|
|
28229
|
-
Object.entries(agentFiles).flatMap(([name, own]) => Object.entries(own).map(([f, t]) => [`agents/${name}/${f}`, t]))
|
|
28230
|
-
) });
|
|
28231
|
-
if (!read.ok && !loose) throw new Error(`official/studios/${folder}: ${read.file}: ${read.reason}`);
|
|
28232
|
-
const parsed = parseStudioFile(folder, files[STUDIO_FILE] ?? "", STUDIO_FILE);
|
|
28233
|
-
if ("problem" in parsed) throw new Error(parsed.problem);
|
|
28234
|
-
const def = parsed.def;
|
|
28235
|
-
for (const name of [...new Set([...def.previews, ...def.land, ...def.scheduled].map((h) => h.agent))].sort()) {
|
|
28236
|
-
for (const [f, text2] of Object.entries(agentFiles[name] ?? {})) files[`agents/${name}/${f}`] = text2;
|
|
28237
|
-
}
|
|
28238
|
-
const checked = loose ? { ok: true } : checkStudioFiles(files, true);
|
|
28239
|
-
if (!checked.ok) throw new Error(`official/studios/${folder}: ${checked.file}: ${checked.reason}`);
|
|
28240
|
-
if (!def.names?.zh && !loose) throw new Error(`official/studios/${folder}/${STUDIO_FILE}: add its Chinese name under \`names: zh\``);
|
|
28241
|
-
return {
|
|
28242
|
-
id: officialId(folder),
|
|
28243
|
-
name: def.name,
|
|
28244
|
-
names: { en: def.name, ...def.names },
|
|
28245
|
-
description: def.description,
|
|
28246
|
-
when: def.when,
|
|
28247
|
-
...landsOf(def),
|
|
28248
|
-
hash: hashOf(files),
|
|
28249
|
-
files
|
|
28250
|
-
};
|
|
28251
|
-
});
|
|
28252
|
-
}
|
|
28253
|
-
|
|
28254
|
-
// ../cli/src/lib/cloud/tasks.ts
|
|
28255
|
-
import fs6 from "node:fs";
|
|
28256
|
-
import path8 from "node:path";
|
|
28257
|
-
|
|
28258
|
-
// ../cli/src/lib/cloud/config.ts
|
|
28259
|
-
var SUPABASE_URL = "https://yajrbpprmdvtkvjjfpbk.supabase.co";
|
|
28260
|
-
var SUPABASE_ANON_KEY = "sb_publishable_ioUQ23BTtoj8NKqndp0Jrw_omVR3m4n";
|
|
28261
|
-
var API_URL = "https://api.ai4kanban.dev";
|
|
28262
|
-
var trimSlash = (url) => url.replace(/\/+$/, "");
|
|
28263
|
-
function cloudEndpoints() {
|
|
28264
|
-
return {
|
|
28265
|
-
supabaseUrl: trimSlash(process.env.AI4KANBAN_SUPABASE_URL || SUPABASE_URL),
|
|
28266
|
-
anonKey: process.env.AI4KANBAN_SUPABASE_ANON_KEY || SUPABASE_ANON_KEY,
|
|
28267
|
-
api: trimSlash(process.env.AI4KANBAN_CLOUD_URL || API_URL)
|
|
28268
|
-
};
|
|
28269
|
-
}
|
|
28270
|
-
|
|
28271
|
-
// ../cli/src/lib/cloud/session.ts
|
|
28272
|
-
import fs5 from "node:fs";
|
|
28273
|
-
import path7 from "node:path";
|
|
28274
|
-
|
|
28275
|
-
// ../cli/src/lib/machine/home.ts
|
|
28276
|
-
import os from "node:os";
|
|
28277
|
-
import path6 from "node:path";
|
|
28278
|
-
function machineHome() {
|
|
28279
|
-
return process.env.AI4KANBAN_HOME || path6.join(os.homedir(), ".ai4kanban");
|
|
28280
|
-
}
|
|
28281
|
-
|
|
28282
|
-
// ../cli/src/lib/cloud/session.ts
|
|
28283
|
-
var sessionFile = () => path7.join(machineHome(), "session.json");
|
|
28284
|
-
function readSession() {
|
|
28285
|
-
let raw;
|
|
28286
|
-
try {
|
|
28287
|
-
raw = fs5.readFileSync(sessionFile(), "utf8");
|
|
28288
|
-
} catch {
|
|
28289
|
-
return null;
|
|
28290
|
-
}
|
|
28291
|
-
try {
|
|
28292
|
-
const held = JSON.parse(raw);
|
|
28293
|
-
if (!held.accessToken || !held.refreshToken || !held.subject) return null;
|
|
28294
|
-
if (held.supabaseUrl !== cloudEndpoints().supabaseUrl) return null;
|
|
28295
|
-
return { ...held, version: 1, expiresAt: Number(held.expiresAt) || 0 };
|
|
28296
|
-
} catch {
|
|
28297
|
-
return null;
|
|
28298
|
-
}
|
|
28299
|
-
}
|
|
28300
|
-
|
|
28301
|
-
// ../cli/src/lib/cloud/tasks.ts
|
|
28302
|
-
var TASK_ENV = "AI4KANBAN_TASK";
|
|
28303
|
-
function workspaceTask() {
|
|
28304
|
-
const id = process.env[TASK_ENV];
|
|
28305
|
-
return id && id.trim() ? id.trim() : null;
|
|
28306
|
-
}
|
|
28307
|
-
function runnerProject(board) {
|
|
28308
|
-
if (path8.basename(board) !== "kanban" || path8.basename(path8.dirname(board)) !== ".akb") return null;
|
|
28309
|
-
const linked = linkedProject(board, path8.dirname(path8.dirname(board)));
|
|
28310
|
-
return linked.ok ? linked.value : null;
|
|
28311
|
-
}
|
|
28312
|
-
function linkedProject(board, root2) {
|
|
28313
|
-
const file = path8.join(root2, ".akb", "base.json");
|
|
28314
|
-
if (!fs6.existsSync(file)) return { ok: true, value: null };
|
|
28315
|
-
try {
|
|
28316
|
-
const base = JSON.parse(fs6.readFileSync(file, "utf8"));
|
|
28317
|
-
if (!base || typeof base !== "object" || base.project !== void 0 && (typeof base.project !== "string" || !base.project.trim()) || base.files !== void 0 && (!base.files || typeof base.files !== "object" || Array.isArray(base.files))) throw new Error();
|
|
28318
|
-
const projects = new Set(Object.keys(base.files ?? {}).flatMap((p) => /^projects\/([^/]+)\//.exec(p)?.[1] ?? []));
|
|
28319
|
-
if (typeof base.project === "string") projects.add(base.project);
|
|
28320
|
-
if (projects.size !== 1) throw new Error();
|
|
28321
|
-
return { ok: true, value: [...projects][0] };
|
|
28322
|
-
} catch {
|
|
28323
|
-
return { ok: false, error: "The project link is invalid or names multiple projects.", code: "invalid-link" };
|
|
28324
|
-
}
|
|
28325
|
-
}
|
|
28326
|
-
|
|
28327
|
-
// ../cli/src/lib/file-memo.ts
|
|
28328
|
-
import fs7 from "node:fs";
|
|
28329
|
-
import path9 from "node:path";
|
|
28330
|
-
function stamp(paths) {
|
|
28331
|
-
const parts = [];
|
|
28332
|
-
const visit = (p) => {
|
|
28333
|
-
let st;
|
|
28334
|
-
try {
|
|
28335
|
-
st = fs7.statSync(p, { bigint: true });
|
|
28336
|
-
} catch {
|
|
28337
|
-
parts.push(`${p}:-`);
|
|
28338
|
-
return;
|
|
28339
|
-
}
|
|
28340
|
-
if (!st.isDirectory()) {
|
|
28341
|
-
parts.push(`${p}:${st.mtimeNs}:${st.size}`);
|
|
28342
|
-
return;
|
|
28343
|
-
}
|
|
28344
|
-
parts.push(`${p}/`);
|
|
28345
|
-
let names2;
|
|
28346
|
-
try {
|
|
28347
|
-
names2 = fs7.readdirSync(p).sort();
|
|
28348
|
-
} catch {
|
|
28349
|
-
return;
|
|
28350
|
-
}
|
|
28351
|
-
for (const name of names2) if (name !== "node_modules" && name !== ".git") visit(path9.join(p, name));
|
|
28352
|
-
};
|
|
28353
|
-
for (const p of paths) visit(p);
|
|
28354
|
-
return parts.join("\n");
|
|
28355
|
-
}
|
|
28356
|
-
function copy(v) {
|
|
28357
|
-
if (Array.isArray(v)) return v.map(copy);
|
|
28358
|
-
if (v instanceof Map) return new Map([...v].map(([k, x]) => [k, copy(x)]));
|
|
28359
|
-
if (v instanceof Set) return new Set([...v].map(copy));
|
|
28360
|
-
if (v && typeof v === "object" && Object.getPrototypeOf(v) === Object.prototype) {
|
|
28361
|
-
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, copy(x)]));
|
|
28362
|
-
}
|
|
28363
|
-
return v;
|
|
28364
|
-
}
|
|
28365
|
-
var perTurn = false;
|
|
28366
|
-
var turn = 0;
|
|
28367
|
-
var turnEnding = false;
|
|
28368
|
-
function currentTurn() {
|
|
28369
|
-
if (!perTurn) return ++turn;
|
|
28370
|
-
if (!turnEnding) {
|
|
28371
|
-
turnEnding = true;
|
|
28372
|
-
setImmediate(() => {
|
|
28373
|
-
turn++;
|
|
28374
|
-
turnEnding = false;
|
|
28375
|
-
}).unref();
|
|
28376
|
-
}
|
|
28377
|
-
return turn;
|
|
28378
|
-
}
|
|
28379
|
-
function memoByFiles(paths, read) {
|
|
28380
|
-
let last = null;
|
|
28381
|
-
return () => {
|
|
28382
|
-
const now = currentTurn();
|
|
28383
|
-
if (last?.turn !== now) {
|
|
28384
|
-
const seen = stamp(paths());
|
|
28385
|
-
if (last?.stamp === seen) last.turn = now;
|
|
28386
|
-
else last = { stamp: seen, turn: now, value: read() };
|
|
28387
|
-
}
|
|
28388
|
-
return copy(last.value);
|
|
28389
|
-
};
|
|
28390
|
-
}
|
|
28391
|
-
|
|
28392
|
-
// ../cli/src/lib/agent/cloud-studios.ts
|
|
28393
|
-
var DEV = "AI4KANBAN_STUDIOS";
|
|
28394
|
-
var root = () => path10.join(machineHome(), "studios");
|
|
28395
|
-
var safe = (name) => name.replace(/[^\w.@-]/g, "_");
|
|
28396
|
-
var versionFile = (id, version) => path10.join(root(), "versions", `${safe(id)}@${version}.json`);
|
|
28397
|
-
var listFile = (project) => path10.join(root(), "lists", `${safe(project)}.json`);
|
|
28398
|
-
var pinFile = (task) => path10.join(root(), "tasks", `${safe(task)}.json`);
|
|
28399
|
-
function readJson(file) {
|
|
28400
|
-
try {
|
|
28401
|
-
return JSON.parse(fs8.readFileSync(file, "utf8"));
|
|
28402
|
-
} catch {
|
|
28403
|
-
return null;
|
|
28404
|
-
}
|
|
28405
|
-
}
|
|
28406
|
-
var readVersion = (id, version) => readJson(versionFile(id, version));
|
|
28407
|
-
var readPin = (task) => readJson(pinFile(task));
|
|
28408
|
-
var boardProject = () => KANBAN ? runnerProject(KANBAN) : null;
|
|
28409
|
-
var devFolder = () => process.env[DEV]?.trim() || "";
|
|
28410
|
-
var flowOf = (held) => {
|
|
28411
|
-
const id = studioName(held.id);
|
|
28412
|
-
const read = parseStudioFile(id, held.files["STUDIO.md"] ?? "", `the \`${id}\` studio`);
|
|
28413
|
-
if ("problem" in read) return null;
|
|
28414
|
-
return { def: read.def, cloudId: held.id, version: held.version, builtIn: held.id.startsWith("wf_builtin_"), files: held.files };
|
|
28415
|
-
};
|
|
28416
|
-
function readFlows() {
|
|
28417
|
-
const dev = devFolder();
|
|
28418
|
-
if (dev) {
|
|
28419
|
-
return packOfficial(dev, true).flatMap((w) => flowOf({ id: w.id, version: 1, name: w.name, names: w.names, files: w.files }) ?? []);
|
|
28420
|
-
}
|
|
28421
|
-
const project = boardProject();
|
|
28422
|
-
if (!project || !readSession()) return [];
|
|
28423
|
-
const list = readJson(listFile(project))?.studios ?? [];
|
|
28424
|
-
const flows2 = list.flatMap((w) => {
|
|
28425
|
-
const held = readVersion(w.id, w.version);
|
|
28426
|
-
return held ? flowOf(held) ?? [] : [];
|
|
28427
|
-
});
|
|
28428
|
-
const task = workspaceTask();
|
|
28429
|
-
const pin = task ? readPin(task) : null;
|
|
28430
|
-
const pinned = pin && readVersion(pin.studio, pin.version);
|
|
28431
|
-
const mine = pinned && flowOf(pinned);
|
|
28432
|
-
if (!mine) return flows2;
|
|
28433
|
-
return [mine, ...flows2.filter((f) => f.cloudId !== mine.cloudId)];
|
|
28434
|
-
}
|
|
28435
|
-
var sources = () => {
|
|
28436
|
-
if (devFolder()) return [devFolder()];
|
|
28437
|
-
const project = boardProject();
|
|
28438
|
-
const task = workspaceTask();
|
|
28439
|
-
return [sessionFile(), ...project ? [listFile(project)] : [], ...task ? [pinFile(task)] : []];
|
|
28440
|
-
};
|
|
28441
|
-
var flows = memoByFiles(sources, readFlows);
|
|
28442
|
-
|
|
28443
|
-
// src/home.ts
|
|
28444
|
-
import fs9 from "node:fs";
|
|
28445
|
-
import os2 from "node:os";
|
|
28446
|
-
import path11 from "node:path";
|
|
28447
|
-
import { parseEnv } from "node:util";
|
|
28448
|
-
|
|
28449
|
-
// src/proxy.ts
|
|
28450
|
-
var import_undici = __toESM(require_undici(), 1);
|
|
28451
|
-
|
|
28452
|
-
// ../cli/src/lib/agent/proxy.ts
|
|
28453
|
-
import { execFileSync } from "node:child_process";
|
|
28454
|
-
var PROXY_KEYS = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"];
|
|
28455
|
-
function withSystemProxy(env = process.env, platform = process.platform, read = () => execFileSync("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 1e3, stdio: ["ignore", "pipe", "ignore"] })) {
|
|
28456
|
-
const out = { ...env };
|
|
28457
|
-
if (platform !== "darwin" || PROXY_KEYS.some((key) => env[key] !== void 0)) return out;
|
|
28458
|
-
let raw;
|
|
28459
|
-
try {
|
|
28460
|
-
raw = read();
|
|
28461
|
-
} catch {
|
|
28462
|
-
return out;
|
|
28463
|
-
}
|
|
28464
|
-
const value = (key) => new RegExp(`^\\s*${key}\\s*:\\s*(.*?)\\s*$`, "m").exec(raw)?.[1];
|
|
28465
|
-
for (const [name, key, scheme] of [["HTTP", "HTTP_PROXY", "http"], ["HTTPS", "HTTPS_PROXY", "http"], ["SOCKS", "ALL_PROXY", "socks5"]]) {
|
|
28466
|
-
if (value(`${name}Enable`) !== "1") continue;
|
|
28467
|
-
const host = value(`${name}Proxy`);
|
|
28468
|
-
const port = Number(value(`${name}Port`));
|
|
28469
|
-
if (!host || /[\s/@?#]/.test(host) || !Number.isInteger(port) || port < 1 || port > 65535) continue;
|
|
28470
|
-
try {
|
|
28471
|
-
out[key] = new URL(`${scheme}://${host.includes(":") && !host.startsWith("[") ? `[${host}]` : host}:${port}`).href.replace(/\/$/, "");
|
|
28472
|
-
} catch {
|
|
28473
|
-
}
|
|
28474
|
-
}
|
|
28475
|
-
if (PROXY_KEYS.some((key) => out[key]) && env.NO_PROXY === void 0 && env.no_proxy === void 0) {
|
|
28476
|
-
const exceptions = /ExceptionsList\s*:\s*<array>\s*\{([^}]+)\}/.exec(raw)?.[1];
|
|
28477
|
-
const bypass = exceptions?.split("\n").flatMap((line) => {
|
|
28478
|
-
const host = /^\s*\d+\s*:\s*(\S+)\s*$/.exec(line)?.[1];
|
|
28479
|
-
return host ? [host.startsWith("*.") ? host.slice(1) : host] : [];
|
|
28480
|
-
});
|
|
28481
|
-
if (bypass?.length) out.NO_PROXY = bypass.join(",");
|
|
28482
|
-
}
|
|
28483
|
-
return out;
|
|
28484
|
-
}
|
|
28485
|
-
|
|
28486
|
-
// src/proxy.ts
|
|
28487
|
-
var LOOPBACK = "localhost,127.0.0.1,[::1]";
|
|
28488
|
-
var HOST_PROXY_ENV = "WILDCRANE_HOST_PROXY";
|
|
28489
|
-
var HOST = null;
|
|
28490
|
-
var current = {};
|
|
28491
|
-
var applied = null;
|
|
28492
|
-
function hostProxy() {
|
|
28493
|
-
if (HOST) return HOST;
|
|
28494
|
-
try {
|
|
28495
|
-
if (process.env[HOST_PROXY_ENV]) return HOST = JSON.parse(process.env[HOST_PROXY_ENV]);
|
|
28496
|
-
} catch {
|
|
28497
|
-
}
|
|
28498
|
-
return HOST = Object.fromEntries(
|
|
28499
|
-
[...PROXY_KEYS, "NO_PROXY", "no_proxy"].flatMap((key) => process.env[key] === void 0 ? [] : [[key, process.env[key]]])
|
|
28500
|
-
);
|
|
28501
|
-
}
|
|
28502
|
-
function followProxy(read) {
|
|
28503
|
-
current = read ? withSystemProxy(hostProxy(), process.platform, read) : withSystemProxy(hostProxy());
|
|
28504
|
-
const httpProxy = current.HTTP_PROXY || current.http_proxy || current.ALL_PROXY || current.all_proxy || void 0;
|
|
28505
|
-
const route = {
|
|
28506
|
-
httpProxy,
|
|
28507
|
-
httpsProxy: current.HTTPS_PROXY || current.https_proxy || httpProxy,
|
|
28508
|
-
noProxy: [current.NO_PROXY ?? current.no_proxy, LOOPBACK].filter(Boolean).join(",")
|
|
28509
|
-
};
|
|
28510
|
-
const key = JSON.stringify(route);
|
|
28511
|
-
if (key !== applied) {
|
|
28512
|
-
if (applied === null) (0, import_undici.install)();
|
|
28513
|
-
(0, import_undici.setGlobalDispatcher)(new import_undici.EnvHttpProxyAgent(route));
|
|
28514
|
-
applied = key;
|
|
28515
|
-
}
|
|
28516
|
-
return current;
|
|
28517
|
-
}
|
|
28518
|
-
|
|
28519
|
-
// src/home.ts
|
|
28520
|
-
function runnerHome() {
|
|
28521
|
-
return process.env.WILDCRANE_HOME || path11.join(os2.homedir(), ".wildcrane");
|
|
28522
|
-
}
|
|
28523
|
-
function runnerCwd() {
|
|
28524
|
-
const dir = runnerHome();
|
|
28525
|
-
fs9.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
28526
|
-
return dir;
|
|
28527
|
-
}
|
|
28528
|
-
function useRunnerHome() {
|
|
28529
|
-
process.env.AI4KANBAN_HOME = runnerHome();
|
|
28530
|
-
loadProxyFile();
|
|
28531
|
-
followProxy();
|
|
28532
|
-
setInterval(followProxy, 6e4).unref();
|
|
28533
|
-
}
|
|
28534
|
-
function loadProxyFile() {
|
|
28535
|
-
try {
|
|
28536
|
-
const config = parseEnv(fs9.readFileSync(path11.join(runnerHome(), "proxy.env"), "utf8"));
|
|
28537
|
-
for (const key of ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY"]) {
|
|
28538
|
-
const lower = key.toLowerCase();
|
|
28539
|
-
const value = config[lower] ?? config[key];
|
|
28540
|
-
if (value !== void 0 && process.env[key] === void 0 && process.env[lower] === void 0) process.env[key] = value;
|
|
28541
|
-
}
|
|
28542
|
-
} catch (error) {
|
|
28543
|
-
if (error.code !== "ENOENT") console.error("runner: could not load proxy.env");
|
|
28544
|
-
}
|
|
28545
|
-
}
|
|
28546
|
-
|
|
28547
|
-
// src/settings-control.ts
|
|
28548
|
-
import fs10 from "node:fs";
|
|
28549
|
-
import path12 from "node:path";
|
|
28550
|
-
var directory = () => path12.join(runnerHome(), "executors");
|
|
28551
|
-
var epochFile = () => path12.join(runnerHome(), "account-generation");
|
|
28552
|
-
function accountGeneration() {
|
|
28553
|
-
try {
|
|
28554
|
-
return fs10.readFileSync(epochFile(), "utf8");
|
|
28555
|
-
} catch {
|
|
28556
|
-
return "";
|
|
28557
|
-
}
|
|
28558
|
-
}
|
|
28559
|
-
function executorRecord() {
|
|
28560
|
-
fs10.mkdirSync(directory(), { recursive: true, mode: 448 });
|
|
28561
|
-
const file = path12.join(directory(), `${process.pid}.json`);
|
|
28562
|
-
fs10.writeFileSync(file, "{}", { mode: 384 });
|
|
28563
|
-
return () => fs10.rmSync(file, { force: true });
|
|
28564
|
-
}
|
|
28565
|
-
|
|
28566
|
-
// src/api.ts
|
|
28567
|
-
var FILE_TIMEOUT_MS = 10 * 6e4;
|
|
28568
|
-
|
|
28569
|
-
// src/cache.ts
|
|
28570
|
-
var IDLE_MS = 7 * 24 * 60 * 6e4;
|
|
28571
|
-
var SWEEP_MS = 24 * 60 * 6e4;
|
|
28572
|
-
var holds = /* @__PURE__ */ new Map();
|
|
28573
|
-
var holdsDir = () => path13.join(runnerHome(), "holds");
|
|
28574
|
-
var holdFile = (dir) => path13.join(holdsDir(), `${crypto2.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
|
|
28575
|
-
function hold(dir) {
|
|
28576
|
-
fs11.mkdirSync(holdsDir(), { recursive: true, mode: 448 });
|
|
28577
|
-
fs11.writeFileSync(holdFile(dir), "", { mode: 384 });
|
|
28578
|
-
holds.set(dir, (holds.get(dir) ?? 0) + 1);
|
|
28579
|
-
let held = true;
|
|
28580
|
-
return () => {
|
|
28581
|
-
if (!held) return;
|
|
28582
|
-
held = false;
|
|
28583
|
-
const left = holds.get(dir) - 1;
|
|
28584
|
-
if (left) holds.set(dir, left);
|
|
28585
|
-
else {
|
|
28586
|
-
holds.delete(dir);
|
|
28587
|
-
fs11.rmSync(holdFile(dir), { force: true });
|
|
28588
|
-
}
|
|
28589
|
-
};
|
|
28590
|
-
}
|
|
28591
|
-
|
|
28592
|
-
// src/codex-service.ts
|
|
28593
|
-
var import_smol_toml = __toESM(require_dist(), 1);
|
|
28594
|
-
import { spawn } from "node:child_process";
|
|
28595
|
-
import crypto3 from "node:crypto";
|
|
28596
|
-
import fs13 from "node:fs";
|
|
28597
|
-
import net from "node:net";
|
|
28598
|
-
import path15 from "node:path";
|
|
28599
|
-
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
28600
|
-
import { createInterface } from "node:readline";
|
|
28601
|
-
|
|
28602
|
-
// ../cli/src/lib/shared/conversation.ts
|
|
28603
|
-
function bounded(work, ms, reason) {
|
|
28604
|
-
return new Promise((resolve, reject) => {
|
|
28605
|
-
const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
|
|
28606
|
-
work.then((value) => {
|
|
28607
|
-
clearTimeout(timer);
|
|
28608
|
-
resolve(value);
|
|
28609
|
-
}, (error) => {
|
|
28610
|
-
clearTimeout(timer);
|
|
28611
|
-
reject(error);
|
|
28612
|
-
});
|
|
28613
|
-
});
|
|
28614
|
-
}
|
|
28615
|
-
|
|
28616
|
-
// ../cli/src/lib/agent/spawnable.ts
|
|
28617
|
-
import fs12 from "node:fs";
|
|
28618
|
-
import path14 from "node:path";
|
|
28619
|
-
var META = /([()\][%!^"`<>&|;, *?])/g;
|
|
28620
|
-
function cmdArg(arg) {
|
|
28621
|
-
const quoted = `"${arg.replace(/\r?\n|\r/g, " ").replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1")}"`;
|
|
28622
|
-
return quoted.replace(META, "^$1").replace(META, "^$1");
|
|
28623
|
-
}
|
|
28624
|
-
function cmdLine(file, args) {
|
|
28625
|
-
return `"${[file.replace(META, "^$1"), ...args.map(cmdArg)].join(" ")}"`;
|
|
28626
|
-
}
|
|
28627
|
-
function shimTarget(text2, file) {
|
|
28628
|
-
const dir = path14.win32.dirname(file);
|
|
28629
|
-
const found = /"%(?:~dp0|dp0%)\\?([^"%]+)"\s+%\*/i.exec(text2);
|
|
28630
|
-
if (!found || !/\\node\.exe"/i.test(text2)) return null;
|
|
28631
|
-
const script = path14.win32.resolve(dir, found[1].replace(/\//g, "\\"));
|
|
28632
|
-
const local = path14.win32.join(dir, "node.exe");
|
|
28633
|
-
const nodePath = /SET "NODE_PATH=([^"]*)"/i.exec(text2)?.[1];
|
|
28634
|
-
return { script, node: fs12.existsSync(local) ? local : "node", env: nodePath ? { NODE_PATH: nodePath } : {} };
|
|
28635
|
-
}
|
|
28636
|
-
function onWindowsPath(name, env) {
|
|
28637
|
-
const exts = (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
28638
|
-
const key = Object.keys(env).find((k) => k.toUpperCase() === "PATH") ?? "PATH";
|
|
28639
|
-
for (const dir of (env[key] ?? "").split(";").filter(Boolean)) {
|
|
28640
|
-
for (const ext of exts) {
|
|
28641
|
-
const file = path14.win32.join(dir, `${name}${ext.toLowerCase()}`);
|
|
28642
|
-
if (fs12.existsSync(file)) return file;
|
|
28643
|
-
}
|
|
28644
|
-
}
|
|
28645
|
-
return void 0;
|
|
28646
|
-
}
|
|
28647
|
-
function spawnable(command, args, options = {}, platform = process.platform) {
|
|
28648
|
-
if (platform !== "win32") return { command, args, options };
|
|
28649
|
-
const env = options.env ?? process.env;
|
|
28650
|
-
const file = path14.extname(command) || /[\\/]/.test(command) ? command : onWindowsPath(command, env) ?? command;
|
|
28651
|
-
const ext = path14.extname(file).toLowerCase();
|
|
28652
|
-
const hidden = { ...options, windowsHide: true, shell: false };
|
|
28653
|
-
if (ext !== ".cmd" && ext !== ".bat") return { command: file, args, options: hidden };
|
|
28654
|
-
let text2 = "";
|
|
28655
|
-
try {
|
|
28656
|
-
text2 = fs12.readFileSync(file, "utf8");
|
|
28657
|
-
} catch {
|
|
28658
|
-
}
|
|
28659
|
-
const shim = shimTarget(text2, file);
|
|
28660
|
-
if (shim) {
|
|
28661
|
-
return { command: shim.node, args: [shim.script, ...args], options: { ...hidden, env: { ...env, ...shim.env } } };
|
|
28662
|
-
}
|
|
28663
|
-
return {
|
|
28664
|
-
command: env.ComSpec || process.env.ComSpec || "cmd.exe",
|
|
28665
|
-
args: ["/d", "/s", "/c", cmdLine(file, args)],
|
|
28666
|
-
options: { ...hidden, windowsVerbatimArguments: true }
|
|
28667
|
-
};
|
|
28668
|
-
}
|
|
28669
|
-
|
|
28670
|
-
// ../cli/src/lib/agent/stop.ts
|
|
28671
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
28672
|
-
|
|
28673
|
-
// ../cli/src/lib/agent/env.ts
|
|
28674
|
-
var STOP_ENV = "KANBAN_STOP_ID";
|
|
28675
|
-
|
|
28676
|
-
// ../cli/src/lib/agent/stop.ts
|
|
28677
|
-
var stopMark = () => ({ name: STOP_ENV, value: randomUUID2(), since: Date.now() });
|
|
28678
|
-
var markEnv = (env, mark) => ({ ...env, [mark.name]: mark.value });
|
|
28679
|
-
var WINDOWS = process.platform === "win32";
|
|
28680
|
-
var LIST_PROCS = [
|
|
28681
|
-
"$ErrorActionPreference = 'Stop'",
|
|
28682
|
-
"Get-CimInstance Win32_Process | ForEach-Object { if ($_.CreationDate) { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds() } }",
|
|
28683
|
-
"'boot {0}' -f ([DateTimeOffset](Get-CimInstance Win32_OperatingSystem).LastBootUpTime).ToUnixTimeMilliseconds()"
|
|
28684
|
-
].join("; ");
|
|
28685
26846
|
|
|
28686
26847
|
// ../cli/src/lib/agent/wire/json.ts
|
|
28687
26848
|
function obj(value) {
|
|
28688
26849
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
28689
26850
|
}
|
|
28690
|
-
function
|
|
26851
|
+
function str(value) {
|
|
28691
26852
|
return typeof value === "string" ? value : "";
|
|
28692
26853
|
}
|
|
28693
26854
|
|
|
@@ -28740,7 +26901,7 @@ function connect(stdout, stdin, onCall, dialect = {}) {
|
|
|
28740
26901
|
if (!pending) continue;
|
|
28741
26902
|
waiting.delete(String(msg.id));
|
|
28742
26903
|
if (msg.error) {
|
|
28743
|
-
const said = [
|
|
26904
|
+
const said = [str(msg.error.message), str(obj(msg.error.data).message)].filter(Boolean).join(": ");
|
|
28744
26905
|
pending.fail(new RpcError(said || `the agent refused (${msg.error.code ?? "no code"})`, msg.error.code));
|
|
28745
26906
|
} else pending.ok(obj(msg.result));
|
|
28746
26907
|
}
|
|
@@ -28773,453 +26934,195 @@ function connect(stdout, stdin, onCall, dialect = {}) {
|
|
|
28773
26934
|
};
|
|
28774
26935
|
}
|
|
28775
26936
|
|
|
28776
|
-
// src/
|
|
28777
|
-
|
|
28778
|
-
|
|
28779
|
-
|
|
28780
|
-
|
|
28781
|
-
|
|
28782
|
-
|
|
28783
|
-
|
|
28784
|
-
|
|
28785
|
-
|
|
28786
|
-
|
|
28787
|
-
const temporary = `${record}.${identity.instance}.tmp`;
|
|
28788
|
-
fs13.writeFileSync(temporary, JSON.stringify(identity), { mode: 384 });
|
|
28789
|
-
fs13.renameSync(temporary, record);
|
|
28790
|
-
};
|
|
28791
|
-
const sockets = /* @__PURE__ */ new Set();
|
|
28792
|
-
const controls = /* @__PURE__ */ new Set();
|
|
28793
|
-
const services = /* @__PURE__ */ new Map();
|
|
28794
|
-
let closing = false;
|
|
28795
|
-
const server = net.createServer((socket) => {
|
|
28796
|
-
sockets.add(socket);
|
|
28797
|
-
socket.on("error", () => {
|
|
28798
|
-
});
|
|
28799
|
-
const lines = createInterface({ input: socket });
|
|
28800
|
-
let peer;
|
|
28801
|
-
let failed = false;
|
|
28802
|
-
const authTimer = setTimeout(() => socket.destroy(), TIMEOUT);
|
|
28803
|
-
lines.on("line", (line) => {
|
|
28804
|
-
if (failed) return;
|
|
28805
|
-
try {
|
|
28806
|
-
const msg = JSON.parse(line);
|
|
28807
|
-
if (controls.has(socket)) {
|
|
28808
|
-
if (msg.method === "shutdown" && sockets.size === controls.size && ![...services.values()].some((s) => s.held())) void close();
|
|
28809
|
-
} else if (!peer) {
|
|
28810
|
-
if (closing || msg.token !== token) return socket.destroy();
|
|
28811
|
-
clearTimeout(authTimer);
|
|
28812
|
-
if (msg.control === true) {
|
|
28813
|
-
if (msg.protocol !== CODEX_PROTOCOL || msg.generation !== identity.generation) return socket.destroy();
|
|
28814
|
-
controls.add(socket);
|
|
28815
|
-
socket.write(JSON.stringify(identity) + "\n");
|
|
28816
|
-
return;
|
|
28817
|
-
}
|
|
28818
|
-
if (!Array.isArray(msg.argv) || typeof msg.argv[0] !== "string") return socket.destroy();
|
|
28819
|
-
const env = obj(msg.env);
|
|
28820
|
-
const config = threadConfig(msg.argv, env);
|
|
28821
|
-
const provider = Object.fromEntries(Object.entries(config).filter(([key2]) => key2 === "model_provider" || key2.startsWith("model_providers.")));
|
|
28822
|
-
const key = crypto3.createHash("sha256").update(JSON.stringify([msg.argv[0], env.CODEX_HOME ?? "", Object.entries(provider).sort(), providerCredentials(provider, env)])).digest("hex");
|
|
28823
|
-
let service = services.get(key);
|
|
28824
|
-
if (!service) {
|
|
28825
|
-
service = providerServer(msg.argv[0], provider, env, home, (backend) => {
|
|
28826
|
-
identity.backends.push(backend);
|
|
28827
|
-
publish();
|
|
28828
|
-
});
|
|
28829
|
-
services.set(key, service);
|
|
28830
|
-
}
|
|
28831
|
-
peer = { socket, cwd: str2(msg.cwd), config, service, threads: /* @__PURE__ */ new Set(), pending: /* @__PURE__ */ new Set(), lease: crypto3.randomUUID() };
|
|
28832
|
-
service.peers.add(peer);
|
|
28833
|
-
} else {
|
|
28834
|
-
const p = peer;
|
|
28835
|
-
const done = p.service.request(p, msg);
|
|
28836
|
-
p.pending.add(done);
|
|
28837
|
-
void done.finally(() => p.pending.delete(done));
|
|
28838
|
-
}
|
|
28839
|
-
} catch (e) {
|
|
28840
|
-
failed = true;
|
|
28841
|
-
socket.end(JSON.stringify({ method: "error", params: { error: { message: e instanceof Error ? e.message : "Invalid Codex connection." } } }) + "\n");
|
|
28842
|
-
}
|
|
28843
|
-
});
|
|
28844
|
-
socket.once("close", () => {
|
|
28845
|
-
clearTimeout(authTimer);
|
|
28846
|
-
sockets.delete(socket);
|
|
28847
|
-
controls.delete(socket);
|
|
28848
|
-
if (peer) void peer.service.release(peer);
|
|
28849
|
-
});
|
|
28850
|
-
});
|
|
28851
|
-
await new Promise((resolve, reject) => {
|
|
28852
|
-
server.once("error", reject);
|
|
28853
|
-
server.listen(address, resolve);
|
|
28854
|
-
});
|
|
28855
|
-
if (process.platform !== "win32") fs13.chmodSync(address, 384);
|
|
28856
|
-
publish();
|
|
28857
|
-
let closingWork;
|
|
28858
|
-
let finished;
|
|
28859
|
-
const closed = new Promise((resolve) => {
|
|
28860
|
-
finished = resolve;
|
|
28861
|
-
});
|
|
28862
|
-
const close = () => closingWork ??= (async () => {
|
|
28863
|
-
closing = true;
|
|
28864
|
-
server.close();
|
|
28865
|
-
await Promise.all([...services.values()].map((service) => service.close()));
|
|
28866
|
-
for (const socket of sockets) socket.destroy();
|
|
28867
|
-
if (process.platform !== "win32") fs13.rmSync(address, { force: true });
|
|
28868
|
-
try {
|
|
28869
|
-
if (JSON.parse(fs13.readFileSync(record, "utf8")).instance === identity.instance) fs13.rmSync(record, { force: true });
|
|
28870
|
-
} catch {
|
|
28871
|
-
}
|
|
28872
|
-
finished();
|
|
28873
|
-
})();
|
|
28874
|
-
return {
|
|
28875
|
-
env: { WILDCRANE_CODEX_SERVER: record, WILDCRANE_CODEX_GENERATION: identity.generation, WILDCRANE_CODEX_PROXY: fileURLToPath2(new URL("./codex-proxy.mjs", import.meta.url)) },
|
|
28876
|
-
close,
|
|
28877
|
-
closed,
|
|
28878
|
-
idle: () => sockets.size === 0 && ![...services.values()].some((s) => s.held())
|
|
28879
|
-
};
|
|
26937
|
+
// src/home.ts
|
|
26938
|
+
import fs2 from "node:fs";
|
|
26939
|
+
import os from "node:os";
|
|
26940
|
+
import path3 from "node:path";
|
|
26941
|
+
|
|
26942
|
+
// src/proxy.ts
|
|
26943
|
+
var import_undici = __toESM(require_undici(), 1);
|
|
26944
|
+
|
|
26945
|
+
// src/home.ts
|
|
26946
|
+
function runnerHome() {
|
|
26947
|
+
return process.env.WILDCRANE_HOME || path3.join(os.homedir(), ".wildcrane");
|
|
28880
26948
|
}
|
|
28881
|
-
function
|
|
28882
|
-
const
|
|
28883
|
-
|
|
28884
|
-
|
|
28885
|
-
const requests = /* @__PURE__ */ new Map();
|
|
28886
|
-
const unloading = /* @__PURE__ */ new Map();
|
|
28887
|
-
const retained = /* @__PURE__ */ new Map();
|
|
28888
|
-
const quarantined = /* @__PURE__ */ new Set();
|
|
28889
|
-
let backend = "";
|
|
28890
|
-
let child;
|
|
28891
|
-
let rpc;
|
|
28892
|
-
let initializing;
|
|
28893
|
-
let closing = false;
|
|
28894
|
-
let exited = Promise.resolve();
|
|
28895
|
-
let stopChild;
|
|
28896
|
-
const send = (p, value) => {
|
|
28897
|
-
if (!p.socket.destroyed) p.socket.write(JSON.stringify(value) + "\n");
|
|
28898
|
-
};
|
|
28899
|
-
const claim = (p, id) => {
|
|
28900
|
-
if (!id) return;
|
|
28901
|
-
if (owners.has(id) && owners.get(id) !== p) throw Error("Codex thread is already in use by another run.");
|
|
28902
|
-
owners.set(id, p);
|
|
28903
|
-
p.threads.add(id);
|
|
28904
|
-
};
|
|
28905
|
-
const ensure = () => {
|
|
28906
|
-
if (closing) return Promise.reject(Error("Runner is stopping."));
|
|
28907
|
-
if (initializing) return initializing;
|
|
28908
|
-
const env = { ...process.env, OPENAI_API_KEY: void 0, CODEX_HOME: environment.CODEX_HOME ?? process.env.CODEX_HOME, WILDCRANE_JOB: "1" };
|
|
28909
|
-
for (const key of Object.keys(env)) if (/^(KANBAN_|AI4KANBAN_EXECUTION|WILDCRANE_FLOW_WORKER|WILDCRANE_CODEX_)/.test(key)) delete env[key];
|
|
28910
|
-
Object.assign(env, providerCredentials(provider, environment));
|
|
28911
|
-
backend = crypto3.randomUUID();
|
|
28912
|
-
const mark = stopMark();
|
|
28913
|
-
const start = spawnable(command, ["app-server", "-c", "thread_unload_delay_secs=0", ...Object.entries(provider).flatMap(([key, value]) => ["-c", `${key}=${tomlValue(value)}`])], { cwd: home, env: markEnv(env, mark), detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"] });
|
|
28914
|
-
const current2 = child = spawn(start.command, start.args, start.options);
|
|
28915
|
-
const processAt = Date.now();
|
|
28916
|
-
const stop = () => {
|
|
28917
|
-
current2.kill("SIGKILL");
|
|
28918
|
-
};
|
|
28919
|
-
stopChild = stop;
|
|
28920
|
-
current2.stdin.on("error", () => {
|
|
28921
|
-
});
|
|
28922
|
-
current2.stderr.resume();
|
|
28923
|
-
exited = new Promise((resolve) => current2.once("close", resolve));
|
|
28924
|
-
const broken = () => {
|
|
28925
|
-
if (child !== current2) return;
|
|
28926
|
-
stop();
|
|
28927
|
-
child = void 0;
|
|
28928
|
-
rpc = void 0;
|
|
28929
|
-
initializing = void 0;
|
|
28930
|
-
for (const p of peers) p.socket.destroy();
|
|
28931
|
-
retained.clear();
|
|
28932
|
-
quarantined.clear();
|
|
28933
|
-
owners.clear();
|
|
28934
|
-
active.clear();
|
|
28935
|
-
requests.clear();
|
|
28936
|
-
for (const done of unloading.values()) done();
|
|
28937
|
-
unloading.clear();
|
|
28938
|
-
};
|
|
28939
|
-
current2.once("error", broken);
|
|
28940
|
-
current2.once("exit", broken);
|
|
28941
|
-
current2.once("close", broken);
|
|
28942
|
-
try {
|
|
28943
|
-
if (current2.pid) remember({ pid: current2.pid, since: processAt, mark });
|
|
28944
|
-
} catch (error) {
|
|
28945
|
-
stop();
|
|
28946
|
-
throw error;
|
|
28947
|
-
}
|
|
28948
|
-
const wire = rpc = connect(current2.stdout, current2.stdin, (msg) => {
|
|
28949
|
-
const params = obj(msg.params);
|
|
28950
|
-
const thread = obj(params.thread);
|
|
28951
|
-
const id = str2(params.threadId) || str2(thread.id);
|
|
28952
|
-
if (msg.method === "thread/closed") {
|
|
28953
|
-
unloading.get(id)?.();
|
|
28954
|
-
unloading.delete(id);
|
|
28955
|
-
}
|
|
28956
|
-
if (msg.method === "turn/started") active.set(id, str2(obj(params.turn).id));
|
|
28957
|
-
if (msg.method === "turn/completed") active.delete(id);
|
|
28958
|
-
if (msg.method === "item/completed" && obj(params.item).type === "commandExecution") {
|
|
28959
|
-
for (const [root2, group] of retained) {
|
|
28960
|
-
group.kept = group.kept.filter((t) => t.threadId !== id || t.itemId !== obj(params.item).id);
|
|
28961
|
-
if (group.kept.length) continue;
|
|
28962
|
-
retained.delete(root2);
|
|
28963
|
-
const p = group.peer;
|
|
28964
|
-
p.settled = { root: root2, execution: group.execution, kept: [] };
|
|
28965
|
-
p.closing = void 0;
|
|
28966
|
-
for (const thread2 of group.threads) claim(p, thread2);
|
|
28967
|
-
void release2(p);
|
|
28968
|
-
}
|
|
28969
|
-
}
|
|
28970
|
-
let owner = owners.get(id);
|
|
28971
|
-
if (!owner) {
|
|
28972
|
-
const parent = str2(thread.parentThreadId) || str2(thread.forkedFromId);
|
|
28973
|
-
owner = owners.get(parent);
|
|
28974
|
-
if (owner) claim(owner, id);
|
|
28975
|
-
}
|
|
28976
|
-
if (owner) {
|
|
28977
|
-
const item = obj(params.item);
|
|
28978
|
-
if (item.type === "subAgentActivity" && item.kind === "started" && str2(item.agentThreadId) && !owners.has(str2(item.agentThreadId))) claim(owner, str2(item.agentThreadId));
|
|
28979
|
-
if (item.type === "collabAgentToolCall" && item.tool === "spawnAgent") {
|
|
28980
|
-
for (const id2 of Array.isArray(item.receiverThreadIds) ? item.receiverThreadIds : []) {
|
|
28981
|
-
if (typeof id2 === "string" && !owners.has(id2)) claim(owner, id2);
|
|
28982
|
-
}
|
|
28983
|
-
}
|
|
28984
|
-
if (msg.id !== void 0) requests.set(String(msg.id), owner);
|
|
28985
|
-
send(owner, msg);
|
|
28986
|
-
} else if (msg.id !== void 0) wire.refuse(msg.id, "No run owns this request.");
|
|
28987
|
-
});
|
|
28988
|
-
initializing = bounded(wire.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), TIMEOUT, "Codex initialize timed out.").then((result) => {
|
|
28989
|
-
wire.notify("initialized");
|
|
28990
|
-
return result;
|
|
28991
|
-
});
|
|
28992
|
-
void initializing.catch(() => {
|
|
28993
|
-
if (child === current2) stop();
|
|
28994
|
-
});
|
|
28995
|
-
return initializing;
|
|
28996
|
-
};
|
|
28997
|
-
const terminals = async (wire, threadId) => {
|
|
28998
|
-
const result = [];
|
|
28999
|
-
const seen = /* @__PURE__ */ new Set();
|
|
29000
|
-
let cursor = null;
|
|
29001
|
-
do {
|
|
29002
|
-
if (seen.has(cursor)) throw Error("Codex repeated a terminal cursor.");
|
|
29003
|
-
seen.add(cursor);
|
|
29004
|
-
const page = await wire.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
|
|
29005
|
-
for (const value of Array.isArray(page.data) ? page.data : []) result.push({ ...obj(value), threadId });
|
|
29006
|
-
cursor = page.nextCursor;
|
|
29007
|
-
} while (cursor);
|
|
29008
|
-
return result;
|
|
29009
|
-
};
|
|
29010
|
-
const release2 = (p) => {
|
|
29011
|
-
if (p.closing) return p.closing;
|
|
29012
|
-
const cleanup = async () => {
|
|
29013
|
-
await Promise.allSettled(p.pending);
|
|
29014
|
-
const wire = p.wire;
|
|
29015
|
-
if (wire) {
|
|
29016
|
-
for (const [id, owner] of requests) if (owner === p) {
|
|
29017
|
-
wire.refuse(id, "Run disconnected.");
|
|
29018
|
-
requests.delete(id);
|
|
29019
|
-
}
|
|
29020
|
-
if (p.settled?.kept.length && !closing) {
|
|
29021
|
-
retained.set(p.settled.root, { threads: new Set(p.threads), kept: p.settled.kept, execution: p.settled.execution, peer: p, settings: JSON.stringify([p.cwd, p.config]) });
|
|
29022
|
-
} else {
|
|
29023
|
-
for (const threadId of p.threads) {
|
|
29024
|
-
if (owners.get(threadId) !== p || wire !== rpc) continue;
|
|
29025
|
-
if (!p.settled) {
|
|
29026
|
-
const turnId = active.get(threadId);
|
|
29027
|
-
if (turnId) await wire.call("turn/interrupt", { threadId, turnId });
|
|
29028
|
-
try {
|
|
29029
|
-
await wire.call("thread/backgroundTerminals/clean", { threadId });
|
|
29030
|
-
} catch (e) {
|
|
29031
|
-
if (!(e instanceof RpcError) || e.code !== -32601) throw e;
|
|
29032
|
-
}
|
|
29033
|
-
}
|
|
29034
|
-
const unloaded = new Promise((resolve) => unloading.set(threadId, resolve));
|
|
29035
|
-
const result = obj(await wire.call("thread/unsubscribe", { threadId }));
|
|
29036
|
-
if (result.status === "unsubscribed") await unloaded;
|
|
29037
|
-
unloading.delete(threadId);
|
|
29038
|
-
}
|
|
29039
|
-
}
|
|
29040
|
-
}
|
|
29041
|
-
for (const id of p.threads) if (owners.get(id) === p) owners.delete(id);
|
|
29042
|
-
quarantined.delete(p);
|
|
29043
|
-
};
|
|
29044
|
-
const work = cleanup();
|
|
29045
|
-
p.closing = (async () => {
|
|
29046
|
-
try {
|
|
29047
|
-
await bounded(work, TIMEOUT, "Codex thread cleanup timed out; the thread remains reserved.");
|
|
29048
|
-
} catch (e) {
|
|
29049
|
-
quarantined.add(p);
|
|
29050
|
-
console.error(e instanceof Error ? e.message : String(e));
|
|
29051
|
-
send(p, { method: "wildcrane/cleanup", params: { status: "unconfirmed", lease: p.lease } });
|
|
29052
|
-
}
|
|
29053
|
-
peers.delete(p);
|
|
29054
|
-
p.socket.end();
|
|
29055
|
-
})();
|
|
29056
|
-
return p.closing;
|
|
29057
|
-
};
|
|
29058
|
-
const request = async (p, msg) => {
|
|
29059
|
-
if (msg.method === "wildcrane/release") {
|
|
29060
|
-
void release2(p);
|
|
29061
|
-
return;
|
|
29062
|
-
}
|
|
29063
|
-
if (p.closing || !msg.method) {
|
|
29064
|
-
if (msg.id !== void 0 && !msg.method) {
|
|
29065
|
-
if (requests.get(String(msg.id)) !== p) return;
|
|
29066
|
-
requests.delete(String(msg.id));
|
|
29067
|
-
if (msg.error) rpc?.refuse(msg.id, msg.error.message ?? "Interaction refused.");
|
|
29068
|
-
else rpc?.reply(msg.id, obj(msg.result));
|
|
29069
|
-
}
|
|
29070
|
-
return;
|
|
29071
|
-
}
|
|
29072
|
-
const id = msg.id;
|
|
29073
|
-
try {
|
|
29074
|
-
const initialized = await ensure();
|
|
29075
|
-
p.wire = rpc;
|
|
29076
|
-
if (msg.method === "initialize") {
|
|
29077
|
-
send(p, { id, result: { ...initialized, wildcrane: { instance: backend, lease: p.lease } } });
|
|
29078
|
-
return;
|
|
29079
|
-
}
|
|
29080
|
-
if (msg.method === "initialized") return;
|
|
29081
|
-
const wire = rpc;
|
|
29082
|
-
let params = obj(msg.params);
|
|
29083
|
-
if (msg.method === "wildcrane/settled") {
|
|
29084
|
-
if (params.instance !== backend || params.lease !== p.lease || !str2(params.execution) || owners.get(str2(params.threadId)) !== p || params.confirmed !== true) throw Error("Codex cleanup is unconfirmed; the host will perform bounded session recovery.");
|
|
29085
|
-
const kept = Array.isArray(params.kept) ? params.kept.map(obj) : [];
|
|
29086
|
-
await bounded((async () => {
|
|
29087
|
-
const actual = [];
|
|
29088
|
-
for (const thread of p.threads) {
|
|
29089
|
-
if (active.has(thread)) throw Error("A Codex turn is still active.");
|
|
29090
|
-
actual.push(...await terminals(wire, thread));
|
|
29091
|
-
}
|
|
29092
|
-
const key = (v) => JSON.stringify([v.threadId, v.itemId, v.processId]);
|
|
29093
|
-
if (new Set(kept.map(key)).size !== kept.length || actual.length !== kept.length || actual.some((t) => !kept.some((k) => key(k) === key(t)))) throw Error("Codex retained terminal state changed before handoff.");
|
|
29094
|
-
})(), TIMEOUT, "Codex retention verification timed out.");
|
|
29095
|
-
if (p.closing || wire !== rpc) throw Error("Codex execution ownership expired.");
|
|
29096
|
-
p.settled = { root: str2(params.threadId), execution: str2(params.execution), kept };
|
|
29097
|
-
send(p, { id, result: { confirmed: true, instance: backend, lease: p.lease } });
|
|
29098
|
-
return;
|
|
29099
|
-
}
|
|
29100
|
-
let held;
|
|
29101
|
-
if (["thread/start", "thread/resume", "thread/fork"].includes(msg.method)) {
|
|
29102
|
-
if (msg.method !== "thread/start") {
|
|
29103
|
-
const source = str2(params.threadId);
|
|
29104
|
-
const previous = retained.get(source);
|
|
29105
|
-
if (previous && msg.method === "thread/resume" && previous.settings !== JSON.stringify([p.cwd, p.config])) throw Error("This Codex version cannot change execution settings while retaining a loaded session. Its services and saved results were preserved; no new work was submitted.");
|
|
29106
|
-
held = msg.method === "thread/resume" ? previous : void 0;
|
|
29107
|
-
if ([...retained.values()].some((group) => group.threads.has(source)) && !previous) throw Error("Resume the owning Codex thread to adopt its retained work.");
|
|
29108
|
-
if (msg.method === "thread/resume" || !previous) claim(p, source);
|
|
29109
|
-
if (held) {
|
|
29110
|
-
for (const thread of held.threads) claim(p, thread);
|
|
29111
|
-
retained.delete(source);
|
|
29112
|
-
}
|
|
29113
|
-
}
|
|
29114
|
-
const cwd = params.cwd ?? p.cwd;
|
|
29115
|
-
const settings = await wire.call("config/read", { cwd, includeLayers: false });
|
|
29116
|
-
const config = { ...p.config, ...obj(params.config), thread_unload_delay_secs: 0 };
|
|
29117
|
-
mcpEnvironment(config, obj(obj(settings.config).mcp_servers));
|
|
29118
|
-
params = { ...params, cwd, config };
|
|
29119
|
-
} else {
|
|
29120
|
-
const threadId2 = str2(params.threadId);
|
|
29121
|
-
if (!threadId2 || owners.get(threadId2) !== p) throw Error("This run does not own that Codex thread.");
|
|
29122
|
-
}
|
|
29123
|
-
if (msg.method === "turn/start") p.settled = void 0;
|
|
29124
|
-
const result = await wire.call(msg.method, params);
|
|
29125
|
-
if (held) result.retainedThreads = [...held.threads].map((id2) => ({ id: id2 }));
|
|
29126
|
-
const threadId = str2(obj(result.thread).id);
|
|
29127
|
-
if (threadId) claim(p, threadId);
|
|
29128
|
-
if (id !== void 0) send(p, { id, result });
|
|
29129
|
-
} catch (e) {
|
|
29130
|
-
if (id !== void 0) send(p, { id, error: { code: e instanceof RpcError ? e.code : -32e3, message: e instanceof Error ? e.message : String(e) } });
|
|
29131
|
-
}
|
|
29132
|
-
};
|
|
29133
|
-
return {
|
|
29134
|
-
peers,
|
|
29135
|
-
request,
|
|
29136
|
-
release: release2,
|
|
29137
|
-
held: () => retained.size > 0 || quarantined.size > 0,
|
|
29138
|
-
async close() {
|
|
29139
|
-
closing = true;
|
|
29140
|
-
await bounded(Promise.allSettled([...peers].map(release2)), TIMEOUT, "Codex cleanup timed out.").catch(() => {
|
|
29141
|
-
});
|
|
29142
|
-
const current2 = child;
|
|
29143
|
-
if (current2) {
|
|
29144
|
-
stopChild?.();
|
|
29145
|
-
const timer = setTimeout(() => current2.kill("SIGKILL"), 2e3);
|
|
29146
|
-
await exited;
|
|
29147
|
-
clearTimeout(timer);
|
|
29148
|
-
}
|
|
29149
|
-
}
|
|
29150
|
-
};
|
|
26949
|
+
function runnerCwd() {
|
|
26950
|
+
const dir = runnerHome();
|
|
26951
|
+
fs2.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
26952
|
+
return dir;
|
|
29151
26953
|
}
|
|
29152
|
-
|
|
29153
|
-
|
|
29154
|
-
|
|
29155
|
-
|
|
29156
|
-
|
|
29157
|
-
|
|
29158
|
-
|
|
29159
|
-
|
|
29160
|
-
|
|
29161
|
-
|
|
29162
|
-
|
|
26954
|
+
|
|
26955
|
+
// src/codex-native.ts
|
|
26956
|
+
var CODEX_TIMEOUT = 1e4;
|
|
26957
|
+
var nativeDirectory = () => path4.join(runnerCwd(), "codex-native");
|
|
26958
|
+
var leaseFile = (backend, thread) => path4.join(nativeDirectory(), "threads", backend.instance, `${crypto.createHash("sha256").update(thread).digest("hex")}.json`);
|
|
26959
|
+
var processIdentity = () => ({ pid: process.pid, identity: connectionIdentity(process.pid) });
|
|
26960
|
+
function writePrivate(file, value) {
|
|
26961
|
+
fs3.mkdirSync(path4.dirname(file), { recursive: true, mode: 448 });
|
|
26962
|
+
const temporary = `${file}.${crypto.randomUUID()}.tmp`;
|
|
26963
|
+
fs3.writeFileSync(temporary, JSON.stringify(value), { mode: 384 });
|
|
26964
|
+
fs3.renameSync(temporary, file);
|
|
26965
|
+
}
|
|
26966
|
+
function readPrivate(file) {
|
|
26967
|
+
try {
|
|
26968
|
+
return JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
26969
|
+
} catch (error) {
|
|
26970
|
+
if (error.code === "ENOENT") return;
|
|
26971
|
+
throw error;
|
|
29163
26972
|
}
|
|
29164
26973
|
}
|
|
29165
|
-
function
|
|
29166
|
-
const
|
|
29167
|
-
|
|
29168
|
-
|
|
29169
|
-
|
|
29170
|
-
|
|
29171
|
-
|
|
29172
|
-
|
|
29173
|
-
|
|
29174
|
-
const pair = argv[++i] ?? "";
|
|
29175
|
-
const at = pair.indexOf("=");
|
|
29176
|
-
if (at < 1) throw Error("Invalid Codex configuration override.");
|
|
29177
|
-
const key = pair.slice(0, at), value = pair.slice(at + 1).trim();
|
|
26974
|
+
async function nativeConnection(backend, onMessage) {
|
|
26975
|
+
const unix = backend.endpoint.startsWith("unix://");
|
|
26976
|
+
const dispatcher = unix ? new import_undici2.Agent({ connect: { socketPath: backend.endpoint.slice(7) } }) : void 0;
|
|
26977
|
+
const ws = new import_undici2.WebSocket(unix ? "ws://localhost" : backend.endpoint, {
|
|
26978
|
+
...dispatcher ? { dispatcher } : {},
|
|
26979
|
+
...backend.token ? { headers: { authorization: `Bearer ${backend.token}` } } : {}
|
|
26980
|
+
});
|
|
26981
|
+
const incoming = new PassThrough();
|
|
26982
|
+
const outgoing = new Writable({ write(chunk, _encoding, done) {
|
|
29178
26983
|
try {
|
|
29179
|
-
|
|
29180
|
-
|
|
29181
|
-
|
|
26984
|
+
ws.send(String(chunk).trimEnd());
|
|
26985
|
+
done();
|
|
26986
|
+
} catch (error) {
|
|
26987
|
+
done(error);
|
|
29182
26988
|
}
|
|
26989
|
+
} });
|
|
26990
|
+
incoming.on("error", () => {
|
|
26991
|
+
});
|
|
26992
|
+
outgoing.on("error", () => {
|
|
26993
|
+
});
|
|
26994
|
+
ws.addEventListener("message", (event) => incoming.write(String(event.data) + "\n"));
|
|
26995
|
+
ws.addEventListener("close", () => incoming.destroy());
|
|
26996
|
+
ws.addEventListener("error", () => incoming.destroy(Error("Codex native connection failed.")));
|
|
26997
|
+
const close = () => {
|
|
26998
|
+
ws.close();
|
|
26999
|
+
incoming.destroy();
|
|
27000
|
+
outgoing.destroy();
|
|
27001
|
+
void dispatcher?.destroy();
|
|
27002
|
+
};
|
|
27003
|
+
try {
|
|
27004
|
+
await bounded(new Promise((resolve, reject) => {
|
|
27005
|
+
ws.addEventListener("open", () => resolve(), { once: true });
|
|
27006
|
+
ws.addEventListener("error", () => reject(Error("Codex native listener did not answer.")), { once: true });
|
|
27007
|
+
}), CODEX_TIMEOUT, "Codex native connection timed out.");
|
|
27008
|
+
} catch (error) {
|
|
27009
|
+
close();
|
|
27010
|
+
throw error;
|
|
29183
27011
|
}
|
|
29184
|
-
const
|
|
29185
|
-
|
|
29186
|
-
|
|
27012
|
+
const rpc = connect(incoming, outgoing, onMessage);
|
|
27013
|
+
return { rpc, incoming, close };
|
|
27014
|
+
}
|
|
27015
|
+
async function initializeNative(connection) {
|
|
27016
|
+
const result = await bounded(connection.rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), CODEX_TIMEOUT, "Codex initialize timed out.");
|
|
27017
|
+
connection.rpc.notify("initialized");
|
|
27018
|
+
return result;
|
|
29187
27019
|
}
|
|
29188
|
-
function
|
|
29189
|
-
const
|
|
29190
|
-
|
|
29191
|
-
|
|
29192
|
-
|
|
27020
|
+
async function backgroundTerminals(rpc, threadId) {
|
|
27021
|
+
const result = [], seen = /* @__PURE__ */ new Set();
|
|
27022
|
+
let cursor = null;
|
|
27023
|
+
do {
|
|
27024
|
+
if (seen.has(cursor)) throw Error("Codex repeated a terminal cursor.");
|
|
27025
|
+
seen.add(cursor);
|
|
27026
|
+
const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
|
|
27027
|
+
for (const value of Array.isArray(page.data) ? page.data : []) result.push({ ...obj(value), threadId });
|
|
27028
|
+
cursor = page.nextCursor;
|
|
27029
|
+
} while (cursor);
|
|
27030
|
+
return result;
|
|
27031
|
+
}
|
|
27032
|
+
|
|
27033
|
+
// src/settings-control.ts
|
|
27034
|
+
import fs4 from "node:fs";
|
|
27035
|
+
import path5 from "node:path";
|
|
27036
|
+
var directory = () => path5.join(runnerHome(), "executors");
|
|
27037
|
+
var epochFile = () => path5.join(runnerHome(), "account-generation");
|
|
27038
|
+
function accountGeneration() {
|
|
27039
|
+
try {
|
|
27040
|
+
return fs4.readFileSync(epochFile(), "utf8");
|
|
27041
|
+
} catch {
|
|
27042
|
+
return "";
|
|
29193
27043
|
}
|
|
29194
|
-
return credentials;
|
|
29195
27044
|
}
|
|
29196
|
-
function
|
|
29197
|
-
|
|
29198
|
-
|
|
29199
|
-
|
|
27045
|
+
function executorRecord() {
|
|
27046
|
+
fs4.mkdirSync(directory(), { recursive: true, mode: 448 });
|
|
27047
|
+
const file = path5.join(directory(), `${process.pid}.json`);
|
|
27048
|
+
fs4.writeFileSync(file, "{}", { mode: 384 });
|
|
27049
|
+
return () => fs4.rmSync(file, { force: true });
|
|
29200
27050
|
}
|
|
29201
27051
|
|
|
29202
|
-
// src/codex-
|
|
29203
|
-
|
|
29204
|
-
|
|
29205
|
-
|
|
29206
|
-
|
|
29207
|
-
|
|
29208
|
-
|
|
29209
|
-
|
|
29210
|
-
const
|
|
29211
|
-
let
|
|
29212
|
-
const
|
|
29213
|
-
|
|
29214
|
-
|
|
29215
|
-
|
|
29216
|
-
|
|
29217
|
-
|
|
27052
|
+
// src/codex-retained.ts
|
|
27053
|
+
async function retain() {
|
|
27054
|
+
const backend = readPrivate(process.argv[2]);
|
|
27055
|
+
const initial = readPrivate(process.argv[3]);
|
|
27056
|
+
const lease = process.argv[4];
|
|
27057
|
+
if (!backend || !initial?.retained || initial.lease !== lease || initial.instance !== backend.instance || backend.generation !== accountGeneration()) throw Error("Codex retained ownership expired.");
|
|
27058
|
+
const identity = processIdentity();
|
|
27059
|
+
const release = executorRecord();
|
|
27060
|
+
const state = { ...initial, ...identity };
|
|
27061
|
+
let closing = false, transferred = false;
|
|
27062
|
+
const active = /* @__PURE__ */ new Map(), unloaded = /* @__PURE__ */ new Map();
|
|
27063
|
+
let wake;
|
|
27064
|
+
const done = new Promise((resolve) => {
|
|
27065
|
+
wake = resolve;
|
|
27066
|
+
});
|
|
27067
|
+
const connection = await nativeConnection(backend, (message) => {
|
|
27068
|
+
const params = obj(message.params), id = str(params.threadId);
|
|
27069
|
+
if (message.id !== void 0) {
|
|
27070
|
+
connection.rpc.refuse(message.id, "Retained services cannot request new interaction.");
|
|
27071
|
+
return;
|
|
27072
|
+
}
|
|
27073
|
+
if (message.method === "turn/started") active.set(id, str(obj(params.turn).id));
|
|
27074
|
+
if (message.method === "turn/completed") active.delete(id);
|
|
27075
|
+
if (message.method === "thread/closed") unloaded.get(id)?.();
|
|
27076
|
+
if (message.method === "item/completed" && obj(params.item).type === "commandExecution") {
|
|
27077
|
+
state.retained = { ...state.retained, kept: state.retained.kept.filter((item) => item.threadId !== id || item.itemId !== obj(params.item).id) };
|
|
27078
|
+
for (const thread of initial.threads) {
|
|
27079
|
+
const current = readPrivate(leaseFile(backend, thread));
|
|
27080
|
+
if (current?.lease === lease && current.pid === process.pid) writePrivate(leaseFile(backend, thread), { ...state, retained: state.retained.kept.length ? state.retained : void 0 });
|
|
27081
|
+
}
|
|
27082
|
+
if (!state.retained.kept.length) wake();
|
|
27083
|
+
}
|
|
29218
27084
|
});
|
|
29219
|
-
|
|
29220
|
-
|
|
29221
|
-
|
|
29222
|
-
|
|
29223
|
-
|
|
29224
|
-
|
|
27085
|
+
try {
|
|
27086
|
+
await initializeNative(connection);
|
|
27087
|
+
for (const id of initial.threads) await connection.rpc.call("thread/resume", { threadId: id });
|
|
27088
|
+
if (readPrivate(process.argv[3])?.lease !== lease) throw Error("Codex retained ownership changed during preparation.");
|
|
27089
|
+
for (const id of initial.threads) writePrivate(leaseFile(backend, id), state);
|
|
27090
|
+
process.send?.({ ready: lease });
|
|
27091
|
+
const timer = setInterval(() => {
|
|
27092
|
+
const current = readPrivate(process.argv[3]);
|
|
27093
|
+
if (current?.lease !== lease && current?.adopting !== lease) {
|
|
27094
|
+
transferred = true;
|
|
27095
|
+
wake();
|
|
27096
|
+
}
|
|
27097
|
+
if (backend.generation !== accountGeneration()) wake();
|
|
27098
|
+
}, 200);
|
|
27099
|
+
connection.incoming.once("close", wake);
|
|
27100
|
+
for (const signal of ["SIGTERM", "SIGINT"]) process.once(signal, wake);
|
|
27101
|
+
await done;
|
|
27102
|
+
closing = true;
|
|
27103
|
+
clearInterval(timer);
|
|
27104
|
+
if (transferred) return;
|
|
27105
|
+
await bounded((async () => {
|
|
27106
|
+
for (const id of initial.threads) {
|
|
27107
|
+
if (readPrivate(leaseFile(backend, id))?.lease !== lease) continue;
|
|
27108
|
+
if (active.has(id)) await connection.rpc.call("turn/interrupt", { threadId: id, turnId: active.get(id) });
|
|
27109
|
+
const terminals = await backgroundTerminals(connection.rpc, id);
|
|
27110
|
+
if (terminals.length) await connection.rpc.call("thread/backgroundTerminals/clean", { threadId: id });
|
|
27111
|
+
const closed = new Promise((resolve) => unloaded.set(id, resolve));
|
|
27112
|
+
const answer = await connection.rpc.call("thread/unsubscribe", { threadId: id });
|
|
27113
|
+
if (answer.status === "unsubscribed") await closed;
|
|
27114
|
+
if (readPrivate(leaseFile(backend, id))?.lease === lease) fs5.rmSync(leaseFile(backend, id), { force: true });
|
|
27115
|
+
}
|
|
27116
|
+
})(), CODEX_TIMEOUT, "Retained Codex cleanup is unconfirmed.");
|
|
27117
|
+
} catch (error) {
|
|
27118
|
+
for (const id of initial.threads) if (readPrivate(leaseFile(backend, id))?.lease === lease) writePrivate(leaseFile(backend, id), { ...state, retained: void 0, uncertain: true });
|
|
27119
|
+
if (!closing) throw error;
|
|
27120
|
+
} finally {
|
|
27121
|
+
connection.close();
|
|
27122
|
+
release();
|
|
27123
|
+
}
|
|
29225
27124
|
}
|
|
27125
|
+
void retain().catch((error) => {
|
|
27126
|
+
console.error(String(error));
|
|
27127
|
+
process.exitCode = 1;
|
|
27128
|
+
});
|