billion-context 0.1.78-pr.504.326 → 0.1.78
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 +387 -611
- 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 timer2 = fastTimers[idx];
|
|
136
|
+
if (timer2._state === PENDING) {
|
|
137
|
+
timer2._idleStart = fastNow - TICK_MS;
|
|
138
|
+
timer2._state = ACTIVE;
|
|
139
|
+
} else if (timer2._state === ACTIVE && fastNow >= timer2._idleStart + timer2._idleTimeout) {
|
|
140
|
+
timer2._state = TO_BE_CLEARED;
|
|
141
|
+
timer2._idleStart = -1;
|
|
142
|
+
timer2._onTimeout(timer2._timerArg);
|
|
143
|
+
}
|
|
144
|
+
if (timer2._state === TO_BE_CLEARED) {
|
|
145
|
+
timer2._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 path17 = 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 (path17 && path17[0] !== "/") {
|
|
1149
|
+
path17 = `/${path17}`;
|
|
1150
1150
|
}
|
|
1151
|
-
return new URL(`${origin}${
|
|
1151
|
+
return new URL(`${origin}${path17}`);
|
|
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: path17, origin }
|
|
1973
1973
|
} = evt;
|
|
1974
|
-
debugLog("sending request to %s %s%s", method, origin,
|
|
1974
|
+
debugLog("sending request to %s %s%s", method, origin, path17);
|
|
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: path17, 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
|
+
path17,
|
|
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: path17, origin }
|
|
2009
2009
|
} = evt;
|
|
2010
|
-
debugLog("trailers received from %s %s%s", method, origin,
|
|
2010
|
+
debugLog("trailers received from %s %s%s", method, origin, path17);
|
|
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: path17, 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
|
+
path17,
|
|
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: path17,
|
|
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 path17 !== "string") {
|
|
2157
2157
|
throw new InvalidArgumentError("path must be a string");
|
|
2158
|
-
} else if (
|
|
2158
|
+
} else if (path17[0] !== "/" && !(path17.startsWith("http://") || path17.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(path17)) {
|
|
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(path17, query) : path17;
|
|
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: path17, 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} ${path17} 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: path17, 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] = path17;
|
|
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] = path17;
|
|
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: path17 = "/",
|
|
10602
10602
|
headers = {}
|
|
10603
10603
|
} = opts;
|
|
10604
|
-
opts.path = origin +
|
|
10604
|
+
opts.path = origin + path17;
|
|
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(path17) {
|
|
12688
|
+
if (typeof path17 !== "string") {
|
|
12689
|
+
return path17;
|
|
12690
12690
|
}
|
|
12691
|
-
const pathSegments =
|
|
12691
|
+
const pathSegments = path17.split("?", 3);
|
|
12692
12692
|
if (pathSegments.length !== 2) {
|
|
12693
|
-
return
|
|
12693
|
+
return path17;
|
|
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: path17, method, body, headers }) {
|
|
12700
|
+
const pathMatch = matchValue(mockDispatch2.path, path17);
|
|
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: path17, ignoreTrailingSlash }) => {
|
|
12726
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path17)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path17), 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(path17) {
|
|
12766
|
+
while (path17.endsWith("/")) {
|
|
12767
|
+
path17 = path17.slice(0, -1);
|
|
12768
12768
|
}
|
|
12769
|
-
if (
|
|
12770
|
-
|
|
12769
|
+
if (path17.length === 0) {
|
|
12770
|
+
path17 = "/";
|
|
12771
12771
|
}
|
|
12772
|
-
return
|
|
12772
|
+
return path17;
|
|
12773
12773
|
}
|
|
12774
12774
|
function buildKey(opts) {
|
|
12775
|
-
const { path:
|
|
12775
|
+
const { path: path17, method, body, headers, query } = opts;
|
|
12776
12776
|
return {
|
|
12777
|
-
path:
|
|
12777
|
+
path: path17,
|
|
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 timer2 = 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 (timer2 !== null) {
|
|
12835
|
+
clearTimeout(timer2);
|
|
12836
|
+
timer2 = 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
|
+
timer2 = setTimeout(() => {
|
|
12843
|
+
timer2 = 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: path17, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
13468
13468
|
Method: method,
|
|
13469
13469
|
Origin: origin,
|
|
13470
|
-
Path:
|
|
13470
|
+
Path: path17,
|
|
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 [path17, searchParams] = dispatchOpts.path.split("?");
|
|
13553
13553
|
const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
|
|
13554
|
-
dispatchOpts.path = `${
|
|
13554
|
+
dispatchOpts.path = `${path17}?${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 path17 = filePath || this.#snapshotPath;
|
|
13956
|
+
if (!path17) {
|
|
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(path17), "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 ${path17}`, { 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 path17 = filePath || this.#snapshotPath;
|
|
13986
|
+
if (!path17) {
|
|
13987
13987
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
13988
13988
|
}
|
|
13989
|
-
const resolvedPath = resolve(
|
|
13989
|
+
const resolvedPath = resolve(path17);
|
|
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 path17 = search ? `${pathname}${search}` : pathname;
|
|
14622
|
+
const redirectUrlString = `${origin}${path17}`;
|
|
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 = path17;
|
|
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, path17) {
|
|
16399
16399
|
deleteCachedValue(store, {
|
|
16400
16400
|
...cacheKey,
|
|
16401
|
-
path:
|
|
16401
|
+
path: path17
|
|
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: path17
|
|
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 path17 = getSameOriginPath(cacheKey, values[i]);
|
|
16421
|
+
if (path17 !== void 0) {
|
|
16422
|
+
deleteCachedUri(store, cacheKey, path17);
|
|
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 path17 = 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 ? `${path17}?` : path17,
|
|
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(path17) {
|
|
22252
|
+
for (let i = 0; i < path17.length; ++i) {
|
|
22253
|
+
const code = path17.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 states = {
|
|
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,
|
|
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
|
|
22997
|
+
var { states, 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 === states.CONNECTING;
|
|
23003
23003
|
}
|
|
23004
23004
|
function isEstablished(readyState) {
|
|
23005
|
-
return readyState ===
|
|
23005
|
+
return readyState === states.OPEN;
|
|
23006
23006
|
}
|
|
23007
23007
|
function isClosing(readyState) {
|
|
23008
|
-
return readyState ===
|
|
23008
|
+
return readyState === states.CLOSING;
|
|
23009
23009
|
}
|
|
23010
23010
|
function isClosed(readyState) {
|
|
23011
|
-
return readyState ===
|
|
23011
|
+
return readyState === states.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
|
|
23279
|
+
var { uid, states, 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 = states.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 = states.CLOSING;
|
|
23408
23408
|
} else {
|
|
23409
|
-
object.readyState =
|
|
23409
|
+
object.readyState = states.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
|
|
23518
|
+
var { parserStates, opcodes, states, 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 = states.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
|
|
23966
|
+
var { staticPropertyDescriptors, states, 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 = states.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: states.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 = states.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 !== states.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 = states.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 = states.CONNECTING;
|
|
24366
|
+
WebSocket.OPEN = WebSocket.prototype.OPEN = states.OPEN;
|
|
24367
|
+
WebSocket.CLOSING = WebSocket.prototype.CLOSING = states.CLOSING;
|
|
24368
|
+
WebSocket.CLOSED = WebSocket.prototype.CLOSED = states.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
|
|
24534
|
+
var { states, 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 = states.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: states.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 = states.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 = states.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 !== states.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 = states.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 path17 = opts.path;
|
|
25491
25491
|
if (!opts.path.startsWith("/")) {
|
|
25492
|
-
|
|
25492
|
+
path17 = `/${path17}`;
|
|
25493
25493
|
}
|
|
25494
|
-
url = new URL(util.parseOrigin(url).origin +
|
|
25494
|
+
url = new URL(util.parseOrigin(url).origin + path17);
|
|
25495
25495
|
} else {
|
|
25496
25496
|
if (!opts) {
|
|
25497
25497
|
opts = typeof url === "object" ? url : {};
|
|
@@ -47522,16 +47522,16 @@ function connectDirect(host, port, timeoutMs = CONNECT_TIMEOUT_MS) {
|
|
|
47522
47522
|
const finishError = (error) => {
|
|
47523
47523
|
if (settled) return;
|
|
47524
47524
|
settled = true;
|
|
47525
|
-
clearTimeout(
|
|
47525
|
+
clearTimeout(timer2);
|
|
47526
47526
|
socket.destroy();
|
|
47527
47527
|
reject(error);
|
|
47528
47528
|
};
|
|
47529
|
-
const
|
|
47529
|
+
const timer2 = setTimeout(() => finishError(new Error(`upstream connect ${host}:${port} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
47530
47530
|
socket.once("error", finishError);
|
|
47531
47531
|
socket.once("connect", () => {
|
|
47532
47532
|
if (settled) return;
|
|
47533
47533
|
settled = true;
|
|
47534
|
-
clearTimeout(
|
|
47534
|
+
clearTimeout(timer2);
|
|
47535
47535
|
resolve(socket);
|
|
47536
47536
|
});
|
|
47537
47537
|
});
|
|
@@ -47548,11 +47548,11 @@ function connectThroughProxy(host, port, proxyUrl) {
|
|
|
47548
47548
|
const finishError = (error) => {
|
|
47549
47549
|
if (settled) return;
|
|
47550
47550
|
settled = true;
|
|
47551
|
-
clearTimeout(
|
|
47551
|
+
clearTimeout(timer2);
|
|
47552
47552
|
socket.destroy();
|
|
47553
47553
|
reject(error);
|
|
47554
47554
|
};
|
|
47555
|
-
const
|
|
47555
|
+
const timer2 = setTimeout(() => finishError(new Error(`upstream proxy CONNECT ${host}:${port} handshake timeout`)), CONNECT_TIMEOUT_MS);
|
|
47556
47556
|
socket.once("error", finishError);
|
|
47557
47557
|
const connectedEvent = proxy.protocol === "https:" ? "secureConnect" : "connect";
|
|
47558
47558
|
socket.once(connectedEvent, () => {
|
|
@@ -47581,7 +47581,7 @@ function connectThroughProxy(host, port, proxyUrl) {
|
|
|
47581
47581
|
return;
|
|
47582
47582
|
}
|
|
47583
47583
|
settled = true;
|
|
47584
|
-
clearTimeout(
|
|
47584
|
+
clearTimeout(timer2);
|
|
47585
47585
|
socket.removeListener("error", finishError);
|
|
47586
47586
|
const rest = buffer.subarray(end + 4);
|
|
47587
47587
|
if (rest.length > 0) socket.unshift(rest);
|
|
@@ -47647,13 +47647,13 @@ function getUpstreamConnectionStatus() {
|
|
|
47647
47647
|
}
|
|
47648
47648
|
|
|
47649
47649
|
// src/config.ts
|
|
47650
|
-
function safeReadJson(
|
|
47650
|
+
function safeReadJson(path17) {
|
|
47651
47651
|
try {
|
|
47652
|
-
const raw = readFileSync(
|
|
47652
|
+
const raw = readFileSync(path17, "utf8").replace(/^\uFEFF/, "");
|
|
47653
47653
|
return JSON.parse(raw);
|
|
47654
47654
|
} catch (e) {
|
|
47655
47655
|
if (e.code !== "ENOENT") {
|
|
47656
|
-
log("error", `[acp-config] failed to parse ${
|
|
47656
|
+
log("error", `[acp-config] failed to parse ${path17}: ${String(e)}`);
|
|
47657
47657
|
}
|
|
47658
47658
|
return void 0;
|
|
47659
47659
|
}
|
|
@@ -47933,7 +47933,7 @@ function rejectLegacyRoute(key, value) {
|
|
|
47933
47933
|
|
|
47934
47934
|
// src/server.ts
|
|
47935
47935
|
import http from "http";
|
|
47936
|
-
import
|
|
47936
|
+
import fs7 from "fs";
|
|
47937
47937
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
47938
47938
|
|
|
47939
47939
|
// src/compress-settings.ts
|
|
@@ -48048,11 +48048,11 @@ async function fetchWithTimeout(url, opts, timeoutMs = UPSTREAM_TIMEOUT_MS, exte
|
|
|
48048
48048
|
liveUpstreamTimers.add(t);
|
|
48049
48049
|
return t;
|
|
48050
48050
|
};
|
|
48051
|
-
let
|
|
48051
|
+
let timer2 = armTimer();
|
|
48052
48052
|
const rearm = () => {
|
|
48053
|
-
clearTimeout(
|
|
48054
|
-
liveUpstreamTimers.delete(
|
|
48055
|
-
|
|
48053
|
+
clearTimeout(timer2);
|
|
48054
|
+
liveUpstreamTimers.delete(timer2);
|
|
48055
|
+
timer2 = armTimer();
|
|
48056
48056
|
};
|
|
48057
48057
|
let onExternalAbort = null;
|
|
48058
48058
|
if (externalSignal) {
|
|
@@ -48063,8 +48063,8 @@ async function fetchWithTimeout(url, opts, timeoutMs = UPSTREAM_TIMEOUT_MS, exte
|
|
|
48063
48063
|
}
|
|
48064
48064
|
}
|
|
48065
48065
|
const cleanup = () => {
|
|
48066
|
-
clearTimeout(
|
|
48067
|
-
liveUpstreamTimers.delete(
|
|
48066
|
+
clearTimeout(timer2);
|
|
48067
|
+
liveUpstreamTimers.delete(timer2);
|
|
48068
48068
|
if (onExternalAbort && externalSignal) externalSignal.removeEventListener("abort", onExternalAbort);
|
|
48069
48069
|
};
|
|
48070
48070
|
try {
|
|
@@ -48157,13 +48157,13 @@ function replayBackoffMs(attempt) {
|
|
|
48157
48157
|
function sleep(ms2, signal) {
|
|
48158
48158
|
if (ms2 <= 0 || signal?.aborted) return Promise.resolve();
|
|
48159
48159
|
return new Promise((resolve) => {
|
|
48160
|
-
let
|
|
48160
|
+
let timer2 = null;
|
|
48161
48161
|
const finish2 = () => {
|
|
48162
|
-
if (
|
|
48162
|
+
if (timer2) clearTimeout(timer2);
|
|
48163
48163
|
if (signal) signal.removeEventListener("abort", finish2);
|
|
48164
48164
|
resolve();
|
|
48165
48165
|
};
|
|
48166
|
-
|
|
48166
|
+
timer2 = setTimeout(finish2, ms2);
|
|
48167
48167
|
if (signal) signal.addEventListener("abort", finish2, { once: true });
|
|
48168
48168
|
});
|
|
48169
48169
|
}
|
|
@@ -49385,7 +49385,7 @@ var StateStore = class {
|
|
|
49385
49385
|
this.pending.set(id, build2);
|
|
49386
49386
|
const existing = this.timers.get(id);
|
|
49387
49387
|
if (existing) return;
|
|
49388
|
-
const
|
|
49388
|
+
const timer2 = setTimeout(() => {
|
|
49389
49389
|
this.timers.delete(id);
|
|
49390
49390
|
const builder = this.pending.get(id);
|
|
49391
49391
|
this.pending.delete(id);
|
|
@@ -49393,8 +49393,8 @@ var StateStore = class {
|
|
|
49393
49393
|
void this.writeNow(id, builder).catch(() => {
|
|
49394
49394
|
});
|
|
49395
49395
|
}, this.debounceMs);
|
|
49396
|
-
|
|
49397
|
-
this.timers.set(id,
|
|
49396
|
+
timer2.unref?.();
|
|
49397
|
+
this.timers.set(id, timer2);
|
|
49398
49398
|
}
|
|
49399
49399
|
/** Immediate save, serialized per id. Rejects on write failure; a
|
|
49400
49400
|
* failing write never breaks the chain for the next one. */
|
|
@@ -49416,9 +49416,9 @@ var StateStore = class {
|
|
|
49416
49416
|
* the result to drop in-memory state must NOT drop it on failure. */
|
|
49417
49417
|
flushSync(id, build2) {
|
|
49418
49418
|
if (!this.enabled) return true;
|
|
49419
|
-
const
|
|
49420
|
-
if (
|
|
49421
|
-
clearTimeout(
|
|
49419
|
+
const timer2 = this.timers.get(id);
|
|
49420
|
+
if (timer2) {
|
|
49421
|
+
clearTimeout(timer2);
|
|
49422
49422
|
this.timers.delete(id);
|
|
49423
49423
|
this.pending.delete(id);
|
|
49424
49424
|
}
|
|
@@ -49541,7 +49541,7 @@ var StateStore = class {
|
|
|
49541
49541
|
* writes. For graceful shutdown (SIGTERM/SIGINT). Never rejects. */
|
|
49542
49542
|
async flushAll() {
|
|
49543
49543
|
const ids = this.pendingIds();
|
|
49544
|
-
for (const
|
|
49544
|
+
for (const timer2 of this.timers.values()) clearTimeout(timer2);
|
|
49545
49545
|
this.timers.clear();
|
|
49546
49546
|
const builders = /* @__PURE__ */ new Map();
|
|
49547
49547
|
for (const id of ids) {
|
|
@@ -49560,7 +49560,7 @@ var StateStore = class {
|
|
|
49560
49560
|
}
|
|
49561
49561
|
/** Cancel all pending debounced writes without flushing (tests). */
|
|
49562
49562
|
cancelAll() {
|
|
49563
|
-
for (const
|
|
49563
|
+
for (const timer2 of this.timers.values()) clearTimeout(timer2);
|
|
49564
49564
|
this.timers.clear();
|
|
49565
49565
|
this.pending.clear();
|
|
49566
49566
|
}
|
|
@@ -51568,93 +51568,6 @@ ${icon} [ACP] ${inner}
|
|
|
51568
51568
|
`;
|
|
51569
51569
|
}
|
|
51570
51570
|
|
|
51571
|
-
// src/weak-overflow.ts
|
|
51572
|
-
var MIN_USAGE = 0.9;
|
|
51573
|
-
var WINDOW_MS = 15 * 60 * 1e3;
|
|
51574
|
-
var MIN_EVENTS = 3;
|
|
51575
|
-
var MAX_TRACKED_SESSIONS = 512;
|
|
51576
|
-
var states = /* @__PURE__ */ new Map();
|
|
51577
|
-
function resolvedWindow2(session) {
|
|
51578
|
-
const md = session.metadata ?? {};
|
|
51579
|
-
const learned = md.learnedContextLimit;
|
|
51580
|
-
const effective = md.effectiveContextLimit;
|
|
51581
|
-
const candidates = [learned, effective].filter((v2) => typeof v2 === "number" && v2 > 0);
|
|
51582
|
-
if (candidates.length === 0) return 0;
|
|
51583
|
-
return Math.min(...candidates);
|
|
51584
|
-
}
|
|
51585
|
-
function noteWeakOverflow(session, opts) {
|
|
51586
|
-
const window2 = resolvedWindow2(session);
|
|
51587
|
-
if (window2 <= 0) return;
|
|
51588
|
-
const input = opts.inputTokens && opts.inputTokens > 0 ? opts.inputTokens : session.stats?.lastInputTokens ?? 0;
|
|
51589
|
-
if (input <= 0) return;
|
|
51590
|
-
if (input / window2 < MIN_USAGE) return;
|
|
51591
|
-
if (states.size > MAX_TRACKED_SESSIONS) {
|
|
51592
|
-
const oldest = states.keys().next().value;
|
|
51593
|
-
if (oldest !== void 0) states.delete(oldest);
|
|
51594
|
-
}
|
|
51595
|
-
const state = states.get(session.id) ?? { events: [] };
|
|
51596
|
-
const now = Date.now();
|
|
51597
|
-
state.events = state.events.filter((t) => now - t < WINDOW_MS);
|
|
51598
|
-
state.events.push(now);
|
|
51599
|
-
states.set(session.id, state);
|
|
51600
|
-
if (state.events.length < MIN_EVENTS) {
|
|
51601
|
-
log("warn", `[${session.id}] weak overflow signal ${state.events.length}/${MIN_EVENTS} (usage ${Math.round(input / window2 * 100)}%, ${opts.reason})`);
|
|
51602
|
-
return;
|
|
51603
|
-
}
|
|
51604
|
-
states.delete(session.id);
|
|
51605
|
-
const md = session.metadata ?? {};
|
|
51606
|
-
if (md.learnedContextLimits === void 0) md.learnedContextLimits = {};
|
|
51607
|
-
const learnedMap = md.learnedContextLimits;
|
|
51608
|
-
const reqModel = opts.model;
|
|
51609
|
-
const prev = (reqModel ? learnedMap[reqModel] : void 0) ?? md.learnedContextLimit;
|
|
51610
|
-
if (prev === void 0 || input < prev) {
|
|
51611
|
-
if (reqModel) learnedMap[reqModel] = input;
|
|
51612
|
-
else md.learnedContextLimit = input;
|
|
51613
|
-
session.metadata = md;
|
|
51614
|
-
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`);
|
|
51615
|
-
} else {
|
|
51616
|
-
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`);
|
|
51617
|
-
}
|
|
51618
|
-
if (!session.stats) session.stats = { lastInputTokens: input };
|
|
51619
|
-
else session.stats.lastInputTokens = Math.max(session.stats.lastInputTokens, input);
|
|
51620
|
-
markDirty(session);
|
|
51621
|
-
}
|
|
51622
|
-
|
|
51623
|
-
// src/cache-warn.ts
|
|
51624
|
-
var MIN_INPUT = 8e3;
|
|
51625
|
-
var HIGH_HIT = 0.5;
|
|
51626
|
-
var LOW_HIT = 0.1;
|
|
51627
|
-
var LOW_RUN = 5;
|
|
51628
|
-
var MAX_TRACKED_SESSIONS2 = 1024;
|
|
51629
|
-
var watches = /* @__PURE__ */ new Map();
|
|
51630
|
-
function warnCacheCollapse(session, input, cached) {
|
|
51631
|
-
if (input < MIN_INPUT) return;
|
|
51632
|
-
if (watches.size > MAX_TRACKED_SESSIONS2) {
|
|
51633
|
-
const oldest = watches.keys().next().value;
|
|
51634
|
-
if (oldest !== void 0) watches.delete(oldest);
|
|
51635
|
-
}
|
|
51636
|
-
const watch = watches.get(session.id) ?? { sawHigh: false, lowRun: 0, warned: false };
|
|
51637
|
-
watches.set(session.id, watch);
|
|
51638
|
-
const hit = cached / input;
|
|
51639
|
-
if (hit >= HIGH_HIT) {
|
|
51640
|
-
watch.sawHigh = true;
|
|
51641
|
-
watch.lowRun = 0;
|
|
51642
|
-
return;
|
|
51643
|
-
}
|
|
51644
|
-
if (!watch.sawHigh || watch.warned) return;
|
|
51645
|
-
if (hit > LOW_HIT) {
|
|
51646
|
-
watch.lowRun = 0;
|
|
51647
|
-
return;
|
|
51648
|
-
}
|
|
51649
|
-
watch.lowRun++;
|
|
51650
|
-
if (watch.lowRun < LOW_RUN) return;
|
|
51651
|
-
watch.warned = true;
|
|
51652
|
-
log(
|
|
51653
|
-
"warn",
|
|
51654
|
-
`[${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.`
|
|
51655
|
-
);
|
|
51656
|
-
}
|
|
51657
|
-
|
|
51658
51571
|
// src/loop/core.ts
|
|
51659
51572
|
var MAX_LOOP_ROUNDS = 10;
|
|
51660
51573
|
function isLoopThinking(m2) {
|
|
@@ -51737,7 +51650,6 @@ function recordUsage(ctx, usage, round) {
|
|
|
51737
51650
|
}
|
|
51738
51651
|
if (typeof out === "number") ctx.session.stats.outputTokens += out;
|
|
51739
51652
|
const hitPct = typeof cached === "number" && total > 0 ? Math.round(cached / total * 100) : 0;
|
|
51740
|
-
warnCacheCollapse(ctx.session, total, cached ?? 0);
|
|
51741
51653
|
ctx.log(
|
|
51742
51654
|
`[acp-usage] round ${round} input=${total} cached=${cached ?? 0} (cache hit ${hitPct}%)`
|
|
51743
51655
|
);
|
|
@@ -51992,14 +51904,6 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
51992
51904
|
}
|
|
51993
51905
|
const reRequest = proxyResults.length > 0 && realCalls === 0;
|
|
51994
51906
|
if (!reRequest) {
|
|
51995
|
-
if (!sawDone || truncatedDone) {
|
|
51996
|
-
const reqModel = typeof requestBody["model"] === "string" ? requestBody["model"] : void 0;
|
|
51997
|
-
noteWeakOverflow(ctx.session, {
|
|
51998
|
-
inputTokens: usage.inputTokens,
|
|
51999
|
-
model: reqModel,
|
|
52000
|
-
reason: `round ${round}: upstream stream truncated without a completion event`
|
|
52001
|
-
});
|
|
52002
|
-
}
|
|
52003
51907
|
if (!sawDone) {
|
|
52004
51908
|
const partialText = assistantText.length;
|
|
52005
51909
|
const partialReasoning = assistantReasoning.length;
|
|
@@ -52024,11 +51928,11 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
52024
51928
|
let newBody = adapter.buildRequest(coreMessages, systemPrompt, requestBody);
|
|
52025
51929
|
if (process.env.ACP_DUMP_BODY === "1") {
|
|
52026
51930
|
try {
|
|
52027
|
-
const
|
|
51931
|
+
const fs12 = await import("fs");
|
|
52028
51932
|
const dumpDir = process.env.ACP_DUMP_DIR || `${process.env.HOME}/.local/state/billion-context/dumps`;
|
|
52029
|
-
|
|
51933
|
+
fs12.mkdirSync(dumpDir, { recursive: true });
|
|
52030
51934
|
const sid = ctx.session.id ?? "unknown";
|
|
52031
|
-
|
|
51935
|
+
fs12.writeFileSync(`${dumpDir}/req-${Date.now()}-${sid}-REREQUEST.json`, JSON.stringify(newBody, null, 2));
|
|
52032
51936
|
} catch {
|
|
52033
51937
|
}
|
|
52034
51938
|
}
|
|
@@ -52054,12 +51958,6 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
52054
51958
|
const suffix = e.attempts > 1 ? ` after ${e.attempts} attempt(s)` : "";
|
|
52055
51959
|
ctx.log(`[acp-proxy: compress loop upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}]`);
|
|
52056
51960
|
log("error", `[acp-loop] upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}`);
|
|
52057
|
-
const reqModel = typeof requestBody["model"] === "string" ? requestBody["model"] : void 0;
|
|
52058
|
-
noteWeakOverflow(ctx.session, {
|
|
52059
|
-
inputTokens: usage.inputTokens,
|
|
52060
|
-
model: reqModel,
|
|
52061
|
-
reason: `round ${round}: upstream error ${e.status}${suffix}`
|
|
52062
|
-
});
|
|
52063
51961
|
yield adapter.emitError(`upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}`);
|
|
52064
51962
|
return;
|
|
52065
51963
|
}
|
|
@@ -54044,7 +53942,7 @@ function codexTurnIdentity(headers) {
|
|
|
54044
53942
|
// src/prefix-affinity.ts
|
|
54045
53943
|
import { createHash as createHash5 } from "crypto";
|
|
54046
53944
|
var MIN_CANONICAL_BYTES = 24;
|
|
54047
|
-
var
|
|
53945
|
+
var MAX_TRACKED_SESSIONS = 256;
|
|
54048
53946
|
var TTL_MS2 = 7 * 24 * 60 * 60 * 1e3;
|
|
54049
53947
|
var TAIL_WINDOW = 8;
|
|
54050
53948
|
var MIN_TAIL_MATCH = 3;
|
|
@@ -54190,7 +54088,7 @@ var PrefixAffinityResolver = class {
|
|
|
54190
54088
|
const tracked = this.trackedChains;
|
|
54191
54089
|
tracked.delete(sessionId);
|
|
54192
54090
|
tracked.set(sessionId, { sessionId, depth, tailHash, itemHashes, lastSeen: Date.now() });
|
|
54193
|
-
while (tracked.size >
|
|
54091
|
+
while (tracked.size > MAX_TRACKED_SESSIONS) {
|
|
54194
54092
|
const oldest = [...tracked.values()].sort((a, b2) => a.lastSeen - b2.lastSeen)[0];
|
|
54195
54093
|
if (!oldest) break;
|
|
54196
54094
|
tracked.delete(oldest.sessionId);
|
|
@@ -54203,48 +54101,6 @@ var PrefixAffinityResolver = class {
|
|
|
54203
54101
|
trackedSessionIds() {
|
|
54204
54102
|
return [...this.trackedChains.keys()];
|
|
54205
54103
|
}
|
|
54206
|
-
/** Serializable copy of the tracked chains (for #499 P1a persistence). */
|
|
54207
|
-
exportSnapshot() {
|
|
54208
|
-
return [...this.trackedChains.values()].map((e) => ({
|
|
54209
|
-
sessionId: e.sessionId,
|
|
54210
|
-
depth: e.depth,
|
|
54211
|
-
tailHash: e.tailHash,
|
|
54212
|
-
itemHashes: e.itemHashes,
|
|
54213
|
-
lastSeen: e.lastSeen
|
|
54214
|
-
}));
|
|
54215
|
-
}
|
|
54216
|
-
/** Load chains persisted by a previous process. Entries older than the
|
|
54217
|
-
* TTL are dropped (they would not match anyway). Returns the count
|
|
54218
|
-
* actually imported. Defensive: a corrupt/hand-edited file must never
|
|
54219
|
-
* crash the proxy — malformed entries are skipped. */
|
|
54220
|
-
importSnapshot(entries) {
|
|
54221
|
-
if (!Array.isArray(entries)) return 0;
|
|
54222
|
-
const now = Date.now();
|
|
54223
|
-
let imported = 0;
|
|
54224
|
-
for (const raw of entries) {
|
|
54225
|
-
if (!raw || typeof raw !== "object") continue;
|
|
54226
|
-
const e = raw;
|
|
54227
|
-
if (typeof e.sessionId !== "string" || typeof e.depth !== "number" || typeof e.tailHash !== "string") continue;
|
|
54228
|
-
if (!Array.isArray(e.itemHashes) || e.itemHashes.some((h) => typeof h !== "string")) continue;
|
|
54229
|
-
if (typeof e.lastSeen !== "number" || now - e.lastSeen > TTL_MS2) continue;
|
|
54230
|
-
const entry = {
|
|
54231
|
-
sessionId: e.sessionId,
|
|
54232
|
-
depth: e.depth,
|
|
54233
|
-
tailHash: e.tailHash,
|
|
54234
|
-
itemHashes: e.itemHashes.slice(-MAX_STORED_ITEMS),
|
|
54235
|
-
lastSeen: e.lastSeen
|
|
54236
|
-
};
|
|
54237
|
-
this.trackedChains.delete(entry.sessionId);
|
|
54238
|
-
this.trackedChains.set(entry.sessionId, entry);
|
|
54239
|
-
imported++;
|
|
54240
|
-
}
|
|
54241
|
-
while (this.trackedChains.size > MAX_TRACKED_SESSIONS3) {
|
|
54242
|
-
const oldest = [...this.trackedChains.values()].sort((a, b2) => a.lastSeen - b2.lastSeen)[0];
|
|
54243
|
-
if (!oldest) break;
|
|
54244
|
-
this.trackedChains.delete(oldest.sessionId);
|
|
54245
|
-
}
|
|
54246
|
-
return imported;
|
|
54247
|
-
}
|
|
54248
54104
|
expire(tracked) {
|
|
54249
54105
|
if (tracked.size === 0) return;
|
|
54250
54106
|
const now = Date.now();
|
|
@@ -54255,58 +54111,6 @@ var PrefixAffinityResolver = class {
|
|
|
54255
54111
|
};
|
|
54256
54112
|
var prefixAffinity = new PrefixAffinityResolver();
|
|
54257
54113
|
|
|
54258
|
-
// src/affinity-persist.ts
|
|
54259
|
-
import fs4 from "fs";
|
|
54260
|
-
import path8 from "path";
|
|
54261
|
-
var PERSIST_DEBOUNCE_MS = 5e3;
|
|
54262
|
-
function affinityFile() {
|
|
54263
|
-
return path8.join(stateDir(), "prefix-affinity.json");
|
|
54264
|
-
}
|
|
54265
|
-
var timer = null;
|
|
54266
|
-
var writing = false;
|
|
54267
|
-
function writeSnapshot() {
|
|
54268
|
-
if (writing) return;
|
|
54269
|
-
writing = true;
|
|
54270
|
-
try {
|
|
54271
|
-
const file = affinityFile();
|
|
54272
|
-
const snapshot = { version: 1, entries: prefixAffinity.exportSnapshot() };
|
|
54273
|
-
const tmp = `${file}.tmp`;
|
|
54274
|
-
fs4.mkdirSync(path8.dirname(file), { recursive: true });
|
|
54275
|
-
fs4.writeFileSync(tmp, JSON.stringify(snapshot));
|
|
54276
|
-
fs4.renameSync(tmp, file);
|
|
54277
|
-
} catch (e) {
|
|
54278
|
-
log("warn", `[prefix-affinity] persist failed (${e instanceof Error ? e.message : String(e)}); affinity survives in memory`);
|
|
54279
|
-
} finally {
|
|
54280
|
-
writing = false;
|
|
54281
|
-
}
|
|
54282
|
-
}
|
|
54283
|
-
function scheduleAffinityPersist() {
|
|
54284
|
-
if (timer) clearTimeout(timer);
|
|
54285
|
-
timer = setTimeout(() => {
|
|
54286
|
-
timer = null;
|
|
54287
|
-
writeSnapshot();
|
|
54288
|
-
}, PERSIST_DEBOUNCE_MS);
|
|
54289
|
-
timer.unref?.();
|
|
54290
|
-
}
|
|
54291
|
-
function flushPrefixAffinity() {
|
|
54292
|
-
if (timer) {
|
|
54293
|
-
clearTimeout(timer);
|
|
54294
|
-
timer = null;
|
|
54295
|
-
}
|
|
54296
|
-
writeSnapshot();
|
|
54297
|
-
}
|
|
54298
|
-
function hydratePrefixAffinity() {
|
|
54299
|
-
try {
|
|
54300
|
-
const file = affinityFile();
|
|
54301
|
-
if (!fs4.existsSync(file)) return;
|
|
54302
|
-
const parsed = JSON.parse(fs4.readFileSync(file, "utf8"));
|
|
54303
|
-
const imported = prefixAffinity.importSnapshot(parsed.entries);
|
|
54304
|
-
if (imported > 0) log("info", `[prefix-affinity] hydrated ${imported} chain(s) from ${path8.basename(file)} \u2014 anonymous sessions reattach across restarts`);
|
|
54305
|
-
} catch (e) {
|
|
54306
|
-
log("warn", `[prefix-affinity] hydrate failed (${e instanceof Error ? e.message : String(e)}); starting with empty affinity`);
|
|
54307
|
-
}
|
|
54308
|
-
}
|
|
54309
|
-
|
|
54310
54114
|
// node_modules/acp-kernel/dist/panel/index.js
|
|
54311
54115
|
function topicFallback(summary) {
|
|
54312
54116
|
const first = summary.split(/[.\n]/)[0] ?? "";
|
|
@@ -54450,8 +54254,8 @@ function buildStatusPanel(input) {
|
|
|
54450
54254
|
|
|
54451
54255
|
// src/plugin.ts
|
|
54452
54256
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
54453
|
-
import
|
|
54454
|
-
import
|
|
54257
|
+
import fs4 from "fs";
|
|
54258
|
+
import path8 from "path";
|
|
54455
54259
|
|
|
54456
54260
|
// src/sse-util.ts
|
|
54457
54261
|
function normalizeSseLineEndings(buf) {
|
|
@@ -54463,8 +54267,8 @@ function normalizeSseLineEndings(buf) {
|
|
|
54463
54267
|
var PROXY_VERSION = (() => {
|
|
54464
54268
|
try {
|
|
54465
54269
|
const here = fileURLToPath2(import.meta.url);
|
|
54466
|
-
const pkg =
|
|
54467
|
-
return JSON.parse(
|
|
54270
|
+
const pkg = path8.join(path8.dirname(here), "..", "package.json");
|
|
54271
|
+
return JSON.parse(fs4.readFileSync(pkg, "utf8")).version ?? "dev";
|
|
54468
54272
|
} catch {
|
|
54469
54273
|
return "dev";
|
|
54470
54274
|
}
|
|
@@ -54476,8 +54280,8 @@ var PLUGIN_PROTOCOL_VERSION = 1;
|
|
|
54476
54280
|
var VERSION = (() => {
|
|
54477
54281
|
try {
|
|
54478
54282
|
const here = fileURLToPath2(import.meta.url);
|
|
54479
|
-
const pkg =
|
|
54480
|
-
return JSON.parse(
|
|
54283
|
+
const pkg = path8.join(path8.dirname(here), "..", "package.json");
|
|
54284
|
+
return JSON.parse(fs4.readFileSync(pkg, "utf8")).version ?? "dev";
|
|
54481
54285
|
} catch {
|
|
54482
54286
|
return "dev";
|
|
54483
54287
|
}
|
|
@@ -54506,7 +54310,7 @@ function pluginReportedContextWindow(headers) {
|
|
|
54506
54310
|
var MAX_PLUGIN_CONVERSATIONS = 1024;
|
|
54507
54311
|
var conversations = /* @__PURE__ */ new Map();
|
|
54508
54312
|
var remembered = /* @__PURE__ */ new Map();
|
|
54509
|
-
var conversationsFile = () =>
|
|
54313
|
+
var conversationsFile = () => path8.join(stateDir(), "plugin-conversations.json");
|
|
54510
54314
|
var conversationsSaveTimer;
|
|
54511
54315
|
var conversationsDirty = false;
|
|
54512
54316
|
function writeConversationsFile() {
|
|
@@ -54514,11 +54318,11 @@ function writeConversationsFile() {
|
|
|
54514
54318
|
try {
|
|
54515
54319
|
const obj = {};
|
|
54516
54320
|
for (const [k2, v2] of conversations) obj[k2] = v2;
|
|
54517
|
-
|
|
54321
|
+
fs4.mkdirSync(stateDir(), { recursive: true });
|
|
54518
54322
|
const filePath = conversationsFile();
|
|
54519
54323
|
const draft = `${filePath}.${process.pid}.bili-tmp`;
|
|
54520
|
-
|
|
54521
|
-
|
|
54324
|
+
fs4.writeFileSync(draft, JSON.stringify(obj));
|
|
54325
|
+
fs4.renameSync(draft, filePath);
|
|
54522
54326
|
conversationsDirty = false;
|
|
54523
54327
|
} catch {
|
|
54524
54328
|
}
|
|
@@ -54540,7 +54344,7 @@ function flushConversations() {
|
|
|
54540
54344
|
function loadConversations() {
|
|
54541
54345
|
let raw;
|
|
54542
54346
|
try {
|
|
54543
|
-
raw =
|
|
54347
|
+
raw = fs4.readFileSync(conversationsFile(), "utf8");
|
|
54544
54348
|
} catch {
|
|
54545
54349
|
return;
|
|
54546
54350
|
}
|
|
@@ -54553,7 +54357,7 @@ function loadConversations() {
|
|
|
54553
54357
|
}
|
|
54554
54358
|
} catch {
|
|
54555
54359
|
try {
|
|
54556
|
-
|
|
54360
|
+
fs4.renameSync(conversationsFile(), `${conversationsFile()}.corrupt-${Date.now()}`);
|
|
54557
54361
|
} catch {
|
|
54558
54362
|
}
|
|
54559
54363
|
log("warn", "[plugin] plugin-conversations.json is corrupt \u2014 backed up beside the original, starting an empty routing table");
|
|
@@ -54839,7 +54643,6 @@ function applyUsageSample(session, sample, protocol) {
|
|
|
54839
54643
|
const total = sample.inputTokens + (!includesCached && sample.cachedTokens !== void 0 ? sample.cachedTokens : 0);
|
|
54840
54644
|
session.stats.inputTokens += total;
|
|
54841
54645
|
session.stats.lastInputTokens = Math.max(0, total - (session.stats.compressCreditTokens ?? 0));
|
|
54842
|
-
warnCacheCollapse(session, total, sample.cachedTokens ?? 0);
|
|
54843
54646
|
}
|
|
54844
54647
|
if (sample.outputTokens !== void 0) session.stats.outputTokens += sample.outputTokens;
|
|
54845
54648
|
}
|
|
@@ -54903,14 +54706,6 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
54903
54706
|
markDirty(session);
|
|
54904
54707
|
}
|
|
54905
54708
|
};
|
|
54906
|
-
let sawTerminal = false;
|
|
54907
|
-
const maybeNoteTruncated = () => {
|
|
54908
|
-
if (sawTerminal || !session || res.destroyed || res.writableEnded) return;
|
|
54909
|
-
noteWeakOverflow(session, {
|
|
54910
|
-
inputTokens: acc.inputTokens,
|
|
54911
|
-
reason: "plugin chat passthrough stream ended without a completion event"
|
|
54912
|
-
});
|
|
54913
|
-
};
|
|
54914
54709
|
const pushField = (field, index, text) => {
|
|
54915
54710
|
const s3 = filterFor(field, index);
|
|
54916
54711
|
const clean = s3.filter.push(text);
|
|
@@ -54996,7 +54791,6 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
54996
54791
|
const jsonStr = dataLines.map((l) => l.slice(5).replace(/^ /, "")).join("\n").trim();
|
|
54997
54792
|
if (!jsonStr) continue;
|
|
54998
54793
|
if (jsonStr === "[DONE]") {
|
|
54999
|
-
sawTerminal = true;
|
|
55000
54794
|
await write(flushTails() + rawEvent + "\n\n");
|
|
55001
54795
|
continue;
|
|
55002
54796
|
}
|
|
@@ -55007,7 +54801,6 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
55007
54801
|
await write(rawEvent + "\n\n");
|
|
55008
54802
|
continue;
|
|
55009
54803
|
}
|
|
55010
|
-
if (ev["type"] === "message_stop") sawTerminal = true;
|
|
55011
54804
|
const sample = usageFromSseEvent(ev);
|
|
55012
54805
|
if (sample) mergeUsageSample(acc, sample);
|
|
55013
54806
|
const out = protocol === "anthropic" ? processAnthropic(ev, rawEvent) : processOpenai(ev, rawEvent);
|
|
@@ -55019,10 +54812,8 @@ data: ${JSON.stringify({ type: "content_block_delta", index, delta: { type: delt
|
|
|
55019
54812
|
const rest = flushTails();
|
|
55020
54813
|
if (rest.length > 0 && !res.destroyed && !res.writableEnded) await write(rest);
|
|
55021
54814
|
settleUsage();
|
|
55022
|
-
maybeNoteTruncated();
|
|
55023
54815
|
} catch (e) {
|
|
55024
54816
|
settleUsage();
|
|
55025
|
-
maybeNoteTruncated();
|
|
55026
54817
|
if (res.destroyed || res.writableEnded) {
|
|
55027
54818
|
log2?.("client aborted mid-stream");
|
|
55028
54819
|
return;
|
|
@@ -55067,14 +54858,6 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
55067
54858
|
markDirty(session);
|
|
55068
54859
|
}
|
|
55069
54860
|
};
|
|
55070
|
-
let sawTerminal = false;
|
|
55071
|
-
const maybeNoteTruncated = () => {
|
|
55072
|
-
if (sawTerminal || !session || res.destroyed || res.writableEnded) return;
|
|
55073
|
-
noteWeakOverflow(session, {
|
|
55074
|
-
inputTokens: acc.inputTokens,
|
|
55075
|
-
reason: "plugin responses passthrough stream ended without a completion event"
|
|
55076
|
-
});
|
|
55077
|
-
};
|
|
55078
54861
|
let lastDeltaMeta = null;
|
|
55079
54862
|
const flushTail = (after) => {
|
|
55080
54863
|
const tail = tagFilter.flush();
|
|
@@ -55100,7 +54883,6 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
55100
54883
|
if (dataLines.length === 0) continue;
|
|
55101
54884
|
const jsonStr = dataLines.map((l) => l.slice(5).replace(/^ /, "")).join("\n").trim();
|
|
55102
54885
|
if (!jsonStr || jsonStr === "[DONE]") {
|
|
55103
|
-
if (jsonStr === "[DONE]") sawTerminal = true;
|
|
55104
54886
|
await write(rawEvent + "\n\n");
|
|
55105
54887
|
continue;
|
|
55106
54888
|
}
|
|
@@ -55115,7 +54897,6 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
55115
54897
|
if (sample) mergeUsageSample(acc, sample);
|
|
55116
54898
|
const type = ev["type"];
|
|
55117
54899
|
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") {
|
|
55118
|
-
if (type === "response.completed" || type === "response.failed" || type === "response.incomplete") sawTerminal = true;
|
|
55119
54900
|
const out = containsRenderTagText(jsonStr) ? rebuildEvent(rawEvent, stripResponsesText(ev)) : rawEvent + "\n\n";
|
|
55120
54901
|
await write(flushTail(out));
|
|
55121
54902
|
continue;
|
|
@@ -55150,10 +54931,8 @@ async function pipePluginResponsesWithStrip(stream2, res, session, log2) {
|
|
|
55150
54931
|
if (rest.length > 0) await write(rest);
|
|
55151
54932
|
}
|
|
55152
54933
|
settleUsage();
|
|
55153
|
-
maybeNoteTruncated();
|
|
55154
54934
|
} catch (e) {
|
|
55155
54935
|
settleUsage();
|
|
55156
|
-
maybeNoteTruncated();
|
|
55157
54936
|
if (res.destroyed || res.writableEnded) {
|
|
55158
54937
|
log2?.("client aborted mid-stream");
|
|
55159
54938
|
return;
|
|
@@ -55229,14 +55008,14 @@ async function pipePluginJson(stream2, res, session, protocol) {
|
|
|
55229
55008
|
import tls3 from "tls";
|
|
55230
55009
|
|
|
55231
55010
|
// src/discover.ts
|
|
55232
|
-
import
|
|
55011
|
+
import fs6 from "fs";
|
|
55233
55012
|
import os2 from "os";
|
|
55234
|
-
import
|
|
55013
|
+
import path10 from "path";
|
|
55235
55014
|
|
|
55236
55015
|
// src/client-config.ts
|
|
55237
|
-
import
|
|
55016
|
+
import fs5 from "fs";
|
|
55238
55017
|
import os from "os";
|
|
55239
|
-
import
|
|
55018
|
+
import path9 from "path";
|
|
55240
55019
|
function toModelWindow(id, contextWindow) {
|
|
55241
55020
|
return typeof id === "string" && id.length > 0 && typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? { id, contextWindow: Math.floor(contextWindow) } : null;
|
|
55242
55021
|
}
|
|
@@ -55245,7 +55024,7 @@ function nonEmpty2(s3) {
|
|
|
55245
55024
|
}
|
|
55246
55025
|
function readJsonObject(filePath) {
|
|
55247
55026
|
try {
|
|
55248
|
-
const txt =
|
|
55027
|
+
const txt = fs5.readFileSync(filePath, "utf8");
|
|
55249
55028
|
const parsed = JSON.parse(txt);
|
|
55250
55029
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
55251
55030
|
} catch {
|
|
@@ -55254,19 +55033,19 @@ function readJsonObject(filePath) {
|
|
|
55254
55033
|
}
|
|
55255
55034
|
function resolvePiHome(env) {
|
|
55256
55035
|
const h = os.homedir();
|
|
55257
|
-
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : nonEmpty2(env.PI_HOME) ? env.PI_HOME :
|
|
55036
|
+
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : nonEmpty2(env.PI_HOME) ? env.PI_HOME : path9.join(h, ".pi", "agent");
|
|
55258
55037
|
}
|
|
55259
55038
|
function resolveOmpHome(env) {
|
|
55260
55039
|
const h = os.homedir();
|
|
55261
|
-
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR :
|
|
55040
|
+
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : path9.join(h, ".omp", "agent");
|
|
55262
55041
|
}
|
|
55263
55042
|
function resolveHermesHome(env) {
|
|
55264
55043
|
const h = os.homedir();
|
|
55265
|
-
return nonEmpty2(env.HERMES_HOME) ? env.HERMES_HOME :
|
|
55044
|
+
return nonEmpty2(env.HERMES_HOME) ? env.HERMES_HOME : path9.join(h, ".hermes");
|
|
55266
55045
|
}
|
|
55267
55046
|
function resolveDshHome(env) {
|
|
55268
55047
|
const h = os.homedir();
|
|
55269
|
-
return nonEmpty2(env.DSH_HOME) ? env.DSH_HOME :
|
|
55048
|
+
return nonEmpty2(env.DSH_HOME) ? env.DSH_HOME : path9.join(h, ".dsh");
|
|
55270
55049
|
}
|
|
55271
55050
|
function parseDshSettingsYaml(text) {
|
|
55272
55051
|
const out = [];
|
|
@@ -55285,7 +55064,7 @@ function parseDshSettingsYaml(text) {
|
|
|
55285
55064
|
function readDshConfig(dshHome) {
|
|
55286
55065
|
let text;
|
|
55287
55066
|
try {
|
|
55288
|
-
text =
|
|
55067
|
+
text = fs5.readFileSync(path9.join(dshHome, "settings.yaml"), "utf8");
|
|
55289
55068
|
} catch {
|
|
55290
55069
|
return { baseUrls: [] };
|
|
55291
55070
|
}
|
|
@@ -55293,8 +55072,8 @@ function readDshConfig(dshHome) {
|
|
|
55293
55072
|
}
|
|
55294
55073
|
function readClaudeSettings(homeDir, cwd, env = process.env) {
|
|
55295
55074
|
const files = [
|
|
55296
|
-
|
|
55297
|
-
|
|
55075
|
+
path9.join(homeDir, ".claude", "settings.json"),
|
|
55076
|
+
path9.join(cwd, ".claude", "settings.json")
|
|
55298
55077
|
];
|
|
55299
55078
|
let anthropicBaseUrl;
|
|
55300
55079
|
let model;
|
|
@@ -55367,17 +55146,17 @@ function parseCodexToml(text) {
|
|
|
55367
55146
|
return result;
|
|
55368
55147
|
}
|
|
55369
55148
|
function readCodexConfig(codexHome) {
|
|
55370
|
-
const cfgPath =
|
|
55149
|
+
const cfgPath = path9.join(codexHome, "config.toml");
|
|
55371
55150
|
let text;
|
|
55372
55151
|
try {
|
|
55373
|
-
text =
|
|
55152
|
+
text = fs5.readFileSync(cfgPath, "utf8");
|
|
55374
55153
|
} catch {
|
|
55375
55154
|
return { providers: {} };
|
|
55376
55155
|
}
|
|
55377
55156
|
return parseCodexToml(text);
|
|
55378
55157
|
}
|
|
55379
55158
|
function readPiConfig(piHome) {
|
|
55380
|
-
const cfgPath =
|
|
55159
|
+
const cfgPath = path9.join(piHome, "models.json");
|
|
55381
55160
|
const obj = readJsonObject(cfgPath);
|
|
55382
55161
|
const providers = {};
|
|
55383
55162
|
const rawProviders = obj?.providers;
|
|
@@ -55458,10 +55237,10 @@ function parseOmpYaml(text) {
|
|
|
55458
55237
|
return result;
|
|
55459
55238
|
}
|
|
55460
55239
|
function readOmpConfig(ompHome) {
|
|
55461
|
-
const cfgPath =
|
|
55240
|
+
const cfgPath = path9.join(ompHome, "models.yml");
|
|
55462
55241
|
let text;
|
|
55463
55242
|
try {
|
|
55464
|
-
text =
|
|
55243
|
+
text = fs5.readFileSync(cfgPath, "utf8");
|
|
55465
55244
|
} catch {
|
|
55466
55245
|
return { providers: {} };
|
|
55467
55246
|
}
|
|
@@ -55534,10 +55313,10 @@ function parseHermesYaml(text) {
|
|
|
55534
55313
|
return result;
|
|
55535
55314
|
}
|
|
55536
55315
|
function readHermesConfig(hermesHome) {
|
|
55537
|
-
const cfgPath =
|
|
55316
|
+
const cfgPath = path9.join(hermesHome, "config.yaml");
|
|
55538
55317
|
let text;
|
|
55539
55318
|
try {
|
|
55540
|
-
text =
|
|
55319
|
+
text = fs5.readFileSync(cfgPath, "utf8");
|
|
55541
55320
|
} catch {
|
|
55542
55321
|
return { providers: {} };
|
|
55543
55322
|
}
|
|
@@ -55545,13 +55324,13 @@ function readHermesConfig(hermesHome) {
|
|
|
55545
55324
|
}
|
|
55546
55325
|
function resolveOpencodeConfigFile(env) {
|
|
55547
55326
|
if (nonEmpty2(env.OPENCODE_CONFIG)) return env.OPENCODE_CONFIG;
|
|
55548
|
-
const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME :
|
|
55549
|
-
return
|
|
55327
|
+
const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path9.join(os.homedir(), ".config");
|
|
55328
|
+
return path9.join(xdg2, "opencode", "opencode.json");
|
|
55550
55329
|
}
|
|
55551
55330
|
function readOpencodeConfig(file) {
|
|
55552
55331
|
let text;
|
|
55553
55332
|
try {
|
|
55554
|
-
text =
|
|
55333
|
+
text = fs5.readFileSync(file, "utf8");
|
|
55555
55334
|
} catch {
|
|
55556
55335
|
return { providers: {} };
|
|
55557
55336
|
}
|
|
@@ -55608,10 +55387,10 @@ function parseZcodeConfig(obj) {
|
|
|
55608
55387
|
return result;
|
|
55609
55388
|
}
|
|
55610
55389
|
function readZcodeConfig(zcodeHome) {
|
|
55611
|
-
const cfgPath =
|
|
55390
|
+
const cfgPath = path9.join(zcodeHome, "v2", "config.json");
|
|
55612
55391
|
let txt;
|
|
55613
55392
|
try {
|
|
55614
|
-
txt =
|
|
55393
|
+
txt = fs5.readFileSync(cfgPath, "utf8");
|
|
55615
55394
|
} catch {
|
|
55616
55395
|
return { providers: {} };
|
|
55617
55396
|
}
|
|
@@ -55627,10 +55406,10 @@ function loadClientConfig(env, cwd) {
|
|
|
55627
55406
|
const home = os.homedir();
|
|
55628
55407
|
const config = {};
|
|
55629
55408
|
config.claude = readClaudeSettings(home, cwd, env);
|
|
55630
|
-
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME :
|
|
55409
|
+
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path9.join(home, ".codex");
|
|
55631
55410
|
config.codex = readCodexConfig(codexHome);
|
|
55632
55411
|
config.pi = readPiConfig(resolvePiHome(env));
|
|
55633
|
-
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR :
|
|
55412
|
+
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path9.join(home, ".zcode");
|
|
55634
55413
|
config.zcode = readZcodeConfig(zcodeHome);
|
|
55635
55414
|
config.omp = readOmpConfig(resolveOmpHome(env));
|
|
55636
55415
|
config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
|
|
@@ -55697,21 +55476,21 @@ function extractHttpsHosts(config) {
|
|
|
55697
55476
|
}
|
|
55698
55477
|
function configFilePaths(env) {
|
|
55699
55478
|
const home = os2.homedir();
|
|
55700
|
-
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME :
|
|
55701
|
-
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR :
|
|
55479
|
+
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path10.join(home, ".codex");
|
|
55480
|
+
const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path10.join(home, ".zcode");
|
|
55702
55481
|
return [
|
|
55703
|
-
|
|
55704
|
-
|
|
55705
|
-
|
|
55706
|
-
|
|
55707
|
-
|
|
55482
|
+
path10.join(home, ".claude", "settings.json"),
|
|
55483
|
+
path10.join(process.cwd(), ".claude", "settings.json"),
|
|
55484
|
+
path10.join(codexHome, "config.toml"),
|
|
55485
|
+
path10.join(resolvePiHome(env), "models.json"),
|
|
55486
|
+
path10.join(zcodeHome, "v2", "config.json")
|
|
55708
55487
|
];
|
|
55709
55488
|
}
|
|
55710
55489
|
function readMtimes(paths) {
|
|
55711
55490
|
const mtimes = /* @__PURE__ */ new Map();
|
|
55712
55491
|
for (const p2 of paths) {
|
|
55713
55492
|
try {
|
|
55714
|
-
const st2 =
|
|
55493
|
+
const st2 = fs6.statSync(p2);
|
|
55715
55494
|
mtimes.set(p2, st2.mtimeMs);
|
|
55716
55495
|
} catch {
|
|
55717
55496
|
}
|
|
@@ -56893,8 +56672,7 @@ Content-Length: ${Buffer.byteLength(body)}\r
|
|
|
56893
56672
|
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;
|
|
56894
56673
|
const origin = `http://${originHost}:${actualPort}`;
|
|
56895
56674
|
try {
|
|
56896
|
-
|
|
56897
|
-
hydratePrefixAffinity();
|
|
56675
|
+
fs7.mkdirSync(stateDir(), { recursive: true });
|
|
56898
56676
|
atomicWriteInstanceFile({
|
|
56899
56677
|
origin,
|
|
56900
56678
|
instanceId,
|
|
@@ -56959,7 +56737,6 @@ Content-Length: ${Buffer.byteLength(body)}\r
|
|
|
56959
56737
|
});
|
|
56960
56738
|
let shuttingDown = false;
|
|
56961
56739
|
const finishShutdown = () => {
|
|
56962
|
-
flushPrefixAffinity();
|
|
56963
56740
|
clearProxyInstanceFile(instanceId);
|
|
56964
56741
|
unregisterInstance(instanceId);
|
|
56965
56742
|
closeLogger();
|
|
@@ -57236,14 +57013,14 @@ async function handle(req, res, opts, core, config, log2, instanceId, instanceSt
|
|
|
57236
57013
|
try {
|
|
57237
57014
|
const rawDir = process.env.ACP_RAW_DUMP_DIR || `${stateDir()}/raw`;
|
|
57238
57015
|
try {
|
|
57239
|
-
|
|
57016
|
+
fs7.mkdirSync(rawDir, { recursive: true });
|
|
57240
57017
|
} catch {
|
|
57241
57018
|
}
|
|
57242
57019
|
const hdrs = maskHeadersForLog(
|
|
57243
57020
|
Object.fromEntries(Object.entries(req.headers).map(([k2, v2]) => [k2, Array.isArray(v2) ? v2.join(",") : String(v2)]))
|
|
57244
57021
|
);
|
|
57245
57022
|
const hdrText = Object.entries(hdrs).map(([k2, v2]) => `${k2}: ${v2}`).join("\n");
|
|
57246
|
-
|
|
57023
|
+
fs7.writeFileSync(`${rawDir}/${Date.now()}-INCOMING.txt`, `${req.method} ${maskUrlsInText(req.url ?? "")}
|
|
57247
57024
|
${hdrText}
|
|
57248
57025
|
|
|
57249
57026
|
${bodyBuffer.toString("utf8")}`);
|
|
@@ -57348,7 +57125,6 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
57348
57125
|
const session = getSession(sessionId, { protocol, upstreamOrigin, label: clientLabel ?? (anonAffinity ? "prefix-affinity" : void 0) });
|
|
57349
57126
|
if (anonAffinity) {
|
|
57350
57127
|
prefixAffinity.note(sessionId, anonAffinity.incomingDepth, anonAffinity.tailHash, anonAffinity.itemHashes);
|
|
57351
|
-
scheduleAffinityPersist();
|
|
57352
57128
|
session.metadata.anonymousPrefixAffinity = {
|
|
57353
57129
|
depth: anonAffinity.incomingDepth,
|
|
57354
57130
|
tailHash: anonAffinity.tailHash,
|
|
@@ -58096,16 +57872,16 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
|
|
|
58096
57872
|
if (bodyDumpEnabled() && process.env.ACP_DUMP_REQ !== "0") {
|
|
58097
57873
|
const dumpDir = process.env.ACP_DUMP_DIR || `${stateDir()}/dumps`;
|
|
58098
57874
|
try {
|
|
58099
|
-
|
|
57875
|
+
fs7.mkdirSync(dumpDir, { recursive: true });
|
|
58100
57876
|
} catch {
|
|
58101
57877
|
}
|
|
58102
57878
|
const sid = prepared?.session.id ?? "unknown";
|
|
58103
57879
|
const out = `${dumpDir}/req-${Date.now()}-${safeSessionId(sid)}.json`;
|
|
58104
57880
|
try {
|
|
58105
57881
|
const pretty = JSON.stringify(JSON.parse(body), null, 2);
|
|
58106
|
-
|
|
57882
|
+
fs7.writeFileSync(out, pretty);
|
|
58107
57883
|
} catch {
|
|
58108
|
-
|
|
57884
|
+
fs7.writeFileSync(out, body);
|
|
58109
57885
|
}
|
|
58110
57886
|
log2("info", `[debug] forwarded body written to ${out}`);
|
|
58111
57887
|
}
|
|
@@ -58125,7 +57901,7 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
|
|
|
58125
57901
|
const rawBase = bodyDumpEnabled() ? (() => {
|
|
58126
57902
|
try {
|
|
58127
57903
|
const rawDir = process.env.ACP_RAW_DUMP_DIR || `${stateDir()}/raw`;
|
|
58128
|
-
|
|
57904
|
+
fs7.mkdirSync(rawDir, { recursive: true });
|
|
58129
57905
|
return `${rawDir}/${Date.now()}-${safeSessionId(prepared?.session.id)}`;
|
|
58130
57906
|
} catch {
|
|
58131
57907
|
return "";
|
|
@@ -58136,7 +57912,7 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
|
|
|
58136
57912
|
const hdrText = Object.entries(maskHeadersForLog(headers)).map(([k2, v2]) => `${k2}: ${v2}`).join("\n");
|
|
58137
57913
|
const bodyText = req.method === "GET" || req.method === "HEAD" ? "" : typeof body === "string" ? body : Buffer.from(body).toString("utf8");
|
|
58138
57914
|
const reqPath = `${rawBase}-REQ.txt`;
|
|
58139
|
-
|
|
57915
|
+
fs7.writeFileSync(reqPath, `${req.method ?? "POST"} ${maskUrlForLog(upstreamUrl)}
|
|
58140
57916
|
${hdrText}
|
|
58141
57917
|
|
|
58142
57918
|
${bodyText}`);
|
|
@@ -58186,7 +57962,7 @@ ${bodyText}`);
|
|
|
58186
57962
|
try {
|
|
58187
57963
|
const hdrText = Object.entries(maskHeadersForLog(respHeaders)).map(([k2, v2]) => `${k2}: ${v2}`).join("\n");
|
|
58188
57964
|
const resPath = `${rawBase}-RES.txt`;
|
|
58189
|
-
|
|
57965
|
+
fs7.writeFileSync(resPath, `${upstream.status}
|
|
58190
57966
|
${hdrText}
|
|
58191
57967
|
`);
|
|
58192
57968
|
log2("info", `[debug] RAW response dump: ${resPath}`);
|
|
@@ -60602,7 +60378,7 @@ var hr = /* @__PURE__ */ Symbol("entry");
|
|
|
60602
60378
|
var cs = /* @__PURE__ */ Symbol("entryOpt");
|
|
60603
60379
|
var ui = /* @__PURE__ */ Symbol("writeEntryClass");
|
|
60604
60380
|
var lr = /* @__PURE__ */ Symbol("write");
|
|
60605
|
-
var
|
|
60381
|
+
var fs8 = /* @__PURE__ */ Symbol("ondrain");
|
|
60606
60382
|
var wt = class extends A {
|
|
60607
60383
|
sync = false;
|
|
60608
60384
|
opt;
|
|
@@ -60636,8 +60412,8 @@ var wt = class extends A {
|
|
|
60636
60412
|
if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive");
|
|
60637
60413
|
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");
|
|
60638
60414
|
let e = this.zip;
|
|
60639
|
-
e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[
|
|
60640
|
-
} else this.on("drain", this[
|
|
60415
|
+
e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs8]()), this.on("resume", () => e.resume());
|
|
60416
|
+
} else this.on("drain", this[fs8]);
|
|
60641
60417
|
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;
|
|
60642
60418
|
}
|
|
60643
60419
|
[lr](t) {
|
|
@@ -60750,7 +60526,7 @@ var wt = class extends A {
|
|
|
60750
60526
|
this.emit("error", e);
|
|
60751
60527
|
}
|
|
60752
60528
|
}
|
|
60753
|
-
[
|
|
60529
|
+
[fs8]() {
|
|
60754
60530
|
this[Et] && this[Et].entry && this[Et].entry.resume();
|
|
60755
60531
|
}
|
|
60756
60532
|
[di](t) {
|
|
@@ -61635,17 +61411,17 @@ var To = (s3) => {
|
|
|
61635
61411
|
};
|
|
61636
61412
|
|
|
61637
61413
|
// src/update.ts
|
|
61638
|
-
import
|
|
61414
|
+
import path11 from "path";
|
|
61639
61415
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
61640
61416
|
var REGISTRY_BASE = "https://registry.npmjs.org";
|
|
61641
61417
|
var CHECK_INTERVAL_MS = 3 * 60 * 1e3;
|
|
61642
|
-
var THROTTLE_FILE =
|
|
61643
|
-
var LOCK_FILE =
|
|
61418
|
+
var THROTTLE_FILE = path11.join(cacheDir(), ".update-check");
|
|
61419
|
+
var LOCK_FILE = path11.join(cacheDir(), ".update-lock");
|
|
61644
61420
|
var LOCK_MAX_AGE_MS = 30 * 60 * 1e3;
|
|
61645
61421
|
function shouldStealLock(holderAlive, ageMs) {
|
|
61646
61422
|
return !holderAlive || ageMs >= LOCK_MAX_AGE_MS;
|
|
61647
61423
|
}
|
|
61648
|
-
var
|
|
61424
|
+
var timer;
|
|
61649
61425
|
var inFlight = false;
|
|
61650
61426
|
var firstCheckDone = false;
|
|
61651
61427
|
function parseVersion(v2) {
|
|
@@ -61675,27 +61451,27 @@ async function readLastCheck() {
|
|
|
61675
61451
|
}
|
|
61676
61452
|
async function writeLastCheck(ts2) {
|
|
61677
61453
|
try {
|
|
61678
|
-
await mkdir2(
|
|
61454
|
+
await mkdir2(path11.dirname(THROTTLE_FILE), { recursive: true });
|
|
61679
61455
|
await writeFile2(THROTTLE_FILE, String(ts2), "utf-8");
|
|
61680
61456
|
} catch {
|
|
61681
61457
|
}
|
|
61682
61458
|
}
|
|
61683
61459
|
async function findInstallDir(packageName) {
|
|
61684
|
-
let dir =
|
|
61460
|
+
let dir = path11.dirname(fileURLToPath3(import.meta.url));
|
|
61685
61461
|
for (; ; ) {
|
|
61686
61462
|
try {
|
|
61687
|
-
const pkg = JSON.parse(await readFile2(
|
|
61463
|
+
const pkg = JSON.parse(await readFile2(path11.join(dir, "package.json"), "utf-8"));
|
|
61688
61464
|
if (pkg.name === packageName) return dir;
|
|
61689
61465
|
} catch {
|
|
61690
61466
|
}
|
|
61691
|
-
const parent =
|
|
61467
|
+
const parent = path11.dirname(dir);
|
|
61692
61468
|
if (parent === dir) return void 0;
|
|
61693
61469
|
dir = parent;
|
|
61694
61470
|
}
|
|
61695
61471
|
}
|
|
61696
61472
|
async function readDiskVersion(installDir) {
|
|
61697
61473
|
try {
|
|
61698
|
-
const pkg = JSON.parse(await readFile2(
|
|
61474
|
+
const pkg = JSON.parse(await readFile2(path11.join(installDir, "package.json"), "utf-8"));
|
|
61699
61475
|
return pkg.version;
|
|
61700
61476
|
} catch {
|
|
61701
61477
|
return void 0;
|
|
@@ -61732,13 +61508,13 @@ async function syntaxCheckEntry(entryAbs) {
|
|
|
61732
61508
|
} catch (e) {
|
|
61733
61509
|
return `entry unreadable: ${String(e)}`;
|
|
61734
61510
|
}
|
|
61735
|
-
const tmpCheck =
|
|
61511
|
+
const tmpCheck = path11.join(cacheDir(), ".update-syntax-check.mjs");
|
|
61736
61512
|
try {
|
|
61737
61513
|
await mkdir2(cacheDir(), { recursive: true });
|
|
61738
61514
|
await writeFile2(tmpCheck, source);
|
|
61739
61515
|
const r = await runNodeCheck(tmpCheck);
|
|
61740
61516
|
if (r.code !== 0) {
|
|
61741
|
-
return `entry does not parse (${
|
|
61517
|
+
return `entry does not parse (${path11.basename(entryAbs)}): ${r.stderr.split("\n").filter(Boolean).slice(0, 3).join(" | ").slice(0, 300)}`;
|
|
61742
61518
|
}
|
|
61743
61519
|
return null;
|
|
61744
61520
|
} finally {
|
|
@@ -61751,7 +61527,7 @@ async function syntaxCheckEntry(entryAbs) {
|
|
|
61751
61527
|
async function verifyEntries(dir, label) {
|
|
61752
61528
|
let pkg;
|
|
61753
61529
|
try {
|
|
61754
|
-
pkg = JSON.parse(await readFile2(
|
|
61530
|
+
pkg = JSON.parse(await readFile2(path11.join(dir, "package.json"), "utf-8"));
|
|
61755
61531
|
} catch (e) {
|
|
61756
61532
|
return `${label}: package.json unreadable: ${String(e)}`;
|
|
61757
61533
|
}
|
|
@@ -61761,11 +61537,11 @@ async function verifyEntries(dir, label) {
|
|
|
61761
61537
|
}
|
|
61762
61538
|
for (const rel2 of entries) {
|
|
61763
61539
|
try {
|
|
61764
|
-
await access(
|
|
61540
|
+
await access(path11.join(dir, rel2));
|
|
61765
61541
|
} catch {
|
|
61766
61542
|
return `${label}: entry missing: ${rel2}`;
|
|
61767
61543
|
}
|
|
61768
|
-
const reason = await syntaxCheckEntry(
|
|
61544
|
+
const reason = await syntaxCheckEntry(path11.join(dir, rel2));
|
|
61769
61545
|
if (reason) return `${label}: ${reason}`;
|
|
61770
61546
|
}
|
|
61771
61547
|
return null;
|
|
@@ -61970,14 +61746,14 @@ async function installViaTarball(version2, tarballUrl, installDir, integrity, sh
|
|
|
61970
61746
|
if (!v2.ok) {
|
|
61971
61747
|
return { ok: false, error: `tarball integrity verification failed: ${v2.error}` };
|
|
61972
61748
|
}
|
|
61973
|
-
const tmpFile =
|
|
61749
|
+
const tmpFile = path11.join(cacheDir(), `.update-${version2}.tgz`);
|
|
61974
61750
|
try {
|
|
61975
61751
|
await mkdir2(cacheDir(), { recursive: true });
|
|
61976
61752
|
await writeFile2(tmpFile, tgzBuffer);
|
|
61977
61753
|
} catch (e) {
|
|
61978
61754
|
return { ok: false, error: `failed to write temp file ${tmpFile}: ${String(e)}` };
|
|
61979
61755
|
}
|
|
61980
|
-
const stagingDir =
|
|
61756
|
+
const stagingDir = path11.join(cacheDir(), `.update-staging-${version2}`);
|
|
61981
61757
|
try {
|
|
61982
61758
|
await rm2(stagingDir, { recursive: true, force: true });
|
|
61983
61759
|
await mkdir2(stagingDir, { recursive: true });
|
|
@@ -61999,7 +61775,7 @@ async function installViaTarball(version2, tarballUrl, installDir, integrity, sh
|
|
|
61999
61775
|
} finally {
|
|
62000
61776
|
await rm2(tmpFile, { force: true });
|
|
62001
61777
|
}
|
|
62002
|
-
const backupDir =
|
|
61778
|
+
const backupDir = path11.join(cacheDir(), `.update-backup-${version2}`);
|
|
62003
61779
|
try {
|
|
62004
61780
|
await rm2(backupDir, { recursive: true, force: true });
|
|
62005
61781
|
await cp(installDir, backupDir, { recursive: true, force: true });
|
|
@@ -62048,21 +61824,21 @@ function startAutoUpdate(opts) {
|
|
|
62048
61824
|
setTimeout(() => {
|
|
62049
61825
|
void checkForUpdate(opts);
|
|
62050
61826
|
}, 1e4);
|
|
62051
|
-
|
|
61827
|
+
timer = setInterval(() => {
|
|
62052
61828
|
void checkForUpdate(opts);
|
|
62053
61829
|
}, CHECK_INTERVAL_MS);
|
|
62054
|
-
|
|
61830
|
+
timer.unref?.();
|
|
62055
61831
|
}
|
|
62056
61832
|
|
|
62057
61833
|
// src/mcp.ts
|
|
62058
|
-
import
|
|
62059
|
-
import
|
|
61834
|
+
import fs9 from "fs";
|
|
61835
|
+
import path12 from "path";
|
|
62060
61836
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
62061
61837
|
var VERSION2 = (() => {
|
|
62062
61838
|
try {
|
|
62063
61839
|
const here = fileURLToPath4(import.meta.url);
|
|
62064
|
-
const pkg =
|
|
62065
|
-
return JSON.parse(
|
|
61840
|
+
const pkg = path12.join(path12.dirname(here), "..", "package.json");
|
|
61841
|
+
return JSON.parse(fs9.readFileSync(pkg, "utf8")).version ?? "dev";
|
|
62066
61842
|
} catch {
|
|
62067
61843
|
return "dev";
|
|
62068
61844
|
}
|
|
@@ -62231,8 +62007,8 @@ if (process.argv[1] && /(?:^|[\\/])mcp\.(?:ts|js)$/.test(process.argv[1])) {
|
|
|
62231
62007
|
}
|
|
62232
62008
|
|
|
62233
62009
|
// src/plugin-install.ts
|
|
62234
|
-
import
|
|
62235
|
-
import
|
|
62010
|
+
import fs10 from "fs";
|
|
62011
|
+
import path13 from "path";
|
|
62236
62012
|
import os4 from "os";
|
|
62237
62013
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
62238
62014
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -62251,22 +62027,22 @@ function proxyOriginForInstall() {
|
|
|
62251
62027
|
var PLUGIN_AGENTS = ["pi", "omp", "claude", "codex", "opencode"];
|
|
62252
62028
|
function selfPackageRoot() {
|
|
62253
62029
|
const here = fileURLToPath5(import.meta.url);
|
|
62254
|
-
return
|
|
62030
|
+
return path13.resolve(path13.dirname(here), "..");
|
|
62255
62031
|
}
|
|
62256
62032
|
function homeFile(rel2, envOverride) {
|
|
62257
62033
|
const raw = (envOverride !== void 0 ? process.env[envOverride] : void 0)?.trim();
|
|
62258
62034
|
const base = raw && raw.length > 0 ? raw : os4.homedir();
|
|
62259
|
-
return
|
|
62035
|
+
return path13.join(base, rel2);
|
|
62260
62036
|
}
|
|
62261
62037
|
function backupOnce(file) {
|
|
62262
|
-
if (
|
|
62263
|
-
|
|
62038
|
+
if (fs10.existsSync(file) && !fs10.existsSync(`${file}.bili-bak`)) {
|
|
62039
|
+
fs10.copyFileSync(file, `${file}.bili-bak`);
|
|
62264
62040
|
}
|
|
62265
62041
|
}
|
|
62266
62042
|
function readJson(file) {
|
|
62267
62043
|
let text;
|
|
62268
62044
|
try {
|
|
62269
|
-
text =
|
|
62045
|
+
text = fs10.readFileSync(file, "utf8");
|
|
62270
62046
|
} catch (err2) {
|
|
62271
62047
|
if (err2.code === "ENOENT") return {};
|
|
62272
62048
|
throw err2;
|
|
@@ -62275,7 +62051,7 @@ function readJson(file) {
|
|
|
62275
62051
|
try {
|
|
62276
62052
|
parsed = JSON.parse(text);
|
|
62277
62053
|
} catch (err2) {
|
|
62278
|
-
throw new Error(`${file}: not valid JSON (${err2 instanceof Error ? err2.message : String(err2)}) \u2014 fix it or restore ${
|
|
62054
|
+
throw new Error(`${file}: not valid JSON (${err2 instanceof Error ? err2.message : String(err2)}) \u2014 fix it or restore ${path13.basename(file)}.bili-bak first; refusing to overwrite`);
|
|
62279
62055
|
}
|
|
62280
62056
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
62281
62057
|
throw new Error(`${file}: expected a JSON object at top level, refusing to overwrite`);
|
|
@@ -62283,18 +62059,18 @@ function readJson(file) {
|
|
|
62283
62059
|
return parsed;
|
|
62284
62060
|
}
|
|
62285
62061
|
function writeJson(file, data) {
|
|
62286
|
-
|
|
62062
|
+
fs10.mkdirSync(path13.dirname(file), { recursive: true });
|
|
62287
62063
|
backupOnce(file);
|
|
62288
|
-
|
|
62064
|
+
fs10.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
|
|
62289
62065
|
}
|
|
62290
62066
|
function requireDistFile(file) {
|
|
62291
|
-
if (!
|
|
62067
|
+
if (!fs10.existsSync(file)) {
|
|
62292
62068
|
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
|
|
62293
62069
|
`);
|
|
62294
62070
|
}
|
|
62295
62071
|
}
|
|
62296
62072
|
function piSettingsFile() {
|
|
62297
|
-
return
|
|
62073
|
+
return path13.join(resolvePiHome(process.env), "settings.json");
|
|
62298
62074
|
}
|
|
62299
62075
|
function isPiEntry(entry, root) {
|
|
62300
62076
|
return entry === root || /^npm:billion-context(-pi)?(@|$)/.test(entry) || /(^|[/\\])node_modules[/\\]billion-context(-pi)?([\/\\]|$)/.test(entry) || /(^|[/\\])billion-context(-pi)?$/.test(entry);
|
|
@@ -62360,14 +62136,14 @@ function ompConfigFile() {
|
|
|
62360
62136
|
`bili plugin: PI_CODING_AGENT_DIR points at the bili overlay ${raw} \u2014 operating on the real omp home ${realHome} instead
|
|
62361
62137
|
`
|
|
62362
62138
|
);
|
|
62363
|
-
return
|
|
62139
|
+
return path13.join(realHome, "config.yml");
|
|
62364
62140
|
}
|
|
62365
|
-
return
|
|
62141
|
+
return path13.join(raw, "config.yml");
|
|
62366
62142
|
}
|
|
62367
|
-
return
|
|
62143
|
+
return path13.join(os4.homedir(), ".omp", "agent", "config.yml");
|
|
62368
62144
|
}
|
|
62369
62145
|
function ompExtensionPath() {
|
|
62370
|
-
return
|
|
62146
|
+
return path13.join(selfPackageRoot(), "dist", "agent", "omp.js");
|
|
62371
62147
|
}
|
|
62372
62148
|
function ompEntryValue(line) {
|
|
62373
62149
|
return line.replace(/#.*$/, "").trim().replace(/^-\s*/, "").replace(/^["']|["']$/g, "").trim();
|
|
@@ -62376,13 +62152,13 @@ function ompBlockLoaded(text) {
|
|
|
62376
62152
|
const lines = text.split("\n");
|
|
62377
62153
|
return ompExtensionItemLines(text).some((i) => {
|
|
62378
62154
|
const v2 = ompEntryValue(lines[i]);
|
|
62379
|
-
return OMP_ENTRY_RE.test(v2) &&
|
|
62155
|
+
return OMP_ENTRY_RE.test(v2) && fs10.existsSync(v2);
|
|
62380
62156
|
});
|
|
62381
62157
|
}
|
|
62382
62158
|
function ompRemove() {
|
|
62383
62159
|
const file = ompConfigFile();
|
|
62384
|
-
if (!
|
|
62385
|
-
const text =
|
|
62160
|
+
if (!fs10.existsSync(file)) return `omp: not installed (${file})`;
|
|
62161
|
+
const text = fs10.readFileSync(file, "utf8");
|
|
62386
62162
|
const lines = text.split("\n");
|
|
62387
62163
|
const drop = new Set(
|
|
62388
62164
|
ompExtensionItemLines(text).filter((i) => OMP_ENTRY_RE.test(ompEntryValue(lines[i])))
|
|
@@ -62390,15 +62166,15 @@ function ompRemove() {
|
|
|
62390
62166
|
if (drop.size === 0) return `omp: not installed (${file})`;
|
|
62391
62167
|
const cleaned = lines.filter((_2, i) => !drop.has(i)).join("\n");
|
|
62392
62168
|
backupOnce(file);
|
|
62393
|
-
|
|
62169
|
+
fs10.writeFileSync(file, cleaned);
|
|
62394
62170
|
return `omp: removed from ${file}`;
|
|
62395
62171
|
}
|
|
62396
62172
|
function ompInstall() {
|
|
62397
62173
|
const file = ompConfigFile();
|
|
62398
62174
|
const entry = ompExtensionPath();
|
|
62399
62175
|
requireDistFile(entry);
|
|
62400
|
-
|
|
62401
|
-
let text =
|
|
62176
|
+
fs10.mkdirSync(path13.dirname(file), { recursive: true });
|
|
62177
|
+
let text = fs10.existsSync(file) ? fs10.readFileSync(file, "utf8") : "";
|
|
62402
62178
|
if (ompBlockLoaded(text)) return `omp: already installed (${file})`;
|
|
62403
62179
|
{
|
|
62404
62180
|
const lines = text.split("\n");
|
|
@@ -62440,25 +62216,25 @@ ${tail}`;
|
|
|
62440
62216
|
throw new Error(`${file}: edit would leave ${occurrences} copies of the entry \u2014 aborting without writing`);
|
|
62441
62217
|
}
|
|
62442
62218
|
backupOnce(file);
|
|
62443
|
-
|
|
62219
|
+
fs10.writeFileSync(file, out);
|
|
62444
62220
|
return `omp: installed -> ${file} extensions += ${entry}`;
|
|
62445
62221
|
}
|
|
62446
62222
|
function ompStatus() {
|
|
62447
62223
|
const file = ompConfigFile();
|
|
62448
|
-
const text =
|
|
62224
|
+
const text = fs10.existsSync(file) ? fs10.readFileSync(file, "utf8") : "";
|
|
62449
62225
|
const lines = text.split("\n");
|
|
62450
62226
|
let broken = false;
|
|
62451
62227
|
for (const i of ompExtensionItemLines(text)) {
|
|
62452
62228
|
const v2 = ompEntryValue(lines[i]);
|
|
62453
62229
|
if (!OMP_ENTRY_RE.test(v2)) continue;
|
|
62454
|
-
if (
|
|
62230
|
+
if (fs10.existsSync(v2)) return "installed";
|
|
62455
62231
|
broken = true;
|
|
62456
62232
|
}
|
|
62457
62233
|
return broken ? "broken" : "not installed";
|
|
62458
62234
|
}
|
|
62459
62235
|
function ompPluginLoadedFrom(ompHome) {
|
|
62460
62236
|
try {
|
|
62461
|
-
return ompBlockLoaded(
|
|
62237
|
+
return ompBlockLoaded(fs10.readFileSync(path13.join(ompHome, "config.yml"), "utf8"));
|
|
62462
62238
|
} catch {
|
|
62463
62239
|
return false;
|
|
62464
62240
|
}
|
|
@@ -62469,7 +62245,7 @@ function claudeMcpJson() {
|
|
|
62469
62245
|
}
|
|
62470
62246
|
function claudeInstall() {
|
|
62471
62247
|
const root = selfPackageRoot();
|
|
62472
|
-
const mcpJs =
|
|
62248
|
+
const mcpJs = path13.join(root, "dist", "mcp.js");
|
|
62473
62249
|
requireDistFile(mcpJs);
|
|
62474
62250
|
const claude = process.env.CLAUDE?.trim() || "claude";
|
|
62475
62251
|
try {
|
|
@@ -62496,38 +62272,38 @@ function claudeStatus() {
|
|
|
62496
62272
|
}
|
|
62497
62273
|
function codexToml() {
|
|
62498
62274
|
const raw = process.env.CODEX_HOME?.trim();
|
|
62499
|
-
if (raw && raw.length > 0) return
|
|
62275
|
+
if (raw && raw.length > 0) return path13.join(raw, "config.toml");
|
|
62500
62276
|
return homeFile(".codex/config.toml");
|
|
62501
62277
|
}
|
|
62502
62278
|
function codexBlock() {
|
|
62503
62279
|
return `
|
|
62504
62280
|
[mcp_servers.bili]
|
|
62505
62281
|
command = ${JSON.stringify(process.execPath)}
|
|
62506
|
-
args = [${JSON.stringify(
|
|
62282
|
+
args = [${JSON.stringify(path13.join(selfPackageRoot(), "dist", "mcp.js"))}]
|
|
62507
62283
|
env = { BILI_MCP_PROXY = ${JSON.stringify(proxyOriginForInstall())} }
|
|
62508
62284
|
`;
|
|
62509
62285
|
}
|
|
62510
62286
|
function codexInstall() {
|
|
62511
62287
|
const file = codexToml();
|
|
62512
|
-
const text =
|
|
62288
|
+
const text = fs10.existsSync(file) ? fs10.readFileSync(file, "utf8") : "";
|
|
62513
62289
|
const existing = /^[ \t]*\[mcp_servers\.bili\][ \t]*$/m.exec(text);
|
|
62514
62290
|
if (existing !== null) {
|
|
62515
62291
|
const block = text.slice(existing.index, text.indexOf("\n[", existing.index + 1) === -1 ? void 0 : text.indexOf("\n[", existing.index + 1));
|
|
62516
62292
|
if (block.includes(`BILI_MCP_PROXY = ${JSON.stringify(proxyOriginForInstall())}`)) return `codex: already installed (${file})`;
|
|
62517
62293
|
const refreshed = text.slice(0, existing.index) + codexBlock().replace(/^\n/, "") + text.slice(existing.index + block.length);
|
|
62518
62294
|
backupOnce(file);
|
|
62519
|
-
|
|
62295
|
+
fs10.writeFileSync(file, refreshed);
|
|
62520
62296
|
return `codex: refreshed proxy origin -> ${file} [mcp_servers.bili]`;
|
|
62521
62297
|
}
|
|
62522
|
-
|
|
62298
|
+
fs10.mkdirSync(path13.dirname(file), { recursive: true });
|
|
62523
62299
|
backupOnce(file);
|
|
62524
|
-
|
|
62300
|
+
fs10.writeFileSync(file, text + (text.endsWith("\n") || text.length === 0 ? "" : "\n") + codexBlock());
|
|
62525
62301
|
return `codex: installed -> ${file} [mcp_servers.bili]`;
|
|
62526
62302
|
}
|
|
62527
62303
|
function codexRemove() {
|
|
62528
62304
|
const file = codexToml();
|
|
62529
|
-
if (!
|
|
62530
|
-
const text =
|
|
62305
|
+
if (!fs10.existsSync(file)) return `codex: not installed (${file})`;
|
|
62306
|
+
const text = fs10.readFileSync(file, "utf8");
|
|
62531
62307
|
const start = (() => {
|
|
62532
62308
|
const m2 = /^[ \t]*\[mcp_servers\.bili\][ \t]*$/m.exec(text);
|
|
62533
62309
|
return m2 === null ? -1 : m2.index;
|
|
@@ -62540,23 +62316,23 @@ function codexRemove() {
|
|
|
62540
62316
|
const end = nextTable >= 0 ? start + firstNewline + 1 + nextTable : text.length;
|
|
62541
62317
|
const cleaned = (text.slice(0, lineStart).replace(/\n+$/, "\n") + text.slice(end)).replace(/^\n+/, "");
|
|
62542
62318
|
backupOnce(file);
|
|
62543
|
-
|
|
62319
|
+
fs10.writeFileSync(file, cleaned);
|
|
62544
62320
|
return `codex: removed from ${file}`;
|
|
62545
62321
|
}
|
|
62546
62322
|
function codexStatus() {
|
|
62547
|
-
const text =
|
|
62323
|
+
const text = fs10.existsSync(codexToml()) ? fs10.readFileSync(codexToml(), "utf8") : "";
|
|
62548
62324
|
return /^\[mcp_servers\.bili\]\s*$/m.test(text) ? "installed" : "not installed";
|
|
62549
62325
|
}
|
|
62550
62326
|
function opencodeJson() {
|
|
62551
62327
|
const raw = process.env.OPENCODE_CONFIG?.trim();
|
|
62552
62328
|
if (raw && raw.length > 0) return raw;
|
|
62553
62329
|
const xdg2 = process.env.XDG_CONFIG_HOME?.trim();
|
|
62554
|
-
if (xdg2 && xdg2.length > 0) return
|
|
62555
|
-
return
|
|
62330
|
+
if (xdg2 && xdg2.length > 0) return path13.join(xdg2, "opencode/opencode.json");
|
|
62331
|
+
return path13.join(os4.homedir(), ".config", "opencode", "opencode.json");
|
|
62556
62332
|
}
|
|
62557
62333
|
function opencodeInstall() {
|
|
62558
62334
|
const file = opencodeJson();
|
|
62559
|
-
const mcpJs =
|
|
62335
|
+
const mcpJs = path13.join(selfPackageRoot(), "dist", "mcp.js");
|
|
62560
62336
|
requireDistFile(mcpJs);
|
|
62561
62337
|
const data = readJson(file);
|
|
62562
62338
|
const mcp = data.mcp ?? {};
|
|
@@ -62608,14 +62384,14 @@ function pluginStatusAll() {
|
|
|
62608
62384
|
|
|
62609
62385
|
// src/launcher.ts
|
|
62610
62386
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
62611
|
-
import
|
|
62387
|
+
import fs11 from "fs";
|
|
62612
62388
|
import net2 from "net";
|
|
62613
62389
|
import os5 from "os";
|
|
62614
|
-
import
|
|
62390
|
+
import path14 from "path";
|
|
62615
62391
|
import { pathToFileURL } from "url";
|
|
62616
62392
|
import { spawn } from "child_process";
|
|
62617
62393
|
function selfDistFile(name) {
|
|
62618
|
-
return
|
|
62394
|
+
return path14.join(selfPackageRoot(), "dist", name);
|
|
62619
62395
|
}
|
|
62620
62396
|
var LAUNCHER_DEFAULT_HOST = "127.0.0.1";
|
|
62621
62397
|
var LAUNCHER_DEFAULT_PORT = 8787;
|
|
@@ -62651,12 +62427,12 @@ function unwrapUpstream2(url) {
|
|
|
62651
62427
|
return idx >= 0 ? url.slice(idx + "/bili/".length) : url;
|
|
62652
62428
|
}
|
|
62653
62429
|
function resolveCaCertPath(env) {
|
|
62654
|
-
const base = env.XDG_DATA_HOME ||
|
|
62655
|
-
return
|
|
62430
|
+
const base = env.XDG_DATA_HOME || path14.join(os5.homedir(), ".local/share");
|
|
62431
|
+
return path14.join(base, "billion-context", "ca", "root-ca.pem");
|
|
62656
62432
|
}
|
|
62657
62433
|
function resolveCombinedCaPath(env) {
|
|
62658
|
-
const base = env.XDG_DATA_HOME ||
|
|
62659
|
-
return
|
|
62434
|
+
const base = env.XDG_DATA_HOME || path14.join(os5.homedir(), ".local/share");
|
|
62435
|
+
return path14.join(base, "billion-context", "ca", "combined-ca.pem");
|
|
62660
62436
|
}
|
|
62661
62437
|
function discoverRoutes(client, config) {
|
|
62662
62438
|
const httpsDomains = [];
|
|
@@ -62889,12 +62665,12 @@ function buildCodexMcpArgs(origin, conversationId2) {
|
|
|
62889
62665
|
];
|
|
62890
62666
|
}
|
|
62891
62667
|
function overlayLockPath(overlay) {
|
|
62892
|
-
return
|
|
62668
|
+
return path14.join(overlay, ".bili-launch.pid");
|
|
62893
62669
|
}
|
|
62894
62670
|
function livePidHoldsOverlay(overlay) {
|
|
62895
62671
|
let raw;
|
|
62896
62672
|
try {
|
|
62897
|
-
raw =
|
|
62673
|
+
raw = fs11.readFileSync(overlayLockPath(overlay), "utf8");
|
|
62898
62674
|
} catch {
|
|
62899
62675
|
return void 0;
|
|
62900
62676
|
}
|
|
@@ -62908,17 +62684,17 @@ function livePidHoldsOverlay(overlay) {
|
|
|
62908
62684
|
return pid;
|
|
62909
62685
|
}
|
|
62910
62686
|
function linkOverlayEntry(realHome, overlay, entry) {
|
|
62911
|
-
const target =
|
|
62912
|
-
const link =
|
|
62687
|
+
const target = path14.join(realHome, entry);
|
|
62688
|
+
const link = path14.join(overlay, entry);
|
|
62913
62689
|
let st2;
|
|
62914
62690
|
try {
|
|
62915
|
-
st2 =
|
|
62691
|
+
st2 = fs11.lstatSync(target);
|
|
62916
62692
|
} catch {
|
|
62917
62693
|
return false;
|
|
62918
62694
|
}
|
|
62919
62695
|
const kind = st2.isDirectory() ? process.platform === "win32" ? "junction" : "dir" : "file";
|
|
62920
62696
|
try {
|
|
62921
|
-
|
|
62697
|
+
fs11.symlinkSync(target, link, kind);
|
|
62922
62698
|
return true;
|
|
62923
62699
|
} catch (err2) {
|
|
62924
62700
|
const code = err2.code;
|
|
@@ -62926,18 +62702,18 @@ function linkOverlayEntry(realHome, overlay, entry) {
|
|
|
62926
62702
|
}
|
|
62927
62703
|
if (st2.isDirectory()) {
|
|
62928
62704
|
try {
|
|
62929
|
-
|
|
62705
|
+
fs11.symlinkSync(target, link, "junction");
|
|
62930
62706
|
return true;
|
|
62931
62707
|
} catch {
|
|
62932
62708
|
return false;
|
|
62933
62709
|
}
|
|
62934
62710
|
}
|
|
62935
62711
|
try {
|
|
62936
|
-
|
|
62712
|
+
fs11.linkSync(target, link);
|
|
62937
62713
|
return true;
|
|
62938
62714
|
} catch {
|
|
62939
62715
|
try {
|
|
62940
|
-
|
|
62716
|
+
fs11.copyFileSync(target, link);
|
|
62941
62717
|
return true;
|
|
62942
62718
|
} catch {
|
|
62943
62719
|
return false;
|
|
@@ -62947,7 +62723,7 @@ function linkOverlayEntry(realHome, overlay, entry) {
|
|
|
62947
62723
|
function isWriteThroughHardlink(overlayPath, realPath, st2) {
|
|
62948
62724
|
if (st2.isDirectory() || st2.isSymbolicLink() || st2.nlink <= 1) return false;
|
|
62949
62725
|
try {
|
|
62950
|
-
const realSt =
|
|
62726
|
+
const realSt = fs11.lstatSync(realPath);
|
|
62951
62727
|
return st2.dev === realSt.dev && st2.ino === realSt.ino;
|
|
62952
62728
|
} catch {
|
|
62953
62729
|
return false;
|
|
@@ -62961,7 +62737,7 @@ function freeConflictName(dst) {
|
|
|
62961
62737
|
let n = 1;
|
|
62962
62738
|
while (n < 1e5) {
|
|
62963
62739
|
try {
|
|
62964
|
-
|
|
62740
|
+
fs11.lstatSync(candidate);
|
|
62965
62741
|
candidate = `${dst}.bili-conflict.${n}`;
|
|
62966
62742
|
n += 1;
|
|
62967
62743
|
} catch {
|
|
@@ -62974,7 +62750,7 @@ function mergeSqliteSet(overlay, realHome, base) {
|
|
|
62974
62750
|
const members = sqliteSetMembers(base);
|
|
62975
62751
|
const statFile = (dir, m2) => {
|
|
62976
62752
|
try {
|
|
62977
|
-
const st2 =
|
|
62753
|
+
const st2 = fs11.lstatSync(path14.join(dir, m2));
|
|
62978
62754
|
return st2.isFile() ? st2 : void 0;
|
|
62979
62755
|
} catch {
|
|
62980
62756
|
return void 0;
|
|
@@ -63000,35 +62776,35 @@ function mergeSqliteSet(overlay, realHome, base) {
|
|
|
63000
62776
|
const movePreserving = (src, dst) => {
|
|
63001
62777
|
let dstStat;
|
|
63002
62778
|
try {
|
|
63003
|
-
dstStat =
|
|
62779
|
+
dstStat = fs11.lstatSync(dst);
|
|
63004
62780
|
} catch {
|
|
63005
62781
|
}
|
|
63006
62782
|
if (dstStat) {
|
|
63007
62783
|
if (dstStat.isDirectory()) throw new Error("target is a directory");
|
|
63008
62784
|
const conflict = freeConflictName(dst);
|
|
63009
|
-
|
|
63010
|
-
undo.push(() =>
|
|
62785
|
+
fs11.renameSync(dst, conflict);
|
|
62786
|
+
undo.push(() => fs11.renameSync(conflict, dst));
|
|
63011
62787
|
}
|
|
63012
|
-
|
|
63013
|
-
undo.push(() =>
|
|
62788
|
+
fs11.renameSync(src, dst);
|
|
62789
|
+
undo.push(() => fs11.renameSync(dst, src));
|
|
63014
62790
|
};
|
|
63015
62791
|
const preserveAsConflict = (src, name) => {
|
|
63016
|
-
const conflict = freeConflictName(
|
|
63017
|
-
|
|
63018
|
-
undo.push(() =>
|
|
62792
|
+
const conflict = freeConflictName(path14.join(realHome, name));
|
|
62793
|
+
fs11.renameSync(src, conflict);
|
|
62794
|
+
undo.push(() => fs11.renameSync(conflict, src));
|
|
63019
62795
|
};
|
|
63020
62796
|
try {
|
|
63021
62797
|
for (const m2 of members) {
|
|
63022
62798
|
const o = statFile(overlay, m2);
|
|
63023
62799
|
const r = statFile(realHome, m2);
|
|
63024
62800
|
if (winner === "overlay") {
|
|
63025
|
-
if (o) movePreserving(
|
|
63026
|
-
else if (r) preserveAsConflict(
|
|
62801
|
+
if (o) movePreserving(path14.join(overlay, m2), path14.join(realHome, m2));
|
|
62802
|
+
else if (r) preserveAsConflict(path14.join(realHome, m2), m2);
|
|
63027
62803
|
} else if (winner === "real") {
|
|
63028
|
-
if (o) preserveAsConflict(
|
|
62804
|
+
if (o) preserveAsConflict(path14.join(overlay, m2), m2);
|
|
63029
62805
|
} else {
|
|
63030
|
-
if (o) preserveAsConflict(
|
|
63031
|
-
else if (r) preserveAsConflict(
|
|
62806
|
+
if (o) preserveAsConflict(path14.join(overlay, m2), m2);
|
|
62807
|
+
else if (r) preserveAsConflict(path14.join(realHome, m2), m2);
|
|
63032
62808
|
}
|
|
63033
62809
|
}
|
|
63034
62810
|
return true;
|
|
@@ -63041,7 +62817,7 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
63041
62817
|
const generatedFiles = new Set(Array.isArray(generatedFile) ? generatedFile : [generatedFile]);
|
|
63042
62818
|
const isGeneratedDraft = (name) => [...generatedFiles].some((g2) => name.startsWith(`.${g2}.`) && name.endsWith(".tmp"));
|
|
63043
62819
|
try {
|
|
63044
|
-
|
|
62820
|
+
fs11.mkdirSync(overlay, { recursive: true });
|
|
63045
62821
|
} catch {
|
|
63046
62822
|
return false;
|
|
63047
62823
|
}
|
|
@@ -63052,19 +62828,19 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
63052
62828
|
);
|
|
63053
62829
|
}
|
|
63054
62830
|
try {
|
|
63055
|
-
|
|
62831
|
+
fs11.writeFileSync(overlayLockPath(overlay), `${process.pid}
|
|
63056
62832
|
`);
|
|
63057
62833
|
} catch {
|
|
63058
62834
|
}
|
|
63059
62835
|
const realEntries = /* @__PURE__ */ new Set();
|
|
63060
62836
|
try {
|
|
63061
|
-
for (const entry of
|
|
62837
|
+
for (const entry of fs11.readdirSync(realHome)) realEntries.add(entry);
|
|
63062
62838
|
} catch {
|
|
63063
62839
|
}
|
|
63064
62840
|
try {
|
|
63065
62841
|
let overlayEntries;
|
|
63066
62842
|
try {
|
|
63067
|
-
overlayEntries =
|
|
62843
|
+
overlayEntries = fs11.readdirSync(overlay);
|
|
63068
62844
|
} catch {
|
|
63069
62845
|
overlayEntries = [];
|
|
63070
62846
|
}
|
|
@@ -63075,10 +62851,10 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
63075
62851
|
if (!members.some((m2) => m2 !== entry && overlayEntries.includes(m2))) continue;
|
|
63076
62852
|
let mainSt;
|
|
63077
62853
|
try {
|
|
63078
|
-
mainSt =
|
|
62854
|
+
mainSt = fs11.lstatSync(path14.join(overlay, entry));
|
|
63079
62855
|
} catch {
|
|
63080
62856
|
}
|
|
63081
|
-
const keepSidecars = mainSt !== void 0 && isWriteThroughHardlink(
|
|
62857
|
+
const keepSidecars = mainSt !== void 0 && isWriteThroughHardlink(path14.join(overlay, entry), path14.join(realHome, entry), mainSt);
|
|
63082
62858
|
dbSets.push({ base: entry, keepSidecars });
|
|
63083
62859
|
}
|
|
63084
62860
|
const skipEntries = /* @__PURE__ */ new Set();
|
|
@@ -63089,10 +62865,10 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
63089
62865
|
}
|
|
63090
62866
|
for (const entry of overlayEntries) {
|
|
63091
62867
|
if (generatedFiles.has(entry)) continue;
|
|
63092
|
-
const overlayPath =
|
|
62868
|
+
const overlayPath = path14.join(overlay, entry);
|
|
63093
62869
|
if (isGeneratedDraft(entry)) {
|
|
63094
62870
|
try {
|
|
63095
|
-
|
|
62871
|
+
fs11.unlinkSync(overlayPath);
|
|
63096
62872
|
} catch {
|
|
63097
62873
|
}
|
|
63098
62874
|
continue;
|
|
@@ -63100,33 +62876,33 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
63100
62876
|
if (skipEntries.has(entry)) continue;
|
|
63101
62877
|
let st2;
|
|
63102
62878
|
try {
|
|
63103
|
-
st2 =
|
|
62879
|
+
st2 = fs11.lstatSync(overlayPath);
|
|
63104
62880
|
} catch {
|
|
63105
62881
|
continue;
|
|
63106
62882
|
}
|
|
63107
62883
|
if (st2.isSymbolicLink()) {
|
|
63108
62884
|
let target;
|
|
63109
62885
|
try {
|
|
63110
|
-
target =
|
|
62886
|
+
target = fs11.readlinkSync(overlayPath);
|
|
63111
62887
|
} catch {
|
|
63112
62888
|
}
|
|
63113
|
-
const wanted = realEntries.has(entry) ?
|
|
62889
|
+
const wanted = realEntries.has(entry) ? path14.join(realHome, entry) : void 0;
|
|
63114
62890
|
if (!wanted || target !== wanted) {
|
|
63115
62891
|
try {
|
|
63116
|
-
|
|
62892
|
+
fs11.unlinkSync(overlayPath);
|
|
63117
62893
|
} catch {
|
|
63118
62894
|
}
|
|
63119
62895
|
}
|
|
63120
62896
|
} else if (realEntries.has(entry)) {
|
|
63121
|
-
const realPath =
|
|
62897
|
+
const realPath = path14.join(realHome, entry);
|
|
63122
62898
|
if (isWriteThroughHardlink(overlayPath, realPath, st2)) {
|
|
63123
62899
|
try {
|
|
63124
|
-
|
|
62900
|
+
fs11.unlinkSync(overlayPath);
|
|
63125
62901
|
} catch {
|
|
63126
62902
|
}
|
|
63127
62903
|
} else if (mergeOverlayEntry(overlayPath, realPath, generatedFiles)) {
|
|
63128
62904
|
try {
|
|
63129
|
-
|
|
62905
|
+
fs11.rmSync(overlayPath, { recursive: true, force: true });
|
|
63130
62906
|
} catch {
|
|
63131
62907
|
}
|
|
63132
62908
|
} else {
|
|
@@ -63148,10 +62924,10 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
63148
62924
|
for (const entry of realEntries) {
|
|
63149
62925
|
if (generatedFiles.has(entry)) continue;
|
|
63150
62926
|
total += 1;
|
|
63151
|
-
const overlayPath =
|
|
62927
|
+
const overlayPath = path14.join(overlay, entry);
|
|
63152
62928
|
let present = false;
|
|
63153
62929
|
try {
|
|
63154
|
-
|
|
62930
|
+
fs11.lstatSync(overlayPath);
|
|
63155
62931
|
present = true;
|
|
63156
62932
|
} catch {
|
|
63157
62933
|
}
|
|
@@ -63183,45 +62959,45 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
|
63183
62959
|
function mergeOverlayEntry(src, dst, excludedNames) {
|
|
63184
62960
|
let st2;
|
|
63185
62961
|
try {
|
|
63186
|
-
st2 =
|
|
62962
|
+
st2 = fs11.lstatSync(src);
|
|
63187
62963
|
} catch {
|
|
63188
62964
|
return true;
|
|
63189
62965
|
}
|
|
63190
62966
|
let dstStat;
|
|
63191
62967
|
try {
|
|
63192
|
-
dstStat =
|
|
62968
|
+
dstStat = fs11.lstatSync(dst);
|
|
63193
62969
|
} catch {
|
|
63194
62970
|
}
|
|
63195
62971
|
if (st2.isDirectory()) {
|
|
63196
62972
|
if (dstStat && !dstStat.isDirectory()) {
|
|
63197
62973
|
try {
|
|
63198
|
-
|
|
62974
|
+
fs11.renameSync(dst, freeConflictName(dst));
|
|
63199
62975
|
dstStat = void 0;
|
|
63200
62976
|
} catch {
|
|
63201
62977
|
return false;
|
|
63202
62978
|
}
|
|
63203
62979
|
}
|
|
63204
62980
|
try {
|
|
63205
|
-
|
|
62981
|
+
fs11.mkdirSync(dst, { recursive: true });
|
|
63206
62982
|
} catch {
|
|
63207
62983
|
return false;
|
|
63208
62984
|
}
|
|
63209
62985
|
let entries;
|
|
63210
62986
|
try {
|
|
63211
|
-
entries =
|
|
62987
|
+
entries = fs11.readdirSync(src);
|
|
63212
62988
|
} catch {
|
|
63213
62989
|
return false;
|
|
63214
62990
|
}
|
|
63215
62991
|
let ok = true;
|
|
63216
62992
|
for (const entry of entries) {
|
|
63217
62993
|
if (excludedNames?.has(entry)) continue;
|
|
63218
|
-
if (!mergeOverlayEntry(
|
|
62994
|
+
if (!mergeOverlayEntry(path14.join(src, entry), path14.join(dst, entry), excludedNames)) ok = false;
|
|
63219
62995
|
}
|
|
63220
62996
|
return ok;
|
|
63221
62997
|
}
|
|
63222
62998
|
if (dstStat && dstStat.isDirectory()) {
|
|
63223
62999
|
try {
|
|
63224
|
-
|
|
63000
|
+
fs11.renameSync(src, freeConflictName(dst));
|
|
63225
63001
|
return true;
|
|
63226
63002
|
} catch {
|
|
63227
63003
|
return false;
|
|
@@ -63230,13 +63006,13 @@ function mergeOverlayEntry(src, dst, excludedNames) {
|
|
|
63230
63006
|
if (st2.isSymbolicLink()) {
|
|
63231
63007
|
if (dstStat) {
|
|
63232
63008
|
try {
|
|
63233
|
-
|
|
63009
|
+
fs11.unlinkSync(src);
|
|
63234
63010
|
} catch {
|
|
63235
63011
|
}
|
|
63236
63012
|
return true;
|
|
63237
63013
|
}
|
|
63238
63014
|
try {
|
|
63239
|
-
|
|
63015
|
+
fs11.renameSync(src, dst);
|
|
63240
63016
|
} catch {
|
|
63241
63017
|
return false;
|
|
63242
63018
|
}
|
|
@@ -63244,7 +63020,7 @@ function mergeOverlayEntry(src, dst, excludedNames) {
|
|
|
63244
63020
|
}
|
|
63245
63021
|
if (dstStat && dstStat.mtimeMs >= st2.mtimeMs) {
|
|
63246
63022
|
try {
|
|
63247
|
-
|
|
63023
|
+
fs11.renameSync(src, freeConflictName(dst));
|
|
63248
63024
|
return true;
|
|
63249
63025
|
} catch {
|
|
63250
63026
|
return false;
|
|
@@ -63252,13 +63028,13 @@ function mergeOverlayEntry(src, dst, excludedNames) {
|
|
|
63252
63028
|
}
|
|
63253
63029
|
if (dstStat) {
|
|
63254
63030
|
try {
|
|
63255
|
-
|
|
63031
|
+
fs11.renameSync(dst, freeConflictName(dst));
|
|
63256
63032
|
} catch {
|
|
63257
63033
|
return false;
|
|
63258
63034
|
}
|
|
63259
63035
|
}
|
|
63260
63036
|
try {
|
|
63261
|
-
|
|
63037
|
+
fs11.renameSync(src, dst);
|
|
63262
63038
|
return true;
|
|
63263
63039
|
} catch {
|
|
63264
63040
|
return false;
|
|
@@ -63268,7 +63044,7 @@ function piPluginInstalled(piHome) {
|
|
|
63268
63044
|
const root = selfPackageRoot();
|
|
63269
63045
|
if (!root) return false;
|
|
63270
63046
|
try {
|
|
63271
|
-
const parsed = JSON.parse(
|
|
63047
|
+
const parsed = JSON.parse(fs11.readFileSync(path14.join(piHome, "settings.json"), "utf8"));
|
|
63272
63048
|
const list = Array.isArray(parsed.packages) ? parsed.packages.map(String) : [];
|
|
63273
63049
|
return list.some((p2) => isBiliPiEntry(p2, root));
|
|
63274
63050
|
} catch {
|
|
@@ -63276,13 +63052,13 @@ function piPluginInstalled(piHome) {
|
|
|
63276
63052
|
}
|
|
63277
63053
|
}
|
|
63278
63054
|
function writeOverlayFileAtomic(overlay, fileName, contents) {
|
|
63279
|
-
const draft =
|
|
63055
|
+
const draft = path14.join(overlay, `.${fileName}.${process.pid}.tmp`);
|
|
63280
63056
|
try {
|
|
63281
|
-
|
|
63282
|
-
|
|
63057
|
+
fs11.writeFileSync(draft, contents);
|
|
63058
|
+
fs11.renameSync(draft, path14.join(overlay, fileName));
|
|
63283
63059
|
} catch {
|
|
63284
63060
|
try {
|
|
63285
|
-
|
|
63061
|
+
fs11.rmSync(draft, { force: true });
|
|
63286
63062
|
} catch {
|
|
63287
63063
|
}
|
|
63288
63064
|
}
|
|
@@ -63290,7 +63066,7 @@ function writeOverlayFileAtomic(overlay, fileName, contents) {
|
|
|
63290
63066
|
function writePiCompactionDisabledSettings(piHome, overlay) {
|
|
63291
63067
|
let settings = {};
|
|
63292
63068
|
try {
|
|
63293
|
-
const parsed = JSON.parse(
|
|
63069
|
+
const parsed = JSON.parse(fs11.readFileSync(path14.join(piHome, "settings.json"), "utf8"));
|
|
63294
63070
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
63295
63071
|
settings = parsed;
|
|
63296
63072
|
}
|
|
@@ -63303,12 +63079,12 @@ function writePiCompactionDisabledSettings(piHome, overlay) {
|
|
|
63303
63079
|
writeOverlayFileAtomic(overlay, "settings.json", JSON.stringify(settings, null, 2));
|
|
63304
63080
|
}
|
|
63305
63081
|
function preparePiHttpRewrite(piHome, origin, httpRewrites, httpsRewrites) {
|
|
63306
|
-
if (!
|
|
63082
|
+
if (!fs11.existsSync(piHome)) return void 0;
|
|
63307
63083
|
const overlay = `${piHome}-bili`;
|
|
63308
63084
|
const generated = ["settings.json"];
|
|
63309
63085
|
let modelsRoot;
|
|
63310
63086
|
try {
|
|
63311
|
-
const parsed = JSON.parse(
|
|
63087
|
+
const parsed = JSON.parse(fs11.readFileSync(path14.join(piHome, "models.json"), "utf8"));
|
|
63312
63088
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
63313
63089
|
modelsRoot = parsed;
|
|
63314
63090
|
generated.push("models.json");
|
|
@@ -63344,11 +63120,11 @@ function preparePiHttpRewrite(piHome, origin, httpRewrites, httpsRewrites) {
|
|
|
63344
63120
|
function atomicWriteTextFile(filePath, contents) {
|
|
63345
63121
|
const draft = `${filePath}.${process.pid}.bili-tmp`;
|
|
63346
63122
|
try {
|
|
63347
|
-
|
|
63348
|
-
|
|
63123
|
+
fs11.writeFileSync(draft, contents);
|
|
63124
|
+
fs11.renameSync(draft, filePath);
|
|
63349
63125
|
} catch {
|
|
63350
63126
|
try {
|
|
63351
|
-
|
|
63127
|
+
fs11.rmSync(draft, { force: true });
|
|
63352
63128
|
} catch {
|
|
63353
63129
|
}
|
|
63354
63130
|
throw new Error(`bili: could not write ${filePath}`);
|
|
@@ -63370,7 +63146,7 @@ function liveProxyPorts() {
|
|
|
63370
63146
|
function unpackDeadProxyUrlsInFile(filePath, livePorts) {
|
|
63371
63147
|
let txt;
|
|
63372
63148
|
try {
|
|
63373
|
-
txt =
|
|
63149
|
+
txt = fs11.readFileSync(filePath, "utf8");
|
|
63374
63150
|
} catch {
|
|
63375
63151
|
return 0;
|
|
63376
63152
|
}
|
|
@@ -63441,14 +63217,14 @@ function writeOmpCompactionDisabledConfig(ompHome, overlay) {
|
|
|
63441
63217
|
let baseIsJson = false;
|
|
63442
63218
|
for (const name of ["config.yml", "config.yaml"]) {
|
|
63443
63219
|
try {
|
|
63444
|
-
base =
|
|
63220
|
+
base = fs11.readFileSync(path14.join(ompHome, name), "utf8");
|
|
63445
63221
|
break;
|
|
63446
63222
|
} catch {
|
|
63447
63223
|
}
|
|
63448
63224
|
}
|
|
63449
63225
|
if (base === void 0) {
|
|
63450
63226
|
try {
|
|
63451
|
-
base =
|
|
63227
|
+
base = fs11.readFileSync(path14.join(ompHome, "settings.json"), "utf8");
|
|
63452
63228
|
baseIsJson = true;
|
|
63453
63229
|
} catch {
|
|
63454
63230
|
}
|
|
@@ -63476,17 +63252,17 @@ function writeOmpCompactionDisabledConfig(ompHome, overlay) {
|
|
|
63476
63252
|
writeOverlayFileAtomic(overlay, "config.yml", merged);
|
|
63477
63253
|
}
|
|
63478
63254
|
function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
|
|
63479
|
-
if (!
|
|
63255
|
+
if (!fs11.existsSync(ompHome)) return void 0;
|
|
63480
63256
|
const overlay = `${ompHome}-bili`;
|
|
63481
63257
|
const generated = ["config.yml"];
|
|
63482
|
-
const modelsPath =
|
|
63258
|
+
const modelsPath = path14.join(ompHome, "models.yml");
|
|
63483
63259
|
const unpacked = unpackDeadProxyUrlsInFile(modelsPath, liveProxyPorts());
|
|
63484
63260
|
if (unpacked > 0) {
|
|
63485
63261
|
console.error(`bili: unpacked ${unpacked} dead proxy URL(s) from the real ${modelsPath}`);
|
|
63486
63262
|
}
|
|
63487
63263
|
let modelsText;
|
|
63488
63264
|
try {
|
|
63489
|
-
modelsText =
|
|
63265
|
+
modelsText = fs11.readFileSync(modelsPath, "utf8");
|
|
63490
63266
|
generated.push("models.yml");
|
|
63491
63267
|
} catch {
|
|
63492
63268
|
}
|
|
@@ -63532,10 +63308,10 @@ function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
|
|
|
63532
63308
|
}
|
|
63533
63309
|
function prepareHermesHome(hermesHome, origin, rewrites) {
|
|
63534
63310
|
if (rewrites.length === 0) return void 0;
|
|
63535
|
-
const cfgPath =
|
|
63311
|
+
const cfgPath = path14.join(hermesHome, "config.yaml");
|
|
63536
63312
|
let txt;
|
|
63537
63313
|
try {
|
|
63538
|
-
txt =
|
|
63314
|
+
txt = fs11.readFileSync(cfgPath, "utf8");
|
|
63539
63315
|
} catch {
|
|
63540
63316
|
return void 0;
|
|
63541
63317
|
}
|
|
@@ -63562,21 +63338,21 @@ function prepareHermesHome(hermesHome, origin, rewrites) {
|
|
|
63562
63338
|
}
|
|
63563
63339
|
function writeHermesIdentityPlugin(hermesHome, overlay, rewrites) {
|
|
63564
63340
|
try {
|
|
63565
|
-
if (
|
|
63341
|
+
if (fs11.existsSync(path14.join(hermesHome, "plugins"))) return false;
|
|
63566
63342
|
} catch {
|
|
63567
63343
|
return false;
|
|
63568
63344
|
}
|
|
63569
|
-
const dir =
|
|
63345
|
+
const dir = path14.join("plugins", "model-providers", "bili-session-identity");
|
|
63570
63346
|
try {
|
|
63571
|
-
|
|
63347
|
+
fs11.mkdirSync(path14.join(overlay, dir), { recursive: true });
|
|
63572
63348
|
} catch {
|
|
63573
63349
|
return false;
|
|
63574
63350
|
}
|
|
63575
63351
|
const keys = rewrites.map((r) => r.key);
|
|
63576
|
-
const pluginDir =
|
|
63352
|
+
const pluginDir = path14.join(overlay, dir);
|
|
63577
63353
|
try {
|
|
63578
|
-
|
|
63579
|
-
|
|
63354
|
+
fs11.writeFileSync(path14.join(pluginDir, "__init__.py"), hermesIdentityPluginSource(keys));
|
|
63355
|
+
fs11.writeFileSync(path14.join(pluginDir, "plugin.yaml"), [
|
|
63580
63356
|
"name: bili-session-identity",
|
|
63581
63357
|
"kind: model-provider",
|
|
63582
63358
|
"version: 1.0.0",
|
|
@@ -63588,7 +63364,7 @@ function writeHermesIdentityPlugin(hermesHome, overlay, rewrites) {
|
|
|
63588
63364
|
return false;
|
|
63589
63365
|
}
|
|
63590
63366
|
try {
|
|
63591
|
-
return
|
|
63367
|
+
return fs11.existsSync(path14.join(overlay, dir, "__init__.py"));
|
|
63592
63368
|
} catch {
|
|
63593
63369
|
return false;
|
|
63594
63370
|
}
|
|
@@ -63645,10 +63421,10 @@ function hermesIdentityPluginSource(providerKeys) {
|
|
|
63645
63421
|
].join("\n");
|
|
63646
63422
|
}
|
|
63647
63423
|
function prepareDshHome(dshHome, origin, rewrites) {
|
|
63648
|
-
const cfgPath =
|
|
63424
|
+
const cfgPath = path14.join(dshHome, "settings.yaml");
|
|
63649
63425
|
let txt;
|
|
63650
63426
|
try {
|
|
63651
|
-
txt =
|
|
63427
|
+
txt = fs11.readFileSync(cfgPath, "utf8");
|
|
63652
63428
|
} catch {
|
|
63653
63429
|
return void 0;
|
|
63654
63430
|
}
|
|
@@ -63676,16 +63452,16 @@ function writeDshAcpPatch(dshHome) {
|
|
|
63676
63452
|
const pluginUrl = pathToFileURL(selfDistFile("agent/dsh-acp.js")).href;
|
|
63677
63453
|
const dir = `${dshHome}-bili`;
|
|
63678
63454
|
try {
|
|
63679
|
-
|
|
63455
|
+
fs11.mkdirSync(dir, { recursive: true });
|
|
63680
63456
|
} catch {
|
|
63681
63457
|
return void 0;
|
|
63682
63458
|
}
|
|
63683
63459
|
writeOverlayFileAtomic(dir, ".bili-acp.patch.yml", `- insert:
|
|
63684
63460
|
- name: ${pluginUrl}
|
|
63685
63461
|
`);
|
|
63686
|
-
const file =
|
|
63462
|
+
const file = path14.join(dir, ".bili-acp.patch.yml");
|
|
63687
63463
|
try {
|
|
63688
|
-
return
|
|
63464
|
+
return fs11.existsSync(file) ? file : void 0;
|
|
63689
63465
|
} catch {
|
|
63690
63466
|
return void 0;
|
|
63691
63467
|
}
|
|
@@ -63700,7 +63476,7 @@ function prepareOpencodeHttpRewrite(configFile2, origin, httpRewrites, httpsRewr
|
|
|
63700
63476
|
if (httpRewrites.length === 0 && httpsRewrites.length === 0 && !pluginPath) return void 0;
|
|
63701
63477
|
let root = {};
|
|
63702
63478
|
try {
|
|
63703
|
-
const txt =
|
|
63479
|
+
const txt = fs11.readFileSync(configFile2, "utf8");
|
|
63704
63480
|
const parsed = JSON.parse(txt);
|
|
63705
63481
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
63706
63482
|
root = { ...parsed };
|
|
@@ -63728,9 +63504,9 @@ function prepareOpencodeHttpRewrite(configFile2, origin, httpRewrites, httpsRewr
|
|
|
63728
63504
|
if (!plugins.includes(pluginPath)) plugins.push(pluginPath);
|
|
63729
63505
|
root.plugin = plugins;
|
|
63730
63506
|
}
|
|
63731
|
-
const tmp =
|
|
63732
|
-
const tmpFile =
|
|
63733
|
-
|
|
63507
|
+
const tmp = fs11.mkdtempSync(path14.join(os5.tmpdir(), "bili-opencode-"));
|
|
63508
|
+
const tmpFile = path14.join(tmp, "opencode.json");
|
|
63509
|
+
fs11.writeFileSync(tmpFile, JSON.stringify(root));
|
|
63734
63510
|
return tmpFile;
|
|
63735
63511
|
}
|
|
63736
63512
|
function dedupeInOrder(list) {
|
|
@@ -63820,8 +63596,8 @@ async function ensureProxyRunning(opts, deps = {}) {
|
|
|
63820
63596
|
const port = opts.port;
|
|
63821
63597
|
const script = process.argv[1];
|
|
63822
63598
|
if (!script) throw new Error("bili: cannot resolve launcher script path");
|
|
63823
|
-
const logPath2 =
|
|
63824
|
-
const logFd =
|
|
63599
|
+
const logPath2 = path14.join(os5.tmpdir(), `bili-proxy-${port}.log`);
|
|
63600
|
+
const logFd = fs11.openSync(logPath2, "a");
|
|
63825
63601
|
let child;
|
|
63826
63602
|
try {
|
|
63827
63603
|
child = spawnImpl(
|
|
@@ -63841,7 +63617,7 @@ async function ensureProxyRunning(opts, deps = {}) {
|
|
|
63841
63617
|
);
|
|
63842
63618
|
} finally {
|
|
63843
63619
|
try {
|
|
63844
|
-
|
|
63620
|
+
fs11.closeSync(logFd);
|
|
63845
63621
|
} catch {
|
|
63846
63622
|
}
|
|
63847
63623
|
}
|
|
@@ -63900,12 +63676,12 @@ var PATH_EXTS = process.platform === "win32" ? [".cmd", ".bat", ".exe", ""] : ["
|
|
|
63900
63676
|
function resolveOnPath(name, env) {
|
|
63901
63677
|
const p2 = env.PATH;
|
|
63902
63678
|
if (!p2) return void 0;
|
|
63903
|
-
for (const dir of p2.split(
|
|
63679
|
+
for (const dir of p2.split(path14.delimiter)) {
|
|
63904
63680
|
if (!dir) continue;
|
|
63905
63681
|
for (const ext of PATH_EXTS) {
|
|
63906
|
-
const f2 =
|
|
63682
|
+
const f2 = path14.join(dir, name + ext);
|
|
63907
63683
|
try {
|
|
63908
|
-
if (
|
|
63684
|
+
if (fs11.existsSync(f2) && fs11.statSync(f2).isFile()) return f2;
|
|
63909
63685
|
} catch {
|
|
63910
63686
|
}
|
|
63911
63687
|
}
|
|
@@ -63923,7 +63699,7 @@ function resolveClientCommand(client, env) {
|
|
|
63923
63699
|
if (piBin) return { command: piBin, prefixArgs: [] };
|
|
63924
63700
|
const piResolved = resolveOnPath("pi", env);
|
|
63925
63701
|
if (piResolved) return { command: piResolved, prefixArgs: [] };
|
|
63926
|
-
const cli =
|
|
63702
|
+
const cli = path14.join(
|
|
63927
63703
|
os5.homedir(),
|
|
63928
63704
|
".pi/agent/npm/node_modules/@earendil-works/pi-coding-agent/dist/cli.js"
|
|
63929
63705
|
);
|
|
@@ -63995,7 +63771,7 @@ async function runLaunch(params, deps = {}) {
|
|
|
63995
63771
|
piOverlayHome = preparePiHttpRewrite(resolvePiHome(process.env), origin, routes.httpRewrites, routes.httpsRewrites);
|
|
63996
63772
|
if (piOverlayHome) env.PI_CODING_AGENT_DIR = piOverlayHome;
|
|
63997
63773
|
const piExt = selfDistFile("agent/pi.js");
|
|
63998
|
-
if (piExt &&
|
|
63774
|
+
if (piExt && fs11.existsSync(piExt) && !piPluginInstalled(resolvePiHome(process.env))) {
|
|
63999
63775
|
clientArgs = ["-e", piExt, ...clientArgs];
|
|
64000
63776
|
}
|
|
64001
63777
|
} else if (base === "omp") {
|
|
@@ -64003,13 +63779,13 @@ async function runLaunch(params, deps = {}) {
|
|
|
64003
63779
|
ompOverlayHome = prepareOmpHttpRewrite(resolveOmpHome(process.env), origin, routes.httpRewrites, routes.httpsRewrites);
|
|
64004
63780
|
if (ompOverlayHome) env.PI_CODING_AGENT_DIR = ompOverlayHome;
|
|
64005
63781
|
const ompExt = selfDistFile("agent/omp.js");
|
|
64006
|
-
if (ompExt &&
|
|
63782
|
+
if (ompExt && fs11.existsSync(ompExt) && !ompPluginLoadedFrom(resolveOmpHome(process.env))) {
|
|
64007
63783
|
clientArgs = ["-e", ompExt, ...clientArgs];
|
|
64008
63784
|
}
|
|
64009
63785
|
} else if (base === "opencode") {
|
|
64010
63786
|
env = { ...process.env, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: ca, BILLION_CONTEXT_PROXY: origin };
|
|
64011
63787
|
const opencodePlugin = selfDistFile("agent/opencode.js");
|
|
64012
|
-
const opencodePluginPath = opencodePlugin &&
|
|
63788
|
+
const opencodePluginPath = opencodePlugin && fs11.existsSync(opencodePlugin) ? opencodePlugin : void 0;
|
|
64013
63789
|
opencodeTmpFile = prepareOpencodeHttpRewrite(resolveOpencodeConfigFile(process.env), origin, routes.httpRewrites, routes.httpsRewrites, opencodePluginPath);
|
|
64014
63790
|
if (opencodeTmpFile) env.OPENCODE_CONFIG = opencodeTmpFile;
|
|
64015
63791
|
} else if (base === "hermes") {
|
|
@@ -64082,8 +63858,8 @@ async function runLaunch(params, deps = {}) {
|
|
|
64082
63858
|
console.error(`bili: claude budget aligned \u2014 CLAUDE_CODE_AUTO_COMPACT_WINDOW=${claudeBudget.CLAUDE_CODE_AUTO_COMPACT_WINDOW}`);
|
|
64083
63859
|
}
|
|
64084
63860
|
if (injectMcp) {
|
|
64085
|
-
const mcpFile =
|
|
64086
|
-
|
|
63861
|
+
const mcpFile = path14.join(os5.tmpdir(), `bili-mcp-${Date.now()}.json`);
|
|
63862
|
+
fs11.writeFileSync(mcpFile, JSON.stringify(buildMcpConfig(origin)));
|
|
64087
63863
|
tmpFiles.push(mcpFile);
|
|
64088
63864
|
clientArgs = ["--mcp-config", mcpFile, ...clientArgs];
|
|
64089
63865
|
}
|
|
@@ -64102,13 +63878,13 @@ async function runLaunch(params, deps = {}) {
|
|
|
64102
63878
|
stopProxy(handle2);
|
|
64103
63879
|
if (opencodeTmpFile) {
|
|
64104
63880
|
try {
|
|
64105
|
-
|
|
63881
|
+
fs11.rmSync(path14.dirname(opencodeTmpFile), { recursive: true, force: true });
|
|
64106
63882
|
} catch {
|
|
64107
63883
|
}
|
|
64108
63884
|
}
|
|
64109
63885
|
for (const f2 of tmpFiles) {
|
|
64110
63886
|
try {
|
|
64111
|
-
|
|
63887
|
+
fs11.rmSync(f2, { force: true });
|
|
64112
63888
|
} catch {
|
|
64113
63889
|
}
|
|
64114
63890
|
}
|
|
@@ -64134,8 +63910,8 @@ async function runTestPi(params, deps = {}) {
|
|
|
64134
63910
|
}
|
|
64135
63911
|
const ca = resolveCaCertPath(process.env);
|
|
64136
63912
|
const env = buildPiEnv(handle2.origin, ca, process.env);
|
|
64137
|
-
const sessionDir =
|
|
64138
|
-
|
|
63913
|
+
const sessionDir = path14.join(os5.tmpdir(), `bili-pi-test-${Date.now()}`);
|
|
63914
|
+
fs11.mkdirSync(sessionDir, { recursive: true });
|
|
64139
63915
|
const args = [
|
|
64140
63916
|
"-p",
|
|
64141
63917
|
"--no-session",
|
|
@@ -64163,7 +63939,7 @@ async function runTestPi(params, deps = {}) {
|
|
|
64163
63939
|
|
|
64164
63940
|
// src/export.ts
|
|
64165
63941
|
import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "fs";
|
|
64166
|
-
import
|
|
63942
|
+
import path15 from "path";
|
|
64167
63943
|
function fmtDate(ms2) {
|
|
64168
63944
|
return ms2 ? new Date(ms2).toISOString().replace("T", " ").slice(0, 19) + " UTC" : "\u2014";
|
|
64169
63945
|
}
|
|
@@ -64295,7 +64071,7 @@ async function exportSession(selector, opts = {}) {
|
|
|
64295
64071
|
}
|
|
64296
64072
|
const markdown = renderHandoff(matches[0], opts.full ?? false);
|
|
64297
64073
|
if (opts.output) {
|
|
64298
|
-
mkdirSync5(
|
|
64074
|
+
mkdirSync5(path15.dirname(path15.resolve(opts.output)), { recursive: true });
|
|
64299
64075
|
writeFileSync4(opts.output, markdown, "utf8");
|
|
64300
64076
|
return `written to ${opts.output}`;
|
|
64301
64077
|
}
|
|
@@ -64305,11 +64081,11 @@ async function exportSession(selector, opts = {}) {
|
|
|
64305
64081
|
// src/cli.ts
|
|
64306
64082
|
import { readFileSync as readFileSync4 } from "fs";
|
|
64307
64083
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
64308
|
-
import
|
|
64084
|
+
import path16 from "path";
|
|
64309
64085
|
var VERSION3 = (() => {
|
|
64310
64086
|
try {
|
|
64311
64087
|
const here = fileURLToPath6(import.meta.url);
|
|
64312
|
-
const pkg =
|
|
64088
|
+
const pkg = path16.join(path16.dirname(here), "..", "package.json");
|
|
64313
64089
|
return JSON.parse(readFileSync4(pkg, "utf8")).version ?? "dev";
|
|
64314
64090
|
} catch {
|
|
64315
64091
|
return "dev";
|
|
@@ -64318,7 +64094,7 @@ var VERSION3 = (() => {
|
|
|
64318
64094
|
var PACKAGE_NAME = (() => {
|
|
64319
64095
|
try {
|
|
64320
64096
|
const here = fileURLToPath6(import.meta.url);
|
|
64321
|
-
const pkg =
|
|
64097
|
+
const pkg = path16.join(path16.dirname(here), "..", "package.json");
|
|
64322
64098
|
return JSON.parse(readFileSync4(pkg, "utf8")).name ?? "billion-context";
|
|
64323
64099
|
} catch {
|
|
64324
64100
|
return "billion-context";
|