@musdrop/ds-harness-remote 0.6.25 → 0.6.27
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/client.js +268 -183
- package/dist/index.js +871 -597
- package/dsh-plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -65042,7 +65042,10 @@ var workspaceGitTurnsResultSchema = external_exports.object({
|
|
|
65042
65042
|
}).strict();
|
|
65043
65043
|
|
|
65044
65044
|
// packages/protocol/dist/model-share.js
|
|
65045
|
+
var MODEL_SHARE_CHANNEL_MESSAGE_BYTES = 16 * 1024 * 1024;
|
|
65045
65046
|
var MODEL_SHARE_CAPABILITY = "model.share.v1";
|
|
65047
|
+
var MODEL_SHARE_ATTACH_MAX_BASE64 = Math.floor(MODEL_SHARE_CHANNEL_MESSAGE_BYTES * 0.75);
|
|
65048
|
+
var MODEL_SHARE_ATTACH_MAX_BYTES = Math.floor(MODEL_SHARE_ATTACH_MAX_BASE64 / 4) * 3;
|
|
65046
65049
|
var MODEL_SHARE_FAILURE_CODES = {
|
|
65047
65050
|
FAILED: "MODEL_SHARE_HOST_FAILED",
|
|
65048
65051
|
BUFFER_LIMIT: "MODEL_SHARE_BUFFER_LIMIT"
|
|
@@ -65051,8 +65054,27 @@ var MODEL_SHARE_METHODS = [
|
|
|
65051
65054
|
"model.share.list",
|
|
65052
65055
|
"model.share.open",
|
|
65053
65056
|
"model.share.chunk",
|
|
65054
|
-
"model.share.close"
|
|
65057
|
+
"model.share.close",
|
|
65058
|
+
"model.share.attach"
|
|
65055
65059
|
];
|
|
65060
|
+
var attachRequestSchema = external_exports.object({
|
|
65061
|
+
mediaType: external_exports.enum(["image/png", "image/jpeg", "image/webp", "image/gif"]),
|
|
65062
|
+
data: external_exports.string().min(1).max(MODEL_SHARE_ATTACH_MAX_BASE64)
|
|
65063
|
+
}).strict();
|
|
65064
|
+
var attachResponseSchema = external_exports.object({
|
|
65065
|
+
image: external_exports.object({
|
|
65066
|
+
attachmentId: external_exports.string().min(1).max(256),
|
|
65067
|
+
mediaType: external_exports.enum(["image/png", "image/jpeg", "image/webp", "image/gif"]),
|
|
65068
|
+
bytes: external_exports.number().int().positive(),
|
|
65069
|
+
width: external_exports.number().int().positive(),
|
|
65070
|
+
height: external_exports.number().int().positive(),
|
|
65071
|
+
name: external_exports.string().min(1).max(512).optional(),
|
|
65072
|
+
originalDimensions: external_exports.object({
|
|
65073
|
+
width: external_exports.number().int().positive(),
|
|
65074
|
+
height: external_exports.number().int().positive()
|
|
65075
|
+
}).strict().optional()
|
|
65076
|
+
}).strict()
|
|
65077
|
+
}).strict();
|
|
65056
65078
|
var sharedModelSchema = external_exports.object({
|
|
65057
65079
|
/** Stable route key: `${provider}::${model}`. Also the borrower-facing model id. */
|
|
65058
65080
|
id: external_exports.string().min(1).max(256),
|
|
@@ -66024,9 +66046,10 @@ function isSecureFragment(frame) {
|
|
|
66024
66046
|
function assertControlFrameSize(bytes, type, limits) {
|
|
66025
66047
|
const configured = type === "relay" ? limits.maxRelayFrameBytes : limits.maxControlFrameBytes;
|
|
66026
66048
|
const protocolMaximum = type === "relay" ? MAX_RELAY_FRAME_BYTES : MAX_CONTROL_FRAME_BYTES;
|
|
66027
|
-
|
|
66028
|
-
if (!Number.isSafeInteger(maximum) || maximum <= 0)
|
|
66049
|
+
if (configured !== void 0 && (!Number.isSafeInteger(configured) || configured <= 0)) {
|
|
66029
66050
|
throw new Error("Control frame limit is invalid.");
|
|
66051
|
+
}
|
|
66052
|
+
const maximum = configured === void 0 ? protocolMaximum : Math.min(protocolMaximum, configured);
|
|
66030
66053
|
if (bytes > maximum)
|
|
66031
66054
|
throw new Error(`${type === "relay" ? "Relay" : "Control"} frame exceeds its limit.`);
|
|
66032
66055
|
}
|
|
@@ -75569,7 +75592,7 @@ function parseIpv6(value) {
|
|
|
75569
75592
|
}
|
|
75570
75593
|
|
|
75571
75594
|
// packages/plugin/src/version.ts
|
|
75572
|
-
var PLUGIN_VERSION = "0.6.
|
|
75595
|
+
var PLUGIN_VERSION = "0.6.27";
|
|
75573
75596
|
|
|
75574
75597
|
// packages/plugin/src/server-api.ts
|
|
75575
75598
|
var TERMINAL_CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
@@ -80395,6 +80418,60 @@ function isRecord2(value) {
|
|
|
80395
80418
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80396
80419
|
}
|
|
80397
80420
|
|
|
80421
|
+
// packages/client-core/dist/codex-usage.js
|
|
80422
|
+
function isRecord3(value) {
|
|
80423
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80424
|
+
}
|
|
80425
|
+
function nonNegative(value) {
|
|
80426
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
80427
|
+
}
|
|
80428
|
+
function readBreakdown(value) {
|
|
80429
|
+
if (!isRecord3(value))
|
|
80430
|
+
return void 0;
|
|
80431
|
+
const input4 = nonNegative(value.inputTokens ?? value.input_tokens);
|
|
80432
|
+
const output2 = nonNegative(value.outputTokens ?? value.output_tokens);
|
|
80433
|
+
if (input4 === void 0 || output2 === void 0)
|
|
80434
|
+
return void 0;
|
|
80435
|
+
const cached2 = nonNegative(value.cachedInputTokens ?? value.cached_input_tokens) ?? 0;
|
|
80436
|
+
const cacheWrite = nonNegative(value.cacheWriteInputTokens ?? value.cache_write_input_tokens) ?? 0;
|
|
80437
|
+
const total = nonNegative(value.totalTokens ?? value.total_tokens);
|
|
80438
|
+
return {
|
|
80439
|
+
inputTokens: input4,
|
|
80440
|
+
cachedInputTokens: cached2,
|
|
80441
|
+
cacheWriteInputTokens: cacheWrite,
|
|
80442
|
+
outputTokens: output2,
|
|
80443
|
+
totalTokens: total
|
|
80444
|
+
};
|
|
80445
|
+
}
|
|
80446
|
+
function parseCodexTokenUsage(params) {
|
|
80447
|
+
if (!isRecord3(params))
|
|
80448
|
+
return void 0;
|
|
80449
|
+
const raw = isRecord3(params.tokenUsage) ? params.tokenUsage : isRecord3(params.token_usage) ? params.token_usage : void 0;
|
|
80450
|
+
if (raw === void 0)
|
|
80451
|
+
return void 0;
|
|
80452
|
+
const total = readBreakdown(raw.total ?? raw.total_token_usage);
|
|
80453
|
+
if (total === void 0)
|
|
80454
|
+
return void 0;
|
|
80455
|
+
const last = readBreakdown(raw.last ?? raw.last_token_usage);
|
|
80456
|
+
const contextWindow = nonNegative(raw.modelContextWindow ?? raw.model_context_window);
|
|
80457
|
+
const uncached = Math.max(0, total.inputTokens - total.cachedInputTokens - total.cacheWriteInputTokens);
|
|
80458
|
+
const tokenUsage = {
|
|
80459
|
+
uncachedInputTokens: uncached,
|
|
80460
|
+
outputTokens: total.outputTokens,
|
|
80461
|
+
cacheReadTokens: total.cachedInputTokens,
|
|
80462
|
+
cacheWriteTokens: total.cacheWriteInputTokens
|
|
80463
|
+
};
|
|
80464
|
+
if (last === void 0 || contextWindow === void 0)
|
|
80465
|
+
return { tokenUsage };
|
|
80466
|
+
const used = last.totalTokens ?? last.inputTokens + last.outputTokens;
|
|
80467
|
+
const contextPressure = {
|
|
80468
|
+
used,
|
|
80469
|
+
size: contextWindow,
|
|
80470
|
+
ratio: contextWindow > 0 ? Math.min(1, Math.max(0, used / contextWindow)) : 0
|
|
80471
|
+
};
|
|
80472
|
+
return { tokenUsage, contextPressure };
|
|
80473
|
+
}
|
|
80474
|
+
|
|
80398
80475
|
// packages/client-core/dist/acp-client.js
|
|
80399
80476
|
var REPLAYABLE_WORKSPACE_READS = /* @__PURE__ */ new Set([
|
|
80400
80477
|
"workspaceFiles/list",
|
|
@@ -80421,7 +80498,7 @@ var AgentAcpClient = class {
|
|
|
80421
80498
|
}
|
|
80422
80499
|
onSessionArchived(handler) {
|
|
80423
80500
|
return this.core.onEvent((event2) => {
|
|
80424
|
-
if (event2.event === "agent.acp.catalog.changed" &&
|
|
80501
|
+
if (event2.event === "agent.acp.catalog.changed" && isRecord4(event2.data) && event2.data.backend === "opencode" && event2.data.archived === true && typeof event2.data.sessionId === "string" && /^[A-Za-z0-9_-]{1,256}$/.test(event2.data.sessionId))
|
|
80425
80502
|
handler(event2.data);
|
|
80426
80503
|
});
|
|
80427
80504
|
}
|
|
@@ -80429,7 +80506,7 @@ var AgentAcpClient = class {
|
|
|
80429
80506
|
if (!this.supportsArchive(backend))
|
|
80430
80507
|
throw new RemoteGatewayError("OPENCODE_ARCHIVE_UNAVAILABLE", "Update the Host plugin to support OpenCode native archiving.");
|
|
80431
80508
|
const result = await this.call("dsh/sessionArchive", { sessionId, backend }, signal);
|
|
80432
|
-
if (!
|
|
80509
|
+
if (!isRecord4(result) || result.backend !== backend || result.sessionId !== sessionId || result.archived !== true)
|
|
80433
80510
|
throw new RemoteGatewayError("INVALID_RESPONSE", "OpenCode did not confirm the session archive state.");
|
|
80434
80511
|
return result;
|
|
80435
80512
|
}
|
|
@@ -80461,33 +80538,33 @@ var AgentAcpClient = class {
|
|
|
80461
80538
|
model: selection.model,
|
|
80462
80539
|
...selection.reasoningEffort === void 0 ? {} : { reasoningEffort: selection.reasoningEffort }
|
|
80463
80540
|
}, signal);
|
|
80464
|
-
if (!
|
|
80541
|
+
if (!isRecord4(result) || !isRecord4(result.selected) || result.selected.provider !== backend || typeof result.selected.model !== "string") {
|
|
80465
80542
|
throw new RemoteGatewayError("INVALID_RESPONSE", "ACP did not confirm the selected model.");
|
|
80466
80543
|
}
|
|
80467
80544
|
return result.selected;
|
|
80468
80545
|
}
|
|
80469
80546
|
async sessionModes(sessionId, backend, signal) {
|
|
80470
80547
|
const result = await this.call("dsh/sessionModes", { sessionId, backend }, signal);
|
|
80471
|
-
if (!
|
|
80548
|
+
if (!isRecord4(result) || !Array.isArray(result.availableModes)) {
|
|
80472
80549
|
return { availableModes: [] };
|
|
80473
80550
|
}
|
|
80474
80551
|
return {
|
|
80475
80552
|
...typeof result.currentModeId === "string" ? { currentModeId: result.currentModeId } : {},
|
|
80476
|
-
availableModes: result.availableModes.flatMap((item) =>
|
|
80553
|
+
availableModes: result.availableModes.flatMap((item) => isRecord4(item) && typeof item.id === "string" && typeof item.name === "string" ? [{ id: item.id, name: item.name, ...typeof item.description === "string" ? { description: item.description } : {} }] : [])
|
|
80477
80554
|
};
|
|
80478
80555
|
}
|
|
80479
80556
|
async setMode(sessionId, backend, modeId, signal) {
|
|
80480
80557
|
const result = await this.call("session/set_mode", { sessionId, backend, modeId }, signal);
|
|
80481
|
-
return
|
|
80558
|
+
return isRecord4(result) && typeof result.currentModeId === "string" ? { currentModeId: result.currentModeId } : { currentModeId: modeId };
|
|
80482
80559
|
}
|
|
80483
80560
|
async sessionCommands(sessionId, backend, signal) {
|
|
80484
80561
|
const result = await this.call("dsh/sessionCommands", { sessionId, backend }, signal);
|
|
80485
|
-
if (!
|
|
80562
|
+
if (!isRecord4(result) || !Array.isArray(result.commands))
|
|
80486
80563
|
return [];
|
|
80487
|
-
return result.commands.flatMap((item) =>
|
|
80564
|
+
return result.commands.flatMap((item) => isRecord4(item) && typeof item.name === "string" ? [{
|
|
80488
80565
|
name: item.name,
|
|
80489
80566
|
...typeof item.description === "string" ? { description: item.description } : {},
|
|
80490
|
-
...
|
|
80567
|
+
...isRecord4(item.input) && typeof item.input.hint === "string" ? { input: { hint: item.input.hint } } : {}
|
|
80491
80568
|
}] : []);
|
|
80492
80569
|
}
|
|
80493
80570
|
async forkSession(sessionId, backend, signal) {
|
|
@@ -80499,14 +80576,14 @@ var AgentAcpClient = class {
|
|
|
80499
80576
|
}
|
|
80500
80577
|
async createWorkspace(path, backend, title, signal) {
|
|
80501
80578
|
const result = await this.call("dsh/workspaceCreate", { backend, path, ...title ? { title } : {} }, signal);
|
|
80502
|
-
if (!
|
|
80579
|
+
if (!isRecord4(result) || typeof result.path !== "string") {
|
|
80503
80580
|
throw new RemoteGatewayError("INVALID_RESPONSE", "ACP workspace creation failed.");
|
|
80504
80581
|
}
|
|
80505
80582
|
return result;
|
|
80506
80583
|
}
|
|
80507
80584
|
async renameWorkspace(path, backend, title, signal) {
|
|
80508
80585
|
const result = await this.call("dsh/workspaceRename", { backend, path, title }, signal);
|
|
80509
|
-
if (!
|
|
80586
|
+
if (!isRecord4(result) || typeof result.path !== "string") {
|
|
80510
80587
|
throw new RemoteGatewayError("INVALID_RESPONSE", "ACP workspace rename failed.");
|
|
80511
80588
|
}
|
|
80512
80589
|
return result;
|
|
@@ -80516,15 +80593,15 @@ var AgentAcpClient = class {
|
|
|
80516
80593
|
}
|
|
80517
80594
|
async reorderWorkspaces(backend, paths, signal) {
|
|
80518
80595
|
const result = await this.call("dsh/workspaceReorder", { backend, paths }, signal);
|
|
80519
|
-
return
|
|
80596
|
+
return isRecord4(result) && Array.isArray(result.paths) ? result.paths.filter((item) => typeof item === "string") : paths;
|
|
80520
80597
|
}
|
|
80521
80598
|
async pinSession(sessionId, backend, signal) {
|
|
80522
80599
|
const result = await this.call("dsh/sessionPin", { backend, sessionId }, signal);
|
|
80523
|
-
return
|
|
80600
|
+
return isRecord4(result) && Array.isArray(result.pinnedSessionIds) ? result.pinnedSessionIds.filter((item) => typeof item === "string") : [];
|
|
80524
80601
|
}
|
|
80525
80602
|
async unpinSession(sessionId, backend, signal) {
|
|
80526
80603
|
const result = await this.call("dsh/sessionUnpin", { backend, sessionId }, signal);
|
|
80527
|
-
return
|
|
80604
|
+
return isRecord4(result) && Array.isArray(result.pinnedSessionIds) ? result.pinnedSessionIds.filter((item) => typeof item === "string") : [];
|
|
80528
80605
|
}
|
|
80529
80606
|
async selectPermission(sessionId, backend, preset, signal) {
|
|
80530
80607
|
return this.call("dsh/selectPermission", { sessionId, backend, preset }, signal);
|
|
@@ -80562,10 +80639,10 @@ var AgentAcpClient = class {
|
|
|
80562
80639
|
throw error62;
|
|
80563
80640
|
return { items: [] };
|
|
80564
80641
|
});
|
|
80565
|
-
if ((backend === "pi" || backend === "claude" || backend === "hermes" || backend === "kimi") && (!
|
|
80642
|
+
if ((backend === "pi" || backend === "claude" || backend === "hermes" || backend === "kimi") && (!isRecord4(result) || !Array.isArray(result.items))) {
|
|
80566
80643
|
throw new RemoteGatewayError("INVALID_RESPONSE", "ACP session catalog is invalid.");
|
|
80567
80644
|
}
|
|
80568
|
-
return
|
|
80645
|
+
return isRecord4(result) && Array.isArray(result.items) ? result.items : [];
|
|
80569
80646
|
}
|
|
80570
80647
|
async loadSessionHistory(sessionId, backend, signal) {
|
|
80571
80648
|
const details2 = await this.loadSessionDetails(sessionId, backend, signal);
|
|
@@ -80586,25 +80663,25 @@ var AgentAcpClient = class {
|
|
|
80586
80663
|
throw error62;
|
|
80587
80664
|
return { events: [] };
|
|
80588
80665
|
});
|
|
80589
|
-
if (strictHistoryBackend && (!
|
|
80666
|
+
if (strictHistoryBackend && (!isRecord4(result) || !Array.isArray(result.events))) {
|
|
80590
80667
|
throw new RemoteGatewayError("INVALID_RESPONSE", "ACP session history is invalid.");
|
|
80591
80668
|
}
|
|
80592
|
-
if (!
|
|
80669
|
+
if (!isRecord4(result))
|
|
80593
80670
|
return { events: [] };
|
|
80594
80671
|
const events = Array.isArray(result.events) ? result.events : [];
|
|
80595
80672
|
const permissionPreset2 = typeof result.permissionPreset === "string" ? result.permissionPreset : void 0;
|
|
80596
80673
|
const running = typeof result.running === "boolean" ? result.running : void 0;
|
|
80597
80674
|
const hasMore = typeof result.hasMore === "boolean" ? result.hasMore : void 0;
|
|
80598
80675
|
const oldestSeq = typeof result.oldestSeq === "number" && Number.isSafeInteger(result.oldestSeq) && result.oldestSeq >= 0 ? result.oldestSeq : void 0;
|
|
80599
|
-
const models =
|
|
80600
|
-
const modes =
|
|
80676
|
+
const models = isRecord4(result.models) && isRecord4(result.models.current) && typeof result.models.current.model === "string" && typeof result.models.current.provider === "string" && (backend === void 0 || result.models.current.provider === backend) && Array.isArray(result.models.groups) ? result.models : void 0;
|
|
80677
|
+
const modes = isRecord4(result.modes) && Array.isArray(result.modes.availableModes) ? {
|
|
80601
80678
|
...typeof result.modes.currentModeId === "string" ? { currentModeId: result.modes.currentModeId } : {},
|
|
80602
|
-
availableModes: result.modes.availableModes.flatMap((item) =>
|
|
80679
|
+
availableModes: result.modes.availableModes.flatMap((item) => isRecord4(item) && typeof item.id === "string" && typeof item.name === "string" ? [{ id: item.id, name: item.name, ...typeof item.description === "string" ? { description: item.description } : {} }] : [])
|
|
80603
80680
|
} : void 0;
|
|
80604
|
-
const commands = Array.isArray(result.commands) ? result.commands.flatMap((item) =>
|
|
80681
|
+
const commands = Array.isArray(result.commands) ? result.commands.flatMap((item) => isRecord4(item) && typeof item.name === "string" ? [{
|
|
80605
80682
|
name: item.name,
|
|
80606
80683
|
...typeof item.description === "string" ? { description: item.description } : {},
|
|
80607
|
-
...
|
|
80684
|
+
...isRecord4(item.input) && typeof item.input.hint === "string" ? { input: { hint: item.input.hint } } : {}
|
|
80608
80685
|
}] : []) : void 0;
|
|
80609
80686
|
return {
|
|
80610
80687
|
events,
|
|
@@ -80668,13 +80745,13 @@ var AgentAcpClient = class {
|
|
|
80668
80745
|
return true;
|
|
80669
80746
|
};
|
|
80670
80747
|
unsubscribe = this.core.onEvent((event2) => {
|
|
80671
|
-
if (event2.event === "agent.acp.frame" &&
|
|
80748
|
+
if (event2.event === "agent.acp.frame" && isRecord4(event2.data)) {
|
|
80672
80749
|
const data2 = event2.data;
|
|
80673
80750
|
if (tool ? data2.streamId !== streamId : !frameMatchesSubscription(data2, streamId, sessionId))
|
|
80674
80751
|
return;
|
|
80675
80752
|
onFrame(data2);
|
|
80676
80753
|
}
|
|
80677
|
-
if (event2.event === "agent.acp.stream.closed" &&
|
|
80754
|
+
if (event2.event === "agent.acp.stream.closed" && isRecord4(event2.data) && event2.data.streamId === streamId) {
|
|
80678
80755
|
if (!markClosed())
|
|
80679
80756
|
return;
|
|
80680
80757
|
const closedData = event2.data;
|
|
@@ -80803,9 +80880,9 @@ function rpcTimeoutForMethod(method) {
|
|
|
80803
80880
|
return void 0;
|
|
80804
80881
|
}
|
|
80805
80882
|
function readString(value, key) {
|
|
80806
|
-
return
|
|
80883
|
+
return isRecord4(value) && typeof value[key] === "string" ? value[key] : void 0;
|
|
80807
80884
|
}
|
|
80808
|
-
function
|
|
80885
|
+
function isRecord4(value) {
|
|
80809
80886
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80810
80887
|
}
|
|
80811
80888
|
function frameMatchesSubscription(data2, streamId, sessionId) {
|
|
@@ -80813,12 +80890,12 @@ function frameMatchesSubscription(data2, streamId, sessionId) {
|
|
|
80813
80890
|
return true;
|
|
80814
80891
|
if (data2.streamId === sessionScopedStreamId(sessionId))
|
|
80815
80892
|
return true;
|
|
80816
|
-
const params =
|
|
80893
|
+
const params = isRecord4(data2.frame.params) ? data2.frame.params : void 0;
|
|
80817
80894
|
if (params === void 0)
|
|
80818
80895
|
return false;
|
|
80819
80896
|
if (params.sessionId === sessionId)
|
|
80820
80897
|
return true;
|
|
80821
|
-
return
|
|
80898
|
+
return isRecord4(params.update) && params.update.sessionId === sessionId;
|
|
80822
80899
|
}
|
|
80823
80900
|
function sessionScopedStreamId(sessionId) {
|
|
80824
80901
|
return `session:${sessionId}`;
|
|
@@ -81057,7 +81134,7 @@ var MAX_CACHED_RECORDS_PER_SESSION = 200;
|
|
|
81057
81134
|
var MAX_ACP_CACHED_EVENTS_PER_SESSION = 1e4;
|
|
81058
81135
|
var MAX_UNARY_PAGES_PER_SESSION = 8;
|
|
81059
81136
|
var MAX_INVALIDATION_KEYS = 256;
|
|
81060
|
-
function
|
|
81137
|
+
function isRecord5(value) {
|
|
81061
81138
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
81062
81139
|
}
|
|
81063
81140
|
function cloneStructured(value) {
|
|
@@ -81111,12 +81188,12 @@ function attachSharedInFlight(entry, signal) {
|
|
|
81111
81188
|
});
|
|
81112
81189
|
}
|
|
81113
81190
|
function extractSessionIdFromGatewayPayload(payload) {
|
|
81114
|
-
if (!
|
|
81115
|
-
const args =
|
|
81116
|
-
const request2 =
|
|
81191
|
+
if (!isRecord5(payload)) return void 0;
|
|
81192
|
+
const args = isRecord5(payload.args) ? payload.args : payload;
|
|
81193
|
+
const request2 = isRecord5(args.request) ? args.request : isRecord5(args._request) ? args._request : args;
|
|
81117
81194
|
if (typeof request2.sessionId === "string" && request2.sessionId.length > 0) return request2.sessionId;
|
|
81118
81195
|
if (typeof request2.agentId === "string" && request2.agentId.length > 0) return request2.agentId;
|
|
81119
|
-
if (
|
|
81196
|
+
if (isRecord5(request2.address)) {
|
|
81120
81197
|
const address2 = request2.address;
|
|
81121
81198
|
if (typeof address2.sessionId === "string" && address2.sessionId.length > 0) return address2.sessionId;
|
|
81122
81199
|
if (typeof address2.childSessionId === "string" && address2.childSessionId.length > 0) return address2.childSessionId;
|
|
@@ -81127,9 +81204,9 @@ function isSessionMutationEndpoint(endpoint) {
|
|
|
81127
81204
|
return endpoint === "session/prompt" || endpoint === "session/cancel" || endpoint === "session/rename" || endpoint === "session/selectModel" || endpoint === "session/selectPermission" || endpoint === "session/fork" || endpoint === "agentPresets/select" || endpoint === "agentTeams/setEnabled" || endpoint === "commands/execute" || endpoint === "workspace/archiveSession";
|
|
81128
81205
|
}
|
|
81129
81206
|
function canonicalUnaryHistoryKey(endpoint, payload) {
|
|
81130
|
-
if (!
|
|
81131
|
-
const args =
|
|
81132
|
-
const request2 =
|
|
81207
|
+
if (!isRecord5(payload)) return endpoint;
|
|
81208
|
+
const args = isRecord5(payload.args) ? payload.args : payload;
|
|
81209
|
+
const request2 = isRecord5(args.request) ? args.request : isRecord5(args._request) ? args._request : args;
|
|
81133
81210
|
return JSON.stringify([
|
|
81134
81211
|
endpoint,
|
|
81135
81212
|
typeof request2.beforeSeq === "number" ? request2.beforeSeq : null,
|
|
@@ -81159,15 +81236,15 @@ var RemoteSessionHistoryCache = class {
|
|
|
81159
81236
|
return {
|
|
81160
81237
|
snapshot: {
|
|
81161
81238
|
...snapshot2,
|
|
81162
|
-
...
|
|
81239
|
+
...isRecord5(snapshot2.assistantStream) ? { assistantStream: { ...snapshot2.assistantStream, revision: 0 } } : {}
|
|
81163
81240
|
},
|
|
81164
81241
|
sameClient: entry.client === client,
|
|
81165
81242
|
cursor: cursor3
|
|
81166
81243
|
};
|
|
81167
81244
|
}
|
|
81168
81245
|
recordFollowSnapshot(client, sessionId, frame) {
|
|
81169
|
-
if (!
|
|
81170
|
-
const id7 = sessionId.length > 0 ? sessionId :
|
|
81246
|
+
if (!isRecord5(frame) || frame.type !== "snapshot") return;
|
|
81247
|
+
const id7 = sessionId.length > 0 ? sessionId : isRecord5(frame.header) && typeof frame.header.id === "string" ? frame.header.id : "";
|
|
81171
81248
|
if (id7.length === 0) return;
|
|
81172
81249
|
const existing = this.sessions.get(id7) ?? { unary: /* @__PURE__ */ new Map() };
|
|
81173
81250
|
const cloned = cloneStructured(frame);
|
|
@@ -81185,7 +81262,7 @@ var RemoteSessionHistoryCache = class {
|
|
|
81185
81262
|
if (entry === void 0 || entry.client !== client || entry.snapshot === void 0 || !Array.isArray(entry.snapshot.records)) return;
|
|
81186
81263
|
const bySeq = /* @__PURE__ */ new Map();
|
|
81187
81264
|
for (const item of [...backfilled, ...entry.snapshot.records]) {
|
|
81188
|
-
if (
|
|
81265
|
+
if (isRecord5(item) && isRecord5(item.event) && typeof item.event.seq === "number") {
|
|
81189
81266
|
bySeq.set(item.event.seq, cloneStructured(item));
|
|
81190
81267
|
}
|
|
81191
81268
|
}
|
|
@@ -81205,10 +81282,10 @@ var RemoteSessionHistoryCache = class {
|
|
|
81205
81282
|
this.invalidateUnary(sessionId, entry);
|
|
81206
81283
|
}
|
|
81207
81284
|
recordFollowFrame(client, sessionId, frame) {
|
|
81208
|
-
if (sessionId.length === 0 || !
|
|
81285
|
+
if (sessionId.length === 0 || !isRecord5(frame)) return;
|
|
81209
81286
|
const entry = this.sessions.get(sessionId);
|
|
81210
81287
|
if (entry === void 0 || entry.client !== client || entry.snapshot === void 0) return;
|
|
81211
|
-
if (frame.type === "event" &&
|
|
81288
|
+
if (frame.type === "event" && isRecord5(frame.event) && typeof frame.event.seq === "number") {
|
|
81212
81289
|
const seq = frame.event.seq;
|
|
81213
81290
|
const currentCursor = typeof entry.snapshot.cursor === "number" ? entry.snapshot.cursor : -1;
|
|
81214
81291
|
if (seq <= currentCursor) return;
|
|
@@ -81227,8 +81304,8 @@ var RemoteSessionHistoryCache = class {
|
|
|
81227
81304
|
return;
|
|
81228
81305
|
}
|
|
81229
81306
|
if (frame.type === "projection" && typeof frame.key === "string") {
|
|
81230
|
-
const projections =
|
|
81231
|
-
if (projections !== void 0 &&
|
|
81307
|
+
const projections = isRecord5(entry.snapshot.projections) ? entry.snapshot.projections : void 0;
|
|
81308
|
+
if (projections !== void 0 && isRecord5(projections.values)) {
|
|
81232
81309
|
projections.values[frame.key] = cloneStructured(frame.value);
|
|
81233
81310
|
if (typeof frame.seq === "number" && typeof projections.asOfSeq === "number" && frame.seq > projections.asOfSeq) {
|
|
81234
81311
|
projections.asOfSeq = frame.seq;
|
|
@@ -81307,18 +81384,18 @@ var RemoteSessionHistoryCache = class {
|
|
|
81307
81384
|
}
|
|
81308
81385
|
sliceSnapshotRecords(snapshot2, payload) {
|
|
81309
81386
|
if (!Array.isArray(snapshot2.records)) return void 0;
|
|
81310
|
-
const args =
|
|
81311
|
-
const request2 =
|
|
81387
|
+
const args = isRecord5(payload) && isRecord5(payload.args) ? payload.args : isRecord5(payload) ? payload : {};
|
|
81388
|
+
const request2 = isRecord5(args.request) ? args.request : isRecord5(args._request) ? args._request : args;
|
|
81312
81389
|
if (request2.turnWindow !== void 0) return void 0;
|
|
81313
81390
|
const snapshotCursor = typeof snapshot2.cursor === "number" ? snapshot2.cursor : -1;
|
|
81314
81391
|
const throughSeq = typeof request2.throughSeq === "number" ? request2.throughSeq : snapshotCursor;
|
|
81315
81392
|
if (throughSeq > snapshotCursor) return void 0;
|
|
81316
81393
|
const beforeSeq = typeof request2.beforeSeq === "number" ? request2.beforeSeq : void 0;
|
|
81317
81394
|
const endSeq = beforeSeq === void 0 ? throughSeq : Math.min(throughSeq, beforeSeq - 1);
|
|
81318
|
-
const window2 = endSeq < 0 ? [] : snapshot2.records.filter((item) =>
|
|
81395
|
+
const window2 = endSeq < 0 ? [] : snapshot2.records.filter((item) => isRecord5(item) && isRecord5(item.event) && typeof item.event.seq === "number" && item.event.seq <= endSeq);
|
|
81319
81396
|
if (throughSeq >= 0 && beforeSeq === void 0 && window2.length > 0) {
|
|
81320
81397
|
const tail = window2.at(-1);
|
|
81321
|
-
if (!
|
|
81398
|
+
if (!isRecord5(tail) || !isRecord5(tail.event) || tail.event.seq !== throughSeq) return void 0;
|
|
81322
81399
|
}
|
|
81323
81400
|
const maxMessages = typeof request2.maxMessages === "number" && request2.maxMessages > 0 ? request2.maxMessages : typeof request2.limit === "number" && request2.limit > 0 ? request2.limit : void 0;
|
|
81324
81401
|
const records = maxMessages === void 0 ? window2 : window2.slice(Math.max(0, window2.length - maxMessages));
|
|
@@ -82713,11 +82790,11 @@ function isPlainRecord2(value) {
|
|
|
82713
82790
|
}
|
|
82714
82791
|
|
|
82715
82792
|
// packages/plugin/src/virtual-harness-core.ts
|
|
82716
|
-
function
|
|
82793
|
+
function isRecord6(value) {
|
|
82717
82794
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
82718
82795
|
}
|
|
82719
82796
|
function record4(value) {
|
|
82720
|
-
return
|
|
82797
|
+
return isRecord6(value) ? value : {};
|
|
82721
82798
|
}
|
|
82722
82799
|
function array2(value) {
|
|
82723
82800
|
return Array.isArray(value) ? value : [];
|
|
@@ -82756,18 +82833,18 @@ function failure2(code, message, details2 = {}) {
|
|
|
82756
82833
|
return { ok: false, error: { code, message, details: details2 } };
|
|
82757
82834
|
}
|
|
82758
82835
|
function business(value, defaultErrorMessage = "The virtual Harness request failed.") {
|
|
82759
|
-
if (
|
|
82836
|
+
if (isRecord6(value) && value.ok === false) {
|
|
82760
82837
|
const err5 = record4(value.error);
|
|
82761
82838
|
return {
|
|
82762
82839
|
ok: false,
|
|
82763
82840
|
error: {
|
|
82764
82841
|
code: string4(err5.code) ?? "internal",
|
|
82765
82842
|
message: string4(err5.message) ?? defaultErrorMessage,
|
|
82766
|
-
details:
|
|
82843
|
+
details: isRecord6(err5.details) ? err5.details : {}
|
|
82767
82844
|
}
|
|
82768
82845
|
};
|
|
82769
82846
|
}
|
|
82770
|
-
if (
|
|
82847
|
+
if (isRecord6(value) && value.ok === true) {
|
|
82771
82848
|
return value.value === void 0 ? { ok: true } : { ok: true, value: value.value };
|
|
82772
82849
|
}
|
|
82773
82850
|
return value === void 0 ? { ok: true } : { ok: true, value };
|
|
@@ -82903,16 +82980,16 @@ function extractPromptText(content) {
|
|
|
82903
82980
|
function extractText(update) {
|
|
82904
82981
|
const content = update.content;
|
|
82905
82982
|
if (typeof content === "string") return content;
|
|
82906
|
-
if (
|
|
82983
|
+
if (isRecord6(content) && typeof content.text === "string") return content.text;
|
|
82907
82984
|
if (Array.isArray(content)) {
|
|
82908
|
-
const parts = content.map((part) =>
|
|
82985
|
+
const parts = content.map((part) => isRecord6(part) && typeof part.text === "string" ? part.text : void 0).filter((part) => part !== void 0);
|
|
82909
82986
|
return parts.length === 0 ? void 0 : parts.join("");
|
|
82910
82987
|
}
|
|
82911
82988
|
return typeof update.text === "string" ? update.text : void 0;
|
|
82912
82989
|
}
|
|
82913
82990
|
function summarizeQuestions(params) {
|
|
82914
82991
|
if (!Array.isArray(params.questions)) return void 0;
|
|
82915
|
-
const lines = params.questions.map((question) =>
|
|
82992
|
+
const lines = params.questions.map((question) => isRecord6(question) ? string4(question.prompt) : void 0).filter((line) => line !== void 0);
|
|
82916
82993
|
return lines.length === 0 ? void 0 : lines.join("\n");
|
|
82917
82994
|
}
|
|
82918
82995
|
function sessionIdFromAddress(address2) {
|
|
@@ -82925,7 +83002,7 @@ function sessionIdFromAddress(address2) {
|
|
|
82925
83002
|
}
|
|
82926
83003
|
function extractSessionId(request2) {
|
|
82927
83004
|
if (typeof request2.sessionId === "string" && request2.sessionId.length > 0) return request2.sessionId;
|
|
82928
|
-
if (
|
|
83005
|
+
if (isRecord6(request2.address)) return sessionIdFromAddress(request2.address);
|
|
82929
83006
|
throw new Error("The sessionId is required.");
|
|
82930
83007
|
}
|
|
82931
83008
|
function sessionPrefix(backend) {
|
|
@@ -83022,8 +83099,8 @@ var AcpEventCarrier = class {
|
|
|
83022
83099
|
const pending = this.context.pendingApprovals.get(eventId);
|
|
83023
83100
|
if (pending === void 0) return void 0;
|
|
83024
83101
|
this.context.pendingApprovals.delete(eventId);
|
|
83025
|
-
const decision = outcome.kind === "result" && (outcome.value === "allowed-once" || outcome.value === "answered" ||
|
|
83026
|
-
const result = outcome.kind === "result" &&
|
|
83102
|
+
const decision = outcome.kind === "result" && (outcome.value === "allowed-once" || outcome.value === "answered" || isRecord6(outcome.value)) ? "allow-once" : outcome.kind === "result" && outcome.value === "cancelled" ? "cancel" : "reject-once";
|
|
83103
|
+
const result = outcome.kind === "result" && isRecord6(outcome.value) ? { outcome: { outcome: "answered", ...outcome.value } } : void 0;
|
|
83027
83104
|
await this.context.client.respond(pending.requestHandle, decision, result, signal);
|
|
83028
83105
|
return void 0;
|
|
83029
83106
|
}
|
|
@@ -83203,7 +83280,7 @@ var AcpHistoryAccumulator = class {
|
|
|
83203
83280
|
if (input4 !== void 0 && input4 !== null) tool.input = input4;
|
|
83204
83281
|
const argumentsText = tool.input === void 0 ? tool.titleArguments : formatToolArguments(tool.input);
|
|
83205
83282
|
const callData = tool.callEvent?.event.data;
|
|
83206
|
-
if (
|
|
83283
|
+
if (isRecord7(callData) && callData.arguments !== argumentsText) {
|
|
83207
83284
|
const nextData = { ...callData, arguments: argumentsText };
|
|
83208
83285
|
const bucket = tool.callBucket;
|
|
83209
83286
|
if (bucket !== void 0) {
|
|
@@ -83367,7 +83444,7 @@ function formatToolArguments(input4) {
|
|
|
83367
83444
|
return "";
|
|
83368
83445
|
}
|
|
83369
83446
|
}
|
|
83370
|
-
function
|
|
83447
|
+
function isRecord7(value) {
|
|
83371
83448
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
83372
83449
|
}
|
|
83373
83450
|
|
|
@@ -83389,7 +83466,7 @@ var AcpLiveProjection = class {
|
|
|
83389
83466
|
queue,
|
|
83390
83467
|
hasConsumer,
|
|
83391
83468
|
nextSeq: session2.events.length === 0 ? 0 : Math.max(...session2.events.map((entry) => entry.event.seq)) + 1,
|
|
83392
|
-
turn: Math.max(0, ...session2.events.map((entry) =>
|
|
83469
|
+
turn: Math.max(0, ...session2.events.map((entry) => isRecord6(entry.event.data) && typeof entry.event.data.turn === "number" ? entry.event.data.turn : 0)),
|
|
83393
83470
|
stepOpen,
|
|
83394
83471
|
streamActive: false,
|
|
83395
83472
|
assistantStreamRevision: 0,
|
|
@@ -83580,7 +83657,7 @@ var AcpLiveProjection = class {
|
|
|
83580
83657
|
}
|
|
83581
83658
|
}
|
|
83582
83659
|
acceptSessionUpdate(follow, params) {
|
|
83583
|
-
const update =
|
|
83660
|
+
const update = isRecord6(params.update) ? params.update : params;
|
|
83584
83661
|
const kind = string4(update.sessionUpdate) ?? string4(update.type);
|
|
83585
83662
|
const session2 = this.context.sessions.get(follow.sessionId);
|
|
83586
83663
|
if (kind === "session_info_update") {
|
|
@@ -83643,7 +83720,7 @@ var AcpLiveProjection = class {
|
|
|
83643
83720
|
return;
|
|
83644
83721
|
}
|
|
83645
83722
|
if (follow.closed) return;
|
|
83646
|
-
if (kind === "model_selection" &&
|
|
83723
|
+
if (kind === "model_selection" && isRecord6(update.selected) && update.selected.provider === this.context.backend && typeof update.selected.model === "string") {
|
|
83647
83724
|
this.context.selectedModels.set(follow.sessionId, update.selected);
|
|
83648
83725
|
this.context.publishProjection(follow.sessionId, "modelSelection", this.context.modelSelectionProjection(follow.sessionId), this.context.nextProjectionSeq(follow.sessionId));
|
|
83649
83726
|
return;
|
|
@@ -83806,8 +83883,8 @@ var AcpLiveProjection = class {
|
|
|
83806
83883
|
const hasLiveContent = follow.stepOpen || follow.streamActive;
|
|
83807
83884
|
if (!hasLiveContent && Array.isArray(update.catchUp)) {
|
|
83808
83885
|
for (const item of update.catchUp) {
|
|
83809
|
-
if (!
|
|
83810
|
-
const catchUpParams =
|
|
83886
|
+
if (!isRecord6(item) || typeof item.method !== "string") continue;
|
|
83887
|
+
const catchUpParams = isRecord6(item.params) ? item.params : {};
|
|
83811
83888
|
if (item.method === "session/update") this.acceptSessionUpdate(follow, catchUpParams);
|
|
83812
83889
|
}
|
|
83813
83890
|
}
|
|
@@ -84058,11 +84135,11 @@ function nonNegativeNumber(value) {
|
|
|
84058
84135
|
}
|
|
84059
84136
|
function toolCallArguments(call, update) {
|
|
84060
84137
|
if (typeof call.input === "string") return call.input;
|
|
84061
|
-
if (
|
|
84138
|
+
if (isRecord6(call.input)) return JSON.stringify(call.input);
|
|
84062
84139
|
return call.titleArguments ?? commandTitleArguments(update);
|
|
84063
84140
|
}
|
|
84064
84141
|
function normalizeAcpUsage(value) {
|
|
84065
|
-
if (!
|
|
84142
|
+
if (!isRecord6(value)) return void 0;
|
|
84066
84143
|
const totalTokens = nonNegativeNumber(value.totalTokens);
|
|
84067
84144
|
const inputTokens = nonNegativeNumber(value.inputTokens);
|
|
84068
84145
|
const outputTokens = nonNegativeNumber(value.outputTokens);
|
|
@@ -84103,8 +84180,8 @@ function normalizeAvailableCommands(value) {
|
|
|
84103
84180
|
if (!Array.isArray(value)) return void 0;
|
|
84104
84181
|
const items = [];
|
|
84105
84182
|
for (const entry of value) {
|
|
84106
|
-
if (!
|
|
84107
|
-
const input4 =
|
|
84183
|
+
if (!isRecord6(entry) || typeof entry.name !== "string" || entry.name.trim().length === 0) continue;
|
|
84184
|
+
const input4 = isRecord6(entry.input) && typeof entry.input.hint === "string" ? { hint: entry.input.hint } : void 0;
|
|
84108
84185
|
items.push({
|
|
84109
84186
|
name: entry.name.trim(),
|
|
84110
84187
|
...typeof entry.description === "string" ? { description: entry.description } : {},
|
|
@@ -84117,7 +84194,7 @@ function normalizeAcpTodos(value) {
|
|
|
84117
84194
|
if (!Array.isArray(value)) return void 0;
|
|
84118
84195
|
const items = [];
|
|
84119
84196
|
for (const entry of value) {
|
|
84120
|
-
if (!
|
|
84197
|
+
if (!isRecord6(entry)) continue;
|
|
84121
84198
|
const content = string4(entry.content) ?? string4(entry.title) ?? string4(entry.label);
|
|
84122
84199
|
if (content === void 0 || content.trim().length === 0) continue;
|
|
84123
84200
|
const rawStatus = string4(entry.status);
|
|
@@ -85101,7 +85178,7 @@ var AcpVirtualHarness = class _AcpVirtualHarness {
|
|
|
85101
85178
|
const seenSeq = new Set(session2.events.map((entry) => entry.event.seq));
|
|
85102
85179
|
const prepended = [];
|
|
85103
85180
|
for (const entry of incoming) {
|
|
85104
|
-
if (!
|
|
85181
|
+
if (!isRecord6(entry) || !isRecord6(entry.event) || typeof entry.event.seq !== "number") continue;
|
|
85105
85182
|
if (seenSeq.has(entry.event.seq)) continue;
|
|
85106
85183
|
seenSeq.add(entry.event.seq);
|
|
85107
85184
|
prepended.push(entry);
|
|
@@ -85269,7 +85346,7 @@ var AcpVirtualHarness = class _AcpVirtualHarness {
|
|
|
85269
85346
|
const window2 = endSeq < 0 ? [] : session2.events.filter((entry) => entry.event.seq <= endSeq);
|
|
85270
85347
|
let maxTurn = 0;
|
|
85271
85348
|
for (const entry of session2.events) {
|
|
85272
|
-
if (
|
|
85349
|
+
if (isRecord6(entry.event.data) && typeof entry.event.data.turn === "number" && entry.event.data.turn > maxTurn) {
|
|
85273
85350
|
maxTurn = entry.event.data.turn;
|
|
85274
85351
|
}
|
|
85275
85352
|
}
|
|
@@ -88281,11 +88358,11 @@ var DATA_IMAGE_URL2 = /^data:(image\/(?:png|jpeg|webp|gif));base64,([A-Za-z0-9+/
|
|
|
88281
88358
|
function string5(value) {
|
|
88282
88359
|
return typeof value === "string" ? value : void 0;
|
|
88283
88360
|
}
|
|
88284
|
-
function
|
|
88361
|
+
function isRecord8(value) {
|
|
88285
88362
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
88286
88363
|
}
|
|
88287
88364
|
function record7(value) {
|
|
88288
|
-
return
|
|
88365
|
+
return isRecord8(value) ? value : {};
|
|
88289
88366
|
}
|
|
88290
88367
|
function toolOutputImageBlocks(item) {
|
|
88291
88368
|
const candidates = [
|
|
@@ -88375,7 +88452,7 @@ function collectImageBlocks(value, output2 = []) {
|
|
|
88375
88452
|
for (const item of value) collectImageBlocks(item, output2);
|
|
88376
88453
|
return output2;
|
|
88377
88454
|
}
|
|
88378
|
-
if (!
|
|
88455
|
+
if (!isRecord8(value)) return output2;
|
|
88379
88456
|
if (value.type === "image") output2.push(value);
|
|
88380
88457
|
for (const [key, child] of Object.entries(value)) {
|
|
88381
88458
|
if (key === "attachment") continue;
|
|
@@ -88537,7 +88614,7 @@ function codexPromptInput(content) {
|
|
|
88537
88614
|
if (content.length === 0 || content.length > MAX_CODEX_PROMPT_PARTS) return void 0;
|
|
88538
88615
|
const input4 = [];
|
|
88539
88616
|
for (const value of content) {
|
|
88540
|
-
if (!
|
|
88617
|
+
if (!isRecord6(value)) return void 0;
|
|
88541
88618
|
if (value.type === "text") {
|
|
88542
88619
|
if (typeof value.text !== "string" || value.text.length === 0 || value.text.length > MAX_CODEX_PROMPT_TEXT) return void 0;
|
|
88543
88620
|
input4.push({ type: "text", text: value.text });
|
|
@@ -88601,7 +88678,7 @@ function isLegacySessionHistoryUnsupported(error62) {
|
|
|
88601
88678
|
return errorCode(error62) === "METHOD_NOT_ALLOWED" || errorCode(error62) === "METHOD_NOT_FOUND" || error62.message.includes("The requested Codex method is not available over Remote.");
|
|
88602
88679
|
}
|
|
88603
88680
|
function errorDetails(error62) {
|
|
88604
|
-
return "details" in error62 &&
|
|
88681
|
+
return "details" in error62 && isRecord6(error62.details) ? error62.details : {};
|
|
88605
88682
|
}
|
|
88606
88683
|
function truncateCodePoints(value, maximum) {
|
|
88607
88684
|
return [...value].slice(0, maximum).join("");
|
|
@@ -89216,6 +89293,15 @@ function isCodexNativeHistoryPage(value, sessionId) {
|
|
|
89216
89293
|
return header.id === sessionId && integer2(page.cursor) !== void 0 && integer2(page.nextTurn) !== void 0 && Array.isArray(page.records) && typeof page.hasMore === "boolean" && (page.activeTurnId === void 0 || typeof page.activeTurnId === "string");
|
|
89217
89294
|
}
|
|
89218
89295
|
|
|
89296
|
+
// packages/plugin/src/codex/virtual-usage.ts
|
|
89297
|
+
function usageProjectionValues(state2) {
|
|
89298
|
+
if (state2 === void 0) return {};
|
|
89299
|
+
return {
|
|
89300
|
+
tokenUsage: state2.tokenUsage,
|
|
89301
|
+
contextPressure: state2.contextPressure ?? null
|
|
89302
|
+
};
|
|
89303
|
+
}
|
|
89304
|
+
|
|
89219
89305
|
// packages/plugin/src/codex/virtual-live.ts
|
|
89220
89306
|
var CodexLiveProjection = class {
|
|
89221
89307
|
constructor(context) {
|
|
@@ -89241,7 +89327,7 @@ var CodexLiveProjection = class {
|
|
|
89241
89327
|
isDSHRemoteError: true,
|
|
89242
89328
|
code: "response-too-large",
|
|
89243
89329
|
retryable: false,
|
|
89244
|
-
details: "details" in error62 &&
|
|
89330
|
+
details: "details" in error62 && isRecord6(error62.details) ? error62.details : {}
|
|
89245
89331
|
});
|
|
89246
89332
|
}
|
|
89247
89333
|
throw error62;
|
|
@@ -89284,7 +89370,8 @@ var CodexLiveProjection = class {
|
|
|
89284
89370
|
sessionListMetadata: { blank: history2.cursor < 0, lastPromptAt: null },
|
|
89285
89371
|
modelSelection: modelSelectionProjection(this.context.modelSelection(sessionId, directory)),
|
|
89286
89372
|
permissions: codexPermissionsProjection(this.context.permissionSelection(sessionId)),
|
|
89287
|
-
imageLimits: codexImageLimitsProjection()
|
|
89373
|
+
imageLimits: codexImageLimitsProjection(),
|
|
89374
|
+
...usageProjectionValues(this.context.usageState(sessionId))
|
|
89288
89375
|
}
|
|
89289
89376
|
},
|
|
89290
89377
|
...this.context.sessionGeneration === "v3" ? { assistantStream: { revision: 0 } } : {}
|
|
@@ -89335,6 +89422,20 @@ var CodexLiveProjection = class {
|
|
|
89335
89422
|
this.context.setPermissionSelection(follow.sessionId, preset);
|
|
89336
89423
|
return;
|
|
89337
89424
|
}
|
|
89425
|
+
if (frame.method === "thread/tokenUsage/updated") {
|
|
89426
|
+
const usage = parseCodexTokenUsage(params);
|
|
89427
|
+
if (usage !== void 0) {
|
|
89428
|
+
this.context.updateUsageState(follow.sessionId, usage);
|
|
89429
|
+
this.context.publishProjection(follow.sessionId, "tokenUsage", usage.tokenUsage, this.context.nextProjectionSeq());
|
|
89430
|
+
this.context.publishProjection(
|
|
89431
|
+
follow.sessionId,
|
|
89432
|
+
"contextPressure",
|
|
89433
|
+
usage.contextPressure ?? null,
|
|
89434
|
+
this.context.nextProjectionSeq()
|
|
89435
|
+
);
|
|
89436
|
+
}
|
|
89437
|
+
return;
|
|
89438
|
+
}
|
|
89338
89439
|
this.context.invalidateThreadHistory?.(follow.threadId);
|
|
89339
89440
|
if (frame.method === "dsh/goalStatus" && typeof params.goalActive === "boolean") {
|
|
89340
89441
|
follow.goalActive = params.goalActive;
|
|
@@ -89797,6 +89898,10 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
89797
89898
|
nextProjectionSeq: (...args) => owner.nextProjectionSeq(...args),
|
|
89798
89899
|
updateThreadName: (...args) => owner.updateThreadName(...args),
|
|
89799
89900
|
publishProjection: (...args) => owner.events.publishProjection(...args),
|
|
89901
|
+
usageState: (sessionId) => owner.usageStates.get(sessionId),
|
|
89902
|
+
updateUsageState: (sessionId, state2) => {
|
|
89903
|
+
owner.usageStates.set(sessionId, state2);
|
|
89904
|
+
},
|
|
89800
89905
|
setPermissionSelection: (...args) => owner.setPermissionSelection(...args),
|
|
89801
89906
|
emitRemoteEvent: (...args) => owner.events.emitRemoteEvent(...args),
|
|
89802
89907
|
get selectedModels() {
|
|
@@ -89851,6 +89956,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
89851
89956
|
blankThreads = /* @__PURE__ */ new Set();
|
|
89852
89957
|
selectedModels = /* @__PURE__ */ new Map();
|
|
89853
89958
|
selectedPermissions = /* @__PURE__ */ new Map();
|
|
89959
|
+
usageStates = /* @__PURE__ */ new Map();
|
|
89854
89960
|
imageAttachments = /* @__PURE__ */ new Map();
|
|
89855
89961
|
modelDirectory;
|
|
89856
89962
|
modelDirectoryPromise;
|
|
@@ -90253,7 +90359,8 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
90253
90359
|
sessionListMetadata: { blank: options.blank, lastPromptAt: options.lastPromptAt },
|
|
90254
90360
|
modelSelection: modelSelectionProjection(options.modelSelection),
|
|
90255
90361
|
permissions: codexPermissionsProjection(this.permissionSelection(session2.id)),
|
|
90256
|
-
imageLimits: codexImageLimitsProjection()
|
|
90362
|
+
imageLimits: codexImageLimitsProjection(),
|
|
90363
|
+
...usageProjectionValues(this.usageStates.get(session2.id))
|
|
90257
90364
|
}
|
|
90258
90365
|
}
|
|
90259
90366
|
};
|
|
@@ -90692,7 +90799,8 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
90692
90799
|
sessionListMetadata: { blank: history2.cursor < 0, lastPromptAt: null },
|
|
90693
90800
|
modelSelection: modelSelectionProjection(this.modelSelection(sessionId, directory)),
|
|
90694
90801
|
permissions: codexPermissionsProjection(this.permissionSelection(sessionId)),
|
|
90695
|
-
imageLimits: codexImageLimitsProjection()
|
|
90802
|
+
imageLimits: codexImageLimitsProjection(),
|
|
90803
|
+
...usageProjectionValues(this.usageStates.get(sessionId))
|
|
90696
90804
|
}
|
|
90697
90805
|
}
|
|
90698
90806
|
}
|
|
@@ -91078,15 +91186,15 @@ function normalizeLegacySessionGatewayValue(endpoint, value) {
|
|
|
91078
91186
|
return value;
|
|
91079
91187
|
}
|
|
91080
91188
|
function normalizeAssistantMessageStreamValue(endpoint, value) {
|
|
91081
|
-
if (endpoint === "session/page" &&
|
|
91082
|
-
if (endpoint === "session/follow" &&
|
|
91189
|
+
if (endpoint === "session/page" && isRecord9(value)) return { ...value, records: normalizeRecords(value.records) };
|
|
91190
|
+
if (endpoint === "session/follow" && isRecord9(value) && value.type === "snapshot") {
|
|
91083
91191
|
return { ...value, records: normalizeRecords(value.records) };
|
|
91084
91192
|
}
|
|
91085
91193
|
if (endpoint === "session/follow") return normalizeEntry(value);
|
|
91086
91194
|
return value;
|
|
91087
91195
|
}
|
|
91088
91196
|
function normalizeFollowFrame(value) {
|
|
91089
|
-
if (!
|
|
91197
|
+
if (!isRecord9(value)) return value;
|
|
91090
91198
|
if (value.type === "snapshot") {
|
|
91091
91199
|
return {
|
|
91092
91200
|
...value,
|
|
@@ -91098,7 +91206,7 @@ function normalizeFollowFrame(value) {
|
|
|
91098
91206
|
return normalizeEntry(value);
|
|
91099
91207
|
}
|
|
91100
91208
|
function normalizePage(value) {
|
|
91101
|
-
if (!
|
|
91209
|
+
if (!isRecord9(value)) return value;
|
|
91102
91210
|
return { ...value, records: normalizeRecords(value.records) };
|
|
91103
91211
|
}
|
|
91104
91212
|
function normalizeRecords(value) {
|
|
@@ -91143,10 +91251,10 @@ function eventTime(value) {
|
|
|
91143
91251
|
return typeof value.event.time === "number" && Number.isSafeInteger(value.event.time) ? value.event.time : 0;
|
|
91144
91252
|
}
|
|
91145
91253
|
function isEventEntry(value) {
|
|
91146
|
-
return
|
|
91254
|
+
return isRecord9(value) && value.type === "event" && isRecord9(value.event);
|
|
91147
91255
|
}
|
|
91148
91256
|
function normalizeHeader(value) {
|
|
91149
|
-
if (!
|
|
91257
|
+
if (!isRecord9(value)) return value;
|
|
91150
91258
|
const next = {
|
|
91151
91259
|
...value,
|
|
91152
91260
|
version: 3,
|
|
@@ -91155,7 +91263,7 @@ function normalizeHeader(value) {
|
|
|
91155
91263
|
return next.agentPreset === "code" ? { ...next, agentPreset: "ptc" } : next;
|
|
91156
91264
|
}
|
|
91157
91265
|
function normalizeEvent(value) {
|
|
91158
|
-
if (!
|
|
91266
|
+
if (!isRecord9(value)) return value;
|
|
91159
91267
|
let next = value;
|
|
91160
91268
|
const type = normalizeEventType(value.type);
|
|
91161
91269
|
if (type !== value.type) next = { ...next, type };
|
|
@@ -91175,7 +91283,7 @@ function normalizeEventType(value) {
|
|
|
91175
91283
|
return value;
|
|
91176
91284
|
}
|
|
91177
91285
|
function normalizeEventData(type, value) {
|
|
91178
|
-
if (!
|
|
91286
|
+
if (!isRecord9(value)) return value;
|
|
91179
91287
|
if (type === "assistant/message" && Object.hasOwn(value, "stream") && !Array.isArray(value.stream)) {
|
|
91180
91288
|
const { stream: _stream, ...rest } = value;
|
|
91181
91289
|
return rest;
|
|
@@ -91192,7 +91300,7 @@ function normalizeEventData(type, value) {
|
|
|
91192
91300
|
return value;
|
|
91193
91301
|
}
|
|
91194
91302
|
function normalizeRequestHeaderData(value) {
|
|
91195
|
-
if (!
|
|
91303
|
+
if (!isRecord9(value.header)) return value;
|
|
91196
91304
|
const header = normalizeRequestHeader(value.header);
|
|
91197
91305
|
return header === value.header ? value : { ...value, header };
|
|
91198
91306
|
}
|
|
@@ -91208,7 +91316,7 @@ function normalizeRequestHeader(value) {
|
|
|
91208
91316
|
changed = true;
|
|
91209
91317
|
continue;
|
|
91210
91318
|
}
|
|
91211
|
-
if (key === "adapterDefaults" &&
|
|
91319
|
+
if (key === "adapterDefaults" && isRecord9(field) && Object.keys(field).length === 0) {
|
|
91212
91320
|
changed = true;
|
|
91213
91321
|
continue;
|
|
91214
91322
|
}
|
|
@@ -91217,12 +91325,12 @@ function normalizeRequestHeader(value) {
|
|
|
91217
91325
|
return changed ? next : value;
|
|
91218
91326
|
}
|
|
91219
91327
|
function normalizeMessage(value) {
|
|
91220
|
-
if (!
|
|
91328
|
+
if (!isRecord9(value) || !isRecord9(value.source)) return value;
|
|
91221
91329
|
if (value.source.kind !== "plugin" || value.source.plugin !== "tools-code-mode") return value;
|
|
91222
91330
|
return { ...value, source: { ...value.source, plugin: "tools-ptc" } };
|
|
91223
91331
|
}
|
|
91224
91332
|
function normalizeSurfaceOp(value) {
|
|
91225
|
-
if (!
|
|
91333
|
+
if (!isRecord9(value) || value.op !== "replace") return value;
|
|
91226
91334
|
const { start, end, ...rest } = value;
|
|
91227
91335
|
if (start === void 0 && end === void 0) return value;
|
|
91228
91336
|
return {
|
|
@@ -91232,7 +91340,7 @@ function normalizeSurfaceOp(value) {
|
|
|
91232
91340
|
...end === void 0 ? {} : { endSeq: end }
|
|
91233
91341
|
};
|
|
91234
91342
|
}
|
|
91235
|
-
function
|
|
91343
|
+
function isRecord9(value) {
|
|
91236
91344
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
91237
91345
|
}
|
|
91238
91346
|
function isEventSeq(value) {
|
|
@@ -91297,7 +91405,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91297
91405
|
}
|
|
91298
91406
|
return result2;
|
|
91299
91407
|
} catch (error62) {
|
|
91300
|
-
if (!sharedSignal.aborted && !(
|
|
91408
|
+
if (!sharedSignal.aborted && !(isRecord10(error62) && error62.isDSHRemoteError === true)) {
|
|
91301
91409
|
const fallback = this.historyCache.getFallbackUnary(sessionId, endpoint, key, payload);
|
|
91302
91410
|
if (fallback !== void 0) return { ok: true, value: fallback };
|
|
91303
91411
|
}
|
|
@@ -91345,11 +91453,11 @@ var RemoteTypertGateway2 = class {
|
|
|
91345
91453
|
/** DSH <=0.1.6 cannot persist the 0.1.7 welcome acknowledgement remotely. */
|
|
91346
91454
|
normalizeLegacyWelcomeSettings(endpoint, payload, result) {
|
|
91347
91455
|
if (!isLegacyRemoteHost(this.harnessVersion)) return void 0;
|
|
91348
|
-
if (endpoint === "settings/describe" && result.ok &&
|
|
91456
|
+
if (endpoint === "settings/describe" && result.ok && isRecord10(result.value)) {
|
|
91349
91457
|
this.settingsDescribeValue = result.value;
|
|
91350
91458
|
return this.legacyWelcomeAcknowledged ? { ...result, value: patchWelcomeDescribe(result.value) } : void 0;
|
|
91351
91459
|
}
|
|
91352
|
-
if (endpoint !== "settings/mutate" || !
|
|
91460
|
+
if (endpoint !== "settings/mutate" || !isRecord10(payload) || !isRecord10(payload.args)) return void 0;
|
|
91353
91461
|
const args = payload.args;
|
|
91354
91462
|
if (args.ns !== WELCOME_NOTICE_NAMESPACE || !isWelcomeNoticeOperation(args.ops)) return void 0;
|
|
91355
91463
|
const value = patchWelcomeDescribe(this.settingsDescribeValue ?? { namespaces: [] });
|
|
@@ -91367,7 +91475,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91367
91475
|
try {
|
|
91368
91476
|
return await this.openRaw(endpoint, payload, signal, sessionId, cached2?.snapshot);
|
|
91369
91477
|
} catch (error62) {
|
|
91370
|
-
if (cached2 !== void 0 && !signal.aborted && !(
|
|
91478
|
+
if (cached2 !== void 0 && !signal.aborted && !(isRecord10(error62) && error62.isDSHRemoteError === true)) {
|
|
91371
91479
|
return this.iterateFallbackSnapshot(cached2.snapshot, signal);
|
|
91372
91480
|
}
|
|
91373
91481
|
throw error62;
|
|
@@ -91399,7 +91507,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91399
91507
|
try {
|
|
91400
91508
|
if (this.frameTransfers === void 0) {
|
|
91401
91509
|
const description = await this.client.rpc("harness.transport.describe", {}, signal);
|
|
91402
|
-
this.frameTransfers =
|
|
91510
|
+
this.frameTransfers = isRecord10(description) && Array.isArray(description.capabilities) && description.capabilities.includes("harness.remote.stream.transfer.v1");
|
|
91403
91511
|
}
|
|
91404
91512
|
signal.throwIfAborted();
|
|
91405
91513
|
await this.client.rpc("harness.remote.stream.open", {
|
|
@@ -91459,11 +91567,11 @@ var RemoteTypertGateway2 = class {
|
|
|
91459
91567
|
},
|
|
91460
91568
|
upstreamController.signal
|
|
91461
91569
|
).catch(() => void 0);
|
|
91462
|
-
if (!backfilled?.ok || !
|
|
91570
|
+
if (!backfilled?.ok || !isRecord10(backfilled.value) || !Array.isArray(backfilled.value.records)) {
|
|
91463
91571
|
return void 0;
|
|
91464
91572
|
}
|
|
91465
91573
|
const records = backfilled.value.records.filter(
|
|
91466
|
-
(record14) =>
|
|
91574
|
+
(record14) => isRecord10(record14) && isRecord10(record14.event) && typeof record14.event.seq === "number" && record14.event.seq > fromExclusive && record14.event.seq <= toInclusive
|
|
91467
91575
|
);
|
|
91468
91576
|
if (records.length !== missingCount) return void 0;
|
|
91469
91577
|
for (let index = 0; index < records.length; index += 1) {
|
|
@@ -91480,7 +91588,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91480
91588
|
const next = await upstreamIterator.next();
|
|
91481
91589
|
if (next.done) break;
|
|
91482
91590
|
const item = next.value;
|
|
91483
|
-
if (
|
|
91591
|
+
if (isRecord10(item) && item.type === "snapshot") {
|
|
91484
91592
|
const upstreamCursor = typeof item.cursor === "number" ? item.cursor : lastCursor;
|
|
91485
91593
|
if (upstreamCursor < lastCursor) {
|
|
91486
91594
|
this.historyCache.recordFollowSnapshot(this.client, sessionId, item);
|
|
@@ -91489,7 +91597,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91489
91597
|
}
|
|
91490
91598
|
if (Array.isArray(item.records)) {
|
|
91491
91599
|
const newerRecords = item.records.filter(
|
|
91492
|
-
(record14) =>
|
|
91600
|
+
(record14) => isRecord10(record14) && isRecord10(record14.event) && typeof record14.event.seq === "number" && record14.event.seq > lastCursor
|
|
91493
91601
|
);
|
|
91494
91602
|
for (const record14 of newerRecords) {
|
|
91495
91603
|
if (record14.event.seq <= lastCursor) continue;
|
|
@@ -91523,8 +91631,8 @@ var RemoteTypertGateway2 = class {
|
|
|
91523
91631
|
yield missing;
|
|
91524
91632
|
}
|
|
91525
91633
|
}
|
|
91526
|
-
if (
|
|
91527
|
-
const cachedProjections =
|
|
91634
|
+
if (isRecord10(item.projections) && isRecord10(item.projections.values)) {
|
|
91635
|
+
const cachedProjections = isRecord10(cachedSnapshot.projections) && isRecord10(cachedSnapshot.projections.values) ? cachedSnapshot.projections.values : void 0;
|
|
91528
91636
|
const asOfSeq = typeof item.projections.asOfSeq === "number" ? item.projections.asOfSeq : lastCursor;
|
|
91529
91637
|
for (const [key, value] of Object.entries(item.projections.values)) {
|
|
91530
91638
|
if (cachedProjections === void 0 || JSON.stringify(cachedProjections[key]) !== JSON.stringify(value)) {
|
|
@@ -91532,8 +91640,8 @@ var RemoteTypertGateway2 = class {
|
|
|
91532
91640
|
}
|
|
91533
91641
|
}
|
|
91534
91642
|
}
|
|
91535
|
-
if (
|
|
91536
|
-
const cachedAssistant =
|
|
91643
|
+
if (isRecord10(item.assistantStream)) {
|
|
91644
|
+
const cachedAssistant = isRecord10(cachedSnapshot.assistantStream) ? cachedSnapshot.assistantStream : void 0;
|
|
91537
91645
|
const hasActiveStream = item.assistantStream.active === true || item.assistantStream.message != null || Array.isArray(item.assistantStream.entries) && item.assistantStream.entries.length > 0;
|
|
91538
91646
|
const cachedHadActiveStream = cachedAssistant !== void 0 && (cachedAssistant.active === true || cachedAssistant.message != null || Array.isArray(cachedAssistant.entries) && cachedAssistant.entries.length > 0);
|
|
91539
91647
|
if (hasActiveStream || cachedHadActiveStream) {
|
|
@@ -91548,7 +91656,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91548
91656
|
}
|
|
91549
91657
|
continue;
|
|
91550
91658
|
}
|
|
91551
|
-
if (
|
|
91659
|
+
if (isRecord10(item) && item.type === "event" && isRecord10(item.event) && typeof item.event.seq === "number") {
|
|
91552
91660
|
if (item.event.seq <= lastCursor) continue;
|
|
91553
91661
|
if (item.event.seq > lastCursor + 1) {
|
|
91554
91662
|
const recovered = await backfillRange(lastCursor, item.event.seq - 1);
|
|
@@ -91567,7 +91675,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91567
91675
|
yield item;
|
|
91568
91676
|
continue;
|
|
91569
91677
|
}
|
|
91570
|
-
if (
|
|
91678
|
+
if (isRecord10(item) && item.type === "assistant-stream" && isRecord10(item.frame)) {
|
|
91571
91679
|
yield {
|
|
91572
91680
|
...item,
|
|
91573
91681
|
frame: {
|
|
@@ -91581,7 +91689,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91581
91689
|
}
|
|
91582
91690
|
} catch (error62) {
|
|
91583
91691
|
if (signal.aborted) return;
|
|
91584
|
-
if (resyncRequired ||
|
|
91692
|
+
if (resyncRequired || isRecord10(error62) && error62.isDSHRemoteError === true) throw error62;
|
|
91585
91693
|
if (this.deferStreamDisconnect) {
|
|
91586
91694
|
await new Promise((resolve12) => signal.addEventListener("abort", () => resolve12(), { once: true }));
|
|
91587
91695
|
return;
|
|
@@ -91610,7 +91718,7 @@ var RemoteTypertGateway2 = class {
|
|
|
91610
91718
|
const descriptor2 = frame.transfer;
|
|
91611
91719
|
try {
|
|
91612
91720
|
const decoded = await this.readTransferred(descriptor2, transferSignal);
|
|
91613
|
-
if (!
|
|
91721
|
+
if (!isRecord10(decoded) || decoded.streamId !== streamId || decoded.hasValue !== true || Object.hasOwn(decoded, "transfer")) {
|
|
91614
91722
|
throw new Error("Invalid Harness Remote transferred stream frame");
|
|
91615
91723
|
}
|
|
91616
91724
|
frame = decoded;
|
|
@@ -91623,9 +91731,9 @@ var RemoteTypertGateway2 = class {
|
|
|
91623
91731
|
transferSignal.throwIfAborted();
|
|
91624
91732
|
const value = frame.value;
|
|
91625
91733
|
const normalized = this.compatibility === "legacy-to-v3" ? normalizeLegacySessionGatewayValue(endpoint, value) : normalizeAssistantMessageStreamValue(endpoint, value);
|
|
91626
|
-
if (endpoint === "session/follow" &&
|
|
91734
|
+
if (endpoint === "session/follow" && isRecord10(normalized)) {
|
|
91627
91735
|
if (normalized.type === "snapshot") {
|
|
91628
|
-
if (resolvedSessionId.length === 0 &&
|
|
91736
|
+
if (resolvedSessionId.length === 0 && isRecord10(normalized.header) && typeof normalized.header.id === "string") {
|
|
91629
91737
|
resolvedSessionId = normalized.header.id;
|
|
91630
91738
|
}
|
|
91631
91739
|
this.historyCache.recordFollowSnapshot(this.client, resolvedSessionId, normalized);
|
|
@@ -91650,32 +91758,32 @@ var RemoteTypertGateway2 = class {
|
|
|
91650
91758
|
}
|
|
91651
91759
|
async deferDisconnect(error62, disconnected, signal) {
|
|
91652
91760
|
if (!this.deferStreamDisconnect || !disconnected || signal.aborted) return;
|
|
91653
|
-
if (
|
|
91761
|
+
if (isRecord10(error62) && error62.isDSHRemoteError === true) return;
|
|
91654
91762
|
await new Promise((resolve12) => signal.addEventListener("abort", () => resolve12(), { once: true }));
|
|
91655
91763
|
}
|
|
91656
91764
|
async supportsBinaryWorkspaceReads(signal) {
|
|
91657
91765
|
if (this.binaryWorkspaceReads === void 0) {
|
|
91658
91766
|
const description = await this.client.rpc("harness.transport.describe", {}, signal);
|
|
91659
|
-
this.binaryWorkspaceReads =
|
|
91767
|
+
this.binaryWorkspaceReads = isRecord10(description) && Array.isArray(description.capabilities) && description.capabilities.includes(BINARY_WORKSPACE_READ_CAPABILITY);
|
|
91660
91768
|
}
|
|
91661
91769
|
return this.binaryWorkspaceReads;
|
|
91662
91770
|
}
|
|
91663
91771
|
async readBinaryWorkspaceFile(payload, signal) {
|
|
91664
91772
|
const descriptor2 = await this.client.rpc("workspace.read.binary.open", { payload }, signal);
|
|
91665
|
-
if (
|
|
91666
|
-
if (!
|
|
91773
|
+
if (isRecord10(descriptor2) && descriptor2.kind === "inline") return descriptor2.response;
|
|
91774
|
+
if (!isRecord10(descriptor2) || typeof descriptor2.transferId !== "string" || !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(descriptor2.transferId)) {
|
|
91667
91775
|
throw new Error("Invalid binary workspace transfer descriptor.");
|
|
91668
91776
|
}
|
|
91669
91777
|
const { transferId: transferId2, totalBytes, totalChunks, metadata } = descriptor2;
|
|
91670
91778
|
try {
|
|
91671
|
-
if (descriptor2.kind !== "chunked" || !
|
|
91779
|
+
if (descriptor2.kind !== "chunked" || !isRecord10(metadata) || "data" in metadata || typeof totalBytes !== "number" || !Number.isSafeInteger(totalBytes) || totalBytes < 1 || totalBytes > MAX_COMPLETE_WORKSPACE_READ_BYTES || totalChunks !== Math.ceil(totalBytes / HARNESS_API_TRANSFER_CHUNK_BYTES)) {
|
|
91672
91780
|
throw new Error("Invalid binary workspace transfer descriptor.");
|
|
91673
91781
|
}
|
|
91674
91782
|
const data2 = new Uint8Array(totalBytes);
|
|
91675
91783
|
for (let index = 0; index < totalChunks; index += 1) {
|
|
91676
91784
|
const offset2 = index * HARNESS_API_TRANSFER_CHUNK_BYTES;
|
|
91677
91785
|
const chunk = await this.client.rpc("workspace.read.binary.chunk", { transferId: transferId2, index }, signal);
|
|
91678
|
-
if (!
|
|
91786
|
+
if (!isRecord10(chunk) || chunk.kind !== "workspace.binary.chunk" || chunk.transferId !== transferId2 || chunk.index !== index || !(chunk.data instanceof Uint8Array) || chunk.data.byteLength !== Math.min(HARNESS_API_TRANSFER_CHUNK_BYTES, totalBytes - offset2)) {
|
|
91679
91787
|
throw new Error("Invalid binary workspace transfer chunk.");
|
|
91680
91788
|
}
|
|
91681
91789
|
data2.set(chunk.data, offset2);
|
|
@@ -91823,16 +91931,16 @@ function routeStreamEvent(event2, streamId, queue) {
|
|
|
91823
91931
|
queue.fail(remoteFailure({
|
|
91824
91932
|
code: typeof failure4?.code === "string" ? failure4.code : "internal",
|
|
91825
91933
|
message: typeof failure4?.message === "string" ? failure4.message : "The remote Harness stream failed.",
|
|
91826
|
-
details:
|
|
91934
|
+
details: isRecord10(failure4?.details) ? failure4.details : {}
|
|
91827
91935
|
}));
|
|
91828
91936
|
} else {
|
|
91829
91937
|
queue.close();
|
|
91830
91938
|
}
|
|
91831
91939
|
}
|
|
91832
91940
|
function parseRpcResult(value) {
|
|
91833
|
-
if (!
|
|
91941
|
+
if (!isRecord10(value)) throw new Error("The remote Host returned an invalid Gateway result.");
|
|
91834
91942
|
if (value.ok === true) return Object.hasOwn(value, "value") ? { ok: true, value: value.value } : { ok: true };
|
|
91835
|
-
if (value.ok !== false || !
|
|
91943
|
+
if (value.ok !== false || !isRecord10(value.error) || typeof value.error.code !== "string" || typeof value.error.message !== "string" || !isRecord10(value.error.details)) {
|
|
91836
91944
|
throw new Error("The remote Host returned an invalid Gateway failure.");
|
|
91837
91945
|
}
|
|
91838
91946
|
return {
|
|
@@ -91857,15 +91965,15 @@ function base64ToBytes3(value) {
|
|
|
91857
91965
|
}
|
|
91858
91966
|
function normalizeWorkspaceBinaryResult(endpoint, value) {
|
|
91859
91967
|
if (!WORKSPACE_BINARY_ENDPOINTS.has(endpoint)) return value;
|
|
91860
|
-
if (!
|
|
91968
|
+
if (!isRecord10(value) || typeof value.data !== "string") return value;
|
|
91861
91969
|
return { ...value, data: base64ToBytes3(value.data) };
|
|
91862
91970
|
}
|
|
91863
91971
|
function isCompleteWorkspaceRead(payload) {
|
|
91864
|
-
if (!
|
|
91972
|
+
if (!isRecord10(payload) || !isRecord10(payload.args)) return false;
|
|
91865
91973
|
const { args } = payload;
|
|
91866
|
-
return !("range" in args || "offset" in args || "length" in args ||
|
|
91974
|
+
return !("range" in args || "offset" in args || "length" in args || isRecord10(args.options) && "range" in args.options);
|
|
91867
91975
|
}
|
|
91868
|
-
function
|
|
91976
|
+
function isRecord10(value) {
|
|
91869
91977
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
91870
91978
|
}
|
|
91871
91979
|
function hasErrorCode(error62, code) {
|
|
@@ -91878,23 +91986,23 @@ function isLegacyRemoteHost(version3) {
|
|
|
91878
91986
|
return Number(match[1]) === 0 && Number(match[2]) === 1 && Number(match[3]) < 7;
|
|
91879
91987
|
}
|
|
91880
91988
|
function isWelcomeNoticeOperation(value) {
|
|
91881
|
-
return Array.isArray(value) && value.some((operation) =>
|
|
91989
|
+
return Array.isArray(value) && value.some((operation) => isRecord10(operation) && operation.op === "set" && Array.isArray(operation.path) && operation.path.length === 1 && operation.path[0] === WELCOME_NOTICE_FIELD && operation.value === WELCOME_NOTICE_VERSION);
|
|
91882
91990
|
}
|
|
91883
91991
|
function patchWelcomeDescribe(value) {
|
|
91884
91992
|
if (!Array.isArray(value.namespaces)) return value;
|
|
91885
91993
|
const namespaces = value.namespaces.map((namespace) => {
|
|
91886
|
-
if (!
|
|
91887
|
-
const current =
|
|
91994
|
+
if (!isRecord10(namespace) || namespace.ns !== WELCOME_NOTICE_NAMESPACE) return namespace;
|
|
91995
|
+
const current = isRecord10(namespace.value) ? namespace.value : {};
|
|
91888
91996
|
return { ...namespace, value: { ...current, [WELCOME_NOTICE_FIELD]: WELCOME_NOTICE_VERSION } };
|
|
91889
91997
|
});
|
|
91890
91998
|
return { ...value, namespaces };
|
|
91891
91999
|
}
|
|
91892
92000
|
function normalizeProjectionResult(endpoint, value) {
|
|
91893
|
-
if (endpoint !== "session/projections" || !
|
|
91894
|
-
return Number.isSafeInteger(value.asOfSeq) &&
|
|
92001
|
+
if (endpoint !== "session/projections" || !isRecord10(value) || value.kind !== void 0) return value;
|
|
92002
|
+
return Number.isSafeInteger(value.asOfSeq) && isRecord10(value.values) ? { ...value, kind: "sequenced" } : value;
|
|
91895
92003
|
}
|
|
91896
92004
|
function normalizeThemeSettingsResult(endpoint, result) {
|
|
91897
|
-
if (!result.ok || !
|
|
92005
|
+
if (!result.ok || !isRecord10(result.value)) return result;
|
|
91898
92006
|
const value = result.value;
|
|
91899
92007
|
if (endpoint === "settings/describe" && Array.isArray(value.namespaces)) {
|
|
91900
92008
|
const original = value.namespaces;
|
|
@@ -91908,7 +92016,7 @@ function normalizeThemeSettingsResult(endpoint, result) {
|
|
|
91908
92016
|
return result;
|
|
91909
92017
|
}
|
|
91910
92018
|
function normalizeThemeNamespace(namespace) {
|
|
91911
|
-
if (!
|
|
92019
|
+
if (!isRecord10(namespace) || namespace.ns !== "ui-theme" || !isRecord10(namespace.value)) return namespace;
|
|
91912
92020
|
const section = namespace.value;
|
|
91913
92021
|
const defaults = {
|
|
91914
92022
|
codeFontSize: 11,
|
|
@@ -92859,13 +92967,13 @@ var TerminalCarrierCompat = class {
|
|
|
92859
92967
|
try {
|
|
92860
92968
|
for await (const value of source) {
|
|
92861
92969
|
if (lifetime2.aborted) break;
|
|
92862
|
-
if (
|
|
92970
|
+
if (isRecord11(value) && value.type === "ack") {
|
|
92863
92971
|
const pending = entry.pending.get(Number(value.sequence));
|
|
92864
92972
|
if (!pending) throw new RpcError("INVALID_MESSAGE", "Unexpected terminal input acknowledgement.");
|
|
92865
92973
|
entry.pending.delete(Number(value.sequence));
|
|
92866
92974
|
if (value.refusal) pending.reject(new RpcError("PERMISSION_DENIED", "Terminal input was refused."));
|
|
92867
92975
|
else pending.resolve();
|
|
92868
|
-
} else if (
|
|
92976
|
+
} else if (isRecord11(value) && (value.type === "snapshot" || value.type === "state") && isRecord11(value.info)) {
|
|
92869
92977
|
entry.writable = value.writable === true;
|
|
92870
92978
|
yield { ...value, info: { ...value.info, ...entry.writable ? { controllerId: args.attachmentId } : {} } };
|
|
92871
92979
|
} else yield value;
|
|
@@ -92939,7 +93047,7 @@ async function openRemoteTerminal(target3, payload, signal, uplink) {
|
|
|
92939
93047
|
try {
|
|
92940
93048
|
for await (const value of source) {
|
|
92941
93049
|
if (lifetime2.aborted) break;
|
|
92942
|
-
if (
|
|
93050
|
+
if (isRecord11(value) && (value.type === "snapshot" || value.type === "state") && isRecord11(value.info)) {
|
|
92943
93051
|
writable = value.info.controllerId === attachmentId;
|
|
92944
93052
|
output2.push({ ...value, writable });
|
|
92945
93053
|
if (value.type === "snapshot") startInput();
|
|
@@ -92987,7 +93095,7 @@ async function openRemoteTerminal(target3, payload, signal, uplink) {
|
|
|
92987
93095
|
}
|
|
92988
93096
|
})();
|
|
92989
93097
|
}
|
|
92990
|
-
function
|
|
93098
|
+
function isRecord11(value) {
|
|
92991
93099
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
92992
93100
|
}
|
|
92993
93101
|
|
|
@@ -93161,14 +93269,14 @@ var TypertGatewaySwitch = class {
|
|
|
93161
93269
|
if (normalized !== void 0) return normalized;
|
|
93162
93270
|
const source = error62 instanceof Error ? error62 : new Error("The Harness Gateway rejected the request.");
|
|
93163
93271
|
const code = "code" in source && typeof source.code === "string" ? source.code : "internal";
|
|
93164
|
-
const details2 = "details" in source &&
|
|
93272
|
+
const details2 = "details" in source && isRecord12(source.details) ? source.details : {};
|
|
93165
93273
|
return { code, message: source.message, details: details2 };
|
|
93166
93274
|
}
|
|
93167
93275
|
};
|
|
93168
93276
|
function workspaceConnectionResult(endpoint, result) {
|
|
93169
93277
|
if (endpoint === "terminal/environment" && result.ok) return { ...result, value: normalizeTerminalEnvironment(endpoint, result.value) };
|
|
93170
93278
|
if (!WORKSPACE_BINARY_ENDPOINTS.has(endpoint)) return result;
|
|
93171
|
-
if (!result.ok || !
|
|
93279
|
+
if (!result.ok || !isRecord12(result.value) || !(result.value.data instanceof Uint8Array)) return result;
|
|
93172
93280
|
return {
|
|
93173
93281
|
...result,
|
|
93174
93282
|
value: { ...result.value, data: null },
|
|
@@ -93198,7 +93306,7 @@ function linkControl(signal) {
|
|
|
93198
93306
|
return control;
|
|
93199
93307
|
}
|
|
93200
93308
|
function hasPeerSignal(peer) {
|
|
93201
|
-
if (!
|
|
93309
|
+
if (!isRecord12(peer)) return false;
|
|
93202
93310
|
const signal = peer.signal;
|
|
93203
93311
|
return typeof signal === "object" && signal !== null && typeof signal.aborted === "boolean" && typeof signal.addEventListener === "function";
|
|
93204
93312
|
}
|
|
@@ -93222,7 +93330,7 @@ function requestFromCarrier(endpoint, payload, signal) {
|
|
|
93222
93330
|
if (segments.length !== 2 || segments.some((segment) => segment.length === 0)) {
|
|
93223
93331
|
throw new Error("The Harness Gateway endpoint is invalid.");
|
|
93224
93332
|
}
|
|
93225
|
-
if (!
|
|
93333
|
+
if (!isRecord12(payload) || !isRecord12(payload.args)) {
|
|
93226
93334
|
throw new Error("The Harness Gateway payload is invalid.");
|
|
93227
93335
|
}
|
|
93228
93336
|
return { namespace: segments[0], method: segments[1], args: payload.args, signal };
|
|
@@ -93237,11 +93345,11 @@ function isLocalOnlyEndpoint(endpoint) {
|
|
|
93237
93345
|
function isRemoteCommandMethod(method) {
|
|
93238
93346
|
return REMOTE_COMMAND_METHODS.includes(method);
|
|
93239
93347
|
}
|
|
93240
|
-
function
|
|
93348
|
+
function isRecord12(value) {
|
|
93241
93349
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
93242
93350
|
}
|
|
93243
93351
|
function normalizeTerminalEnvironment(endpoint, value) {
|
|
93244
|
-
if (endpoint !== "terminal/environment" || !
|
|
93352
|
+
if (endpoint !== "terminal/environment" || !isRecord12(value) || value.maxBufferedBytes !== void 0) return value;
|
|
93245
93353
|
return { ...value, maxBufferedBytes: 256 * 1024 };
|
|
93246
93354
|
}
|
|
93247
93355
|
|
|
@@ -94744,6 +94852,15 @@ var ClientModeRuntime = class {
|
|
|
94744
94852
|
* stream is on instead of opening their own.
|
|
94745
94853
|
*/
|
|
94746
94854
|
borrowHeld = /* @__PURE__ */ new Map();
|
|
94855
|
+
/**
|
|
94856
|
+
* Reads one image from *this* machine's attachment store.
|
|
94857
|
+
*
|
|
94858
|
+
* Injected by the plugin runtime, which can reach the `attachments` service.
|
|
94859
|
+
* `ClientModeRuntime` deliberately owns no service lookups, and model sharing
|
|
94860
|
+
* needs the bytes locally only so they can be copied to the lending Host.
|
|
94861
|
+
* The store validates the full reference, so it is passed through unchanged.
|
|
94862
|
+
*/
|
|
94863
|
+
modelShareImageReader;
|
|
94747
94864
|
runSessionTool(operation, args, signal) {
|
|
94748
94865
|
this.assertHostAuthorizationForDeviceDiscovery();
|
|
94749
94866
|
if (this.closed) throw new ClientModeError("CANCELLED", "The Remote runtime is closed.");
|
|
@@ -94831,6 +94948,47 @@ var ClientModeRuntime = class {
|
|
|
94831
94948
|
);
|
|
94832
94949
|
return response;
|
|
94833
94950
|
},
|
|
94951
|
+
/**
|
|
94952
|
+
* Copy one image to the lending Host and return the reference it minted.
|
|
94953
|
+
*
|
|
94954
|
+
* Attachment ids are content-addressed handles into one machine's storage
|
|
94955
|
+
* (`ImageAttachmentRef.attachmentId`), so a reference created here is
|
|
94956
|
+
* meaningless there — that is the `ATTACHMENT_NOT_FOUND` a borrowed call
|
|
94957
|
+
* would otherwise hit. The Host's own upload route already solves this:
|
|
94958
|
+
* it stores the bytes in *its* attachment store and answers with *its*
|
|
94959
|
+
* reference. Reusing it keeps one implementation of limits, normalization
|
|
94960
|
+
* and receipts.
|
|
94961
|
+
*
|
|
94962
|
+
* It runs on the held connection for the same reason `list` does: a peer
|
|
94963
|
+
* closes the previous connection for a device when another arrives, and
|
|
94964
|
+
* that would abort a reply already streaming.
|
|
94965
|
+
*/
|
|
94966
|
+
copyImage: async (ref, signal) => {
|
|
94967
|
+
const read = this.modelShareImageReader;
|
|
94968
|
+
if (read === void 0) {
|
|
94969
|
+
throw new ClientModeError("CANCELLED", "This machine has no attachment store to read the image from.");
|
|
94970
|
+
}
|
|
94971
|
+
const stored = await read(ref, signal);
|
|
94972
|
+
if (stored.data.byteLength > MODEL_SHARE_ATTACH_MAX_BYTES) {
|
|
94973
|
+
const limitMb = (MODEL_SHARE_ATTACH_MAX_BYTES / 1024 ** 2).toFixed(1);
|
|
94974
|
+
throw new ClientModeError(
|
|
94975
|
+
"INVALID_MESSAGE",
|
|
94976
|
+
`\u8FD9\u5F20\u56FE\u7247\u7EA6 ${(stored.data.byteLength / 1024 ** 2).toFixed(1)} MiB\uFF0C\u8D85\u8FC7\u8DE8\u8BBE\u5907\u501F\u7528\u6A21\u578B ${limitMb} MiB \u7684\u5355\u56FE\u4E0A\u9650\u3002\u8BF7\u538B\u7F29\u6216\u88C1\u526A\u540E\u518D\u53D1\uFF0C\u6216\u6539\u7528\u672C\u5730\u6A21\u578B\u5904\u7406\u8FD9\u5F20\u56FE\u7247\u3002`
|
|
94977
|
+
);
|
|
94978
|
+
}
|
|
94979
|
+
const connection = await acquire();
|
|
94980
|
+
const attachSignal = signal === void 0 ? connection.signal : AbortSignal.any([signal, connection.signal]);
|
|
94981
|
+
signal?.throwIfAborted();
|
|
94982
|
+
const result = await connection.remote.client.rpc("model.share.attach", {
|
|
94983
|
+
mediaType: stored.ref.mediaType,
|
|
94984
|
+
data: Buffer.from(stored.data).toString("base64")
|
|
94985
|
+
}, attachSignal);
|
|
94986
|
+
if (typeof result?.image?.attachmentId !== "string") {
|
|
94987
|
+
const detail = typeof result?.message === "string" ? ` ${result.message}` : "";
|
|
94988
|
+
throw new ClientModeError("INVALID_MESSAGE", `The lending Host could not store the image.${detail}`);
|
|
94989
|
+
}
|
|
94990
|
+
return result.image;
|
|
94991
|
+
},
|
|
94834
94992
|
open: async (request2) => {
|
|
94835
94993
|
const openGeneration = generation;
|
|
94836
94994
|
const connection = await acquire();
|
|
@@ -97508,17 +97666,17 @@ var HostAttentionTracker = class {
|
|
|
97508
97666
|
// ── DS-Bot live PluginRouteBridge observation (zero idle polling) ─────────
|
|
97509
97667
|
observeBotResponse(route, body, result) {
|
|
97510
97668
|
if (this.closed || route !== "api/bot" || result.status !== 200) return;
|
|
97511
|
-
if (!
|
|
97669
|
+
if (!isRecord13(result.json) || result.json.ok !== true) return;
|
|
97512
97670
|
const value = result.json.value;
|
|
97513
97671
|
if (body.endpoint === "approval-answer") {
|
|
97514
|
-
const approvalId =
|
|
97672
|
+
const approvalId = isRecord13(body.payload) && typeof body.payload.id === "string" ? body.payload.id : void 0;
|
|
97515
97673
|
if (approvalId !== void 0) this.onInteractionResolved(botApprovalItemId(approvalId));
|
|
97516
97674
|
return;
|
|
97517
97675
|
}
|
|
97518
97676
|
if (body.endpoint === "answer-question" || body.endpoint === "dismiss-question") {
|
|
97519
|
-
const botId =
|
|
97520
|
-
const sessionId = (
|
|
97521
|
-
const questionId =
|
|
97677
|
+
const botId = isRecord13(body.payload) && typeof body.payload.botId === "string" ? body.payload.botId : void 0;
|
|
97678
|
+
const sessionId = (isRecord13(body.payload) && typeof body.payload.sessionId === "string" ? body.payload.sessionId : void 0) ?? (botId !== void 0 ? this.botNamesById.get(botId)?.sessionId : void 0);
|
|
97679
|
+
const questionId = isRecord13(body.payload) && typeof body.payload.questionId === "string" ? body.payload.questionId : void 0;
|
|
97522
97680
|
if (sessionId !== void 0 && questionId !== void 0) {
|
|
97523
97681
|
this.onInteractionResolved(botQuestionItemId(sessionId, questionId));
|
|
97524
97682
|
} else if (sessionId !== void 0) {
|
|
@@ -97530,8 +97688,8 @@ var HostAttentionTracker = class {
|
|
|
97530
97688
|
return;
|
|
97531
97689
|
}
|
|
97532
97690
|
if (body.endpoint === "view-reply" || body.endpoint === "dismiss-view") {
|
|
97533
|
-
const viewId =
|
|
97534
|
-
const sessionId =
|
|
97691
|
+
const viewId = isRecord13(body.payload) && typeof body.payload.viewId === "string" ? body.payload.viewId : void 0;
|
|
97692
|
+
const sessionId = isRecord13(body.payload) && typeof body.payload.sessionId === "string" ? body.payload.sessionId : void 0;
|
|
97535
97693
|
if (viewId !== void 0) {
|
|
97536
97694
|
this.onInteractionResolved(botInboxItemId("view", viewId));
|
|
97537
97695
|
} else if (sessionId !== void 0) {
|
|
@@ -97544,16 +97702,16 @@ var HostAttentionTracker = class {
|
|
|
97544
97702
|
return;
|
|
97545
97703
|
}
|
|
97546
97704
|
if (body.endpoint === "computer-app-answer") {
|
|
97547
|
-
const askId =
|
|
97705
|
+
const askId = isRecord13(body.payload) ? firstNonEmptyString(body.payload.askId, body.payload.id) : void 0;
|
|
97548
97706
|
if (askId !== void 0) {
|
|
97549
97707
|
this.onInteractionResolved(botInboxItemId("computer", askId));
|
|
97550
97708
|
}
|
|
97551
97709
|
return;
|
|
97552
97710
|
}
|
|
97553
97711
|
if (body.endpoint === "learning-answer") {
|
|
97554
|
-
const proposalId =
|
|
97555
|
-
const botId =
|
|
97556
|
-
const sessionId = (
|
|
97712
|
+
const proposalId = isRecord13(body.payload) ? firstNonEmptyString(body.payload.id) : void 0;
|
|
97713
|
+
const botId = isRecord13(body.payload) && typeof body.payload.botId === "string" ? body.payload.botId : void 0;
|
|
97714
|
+
const sessionId = (isRecord13(body.payload) && typeof body.payload.sessionId === "string" ? body.payload.sessionId : void 0) ?? (botId !== void 0 ? this.botNamesById.get(botId)?.sessionId : void 0);
|
|
97557
97715
|
if (proposalId !== void 0) {
|
|
97558
97716
|
this.onInteractionResolved(botInboxItemId("learning", proposalId));
|
|
97559
97717
|
} else if (sessionId !== void 0) {
|
|
@@ -97567,9 +97725,9 @@ var HostAttentionTracker = class {
|
|
|
97567
97725
|
}
|
|
97568
97726
|
if (body.endpoint === "secret-set" || body.endpoint === "secret-allow" || body.endpoint === "secret-cancel" || body.endpoint === "mail-send-answer") {
|
|
97569
97727
|
const kind = body.endpoint === "mail-send-answer" ? "mail" : "secret";
|
|
97570
|
-
const requestId2 =
|
|
97571
|
-
const botId =
|
|
97572
|
-
const sessionId = (
|
|
97728
|
+
const requestId2 = isRecord13(body.payload) ? firstNonEmptyString(body.payload.id, body.payload.requestId) : void 0;
|
|
97729
|
+
const botId = isRecord13(body.payload) && typeof body.payload.botId === "string" ? body.payload.botId : void 0;
|
|
97730
|
+
const sessionId = (isRecord13(body.payload) && typeof body.payload.sessionId === "string" ? body.payload.sessionId : void 0) ?? (botId !== void 0 ? this.botNamesById.get(botId)?.sessionId : void 0);
|
|
97573
97731
|
if (requestId2 !== void 0) {
|
|
97574
97732
|
this.onInteractionResolved(botInboxItemId(kind, requestId2));
|
|
97575
97733
|
} else if (sessionId !== void 0) {
|
|
@@ -97581,7 +97739,7 @@ var HostAttentionTracker = class {
|
|
|
97581
97739
|
}
|
|
97582
97740
|
return;
|
|
97583
97741
|
}
|
|
97584
|
-
if (body.endpoint === "state" &&
|
|
97742
|
+
if (body.endpoint === "state" && isRecord13(value)) {
|
|
97585
97743
|
this.observeBotState(value);
|
|
97586
97744
|
return;
|
|
97587
97745
|
}
|
|
@@ -97598,13 +97756,13 @@ var HostAttentionTracker = class {
|
|
|
97598
97756
|
this.botNamesById.clear();
|
|
97599
97757
|
this.taskOwnerBySessionId.clear();
|
|
97600
97758
|
for (const entry of state2.bots) {
|
|
97601
|
-
if (!
|
|
97759
|
+
if (!isRecord13(entry) || typeof entry.id !== "string" || typeof entry.sessionId !== "string") continue;
|
|
97602
97760
|
const name2 = typeof entry.name === "string" && entry.name.trim().length > 0 ? entry.name.trim() : entry.id;
|
|
97603
97761
|
this.botNamesById.set(entry.id, { name: name2, sessionId: entry.sessionId });
|
|
97604
97762
|
this.rememberTitle(entry.sessionId, name2);
|
|
97605
97763
|
if (Array.isArray(entry.tasks)) {
|
|
97606
97764
|
for (const task of entry.tasks) {
|
|
97607
|
-
if (
|
|
97765
|
+
if (isRecord13(task) && typeof task.sessionId === "string" && task.sessionId.length > 0) {
|
|
97608
97766
|
this.taskOwnerBySessionId.set(task.sessionId, { botId: entry.id, sessionId: entry.sessionId, name: name2 });
|
|
97609
97767
|
}
|
|
97610
97768
|
}
|
|
@@ -97621,7 +97779,7 @@ var HostAttentionTracker = class {
|
|
|
97621
97779
|
if (Array.isArray(state2.rooms)) {
|
|
97622
97780
|
this.roomNamesById.clear();
|
|
97623
97781
|
for (const entry of state2.rooms) {
|
|
97624
|
-
if (!
|
|
97782
|
+
if (!isRecord13(entry) || typeof entry.id !== "string") continue;
|
|
97625
97783
|
const sessionId = typeof entry.sessionId === "string" && entry.sessionId.length > 0 ? entry.sessionId : entry.id;
|
|
97626
97784
|
const name2 = typeof entry.name === "string" && entry.name.trim().length > 0 ? entry.name.trim() : entry.id;
|
|
97627
97785
|
this.roomNamesById.set(entry.id, { name: name2, sessionId });
|
|
@@ -97635,14 +97793,14 @@ var HostAttentionTracker = class {
|
|
|
97635
97793
|
});
|
|
97636
97794
|
}
|
|
97637
97795
|
}
|
|
97638
|
-
const work =
|
|
97796
|
+
const work = isRecord13(state2.work) ? state2.work : void 0;
|
|
97639
97797
|
const rawApprovals = Array.isArray(work?.approvals) ? work.approvals : Array.isArray(state2.approvals) ? state2.approvals : void 0;
|
|
97640
97798
|
if (rawApprovals !== void 0) {
|
|
97641
97799
|
const activeApprovalIds = /* @__PURE__ */ new Set();
|
|
97642
97800
|
for (const approval of rawApprovals) {
|
|
97643
|
-
if (!
|
|
97801
|
+
if (!isRecord13(approval) || typeof approval.id !== "string" || approval.id.length === 0) continue;
|
|
97644
97802
|
if (approval.answerable === false) continue;
|
|
97645
|
-
if (
|
|
97803
|
+
if (isRecord13(approval.review) && approval.review.status === "reviewing") continue;
|
|
97646
97804
|
const room = typeof approval.roomId === "string" ? this.roomNamesById.get(approval.roomId) : void 0;
|
|
97647
97805
|
const taskOwner = typeof approval.sessionId === "string" ? this.taskOwnerBySessionId.get(approval.sessionId) : void 0;
|
|
97648
97806
|
const bot = typeof approval.botId === "string" ? this.botNamesById.get(approval.botId) : void 0;
|
|
@@ -97669,10 +97827,10 @@ var HostAttentionTracker = class {
|
|
|
97669
97827
|
}
|
|
97670
97828
|
}
|
|
97671
97829
|
}
|
|
97672
|
-
if (
|
|
97830
|
+
if (isRecord13(state2.questions)) {
|
|
97673
97831
|
const activeQuestionIds = /* @__PURE__ */ new Set();
|
|
97674
97832
|
for (const [sessionId, rawQuestion] of Object.entries(state2.questions)) {
|
|
97675
|
-
if (!
|
|
97833
|
+
if (!isRecord13(rawQuestion) || typeof rawQuestion.id !== "string" || rawQuestion.id.length === 0) continue;
|
|
97676
97834
|
const itemId = botQuestionItemId(sessionId, rawQuestion.id);
|
|
97677
97835
|
activeQuestionIds.add(itemId);
|
|
97678
97836
|
const summary3 = firstNonEmptyString(rawQuestion.question, rawQuestion.title, rawQuestion.prompt, rawQuestion.text);
|
|
@@ -97693,10 +97851,10 @@ var HostAttentionTracker = class {
|
|
|
97693
97851
|
}
|
|
97694
97852
|
}
|
|
97695
97853
|
}
|
|
97696
|
-
if (
|
|
97854
|
+
if (isRecord13(state2.inbox) && Array.isArray(state2.inbox.items)) {
|
|
97697
97855
|
const activeInboxIds = /* @__PURE__ */ new Set();
|
|
97698
97856
|
for (const entry of state2.inbox.items) {
|
|
97699
|
-
if (!
|
|
97857
|
+
if (!isRecord13(entry) || typeof entry.kind !== "string") continue;
|
|
97700
97858
|
const kind = entry.kind;
|
|
97701
97859
|
const isInboxApproval = BOT_INBOX_APPROVAL_KINDS.has(kind);
|
|
97702
97860
|
const isInboxQuestion = BOT_INBOX_QUESTION_KINDS.has(kind);
|
|
@@ -97729,9 +97887,9 @@ var HostAttentionTracker = class {
|
|
|
97729
97887
|
}
|
|
97730
97888
|
}
|
|
97731
97889
|
}
|
|
97732
|
-
if (work !== void 0 && (
|
|
97890
|
+
if (work !== void 0 && (isRecord13(work.bots) || isRecord13(work.rooms))) {
|
|
97733
97891
|
const activeSessionIds = /* @__PURE__ */ new Set();
|
|
97734
|
-
if (
|
|
97892
|
+
if (isRecord13(work.bots)) {
|
|
97735
97893
|
for (const [botId, workEntry] of Object.entries(work.bots)) {
|
|
97736
97894
|
if (!isBotWorkActive(workEntry)) continue;
|
|
97737
97895
|
const bot = this.botNamesById.get(botId);
|
|
@@ -97746,7 +97904,7 @@ var HostAttentionTracker = class {
|
|
|
97746
97904
|
});
|
|
97747
97905
|
}
|
|
97748
97906
|
}
|
|
97749
|
-
if (
|
|
97907
|
+
if (isRecord13(work.rooms)) {
|
|
97750
97908
|
for (const [roomId, workEntry] of Object.entries(work.rooms)) {
|
|
97751
97909
|
if (!isBotWorkActive(workEntry)) continue;
|
|
97752
97910
|
const room = this.roomNamesById.get(roomId);
|
|
@@ -97814,9 +97972,9 @@ var HostAttentionTracker = class {
|
|
|
97814
97972
|
}
|
|
97815
97973
|
}
|
|
97816
97974
|
observeBotNotices(value) {
|
|
97817
|
-
const entries = Array.isArray(value) ? value :
|
|
97975
|
+
const entries = Array.isArray(value) ? value : isRecord13(value) && Array.isArray(value.notices) ? value.notices : isRecord13(value) && Array.isArray(value.items) ? value.items : [];
|
|
97818
97976
|
for (const entry of entries) {
|
|
97819
|
-
if (!
|
|
97977
|
+
if (!isRecord13(entry)) continue;
|
|
97820
97978
|
const room = typeof entry.roomId === "string" ? this.roomNamesById.get(entry.roomId) : void 0;
|
|
97821
97979
|
const bot = typeof entry.botId === "string" ? this.botNamesById.get(entry.botId) : void 0;
|
|
97822
97980
|
const sessionId = room?.sessionId ?? bot?.sessionId ?? firstNonEmptyString(entry.sessionId, entry.botId, entry.roomId, entry.id);
|
|
@@ -97962,7 +98120,7 @@ var HostAttentionTracker = class {
|
|
|
97962
98120
|
while (!this.closed && !controller.signal.aborted) {
|
|
97963
98121
|
const next = await iterator.next();
|
|
97964
98122
|
if (next.done || this.closed || controller.signal.aborted) break;
|
|
97965
|
-
if (
|
|
98123
|
+
if (isRecord13(next.value) && (next.value.type === "baseline" || next.value.type === "projection")) {
|
|
97966
98124
|
attempt = 0;
|
|
97967
98125
|
}
|
|
97968
98126
|
this.handleHarnessControlFrame(next.value);
|
|
@@ -98005,8 +98163,8 @@ var HostAttentionTracker = class {
|
|
|
98005
98163
|
args: { endpoint: "hello", payload: { api: [1] } }
|
|
98006
98164
|
}, controller.signal);
|
|
98007
98165
|
if (this.closed || controller.signal.aborted) break;
|
|
98008
|
-
if (!
|
|
98009
|
-
const code =
|
|
98166
|
+
if (!isRecord13(helloRpc) || helloRpc.ok !== true) {
|
|
98167
|
+
const code = isRecord13(helloRpc) && isRecord13(helloRpc.error) && typeof helloRpc.error.code === "string" ? helloRpc.error.code : void 0;
|
|
98010
98168
|
const retryableRpc = code === "gateway/invocation-unavailable" || code === "gateway/service-unavailable";
|
|
98011
98169
|
if (code === void 0 || retryableRpc && attempt >= this.observerBackoffMs.length || !retryableRpc && TERMINAL_OBSERVER_ERROR_CODES.has(code)) {
|
|
98012
98170
|
terminal = true;
|
|
@@ -98015,7 +98173,7 @@ var HostAttentionTracker = class {
|
|
|
98015
98173
|
throw Object.assign(new Error("dsBot/call hello failed"), { code });
|
|
98016
98174
|
}
|
|
98017
98175
|
const helloEnvelope = unwrapDsBotEnvelope(helloRpc.value);
|
|
98018
|
-
if (!
|
|
98176
|
+
if (!isRecord13(helloEnvelope) || helloEnvelope.ok !== true || !isRecord13(helloEnvelope.value)) {
|
|
98019
98177
|
terminal = true;
|
|
98020
98178
|
break;
|
|
98021
98179
|
}
|
|
@@ -98073,7 +98231,7 @@ var HostAttentionTracker = class {
|
|
|
98073
98231
|
});
|
|
98074
98232
|
}
|
|
98075
98233
|
handleDsBotFeedFrame(gateway, frame) {
|
|
98076
|
-
if (!
|
|
98234
|
+
if (!isRecord13(frame) || typeof frame.event !== "string") return;
|
|
98077
98235
|
const { event: event2, data: data2 } = frame;
|
|
98078
98236
|
if (event2 === "hello" || event2 === "state" || event2 === "revision") {
|
|
98079
98237
|
this.scheduleBotStateSync(gateway, true);
|
|
@@ -98083,7 +98241,7 @@ var HostAttentionTracker = class {
|
|
|
98083
98241
|
this.scheduleBotStateSync(gateway, false);
|
|
98084
98242
|
return;
|
|
98085
98243
|
}
|
|
98086
|
-
if (event2 === "notice" &&
|
|
98244
|
+
if (event2 === "notice" && isRecord13(data2)) {
|
|
98087
98245
|
this.observeBotResponse(
|
|
98088
98246
|
"api/bot",
|
|
98089
98247
|
{ endpoint: "notices", payload: {} },
|
|
@@ -98113,9 +98271,9 @@ var HostAttentionTracker = class {
|
|
|
98113
98271
|
const rpcResult = await gateway.dispatch("dsBot/call", {
|
|
98114
98272
|
args: { endpoint: "state", payload }
|
|
98115
98273
|
}, this.botObserverController?.signal ?? AbortSignal.timeout(15e3));
|
|
98116
|
-
if (this.closed || !
|
|
98274
|
+
if (this.closed || !isRecord13(rpcResult) || rpcResult.ok !== true) return;
|
|
98117
98275
|
const envelope = unwrapDsBotEnvelope(rpcResult.value);
|
|
98118
|
-
if (!
|
|
98276
|
+
if (!isRecord13(envelope) || envelope.ok !== true || !isRecord13(envelope.value)) return;
|
|
98119
98277
|
if (typeof envelope.value.revision === "number") this.botStateRevision = envelope.value.revision;
|
|
98120
98278
|
if (typeof envelope.value.liveKey === "string") this.botStateLiveKey = envelope.value.liveKey;
|
|
98121
98279
|
this.observeBotResponse(
|
|
@@ -98132,8 +98290,8 @@ var HostAttentionTracker = class {
|
|
|
98132
98290
|
}
|
|
98133
98291
|
}
|
|
98134
98292
|
handleHarnessControlFrame(frame) {
|
|
98135
|
-
if (!
|
|
98136
|
-
if (frame.type === "baseline" &&
|
|
98293
|
+
if (!isRecord13(frame) || typeof frame.type !== "string") return;
|
|
98294
|
+
if (frame.type === "baseline" && isRecord13(frame.value) && isRecord13(frame.value.projections)) {
|
|
98137
98295
|
const nextIds = /* @__PURE__ */ new Set();
|
|
98138
98296
|
const sessionsWithUserQuestions = /* @__PURE__ */ new Set();
|
|
98139
98297
|
const baselineStates = [];
|
|
@@ -98145,7 +98303,7 @@ var HostAttentionTracker = class {
|
|
|
98145
98303
|
if (oldest === void 0) break;
|
|
98146
98304
|
nextIds.delete(oldest);
|
|
98147
98305
|
}
|
|
98148
|
-
if (!
|
|
98306
|
+
if (!isRecord13(block) || !isRecord13(block.values)) continue;
|
|
98149
98307
|
const seq = typeof block.asOfSeq === "number" ? block.asOfSeq : void 0;
|
|
98150
98308
|
if (Object.hasOwn(block.values, "title")) {
|
|
98151
98309
|
this.applyHarnessControlProjection(sessionId, "title", block.values.title, seq);
|
|
@@ -98199,7 +98357,7 @@ var HostAttentionTracker = class {
|
|
|
98199
98357
|
const seq = typeof frame.seq === "number" ? frame.seq : void 0;
|
|
98200
98358
|
if (Array.isArray(frame.changes)) {
|
|
98201
98359
|
for (const change of frame.changes) {
|
|
98202
|
-
if (!
|
|
98360
|
+
if (!isRecord13(change) || typeof change.key !== "string") continue;
|
|
98203
98361
|
if (change.key === "title") {
|
|
98204
98362
|
this.applyHarnessControlProjection(frame.sessionId, "title", change.val, seq);
|
|
98205
98363
|
}
|
|
@@ -98210,7 +98368,7 @@ var HostAttentionTracker = class {
|
|
|
98210
98368
|
}
|
|
98211
98369
|
}
|
|
98212
98370
|
for (const change of frame.changes) {
|
|
98213
|
-
if (
|
|
98371
|
+
if (isRecord13(change) && change.key === "userQuestions") {
|
|
98214
98372
|
this.applyHarnessControlProjection(frame.sessionId, "userQuestions", change.val, seq);
|
|
98215
98373
|
}
|
|
98216
98374
|
}
|
|
@@ -98285,12 +98443,12 @@ var HostAttentionTracker = class {
|
|
|
98285
98443
|
}
|
|
98286
98444
|
return;
|
|
98287
98445
|
}
|
|
98288
|
-
if (!
|
|
98446
|
+
if (!isRecord13(value) || !Array.isArray(value.active)) return;
|
|
98289
98447
|
if ("settled" in value && value.settled !== void 0 && !Array.isArray(value.settled)) return;
|
|
98290
98448
|
if (seq !== void 0) this.rememberHarnessQuestionSeq(sessionId, seq);
|
|
98291
98449
|
const nextActiveIds = /* @__PURE__ */ new Set();
|
|
98292
98450
|
for (const row of value.active) {
|
|
98293
|
-
if (!
|
|
98451
|
+
if (!isRecord13(row) || typeof row.callId !== "string" || row.callId.length === 0) continue;
|
|
98294
98452
|
if (row.state !== "open" && row.state !== "continued") continue;
|
|
98295
98453
|
if (row.questions !== void 0 && !Array.isArray(row.questions)) continue;
|
|
98296
98454
|
const itemId = harnessProjectedQuestionItemId(sessionId, row.callId);
|
|
@@ -98313,7 +98471,7 @@ var HostAttentionTracker = class {
|
|
|
98313
98471
|
}
|
|
98314
98472
|
if (Array.isArray(value.settled)) {
|
|
98315
98473
|
for (const row of value.settled) {
|
|
98316
|
-
if (!
|
|
98474
|
+
if (!isRecord13(row) || typeof row.callId !== "string" || row.callId.length === 0) continue;
|
|
98317
98475
|
const settledId = harnessProjectedQuestionItemId(sessionId, row.callId);
|
|
98318
98476
|
if (!nextActiveIds.has(settledId)) this.onInteractionResolved(settledId);
|
|
98319
98477
|
}
|
|
@@ -98341,12 +98499,12 @@ var HostAttentionTracker = class {
|
|
|
98341
98499
|
});
|
|
98342
98500
|
}
|
|
98343
98501
|
handleHarnessEventFrame(frame) {
|
|
98344
|
-
if (!
|
|
98502
|
+
if (!isRecord13(frame) || typeof frame.type !== "string") return;
|
|
98345
98503
|
if (frame.type === "emit" && typeof frame.event === "string" && Array.isArray(frame.args)) {
|
|
98346
98504
|
this.handleHarnessEmit(frame.event, frame.args);
|
|
98347
98505
|
return;
|
|
98348
98506
|
}
|
|
98349
|
-
if (frame.type === "waterfall" && typeof frame.eventId === "string" && typeof frame.agentId === "string" &&
|
|
98507
|
+
if (frame.type === "waterfall" && typeof frame.eventId === "string" && typeof frame.agentId === "string" && isRecord13(frame.request)) {
|
|
98350
98508
|
this.handleHarnessWaterfall(frame.event, frame.eventId, frame.agentId, frame.request);
|
|
98351
98509
|
return;
|
|
98352
98510
|
}
|
|
@@ -98376,9 +98534,9 @@ var HostAttentionTracker = class {
|
|
|
98376
98534
|
case "api-session/added":
|
|
98377
98535
|
case "api-session/updated": {
|
|
98378
98536
|
const raw = args[0];
|
|
98379
|
-
if (!
|
|
98537
|
+
if (!isRecord13(raw) || typeof raw.sessionId !== "string" || raw.sessionId.length === 0) return;
|
|
98380
98538
|
const sessionId = raw.sessionId;
|
|
98381
|
-
const projections =
|
|
98539
|
+
const projections = isRecord13(raw.projections) && isRecord13(raw.projections.values) ? raw.projections.values : void 0;
|
|
98382
98540
|
const sessionTitle = firstNonEmptyString(projections?.title, raw.title, raw.name);
|
|
98383
98541
|
const workspaceId = firstNonEmptyString(raw.workspaceId);
|
|
98384
98542
|
const workspaceLabel = firstNonEmptyString(raw.workspaceLabel, raw.workspaceName);
|
|
@@ -98470,7 +98628,7 @@ var HostAttentionTracker = class {
|
|
|
98470
98628
|
}
|
|
98471
98629
|
if (event2 === "user-questions/request") {
|
|
98472
98630
|
const summary3 = extractHarnessQuestionSummary(request2);
|
|
98473
|
-
const wait =
|
|
98631
|
+
const wait = isRecord13(request2.wait) ? request2.wait : void 0;
|
|
98474
98632
|
const callId = typeof wait?.callId === "string" && wait.callId.length > 0 ? wait.callId : void 0;
|
|
98475
98633
|
const itemId = callId === void 0 ? harnessQuestionItemId(eventId) : harnessProjectedQuestionItemId(sessionId, callId);
|
|
98476
98634
|
if (callId !== void 0) {
|
|
@@ -98787,7 +98945,7 @@ function isBotWorkActive(value) {
|
|
|
98787
98945
|
if (typeof value === "number") return value > 0;
|
|
98788
98946
|
if (typeof value === "string") return value.trim().length > 0 && value !== "idle";
|
|
98789
98947
|
if (Array.isArray(value)) return value.length > 0;
|
|
98790
|
-
if (
|
|
98948
|
+
if (isRecord13(value)) {
|
|
98791
98949
|
if (value.active === false || value.running === false || value.status === "idle") return false;
|
|
98792
98950
|
return Object.keys(value).length > 0;
|
|
98793
98951
|
}
|
|
@@ -98796,7 +98954,7 @@ function isBotWorkActive(value) {
|
|
|
98796
98954
|
function extractHarnessQuestionSummary(request2) {
|
|
98797
98955
|
if (Array.isArray(request2.questions)) {
|
|
98798
98956
|
for (const entry of request2.questions) {
|
|
98799
|
-
if (
|
|
98957
|
+
if (isRecord13(entry)) {
|
|
98800
98958
|
const text = firstNonEmptyString(entry.question, entry.header, entry.prompt, entry.title);
|
|
98801
98959
|
if (text !== void 0) return text;
|
|
98802
98960
|
} else if (typeof entry === "string" && entry.trim().length > 0) {
|
|
@@ -98833,11 +98991,11 @@ function controlStateSignature(value) {
|
|
|
98833
98991
|
}
|
|
98834
98992
|
return "o";
|
|
98835
98993
|
}
|
|
98836
|
-
function
|
|
98994
|
+
function isRecord13(value) {
|
|
98837
98995
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
98838
98996
|
}
|
|
98839
98997
|
function unwrapDsBotEnvelope(value) {
|
|
98840
|
-
if (!
|
|
98998
|
+
if (!isRecord13(value)) return void 0;
|
|
98841
98999
|
if (typeof value.ok === "boolean") return value;
|
|
98842
99000
|
return { ok: true, value };
|
|
98843
99001
|
}
|
|
@@ -102513,7 +102671,7 @@ var CodexAppServerClient = class {
|
|
|
102513
102671
|
this.handleProcessFailure("CODEX_INVALID_RESPONSE", new Error("Codex App Server emitted invalid JSON."));
|
|
102514
102672
|
return false;
|
|
102515
102673
|
}
|
|
102516
|
-
if (!
|
|
102674
|
+
if (!isRecord14(value)) {
|
|
102517
102675
|
this.handleProcessFailure("CODEX_INVALID_RESPONSE", new Error("Codex App Server emitted an invalid message."));
|
|
102518
102676
|
return false;
|
|
102519
102677
|
}
|
|
@@ -102604,7 +102762,7 @@ var CodexAppServerClient = class {
|
|
|
102604
102762
|
var CODEX_THREAD_UNMATERIALIZED = "CODEX_THREAD_UNMATERIALIZED";
|
|
102605
102763
|
var CODEX_UNMATERIALIZED_THREAD_MESSAGE = "Codex thread has no turns yet.";
|
|
102606
102764
|
function safeUpstreamError(value, method) {
|
|
102607
|
-
if (!
|
|
102765
|
+
if (!isRecord14(value) || typeof value.message !== "string") {
|
|
102608
102766
|
return attachSessionUpstreamFailure(
|
|
102609
102767
|
new CodexAppServerError("CODEX_UPSTREAM_ERROR", "Codex App Server rejected the request."),
|
|
102610
102768
|
value
|
|
@@ -102634,7 +102792,7 @@ function safeUpstreamError(value, method) {
|
|
|
102634
102792
|
value
|
|
102635
102793
|
);
|
|
102636
102794
|
}
|
|
102637
|
-
function
|
|
102795
|
+
function isRecord14(value) {
|
|
102638
102796
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
102639
102797
|
}
|
|
102640
102798
|
|
|
@@ -103602,18 +103760,18 @@ var CodexPeerBridge = class {
|
|
|
103602
103760
|
if (this.closed) throw new RpcError("CODEX_CONNECTION_CLOSED", "The Codex connection is closed.");
|
|
103603
103761
|
}
|
|
103604
103762
|
};
|
|
103605
|
-
function
|
|
103763
|
+
function isRecord15(value) {
|
|
103606
103764
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
103607
103765
|
}
|
|
103608
103766
|
function safeErrorCode2(error62) {
|
|
103609
|
-
if (
|
|
103767
|
+
if (isRecord15(error62) && typeof error62.code === "string") return error62.code;
|
|
103610
103768
|
return "UNKNOWN";
|
|
103611
103769
|
}
|
|
103612
103770
|
function isResponseTooLargeError(error62) {
|
|
103613
|
-
return
|
|
103771
|
+
return isRecord15(error62) && error62.code === "RESPONSE_TOO_LARGE";
|
|
103614
103772
|
}
|
|
103615
103773
|
function safeMethod(input4) {
|
|
103616
|
-
return
|
|
103774
|
+
return isRecord15(input4) && typeof input4.method === "string" ? input4.method : "invalid";
|
|
103617
103775
|
}
|
|
103618
103776
|
|
|
103619
103777
|
// packages/plugin/src/codex/thread-lifecycle.ts
|
|
@@ -103991,7 +104149,7 @@ var CodexRemoteDomain = class {
|
|
|
103991
104149
|
async readThreadGoal(threadId) {
|
|
103992
104150
|
try {
|
|
103993
104151
|
const result = await this.callUpstream("thread/goal/get", { threadId }, 5e3);
|
|
103994
|
-
if (!
|
|
104152
|
+
if (!isRecord16(result) || !("goal" in result)) {
|
|
103995
104153
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid Goal.");
|
|
103996
104154
|
}
|
|
103997
104155
|
return {
|
|
@@ -104046,7 +104204,7 @@ var CodexRemoteDomain = class {
|
|
|
104046
104204
|
assertCurrent();
|
|
104047
104205
|
const result = await this.callUpstream(call.method, call.params);
|
|
104048
104206
|
if (call.method === "project/update") return sanitizeProjectResponse(result);
|
|
104049
|
-
if (!
|
|
104207
|
+
if (!isRecord16(result)) throw new RpcError("CODEX_INVALID_RESPONSE", "Invalid Codex project mutation response.");
|
|
104050
104208
|
return {};
|
|
104051
104209
|
}
|
|
104052
104210
|
if (call.method === "project/create") {
|
|
@@ -104586,15 +104744,15 @@ var CodexRemoteDomain = class {
|
|
|
104586
104744
|
}
|
|
104587
104745
|
const threadId = extractThreadId(message.params);
|
|
104588
104746
|
if (threadId !== void 0 && (message.method === "thread/goal/updated" || message.method === "thread/goal/cleared")) {
|
|
104589
|
-
const active2 = message.method !== "thread/goal/cleared" && (!
|
|
104590
|
-
const goal =
|
|
104747
|
+
const active2 = message.method !== "thread/goal/cleared" && (!isRecord16(message.params) || goalRetainsThread(message.params.goal, threadId));
|
|
104748
|
+
const goal = isRecord16(message.params) ? message.params.goal : void 0;
|
|
104591
104749
|
const goalActive = message.method === "thread/goal/cleared" ? false : isActiveGoal(goal, threadId);
|
|
104592
104750
|
this.threadGoals.set(threadId, { active: active2, goalActive });
|
|
104593
104751
|
void this.threadLifecycle.retry(threadId);
|
|
104594
104752
|
await this.publishToThread(threadId, { method: "dsh/goalStatus", params: { threadId, goalActive } }, receivedAt);
|
|
104595
104753
|
return;
|
|
104596
104754
|
}
|
|
104597
|
-
if (message.method === "thread/name/updated" && threadId !== void 0 &&
|
|
104755
|
+
if (message.method === "thread/name/updated" && threadId !== void 0 && isRecord16(message.params)) {
|
|
104598
104756
|
const name2 = typeof message.params.name === "string" ? message.params.name : void 0;
|
|
104599
104757
|
if (name2 !== void 0 && name2.trim().length > 0) this.rememberThreadMeta(threadId, { name: name2 });
|
|
104600
104758
|
}
|
|
@@ -104616,7 +104774,7 @@ var CodexRemoteDomain = class {
|
|
|
104616
104774
|
this.turnOwners.delete(threadId);
|
|
104617
104775
|
this.clearTurnWatchdog(threadId);
|
|
104618
104776
|
this.threadLifecycle.active(threadId, false);
|
|
104619
|
-
const turn =
|
|
104777
|
+
const turn = isRecord16(sanitizedParams) && isRecord16(sanitizedParams.turn) ? sanitizedParams.turn : void 0;
|
|
104620
104778
|
const turnId = extractTurnId(sanitizedParams);
|
|
104621
104779
|
const turnStatus = typeof turn?.status === "string" ? turn.status : void 0;
|
|
104622
104780
|
if (turnStatus === "interrupted" || turnStatus === "cancelled" || turnStatus === "canceled" || turnStatus === "aborted") {
|
|
@@ -104625,7 +104783,7 @@ var CodexRemoteDomain = class {
|
|
|
104625
104783
|
} else {
|
|
104626
104784
|
const failed = turnStatus === "failed";
|
|
104627
104785
|
this.turnDiff?.onTurnEnded(`codex:${threadId}`, failed ? "failed" : "completed", turnId);
|
|
104628
|
-
const errorMessage2 = failed &&
|
|
104786
|
+
const errorMessage2 = failed && isRecord16(turn?.error) && typeof turn.error.message === "string" ? turn.error.message : void 0;
|
|
104629
104787
|
this.attention?.onSessionCompleted({
|
|
104630
104788
|
...this.attentionSessionInfo(threadId),
|
|
104631
104789
|
failed,
|
|
@@ -104640,7 +104798,7 @@ var CodexRemoteDomain = class {
|
|
|
104640
104798
|
this.declineApprovalsForThreadSync(threadId);
|
|
104641
104799
|
this.threadLifecycle.active(threadId, false);
|
|
104642
104800
|
if (wasActive) {
|
|
104643
|
-
const statusType =
|
|
104801
|
+
const statusType = isRecord16(message.params) && isRecord16(message.params.status) && typeof message.params.status.type === "string" ? message.params.status.type : void 0;
|
|
104644
104802
|
const failed = statusType === "systemError" || statusType === "failed";
|
|
104645
104803
|
this.turnDiff?.onTurnEnded(`codex:${threadId}`, failed ? "failed" : "stopped");
|
|
104646
104804
|
if (failed) {
|
|
@@ -104659,7 +104817,7 @@ var CodexRemoteDomain = class {
|
|
|
104659
104817
|
this.attention?.onSessionRunning(this.attentionSessionInfo(threadId));
|
|
104660
104818
|
this.turnDiff?.onTurnStarted(`codex:${threadId}`, turnId);
|
|
104661
104819
|
}
|
|
104662
|
-
if (message.method === "thread/status/changed" && threadId !== void 0 &&
|
|
104820
|
+
if (message.method === "thread/status/changed" && threadId !== void 0 && isRecord16(message.params) && isRecord16(message.params.status) && message.params.status.type === "active") {
|
|
104663
104821
|
this.threadLifecycle.active(threadId, true);
|
|
104664
104822
|
}
|
|
104665
104823
|
if (message.method === "serverRequest/resolved") {
|
|
@@ -104668,7 +104826,7 @@ var CodexRemoteDomain = class {
|
|
|
104668
104826
|
for (const entry of resolved) {
|
|
104669
104827
|
const targetThreadId = threadId ?? entry.threadId;
|
|
104670
104828
|
if (this.turnOwners.has(targetThreadId)) this.armTurnWatchdog(targetThreadId);
|
|
104671
|
-
const params =
|
|
104829
|
+
const params = isRecord16(message.params) ? { ...message.params, threadId: targetThreadId, requestHandle: entry.handle } : { threadId: targetThreadId, requestHandle: entry.handle };
|
|
104672
104830
|
await this.publishToThread(targetThreadId, {
|
|
104673
104831
|
method: message.method,
|
|
104674
104832
|
params
|
|
@@ -104843,7 +105001,7 @@ var CodexRemoteDomain = class {
|
|
|
104843
105001
|
this.pruneFrameBuffer(threadId);
|
|
104844
105002
|
const entry = this.recentFrames.get(threadId);
|
|
104845
105003
|
if (entry === void 0) return;
|
|
104846
|
-
const turns = Array.isArray(thread.turns) ? thread.turns.filter(
|
|
105004
|
+
const turns = Array.isArray(thread.turns) ? thread.turns.filter(isRecord16) : [];
|
|
104847
105005
|
if (turns.length === 0) return;
|
|
104848
105006
|
let activeTurn;
|
|
104849
105007
|
for (let index = turns.length - 1; index >= 0; index -= 1) {
|
|
@@ -104874,7 +105032,7 @@ var CodexRemoteDomain = class {
|
|
|
104874
105032
|
}
|
|
104875
105033
|
if (Array.isArray(turn.items)) {
|
|
104876
105034
|
for (const item of turn.items) {
|
|
104877
|
-
if (
|
|
105035
|
+
if (isRecord16(item) && typeof item.id === "string" && item.id.length > 0) {
|
|
104878
105036
|
persistedItemIds.add(item.id);
|
|
104879
105037
|
}
|
|
104880
105038
|
}
|
|
@@ -104950,7 +105108,7 @@ var CodexRemoteDomain = class {
|
|
|
104950
105108
|
if (codexPermissionPresetFromResponse(result) !== params.permissionPreset) {
|
|
104951
105109
|
await this.callUpstream("thread/settings/update", { threadId, ...settings });
|
|
104952
105110
|
assertCanMutate();
|
|
104953
|
-
result = { ...
|
|
105111
|
+
result = { ...isRecord16(result) ? result : {}, ...settings, sandbox: settings.sandboxPolicy };
|
|
104954
105112
|
}
|
|
104955
105113
|
}
|
|
104956
105114
|
await this.publishPermission(threadId, result);
|
|
@@ -104958,7 +105116,7 @@ var CodexRemoteDomain = class {
|
|
|
104958
105116
|
}
|
|
104959
105117
|
async publishPermission(threadId, value) {
|
|
104960
105118
|
if (!this.available) return;
|
|
104961
|
-
const source =
|
|
105119
|
+
const source = isRecord16(value) ? value : {};
|
|
104962
105120
|
const threadSettings = { approvalPolicy: source.approvalPolicy, sandboxPolicy: source.sandboxPolicy ?? source.sandbox };
|
|
104963
105121
|
const params = { threadId, threadSettings };
|
|
104964
105122
|
this.rememberPermission(threadId, params);
|
|
@@ -105093,7 +105251,7 @@ var CodexRemoteDomain = class {
|
|
|
105093
105251
|
if (legacyThread === void 0 || legacyThread.id !== threadId || !Array.isArray(legacyThread.turns)) {
|
|
105094
105252
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid Thread history.");
|
|
105095
105253
|
}
|
|
105096
|
-
if (legacyThread.turns.some((turn) => !
|
|
105254
|
+
if (legacyThread.turns.some((turn) => !isRecord16(turn) || typeof turn.id !== "string" || !Array.isArray(turn.items) || turn.items.some((item) => !isRecord16(item)))) {
|
|
105097
105255
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned invalid Thread history content.");
|
|
105098
105256
|
}
|
|
105099
105257
|
return legacyThread;
|
|
@@ -105127,17 +105285,17 @@ var CodexRemoteDomain = class {
|
|
|
105127
105285
|
}
|
|
105128
105286
|
throw error62;
|
|
105129
105287
|
}
|
|
105130
|
-
if (!
|
|
105288
|
+
if (!isRecord16(result) || !Array.isArray(result.data)) {
|
|
105131
105289
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid Turn page.");
|
|
105132
105290
|
}
|
|
105133
105291
|
const pageResult = result;
|
|
105134
105292
|
const pageTurns = await Promise.all(result.data.map(async (rawTurn) => {
|
|
105135
|
-
if (!
|
|
105293
|
+
if (!isRecord16(rawTurn) || typeof rawTurn.id !== "string" || rawTurn.id.length === 0 || rawTurn.itemsView === "full" && !Array.isArray(rawTurn.items)) {
|
|
105136
105294
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid history Turn.");
|
|
105137
105295
|
}
|
|
105138
105296
|
const inlineFull = rawTurn.itemsView === "full" || rawTurn.itemsView === void 0 && itemsView === "full" && Array.isArray(rawTurn.items);
|
|
105139
105297
|
const items = inlineFull ? rawTurn.items : await this.readThreadItems(threadId, rawTurn.id);
|
|
105140
|
-
if (items.some((item) => !
|
|
105298
|
+
if (items.some((item) => !isRecord16(item))) {
|
|
105141
105299
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid history Item.");
|
|
105142
105300
|
}
|
|
105143
105301
|
return { ...rawTurn, items };
|
|
@@ -105159,11 +105317,11 @@ var CodexRemoteDomain = class {
|
|
|
105159
105317
|
sortDirection: "asc",
|
|
105160
105318
|
...cursor3 === void 0 ? {} : { cursor: cursor3 }
|
|
105161
105319
|
});
|
|
105162
|
-
if (!
|
|
105320
|
+
if (!isRecord16(result) || !Array.isArray(result.data)) {
|
|
105163
105321
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid Item page.");
|
|
105164
105322
|
}
|
|
105165
105323
|
for (const entry of result.data) {
|
|
105166
|
-
if (!
|
|
105324
|
+
if (!isRecord16(entry) || !isRecord16(entry.item)) {
|
|
105167
105325
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid history Item.");
|
|
105168
105326
|
}
|
|
105169
105327
|
items.push(entry.item);
|
|
@@ -105259,11 +105417,11 @@ var CodexRemoteDomain = class {
|
|
|
105259
105417
|
});
|
|
105260
105418
|
}
|
|
105261
105419
|
findInboundThreadForResolved(params) {
|
|
105262
|
-
if (!
|
|
105420
|
+
if (!isRecord16(params) || typeof params.requestId !== "string" && typeof params.requestId !== "number") return void 0;
|
|
105263
105421
|
return this.pendingRequestThreads.get(params.requestId)?.threadId ?? this.findMatchingApprovals(params)[0]?.threadId;
|
|
105264
105422
|
}
|
|
105265
105423
|
findMatchingApprovals(params) {
|
|
105266
|
-
if (!
|
|
105424
|
+
if (!isRecord16(params) || typeof params.requestId !== "string" && typeof params.requestId !== "number") return [];
|
|
105267
105425
|
const matches = [];
|
|
105268
105426
|
for (const [handle, approval] of this.approvals) {
|
|
105269
105427
|
if (approval.upstreamId === params.requestId) {
|
|
@@ -105662,8 +105820,8 @@ function findImageBlock(value, attachmentId) {
|
|
|
105662
105820
|
}
|
|
105663
105821
|
return void 0;
|
|
105664
105822
|
}
|
|
105665
|
-
if (!
|
|
105666
|
-
if (value.type === "image" &&
|
|
105823
|
+
if (!isRecord16(value)) return void 0;
|
|
105824
|
+
if (value.type === "image" && isRecord16(value.attachment) && value.attachment.attachmentId === attachmentId && typeof value.data === "string") {
|
|
105667
105825
|
return { attachment: value.attachment, data: value.data };
|
|
105668
105826
|
}
|
|
105669
105827
|
for (const child of Object.values(value)) {
|
|
@@ -105688,7 +105846,7 @@ function macOSCodexBinaryCandidates(userHome) {
|
|
|
105688
105846
|
const codexCli = join8(chatGptApp, "Contents", "Resources", "codex-cli");
|
|
105689
105847
|
try {
|
|
105690
105848
|
const manifest = JSON.parse(readFileSync2(join8(codexCli, "codex-package.json"), "utf8"));
|
|
105691
|
-
if (!
|
|
105849
|
+
if (!isRecord16(manifest) || typeof manifest.entrypoint !== "string" || manifest.entrypoint.length === 0) {
|
|
105692
105850
|
return [];
|
|
105693
105851
|
}
|
|
105694
105852
|
const candidate = join8(codexCli, manifest.entrypoint);
|
|
@@ -105722,24 +105880,24 @@ function windowsBundledCodexCandidates(userHome) {
|
|
|
105722
105880
|
}
|
|
105723
105881
|
}
|
|
105724
105882
|
function parseCallEnvelope(input4) {
|
|
105725
|
-
if (!
|
|
105883
|
+
if (!isRecord16(input4) || typeof input4.method !== "string" || !("params" in input4) || Object.keys(input4).some((key) => key !== "method" && key !== "params")) {
|
|
105726
105884
|
throw new RpcError("INVALID_MESSAGE", "The Codex call envelope is invalid.");
|
|
105727
105885
|
}
|
|
105728
105886
|
return { method: input4.method, params: input4.params };
|
|
105729
105887
|
}
|
|
105730
105888
|
function parseRespond(input4) {
|
|
105731
|
-
if (!
|
|
105889
|
+
if (!isRecord16(input4) || typeof input4.requestHandle !== "string" || !["accept", "decline", "cancel"].includes(String(input4.decision)) || Object.keys(input4).some((key) => key !== "requestHandle" && key !== "decision")) {
|
|
105732
105890
|
throw new RpcError("INVALID_MESSAGE", "The Codex approval response is invalid.");
|
|
105733
105891
|
}
|
|
105734
105892
|
return input4;
|
|
105735
105893
|
}
|
|
105736
105894
|
function accountCanRun(result) {
|
|
105737
|
-
if (!
|
|
105738
|
-
return result.requiresOpenaiAuth === false ||
|
|
105895
|
+
if (!isRecord16(result) || typeof result.requiresOpenaiAuth !== "boolean") return false;
|
|
105896
|
+
return result.requiresOpenaiAuth === false || isRecord16(result.account);
|
|
105739
105897
|
}
|
|
105740
105898
|
function sanitizeAccount(result) {
|
|
105741
|
-
if (!
|
|
105742
|
-
const account =
|
|
105899
|
+
if (!isRecord16(result)) throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned invalid account state.");
|
|
105900
|
+
const account = isRecord16(result.account) ? result.account : void 0;
|
|
105743
105901
|
return {
|
|
105744
105902
|
authenticated: account !== void 0 || result.requiresOpenaiAuth === false,
|
|
105745
105903
|
requiresOpenaiAuth: result.requiresOpenaiAuth === true,
|
|
@@ -105752,11 +105910,11 @@ function sanitizeAccount(result) {
|
|
|
105752
105910
|
};
|
|
105753
105911
|
}
|
|
105754
105912
|
function sanitizeThreadList(result) {
|
|
105755
|
-
if (!
|
|
105913
|
+
if (!isRecord16(result) || !Array.isArray(result.data)) {
|
|
105756
105914
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid thread list.");
|
|
105757
105915
|
}
|
|
105758
105916
|
const data2 = result.data.flatMap((value) => {
|
|
105759
|
-
if (!
|
|
105917
|
+
if (!isRecord16(value) || typeof value.id !== "string") return [];
|
|
105760
105918
|
return [{
|
|
105761
105919
|
id: value.id,
|
|
105762
105920
|
...typeof value.sessionId === "string" ? { sessionId: value.sessionId } : {},
|
|
@@ -105768,7 +105926,7 @@ function sanitizeThreadList(result) {
|
|
|
105768
105926
|
...typeof value.updatedAt === "number" && Number.isFinite(value.updatedAt) ? { updatedAt: value.updatedAt } : {},
|
|
105769
105927
|
...typeof value.archived === "boolean" ? { archived: value.archived } : {},
|
|
105770
105928
|
...typeof value.isPinned === "boolean" ? { isPinned: value.isPinned } : {},
|
|
105771
|
-
...
|
|
105929
|
+
...isRecord16(value.status) ? { status: value.status } : {}
|
|
105772
105930
|
}];
|
|
105773
105931
|
});
|
|
105774
105932
|
return {
|
|
@@ -105778,18 +105936,18 @@ function sanitizeThreadList(result) {
|
|
|
105778
105936
|
};
|
|
105779
105937
|
}
|
|
105780
105938
|
function filterThreadListByWorkspaceAuthority(result, authority) {
|
|
105781
|
-
if (!
|
|
105939
|
+
if (!isRecord16(result) || !Array.isArray(result.data)) {
|
|
105782
105940
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid thread list.");
|
|
105783
105941
|
}
|
|
105784
105942
|
return {
|
|
105785
105943
|
...result,
|
|
105786
|
-
data: result.data.map((record14) =>
|
|
105944
|
+
data: result.data.map((record14) => isRecord16(record14) ? record14 : void 0).filter((thread) => thread !== void 0 && isThreadAllowedByWorkspaceAuthority(thread, authority))
|
|
105787
105945
|
};
|
|
105788
105946
|
}
|
|
105789
105947
|
function sanitizeProject(value) {
|
|
105790
|
-
if (!
|
|
105948
|
+
if (!isRecord16(value) || typeof value.id !== "string" || typeof value.name !== "string") return void 0;
|
|
105791
105949
|
const roots = Array.isArray(value.roots) ? value.roots.flatMap((root2) => {
|
|
105792
|
-
const path =
|
|
105950
|
+
const path = isRecord16(root2) && typeof root2.path === "string" && root2.path.length > 0 ? root2.path : void 0;
|
|
105793
105951
|
return path === void 0 || !isAbsolute4(path) ? [] : [{ path }];
|
|
105794
105952
|
}) : [];
|
|
105795
105953
|
if (roots.length === 0) return void 0;
|
|
@@ -105803,7 +105961,7 @@ function sanitizeProject(value) {
|
|
|
105803
105961
|
};
|
|
105804
105962
|
}
|
|
105805
105963
|
function sanitizeProjectList(result) {
|
|
105806
|
-
if (!
|
|
105964
|
+
if (!isRecord16(result) || !Array.isArray(result.data)) {
|
|
105807
105965
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid project list.");
|
|
105808
105966
|
}
|
|
105809
105967
|
const data2 = result.data.flatMap((value) => sanitizeProject(value) ?? []);
|
|
@@ -105813,7 +105971,7 @@ function sanitizeProjectList(result) {
|
|
|
105813
105971
|
};
|
|
105814
105972
|
}
|
|
105815
105973
|
function sanitizeProjectResponse(result) {
|
|
105816
|
-
const project2 =
|
|
105974
|
+
const project2 = isRecord16(result) ? sanitizeProject(result.project) : void 0;
|
|
105817
105975
|
if (project2 === void 0) {
|
|
105818
105976
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid project.");
|
|
105819
105977
|
}
|
|
@@ -105845,30 +106003,30 @@ function codexDirectoryCrumbs(root2, path) {
|
|
|
105845
106003
|
return crumbs2;
|
|
105846
106004
|
}
|
|
105847
106005
|
function extractThread(result) {
|
|
105848
|
-
return
|
|
106006
|
+
return isRecord16(result) && isRecord16(result.thread) ? result.thread : void 0;
|
|
105849
106007
|
}
|
|
105850
106008
|
function extractTurnId(result) {
|
|
105851
|
-
if (!
|
|
106009
|
+
if (!isRecord16(result)) return void 0;
|
|
105852
106010
|
if (typeof result.turnId === "string" && result.turnId.length > 0) return result.turnId;
|
|
105853
|
-
if (
|
|
106011
|
+
if (isRecord16(result.turn) && typeof result.turn.id === "string" && result.turn.id.length > 0) return result.turn.id;
|
|
105854
106012
|
return void 0;
|
|
105855
106013
|
}
|
|
105856
106014
|
function extractThreadId(params) {
|
|
105857
|
-
if (!
|
|
106015
|
+
if (!isRecord16(params)) return void 0;
|
|
105858
106016
|
if (typeof params.threadId === "string") return params.threadId;
|
|
105859
|
-
if (
|
|
105860
|
-
if (
|
|
106017
|
+
if (isRecord16(params.thread) && typeof params.thread.id === "string") return params.thread.id;
|
|
106018
|
+
if (isRecord16(params.turn) && typeof params.turn.threadId === "string") return params.turn.threadId;
|
|
105861
106019
|
return void 0;
|
|
105862
106020
|
}
|
|
105863
106021
|
function isActiveGoal(goal, threadId) {
|
|
105864
|
-
return
|
|
106022
|
+
return isRecord16(goal) && goal.threadId === threadId && goal.status === "active";
|
|
105865
106023
|
}
|
|
105866
106024
|
function goalRetainsThread(goal, threadId) {
|
|
105867
|
-
if (!
|
|
106025
|
+
if (!isRecord16(goal) || goal.threadId !== threadId || typeof goal.status !== "string") return true;
|
|
105868
106026
|
return !["complete", "paused", "blocked", "usageLimited", "budgetLimited"].includes(goal.status);
|
|
105869
106027
|
}
|
|
105870
106028
|
function isTerminalThreadStatus(params) {
|
|
105871
|
-
if (!
|
|
106029
|
+
if (!isRecord16(params) || !isRecord16(params.status) || typeof params.status.type !== "string") return false;
|
|
105872
106030
|
return params.status.type !== "active";
|
|
105873
106031
|
}
|
|
105874
106032
|
function optionalInteger3(value) {
|
|
@@ -105910,13 +106068,13 @@ function mapCodexImageInputs(params) {
|
|
|
105910
106068
|
return {
|
|
105911
106069
|
...params,
|
|
105912
106070
|
input: params.input.map((value) => {
|
|
105913
|
-
if (!
|
|
106071
|
+
if (!isRecord16(value) || value.type !== "image" || typeof value.mediaType !== "string" || typeof value.data !== "string") return value;
|
|
105914
106072
|
return { type: "image", url: `data:${value.mediaType};base64,${value.data}` };
|
|
105915
106073
|
})
|
|
105916
106074
|
};
|
|
105917
106075
|
}
|
|
105918
106076
|
function sanitizeApprovalParams(params, requestHandle) {
|
|
105919
|
-
if (!
|
|
106077
|
+
if (!isRecord16(params)) return { requestHandle };
|
|
105920
106078
|
const safe = { ...params };
|
|
105921
106079
|
delete safe.proposedExecpolicyAmendment;
|
|
105922
106080
|
delete safe.additionalPermissions;
|
|
@@ -105925,7 +106083,7 @@ function sanitizeApprovalParams(params, requestHandle) {
|
|
|
105925
106083
|
return safe;
|
|
105926
106084
|
}
|
|
105927
106085
|
function codexApprovalSummary(method, params) {
|
|
105928
|
-
if (
|
|
106086
|
+
if (isRecord16(params)) {
|
|
105929
106087
|
if (typeof params.command === "string" && params.command.trim().length > 0) return params.command.trim();
|
|
105930
106088
|
if (typeof params.reason === "string" && params.reason.trim().length > 0) return params.reason.trim();
|
|
105931
106089
|
if (typeof params.path === "string" && params.path.trim().length > 0) return params.path.trim();
|
|
@@ -105947,7 +106105,7 @@ function mapAppServerError(error62) {
|
|
|
105947
106105
|
return new RpcError("CODEX_UPSTREAM_ERROR", "Codex App Server could not complete the request.");
|
|
105948
106106
|
}
|
|
105949
106107
|
function sanitizeCodexThreadReadResult(result) {
|
|
105950
|
-
if (!
|
|
106108
|
+
if (!isRecord16(result) || !isRecord16(result.thread) || !Array.isArray(result.thread.turns)) {
|
|
105951
106109
|
return result;
|
|
105952
106110
|
}
|
|
105953
106111
|
return {
|
|
@@ -105959,14 +106117,14 @@ function sanitizeCodexThreadReadResult(result) {
|
|
|
105959
106117
|
};
|
|
105960
106118
|
}
|
|
105961
106119
|
function sanitizeCodexInboundParams(method, params) {
|
|
105962
|
-
if (!
|
|
105963
|
-
if (method === "turn/completed" &&
|
|
106120
|
+
if (!isRecord16(params)) return params;
|
|
106121
|
+
if (method === "turn/completed" && isRecord16(params.turn)) {
|
|
105964
106122
|
return {
|
|
105965
106123
|
...params,
|
|
105966
106124
|
turn: sanitizeCodexTurn(params.turn)
|
|
105967
106125
|
};
|
|
105968
106126
|
}
|
|
105969
|
-
if ((method === "item/completed" || method === "item/started") &&
|
|
106127
|
+
if ((method === "item/completed" || method === "item/started") && isRecord16(params.item) && params.item.type === "error") {
|
|
105970
106128
|
return {
|
|
105971
106129
|
...params,
|
|
105972
106130
|
item: sanitizeCodexErrorItem(params.item)
|
|
@@ -105975,10 +106133,10 @@ function sanitizeCodexInboundParams(method, params) {
|
|
|
105975
106133
|
return params;
|
|
105976
106134
|
}
|
|
105977
106135
|
function sanitizeCodexTurn(rawTurn) {
|
|
105978
|
-
if (!
|
|
106136
|
+
if (!isRecord16(rawTurn)) return rawTurn;
|
|
105979
106137
|
const hasError = rawTurn.error !== void 0 && rawTurn.error !== null;
|
|
105980
106138
|
const sanitizedError = hasError ? sanitizeCodexTurnError(rawTurn.error) : void 0;
|
|
105981
|
-
const items = Array.isArray(rawTurn.items) ? rawTurn.items.map((item) =>
|
|
106139
|
+
const items = Array.isArray(rawTurn.items) ? rawTurn.items.map((item) => isRecord16(item) && item.type === "error" ? sanitizeCodexErrorItem(item) : item) : void 0;
|
|
105982
106140
|
if (!hasError && items === void 0) return rawTurn;
|
|
105983
106141
|
return {
|
|
105984
106142
|
...rawTurn,
|
|
@@ -106030,7 +106188,7 @@ function sanitizeCodexErrorItem(item) {
|
|
|
106030
106188
|
if (typeof part === "string") {
|
|
106031
106189
|
return [sanitizeCodexErrorDisplayText(part)];
|
|
106032
106190
|
}
|
|
106033
|
-
if (!
|
|
106191
|
+
if (!isRecord16(part)) return [];
|
|
106034
106192
|
const sanitizedPart = {};
|
|
106035
106193
|
if (typeof part.type === "string") sanitizedPart.type = part.type;
|
|
106036
106194
|
for (const partKey of ["text", "content", "message"]) {
|
|
@@ -106098,7 +106256,7 @@ function isProjectListFallbackError(error62) {
|
|
|
106098
106256
|
function canTryNextBinary(error62) {
|
|
106099
106257
|
return !(error62 instanceof RpcError) || !["CODEX_AUTH_REQUIRED", "CODEX_CLOSED"].includes(error62.code);
|
|
106100
106258
|
}
|
|
106101
|
-
function
|
|
106259
|
+
function isRecord16(value) {
|
|
106102
106260
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
106103
106261
|
}
|
|
106104
106262
|
function maskId(value) {
|
|
@@ -106111,22 +106269,22 @@ function isUnpersistedThreadError(error62) {
|
|
|
106111
106269
|
return error62 instanceof RpcError && error62.code === "CODEX_UPSTREAM_ERROR" && error62.message.toLowerCase().includes("not persisted yet");
|
|
106112
106270
|
}
|
|
106113
106271
|
function extractFrameTurnId(params) {
|
|
106114
|
-
if (!
|
|
106272
|
+
if (!isRecord16(params)) return void 0;
|
|
106115
106273
|
if (typeof params.turnId === "string" && params.turnId.length > 0) return params.turnId;
|
|
106116
|
-
if (
|
|
106274
|
+
if (isRecord16(params.turn) && typeof params.turn.id === "string" && params.turn.id.length > 0) return params.turn.id;
|
|
106117
106275
|
return void 0;
|
|
106118
106276
|
}
|
|
106119
106277
|
function extractFrameItemId(params) {
|
|
106120
|
-
if (!
|
|
106278
|
+
if (!isRecord16(params)) return void 0;
|
|
106121
106279
|
if (typeof params.itemId === "string" && params.itemId.length > 0) return params.itemId;
|
|
106122
|
-
if (
|
|
106280
|
+
if (isRecord16(params.item) && typeof params.item.id === "string" && params.item.id.length > 0) return params.item.id;
|
|
106123
106281
|
return void 0;
|
|
106124
106282
|
}
|
|
106125
106283
|
function isOversizedCodexFrame(frame) {
|
|
106126
106284
|
return encodeMessage(createEvent("codex.app.frame", { streamId: MAX_STREAM_ID_PROBE, frame })).byteLength > MAX_SECURE_MESSAGE_BYTES;
|
|
106127
106285
|
}
|
|
106128
106286
|
function isResponseTooLargeError2(error62) {
|
|
106129
|
-
return
|
|
106287
|
+
return isRecord16(error62) && error62.code === "RESPONSE_TOO_LARGE";
|
|
106130
106288
|
}
|
|
106131
106289
|
function isUnmaterializedThreadError(error62) {
|
|
106132
106290
|
return error62 instanceof RpcError && error62.code === CODEX_THREAD_UNMATERIALIZED;
|
|
@@ -106152,17 +106310,17 @@ var DEFAULT_LOGIN_COMMANDS = {
|
|
|
106152
106310
|
kimi: "kimi login"
|
|
106153
106311
|
};
|
|
106154
106312
|
function parseInitializeMetadata(result) {
|
|
106155
|
-
if (!
|
|
106313
|
+
if (!isRecord17(result)) {
|
|
106156
106314
|
return { agentCapabilities: {}, authMethods: [] };
|
|
106157
106315
|
}
|
|
106158
|
-
const caps =
|
|
106159
|
-
const promptCaps =
|
|
106160
|
-
const sessionCaps =
|
|
106161
|
-
const rawMeta =
|
|
106162
|
-
const steering =
|
|
106163
|
-
const rawInfo =
|
|
106316
|
+
const caps = isRecord17(result.agentCapabilities) ? result.agentCapabilities : {};
|
|
106317
|
+
const promptCaps = isRecord17(caps.promptCapabilities) ? caps.promptCapabilities : void 0;
|
|
106318
|
+
const sessionCaps = isRecord17(caps.sessionCapabilities) ? caps.sessionCapabilities : isRecord17(caps.session_capabilities) ? caps.session_capabilities : void 0;
|
|
106319
|
+
const rawMeta = isRecord17(result._meta) ? result._meta : isRecord17(caps._meta) ? caps._meta : void 0;
|
|
106320
|
+
const steering = isRecord17(rawMeta?.steering) && rawMeta.steering.supported === true;
|
|
106321
|
+
const rawInfo = isRecord17(result.agentInfo) ? result.agentInfo : void 0;
|
|
106164
106322
|
const authMethods = Array.isArray(result.authMethods) ? result.authMethods.flatMap((item) => {
|
|
106165
|
-
if (!
|
|
106323
|
+
if (!isRecord17(item) || typeof item.id !== "string" || typeof item.name !== "string") return [];
|
|
106166
106324
|
return [{
|
|
106167
106325
|
id: item.id,
|
|
106168
106326
|
name: item.name,
|
|
@@ -106189,12 +106347,12 @@ function parseInitializeMetadata(result) {
|
|
|
106189
106347
|
} : {},
|
|
106190
106348
|
...sessionCaps ? {
|
|
106191
106349
|
sessionCapabilities: {
|
|
106192
|
-
...
|
|
106193
|
-
...
|
|
106194
|
-
...
|
|
106195
|
-
...
|
|
106196
|
-
...
|
|
106197
|
-
...
|
|
106350
|
+
...isRecord17(sessionCaps.list) || sessionCaps.list === true ? { list: true } : {},
|
|
106351
|
+
...isRecord17(sessionCaps.fork) || sessionCaps.fork === true ? { fork: true } : {},
|
|
106352
|
+
...isRecord17(sessionCaps.delete) || sessionCaps.delete === true ? { delete: true } : {},
|
|
106353
|
+
...isRecord17(sessionCaps.resume) || sessionCaps.resume === true ? { resume: true } : {},
|
|
106354
|
+
...isRecord17(sessionCaps.close) || sessionCaps.close === true ? { close: true } : {},
|
|
106355
|
+
...isRecord17(sessionCaps.additionalDirectories) || sessionCaps.additionalDirectories === true ? { additionalDirectories: true } : {}
|
|
106198
106356
|
}
|
|
106199
106357
|
} : {},
|
|
106200
106358
|
...steering ? { steering: true } : {}
|
|
@@ -106203,10 +106361,10 @@ function parseInitializeMetadata(result) {
|
|
|
106203
106361
|
};
|
|
106204
106362
|
}
|
|
106205
106363
|
function detectUpstreamAuthFailure(backend, errorValue, authMethods = []) {
|
|
106206
|
-
if (!
|
|
106364
|
+
if (!isRecord17(errorValue)) return void 0;
|
|
106207
106365
|
const rpcCode = typeof errorValue.code === "number" ? errorValue.code : void 0;
|
|
106208
106366
|
const messageText = typeof errorValue.message === "string" ? errorValue.message : "";
|
|
106209
|
-
const dataMessage =
|
|
106367
|
+
const dataMessage = isRecord17(errorValue.data) && typeof errorValue.data.message === "string" ? errorValue.data.message : "";
|
|
106210
106368
|
const combined = `${messageText} ${dataMessage}`.trim();
|
|
106211
106369
|
const lower = combined.toLowerCase();
|
|
106212
106370
|
const browserOpenFailed = (rpcCode === -32602 || lower.includes("browser")) && lower.includes("open browser");
|
|
@@ -106254,10 +106412,10 @@ function buildAuthDiagnosticFromMetadata(backend, metadata, lastDiagnostic, read
|
|
|
106254
106412
|
};
|
|
106255
106413
|
}
|
|
106256
106414
|
function parseAvailableCommands(update) {
|
|
106257
|
-
if (!
|
|
106415
|
+
if (!isRecord17(update) || !Array.isArray(update.availableCommands)) return [];
|
|
106258
106416
|
return update.availableCommands.flatMap((item) => {
|
|
106259
|
-
if (!
|
|
106260
|
-
const input4 =
|
|
106417
|
+
if (!isRecord17(item) || typeof item.name !== "string" || item.name.trim().length === 0) return [];
|
|
106418
|
+
const input4 = isRecord17(item.input) && typeof item.input.hint === "string" ? { hint: item.input.hint } : void 0;
|
|
106261
106419
|
return [{
|
|
106262
106420
|
name: item.name.trim(),
|
|
106263
106421
|
...typeof item.description === "string" ? { description: item.description } : {},
|
|
@@ -106278,7 +106436,7 @@ function extractSafeHttpsUrl(text) {
|
|
|
106278
106436
|
function redactPaths(text) {
|
|
106279
106437
|
return text.replace(/(["'])[A-Za-z]:\\(?:Users|Documents and Settings)\\[^\\\r\n"']+?(?:\\[^\\\r\n"']+)*\1/gi, (quote) => `${quote[0]}<host-path>${quote[0]}`).replace(/[A-Za-z]:\\(?:Users|Documents and Settings)\\[^\\\r\n:*?"<>|]+(?:\\[^\s\\/:*?"<>|'`]+)+/gi, "<host-path>").replace(/[A-Za-z]:\\(?:Users|Documents and Settings)\\[^\s\\/:*?"<>|'`]+/gi, "<host-path>").replace(/(["'])\/(?:Users|home)\/[^/\r\n"']+?(?:\/[^/\r\n"']+)*\1/g, (quote) => `${quote[0]}<host-path>${quote[0]}`).replace(/\/(?:Users|home)\/[^/\r\n:*?"<>|]+(?:\/[^\s/:*?"<>|'`]+)+/g, "<host-path>").replace(/\/(?:Users|home)\/[^\s/:*?"<>|'`]+/g, "<host-path>");
|
|
106280
106438
|
}
|
|
106281
|
-
function
|
|
106439
|
+
function isRecord17(value) {
|
|
106282
106440
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
106283
106441
|
}
|
|
106284
106442
|
|
|
@@ -106525,7 +106683,7 @@ var AcpStdioJsonRpcChannel = class {
|
|
|
106525
106683
|
);
|
|
106526
106684
|
return;
|
|
106527
106685
|
}
|
|
106528
|
-
if (!
|
|
106686
|
+
if (!isRecord18(value)) {
|
|
106529
106687
|
this.options.onProtocolFailure(
|
|
106530
106688
|
this.options.errorCode("INVALID_RESPONSE"),
|
|
106531
106689
|
new Error(`${this.options.getLabel()} ACP emitted an invalid message.`)
|
|
@@ -106564,7 +106722,7 @@ var AcpStdioJsonRpcChannel = class {
|
|
|
106564
106722
|
}
|
|
106565
106723
|
};
|
|
106566
106724
|
function safeUpstreamError2(value, label) {
|
|
106567
|
-
if (!
|
|
106725
|
+
if (!isRecord18(value) || typeof value.message !== "string") return `${label} ACP rejected the request.`;
|
|
106568
106726
|
const message = value.message.toLowerCase();
|
|
106569
106727
|
if (message.includes("auth") || message.includes("login") || message.includes("api key")) {
|
|
106570
106728
|
return `${label} ACP authentication failed.`;
|
|
@@ -106572,7 +106730,7 @@ function safeUpstreamError2(value, label) {
|
|
|
106572
106730
|
if (message.includes("not initialized")) return `${label} ACP is not initialized.`;
|
|
106573
106731
|
return `${label} ACP rejected the request.`;
|
|
106574
106732
|
}
|
|
106575
|
-
function
|
|
106733
|
+
function isRecord18(value) {
|
|
106576
106734
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
106577
106735
|
}
|
|
106578
106736
|
|
|
@@ -106685,7 +106843,7 @@ var CursorAcpClient = class {
|
|
|
106685
106843
|
async call(method, params, timeoutMs) {
|
|
106686
106844
|
if (!this.ready) throw new CursorAcpError(this.code("UNAVAILABLE"), `${this.adapterLabel} ACP is not ready.`);
|
|
106687
106845
|
const backend = this.options.modelBackend ?? this.backend;
|
|
106688
|
-
const id7 =
|
|
106846
|
+
const id7 = isRecord19(params) && typeof params.sessionId === "string" ? params.sessionId : void 0;
|
|
106689
106847
|
if (method === "dsh/sessionCommands") {
|
|
106690
106848
|
return { commands: id7 ? [...this.sessionCommands.get(id7) ?? []] : [] };
|
|
106691
106849
|
}
|
|
@@ -106718,7 +106876,7 @@ var CursorAcpClient = class {
|
|
|
106718
106876
|
if (!state2 || !id7) throw new CursorAcpError("ACP_SESSION_NOT_LOADED", "Load the ACP session before changing its mode.");
|
|
106719
106877
|
if (method === "dsh/sessionModes") return state2.modesCatalog();
|
|
106720
106878
|
if (this.modelBusy.has(id7)) throw new CursorAcpError("PROMPT_IN_PROGRESS", "Stop the reply before changing its mode.");
|
|
106721
|
-
const modeId =
|
|
106879
|
+
const modeId = isRecord19(params) ? params.modeId : void 0;
|
|
106722
106880
|
this.modelBusy.add(id7);
|
|
106723
106881
|
try {
|
|
106724
106882
|
const result2 = await state2.setMode(
|
|
@@ -106762,7 +106920,7 @@ var CursorAcpClient = class {
|
|
|
106762
106920
|
throw error62;
|
|
106763
106921
|
}
|
|
106764
106922
|
if (backend && (method === "session/new" || method === "session/load" || method === "session/fork")) {
|
|
106765
|
-
const returnedId =
|
|
106923
|
+
const returnedId = isRecord19(result) && typeof result.sessionId === "string" ? result.sessionId : void 0;
|
|
106766
106924
|
const sessionId = method === "session/load" ? id7 : returnedId;
|
|
106767
106925
|
if (!this.ready || !sessionId || returnedId && returnedId !== sessionId) {
|
|
106768
106926
|
if (provisionalLoad && id7) this.modelStates.delete(id7);
|
|
@@ -106898,9 +107056,9 @@ var CursorAcpClient = class {
|
|
|
106898
107056
|
}
|
|
106899
107057
|
handleInbound(inbound) {
|
|
106900
107058
|
const params = inbound.params;
|
|
106901
|
-
if (inbound.kind === "notification" && inbound.method === "session/update" &&
|
|
107059
|
+
if (inbound.kind === "notification" && inbound.method === "session/update" && isRecord19(params) && typeof params.sessionId === "string") {
|
|
106902
107060
|
this.modelStates.get(params.sessionId)?.update(params.update);
|
|
106903
|
-
if (
|
|
107061
|
+
if (isRecord19(params.update) && params.update.sessionUpdate === "available_commands_update") {
|
|
106904
107062
|
this.sessionCommands.delete(params.sessionId);
|
|
106905
107063
|
this.sessionCommands.set(params.sessionId, parseAvailableCommands(params.update));
|
|
106906
107064
|
if (this.sessionCommands.size > MAX_SESSION_COMMANDS) {
|
|
@@ -106928,7 +107086,7 @@ var CursorAcpClient = class {
|
|
|
106928
107086
|
for (const handler of this.unavailableHandlers) handler(code);
|
|
106929
107087
|
}
|
|
106930
107088
|
};
|
|
106931
|
-
function
|
|
107089
|
+
function isRecord19(value) {
|
|
106932
107090
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
106933
107091
|
}
|
|
106934
107092
|
|
|
@@ -108407,8 +108565,8 @@ function isPathOutside2(rel) {
|
|
|
108407
108565
|
return rel.startsWith("../");
|
|
108408
108566
|
}
|
|
108409
108567
|
function argsOf(payload) {
|
|
108410
|
-
const value =
|
|
108411
|
-
return
|
|
108568
|
+
const value = isRecord20(payload) ? payload : {};
|
|
108569
|
+
return isRecord20(value.args) ? value.args : value;
|
|
108412
108570
|
}
|
|
108413
108571
|
function toolScope(endpoint, args) {
|
|
108414
108572
|
const session2 = args.agentId ?? args.sessionId;
|
|
@@ -108418,13 +108576,13 @@ function toolScope(endpoint, args) {
|
|
|
108418
108576
|
}
|
|
108419
108577
|
return session2;
|
|
108420
108578
|
}
|
|
108421
|
-
function
|
|
108579
|
+
function isRecord20(value) {
|
|
108422
108580
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
108423
108581
|
}
|
|
108424
108582
|
function byteOrLineRange(args) {
|
|
108425
|
-
const options =
|
|
108426
|
-
if (options !== void 0 &&
|
|
108427
|
-
return
|
|
108583
|
+
const options = isRecord20(args.options) ? args.options : void 0;
|
|
108584
|
+
if (options !== void 0 && isRecord20(options.range)) return options.range;
|
|
108585
|
+
return isRecord20(args.range) ? args.range : args;
|
|
108428
108586
|
}
|
|
108429
108587
|
function readOffset(args) {
|
|
108430
108588
|
const range = byteOrLineRange(args);
|
|
@@ -108599,7 +108757,7 @@ var ClaudeAcpClient = class extends CursorAcpClient {
|
|
|
108599
108757
|
this.discardPrewarmedHistory();
|
|
108600
108758
|
});
|
|
108601
108759
|
super.onInbound((message) => {
|
|
108602
|
-
const id7 =
|
|
108760
|
+
const id7 = isRecord21(message.params) && typeof message.params.sessionId === "string" ? message.params.sessionId : void 0;
|
|
108603
108761
|
if (id7 && (this.loadSuppressions.has(id7) || this.closingSessions.has(id7))) {
|
|
108604
108762
|
if (message.kind === "request") {
|
|
108605
108763
|
void (message.method === "session/request_permission" ? this.respond(message.id, { outcome: { outcome: "cancelled" } }) : this.respondError(message.id, -32600, `${this.label} session is not loaded.`)).catch(() => void 0);
|
|
@@ -108901,9 +109059,9 @@ var ClaudeAcpClient = class extends CursorAcpClient {
|
|
|
108901
109059
|
callMetadata("dsh/sessionCommands", { sessionId }).catch(() => void 0)
|
|
108902
109060
|
]);
|
|
108903
109061
|
signal?.throwIfAborted();
|
|
108904
|
-
const models =
|
|
108905
|
-
const modes =
|
|
108906
|
-
const commands =
|
|
109062
|
+
const models = isRecord21(modelsRaw) ? modelsRaw : void 0;
|
|
109063
|
+
const modes = isRecord21(modesRaw) && Array.isArray(modesRaw.availableModes) ? modesRaw : void 0;
|
|
109064
|
+
const commands = isRecord21(commandsRaw) && Array.isArray(commandsRaw.commands) && commandsRaw.commands.length > 0 ? commandsRaw.commands : void 0;
|
|
108907
109065
|
this.rememberHistoryMetadata(sessionId, { models, modes, commands });
|
|
108908
109066
|
}
|
|
108909
109067
|
rememberHistoryMetadata(id7, metadata) {
|
|
@@ -109072,7 +109230,7 @@ var ClaudeAcpClient = class extends CursorAcpClient {
|
|
|
109072
109230
|
this.live.clear();
|
|
109073
109231
|
}
|
|
109074
109232
|
};
|
|
109075
|
-
function
|
|
109233
|
+
function isRecord21(value) {
|
|
109076
109234
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109077
109235
|
}
|
|
109078
109236
|
|
|
@@ -109114,7 +109272,7 @@ var KimiAcpClient = class extends ClaudeAcpClient {
|
|
|
109114
109272
|
});
|
|
109115
109273
|
}
|
|
109116
109274
|
async call(method, params, timeoutMs) {
|
|
109117
|
-
const id7 =
|
|
109275
|
+
const id7 = isRecord22(params) && typeof params.sessionId === "string" ? params.sessionId : void 0;
|
|
109118
109276
|
if (method === "session/prompt" && id7 !== void 0) {
|
|
109119
109277
|
while (this.liveHistoryPromises.has(id7) || this.unloadedHistoryPromises.has(id7)) {
|
|
109120
109278
|
await (this.liveHistoryPromises.get(id7) ?? this.unloadedHistoryPromises.get(id7))?.catch(() => void 0);
|
|
@@ -109227,13 +109385,13 @@ var KimiAcpClient = class extends ClaudeAcpClient {
|
|
|
109227
109385
|
createHistoryFilter() {
|
|
109228
109386
|
let hasUserChunkInTurn = false;
|
|
109229
109387
|
return (message) => {
|
|
109230
|
-
if (message.kind !== "notification" || message.method !== "session/update" || !
|
|
109388
|
+
if (message.kind !== "notification" || message.method !== "session/update" || !isRecord22(message.params)) {
|
|
109231
109389
|
return true;
|
|
109232
109390
|
}
|
|
109233
|
-
const update =
|
|
109391
|
+
const update = isRecord22(message.params.update) ? message.params.update : void 0;
|
|
109234
109392
|
const kind = typeof update?.sessionUpdate === "string" ? update.sessionUpdate : void 0;
|
|
109235
109393
|
if (kind === "user_message_chunk") {
|
|
109236
|
-
const content =
|
|
109394
|
+
const content = isRecord22(update?.content) ? update.content : void 0;
|
|
109237
109395
|
const isText = content?.type === "text" && typeof content.text === "string";
|
|
109238
109396
|
const hasNonEmptyText = isText && content.text.trim().length > 0;
|
|
109239
109397
|
const isImage = content?.type === "image" && typeof content.mimeType === "string" && typeof content.data === "string";
|
|
@@ -109276,7 +109434,7 @@ function abortReasonError(signal) {
|
|
|
109276
109434
|
}
|
|
109277
109435
|
return new Error("Aborted");
|
|
109278
109436
|
}
|
|
109279
|
-
function
|
|
109437
|
+
function isRecord22(value) {
|
|
109280
109438
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109281
109439
|
}
|
|
109282
109440
|
|
|
@@ -110821,7 +110979,7 @@ var OpencodeAcpClient = class _OpencodeAcpClient {
|
|
|
110821
110979
|
busy = /* @__PURE__ */ new Set();
|
|
110822
110980
|
async call(method, params, timeoutMs) {
|
|
110823
110981
|
if (!this.ready) throw new OpencodeAcpError("OPENCODE_UNAVAILABLE", "OpenCode ACP is not ready.");
|
|
110824
|
-
const p =
|
|
110982
|
+
const p = isRecord23(params) ? params : {};
|
|
110825
110983
|
const id7 = typeof p.sessionId === "string" ? p.sessionId : void 0;
|
|
110826
110984
|
if (id7 && this.archivingSessions.has(id7)) throw new OpencodeAcpError("ACP_SESSION_BUSY", "The OpenCode session is being archived.");
|
|
110827
110985
|
if (id7 && this.archivedSessions.has(id7) && ["session/load", "session/prompt", "dsh/selectModel"].includes(method)) throw new OpencodeAcpError("ACP_SESSION_ARCHIVED", "This OpenCode session is archived.");
|
|
@@ -110891,11 +111049,11 @@ var OpencodeAcpClient = class _OpencodeAcpClient {
|
|
|
110891
111049
|
}
|
|
110892
111050
|
const result = await this.request(method, params, budget);
|
|
110893
111051
|
const nativeApi = this.nativeApi;
|
|
110894
|
-
if (method === "session/list" && nativeApi &&
|
|
111052
|
+
if (method === "session/list" && nativeApi && isRecord23(result) && Array.isArray(result.sessions)) {
|
|
110895
111053
|
const rawItems = result.sessions;
|
|
110896
111054
|
const items = rawItems.length > MAX_OPENCODE_SESSION_LIST ? [...rawItems].sort((a, b) => {
|
|
110897
|
-
const ta =
|
|
110898
|
-
const tb =
|
|
111055
|
+
const ta = isRecord23(a) && typeof a.updatedAt === "string" ? Date.parse(a.updatedAt) || 0 : 0;
|
|
111056
|
+
const tb = isRecord23(b) && typeof b.updatedAt === "string" ? Date.parse(b.updatedAt) || 0 : 0;
|
|
110899
111057
|
return tb - ta;
|
|
110900
111058
|
}).slice(0, MAX_OPENCODE_SESSION_LIST) : rawItems;
|
|
110901
111059
|
const realpathCache = /* @__PURE__ */ new Map();
|
|
@@ -110914,7 +111072,7 @@ var OpencodeAcpClient = class _OpencodeAcpClient {
|
|
|
110914
111072
|
const index = nextItem++;
|
|
110915
111073
|
if (index >= items.length) return;
|
|
110916
111074
|
const item = items[index];
|
|
110917
|
-
if (!
|
|
111075
|
+
if (!isRecord23(item) || typeof item.sessionId !== "string" || typeof item.cwd !== "string") continue;
|
|
110918
111076
|
const cwd2 = await resolveCwd(item.cwd);
|
|
110919
111077
|
if (cwd2) resolved[index] = { index, sessionId: item.sessionId, cwd: cwd2 };
|
|
110920
111078
|
}
|
|
@@ -110965,7 +111123,7 @@ var OpencodeAcpClient = class _OpencodeAcpClient {
|
|
|
110965
111123
|
}
|
|
110966
111124
|
async loadSession(method, params, budget, sessionId) {
|
|
110967
111125
|
const result = await this.request(method, params, budget);
|
|
110968
|
-
const returnedId =
|
|
111126
|
+
const returnedId = isRecord23(result) && typeof result.sessionId === "string" ? result.sessionId : void 0;
|
|
110969
111127
|
const id7 = sessionId ?? returnedId;
|
|
110970
111128
|
if (!this.ready || !id7 || sessionId && returnedId && returnedId !== sessionId) {
|
|
110971
111129
|
throw new OpencodeAcpError("ACP_INVALID_SESSION", "OpenCode returned an invalid session.");
|
|
@@ -111116,13 +111274,13 @@ var OpencodeAcpClient = class _OpencodeAcpClient {
|
|
|
111116
111274
|
}
|
|
111117
111275
|
handleInbound(inbound) {
|
|
111118
111276
|
const params = inbound.params;
|
|
111119
|
-
if (inbound.kind === "request" &&
|
|
111277
|
+
if (inbound.kind === "request" && isRecord23(params) && typeof params.sessionId === "string" && this.loads.has(params.sessionId)) {
|
|
111120
111278
|
void this.respondError(inbound.id, -32600, "OpenCode session is not loaded.").catch(() => void 0);
|
|
111121
111279
|
return;
|
|
111122
111280
|
}
|
|
111123
|
-
if (inbound.kind === "notification" && inbound.method === "session/update" &&
|
|
111281
|
+
if (inbound.kind === "notification" && inbound.method === "session/update" && isRecord23(params) && typeof params.sessionId === "string") {
|
|
111124
111282
|
this.models.get(params.sessionId)?.update(params.update);
|
|
111125
|
-
if (
|
|
111283
|
+
if (isRecord23(params.update) && params.update.sessionUpdate === "available_commands_update") {
|
|
111126
111284
|
this.sessionCommands.set(params.sessionId, parseAvailableCommands(params.update));
|
|
111127
111285
|
}
|
|
111128
111286
|
if (this.loads.has(params.sessionId) && !this.options.historyReader) return;
|
|
@@ -111149,7 +111307,7 @@ var OpencodeAcpClient = class _OpencodeAcpClient {
|
|
|
111149
111307
|
for (const handler of this.unavailableHandlers) handler(code);
|
|
111150
111308
|
}
|
|
111151
111309
|
};
|
|
111152
|
-
function
|
|
111310
|
+
function isRecord23(value) {
|
|
111153
111311
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
111154
111312
|
}
|
|
111155
111313
|
|
|
@@ -111217,8 +111375,8 @@ function sliceAcpHistoryEvents(events, beforeSeq, maxMessages = DEFAULT_ACP_HIST
|
|
|
111217
111375
|
};
|
|
111218
111376
|
}
|
|
111219
111377
|
function innerEvent(row) {
|
|
111220
|
-
if (!
|
|
111221
|
-
if (row.type === "event" &&
|
|
111378
|
+
if (!isRecord24(row)) return void 0;
|
|
111379
|
+
if (row.type === "event" && isRecord24(row.event)) return row.event;
|
|
111222
111380
|
return row;
|
|
111223
111381
|
}
|
|
111224
111382
|
function eventSeq(row) {
|
|
@@ -111226,15 +111384,15 @@ function eventSeq(row) {
|
|
|
111226
111384
|
return typeof seq === "number" && Number.isSafeInteger(seq) && seq >= 0 ? seq : void 0;
|
|
111227
111385
|
}
|
|
111228
111386
|
function extractToolCallId(data2) {
|
|
111229
|
-
if (!
|
|
111230
|
-
const message =
|
|
111231
|
-
const source = message &&
|
|
111387
|
+
if (!isRecord24(data2)) return void 0;
|
|
111388
|
+
const message = isRecord24(data2.message) ? data2.message : void 0;
|
|
111389
|
+
const source = message && isRecord24(message.source) ? message.source : void 0;
|
|
111232
111390
|
if (typeof source?.callId === "string" && source.callId.length > 0) return source.callId;
|
|
111233
111391
|
if (typeof data2.callId === "string" && data2.callId.length > 0) return data2.callId;
|
|
111234
111392
|
if (typeof data2.id === "string" && data2.id.length > 0) return data2.id;
|
|
111235
111393
|
return void 0;
|
|
111236
111394
|
}
|
|
111237
|
-
function
|
|
111395
|
+
function isRecord24(value) {
|
|
111238
111396
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
111239
111397
|
}
|
|
111240
111398
|
|
|
@@ -112146,15 +112304,15 @@ var AcpPeerBridge = class {
|
|
|
112146
112304
|
if (this.closed) throw new RpcError("ACP_CONNECTION_CLOSED", "The ACP connection is closed.");
|
|
112147
112305
|
}
|
|
112148
112306
|
};
|
|
112149
|
-
function
|
|
112307
|
+
function isRecord25(value) {
|
|
112150
112308
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
112151
112309
|
}
|
|
112152
112310
|
function safeErrorCode3(error62) {
|
|
112153
|
-
if (
|
|
112311
|
+
if (isRecord25(error62) && typeof error62.code === "string") return error62.code;
|
|
112154
112312
|
return "UNKNOWN";
|
|
112155
112313
|
}
|
|
112156
112314
|
function safeMethod2(input4) {
|
|
112157
|
-
return
|
|
112315
|
+
return isRecord25(input4) && typeof input4.method === "string" ? input4.method : "invalid";
|
|
112158
112316
|
}
|
|
112159
112317
|
|
|
112160
112318
|
// packages/plugin/src/acp/workspace-store.ts
|
|
@@ -112356,12 +112514,12 @@ var AcpWorkspaceStore = class _AcpWorkspaceStore {
|
|
|
112356
112514
|
}
|
|
112357
112515
|
};
|
|
112358
112516
|
function normalizeStore(value) {
|
|
112359
|
-
if (!
|
|
112517
|
+
if (!isRecord26(value) || value.version !== 1) return createEmptyStore();
|
|
112360
112518
|
const backends = emptyBackends();
|
|
112361
|
-
if (
|
|
112519
|
+
if (isRecord26(value.backends)) {
|
|
112362
112520
|
for (const [key, raw] of Object.entries(value.backends)) {
|
|
112363
|
-
if (PROTOTYPE_KEYS.has(key) || !
|
|
112364
|
-
const workspaces = Array.isArray(raw.workspaces) ? raw.workspaces.flatMap((item) =>
|
|
112521
|
+
if (PROTOTYPE_KEYS.has(key) || !isRecord26(raw)) continue;
|
|
112522
|
+
const workspaces = Array.isArray(raw.workspaces) ? raw.workspaces.flatMap((item) => isRecord26(item) && typeof item.path === "string" && item.path.length > 0 ? [{
|
|
112365
112523
|
path: item.path,
|
|
112366
112524
|
...typeof item.title === "string" && item.title.trim() ? { title: item.title.trim() } : {},
|
|
112367
112525
|
updatedAt: typeof item.updatedAt === "string" ? item.updatedAt : (/* @__PURE__ */ new Date(0)).toISOString()
|
|
@@ -112369,7 +112527,7 @@ function normalizeStore(value) {
|
|
|
112369
112527
|
const deletedPaths = Array.isArray(raw.deletedPaths) ? raw.deletedPaths.filter((item) => typeof item === "string" && item.length > 0) : [];
|
|
112370
112528
|
const pinnedSessionIds = Array.isArray(raw.pinnedSessionIds) ? raw.pinnedSessionIds.filter((item) => typeof item === "string" && item.length > 0) : [];
|
|
112371
112529
|
const sessionTitles = /* @__PURE__ */ Object.create(null);
|
|
112372
|
-
if (
|
|
112530
|
+
if (isRecord26(raw.sessionTitles)) {
|
|
112373
112531
|
for (const [id7, title] of Object.entries(raw.sessionTitles)) {
|
|
112374
112532
|
if (typeof title === "string" && title.trim()) sessionTitles[id7] = title;
|
|
112375
112533
|
}
|
|
@@ -112378,7 +112536,7 @@ function normalizeStore(value) {
|
|
|
112378
112536
|
}
|
|
112379
112537
|
}
|
|
112380
112538
|
const sessionPermissions = emptyPermissions();
|
|
112381
|
-
if (
|
|
112539
|
+
if (isRecord26(value.sessionPermissions)) {
|
|
112382
112540
|
for (const [key, preset] of Object.entries(value.sessionPermissions)) {
|
|
112383
112541
|
if (!PROTOTYPE_KEYS.has(key) && (preset === "workspace-write" || preset === "danger-full-access")) {
|
|
112384
112542
|
sessionPermissions[key] = preset;
|
|
@@ -112387,7 +112545,7 @@ function normalizeStore(value) {
|
|
|
112387
112545
|
}
|
|
112388
112546
|
return { version: 1, backends, sessionPermissions };
|
|
112389
112547
|
}
|
|
112390
|
-
function
|
|
112548
|
+
function isRecord26(value) {
|
|
112391
112549
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
112392
112550
|
}
|
|
112393
112551
|
|
|
@@ -113133,7 +113291,7 @@ var AcpRemoteGateway = class {
|
|
|
113133
113291
|
if (selected !== void 0 && selected !== requested) throw new RpcError("INVALID_MESSAGE", "The ACP session backend does not match.");
|
|
113134
113292
|
const client = this.requireAcp(requested);
|
|
113135
113293
|
const supportsImages = requested === "antigravity" || requested === "hermes" || requested === "kimi" || client.capabilities?.()?.promptCapabilities?.image === true;
|
|
113136
|
-
if (Array.isArray(call.params.prompt) && call.params.prompt.some((part) =>
|
|
113294
|
+
if (Array.isArray(call.params.prompt) && call.params.prompt.some((part) => isRecord27(part) && part.type === "image") && !supportsImages) {
|
|
113137
113295
|
throw new RpcError("METHOD_NOT_ALLOWED", "This ACP backend does not accept image prompts.");
|
|
113138
113296
|
}
|
|
113139
113297
|
if (sessionId !== void 0 && !this.sessionPermissions.has(sessionId)) {
|
|
@@ -113333,7 +113491,7 @@ var AcpRemoteGateway = class {
|
|
|
113333
113491
|
this.invalidateSessionHistory(sessionId);
|
|
113334
113492
|
const backend = this.sessionBackends.get(sessionId) ?? this.defaultBackend();
|
|
113335
113493
|
const { _meta: promptMeta2, ...upstreamPromptParams } = call.params;
|
|
113336
|
-
const clientRequestId2 =
|
|
113494
|
+
const clientRequestId2 = isRecord27(promptMeta2) && typeof promptMeta2["openandroidintelligence/clientRequestId"] === "string" ? promptMeta2["openandroidintelligence/clientRequestId"] : void 0;
|
|
113337
113495
|
const task = {
|
|
113338
113496
|
backend,
|
|
113339
113497
|
client: this.requireAcp(backend),
|
|
@@ -113442,8 +113600,8 @@ var AcpRemoteGateway = class {
|
|
|
113442
113600
|
endTurnDiff("stopped");
|
|
113443
113601
|
return;
|
|
113444
113602
|
}
|
|
113445
|
-
const stopReason =
|
|
113446
|
-
const usage =
|
|
113603
|
+
const stopReason = isRecord27(result) && typeof result.stopReason === "string" ? result.stopReason : "end_turn";
|
|
113604
|
+
const usage = isRecord27(result) ? sanitizeUsage(result.usage) : void 0;
|
|
113447
113605
|
const catchUp = takeTurnCatchUp(this.turnCatchUp, sessionId);
|
|
113448
113606
|
this.logger.info("ACP prompt finished", {
|
|
113449
113607
|
sessionId: shortSessionId(sessionId),
|
|
@@ -114164,7 +114322,7 @@ var AcpRemoteGateway = class {
|
|
|
114164
114322
|
});
|
|
114165
114323
|
}
|
|
114166
114324
|
resolveReplayedFrame(connectionId, peer, sessionId, frame) {
|
|
114167
|
-
if (frame.origin === void 0 || frame.origin.connectionId !== connectionId || frame.origin.peer !== void 0 && frame.origin.peer !== peer || !
|
|
114325
|
+
if (frame.origin === void 0 || frame.origin.connectionId !== connectionId || frame.origin.peer !== void 0 && frame.origin.peer !== peer || !isRecord27(frame.params) || !isRecord27(frame.params.update)) {
|
|
114168
114326
|
return { method: frame.method, params: frame.params };
|
|
114169
114327
|
}
|
|
114170
114328
|
const updateWithOrigin = { ...frame.params.update, clientRequestId: frame.origin.clientRequestId };
|
|
@@ -114174,7 +114332,7 @@ var AcpRemoteGateway = class {
|
|
|
114174
114332
|
};
|
|
114175
114333
|
if (!isOversizedAcpFrame(sessionId, candidate)) return candidate;
|
|
114176
114334
|
const catchUp = Array.isArray(frame.params.update.catchUp) ? frame.params.update.catchUp.filter(
|
|
114177
|
-
(item) =>
|
|
114335
|
+
(item) => isRecord27(item) && typeof item.method === "string"
|
|
114178
114336
|
) : [];
|
|
114179
114337
|
const { catchUp: _ignored, ...baseUpdate } = updateWithOrigin;
|
|
114180
114338
|
return this.buildTerminalPromptFrame(sessionId, baseUpdate, catchUp);
|
|
@@ -114247,8 +114405,8 @@ var AcpRemoteGateway = class {
|
|
|
114247
114405
|
recordTurnCatchUp(sessionId, frame) {
|
|
114248
114406
|
const list2 = this.turnCatchUp.get(sessionId);
|
|
114249
114407
|
if (list2 === void 0 || frame.method !== "session/update") return;
|
|
114250
|
-
const params =
|
|
114251
|
-
const update = params !== void 0 &&
|
|
114408
|
+
const params = isRecord27(frame.params) ? frame.params : void 0;
|
|
114409
|
+
const update = params !== void 0 && isRecord27(params.update) ? params.update : params;
|
|
114252
114410
|
const kind = update !== void 0 && typeof update.sessionUpdate === "string" ? update.sessionUpdate : void 0;
|
|
114253
114411
|
if (kind === void 0 || !CATCH_UP_SESSION_UPDATES.has(kind)) return;
|
|
114254
114412
|
list2.push({ method: frame.method, params: frame.params });
|
|
@@ -114469,11 +114627,11 @@ var AcpRemoteGateway = class {
|
|
|
114469
114627
|
const client = this.backendInstances.get(backend)?.client;
|
|
114470
114628
|
if (!client) return;
|
|
114471
114629
|
const modes = await client.call("dsh/sessionModes", { sessionId }).catch(() => void 0);
|
|
114472
|
-
if (!
|
|
114630
|
+
if (!isRecord27(modes) || !Array.isArray(modes.availableModes)) return;
|
|
114473
114631
|
const current = typeof modes.currentModeId === "string" ? modes.currentModeId : void 0;
|
|
114474
114632
|
const permissionModes = /* @__PURE__ */ new Set(["default", "accept-edits", "auto", "acceptEdits", "bypassPermissions", "dontAsk", "yolo", "full-auto"]);
|
|
114475
114633
|
if (current && !permissionModes.has(current)) return;
|
|
114476
|
-
const ids = modes.availableModes.filter((item) =>
|
|
114634
|
+
const ids = modes.availableModes.filter((item) => isRecord27(item) && typeof item.id === "string").map((item) => item.id);
|
|
114477
114635
|
const target3 = preset === "danger-full-access" ? ["auto", "bypassPermissions", "yolo", "full-auto", "accept-edits", "acceptEdits"].find((id7) => ids.includes(id7)) : ids.find((id7) => id7 === "default");
|
|
114478
114636
|
if (target3 && target3 !== current) {
|
|
114479
114637
|
await client.call("session/set_mode", { sessionId, modeId: target3 });
|
|
@@ -114558,10 +114716,10 @@ var AcpRemoteGateway = class {
|
|
|
114558
114716
|
throw error62;
|
|
114559
114717
|
}
|
|
114560
114718
|
assertCurrent();
|
|
114561
|
-
if (backend === "cursor" &&
|
|
114719
|
+
if (backend === "cursor" && isRecord27(result) && result.sessions === void 0 && Object.keys(result).length === 0) {
|
|
114562
114720
|
return items;
|
|
114563
114721
|
}
|
|
114564
|
-
if (!
|
|
114722
|
+
if (!isRecord27(result) || !Array.isArray(result.sessions) || result.nextCursor != null && (typeof result.nextCursor !== "string" || result.nextCursor.length === 0)) {
|
|
114565
114723
|
throw new RpcError("INVALID_MESSAGE", "The ACP session catalog response is invalid.");
|
|
114566
114724
|
}
|
|
114567
114725
|
if (process.platform === "win32" && backend === "antigravity" && queryCwd !== void 0 && page === 0 && result.sessions.length === 0 && result.nextCursor == null) {
|
|
@@ -114570,7 +114728,7 @@ var AcpRemoteGateway = class {
|
|
|
114570
114728
|
continue;
|
|
114571
114729
|
}
|
|
114572
114730
|
for (const item of result.sessions) {
|
|
114573
|
-
if (!
|
|
114731
|
+
if (!isRecord27(item) || typeof item.sessionId !== "string" || typeof item.cwd !== "string") continue;
|
|
114574
114732
|
const canonical = await this.resolveCatalogCwd(item.cwd, assertCurrent);
|
|
114575
114733
|
if (!canonical || cwd2 && canonical !== cwd2) continue;
|
|
114576
114734
|
if (this.sessionBackends.has(item.sessionId) && this.sessionBackends.get(item.sessionId) !== backend) continue;
|
|
@@ -114679,24 +114837,24 @@ var AcpRemoteGateway = class {
|
|
|
114679
114837
|
}
|
|
114680
114838
|
};
|
|
114681
114839
|
function parseCallEnvelope2(input4) {
|
|
114682
|
-
if (!
|
|
114840
|
+
if (!isRecord27(input4) || typeof input4.method !== "string") {
|
|
114683
114841
|
throw new RpcError("INVALID_MESSAGE", "The Cursor call envelope is invalid.");
|
|
114684
114842
|
}
|
|
114685
114843
|
return { method: input4.method, params: input4.params ?? {} };
|
|
114686
114844
|
}
|
|
114687
114845
|
function parseRespondEnvelope(input4) {
|
|
114688
|
-
if (!
|
|
114846
|
+
if (!isRecord27(input4) || typeof input4.requestHandle !== "string" || input4.requestHandle.length === 0 || Object.keys(input4).some((key) => !["requestHandle", "decision", "result"].includes(key)) || typeof input4.decision !== "string" || !["allow-once", "reject-once", "cancel"].includes(input4.decision)) {
|
|
114689
114847
|
throw new RpcError("INVALID_MESSAGE", "The ACP respond envelope is invalid.");
|
|
114690
114848
|
}
|
|
114691
114849
|
return input4;
|
|
114692
114850
|
}
|
|
114693
114851
|
function permissionOptions(params) {
|
|
114694
|
-
if (!
|
|
114852
|
+
if (!isRecord27(params) || !Array.isArray(params.options) || params.options.length === 0) {
|
|
114695
114853
|
throw new Error("Missing permission options");
|
|
114696
114854
|
}
|
|
114697
114855
|
const ids = /* @__PURE__ */ new Set();
|
|
114698
114856
|
const options = params.options.map((option) => {
|
|
114699
|
-
if (!
|
|
114857
|
+
if (!isRecord27(option) || typeof option.optionId !== "string" || !option.optionId || typeof option.kind !== "string" || !["allow_once", "allow_always", "reject_once", "reject_always"].includes(option.kind) || ids.has(option.optionId)) throw new Error("Invalid permission option");
|
|
114700
114858
|
ids.add(option.optionId);
|
|
114701
114859
|
return { kind: option.kind, optionId: option.optionId };
|
|
114702
114860
|
});
|
|
@@ -114717,8 +114875,8 @@ function mapPermissionDecision(params, pending) {
|
|
|
114717
114875
|
}
|
|
114718
114876
|
if (pending.method === "cursor/ask_question" && params.decision === "allow-once") {
|
|
114719
114877
|
if (params.result === void 0) return { outcome: { outcome: "answered" } };
|
|
114720
|
-
if (!
|
|
114721
|
-
const outcomeRecord =
|
|
114878
|
+
if (!isRecord27(params.result)) throw invalid();
|
|
114879
|
+
const outcomeRecord = isRecord27(params.result.outcome) ? params.result.outcome : params.result;
|
|
114722
114880
|
const outcomeKind = typeof outcomeRecord.outcome === "string" ? outcomeRecord.outcome : "answered";
|
|
114723
114881
|
if (outcomeKind !== "answered" && outcomeKind !== "selected") throw invalid();
|
|
114724
114882
|
const allowedKeys = /* @__PURE__ */ new Set(["outcome", "answers", "selectedOptionIds", "response"]);
|
|
@@ -114734,21 +114892,21 @@ function mapPermissionDecision(params, pending) {
|
|
|
114734
114892
|
}
|
|
114735
114893
|
const outcome = pending.method === "cursor/create_plan" ? params.decision === "allow-once" ? "accepted" : params.decision === "cancel" ? "cancelled" : "rejected" : "cancelled";
|
|
114736
114894
|
if (params.result !== void 0) {
|
|
114737
|
-
if (!
|
|
114895
|
+
if (!isRecord27(params.result) || Object.keys(params.result).length !== 1 || !isRecord27(params.result.outcome) || Object.keys(params.result.outcome).length !== 1 || params.result.outcome.outcome !== outcome) throw invalid();
|
|
114738
114896
|
}
|
|
114739
114897
|
return { outcome: { outcome } };
|
|
114740
114898
|
}
|
|
114741
114899
|
function readSessionId(value) {
|
|
114742
|
-
if (!
|
|
114900
|
+
if (!isRecord27(value)) return void 0;
|
|
114743
114901
|
return typeof value.sessionId === "string" ? value.sessionId : void 0;
|
|
114744
114902
|
}
|
|
114745
114903
|
function readNestedSessionId(value) {
|
|
114746
|
-
if (!
|
|
114747
|
-
if (
|
|
114904
|
+
if (!isRecord27(value)) return void 0;
|
|
114905
|
+
if (isRecord27(value.update) && typeof value.update.sessionId === "string") return value.update.sessionId;
|
|
114748
114906
|
return void 0;
|
|
114749
114907
|
}
|
|
114750
114908
|
function sanitizeSessionResult(value) {
|
|
114751
|
-
if (!
|
|
114909
|
+
if (!isRecord27(value)) return value;
|
|
114752
114910
|
const next = {};
|
|
114753
114911
|
for (const [key, entry] of Object.entries(value)) {
|
|
114754
114912
|
if (key === "sessionId" || key === "stopReason" || key === "mode" || key === "currentModeId" || key === "modes") {
|
|
@@ -114758,7 +114916,7 @@ function sanitizeSessionResult(value) {
|
|
|
114758
114916
|
return Object.keys(next).length > 0 ? next : value;
|
|
114759
114917
|
}
|
|
114760
114918
|
function sanitizeUsage(value) {
|
|
114761
|
-
if (!
|
|
114919
|
+
if (!isRecord27(value)) return void 0;
|
|
114762
114920
|
const fields = ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens", "cachedReadTokens", "cachedWriteTokens", "reasoningTokens", "thoughtTokens", "totalTokens"];
|
|
114763
114921
|
const normalized = {};
|
|
114764
114922
|
for (const field of fields) {
|
|
@@ -114904,14 +115062,14 @@ function isResponseTooLarge(error62) {
|
|
|
114904
115062
|
let current = error62;
|
|
114905
115063
|
while (current !== void 0 && current !== null && !seen.has(current) && seen.size < 8) {
|
|
114906
115064
|
seen.add(current);
|
|
114907
|
-
if (
|
|
115065
|
+
if (isRecord27(current) && typeof current.code === "string" && OVERSIZED_FRAME_ERROR_CODES.has(current.code)) {
|
|
114908
115066
|
return true;
|
|
114909
115067
|
}
|
|
114910
|
-
const message = current instanceof Error ? current.message :
|
|
115068
|
+
const message = current instanceof Error ? current.message : isRecord27(current) && typeof current.message === "string" ? current.message : void 0;
|
|
114911
115069
|
if (message !== void 0 && /secure message exceeds the reassembly limit|exceeds the secure channel limit/i.test(message)) {
|
|
114912
115070
|
return true;
|
|
114913
115071
|
}
|
|
114914
|
-
current = current instanceof Error ? current.cause :
|
|
115072
|
+
current = current instanceof Error ? current.cause : isRecord27(current) ? current.cause : void 0;
|
|
114915
115073
|
}
|
|
114916
115074
|
return false;
|
|
114917
115075
|
}
|
|
@@ -114923,20 +115081,20 @@ function takeTurnCatchUp(turnCatchUp, sessionId) {
|
|
|
114923
115081
|
turnCatchUp.delete(sessionId);
|
|
114924
115082
|
return list2;
|
|
114925
115083
|
}
|
|
114926
|
-
function
|
|
115084
|
+
function isRecord27(value) {
|
|
114927
115085
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
114928
115086
|
}
|
|
114929
115087
|
function buildAcpApprovalFrameParams(rawParams, requestHandle, sessionId, method) {
|
|
114930
115088
|
return {
|
|
114931
|
-
...
|
|
115089
|
+
...isRecord27(rawParams) ? rawParams : {},
|
|
114932
115090
|
requestHandle,
|
|
114933
115091
|
sessionId,
|
|
114934
115092
|
upstreamMethod: method
|
|
114935
115093
|
};
|
|
114936
115094
|
}
|
|
114937
115095
|
function acpApprovalSummary(method, params) {
|
|
114938
|
-
if (
|
|
114939
|
-
if (
|
|
115096
|
+
if (isRecord27(params)) {
|
|
115097
|
+
if (isRecord27(params.toolCall)) {
|
|
114940
115098
|
const title = typeof params.toolCall.title === "string" && params.toolCall.title.trim().length > 0 ? params.toolCall.title.trim() : void 0;
|
|
114941
115099
|
if (title !== void 0) return title;
|
|
114942
115100
|
}
|
|
@@ -115326,7 +115484,6 @@ import { join as join17 } from "node:path";
|
|
|
115326
115484
|
var DEFAULT_STORE = {
|
|
115327
115485
|
version: 1,
|
|
115328
115486
|
host: {
|
|
115329
|
-
enabled: false,
|
|
115330
115487
|
models: [],
|
|
115331
115488
|
maxConcurrent: 2
|
|
115332
115489
|
},
|
|
@@ -115348,12 +115505,7 @@ function normalizeStore2(input4) {
|
|
|
115348
115505
|
const raw = typeof input4 === "object" && input4 !== null ? input4 : {};
|
|
115349
115506
|
const hostRaw = typeof raw.host === "object" && raw.host !== null ? raw.host : {};
|
|
115350
115507
|
const borrowerRaw = typeof raw.borrower === "object" && raw.borrower !== null ? raw.borrower : {};
|
|
115351
|
-
const
|
|
115352
|
-
const fromRules = Array.isArray(hostRaw.rules) ? hostRaw.rules.flatMap((entry) => {
|
|
115353
|
-
if (typeof entry !== "object" || entry === null) return [];
|
|
115354
|
-
return routeList(entry.models);
|
|
115355
|
-
}) : [];
|
|
115356
|
-
const models = [.../* @__PURE__ */ new Set([...routeList(hostRaw.models), ...fromRules])];
|
|
115508
|
+
const models = Array.isArray(hostRaw.models) ? [...new Set(hostRaw.models.map(normalizeRoute).filter((route) => route !== void 0))] : [];
|
|
115357
115509
|
const sourcesRaw = typeof borrowerRaw.sources === "object" && borrowerRaw.sources !== null ? borrowerRaw.sources : {};
|
|
115358
115510
|
const sources = {};
|
|
115359
115511
|
for (const [deviceId, value] of Object.entries(sourcesRaw)) {
|
|
@@ -115361,7 +115513,6 @@ function normalizeStore2(input4) {
|
|
|
115361
115513
|
const source = value;
|
|
115362
115514
|
sources[deviceId] = {
|
|
115363
115515
|
enabled: source.enabled === true,
|
|
115364
|
-
models: Array.isArray(source.models) ? source.models.filter((model) => typeof model === "string" && model.trim() !== "").map((model) => model.trim()) : [],
|
|
115365
115516
|
...typeof source.hostName === "string" && source.hostName.trim() !== "" ? { hostName: source.hostName.trim() } : {}
|
|
115366
115517
|
};
|
|
115367
115518
|
}
|
|
@@ -115369,7 +115520,6 @@ function normalizeStore2(input4) {
|
|
|
115369
115520
|
return {
|
|
115370
115521
|
version: 1,
|
|
115371
115522
|
host: {
|
|
115372
|
-
enabled: hostRaw.enabled === true,
|
|
115373
115523
|
models,
|
|
115374
115524
|
maxConcurrent: Number.isFinite(maxConcurrentRaw) ? Math.min(Math.max(maxConcurrentRaw, 1), 16) : DEFAULT_STORE.host.maxConcurrent
|
|
115375
115525
|
},
|
|
@@ -115594,6 +115744,7 @@ var PluginControlRuntime = class {
|
|
|
115594
115744
|
if (endpoint === "settings.logs.clear") return ok3(await this.clearLogs());
|
|
115595
115745
|
if (endpoint === "modelshare.get") return ok3(await this.modelShareGet());
|
|
115596
115746
|
if (endpoint === "modelshare.set") return ok3(await this.modelShareSet(payload));
|
|
115747
|
+
if (endpoint === "modelshare.resync") return ok3(await this.modelShareResync());
|
|
115597
115748
|
if (endpoint === "host.authorization.set" && this.client !== void 0) {
|
|
115598
115749
|
const value = record11(payload);
|
|
115599
115750
|
if (typeof value.enabled !== "boolean") throw new ClientModeError("INVALID_MESSAGE", "Host authorization state is required.");
|
|
@@ -115605,7 +115756,7 @@ var PluginControlRuntime = class {
|
|
|
115605
115756
|
if (this.host === void 0) throw new ClientModeError("METHOD_NOT_ALLOWED", "This plugin is not running as a Host.");
|
|
115606
115757
|
await this.persistHostControlEnabled(true, { onlyIfChanged: true });
|
|
115607
115758
|
this.host.reconnectHost();
|
|
115608
|
-
return
|
|
115759
|
+
return this.statusResult(ok3(this.hostOnlyStatus()));
|
|
115609
115760
|
}
|
|
115610
115761
|
if (endpoint === "plugin.update") return ok3(await this.updatePlugin(payload));
|
|
115611
115762
|
if (endpoint === "status") {
|
|
@@ -115620,10 +115771,10 @@ var PluginControlRuntime = class {
|
|
|
115620
115771
|
startupError,
|
|
115621
115772
|
hostAuthorizationAvailable: false
|
|
115622
115773
|
};
|
|
115623
|
-
return
|
|
115774
|
+
return this.statusResult(ok3(failureStatus));
|
|
115624
115775
|
}
|
|
115625
115776
|
const base = this.client !== void 0 ? await this.client.handleControl(endpoint, payload, signal) : ok3(this.hostOnlyStatus());
|
|
115626
|
-
return
|
|
115777
|
+
return this.statusResult(base);
|
|
115627
115778
|
}
|
|
115628
115779
|
if (endpoint === "host.account.login") {
|
|
115629
115780
|
if (this.client !== void 0) {
|
|
@@ -115658,7 +115809,7 @@ var PluginControlRuntime = class {
|
|
|
115658
115809
|
if (this.client !== void 0) return this.client.handleControl(endpoint, payload, signal);
|
|
115659
115810
|
if (endpoint === "devices") return ok3([]);
|
|
115660
115811
|
if (endpoint === "mode.set" && record11(payload).mode === "local") {
|
|
115661
|
-
return
|
|
115812
|
+
return this.statusResult(ok3(this.hostOnlyStatus()));
|
|
115662
115813
|
}
|
|
115663
115814
|
if (this.startupFailure instanceof Error) {
|
|
115664
115815
|
throw this.startupFailure;
|
|
@@ -116236,6 +116387,18 @@ var PluginControlRuntime = class {
|
|
|
116236
116387
|
writable: this.settings !== void 0
|
|
116237
116388
|
};
|
|
116238
116389
|
}
|
|
116390
|
+
/**
|
|
116391
|
+
* Refresh every borrower source now, then return the updated view.
|
|
116392
|
+
*
|
|
116393
|
+
* Backs the settings page refresh button: the periodic sync already runs, but
|
|
116394
|
+
* waiting up to a minute for a newly changed Host is worse than toggling its
|
|
116395
|
+
* switch off and on, which is what users did before.
|
|
116396
|
+
*/
|
|
116397
|
+
async modelShareResync() {
|
|
116398
|
+
const binding = this.modelShareBinding();
|
|
116399
|
+
await binding.resync?.();
|
|
116400
|
+
return await this.modelShareGet();
|
|
116401
|
+
}
|
|
116239
116402
|
async modelShareSet(payload) {
|
|
116240
116403
|
const binding = this.modelShareBinding();
|
|
116241
116404
|
const raw = record11(payload);
|
|
@@ -116349,6 +116512,14 @@ var PluginControlRuntime = class {
|
|
|
116349
116512
|
if (outcome.status === "failed") return { status: "failed", message: outcome.message };
|
|
116350
116513
|
return { status: outcome.status };
|
|
116351
116514
|
}
|
|
116515
|
+
statusResult(result) {
|
|
116516
|
+
const merged = withUpdate(result, this.updates?.snapshot());
|
|
116517
|
+
if (!merged.ok || !isRecord28(merged.value)) return merged;
|
|
116518
|
+
return ok3({
|
|
116519
|
+
...merged.value,
|
|
116520
|
+
remoteToolsEnabled: this.currentEditableConfig().remoteTools?.enabled !== false
|
|
116521
|
+
});
|
|
116522
|
+
}
|
|
116352
116523
|
hostOnlyStatus() {
|
|
116353
116524
|
return {
|
|
116354
116525
|
mode: "local",
|
|
@@ -116417,18 +116588,18 @@ function editableConfig(config2) {
|
|
|
116417
116588
|
...config2.acp === void 0 ? {} : { acp: { enabled: config2.acp.enabled, backends: config2.acp.backends } }
|
|
116418
116589
|
};
|
|
116419
116590
|
}
|
|
116420
|
-
function
|
|
116591
|
+
function isRecord28(value) {
|
|
116421
116592
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
116422
116593
|
}
|
|
116423
116594
|
function record11(value) {
|
|
116424
|
-
if (!
|
|
116595
|
+
if (!isRecord28(value)) throw new ClientModeError("INVALID_MESSAGE", "The control request payload is invalid.");
|
|
116425
116596
|
return value;
|
|
116426
116597
|
}
|
|
116427
116598
|
function ok3(value) {
|
|
116428
116599
|
return { ok: true, value };
|
|
116429
116600
|
}
|
|
116430
116601
|
function withUpdate(result, update) {
|
|
116431
|
-
if (update === void 0 || !result.ok || !
|
|
116602
|
+
if (update === void 0 || !result.ok || !isRecord28(result.value)) return result;
|
|
116432
116603
|
return ok3({ ...result.value, update });
|
|
116433
116604
|
}
|
|
116434
116605
|
function fail4(error62) {
|
|
@@ -118342,9 +118513,9 @@ function diagnosticReason2(error62) {
|
|
|
118342
118513
|
return message.replace(/\s+/g, " ").slice(0, 160) || "Unknown peer connection failure.";
|
|
118343
118514
|
}
|
|
118344
118515
|
function extractEndpoint(message) {
|
|
118345
|
-
if (!
|
|
118516
|
+
if (!isRecord29(message) || !isRecord29(message.payload)) return void 0;
|
|
118346
118517
|
const payload = message.payload;
|
|
118347
|
-
if (
|
|
118518
|
+
if (isRecord29(payload.params)) {
|
|
118348
118519
|
if (typeof payload.params.endpoint === "string") return payload.params.endpoint;
|
|
118349
118520
|
if (typeof payload.params.method === "string") return payload.params.method;
|
|
118350
118521
|
}
|
|
@@ -118352,7 +118523,7 @@ function extractEndpoint(message) {
|
|
|
118352
118523
|
if (typeof payload.method === "string") return payload.method;
|
|
118353
118524
|
return void 0;
|
|
118354
118525
|
}
|
|
118355
|
-
function
|
|
118526
|
+
function isRecord29(value) {
|
|
118356
118527
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
118357
118528
|
}
|
|
118358
118529
|
function shortId2(value) {
|
|
@@ -119002,6 +119173,7 @@ var RpcRouter = class {
|
|
|
119002
119173
|
case "model.share.open":
|
|
119003
119174
|
case "model.share.chunk":
|
|
119004
119175
|
case "model.share.close":
|
|
119176
|
+
case "model.share.attach":
|
|
119005
119177
|
return this.requireModelShare().call(method, params);
|
|
119006
119178
|
default:
|
|
119007
119179
|
if (method.startsWith("session.transfer.")) {
|
|
@@ -121000,17 +121172,18 @@ var SESSION_PROJECTION_WHITELIST = /* @__PURE__ */ new Set([
|
|
|
121000
121172
|
"data",
|
|
121001
121173
|
"view",
|
|
121002
121174
|
"sessionStats",
|
|
121003
|
-
"tokenUsage"
|
|
121175
|
+
"tokenUsage",
|
|
121176
|
+
"contextPressure"
|
|
121004
121177
|
]);
|
|
121005
121178
|
var DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
121006
121179
|
var MAX_WHITELIST_PROJECTION_BYTES = 64 * 1024;
|
|
121007
121180
|
var MAX_UNKNOWN_PROJECTION_BYTES = 4096;
|
|
121008
121181
|
var SESSION_LIST_ROW_BUDGET = 2048;
|
|
121009
|
-
function
|
|
121182
|
+
function isRecord30(value) {
|
|
121010
121183
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
121011
121184
|
}
|
|
121012
121185
|
function filterSessionProjections(session2) {
|
|
121013
|
-
if (!
|
|
121186
|
+
if (!isRecord30(session2) || !isRecord30(session2.projections) || !isRecord30(session2.projections.values)) {
|
|
121014
121187
|
return session2;
|
|
121015
121188
|
}
|
|
121016
121189
|
const originalValues = session2.projections.values;
|
|
@@ -121050,15 +121223,15 @@ function trimSessionCatalogRows(endpoint, items) {
|
|
|
121050
121223
|
return kept.length <= SESSION_LIST_ROW_BUDGET ? kept : kept.slice().sort((left, right) => updatedAtOf(right) - updatedAtOf(left)).slice(0, SESSION_LIST_ROW_BUDGET);
|
|
121051
121224
|
}
|
|
121052
121225
|
function isListableRemoteSession(session2) {
|
|
121053
|
-
return
|
|
121226
|
+
return isRecord30(session2) && session2.parentSessionId === void 0 && session2.origin === void 0;
|
|
121054
121227
|
}
|
|
121055
121228
|
function updatedAtOf(session2) {
|
|
121056
|
-
return
|
|
121229
|
+
return isRecord30(session2) && typeof session2.updatedAt === "number" ? session2.updatedAt : 0;
|
|
121057
121230
|
}
|
|
121058
121231
|
function withSessionRowTitle(session2) {
|
|
121059
|
-
if (!
|
|
121060
|
-
const values =
|
|
121061
|
-
const title =
|
|
121232
|
+
if (!isRecord30(session2) || typeof session2.title === "string" && session2.title !== "") return session2;
|
|
121233
|
+
const values = isRecord30(session2.projections) ? session2.projections.values : void 0;
|
|
121234
|
+
const title = isRecord30(values) ? values.title : void 0;
|
|
121062
121235
|
return typeof title === "string" && title !== "" ? { ...session2, title } : session2;
|
|
121063
121236
|
}
|
|
121064
121237
|
function filterSessionListProjections(resultOrEndpoint, maybeResult) {
|
|
@@ -121067,7 +121240,7 @@ function filterSessionListProjections(resultOrEndpoint, maybeResult) {
|
|
|
121067
121240
|
if (endpoint !== void 0 && endpoint !== "session/list" && endpoint !== "session/search") return result;
|
|
121068
121241
|
if (!result || !result.ok) return result;
|
|
121069
121242
|
const filterList = (items) => trimSessionCatalogRows(endpoint, items).map(filterSessionProjections).map(withSessionRowTitle);
|
|
121070
|
-
if (
|
|
121243
|
+
if (isRecord30(result.value)) {
|
|
121071
121244
|
let changed = false;
|
|
121072
121245
|
const updated = { ...result.value };
|
|
121073
121246
|
if (Array.isArray(result.value.items)) {
|
|
@@ -121090,7 +121263,7 @@ function filterSessionListProjections(resultOrEndpoint, maybeResult) {
|
|
|
121090
121263
|
}
|
|
121091
121264
|
function extractSessionRows(result) {
|
|
121092
121265
|
if (!result || !result.ok) return [];
|
|
121093
|
-
if (
|
|
121266
|
+
if (isRecord30(result.value)) {
|
|
121094
121267
|
if (Array.isArray(result.value.items)) return result.value.items;
|
|
121095
121268
|
if (Array.isArray(result.value.sessions)) return result.value.sessions;
|
|
121096
121269
|
return [];
|
|
@@ -121101,16 +121274,16 @@ function countSessionListRows(result) {
|
|
|
121101
121274
|
return extractSessionRows(result).length;
|
|
121102
121275
|
}
|
|
121103
121276
|
function defaultSessionListPayloadKey(payload) {
|
|
121104
|
-
if (!
|
|
121277
|
+
if (!isRecord30(payload)) return void 0;
|
|
121105
121278
|
const topKeys = Object.keys(payload);
|
|
121106
121279
|
if (topKeys.length !== 1 || topKeys[0] !== "args") return void 0;
|
|
121107
121280
|
const args = payload.args;
|
|
121108
|
-
if (!
|
|
121281
|
+
if (!isRecord30(args)) return void 0;
|
|
121109
121282
|
const argKeys = Object.keys(args);
|
|
121110
121283
|
if (argKeys.length === 0) return "empty";
|
|
121111
121284
|
if (argKeys.length !== 1 || argKeys[0] !== "_request") return void 0;
|
|
121112
121285
|
const inner = args._request;
|
|
121113
|
-
return
|
|
121286
|
+
return isRecord30(inner) && Object.keys(inner).length === 0 ? "_request" : void 0;
|
|
121114
121287
|
}
|
|
121115
121288
|
function isDefaultSessionListPayload(payload) {
|
|
121116
121289
|
return defaultSessionListPayloadKey(payload) !== void 0;
|
|
@@ -121397,7 +121570,7 @@ var HostSessionListCache = class {
|
|
|
121397
121570
|
function buildWorkspaceRoots(rows) {
|
|
121398
121571
|
const roots = /* @__PURE__ */ new Map();
|
|
121399
121572
|
for (const row of rows) {
|
|
121400
|
-
if (!
|
|
121573
|
+
if (!isRecord30(row) || typeof row.sessionId !== "string" || row.sessionId.length === 0) continue;
|
|
121401
121574
|
if (typeof row.cwd !== "string" || row.cwd.length === 0) continue;
|
|
121402
121575
|
if (!roots.has(row.sessionId)) {
|
|
121403
121576
|
roots.set(row.sessionId, row.cwd);
|
|
@@ -121728,7 +121901,7 @@ var HarnessRemoteBridge = class {
|
|
|
121728
121901
|
let validatedDsBotBody;
|
|
121729
121902
|
if (params.endpoint === "dsBot/call") {
|
|
121730
121903
|
const root2 = record13(params.payload);
|
|
121731
|
-
const wrappedArgs =
|
|
121904
|
+
const wrappedArgs = isRecord31(root2.args) ? root2.args : void 0;
|
|
121732
121905
|
const botArgs = wrappedArgs ?? root2;
|
|
121733
121906
|
const endpoint = typeof botArgs.endpoint === "string" ? botArgs.endpoint : "";
|
|
121734
121907
|
if (endpoint === "dsh-update-install") {
|
|
@@ -121737,12 +121910,12 @@ var HarnessRemoteBridge = class {
|
|
|
121737
121910
|
if (!BOT_REMOTE_OPERATION_SET.has(endpoint)) {
|
|
121738
121911
|
throw new RpcError("INVALID_MESSAGE", "The DS-Bot operation is invalid for the remote channel.");
|
|
121739
121912
|
}
|
|
121740
|
-
if (botArgs.payload !== void 0 && botArgs.payload !== null && !
|
|
121913
|
+
if (botArgs.payload !== void 0 && botArgs.payload !== null && !isRecord31(botArgs.payload)) {
|
|
121741
121914
|
throw new RpcError("INVALID_MESSAGE", "The DS-Bot payload is invalid for the remote channel.");
|
|
121742
121915
|
}
|
|
121743
121916
|
const sanitizedBody = sanitizeBotRequestBody({
|
|
121744
121917
|
endpoint,
|
|
121745
|
-
payload:
|
|
121918
|
+
payload: isRecord31(botArgs.payload) ? botArgs.payload : null
|
|
121746
121919
|
});
|
|
121747
121920
|
const nextBotArgs = { endpoint: sanitizedBody.endpoint, payload: sanitizedBody.payload ?? null };
|
|
121748
121921
|
validatedDsBotBody = nextBotArgs;
|
|
@@ -121853,7 +122026,7 @@ var HarnessRemoteBridge = class {
|
|
|
121853
122026
|
if (params.endpoint === "$events/result" && nativeResult.ok && this.forwardedEventsObserver?.onEventResult !== void 0) {
|
|
121854
122027
|
const args = requestArgs(params.payload);
|
|
121855
122028
|
const eventId = typeof args.eventId === "string" && args.eventId.length > 0 ? args.eventId : void 0;
|
|
121856
|
-
const outcomeKind =
|
|
122029
|
+
const outcomeKind = isRecord31(args.outcome) && typeof args.outcome.kind === "string" ? args.outcome.kind : void 0;
|
|
121857
122030
|
if (eventId !== void 0) {
|
|
121858
122031
|
try {
|
|
121859
122032
|
this.forwardedEventsObserver.onEventResult(eventId, outcomeKind);
|
|
@@ -121861,7 +122034,7 @@ var HarnessRemoteBridge = class {
|
|
|
121861
122034
|
}
|
|
121862
122035
|
}
|
|
121863
122036
|
}
|
|
121864
|
-
if (validatedDsBotBody !== void 0 && nativeResult.ok &&
|
|
122037
|
+
if (validatedDsBotBody !== void 0 && nativeResult.ok && isRecord31(nativeResult.value) && this.forwardedEventsObserver?.onDsBotCall !== void 0) {
|
|
121865
122038
|
try {
|
|
121866
122039
|
this.forwardedEventsObserver.onDsBotCall(validatedDsBotBody, nativeResult.value);
|
|
121867
122040
|
} catch {
|
|
@@ -121873,7 +122046,7 @@ var HarnessRemoteBridge = class {
|
|
|
121873
122046
|
endpoint: params.endpoint,
|
|
121874
122047
|
durationMs
|
|
121875
122048
|
});
|
|
121876
|
-
if (params.endpoint === "directoryPicker/list" && result.ok &&
|
|
122049
|
+
if (params.endpoint === "directoryPicker/list" && result.ok && isRecord31(result.value)) {
|
|
121877
122050
|
return { ...result, value: { ...result.value, canCreateDirectory: true } };
|
|
121878
122051
|
}
|
|
121879
122052
|
const filteredResult = sessionListLookup !== void 0 ? result : filterSessionListProjections(params.endpoint, result);
|
|
@@ -121995,7 +122168,7 @@ var HarnessRemoteBridge = class {
|
|
|
121995
122168
|
const record14 = await this.schedule.create(sessionId, request2, AbortSignal.timeout(6e4));
|
|
121996
122169
|
return { ok: true, value: record14 };
|
|
121997
122170
|
} catch (error62) {
|
|
121998
|
-
const published =
|
|
122171
|
+
const published = isRecord31(error62) && typeof error62.code === "string" ? PUBLIC_SCHEDULE_ERRORS[error62.code] : void 0;
|
|
121999
122172
|
if (published === void 0) {
|
|
122000
122173
|
return {
|
|
122001
122174
|
ok: false,
|
|
@@ -122197,8 +122370,8 @@ var HarnessRemoteBridge = class {
|
|
|
122197
122370
|
const args = parsed.data.args;
|
|
122198
122371
|
const result = await this.gateway.dispatch(plugin ? "pluginManager/listPlugins" : "pluginManager/listBundles", { args: {} }, AbortSignal.timeout(6e4));
|
|
122199
122372
|
if (!result.ok || !Array.isArray(result.value)) throw new RpcError("PERMISSION_DENIED", "Cannot verify the Host plugin inventory.");
|
|
122200
|
-
const row = result.value.find((value) =>
|
|
122201
|
-
if (!
|
|
122373
|
+
const row = result.value.find((value) => isRecord31(value) && value[plugin ? "entryId" : "name"] === args[key]);
|
|
122374
|
+
if (!isRecord31(row) || row.readOnlyReason !== void 0) throw new RpcError("PERMISSION_DENIED", "The Host plugin cannot be changed remotely.");
|
|
122202
122375
|
if (remoteOwnedBundleRow(row, plugin)) {
|
|
122203
122376
|
throw new RpcError("PERMISSION_DENIED", "The Remote plugin can only be enabled or disabled locally on the Host.");
|
|
122204
122377
|
}
|
|
@@ -122218,8 +122391,8 @@ var HarnessRemoteBridge = class {
|
|
|
122218
122391
|
if (!parsed.success) throw new RpcError("INVALID_MESSAGE", "Invalid plugin update request.");
|
|
122219
122392
|
const result = await this.gateway.dispatch("pluginManager/listBundles", { args: {} }, AbortSignal.timeout(6e4));
|
|
122220
122393
|
if (!result.ok || !Array.isArray(result.value)) throw new RpcError("PERMISSION_DENIED", "Cannot verify the Host plugin inventory.");
|
|
122221
|
-
const row = result.value.find((value) =>
|
|
122222
|
-
if (!
|
|
122394
|
+
const row = result.value.find((value) => isRecord31(value) && value.name === parsed.data.args.name);
|
|
122395
|
+
if (!isRecord31(row) || row.readOnlyReason !== void 0 || row.updatable !== true) {
|
|
122223
122396
|
throw new RpcError("PERMISSION_DENIED", "The Host plugin cannot be updated remotely.");
|
|
122224
122397
|
}
|
|
122225
122398
|
if (remoteOwnedBundleRow(row, false)) {
|
|
@@ -122259,14 +122432,14 @@ var HarnessRemoteBridge = class {
|
|
|
122259
122432
|
for await (const value of source) {
|
|
122260
122433
|
if (signal.aborted) break;
|
|
122261
122434
|
if (sessionId !== void 0) this.messageFiles.observe(sessionId, value);
|
|
122262
|
-
if (historyFollow &&
|
|
122263
|
-
if (followSessionId === void 0 && value.type === "snapshot" &&
|
|
122435
|
+
if (historyFollow && isRecord31(value)) {
|
|
122436
|
+
if (followSessionId === void 0 && value.type === "snapshot" && isRecord31(value.header)) {
|
|
122264
122437
|
const headerId = typeof value.header.sessionId === "string" ? value.header.sessionId : typeof value.header.id === "string" ? value.header.id : void 0;
|
|
122265
122438
|
if (headerId !== void 0 && headerId.length > 0) followSessionId = headerId;
|
|
122266
122439
|
}
|
|
122267
|
-
if (followSessionId !== void 0 && value.type === "event" &&
|
|
122440
|
+
if (followSessionId !== void 0 && value.type === "event" && isRecord31(value.event)) {
|
|
122268
122441
|
const event2 = value.event;
|
|
122269
|
-
const data2 =
|
|
122442
|
+
const data2 = isRecord31(event2.data) ? event2.data : void 0;
|
|
122270
122443
|
const turnStr = extractHarnessTurnId(data2);
|
|
122271
122444
|
if (event2.type === "turn/start") {
|
|
122272
122445
|
this.turnDiff?.onTurnStarted(followSessionId, turnStr);
|
|
@@ -122276,7 +122449,7 @@ var HarnessRemoteBridge = class {
|
|
|
122276
122449
|
}
|
|
122277
122450
|
}
|
|
122278
122451
|
if (forwardedEvents) {
|
|
122279
|
-
if (this.sessionListCache !== void 0 &&
|
|
122452
|
+
if (this.sessionListCache !== void 0 && isRecord31(value) && value.type === "emit" && typeof value.event === "string" && SESSION_LIST_INVALIDATING_EVENTS.has(value.event)) {
|
|
122280
122453
|
this.sessionListCache.invalidate();
|
|
122281
122454
|
}
|
|
122282
122455
|
if (this.forwardedEventsObserver !== void 0) {
|
|
@@ -122351,7 +122524,7 @@ var HarnessRemoteBridge = class {
|
|
|
122351
122524
|
}
|
|
122352
122525
|
async resolveMessageFilePayload(payload, endpoint, signal) {
|
|
122353
122526
|
const deny = () => workspaceFileFailure("WORKSPACE_PATH_DENIED", "The message attachment is unavailable.", "outside-root");
|
|
122354
|
-
if (!
|
|
122527
|
+
if (!isRecord31(payload) || !isRecord31(payload.args)) throw deny();
|
|
122355
122528
|
const args = payload.args;
|
|
122356
122529
|
const sessionId = args.workspaceFileScopeId;
|
|
122357
122530
|
if (typeof sessionId !== "string" || !isMessageFilePath(args.path)) throw deny();
|
|
@@ -122377,9 +122550,9 @@ var HarnessRemoteBridge = class {
|
|
|
122377
122550
|
throw workspaceFileFailure("WORKSPACE_TOO_LARGE", "The requested workspace file is too large.", "too-large");
|
|
122378
122551
|
}
|
|
122379
122552
|
if (endpoint === "workspaceFiles/readBytes") {
|
|
122380
|
-
const options =
|
|
122553
|
+
const options = isRecord31(args.options) ? args.options : {};
|
|
122381
122554
|
if ("baseFile" in args || "baseFile" in options) throw deny();
|
|
122382
|
-
if (!
|
|
122555
|
+
if (!isRecord31(options.range) && !isRecord31(args.range)) {
|
|
122383
122556
|
if (this.supportsBinaryWorkspaceRead()) {
|
|
122384
122557
|
this.assertCompleteWorkspaceReadSize(reference.bytes);
|
|
122385
122558
|
} else if (reference.bytes > MAX_READ_BYTES2) {
|
|
@@ -122395,7 +122568,7 @@ var HarnessRemoteBridge = class {
|
|
|
122395
122568
|
return { ...payload, args: { ...args, path } };
|
|
122396
122569
|
}
|
|
122397
122570
|
async assertNativeWorkspaceFileCall(endpoint, payload, signal) {
|
|
122398
|
-
const rootPayload =
|
|
122571
|
+
const rootPayload = isRecord31(payload) ? payload : {};
|
|
122399
122572
|
const args = requestArgs(payload);
|
|
122400
122573
|
if ((endpoint === "workspaceFiles/list" || endpoint === "workspaceFiles/changes") && typeof args.path !== "string") {
|
|
122401
122574
|
throw new RpcError("INVALID_MESSAGE", "A workspace path is required.");
|
|
@@ -122408,7 +122581,7 @@ var HarnessRemoteBridge = class {
|
|
|
122408
122581
|
if (!sessionWorkspace) {
|
|
122409
122582
|
throw workspaceFileFailure("WORKSPACE_UNAVAILABLE", "The workspace is unavailable.", "authority-unavailable");
|
|
122410
122583
|
}
|
|
122411
|
-
const options =
|
|
122584
|
+
const options = isRecord31(args.options) ? args.options : void 0;
|
|
122412
122585
|
const rawBaseFile = endpoint === "workspaceFiles/readBytes" ? typeof options?.baseFile === "string" ? options.baseFile : typeof args.baseFile === "string" ? args.baseFile : void 0 : void 0;
|
|
122413
122586
|
if (endpoint === "workspaceFiles/readBytes") {
|
|
122414
122587
|
if (options !== void 0 && "baseFile" in options && options.baseFile !== void 0 && typeof options.baseFile !== "string") {
|
|
@@ -122443,8 +122616,8 @@ var HarnessRemoteBridge = class {
|
|
|
122443
122616
|
}
|
|
122444
122617
|
safeRel = await this.verifyWorkspacePathContainment(sessionWorkspace.root, path, endpoint, sessionWorkspace.cwd, completeByteRead);
|
|
122445
122618
|
}
|
|
122446
|
-
let finalArgs =
|
|
122447
|
-
if (
|
|
122619
|
+
let finalArgs = isRecord31(rootPayload.args) ? { ...rootPayload.args, path: safeRel } : { ...rootPayload, path: safeRel };
|
|
122620
|
+
if (isRecord31(finalArgs.options)) {
|
|
122448
122621
|
const { baseFile: _baseFile, ...restOptions } = finalArgs.options;
|
|
122449
122622
|
finalArgs.options = restOptions;
|
|
122450
122623
|
}
|
|
@@ -122456,11 +122629,11 @@ var HarnessRemoteBridge = class {
|
|
|
122456
122629
|
const boundedLength = Math.min(rawLength, MAX_READ_BYTES2);
|
|
122457
122630
|
const normalizedRange = { offset: offset2, length: boundedLength };
|
|
122458
122631
|
if (requiresWorkspaceChangePath(this.harnessVersion)) {
|
|
122459
|
-
finalArgs.options = { ...
|
|
122632
|
+
finalArgs.options = { ...isRecord31(finalArgs.options) ? finalArgs.options : {}, range: normalizedRange };
|
|
122460
122633
|
delete finalArgs.range;
|
|
122461
122634
|
} else {
|
|
122462
122635
|
finalArgs.range = normalizedRange;
|
|
122463
|
-
if (
|
|
122636
|
+
if (isRecord31(finalArgs.options)) {
|
|
122464
122637
|
finalArgs.options = { ...finalArgs.options, range: normalizedRange };
|
|
122465
122638
|
}
|
|
122466
122639
|
}
|
|
@@ -122469,7 +122642,7 @@ var HarnessRemoteBridge = class {
|
|
|
122469
122642
|
finalArgs.length = boundedLength;
|
|
122470
122643
|
}
|
|
122471
122644
|
}
|
|
122472
|
-
return
|
|
122645
|
+
return isRecord31(rootPayload.args) ? { ...rootPayload, args: finalArgs } : finalArgs;
|
|
122473
122646
|
}
|
|
122474
122647
|
async resolveWorkspaceRootForSession(sessionId, signal) {
|
|
122475
122648
|
signal.throwIfAborted();
|
|
@@ -122584,7 +122757,7 @@ var HarnessRemoteBridge = class {
|
|
|
122584
122757
|
};
|
|
122585
122758
|
function journalSessionId(payload) {
|
|
122586
122759
|
const address2 = requestArgs(payload).address;
|
|
122587
|
-
return
|
|
122760
|
+
return isRecord31(address2) && address2.kind === "session" && typeof address2.sessionId === "string" ? address2.sessionId : void 0;
|
|
122588
122761
|
}
|
|
122589
122762
|
function isPathOutside3(rel) {
|
|
122590
122763
|
if (rel === ".." || isAbsolute11(rel)) return true;
|
|
@@ -122594,21 +122767,21 @@ function isPathOutside3(rel) {
|
|
|
122594
122767
|
return rel.startsWith("../");
|
|
122595
122768
|
}
|
|
122596
122769
|
function isCompleteWorkspaceRead2(args) {
|
|
122597
|
-
const options =
|
|
122770
|
+
const options = isRecord31(args.options) ? args.options : void 0;
|
|
122598
122771
|
return !("range" in args || "offset" in args || "length" in args || options !== void 0 && "range" in options);
|
|
122599
122772
|
}
|
|
122600
122773
|
function byteOrLineRange2(args) {
|
|
122601
|
-
const options =
|
|
122602
|
-
if (options !== void 0 &&
|
|
122603
|
-
return
|
|
122774
|
+
const options = isRecord31(args.options) ? args.options : void 0;
|
|
122775
|
+
if (options !== void 0 && isRecord31(options.range)) return options.range;
|
|
122776
|
+
return isRecord31(args.range) ? args.range : args;
|
|
122604
122777
|
}
|
|
122605
122778
|
function normalizeWorkspaceChangesPayload(endpoint, payload, harnessVersion) {
|
|
122606
122779
|
if (endpoint !== "workspaceFiles/changes" || !requiresWorkspaceChangePath(harnessVersion)) return payload;
|
|
122607
|
-
if (!
|
|
122780
|
+
if (!isRecord31(payload) || !isRecord31(payload.args) || Object.hasOwn(payload.args, "path")) return payload;
|
|
122608
122781
|
return { ...payload, args: { ...payload.args, path: "." } };
|
|
122609
122782
|
}
|
|
122610
122783
|
function normalizeWorkspaceRequestPayload(endpoint, payload, harnessVersion) {
|
|
122611
|
-
if (!
|
|
122784
|
+
if (!isRecord31(payload) || !isRecord31(payload.args)) return payload;
|
|
122612
122785
|
const args = payload.args;
|
|
122613
122786
|
if (endpoint === "workspaceFiles/readBytes" && requiresWorkspaceChangePath(harnessVersion)) {
|
|
122614
122787
|
if (!Object.hasOwn(args, "range") || Object.hasOwn(args, "options")) return payload;
|
|
@@ -122622,10 +122795,10 @@ function normalizeWorkspaceRequestPayload(endpoint, payload, harnessVersion) {
|
|
|
122622
122795
|
return payload;
|
|
122623
122796
|
}
|
|
122624
122797
|
async function normalizeSessionAttachmentPayload(endpoint, payload, harnessVersion, gateway, signal) {
|
|
122625
|
-
if (endpoint !== "session/attachment" || !
|
|
122626
|
-
const request2 =
|
|
122798
|
+
if (endpoint !== "session/attachment" || !isRecord31(payload) || !isRecord31(payload.args)) return payload;
|
|
122799
|
+
const request2 = isRecord31(payload.args.request) ? payload.args.request : void 0;
|
|
122627
122800
|
if (request2 === void 0) return payload;
|
|
122628
|
-
const attachment =
|
|
122801
|
+
const attachment = isRecord31(request2.attachment) ? request2.attachment : void 0;
|
|
122629
122802
|
const attachmentId = attachment !== void 0 && typeof attachment.attachmentId === "string" ? attachment.attachmentId : typeof request2.attachmentId === "string" ? request2.attachmentId : void 0;
|
|
122630
122803
|
if (attachmentId === void 0) return payload;
|
|
122631
122804
|
if (!isDshV022OrNewer(harnessVersion)) {
|
|
@@ -122657,7 +122830,7 @@ async function findSessionAttachmentReference(gateway, sessionId, attachmentId,
|
|
|
122657
122830
|
const result = await gateway.dispatch("session/page", { args: { request: pageRequest } }, signal);
|
|
122658
122831
|
const reference = extractAttachmentReference(result, attachmentId);
|
|
122659
122832
|
if (reference !== void 0) return reference;
|
|
122660
|
-
if (result.ok === true &&
|
|
122833
|
+
if (result.ok === true && isRecord31(result.value)) {
|
|
122661
122834
|
if (result.value.hasMore === true && typeof result.value.beforeSeq === "number") {
|
|
122662
122835
|
beforeSeq = result.value.beforeSeq;
|
|
122663
122836
|
continue;
|
|
@@ -122681,7 +122854,7 @@ function extractAttachmentReference(result, attachmentId) {
|
|
|
122681
122854
|
const value = result.value;
|
|
122682
122855
|
let records;
|
|
122683
122856
|
if (Array.isArray(value)) records = value;
|
|
122684
|
-
else if (
|
|
122857
|
+
else if (isRecord31(value)) {
|
|
122685
122858
|
if (Array.isArray(value.records)) records = value.records;
|
|
122686
122859
|
else if (Array.isArray(value.events)) records = value.events;
|
|
122687
122860
|
}
|
|
@@ -122702,7 +122875,7 @@ function findImageReference(value, attachmentId, depth) {
|
|
|
122702
122875
|
return void 0;
|
|
122703
122876
|
}
|
|
122704
122877
|
const block = value;
|
|
122705
|
-
const candidate =
|
|
122878
|
+
const candidate = isRecord31(block.attachment) ? block.attachment : block;
|
|
122706
122879
|
const candidateId = typeof candidate.attachmentId === "string" ? candidate.attachmentId : void 0;
|
|
122707
122880
|
if (candidateId === attachmentId && isCompleteImageReference(candidate)) {
|
|
122708
122881
|
return {
|
|
@@ -122807,27 +122980,27 @@ function needsDirectoryFallback(result) {
|
|
|
122807
122980
|
function filterRemotePluginInventory(endpoint, result) {
|
|
122808
122981
|
if (!result.ok) return result;
|
|
122809
122982
|
const isRemote = (value) => typeof value === "string" && /^(?:ds-harness-remote|dsh-remote)(?:\/|$)/.test(value);
|
|
122810
|
-
const filterEntries = (entries) => entries.filter((entry) => !
|
|
122983
|
+
const filterEntries = (entries) => entries.filter((entry) => !isRecord31(entry) || !isRemote(entry.moduleName));
|
|
122811
122984
|
if (endpoint === "pluginManager/listPlugins" && Array.isArray(result.value)) {
|
|
122812
122985
|
return { ...result, value: filterEntries(result.value) };
|
|
122813
122986
|
}
|
|
122814
122987
|
if (endpoint === "pluginManager/listBundles" && Array.isArray(result.value)) {
|
|
122815
|
-
return { ...result, value: result.value.filter((bundle) => !
|
|
122988
|
+
return { ...result, value: result.value.filter((bundle) => !isRecord31(bundle) || !isRemote(bundle.name)).map((bundle) => isRecord31(bundle) && Array.isArray(bundle.rows) ? { ...bundle, rows: filterEntries(bundle.rows) } : bundle) };
|
|
122816
122989
|
}
|
|
122817
|
-
if (endpoint === "pluginInventory/list" &&
|
|
122990
|
+
if (endpoint === "pluginInventory/list" && isRecord31(result.value) && Array.isArray(result.value.entries)) {
|
|
122818
122991
|
return { ...result, value: { ...result.value, entries: filterEntries(result.value.entries) } };
|
|
122819
122992
|
}
|
|
122820
122993
|
return result;
|
|
122821
122994
|
}
|
|
122822
122995
|
function requestArgs(payload) {
|
|
122823
122996
|
const root2 = record13(payload);
|
|
122824
|
-
const args =
|
|
122997
|
+
const args = isRecord31(root2.args) ? root2.args : root2;
|
|
122825
122998
|
return record13(args.request ?? args._request ?? args);
|
|
122826
122999
|
}
|
|
122827
123000
|
function record13(value) {
|
|
122828
|
-
return
|
|
123001
|
+
return isRecord31(value) ? value : {};
|
|
122829
123002
|
}
|
|
122830
|
-
function
|
|
123003
|
+
function isRecord31(value) {
|
|
122831
123004
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
122832
123005
|
}
|
|
122833
123006
|
function isCompactSnapshot(value) {
|
|
@@ -122836,7 +123009,7 @@ function isCompactSnapshot(value) {
|
|
|
122836
123009
|
function remoteOwnedBundleRow(row, plugin) {
|
|
122837
123010
|
const remoteModule = (value) => typeof value === "string" && /^(?:ds-harness-remote|dsh-remote)(?:\/|$)/.test(value);
|
|
122838
123011
|
if (remoteModule(plugin ? row.moduleName : row.name)) return true;
|
|
122839
|
-
return !plugin && (!Array.isArray(row.rows) || row.rows.some((value) => !
|
|
123012
|
+
return !plugin && (!Array.isArray(row.rows) || row.rows.some((value) => !isRecord31(value) || remoteModule(value.moduleName)) || Array.isArray(row.overrides) && row.overrides.some((value) => remoteModule(value)));
|
|
122840
123013
|
}
|
|
122841
123014
|
function extractHarnessTurnId(data2) {
|
|
122842
123015
|
if (data2 === void 0) return void 0;
|
|
@@ -122846,7 +123019,7 @@ function extractHarnessTurnId(data2) {
|
|
|
122846
123019
|
return void 0;
|
|
122847
123020
|
}
|
|
122848
123021
|
function mapHarnessTurnEndOutcome(reason) {
|
|
122849
|
-
const kind = typeof reason === "string" ? reason :
|
|
123022
|
+
const kind = typeof reason === "string" ? reason : isRecord31(reason) && typeof reason.kind === "string" ? reason.kind : "completed";
|
|
122850
123023
|
if (kind === "error" || kind === "failed") return "failed";
|
|
122851
123024
|
if (kind === "interrupted" || kind === "cancelled" || kind === "canceled" || kind === "aborted" || kind === "stopped") {
|
|
122852
123025
|
return "stopped";
|
|
@@ -122870,11 +123043,11 @@ var MAX_CAUSE_DEPTH = 8;
|
|
|
122870
123043
|
function requestIndexKey(ownerDeviceId, sessionId, requestId2) {
|
|
122871
123044
|
return `${ownerDeviceId}\0${sessionId}\0${requestId2}`;
|
|
122872
123045
|
}
|
|
122873
|
-
function
|
|
123046
|
+
function isRecord32(value) {
|
|
122874
123047
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
122875
123048
|
}
|
|
122876
123049
|
function commandIdOf(result) {
|
|
122877
|
-
if (result?.ok !== true || !
|
|
123050
|
+
if (result?.ok !== true || !isRecord32(result.value)) return void 0;
|
|
122878
123051
|
return typeof result.value.commandId === "string" ? result.value.commandId : void 0;
|
|
122879
123052
|
}
|
|
122880
123053
|
var RemoteCompactionOperations = class {
|
|
@@ -123266,7 +123439,7 @@ function isAbortThrown(thrown, reason) {
|
|
|
123266
123439
|
current = "cause" in current ? current.cause : void 0;
|
|
123267
123440
|
continue;
|
|
123268
123441
|
}
|
|
123269
|
-
if (
|
|
123442
|
+
if (isRecord32(current)) {
|
|
123270
123443
|
if (typeof current.code === "string" && ABORT_CODE_PATTERN.test(current.code)) return true;
|
|
123271
123444
|
if (typeof current.message === "string" && matchesSignalReason(current.message, reason)) return true;
|
|
123272
123445
|
current = current.cause;
|
|
@@ -123281,13 +123454,13 @@ function matchesSignalReason(message, reason) {
|
|
|
123281
123454
|
return reasonMessage !== void 0 && reasonMessage !== "" && message.includes(reasonMessage);
|
|
123282
123455
|
}
|
|
123283
123456
|
function isCommandSuccess(result) {
|
|
123284
|
-
if (result.ok !== true || !
|
|
123285
|
-
const command =
|
|
123457
|
+
if (result.ok !== true || !isRecord32(result.value)) return false;
|
|
123458
|
+
const command = isRecord32(result.value.result) ? result.value.result : void 0;
|
|
123286
123459
|
return command?.kind === "success";
|
|
123287
123460
|
}
|
|
123288
123461
|
function commandText2(result) {
|
|
123289
|
-
if (result.ok !== true || !
|
|
123290
|
-
const command =
|
|
123462
|
+
if (result.ok !== true || !isRecord32(result.value)) return void 0;
|
|
123463
|
+
const command = isRecord32(result.value.result) ? result.value.result : void 0;
|
|
123291
123464
|
return typeof command?.text === "string" && command.text.trim() !== "" ? command.text : void 0;
|
|
123292
123465
|
}
|
|
123293
123466
|
function sanitizeMessage(message) {
|
|
@@ -123306,13 +123479,13 @@ function waitWithTimeout(promise2, ms) {
|
|
|
123306
123479
|
});
|
|
123307
123480
|
}
|
|
123308
123481
|
function readCompactionConfirmation(result, acceptedAt, commandId) {
|
|
123309
|
-
if (result.ok !== true || !
|
|
123482
|
+
if (result.ok !== true || !isRecord32(result.value)) return { kind: "unknown" };
|
|
123310
123483
|
const records = Array.isArray(result.value.records) ? result.value.records : [];
|
|
123311
123484
|
const legacy = Array.isArray(result.value.events) ? result.value.events : [];
|
|
123312
123485
|
const events = [];
|
|
123313
123486
|
for (const record14 of [...records, ...legacy]) {
|
|
123314
|
-
const event2 =
|
|
123315
|
-
if (
|
|
123487
|
+
const event2 = isRecord32(record14) && isRecord32(record14.event) ? record14.event : record14;
|
|
123488
|
+
if (isRecord32(event2) && typeof event2.type === "string") events.push(event2);
|
|
123316
123489
|
}
|
|
123317
123490
|
if (events.length === 0) return { kind: "unknown" };
|
|
123318
123491
|
const matchedCommandRun = commandId === void 0 ? latestCompactCommandId(events, acceptedAt) : hasCompactCommandRun(events, commandId) ? commandId : void 0;
|
|
@@ -123320,34 +123493,34 @@ function readCompactionConfirmation(result, acceptedAt, commandId) {
|
|
|
123320
123493
|
if (resolvedCommandId === void 0) return { kind: "not-yet" };
|
|
123321
123494
|
const end = [...events].reverse().find((event2) => {
|
|
123322
123495
|
if (event2.type !== "compaction/end") return false;
|
|
123323
|
-
const data3 =
|
|
123496
|
+
const data3 = isRecord32(event2.data) ? event2.data : void 0;
|
|
123324
123497
|
return data3?.sourceCommandId === resolvedCommandId;
|
|
123325
123498
|
});
|
|
123326
123499
|
if (end === void 0) {
|
|
123327
123500
|
const hasCompactionStart = events.some((event2) => {
|
|
123328
123501
|
if (event2.type !== "compaction/start") return false;
|
|
123329
|
-
const data3 =
|
|
123502
|
+
const data3 = isRecord32(event2.data) ? event2.data : void 0;
|
|
123330
123503
|
return data3?.sourceCommandId === resolvedCommandId;
|
|
123331
123504
|
});
|
|
123332
123505
|
if (hasCompactionStart) return { kind: "not-yet", started: true };
|
|
123333
123506
|
if (matchedCommandRun !== void 0) return { kind: "not-yet", commandRecorded: true };
|
|
123334
123507
|
return { kind: "not-yet" };
|
|
123335
123508
|
}
|
|
123336
|
-
const data2 =
|
|
123509
|
+
const data2 = isRecord32(end.data) ? end.data : {};
|
|
123337
123510
|
const error62 = data2.error === void 0 ? void 0 : errorText(data2.error);
|
|
123338
123511
|
return error62 === void 0 ? { kind: "finished" } : { kind: "finished", error: error62 };
|
|
123339
123512
|
}
|
|
123340
123513
|
function hasCompactCommandRun(events, commandId) {
|
|
123341
123514
|
return events.some((event2) => {
|
|
123342
123515
|
if (event2.type !== "command/run") return false;
|
|
123343
|
-
const data2 =
|
|
123516
|
+
const data2 = isRecord32(event2.data) ? event2.data : void 0;
|
|
123344
123517
|
return data2?.name === "compact" && data2.commandId === commandId;
|
|
123345
123518
|
});
|
|
123346
123519
|
}
|
|
123347
123520
|
function latestCompactCommandId(events, acceptedAt) {
|
|
123348
123521
|
for (const event2 of [...events].reverse()) {
|
|
123349
123522
|
if (event2.type !== "command/run") continue;
|
|
123350
|
-
const data2 =
|
|
123523
|
+
const data2 = isRecord32(event2.data) ? event2.data : void 0;
|
|
123351
123524
|
if (data2?.name !== "compact" || typeof data2.commandId !== "string") continue;
|
|
123352
123525
|
const time3 = typeof event2.time === "number" ? event2.time : 0;
|
|
123353
123526
|
if (time3 !== 0 && time3 < acceptedAt - 5e3) continue;
|
|
@@ -123357,7 +123530,7 @@ function latestCompactCommandId(events, acceptedAt) {
|
|
|
123357
123530
|
}
|
|
123358
123531
|
function errorText(error62) {
|
|
123359
123532
|
if (typeof error62 === "string") return sanitizeMessage(error62);
|
|
123360
|
-
if (
|
|
123533
|
+
if (isRecord32(error62)) {
|
|
123361
123534
|
const message = error62.message ?? error62.error ?? error62.reason;
|
|
123362
123535
|
if (typeof message === "string" && message.trim() !== "") return sanitizeMessage(message);
|
|
123363
123536
|
try {
|
|
@@ -124218,23 +124391,69 @@ function parseRouteKey(key) {
|
|
|
124218
124391
|
return { provider, model };
|
|
124219
124392
|
}
|
|
124220
124393
|
function grantAllows(policy, provider, model) {
|
|
124221
|
-
|
|
124222
|
-
return policy.models.includes(`${provider}::${model}`) || policy.models.includes(`${provider}::*`);
|
|
124394
|
+
return policy.models.includes(`${provider}::${model}`);
|
|
124223
124395
|
}
|
|
124224
124396
|
function allowedRoutes(policy) {
|
|
124225
|
-
return
|
|
124397
|
+
return new Set(policy.models);
|
|
124226
124398
|
}
|
|
124227
124399
|
var ModelShareHost = class {
|
|
124228
|
-
constructor(llm, store, logger2, deviceId = "", concurrency = { active: 0 }, controlAllowed = () => true) {
|
|
124400
|
+
constructor(llm, store, logger2, deviceId = "", concurrency = { active: 0 }, controlAllowed = () => true, attachments) {
|
|
124229
124401
|
this.llm = llm;
|
|
124230
124402
|
this.store = store;
|
|
124231
124403
|
this.logger = logger2;
|
|
124232
124404
|
this.deviceId = deviceId;
|
|
124233
124405
|
this.concurrency = concurrency;
|
|
124234
124406
|
this.controlAllowed = controlAllowed;
|
|
124407
|
+
this.attachments = attachments;
|
|
124235
124408
|
}
|
|
124236
124409
|
streams = /* @__PURE__ */ new Map();
|
|
124237
124410
|
pending = /* @__PURE__ */ new Map();
|
|
124411
|
+
/**
|
|
124412
|
+
* `model.share.attach` — store one image on this machine and return its
|
|
124413
|
+
* reference.
|
|
124414
|
+
*
|
|
124415
|
+
* Image attachment ids are handles into one machine's storage, so a borrower
|
|
124416
|
+
* cannot cite its own copy in a request this Host executes. The bytes are
|
|
124417
|
+
* copied here and the borrower rewrites the message to cite the returned
|
|
124418
|
+
* reference.
|
|
124419
|
+
*
|
|
124420
|
+
* This accepts writes, so it is gated exactly like lending itself and adds no
|
|
124421
|
+
* path of its own: the host-control switch must allow remote control *and*
|
|
124422
|
+
* sharing must be on with at least one shared model, otherwise a peer could
|
|
124423
|
+
* use this machine as image storage without ever borrowing a model.
|
|
124424
|
+
*
|
|
124425
|
+
* One image per call, bounded by the protocol limit. There is deliberately no
|
|
124426
|
+
* cumulative budget: the attachment store exposes no delete, so a cap could
|
|
124427
|
+
* not reclaim anything it refused, and it would only block legitimate
|
|
124428
|
+
* multi-image turns.
|
|
124429
|
+
*/
|
|
124430
|
+
async attach(params) {
|
|
124431
|
+
if (!this.lendingAllowed()) {
|
|
124432
|
+
throw new RpcError("PERMISSION_DENIED", "This device does not allow remote control, so it accepts no shared attachments.");
|
|
124433
|
+
}
|
|
124434
|
+
const store = this.attachments;
|
|
124435
|
+
if (store === void 0) throw new RpcError("FEATURE_NOT_SUPPORTED", "This Host cannot store borrowed images.");
|
|
124436
|
+
const { host } = await this.store.read();
|
|
124437
|
+
if (host.models.length === 0) {
|
|
124438
|
+
throw new RpcError("PERMISSION_DENIED", "This Host is not sharing any models, so it accepts no shared attachments.");
|
|
124439
|
+
}
|
|
124440
|
+
const request2 = attachRequestSchema.parse(params);
|
|
124441
|
+
const data2 = Buffer.from(request2.data, "base64");
|
|
124442
|
+
if (data2.byteLength === 0) throw new RpcError("INVALID_MESSAGE", "The image is empty.");
|
|
124443
|
+
const ref = await store.saveImage({ data: data2, mediaType: request2.mediaType });
|
|
124444
|
+
this.logger?.info("model-share: attachment stored", { bytes: data2.byteLength });
|
|
124445
|
+
return {
|
|
124446
|
+
image: {
|
|
124447
|
+
attachmentId: String(ref.attachmentId),
|
|
124448
|
+
mediaType: String(ref.mediaType),
|
|
124449
|
+
bytes: Number(ref.bytes),
|
|
124450
|
+
width: Number(ref.width),
|
|
124451
|
+
height: Number(ref.height),
|
|
124452
|
+
...typeof ref.name === "string" ? { name: ref.name } : {},
|
|
124453
|
+
...ref.originalDimensions === void 0 ? {} : { originalDimensions: ref.originalDimensions }
|
|
124454
|
+
}
|
|
124455
|
+
};
|
|
124456
|
+
}
|
|
124238
124457
|
/** Whether remote devices may use this Host's resources at all. */
|
|
124239
124458
|
lendingAllowed() {
|
|
124240
124459
|
try {
|
|
@@ -124252,18 +124471,7 @@ var ModelShareHost = class {
|
|
|
124252
124471
|
async listShared(_deviceId) {
|
|
124253
124472
|
if (!this.lendingAllowed()) return { enabled: false, models: [] };
|
|
124254
124473
|
const { host } = await this.store.read();
|
|
124255
|
-
|
|
124256
|
-
const allowed = allowedRoutes(host);
|
|
124257
|
-
const wildcardProviders = /* @__PURE__ */ new Set();
|
|
124258
|
-
const exactRoutes = /* @__PURE__ */ new Set();
|
|
124259
|
-
for (const route of allowed) {
|
|
124260
|
-
const separator = route.indexOf(ROUTE_SEPARATOR);
|
|
124261
|
-
if (separator <= 0) continue;
|
|
124262
|
-
const provider = route.slice(0, separator);
|
|
124263
|
-
const model = route.slice(separator + ROUTE_SEPARATOR.length);
|
|
124264
|
-
if (model === "*") wildcardProviders.add(provider);
|
|
124265
|
-
else exactRoutes.add(route);
|
|
124266
|
-
}
|
|
124474
|
+
const exactRoutes = allowedRoutes(host);
|
|
124267
124475
|
const models = [];
|
|
124268
124476
|
const seen = /* @__PURE__ */ new Set();
|
|
124269
124477
|
const emit2 = async (provider, entry) => {
|
|
@@ -124285,10 +124493,7 @@ var ModelShareHost = class {
|
|
|
124285
124493
|
});
|
|
124286
124494
|
if (parsed.success) models.push(parsed.data);
|
|
124287
124495
|
};
|
|
124288
|
-
const providers = [
|
|
124289
|
-
...wildcardProviders,
|
|
124290
|
-
...Array.from(exactRoutes).map((route) => route.slice(0, route.indexOf(ROUTE_SEPARATOR)))
|
|
124291
|
-
])];
|
|
124496
|
+
const providers = [...new Set([...exactRoutes].map((route) => route.slice(0, route.indexOf(ROUTE_SEPARATOR))))];
|
|
124292
124497
|
const catalogs = /* @__PURE__ */ new Map();
|
|
124293
124498
|
let incomplete = false;
|
|
124294
124499
|
await Promise.all(providers.map(async (provider) => {
|
|
@@ -124302,9 +124507,6 @@ var ModelShareHost = class {
|
|
|
124302
124507
|
});
|
|
124303
124508
|
}
|
|
124304
124509
|
}));
|
|
124305
|
-
for (const provider of wildcardProviders) {
|
|
124306
|
-
for (const entry of catalogs.get(provider) ?? []) await emit2(provider, entry);
|
|
124307
|
-
}
|
|
124308
124510
|
for (const route of exactRoutes) {
|
|
124309
124511
|
const separator = route.indexOf(ROUTE_SEPARATOR);
|
|
124310
124512
|
const provider = route.slice(0, separator);
|
|
@@ -124312,7 +124514,7 @@ var ModelShareHost = class {
|
|
|
124312
124514
|
const entry = (catalogs.get(provider) ?? []).find((candidate) => candidate.id === model);
|
|
124313
124515
|
if (entry !== void 0) await emit2(provider, entry);
|
|
124314
124516
|
}
|
|
124315
|
-
return { enabled:
|
|
124517
|
+
return { enabled: exactRoutes.size > 0, models, ...incomplete ? { incomplete: true } : {} };
|
|
124316
124518
|
}
|
|
124317
124519
|
async safeResolve(provider, entry) {
|
|
124318
124520
|
try {
|
|
@@ -124563,7 +124765,7 @@ var ModelShareHost = class {
|
|
|
124563
124765
|
* disturb replies using another.
|
|
124564
124766
|
*/
|
|
124565
124767
|
applyPolicy(policy) {
|
|
124566
|
-
if (
|
|
124768
|
+
if (policy.models.length === 0) return this.revokeAll();
|
|
124567
124769
|
let revoked = 0;
|
|
124568
124770
|
for (const [streamId, active2] of [...this.streams]) {
|
|
124569
124771
|
if (grantAllows(policy, active2.route.provider, active2.route.model)) continue;
|
|
@@ -124622,6 +124824,8 @@ var ModelShareHost = class {
|
|
|
124622
124824
|
return this.drain(deviceId, params);
|
|
124623
124825
|
case "model.share.close":
|
|
124624
124826
|
return this.close(deviceId, params);
|
|
124827
|
+
case "model.share.attach":
|
|
124828
|
+
return this.attach(params);
|
|
124625
124829
|
default:
|
|
124626
124830
|
throw new RpcError("METHOD_NOT_FOUND", "The requested model-share method does not exist.");
|
|
124627
124831
|
}
|
|
@@ -128634,6 +128838,20 @@ function explainModelGone(hostName, hostId, modelId) {
|
|
|
128634
128838
|
}
|
|
128635
128839
|
|
|
128636
128840
|
// packages/plugin/src/model-share/adapter.ts
|
|
128841
|
+
function hasRetainedImage(message) {
|
|
128842
|
+
if (message === null || typeof message !== "object") return false;
|
|
128843
|
+
const content = message.content;
|
|
128844
|
+
if (!Array.isArray(content)) return false;
|
|
128845
|
+
return content.some((block) => block !== null && typeof block === "object" && block.type === "image" && block.offloaded !== true);
|
|
128846
|
+
}
|
|
128847
|
+
function isTerminalChunk(chunk) {
|
|
128848
|
+
return chunk !== null && typeof chunk === "object" && chunk.type === "finish";
|
|
128849
|
+
}
|
|
128850
|
+
function isAttachmentGone(chunk) {
|
|
128851
|
+
if (!isTerminalChunk(chunk)) return false;
|
|
128852
|
+
const reason = chunk.reason;
|
|
128853
|
+
return reason?.kind === "error" && reason.failure?.code === "ATTACHMENT_NOT_FOUND";
|
|
128854
|
+
}
|
|
128637
128855
|
var streamCounter = 0;
|
|
128638
128856
|
function nextStreamId() {
|
|
128639
128857
|
streamCounter += 1;
|
|
@@ -128735,7 +128953,115 @@ var RemoteModelAdapter = class extends LlmAdapter {
|
|
|
128735
128953
|
if (parseRouteKey(model) !== void 0) return model;
|
|
128736
128954
|
return this.findModel(model)?.id;
|
|
128737
128955
|
}
|
|
128956
|
+
/**
|
|
128957
|
+
* Host-minted reference per local attachment id, so one image is copied once
|
|
128958
|
+
* even when the same attachment appears in many turns.
|
|
128959
|
+
*/
|
|
128960
|
+
remappedAttachments = /* @__PURE__ */ new Map();
|
|
128961
|
+
/**
|
|
128962
|
+
* Drop cached Host references so the next attempt re-copies the bytes.
|
|
128963
|
+
*
|
|
128964
|
+
* The Host stores images in a content-addressed attachment store it may
|
|
128965
|
+
* reclaim; a cached reference then points at an object that no longer exists,
|
|
128966
|
+
* and every later call on the same conversation would fail. Clearing makes
|
|
128967
|
+
* the next attempt re-upload, which content addressing collapses back onto
|
|
128968
|
+
* the same object when it does still exist.
|
|
128969
|
+
*/
|
|
128970
|
+
forgetRemappedAttachments() {
|
|
128971
|
+
if (this.remappedAttachments.size === 0) return;
|
|
128972
|
+
const count = this.remappedAttachments.size;
|
|
128973
|
+
this.remappedAttachments.clear();
|
|
128974
|
+
this.logger?.info("model-share: dropped cached attachment references", { count });
|
|
128975
|
+
}
|
|
128976
|
+
/**
|
|
128977
|
+
* Replace local image references with ones the lending Host can resolve.
|
|
128978
|
+
*
|
|
128979
|
+
* A message's image block carries an `ImageAttachmentRef` whose
|
|
128980
|
+
* `attachmentId` is an opaque handle into *this* machine's attachment store.
|
|
128981
|
+
* Forwarding it unchanged makes the Host's model request fail with
|
|
128982
|
+
* `ATTACHMENT_NOT_FOUND`, because the Host holds no such object. The transport
|
|
128983
|
+
* therefore copies the bytes through the Host's own upload route and answers
|
|
128984
|
+
* with the reference *it* minted, which is what the block must cite.
|
|
128985
|
+
*
|
|
128986
|
+
* Only images that still take part in the request are copied: a block marked
|
|
128987
|
+
* `offloaded` was already replaced by a text placeholder upstream, so sending
|
|
128988
|
+
* its bytes would be waste.
|
|
128989
|
+
*/
|
|
128990
|
+
async remapImageAttachments(messages, signal) {
|
|
128991
|
+
const copy = this.transport.copyImage?.bind(this.transport);
|
|
128992
|
+
if (copy === void 0) return messages;
|
|
128993
|
+
if (!messages.some(hasRetainedImage)) return messages;
|
|
128994
|
+
let rewritten;
|
|
128995
|
+
for (const [messageIndex, message] of messages.entries()) {
|
|
128996
|
+
signal?.throwIfAborted();
|
|
128997
|
+
if (message === null || typeof message !== "object") continue;
|
|
128998
|
+
const content = message.content;
|
|
128999
|
+
if (!Array.isArray(content)) continue;
|
|
129000
|
+
let nextContent;
|
|
129001
|
+
for (const [blockIndex, block] of content.entries()) {
|
|
129002
|
+
if (block === null || typeof block !== "object") continue;
|
|
129003
|
+
const image = block;
|
|
129004
|
+
if (image.type !== "image" || image.offloaded === true) continue;
|
|
129005
|
+
const ref = image.attachment;
|
|
129006
|
+
if (ref === void 0 || typeof ref.attachmentId !== "string") continue;
|
|
129007
|
+
let hosted = this.remappedAttachments.get(ref.attachmentId);
|
|
129008
|
+
if (hosted === void 0) {
|
|
129009
|
+
signal?.throwIfAborted();
|
|
129010
|
+
hosted = await copy(ref, signal);
|
|
129011
|
+
this.remappedAttachments.set(ref.attachmentId, hosted);
|
|
129012
|
+
}
|
|
129013
|
+
nextContent ??= [...content];
|
|
129014
|
+
nextContent[blockIndex] = {
|
|
129015
|
+
...image,
|
|
129016
|
+
// Use the Host's reference *whole*. `saveImage` normalizes the image,
|
|
129017
|
+
// so its `mediaType`, `bytes`, `width` and `height` can legitimately
|
|
129018
|
+
// differ from ours; `readImage` validates them, and a spliced
|
|
129019
|
+
// reference would fail that check later.
|
|
129020
|
+
attachment: hosted
|
|
129021
|
+
};
|
|
129022
|
+
}
|
|
129023
|
+
if (nextContent !== void 0) {
|
|
129024
|
+
rewritten ??= [...messages];
|
|
129025
|
+
rewritten[messageIndex] = { ...message, content: nextContent };
|
|
129026
|
+
}
|
|
129027
|
+
}
|
|
129028
|
+
return rewritten ?? messages;
|
|
129029
|
+
}
|
|
129030
|
+
/**
|
|
129031
|
+
* Run one borrowed call, retrying once if the Host reports that an image it
|
|
129032
|
+
* was told to use no longer exists.
|
|
129033
|
+
*
|
|
129034
|
+
* Cached references are keyed by this machine's attachment id, and the Host's
|
|
129035
|
+
* stored copy may be reclaimed. When that happens the Host fails the call with
|
|
129036
|
+
* `ATTACHMENT_NOT_FOUND`; dropping the cache and retrying re-uploads, and
|
|
129037
|
+
* content addressing keeps it a no-op when the object still exists. Without
|
|
129038
|
+
* this the whole conversation would fail on every later turn.
|
|
129039
|
+
*
|
|
129040
|
+
* A retry only happens when the first attempt produced nothing but that
|
|
129041
|
+
* failure, so a partially delivered reply is never duplicated.
|
|
129042
|
+
*/
|
|
128738
129043
|
async *stream(options) {
|
|
129044
|
+
let retried = false;
|
|
129045
|
+
for (; ; ) {
|
|
129046
|
+
const produced = [];
|
|
129047
|
+
for await (const chunk of this.streamOnce(options)) {
|
|
129048
|
+
produced.push(chunk);
|
|
129049
|
+
if (!isTerminalChunk(chunk)) {
|
|
129050
|
+
for (const buffered of produced) yield buffered;
|
|
129051
|
+
produced.length = 0;
|
|
129052
|
+
}
|
|
129053
|
+
}
|
|
129054
|
+
if (produced.length === 0) return;
|
|
129055
|
+
if (!retried && produced.length === 1 && isAttachmentGone(produced[0])) {
|
|
129056
|
+
retried = true;
|
|
129057
|
+
this.forgetRemappedAttachments();
|
|
129058
|
+
continue;
|
|
129059
|
+
}
|
|
129060
|
+
for (const chunk of produced) yield chunk;
|
|
129061
|
+
return;
|
|
129062
|
+
}
|
|
129063
|
+
}
|
|
129064
|
+
async *streamOnce(options) {
|
|
128739
129065
|
const route = this.resolveRoute(options.model);
|
|
128740
129066
|
if (route === void 0) {
|
|
128741
129067
|
this.transport.onStale?.("model-missing");
|
|
@@ -128757,10 +129083,16 @@ var RemoteModelAdapter = class extends LlmAdapter {
|
|
|
128757
129083
|
}
|
|
128758
129084
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
128759
129085
|
try {
|
|
129086
|
+
const messages = options.messages.some(hasRetainedImage) ? await this.remapImageAttachments(options.messages, signal) : options.messages;
|
|
129087
|
+
if (aborted2 || signal?.aborted === true) {
|
|
129088
|
+
if (opened) await this.transport.close(streamId).catch(() => void 0);
|
|
129089
|
+
yield { type: "finish", reason: { kind: "aborted", failure: { code: "ABORTED", message: "The call was cancelled by the borrower." } } };
|
|
129090
|
+
return;
|
|
129091
|
+
}
|
|
128760
129092
|
await this.transport.open({
|
|
128761
129093
|
modelId: route,
|
|
128762
129094
|
streamId,
|
|
128763
|
-
messages
|
|
129095
|
+
messages,
|
|
128764
129096
|
...options.system === void 0 ? {} : { system: options.system },
|
|
128765
129097
|
...options.tools === void 0 ? {} : { tools: options.tools },
|
|
128766
129098
|
...options.temperature === void 0 ? {} : { temperature: options.temperature },
|
|
@@ -128913,6 +129245,7 @@ var BorrowerRuntime = class {
|
|
|
128913
129245
|
hostName,
|
|
128914
129246
|
...transport.onStale === void 0 ? {} : { onStale: transport.onStale },
|
|
128915
129247
|
list: () => transport.list(),
|
|
129248
|
+
...transport.copyImage === void 0 ? {} : { copyImage: (ref, signal) => transport.copyImage(ref, signal) },
|
|
128916
129249
|
open: (request2) => transport.open(request2),
|
|
128917
129250
|
drain: (streamId, waitMs) => transport.drain(streamId, waitMs),
|
|
128918
129251
|
close: (streamId) => transport.close(streamId),
|
|
@@ -128957,7 +129290,7 @@ var BorrowerRuntime = class {
|
|
|
128957
129290
|
this.releaseIfUnregistered(hostId, transport);
|
|
128958
129291
|
return;
|
|
128959
129292
|
}
|
|
128960
|
-
const selected =
|
|
129293
|
+
const selected = models;
|
|
128961
129294
|
if (incomplete && this.registered.has(hostId)) {
|
|
128962
129295
|
this.states.set(hostId, { outcome: "registered" });
|
|
128963
129296
|
return;
|
|
@@ -129033,6 +129366,9 @@ var BorrowerRuntime = class {
|
|
|
129033
129366
|
// the adapter is what notices a missing model or a dropped connection.
|
|
129034
129367
|
onStale: (reason) => holder.current.onStale?.(reason),
|
|
129035
129368
|
list: () => holder.current.list(),
|
|
129369
|
+
// Follows `holder.current`, which is rebound on every reconcile, so a
|
|
129370
|
+
// transport replaced later still routes image copying correctly.
|
|
129371
|
+
copyImage: (ref, signal) => holder.current.copyImage?.(ref, signal) ?? Promise.reject(new Error("This Host transport cannot copy images.")),
|
|
129036
129372
|
open: async (request2) => {
|
|
129037
129373
|
const link3 = holder.current;
|
|
129038
129374
|
holder.streams.set(request2.streamId, link3);
|
|
@@ -129255,58 +129591,12 @@ async function setHostSharedModels(store, models) {
|
|
|
129255
129591
|
store: next
|
|
129256
129592
|
};
|
|
129257
129593
|
}
|
|
129258
|
-
async function setHostGrant(store, provider, models) {
|
|
129259
|
-
const trimmedProvider = provider.trim();
|
|
129260
|
-
if (trimmedProvider === "") return { ok: false, message: "A provider id is required." };
|
|
129261
|
-
const trimmedModels = models.map((model) => model.trim()).filter((model) => model !== "");
|
|
129262
|
-
const added = trimmedModels.length === 0 ? [`${trimmedProvider}::*`] : trimmedModels.map((model) => `${trimmedProvider}::${model}`);
|
|
129263
|
-
const next = await store.update((current) => ({
|
|
129264
|
-
...current,
|
|
129265
|
-
host: { ...current.host, models: [.../* @__PURE__ */ new Set([...current.host.models, ...added])] }
|
|
129266
|
-
}));
|
|
129267
|
-
return {
|
|
129268
|
-
ok: true,
|
|
129269
|
-
message: `Shared ${trimmedProvider}: ${trimmedModels.length === 0 ? "all models" : trimmedModels.join(", ")}.`,
|
|
129270
|
-
store: next
|
|
129271
|
-
};
|
|
129272
|
-
}
|
|
129273
|
-
async function setHostEnabled(store, enabled) {
|
|
129274
|
-
const next = await store.update((current) => ({ ...current, host: { ...current.host, enabled } }));
|
|
129275
|
-
return {
|
|
129276
|
-
ok: true,
|
|
129277
|
-
message: enabled ? "This Host now shares the selected models." : "This Host shares nothing.",
|
|
129278
|
-
store: next
|
|
129279
|
-
};
|
|
129280
|
-
}
|
|
129281
129594
|
async function setBorrowSource(store, hostId, enabled, hostName) {
|
|
129282
129595
|
const trimmed = hostId.trim();
|
|
129283
129596
|
if (trimmed === "") return { ok: false, message: "A Host device id is required." };
|
|
129284
|
-
const next = await store.update((current) => ({
|
|
129285
|
-
...current,
|
|
129286
|
-
borrower: {
|
|
129287
|
-
...current.borrower,
|
|
129288
|
-
sources: {
|
|
129289
|
-
...current.borrower.sources,
|
|
129290
|
-
[trimmed]: {
|
|
129291
|
-
enabled,
|
|
129292
|
-
models: current.borrower.sources[trimmed]?.models ?? [],
|
|
129293
|
-
...hostName === void 0 || hostName.trim() === "" ? current.borrower.sources[trimmed]?.hostName === void 0 ? {} : { hostName: current.borrower.sources[trimmed].hostName } : { hostName: hostName.trim() }
|
|
129294
|
-
}
|
|
129295
|
-
}
|
|
129296
|
-
}
|
|
129297
|
-
}));
|
|
129298
|
-
return {
|
|
129299
|
-
ok: true,
|
|
129300
|
-
message: enabled ? `This machine will borrow from ${trimmed} on the next sync.` : `Stopped borrowing from ${trimmed}.`,
|
|
129301
|
-
store: next
|
|
129302
|
-
};
|
|
129303
|
-
}
|
|
129304
|
-
async function setBorrowModels(store, hostId, modelKeys) {
|
|
129305
|
-
const trimmed = hostId.trim();
|
|
129306
|
-
if (trimmed === "") return { ok: false, message: "A Host device id is required." };
|
|
129307
|
-
const keys = modelKeys.map((key) => key.trim()).filter((key) => key !== "");
|
|
129308
129597
|
const next = await store.update((current) => {
|
|
129309
129598
|
const existing = current.borrower.sources[trimmed];
|
|
129599
|
+
const name2 = hostName?.trim();
|
|
129310
129600
|
return {
|
|
129311
129601
|
...current,
|
|
129312
129602
|
borrower: {
|
|
@@ -129314,9 +129604,8 @@ async function setBorrowModels(store, hostId, modelKeys) {
|
|
|
129314
129604
|
sources: {
|
|
129315
129605
|
...current.borrower.sources,
|
|
129316
129606
|
[trimmed]: {
|
|
129317
|
-
enabled
|
|
129318
|
-
|
|
129319
|
-
...existing?.hostName === void 0 ? {} : { hostName: existing.hostName }
|
|
129607
|
+
enabled,
|
|
129608
|
+
...name2 === void 0 || name2 === "" ? existing?.hostName === void 0 ? {} : { hostName: existing.hostName } : { hostName: name2 }
|
|
129320
129609
|
}
|
|
129321
129610
|
}
|
|
129322
129611
|
}
|
|
@@ -129324,30 +129613,30 @@ async function setBorrowModels(store, hostId, modelKeys) {
|
|
|
129324
129613
|
});
|
|
129325
129614
|
return {
|
|
129326
129615
|
ok: true,
|
|
129327
|
-
message:
|
|
129616
|
+
message: enabled ? `This machine will borrow from ${trimmed} on the next sync.` : `Stopped borrowing from ${trimmed}.`,
|
|
129328
129617
|
store: next
|
|
129329
129618
|
};
|
|
129330
129619
|
}
|
|
129331
129620
|
function describeStore(store) {
|
|
129332
129621
|
const lines = [];
|
|
129333
|
-
lines.push(
|
|
129334
|
-
lines.push(
|
|
129622
|
+
lines.push("access: governed by the host-control switch (whether this machine may be controlled)");
|
|
129623
|
+
lines.push(`maxConcurrent=${store.host.maxConcurrent}`);
|
|
129335
129624
|
if (store.host.models.length === 0) {
|
|
129336
|
-
lines.push("
|
|
129625
|
+
lines.push("sharing no models");
|
|
129337
129626
|
} else {
|
|
129338
129627
|
const models = store.host.models.map((route) => {
|
|
129339
129628
|
const separator = route.indexOf("::");
|
|
129340
129629
|
return separator <= 0 ? route : `${route.slice(0, separator)}/${route.slice(separator + 2)}`;
|
|
129341
129630
|
});
|
|
129342
|
-
lines.push(`
|
|
129631
|
+
lines.push(`sharing ${models.length} model(s): ${models.join(", ")}`);
|
|
129343
129632
|
}
|
|
129344
129633
|
const sources = Object.entries(store.borrower.sources);
|
|
129345
129634
|
if (sources.length === 0) {
|
|
129346
|
-
lines.push("borrowing: no
|
|
129635
|
+
lines.push("borrowing: no Hosts enabled");
|
|
129347
129636
|
} else {
|
|
129348
129637
|
lines.push("borrowing:");
|
|
129349
129638
|
for (const [hostId, source] of sources) {
|
|
129350
|
-
lines.push(` ${source.hostName ?? hostId}: ${source.enabled ? "enabled" : "disabled"}
|
|
129639
|
+
lines.push(` ${source.hostName ?? hostId}: ${source.enabled ? "enabled" : "disabled"}`);
|
|
129351
129640
|
}
|
|
129352
129641
|
}
|
|
129353
129642
|
return lines.join("\n");
|
|
@@ -129888,21 +130177,21 @@ var LocalPluginUpgrade = class {
|
|
|
129888
130177
|
};
|
|
129889
130178
|
function bundleUpdatable(listed, packageName) {
|
|
129890
130179
|
if (!Array.isArray(listed)) return false;
|
|
129891
|
-
return listed.some((row) =>
|
|
130180
|
+
return listed.some((row) => isRecord33(row) && row.name === packageName && (row.update === "registry" || row.update === void 0 && row.updatable === true));
|
|
129892
130181
|
}
|
|
129893
130182
|
function classifyUpdateResult(result) {
|
|
129894
|
-
if (!
|
|
130183
|
+
if (!isRecord33(result) || !isRecord33(result.result)) return { status: "failed", message: "update-failed" };
|
|
129895
130184
|
const application = result.result.application;
|
|
129896
130185
|
if (application === "applied" || application === "restart-required") return { status: "started" };
|
|
129897
130186
|
return { status: "failed", message: failureMessage(result.result.error) };
|
|
129898
130187
|
}
|
|
129899
130188
|
function failureMessage(error62) {
|
|
129900
|
-
if (!
|
|
130189
|
+
if (!isRecord33(error62)) return "update-failed";
|
|
129901
130190
|
const code = typeof error62.code === "string" && error62.code.length > 0 && error62.code.length <= 80 ? error62.code : "update-failed";
|
|
129902
130191
|
const diagnostic = typeof error62.diagnostic === "string" ? error62.diagnostic.replace(/\s+/g, " ").trim().slice(0, 180) : "";
|
|
129903
130192
|
return diagnostic === "" ? code : `${code}: ${diagnostic}`;
|
|
129904
130193
|
}
|
|
129905
|
-
function
|
|
130194
|
+
function isRecord33(value) {
|
|
129906
130195
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
129907
130196
|
}
|
|
129908
130197
|
|
|
@@ -129966,20 +130255,20 @@ function createOwnerPeerFactory(ctx, constructor, connection) {
|
|
|
129966
130255
|
return createStandInOwnerPeer(ctx, interactions);
|
|
129967
130256
|
};
|
|
129968
130257
|
}
|
|
129969
|
-
function
|
|
130258
|
+
function isRecord34(value) {
|
|
129970
130259
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
129971
130260
|
}
|
|
129972
130261
|
function isLiveAbortSignal(value) {
|
|
129973
130262
|
return typeof value === "object" && value !== null && typeof value.aborted === "boolean" && typeof value.addEventListener === "function" && value.aborted === false;
|
|
129974
130263
|
}
|
|
129975
130264
|
function isValidOwnerPeer(candidate, expectedInteractions) {
|
|
129976
|
-
if (!
|
|
130265
|
+
if (!isRecord34(candidate)) return false;
|
|
129977
130266
|
if (!isLiveAbortSignal(candidate.signal)) return false;
|
|
129978
|
-
if (!
|
|
130267
|
+
if (!isRecord34(candidate.principal) || candidate.principal.kind !== "owner") return false;
|
|
129979
130268
|
return candidate.interactions === expectedInteractions;
|
|
129980
130269
|
}
|
|
129981
130270
|
function tryDisposePeer(candidate) {
|
|
129982
|
-
if (!
|
|
130271
|
+
if (!isRecord34(candidate) || typeof candidate.dispose !== "function") return;
|
|
129983
130272
|
try {
|
|
129984
130273
|
const result = candidate.dispose.call(candidate);
|
|
129985
130274
|
if (result !== null && (typeof result === "object" || typeof result === "function") && typeof result.then === "function") {
|
|
@@ -129989,7 +130278,7 @@ function tryDisposePeer(candidate) {
|
|
|
129989
130278
|
}
|
|
129990
130279
|
}
|
|
129991
130280
|
function isDisposedContext(ctx) {
|
|
129992
|
-
if (!
|
|
130281
|
+
if (!isRecord34(ctx) || !isRecord34(ctx.fiber)) return false;
|
|
129993
130282
|
const fiber = ctx.fiber;
|
|
129994
130283
|
return fiber.uid === null || fiber.disposed === true || fiber.state === 4 || fiber.state === 5;
|
|
129995
130284
|
}
|
|
@@ -130003,7 +130292,7 @@ function createStandInOwnerPeer(ctx, interactions) {
|
|
|
130003
130292
|
}
|
|
130004
130293
|
};
|
|
130005
130294
|
let detach;
|
|
130006
|
-
if (
|
|
130295
|
+
if (isRecord34(ctx) && typeof ctx.effect === "function") {
|
|
130007
130296
|
try {
|
|
130008
130297
|
const stop = ctx.effect(
|
|
130009
130298
|
() => () => {
|
|
@@ -130257,12 +130546,9 @@ async function modelShareCommand(args, runtime) {
|
|
|
130257
130546
|
write2(runtime.stdout, [
|
|
130258
130547
|
"Usage: ds-harness-remote model-share <command>",
|
|
130259
130548
|
"",
|
|
130260
|
-
" show
|
|
130261
|
-
"
|
|
130262
|
-
"
|
|
130263
|
-
" host-grant <provider> [model...] Share a provider (empty model list = all models).",
|
|
130264
|
-
" borrow-enable <hostId> [true|false] Opt into one lending Host.",
|
|
130265
|
-
" borrow-models <hostId> [modelKey...] Narrow which shared models appear locally.",
|
|
130549
|
+
" show Print the current sharing and borrowing settings.",
|
|
130550
|
+
" share [modelKey...] Set which models are shared (empty shares none).",
|
|
130551
|
+
" borrow <hostId> [true|false] Turn borrowing from one Host on or off.",
|
|
130266
130552
|
"",
|
|
130267
130553
|
"Who may borrow is not configured here: it follows the host-control switch",
|
|
130268
130554
|
"(whether this machine may be controlled remotely).",
|
|
@@ -130283,34 +130569,16 @@ async function modelShareCommand(args, runtime) {
|
|
|
130283
130569
|
}
|
|
130284
130570
|
return help();
|
|
130285
130571
|
}
|
|
130286
|
-
if (action === "
|
|
130287
|
-
const enabled = rest[0] !== "false";
|
|
130288
|
-
return report(await setHostEnabled(store, enabled));
|
|
130289
|
-
}
|
|
130290
|
-
if (action === "host-share") {
|
|
130572
|
+
if (action === "share") {
|
|
130291
130573
|
return report(await setHostSharedModels(store, rest));
|
|
130292
130574
|
}
|
|
130293
|
-
if (action === "
|
|
130294
|
-
const [provider, ...models] = rest;
|
|
130295
|
-
if (provider === void 0 || provider.trim() === "") {
|
|
130296
|
-
throw new CliUsageError("Usage: ds-harness-remote model-share host-grant <provider> [model...]");
|
|
130297
|
-
}
|
|
130298
|
-
return report(await setHostGrant(store, provider, models));
|
|
130299
|
-
}
|
|
130300
|
-
if (action === "borrow-enable") {
|
|
130575
|
+
if (action === "borrow") {
|
|
130301
130576
|
const [hostId, enabledArg, hostName] = rest;
|
|
130302
130577
|
if (hostId === void 0 || hostId.trim() === "") {
|
|
130303
|
-
throw new CliUsageError("Usage: ds-harness-remote model-share borrow
|
|
130578
|
+
throw new CliUsageError("Usage: ds-harness-remote model-share borrow <hostId> [true|false] [hostName]");
|
|
130304
130579
|
}
|
|
130305
130580
|
return report(await setBorrowSource(store, hostId, enabledArg !== "false", hostName));
|
|
130306
130581
|
}
|
|
130307
|
-
if (action === "borrow-models") {
|
|
130308
|
-
const [hostId, ...models] = rest;
|
|
130309
|
-
if (hostId === void 0 || hostId.trim() === "") {
|
|
130310
|
-
throw new CliUsageError("Usage: ds-harness-remote model-share borrow-models <hostId> [modelKey...]");
|
|
130311
|
-
}
|
|
130312
|
-
return report(await setBorrowModels(store, hostId, models));
|
|
130313
|
-
}
|
|
130314
130582
|
throw new CliUsageError(`Unknown model-share command: ${action}`);
|
|
130315
130583
|
}
|
|
130316
130584
|
async function hostContext(runtime) {
|
|
@@ -130689,13 +130957,15 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
|
|
|
130689
130957
|
const lendingFactory = modelShareEnabled ? (deviceId) => {
|
|
130690
130958
|
const llm = ctx.get("llm", false);
|
|
130691
130959
|
if (llm === void 0) return void 0;
|
|
130960
|
+
const attachmentStore = safeGetService2(ctx, "attachments") ?? safeGetService2(rootContext(ctx), "attachments");
|
|
130692
130961
|
const host = new ModelShareHost(
|
|
130693
130962
|
llm,
|
|
130694
130963
|
activeStore,
|
|
130695
130964
|
logger2,
|
|
130696
130965
|
deviceId,
|
|
130697
130966
|
lendingConcurrency,
|
|
130698
|
-
() => nextConfig.hostControl?.enabled !== false
|
|
130967
|
+
() => nextConfig.hostControl?.enabled !== false,
|
|
130968
|
+
attachmentStore
|
|
130699
130969
|
);
|
|
130700
130970
|
modelShareHosts.add(host);
|
|
130701
130971
|
host.setClosedHook(() => {
|
|
@@ -130747,6 +131017,10 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
|
|
|
130747
131017
|
logger2,
|
|
130748
131018
|
nextRuntime
|
|
130749
131019
|
);
|
|
131020
|
+
const attachmentReader = safeGetService2(ctx, "attachments") ?? safeGetService2(rootContext(ctx), "attachments");
|
|
131021
|
+
if (typeof attachmentReader?.readImage === "function") {
|
|
131022
|
+
nextClientRuntime.modelShareImageReader = (ref, signal) => attachmentReader.readImage(ref, signal);
|
|
131023
|
+
}
|
|
130750
131024
|
}
|
|
130751
131025
|
const llmRegistry = ctx.get("llm", false);
|
|
130752
131026
|
if (modelShareEnabled && llmRegistry !== void 0 && nextClientRuntime !== void 0) {
|