agent-shim 14.20.1 → 14.22.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/dist/cli.cjs +166 -18
- package/dist/index.cjs +899 -862
- package/dist/index.mjs +877 -840
- package/dist/types/index.d.ts +139 -105
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -40507,6 +40507,13 @@ ${request7.rawHeaders.reduce((accumulated, value3, index) => index % 2 === 0 ? `
|
|
|
40507
40507
|
return;
|
|
40508
40508
|
}
|
|
40509
40509
|
if (host === config2.routedHost && servedByPipeline(request7.url)) {
|
|
40510
|
+
const lent = ownedBySurface(request7.socket) ? void 0 : await config2.rewriteForwardedAuthorization?.(host, request7, tunnelTokens.get(request7.socket));
|
|
40511
|
+
if (lent !== void 0) {
|
|
40512
|
+
request7.headers.authorization = lent.authorization;
|
|
40513
|
+
request7.url = lent.url;
|
|
40514
|
+
effects.forwardHttp(config2.upstreamFor(host), request7, response, config2.capture?.observePassthrough(request7));
|
|
40515
|
+
return;
|
|
40516
|
+
}
|
|
40510
40517
|
const tunnelToken = tunnelTokens.get(request7.socket);
|
|
40511
40518
|
if (tunnelToken !== void 0 && request7.headers[AUTH_HEADER] === void 0) {
|
|
40512
40519
|
request7.headers[AUTH_HEADER] = tunnelToken;
|
|
@@ -41071,6 +41078,46 @@ var init_connectorProxyAuth = __esm({
|
|
|
41071
41078
|
}
|
|
41072
41079
|
});
|
|
41073
41080
|
|
|
41081
|
+
// src/toolSurfaceAuth.ts
|
|
41082
|
+
function toolSurfaceOfPath(url2) {
|
|
41083
|
+
const path107 = url2?.split("?", 1)[0];
|
|
41084
|
+
if (path107 === void 0) {
|
|
41085
|
+
return void 0;
|
|
41086
|
+
}
|
|
41087
|
+
return SURFACE_PATHS.find(([, prefix]) => path107 === prefix || path107.startsWith(`${prefix}/`))?.[0];
|
|
41088
|
+
}
|
|
41089
|
+
function lendingBearer(deps, borrowerId, surface) {
|
|
41090
|
+
const identities = deps.identities();
|
|
41091
|
+
const lenderId = identities.find((identity) => identity.id === borrowerId)?.toolLogins?.[surface];
|
|
41092
|
+
const granted = lenderId !== void 0 && identities.find((identity) => identity.id === lenderId)?.grants?.some((grant) => grant.to === borrowerId && grant.features.includes("server-tools")) === true;
|
|
41093
|
+
const login = granted ? readLenderLogin(deps.loginPorts, deps.identitiesDir, lenderId) : void 0;
|
|
41094
|
+
return login !== void 0 && lenderLoginUsable(login, deps.now(), LENDER_LOGIN_GRACE_MS2) ? login.token : void 0;
|
|
41095
|
+
}
|
|
41096
|
+
function toolSurfaceAuthorizationRewriter(deps) {
|
|
41097
|
+
return (host, request7, tunnelToken) => {
|
|
41098
|
+
const surface = host === CONNECT_INTERCEPT_HOST && tunnelToken !== void 0 ? toolSurfaceOfPath(request7.url) : void 0;
|
|
41099
|
+
const borrowerId = surface === void 0 || tunnelToken === void 0 ? void 0 : deps.identityOfToken(tunnelToken);
|
|
41100
|
+
const token = surface === void 0 || borrowerId === void 0 || request7.url === void 0 ? void 0 : lendingBearer(deps, borrowerId, surface);
|
|
41101
|
+
return token === void 0 || request7.url === void 0 ? void 0 : { authorization: `Bearer ${token}`, url: request7.url };
|
|
41102
|
+
};
|
|
41103
|
+
}
|
|
41104
|
+
var LENDER_LOGIN_GRACE_MS2, SURFACE_PATHS;
|
|
41105
|
+
var init_toolSurfaceAuth = __esm({
|
|
41106
|
+
"src/toolSurfaceAuth.ts"() {
|
|
41107
|
+
"use strict";
|
|
41108
|
+
init_connect();
|
|
41109
|
+
init_lenderLogin();
|
|
41110
|
+
LENDER_LOGIN_GRACE_MS2 = 3e4;
|
|
41111
|
+
SURFACE_PATHS = [
|
|
41112
|
+
["design", "/v1/design"],
|
|
41113
|
+
["claude-test", "/v1/claude/test"],
|
|
41114
|
+
["pages", "/v1/pages"],
|
|
41115
|
+
["triggers", "/v1/code/triggers"],
|
|
41116
|
+
["triggers", "/v1/code/webhook-triggers"]
|
|
41117
|
+
];
|
|
41118
|
+
}
|
|
41119
|
+
});
|
|
41120
|
+
|
|
41074
41121
|
// src/codex/http.ts
|
|
41075
41122
|
var HTTP_STATUS;
|
|
41076
41123
|
var init_http = __esm({
|
|
@@ -41554,14 +41601,28 @@ function listIdentities(paths) {
|
|
|
41554
41601
|
}
|
|
41555
41602
|
return result.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
41556
41603
|
}
|
|
41557
|
-
function
|
|
41558
|
-
|
|
41604
|
+
function wiredAuthorizationRewriter(paths, identityOfToken, loginPorts) {
|
|
41605
|
+
const connector = connectorProxyAuthorizationRewriter({
|
|
41559
41606
|
identityOfToken,
|
|
41560
41607
|
identities: () => listIdentities(paths).flatMap((entry) => entry.problem === void 0 ? [{ id: entry.id, name: entry.name, grants: entry.identity.grants }] : []),
|
|
41561
41608
|
identitiesDir: paths.identitiesDir,
|
|
41562
41609
|
loginPorts,
|
|
41563
41610
|
now: Date.now
|
|
41564
41611
|
});
|
|
41612
|
+
const tools = toolSurfaceAuthorizationRewriter({ identityOfToken, ...toolSurfaceLendingDeps(paths, loginPorts) });
|
|
41613
|
+
return (host, request7, tunnelToken) => connector(host, request7, tunnelToken) ?? tools(host, request7, tunnelToken);
|
|
41614
|
+
}
|
|
41615
|
+
function toolSurfaceLendingDeps(paths, loginPorts) {
|
|
41616
|
+
return {
|
|
41617
|
+
identities: () => listIdentities(paths).flatMap((entry) => entry.problem === void 0 ? [{ id: entry.id, name: entry.name, grants: entry.identity.grants, toolLogins: entry.identity.toolLogins }] : []),
|
|
41618
|
+
identitiesDir: paths.identitiesDir,
|
|
41619
|
+
loginPorts,
|
|
41620
|
+
now: Date.now
|
|
41621
|
+
};
|
|
41622
|
+
}
|
|
41623
|
+
function wiredLendWebSearch(paths, loginPorts) {
|
|
41624
|
+
const deps = toolSurfaceLendingDeps(paths, loginPorts);
|
|
41625
|
+
return (identityId) => lendingBearer(deps, identityId, "web-search");
|
|
41565
41626
|
}
|
|
41566
41627
|
function wiredMergeConnectorList2(paths, apiBase, loginPorts) {
|
|
41567
41628
|
return wiredMergeConnectorList({
|
|
@@ -41778,6 +41839,7 @@ var init_identityStore = __esm({
|
|
|
41778
41839
|
init_launchRecords();
|
|
41779
41840
|
init_identityGrants();
|
|
41780
41841
|
init_connectorProxyAuth();
|
|
41842
|
+
init_toolSurfaceAuth();
|
|
41781
41843
|
init_connectorListMerge();
|
|
41782
41844
|
init_lenderLogin();
|
|
41783
41845
|
init_quotaHttp();
|
|
@@ -45429,14 +45491,20 @@ function rcEventWriteResultFromAnswer(answer) {
|
|
|
45429
45491
|
}
|
|
45430
45492
|
return { ok: true, sequenceNums };
|
|
45431
45493
|
}
|
|
45494
|
+
function noOAuthCredentialMessage(sessionId) {
|
|
45495
|
+
return `no claude.ai OAuth bearer has been observed for session ${sessionId}: only worker calls crossed this door, and the worker JWT they carry is answered 401 on the client half. Reconnect Remote Control through this door and the create's own bearer will be observed`;
|
|
45496
|
+
}
|
|
45432
45497
|
function noOAuthCredentialResult(sessionId) {
|
|
45433
|
-
return { ok: false, message:
|
|
45498
|
+
return { ok: false, message: noOAuthCredentialMessage(sessionId), refusal: "session-state" };
|
|
45434
45499
|
}
|
|
45435
45500
|
function rcSessionNotObservedMessage(sessionId) {
|
|
45436
45501
|
return `the front door has not observed Remote Control session ${sessionId}: it may never have passed through this door, or it ended or expired (an entry lives only a bounded idle period past its last observed traffic)`;
|
|
45437
45502
|
}
|
|
45438
45503
|
function rcWriteHeaders(credential) {
|
|
45439
|
-
|
|
45504
|
+
return { "content-type": "application/json", ...rcReadHeaders(credential) };
|
|
45505
|
+
}
|
|
45506
|
+
function rcReadHeaders(credential) {
|
|
45507
|
+
const headers = {};
|
|
45440
45508
|
if (credential.authorization !== void 0) {
|
|
45441
45509
|
headers.authorization = credential.authorization;
|
|
45442
45510
|
}
|
|
@@ -45695,10 +45763,40 @@ async function teleportRcSession(deps, sessionId, marker) {
|
|
|
45695
45763
|
function buildRcMarkReadBody(eventId) {
|
|
45696
45764
|
return eventId === void 0 ? {} : { event_id: eventId };
|
|
45697
45765
|
}
|
|
45698
|
-
|
|
45766
|
+
async function readRcServerState(deps, sessionId) {
|
|
45767
|
+
const credential = deps.credentialOf(sessionId);
|
|
45768
|
+
if (credential === void 0) {
|
|
45769
|
+
return { kind: "unknown", reason: rcSessionNotObservedMessage(sessionId) };
|
|
45770
|
+
}
|
|
45771
|
+
if (credential.authorization === void 0) {
|
|
45772
|
+
return { kind: "unknown", reason: noOAuthCredentialMessage(sessionId) };
|
|
45773
|
+
}
|
|
45774
|
+
let answer;
|
|
45775
|
+
try {
|
|
45776
|
+
answer = await deps.dial.readSession(sessionId, rcReadHeaders(credential));
|
|
45777
|
+
} catch (error63) {
|
|
45778
|
+
return { kind: "unknown", reason: `the door could not reach the API host to read the session: ${error63 instanceof Error ? error63.message : String(error63)}` };
|
|
45779
|
+
}
|
|
45780
|
+
if (!isSuccessful(answer.status)) {
|
|
45781
|
+
return { kind: "unknown", reason: `the API host answered ${String(answer.status)} to the session read` };
|
|
45782
|
+
}
|
|
45783
|
+
let parsed;
|
|
45784
|
+
try {
|
|
45785
|
+
parsed = JSON.parse(answer.body);
|
|
45786
|
+
} catch {
|
|
45787
|
+
return { kind: "unknown", reason: "the session read answered no status" };
|
|
45788
|
+
}
|
|
45789
|
+
const record3 = RcSessionAnswerSchema.safeParse(parsed);
|
|
45790
|
+
if (!record3.success) {
|
|
45791
|
+
return { kind: "unknown", reason: "the session read answered no status" };
|
|
45792
|
+
}
|
|
45793
|
+
return { kind: "read", status: record3.data.status, ...record3.data.worker_status === void 0 ? {} : { workerStatus: record3.data.worker_status }, ...record3.data.connection_status === void 0 ? {} : { connectionStatus: record3.data.connection_status } };
|
|
45794
|
+
}
|
|
45795
|
+
var RC_SEND_DELIVERY_NOTE, RC_PERMISSION_MODES, RC_CONTEXT_USAGE_DETAILS, RC_READ_FILE_ENCODINGS, RcSessionRecordSchema, RcSessionAnswerSchema;
|
|
45699
45796
|
var init_rcWrites = __esm({
|
|
45700
45797
|
"src/frontdoor/rcWrites.ts"() {
|
|
45701
45798
|
"use strict";
|
|
45799
|
+
init_zod();
|
|
45702
45800
|
init_http();
|
|
45703
45801
|
init_rcSessions();
|
|
45704
45802
|
init_rcQuestions();
|
|
@@ -45706,6 +45804,8 @@ var init_rcWrites = __esm({
|
|
|
45706
45804
|
RC_PERMISSION_MODES = ["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk", "auto"];
|
|
45707
45805
|
RC_CONTEXT_USAGE_DETAILS = ["summary", "full"];
|
|
45708
45806
|
RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
|
|
45807
|
+
RcSessionRecordSchema = external_exports.looseObject({ status: external_exports.string(), worker_status: external_exports.string().optional(), connection_status: external_exports.string().optional() });
|
|
45808
|
+
RcSessionAnswerSchema = external_exports.union([external_exports.looseObject({ response_shape: RcSessionRecordSchema }).transform((answer) => answer.response_shape), RcSessionRecordSchema]);
|
|
45709
45809
|
}
|
|
45710
45810
|
});
|
|
45711
45811
|
|
|
@@ -45730,7 +45830,7 @@ var init_machineLoad = __esm({
|
|
|
45730
45830
|
function workerFactSchema(value3) {
|
|
45731
45831
|
return external_exports.strictObject({ value: value3, observedAt: external_exports.number() });
|
|
45732
45832
|
}
|
|
45733
|
-
var RcPermissionModeSchema, RcSessionSummarySchema, RcQuestionOptionSchema, RcPendingQuestionSchema, RcPendingRequestSummarySchema, RcSessionStatusSchema, RcStreamEnvelopeSchema, RcStreamEventSchema, RcRateLimitWindowSchema, RcRateLimitInfoSchema, RcLiveRateLimitSchema, RcSessionQuerySchema, RcSendInputSchema, RcQuestionSelectionSchema, RcQuestionChoicesSchema, RcAnswerInputSchema, RcInterruptInputSchema, RcSetModelInputSchema, RcSetPermissionModeInputSchema, RcEndSessionInputSchema, RcGetUsageInputSchema, RcGetContextUsageInputSchema, RcReadFileInputSchema, RcFileSuggestionsInputSchema, RcKeepAliveInputSchema, RcMcpStatusInputSchema, RcMcpReconnectInputSchema, RcMcpAuthenticateInputSchema, RcMcpOAuthCallbackUrlInputSchema, RcTeleportInputSchema, RcListOutputSchema, RcSessionCommandRouteSchema, RcVersionGateWarningsSchema, RcSessionRouteSchema, RcStatusOutputSchema, RcPendingOutputSchema, RcWriteOutputSchema, RcControlWriteOutputSchema, RcAnswerOutputSchema;
|
|
45833
|
+
var RcPermissionModeSchema, RcSessionSummarySchema, RcQuestionOptionSchema, RcPendingQuestionSchema, RcPendingRequestSummarySchema, RcServerStateSchema, RcSessionStatusSchema, RcStreamEnvelopeSchema, RcStreamEventSchema, RcRateLimitWindowSchema, RcRateLimitInfoSchema, RcLiveRateLimitSchema, RcSessionQuerySchema, RcSendInputSchema, RcQuestionSelectionSchema, RcQuestionChoicesSchema, RcAnswerInputSchema, RcInterruptInputSchema, RcSetModelInputSchema, RcSetPermissionModeInputSchema, RcEndSessionInputSchema, RcGetUsageInputSchema, RcGetContextUsageInputSchema, RcReadFileInputSchema, RcFileSuggestionsInputSchema, RcKeepAliveInputSchema, RcMcpStatusInputSchema, RcMcpReconnectInputSchema, RcMcpAuthenticateInputSchema, RcMcpOAuthCallbackUrlInputSchema, RcTeleportInputSchema, RcListOutputSchema, RcSessionCommandRouteSchema, RcVersionGateWarningsSchema, RcSessionRouteSchema, RcStatusOutputSchema, RcPendingOutputSchema, RcWriteOutputSchema, RcControlWriteOutputSchema, RcAnswerOutputSchema;
|
|
45734
45834
|
var init_rcSchemas = __esm({
|
|
45735
45835
|
"src/frontdoor/rcSchemas.ts"() {
|
|
45736
45836
|
"use strict";
|
|
@@ -45762,6 +45862,10 @@ var init_rcSchemas = __esm({
|
|
|
45762
45862
|
unanswerable: external_exports.string().optional(),
|
|
45763
45863
|
observedAt: external_exports.number()
|
|
45764
45864
|
});
|
|
45865
|
+
RcServerStateSchema = external_exports.discriminatedUnion("kind", [
|
|
45866
|
+
external_exports.strictObject({ kind: external_exports.literal("read"), status: external_exports.string(), workerStatus: external_exports.string().optional(), connectionStatus: external_exports.string().optional() }),
|
|
45867
|
+
external_exports.strictObject({ kind: external_exports.literal("unknown"), reason: external_exports.string() })
|
|
45868
|
+
]);
|
|
45765
45869
|
RcSessionStatusSchema = external_exports.strictObject({
|
|
45766
45870
|
...RcSessionSummarySchema.shape,
|
|
45767
45871
|
workerState: workerFactSchema(external_exports.string()).optional(),
|
|
@@ -45903,7 +46007,7 @@ var init_rcSchemas = __esm({
|
|
|
45903
46007
|
RcSessionCommandRouteSchema = external_exports.enum(["supervised", "launched", "self-hosted"]);
|
|
45904
46008
|
RcVersionGateWarningsSchema = external_exports.readonly(external_exports.array(external_exports.string()).min(1)).optional();
|
|
45905
46009
|
RcSessionRouteSchema = external_exports.union([external_exports.strictObject({ route: RcSessionCommandRouteSchema, warnings: RcVersionGateWarningsSchema }), external_exports.strictObject({ route: external_exports.null(), refused: external_exports.string() })]);
|
|
45906
|
-
RcStatusOutputSchema = external_exports.strictObject({ statuses: external_exports.readonly(external_exports.array(external_exports.strictObject({ ...RcSessionStatusSchema.shape, route: RcSessionRouteSchema }))) });
|
|
46010
|
+
RcStatusOutputSchema = external_exports.strictObject({ statuses: external_exports.readonly(external_exports.array(external_exports.strictObject({ ...RcSessionStatusSchema.shape, route: RcSessionRouteSchema, serverState: RcServerStateSchema }))) });
|
|
45907
46011
|
RcPendingOutputSchema = external_exports.strictObject({
|
|
45908
46012
|
pending: external_exports.readonly(external_exports.array(RcPendingRequestSummarySchema)),
|
|
45909
46013
|
/** The sessions that had requests the door did not list (past the per-session cap, or with an id the protocol does not mint), each with how many: a question the caller expects may be among them. Absent when none did. */
|
|
@@ -46966,14 +47070,14 @@ function tlsFacts(options) {
|
|
|
46966
47070
|
}
|
|
46967
47071
|
function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
46968
47072
|
const agent = new ExemptTlsAgent();
|
|
46969
|
-
const
|
|
47073
|
+
const send = async (method, path107, headers, body) => await new Promise((resolve3, reject) => {
|
|
46970
47074
|
const options = {
|
|
46971
47075
|
host: target.host,
|
|
46972
47076
|
port: target.port,
|
|
46973
|
-
method
|
|
47077
|
+
method,
|
|
46974
47078
|
path: path107,
|
|
46975
47079
|
// 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.
|
|
46976
|
-
headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
|
|
47080
|
+
headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
|
|
46977
47081
|
agent
|
|
46978
47082
|
};
|
|
46979
47083
|
options.servername = target.servername ?? target.host;
|
|
@@ -46993,9 +47097,15 @@ function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PO
|
|
|
46993
47097
|
});
|
|
46994
47098
|
});
|
|
46995
47099
|
request7.once("error", reject);
|
|
46996
|
-
|
|
47100
|
+
if (body === void 0) {
|
|
47101
|
+
request7.end();
|
|
47102
|
+
} else {
|
|
47103
|
+
request7.end(body);
|
|
47104
|
+
}
|
|
46997
47105
|
});
|
|
47106
|
+
const post = async (path107, headers, body) => await send("POST", path107, headers, body);
|
|
46998
47107
|
return {
|
|
47108
|
+
readSession: async (sessionId, headers) => await send("GET", `/v1/code/sessions/${encodeURIComponent(sessionId)}`, headers, void 0),
|
|
46999
47109
|
writeEvents: async (sessionId, headers, body) => await post(`/v1/code/sessions/${encodeURIComponent(sessionId)}/events`, headers, body),
|
|
47000
47110
|
writeTeleportEvents: async (sessionId, headers, body) => await post(`/v1/code/sessions/${encodeURIComponent(sessionId)}/teleport-events`, headers, body)
|
|
47001
47111
|
};
|
|
@@ -47011,7 +47121,8 @@ function lateRcEventDial(resolve3) {
|
|
|
47011
47121
|
};
|
|
47012
47122
|
return {
|
|
47013
47123
|
writeEvents: async (sessionId, headers, body) => await dialFor().writeEvents(sessionId, headers, body),
|
|
47014
|
-
writeTeleportEvents: async (sessionId, headers, body) => await dialFor().writeTeleportEvents(sessionId, headers, body)
|
|
47124
|
+
writeTeleportEvents: async (sessionId, headers, body) => await dialFor().writeTeleportEvents(sessionId, headers, body),
|
|
47125
|
+
readSession: async (sessionId, headers) => await dialFor().readSession(sessionId, headers)
|
|
47015
47126
|
};
|
|
47016
47127
|
}
|
|
47017
47128
|
function lateRcStreamDial(resolve3) {
|
|
@@ -76848,7 +76959,7 @@ var init_package = __esm({
|
|
|
76848
76959
|
"package.json"() {
|
|
76849
76960
|
package_default = {
|
|
76850
76961
|
name: "agent-shim",
|
|
76851
|
-
version: "14.
|
|
76962
|
+
version: "14.22.0",
|
|
76852
76963
|
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.",
|
|
76853
76964
|
license: "MIT",
|
|
76854
76965
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -136723,7 +136834,8 @@ function createDoorPipelines(deps) {
|
|
|
136723
136834
|
canonicalProvider: deps.canonicalProvider,
|
|
136724
136835
|
now: deps.now,
|
|
136725
136836
|
log: deps.log,
|
|
136726
|
-
...deps.mergeConnectorList === void 0 ? {} : { mergeConnectorList: deps.mergeConnectorList }
|
|
136837
|
+
...deps.mergeConnectorList === void 0 ? {} : { mergeConnectorList: deps.mergeConnectorList },
|
|
136838
|
+
...deps.lendWebSearch === void 0 ? {} : { lendWebSearch: deps.lendWebSearch }
|
|
136727
136839
|
},
|
|
136728
136840
|
direct: {
|
|
136729
136841
|
resolveRoute: deps.resolveRoute,
|
|
@@ -148069,7 +148181,7 @@ function createRcApiRouter(deps) {
|
|
|
148069
148181
|
if (input2.session !== void 0 && !statuses.some((entry) => entry.id === input2.session)) {
|
|
148070
148182
|
throw new ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input2.session) });
|
|
148071
148183
|
}
|
|
148072
|
-
return { statuses: await Promise.all(statuses.map(async (status) => ({ ...status, route: await deps.routeOf(status.id) }))) };
|
|
148184
|
+
return { statuses: await Promise.all(statuses.map(async (status) => ({ ...status, route: await deps.routeOf(status.id), serverState: await deps.serverStateOf(status.id) }))) };
|
|
148073
148185
|
}),
|
|
148074
148186
|
pending: authed.meta(openapi({ method: "GET", path: "/rest/rc/pending", summary: "Read the control requests awaiting an answer", tags: [RC_API_TAG] })).input(RcSessionQuerySchema).output(RcPendingOutputSchema).handler(({ input: input2 }) => {
|
|
148075
148187
|
const pending = deps.pendingOf(input2.session);
|
|
@@ -151041,6 +151153,37 @@ function bufferingRoutedResponse(inner, transform2) {
|
|
|
151041
151153
|
};
|
|
151042
151154
|
}
|
|
151043
151155
|
|
|
151156
|
+
// src/webSearchRequest.ts
|
|
151157
|
+
var WEB_SEARCH_BODY_CAP_BYTES = 65536;
|
|
151158
|
+
var WEB_SEARCH_TOOL_PREFIX = "web_search_";
|
|
151159
|
+
function isWebSearchRequestBody(bodyText) {
|
|
151160
|
+
let parsed;
|
|
151161
|
+
try {
|
|
151162
|
+
parsed = JSON.parse(bodyText);
|
|
151163
|
+
} catch {
|
|
151164
|
+
return false;
|
|
151165
|
+
}
|
|
151166
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
151167
|
+
return false;
|
|
151168
|
+
}
|
|
151169
|
+
const tools = Reflect.get(parsed, "tools");
|
|
151170
|
+
return Array.isArray(tools) && tools.some((tool) => typeof tool === "object" && tool !== null && typeof Reflect.get(tool, "type") === "string" && String(Reflect.get(tool, "type")).startsWith(WEB_SEARCH_TOOL_PREFIX));
|
|
151171
|
+
}
|
|
151172
|
+
|
|
151173
|
+
// src/frontdoor/webSearchLending.ts
|
|
151174
|
+
var MESSAGES_PATH2 = "/v1/messages";
|
|
151175
|
+
async function withLentWebSearch(request7, identityId, lend) {
|
|
151176
|
+
if (lend === void 0 || identityId === void 0 || request7.method !== "POST" || request7.url.split("?", 1)[0] !== MESSAGES_PATH2 || request7.session.provider !== void 0 || !(declaredLength(request7.headers) <= WEB_SEARCH_BODY_CAP_BYTES)) {
|
|
151177
|
+
return request7;
|
|
151178
|
+
}
|
|
151179
|
+
const scanned = await scanRequestHead(request7, true, void 0, WEB_SEARCH_BODY_CAP_BYTES);
|
|
151180
|
+
if (scanned.tooLarge === true) {
|
|
151181
|
+
throw new Error("a request declared a body within the web-search read cap and then sent more");
|
|
151182
|
+
}
|
|
151183
|
+
const bearer = scanned.text !== void 0 && isWebSearchRequestBody(scanned.text) ? lend(identityId) : void 0;
|
|
151184
|
+
return bearer === void 0 ? scanned.replayed : { ...scanned.replayed, headers: { ...scanned.replayed.headers, authorization: `Bearer ${bearer}` } };
|
|
151185
|
+
}
|
|
151186
|
+
|
|
151044
151187
|
// src/frontdoor/pipeline.ts
|
|
151045
151188
|
var MCP_SERVERS_PATH2 = "/v1/mcp_servers";
|
|
151046
151189
|
function errorTypeFor(status) {
|
|
@@ -151194,7 +151337,7 @@ async function serveRouted(incoming, givenDeps) {
|
|
|
151194
151337
|
response2.end();
|
|
151195
151338
|
return;
|
|
151196
151339
|
}
|
|
151197
|
-
const
|
|
151340
|
+
const unlent = {
|
|
151198
151341
|
method: request7.method,
|
|
151199
151342
|
url: request7.url,
|
|
151200
151343
|
headers: admission.headers,
|
|
@@ -151206,6 +151349,7 @@ async function serveRouted(incoming, givenDeps) {
|
|
|
151206
151349
|
...admission.launch === void 0 ? {} : { launch: admission.launch }
|
|
151207
151350
|
}
|
|
151208
151351
|
};
|
|
151352
|
+
const routed = await withLentWebSearch(unlent, admission.identity, deps.lendWebSearch);
|
|
151209
151353
|
const resolution = await deps.resolveRoute(routed);
|
|
151210
151354
|
if (!resolution.ok) {
|
|
151211
151355
|
const response2 = createRoutedResponse(request7.response, { deps, session: identified.session, route: "(unrouted)", request: observed, servedPath: observed.path });
|
|
@@ -154675,6 +154819,7 @@ function formatRcSessionStatus(statuses) {
|
|
|
154675
154819
|
status.workerIdleSeconds === void 0 ? "idle unknown" : `idle ${String(status.workerIdleSeconds.value)} s as of ${new Date(status.workerIdleSeconds.observedAt).toISOString()}`
|
|
154676
154820
|
].join(", ");
|
|
154677
154821
|
lines.push(` worker: ${worker}`);
|
|
154822
|
+
lines.push(status.serverState.kind === "read" ? ` server: ${status.serverState.status}${[status.serverState.workerStatus === void 0 ? void 0 : `worker ${status.serverState.workerStatus}`, status.serverState.connectionStatus === void 0 ? void 0 : `connection ${status.serverState.connectionStatus}`].filter((part) => part !== void 0).map((part) => `, ${part}`).join("")}` : ` server: unknown (${status.serverState.reason})`);
|
|
154678
154823
|
lines.push(status.route.route === null ? ` goal, compaction and turn verbs: refused: ${status.route.refused}` : ` goal, compaction and turn verbs: ${status.route.route} route`);
|
|
154679
154824
|
if (status.route.route !== null) {
|
|
154680
154825
|
lines.push(...(status.route.warnings ?? []).map((warning) => ` warning: ${warning}`));
|
|
@@ -158644,7 +158789,8 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
158644
158789
|
headroomDecision,
|
|
158645
158790
|
custody: createCredentialCustody(() => (0, import_node_crypto35.randomUUID)()),
|
|
158646
158791
|
log,
|
|
158647
|
-
mergeConnectorList: wiredMergeConnectorList2(paths, `https://${CONNECT_INTERCEPT_HOST}`, { fs: realFarmFs, run: realRunPort, platform: process.platform })
|
|
158792
|
+
mergeConnectorList: wiredMergeConnectorList2(paths, `https://${CONNECT_INTERCEPT_HOST}`, { fs: realFarmFs, run: realRunPort, platform: process.platform }),
|
|
158793
|
+
lendWebSearch: wiredLendWebSearch(paths, { fs: realFarmFs, run: realRunPort, platform: process.platform })
|
|
158648
158794
|
});
|
|
158649
158795
|
const onListenerError = (name) => (error63) => {
|
|
158650
158796
|
appendDoorLog(paths, `frontdoor ${String(process.pid)}: ${name} listener failed: ${error63.message}; exiting`);
|
|
@@ -158686,6 +158832,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
158686
158832
|
const rcMcpReconnect = async (sessionId, serverName) => await reconnectRcSessionMcpServer(rcControlRequestDeps, sessionId, serverName);
|
|
158687
158833
|
const rcMcpAuthenticate = async (sessionId, serverName, redirectUri) => await authenticateRcSessionMcpServer(rcControlRequestDeps, sessionId, serverName, redirectUri);
|
|
158688
158834
|
const rcMcpOAuthCallbackUrl = async (sessionId, serverName, callbackUrl) => await submitRcSessionMcpOAuthCallbackUrl(rcControlRequestDeps, sessionId, serverName, callbackUrl);
|
|
158835
|
+
const rcServerStateOf = async (sessionId) => await readRcServerState(rcControlRequestDeps, sessionId);
|
|
158689
158836
|
const rcTeleport = async (sessionId, marker) => await teleportRcSession(rcControlRequestDeps, sessionId, marker);
|
|
158690
158837
|
const rcSessionCommands = createDoorRcSessionCommands({
|
|
158691
158838
|
paths,
|
|
@@ -158772,6 +158919,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
158772
158919
|
mcpAuthenticate: rcMcpAuthenticate,
|
|
158773
158920
|
mcpOAuthCallbackUrl: rcMcpOAuthCallbackUrl,
|
|
158774
158921
|
teleport: rcTeleport,
|
|
158922
|
+
serverStateOf: rcServerStateOf,
|
|
158775
158923
|
...rcSessionCommands,
|
|
158776
158924
|
fanout: rcFanout,
|
|
158777
158925
|
sessionEvents: rcSessionEvents,
|
|
@@ -158840,7 +158988,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
158840
158988
|
},
|
|
158841
158989
|
leafFor,
|
|
158842
158990
|
upstreamFor: (host) => ({ host, port: HTTPS_PORT, tls: true }),
|
|
158843
|
-
rewriteForwardedAuthorization:
|
|
158991
|
+
rewriteForwardedAuthorization: wiredAuthorizationRewriter(paths, sessionRegistry.identityOf, { fs: realFarmFs, run: realRunPort, platform: process.platform }),
|
|
158844
158992
|
isLiveCapability: isLiveToken,
|
|
158845
158993
|
...wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? {} : { transparentPort: wantedTransparentPort, ...transparentCapability === void 0 ? {} : { transparentCapability } },
|
|
158846
158994
|
limits: CONNECT_LIMITS,
|