agent-shim 8.11.2 → 8.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cli.cjs +1035 -238
- package/dist/index.cjs +1132 -384
- package/dist/index.mjs +1119 -384
- package/dist/types/index.d.ts +126 -2
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -3248,42 +3248,42 @@ var require_defaults = __commonJS({
|
|
|
3248
3248
|
var require_env_paths = __commonJS({
|
|
3249
3249
|
"node_modules/.pnpm/env-paths@2.2.1/node_modules/env-paths/index.js"(exports2, module2) {
|
|
3250
3250
|
"use strict";
|
|
3251
|
-
var
|
|
3251
|
+
var path43 = require("path");
|
|
3252
3252
|
var os10 = require("os");
|
|
3253
3253
|
var homedir = os10.homedir();
|
|
3254
3254
|
var tmpdir = os10.tmpdir();
|
|
3255
3255
|
var { env } = process;
|
|
3256
3256
|
var macos = (name) => {
|
|
3257
|
-
const library =
|
|
3257
|
+
const library = path43.join(homedir, "Library");
|
|
3258
3258
|
return {
|
|
3259
|
-
data:
|
|
3260
|
-
config:
|
|
3261
|
-
cache:
|
|
3262
|
-
log:
|
|
3263
|
-
temp:
|
|
3259
|
+
data: path43.join(library, "Application Support", name),
|
|
3260
|
+
config: path43.join(library, "Preferences", name),
|
|
3261
|
+
cache: path43.join(library, "Caches", name),
|
|
3262
|
+
log: path43.join(library, "Logs", name),
|
|
3263
|
+
temp: path43.join(tmpdir, name)
|
|
3264
3264
|
};
|
|
3265
3265
|
};
|
|
3266
3266
|
var windows = (name) => {
|
|
3267
|
-
const appData = env.APPDATA ||
|
|
3268
|
-
const localAppData = env.LOCALAPPDATA ||
|
|
3267
|
+
const appData = env.APPDATA || path43.join(homedir, "AppData", "Roaming");
|
|
3268
|
+
const localAppData = env.LOCALAPPDATA || path43.join(homedir, "AppData", "Local");
|
|
3269
3269
|
return {
|
|
3270
3270
|
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
|
|
3271
|
-
data:
|
|
3272
|
-
config:
|
|
3273
|
-
cache:
|
|
3274
|
-
log:
|
|
3275
|
-
temp:
|
|
3271
|
+
data: path43.join(localAppData, name, "Data"),
|
|
3272
|
+
config: path43.join(appData, name, "Config"),
|
|
3273
|
+
cache: path43.join(localAppData, name, "Cache"),
|
|
3274
|
+
log: path43.join(localAppData, name, "Log"),
|
|
3275
|
+
temp: path43.join(tmpdir, name)
|
|
3276
3276
|
};
|
|
3277
3277
|
};
|
|
3278
3278
|
var linux = (name) => {
|
|
3279
|
-
const username =
|
|
3279
|
+
const username = path43.basename(homedir);
|
|
3280
3280
|
return {
|
|
3281
|
-
data:
|
|
3282
|
-
config:
|
|
3283
|
-
cache:
|
|
3281
|
+
data: path43.join(env.XDG_DATA_HOME || path43.join(homedir, ".local", "share"), name),
|
|
3282
|
+
config: path43.join(env.XDG_CONFIG_HOME || path43.join(homedir, ".config"), name),
|
|
3283
|
+
cache: path43.join(env.XDG_CACHE_HOME || path43.join(homedir, ".cache"), name),
|
|
3284
3284
|
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
|
|
3285
|
-
log:
|
|
3286
|
-
temp:
|
|
3285
|
+
log: path43.join(env.XDG_STATE_HOME || path43.join(homedir, ".local", "state"), name),
|
|
3286
|
+
temp: path43.join(tmpdir, username, name)
|
|
3287
3287
|
};
|
|
3288
3288
|
};
|
|
3289
3289
|
var envPaths = (name, options) => {
|
|
@@ -3351,11 +3351,11 @@ var require_util = __commonJS({
|
|
|
3351
3351
|
return result;
|
|
3352
3352
|
}
|
|
3353
3353
|
exports2.emplace = emplace;
|
|
3354
|
-
function getPropertyByPath(source,
|
|
3355
|
-
if (typeof
|
|
3356
|
-
return source[
|
|
3354
|
+
function getPropertyByPath(source, path43) {
|
|
3355
|
+
if (typeof path43 === "string" && Object.prototype.hasOwnProperty.call(source, path43)) {
|
|
3356
|
+
return source[path43];
|
|
3357
3357
|
}
|
|
3358
|
-
const parsedPath = typeof
|
|
3358
|
+
const parsedPath = typeof path43 === "string" ? path43.split(".") : path43;
|
|
3359
3359
|
return parsedPath.reduce((previous, key) => {
|
|
3360
3360
|
if (previous === void 0) {
|
|
3361
3361
|
return previous;
|
|
@@ -3378,9 +3378,9 @@ var require_util = __commonJS({
|
|
|
3378
3378
|
return Object.fromEntries(Object.entries(options).filter(([, value2]) => value2 !== void 0));
|
|
3379
3379
|
}
|
|
3380
3380
|
exports2.removeUndefinedValuesFromObject = removeUndefinedValuesFromObject;
|
|
3381
|
-
async function isDirectory(
|
|
3381
|
+
async function isDirectory(path43) {
|
|
3382
3382
|
try {
|
|
3383
|
-
const stat = await fs_1.promises.stat(
|
|
3383
|
+
const stat = await fs_1.promises.stat(path43);
|
|
3384
3384
|
return stat.isDirectory();
|
|
3385
3385
|
} catch (e) {
|
|
3386
3386
|
if (e.code === "ENOENT") {
|
|
@@ -3390,9 +3390,9 @@ var require_util = __commonJS({
|
|
|
3390
3390
|
}
|
|
3391
3391
|
}
|
|
3392
3392
|
exports2.isDirectory = isDirectory;
|
|
3393
|
-
function isDirectorySync(
|
|
3393
|
+
function isDirectorySync(path43) {
|
|
3394
3394
|
try {
|
|
3395
|
-
const stat = fs_1.default.statSync(
|
|
3395
|
+
const stat = fs_1.default.statSync(path43);
|
|
3396
3396
|
return stat.isDirectory();
|
|
3397
3397
|
} catch (e) {
|
|
3398
3398
|
if (e.code === "ENOENT") {
|
|
@@ -3490,7 +3490,7 @@ var require_ExplorerBase = __commonJS({
|
|
|
3490
3490
|
const idx = importStack.indexOf(fullPath);
|
|
3491
3491
|
if (idx !== -1) {
|
|
3492
3492
|
throw new Error(`Circular import detected:
|
|
3493
|
-
${[...importStack, fullPath].map((
|
|
3493
|
+
${[...importStack, fullPath].map((path43, i2) => `${i2 + 1}. ${path43}`).join("\n")} (same as ${idx + 1}.)`);
|
|
3494
3494
|
}
|
|
3495
3495
|
}
|
|
3496
3496
|
}
|
|
@@ -3678,9 +3678,9 @@ var require_Explorer = __commonJS({
|
|
|
3678
3678
|
throw error62;
|
|
3679
3679
|
}
|
|
3680
3680
|
}
|
|
3681
|
-
async #fileExists(
|
|
3681
|
+
async #fileExists(path43) {
|
|
3682
3682
|
try {
|
|
3683
|
-
await promises_1.default.stat(
|
|
3683
|
+
await promises_1.default.stat(path43);
|
|
3684
3684
|
return true;
|
|
3685
3685
|
} catch (e) {
|
|
3686
3686
|
return false;
|
|
@@ -3840,9 +3840,9 @@ var require_ExplorerSync = __commonJS({
|
|
|
3840
3840
|
throw error62;
|
|
3841
3841
|
}
|
|
3842
3842
|
}
|
|
3843
|
-
#fileExists(
|
|
3843
|
+
#fileExists(path43) {
|
|
3844
3844
|
try {
|
|
3845
|
-
fs_1.default.statSync(
|
|
3845
|
+
fs_1.default.statSync(path43);
|
|
3846
3846
|
return true;
|
|
3847
3847
|
} catch (e) {
|
|
3848
3848
|
return false;
|
|
@@ -3966,7 +3966,7 @@ var require_dist = __commonJS({
|
|
|
3966
3966
|
};
|
|
3967
3967
|
}
|
|
3968
3968
|
function getResolvedSearchPlaces(moduleName, toolDefinedSearchPlaces, userConfiguredOptions) {
|
|
3969
|
-
const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((
|
|
3969
|
+
const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((path43) => path43.replace("{name}", moduleName));
|
|
3970
3970
|
if (userConfiguredOptions.mergeSearchPlaces) {
|
|
3971
3971
|
return [...userConfiguredSearchPlaces ?? [], ...toolDefinedSearchPlaces];
|
|
3972
3972
|
}
|
|
@@ -4374,8 +4374,8 @@ var require_utils = __commonJS({
|
|
|
4374
4374
|
}
|
|
4375
4375
|
return output2;
|
|
4376
4376
|
};
|
|
4377
|
-
exports2.basename = (
|
|
4378
|
-
const segs =
|
|
4377
|
+
exports2.basename = (path43, { windows } = {}) => {
|
|
4378
|
+
const segs = path43.split(windows ? /[\\/]/ : "/");
|
|
4379
4379
|
const last = segs[segs.length - 1];
|
|
4380
4380
|
if (last === "") {
|
|
4381
4381
|
return segs[segs.length - 2];
|
|
@@ -7003,14 +7003,14 @@ var require_util2 = __commonJS({
|
|
|
7003
7003
|
}
|
|
7004
7004
|
const port = url2.port != null ? url2.port : url2.protocol === "https:" ? 443 : 80;
|
|
7005
7005
|
let origin = url2.origin != null ? url2.origin : `${url2.protocol || ""}//${url2.hostname || ""}:${port}`;
|
|
7006
|
-
let
|
|
7006
|
+
let path43 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
|
|
7007
7007
|
if (origin[origin.length - 1] === "/") {
|
|
7008
7008
|
origin = origin.slice(0, origin.length - 1);
|
|
7009
7009
|
}
|
|
7010
|
-
if (
|
|
7011
|
-
|
|
7010
|
+
if (path43 && path43[0] !== "/") {
|
|
7011
|
+
path43 = `/${path43}`;
|
|
7012
7012
|
}
|
|
7013
|
-
return new URL(`${origin}${
|
|
7013
|
+
return new URL(`${origin}${path43}`);
|
|
7014
7014
|
}
|
|
7015
7015
|
if (!isHttpOrHttpsPrefixed(url2.origin || url2.protocol)) {
|
|
7016
7016
|
throw new InvalidArgumentError2("Invalid URL protocol: the URL must start with `http:` or `https:`.");
|
|
@@ -7831,9 +7831,9 @@ var require_diagnostics = __commonJS({
|
|
|
7831
7831
|
"undici:client:sendHeaders",
|
|
7832
7832
|
(evt) => {
|
|
7833
7833
|
const {
|
|
7834
|
-
request: { method, path:
|
|
7834
|
+
request: { method, path: path43, origin }
|
|
7835
7835
|
} = evt;
|
|
7836
|
-
debugLog("sending request to %s %s%s", method, origin,
|
|
7836
|
+
debugLog("sending request to %s %s%s", method, origin, path43);
|
|
7837
7837
|
}
|
|
7838
7838
|
);
|
|
7839
7839
|
}
|
|
@@ -7851,14 +7851,14 @@ var require_diagnostics = __commonJS({
|
|
|
7851
7851
|
"undici:request:headers",
|
|
7852
7852
|
(evt) => {
|
|
7853
7853
|
const {
|
|
7854
|
-
request: { method, path:
|
|
7854
|
+
request: { method, path: path43, origin },
|
|
7855
7855
|
response: { statusCode }
|
|
7856
7856
|
} = evt;
|
|
7857
7857
|
debugLog(
|
|
7858
7858
|
"received response to %s %s%s - HTTP %d",
|
|
7859
7859
|
method,
|
|
7860
7860
|
origin,
|
|
7861
|
-
|
|
7861
|
+
path43,
|
|
7862
7862
|
statusCode
|
|
7863
7863
|
);
|
|
7864
7864
|
}
|
|
@@ -7867,23 +7867,23 @@ var require_diagnostics = __commonJS({
|
|
|
7867
7867
|
"undici:request:trailers",
|
|
7868
7868
|
(evt) => {
|
|
7869
7869
|
const {
|
|
7870
|
-
request: { method, path:
|
|
7870
|
+
request: { method, path: path43, origin }
|
|
7871
7871
|
} = evt;
|
|
7872
|
-
debugLog("trailers received from %s %s%s", method, origin,
|
|
7872
|
+
debugLog("trailers received from %s %s%s", method, origin, path43);
|
|
7873
7873
|
}
|
|
7874
7874
|
);
|
|
7875
7875
|
diagnosticsChannel.subscribe(
|
|
7876
7876
|
"undici:request:error",
|
|
7877
7877
|
(evt) => {
|
|
7878
7878
|
const {
|
|
7879
|
-
request: { method, path:
|
|
7879
|
+
request: { method, path: path43, origin },
|
|
7880
7880
|
error: error62
|
|
7881
7881
|
} = evt;
|
|
7882
7882
|
debugLog(
|
|
7883
7883
|
"request to %s %s%s errored - %s",
|
|
7884
7884
|
method,
|
|
7885
7885
|
origin,
|
|
7886
|
-
|
|
7886
|
+
path43,
|
|
7887
7887
|
error62.message
|
|
7888
7888
|
);
|
|
7889
7889
|
}
|
|
@@ -7998,7 +7998,7 @@ var require_request = __commonJS({
|
|
|
7998
7998
|
var kHandler = /* @__PURE__ */ Symbol("handler");
|
|
7999
7999
|
var Request2 = class {
|
|
8000
8000
|
constructor(origin, {
|
|
8001
|
-
path:
|
|
8001
|
+
path: path43,
|
|
8002
8002
|
method,
|
|
8003
8003
|
body,
|
|
8004
8004
|
headers,
|
|
@@ -8015,11 +8015,11 @@ var require_request = __commonJS({
|
|
|
8015
8015
|
maxRedirections,
|
|
8016
8016
|
typeOfService
|
|
8017
8017
|
}, handler) {
|
|
8018
|
-
if (typeof
|
|
8018
|
+
if (typeof path43 !== "string") {
|
|
8019
8019
|
throw new InvalidArgumentError2("path must be a string");
|
|
8020
|
-
} else if (
|
|
8020
|
+
} else if (path43[0] !== "/" && !(path43.startsWith("http://") || path43.startsWith("https://")) && method !== "CONNECT") {
|
|
8021
8021
|
throw new InvalidArgumentError2("path must be an absolute URL or start with a slash");
|
|
8022
|
-
} else if (invalidPathRegex.test(
|
|
8022
|
+
} else if (invalidPathRegex.test(path43)) {
|
|
8023
8023
|
throw new InvalidArgumentError2("invalid request path");
|
|
8024
8024
|
}
|
|
8025
8025
|
if (typeof method !== "string") {
|
|
@@ -8094,7 +8094,7 @@ var require_request = __commonJS({
|
|
|
8094
8094
|
this.completed = false;
|
|
8095
8095
|
this.aborted = false;
|
|
8096
8096
|
this.upgrade = upgrade || null;
|
|
8097
|
-
this.path = query ? serializePathWithQuery(
|
|
8097
|
+
this.path = query ? serializePathWithQuery(path43, query) : path43;
|
|
8098
8098
|
this.origin = origin;
|
|
8099
8099
|
this.protocol = getProtocolFromUrlString(origin);
|
|
8100
8100
|
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
|
|
@@ -13276,7 +13276,7 @@ var require_client_h1 = __commonJS({
|
|
|
13276
13276
|
return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
|
|
13277
13277
|
}
|
|
13278
13278
|
function writeH1(client, request7) {
|
|
13279
|
-
const { method, path:
|
|
13279
|
+
const { method, path: path43, host, upgrade, blocking, reset } = request7;
|
|
13280
13280
|
let { body, headers, contentLength } = request7;
|
|
13281
13281
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
|
|
13282
13282
|
if (util.isFormDataLike(body)) {
|
|
@@ -13354,7 +13354,7 @@ var require_client_h1 = __commonJS({
|
|
|
13354
13354
|
if (socket.setTypeOfService) {
|
|
13355
13355
|
socket.setTypeOfService(request7.typeOfService);
|
|
13356
13356
|
}
|
|
13357
|
-
let header = `${method} ${
|
|
13357
|
+
let header = `${method} ${path43} HTTP/1.1\r
|
|
13358
13358
|
`;
|
|
13359
13359
|
if (typeof host === "string") {
|
|
13360
13360
|
header += `host: ${host}\r
|
|
@@ -14033,7 +14033,7 @@ var require_client_h2 = __commonJS({
|
|
|
14033
14033
|
const headersTimeout = request7.headersTimeout ?? client[kHeadersTimeout];
|
|
14034
14034
|
const bodyTimeout = request7.bodyTimeout ?? client[kBodyTimeout];
|
|
14035
14035
|
const session = client[kHTTP2Session];
|
|
14036
|
-
const { method, path:
|
|
14036
|
+
const { method, path: path43, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request7;
|
|
14037
14037
|
let { body } = request7;
|
|
14038
14038
|
if (upgrade != null && upgrade !== "websocket") {
|
|
14039
14039
|
util.errorRequest(client, request7, new InvalidArgumentError2(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
|
|
@@ -14102,7 +14102,7 @@ var require_client_h2 = __commonJS({
|
|
|
14102
14102
|
}
|
|
14103
14103
|
headers[HTTP2_HEADER_METHOD] = "CONNECT";
|
|
14104
14104
|
headers[HTTP2_HEADER_PROTOCOL] = "websocket";
|
|
14105
|
-
headers[HTTP2_HEADER_PATH] =
|
|
14105
|
+
headers[HTTP2_HEADER_PATH] = path43;
|
|
14106
14106
|
if (protocol === "ws:" || protocol === "wss:") {
|
|
14107
14107
|
headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
|
|
14108
14108
|
} else {
|
|
@@ -14144,7 +14144,7 @@ var require_client_h2 = __commonJS({
|
|
|
14144
14144
|
stream.setTimeout(headersTimeout);
|
|
14145
14145
|
return true;
|
|
14146
14146
|
}
|
|
14147
|
-
headers[HTTP2_HEADER_PATH] =
|
|
14147
|
+
headers[HTTP2_HEADER_PATH] = path43;
|
|
14148
14148
|
headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
|
|
14149
14149
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
14150
14150
|
if (body && typeof body.read === "function") {
|
|
@@ -16496,10 +16496,10 @@ var require_proxy_agent = __commonJS({
|
|
|
16496
16496
|
};
|
|
16497
16497
|
const {
|
|
16498
16498
|
origin,
|
|
16499
|
-
path:
|
|
16499
|
+
path: path43 = "/",
|
|
16500
16500
|
headers = {}
|
|
16501
16501
|
} = opts;
|
|
16502
|
-
opts.path = origin +
|
|
16502
|
+
opts.path = origin + path43;
|
|
16503
16503
|
if (!("host" in headers) && !("Host" in headers)) {
|
|
16504
16504
|
const { host } = new URL(origin);
|
|
16505
16505
|
headers.host = host;
|
|
@@ -18608,20 +18608,20 @@ var require_mock_utils = __commonJS({
|
|
|
18608
18608
|
}
|
|
18609
18609
|
return normalizedQp;
|
|
18610
18610
|
}
|
|
18611
|
-
function safeUrl(
|
|
18612
|
-
if (typeof
|
|
18613
|
-
return
|
|
18611
|
+
function safeUrl(path43) {
|
|
18612
|
+
if (typeof path43 !== "string") {
|
|
18613
|
+
return path43;
|
|
18614
18614
|
}
|
|
18615
|
-
const pathSegments =
|
|
18615
|
+
const pathSegments = path43.split("?", 3);
|
|
18616
18616
|
if (pathSegments.length !== 2) {
|
|
18617
|
-
return
|
|
18617
|
+
return path43;
|
|
18618
18618
|
}
|
|
18619
18619
|
const qp = new URLSearchParams(pathSegments.pop());
|
|
18620
18620
|
qp.sort();
|
|
18621
18621
|
return [...pathSegments, qp.toString()].join("?");
|
|
18622
18622
|
}
|
|
18623
|
-
function matchKey(mockDispatch2, { path:
|
|
18624
|
-
const pathMatch = matchValue(mockDispatch2.path,
|
|
18623
|
+
function matchKey(mockDispatch2, { path: path43, method, body, headers }) {
|
|
18624
|
+
const pathMatch = matchValue(mockDispatch2.path, path43);
|
|
18625
18625
|
const methodMatch = matchValue(mockDispatch2.method, method);
|
|
18626
18626
|
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
|
|
18627
18627
|
const headersMatch = matchHeaders(mockDispatch2, headers);
|
|
@@ -18646,8 +18646,8 @@ var require_mock_utils = __commonJS({
|
|
|
18646
18646
|
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
|
|
18647
18647
|
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
|
|
18648
18648
|
const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
|
|
18649
|
-
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path:
|
|
18650
|
-
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(
|
|
18649
|
+
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path43, ignoreTrailingSlash }) => {
|
|
18650
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path43)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path43), resolvedPath);
|
|
18651
18651
|
});
|
|
18652
18652
|
if (matchedMockDispatches.length === 0) {
|
|
18653
18653
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
@@ -18686,19 +18686,19 @@ var require_mock_utils = __commonJS({
|
|
|
18686
18686
|
mockDispatches.splice(index, 1);
|
|
18687
18687
|
}
|
|
18688
18688
|
}
|
|
18689
|
-
function removeTrailingSlash(
|
|
18690
|
-
while (
|
|
18691
|
-
|
|
18689
|
+
function removeTrailingSlash(path43) {
|
|
18690
|
+
while (path43.endsWith("/")) {
|
|
18691
|
+
path43 = path43.slice(0, -1);
|
|
18692
18692
|
}
|
|
18693
|
-
if (
|
|
18694
|
-
|
|
18693
|
+
if (path43.length === 0) {
|
|
18694
|
+
path43 = "/";
|
|
18695
18695
|
}
|
|
18696
|
-
return
|
|
18696
|
+
return path43;
|
|
18697
18697
|
}
|
|
18698
18698
|
function buildKey(opts) {
|
|
18699
|
-
const { path:
|
|
18699
|
+
const { path: path43, method, body, headers, query } = opts;
|
|
18700
18700
|
return {
|
|
18701
|
-
path:
|
|
18701
|
+
path: path43,
|
|
18702
18702
|
method,
|
|
18703
18703
|
body,
|
|
18704
18704
|
headers,
|
|
@@ -19388,10 +19388,10 @@ var require_pending_interceptors_formatter = __commonJS({
|
|
|
19388
19388
|
}
|
|
19389
19389
|
format(pendingInterceptors) {
|
|
19390
19390
|
const withPrettyHeaders = pendingInterceptors.map(
|
|
19391
|
-
({ method, path:
|
|
19391
|
+
({ method, path: path43, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
19392
19392
|
Method: method,
|
|
19393
19393
|
Origin: origin,
|
|
19394
|
-
Path:
|
|
19394
|
+
Path: path43,
|
|
19395
19395
|
"Status code": statusCode,
|
|
19396
19396
|
Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
|
|
19397
19397
|
Invocations: timesInvoked,
|
|
@@ -19473,9 +19473,9 @@ var require_mock_agent = __commonJS({
|
|
|
19473
19473
|
const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
|
|
19474
19474
|
const dispatchOpts = { ...opts };
|
|
19475
19475
|
if (acceptNonStandardSearchParameters && dispatchOpts.path) {
|
|
19476
|
-
const [
|
|
19476
|
+
const [path43, searchParams] = dispatchOpts.path.split("?");
|
|
19477
19477
|
const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
|
|
19478
|
-
dispatchOpts.path = `${
|
|
19478
|
+
dispatchOpts.path = `${path43}?${normalizedSearchParams}`;
|
|
19479
19479
|
}
|
|
19480
19480
|
return this[kAgent].dispatch(dispatchOpts, handler);
|
|
19481
19481
|
}
|
|
@@ -19876,12 +19876,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
19876
19876
|
* @return {Promise<void>} - Resolves when snapshots are loaded
|
|
19877
19877
|
*/
|
|
19878
19878
|
async loadSnapshots(filePath) {
|
|
19879
|
-
const
|
|
19880
|
-
if (!
|
|
19879
|
+
const path43 = filePath || this.#snapshotPath;
|
|
19880
|
+
if (!path43) {
|
|
19881
19881
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
19882
19882
|
}
|
|
19883
19883
|
try {
|
|
19884
|
-
const data = await readFile(resolve(
|
|
19884
|
+
const data = await readFile(resolve(path43), "utf8");
|
|
19885
19885
|
const parsed = JSON.parse(data);
|
|
19886
19886
|
if (Array.isArray(parsed)) {
|
|
19887
19887
|
this.#snapshots.clear();
|
|
@@ -19895,7 +19895,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
19895
19895
|
if (error62.code === "ENOENT") {
|
|
19896
19896
|
this.#snapshots.clear();
|
|
19897
19897
|
} else {
|
|
19898
|
-
throw new UndiciError(`Failed to load snapshots from ${
|
|
19898
|
+
throw new UndiciError(`Failed to load snapshots from ${path43}`, { cause: error62 });
|
|
19899
19899
|
}
|
|
19900
19900
|
}
|
|
19901
19901
|
}
|
|
@@ -19906,11 +19906,11 @@ var require_snapshot_recorder = __commonJS({
|
|
|
19906
19906
|
* @returns {Promise<void>} - Resolves when snapshots are saved
|
|
19907
19907
|
*/
|
|
19908
19908
|
async saveSnapshots(filePath) {
|
|
19909
|
-
const
|
|
19910
|
-
if (!
|
|
19909
|
+
const path43 = filePath || this.#snapshotPath;
|
|
19910
|
+
if (!path43) {
|
|
19911
19911
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
19912
19912
|
}
|
|
19913
|
-
const resolvedPath = resolve(
|
|
19913
|
+
const resolvedPath = resolve(path43);
|
|
19914
19914
|
await mkdir(dirname2(resolvedPath), { recursive: true });
|
|
19915
19915
|
const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
|
|
19916
19916
|
hash: hash2,
|
|
@@ -20542,15 +20542,15 @@ var require_redirect_handler = __commonJS({
|
|
|
20542
20542
|
return;
|
|
20543
20543
|
}
|
|
20544
20544
|
const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
|
|
20545
|
-
const
|
|
20546
|
-
const redirectUrlString = `${origin}${
|
|
20545
|
+
const path43 = search ? `${pathname}${search}` : pathname;
|
|
20546
|
+
const redirectUrlString = `${origin}${path43}`;
|
|
20547
20547
|
for (const historyUrl of this.history) {
|
|
20548
20548
|
if (historyUrl.toString() === redirectUrlString) {
|
|
20549
20549
|
throw new InvalidArgumentError2(`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.`);
|
|
20550
20550
|
}
|
|
20551
20551
|
}
|
|
20552
20552
|
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
|
|
20553
|
-
this.opts.path =
|
|
20553
|
+
this.opts.path = path43;
|
|
20554
20554
|
this.opts.origin = origin;
|
|
20555
20555
|
this.opts.query = null;
|
|
20556
20556
|
}
|
|
@@ -22310,10 +22310,10 @@ var require_cache_handler = __commonJS({
|
|
|
22310
22310
|
}
|
|
22311
22311
|
return locationUrl.pathname + locationUrl.search;
|
|
22312
22312
|
}
|
|
22313
|
-
function deleteCachedUri(store, cacheKey,
|
|
22313
|
+
function deleteCachedUri(store, cacheKey, path43) {
|
|
22314
22314
|
deleteCachedValue(store, {
|
|
22315
22315
|
...cacheKey,
|
|
22316
|
-
path:
|
|
22316
|
+
path: path43
|
|
22317
22317
|
});
|
|
22318
22318
|
for (let i2 = 0; i2 < util.safeHTTPMethods.length; i2++) {
|
|
22319
22319
|
const method = util.safeHTTPMethods[i2];
|
|
@@ -22321,7 +22321,7 @@ var require_cache_handler = __commonJS({
|
|
|
22321
22321
|
deleteCachedValue(store, {
|
|
22322
22322
|
...cacheKey,
|
|
22323
22323
|
method,
|
|
22324
|
-
path:
|
|
22324
|
+
path: path43
|
|
22325
22325
|
});
|
|
22326
22326
|
}
|
|
22327
22327
|
}
|
|
@@ -22332,9 +22332,9 @@ var require_cache_handler = __commonJS({
|
|
|
22332
22332
|
}
|
|
22333
22333
|
const values = Array.isArray(headerValue2) ? headerValue2 : [headerValue2];
|
|
22334
22334
|
for (let i2 = 0; i2 < values.length; i2++) {
|
|
22335
|
-
const
|
|
22336
|
-
if (
|
|
22337
|
-
deleteCachedUri(store, cacheKey,
|
|
22335
|
+
const path43 = getSameOriginPath(cacheKey, values[i2]);
|
|
22336
|
+
if (path43 !== void 0) {
|
|
22337
|
+
deleteCachedUri(store, cacheKey, path43);
|
|
22338
22338
|
}
|
|
22339
22339
|
}
|
|
22340
22340
|
}
|
|
@@ -27334,11 +27334,11 @@ var require_fetch = __commonJS({
|
|
|
27334
27334
|
function dispatch({ body }) {
|
|
27335
27335
|
const url2 = requestCurrentURL(request7);
|
|
27336
27336
|
const agent = fetchParams.controller.dispatcher;
|
|
27337
|
-
const
|
|
27337
|
+
const path43 = url2.pathname + url2.search;
|
|
27338
27338
|
const hasTrailingQuestionMark = url2.search.length === 0 && url2.href[url2.href.length - url2.hash.length - 1] === "?";
|
|
27339
27339
|
return new Promise((resolve, reject) => agent.dispatch(
|
|
27340
27340
|
{
|
|
27341
|
-
path: hasTrailingQuestionMark ? `${
|
|
27341
|
+
path: hasTrailingQuestionMark ? `${path43}?` : path43,
|
|
27342
27342
|
origin: url2.origin,
|
|
27343
27343
|
method: request7.method,
|
|
27344
27344
|
body: agent.isMockActive ? request7.body && (request7.body.source || request7.body.stream) : body,
|
|
@@ -28285,9 +28285,9 @@ var require_util5 = __commonJS({
|
|
|
28285
28285
|
}
|
|
28286
28286
|
}
|
|
28287
28287
|
}
|
|
28288
|
-
function validateCookiePath(
|
|
28289
|
-
for (let i2 = 0; i2 <
|
|
28290
|
-
const code =
|
|
28288
|
+
function validateCookiePath(path43) {
|
|
28289
|
+
for (let i2 = 0; i2 < path43.length; ++i2) {
|
|
28290
|
+
const code = path43.charCodeAt(i2);
|
|
28291
28291
|
if (code < 32 || // exclude CTLs (0-31)
|
|
28292
28292
|
code > 126 || // exclude DEL and non-ascii
|
|
28293
28293
|
code === 59) {
|
|
@@ -31635,11 +31635,11 @@ var require_undici = __commonJS({
|
|
|
31635
31635
|
if (typeof opts.path !== "string") {
|
|
31636
31636
|
throw new InvalidArgumentError2("invalid opts.path");
|
|
31637
31637
|
}
|
|
31638
|
-
let
|
|
31638
|
+
let path43 = opts.path;
|
|
31639
31639
|
if (!opts.path.startsWith("/")) {
|
|
31640
|
-
|
|
31640
|
+
path43 = `/${path43}`;
|
|
31641
31641
|
}
|
|
31642
|
-
url2 = new URL(util.parseOrigin(url2).origin +
|
|
31642
|
+
url2 = new URL(util.parseOrigin(url2).origin + path43);
|
|
31643
31643
|
} else {
|
|
31644
31644
|
if (!opts) {
|
|
31645
31645
|
opts = typeof url2 === "object" ? url2 : {};
|
|
@@ -31749,7 +31749,7 @@ ${captureLines}` : capture.stack;
|
|
|
31749
31749
|
});
|
|
31750
31750
|
|
|
31751
31751
|
// src/cli.ts
|
|
31752
|
-
var
|
|
31752
|
+
var import_node_path41 = __toESM(require("node:path"), 1);
|
|
31753
31753
|
|
|
31754
31754
|
// node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
|
|
31755
31755
|
var CommanderError = class extends Error {
|
|
@@ -34862,9 +34862,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
34862
34862
|
* @param {string} [path]
|
|
34863
34863
|
* @return {(string|null|Command)}
|
|
34864
34864
|
*/
|
|
34865
|
-
executableDir(
|
|
34866
|
-
if (
|
|
34867
|
-
this._executableDir =
|
|
34865
|
+
executableDir(path43) {
|
|
34866
|
+
if (path43 === void 0) return this._executableDir;
|
|
34867
|
+
this._executableDir = path43;
|
|
34868
34868
|
return this;
|
|
34869
34869
|
}
|
|
34870
34870
|
/**
|
|
@@ -36002,10 +36002,10 @@ function mergeDefs(...defs) {
|
|
|
36002
36002
|
function cloneDef(schema) {
|
|
36003
36003
|
return mergeDefs(schema._zod.def);
|
|
36004
36004
|
}
|
|
36005
|
-
function getElementAtPath(obj,
|
|
36006
|
-
if (!
|
|
36005
|
+
function getElementAtPath(obj, path43) {
|
|
36006
|
+
if (!path43)
|
|
36007
36007
|
return obj;
|
|
36008
|
-
return
|
|
36008
|
+
return path43.reduce((acc, key) => acc?.[key], obj);
|
|
36009
36009
|
}
|
|
36010
36010
|
function promiseAllObject(promisesObj) {
|
|
36011
36011
|
const keys = Object.keys(promisesObj);
|
|
@@ -36345,11 +36345,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
36345
36345
|
}
|
|
36346
36346
|
return false;
|
|
36347
36347
|
}
|
|
36348
|
-
function prefixIssues(
|
|
36348
|
+
function prefixIssues(path43, issues) {
|
|
36349
36349
|
return issues.map((iss) => {
|
|
36350
36350
|
var _a3;
|
|
36351
36351
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
36352
|
-
iss.path.unshift(
|
|
36352
|
+
iss.path.unshift(path43);
|
|
36353
36353
|
return iss;
|
|
36354
36354
|
});
|
|
36355
36355
|
}
|
|
@@ -36799,16 +36799,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
|
36799
36799
|
}
|
|
36800
36800
|
function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
36801
36801
|
const fieldErrors = { _errors: [] };
|
|
36802
|
-
const processError = (error63,
|
|
36802
|
+
const processError = (error63, path43 = []) => {
|
|
36803
36803
|
for (const issue2 of error63.issues) {
|
|
36804
36804
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
36805
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
36805
|
+
issue2.errors.map((issues) => processError({ issues }, [...path43, ...issue2.path]));
|
|
36806
36806
|
} else if (issue2.code === "invalid_key") {
|
|
36807
|
-
processError({ issues: issue2.issues }, [...
|
|
36807
|
+
processError({ issues: issue2.issues }, [...path43, ...issue2.path]);
|
|
36808
36808
|
} else if (issue2.code === "invalid_element") {
|
|
36809
|
-
processError({ issues: issue2.issues }, [...
|
|
36809
|
+
processError({ issues: issue2.issues }, [...path43, ...issue2.path]);
|
|
36810
36810
|
} else {
|
|
36811
|
-
const fullpath = [...
|
|
36811
|
+
const fullpath = [...path43, ...issue2.path];
|
|
36812
36812
|
if (fullpath.length === 0) {
|
|
36813
36813
|
fieldErrors._errors.push(mapper(issue2));
|
|
36814
36814
|
} else {
|
|
@@ -36847,17 +36847,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
|
36847
36847
|
}
|
|
36848
36848
|
function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
36849
36849
|
const result = { errors: [] };
|
|
36850
|
-
const processError = (error63,
|
|
36850
|
+
const processError = (error63, path43 = []) => {
|
|
36851
36851
|
var _a3;
|
|
36852
36852
|
for (const issue2 of error63.issues) {
|
|
36853
36853
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
36854
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
36854
|
+
issue2.errors.map((issues) => processError({ issues }, [...path43, ...issue2.path]));
|
|
36855
36855
|
} else if (issue2.code === "invalid_key") {
|
|
36856
|
-
processError({ issues: issue2.issues }, [...
|
|
36856
|
+
processError({ issues: issue2.issues }, [...path43, ...issue2.path]);
|
|
36857
36857
|
} else if (issue2.code === "invalid_element") {
|
|
36858
|
-
processError({ issues: issue2.issues }, [...
|
|
36858
|
+
processError({ issues: issue2.issues }, [...path43, ...issue2.path]);
|
|
36859
36859
|
} else {
|
|
36860
|
-
const fullpath = [...
|
|
36860
|
+
const fullpath = [...path43, ...issue2.path];
|
|
36861
36861
|
if (fullpath.length === 0) {
|
|
36862
36862
|
result.errors.push(mapper(issue2));
|
|
36863
36863
|
continue;
|
|
@@ -36896,8 +36896,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
|
36896
36896
|
}
|
|
36897
36897
|
function toDotPath(_path) {
|
|
36898
36898
|
const segs = [];
|
|
36899
|
-
const
|
|
36900
|
-
for (const seg of
|
|
36899
|
+
const path43 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
36900
|
+
for (const seg of path43) {
|
|
36901
36901
|
if (typeof seg === "number")
|
|
36902
36902
|
segs.push(`[${seg}]`);
|
|
36903
36903
|
else if (typeof seg === "symbol")
|
|
@@ -53999,13 +53999,13 @@ function resolveRef(ref, ctx) {
|
|
|
53999
53999
|
if (!ref.startsWith("#")) {
|
|
54000
54000
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
54001
54001
|
}
|
|
54002
|
-
const
|
|
54003
|
-
if (
|
|
54002
|
+
const path43 = ref.slice(1).split("/").filter(Boolean);
|
|
54003
|
+
if (path43.length === 0) {
|
|
54004
54004
|
return ctx.rootSchema;
|
|
54005
54005
|
}
|
|
54006
54006
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
54007
|
-
if (
|
|
54008
|
-
const key =
|
|
54007
|
+
if (path43[0] === defsKey) {
|
|
54008
|
+
const key = path43[1] === void 0 ? void 0 : decodeJSONPointerSegment(path43[1]);
|
|
54009
54009
|
if (!key || !ctx.defs[key]) {
|
|
54010
54010
|
throw new Error(`Reference not found: ${ref}`);
|
|
54011
54011
|
}
|
|
@@ -61710,7 +61710,7 @@ function registerIdentityCommand(program2, deps) {
|
|
|
61710
61710
|
// package.json
|
|
61711
61711
|
var package_default = {
|
|
61712
61712
|
name: "agent-shim",
|
|
61713
|
-
version: "8.
|
|
61713
|
+
version: "8.12.0",
|
|
61714
61714
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
61715
61715
|
license: "MIT",
|
|
61716
61716
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -62140,11 +62140,11 @@ function providerBaseUrl(port, provider) {
|
|
|
62140
62140
|
function directOrigin(port) {
|
|
62141
62141
|
return `http://127.0.0.1:${String(port)}`;
|
|
62142
62142
|
}
|
|
62143
|
-
function parseProviderPath(
|
|
62144
|
-
if (!
|
|
62143
|
+
function parseProviderPath(path43) {
|
|
62144
|
+
if (!path43.startsWith(PROVIDER_PATH_PREFIX)) {
|
|
62145
62145
|
return void 0;
|
|
62146
62146
|
}
|
|
62147
|
-
const tail =
|
|
62147
|
+
const tail = path43.slice(PROVIDER_PATH_PREFIX.length);
|
|
62148
62148
|
const slash = tail.indexOf("/");
|
|
62149
62149
|
if (slash <= 0) {
|
|
62150
62150
|
return void 0;
|
|
@@ -62544,9 +62544,9 @@ function decoderFor(encoding) {
|
|
|
62544
62544
|
return void 0;
|
|
62545
62545
|
}
|
|
62546
62546
|
}
|
|
62547
|
-
function destinationOf(
|
|
62548
|
-
const scoped = parseProviderPath(
|
|
62549
|
-
return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint:
|
|
62547
|
+
function destinationOf(path43) {
|
|
62548
|
+
const scoped = parseProviderPath(path43);
|
|
62549
|
+
return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path43 } : { provider: scoped.provider, endpoint: scoped.rest };
|
|
62550
62550
|
}
|
|
62551
62551
|
function buildRecord(event, context) {
|
|
62552
62552
|
const { scan } = context;
|
|
@@ -64446,7 +64446,7 @@ function registerCodexCommand(program2, deps) {
|
|
|
64446
64446
|
|
|
64447
64447
|
// src/frontdoor/commands.ts
|
|
64448
64448
|
var import_node_crypto12 = require("node:crypto");
|
|
64449
|
-
var
|
|
64449
|
+
var import_node_path34 = __toESM(require("node:path"), 1);
|
|
64450
64450
|
var import_node_fs12 = __toESM(require("node:fs"), 1);
|
|
64451
64451
|
|
|
64452
64452
|
// src/frontdoor/custody.ts
|
|
@@ -65176,8 +65176,8 @@ function parseConnectTarget(authority) {
|
|
|
65176
65176
|
}
|
|
65177
65177
|
return { host, port };
|
|
65178
65178
|
}
|
|
65179
|
-
function servedByPipeline(
|
|
65180
|
-
return
|
|
65179
|
+
function servedByPipeline(path43) {
|
|
65180
|
+
return path43?.startsWith(ROUTED_PATH_PREFIX) === true;
|
|
65181
65181
|
}
|
|
65182
65182
|
var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
|
|
65183
65183
|
"connection",
|
|
@@ -65260,14 +65260,17 @@ ${request7.rawHeaders.reduce((accumulated, value2, index) => index % 2 === 0 ? `
|
|
|
65260
65260
|
pumpTapSession(socket, async (clientAlpn) => await effects.connectTlsUpstream(host, HTTPS_PORT, clientAlpn), config2.capture?.tapStream?.(host), Buffer.from(headText, "utf8"));
|
|
65261
65261
|
};
|
|
65262
65262
|
const sessions = config2.interceptHosts.map((host) => {
|
|
65263
|
-
if (config2.tapHosts.includes(host)) {
|
|
65263
|
+
if (config2.tapHosts.includes(host) && !(config2.localSurface?.parsesHost(host) ?? false)) {
|
|
65264
65264
|
const serveSecure2 = (secure) => {
|
|
65265
65265
|
pumpTapSession(secure, async (clientAlpn) => await effects.connectTlsUpstream(host, HTTPS_PORT, clientAlpn), config2.capture?.tapStream?.(host));
|
|
65266
65266
|
};
|
|
65267
65267
|
const tlsAcceptor2 = effects.createTlsAcceptor(config2.leafFor(host), serveSecure2, TAP_ALPN_PROTOCOLS);
|
|
65268
65268
|
return { host, serveSecure: serveSecure2, tlsAcceptor: tlsAcceptor2 };
|
|
65269
65269
|
}
|
|
65270
|
-
const
|
|
65270
|
+
const handleHostRequest = async (request7, response) => {
|
|
65271
|
+
if (config2.localSurface !== void 0 && await config2.localSurface.serve(host, request7, response)) {
|
|
65272
|
+
return;
|
|
65273
|
+
}
|
|
65271
65274
|
if (host === config2.routedHost && servedByPipeline(request7.url)) {
|
|
65272
65275
|
const tunnelToken = tunnelTokens.get(request7.socket);
|
|
65273
65276
|
if (tunnelToken !== void 0 && request7.headers[AUTH_HEADER] === void 0) {
|
|
@@ -65278,6 +65281,9 @@ ${request7.rawHeaders.reduce((accumulated, value2, index) => index % 2 === 0 ? `
|
|
|
65278
65281
|
}
|
|
65279
65282
|
effects.forwardHttp(config2.upstreamFor(host), request7, response, config2.capture?.observePassthrough(request7));
|
|
65280
65283
|
};
|
|
65284
|
+
const handler = (request7, response) => {
|
|
65285
|
+
void handleHostRequest(request7, response);
|
|
65286
|
+
};
|
|
65281
65287
|
const httpSession = effects.createHttpSession(handler, onUpgrade(host));
|
|
65282
65288
|
const serveSecure = (secure, capability) => {
|
|
65283
65289
|
tunnelTokens.set(secure, capability);
|
|
@@ -65648,7 +65654,7 @@ function parseRcRequestBody(kind, body) {
|
|
|
65648
65654
|
return { controlRequests: [], answeredRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0 };
|
|
65649
65655
|
}
|
|
65650
65656
|
if (kind === "worker-registration") {
|
|
65651
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(parseJsonObject(body), "
|
|
65657
|
+
return { controlRequests: [], answeredRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(parseJsonObject(body), "worker_status") };
|
|
65652
65658
|
}
|
|
65653
65659
|
const controlRequests = [];
|
|
65654
65660
|
const answeredRequestIds = [];
|
|
@@ -65697,11 +65703,11 @@ function createRcSessionTracker(deps) {
|
|
|
65697
65703
|
};
|
|
65698
65704
|
const observeExchange = (request7) => {
|
|
65699
65705
|
const method = (request7.method ?? "").toUpperCase();
|
|
65700
|
-
const
|
|
65701
|
-
if (!
|
|
65706
|
+
const path43 = new URL(request7.url ?? "/", "http://127.0.0.1").pathname;
|
|
65707
|
+
if (!path43.startsWith(RC_SESSIONS_PATH_PREFIX)) {
|
|
65702
65708
|
return void 0;
|
|
65703
65709
|
}
|
|
65704
|
-
const tail =
|
|
65710
|
+
const tail = path43.slice(RC_SESSIONS_PATH_PREFIX.length);
|
|
65705
65711
|
const facts = {
|
|
65706
65712
|
oauthAuthorization: oauthAuthorizationOf(request7.headers),
|
|
65707
65713
|
anthropicVersion: singleHeader(request7.headers, "anthropic-version"),
|
|
@@ -66441,9 +66447,9 @@ function sequenceNumsOfBody(body) {
|
|
|
66441
66447
|
}
|
|
66442
66448
|
function frontDoorRcControl(transport, token) {
|
|
66443
66449
|
const headers = { authorization: `Bearer ${token}` };
|
|
66444
|
-
const listAnswerOf = async (
|
|
66450
|
+
const listAnswerOf = async (path43, what) => {
|
|
66445
66451
|
try {
|
|
66446
|
-
return await transport.request({ method: "GET", path:
|
|
66452
|
+
return await transport.request({ method: "GET", path: path43, headers });
|
|
66447
66453
|
} catch (error62) {
|
|
66448
66454
|
throw new Error(`${what}: could not reach the front door's control listener: ${error62 instanceof Error ? error62.message : String(error62)}`, { cause: error62 });
|
|
66449
66455
|
}
|
|
@@ -66515,10 +66521,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
66515
66521
|
}
|
|
66516
66522
|
return pending;
|
|
66517
66523
|
};
|
|
66518
|
-
const writeOf = async (
|
|
66524
|
+
const writeOf = async (path43, body, describeFailure) => {
|
|
66519
66525
|
let answer;
|
|
66520
66526
|
try {
|
|
66521
|
-
answer = await transport.request({ method: "POST", path:
|
|
66527
|
+
answer = await transport.request({ method: "POST", path: path43, headers: { ...headers, "content-type": "application/json" }, body });
|
|
66522
66528
|
} catch (error62) {
|
|
66523
66529
|
return { ok: false, message: `could not reach the front door's control listener: ${error62 instanceof Error ? error62.message : String(error62)}` };
|
|
66524
66530
|
}
|
|
@@ -66862,14 +66868,41 @@ var NO_CHUNKS = {
|
|
|
66862
66868
|
next: async () => await Promise.resolve({ done: true, value: void 0 })
|
|
66863
66869
|
})
|
|
66864
66870
|
};
|
|
66871
|
+
function lateRcEventDial(resolve) {
|
|
66872
|
+
let built;
|
|
66873
|
+
const dialFor = () => {
|
|
66874
|
+
const target = resolve();
|
|
66875
|
+
if (built === void 0 || built.for !== target) {
|
|
66876
|
+
built = { for: target, dial: realRcEventDial(target) };
|
|
66877
|
+
}
|
|
66878
|
+
return built.dial;
|
|
66879
|
+
};
|
|
66880
|
+
return {
|
|
66881
|
+
writeEvents: async (sessionId, headers, body) => await dialFor().writeEvents(sessionId, headers, body)
|
|
66882
|
+
};
|
|
66883
|
+
}
|
|
66884
|
+
function lateRcStreamDial(resolve) {
|
|
66885
|
+
let built;
|
|
66886
|
+
const dialFor = () => {
|
|
66887
|
+
const target = resolve();
|
|
66888
|
+
if (built === void 0 || built.for !== target) {
|
|
66889
|
+
built = { for: target, dial: realRcStreamDial(target) };
|
|
66890
|
+
}
|
|
66891
|
+
return built.dial;
|
|
66892
|
+
};
|
|
66893
|
+
return {
|
|
66894
|
+
announcePresence: async (sessionId, headers, clientId) => await dialFor().announcePresence(sessionId, headers, clientId),
|
|
66895
|
+
openStream: async (sessionId, headers, resume, signal) => await dialFor().openStream(sessionId, headers, resume, signal)
|
|
66896
|
+
};
|
|
66897
|
+
}
|
|
66865
66898
|
function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
66866
66899
|
const agent = new ExemptTlsAgent();
|
|
66867
|
-
const request7 = async (method,
|
|
66900
|
+
const request7 = async (method, path43, headers, body, signal) => await new Promise((resolve, reject) => {
|
|
66868
66901
|
const options = {
|
|
66869
66902
|
host: target.host,
|
|
66870
66903
|
port: target.port,
|
|
66871
66904
|
method,
|
|
66872
|
-
path:
|
|
66905
|
+
path: path43,
|
|
66873
66906
|
// The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
|
|
66874
66907
|
headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
|
|
66875
66908
|
agent,
|
|
@@ -66906,9 +66939,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
|
|
|
66906
66939
|
return { status, body: await readAll(response) };
|
|
66907
66940
|
},
|
|
66908
66941
|
openStream: async (sessionId, headers, resume, signal) => {
|
|
66909
|
-
const
|
|
66942
|
+
const path43 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
|
|
66910
66943
|
const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
|
|
66911
|
-
const { status, response } = await request7("GET",
|
|
66944
|
+
const { status, response } = await request7("GET", path43, streamHeaders, void 0, signal);
|
|
66912
66945
|
if (!isSuccessful2(status)) {
|
|
66913
66946
|
await readAll(response);
|
|
66914
66947
|
return { status, chunks: NO_CHUNKS };
|
|
@@ -68031,9 +68064,9 @@ function resolveFriendlyClientOptions(options) {
|
|
|
68031
68064
|
};
|
|
68032
68065
|
}
|
|
68033
68066
|
function createORPCClient(link, options = {}) {
|
|
68034
|
-
const
|
|
68067
|
+
const path43 = options.path ?? [];
|
|
68035
68068
|
const procedureClient = async (...[input2, options2 = {}]) => {
|
|
68036
|
-
return await link.call(
|
|
68069
|
+
return await link.call(path43, input2, resolveFriendlyClientOptions(options2));
|
|
68037
68070
|
};
|
|
68038
68071
|
const recursive2 = new Proxy(procedureClient, {
|
|
68039
68072
|
get(target, key) {
|
|
@@ -68042,7 +68075,7 @@ function createORPCClient(link, options = {}) {
|
|
|
68042
68075
|
}
|
|
68043
68076
|
return createORPCClient(link, {
|
|
68044
68077
|
...options,
|
|
68045
|
-
path: [...
|
|
68078
|
+
path: [...path43, key]
|
|
68046
68079
|
});
|
|
68047
68080
|
}
|
|
68048
68081
|
});
|
|
@@ -68344,19 +68377,19 @@ var StandardLink = class {
|
|
|
68344
68377
|
}
|
|
68345
68378
|
interceptors;
|
|
68346
68379
|
clientInterceptors;
|
|
68347
|
-
call(
|
|
68380
|
+
call(path43, input2, options) {
|
|
68348
68381
|
return runWithSpan(
|
|
68349
|
-
{ name: `${ORPC_NAME}.${
|
|
68382
|
+
{ name: `${ORPC_NAME}.${path43.join("/")}`, signal: options.signal },
|
|
68350
68383
|
(span) => {
|
|
68351
68384
|
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
68352
|
-
span?.setAttribute("rpc.method",
|
|
68385
|
+
span?.setAttribute("rpc.method", path43.join("."));
|
|
68353
68386
|
if (isAsyncIteratorObject(input2)) {
|
|
68354
68387
|
input2 = asyncIteratorWithSpan(
|
|
68355
68388
|
{ name: "consume_event_iterator_input", signal: options.signal },
|
|
68356
68389
|
input2
|
|
68357
68390
|
);
|
|
68358
68391
|
}
|
|
68359
|
-
return intercept(this.interceptors, { ...options, path:
|
|
68392
|
+
return intercept(this.interceptors, { ...options, path: path43, input: input2 }, async ({ path: path210, input: input22, ...options2 }) => {
|
|
68360
68393
|
const otelConfig = getGlobalOtelConfig();
|
|
68361
68394
|
let otelContext;
|
|
68362
68395
|
const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
|
|
@@ -68591,8 +68624,8 @@ var StandardRPCJsonSerializer = class {
|
|
|
68591
68624
|
return ref.data;
|
|
68592
68625
|
}
|
|
68593
68626
|
};
|
|
68594
|
-
function toHttpPath(
|
|
68595
|
-
return `/${
|
|
68627
|
+
function toHttpPath(path43) {
|
|
68628
|
+
return `/${path43.map(encodeURIComponent).join("/")}`;
|
|
68596
68629
|
}
|
|
68597
68630
|
function toStandardHeaders2(headers) {
|
|
68598
68631
|
if (typeof headers.forEach === "function") {
|
|
@@ -68617,18 +68650,18 @@ var StandardRPCLinkCodec = class {
|
|
|
68617
68650
|
fallbackMethod;
|
|
68618
68651
|
expectedMethod;
|
|
68619
68652
|
headers;
|
|
68620
|
-
async encode(
|
|
68621
|
-
let headers = toStandardHeaders2(await value(this.headers, options,
|
|
68653
|
+
async encode(path43, input2, options) {
|
|
68654
|
+
let headers = toStandardHeaders2(await value(this.headers, options, path43, input2));
|
|
68622
68655
|
if (options.lastEventId !== void 0) {
|
|
68623
68656
|
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
68624
68657
|
}
|
|
68625
|
-
const expectedMethod = await value(this.expectedMethod, options,
|
|
68626
|
-
const baseUrl = await value(this.baseUrl, options,
|
|
68658
|
+
const expectedMethod = await value(this.expectedMethod, options, path43, input2);
|
|
68659
|
+
const baseUrl = await value(this.baseUrl, options, path43, input2);
|
|
68627
68660
|
const url2 = new URL(baseUrl);
|
|
68628
|
-
url2.pathname = `${url2.pathname.replace(/\/$/, "")}${toHttpPath(
|
|
68661
|
+
url2.pathname = `${url2.pathname.replace(/\/$/, "")}${toHttpPath(path43)}`;
|
|
68629
68662
|
const serialized = this.serializer.serialize(input2);
|
|
68630
68663
|
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
68631
|
-
const maxUrlLength = await value(this.maxUrlLength, options,
|
|
68664
|
+
const maxUrlLength = await value(this.maxUrlLength, options, path43, input2);
|
|
68632
68665
|
const getUrl = new URL(url2);
|
|
68633
68666
|
getUrl.searchParams.append("data", stringifyJSON(serialized));
|
|
68634
68667
|
if (getUrl.toString().length <= maxUrlLength) {
|
|
@@ -68779,11 +68812,11 @@ var LinkFetchClient = class {
|
|
|
68779
68812
|
this.toFetchRequestOptions = options;
|
|
68780
68813
|
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
|
68781
68814
|
}
|
|
68782
|
-
async call(standardRequest, options,
|
|
68815
|
+
async call(standardRequest, options, path43, input2) {
|
|
68783
68816
|
const request7 = toFetchRequest(standardRequest, this.toFetchRequestOptions);
|
|
68784
68817
|
const fetchResponse = await intercept(
|
|
68785
68818
|
this.adapterInterceptors,
|
|
68786
|
-
{ ...options, request: request7, path:
|
|
68819
|
+
{ ...options, request: request7, path: path43, input: input2, init: { redirect: "manual" } },
|
|
68787
68820
|
({ request: request22, path: path210, input: input22, init, ...options2 }) => this.fetch(request22, init, options2, path210, input22)
|
|
68788
68821
|
);
|
|
68789
68822
|
const lazyResponse = toStandardLazyResponse(fetchResponse, { signal: request7.signal });
|
|
@@ -69183,7 +69216,7 @@ function middlewareOutputFn(output2) {
|
|
|
69183
69216
|
function createProcedureClient(lazyableProcedure, ...rest) {
|
|
69184
69217
|
const options = resolveMaybeOptionalOptions(rest);
|
|
69185
69218
|
return async (...[input2, callerOptions]) => {
|
|
69186
|
-
const
|
|
69219
|
+
const path43 = toArray(options.path);
|
|
69187
69220
|
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
69188
69221
|
const clientContext = callerOptions?.context ?? {};
|
|
69189
69222
|
const context = await value(options.context ?? {}, clientContext);
|
|
@@ -69198,7 +69231,7 @@ function createProcedureClient(lazyableProcedure, ...rest) {
|
|
|
69198
69231
|
const output2 = await runWithSpan(
|
|
69199
69232
|
{ name: "call_procedure", signal: callerOptions?.signal },
|
|
69200
69233
|
(span) => {
|
|
69201
|
-
span?.setAttribute("procedure.path", [...
|
|
69234
|
+
span?.setAttribute("procedure.path", [...path43]);
|
|
69202
69235
|
return intercept(
|
|
69203
69236
|
toArray(options.interceptors),
|
|
69204
69237
|
{
|
|
@@ -69206,7 +69239,7 @@ function createProcedureClient(lazyableProcedure, ...rest) {
|
|
|
69206
69239
|
input: input2,
|
|
69207
69240
|
// input only optional when it undefinable so we can safely cast it
|
|
69208
69241
|
errors,
|
|
69209
|
-
path:
|
|
69242
|
+
path: path43,
|
|
69210
69243
|
procedure,
|
|
69211
69244
|
signal: callerOptions?.signal,
|
|
69212
69245
|
lastEventId: callerOptions?.lastEventId
|
|
@@ -69328,10 +69361,10 @@ var HIDDEN_ROUTER_CONTRACT_SYMBOL = /* @__PURE__ */ Symbol("ORPC_HIDDEN_ROUTER_C
|
|
|
69328
69361
|
function getHiddenRouterContract(router) {
|
|
69329
69362
|
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
69330
69363
|
}
|
|
69331
|
-
function getRouter(router,
|
|
69364
|
+
function getRouter(router, path43) {
|
|
69332
69365
|
let current = router;
|
|
69333
|
-
for (let i2 = 0; i2 <
|
|
69334
|
-
const segment =
|
|
69366
|
+
for (let i2 = 0; i2 < path43.length; i2++) {
|
|
69367
|
+
const segment = path43[i2];
|
|
69335
69368
|
if (!current) {
|
|
69336
69369
|
return void 0;
|
|
69337
69370
|
}
|
|
@@ -69346,7 +69379,7 @@ function getRouter(router, path42) {
|
|
|
69346
69379
|
continue;
|
|
69347
69380
|
}
|
|
69348
69381
|
const lazied = current;
|
|
69349
|
-
const rest =
|
|
69382
|
+
const rest = path43.slice(i2);
|
|
69350
69383
|
return lazy2(async () => {
|
|
69351
69384
|
const unwrapped = await unlazy(lazied);
|
|
69352
69385
|
const next = getRouter(unwrapped.default, rest);
|
|
@@ -69924,8 +69957,8 @@ function toAbortSignal(stream) {
|
|
|
69924
69957
|
function toStandardUrl(req) {
|
|
69925
69958
|
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
|
69926
69959
|
const origin = guard(() => new URL(`${protocol}//${req.headers.host ?? "localhost"}`).origin) ?? `${protocol}//localhost`;
|
|
69927
|
-
const
|
|
69928
|
-
return new URL(`${origin}${
|
|
69960
|
+
const path43 = req.originalUrl ?? req.url ?? "/";
|
|
69961
|
+
return new URL(`${origin}${path43.startsWith("/") ? "" : "/"}${path43}`);
|
|
69929
69962
|
}
|
|
69930
69963
|
function toStandardLazyRequest(req, res) {
|
|
69931
69964
|
const signal = toAbortSignal(res);
|
|
@@ -70124,8 +70157,8 @@ var StandardRPCMatcher = class {
|
|
|
70124
70157
|
constructor(options = {}) {
|
|
70125
70158
|
this.filter = options.filter ?? true;
|
|
70126
70159
|
}
|
|
70127
|
-
init(router,
|
|
70128
|
-
const laziedOptions = traverseContractProcedures({ router, path:
|
|
70160
|
+
init(router, path43 = []) {
|
|
70161
|
+
const laziedOptions = traverseContractProcedures({ router, path: path43 }, (traverseOptions) => {
|
|
70129
70162
|
if (!value(this.filter, traverseOptions)) {
|
|
70130
70163
|
return;
|
|
70131
70164
|
}
|
|
@@ -71587,8 +71620,8 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
|
|
|
71587
71620
|
request7.body.resume();
|
|
71588
71621
|
return;
|
|
71589
71622
|
}
|
|
71590
|
-
const
|
|
71591
|
-
const translated = { method: request7.method, path:
|
|
71623
|
+
const path43 = new URL(request7.url, "http://127.0.0.1").pathname;
|
|
71624
|
+
const translated = { method: request7.method, path: path43, body, signal: request7.signal };
|
|
71592
71625
|
const routed = await route(translated);
|
|
71593
71626
|
if (request7.signal.aborted) {
|
|
71594
71627
|
return;
|
|
@@ -71622,7 +71655,7 @@ function createPassthroughRoute(name, target) {
|
|
|
71622
71655
|
headroomUpstream: target.headroomUpstream,
|
|
71623
71656
|
serve: async (request7, response) => {
|
|
71624
71657
|
const incoming = new URL(request7.url, "http://127.0.0.1");
|
|
71625
|
-
const
|
|
71658
|
+
const path43 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
|
|
71626
71659
|
const headers = forwardableHeaders(request7.headers);
|
|
71627
71660
|
delete headers.host;
|
|
71628
71661
|
await new Promise((resolve) => {
|
|
@@ -71630,7 +71663,7 @@ function createPassthroughRoute(name, target) {
|
|
|
71630
71663
|
host: base.hostname,
|
|
71631
71664
|
port: base.port === "" ? void 0 : Number(base.port),
|
|
71632
71665
|
method: request7.method,
|
|
71633
|
-
path: `${basePath}${
|
|
71666
|
+
path: `${basePath}${path43}${incoming.search}`,
|
|
71634
71667
|
headers,
|
|
71635
71668
|
agent
|
|
71636
71669
|
};
|
|
@@ -71679,6 +71712,7 @@ function createPassthroughRoute(name, target) {
|
|
|
71679
71712
|
|
|
71680
71713
|
// src/frontdoor/providerRoute.ts
|
|
71681
71714
|
function createProviderRouteResolver(deps) {
|
|
71715
|
+
const isRcSelfHostPath = (path43) => path43 === "/v1/code/sessions" || path43.startsWith("/v1/code/sessions/") || path43 === "/v1/sessions" || path43.startsWith("/v1/sessions/");
|
|
71682
71716
|
const oauthRoute = createPassthroughRoute("anthropic", { baseUrl: `https://${CONNECT_INTERCEPT_HOST}:${String(HTTPS_PORT)}`, stripPrefix: void 0, headroomUpstream: void 0 });
|
|
71683
71717
|
const passthroughByTarget = /* @__PURE__ */ new Map();
|
|
71684
71718
|
const passthroughFor = (name, target) => {
|
|
@@ -71692,10 +71726,13 @@ function createProviderRouteResolver(deps) {
|
|
|
71692
71726
|
return route;
|
|
71693
71727
|
};
|
|
71694
71728
|
const resolve = (request7) => {
|
|
71695
|
-
const
|
|
71696
|
-
const scoped = parseProviderPath(
|
|
71729
|
+
const path43 = new URL(request7.url, "http://127.0.0.1").pathname;
|
|
71730
|
+
const scoped = parseProviderPath(path43);
|
|
71697
71731
|
if (scoped === void 0) {
|
|
71698
|
-
|
|
71732
|
+
if (deps.rcSelfHostRoute !== void 0 && isRcSelfHostPath(path43)) {
|
|
71733
|
+
return { ok: true, route: deps.rcSelfHostRoute };
|
|
71734
|
+
}
|
|
71735
|
+
return path43.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path43}` };
|
|
71699
71736
|
}
|
|
71700
71737
|
const { provider } = scoped;
|
|
71701
71738
|
let definition;
|
|
@@ -71792,8 +71829,694 @@ function createRcCredentialStore(fs19, dir) {
|
|
|
71792
71829
|
};
|
|
71793
71830
|
}
|
|
71794
71831
|
|
|
71795
|
-
// src/frontdoor/
|
|
71832
|
+
// src/frontdoor/rcSelfHost.ts
|
|
71833
|
+
var RC_SELF_HOST_ENV = "AGENT_SHIM_FRONTDOOR_RC_SELF_HOST";
|
|
71834
|
+
function rcSelfHostFromEnv(env) {
|
|
71835
|
+
return env[RC_SELF_HOST_ENV] === "1";
|
|
71836
|
+
}
|
|
71837
|
+
var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:claude_code", "user:mcp_servers", "user:file_upload"];
|
|
71838
|
+
var RC_SESSIONS_PATH_PREFIX2 = "/v1/code/sessions";
|
|
71839
|
+
var RC_COMPAT_SESSIONS_PATH = "/v1/sessions";
|
|
71840
|
+
var RC_SESSION_ID_PREFIX2 = "cse_";
|
|
71841
|
+
var RC_SELF_HOST_API_BASE_URL = "https://api.anthropic.com";
|
|
71842
|
+
var RC_SELF_HOST_OAUTH_HOST = "platform.claude.com";
|
|
71843
|
+
var HTTP_CONFLICT = 409;
|
|
71844
|
+
var MS_PER_SECOND6 = 1e3;
|
|
71845
|
+
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
71846
|
+
var RC_SELF_HOST_WORKER_JWT_TTL_SECONDS = 46800;
|
|
71847
|
+
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
71848
|
+
var RC_SELF_HOST_KEEPALIVE_MS = 15e3;
|
|
71849
|
+
var RC_SELF_HOST_RETENTION_MS = 6e5;
|
|
71850
|
+
var RC_PRESENCE_REFRESH_SECONDS = 60;
|
|
71851
|
+
var RC_SELF_HOST_MAX_BATCH_EVENTS = 100;
|
|
71852
|
+
var RC_SELF_HOST_WORKER_EPOCH = 1;
|
|
71796
71853
|
var RC_STREAM_EVENT_NAME = "client_event";
|
|
71854
|
+
var RC_SOURCE_WORKER = "worker";
|
|
71855
|
+
var RC_SOURCE_CLIENT = "client";
|
|
71856
|
+
var CONFLICT_REASON_HEADER2 = "x-ccr-conflict-reason";
|
|
71857
|
+
var CONFLICT_REASON_EPOCH_STALE = "epoch_stale";
|
|
71858
|
+
function isRecord5(value2) {
|
|
71859
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
71860
|
+
}
|
|
71861
|
+
function nonEmptyString2(record2, field) {
|
|
71862
|
+
const value2 = record2 === void 0 ? void 0 : record2[field];
|
|
71863
|
+
return typeof value2 === "string" && value2 !== "" ? value2 : void 0;
|
|
71864
|
+
}
|
|
71865
|
+
function numberOf(record2, field) {
|
|
71866
|
+
const value2 = record2 === void 0 ? void 0 : record2[field];
|
|
71867
|
+
if (typeof value2 === "number" && Number.isFinite(value2)) {
|
|
71868
|
+
return value2;
|
|
71869
|
+
}
|
|
71870
|
+
if (typeof value2 === "string" && /^[0-9]+$/.test(value2)) {
|
|
71871
|
+
return Number(value2);
|
|
71872
|
+
}
|
|
71873
|
+
return void 0;
|
|
71874
|
+
}
|
|
71875
|
+
function singleHeader2(headers, name) {
|
|
71876
|
+
const value2 = headers[name];
|
|
71877
|
+
return typeof value2 === "string" ? value2 : void 0;
|
|
71878
|
+
}
|
|
71879
|
+
function bearerOf(headers) {
|
|
71880
|
+
const presented = singleHeader2(headers, "authorization");
|
|
71881
|
+
if (presented === void 0) {
|
|
71882
|
+
return void 0;
|
|
71883
|
+
}
|
|
71884
|
+
return presented.slice(0, "bearer ".length).toLowerCase() === "bearer " ? presented.slice("bearer ".length) : void 0;
|
|
71885
|
+
}
|
|
71886
|
+
async function readBody3(request7, capBytes) {
|
|
71887
|
+
return await new Promise((resolve, reject) => {
|
|
71888
|
+
const chunks = [];
|
|
71889
|
+
let total = 0;
|
|
71890
|
+
request7.on("data", (chunk) => {
|
|
71891
|
+
total += chunk.length;
|
|
71892
|
+
if (total > capBytes) {
|
|
71893
|
+
request7.destroy();
|
|
71894
|
+
reject(new Error("body too large"));
|
|
71895
|
+
return;
|
|
71896
|
+
}
|
|
71897
|
+
chunks.push(chunk);
|
|
71898
|
+
});
|
|
71899
|
+
request7.on("end", () => {
|
|
71900
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
71901
|
+
});
|
|
71902
|
+
request7.on("error", () => {
|
|
71903
|
+
reject(new Error("the request body ended early"));
|
|
71904
|
+
});
|
|
71905
|
+
});
|
|
71906
|
+
}
|
|
71907
|
+
function parseJsonObject2(body) {
|
|
71908
|
+
let parsed;
|
|
71909
|
+
try {
|
|
71910
|
+
parsed = JSON.parse(body);
|
|
71911
|
+
} catch {
|
|
71912
|
+
return void 0;
|
|
71913
|
+
}
|
|
71914
|
+
return isRecord5(parsed) ? parsed : void 0;
|
|
71915
|
+
}
|
|
71916
|
+
function mintWorkerJwt(randomToken, issuedAt) {
|
|
71917
|
+
const encode3 = (value2) => Buffer.from(JSON.stringify(value2), "utf8").toString("base64url");
|
|
71918
|
+
const header = encode3({ alg: "HS256", typ: "JWT" });
|
|
71919
|
+
const payload = encode3({ exp: Math.floor((issuedAt + RC_SELF_HOST_WORKER_JWT_TTL_SECONDS * MS_PER_SECOND6) / MS_PER_SECOND6), iat: Math.floor(issuedAt / MS_PER_SECOND6) });
|
|
71920
|
+
return `${header}.${payload}.${Buffer.from(randomToken(), "utf8").toString("base64url")}`;
|
|
71921
|
+
}
|
|
71922
|
+
function growthBookFeatures() {
|
|
71923
|
+
return {
|
|
71924
|
+
tengu_ccr_bridge: { defaultValue: true },
|
|
71925
|
+
tengu_bridge_repl_v2: { defaultValue: true },
|
|
71926
|
+
tengu_bridge_repl_v2_cse_shim_enabled: { defaultValue: true },
|
|
71927
|
+
tengu_bridge_min_version: { defaultValue: { minVersion: "0.0.0" } }
|
|
71928
|
+
};
|
|
71929
|
+
}
|
|
71930
|
+
function createRcSelfHostSurface(deps) {
|
|
71931
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
71932
|
+
const sweep = () => {
|
|
71933
|
+
const now = deps.now();
|
|
71934
|
+
for (const session of sessions.values()) {
|
|
71935
|
+
while (session.events[0] !== void 0 && now - session.events[0].storedAt > RC_SELF_HOST_RETENTION_MS) {
|
|
71936
|
+
const dropped = session.events.shift();
|
|
71937
|
+
const uuid3 = dropped === void 0 ? void 0 : nonEmptyString2(dropped.payload, "uuid");
|
|
71938
|
+
if (uuid3 !== void 0) {
|
|
71939
|
+
session.seenPayloadUuids.delete(uuid3);
|
|
71940
|
+
}
|
|
71941
|
+
}
|
|
71942
|
+
if (session.workerStreams.size === 0 && session.clientStreams.size === 0 && now - session.lastTrafficAt > RC_SELF_HOST_RETENTION_MS) {
|
|
71943
|
+
sessions.delete(session.id);
|
|
71944
|
+
}
|
|
71945
|
+
}
|
|
71946
|
+
};
|
|
71947
|
+
const timer = setInterval(sweep, RC_SELF_HOST_RETENTION_MS);
|
|
71948
|
+
timer.unref();
|
|
71949
|
+
const keepalive = setInterval(() => {
|
|
71950
|
+
for (const session of sessions.values()) {
|
|
71951
|
+
for (const sink of [...session.workerStreams, ...session.clientStreams]) {
|
|
71952
|
+
sink.write(": keep-alive\n\n");
|
|
71953
|
+
}
|
|
71954
|
+
}
|
|
71955
|
+
}, RC_SELF_HOST_KEEPALIVE_MS);
|
|
71956
|
+
keepalive.unref();
|
|
71957
|
+
const presentsCredential = (headers) => {
|
|
71958
|
+
const expected = deps.credentialRecord()?.accessToken;
|
|
71959
|
+
const presented = bearerOf(headers);
|
|
71960
|
+
return expected !== void 0 && presented !== void 0 && isLiveCapability(presented, [expected]);
|
|
71961
|
+
};
|
|
71962
|
+
const presentsWorkerJwt = (headers, session) => {
|
|
71963
|
+
const presented = bearerOf(headers);
|
|
71964
|
+
if (presented === void 0) {
|
|
71965
|
+
return false;
|
|
71966
|
+
}
|
|
71967
|
+
for (const minted of session.workerJwts) {
|
|
71968
|
+
if (isLiveCapability(presented, [minted])) {
|
|
71969
|
+
return true;
|
|
71970
|
+
}
|
|
71971
|
+
}
|
|
71972
|
+
return false;
|
|
71973
|
+
};
|
|
71974
|
+
const frameOf = (event) => {
|
|
71975
|
+
const envelope = {
|
|
71976
|
+
event_id: event.eventId,
|
|
71977
|
+
event_type: nonEmptyString2(event.payload, "type") ?? "event",
|
|
71978
|
+
sequence_num: event.sequenceNum,
|
|
71979
|
+
source: event.source,
|
|
71980
|
+
payload: event.payload,
|
|
71981
|
+
created_at: event.createdAt
|
|
71982
|
+
};
|
|
71983
|
+
return `event: ${RC_STREAM_EVENT_NAME}
|
|
71984
|
+
id: ${String(event.sequenceNum)}
|
|
71985
|
+
data: ${JSON.stringify(envelope)}
|
|
71986
|
+
|
|
71987
|
+
`;
|
|
71988
|
+
};
|
|
71989
|
+
const holdStream = async (session, which, wantsReplay, request7, response) => {
|
|
71990
|
+
const url2 = new URL(request7.url, "http://127.0.0.1");
|
|
71991
|
+
const cursor3 = numberOf({ value: url2.searchParams.get("from_sequence_num") }, "value") ?? numberOf({ value: singleHeader2(request7.headers, "last-event-id") }, "value");
|
|
71992
|
+
const replay = cursor3 === void 0 ? [] : session.events.filter((event) => wantsReplay(event) && event.sequenceNum > cursor3);
|
|
71993
|
+
response.start(HTTP_STATUS.ok, { "content-type": "text/event-stream", "cache-control": "no-cache" });
|
|
71994
|
+
response.flush();
|
|
71995
|
+
let pending = Promise.resolve();
|
|
71996
|
+
const sink = {
|
|
71997
|
+
write: (frame) => {
|
|
71998
|
+
pending = pending.then(async () => {
|
|
71999
|
+
await response.write(frame);
|
|
72000
|
+
}).catch(() => {
|
|
72001
|
+
});
|
|
72002
|
+
},
|
|
72003
|
+
retire: () => {
|
|
72004
|
+
session[which].delete(sink);
|
|
72005
|
+
}
|
|
72006
|
+
};
|
|
72007
|
+
session[which].add(sink);
|
|
72008
|
+
session.lastTrafficAt = deps.now();
|
|
72009
|
+
for (const event of replay) {
|
|
72010
|
+
sink.write(frameOf(event));
|
|
72011
|
+
}
|
|
72012
|
+
await new Promise((resolve) => {
|
|
72013
|
+
request7.signal.addEventListener("abort", () => {
|
|
72014
|
+
resolve(void 0);
|
|
72015
|
+
}, { once: true });
|
|
72016
|
+
});
|
|
72017
|
+
sink.retire();
|
|
72018
|
+
response.end();
|
|
72019
|
+
};
|
|
72020
|
+
const publish = (session, source, payload) => {
|
|
72021
|
+
const uuid3 = nonEmptyString2(payload, "uuid");
|
|
72022
|
+
const duplicate = uuid3 !== void 0 && session.seenPayloadUuids.has(uuid3);
|
|
72023
|
+
session.sequenceNum += 1;
|
|
72024
|
+
const event = {
|
|
72025
|
+
sequenceNum: session.sequenceNum,
|
|
72026
|
+
eventId: uuid3 ?? deps.newUuid(),
|
|
72027
|
+
source,
|
|
72028
|
+
// The one enrichment the real service was observed making on the live rig's stream: the wall-clock instant it took the write. The worker's handler ignores it; the door's own parser forwards it verbatim.
|
|
72029
|
+
payload: source === RC_SOURCE_CLIENT ? { ...payload, server_received_wall_ms: deps.now() } : payload,
|
|
72030
|
+
createdAt: new Date(deps.now()).toISOString(),
|
|
72031
|
+
toWorker: source === RC_SOURCE_CLIENT,
|
|
72032
|
+
storedAt: deps.now()
|
|
72033
|
+
};
|
|
72034
|
+
session.events.push(event);
|
|
72035
|
+
if (uuid3 !== void 0) {
|
|
72036
|
+
session.seenPayloadUuids.add(uuid3);
|
|
72037
|
+
}
|
|
72038
|
+
session.lastTrafficAt = event.storedAt;
|
|
72039
|
+
const frame = frameOf(event);
|
|
72040
|
+
if (event.toWorker) {
|
|
72041
|
+
for (const sink of [...session.workerStreams]) {
|
|
72042
|
+
sink.write(frame);
|
|
72043
|
+
}
|
|
72044
|
+
}
|
|
72045
|
+
for (const sink of [...session.clientStreams]) {
|
|
72046
|
+
sink.write(frame);
|
|
72047
|
+
}
|
|
72048
|
+
return { sequenceNum: event.sequenceNum, eventId: event.eventId, duplicate };
|
|
72049
|
+
};
|
|
72050
|
+
const answerJson2 = async (response, status, body, extraHeaders = {}) => {
|
|
72051
|
+
const text2 = JSON.stringify(body);
|
|
72052
|
+
response.start(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(text2, "utf8")), ...extraHeaders });
|
|
72053
|
+
await response.write(text2);
|
|
72054
|
+
response.end();
|
|
72055
|
+
};
|
|
72056
|
+
const noCredential = async (response) => {
|
|
72057
|
+
await answerJson2(response, HTTP_SERVICE_UNAVAILABLE, { type: "error", error: { type: "api_error", message: "the front door's self-hosted Remote Control surface is on but no credential has been minted for it; run agent-shim frontdoor rc selfhost mint first" } });
|
|
72058
|
+
};
|
|
72059
|
+
const epochStale = async (response) => {
|
|
72060
|
+
await answerJson2(response, HTTP_CONFLICT, { type: "error", error: { type: "api_error", message: "worker_epoch does not match the session's live epoch" } }, { [CONFLICT_REASON_HEADER2]: CONFLICT_REASON_EPOCH_STALE });
|
|
72061
|
+
};
|
|
72062
|
+
const unauthorized = async (response) => {
|
|
72063
|
+
await answerJson2(response, HTTP_STATUS.unauthorized, { type: "error", error: { type: "authentication_error", message: "the self-hosted Remote Control surface did not recognise the presented credential" } });
|
|
72064
|
+
};
|
|
72065
|
+
const serveSessionPath = async (session, tail, request7, response) => {
|
|
72066
|
+
const method = request7.method.toUpperCase();
|
|
72067
|
+
if (session === void 0) {
|
|
72068
|
+
await answerJson2(response, HTTP_STATUS.notFound, { type: "error", error: { type: "api_error", message: "no such Remote Control session on this door" } });
|
|
72069
|
+
return;
|
|
72070
|
+
}
|
|
72071
|
+
session.lastTrafficAt = deps.now();
|
|
72072
|
+
if (tail === "") {
|
|
72073
|
+
if (method !== "GET") {
|
|
72074
|
+
await answerJson2(response, HTTP_STATUS.methodNotAllowed, { type: "error", error: { type: "api_error", message: "the session read is a GET" } });
|
|
72075
|
+
return;
|
|
72076
|
+
}
|
|
72077
|
+
await answerJson2(response, HTTP_STATUS.ok, { session: { id: session.id, title: session.title, created_at: new Date(session.createdAt).toISOString(), status: "active" } });
|
|
72078
|
+
return;
|
|
72079
|
+
}
|
|
72080
|
+
if (tail === "bridge" && method === "POST") {
|
|
72081
|
+
if (!presentsCredential(request7.headers)) {
|
|
72082
|
+
await unauthorized(response);
|
|
72083
|
+
return;
|
|
72084
|
+
}
|
|
72085
|
+
const workerJwt = mintWorkerJwt(deps.randomToken, deps.now());
|
|
72086
|
+
session.workerJwts.add(workerJwt);
|
|
72087
|
+
deps.log?.(`rc selfhost ${session.id}: bridge registration minted a worker credential`);
|
|
72088
|
+
await answerJson2(response, HTTP_STATUS.ok, { worker_jwt: workerJwt, expires_in: RC_SELF_HOST_WORKER_JWT_TTL_SECONDS, api_base_url: RC_SELF_HOST_API_BASE_URL, worker_epoch: RC_SELF_HOST_WORKER_EPOCH });
|
|
72089
|
+
return;
|
|
72090
|
+
}
|
|
72091
|
+
if (tail === "archive" && method === "POST") {
|
|
72092
|
+
if (!presentsCredential(request7.headers)) {
|
|
72093
|
+
await unauthorized(response);
|
|
72094
|
+
return;
|
|
72095
|
+
}
|
|
72096
|
+
for (const sink of [...session.workerStreams, ...session.clientStreams]) {
|
|
72097
|
+
sink.retire();
|
|
72098
|
+
}
|
|
72099
|
+
sessions.delete(session.id);
|
|
72100
|
+
deps.log?.(`rc selfhost ${session.id}: archived at its client's request`);
|
|
72101
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72102
|
+
return;
|
|
72103
|
+
}
|
|
72104
|
+
if (tail === "worker" || tail.startsWith("worker/")) {
|
|
72105
|
+
if (!presentsWorkerJwt(request7.headers, session)) {
|
|
72106
|
+
await unauthorized(response);
|
|
72107
|
+
return;
|
|
72108
|
+
}
|
|
72109
|
+
const workerTail = tail === "worker" ? "" : tail.slice("worker/".length);
|
|
72110
|
+
if (workerTail === "" && method === "GET") {
|
|
72111
|
+
await answerJson2(response, HTTP_STATUS.ok, { worker: { external_metadata: session.externalMetadata ?? null } });
|
|
72112
|
+
return;
|
|
72113
|
+
}
|
|
72114
|
+
if (workerTail === "" && method === "PUT") {
|
|
72115
|
+
const body = parseJsonObject2(await readBody3(request7.body, CONTROL_BODY_CAP_BYTES));
|
|
72116
|
+
const claimedEpoch = numberOf(body, "worker_epoch");
|
|
72117
|
+
if (claimedEpoch !== void 0 && claimedEpoch !== RC_SELF_HOST_WORKER_EPOCH) {
|
|
72118
|
+
await epochStale(response);
|
|
72119
|
+
return;
|
|
72120
|
+
}
|
|
72121
|
+
const status = nonEmptyString2(body, "worker_status");
|
|
72122
|
+
if (status !== void 0) {
|
|
72123
|
+
session.workerStatus = status;
|
|
72124
|
+
}
|
|
72125
|
+
if (isRecord5(body?.external_metadata)) {
|
|
72126
|
+
session.externalMetadata = body.external_metadata;
|
|
72127
|
+
}
|
|
72128
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72129
|
+
return;
|
|
72130
|
+
}
|
|
72131
|
+
if (workerTail === "register" && method === "POST") {
|
|
72132
|
+
await readBody3(request7.body, CONTROL_BODY_CAP_BYTES);
|
|
72133
|
+
await answerJson2(response, HTTP_STATUS.ok, { worker_epoch: RC_SELF_HOST_WORKER_EPOCH });
|
|
72134
|
+
return;
|
|
72135
|
+
}
|
|
72136
|
+
if (workerTail === "heartbeat" && method === "POST") {
|
|
72137
|
+
await readBody3(request7.body, CONTROL_BODY_CAP_BYTES);
|
|
72138
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72139
|
+
return;
|
|
72140
|
+
}
|
|
72141
|
+
if (workerTail === "events" && method === "POST") {
|
|
72142
|
+
const body = parseJsonObject2(await readBody3(request7.body, CONTROL_BODY_CAP_BYTES));
|
|
72143
|
+
const claimedEpoch = numberOf(body, "worker_epoch");
|
|
72144
|
+
if (claimedEpoch !== void 0 && claimedEpoch !== RC_SELF_HOST_WORKER_EPOCH) {
|
|
72145
|
+
await epochStale(response);
|
|
72146
|
+
return;
|
|
72147
|
+
}
|
|
72148
|
+
const events = body?.events;
|
|
72149
|
+
if (!Array.isArray(events) || events.length === 0 || events.length > RC_SELF_HOST_MAX_BATCH_EVENTS) {
|
|
72150
|
+
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: `a worker event batch is a non-empty array of at most ${String(RC_SELF_HOST_MAX_BATCH_EVENTS)} events` } });
|
|
72151
|
+
return;
|
|
72152
|
+
}
|
|
72153
|
+
const results = [];
|
|
72154
|
+
for (const event of events) {
|
|
72155
|
+
if (!isRecord5(event) || !isRecord5(event.payload)) {
|
|
72156
|
+
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a batch is an object carrying one payload object" } });
|
|
72157
|
+
return;
|
|
72158
|
+
}
|
|
72159
|
+
const published = publish(session, RC_SOURCE_WORKER, event.payload);
|
|
72160
|
+
results.push({ event_id: published.eventId, sequence_num: String(published.sequenceNum) });
|
|
72161
|
+
}
|
|
72162
|
+
sweep();
|
|
72163
|
+
await answerJson2(response, HTTP_STATUS.ok, { results });
|
|
72164
|
+
return;
|
|
72165
|
+
}
|
|
72166
|
+
if (workerTail === "events/stream" && method === "GET") {
|
|
72167
|
+
await holdStream(session, "workerStreams", (event) => event.toWorker, request7, response);
|
|
72168
|
+
return;
|
|
72169
|
+
}
|
|
72170
|
+
if (workerTail === "events/delivery" && method === "POST") {
|
|
72171
|
+
await readBody3(request7.body, CONTROL_BODY_CAP_BYTES);
|
|
72172
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72173
|
+
return;
|
|
72174
|
+
}
|
|
72175
|
+
if (workerTail === "internal-events" && method === "POST") {
|
|
72176
|
+
const body = parseJsonObject2(await readBody3(request7.body, CONTROL_BODY_CAP_BYTES));
|
|
72177
|
+
const claimedEpoch = numberOf(body, "worker_epoch");
|
|
72178
|
+
if (claimedEpoch !== void 0 && claimedEpoch !== RC_SELF_HOST_WORKER_EPOCH) {
|
|
72179
|
+
await epochStale(response);
|
|
72180
|
+
return;
|
|
72181
|
+
}
|
|
72182
|
+
const events = body?.events;
|
|
72183
|
+
if (!Array.isArray(events)) {
|
|
72184
|
+
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "an internal event batch is an array" } });
|
|
72185
|
+
return;
|
|
72186
|
+
}
|
|
72187
|
+
for (const event of events) {
|
|
72188
|
+
if (isRecord5(event)) {
|
|
72189
|
+
session.internalEvents.push({ cursor: deps.newUuid(), body: event });
|
|
72190
|
+
}
|
|
72191
|
+
}
|
|
72192
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72193
|
+
return;
|
|
72194
|
+
}
|
|
72195
|
+
if (workerTail === "internal-events" && method === "GET") {
|
|
72196
|
+
const url2 = new URL(request7.url, "http://127.0.0.1");
|
|
72197
|
+
const cursor3 = url2.searchParams.get("cursor");
|
|
72198
|
+
const from = cursor3 === null ? 0 : session.internalEvents.findIndex((event) => event.cursor === cursor3) + 1;
|
|
72199
|
+
const page = session.internalEvents.slice(from);
|
|
72200
|
+
await answerJson2(response, HTTP_STATUS.ok, { data: page.map((event) => event.body), next_cursor: page.length === 0 ? void 0 : page[page.length - 1]?.cursor });
|
|
72201
|
+
return;
|
|
72202
|
+
}
|
|
72203
|
+
if (workerTail === "diagnostics" && method === "POST") {
|
|
72204
|
+
await readBody3(request7.body, CONTROL_BODY_CAP_BYTES);
|
|
72205
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72206
|
+
return;
|
|
72207
|
+
}
|
|
72208
|
+
await answerJson2(response, HTTP_STATUS.notFound, { type: "error", error: { type: "api_error", message: `the self-hosted Remote Control surface serves no worker path "${workerTail}"` } });
|
|
72209
|
+
return;
|
|
72210
|
+
}
|
|
72211
|
+
if (!presentsCredential(request7.headers)) {
|
|
72212
|
+
await unauthorized(response);
|
|
72213
|
+
return;
|
|
72214
|
+
}
|
|
72215
|
+
if (tail === "events" && method === "POST") {
|
|
72216
|
+
const body = parseJsonObject2(await readBody3(request7.body, CONTROL_BODY_CAP_BYTES));
|
|
72217
|
+
const events = body?.events;
|
|
72218
|
+
if (!Array.isArray(events) || events.length === 0 || events.length > RC_SELF_HOST_MAX_BATCH_EVENTS) {
|
|
72219
|
+
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: `a client event write is a non-empty array of at most ${String(RC_SELF_HOST_MAX_BATCH_EVENTS)} events` } });
|
|
72220
|
+
return;
|
|
72221
|
+
}
|
|
72222
|
+
const results = [];
|
|
72223
|
+
for (const event of events) {
|
|
72224
|
+
if (!isRecord5(event) || !isRecord5(event.payload)) {
|
|
72225
|
+
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a write is an object carrying one payload object" } });
|
|
72226
|
+
return;
|
|
72227
|
+
}
|
|
72228
|
+
const published = publish(session, RC_SOURCE_CLIENT, event.payload);
|
|
72229
|
+
results.push({ sequence_num: String(published.sequenceNum), duplicate: published.duplicate });
|
|
72230
|
+
}
|
|
72231
|
+
sweep();
|
|
72232
|
+
await answerJson2(response, HTTP_STATUS.ok, { results });
|
|
72233
|
+
return;
|
|
72234
|
+
}
|
|
72235
|
+
if (tail === "events" && method === "GET") {
|
|
72236
|
+
await answerJson2(response, HTTP_STATUS.ok, { data: session.events.map((event) => ({ event_id: event.eventId, event_type: nonEmptyString2(event.payload, "type") ?? "event", sequence_num: event.sequenceNum, source: event.source, payload: event.payload, created_at: event.createdAt })) });
|
|
72237
|
+
return;
|
|
72238
|
+
}
|
|
72239
|
+
if (tail === "events/stream" && method === "GET") {
|
|
72240
|
+
await holdStream(session, "clientStreams", () => true, request7, response);
|
|
72241
|
+
return;
|
|
72242
|
+
}
|
|
72243
|
+
if (tail === "client/presence" && method === "POST") {
|
|
72244
|
+
await readBody3(request7.body, CONTROL_BODY_CAP_BYTES);
|
|
72245
|
+
await answerJson2(response, HTTP_STATUS.ok, { refresh_after_seconds: RC_PRESENCE_REFRESH_SECONDS });
|
|
72246
|
+
return;
|
|
72247
|
+
}
|
|
72248
|
+
if (tail === "mark_read" && method === "POST") {
|
|
72249
|
+
await readBody3(request7.body, CONTROL_BODY_CAP_BYTES);
|
|
72250
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72251
|
+
return;
|
|
72252
|
+
}
|
|
72253
|
+
if (tail === "teleport-events" && method === "POST") {
|
|
72254
|
+
await readBody3(request7.body, CONTROL_BODY_CAP_BYTES);
|
|
72255
|
+
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
72256
|
+
return;
|
|
72257
|
+
}
|
|
72258
|
+
await answerJson2(response, HTTP_STATUS.notFound, { type: "error", error: { type: "api_error", message: `the self-hosted Remote Control surface serves no path "${tail}"` } });
|
|
72259
|
+
};
|
|
72260
|
+
const recordMissing = () => deps.credentialRecord() === void 0;
|
|
72261
|
+
const route = {
|
|
72262
|
+
name: "rc-selfhost",
|
|
72263
|
+
headroomEligible: false,
|
|
72264
|
+
headroomUpstream: void 0,
|
|
72265
|
+
serve: async (request7, response) => {
|
|
72266
|
+
const method = request7.method.toUpperCase();
|
|
72267
|
+
const pathname = new URL(request7.url, "http://127.0.0.1").pathname;
|
|
72268
|
+
if (recordMissing()) {
|
|
72269
|
+
await noCredential(response);
|
|
72270
|
+
return;
|
|
72271
|
+
}
|
|
72272
|
+
if (pathname === RC_COMPAT_SESSIONS_PATH) {
|
|
72273
|
+
if (method !== "GET") {
|
|
72274
|
+
await answerJson2(response, HTTP_STATUS.methodNotAllowed, { type: "error", error: { type: "api_error", message: "the compatibility session list is a GET" } });
|
|
72275
|
+
return;
|
|
72276
|
+
}
|
|
72277
|
+
if (!presentsCredential(request7.headers)) {
|
|
72278
|
+
await unauthorized(response);
|
|
72279
|
+
return;
|
|
72280
|
+
}
|
|
72281
|
+
await answerJson2(response, HTTP_STATUS.ok, { data: [] });
|
|
72282
|
+
return;
|
|
72283
|
+
}
|
|
72284
|
+
if (pathname !== RC_SESSIONS_PATH_PREFIX2 && !pathname.startsWith(`${RC_SESSIONS_PATH_PREFIX2}/`)) {
|
|
72285
|
+
await answerJson2(response, HTTP_STATUS.notFound, { type: "error", error: { type: "api_error", message: `the self-hosted Remote Control surface serves no path "${pathname}"` } });
|
|
72286
|
+
return;
|
|
72287
|
+
}
|
|
72288
|
+
if (pathname === RC_SESSIONS_PATH_PREFIX2) {
|
|
72289
|
+
if (method === "POST") {
|
|
72290
|
+
if (!presentsCredential(request7.headers)) {
|
|
72291
|
+
await unauthorized(response);
|
|
72292
|
+
return;
|
|
72293
|
+
}
|
|
72294
|
+
const body = parseJsonObject2(await readBody3(request7.body, CONTROL_BODY_CAP_BYTES));
|
|
72295
|
+
const session = {
|
|
72296
|
+
id: `${RC_SESSION_ID_PREFIX2}${deps.newUuid()}`,
|
|
72297
|
+
createdAt: deps.now(),
|
|
72298
|
+
title: nonEmptyString2(body, "title"),
|
|
72299
|
+
workerJwts: /* @__PURE__ */ new Set(),
|
|
72300
|
+
sequenceNum: 0,
|
|
72301
|
+
events: [],
|
|
72302
|
+
seenPayloadUuids: /* @__PURE__ */ new Set(),
|
|
72303
|
+
workerStreams: /* @__PURE__ */ new Set(),
|
|
72304
|
+
clientStreams: /* @__PURE__ */ new Set(),
|
|
72305
|
+
internalEvents: [],
|
|
72306
|
+
workerStatus: void 0,
|
|
72307
|
+
externalMetadata: void 0,
|
|
72308
|
+
lastTrafficAt: deps.now()
|
|
72309
|
+
};
|
|
72310
|
+
sessions.set(session.id, session);
|
|
72311
|
+
deps.log?.(`rc selfhost ${session.id}: session created on the door's own surface`);
|
|
72312
|
+
await answerJson2(response, HTTP_STATUS.ok, { session: { id: session.id, title: session.title, created_at: new Date(session.createdAt).toISOString(), status: "active" } });
|
|
72313
|
+
return;
|
|
72314
|
+
}
|
|
72315
|
+
if (method === "GET") {
|
|
72316
|
+
if (!presentsCredential(request7.headers)) {
|
|
72317
|
+
await unauthorized(response);
|
|
72318
|
+
return;
|
|
72319
|
+
}
|
|
72320
|
+
await answerJson2(response, HTTP_STATUS.ok, { data: [...sessions.values()].map((session) => ({ id: session.id, title: session.title, created_at: new Date(session.createdAt).toISOString(), updated_at: new Date(session.lastTrafficAt).toISOString(), session_status: "active" })) });
|
|
72321
|
+
return;
|
|
72322
|
+
}
|
|
72323
|
+
await answerJson2(response, HTTP_STATUS.methodNotAllowed, { type: "error", error: { type: "api_error", message: "the session collection is a POST (create) and a GET (list)" } });
|
|
72324
|
+
return;
|
|
72325
|
+
}
|
|
72326
|
+
const rest = pathname.slice(`${RC_SESSIONS_PATH_PREFIX2}/`.length);
|
|
72327
|
+
const slash = rest.indexOf("/");
|
|
72328
|
+
const id = slash === -1 ? rest : rest.slice(0, slash);
|
|
72329
|
+
const tail = slash === -1 ? "" : rest.slice(slash + 1);
|
|
72330
|
+
if (!id.startsWith(RC_SESSION_ID_PREFIX2)) {
|
|
72331
|
+
await answerJson2(response, HTTP_STATUS.notFound, { type: "error", error: { type: "api_error", message: "the session family names one cse_-prefixed session id" } });
|
|
72332
|
+
return;
|
|
72333
|
+
}
|
|
72334
|
+
await serveSessionPath(sessions.get(id), tail, request7, response);
|
|
72335
|
+
}
|
|
72336
|
+
};
|
|
72337
|
+
const answerServerJson = (response, status, body) => {
|
|
72338
|
+
const text2 = JSON.stringify(body);
|
|
72339
|
+
response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(text2, "utf8")) });
|
|
72340
|
+
response.end(text2);
|
|
72341
|
+
};
|
|
72342
|
+
const local = {
|
|
72343
|
+
parsesHost: (host) => host === RC_SELF_HOST_OAUTH_HOST,
|
|
72344
|
+
serve: async (host, request7, response) => {
|
|
72345
|
+
const method = (request7.method ?? "").toUpperCase();
|
|
72346
|
+
const pathname = new URL(request7.url ?? "/", "http://127.0.0.1").pathname;
|
|
72347
|
+
if (host === RC_SELF_HOST_OAUTH_HOST) {
|
|
72348
|
+
if (method === "POST" && pathname === "/v1/oauth/token") {
|
|
72349
|
+
const body = parseJsonObject2(await readBody3(request7, CONTROL_BODY_CAP_BYTES));
|
|
72350
|
+
const record2 = deps.credentialRecord();
|
|
72351
|
+
if (record2 === void 0) {
|
|
72352
|
+
answerServerJson(response, HTTP_SERVICE_UNAVAILABLE, { error: "the front door's self-hosted Remote Control surface is on but no credential has been minted for it" });
|
|
72353
|
+
return true;
|
|
72354
|
+
}
|
|
72355
|
+
if (body?.grant_type !== void 0 && body.grant_type !== "refresh_token") {
|
|
72356
|
+
answerServerJson(response, HTTP_STATUS.badRequest, { error: "unsupported_grant_type" });
|
|
72357
|
+
return true;
|
|
72358
|
+
}
|
|
72359
|
+
answerServerJson(response, HTTP_STATUS.ok, { access_token: record2.accessToken, refresh_token: record2.refreshToken, expires_in: RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS, scope: RC_SELF_HOST_SCOPE_LIST.join(" ") });
|
|
72360
|
+
return true;
|
|
72361
|
+
}
|
|
72362
|
+
if (method === "GET" && pathname === "/v1/oauth/hello") {
|
|
72363
|
+
answerServerJson(response, HTTP_STATUS.ok, {});
|
|
72364
|
+
return true;
|
|
72365
|
+
}
|
|
72366
|
+
return false;
|
|
72367
|
+
}
|
|
72368
|
+
if (method === "POST" && pathname.startsWith("/api/eval/")) {
|
|
72369
|
+
await readBody3(request7, CONTROL_BODY_CAP_BYTES);
|
|
72370
|
+
answerServerJson(response, HTTP_STATUS.ok, { features: growthBookFeatures(), dateUpdated: Math.floor(deps.now() / MS_PER_SECOND6) });
|
|
72371
|
+
return true;
|
|
72372
|
+
}
|
|
72373
|
+
if (method === "GET" && pathname === "/api/oauth/profile") {
|
|
72374
|
+
const record2 = deps.credentialRecord();
|
|
72375
|
+
if (record2 === void 0) {
|
|
72376
|
+
answerServerJson(response, HTTP_SERVICE_UNAVAILABLE, { error: "the front door's self-hosted Remote Control surface is on but no credential has been minted for it" });
|
|
72377
|
+
return true;
|
|
72378
|
+
}
|
|
72379
|
+
answerServerJson(response, HTTP_STATUS.ok, {
|
|
72380
|
+
account: { uuid: record2.accountUuid, display_name: "agent-shim self-hosted", created_at: (/* @__PURE__ */ new Date(0)).toISOString() },
|
|
72381
|
+
organization: { uuid: record2.organizationUuid, organization_type: "claude_max" }
|
|
72382
|
+
});
|
|
72383
|
+
return true;
|
|
72384
|
+
}
|
|
72385
|
+
if (method === "GET" && pathname === "/api/claude_code/policy_limits") {
|
|
72386
|
+
answerServerJson(response, HTTP_STATUS.ok, {});
|
|
72387
|
+
return true;
|
|
72388
|
+
}
|
|
72389
|
+
if (method === "POST" && pathname === "/api/oauth/validate") {
|
|
72390
|
+
await readBody3(request7, CONTROL_BODY_CAP_BYTES);
|
|
72391
|
+
const record2 = deps.credentialRecord();
|
|
72392
|
+
if (record2 === void 0) {
|
|
72393
|
+
answerServerJson(response, HTTP_SERVICE_UNAVAILABLE, { error: "the front door's self-hosted Remote Control surface is on but no credential has been minted for it" });
|
|
72394
|
+
return true;
|
|
72395
|
+
}
|
|
72396
|
+
answerServerJson(response, HTTP_STATUS.ok, { scopes: [...RC_SELF_HOST_SCOPE_LIST], expiresAt: null, subscriptionType: "max", account_uuid: record2.accountUuid, organization_uuid: record2.organizationUuid });
|
|
72397
|
+
return true;
|
|
72398
|
+
}
|
|
72399
|
+
if (method === "POST" && (pathname === "/api/event_logging/v2/batch" || pathname === "/api/claude_code/metrics" || pathname === "/api/claude_cli_feedback")) {
|
|
72400
|
+
await readBody3(request7, CONTROL_BODY_CAP_BYTES);
|
|
72401
|
+
answerServerJson(response, HTTP_STATUS.ok, {});
|
|
72402
|
+
return true;
|
|
72403
|
+
}
|
|
72404
|
+
if (method === "GET" && pathname === "/api/hello") {
|
|
72405
|
+
answerServerJson(response, HTTP_STATUS.ok, {});
|
|
72406
|
+
return true;
|
|
72407
|
+
}
|
|
72408
|
+
return false;
|
|
72409
|
+
}
|
|
72410
|
+
};
|
|
72411
|
+
return {
|
|
72412
|
+
route,
|
|
72413
|
+
local,
|
|
72414
|
+
close: () => {
|
|
72415
|
+
clearInterval(timer);
|
|
72416
|
+
clearInterval(keepalive);
|
|
72417
|
+
for (const session of sessions.values()) {
|
|
72418
|
+
for (const sink of [...session.workerStreams, ...session.clientStreams]) {
|
|
72419
|
+
sink.retire();
|
|
72420
|
+
}
|
|
72421
|
+
}
|
|
72422
|
+
sessions.clear();
|
|
72423
|
+
}
|
|
72424
|
+
};
|
|
72425
|
+
}
|
|
72426
|
+
|
|
72427
|
+
// src/frontdoor/rcSelfHostMint.ts
|
|
72428
|
+
var import_node_path33 = __toESM(require("node:path"), 1);
|
|
72429
|
+
var CREDENTIALS_FILE = ".credentials.json";
|
|
72430
|
+
var CLAUDE_JSON2 = ".claude.json";
|
|
72431
|
+
var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
72432
|
+
var RC_SELF_HOST_RECORD_FILE = "credential.json";
|
|
72433
|
+
var SELF_HOST_EMAIL = "selfhost@agent-shim.invalid";
|
|
72434
|
+
var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
72435
|
+
function isRecord6(value2) {
|
|
72436
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
72437
|
+
}
|
|
72438
|
+
function readJsonObject(fs19, file2) {
|
|
72439
|
+
const raw = fs19.readFileUtf8(file2);
|
|
72440
|
+
if (raw === void 0) {
|
|
72441
|
+
return void 0;
|
|
72442
|
+
}
|
|
72443
|
+
let parsed;
|
|
72444
|
+
try {
|
|
72445
|
+
parsed = JSON.parse(raw);
|
|
72446
|
+
} catch {
|
|
72447
|
+
return void 0;
|
|
72448
|
+
}
|
|
72449
|
+
return isRecord6(parsed) ? parsed : void 0;
|
|
72450
|
+
}
|
|
72451
|
+
function readRcSelfHostRecord(fs19, frontdoorDir) {
|
|
72452
|
+
const parsed = readJsonObject(fs19, import_node_path33.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
72453
|
+
if (parsed === void 0) {
|
|
72454
|
+
return void 0;
|
|
72455
|
+
}
|
|
72456
|
+
const { accessToken, refreshToken, organizationUuid, accountUuid } = parsed;
|
|
72457
|
+
if (typeof accessToken !== "string" || accessToken === "" || typeof refreshToken !== "string" || refreshToken === "" || typeof organizationUuid !== "string" || organizationUuid === "" || typeof accountUuid !== "string" || accountUuid === "") {
|
|
72458
|
+
return void 0;
|
|
72459
|
+
}
|
|
72460
|
+
return { accessToken, refreshToken, organizationUuid, accountUuid };
|
|
72461
|
+
}
|
|
72462
|
+
function mintRcSelfHostCredential(deps) {
|
|
72463
|
+
if (!isIdentityName(deps.identity)) {
|
|
72464
|
+
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
72465
|
+
}
|
|
72466
|
+
const identityDir = import_node_path33.default.join(deps.identitiesDir, deps.identity);
|
|
72467
|
+
const credentialsFile = import_node_path33.default.join(identityDir, CREDENTIALS_FILE);
|
|
72468
|
+
const claudeJsonFile = import_node_path33.default.join(identityDir, CLAUDE_JSON2);
|
|
72469
|
+
const recordDir = import_node_path33.default.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
72470
|
+
const recordFile = import_node_path33.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
72471
|
+
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
72472
|
+
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
72473
|
+
const existingOauth = isRecord6(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
72474
|
+
const existingToken = typeof existingOauth?.accessToken === "string" && existingOauth.accessToken !== "" ? existingOauth.accessToken : void 0;
|
|
72475
|
+
const existingIsOwn = existingToken !== void 0 && previousRecord?.accessToken === existingToken;
|
|
72476
|
+
if (existingToken !== void 0 && !existingIsOwn && !deps.force) {
|
|
72477
|
+
throw new Error(
|
|
72478
|
+
`identity ${deps.identity} already holds an OAuth credential this door did not mint (a real claude.ai login): pass --force to replace it, or mint into an identity with no login. The self-hosted mode expects no Anthropic credential to be in play.`
|
|
72479
|
+
);
|
|
72480
|
+
}
|
|
72481
|
+
const accessToken = `sk-ant-oat${deps.randomToken()}`;
|
|
72482
|
+
const refreshToken = deps.randomToken();
|
|
72483
|
+
const organizationUuid = deps.newUuid();
|
|
72484
|
+
const accountUuid = deps.newUuid();
|
|
72485
|
+
const mintedAt = new Date(deps.now()).toISOString();
|
|
72486
|
+
deps.fs.mkdirPrivate(import_node_path33.default.dirname(credentialsFile));
|
|
72487
|
+
deps.fs.writeFilePrivate(credentialsFile, `${JSON.stringify({ ...existingCredentials, claudeAiOauth: { accessToken, refreshToken, expiresAt: null, scopes: [...RC_SELF_HOST_SCOPE_LIST], subscriptionType: SELF_HOST_SUBSCRIPTION_TYPE, rateLimitTier: null } }, null, 2)}
|
|
72488
|
+
`);
|
|
72489
|
+
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
72490
|
+
const existingBlock = (value2) => isRecord6(value2) ? value2 : {};
|
|
72491
|
+
deps.fs.writeFilePrivate(claudeJsonFile, `${JSON.stringify({
|
|
72492
|
+
...claudeJson,
|
|
72493
|
+
oauthAccount: {
|
|
72494
|
+
...existingBlock(claudeJson.oauthAccount),
|
|
72495
|
+
accountUuid,
|
|
72496
|
+
emailAddress: SELF_HOST_EMAIL,
|
|
72497
|
+
organizationUuid,
|
|
72498
|
+
organizationName: "agent-shim self-hosted",
|
|
72499
|
+
// The billing and creation fields exist so the CLI's "populate the account block if it is missing" step finds a complete block and skips its profile fetch; the door answers that fetch locally anyway, so these are the quiet path, not a load-bearing claim.
|
|
72500
|
+
billingType: "stripe_subscription",
|
|
72501
|
+
accountCreatedAt: mintedAt,
|
|
72502
|
+
subscriptionCreatedAt: mintedAt
|
|
72503
|
+
},
|
|
72504
|
+
cachedGrowthBookFeatures: {
|
|
72505
|
+
...existingBlock(claudeJson.cachedGrowthBookFeatures),
|
|
72506
|
+
tengu_ccr_bridge: true,
|
|
72507
|
+
tengu_bridge_repl_v2: true,
|
|
72508
|
+
tengu_bridge_repl_v2_cse_shim_enabled: true
|
|
72509
|
+
}
|
|
72510
|
+
}, null, 2)}
|
|
72511
|
+
`);
|
|
72512
|
+
deps.fs.mkdirPrivate(recordDir);
|
|
72513
|
+
deps.fs.writeFilePrivate(recordFile, `${JSON.stringify({ accessToken, refreshToken, organizationUuid, accountUuid }, null, 2)}
|
|
72514
|
+
`);
|
|
72515
|
+
return { identity: deps.identity, organizationUuid, credentialsFile, claudeJsonFile, recordFile, replaced: existingIsOwn };
|
|
72516
|
+
}
|
|
72517
|
+
|
|
72518
|
+
// src/frontdoor/rcStream.ts
|
|
72519
|
+
var RC_STREAM_EVENT_NAME2 = "client_event";
|
|
71797
72520
|
var SSE_BYTE_ORDER_MARK = 65279;
|
|
71798
72521
|
var RC_STREAM_BACKOFF_MS = 45e3;
|
|
71799
72522
|
var SUCCESS_STATUS_MAX_EXCLUSIVE3 = 300;
|
|
@@ -71854,7 +72577,7 @@ function createSseParser() {
|
|
|
71854
72577
|
}
|
|
71855
72578
|
};
|
|
71856
72579
|
}
|
|
71857
|
-
function
|
|
72580
|
+
function isRecord7(value2) {
|
|
71858
72581
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
71859
72582
|
}
|
|
71860
72583
|
function sequenceNumOf(value2) {
|
|
@@ -71867,7 +72590,7 @@ function sequenceNumOf(value2) {
|
|
|
71867
72590
|
return void 0;
|
|
71868
72591
|
}
|
|
71869
72592
|
function parseRcStreamEnvelope(parsed) {
|
|
71870
|
-
if (parsed.event !==
|
|
72593
|
+
if (parsed.event !== RC_STREAM_EVENT_NAME2) {
|
|
71871
72594
|
return void 0;
|
|
71872
72595
|
}
|
|
71873
72596
|
let data;
|
|
@@ -71876,7 +72599,7 @@ function parseRcStreamEnvelope(parsed) {
|
|
|
71876
72599
|
} catch {
|
|
71877
72600
|
return void 0;
|
|
71878
72601
|
}
|
|
71879
|
-
if (!
|
|
72602
|
+
if (!isRecord7(data)) {
|
|
71880
72603
|
return void 0;
|
|
71881
72604
|
}
|
|
71882
72605
|
const eventType = data.event_type;
|
|
@@ -72063,7 +72786,7 @@ var ProviderQuotaError = class extends Error {
|
|
|
72063
72786
|
this.name = "ProviderQuotaError";
|
|
72064
72787
|
}
|
|
72065
72788
|
};
|
|
72066
|
-
var
|
|
72789
|
+
var MS_PER_SECOND7 = 1e3;
|
|
72067
72790
|
var SECONDS_PER_HOUR = 3600;
|
|
72068
72791
|
var HOURS_PER_DAY3 = 24;
|
|
72069
72792
|
var DAYS_PER_MONTH = 30;
|
|
@@ -72075,8 +72798,8 @@ var ZAI_QUOTA_URL = `https://${ZAI_HOST}/api/monitor/usage/quota/limit`;
|
|
|
72075
72798
|
var ZAI_UNIT_HOURS = 3;
|
|
72076
72799
|
var ZAI_UNIT_MONTHS = 5;
|
|
72077
72800
|
var ZAI_UNIT_MS = /* @__PURE__ */ new Map([
|
|
72078
|
-
[ZAI_UNIT_HOURS, SECONDS_PER_HOUR *
|
|
72079
|
-
[ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY3 * SECONDS_PER_HOUR *
|
|
72801
|
+
[ZAI_UNIT_HOURS, SECONDS_PER_HOUR * MS_PER_SECOND7],
|
|
72802
|
+
[ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY3 * SECONDS_PER_HOUR * MS_PER_SECOND7]
|
|
72080
72803
|
]);
|
|
72081
72804
|
var ZAI_MEASURES = { TOKENS_LIMIT: "tokens", TIME_LIMIT: "tool-calls" };
|
|
72082
72805
|
var ZaiLimitSchema = external_exports.object({
|
|
@@ -72140,7 +72863,7 @@ var OPENROUTER_HOST = "openrouter.ai";
|
|
|
72140
72863
|
var OPENROUTER_KEY_URL = `https://${OPENROUTER_HOST}/api/v1/key`;
|
|
72141
72864
|
var OPENROUTER_CREDITS_URL = `https://${OPENROUTER_HOST}/api/v1/credits`;
|
|
72142
72865
|
var HTTP_FORBIDDEN = 403;
|
|
72143
|
-
var MS_PER_DAY2 = HOURS_PER_DAY3 * SECONDS_PER_HOUR *
|
|
72866
|
+
var MS_PER_DAY2 = HOURS_PER_DAY3 * SECONDS_PER_HOUR * MS_PER_SECOND7;
|
|
72144
72867
|
var OpenRouterKeySchema = external_exports.object({
|
|
72145
72868
|
data: external_exports.object({
|
|
72146
72869
|
limit: external_exports.number().nonnegative().nullable(),
|
|
@@ -72343,6 +73066,7 @@ function appendLog(paths, line) {
|
|
|
72343
73066
|
import_node_fs12.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
72344
73067
|
`);
|
|
72345
73068
|
}
|
|
73069
|
+
var MINTED_TOKEN_RANDOM_BYTES = 32;
|
|
72346
73070
|
function headroomSocketTarget(fsPort, trust, paths) {
|
|
72347
73071
|
const socketPath = readHeadroomState(fsPort, paths.headroomStateFile)?.socketPath;
|
|
72348
73072
|
return socketPath === void 0 ? void 0 : verifyHeadroomSocket(socketPath, trust);
|
|
@@ -72360,7 +73084,29 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
72360
73084
|
appendLog(paths, `frontdoor ${String(process.pid)}: ${line}`);
|
|
72361
73085
|
};
|
|
72362
73086
|
let directPort = 0;
|
|
73087
|
+
const rcSelfHost = rcSelfHostFromEnv(process.env);
|
|
72363
73088
|
const codexPorts = createCodexRoutePorts(log);
|
|
73089
|
+
let ca;
|
|
73090
|
+
const loadCa = () => {
|
|
73091
|
+
ca ??= ensureCa(realConnectCertStore(paths), () => generateCa(/* @__PURE__ */ new Date()));
|
|
73092
|
+
return ca;
|
|
73093
|
+
};
|
|
73094
|
+
let transparentPort;
|
|
73095
|
+
let selfHostDialTarget;
|
|
73096
|
+
const rcSelfHostDialTarget = () => {
|
|
73097
|
+
if (!rcSelfHost || transparentPort === void 0) {
|
|
73098
|
+
return void 0;
|
|
73099
|
+
}
|
|
73100
|
+
selfHostDialTarget ??= { host: "127.0.0.1", port: transparentPort, servername: CONNECT_INTERCEPT_HOST, ca: [loadCa().certPem] };
|
|
73101
|
+
return selfHostDialTarget;
|
|
73102
|
+
};
|
|
73103
|
+
const rcSelfHostSurface = rcSelfHost ? createRcSelfHostSurface({
|
|
73104
|
+
now: () => Date.now(),
|
|
73105
|
+
newUuid: import_node_crypto12.randomUUID,
|
|
73106
|
+
randomToken: () => (0, import_node_crypto12.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
73107
|
+
credentialRecord: () => readRcSelfHostRecord(realFarmFs, paths.frontdoorDir),
|
|
73108
|
+
log
|
|
73109
|
+
}) : void 0;
|
|
72364
73110
|
const rcTracker = createRcSessionTracker({ now: () => Date.now(), idleMs: RC_IDLE_EXPIRY_MS, credentialStore: createRcCredentialStore(realFarmFs, paths.frontdoorRcCredentialsDir) });
|
|
72365
73111
|
const rcFanout = createRcEventFanout();
|
|
72366
73112
|
const rcHub = createRcStreamHub({
|
|
@@ -72369,7 +73115,7 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
72369
73115
|
trackedSessions: () => rcTracker.list().map((session) => session.id),
|
|
72370
73116
|
fileStreamEvent: rcTracker.fileStreamEvent,
|
|
72371
73117
|
sequenceNumOf: rcTracker.sequenceNumOf,
|
|
72372
|
-
dial: realRcStreamDial(),
|
|
73118
|
+
dial: rcSelfHost ? lateRcStreamDial(rcSelfHostDialTarget) : realRcStreamDial(),
|
|
72373
73119
|
fanout: rcFanout,
|
|
72374
73120
|
newClientId: import_node_crypto12.randomUUID,
|
|
72375
73121
|
backoffMs: RC_STREAM_BACKOFF_MS,
|
|
@@ -72383,7 +73129,11 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
72383
73129
|
}
|
|
72384
73130
|
});
|
|
72385
73131
|
const rcControlToken = (0, import_node_crypto12.randomUUID)();
|
|
72386
|
-
const resolveRoute = rcObservingResolver(
|
|
73132
|
+
const resolveRoute = rcObservingResolver(
|
|
73133
|
+
createProviderRouteResolver({ fs: realFsPort, providersDir: paths.providersDir, codexPorts, directPort: () => directPort, ...rcSelfHostSurface === void 0 ? {} : { rcSelfHostRoute: rcSelfHostSurface.route } }),
|
|
73134
|
+
rcTracker,
|
|
73135
|
+
rcHub
|
|
73136
|
+
);
|
|
72387
73137
|
const isLiveToken = (token) => isLiveCapability(token, liveSessionTokens(realFarmFs, paths.frontdoorSessionsDir));
|
|
72388
73138
|
const usageStore = createUsageStore({
|
|
72389
73139
|
fs: realFarmFs,
|
|
@@ -72413,11 +73163,6 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
72413
73163
|
custody: createCredentialCustody(() => (0, import_node_crypto12.randomUUID)()),
|
|
72414
73164
|
log
|
|
72415
73165
|
});
|
|
72416
|
-
let ca;
|
|
72417
|
-
const loadCa = () => {
|
|
72418
|
-
ca ??= ensureCa(realConnectCertStore(paths), () => generateCa(/* @__PURE__ */ new Date()));
|
|
72419
|
-
return ca;
|
|
72420
|
-
};
|
|
72421
73166
|
const onListenerError = (name) => (error62) => {
|
|
72422
73167
|
appendLog(paths, `frontdoor ${String(process.pid)}: ${name} listener failed: ${error62.message}; exiting`);
|
|
72423
73168
|
process.exit(1);
|
|
@@ -72435,7 +73180,7 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
72435
73180
|
isRunning: realIsProcessRunning,
|
|
72436
73181
|
startProviderListener: async (preferredPort) => {
|
|
72437
73182
|
const authority = loadCa();
|
|
72438
|
-
const rcDial = realRcEventDial();
|
|
73183
|
+
const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
|
|
72439
73184
|
const rcInject = async (sessionId, text2) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto12.randomUUID }, sessionId, text2);
|
|
72440
73185
|
const rcAnswer = async (sessionId, requestId, decision) => await answerRcControlRequest({ credentialOf: rcTracker.credentialOf, pendingOf: (id) => rcTracker.pendingOf(id), completePending: rcTracker.completePending, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial }, sessionId, requestId, decision);
|
|
72441
73186
|
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto12.randomUUID };
|
|
@@ -72464,21 +73209,28 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
72464
73209
|
};
|
|
72465
73210
|
},
|
|
72466
73211
|
startConnectListener: async (preferredPort) => {
|
|
72467
|
-
const
|
|
72468
|
-
const transparentCapability =
|
|
73212
|
+
const wantedTransparentPort = process.env.AGENT_SHIM_TRANSPARENT_SURFACE === void 0 ? void 0 : Number(process.env.AGENT_SHIM_TRANSPARENT_SURFACE);
|
|
73213
|
+
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0, import_node_crypto12.randomUUID)();
|
|
72469
73214
|
if (transparentCapability !== void 0) {
|
|
72470
73215
|
writeFrontDoorSession(realFarmFs, paths.frontdoorSessionsDir, { pid: process.pid, startedAt: Date.now(), token: transparentCapability });
|
|
72471
73216
|
}
|
|
72472
73217
|
const leafFor = createLeafCache(loadCa(), () => /* @__PURE__ */ new Date());
|
|
72473
73218
|
const capture = captureFromEnv(process.env, paths.logsDir);
|
|
72474
73219
|
if (capture !== void 0) {
|
|
72475
|
-
log(`capture enabled, recording CONNECT targets and piped exchanges to ${
|
|
73220
|
+
log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path34.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
|
|
73221
|
+
}
|
|
73222
|
+
if (rcSelfHostSurface !== void 0) {
|
|
73223
|
+
log("self-hosted Remote Control surface on: the door serves the CCR session family itself, and its own client-half dials its own transparent surface");
|
|
73224
|
+
if (wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort)) {
|
|
73225
|
+
log("self-hosted Remote Control surface: AGENT_SHIM_TRANSPARENT_SURFACE is not set, so nothing redirects the CLI's Remote Control traffic to this door and the door's own client half has no surface to dial; set it to the interception port the mode is deployed with");
|
|
73226
|
+
}
|
|
72476
73227
|
}
|
|
72477
73228
|
const server = await startConnectServer(
|
|
72478
73229
|
{
|
|
72479
73230
|
interceptHosts: CONNECT_INTERCEPT_HOSTS,
|
|
72480
73231
|
tapHosts: CONNECT_TAP_HOSTS,
|
|
72481
73232
|
routedHost: CONNECT_INTERCEPT_HOST,
|
|
73233
|
+
...rcSelfHostSurface === void 0 ? {} : { localSurface: rcSelfHostSurface.local },
|
|
72482
73234
|
serveRouted: (request7, response) => {
|
|
72483
73235
|
const abort = new AbortController();
|
|
72484
73236
|
response.on("close", () => {
|
|
@@ -72501,14 +73253,21 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
72501
73253
|
leafFor,
|
|
72502
73254
|
upstreamFor: (host) => ({ host, port: HTTPS_PORT, tls: true }),
|
|
72503
73255
|
isLiveCapability: isLiveToken,
|
|
72504
|
-
...
|
|
73256
|
+
...wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? {} : { transparentPort: wantedTransparentPort, ...transparentCapability === void 0 ? {} : { transparentCapability } },
|
|
72505
73257
|
limits: CONNECT_LIMITS,
|
|
72506
73258
|
...capture === void 0 ? {} : { capture }
|
|
72507
73259
|
},
|
|
72508
73260
|
realConnectEffects(),
|
|
72509
73261
|
preferredPort
|
|
72510
73262
|
);
|
|
72511
|
-
|
|
73263
|
+
transparentPort = server.transparentPort;
|
|
73264
|
+
return {
|
|
73265
|
+
port: server.port,
|
|
73266
|
+
close: async () => {
|
|
73267
|
+
rcSelfHostSurface?.close();
|
|
73268
|
+
await server.close();
|
|
73269
|
+
}
|
|
73270
|
+
};
|
|
72512
73271
|
},
|
|
72513
73272
|
startDirectListener: async (preferredPort) => {
|
|
72514
73273
|
const server = createFrontDoorServer(async (request7) => {
|
|
@@ -72618,6 +73377,15 @@ function formatRcStreamEvent(event) {
|
|
|
72618
73377
|
const sketch = envelope.payload === void 0 ? "" : ` ${eventExcerpt(JSON.stringify(envelope.payload))}`;
|
|
72619
73378
|
return `${event.session} ${envelope.event_type} sequence_num ${String(envelope.sequence_num)} source ${envelope.source}${sketch}`;
|
|
72620
73379
|
}
|
|
73380
|
+
function formatRcSelfHostMint(result) {
|
|
73381
|
+
return [
|
|
73382
|
+
`identity: ${result.identity} (organisation ${result.organizationUuid})`,
|
|
73383
|
+
`credential: ${result.credentialsFile}${result.replaced ? " (replacing this door's previous mint)" : ""}`,
|
|
73384
|
+
`account block: ${result.claudeJsonFile} (oauthAccount and the feature-cache seed merged in)`,
|
|
73385
|
+
`door record: ${result.recordFile} (the copy the door's served surface authenticates against)`,
|
|
73386
|
+
"next: start the door with AGENT_SHIM_FRONTDOOR_RC_SELF_HOST=1 and its transparent surface pointed at the interception port, then launch this identity and switch Remote Control on; no claude.ai login is involved"
|
|
73387
|
+
];
|
|
73388
|
+
}
|
|
72621
73389
|
function frontDoorRcControlFromState(fsPort, paths) {
|
|
72622
73390
|
const state = readFrontDoorState(fsPort, paths.frontdoorStateFile);
|
|
72623
73391
|
if (state?.port === void 0) {
|
|
@@ -72820,6 +73588,32 @@ function registerFrontDoorCommand(program2, deps) {
|
|
|
72820
73588
|
}),
|
|
72821
73589
|
["agent-shim frontdoor rc watch", "agent-shim frontdoor rc watch cse_00000000-0000-4000-8000-000000000000 --json"]
|
|
72822
73590
|
);
|
|
73591
|
+
const selfhost = withExamples(
|
|
73592
|
+
rc.command("selfhost").description("Mint the local credential behind the door's self-hosted Remote Control surface: the opt-in mode (AGENT_SHIM_FRONTDOOR_RC_SELF_HOST=1 in the door's environment) where the door serves the CCR surface itself and a session activates Remote Control with no Anthropic credential anywhere."),
|
|
73593
|
+
["agent-shim frontdoor rc selfhost mint rig"]
|
|
73594
|
+
);
|
|
73595
|
+
withExamples(
|
|
73596
|
+
selfhost.command("mint").description("Mint the local OAuth credential, account block and feature-cache seed one identity needs to activate Remote Control against the door's own served surface, and record the door-side copy the surface authenticates against. Refuses to replace a real claude.ai login unless --force. Never prints a token.").argument("<identity>", "The identity to mint into, as `agent-shim identity list` names it.").option("--force", "Replace an existing OAuth credential this door did not mint.").option("--json", "Print the mint result as JSON.").action((identity, options) => {
|
|
73597
|
+
const result = mintRcSelfHostCredential({
|
|
73598
|
+
fs: realFarmFs,
|
|
73599
|
+
identitiesDir: paths.identitiesDir,
|
|
73600
|
+
frontdoorDir: paths.frontdoorDir,
|
|
73601
|
+
identity,
|
|
73602
|
+
newUuid: import_node_crypto12.randomUUID,
|
|
73603
|
+
randomToken: () => (0, import_node_crypto12.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
73604
|
+
force: options.force === true,
|
|
73605
|
+
now: () => Date.now()
|
|
73606
|
+
});
|
|
73607
|
+
if (options.json === true) {
|
|
73608
|
+
printJson(result);
|
|
73609
|
+
return;
|
|
73610
|
+
}
|
|
73611
|
+
for (const line of formatRcSelfHostMint(result)) {
|
|
73612
|
+
console.log(line);
|
|
73613
|
+
}
|
|
73614
|
+
}),
|
|
73615
|
+
["agent-shim frontdoor rc selfhost mint rig", "agent-shim frontdoor rc selfhost mint rig --force"]
|
|
73616
|
+
);
|
|
72823
73617
|
program2.command("__frontdoor-supervisor", { hidden: true }).description("Internal: serve the front-door routing listeners. Started by the launcher; never run by hand.").allowUnknownOption().action(async () => {
|
|
72824
73618
|
const idleShutdownMinutes = readGlobalConfig(paths)?.frontdoor?.idleShutdownMinutes ?? FRONTDOOR_DEFAULT_IDLE_SHUTDOWN_MINUTES;
|
|
72825
73619
|
process.on("SIGTERM", () => {
|
|
@@ -73124,15 +73918,15 @@ var import_node_child_process4 = require("node:child_process");
|
|
|
73124
73918
|
|
|
73125
73919
|
// src/identityToken.ts
|
|
73126
73920
|
var import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
73127
|
-
var
|
|
73921
|
+
var import_node_path35 = __toESM(require("node:path"), 1);
|
|
73128
73922
|
var TOKEN_FILE_MODE = 384;
|
|
73129
73923
|
var TOKEN_DIR_MODE = 448;
|
|
73130
73924
|
var OAUTH_TOKEN_RE = /^sk-ant-oat\d+-[A-Za-z0-9_-]+$/;
|
|
73131
73925
|
function identityTokenDir(paths) {
|
|
73132
|
-
return
|
|
73926
|
+
return import_node_path35.default.join(paths.root, "credentials");
|
|
73133
73927
|
}
|
|
73134
73928
|
function identityTokenPath(paths, identityName) {
|
|
73135
|
-
return
|
|
73929
|
+
return import_node_path35.default.join(identityTokenDir(paths), `${identityName}.token`);
|
|
73136
73930
|
}
|
|
73137
73931
|
function storeIdentityToken(paths, identityName, raw) {
|
|
73138
73932
|
const token = raw.trim();
|
|
@@ -73143,7 +73937,7 @@ function storeIdentityToken(paths, identityName, raw) {
|
|
|
73143
73937
|
import_node_fs13.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
|
|
73144
73938
|
import_node_fs13.default.chmodSync(dir, TOKEN_DIR_MODE);
|
|
73145
73939
|
const target = identityTokenPath(paths, identityName);
|
|
73146
|
-
const temp =
|
|
73940
|
+
const temp = import_node_path35.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
|
|
73147
73941
|
import_node_fs13.default.writeFileSync(temp, `${token}
|
|
73148
73942
|
`, { mode: TOKEN_FILE_MODE });
|
|
73149
73943
|
import_node_fs13.default.renameSync(temp, target);
|
|
@@ -73282,7 +74076,7 @@ function subjectName(positional, provider) {
|
|
|
73282
74076
|
|
|
73283
74077
|
// src/doctorReport.ts
|
|
73284
74078
|
var import_node_fs14 = __toESM(require("node:fs"), 1);
|
|
73285
|
-
var
|
|
74079
|
+
var import_node_path36 = __toESM(require("node:path"), 1);
|
|
73286
74080
|
function refinePathShadow(status, ownExecutablePath, realpath) {
|
|
73287
74081
|
if (status.status !== "shadowed") {
|
|
73288
74082
|
return status;
|
|
@@ -73306,7 +74100,7 @@ function validateJson(schema, input2) {
|
|
|
73306
74100
|
return { ok: true, data: result.data };
|
|
73307
74101
|
}
|
|
73308
74102
|
function pushPathResolution(push, resolution) {
|
|
73309
|
-
const ownDir =
|
|
74103
|
+
const ownDir = import_node_path36.default.dirname(resolution.ownExecutablePath);
|
|
73310
74104
|
switch (resolution.agentShim.status) {
|
|
73311
74105
|
case "ok":
|
|
73312
74106
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -73379,17 +74173,20 @@ function pushProvider(push, entry, cacheEnv) {
|
|
|
73379
74173
|
}
|
|
73380
74174
|
const cache = cacheClause(cacheEnv, `provider ${entry.name}`, validated2.data.credential);
|
|
73381
74175
|
push("provider", cache.unreadable ? "fail" : "pass", `${entry.name} is valid (${describeProviderEndpoint(validated2.data)}, credential ${describeCredential(validated2.data.credential)})${cache.text}.`, entry.name);
|
|
74176
|
+
if (validated2.data.env?.ENABLE_TOOL_SEARCH === void 0) {
|
|
74177
|
+
push("provider", "warn", `${entry.name} does not set ENABLE_TOOL_SEARCH: a session on this provider loads MCP tools upfront rather than deferring them, because its base URL is the front door, which Claude Code treats as a non-first-party host. Set ENABLE_TOOL_SEARCH in the provider's env block to restore deferred loading, when the upstream backend supports the tool_reference payloads it sends.`, entry.name);
|
|
74178
|
+
}
|
|
73382
74179
|
}
|
|
73383
74180
|
function pushLegacyName(push, params) {
|
|
73384
74181
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
73385
|
-
if (legacyVariables.length === 0 &&
|
|
74182
|
+
if (legacyVariables.length === 0 && import_node_path36.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
73386
74183
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
73387
74184
|
return;
|
|
73388
74185
|
}
|
|
73389
74186
|
for (const name of legacyVariables) {
|
|
73390
74187
|
push("legacy-name", "warn", `${name} is the former name of ${name.replace(LEGACY_ENV_PREFIX, ENV_PREFIX)}. Rename it; the old name still works but is only a fallback.`, name);
|
|
73391
74188
|
}
|
|
73392
|
-
if (
|
|
74189
|
+
if (import_node_path36.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
73393
74190
|
push(
|
|
73394
74191
|
"legacy-name",
|
|
73395
74192
|
"warn",
|
|
@@ -73708,18 +74505,18 @@ function collectDoctorReport(params) {
|
|
|
73708
74505
|
const { paths } = params;
|
|
73709
74506
|
const identityNames = import_node_fs14.default.existsSync(paths.identitiesDir) ? import_node_fs14.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
|
|
73710
74507
|
const identities = identityNames.map((name) => {
|
|
73711
|
-
const farmRoot =
|
|
73712
|
-
const identityPath =
|
|
74508
|
+
const farmRoot = import_node_path36.default.join(paths.identitiesDir, name);
|
|
74509
|
+
const identityPath = import_node_path36.default.join(farmRoot, "identity.json");
|
|
73713
74510
|
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
|
|
73714
74511
|
});
|
|
73715
74512
|
const profileNames = import_node_fs14.default.existsSync(paths.configProfilesDir) ? import_node_fs14.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
73716
74513
|
const configProfiles = profileNames.map((name) => {
|
|
73717
|
-
const profilePath =
|
|
74514
|
+
const profilePath = import_node_path36.default.join(paths.configProfilesDir, `${name}.json`);
|
|
73718
74515
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
73719
74516
|
});
|
|
73720
74517
|
const providerNames = import_node_fs14.default.existsSync(paths.providersDir) ? import_node_fs14.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
73721
74518
|
const providers = providerNames.map((name) => {
|
|
73722
|
-
const providerPath =
|
|
74519
|
+
const providerPath = import_node_path36.default.join(paths.providersDir, `${name}.json`);
|
|
73723
74520
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
73724
74521
|
});
|
|
73725
74522
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -73731,12 +74528,12 @@ function collectDoctorReport(params) {
|
|
|
73731
74528
|
binaryDiscovery = { ok: false, message: error62 instanceof Error ? error62.message : String(error62) };
|
|
73732
74529
|
}
|
|
73733
74530
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
73734
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
74531
|
+
const pathDirs = (params.env.PATH ?? "").split(import_node_path36.default.delimiter).filter((dir) => dir !== "");
|
|
73735
74532
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
73736
74533
|
findPathShadow({
|
|
73737
74534
|
pathDirs,
|
|
73738
|
-
targetDir:
|
|
73739
|
-
targetFilename:
|
|
74535
|
+
targetDir: import_node_path36.default.dirname(shimState.targetPath),
|
|
74536
|
+
targetFilename: import_node_path36.default.basename(shimState.targetPath),
|
|
73740
74537
|
findExecutableInDir
|
|
73741
74538
|
}),
|
|
73742
74539
|
shimState.targetPath,
|
|
@@ -73761,7 +74558,7 @@ function collectDoctorReport(params) {
|
|
|
73761
74558
|
agentShim: refinePathShadow(
|
|
73762
74559
|
findPathShadow({
|
|
73763
74560
|
pathDirs,
|
|
73764
|
-
targetDir:
|
|
74561
|
+
targetDir: import_node_path36.default.dirname(ownExecutablePath),
|
|
73765
74562
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
73766
74563
|
findExecutableInDir
|
|
73767
74564
|
}),
|
|
@@ -73804,7 +74601,7 @@ function registerDoctorCommand(program2, deps) {
|
|
|
73804
74601
|
// src/headroom/commands.ts
|
|
73805
74602
|
var import_node_fs16 = __toESM(require("node:fs"), 1);
|
|
73806
74603
|
var import_node_http2 = __toESM(require("node:http"), 1);
|
|
73807
|
-
var
|
|
74604
|
+
var import_node_path38 = __toESM(require("node:path"), 1);
|
|
73808
74605
|
var import_node_child_process5 = require("node:child_process");
|
|
73809
74606
|
|
|
73810
74607
|
// src/frontdoor/realFrontDoorPort.ts
|
|
@@ -73950,11 +74747,11 @@ function probeFrontDoorSync(port, caPem) {
|
|
|
73950
74747
|
|
|
73951
74748
|
// src/frontdoor/trust.ts
|
|
73952
74749
|
var import_node_crypto14 = require("node:crypto");
|
|
73953
|
-
var
|
|
74750
|
+
var import_node_path37 = __toESM(require("node:path"), 1);
|
|
73954
74751
|
var BUNDLE_NAME_HEX_DIGITS = 16;
|
|
73955
74752
|
function resolveTrustBundle(params) {
|
|
73956
74753
|
const { caCertFile, bundlesDir, variable, inherited, fs: fs19 } = params;
|
|
73957
|
-
if (inherited === void 0 || inherited === "" ||
|
|
74754
|
+
if (inherited === void 0 || inherited === "" || import_node_path37.default.resolve(inherited) === import_node_path37.default.resolve(caCertFile)) {
|
|
73958
74755
|
return { path: caCertFile };
|
|
73959
74756
|
}
|
|
73960
74757
|
const caPem = fs19.readFileUtf8(caCertFile);
|
|
@@ -73972,7 +74769,7 @@ function resolveTrustBundle(params) {
|
|
|
73972
74769
|
}
|
|
73973
74770
|
const combined = `${inheritedPem.trimEnd()}
|
|
73974
74771
|
${caPem}`;
|
|
73975
|
-
const bundle =
|
|
74772
|
+
const bundle = import_node_path37.default.join(bundlesDir, `${(0, import_node_crypto14.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
73976
74773
|
if (!fs19.exists(bundle)) {
|
|
73977
74774
|
fs19.mkdirp(bundlesDir);
|
|
73978
74775
|
fs19.writeFileAtomic(bundle, combined);
|
|
@@ -74130,12 +74927,12 @@ function readInstalledHeadroomCommit() {
|
|
|
74130
74927
|
if (toolDir.status !== 0) {
|
|
74131
74928
|
return void 0;
|
|
74132
74929
|
}
|
|
74133
|
-
const libDir =
|
|
74930
|
+
const libDir = import_node_path38.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
|
|
74134
74931
|
for (const python of realFarmFs.readdir(libDir)) {
|
|
74135
|
-
const sitePackages =
|
|
74932
|
+
const sitePackages = import_node_path38.default.join(libDir, python, "site-packages");
|
|
74136
74933
|
for (const entry of realFarmFs.readdir(sitePackages)) {
|
|
74137
74934
|
if (entry.startsWith("headroom_ai-") && entry.endsWith(".dist-info")) {
|
|
74138
|
-
const directUrl = realFarmFs.readFileUtf8(
|
|
74935
|
+
const directUrl = realFarmFs.readFileUtf8(import_node_path38.default.join(sitePackages, entry, "direct_url.json"));
|
|
74139
74936
|
return directUrl === void 0 ? void 0 : parseInstalledCommit(directUrl);
|
|
74140
74937
|
}
|
|
74141
74938
|
}
|
|
@@ -74942,7 +75739,7 @@ var import_node_crypto16 = require("node:crypto");
|
|
|
74942
75739
|
|
|
74943
75740
|
// src/launcher.ts
|
|
74944
75741
|
var import_node_crypto15 = require("node:crypto");
|
|
74945
|
-
var
|
|
75742
|
+
var import_node_path40 = __toESM(require("node:path"), 1);
|
|
74946
75743
|
|
|
74947
75744
|
// src/launcher/cliOverride.ts
|
|
74948
75745
|
var InvalidCliCategoryError = class extends CliError {
|
|
@@ -75026,7 +75823,7 @@ function buildCliOverride(params) {
|
|
|
75026
75823
|
}
|
|
75027
75824
|
|
|
75028
75825
|
// src/launcher/flags.ts
|
|
75029
|
-
var
|
|
75826
|
+
var import_node_path39 = __toESM(require("node:path"), 1);
|
|
75030
75827
|
|
|
75031
75828
|
// src/headroom/headers.ts
|
|
75032
75829
|
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
@@ -75096,7 +75893,7 @@ function buildEnv(params) {
|
|
|
75096
75893
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
75097
75894
|
let providerCustomHeaders;
|
|
75098
75895
|
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
75099
|
-
env.CLAUDE_CONFIG_DIR =
|
|
75896
|
+
env.CLAUDE_CONFIG_DIR = import_node_path39.default.join(params.identitiesDir, params.resolvedIdentityName);
|
|
75100
75897
|
}
|
|
75101
75898
|
if (params.provider !== void 0) {
|
|
75102
75899
|
const providerEnv = params.provider.definition.env ?? {};
|
|
@@ -75280,7 +76077,7 @@ function prepareLaunch(params) {
|
|
|
75280
76077
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
75281
76078
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
75282
76079
|
});
|
|
75283
|
-
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs19.readConfigFile(
|
|
76080
|
+
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs19.readConfigFile(import_node_path40.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
|
|
75284
76081
|
log.error(
|
|
75285
76082
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
75286
76083
|
);
|
|
@@ -75626,7 +76423,7 @@ async function runClaude(argvOverride) {
|
|
|
75626
76423
|
// src/cli.ts
|
|
75627
76424
|
async function main() {
|
|
75628
76425
|
aliasLegacyEnv(process.env);
|
|
75629
|
-
const invokedName =
|
|
76426
|
+
const invokedName = import_node_path41.default.basename(process.argv[1] ?? "agent-shim");
|
|
75630
76427
|
if (isInvokedAsClaude(invokedName)) {
|
|
75631
76428
|
await runClaude();
|
|
75632
76429
|
return;
|