billion-context 0.1.79 → 0.1.80-pr.506.329
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +611 -387
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -132,17 +132,17 @@ var require_timers = __commonJS({
|
|
|
132
132
|
let idx = 0;
|
|
133
133
|
let len = fastTimers.length;
|
|
134
134
|
while (idx < len) {
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
} else if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
if (
|
|
145
|
-
|
|
135
|
+
const timer3 = fastTimers[idx];
|
|
136
|
+
if (timer3._state === PENDING) {
|
|
137
|
+
timer3._idleStart = fastNow - TICK_MS;
|
|
138
|
+
timer3._state = ACTIVE;
|
|
139
|
+
} else if (timer3._state === ACTIVE && fastNow >= timer3._idleStart + timer3._idleTimeout) {
|
|
140
|
+
timer3._state = TO_BE_CLEARED;
|
|
141
|
+
timer3._idleStart = -1;
|
|
142
|
+
timer3._onTimeout(timer3._timerArg);
|
|
143
|
+
}
|
|
144
|
+
if (timer3._state === TO_BE_CLEARED) {
|
|
145
|
+
timer3._state = NOT_IN_LIST;
|
|
146
146
|
if (--len !== 0) {
|
|
147
147
|
fastTimers[idx] = fastTimers[len];
|
|
148
148
|
}
|
|
@@ -1141,14 +1141,14 @@ var require_util = __commonJS({
|
|
|
1141
1141
|
}
|
|
1142
1142
|
const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
|
|
1143
1143
|
let origin = url.origin != null ? url.origin : `${url.protocol || ""}//${url.hostname || ""}:${port}`;
|
|
1144
|
-
let
|
|
1144
|
+
let path18 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
|
|
1145
1145
|
if (origin[origin.length - 1] === "/") {
|
|
1146
1146
|
origin = origin.slice(0, origin.length - 1);
|
|
1147
1147
|
}
|
|
1148
|
-
if (
|
|
1149
|
-
|
|
1148
|
+
if (path18 && path18[0] !== "/") {
|
|
1149
|
+
path18 = `/${path18}`;
|
|
1150
1150
|
}
|
|
1151
|
-
return new URL(`${origin}${
|
|
1151
|
+
return new URL(`${origin}${path18}`);
|
|
1152
1152
|
}
|
|
1153
1153
|
if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) {
|
|
1154
1154
|
throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`.");
|
|
@@ -1969,9 +1969,9 @@ var require_diagnostics = __commonJS({
|
|
|
1969
1969
|
"undici:client:sendHeaders",
|
|
1970
1970
|
(evt) => {
|
|
1971
1971
|
const {
|
|
1972
|
-
request: { method, path:
|
|
1972
|
+
request: { method, path: path18, origin }
|
|
1973
1973
|
} = evt;
|
|
1974
|
-
debugLog("sending request to %s %s%s", method, origin,
|
|
1974
|
+
debugLog("sending request to %s %s%s", method, origin, path18);
|
|
1975
1975
|
}
|
|
1976
1976
|
);
|
|
1977
1977
|
}
|
|
@@ -1989,14 +1989,14 @@ var require_diagnostics = __commonJS({
|
|
|
1989
1989
|
"undici:request:headers",
|
|
1990
1990
|
(evt) => {
|
|
1991
1991
|
const {
|
|
1992
|
-
request: { method, path:
|
|
1992
|
+
request: { method, path: path18, origin },
|
|
1993
1993
|
response: { statusCode }
|
|
1994
1994
|
} = evt;
|
|
1995
1995
|
debugLog(
|
|
1996
1996
|
"received response to %s %s%s - HTTP %d",
|
|
1997
1997
|
method,
|
|
1998
1998
|
origin,
|
|
1999
|
-
|
|
1999
|
+
path18,
|
|
2000
2000
|
statusCode
|
|
2001
2001
|
);
|
|
2002
2002
|
}
|
|
@@ -2005,23 +2005,23 @@ var require_diagnostics = __commonJS({
|
|
|
2005
2005
|
"undici:request:trailers",
|
|
2006
2006
|
(evt) => {
|
|
2007
2007
|
const {
|
|
2008
|
-
request: { method, path:
|
|
2008
|
+
request: { method, path: path18, origin }
|
|
2009
2009
|
} = evt;
|
|
2010
|
-
debugLog("trailers received from %s %s%s", method, origin,
|
|
2010
|
+
debugLog("trailers received from %s %s%s", method, origin, path18);
|
|
2011
2011
|
}
|
|
2012
2012
|
);
|
|
2013
2013
|
diagnosticsChannel.subscribe(
|
|
2014
2014
|
"undici:request:error",
|
|
2015
2015
|
(evt) => {
|
|
2016
2016
|
const {
|
|
2017
|
-
request: { method, path:
|
|
2017
|
+
request: { method, path: path18, origin },
|
|
2018
2018
|
error
|
|
2019
2019
|
} = evt;
|
|
2020
2020
|
debugLog(
|
|
2021
2021
|
"request to %s %s%s errored - %s",
|
|
2022
2022
|
method,
|
|
2023
2023
|
origin,
|
|
2024
|
-
|
|
2024
|
+
path18,
|
|
2025
2025
|
error.message
|
|
2026
2026
|
);
|
|
2027
2027
|
}
|
|
@@ -2136,7 +2136,7 @@ var require_request = __commonJS({
|
|
|
2136
2136
|
var kHandler = /* @__PURE__ */ Symbol("handler");
|
|
2137
2137
|
var Request = class {
|
|
2138
2138
|
constructor(origin, {
|
|
2139
|
-
path:
|
|
2139
|
+
path: path18,
|
|
2140
2140
|
method,
|
|
2141
2141
|
body,
|
|
2142
2142
|
headers,
|
|
@@ -2153,11 +2153,11 @@ var require_request = __commonJS({
|
|
|
2153
2153
|
maxRedirections,
|
|
2154
2154
|
typeOfService
|
|
2155
2155
|
}, handler) {
|
|
2156
|
-
if (typeof
|
|
2156
|
+
if (typeof path18 !== "string") {
|
|
2157
2157
|
throw new InvalidArgumentError("path must be a string");
|
|
2158
|
-
} else if (
|
|
2158
|
+
} else if (path18[0] !== "/" && !(path18.startsWith("http://") || path18.startsWith("https://")) && method !== "CONNECT") {
|
|
2159
2159
|
throw new InvalidArgumentError("path must be an absolute URL or start with a slash");
|
|
2160
|
-
} else if (invalidPathRegex.test(
|
|
2160
|
+
} else if (invalidPathRegex.test(path18)) {
|
|
2161
2161
|
throw new InvalidArgumentError("invalid request path");
|
|
2162
2162
|
}
|
|
2163
2163
|
if (typeof method !== "string") {
|
|
@@ -2232,7 +2232,7 @@ var require_request = __commonJS({
|
|
|
2232
2232
|
this.completed = false;
|
|
2233
2233
|
this.aborted = false;
|
|
2234
2234
|
this.upgrade = upgrade || null;
|
|
2235
|
-
this.path = query ? serializePathWithQuery(
|
|
2235
|
+
this.path = query ? serializePathWithQuery(path18, query) : path18;
|
|
2236
2236
|
this.origin = origin;
|
|
2237
2237
|
this.protocol = getProtocolFromUrlString(origin);
|
|
2238
2238
|
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
|
|
@@ -7415,7 +7415,7 @@ var require_client_h1 = __commonJS({
|
|
|
7415
7415
|
return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
|
|
7416
7416
|
}
|
|
7417
7417
|
function writeH1(client, request) {
|
|
7418
|
-
const { method, path:
|
|
7418
|
+
const { method, path: path18, host, upgrade, blocking, reset } = request;
|
|
7419
7419
|
let { body, headers, contentLength } = request;
|
|
7420
7420
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
|
|
7421
7421
|
if (util.isFormDataLike(body)) {
|
|
@@ -7493,7 +7493,7 @@ var require_client_h1 = __commonJS({
|
|
|
7493
7493
|
if (socket.setTypeOfService) {
|
|
7494
7494
|
socket.setTypeOfService(request.typeOfService);
|
|
7495
7495
|
}
|
|
7496
|
-
let header = `${method} ${
|
|
7496
|
+
let header = `${method} ${path18} HTTP/1.1\r
|
|
7497
7497
|
`;
|
|
7498
7498
|
if (typeof host === "string") {
|
|
7499
7499
|
header += `host: ${host}\r
|
|
@@ -8146,7 +8146,7 @@ var require_client_h2 = __commonJS({
|
|
|
8146
8146
|
function writeH2(client, request) {
|
|
8147
8147
|
const requestTimeout = request.bodyTimeout ?? client[kBodyTimeout];
|
|
8148
8148
|
const session = client[kHTTP2Session];
|
|
8149
|
-
const { method, path:
|
|
8149
|
+
const { method, path: path18, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request;
|
|
8150
8150
|
let { body } = request;
|
|
8151
8151
|
if (upgrade != null && upgrade !== "websocket") {
|
|
8152
8152
|
util.errorRequest(client, request, new InvalidArgumentError(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
|
|
@@ -8214,7 +8214,7 @@ var require_client_h2 = __commonJS({
|
|
|
8214
8214
|
}
|
|
8215
8215
|
headers[HTTP2_HEADER_METHOD] = "CONNECT";
|
|
8216
8216
|
headers[HTTP2_HEADER_PROTOCOL] = "websocket";
|
|
8217
|
-
headers[HTTP2_HEADER_PATH] =
|
|
8217
|
+
headers[HTTP2_HEADER_PATH] = path18;
|
|
8218
8218
|
if (protocol === "ws:" || protocol === "wss:") {
|
|
8219
8219
|
headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
|
|
8220
8220
|
} else {
|
|
@@ -8255,7 +8255,7 @@ var require_client_h2 = __commonJS({
|
|
|
8255
8255
|
stream2.setTimeout(requestTimeout);
|
|
8256
8256
|
return true;
|
|
8257
8257
|
}
|
|
8258
|
-
headers[HTTP2_HEADER_PATH] =
|
|
8258
|
+
headers[HTTP2_HEADER_PATH] = path18;
|
|
8259
8259
|
headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
|
|
8260
8260
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
8261
8261
|
if (body && typeof body.read === "function") {
|
|
@@ -10598,10 +10598,10 @@ var require_proxy_agent = __commonJS({
|
|
|
10598
10598
|
};
|
|
10599
10599
|
const {
|
|
10600
10600
|
origin,
|
|
10601
|
-
path:
|
|
10601
|
+
path: path18 = "/",
|
|
10602
10602
|
headers = {}
|
|
10603
10603
|
} = opts;
|
|
10604
|
-
opts.path = origin +
|
|
10604
|
+
opts.path = origin + path18;
|
|
10605
10605
|
if (!("host" in headers) && !("Host" in headers)) {
|
|
10606
10606
|
const { host } = new URL(origin);
|
|
10607
10607
|
headers.host = host;
|
|
@@ -12684,20 +12684,20 @@ var require_mock_utils = __commonJS({
|
|
|
12684
12684
|
}
|
|
12685
12685
|
return normalizedQp;
|
|
12686
12686
|
}
|
|
12687
|
-
function safeUrl(
|
|
12688
|
-
if (typeof
|
|
12689
|
-
return
|
|
12687
|
+
function safeUrl(path18) {
|
|
12688
|
+
if (typeof path18 !== "string") {
|
|
12689
|
+
return path18;
|
|
12690
12690
|
}
|
|
12691
|
-
const pathSegments =
|
|
12691
|
+
const pathSegments = path18.split("?", 3);
|
|
12692
12692
|
if (pathSegments.length !== 2) {
|
|
12693
|
-
return
|
|
12693
|
+
return path18;
|
|
12694
12694
|
}
|
|
12695
12695
|
const qp = new URLSearchParams(pathSegments.pop());
|
|
12696
12696
|
qp.sort();
|
|
12697
12697
|
return [...pathSegments, qp.toString()].join("?");
|
|
12698
12698
|
}
|
|
12699
|
-
function matchKey(mockDispatch2, { path:
|
|
12700
|
-
const pathMatch = matchValue(mockDispatch2.path,
|
|
12699
|
+
function matchKey(mockDispatch2, { path: path18, method, body, headers }) {
|
|
12700
|
+
const pathMatch = matchValue(mockDispatch2.path, path18);
|
|
12701
12701
|
const methodMatch = matchValue(mockDispatch2.method, method);
|
|
12702
12702
|
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
|
|
12703
12703
|
const headersMatch = matchHeaders(mockDispatch2, headers);
|
|
@@ -12722,8 +12722,8 @@ var require_mock_utils = __commonJS({
|
|
|
12722
12722
|
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
|
|
12723
12723
|
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
|
|
12724
12724
|
const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
|
|
12725
|
-
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path:
|
|
12726
|
-
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(
|
|
12725
|
+
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path18, ignoreTrailingSlash }) => {
|
|
12726
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path18)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path18), resolvedPath);
|
|
12727
12727
|
});
|
|
12728
12728
|
if (matchedMockDispatches.length === 0) {
|
|
12729
12729
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
@@ -12762,19 +12762,19 @@ var require_mock_utils = __commonJS({
|
|
|
12762
12762
|
mockDispatches.splice(index, 1);
|
|
12763
12763
|
}
|
|
12764
12764
|
}
|
|
12765
|
-
function removeTrailingSlash(
|
|
12766
|
-
while (
|
|
12767
|
-
|
|
12765
|
+
function removeTrailingSlash(path18) {
|
|
12766
|
+
while (path18.endsWith("/")) {
|
|
12767
|
+
path18 = path18.slice(0, -1);
|
|
12768
12768
|
}
|
|
12769
|
-
if (
|
|
12770
|
-
|
|
12769
|
+
if (path18.length === 0) {
|
|
12770
|
+
path18 = "/";
|
|
12771
12771
|
}
|
|
12772
|
-
return
|
|
12772
|
+
return path18;
|
|
12773
12773
|
}
|
|
12774
12774
|
function buildKey(opts) {
|
|
12775
|
-
const { path:
|
|
12775
|
+
const { path: path18, method, body, headers, query } = opts;
|
|
12776
12776
|
return {
|
|
12777
|
-
path:
|
|
12777
|
+
path: path18,
|
|
12778
12778
|
method,
|
|
12779
12779
|
body,
|
|
12780
12780
|
headers,
|
|
@@ -12825,22 +12825,22 @@ var require_mock_utils = __commonJS({
|
|
|
12825
12825
|
return true;
|
|
12826
12826
|
}
|
|
12827
12827
|
let aborted = false;
|
|
12828
|
-
let
|
|
12828
|
+
let timer3 = null;
|
|
12829
12829
|
function abort(err2) {
|
|
12830
12830
|
if (aborted) {
|
|
12831
12831
|
return;
|
|
12832
12832
|
}
|
|
12833
12833
|
aborted = true;
|
|
12834
|
-
if (
|
|
12835
|
-
clearTimeout(
|
|
12836
|
-
|
|
12834
|
+
if (timer3 !== null) {
|
|
12835
|
+
clearTimeout(timer3);
|
|
12836
|
+
timer3 = null;
|
|
12837
12837
|
}
|
|
12838
12838
|
handler.onError(err2);
|
|
12839
12839
|
}
|
|
12840
12840
|
handler.onConnect?.(abort, null);
|
|
12841
12841
|
if (typeof delay === "number" && delay > 0) {
|
|
12842
|
-
|
|
12843
|
-
|
|
12842
|
+
timer3 = setTimeout(() => {
|
|
12843
|
+
timer3 = null;
|
|
12844
12844
|
handleReply(this[kDispatches]);
|
|
12845
12845
|
}, delay);
|
|
12846
12846
|
} else {
|
|
@@ -13464,10 +13464,10 @@ var require_pending_interceptors_formatter = __commonJS({
|
|
|
13464
13464
|
}
|
|
13465
13465
|
format(pendingInterceptors) {
|
|
13466
13466
|
const withPrettyHeaders = pendingInterceptors.map(
|
|
13467
|
-
({ method, path:
|
|
13467
|
+
({ method, path: path18, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
13468
13468
|
Method: method,
|
|
13469
13469
|
Origin: origin,
|
|
13470
|
-
Path:
|
|
13470
|
+
Path: path18,
|
|
13471
13471
|
"Status code": statusCode,
|
|
13472
13472
|
Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
|
|
13473
13473
|
Invocations: timesInvoked,
|
|
@@ -13549,9 +13549,9 @@ var require_mock_agent = __commonJS({
|
|
|
13549
13549
|
const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
|
|
13550
13550
|
const dispatchOpts = { ...opts };
|
|
13551
13551
|
if (acceptNonStandardSearchParameters && dispatchOpts.path) {
|
|
13552
|
-
const [
|
|
13552
|
+
const [path18, searchParams] = dispatchOpts.path.split("?");
|
|
13553
13553
|
const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
|
|
13554
|
-
dispatchOpts.path = `${
|
|
13554
|
+
dispatchOpts.path = `${path18}?${normalizedSearchParams}`;
|
|
13555
13555
|
}
|
|
13556
13556
|
return this[kAgent].dispatch(dispatchOpts, handler);
|
|
13557
13557
|
}
|
|
@@ -13952,12 +13952,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
13952
13952
|
* @return {Promise<void>} - Resolves when snapshots are loaded
|
|
13953
13953
|
*/
|
|
13954
13954
|
async loadSnapshots(filePath) {
|
|
13955
|
-
const
|
|
13956
|
-
if (!
|
|
13955
|
+
const path18 = filePath || this.#snapshotPath;
|
|
13956
|
+
if (!path18) {
|
|
13957
13957
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
13958
13958
|
}
|
|
13959
13959
|
try {
|
|
13960
|
-
const data = await readFile3(resolve(
|
|
13960
|
+
const data = await readFile3(resolve(path18), "utf8");
|
|
13961
13961
|
const parsed = JSON.parse(data);
|
|
13962
13962
|
if (Array.isArray(parsed)) {
|
|
13963
13963
|
this.#snapshots.clear();
|
|
@@ -13971,7 +13971,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
13971
13971
|
if (error.code === "ENOENT") {
|
|
13972
13972
|
this.#snapshots.clear();
|
|
13973
13973
|
} else {
|
|
13974
|
-
throw new UndiciError(`Failed to load snapshots from ${
|
|
13974
|
+
throw new UndiciError(`Failed to load snapshots from ${path18}`, { cause: error });
|
|
13975
13975
|
}
|
|
13976
13976
|
}
|
|
13977
13977
|
}
|
|
@@ -13982,11 +13982,11 @@ var require_snapshot_recorder = __commonJS({
|
|
|
13982
13982
|
* @returns {Promise<void>} - Resolves when snapshots are saved
|
|
13983
13983
|
*/
|
|
13984
13984
|
async saveSnapshots(filePath) {
|
|
13985
|
-
const
|
|
13986
|
-
if (!
|
|
13985
|
+
const path18 = filePath || this.#snapshotPath;
|
|
13986
|
+
if (!path18) {
|
|
13987
13987
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
13988
13988
|
}
|
|
13989
|
-
const resolvedPath = resolve(
|
|
13989
|
+
const resolvedPath = resolve(path18);
|
|
13990
13990
|
await mkdir3(dirname5(resolvedPath), { recursive: true });
|
|
13991
13991
|
const data = Array.from(this.#snapshots.entries()).map(([hash, snapshot]) => ({
|
|
13992
13992
|
hash,
|
|
@@ -14618,15 +14618,15 @@ var require_redirect_handler = __commonJS({
|
|
|
14618
14618
|
return;
|
|
14619
14619
|
}
|
|
14620
14620
|
const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
|
|
14621
|
-
const
|
|
14622
|
-
const redirectUrlString = `${origin}${
|
|
14621
|
+
const path18 = search ? `${pathname}${search}` : pathname;
|
|
14622
|
+
const redirectUrlString = `${origin}${path18}`;
|
|
14623
14623
|
for (const historyUrl of this.history) {
|
|
14624
14624
|
if (historyUrl.toString() === redirectUrlString) {
|
|
14625
14625
|
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.`);
|
|
14626
14626
|
}
|
|
14627
14627
|
}
|
|
14628
14628
|
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
|
|
14629
|
-
this.opts.path =
|
|
14629
|
+
this.opts.path = path18;
|
|
14630
14630
|
this.opts.origin = origin;
|
|
14631
14631
|
this.opts.query = null;
|
|
14632
14632
|
}
|
|
@@ -16395,10 +16395,10 @@ var require_cache_handler = __commonJS({
|
|
|
16395
16395
|
}
|
|
16396
16396
|
return locationUrl.pathname + locationUrl.search;
|
|
16397
16397
|
}
|
|
16398
|
-
function deleteCachedUri(store, cacheKey,
|
|
16398
|
+
function deleteCachedUri(store, cacheKey, path18) {
|
|
16399
16399
|
deleteCachedValue(store, {
|
|
16400
16400
|
...cacheKey,
|
|
16401
|
-
path:
|
|
16401
|
+
path: path18
|
|
16402
16402
|
});
|
|
16403
16403
|
for (let i = 0; i < util.safeHTTPMethods.length; i++) {
|
|
16404
16404
|
const method = util.safeHTTPMethods[i];
|
|
@@ -16406,7 +16406,7 @@ var require_cache_handler = __commonJS({
|
|
|
16406
16406
|
deleteCachedValue(store, {
|
|
16407
16407
|
...cacheKey,
|
|
16408
16408
|
method,
|
|
16409
|
-
path:
|
|
16409
|
+
path: path18
|
|
16410
16410
|
});
|
|
16411
16411
|
}
|
|
16412
16412
|
}
|
|
@@ -16417,9 +16417,9 @@ var require_cache_handler = __commonJS({
|
|
|
16417
16417
|
}
|
|
16418
16418
|
const values = Array.isArray(headerValue3) ? headerValue3 : [headerValue3];
|
|
16419
16419
|
for (let i = 0; i < values.length; i++) {
|
|
16420
|
-
const
|
|
16421
|
-
if (
|
|
16422
|
-
deleteCachedUri(store, cacheKey,
|
|
16420
|
+
const path18 = getSameOriginPath(cacheKey, values[i]);
|
|
16421
|
+
if (path18 !== void 0) {
|
|
16422
|
+
deleteCachedUri(store, cacheKey, path18);
|
|
16423
16423
|
}
|
|
16424
16424
|
}
|
|
16425
16425
|
}
|
|
@@ -21297,11 +21297,11 @@ var require_fetch = __commonJS({
|
|
|
21297
21297
|
function dispatch({ body }) {
|
|
21298
21298
|
const url = requestCurrentURL(request);
|
|
21299
21299
|
const agent = fetchParams.controller.dispatcher;
|
|
21300
|
-
const
|
|
21300
|
+
const path18 = url.pathname + url.search;
|
|
21301
21301
|
const hasTrailingQuestionMark = url.search.length === 0 && url.href[url.href.length - url.hash.length - 1] === "?";
|
|
21302
21302
|
return new Promise((resolve, reject) => agent.dispatch(
|
|
21303
21303
|
{
|
|
21304
|
-
path: hasTrailingQuestionMark ? `${
|
|
21304
|
+
path: hasTrailingQuestionMark ? `${path18}?` : path18,
|
|
21305
21305
|
origin: url.origin,
|
|
21306
21306
|
method: request.method,
|
|
21307
21307
|
body: agent.isMockActive ? request.body && (request.body.source || request.body.stream) : body,
|
|
@@ -22248,9 +22248,9 @@ var require_util4 = __commonJS({
|
|
|
22248
22248
|
}
|
|
22249
22249
|
}
|
|
22250
22250
|
}
|
|
22251
|
-
function validateCookiePath(
|
|
22252
|
-
for (let i = 0; i <
|
|
22253
|
-
const code =
|
|
22251
|
+
function validateCookiePath(path18) {
|
|
22252
|
+
for (let i = 0; i < path18.length; ++i) {
|
|
22253
|
+
const code = path18.charCodeAt(i);
|
|
22254
22254
|
if (code < 32 || // exclude CTLs (0-31)
|
|
22255
22255
|
code > 126 || // exclude DEL and non-ascii
|
|
22256
22256
|
code === 59) {
|
|
@@ -22944,7 +22944,7 @@ var require_constants5 = __commonJS({
|
|
|
22944
22944
|
writable: false,
|
|
22945
22945
|
configurable: false
|
|
22946
22946
|
};
|
|
22947
|
-
var
|
|
22947
|
+
var states2 = {
|
|
22948
22948
|
CONNECTING: 0,
|
|
22949
22949
|
OPEN: 1,
|
|
22950
22950
|
CLOSING: 2,
|
|
@@ -22980,7 +22980,7 @@ var require_constants5 = __commonJS({
|
|
|
22980
22980
|
uid,
|
|
22981
22981
|
sentCloseFrameState,
|
|
22982
22982
|
staticPropertyDescriptors,
|
|
22983
|
-
states,
|
|
22983
|
+
states: states2,
|
|
22984
22984
|
opcodes,
|
|
22985
22985
|
maxUnsigned16Bit,
|
|
22986
22986
|
parserStates,
|
|
@@ -22994,21 +22994,21 @@ var require_constants5 = __commonJS({
|
|
|
22994
22994
|
var require_util5 = __commonJS({
|
|
22995
22995
|
"node_modules/undici/lib/web/websocket/util.js"(exports, module) {
|
|
22996
22996
|
"use strict";
|
|
22997
|
-
var { states, opcodes } = require_constants5();
|
|
22997
|
+
var { states: states2, opcodes } = require_constants5();
|
|
22998
22998
|
var { isUtf8 } = __require("buffer");
|
|
22999
22999
|
var { removeHTTPWhitespace } = require_data_url();
|
|
23000
23000
|
var { collectASequenceOfCodePointsFast } = require_infra();
|
|
23001
23001
|
function isConnecting(readyState) {
|
|
23002
|
-
return readyState ===
|
|
23002
|
+
return readyState === states2.CONNECTING;
|
|
23003
23003
|
}
|
|
23004
23004
|
function isEstablished(readyState) {
|
|
23005
|
-
return readyState ===
|
|
23005
|
+
return readyState === states2.OPEN;
|
|
23006
23006
|
}
|
|
23007
23007
|
function isClosing(readyState) {
|
|
23008
|
-
return readyState ===
|
|
23008
|
+
return readyState === states2.CLOSING;
|
|
23009
23009
|
}
|
|
23010
23010
|
function isClosed(readyState) {
|
|
23011
|
-
return readyState ===
|
|
23011
|
+
return readyState === states2.CLOSED;
|
|
23012
23012
|
}
|
|
23013
23013
|
function fireEvent(e, target, eventFactory = (type, init) => new Event(type, init), eventInitDict = {}) {
|
|
23014
23014
|
const event = eventFactory(e, eventInitDict);
|
|
@@ -23276,7 +23276,7 @@ var require_frame = __commonJS({
|
|
|
23276
23276
|
var require_connection = __commonJS({
|
|
23277
23277
|
"node_modules/undici/lib/web/websocket/connection.js"(exports, module) {
|
|
23278
23278
|
"use strict";
|
|
23279
|
-
var { uid, states, sentCloseFrameState, emptyBuffer, opcodes } = require_constants5();
|
|
23279
|
+
var { uid, states: states2, sentCloseFrameState, emptyBuffer, opcodes } = require_constants5();
|
|
23280
23280
|
var { parseExtensions, isClosed, isClosing, isEstablished, isConnecting, validateCloseCodeAndReason } = require_util5();
|
|
23281
23281
|
var { makeRequest } = require_request2();
|
|
23282
23282
|
var { fetching } = require_fetch();
|
|
@@ -23383,7 +23383,7 @@ var require_connection = __commonJS({
|
|
|
23383
23383
|
if (isClosed(object.readyState) || isClosing(object.readyState)) {
|
|
23384
23384
|
} else if (!isEstablished(object.readyState)) {
|
|
23385
23385
|
failWebsocketConnection(object);
|
|
23386
|
-
object.readyState =
|
|
23386
|
+
object.readyState = states2.CLOSING;
|
|
23387
23387
|
} else if (!object.closeState.has(sentCloseFrameState.SENT) && !object.closeState.has(sentCloseFrameState.RECEIVED)) {
|
|
23388
23388
|
const frame = new WebsocketFrameSend();
|
|
23389
23389
|
if (reason.length !== 0 && code === null) {
|
|
@@ -23404,9 +23404,9 @@ var require_connection = __commonJS({
|
|
|
23404
23404
|
}
|
|
23405
23405
|
object.socket.write(frame.createFrame(opcodes.CLOSE));
|
|
23406
23406
|
object.closeState.add(sentCloseFrameState.SENT);
|
|
23407
|
-
object.readyState =
|
|
23407
|
+
object.readyState = states2.CLOSING;
|
|
23408
23408
|
} else {
|
|
23409
|
-
object.readyState =
|
|
23409
|
+
object.readyState = states2.CLOSING;
|
|
23410
23410
|
}
|
|
23411
23411
|
}
|
|
23412
23412
|
function failWebsocketConnection(handler, code, reason, cause) {
|
|
@@ -23515,7 +23515,7 @@ var require_receiver = __commonJS({
|
|
|
23515
23515
|
"use strict";
|
|
23516
23516
|
var { Writable } = __require("stream");
|
|
23517
23517
|
var assert = __require("assert");
|
|
23518
|
-
var { parserStates, opcodes, states, emptyBuffer, sentCloseFrameState } = require_constants5();
|
|
23518
|
+
var { parserStates, opcodes, states: states2, emptyBuffer, sentCloseFrameState } = require_constants5();
|
|
23519
23519
|
var {
|
|
23520
23520
|
isValidStatusCode,
|
|
23521
23521
|
isValidOpcode,
|
|
@@ -23844,7 +23844,7 @@ var require_receiver = __commonJS({
|
|
|
23844
23844
|
this.#handler.socket.write(closeFrame.createFrame(opcodes.CLOSE));
|
|
23845
23845
|
this.#handler.closeState.add(sentCloseFrameState.SENT);
|
|
23846
23846
|
}
|
|
23847
|
-
this.#handler.readyState =
|
|
23847
|
+
this.#handler.readyState = states2.CLOSING;
|
|
23848
23848
|
this.#handler.closeState.add(sentCloseFrameState.RECEIVED);
|
|
23849
23849
|
return false;
|
|
23850
23850
|
} else if (opcode === opcodes.PING) {
|
|
@@ -23963,7 +23963,7 @@ var require_websocket = __commonJS({
|
|
|
23963
23963
|
var { webidl } = require_webidl();
|
|
23964
23964
|
var { URLSerializer } = require_data_url();
|
|
23965
23965
|
var { environmentSettingsObject } = require_util2();
|
|
23966
|
-
var { staticPropertyDescriptors, states, sentCloseFrameState, sendHints, opcodes } = require_constants5();
|
|
23966
|
+
var { staticPropertyDescriptors, states: states2, sentCloseFrameState, sendHints, opcodes } = require_constants5();
|
|
23967
23967
|
var {
|
|
23968
23968
|
isConnecting,
|
|
23969
23969
|
isEstablished,
|
|
@@ -24016,7 +24016,7 @@ var require_websocket = __commonJS({
|
|
|
24016
24016
|
}
|
|
24017
24017
|
},
|
|
24018
24018
|
onSocketError: (err2) => {
|
|
24019
|
-
this.#handler.readyState =
|
|
24019
|
+
this.#handler.readyState = states2.CLOSING;
|
|
24020
24020
|
if (channels.socketError.hasSubscribers) {
|
|
24021
24021
|
channels.socketError.publish(err2);
|
|
24022
24022
|
}
|
|
@@ -24039,7 +24039,7 @@ var require_websocket = __commonJS({
|
|
|
24039
24039
|
});
|
|
24040
24040
|
}
|
|
24041
24041
|
},
|
|
24042
|
-
readyState:
|
|
24042
|
+
readyState: states2.CONNECTING,
|
|
24043
24043
|
socket: null,
|
|
24044
24044
|
closeState: /* @__PURE__ */ new Set(),
|
|
24045
24045
|
controller: null,
|
|
@@ -24256,7 +24256,7 @@ var require_websocket = __commonJS({
|
|
|
24256
24256
|
parser.on("error", (err2) => this.#handler.onParserError(err2));
|
|
24257
24257
|
this.#parser = parser;
|
|
24258
24258
|
this.#sendQueue = new SendQueue(response.socket);
|
|
24259
|
-
this.#handler.readyState =
|
|
24259
|
+
this.#handler.readyState = states2.OPEN;
|
|
24260
24260
|
const extensions = response.headersList.get("sec-websocket-extensions");
|
|
24261
24261
|
if (extensions !== null) {
|
|
24262
24262
|
this.#extensions = extensions;
|
|
@@ -24282,7 +24282,7 @@ var require_websocket = __commonJS({
|
|
|
24282
24282
|
}
|
|
24283
24283
|
}
|
|
24284
24284
|
#onMessage(type, data) {
|
|
24285
|
-
if (this.#handler.readyState !==
|
|
24285
|
+
if (this.#handler.readyState !== states2.OPEN) {
|
|
24286
24286
|
return;
|
|
24287
24287
|
}
|
|
24288
24288
|
let dataForEvent;
|
|
@@ -24321,7 +24321,7 @@ var require_websocket = __commonJS({
|
|
|
24321
24321
|
code = result.code ?? 1005;
|
|
24322
24322
|
reason = result.reason;
|
|
24323
24323
|
}
|
|
24324
|
-
this.#handler.readyState =
|
|
24324
|
+
this.#handler.readyState = states2.CLOSED;
|
|
24325
24325
|
if (!this.#handler.closeState.has(sentCloseFrameState.RECEIVED)) {
|
|
24326
24326
|
code = 1006;
|
|
24327
24327
|
fireEvent("error", this, (type, init) => new ErrorEvent(type, init), {
|
|
@@ -24362,10 +24362,10 @@ var require_websocket = __commonJS({
|
|
|
24362
24362
|
};
|
|
24363
24363
|
var { ping } = WebSocket;
|
|
24364
24364
|
Reflect.deleteProperty(WebSocket, "ping");
|
|
24365
|
-
WebSocket.CONNECTING = WebSocket.prototype.CONNECTING =
|
|
24366
|
-
WebSocket.OPEN = WebSocket.prototype.OPEN =
|
|
24367
|
-
WebSocket.CLOSING = WebSocket.prototype.CLOSING =
|
|
24368
|
-
WebSocket.CLOSED = WebSocket.prototype.CLOSED =
|
|
24365
|
+
WebSocket.CONNECTING = WebSocket.prototype.CONNECTING = states2.CONNECTING;
|
|
24366
|
+
WebSocket.OPEN = WebSocket.prototype.OPEN = states2.OPEN;
|
|
24367
|
+
WebSocket.CLOSING = WebSocket.prototype.CLOSING = states2.CLOSING;
|
|
24368
|
+
WebSocket.CLOSED = WebSocket.prototype.CLOSED = states2.CLOSED;
|
|
24369
24369
|
Object.defineProperties(WebSocket.prototype, {
|
|
24370
24370
|
CONNECTING: staticPropertyDescriptors,
|
|
24371
24371
|
OPEN: staticPropertyDescriptors,
|
|
@@ -24531,7 +24531,7 @@ var require_websocketstream = __commonJS({
|
|
|
24531
24531
|
"use strict";
|
|
24532
24532
|
var { createDeferredPromise } = require_promise();
|
|
24533
24533
|
var { environmentSettingsObject } = require_util2();
|
|
24534
|
-
var { states, opcodes, sentCloseFrameState } = require_constants5();
|
|
24534
|
+
var { states: states2, opcodes, sentCloseFrameState } = require_constants5();
|
|
24535
24535
|
var { webidl } = require_webidl();
|
|
24536
24536
|
var { getURLRecord, isValidSubprotocol, isEstablished, utf8Decode } = require_util5();
|
|
24537
24537
|
var { establishWebSocketConnection, failWebsocketConnection, closeWebSocketConnection } = require_connection();
|
|
@@ -24575,7 +24575,7 @@ var require_websocketstream = __commonJS({
|
|
|
24575
24575
|
}
|
|
24576
24576
|
},
|
|
24577
24577
|
onSocketError: (err2) => {
|
|
24578
|
-
this.#handler.readyState =
|
|
24578
|
+
this.#handler.readyState = states2.CLOSING;
|
|
24579
24579
|
if (channels.socketError.hasSubscribers) {
|
|
24580
24580
|
channels.socketError.publish(err2);
|
|
24581
24581
|
}
|
|
@@ -24586,7 +24586,7 @@ var require_websocketstream = __commonJS({
|
|
|
24586
24586
|
},
|
|
24587
24587
|
onPong: () => {
|
|
24588
24588
|
},
|
|
24589
|
-
readyState:
|
|
24589
|
+
readyState: states2.CONNECTING,
|
|
24590
24590
|
socket: null,
|
|
24591
24591
|
closeState: /* @__PURE__ */ new Set(),
|
|
24592
24592
|
controller: null,
|
|
@@ -24628,7 +24628,7 @@ var require_websocketstream = __commonJS({
|
|
|
24628
24628
|
signal.addEventListener("abort", () => {
|
|
24629
24629
|
if (!isEstablished(this.#handler.readyState)) {
|
|
24630
24630
|
failWebsocketConnection(this.#handler);
|
|
24631
|
-
this.#handler.readyState =
|
|
24631
|
+
this.#handler.readyState = states2.CLOSING;
|
|
24632
24632
|
this.#openedPromise.reject(signal.reason);
|
|
24633
24633
|
this.#closedPromise.reject(signal.reason);
|
|
24634
24634
|
this.#handshakeAborted = true;
|
|
@@ -24704,7 +24704,7 @@ var require_websocketstream = __commonJS({
|
|
|
24704
24704
|
parser.on("drain", () => this.#handler.onParserDrain());
|
|
24705
24705
|
parser.on("error", (err2) => this.#handler.onParserError(err2));
|
|
24706
24706
|
this.#parser = parser;
|
|
24707
|
-
this.#handler.readyState =
|
|
24707
|
+
this.#handler.readyState = states2.OPEN;
|
|
24708
24708
|
const extensions = parsedExtensions ?? "";
|
|
24709
24709
|
const protocol = response.headersList.get("sec-websocket-protocol") ?? "";
|
|
24710
24710
|
const readable = new ReadableStream({
|
|
@@ -24729,7 +24729,7 @@ var require_websocketstream = __commonJS({
|
|
|
24729
24729
|
}
|
|
24730
24730
|
/** @type {import('../websocket').Handler['onMessage']} */
|
|
24731
24731
|
#onMessage(type, data) {
|
|
24732
|
-
if (this.#handler.readyState !==
|
|
24732
|
+
if (this.#handler.readyState !== states2.OPEN) {
|
|
24733
24733
|
return;
|
|
24734
24734
|
}
|
|
24735
24735
|
let chunk;
|
|
@@ -24748,7 +24748,7 @@ var require_websocketstream = __commonJS({
|
|
|
24748
24748
|
/** @type {import('../websocket').Handler['onSocketClose']} */
|
|
24749
24749
|
#onSocketClose() {
|
|
24750
24750
|
const wasClean = this.#handler.closeState.has(sentCloseFrameState.SENT) && this.#handler.closeState.has(sentCloseFrameState.RECEIVED);
|
|
24751
|
-
this.#handler.readyState =
|
|
24751
|
+
this.#handler.readyState = states2.CLOSED;
|
|
24752
24752
|
if (this.#handshakeAborted) {
|
|
24753
24753
|
return;
|
|
24754
24754
|
}
|
|
@@ -25487,11 +25487,11 @@ var require_undici = __commonJS({
|
|
|
25487
25487
|
if (typeof opts.path !== "string") {
|
|
25488
25488
|
throw new InvalidArgumentError("invalid opts.path");
|
|
25489
25489
|
}
|
|
25490
|
-
let
|
|
25490
|
+
let path18 = opts.path;
|
|
25491
25491
|
if (!opts.path.startsWith("/")) {
|
|
25492
|
-
|
|
25492
|
+
path18 = `/${path18}`;
|
|
25493
25493
|
}
|
|
25494
|
-
url = new URL(util.parseOrigin(url).origin +
|
|
25494
|
+
url = new URL(util.parseOrigin(url).origin + path18);
|
|
25495
25495
|
} else {
|
|
25496
25496
|
if (!opts) {
|
|
25497
25497
|
opts = typeof url === "object" ? url : {};
|
|
@@ -47526,16 +47526,16 @@ function connectDirect(host, port, timeoutMs = CONNECT_TIMEOUT_MS) {
|
|
|
47526
47526
|
const finishError = (error) => {
|
|
47527
47527
|
if (settled) return;
|
|
47528
47528
|
settled = true;
|
|
47529
|
-
clearTimeout(
|
|
47529
|
+
clearTimeout(timer3);
|
|
47530
47530
|
socket.destroy();
|
|
47531
47531
|
reject(error);
|
|
47532
47532
|
};
|
|
47533
|
-
const
|
|
47533
|
+
const timer3 = setTimeout(() => finishError(new Error(`upstream connect ${host}:${port} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
47534
47534
|
socket.once("error", finishError);
|
|
47535
47535
|
socket.once("connect", () => {
|
|
47536
47536
|
if (settled) return;
|
|
47537
47537
|
settled = true;
|
|
47538
|
-
clearTimeout(
|
|
47538
|
+
clearTimeout(timer3);
|
|
47539
47539
|
resolve(socket);
|
|
47540
47540
|
});
|
|
47541
47541
|
});
|
|
@@ -47552,11 +47552,11 @@ function connectThroughProxy(host, port, proxyUrl) {
|
|
|
47552
47552
|
const finishError = (error) => {
|
|
47553
47553
|
if (settled) return;
|
|
47554
47554
|
settled = true;
|
|
47555
|
-
clearTimeout(
|
|
47555
|
+
clearTimeout(timer3);
|
|
47556
47556
|
socket.destroy();
|
|
47557
47557
|
reject(error);
|
|
47558
47558
|
};
|
|
47559
|
-
const
|
|
47559
|
+
const timer3 = setTimeout(() => finishError(new Error(`upstream proxy CONNECT ${host}:${port} handshake timeout`)), CONNECT_TIMEOUT_MS);
|
|
47560
47560
|
socket.once("error", finishError);
|
|
47561
47561
|
const connectedEvent = proxy.protocol === "https:" ? "secureConnect" : "connect";
|
|
47562
47562
|
socket.once(connectedEvent, () => {
|
|
@@ -47585,7 +47585,7 @@ function connectThroughProxy(host, port, proxyUrl) {
|
|
|
47585
47585
|
return;
|
|
47586
47586
|
}
|
|
47587
47587
|
settled = true;
|
|
47588
|
-
clearTimeout(
|
|
47588
|
+
clearTimeout(timer3);
|
|
47589
47589
|
socket.removeListener("error", finishError);
|
|
47590
47590
|
const rest = buffer.subarray(end + 4);
|
|
47591
47591
|
if (rest.length > 0) socket.unshift(rest);
|
|
@@ -47651,13 +47651,13 @@ function getUpstreamConnectionStatus() {
|
|
|
47651
47651
|
}
|
|
47652
47652
|
|
|
47653
47653
|
// src/config.ts
|
|
47654
|
-
function safeReadJson(
|
|
47654
|
+
function safeReadJson(path18) {
|
|
47655
47655
|
try {
|
|
47656
|
-
const raw = readFileSync(
|
|
47656
|
+
const raw = readFileSync(path18, "utf8").replace(/^\uFEFF/, "");
|
|
47657
47657
|
return JSON.parse(raw);
|
|
47658
47658
|
} catch (e) {
|
|
47659
47659
|
if (e.code !== "ENOENT") {
|
|
47660
|
-
log("error", `[acp-config] failed to parse ${
|
|
47660
|
+
log("error", `[acp-config] failed to parse ${path18}: ${String(e)}`);
|
|
47661
47661
|
}
|
|
47662
47662
|
return void 0;
|
|
47663
47663
|
}
|
|
@@ -47937,7 +47937,7 @@ function rejectLegacyRoute(key, value) {
|
|
|
47937
47937
|
|
|
47938
47938
|
// src/server.ts
|
|
47939
47939
|
import http from "http";
|
|
47940
|
-
import
|
|
47940
|
+
import fs8 from "fs";
|
|
47941
47941
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
47942
47942
|
|
|
47943
47943
|
// src/compress-settings.ts
|
|
@@ -48052,11 +48052,11 @@ async function fetchWithTimeout(url, opts, timeoutMs = UPSTREAM_TIMEOUT_MS, exte
|
|
|
48052
48052
|
liveUpstreamTimers.add(t);
|
|
48053
48053
|
return t;
|
|
48054
48054
|
};
|
|
48055
|
-
let
|
|
48055
|
+
let timer3 = armTimer();
|
|
48056
48056
|
const rearm = () => {
|
|
48057
|
-
clearTimeout(
|
|
48058
|
-
liveUpstreamTimers.delete(
|
|
48059
|
-
|
|
48057
|
+
clearTimeout(timer3);
|
|
48058
|
+
liveUpstreamTimers.delete(timer3);
|
|
48059
|
+
timer3 = armTimer();
|
|
48060
48060
|
};
|
|
48061
48061
|
let onExternalAbort = null;
|
|
48062
48062
|
if (externalSignal) {
|
|
@@ -48067,8 +48067,8 @@ async function fetchWithTimeout(url, opts, timeoutMs = UPSTREAM_TIMEOUT_MS, exte
|
|
|
48067
48067
|
}
|
|
48068
48068
|
}
|
|
48069
48069
|
const cleanup = () => {
|
|
48070
|
-
clearTimeout(
|
|
48071
|
-
liveUpstreamTimers.delete(
|
|
48070
|
+
clearTimeout(timer3);
|
|
48071
|
+
liveUpstreamTimers.delete(timer3);
|
|
48072
48072
|
if (onExternalAbort && externalSignal) externalSignal.removeEventListener("abort", onExternalAbort);
|
|
48073
48073
|
};
|
|
48074
48074
|
try {
|
|
@@ -48161,13 +48161,13 @@ function replayBackoffMs(attempt) {
|
|
|
48161
48161
|
function sleep(ms2, signal) {
|
|
48162
48162
|
if (ms2 <= 0 || signal?.aborted) return Promise.resolve();
|
|
48163
48163
|
return new Promise((resolve) => {
|
|
48164
|
-
let
|
|
48164
|
+
let timer3 = null;
|
|
48165
48165
|
const finish2 = () => {
|
|
48166
|
-
if (
|
|
48166
|
+
if (timer3) clearTimeout(timer3);
|
|
48167
48167
|
if (signal) signal.removeEventListener("abort", finish2);
|
|
48168
48168
|
resolve();
|
|
48169
48169
|
};
|
|
48170
|
-
|
|
48170
|
+
timer3 = setTimeout(finish2, ms2);
|
|
48171
48171
|
if (signal) signal.addEventListener("abort", finish2, { once: true });
|
|
48172
48172
|
});
|
|
48173
48173
|
}
|
|
@@ -49389,7 +49389,7 @@ var StateStore = class {
|
|
|
49389
49389
|
this.pending.set(id, build2);
|
|
49390
49390
|
const existing = this.timers.get(id);
|
|
49391
49391
|
if (existing) return;
|
|
49392
|
-
const
|
|
49392
|
+
const timer3 = setTimeout(() => {
|
|
49393
49393
|
this.timers.delete(id);
|
|
49394
49394
|
const builder = this.pending.get(id);
|
|
49395
49395
|
this.pending.delete(id);
|
|
@@ -49397,8 +49397,8 @@ var StateStore = class {
|
|
|
49397
49397
|
void this.writeNow(id, builder).catch(() => {
|
|
49398
49398
|
});
|
|
49399
49399
|
}, this.debounceMs);
|
|
49400
|
-
|
|
49401
|
-
this.timers.set(id,
|
|
49400
|
+
timer3.unref?.();
|
|
49401
|
+
this.timers.set(id, timer3);
|
|
49402
49402
|
}
|
|
49403
49403
|
/** Immediate save, serialized per id. Rejects on write failure; a
|
|
49404
49404
|
* failing write never breaks the chain for the next one. */
|
|
@@ -49420,9 +49420,9 @@ var StateStore = class {
|
|
|
49420
49420
|
* the result to drop in-memory state must NOT drop it on failure. */
|
|
49421
49421
|
flushSync(id, build2) {
|
|
49422
49422
|
if (!this.enabled) return true;
|
|
49423
|
-
const
|
|
49424
|
-
if (
|
|
49425
|
-
clearTimeout(
|
|
49423
|
+
const timer3 = this.timers.get(id);
|
|
49424
|
+
if (timer3) {
|
|
49425
|
+
clearTimeout(timer3);
|
|
49426
49426
|
this.timers.delete(id);
|
|
49427
49427
|
this.pending.delete(id);
|
|
49428
49428
|
}
|
|
@@ -49545,7 +49545,7 @@ var StateStore = class {
|
|
|
49545
49545
|
* writes. For graceful shutdown (SIGTERM/SIGINT). Never rejects. */
|
|
49546
49546
|
async flushAll() {
|
|
49547
49547
|
const ids = this.pendingIds();
|
|
49548
|
-
for (const
|
|
49548
|
+
for (const timer3 of this.timers.values()) clearTimeout(timer3);
|
|
49549
49549
|
this.timers.clear();
|
|
49550
49550
|
const builders = /* @__PURE__ */ new Map();
|
|
49551
49551
|
for (const id of ids) {
|
|
@@ -49564,7 +49564,7 @@ var StateStore = class {
|
|
|
49564
49564
|
}
|
|
49565
49565
|
/** Cancel all pending debounced writes without flushing (tests). */
|
|
49566
49566
|
cancelAll() {
|
|
49567
|
-
for (const
|
|
49567
|
+
for (const timer3 of this.timers.values()) clearTimeout(timer3);
|
|
49568
49568
|
this.timers.clear();
|
|
49569
49569
|
this.pending.clear();
|
|
49570
49570
|
}
|
|
@@ -51572,6 +51572,93 @@ ${icon} [ACP] ${inner}
|
|
|
51572
51572
|
`;
|
|
51573
51573
|
}
|
|
51574
51574
|
|
|
51575
|
+
// src/weak-overflow.ts
|
|
51576
|
+
var MIN_USAGE = 0.9;
|
|
51577
|
+
var WINDOW_MS = 15 * 60 * 1e3;
|
|
51578
|
+
var MIN_EVENTS = 3;
|
|
51579
|
+
var MAX_TRACKED_SESSIONS = 512;
|
|
51580
|
+
var states = /* @__PURE__ */ new Map();
|
|
51581
|
+
function resolvedWindow2(session) {
|
|
51582
|
+
const md = session.metadata ?? {};
|
|
51583
|
+
const learned = md.learnedContextLimit;
|
|
51584
|
+
const effective = md.effectiveContextLimit;
|
|
51585
|
+
const candidates = [learned, effective].filter((v2) => typeof v2 === "number" && v2 > 0);
|
|
51586
|
+
if (candidates.length === 0) return 0;
|
|
51587
|
+
return Math.min(...candidates);
|
|
51588
|
+
}
|
|
51589
|
+
function noteWeakOverflow(session, opts) {
|
|
51590
|
+
const window2 = resolvedWindow2(session);
|
|
51591
|
+
if (window2 <= 0) return;
|
|
51592
|
+
const input = opts.inputTokens && opts.inputTokens > 0 ? opts.inputTokens : session.stats?.lastInputTokens ?? 0;
|
|
51593
|
+
if (input <= 0) return;
|
|
51594
|
+
if (input / window2 < MIN_USAGE) return;
|
|
51595
|
+
if (states.size > MAX_TRACKED_SESSIONS) {
|
|
51596
|
+
const oldest = states.keys().next().value;
|
|
51597
|
+
if (oldest !== void 0) states.delete(oldest);
|
|
51598
|
+
}
|
|
51599
|
+
const state = states.get(session.id) ?? { events: [] };
|
|
51600
|
+
const now = Date.now();
|
|
51601
|
+
state.events = state.events.filter((t) => now - t < WINDOW_MS);
|
|
51602
|
+
state.events.push(now);
|
|
51603
|
+
states.set(session.id, state);
|
|
51604
|
+
if (state.events.length < MIN_EVENTS) {
|
|
51605
|
+
log("warn", `[${session.id}] weak overflow signal ${state.events.length}/${MIN_EVENTS} (usage ${Math.round(input / window2 * 100)}%, ${opts.reason})`);
|
|
51606
|
+
return;
|
|
51607
|
+
}
|
|
51608
|
+
states.delete(session.id);
|
|
51609
|
+
const md = session.metadata ?? {};
|
|
51610
|
+
if (md.learnedContextLimits === void 0) md.learnedContextLimits = {};
|
|
51611
|
+
const learnedMap = md.learnedContextLimits;
|
|
51612
|
+
const reqModel = opts.model;
|
|
51613
|
+
const prev = (reqModel ? learnedMap[reqModel] : void 0) ?? md.learnedContextLimit;
|
|
51614
|
+
if (prev === void 0 || input < prev) {
|
|
51615
|
+
if (reqModel) learnedMap[reqModel] = input;
|
|
51616
|
+
else md.learnedContextLimit = input;
|
|
51617
|
+
session.metadata = md;
|
|
51618
|
+
log("warn", `[${session.id}] weak overflow confirmed (${MIN_EVENTS}\xD7 high-usage failures, ${opts.reason}) \u2014 learned conservative window ${input} for ${reqModel ?? "(unknown model)"} (was ${prev ?? "unset"}); arming emergency shrink`);
|
|
51619
|
+
} else {
|
|
51620
|
+
log("warn", `[${session.id}] weak overflow confirmed (${MIN_EVENTS}\xD7 high-usage failures, ${opts.reason}) \u2014 conservative window ${input} not below learned ${prev}; arming emergency shrink only`);
|
|
51621
|
+
}
|
|
51622
|
+
if (!session.stats) session.stats = { lastInputTokens: input };
|
|
51623
|
+
else session.stats.lastInputTokens = Math.max(session.stats.lastInputTokens, input);
|
|
51624
|
+
markDirty(session);
|
|
51625
|
+
}
|
|
51626
|
+
|
|
51627
|
+
// src/cache-warn.ts
|
|
51628
|
+
var MIN_INPUT = 8e3;
|
|
51629
|
+
var HIGH_HIT = 0.5;
|
|
51630
|
+
var LOW_HIT = 0.1;
|
|
51631
|
+
var LOW_RUN = 5;
|
|
51632
|
+
var MAX_TRACKED_SESSIONS2 = 1024;
|
|
51633
|
+
var watches = /* @__PURE__ */ new Map();
|
|
51634
|
+
function warnCacheCollapse(session, input, cached) {
|
|
51635
|
+
if (input < MIN_INPUT) return;
|
|
51636
|
+
if (watches.size > MAX_TRACKED_SESSIONS2) {
|
|
51637
|
+
const oldest = watches.keys().next().value;
|
|
51638
|
+
if (oldest !== void 0) watches.delete(oldest);
|
|
51639
|
+
}
|
|
51640
|
+
const watch = watches.get(session.id) ?? { sawHigh: false, lowRun: 0, warned: false };
|
|
51641
|
+
watches.set(session.id, watch);
|
|
51642
|
+
const hit = cached / input;
|
|
51643
|
+
if (hit >= HIGH_HIT) {
|
|
51644
|
+
watch.sawHigh = true;
|
|
51645
|
+
watch.lowRun = 0;
|
|
51646
|
+
return;
|
|
51647
|
+
}
|
|
51648
|
+
if (!watch.sawHigh || watch.warned) return;
|
|
51649
|
+
if (hit > LOW_HIT) {
|
|
51650
|
+
watch.lowRun = 0;
|
|
51651
|
+
return;
|
|
51652
|
+
}
|
|
51653
|
+
watch.lowRun++;
|
|
51654
|
+
if (watch.lowRun < LOW_RUN) return;
|
|
51655
|
+
watch.warned = true;
|
|
51656
|
+
log(
|
|
51657
|
+
"warn",
|
|
51658
|
+
`[${session.id}] upstream prompt-cache collapse: ${LOW_RUN} consecutive large requests at ~0% hit (last: input=${input}, cached=${cached}) after earlier \u2265${Math.round(HIGH_HIT * 100)}% hits \u2014 the context is being resent cold every turn. Likely causes: proxy/session restart re-forked the session (#499), or the upstream KV cache was dropped (window/deployment change). Check the session id upstream sees and compress.modelContextLimit.`
|
|
51659
|
+
);
|
|
51660
|
+
}
|
|
51661
|
+
|
|
51575
51662
|
// src/loop/core.ts
|
|
51576
51663
|
var MAX_LOOP_ROUNDS = 10;
|
|
51577
51664
|
function isLoopThinking(m2) {
|
|
@@ -51654,6 +51741,7 @@ function recordUsage(ctx, usage, round) {
|
|
|
51654
51741
|
}
|
|
51655
51742
|
if (typeof out === "number") ctx.session.stats.outputTokens += out;
|
|
51656
51743
|
const hitPct = typeof cached === "number" && total > 0 ? Math.round(cached / total * 100) : 0;
|
|
51744
|
+
warnCacheCollapse(ctx.session, total, cached ?? 0);
|
|
51657
51745
|
ctx.log(
|
|
51658
51746
|
`[acp-usage] round ${round} input=${total} cached=${cached ?? 0} (cache hit ${hitPct}%)`
|
|
51659
51747
|
);
|
|
@@ -51908,6 +51996,14 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
51908
51996
|
}
|
|
51909
51997
|
const reRequest = proxyResults.length > 0 && realCalls === 0;
|
|
51910
51998
|
if (!reRequest) {
|
|
51999
|
+
if (!sawDone || truncatedDone) {
|
|
52000
|
+
const reqModel = typeof requestBody["model"] === "string" ? requestBody["model"] : void 0;
|
|
52001
|
+
noteWeakOverflow(ctx.session, {
|
|
52002
|
+
inputTokens: usage.inputTokens,
|
|
52003
|
+
model: reqModel,
|
|
52004
|
+
reason: `round ${round}: upstream stream truncated without a completion event`
|
|
52005
|
+
});
|
|
52006
|
+
}
|
|
51911
52007
|
if (!sawDone) {
|
|
51912
52008
|
const partialText = assistantText.length;
|
|
51913
52009
|
const partialReasoning = assistantReasoning.length;
|
|
@@ -51932,11 +52028,11 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
51932
52028
|
let newBody = adapter.buildRequest(coreMessages, systemPrompt, requestBody);
|
|
51933
52029
|
if (process.env.ACP_DUMP_BODY === "1") {
|
|
51934
52030
|
try {
|
|
51935
|
-
const
|
|
52031
|
+
const fs13 = await import("fs");
|
|
51936
52032
|
const dumpDir = process.env.ACP_DUMP_DIR || `${process.env.HOME}/.local/state/billion-context/dumps`;
|
|
51937
|
-
|
|
52033
|
+
fs13.mkdirSync(dumpDir, { recursive: true });
|
|
51938
52034
|
const sid = ctx.session.id ?? "unknown";
|
|
51939
|
-
|
|
52035
|
+
fs13.writeFileSync(`${dumpDir}/req-${Date.now()}-${sid}-REREQUEST.json`, JSON.stringify(newBody, null, 2));
|
|
51940
52036
|
} catch {
|
|
51941
52037
|
}
|
|
51942
52038
|
}
|
|
@@ -51962,6 +52058,12 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
51962
52058
|
const suffix = e.attempts > 1 ? ` after ${e.attempts} attempt(s)` : "";
|
|
51963
52059
|
ctx.log(`[acp-proxy: compress loop upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}]`);
|
|
51964
52060
|
log("error", `[acp-loop] upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}`);
|
|
52061
|
+
const reqModel = typeof requestBody["model"] === "string" ? requestBody["model"] : void 0;
|
|
52062
|
+
noteWeakOverflow(ctx.session, {
|
|
52063
|
+
inputTokens: usage.inputTokens,
|
|
52064
|
+
model: reqModel,
|
|
52065
|
+
reason: `round ${round}: upstream error ${e.status}${suffix}`
|
|
52066
|
+
});
|
|
51965
52067
|
yield adapter.emitError(`upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}`);
|
|
51966
52068
|
return;
|
|
51967
52069
|
}
|
|
@@ -53946,7 +54048,7 @@ function codexTurnIdentity(headers) {
|
|
|
53946
54048
|
// src/prefix-affinity.ts
|
|
53947
54049
|
import { createHash as createHash5 } from "crypto";
|
|
53948
54050
|
var MIN_CANONICAL_BYTES = 24;
|
|
53949
|
-
var
|
|
54051
|
+
var MAX_TRACKED_SESSIONS3 = 256;
|
|
53950
54052
|
var TTL_MS2 = 7 * 24 * 60 * 60 * 1e3;
|
|
53951
54053
|
var TAIL_WINDOW = 8;
|
|
53952
54054
|
var MIN_TAIL_MATCH = 3;
|
|
@@ -54092,7 +54194,7 @@ var PrefixAffinityResolver = class {
|
|
|
54092
54194
|
const tracked = this.trackedChains;
|
|
54093
54195
|
tracked.delete(sessionId);
|
|
54094
54196
|
tracked.set(sessionId, { sessionId, depth, tailHash, itemHashes, lastSeen: Date.now() });
|
|
54095
|
-
while (tracked.size >
|
|
54197
|
+
while (tracked.size > MAX_TRACKED_SESSIONS3) {
|
|
54096
54198
|
const oldest = [...tracked.values()].sort((a, b2) => a.lastSeen - b2.lastSeen)[0];
|
|
54097
54199
|
if (!oldest) break;
|
|
54098
54200
|
tracked.delete(oldest.sessionId);
|
|
@@ -54105,6 +54207,48 @@ var PrefixAffinityResolver = class {
|
|
|
54105
54207
|
trackedSessionIds() {
|
|
54106
54208
|
return [...this.trackedChains.keys()];
|
|
54107
54209
|
}
|
|
54210
|
+
/** Serializable copy of the tracked chains (for #499 P1a persistence). */
|
|
54211
|
+
exportSnapshot() {
|
|
54212
|
+
return [...this.trackedChains.values()].map((e) => ({
|
|
54213
|
+
sessionId: e.sessionId,
|
|
54214
|
+
depth: e.depth,
|
|
54215
|
+
tailHash: e.tailHash,
|
|
54216
|
+
itemHashes: e.itemHashes,
|
|
54217
|
+
lastSeen: e.lastSeen
|
|
54218
|
+
}));
|
|
54219
|
+
}
|
|
54220
|
+
/** Load chains persisted by a previous process. Entries older than the
|
|
54221
|
+
* TTL are dropped (they would not match anyway). Returns the count
|
|
54222
|
+
* actually imported. Defensive: a corrupt/hand-edited file must never
|
|
54223
|
+
* crash the proxy — malformed entries are skipped. */
|
|
54224
|
+
importSnapshot(entries) {
|
|
54225
|
+
if (!Array.isArray(entries)) return 0;
|
|
54226
|
+
const now = Date.now();
|
|
54227
|
+
let imported = 0;
|
|
54228
|
+
for (const raw of entries) {
|
|
54229
|
+
if (!raw || typeof raw !== "object") continue;
|
|
54230
|
+
const e = raw;
|
|
54231
|
+
if (typeof e.sessionId !== "string" || typeof e.depth !== "number" || typeof e.tailHash !== "string") continue;
|
|
54232
|
+
if (!Array.isArray(e.itemHashes) || e.itemHashes.some((h) => typeof h !== "string")) continue;
|
|
54233
|
+
if (typeof e.lastSeen !== "number" || now - e.lastSeen > TTL_MS2) continue;
|
|
54234
|
+
const entry = {
|
|
54235
|
+
sessionId: e.sessionId,
|
|
54236
|
+
depth: e.depth,
|
|
54237
|
+
tailHash: e.tailHash,
|
|
54238
|
+
itemHashes: e.itemHashes.slice(-MAX_STORED_ITEMS),
|
|
54239
|
+
lastSeen: e.lastSeen
|
|
54240
|
+
};
|
|
54241
|
+
this.trackedChains.delete(entry.sessionId);
|
|
54242
|
+
this.trackedChains.set(entry.sessionId, entry);
|
|
54243
|
+
imported++;
|
|
54244
|
+
}
|
|
54245
|
+
while (this.trackedChains.size > MAX_TRACKED_SESSIONS3) {
|
|
54246
|
+
const oldest = [...this.trackedChains.values()].sort((a, b2) => a.lastSeen - b2.lastSeen)[0];
|
|
54247
|
+
if (!oldest) break;
|
|
54248
|
+
this.trackedChains.delete(oldest.sessionId);
|
|
54249
|
+
}
|
|
54250
|
+
return imported;
|
|
54251
|
+
}
|
|
54108
54252
|
expire(tracked) {
|
|
54109
54253
|
if (tracked.size === 0) return;
|
|
54110
54254
|
const now = Date.now();
|
|
@@ -54115,6 +54259,58 @@ var PrefixAffinityResolver = class {
|
|
|
54115
54259
|
};
|
|
54116
54260
|
var prefixAffinity = new PrefixAffinityResolver();
|
|
54117
54261
|
|
|
54262
|
+
// src/affinity-persist.ts
|
|
54263
|
+
import fs4 from "fs";
|
|
54264
|
+
import path8 from "path";
|
|
54265
|
+
var PERSIST_DEBOUNCE_MS = 5e3;
|
|
54266
|
+
function affinityFile() {
|
|
54267
|
+
return path8.join(stateDir(), "prefix-affinity.json");
|
|
54268
|
+
}
|
|
54269
|
+
var timer = null;
|
|
54270
|
+
var writing = false;
|
|
54271
|
+
function writeSnapshot() {
|
|
54272
|
+
if (writing) return;
|
|
54273
|
+
writing = true;
|
|
54274
|
+
try {
|
|
54275
|
+
const file = affinityFile();
|
|
54276
|
+
const snapshot = { version: 1, entries: prefixAffinity.exportSnapshot() };
|
|
54277
|
+
const tmp = `${file}.tmp`;
|
|
54278
|
+
fs4.mkdirSync(path8.dirname(file), { recursive: true });
|
|
54279
|
+
fs4.writeFileSync(tmp, JSON.stringify(snapshot));
|
|
54280
|
+
fs4.renameSync(tmp, file);
|
|
54281
|
+
} catch (e) {
|
|
54282
|
+
log("warn", `[prefix-affinity] persist failed (${e instanceof Error ? e.message : String(e)}); affinity survives in memory`);
|
|
54283
|
+
} finally {
|
|
54284
|
+
writing = false;
|
|
54285
|
+
}
|
|
54286
|
+
}
|
|
54287
|
+
function scheduleAffinityPersist() {
|
|
54288
|
+
if (timer) clearTimeout(timer);
|
|
54289
|
+
timer = setTimeout(() => {
|
|
54290
|
+
timer = null;
|
|
54291
|
+
writeSnapshot();
|
|
54292
|
+
}, PERSIST_DEBOUNCE_MS);
|
|
54293
|
+
timer.unref?.();
|
|
54294
|
+
}
|
|
54295
|
+
function flushPrefixAffinity() {
|
|
54296
|
+
if (timer) {
|
|
54297
|
+
clearTimeout(timer);
|
|
54298
|
+
timer = null;
|
|
54299
|
+
}
|
|
54300
|
+
writeSnapshot();
|
|
54301
|
+
}
|
|
54302
|
+
function hydratePrefixAffinity() {
|
|
54303
|
+
try {
|
|
54304
|
+
const file = affinityFile();
|
|
54305
|
+
if (!fs4.existsSync(file)) return;
|
|
54306
|
+
const parsed = JSON.parse(fs4.readFileSync(file, "utf8"));
|
|
54307
|
+
const imported = prefixAffinity.importSnapshot(parsed.entries);
|
|
54308
|
+
if (imported > 0) log("info", `[prefix-affinity] hydrated ${imported} chain(s) from ${path8.basename(file)} \u2014 anonymous sessions reattach across restarts`);
|
|
54309
|
+
} catch (e) {
|
|
54310
|
+
log("warn", `[prefix-affinity] hydrate failed (${e instanceof Error ? e.message : String(e)}); starting with empty affinity`);
|
|
54311
|
+
}
|
|
54312
|
+
}
|
|
54313
|
+
|
|
54118
54314
|
// node_modules/acp-kernel/dist/panel/index.js
|
|
54119
54315
|
function topicFallback(summary) {
|
|
54120
54316
|
const first = summary.split(/[.\n]/)[0] ?? "";
|
|
@@ -54258,8 +54454,8 @@ function buildStatusPanel(input) {
|
|
|
54258
54454
|
|
|
54259
54455
|
// src/plugin.ts
|
|
54260
54456
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
54261
|
-
import
|
|
54262
|
-
import
|
|
54457
|
+
import fs5 from "fs";
|
|
54458
|
+
import path9 from "path";
|
|
54263
54459
|
|
|
54264
54460
|
// src/sse-util.ts
|
|
54265
54461
|
function normalizeSseLineEndings(buf) {
|
|
@@ -54271,8 +54467,8 @@ function normalizeSseLineEndings(buf) {
|
|
|
54271
54467
|
var PROXY_VERSION = (() => {
|
|
54272
54468
|
try {
|
|
54273
54469
|
const here = fileURLToPath2(import.meta.url);
|
|
54274
|
-
const pkg =
|
|
54275
|
-
return JSON.parse(
|
|
54470
|
+
const pkg = path9.join(path9.dirname(here), "..", "package.json");
|
|
54471
|
+
return JSON.parse(fs5.readFileSync(pkg, "utf8")).version ?? "dev";
|
|
54276
54472
|
} catch {
|
|
54277
54473
|
return "dev";
|
|
54278
54474
|
}
|
|
@@ -54284,8 +54480,8 @@ var PLUGIN_PROTOCOL_VERSION = 1;
|
|
|
54284
54480
|
var VERSION = (() => {
|
|
54285
54481
|
try {
|
|
54286
54482
|
const here = fileURLToPath2(import.meta.url);
|
|
54287
|
-
const pkg =
|
|
54288
|
-
return JSON.parse(
|
|
54483
|
+
const pkg = path9.join(path9.dirname(here), "..", "package.json");
|
|
54484
|
+
return JSON.parse(fs5.readFileSync(pkg, "utf8")).version ?? "dev";
|
|
54289
54485
|
} catch {
|
|
54290
54486
|
return "dev";
|
|
54291
54487
|
}
|
|
@@ -54314,7 +54510,7 @@ function pluginReportedContextWindow(headers) {
|
|
|
54314
54510
|
var MAX_PLUGIN_CONVERSATIONS = 1024;
|
|
54315
54511
|
var conversations = /* @__PURE__ */ new Map();
|
|
54316
54512
|
var remembered = /* @__PURE__ */ new Map();
|
|
54317
|
-
var conversationsFile = () =>
|
|
54513
|
+
var conversationsFile = () => path9.join(stateDir(), "plugin-conversations.json");
|
|
54318
54514
|
var conversationsSaveTimer;
|
|
54319
54515
|
var conversationsDirty = false;
|
|
54320
54516
|
function writeConversationsFile() {
|
|
@@ -54322,11 +54518,11 @@ function writeConversationsFile() {
|
|
|
54322
54518
|
try {
|
|
54323
54519
|
const obj = {};
|
|
54324
54520
|
for (const [k2, v2] of conversations) obj[k2] = v2;
|
|
54325
|
-
|
|
54521
|
+
fs5.mkdirSync(stateDir(), { recursive: true });
|
|
54326
54522
|
const filePath = conversationsFile();
|
|
54327
54523
|
const draft = `${filePath}.${process.pid}.bili-tmp`;
|
|
54328
|
-
|
|
54329
|
-
|
|
54524
|
+
fs5.writeFileSync(draft, JSON.stringify(obj));
|
|
54525
|
+
fs5.renameSync(draft, filePath);
|
|
54330
54526
|
conversationsDirty = false;
|
|
54331
54527
|
} catch {
|
|
54332
54528
|
}
|
|
@@ -54348,7 +54544,7 @@ function flushConversations() {
|
|
|
54348
54544
|
function loadConversations() {
|
|
54349
54545
|
let raw;
|
|
54350
54546
|
try {
|
|
54351
|
-
raw =
|
|
54547
|
+
raw = fs5.readFileSync(conversationsFile(), "utf8");
|
|
54352
54548
|
} catch {
|
|
54353
54549
|
return;
|
|
54354
54550
|
}
|
|
@@ -54361,7 +54557,7 @@ function loadConversations() {
|
|
|
54361
54557
|
}
|
|
54362
54558
|
} catch {
|
|
54363
54559
|
try {
|
|
54364
|
-
|
|
54560
|
+
fs5.renameSync(conversationsFile(), `${conversationsFile()}.corrupt-${Date.now()}`);
|
|
54365
54561
|
} catch {
|
|
54366
54562
|
}
|
|
54367
54563
|
log("warn", "[plugin] plugin-conversations.json is corrupt \u2014 backed up beside the original, starting an empty routing table");
|
|
@@ -54647,6 +54843,7 @@ function applyUsageSample(session, sample, protocol) {
|
|
|
54647
54843
|
const total = sample.inputTokens + (!includesCached && sample.cachedTokens !== void 0 ? sample.cachedTokens : 0);
|
|
54648
54844
|
session.stats.inputTokens += total;
|
|
54649
54845
|
session.stats.lastInputTokens = Math.max(0, total - (session.stats.compressCreditTokens ?? 0));
|
|
54846
|
+
warnCacheCollapse(session, total, sample.cachedTokens ?? 0);
|
|
54650
54847
|
}
|
|
54651
54848
|
if (sample.outputTokens !== void 0) session.stats.outputTokens += sample.outputTokens;
|
|
54652
54849
|
}
|
|
@@ -54710,6 +54907,14 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
54710
54907
|
markDirty(session);
|
|
54711
54908
|
}
|
|
54712
54909
|
};
|
|
54910
|
+
let sawTerminal = false;
|
|
54911
|
+
const maybeNoteTruncated = () => {
|
|
54912
|
+
if (sawTerminal || !session || res.destroyed || res.writableEnded) return;
|
|
54913
|
+
noteWeakOverflow(session, {
|
|
54914
|
+
inputTokens: acc.inputTokens,
|
|
54915
|
+
reason: "plugin chat passthrough stream ended without a completion event"
|
|
54916
|
+
});
|
|
54917
|
+
};
|
|
54713
54918
|
const pushField = (field, index, text) => {
|
|
54714
54919
|
const s3 = filterFor(field, index);
|
|
54715
54920
|
const clean = s3.filter.push(text);
|
|
@@ -54795,6 +55000,7 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
54795
55000
|
const jsonStr = dataLines.map((l) => l.slice(5).replace(/^ /, "")).join("\n").trim();
|
|
54796
55001
|
if (!jsonStr) continue;
|
|
54797
55002
|
if (jsonStr === "[DONE]") {
|
|
55003
|
+
sawTerminal = true;
|
|
54798
55004
|
await write(flushTails() + rawEvent + "\n\n");
|
|
54799
55005
|
continue;
|
|
54800
55006
|
}
|
|
@@ -54805,6 +55011,7 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
54805
55011
|
await write(rawEvent + "\n\n");
|
|
54806
55012
|
continue;
|
|
54807
55013
|
}
|
|
55014
|
+
if (ev["type"] === "message_stop") sawTerminal = true;
|
|
54808
55015
|
const sample = usageFromSseEvent(ev);
|
|
54809
55016
|
if (sample) mergeUsageSample(acc, sample);
|
|
54810
55017
|
const out = protocol === "anthropic" ? processAnthropic(ev, rawEvent) : processOpenai(ev, rawEvent);
|
|
@@ -54816,8 +55023,10 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
54816
55023
|
const rest = flushTails();
|
|
54817
55024
|
if (rest.length > 0 && !res.destroyed && !res.writableEnded) await write(rest);
|
|
54818
55025
|
settleUsage();
|
|
55026
|
+
maybeNoteTruncated();
|
|
54819
55027
|
} catch (e) {
|
|
54820
55028
|
settleUsage();
|
|
55029
|
+
maybeNoteTruncated();
|
|
54821
55030
|
if (res.destroyed || res.writableEnded) {
|
|
54822
55031
|
log2?.("client aborted mid-stream");
|
|
54823
55032
|
return;
|
|
@@ -54862,6 +55071,14 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
54862
55071
|
markDirty(session);
|
|
54863
55072
|
}
|
|
54864
55073
|
};
|
|
55074
|
+
let sawTerminal = false;
|
|
55075
|
+
const maybeNoteTruncated = () => {
|
|
55076
|
+
if (sawTerminal || !session || res.destroyed || res.writableEnded) return;
|
|
55077
|
+
noteWeakOverflow(session, {
|
|
55078
|
+
inputTokens: acc.inputTokens,
|
|
55079
|
+
reason: "plugin responses passthrough stream ended without a completion event"
|
|
55080
|
+
});
|
|
55081
|
+
};
|
|
54865
55082
|
let lastDeltaMeta = null;
|
|
54866
55083
|
const flushTail = (after) => {
|
|
54867
55084
|
const tail = tagFilter.flush();
|
|
@@ -54887,6 +55104,7 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
54887
55104
|
if (dataLines.length === 0) continue;
|
|
54888
55105
|
const jsonStr = dataLines.map((l) => l.slice(5).replace(/^ /, "")).join("\n").trim();
|
|
54889
55106
|
if (!jsonStr || jsonStr === "[DONE]") {
|
|
55107
|
+
if (jsonStr === "[DONE]") sawTerminal = true;
|
|
54890
55108
|
await write(rawEvent + "\n\n");
|
|
54891
55109
|
continue;
|
|
54892
55110
|
}
|
|
@@ -54901,6 +55119,7 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
54901
55119
|
if (sample) mergeUsageSample(acc, sample);
|
|
54902
55120
|
const type = ev["type"];
|
|
54903
55121
|
if (type === "response.output_text.done" || type === "response.content_part.done" || type === "response.output_item.done" || type === "response.completed" || type === "response.failed" || type === "response.incomplete") {
|
|
55122
|
+
if (type === "response.completed" || type === "response.failed" || type === "response.incomplete") sawTerminal = true;
|
|
54904
55123
|
const out = containsRenderTagText(jsonStr) ? rebuildEvent(rawEvent, stripResponsesText(ev)) : rawEvent + "\n\n";
|
|
54905
55124
|
await write(flushTail(out));
|
|
54906
55125
|
continue;
|
|
@@ -54935,8 +55154,10 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
54935
55154
|
if (rest.length > 0) await write(rest);
|
|
54936
55155
|
}
|
|
54937
55156
|
settleUsage();
|
|
55157
|
+
maybeNoteTruncated();
|
|
54938
55158
|
} catch (e) {
|
|
54939
55159
|
settleUsage();
|
|
55160
|
+
maybeNoteTruncated();
|
|
54940
55161
|
if (res.destroyed || res.writableEnded) {
|
|
54941
55162
|
log2?.("client aborted mid-stream");
|
|
54942
55163
|
return;
|
|
@@ -55012,14 +55233,14 @@ async function pipePluginJson(stream2, res, session, protocol) {
|
|
|
55012
55233
|
import tls3 from "tls";
|
|
55013
55234
|
|
|
55014
55235
|
// src/discover.ts
|
|
55015
|
-
import
|
|
55236
|
+
import fs7 from "fs";
|
|
55016
55237
|
import os2 from "os";
|
|
55017
|
-
import
|
|
55238
|
+
import path11 from "path";
|
|
55018
55239
|
|
|
55019
55240
|
// src/client-config.ts
|
|
55020
|
-
import
|
|
55241
|
+
import fs6 from "fs";
|
|
55021
55242
|
import os from "os";
|
|
55022
|
-
import
|
|
55243
|
+
import path10 from "path";
|
|
55023
55244
|
function toModelWindow(id, contextWindow) {
|
|
55024
55245
|
return typeof id === "string" && id.length > 0 && typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? { id, contextWindow: Math.floor(contextWindow) } : null;
|
|
55025
55246
|
}
|
|
@@ -55028,7 +55249,7 @@ function nonEmpty2(s3) {
|
|
|
55028
55249
|
}
|
|
55029
55250
|
function readJsonObject(filePath) {
|
|
55030
55251
|
try {
|
|
55031
|
-
const txt =
|
|
55252
|
+
const txt = fs6.readFileSync(filePath, "utf8");
|
|
55032
55253
|
const parsed = JSON.parse(txt);
|
|
55033
55254
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
55034
55255
|
} catch {
|
|
@@ -55037,19 +55258,19 @@ function readJsonObject(filePath) {
|
|
|
55037
55258
|
}
|
|
55038
55259
|
function resolvePiHome(env) {
|
|
55039
55260
|
const h = os.homedir();
|
|
55040
|
-
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : nonEmpty2(env.PI_HOME) ? env.PI_HOME :
|
|
55261
|
+
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : nonEmpty2(env.PI_HOME) ? env.PI_HOME : path10.join(h, ".pi", "agent");
|
|
55041
55262
|
}
|
|
55042
55263
|
function resolveOmpHome(env) {
|
|
55043
55264
|
const h = os.homedir();
|
|
55044
|
-
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR :
|
|
55265
|
+
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : path10.join(h, ".omp", "agent");
|
|
55045
55266
|
}
|
|
55046
55267
|
function resolveHermesHome(env) {
|
|
55047
55268
|
const h = os.homedir();
|
|
55048
|
-
return nonEmpty2(env.HERMES_HOME) ? env.HERMES_HOME :
|
|
55269
|
+
return nonEmpty2(env.HERMES_HOME) ? env.HERMES_HOME : path10.join(h, ".hermes");
|
|
55049
55270
|
}
|
|
55050
55271
|
function resolveDshHome(env) {
|
|
55051
55272
|
const h = os.homedir();
|
|
55052
|
-
return nonEmpty2(env.DSH_HOME) ? env.DSH_HOME :
|
|
55273
|
+
return nonEmpty2(env.DSH_HOME) ? env.DSH_HOME : path10.join(h, ".dsh");
|
|
55053
55274
|
}
|
|
55054
55275
|
function parseDshSettingsYaml(text) {
|
|
55055
55276
|
const out = [];
|
|
@@ -55068,7 +55289,7 @@ function parseDshSettingsYaml(text) {
|
|
|
55068
55289
|
function readDshConfig(dshHome) {
|
|
55069
55290
|
let text;
|
|
55070
55291
|
try {
|
|
55071
|
-
text =
|
|
55292
|
+
text = fs6.readFileSync(path10.join(dshHome, "settings.yaml"), "utf8");
|
|
55072
55293
|
} catch {
|
|
55073
55294
|
return { baseUrls: [] };
|
|
55074
55295
|
}
|
|
@@ -55076,8 +55297,8 @@ function readDshConfig(dshHome) {
|
|
|
55076
55297
|
}
|
|
55077
55298
|
function readClaudeSettings(homeDir, cwd, env = process.env) {
|
|
55078
55299
|
const files = [
|
|
55079
|
-
|
|
55080
|
-
|
|
55300
|
+
path10.join(homeDir, ".claude", "settings.json"),
|
|
55301
|
+
path10.join(cwd, ".claude", "settings.json")
|
|
55081
55302
|
];
|
|
55082
55303
|
let anthropicBaseUrl;
|
|
55083
55304
|
let model;
|
|
@@ -55150,17 +55371,17 @@ function parseCodexToml(text) {
|
|
|
55150
55371
|
return result;
|
|
55151
55372
|
}
|
|
55152
55373
|
function readCodexConfig(codexHome) {
|
|
55153
|
-
const cfgPath =
|
|
55374
|
+
const cfgPath = path10.join(codexHome, "config.toml");
|
|
55154
55375
|
let text;
|
|
55155
55376
|
try {
|
|
55156
|
-
text =
|
|
55377
|
+
text = fs6.readFileSync(cfgPath, "utf8");
|
|
55157
55378
|
} catch {
|
|
55158
55379
|
return { providers: {} };
|
|
55159
55380
|
}
|
|
55160
55381
|
return parseCodexToml(text);
|
|
55161
55382
|
}
|
|
55162
55383
|
function readPiConfig(piHome) {
|
|
55163
|
-
const cfgPath =
|
|
55384
|
+
const cfgPath = path10.join(piHome, "models.json");
|
|
55164
55385
|
const obj = readJsonObject(cfgPath);
|
|
55165
55386
|
const providers = {};
|
|
55166
55387
|
const rawProviders = obj?.providers;
|
|
@@ -55241,10 +55462,10 @@ function parseOmpYaml(text) {
|
|
|
55241
55462
|
return result;
|
|
55242
55463
|
}
|
|
55243
55464
|
function readOmpConfig(ompHome) {
|
|
55244
|
-
const cfgPath =
|
|
55465
|
+
const cfgPath = path10.join(ompHome, "models.yml");
|
|
55245
55466
|
let text;
|
|
55246
55467
|
try {
|
|
55247
|
-
text =
|
|
55468
|
+
text = fs6.readFileSync(cfgPath, "utf8");
|
|
55248
55469
|
} catch {
|
|
55249
55470
|
return { providers: {} };
|
|
55250
55471
|
}
|
|
@@ -55317,10 +55538,10 @@ function parseHermesYaml(text) {
|
|
|
55317
55538
|
return result;
|
|
55318
55539
|
}
|
|
55319
55540
|
function readHermesConfig(hermesHome) {
|
|
55320
|
-
const cfgPath =
|
|
55541
|
+
const cfgPath = path10.join(hermesHome, "config.yaml");
|
|
55321
55542
|
let text;
|
|
55322
55543
|
try {
|
|
55323
|
-
text =
|
|
55544
|
+
text = fs6.readFileSync(cfgPath, "utf8");
|
|
55324
55545
|
} catch {
|
|
55325
55546
|
return { providers: {} };
|
|
55326
55547
|
}
|
|
@@ -55328,13 +55549,13 @@ function readHermesConfig(hermesHome) {
|
|
|
55328
55549
|
}
|
|
55329
55550
|
function resolveOpencodeConfigFile(env) {
|
|
55330
55551
|
if (nonEmpty2(env.OPENCODE_CONFIG)) return env.OPENCODE_CONFIG;
|
|
55331
|
-
const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME :
|
|
55332
|
-
return
|
|
55552
|
+
const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path10.join(os.homedir(), ".config");
|
|
55553
|
+
return path10.join(xdg2, "opencode", "opencode.json");
|
|
55333
55554
|
}
|
|
55334
55555
|
function readOpencodeConfig(file) {
|
|
55335
55556
|
let text;
|
|
55336
55557
|
try {
|
|
55337
|
-
text =
|
|
55558
|
+
text = fs6.readFileSync(file, "utf8");
|
|
55338
55559
|
} catch {
|
|
55339
55560
|
return { providers: {} };
|
|
55340
55561
|
}
|
|
@@ -55391,10 +55612,10 @@ function parseZcodeConfig(obj) {
|
|
|
55391
55612
|
return result;
|
|
55392
55613
|
}
|
|
55393
55614
|
function readZcodeConfig(zcodeHome) {
|
|
55394
|
-
const cfgPath =
|
|
55615
|
+
const cfgPath = path10.join(zcodeHome, "v2", "config.json");
|
|
55395
55616
|
let txt;
|
|
55396
55617
|
try {
|
|
55397
|
-
txt =
|
|
55618
|
+
txt = fs6.readFileSync(cfgPath, "utf8");
|
|
55398
55619
|
} catch {
|
|
55399
55620
|
return { providers: {} };
|
|
55400
55621
|
}
|
|
@@ -55410,10 +55631,10 @@ function loadClientConfig(env, cwd) {
|
|
|
55410
55631
|
const home = os.homedir();
|
|
55411
55632
|
const config = {};
|
|
55412
55633
|
config.claude = readClaudeSettings(home, cwd, env);
|
|
55413
|
-
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME :
|
|
55634
|
+
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path10.join(home, ".codex");
|
|
55414
55635
|
config.codex = readCodexConfig(codexHome);
|
|
55415
55636
|
config.pi = readPiConfig(resolvePiHome(env));
|
|
55416
|
-
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR :
|
|
55637
|
+
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path10.join(home, ".zcode");
|
|
55417
55638
|
config.zcode = readZcodeConfig(zcodeHome);
|
|
55418
55639
|
config.omp = readOmpConfig(resolveOmpHome(env));
|
|
55419
55640
|
config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
|
|
@@ -55480,21 +55701,21 @@ function extractHttpsHosts(config) {
|
|
|
55480
55701
|
}
|
|
55481
55702
|
function configFilePaths(env) {
|
|
55482
55703
|
const home = os2.homedir();
|
|
55483
|
-
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME :
|
|
55484
|
-
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR :
|
|
55704
|
+
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path11.join(home, ".codex");
|
|
55705
|
+
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path11.join(home, ".zcode");
|
|
55485
55706
|
return [
|
|
55486
|
-
|
|
55487
|
-
|
|
55488
|
-
|
|
55489
|
-
|
|
55490
|
-
|
|
55707
|
+
path11.join(home, ".claude", "settings.json"),
|
|
55708
|
+
path11.join(process.cwd(), ".claude", "settings.json"),
|
|
55709
|
+
path11.join(codexHome, "config.toml"),
|
|
55710
|
+
path11.join(resolvePiHome(env), "models.json"),
|
|
55711
|
+
path11.join(zcodeHome, "v2", "config.json")
|
|
55491
55712
|
];
|
|
55492
55713
|
}
|
|
55493
55714
|
function readMtimes(paths) {
|
|
55494
55715
|
const mtimes = /* @__PURE__ */ new Map();
|
|
55495
55716
|
for (const p2 of paths) {
|
|
55496
55717
|
try {
|
|
55497
|
-
const st2 =
|
|
55718
|
+
const st2 = fs7.statSync(p2);
|
|
55498
55719
|
mtimes.set(p2, st2.mtimeMs);
|
|
55499
55720
|
} catch {
|
|
55500
55721
|
}
|
|
@@ -56676,7 +56897,8 @@ Content-Length: ${Buffer.byteLength(body)}\r
|
|
|
56676
56897
|
const originHost = opts.host === "0.0.0.0" || opts.host === "::" || opts.host === "localhost" ? "127.0.0.1" : opts.host.includes(":") && !opts.host.startsWith("[") ? `[${opts.host}]` : opts.host;
|
|
56677
56898
|
const origin = `http://${originHost}:${actualPort}`;
|
|
56678
56899
|
try {
|
|
56679
|
-
|
|
56900
|
+
fs8.mkdirSync(stateDir(), { recursive: true });
|
|
56901
|
+
hydratePrefixAffinity();
|
|
56680
56902
|
atomicWriteInstanceFile({
|
|
56681
56903
|
origin,
|
|
56682
56904
|
instanceId,
|
|
@@ -56741,6 +56963,7 @@ Content-Length: ${Buffer.byteLength(body)}\r
|
|
|
56741
56963
|
});
|
|
56742
56964
|
let shuttingDown = false;
|
|
56743
56965
|
const finishShutdown = () => {
|
|
56966
|
+
flushPrefixAffinity();
|
|
56744
56967
|
clearProxyInstanceFile(instanceId);
|
|
56745
56968
|
unregisterInstance(instanceId);
|
|
56746
56969
|
closeLogger();
|
|
@@ -57017,14 +57240,14 @@ async function handle(req, res, opts, core, config, log2, instanceId, instanceSt
|
|
|
57017
57240
|
try {
|
|
57018
57241
|
const rawDir = process.env.ACP_RAW_DUMP_DIR || `${stateDir()}/raw`;
|
|
57019
57242
|
try {
|
|
57020
|
-
|
|
57243
|
+
fs8.mkdirSync(rawDir, { recursive: true });
|
|
57021
57244
|
} catch {
|
|
57022
57245
|
}
|
|
57023
57246
|
const hdrs = maskHeadersForLog(
|
|
57024
57247
|
Object.fromEntries(Object.entries(req.headers).map(([k2, v2]) => [k2, Array.isArray(v2) ? v2.join(",") : String(v2)]))
|
|
57025
57248
|
);
|
|
57026
57249
|
const hdrText = Object.entries(hdrs).map(([k2, v2]) => `${k2}: ${v2}`).join("\n");
|
|
57027
|
-
|
|
57250
|
+
fs8.writeFileSync(`${rawDir}/${Date.now()}-INCOMING.txt`, `${req.method} ${maskUrlsInText(req.url ?? "")}
|
|
57028
57251
|
${hdrText}
|
|
57029
57252
|
|
|
57030
57253
|
${bodyBuffer.toString("utf8")}`);
|
|
@@ -57129,6 +57352,7 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
57129
57352
|
const session = getSession(sessionId, { protocol, upstreamOrigin, label: clientLabel ?? (anonAffinity ? "prefix-affinity" : void 0) });
|
|
57130
57353
|
if (anonAffinity) {
|
|
57131
57354
|
prefixAffinity.note(sessionId, anonAffinity.incomingDepth, anonAffinity.tailHash, anonAffinity.itemHashes);
|
|
57355
|
+
scheduleAffinityPersist();
|
|
57132
57356
|
session.metadata.anonymousPrefixAffinity = {
|
|
57133
57357
|
depth: anonAffinity.incomingDepth,
|
|
57134
57358
|
tailHash: anonAffinity.tailHash,
|
|
@@ -57876,16 +58100,16 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
|
|
|
57876
58100
|
if (bodyDumpEnabled() && process.env.ACP_DUMP_REQ !== "0") {
|
|
57877
58101
|
const dumpDir = process.env.ACP_DUMP_DIR || `${stateDir()}/dumps`;
|
|
57878
58102
|
try {
|
|
57879
|
-
|
|
58103
|
+
fs8.mkdirSync(dumpDir, { recursive: true });
|
|
57880
58104
|
} catch {
|
|
57881
58105
|
}
|
|
57882
58106
|
const sid = prepared?.session.id ?? "unknown";
|
|
57883
58107
|
const out = `${dumpDir}/req-${Date.now()}-${safeSessionId(sid)}.json`;
|
|
57884
58108
|
try {
|
|
57885
58109
|
const pretty = JSON.stringify(JSON.parse(body), null, 2);
|
|
57886
|
-
|
|
58110
|
+
fs8.writeFileSync(out, pretty);
|
|
57887
58111
|
} catch {
|
|
57888
|
-
|
|
58112
|
+
fs8.writeFileSync(out, body);
|
|
57889
58113
|
}
|
|
57890
58114
|
log2("info", `[debug] forwarded body written to ${out}`);
|
|
57891
58115
|
}
|
|
@@ -57905,7 +58129,7 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
|
|
|
57905
58129
|
const rawBase = bodyDumpEnabled() ? (() => {
|
|
57906
58130
|
try {
|
|
57907
58131
|
const rawDir = process.env.ACP_RAW_DUMP_DIR || `${stateDir()}/raw`;
|
|
57908
|
-
|
|
58132
|
+
fs8.mkdirSync(rawDir, { recursive: true });
|
|
57909
58133
|
return `${rawDir}/${Date.now()}-${safeSessionId(prepared?.session.id)}`;
|
|
57910
58134
|
} catch {
|
|
57911
58135
|
return "";
|
|
@@ -57916,7 +58140,7 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
|
|
|
57916
58140
|
const hdrText = Object.entries(maskHeadersForLog(headers)).map(([k2, v2]) => `${k2}: ${v2}`).join("\n");
|
|
57917
58141
|
const bodyText = req.method === "GET" || req.method === "HEAD" ? "" : typeof body === "string" ? body : Buffer.from(body).toString("utf8");
|
|
57918
58142
|
const reqPath = `${rawBase}-REQ.txt`;
|
|
57919
|
-
|
|
58143
|
+
fs8.writeFileSync(reqPath, `${req.method ?? "POST"} ${maskUrlForLog(upstreamUrl)}
|
|
57920
58144
|
${hdrText}
|
|
57921
58145
|
|
|
57922
58146
|
${bodyText}`);
|
|
@@ -57966,7 +58190,7 @@ ${bodyText}`);
|
|
|
57966
58190
|
try {
|
|
57967
58191
|
const hdrText = Object.entries(maskHeadersForLog(respHeaders)).map(([k2, v2]) => `${k2}: ${v2}`).join("\n");
|
|
57968
58192
|
const resPath = `${rawBase}-RES.txt`;
|
|
57969
|
-
|
|
58193
|
+
fs8.writeFileSync(resPath, `${upstream.status}
|
|
57970
58194
|
${hdrText}
|
|
57971
58195
|
`);
|
|
57972
58196
|
log2("info", `[debug] RAW response dump: ${resPath}`);
|
|
@@ -60382,7 +60606,7 @@ var hr = /* @__PURE__ */ Symbol("entry");
|
|
|
60382
60606
|
var cs = /* @__PURE__ */ Symbol("entryOpt");
|
|
60383
60607
|
var ui = /* @__PURE__ */ Symbol("writeEntryClass");
|
|
60384
60608
|
var lr = /* @__PURE__ */ Symbol("write");
|
|
60385
|
-
var
|
|
60609
|
+
var fs9 = /* @__PURE__ */ Symbol("ondrain");
|
|
60386
60610
|
var wt = class extends A {
|
|
60387
60611
|
sync = false;
|
|
60388
60612
|
opt;
|
|
@@ -60416,8 +60640,8 @@ var wt = class extends A {
|
|
|
60416
60640
|
if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive");
|
|
60417
60641
|
if (t.gzip && (typeof t.gzip != "object" && (t.gzip = {}), this.portable && (t.gzip.portable = true), this.zip = new ze(t.gzip)), t.brotli && (typeof t.brotli != "object" && (t.brotli = {}), this.zip = new We(t.brotli)), t.zstd && (typeof t.zstd != "object" && (t.zstd = {}), this.zip = new Ye(t.zstd)), !this.zip) throw new Error("impossible");
|
|
60418
60642
|
let e = this.zip;
|
|
60419
|
-
e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[
|
|
60420
|
-
} else this.on("drain", this[
|
|
60643
|
+
e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs9]()), this.on("resume", () => e.resume());
|
|
60644
|
+
} else this.on("drain", this[fs9]);
|
|
60421
60645
|
this.noDirRecurse = !!t.noDirRecurse, this.follow = !!t.follow, this.noMtime = !!t.noMtime, t.mtime && (this.mtime = t.mtime), this.filter = typeof t.filter == "function" ? t.filter : () => true, this[W] = new hi(), this[G] = 0, this.jobs = Number(t.jobs) || 4, this[Ee] = false, this[me] = false;
|
|
60422
60646
|
}
|
|
60423
60647
|
[lr](t) {
|
|
@@ -60530,7 +60754,7 @@ var wt = class extends A {
|
|
|
60530
60754
|
this.emit("error", e);
|
|
60531
60755
|
}
|
|
60532
60756
|
}
|
|
60533
|
-
[
|
|
60757
|
+
[fs9]() {
|
|
60534
60758
|
this[Et] && this[Et].entry && this[Et].entry.resume();
|
|
60535
60759
|
}
|
|
60536
60760
|
[di](t) {
|
|
@@ -61415,17 +61639,17 @@ var To = (s3) => {
|
|
|
61415
61639
|
};
|
|
61416
61640
|
|
|
61417
61641
|
// src/update.ts
|
|
61418
|
-
import
|
|
61642
|
+
import path12 from "path";
|
|
61419
61643
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
61420
61644
|
var REGISTRY_BASE = "https://registry.npmjs.org";
|
|
61421
61645
|
var CHECK_INTERVAL_MS = 3 * 60 * 1e3;
|
|
61422
|
-
var THROTTLE_FILE =
|
|
61423
|
-
var LOCK_FILE =
|
|
61646
|
+
var THROTTLE_FILE = path12.join(cacheDir(), ".update-check");
|
|
61647
|
+
var LOCK_FILE = path12.join(cacheDir(), ".update-lock");
|
|
61424
61648
|
var LOCK_MAX_AGE_MS = 30 * 60 * 1e3;
|
|
61425
61649
|
function shouldStealLock(holderAlive, ageMs) {
|
|
61426
61650
|
return !holderAlive || ageMs >= LOCK_MAX_AGE_MS;
|
|
61427
61651
|
}
|
|
61428
|
-
var
|
|
61652
|
+
var timer2;
|
|
61429
61653
|
var inFlight = false;
|
|
61430
61654
|
var firstCheckDone = false;
|
|
61431
61655
|
function parseVersion(v2) {
|
|
@@ -61455,27 +61679,27 @@ async function readLastCheck() {
|
|
|
61455
61679
|
}
|
|
61456
61680
|
async function writeLastCheck(ts2) {
|
|
61457
61681
|
try {
|
|
61458
|
-
await mkdir2(
|
|
61682
|
+
await mkdir2(path12.dirname(THROTTLE_FILE), { recursive: true });
|
|
61459
61683
|
await writeFile2(THROTTLE_FILE, String(ts2), "utf-8");
|
|
61460
61684
|
} catch {
|
|
61461
61685
|
}
|
|
61462
61686
|
}
|
|
61463
61687
|
async function findInstallDir(packageName) {
|
|
61464
|
-
let dir =
|
|
61688
|
+
let dir = path12.dirname(fileURLToPath3(import.meta.url));
|
|
61465
61689
|
for (; ; ) {
|
|
61466
61690
|
try {
|
|
61467
|
-
const pkg = JSON.parse(await readFile2(
|
|
61691
|
+
const pkg = JSON.parse(await readFile2(path12.join(dir, "package.json"), "utf-8"));
|
|
61468
61692
|
if (pkg.name === packageName) return dir;
|
|
61469
61693
|
} catch {
|
|
61470
61694
|
}
|
|
61471
|
-
const parent =
|
|
61695
|
+
const parent = path12.dirname(dir);
|
|
61472
61696
|
if (parent === dir) return void 0;
|
|
61473
61697
|
dir = parent;
|
|
61474
61698
|
}
|
|
61475
61699
|
}
|
|
61476
61700
|
async function readDiskVersion(installDir) {
|
|
61477
61701
|
try {
|
|
61478
|
-
const pkg = JSON.parse(await readFile2(
|
|
61702
|
+
const pkg = JSON.parse(await readFile2(path12.join(installDir, "package.json"), "utf-8"));
|
|
61479
61703
|
return pkg.version;
|
|
61480
61704
|
} catch {
|
|
61481
61705
|
return void 0;
|
|
@@ -61512,13 +61736,13 @@ async function syntaxCheckEntry(entryAbs) {
|
|
|
61512
61736
|
} catch (e) {
|
|
61513
61737
|
return `entry unreadable: ${String(e)}`;
|
|
61514
61738
|
}
|
|
61515
|
-
const tmpCheck =
|
|
61739
|
+
const tmpCheck = path12.join(cacheDir(), ".update-syntax-check.mjs");
|
|
61516
61740
|
try {
|
|
61517
61741
|
await mkdir2(cacheDir(), { recursive: true });
|
|
61518
61742
|
await writeFile2(tmpCheck, source);
|
|
61519
61743
|
const r = await runNodeCheck(tmpCheck);
|
|
61520
61744
|
if (r.code !== 0) {
|
|
61521
|
-
return `entry does not parse (${
|
|
61745
|
+
return `entry does not parse (${path12.basename(entryAbs)}): ${r.stderr.split("\n").filter(Boolean).slice(0, 3).join(" | ").slice(0, 300)}`;
|
|
61522
61746
|
}
|
|
61523
61747
|
return null;
|
|
61524
61748
|
} finally {
|
|
@@ -61531,7 +61755,7 @@ async function syntaxCheckEntry(entryAbs) {
|
|
|
61531
61755
|
async function verifyEntries(dir, label) {
|
|
61532
61756
|
let pkg;
|
|
61533
61757
|
try {
|
|
61534
|
-
pkg = JSON.parse(await readFile2(
|
|
61758
|
+
pkg = JSON.parse(await readFile2(path12.join(dir, "package.json"), "utf-8"));
|
|
61535
61759
|
} catch (e) {
|
|
61536
61760
|
return `${label}: package.json unreadable: ${String(e)}`;
|
|
61537
61761
|
}
|
|
@@ -61541,11 +61765,11 @@ async function verifyEntries(dir, label) {
|
|
|
61541
61765
|
}
|
|
61542
61766
|
for (const rel2 of entries) {
|
|
61543
61767
|
try {
|
|
61544
|
-
await access(
|
|
61768
|
+
await access(path12.join(dir, rel2));
|
|
61545
61769
|
} catch {
|
|
61546
61770
|
return `${label}: entry missing: ${rel2}`;
|
|
61547
61771
|
}
|
|
61548
|
-
const reason = await syntaxCheckEntry(
|
|
61772
|
+
const reason = await syntaxCheckEntry(path12.join(dir, rel2));
|
|
61549
61773
|
if (reason) return `${label}: ${reason}`;
|
|
61550
61774
|
}
|
|
61551
61775
|
return null;
|
|
@@ -61750,14 +61974,14 @@ async function installViaTarball(version2, tarballUrl, installDir, integrity, sh
|
|
|
61750
61974
|
if (!v2.ok) {
|
|
61751
61975
|
return { ok: false, error: `tarball integrity verification failed: ${v2.error}` };
|
|
61752
61976
|
}
|
|
61753
|
-
const tmpFile =
|
|
61977
|
+
const tmpFile = path12.join(cacheDir(), `.update-${version2}.tgz`);
|
|
61754
61978
|
try {
|
|
61755
61979
|
await mkdir2(cacheDir(), { recursive: true });
|
|
61756
61980
|
await writeFile2(tmpFile, tgzBuffer);
|
|
61757
61981
|
} catch (e) {
|
|
61758
61982
|
return { ok: false, error: `failed to write temp file ${tmpFile}: ${String(e)}` };
|
|
61759
61983
|
}
|
|
61760
|
-
const stagingDir =
|
|
61984
|
+
const stagingDir = path12.join(cacheDir(), `.update-staging-${version2}`);
|
|
61761
61985
|
try {
|
|
61762
61986
|
await rm2(stagingDir, { recursive: true, force: true });
|
|
61763
61987
|
await mkdir2(stagingDir, { recursive: true });
|
|
@@ -61779,7 +62003,7 @@ async function installViaTarball(version2, tarballUrl, installDir, integrity, sh
|
|
|
61779
62003
|
} finally {
|
|
61780
62004
|
await rm2(tmpFile, { force: true });
|
|
61781
62005
|
}
|
|
61782
|
-
const backupDir =
|
|
62006
|
+
const backupDir = path12.join(cacheDir(), `.update-backup-${version2}`);
|
|
61783
62007
|
try {
|
|
61784
62008
|
await rm2(backupDir, { recursive: true, force: true });
|
|
61785
62009
|
await cp(installDir, backupDir, { recursive: true, force: true });
|
|
@@ -61828,21 +62052,21 @@ function startAutoUpdate(opts) {
|
|
|
61828
62052
|
setTimeout(() => {
|
|
61829
62053
|
void checkForUpdate(opts);
|
|
61830
62054
|
}, 1e4);
|
|
61831
|
-
|
|
62055
|
+
timer2 = setInterval(() => {
|
|
61832
62056
|
void checkForUpdate(opts);
|
|
61833
62057
|
}, CHECK_INTERVAL_MS);
|
|
61834
|
-
|
|
62058
|
+
timer2.unref?.();
|
|
61835
62059
|
}
|
|
61836
62060
|
|
|
61837
62061
|
// src/mcp.ts
|
|
61838
|
-
import
|
|
61839
|
-
import
|
|
62062
|
+
import fs10 from "fs";
|
|
62063
|
+
import path13 from "path";
|
|
61840
62064
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
61841
62065
|
var VERSION2 = (() => {
|
|
61842
62066
|
try {
|
|
61843
62067
|
const here = fileURLToPath4(import.meta.url);
|
|
61844
|
-
const pkg =
|
|
61845
|
-
return JSON.parse(
|
|
62068
|
+
const pkg = path13.join(path13.dirname(here), "..", "package.json");
|
|
62069
|
+
return JSON.parse(fs10.readFileSync(pkg, "utf8")).version ?? "dev";
|
|
61846
62070
|
} catch {
|
|
61847
62071
|
return "dev";
|
|
61848
62072
|
}
|
|
@@ -62011,8 +62235,8 @@ if (process.argv[1] && /(?:^|[\\/])mcp\.(?:ts|js)$/.test(process.argv[1])) {
|
|
|
62011
62235
|
}
|
|
62012
62236
|
|
|
62013
62237
|
// src/plugin-install.ts
|
|
62014
|
-
import
|
|
62015
|
-
import
|
|
62238
|
+
import fs11 from "fs";
|
|
62239
|
+
import path14 from "path";
|
|
62016
62240
|
import os4 from "os";
|
|
62017
62241
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
62018
62242
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -62031,22 +62255,22 @@ function proxyOriginForInstall() {
|
|
|
62031
62255
|
var PLUGIN_AGENTS = ["pi", "omp", "claude", "codex", "opencode"];
|
|
62032
62256
|
function selfPackageRoot() {
|
|
62033
62257
|
const here = fileURLToPath5(import.meta.url);
|
|
62034
|
-
return
|
|
62258
|
+
return path14.resolve(path14.dirname(here), "..");
|
|
62035
62259
|
}
|
|
62036
62260
|
function homeFile(rel2, envOverride) {
|
|
62037
62261
|
const raw = (envOverride !== void 0 ? process.env[envOverride] : void 0)?.trim();
|
|
62038
62262
|
const base = raw && raw.length > 0 ? raw : os4.homedir();
|
|
62039
|
-
return
|
|
62263
|
+
return path14.join(base, rel2);
|
|
62040
62264
|
}
|
|
62041
62265
|
function backupOnce(file) {
|
|
62042
|
-
if (
|
|
62043
|
-
|
|
62266
|
+
if (fs11.existsSync(file) && !fs11.existsSync(`${file}.bili-bak`)) {
|
|
62267
|
+
fs11.copyFileSync(file, `${file}.bili-bak`);
|
|
62044
62268
|
}
|
|
62045
62269
|
}
|
|
62046
62270
|
function readJson(file) {
|
|
62047
62271
|
let text;
|
|
62048
62272
|
try {
|
|
62049
|
-
text =
|
|
62273
|
+
text = fs11.readFileSync(file, "utf8");
|
|
62050
62274
|
} catch (err2) {
|
|
62051
62275
|
if (err2.code === "ENOENT") return {};
|
|
62052
62276
|
throw err2;
|
|
@@ -62055,7 +62279,7 @@ function readJson(file) {
|
|
|
62055
62279
|
try {
|
|
62056
62280
|
parsed = JSON.parse(text);
|
|
62057
62281
|
} catch (err2) {
|
|
62058
|
-
throw new Error(`${file}: not valid JSON (${err2 instanceof Error ? err2.message : String(err2)}) \u2014 fix it or restore ${
|
|
62282
|
+
throw new Error(`${file}: not valid JSON (${err2 instanceof Error ? err2.message : String(err2)}) \u2014 fix it or restore ${path14.basename(file)}.bili-bak first; refusing to overwrite`);
|
|
62059
62283
|
}
|
|
62060
62284
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
62061
62285
|
throw new Error(`${file}: expected a JSON object at top level, refusing to overwrite`);
|
|
@@ -62063,18 +62287,18 @@ function readJson(file) {
|
|
|
62063
62287
|
return parsed;
|
|
62064
62288
|
}
|
|
62065
62289
|
function writeJson(file, data) {
|
|
62066
|
-
|
|
62290
|
+
fs11.mkdirSync(path14.dirname(file), { recursive: true });
|
|
62067
62291
|
backupOnce(file);
|
|
62068
|
-
|
|
62292
|
+
fs11.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
|
|
62069
62293
|
}
|
|
62070
62294
|
function requireDistFile(file) {
|
|
62071
|
-
if (!
|
|
62295
|
+
if (!fs11.existsSync(file)) {
|
|
62072
62296
|
process.stderr.write(`bili plugin: warning: ${file} does not exist yet (run \`npm run build\` in ${selfPackageRoot()}) \u2014 the entry will be dead until built
|
|
62073
62297
|
`);
|
|
62074
62298
|
}
|
|
62075
62299
|
}
|
|
62076
62300
|
function piSettingsFile() {
|
|
62077
|
-
return
|
|
62301
|
+
return path14.join(resolvePiHome(process.env), "settings.json");
|
|
62078
62302
|
}
|
|
62079
62303
|
function isPiEntry(entry, root) {
|
|
62080
62304
|
return entry === root || /^npm:billion-context(-pi)?(@|$)/.test(entry) || /(^|[/\\])node_modules[/\\]billion-context(-pi)?([\/\\]|$)/.test(entry) || /(^|[/\\])billion-context(-pi)?$/.test(entry);
|
|
@@ -62140,14 +62364,14 @@ function ompConfigFile() {
|
|
|
62140
62364
|
`bili plugin: PI_CODING_AGENT_DIR points at the bili overlay ${raw} \u2014 operating on the real omp home ${realHome} instead
|
|
62141
62365
|
`
|
|
62142
62366
|
);
|
|
62143
|
-
return
|
|
62367
|
+
return path14.join(realHome, "config.yml");
|
|
62144
62368
|
}
|
|
62145
|
-
return
|
|
62369
|
+
return path14.join(raw, "config.yml");
|
|
62146
62370
|
}
|
|
62147
|
-
return
|
|
62371
|
+
return path14.join(os4.homedir(), ".omp", "agent", "config.yml");
|
|
62148
62372
|
}
|
|
62149
62373
|
function ompExtensionPath() {
|
|
62150
|
-
return
|
|
62374
|
+
return path14.join(selfPackageRoot(), "dist", "agent", "omp.js");
|
|
62151
62375
|
}
|
|
62152
62376
|
function ompEntryValue(line) {
|
|
62153
62377
|
return line.replace(/#.*$/, "").trim().replace(/^-\s*/, "").replace(/^["']|["']$/g, "").trim();
|
|
@@ -62156,13 +62380,13 @@ function ompBlockLoaded(text) {
|
|
|
62156
62380
|
const lines = text.split("\n");
|
|
62157
62381
|
return ompExtensionItemLines(text).some((i) => {
|
|
62158
62382
|
const v2 = ompEntryValue(lines[i]);
|
|
62159
|
-
return OMP_ENTRY_RE.test(v2) &&
|
|
62383
|
+
return OMP_ENTRY_RE.test(v2) && fs11.existsSync(v2);
|
|
62160
62384
|
});
|
|
62161
62385
|
}
|
|
62162
62386
|
function ompRemove() {
|
|
62163
62387
|
const file = ompConfigFile();
|
|
62164
|
-
if (!
|
|
62165
|
-
const text =
|
|
62388
|
+
if (!fs11.existsSync(file)) return `omp: not installed (${file})`;
|
|
62389
|
+
const text = fs11.readFileSync(file, "utf8");
|
|
62166
62390
|
const lines = text.split("\n");
|
|
62167
62391
|
const drop = new Set(
|
|
62168
62392
|
ompExtensionItemLines(text).filter((i) => OMP_ENTRY_RE.test(ompEntryValue(lines[i])))
|
|
@@ -62170,15 +62394,15 @@ function ompRemove() {
|
|
|
62170
62394
|
if (drop.size === 0) return `omp: not installed (${file})`;
|
|
62171
62395
|
const cleaned = lines.filter((_2, i) => !drop.has(i)).join("\n");
|
|
62172
62396
|
backupOnce(file);
|
|
62173
|
-
|
|
62397
|
+
fs11.writeFileSync(file, cleaned);
|
|
62174
62398
|
return `omp: removed from ${file}`;
|
|
62175
62399
|
}
|
|
62176
62400
|
function ompInstall() {
|
|
62177
62401
|
const file = ompConfigFile();
|
|
62178
62402
|
const entry = ompExtensionPath();
|
|
62179
62403
|
requireDistFile(entry);
|
|
62180
|
-
|
|
62181
|
-
let text =
|
|
62404
|
+
fs11.mkdirSync(path14.dirname(file), { recursive: true });
|
|
62405
|
+
let text = fs11.existsSync(file) ? fs11.readFileSync(file, "utf8") : "";
|
|
62182
62406
|
if (ompBlockLoaded(text)) return `omp: already installed (${file})`;
|
|
62183
62407
|
{
|
|
62184
62408
|
const lines = text.split("\n");
|
|
@@ -62220,25 +62444,25 @@ ${tail}`;
|
|
|
62220
62444
|
throw new Error(`${file}: edit would leave ${occurrences} copies of the entry \u2014 aborting without writing`);
|
|
62221
62445
|
}
|
|
62222
62446
|
backupOnce(file);
|
|
62223
|
-
|
|
62447
|
+
fs11.writeFileSync(file, out);
|
|
62224
62448
|
return `omp: installed -> ${file} extensions += ${entry}`;
|
|
62225
62449
|
}
|
|
62226
62450
|
function ompStatus() {
|
|
62227
62451
|
const file = ompConfigFile();
|
|
62228
|
-
const text =
|
|
62452
|
+
const text = fs11.existsSync(file) ? fs11.readFileSync(file, "utf8") : "";
|
|
62229
62453
|
const lines = text.split("\n");
|
|
62230
62454
|
let broken = false;
|
|
62231
62455
|
for (const i of ompExtensionItemLines(text)) {
|
|
62232
62456
|
const v2 = ompEntryValue(lines[i]);
|
|
62233
62457
|
if (!OMP_ENTRY_RE.test(v2)) continue;
|
|
62234
|
-
if (
|
|
62458
|
+
if (fs11.existsSync(v2)) return "installed";
|
|
62235
62459
|
broken = true;
|
|
62236
62460
|
}
|
|
62237
62461
|
return broken ? "broken" : "not installed";
|
|
62238
62462
|
}
|
|
62239
62463
|
function ompPluginLoadedFrom(ompHome) {
|
|
62240
62464
|
try {
|
|
62241
|
-
return ompBlockLoaded(
|
|
62465
|
+
return ompBlockLoaded(fs11.readFileSync(path14.join(ompHome, "config.yml"), "utf8"));
|
|
62242
62466
|
} catch {
|
|
62243
62467
|
return false;
|
|
62244
62468
|
}
|
|
@@ -62249,7 +62473,7 @@ function claudeMcpJson() {
|
|
|
62249
62473
|
}
|
|
62250
62474
|
function claudeInstall() {
|
|
62251
62475
|
const root = selfPackageRoot();
|
|
62252
|
-
const mcpJs =
|
|
62476
|
+
const mcpJs = path14.join(root, "dist", "mcp.js");
|
|
62253
62477
|
requireDistFile(mcpJs);
|
|
62254
62478
|
const claude = process.env.CLAUDE?.trim() || "claude";
|
|
62255
62479
|
try {
|
|
@@ -62276,38 +62500,38 @@ function claudeStatus() {
|
|
|
62276
62500
|
}
|
|
62277
62501
|
function codexToml() {
|
|
62278
62502
|
const raw = process.env.CODEX_HOME?.trim();
|
|
62279
|
-
if (raw && raw.length > 0) return
|
|
62503
|
+
if (raw && raw.length > 0) return path14.join(raw, "config.toml");
|
|
62280
62504
|
return homeFile(".codex/config.toml");
|
|
62281
62505
|
}
|
|
62282
62506
|
function codexBlock() {
|
|
62283
62507
|
return `
|
|
62284
62508
|
[mcp_servers.bili]
|
|
62285
62509
|
command = ${JSON.stringify(process.execPath)}
|
|
62286
|
-
args = [${JSON.stringify(
|
|
62510
|
+
args = [${JSON.stringify(path14.join(selfPackageRoot(), "dist", "mcp.js"))}]
|
|
62287
62511
|
env = { BILI_MCP_PROXY = ${JSON.stringify(proxyOriginForInstall())} }
|
|
62288
62512
|
`;
|
|
62289
62513
|
}
|
|
62290
62514
|
function codexInstall() {
|
|
62291
62515
|
const file = codexToml();
|
|
62292
|
-
const text =
|
|
62516
|
+
const text = fs11.existsSync(file) ? fs11.readFileSync(file, "utf8") : "";
|
|
62293
62517
|
const existing = /^[ \t]*\[mcp_servers\.bili\][ \t]*$/m.exec(text);
|
|
62294
62518
|
if (existing !== null) {
|
|
62295
62519
|
const block = text.slice(existing.index, text.indexOf("\n[", existing.index + 1) === -1 ? void 0 : text.indexOf("\n[", existing.index + 1));
|
|
62296
62520
|
if (block.includes(`BILI_MCP_PROXY = ${JSON.stringify(proxyOriginForInstall())}`)) return `codex: already installed (${file})`;
|
|
62297
62521
|
const refreshed = text.slice(0, existing.index) + codexBlock().replace(/^\n/, "") + text.slice(existing.index + block.length);
|
|
62298
62522
|
backupOnce(file);
|
|
62299
|
-
|
|
62523
|
+
fs11.writeFileSync(file, refreshed);
|
|
62300
62524
|
return `codex: refreshed proxy origin -> ${file} [mcp_servers.bili]`;
|
|
62301
62525
|
}
|
|
62302
|
-
|
|
62526
|
+
fs11.mkdirSync(path14.dirname(file), { recursive: true });
|
|
62303
62527
|
backupOnce(file);
|
|
62304
|
-
|
|
62528
|
+
fs11.writeFileSync(file, text + (text.endsWith("\n") || text.length === 0 ? "" : "\n") + codexBlock());
|
|
62305
62529
|
return `codex: installed -> ${file} [mcp_servers.bili]`;
|
|
62306
62530
|
}
|
|
62307
62531
|
function codexRemove() {
|
|
62308
62532
|
const file = codexToml();
|
|
62309
|
-
if (!
|
|
62310
|
-
const text =
|
|
62533
|
+
if (!fs11.existsSync(file)) return `codex: not installed (${file})`;
|
|
62534
|
+
const text = fs11.readFileSync(file, "utf8");
|
|
62311
62535
|
const start = (() => {
|
|
62312
62536
|
const m2 = /^[ \t]*\[mcp_servers\.bili\][ \t]*$/m.exec(text);
|
|
62313
62537
|
return m2 === null ? -1 : m2.index;
|
|
@@ -62320,23 +62544,23 @@ function codexRemove() {
|
|
|
62320
62544
|
const end = nextTable >= 0 ? start + firstNewline + 1 + nextTable : text.length;
|
|
62321
62545
|
const cleaned = (text.slice(0, lineStart).replace(/\n+$/, "\n") + text.slice(end)).replace(/^\n+/, "");
|
|
62322
62546
|
backupOnce(file);
|
|
62323
|
-
|
|
62547
|
+
fs11.writeFileSync(file, cleaned);
|
|
62324
62548
|
return `codex: removed from ${file}`;
|
|
62325
62549
|
}
|
|
62326
62550
|
function codexStatus() {
|
|
62327
|
-
const text =
|
|
62551
|
+
const text = fs11.existsSync(codexToml()) ? fs11.readFileSync(codexToml(), "utf8") : "";
|
|
62328
62552
|
return /^\[mcp_servers\.bili\]\s*$/m.test(text) ? "installed" : "not installed";
|
|
62329
62553
|
}
|
|
62330
62554
|
function opencodeJson() {
|
|
62331
62555
|
const raw = process.env.OPENCODE_CONFIG?.trim();
|
|
62332
62556
|
if (raw && raw.length > 0) return raw;
|
|
62333
62557
|
const xdg2 = process.env.XDG_CONFIG_HOME?.trim();
|
|
62334
|
-
if (xdg2 && xdg2.length > 0) return
|
|
62335
|
-
return
|
|
62558
|
+
if (xdg2 && xdg2.length > 0) return path14.join(xdg2, "opencode/opencode.json");
|
|
62559
|
+
return path14.join(os4.homedir(), ".config", "opencode", "opencode.json");
|
|
62336
62560
|
}
|
|
62337
62561
|
function opencodeInstall() {
|
|
62338
62562
|
const file = opencodeJson();
|
|
62339
|
-
const mcpJs =
|
|
62563
|
+
const mcpJs = path14.join(selfPackageRoot(), "dist", "mcp.js");
|
|
62340
62564
|
requireDistFile(mcpJs);
|
|
62341
62565
|
const data = readJson(file);
|
|
62342
62566
|
const mcp = data.mcp ?? {};
|
|
@@ -62388,14 +62612,14 @@ function pluginStatusAll() {
|
|
|
62388
62612
|
|
|
62389
62613
|
// src/launcher.ts
|
|
62390
62614
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
62391
|
-
import
|
|
62615
|
+
import fs12 from "fs";
|
|
62392
62616
|
import net2 from "net";
|
|
62393
62617
|
import os5 from "os";
|
|
62394
|
-
import
|
|
62618
|
+
import path15 from "path";
|
|
62395
62619
|
import { pathToFileURL } from "url";
|
|
62396
62620
|
import { spawn } from "child_process";
|
|
62397
62621
|
function selfDistFile(name) {
|
|
62398
|
-
return
|
|
62622
|
+
return path15.join(selfPackageRoot(), "dist", name);
|
|
62399
62623
|
}
|
|
62400
62624
|
var LAUNCHER_DEFAULT_HOST = "127.0.0.1";
|
|
62401
62625
|
var LAUNCHER_DEFAULT_PORT = 8787;
|
|
@@ -62431,12 +62655,12 @@ function unwrapUpstream2(url) {
|
|
|
62431
62655
|
return idx >= 0 ? url.slice(idx + "/bili/".length) : url;
|
|
62432
62656
|
}
|
|
62433
62657
|
function resolveCaCertPath(env) {
|
|
62434
|
-
const base = env.XDG_DATA_HOME ||
|
|
62435
|
-
return
|
|
62658
|
+
const base = env.XDG_DATA_HOME || path15.join(os5.homedir(), ".local/share");
|
|
62659
|
+
return path15.join(base, "billion-context", "ca", "root-ca.pem");
|
|
62436
62660
|
}
|
|
62437
62661
|
function resolveCombinedCaPath(env) {
|
|
62438
|
-
const base = env.XDG_DATA_HOME ||
|
|
62439
|
-
return
|
|
62662
|
+
const base = env.XDG_DATA_HOME || path15.join(os5.homedir(), ".local/share");
|
|
62663
|
+
return path15.join(base, "billion-context", "ca", "combined-ca.pem");
|
|
62440
62664
|
}
|
|
62441
62665
|
function discoverRoutes(client, config) {
|
|
62442
62666
|
const httpsDomains = [];
|
|
@@ -62669,12 +62893,12 @@ function buildCodexMcpArgs(origin, conversationId2) {
|
|
|
62669
62893
|
];
|
|
62670
62894
|
}
|
|
62671
62895
|
function overlayLockPath(overlay) {
|
|
62672
|
-
return
|
|
62896
|
+
return path15.join(overlay, ".bili-launch.pid");
|
|
62673
62897
|
}
|
|
62674
62898
|
function livePidHoldsOverlay(overlay) {
|
|
62675
62899
|
let raw;
|
|
62676
62900
|
try {
|
|
62677
|
-
raw =
|
|
62901
|
+
raw = fs12.readFileSync(overlayLockPath(overlay), "utf8");
|
|
62678
62902
|
} catch {
|
|
62679
62903
|
return void 0;
|
|
62680
62904
|
}
|
|
@@ -62688,17 +62912,17 @@ function livePidHoldsOverlay(overlay) {
|
|
|
62688
62912
|
return pid;
|
|
62689
62913
|
}
|
|
62690
62914
|
function linkOverlayEntry(realHome, overlay, entry) {
|
|
62691
|
-
const target =
|
|
62692
|
-
const link =
|
|
62915
|
+
const target = path15.join(realHome, entry);
|
|
62916
|
+
const link = path15.join(overlay, entry);
|
|
62693
62917
|
let st2;
|
|
62694
62918
|
try {
|
|
62695
|
-
st2 =
|
|
62919
|
+
st2 = fs12.lstatSync(target);
|
|
62696
62920
|
} catch {
|
|
62697
62921
|
return false;
|
|
62698
62922
|
}
|
|
62699
62923
|
const kind = st2.isDirectory() ? process.platform === "win32" ? "junction" : "dir" : "file";
|
|
62700
62924
|
try {
|
|
62701
|
-
|
|
62925
|
+
fs12.symlinkSync(target, link, kind);
|
|
62702
62926
|
return true;
|
|
62703
62927
|
} catch (err2) {
|
|
62704
62928
|
const code = err2.code;
|
|
@@ -62706,18 +62930,18 @@ function linkOverlayEntry(realHome, overlay, entry) {
|
|
|
62706
62930
|
}
|
|
62707
62931
|
if (st2.isDirectory()) {
|
|
62708
62932
|
try {
|
|
62709
|
-
|
|
62933
|
+
fs12.symlinkSync(target, link, "junction");
|
|
62710
62934
|
return true;
|
|
62711
62935
|
} catch {
|
|
62712
62936
|
return false;
|
|
62713
62937
|
}
|
|
62714
62938
|
}
|
|
62715
62939
|
try {
|
|
62716
|
-
|
|
62940
|
+
fs12.linkSync(target, link);
|
|
62717
62941
|
return true;
|
|
62718
62942
|
} catch {
|
|
62719
62943
|
try {
|
|
62720
|
-
|
|
62944
|
+
fs12.copyFileSync(target, link);
|
|
62721
62945
|
return true;
|
|
62722
62946
|
} catch {
|
|
62723
62947
|
return false;
|
|
@@ -62727,7 +62951,7 @@ function linkOverlayEntry(realHome, overlay, entry) {
|
|
|
62727
62951
|
function isWriteThroughHardlink(overlayPath, realPath, st2) {
|
|
62728
62952
|
if (st2.isDirectory() || st2.isSymbolicLink() || st2.nlink <= 1) return false;
|
|
62729
62953
|
try {
|
|
62730
|
-
const realSt =
|
|
62954
|
+
const realSt = fs12.lstatSync(realPath);
|
|
62731
62955
|
return st2.dev === realSt.dev && st2.ino === realSt.ino;
|
|
62732
62956
|
} catch {
|
|
62733
62957
|
return false;
|
|
@@ -62741,7 +62965,7 @@ function freeConflictName(dst) {
|
|
|
62741
62965
|
let n = 1;
|
|
62742
62966
|
while (n < 1e5) {
|
|
62743
62967
|
try {
|
|
62744
|
-
|
|
62968
|
+
fs12.lstatSync(candidate);
|
|
62745
62969
|
candidate = `${dst}.bili-conflict.${n}`;
|
|
62746
62970
|
n += 1;
|
|
62747
62971
|
} catch {
|
|
@@ -62754,7 +62978,7 @@ function mergeSqliteSet(overlay, realHome, base) {
|
|
|
62754
62978
|
const members = sqliteSetMembers(base);
|
|
62755
62979
|
const statFile = (dir, m2) => {
|
|
62756
62980
|
try {
|
|
62757
|
-
const st2 =
|
|
62981
|
+
const st2 = fs12.lstatSync(path15.join(dir, m2));
|
|
62758
62982
|
return st2.isFile() ? st2 : void 0;
|
|
62759
62983
|
} catch {
|
|
62760
62984
|
return void 0;
|
|
@@ -62780,35 +63004,35 @@ function mergeSqliteSet(overlay, realHome, base) {
|
|
|
62780
63004
|
const movePreserving = (src, dst) => {
|
|
62781
63005
|
let dstStat;
|
|
62782
63006
|
try {
|
|
62783
|
-
dstStat =
|
|
63007
|
+
dstStat = fs12.lstatSync(dst);
|
|
62784
63008
|
} catch {
|
|
62785
63009
|
}
|
|
62786
63010
|
if (dstStat) {
|
|
62787
63011
|
if (dstStat.isDirectory()) throw new Error("target is a directory");
|
|
62788
63012
|
const conflict = freeConflictName(dst);
|
|
62789
|
-
|
|
62790
|
-
undo.push(() =>
|
|
63013
|
+
fs12.renameSync(dst, conflict);
|
|
63014
|
+
undo.push(() => fs12.renameSync(conflict, dst));
|
|
62791
63015
|
}
|
|
62792
|
-
|
|
62793
|
-
undo.push(() =>
|
|
63016
|
+
fs12.renameSync(src, dst);
|
|
63017
|
+
undo.push(() => fs12.renameSync(dst, src));
|
|
62794
63018
|
};
|
|
62795
63019
|
const preserveAsConflict = (src, name) => {
|
|
62796
|
-
const conflict = freeConflictName(
|
|
62797
|
-
|
|
62798
|
-
undo.push(() =>
|
|
63020
|
+
const conflict = freeConflictName(path15.join(realHome, name));
|
|
63021
|
+
fs12.renameSync(src, conflict);
|
|
63022
|
+
undo.push(() => fs12.renameSync(conflict, src));
|
|
62799
63023
|
};
|
|
62800
63024
|
try {
|
|
62801
63025
|
for (const m2 of members) {
|
|
62802
63026
|
const o = statFile(overlay, m2);
|
|
62803
63027
|
const r = statFile(realHome, m2);
|
|
62804
63028
|
if (winner === "overlay") {
|
|
62805
|
-
if (o) movePreserving(
|
|
62806
|
-
else if (r) preserveAsConflict(
|
|
63029
|
+
if (o) movePreserving(path15.join(overlay, m2), path15.join(realHome, m2));
|
|
63030
|
+
else if (r) preserveAsConflict(path15.join(realHome, m2), m2);
|
|
62807
63031
|
} else if (winner === "real") {
|
|
62808
|
-
if (o) preserveAsConflict(
|
|
63032
|
+
if (o) preserveAsConflict(path15.join(overlay, m2), m2);
|
|
62809
63033
|
} else {
|
|
62810
|
-
if (o) preserveAsConflict(
|
|
62811
|
-
else if (r) preserveAsConflict(
|
|
63034
|
+
if (o) preserveAsConflict(path15.join(overlay, m2), m2);
|
|
63035
|
+
else if (r) preserveAsConflict(path15.join(realHome, m2), m2);
|
|
62812
63036
|
}
|
|
62813
63037
|
}
|
|
62814
63038
|
return true;
|
|
@@ -62821,7 +63045,7 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
62821
63045
|
const generatedFiles = new Set(Array.isArray(generatedFile) ? generatedFile : [generatedFile]);
|
|
62822
63046
|
const isGeneratedDraft = (name) => [...generatedFiles].some((g2) => name.startsWith(`.${g2}.`) && name.endsWith(".tmp"));
|
|
62823
63047
|
try {
|
|
62824
|
-
|
|
63048
|
+
fs12.mkdirSync(overlay, { recursive: true });
|
|
62825
63049
|
} catch {
|
|
62826
63050
|
return false;
|
|
62827
63051
|
}
|
|
@@ -62832,19 +63056,19 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
62832
63056
|
);
|
|
62833
63057
|
}
|
|
62834
63058
|
try {
|
|
62835
|
-
|
|
63059
|
+
fs12.writeFileSync(overlayLockPath(overlay), `${process.pid}
|
|
62836
63060
|
`);
|
|
62837
63061
|
} catch {
|
|
62838
63062
|
}
|
|
62839
63063
|
const realEntries = /* @__PURE__ */ new Set();
|
|
62840
63064
|
try {
|
|
62841
|
-
for (const entry of
|
|
63065
|
+
for (const entry of fs12.readdirSync(realHome)) realEntries.add(entry);
|
|
62842
63066
|
} catch {
|
|
62843
63067
|
}
|
|
62844
63068
|
try {
|
|
62845
63069
|
let overlayEntries;
|
|
62846
63070
|
try {
|
|
62847
|
-
overlayEntries =
|
|
63071
|
+
overlayEntries = fs12.readdirSync(overlay);
|
|
62848
63072
|
} catch {
|
|
62849
63073
|
overlayEntries = [];
|
|
62850
63074
|
}
|
|
@@ -62855,10 +63079,10 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
62855
63079
|
if (!members.some((m2) => m2 !== entry && overlayEntries.includes(m2))) continue;
|
|
62856
63080
|
let mainSt;
|
|
62857
63081
|
try {
|
|
62858
|
-
mainSt =
|
|
63082
|
+
mainSt = fs12.lstatSync(path15.join(overlay, entry));
|
|
62859
63083
|
} catch {
|
|
62860
63084
|
}
|
|
62861
|
-
const keepSidecars = mainSt !== void 0 && isWriteThroughHardlink(
|
|
63085
|
+
const keepSidecars = mainSt !== void 0 && isWriteThroughHardlink(path15.join(overlay, entry), path15.join(realHome, entry), mainSt);
|
|
62862
63086
|
dbSets.push({ base: entry, keepSidecars });
|
|
62863
63087
|
}
|
|
62864
63088
|
const skipEntries = /* @__PURE__ */ new Set();
|
|
@@ -62869,10 +63093,10 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
62869
63093
|
}
|
|
62870
63094
|
for (const entry of overlayEntries) {
|
|
62871
63095
|
if (generatedFiles.has(entry)) continue;
|
|
62872
|
-
const overlayPath =
|
|
63096
|
+
const overlayPath = path15.join(overlay, entry);
|
|
62873
63097
|
if (isGeneratedDraft(entry)) {
|
|
62874
63098
|
try {
|
|
62875
|
-
|
|
63099
|
+
fs12.unlinkSync(overlayPath);
|
|
62876
63100
|
} catch {
|
|
62877
63101
|
}
|
|
62878
63102
|
continue;
|
|
@@ -62880,33 +63104,33 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
62880
63104
|
if (skipEntries.has(entry)) continue;
|
|
62881
63105
|
let st2;
|
|
62882
63106
|
try {
|
|
62883
|
-
st2 =
|
|
63107
|
+
st2 = fs12.lstatSync(overlayPath);
|
|
62884
63108
|
} catch {
|
|
62885
63109
|
continue;
|
|
62886
63110
|
}
|
|
62887
63111
|
if (st2.isSymbolicLink()) {
|
|
62888
63112
|
let target;
|
|
62889
63113
|
try {
|
|
62890
|
-
target =
|
|
63114
|
+
target = fs12.readlinkSync(overlayPath);
|
|
62891
63115
|
} catch {
|
|
62892
63116
|
}
|
|
62893
|
-
const wanted = realEntries.has(entry) ?
|
|
63117
|
+
const wanted = realEntries.has(entry) ? path15.join(realHome, entry) : void 0;
|
|
62894
63118
|
if (!wanted || target !== wanted) {
|
|
62895
63119
|
try {
|
|
62896
|
-
|
|
63120
|
+
fs12.unlinkSync(overlayPath);
|
|
62897
63121
|
} catch {
|
|
62898
63122
|
}
|
|
62899
63123
|
}
|
|
62900
63124
|
} else if (realEntries.has(entry)) {
|
|
62901
|
-
const realPath =
|
|
63125
|
+
const realPath = path15.join(realHome, entry);
|
|
62902
63126
|
if (isWriteThroughHardlink(overlayPath, realPath, st2)) {
|
|
62903
63127
|
try {
|
|
62904
|
-
|
|
63128
|
+
fs12.unlinkSync(overlayPath);
|
|
62905
63129
|
} catch {
|
|
62906
63130
|
}
|
|
62907
63131
|
} else if (mergeOverlayEntry(overlayPath, realPath, generatedFiles)) {
|
|
62908
63132
|
try {
|
|
62909
|
-
|
|
63133
|
+
fs12.rmSync(overlayPath, { recursive: true, force: true });
|
|
62910
63134
|
} catch {
|
|
62911
63135
|
}
|
|
62912
63136
|
} else {
|
|
@@ -62928,10 +63152,10 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
62928
63152
|
for (const entry of realEntries) {
|
|
62929
63153
|
if (generatedFiles.has(entry)) continue;
|
|
62930
63154
|
total += 1;
|
|
62931
|
-
const overlayPath =
|
|
63155
|
+
const overlayPath = path15.join(overlay, entry);
|
|
62932
63156
|
let present = false;
|
|
62933
63157
|
try {
|
|
62934
|
-
|
|
63158
|
+
fs12.lstatSync(overlayPath);
|
|
62935
63159
|
present = true;
|
|
62936
63160
|
} catch {
|
|
62937
63161
|
}
|
|
@@ -62963,45 +63187,45 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
62963
63187
|
function mergeOverlayEntry(src, dst, excludedNames) {
|
|
62964
63188
|
let st2;
|
|
62965
63189
|
try {
|
|
62966
|
-
st2 =
|
|
63190
|
+
st2 = fs12.lstatSync(src);
|
|
62967
63191
|
} catch {
|
|
62968
63192
|
return true;
|
|
62969
63193
|
}
|
|
62970
63194
|
let dstStat;
|
|
62971
63195
|
try {
|
|
62972
|
-
dstStat =
|
|
63196
|
+
dstStat = fs12.lstatSync(dst);
|
|
62973
63197
|
} catch {
|
|
62974
63198
|
}
|
|
62975
63199
|
if (st2.isDirectory()) {
|
|
62976
63200
|
if (dstStat && !dstStat.isDirectory()) {
|
|
62977
63201
|
try {
|
|
62978
|
-
|
|
63202
|
+
fs12.renameSync(dst, freeConflictName(dst));
|
|
62979
63203
|
dstStat = void 0;
|
|
62980
63204
|
} catch {
|
|
62981
63205
|
return false;
|
|
62982
63206
|
}
|
|
62983
63207
|
}
|
|
62984
63208
|
try {
|
|
62985
|
-
|
|
63209
|
+
fs12.mkdirSync(dst, { recursive: true });
|
|
62986
63210
|
} catch {
|
|
62987
63211
|
return false;
|
|
62988
63212
|
}
|
|
62989
63213
|
let entries;
|
|
62990
63214
|
try {
|
|
62991
|
-
entries =
|
|
63215
|
+
entries = fs12.readdirSync(src);
|
|
62992
63216
|
} catch {
|
|
62993
63217
|
return false;
|
|
62994
63218
|
}
|
|
62995
63219
|
let ok = true;
|
|
62996
63220
|
for (const entry of entries) {
|
|
62997
63221
|
if (excludedNames?.has(entry)) continue;
|
|
62998
|
-
if (!mergeOverlayEntry(
|
|
63222
|
+
if (!mergeOverlayEntry(path15.join(src, entry), path15.join(dst, entry), excludedNames)) ok = false;
|
|
62999
63223
|
}
|
|
63000
63224
|
return ok;
|
|
63001
63225
|
}
|
|
63002
63226
|
if (dstStat && dstStat.isDirectory()) {
|
|
63003
63227
|
try {
|
|
63004
|
-
|
|
63228
|
+
fs12.renameSync(src, freeConflictName(dst));
|
|
63005
63229
|
return true;
|
|
63006
63230
|
} catch {
|
|
63007
63231
|
return false;
|
|
@@ -63010,13 +63234,13 @@ function mergeOverlayEntry(src, dst, excludedNames) {
|
|
|
63010
63234
|
if (st2.isSymbolicLink()) {
|
|
63011
63235
|
if (dstStat) {
|
|
63012
63236
|
try {
|
|
63013
|
-
|
|
63237
|
+
fs12.unlinkSync(src);
|
|
63014
63238
|
} catch {
|
|
63015
63239
|
}
|
|
63016
63240
|
return true;
|
|
63017
63241
|
}
|
|
63018
63242
|
try {
|
|
63019
|
-
|
|
63243
|
+
fs12.renameSync(src, dst);
|
|
63020
63244
|
} catch {
|
|
63021
63245
|
return false;
|
|
63022
63246
|
}
|
|
@@ -63024,7 +63248,7 @@ function mergeOverlayEntry(src, dst, excludedNames) {
|
|
|
63024
63248
|
}
|
|
63025
63249
|
if (dstStat && dstStat.mtimeMs >= st2.mtimeMs) {
|
|
63026
63250
|
try {
|
|
63027
|
-
|
|
63251
|
+
fs12.renameSync(src, freeConflictName(dst));
|
|
63028
63252
|
return true;
|
|
63029
63253
|
} catch {
|
|
63030
63254
|
return false;
|
|
@@ -63032,13 +63256,13 @@ function mergeOverlayEntry(src, dst, excludedNames) {
|
|
|
63032
63256
|
}
|
|
63033
63257
|
if (dstStat) {
|
|
63034
63258
|
try {
|
|
63035
|
-
|
|
63259
|
+
fs12.renameSync(dst, freeConflictName(dst));
|
|
63036
63260
|
} catch {
|
|
63037
63261
|
return false;
|
|
63038
63262
|
}
|
|
63039
63263
|
}
|
|
63040
63264
|
try {
|
|
63041
|
-
|
|
63265
|
+
fs12.renameSync(src, dst);
|
|
63042
63266
|
return true;
|
|
63043
63267
|
} catch {
|
|
63044
63268
|
return false;
|
|
@@ -63048,7 +63272,7 @@ function piPluginInstalled(piHome) {
|
|
|
63048
63272
|
const root = selfPackageRoot();
|
|
63049
63273
|
if (!root) return false;
|
|
63050
63274
|
try {
|
|
63051
|
-
const parsed = JSON.parse(
|
|
63275
|
+
const parsed = JSON.parse(fs12.readFileSync(path15.join(piHome, "settings.json"), "utf8"));
|
|
63052
63276
|
const list = Array.isArray(parsed.packages) ? parsed.packages.map(String) : [];
|
|
63053
63277
|
return list.some((p2) => isBiliPiEntry(p2, root));
|
|
63054
63278
|
} catch {
|
|
@@ -63056,13 +63280,13 @@ function piPluginInstalled(piHome) {
|
|
|
63056
63280
|
}
|
|
63057
63281
|
}
|
|
63058
63282
|
function writeOverlayFileAtomic(overlay, fileName, contents) {
|
|
63059
|
-
const draft =
|
|
63283
|
+
const draft = path15.join(overlay, `.${fileName}.${process.pid}.tmp`);
|
|
63060
63284
|
try {
|
|
63061
|
-
|
|
63062
|
-
|
|
63285
|
+
fs12.writeFileSync(draft, contents);
|
|
63286
|
+
fs12.renameSync(draft, path15.join(overlay, fileName));
|
|
63063
63287
|
} catch {
|
|
63064
63288
|
try {
|
|
63065
|
-
|
|
63289
|
+
fs12.rmSync(draft, { force: true });
|
|
63066
63290
|
} catch {
|
|
63067
63291
|
}
|
|
63068
63292
|
}
|
|
@@ -63070,7 +63294,7 @@ function writeOverlayFileAtomic(overlay, fileName, contents) {
|
|
|
63070
63294
|
function writePiCompactionDisabledSettings(piHome, overlay) {
|
|
63071
63295
|
let settings = {};
|
|
63072
63296
|
try {
|
|
63073
|
-
const parsed = JSON.parse(
|
|
63297
|
+
const parsed = JSON.parse(fs12.readFileSync(path15.join(piHome, "settings.json"), "utf8"));
|
|
63074
63298
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
63075
63299
|
settings = parsed;
|
|
63076
63300
|
}
|
|
@@ -63083,12 +63307,12 @@ function writePiCompactionDisabledSettings(piHome, overlay) {
|
|
|
63083
63307
|
writeOverlayFileAtomic(overlay, "settings.json", JSON.stringify(settings, null, 2));
|
|
63084
63308
|
}
|
|
63085
63309
|
function preparePiHttpRewrite(piHome, origin, httpRewrites, httpsRewrites) {
|
|
63086
|
-
if (!
|
|
63310
|
+
if (!fs12.existsSync(piHome)) return void 0;
|
|
63087
63311
|
const overlay = `${piHome}-bili`;
|
|
63088
63312
|
const generated = ["settings.json"];
|
|
63089
63313
|
let modelsRoot;
|
|
63090
63314
|
try {
|
|
63091
|
-
const parsed = JSON.parse(
|
|
63315
|
+
const parsed = JSON.parse(fs12.readFileSync(path15.join(piHome, "models.json"), "utf8"));
|
|
63092
63316
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
63093
63317
|
modelsRoot = parsed;
|
|
63094
63318
|
generated.push("models.json");
|
|
@@ -63124,11 +63348,11 @@ function preparePiHttpRewrite(piHome, origin, httpRewrites, httpsRewrites) {
|
|
|
63124
63348
|
function atomicWriteTextFile(filePath, contents) {
|
|
63125
63349
|
const draft = `${filePath}.${process.pid}.bili-tmp`;
|
|
63126
63350
|
try {
|
|
63127
|
-
|
|
63128
|
-
|
|
63351
|
+
fs12.writeFileSync(draft, contents);
|
|
63352
|
+
fs12.renameSync(draft, filePath);
|
|
63129
63353
|
} catch {
|
|
63130
63354
|
try {
|
|
63131
|
-
|
|
63355
|
+
fs12.rmSync(draft, { force: true });
|
|
63132
63356
|
} catch {
|
|
63133
63357
|
}
|
|
63134
63358
|
throw new Error(`bili: could not write ${filePath}`);
|
|
@@ -63150,7 +63374,7 @@ function liveProxyPorts() {
|
|
|
63150
63374
|
function unpackDeadProxyUrlsInFile(filePath, livePorts) {
|
|
63151
63375
|
let txt;
|
|
63152
63376
|
try {
|
|
63153
|
-
txt =
|
|
63377
|
+
txt = fs12.readFileSync(filePath, "utf8");
|
|
63154
63378
|
} catch {
|
|
63155
63379
|
return 0;
|
|
63156
63380
|
}
|
|
@@ -63221,14 +63445,14 @@ function writeOmpCompactionDisabledConfig(ompHome, overlay) {
|
|
|
63221
63445
|
let baseIsJson = false;
|
|
63222
63446
|
for (const name of ["config.yml", "config.yaml"]) {
|
|
63223
63447
|
try {
|
|
63224
|
-
base =
|
|
63448
|
+
base = fs12.readFileSync(path15.join(ompHome, name), "utf8");
|
|
63225
63449
|
break;
|
|
63226
63450
|
} catch {
|
|
63227
63451
|
}
|
|
63228
63452
|
}
|
|
63229
63453
|
if (base === void 0) {
|
|
63230
63454
|
try {
|
|
63231
|
-
base =
|
|
63455
|
+
base = fs12.readFileSync(path15.join(ompHome, "settings.json"), "utf8");
|
|
63232
63456
|
baseIsJson = true;
|
|
63233
63457
|
} catch {
|
|
63234
63458
|
}
|
|
@@ -63256,17 +63480,17 @@ function writeOmpCompactionDisabledConfig(ompHome, overlay) {
|
|
|
63256
63480
|
writeOverlayFileAtomic(overlay, "config.yml", merged);
|
|
63257
63481
|
}
|
|
63258
63482
|
function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
|
|
63259
|
-
if (!
|
|
63483
|
+
if (!fs12.existsSync(ompHome)) return void 0;
|
|
63260
63484
|
const overlay = `${ompHome}-bili`;
|
|
63261
63485
|
const generated = ["config.yml"];
|
|
63262
|
-
const modelsPath =
|
|
63486
|
+
const modelsPath = path15.join(ompHome, "models.yml");
|
|
63263
63487
|
const unpacked = unpackDeadProxyUrlsInFile(modelsPath, liveProxyPorts());
|
|
63264
63488
|
if (unpacked > 0) {
|
|
63265
63489
|
console.error(`bili: unpacked ${unpacked} dead proxy URL(s) from the real ${modelsPath}`);
|
|
63266
63490
|
}
|
|
63267
63491
|
let modelsText;
|
|
63268
63492
|
try {
|
|
63269
|
-
modelsText =
|
|
63493
|
+
modelsText = fs12.readFileSync(modelsPath, "utf8");
|
|
63270
63494
|
generated.push("models.yml");
|
|
63271
63495
|
} catch {
|
|
63272
63496
|
}
|
|
@@ -63312,10 +63536,10 @@ function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
|
|
|
63312
63536
|
}
|
|
63313
63537
|
function prepareHermesHome(hermesHome, origin, rewrites) {
|
|
63314
63538
|
if (rewrites.length === 0) return void 0;
|
|
63315
|
-
const cfgPath =
|
|
63539
|
+
const cfgPath = path15.join(hermesHome, "config.yaml");
|
|
63316
63540
|
let txt;
|
|
63317
63541
|
try {
|
|
63318
|
-
txt =
|
|
63542
|
+
txt = fs12.readFileSync(cfgPath, "utf8");
|
|
63319
63543
|
} catch {
|
|
63320
63544
|
return void 0;
|
|
63321
63545
|
}
|
|
@@ -63342,21 +63566,21 @@ function prepareHermesHome(hermesHome, origin, rewrites) {
|
|
|
63342
63566
|
}
|
|
63343
63567
|
function writeHermesIdentityPlugin(hermesHome, overlay, rewrites) {
|
|
63344
63568
|
try {
|
|
63345
|
-
if (
|
|
63569
|
+
if (fs12.existsSync(path15.join(hermesHome, "plugins"))) return false;
|
|
63346
63570
|
} catch {
|
|
63347
63571
|
return false;
|
|
63348
63572
|
}
|
|
63349
|
-
const dir =
|
|
63573
|
+
const dir = path15.join("plugins", "model-providers", "bili-session-identity");
|
|
63350
63574
|
try {
|
|
63351
|
-
|
|
63575
|
+
fs12.mkdirSync(path15.join(overlay, dir), { recursive: true });
|
|
63352
63576
|
} catch {
|
|
63353
63577
|
return false;
|
|
63354
63578
|
}
|
|
63355
63579
|
const keys = rewrites.map((r) => r.key);
|
|
63356
|
-
const pluginDir =
|
|
63580
|
+
const pluginDir = path15.join(overlay, dir);
|
|
63357
63581
|
try {
|
|
63358
|
-
|
|
63359
|
-
|
|
63582
|
+
fs12.writeFileSync(path15.join(pluginDir, "__init__.py"), hermesIdentityPluginSource(keys));
|
|
63583
|
+
fs12.writeFileSync(path15.join(pluginDir, "plugin.yaml"), [
|
|
63360
63584
|
"name: bili-session-identity",
|
|
63361
63585
|
"kind: model-provider",
|
|
63362
63586
|
"version: 1.0.0",
|
|
@@ -63368,7 +63592,7 @@ function writeHermesIdentityPlugin(hermesHome, overlay, rewrites) {
|
|
|
63368
63592
|
return false;
|
|
63369
63593
|
}
|
|
63370
63594
|
try {
|
|
63371
|
-
return
|
|
63595
|
+
return fs12.existsSync(path15.join(overlay, dir, "__init__.py"));
|
|
63372
63596
|
} catch {
|
|
63373
63597
|
return false;
|
|
63374
63598
|
}
|
|
@@ -63425,10 +63649,10 @@ function hermesIdentityPluginSource(providerKeys) {
|
|
|
63425
63649
|
].join("\n");
|
|
63426
63650
|
}
|
|
63427
63651
|
function prepareDshHome(dshHome, origin, rewrites) {
|
|
63428
|
-
const cfgPath =
|
|
63652
|
+
const cfgPath = path15.join(dshHome, "settings.yaml");
|
|
63429
63653
|
let txt;
|
|
63430
63654
|
try {
|
|
63431
|
-
txt =
|
|
63655
|
+
txt = fs12.readFileSync(cfgPath, "utf8");
|
|
63432
63656
|
} catch {
|
|
63433
63657
|
return void 0;
|
|
63434
63658
|
}
|
|
@@ -63456,16 +63680,16 @@ function writeDshAcpPatch(dshHome) {
|
|
|
63456
63680
|
const pluginUrl = pathToFileURL(selfDistFile("agent/dsh-acp.js")).href;
|
|
63457
63681
|
const dir = `${dshHome}-bili`;
|
|
63458
63682
|
try {
|
|
63459
|
-
|
|
63683
|
+
fs12.mkdirSync(dir, { recursive: true });
|
|
63460
63684
|
} catch {
|
|
63461
63685
|
return void 0;
|
|
63462
63686
|
}
|
|
63463
63687
|
writeOverlayFileAtomic(dir, ".bili-acp.patch.yml", `- insert:
|
|
63464
63688
|
- name: ${pluginUrl}
|
|
63465
63689
|
`);
|
|
63466
|
-
const file =
|
|
63690
|
+
const file = path15.join(dir, ".bili-acp.patch.yml");
|
|
63467
63691
|
try {
|
|
63468
|
-
return
|
|
63692
|
+
return fs12.existsSync(file) ? file : void 0;
|
|
63469
63693
|
} catch {
|
|
63470
63694
|
return void 0;
|
|
63471
63695
|
}
|
|
@@ -63480,7 +63704,7 @@ function prepareOpencodeHttpRewrite(configFile2, origin, httpRewrites, httpsRewr
|
|
|
63480
63704
|
if (httpRewrites.length === 0 && httpsRewrites.length === 0 && !pluginPath) return void 0;
|
|
63481
63705
|
let root = {};
|
|
63482
63706
|
try {
|
|
63483
|
-
const txt =
|
|
63707
|
+
const txt = fs12.readFileSync(configFile2, "utf8");
|
|
63484
63708
|
const parsed = JSON.parse(txt);
|
|
63485
63709
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
63486
63710
|
root = { ...parsed };
|
|
@@ -63508,9 +63732,9 @@ function prepareOpencodeHttpRewrite(configFile2, origin, httpRewrites, httpsRewr
|
|
|
63508
63732
|
if (!plugins.includes(pluginPath)) plugins.push(pluginPath);
|
|
63509
63733
|
root.plugin = plugins;
|
|
63510
63734
|
}
|
|
63511
|
-
const tmp =
|
|
63512
|
-
const tmpFile =
|
|
63513
|
-
|
|
63735
|
+
const tmp = fs12.mkdtempSync(path15.join(os5.tmpdir(), "bili-opencode-"));
|
|
63736
|
+
const tmpFile = path15.join(tmp, "opencode.json");
|
|
63737
|
+
fs12.writeFileSync(tmpFile, JSON.stringify(root));
|
|
63514
63738
|
return tmpFile;
|
|
63515
63739
|
}
|
|
63516
63740
|
function dedupeInOrder(list) {
|
|
@@ -63600,8 +63824,8 @@ async function ensureProxyRunning(opts, deps = {}) {
|
|
|
63600
63824
|
const port = opts.port;
|
|
63601
63825
|
const script = process.argv[1];
|
|
63602
63826
|
if (!script) throw new Error("bili: cannot resolve launcher script path");
|
|
63603
|
-
const logPath2 =
|
|
63604
|
-
const logFd =
|
|
63827
|
+
const logPath2 = path15.join(os5.tmpdir(), `bili-proxy-${port}.log`);
|
|
63828
|
+
const logFd = fs12.openSync(logPath2, "a");
|
|
63605
63829
|
let child;
|
|
63606
63830
|
try {
|
|
63607
63831
|
child = spawnImpl(
|
|
@@ -63621,7 +63845,7 @@ async function ensureProxyRunning(opts, deps = {}) {
|
|
|
63621
63845
|
);
|
|
63622
63846
|
} finally {
|
|
63623
63847
|
try {
|
|
63624
|
-
|
|
63848
|
+
fs12.closeSync(logFd);
|
|
63625
63849
|
} catch {
|
|
63626
63850
|
}
|
|
63627
63851
|
}
|
|
@@ -63680,12 +63904,12 @@ var PATH_EXTS = process.platform === "win32" ? [".cmd", ".bat", ".exe", ""] : ["
|
|
|
63680
63904
|
function resolveOnPath(name, env) {
|
|
63681
63905
|
const p2 = env.PATH;
|
|
63682
63906
|
if (!p2) return void 0;
|
|
63683
|
-
for (const dir of p2.split(
|
|
63907
|
+
for (const dir of p2.split(path15.delimiter)) {
|
|
63684
63908
|
if (!dir) continue;
|
|
63685
63909
|
for (const ext of PATH_EXTS) {
|
|
63686
|
-
const f2 =
|
|
63910
|
+
const f2 = path15.join(dir, name + ext);
|
|
63687
63911
|
try {
|
|
63688
|
-
if (
|
|
63912
|
+
if (fs12.existsSync(f2) && fs12.statSync(f2).isFile()) return f2;
|
|
63689
63913
|
} catch {
|
|
63690
63914
|
}
|
|
63691
63915
|
}
|
|
@@ -63703,7 +63927,7 @@ function resolveClientCommand(client, env) {
|
|
|
63703
63927
|
if (piBin) return { command: piBin, prefixArgs: [] };
|
|
63704
63928
|
const piResolved = resolveOnPath("pi", env);
|
|
63705
63929
|
if (piResolved) return { command: piResolved, prefixArgs: [] };
|
|
63706
|
-
const cli =
|
|
63930
|
+
const cli = path15.join(
|
|
63707
63931
|
os5.homedir(),
|
|
63708
63932
|
".pi/agent/npm/node_modules/@earendil-works/pi-coding-agent/dist/cli.js"
|
|
63709
63933
|
);
|
|
@@ -63775,7 +63999,7 @@ async function runLaunch(params, deps = {}) {
|
|
|
63775
63999
|
piOverlayHome = preparePiHttpRewrite(resolvePiHome(process.env), origin, routes.httpRewrites, routes.httpsRewrites);
|
|
63776
64000
|
if (piOverlayHome) env.PI_CODING_AGENT_DIR = piOverlayHome;
|
|
63777
64001
|
const piExt = selfDistFile("agent/pi.js");
|
|
63778
|
-
if (piExt &&
|
|
64002
|
+
if (piExt && fs12.existsSync(piExt) && !piPluginInstalled(resolvePiHome(process.env))) {
|
|
63779
64003
|
clientArgs = ["-e", piExt, ...clientArgs];
|
|
63780
64004
|
}
|
|
63781
64005
|
} else if (base === "omp") {
|
|
@@ -63783,13 +64007,13 @@ async function runLaunch(params, deps = {}) {
|
|
|
63783
64007
|
ompOverlayHome = prepareOmpHttpRewrite(resolveOmpHome(process.env), origin, routes.httpRewrites, routes.httpsRewrites);
|
|
63784
64008
|
if (ompOverlayHome) env.PI_CODING_AGENT_DIR = ompOverlayHome;
|
|
63785
64009
|
const ompExt = selfDistFile("agent/omp.js");
|
|
63786
|
-
if (ompExt &&
|
|
64010
|
+
if (ompExt && fs12.existsSync(ompExt) && !ompPluginLoadedFrom(resolveOmpHome(process.env))) {
|
|
63787
64011
|
clientArgs = ["-e", ompExt, ...clientArgs];
|
|
63788
64012
|
}
|
|
63789
64013
|
} else if (base === "opencode") {
|
|
63790
64014
|
env = { ...process.env, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: ca, BILLION_CONTEXT_PROXY: origin };
|
|
63791
64015
|
const opencodePlugin = selfDistFile("agent/opencode.js");
|
|
63792
|
-
const opencodePluginPath = opencodePlugin &&
|
|
64016
|
+
const opencodePluginPath = opencodePlugin && fs12.existsSync(opencodePlugin) ? opencodePlugin : void 0;
|
|
63793
64017
|
opencodeTmpFile = prepareOpencodeHttpRewrite(resolveOpencodeConfigFile(process.env), origin, routes.httpRewrites, routes.httpsRewrites, opencodePluginPath);
|
|
63794
64018
|
if (opencodeTmpFile) env.OPENCODE_CONFIG = opencodeTmpFile;
|
|
63795
64019
|
} else if (base === "hermes") {
|
|
@@ -63862,8 +64086,8 @@ async function runLaunch(params, deps = {}) {
|
|
|
63862
64086
|
console.error(`bili: claude budget aligned \u2014 CLAUDE_CODE_AUTO_COMPACT_WINDOW=${claudeBudget.CLAUDE_CODE_AUTO_COMPACT_WINDOW}`);
|
|
63863
64087
|
}
|
|
63864
64088
|
if (injectMcp) {
|
|
63865
|
-
const mcpFile =
|
|
63866
|
-
|
|
64089
|
+
const mcpFile = path15.join(os5.tmpdir(), `bili-mcp-${Date.now()}.json`);
|
|
64090
|
+
fs12.writeFileSync(mcpFile, JSON.stringify(buildMcpConfig(origin)));
|
|
63867
64091
|
tmpFiles.push(mcpFile);
|
|
63868
64092
|
clientArgs = ["--mcp-config", mcpFile, ...clientArgs];
|
|
63869
64093
|
}
|
|
@@ -63882,13 +64106,13 @@ async function runLaunch(params, deps = {}) {
|
|
|
63882
64106
|
stopProxy(handle2);
|
|
63883
64107
|
if (opencodeTmpFile) {
|
|
63884
64108
|
try {
|
|
63885
|
-
|
|
64109
|
+
fs12.rmSync(path15.dirname(opencodeTmpFile), { recursive: true, force: true });
|
|
63886
64110
|
} catch {
|
|
63887
64111
|
}
|
|
63888
64112
|
}
|
|
63889
64113
|
for (const f2 of tmpFiles) {
|
|
63890
64114
|
try {
|
|
63891
|
-
|
|
64115
|
+
fs12.rmSync(f2, { force: true });
|
|
63892
64116
|
} catch {
|
|
63893
64117
|
}
|
|
63894
64118
|
}
|
|
@@ -63914,8 +64138,8 @@ async function runTestPi(params, deps = {}) {
|
|
|
63914
64138
|
}
|
|
63915
64139
|
const ca = resolveCaCertPath(process.env);
|
|
63916
64140
|
const env = buildPiEnv(handle2.origin, ca, process.env);
|
|
63917
|
-
const sessionDir =
|
|
63918
|
-
|
|
64141
|
+
const sessionDir = path15.join(os5.tmpdir(), `bili-pi-test-${Date.now()}`);
|
|
64142
|
+
fs12.mkdirSync(sessionDir, { recursive: true });
|
|
63919
64143
|
const args = [
|
|
63920
64144
|
"-p",
|
|
63921
64145
|
"--no-session",
|
|
@@ -63943,7 +64167,7 @@ async function runTestPi(params, deps = {}) {
|
|
|
63943
64167
|
|
|
63944
64168
|
// src/export.ts
|
|
63945
64169
|
import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "fs";
|
|
63946
|
-
import
|
|
64170
|
+
import path16 from "path";
|
|
63947
64171
|
function fmtDate(ms2) {
|
|
63948
64172
|
return ms2 ? new Date(ms2).toISOString().replace("T", " ").slice(0, 19) + " UTC" : "\u2014";
|
|
63949
64173
|
}
|
|
@@ -64075,7 +64299,7 @@ async function exportSession(selector, opts = {}) {
|
|
|
64075
64299
|
}
|
|
64076
64300
|
const markdown = renderHandoff(matches[0], opts.full ?? false);
|
|
64077
64301
|
if (opts.output) {
|
|
64078
|
-
mkdirSync5(
|
|
64302
|
+
mkdirSync5(path16.dirname(path16.resolve(opts.output)), { recursive: true });
|
|
64079
64303
|
writeFileSync4(opts.output, markdown, "utf8");
|
|
64080
64304
|
return `written to ${opts.output}`;
|
|
64081
64305
|
}
|
|
@@ -64085,11 +64309,11 @@ async function exportSession(selector, opts = {}) {
|
|
|
64085
64309
|
// src/cli.ts
|
|
64086
64310
|
import { readFileSync as readFileSync4 } from "fs";
|
|
64087
64311
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
64088
|
-
import
|
|
64312
|
+
import path17 from "path";
|
|
64089
64313
|
var VERSION3 = (() => {
|
|
64090
64314
|
try {
|
|
64091
64315
|
const here = fileURLToPath6(import.meta.url);
|
|
64092
|
-
const pkg =
|
|
64316
|
+
const pkg = path17.join(path17.dirname(here), "..", "package.json");
|
|
64093
64317
|
return JSON.parse(readFileSync4(pkg, "utf8")).version ?? "dev";
|
|
64094
64318
|
} catch {
|
|
64095
64319
|
return "dev";
|
|
@@ -64098,7 +64322,7 @@ var VERSION3 = (() => {
|
|
|
64098
64322
|
var PACKAGE_NAME = (() => {
|
|
64099
64323
|
try {
|
|
64100
64324
|
const here = fileURLToPath6(import.meta.url);
|
|
64101
|
-
const pkg =
|
|
64325
|
+
const pkg = path17.join(path17.dirname(here), "..", "package.json");
|
|
64102
64326
|
return JSON.parse(readFileSync4(pkg, "utf8")).name ?? "billion-context";
|
|
64103
64327
|
} catch {
|
|
64104
64328
|
return "billion-context";
|