@agentknight/sdk 0.9.49 → 0.9.50
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/LICENSE +201 -201
- package/dist/chunks/{acp-adapter-2ZBDMHA3.js → acp-adapter-GUM5LZFV.js} +3 -3
- package/dist/chunks/{chunk-R5LSWHRH.js → chunk-4XVACOU5.js} +1 -1
- package/dist/chunks/{chunk-BDKVGENQ.js → chunk-BMMKEB6V.js} +819 -605
- package/dist/chunks/{chunk-6VEMXJW4.js → chunk-FEH4GODE.js} +1 -1
- package/dist/chunks/{chunk-YFLDTX2W.js → chunk-HHI2UYWK.js} +2 -2
- package/dist/chunks/{chunk-2QHOQXOR.js → chunk-LDF3XNVN.js} +1 -1
- package/dist/chunks/{chunk-IU5NTPMF.js → chunk-RPVK6HQV.js} +11 -0
- package/dist/chunks/{chunk-7HZ5UZSC.js → chunk-SNKTDPG5.js} +1 -1
- package/dist/chunks/{chunk-H6FG5CCS.js → chunk-UXIZLEZV.js} +2 -2
- package/dist/chunks/{chunk-RX7VGB3T.js → chunk-ZVPUOCY5.js} +3 -3
- package/dist/chunks/{claude-adapter-WCIDCXOP.js → claude-adapter-2LMBCBBB.js} +3 -3
- package/dist/chunks/{codex-adapter-PYAYTZSJ.js → codex-adapter-5OWQVTGF.js} +3 -3
- package/dist/chunks/{copilot-adapter-RSL5GJYO.js → copilot-adapter-WJQ2XNI5.js} +6 -6
- package/dist/chunks/{managed-agent-adapter-CXWPNKSZ.js → managed-agent-adapter-Q2YBBAWL.js} +5 -5
- package/dist/chunks/{pi-adapter-WGHEJ5WA.js → pi-adapter-YN44NYIN.js} +3 -3
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +8 -6
- package/dist/index.d.ts +40 -4
- package/dist/index.js +795 -621
- package/dist/runtime.js +2 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -4,19 +4,20 @@ import {
|
|
|
4
4
|
PeerChatRequestSchema,
|
|
5
5
|
PeerChatResultSchema,
|
|
6
6
|
validateDataDirectory
|
|
7
|
-
} from "./chunks/chunk-
|
|
7
|
+
} from "./chunks/chunk-SNKTDPG5.js";
|
|
8
8
|
import {
|
|
9
9
|
DeviceIdentitySchema,
|
|
10
10
|
LEGACY_CLIENT_STATE_DIRECTORY,
|
|
11
11
|
SessionImageRelayUrlSchema,
|
|
12
12
|
SessionImagesConfigSchema,
|
|
13
|
-
codingAgentPresentation
|
|
14
|
-
|
|
13
|
+
codingAgentPresentation,
|
|
14
|
+
relayRequestToken
|
|
15
|
+
} from "./chunks/chunk-RPVK6HQV.js";
|
|
15
16
|
import {
|
|
16
17
|
AgentSelectionSchema,
|
|
17
18
|
assertSelectionSnapshotFits,
|
|
18
19
|
supportsAgentSelection
|
|
19
|
-
} from "./chunks/chunk-
|
|
20
|
+
} from "./chunks/chunk-HHI2UYWK.js";
|
|
20
21
|
import {
|
|
21
22
|
ConversationNormalizer,
|
|
22
23
|
LiveTimelineProjection,
|
|
@@ -38,11 +39,11 @@ import {
|
|
|
38
39
|
resolveGitProjectIdentity,
|
|
39
40
|
sessionRestoreFailure,
|
|
40
41
|
validateOperationResponse
|
|
41
|
-
} from "./chunks/chunk-
|
|
42
|
+
} from "./chunks/chunk-ZVPUOCY5.js";
|
|
42
43
|
import {
|
|
43
44
|
GROUP_CHAT_MAX_TURNS,
|
|
44
45
|
GroupChatError
|
|
45
|
-
} from "./chunks/chunk-
|
|
46
|
+
} from "./chunks/chunk-UXIZLEZV.js";
|
|
46
47
|
import {
|
|
47
48
|
detectClaude,
|
|
48
49
|
detectCopilot,
|
|
@@ -53,7 +54,7 @@ import {
|
|
|
53
54
|
assistantPreview,
|
|
54
55
|
isContentfulAssistant,
|
|
55
56
|
userPreview
|
|
56
|
-
} from "./chunks/chunk-
|
|
57
|
+
} from "./chunks/chunk-FEH4GODE.js";
|
|
57
58
|
import {
|
|
58
59
|
AgentModelListingError,
|
|
59
60
|
AgentSessionRenameError,
|
|
@@ -64,7 +65,7 @@ import {
|
|
|
64
65
|
UnsupportedAgentOperationError,
|
|
65
66
|
captureResearchAccess,
|
|
66
67
|
captureWorkbenchAccess
|
|
67
|
-
} from "./chunks/chunk-
|
|
68
|
+
} from "./chunks/chunk-4XVACOU5.js";
|
|
68
69
|
import {
|
|
69
70
|
A2aRelayRequestSchema,
|
|
70
71
|
A2aRelayResponseSchema,
|
|
@@ -88,9 +89,12 @@ import {
|
|
|
88
89
|
InteractionRespondResultSchema,
|
|
89
90
|
MACHINE_HELLO_SDK_COMPAT_VERSION,
|
|
90
91
|
MANAGED_SESSION_SELECTION_CAPABILITY,
|
|
92
|
+
MOBILE_AUTHORIZATION_URI_HOST,
|
|
91
93
|
MOBILE_CONNECTED_REPLAY_CAPABILITY,
|
|
92
94
|
MOBILE_INTERACTION_PERSISTENCE_CAPABILITY,
|
|
93
95
|
MachineHelloSchema,
|
|
96
|
+
MobileAuthorizationCreateResultSchema,
|
|
97
|
+
MobileAuthorizationListResultSchema,
|
|
94
98
|
MobileConnectedSchema,
|
|
95
99
|
MobileDisconnectedSchema,
|
|
96
100
|
OperationAckSchema,
|
|
@@ -250,12 +254,12 @@ import {
|
|
|
250
254
|
sessionCommunicationError,
|
|
251
255
|
sessionCommunicationOperationCapability,
|
|
252
256
|
workbenchCapability
|
|
253
|
-
} from "./chunks/chunk-
|
|
257
|
+
} from "./chunks/chunk-BMMKEB6V.js";
|
|
254
258
|
|
|
255
259
|
// src/initialize.ts
|
|
256
260
|
import { createHash as createHash16 } from "node:crypto";
|
|
257
261
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
258
|
-
import { z as
|
|
262
|
+
import { z as z11 } from "zod";
|
|
259
263
|
|
|
260
264
|
// src/coding-agent-factory.ts
|
|
261
265
|
import { resolve } from "node:path";
|
|
@@ -270,7 +274,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
|
|
|
270
274
|
switch (engine.kind) {
|
|
271
275
|
case "managed": {
|
|
272
276
|
if (owner === void 0) throw new Error("Managed coding agents require the PC owner identity");
|
|
273
|
-
const { ManagedCodingAgentAdapter } = await import("./chunks/managed-agent-adapter-
|
|
277
|
+
const { ManagedCodingAgentAdapter } = await import("./chunks/managed-agent-adapter-Q2YBBAWL.js");
|
|
274
278
|
return new ManagedCodingAgentAdapter({
|
|
275
279
|
dataDirectory: config.dataDirectory,
|
|
276
280
|
owner,
|
|
@@ -327,7 +331,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
|
|
|
327
331
|
});
|
|
328
332
|
}
|
|
329
333
|
case "copilot": {
|
|
330
|
-
const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-
|
|
334
|
+
const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-WJQ2XNI5.js");
|
|
331
335
|
if (owner !== void 0) {
|
|
332
336
|
return new GithubCopilotAdapter(void 0, void 0, void 0, {
|
|
333
337
|
dataDirectory: config.dataDirectory,
|
|
@@ -347,13 +351,13 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
|
|
|
347
351
|
}
|
|
348
352
|
case "pi": {
|
|
349
353
|
assertPiRuntimeSupported();
|
|
350
|
-
const { PiCodingAgentAdapter } = await import("./chunks/pi-adapter-
|
|
354
|
+
const { PiCodingAgentAdapter } = await import("./chunks/pi-adapter-YN44NYIN.js");
|
|
351
355
|
return new PiCodingAgentAdapter(
|
|
352
356
|
engine.agentDirectory === void 0 ? {} : { agentDirectory: resolve(engine.agentDirectory) }
|
|
353
357
|
);
|
|
354
358
|
}
|
|
355
359
|
case "codex": {
|
|
356
|
-
const { CodexCodingAgentAdapter } = await import("./chunks/codex-adapter-
|
|
360
|
+
const { CodexCodingAgentAdapter } = await import("./chunks/codex-adapter-5OWQVTGF.js");
|
|
357
361
|
return new CodexCodingAgentAdapter({
|
|
358
362
|
dataDirectory: resolve(config.dataDirectory, "coding-agents"),
|
|
359
363
|
...owner === void 0 ? {} : { nativeSessionOwner: owner },
|
|
@@ -362,7 +366,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
|
|
|
362
366
|
});
|
|
363
367
|
}
|
|
364
368
|
case "claude": {
|
|
365
|
-
const { ClaudeCodingAgentAdapter } = await import("./chunks/claude-adapter-
|
|
369
|
+
const { ClaudeCodingAgentAdapter } = await import("./chunks/claude-adapter-2LMBCBBB.js");
|
|
366
370
|
return new ClaudeCodingAgentAdapter({
|
|
367
371
|
dataDirectory: resolve(config.dataDirectory, "coding-agents"),
|
|
368
372
|
...owner === void 0 ? {} : { nativeSessionOwner: owner },
|
|
@@ -370,7 +374,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
|
|
|
370
374
|
});
|
|
371
375
|
}
|
|
372
376
|
case "acp": {
|
|
373
|
-
const { AcpCodingAgentAdapter } = await import("./chunks/acp-adapter-
|
|
377
|
+
const { AcpCodingAgentAdapter } = await import("./chunks/acp-adapter-GUM5LZFV.js");
|
|
374
378
|
return new AcpCodingAgentAdapter({
|
|
375
379
|
command: engine.command,
|
|
376
380
|
args: engine.args,
|
|
@@ -793,8 +797,10 @@ async function requestPairingUri(config, identity2, contentKey) {
|
|
|
793
797
|
`${config.relayUrl.replace(/\/+$/, "")}/auth/pairing`,
|
|
794
798
|
{
|
|
795
799
|
method: "POST",
|
|
800
|
+
redirect: "error",
|
|
801
|
+
credentials: "omit",
|
|
796
802
|
headers: {
|
|
797
|
-
authorization: `Bearer ${config
|
|
803
|
+
authorization: `Bearer ${await relayRequestToken(config)}`,
|
|
798
804
|
"content-type": "application/json"
|
|
799
805
|
},
|
|
800
806
|
body: JSON.stringify(payload)
|
|
@@ -820,8 +826,10 @@ async function requestPairingUri(config, identity2, contentKey) {
|
|
|
820
826
|
async function requestPairingStatus(config, identity2, statusId) {
|
|
821
827
|
const response = await fetch(`${config.relayUrl.replace(/\/+$/, "")}/auth/pairing/status`, {
|
|
822
828
|
method: "POST",
|
|
829
|
+
redirect: "error",
|
|
830
|
+
credentials: "omit",
|
|
823
831
|
headers: {
|
|
824
|
-
authorization: `Bearer ${config
|
|
832
|
+
authorization: `Bearer ${await relayRequestToken(config)}`,
|
|
825
833
|
"content-type": "application/json"
|
|
826
834
|
},
|
|
827
835
|
body: JSON.stringify({ userId: config.userId, machineId: identity2.machineId, statusId }),
|
|
@@ -834,6 +842,78 @@ async function requestPairingStatus(config, identity2, statusId) {
|
|
|
834
842
|
return result.state;
|
|
835
843
|
}
|
|
836
844
|
|
|
845
|
+
// src/mobile-clients.ts
|
|
846
|
+
import { constants, createPublicKey, publicEncrypt } from "node:crypto";
|
|
847
|
+
import { z as z2 } from "zod";
|
|
848
|
+
var SuccessSchema = z2.object({ ok: z2.literal(true) });
|
|
849
|
+
async function request(config, operation, input) {
|
|
850
|
+
const response = await fetch(`${config.relayUrl.replace(/\/+$/u, "")}/auth/mobile-clients/${operation}`, {
|
|
851
|
+
method: "POST",
|
|
852
|
+
redirect: "error",
|
|
853
|
+
credentials: "omit",
|
|
854
|
+
headers: { authorization: `Bearer ${await relayRequestToken(config)}`, "content-type": "application/json" },
|
|
855
|
+
body: JSON.stringify(input),
|
|
856
|
+
signal: AbortSignal.timeout(1e4)
|
|
857
|
+
});
|
|
858
|
+
if (!response.ok) throw new Error(response.status === 404 ? "Relay must be upgraded to support PC-approved mobile clients." : `Client authorization returned HTTP ${response.status}; refresh the client list before retrying.`);
|
|
859
|
+
return response.json();
|
|
860
|
+
}
|
|
861
|
+
var ApprovedPairingProvider = class extends CachedPairingProvider {
|
|
862
|
+
constructor(config, identity2, contentKey) {
|
|
863
|
+
const scope = { userId: config.userId, machineId: identity2.machineId };
|
|
864
|
+
super(async () => {
|
|
865
|
+
const ticket = MobileAuthorizationCreateResultSchema.parse(await request(config, "create", {
|
|
866
|
+
...scope,
|
|
867
|
+
machineName: identity2.machineName,
|
|
868
|
+
stableDeviceId: identity2.stableDeviceId,
|
|
869
|
+
keyId: contentKey.keyId
|
|
870
|
+
}));
|
|
871
|
+
const uri = new URL(`agentknight://${MOBILE_AUTHORIZATION_URI_HOST}`);
|
|
872
|
+
for (const [key, value] of Object.entries({
|
|
873
|
+
v: "1",
|
|
874
|
+
relay: config.relayUrl.replace(/\/+$/u, ""),
|
|
875
|
+
machine: identity2.machineId,
|
|
876
|
+
request: ticket.requestId,
|
|
877
|
+
code: ticket.code
|
|
878
|
+
})) uri.searchParams.set(key, value);
|
|
879
|
+
return { uri: uri.toString(), expiresAt: ticket.expiresAt, statusId: ticket.requestId };
|
|
880
|
+
}, void 0, (id) => requestPairingStatus(config, identity2, id));
|
|
881
|
+
this.config = config;
|
|
882
|
+
this.identity = identity2;
|
|
883
|
+
this.contentKey = contentKey;
|
|
884
|
+
}
|
|
885
|
+
config;
|
|
886
|
+
identity;
|
|
887
|
+
contentKey;
|
|
888
|
+
async enableApproval() {
|
|
889
|
+
SuccessSchema.parse(await request(this.config, "enable", this.scope()));
|
|
890
|
+
}
|
|
891
|
+
async listClients() {
|
|
892
|
+
return MobileAuthorizationListResultSchema.parse(await request(this.config, "list", this.scope())).clients;
|
|
893
|
+
}
|
|
894
|
+
async decideClient(requestId, action, expectedPublicKey) {
|
|
895
|
+
const client = (await this.listClients()).find((item) => item.requestId === requestId);
|
|
896
|
+
if (client === void 0 || client.publicKey !== expectedPublicKey) throw new Error("Client identity changed; refresh the page.");
|
|
897
|
+
const key = createPublicKey({ key: Buffer.from(client.publicKey, "base64url"), format: "der", type: "spki" });
|
|
898
|
+
if (key.asymmetricKeyType !== "rsa" || key.asymmetricKeyDetails?.modulusLength !== 2048) {
|
|
899
|
+
throw new Error("Unsupported mobile identity key.");
|
|
900
|
+
}
|
|
901
|
+
SuccessSchema.parse(await request(this.config, "decide", {
|
|
902
|
+
...this.scope(),
|
|
903
|
+
requestId,
|
|
904
|
+
action,
|
|
905
|
+
...action !== "approve" ? {} : { encryptedKey: publicEncrypt({
|
|
906
|
+
key,
|
|
907
|
+
padding: constants.RSA_PKCS1_OAEP_PADDING,
|
|
908
|
+
oaepHash: "sha1"
|
|
909
|
+
}, this.contentKey.bytes).toString("base64url") }
|
|
910
|
+
}));
|
|
911
|
+
}
|
|
912
|
+
scope() {
|
|
913
|
+
return { userId: this.config.userId, machineId: this.identity.machineId };
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
|
|
837
917
|
// src/pc-agent.ts
|
|
838
918
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
839
919
|
|
|
@@ -842,7 +922,7 @@ import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypt
|
|
|
842
922
|
import { lstat as lstat3, realpath as realpath3, stat as stat3 } from "node:fs/promises";
|
|
843
923
|
import { isAbsolute as isAbsolute3, join as join4 } from "node:path";
|
|
844
924
|
import { gunzipSync } from "node:zlib";
|
|
845
|
-
import { z as
|
|
925
|
+
import { z as z4 } from "zod";
|
|
846
926
|
|
|
847
927
|
// src/session-directory.ts
|
|
848
928
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -992,7 +1072,7 @@ var SessionDirectoryLister = class {
|
|
|
992
1072
|
// src/session-file.ts
|
|
993
1073
|
import { isUtf8 } from "node:buffer";
|
|
994
1074
|
import { createHash as createHash3 } from "node:crypto";
|
|
995
|
-
import { constants } from "node:fs";
|
|
1075
|
+
import { constants as constants2 } from "node:fs";
|
|
996
1076
|
import { lstat as lstat2, open, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
997
1077
|
import { extname, isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
998
1078
|
import { promisify } from "node:util";
|
|
@@ -1383,7 +1463,7 @@ var SessionFileReader = class {
|
|
|
1383
1463
|
if (before.size > BigInt(maxOriginalBytes)) fail2("FILE_TOO_LARGE");
|
|
1384
1464
|
const extension = extname(path).toLowerCase();
|
|
1385
1465
|
const resourceType = resource ? resourceMediaType(extension) : void 0;
|
|
1386
|
-
const handle = await open(target,
|
|
1466
|
+
const handle = await open(target, constants2.O_RDONLY | (constants2.O_NOFOLLOW ?? 0) | (constants2.O_NONBLOCK ?? 0));
|
|
1387
1467
|
try {
|
|
1388
1468
|
const opened = await handle.stat({ bigint: true });
|
|
1389
1469
|
const includeChangeTime = process.platform !== "win32";
|
|
@@ -1489,24 +1569,24 @@ function sessionCommunicationOperation(options) {
|
|
|
1489
1569
|
return {
|
|
1490
1570
|
operation: options.operation,
|
|
1491
1571
|
version: options.version,
|
|
1492
|
-
execute: async (
|
|
1493
|
-
const data = options.schema.safeParse(
|
|
1572
|
+
execute: async (request2) => {
|
|
1573
|
+
const data = options.schema.safeParse(request2.data);
|
|
1494
1574
|
if (!data.success) {
|
|
1495
1575
|
recordOperationFailure(data.error, "validate-request");
|
|
1496
|
-
return sessionCommunicationError(
|
|
1576
|
+
return sessionCommunicationError(request2, {
|
|
1497
1577
|
code: "INVALID_OPERATION_DATA",
|
|
1498
1578
|
message: "The operation payload is invalid"
|
|
1499
1579
|
});
|
|
1500
1580
|
}
|
|
1501
1581
|
let phase = "handle";
|
|
1502
1582
|
try {
|
|
1503
|
-
const value = await options.handle(data.data,
|
|
1583
|
+
const value = await options.handle(data.data, request2);
|
|
1504
1584
|
phase = "validate-response";
|
|
1505
1585
|
const result = SessionCommunicationDataSchema.parse(value);
|
|
1506
|
-
return { ...
|
|
1586
|
+
return { ...request2, kind: "response", data: result };
|
|
1507
1587
|
} catch (error) {
|
|
1508
1588
|
recordOperationFailure(error, phase);
|
|
1509
|
-
return sessionCommunicationError(
|
|
1589
|
+
return sessionCommunicationError(request2, sessionRestoreFailure(error) ?? options.onError(error));
|
|
1510
1590
|
}
|
|
1511
1591
|
}
|
|
1512
1592
|
};
|
|
@@ -1525,18 +1605,18 @@ var SessionCommunicationDispatcher = class {
|
|
|
1525
1605
|
get capabilities() {
|
|
1526
1606
|
return [...this.#operations.keys()];
|
|
1527
1607
|
}
|
|
1528
|
-
async dispatch(
|
|
1608
|
+
async dispatch(request2) {
|
|
1529
1609
|
const operation = this.#operations.get(
|
|
1530
|
-
sessionCommunicationOperationCapability(
|
|
1610
|
+
sessionCommunicationOperationCapability(request2.operation, request2.version)
|
|
1531
1611
|
);
|
|
1532
1612
|
if (operation === void 0) {
|
|
1533
|
-
const knownOperation = [...this.#operations.values()].some((candidate) => candidate.operation ===
|
|
1534
|
-
return sessionCommunicationError(
|
|
1613
|
+
const knownOperation = [...this.#operations.values()].some((candidate) => candidate.operation === request2.operation);
|
|
1614
|
+
return sessionCommunicationError(request2, {
|
|
1535
1615
|
code: knownOperation ? "UNSUPPORTED_OPERATION_VERSION" : "UNSUPPORTED_OPERATION",
|
|
1536
1616
|
message: knownOperation ? "The endpoint does not support this operation version" : "The endpoint does not support this operation"
|
|
1537
1617
|
});
|
|
1538
1618
|
}
|
|
1539
|
-
return operation.execute(
|
|
1619
|
+
return operation.execute(request2);
|
|
1540
1620
|
}
|
|
1541
1621
|
};
|
|
1542
1622
|
|
|
@@ -1684,22 +1764,22 @@ function createWorkbenchOperations(options) {
|
|
|
1684
1764
|
operation,
|
|
1685
1765
|
version: WORKBENCH_VERSION,
|
|
1686
1766
|
schema,
|
|
1687
|
-
handle: async (data,
|
|
1767
|
+
handle: async (data, request2) => {
|
|
1688
1768
|
const check = options.captureAccess?.();
|
|
1689
1769
|
check?.();
|
|
1690
|
-
const result = await handle(data,
|
|
1770
|
+
const result = await handle(data, request2);
|
|
1691
1771
|
check?.();
|
|
1692
1772
|
return result;
|
|
1693
1773
|
},
|
|
1694
1774
|
onError: (error) => onError(error, operation)
|
|
1695
1775
|
});
|
|
1696
1776
|
}
|
|
1697
|
-
function submit(
|
|
1698
|
-
const operation = WorkbenchOperationStatusSchema.shape.operation.parse(
|
|
1777
|
+
function submit(request2, data, execute) {
|
|
1778
|
+
const operation = WorkbenchOperationStatusSchema.shape.operation.parse(request2.operation);
|
|
1699
1779
|
const check = options.captureAccess?.();
|
|
1700
1780
|
return options.operations.submit({
|
|
1701
1781
|
clientId: options.requester(),
|
|
1702
|
-
sessionId:
|
|
1782
|
+
sessionId: request2.sessionId,
|
|
1703
1783
|
operationId: data.operationId,
|
|
1704
1784
|
operationCreatedAt: data.operationCreatedAt,
|
|
1705
1785
|
expectedAgentRunId: data.expectedAgentRunId,
|
|
@@ -1718,9 +1798,9 @@ function createWorkbenchOperations(options) {
|
|
|
1718
1798
|
}).then((status) => output(WorkbenchOperationStatusSchema, status));
|
|
1719
1799
|
}
|
|
1720
1800
|
const routes = [
|
|
1721
|
-
route("operation.get", WorkbenchOperationGetSchema, async ({ operationId },
|
|
1801
|
+
route("operation.get", WorkbenchOperationGetSchema, async ({ operationId }, request2) => output(WorkbenchOperationStatusSchema, await options.operations.get({
|
|
1722
1802
|
clientId: options.requester(),
|
|
1723
|
-
sessionId:
|
|
1803
|
+
sessionId: request2.sessionId
|
|
1724
1804
|
}, operationId)))
|
|
1725
1805
|
];
|
|
1726
1806
|
const runtime = options.runtime;
|
|
@@ -1732,67 +1812,67 @@ function createWorkbenchOperations(options) {
|
|
|
1732
1812
|
}
|
|
1733
1813
|
};
|
|
1734
1814
|
routes.push(
|
|
1735
|
-
route("schedule.snapshot", WorkbenchEmptyRequestSchema, async (_data,
|
|
1736
|
-
await assertMain(
|
|
1737
|
-
return output(WorkbenchScheduleSnapshotSchema, await schedules.snapshot(
|
|
1815
|
+
route("schedule.snapshot", WorkbenchEmptyRequestSchema, async (_data, request2) => {
|
|
1816
|
+
await assertMain(request2.sessionId);
|
|
1817
|
+
return output(WorkbenchScheduleSnapshotSchema, await schedules.snapshot(request2.sessionId));
|
|
1738
1818
|
}),
|
|
1739
|
-
route("schedule.resume", WorkbenchSubmitRequestSchema, (data,
|
|
1819
|
+
route("schedule.resume", WorkbenchSubmitRequestSchema, (data, request2) => {
|
|
1740
1820
|
const check = options.captureAccess?.();
|
|
1741
|
-
return submit(
|
|
1742
|
-
await assertMain(
|
|
1743
|
-
return output(WorkbenchScheduleSnapshotSchema, await schedules.resume(
|
|
1821
|
+
return submit(request2, data, async () => {
|
|
1822
|
+
await assertMain(request2.sessionId);
|
|
1823
|
+
return output(WorkbenchScheduleSnapshotSchema, await schedules.resume(request2.sessionId, check));
|
|
1744
1824
|
});
|
|
1745
1825
|
}),
|
|
1746
|
-
route("schedule.create", WorkbenchScheduleCreateRequestSchema, (data,
|
|
1826
|
+
route("schedule.create", WorkbenchScheduleCreateRequestSchema, (data, request2) => {
|
|
1747
1827
|
const check = options.captureAccess?.();
|
|
1748
|
-
return submit(
|
|
1749
|
-
await assertMain(
|
|
1750
|
-
return output(WorkbenchScheduleCreateResultSchema, await schedules.create(
|
|
1828
|
+
return submit(request2, data, async () => {
|
|
1829
|
+
await assertMain(request2.sessionId);
|
|
1830
|
+
return output(WorkbenchScheduleCreateResultSchema, await schedules.create(request2.sessionId, data, check));
|
|
1751
1831
|
});
|
|
1752
1832
|
}),
|
|
1753
|
-
route("schedule.delete", WorkbenchScheduleDeleteRequestSchema, (data,
|
|
1833
|
+
route("schedule.delete", WorkbenchScheduleDeleteRequestSchema, (data, request2) => {
|
|
1754
1834
|
const check = options.captureAccess?.();
|
|
1755
|
-
return submit(
|
|
1756
|
-
await assertMain(
|
|
1757
|
-
return output(WorkbenchScheduleDeleteResultSchema, await schedules.delete(
|
|
1835
|
+
return submit(request2, data, async () => {
|
|
1836
|
+
await assertMain(request2.sessionId);
|
|
1837
|
+
return output(WorkbenchScheduleDeleteResultSchema, await schedules.delete(request2.sessionId, data.id, check));
|
|
1758
1838
|
});
|
|
1759
1839
|
}),
|
|
1760
|
-
route("schedule.draft.dismiss", WorkbenchScheduleDraftDismissRequestSchema, (data,
|
|
1840
|
+
route("schedule.draft.dismiss", WorkbenchScheduleDraftDismissRequestSchema, (data, request2) => {
|
|
1761
1841
|
const check = options.captureAccess?.();
|
|
1762
|
-
return submit(
|
|
1763
|
-
await assertMain(
|
|
1764
|
-
await schedules.dismissDraft(
|
|
1842
|
+
return submit(request2, data, async () => {
|
|
1843
|
+
await assertMain(request2.sessionId);
|
|
1844
|
+
await schedules.dismissDraft(request2.sessionId, data.draftId, check);
|
|
1765
1845
|
return output(WorkbenchCompletedResultSchema, { completed: true });
|
|
1766
1846
|
});
|
|
1767
1847
|
})
|
|
1768
1848
|
);
|
|
1769
1849
|
}
|
|
1770
1850
|
if (runtime !== void 0) routes.push(
|
|
1771
|
-
route("question.ask", WorkbenchAskRequestSchema, (data,
|
|
1772
|
-
route("command.list", WorkbenchEmptyRequestSchema, async (_data,
|
|
1773
|
-
route("command.invoke", WorkbenchCommandInvokeRequestSchema, (data,
|
|
1851
|
+
route("question.ask", WorkbenchAskRequestSchema, (data, request2) => submit(request2, data, async () => output(WorkbenchAskResultSchema, await runtime.ask(request2.sessionId, data.question)))),
|
|
1852
|
+
route("command.list", WorkbenchEmptyRequestSchema, async (_data, request2) => output(WorkbenchCommandListResultSchema, { commands: await runtime.commands(request2.sessionId) })),
|
|
1853
|
+
route("command.invoke", WorkbenchCommandInvokeRequestSchema, (data, request2) => submit(request2, data, async () => output(
|
|
1774
1854
|
WorkbenchCommandResultSchema,
|
|
1775
|
-
await runtime.invokeCommand(
|
|
1855
|
+
await runtime.invokeCommand(request2.sessionId, data.name, data.input, data.operationId)
|
|
1776
1856
|
))),
|
|
1777
|
-
route("queue.snapshot", WorkbenchEmptyRequestSchema, async (_data,
|
|
1778
|
-
route("queue.mutate", WorkbenchQueueMutationRequestSchema, (data,
|
|
1779
|
-
route("insights.read", WorkbenchEmptyRequestSchema, async (_data,
|
|
1780
|
-
const isolated = options.isResearchSession?.() === true || await options.research?.parentSessionId(
|
|
1857
|
+
route("queue.snapshot", WorkbenchEmptyRequestSchema, async (_data, request2) => output(WorkbenchQueueSnapshotSchema, await runtime.queue(request2.sessionId))),
|
|
1858
|
+
route("queue.mutate", WorkbenchQueueMutationRequestSchema, (data, request2) => submit(request2, data, async () => output(WorkbenchQueueMutationResultSchema, await runtime.mutateQueue(request2.sessionId, data)))),
|
|
1859
|
+
route("insights.read", WorkbenchEmptyRequestSchema, async (_data, request2) => {
|
|
1860
|
+
const isolated = options.isResearchSession?.() === true || await options.research?.parentSessionId(request2.sessionId) !== void 0;
|
|
1781
1861
|
if (isolated) {
|
|
1782
1862
|
if (options.research?.insights === void 0) {
|
|
1783
1863
|
throw new SessionOperationError("WORKBENCH_UNSUPPORTED", "Research usage inspection is unavailable");
|
|
1784
1864
|
}
|
|
1785
|
-
return output(WorkbenchInsightsSchema, await options.research.insights(
|
|
1865
|
+
return output(WorkbenchInsightsSchema, await options.research.insights(request2.sessionId));
|
|
1786
1866
|
}
|
|
1787
|
-
return output(WorkbenchInsightsSchema, await runtime.insights(
|
|
1867
|
+
return output(WorkbenchInsightsSchema, await runtime.insights(request2.sessionId));
|
|
1788
1868
|
}),
|
|
1789
|
-
route("context.compact", WorkbenchSubmitRequestSchema, (data,
|
|
1869
|
+
route("context.compact", WorkbenchSubmitRequestSchema, (data, request2) => submit(request2, data, async () => output(WorkbenchCompactResultSchema, await runtime.compact(request2.sessionId))))
|
|
1790
1870
|
);
|
|
1791
1871
|
const research = options.research;
|
|
1792
1872
|
if (research !== void 0) routes.push(
|
|
1793
|
-
route("research.create", WorkbenchResearchCreateRequestSchema, (data,
|
|
1873
|
+
route("research.create", WorkbenchResearchCreateRequestSchema, (data, request2) => submit(request2, data, async () => output(WorkbenchResearchCreateResultSchema, {
|
|
1794
1874
|
thread: await research.create({
|
|
1795
|
-
parentSessionId:
|
|
1875
|
+
parentSessionId: request2.sessionId,
|
|
1796
1876
|
...data.deferInitialPrompt === void 0 ? {} : { deferInitialPrompt: data.deferInitialPrompt },
|
|
1797
1877
|
title: data.title,
|
|
1798
1878
|
question: data.question,
|
|
@@ -1800,15 +1880,15 @@ function createWorkbenchOperations(options) {
|
|
|
1800
1880
|
...data.sourceItemId === void 0 ? {} : { sourceItemId: data.sourceItemId }
|
|
1801
1881
|
})
|
|
1802
1882
|
}))),
|
|
1803
|
-
route("research.list", WorkbenchEmptyRequestSchema, async (_data,
|
|
1804
|
-
route("research.timeline", WorkbenchResearchTimelineRequestSchema, async (data,
|
|
1805
|
-
route("research.send", WorkbenchResearchSendRequestSchema, (data,
|
|
1806
|
-
route("research.abort", WorkbenchSubmitRequestSchema, (data,
|
|
1807
|
-
await research.abort(
|
|
1883
|
+
route("research.list", WorkbenchEmptyRequestSchema, async (_data, request2) => output(WorkbenchResearchListResultSchema, { threads: await research.list(request2.sessionId) })),
|
|
1884
|
+
route("research.timeline", WorkbenchResearchTimelineRequestSchema, async (data, request2) => output(SessionTimelinePageSchema, await research.timeline(request2.sessionId, data.cursor))),
|
|
1885
|
+
route("research.send", WorkbenchResearchSendRequestSchema, (data, request2) => submit(request2, data, async () => output(WorkbenchResearchSendResultSchema, await research.send(request2.sessionId, data.prompt, data.operationId)))),
|
|
1886
|
+
route("research.abort", WorkbenchSubmitRequestSchema, (data, request2) => submit(request2, data, async () => {
|
|
1887
|
+
await research.abort(request2.sessionId);
|
|
1808
1888
|
return output(WorkbenchCompletedResultSchema, { completed: true });
|
|
1809
1889
|
})),
|
|
1810
|
-
route("research.delete", WorkbenchSubmitRequestSchema, (data,
|
|
1811
|
-
await research.delete(
|
|
1890
|
+
route("research.delete", WorkbenchSubmitRequestSchema, (data, request2) => submit(request2, data, async () => {
|
|
1891
|
+
await research.delete(request2.sessionId);
|
|
1812
1892
|
return output(WorkbenchCompletedResultSchema, { completed: true });
|
|
1813
1893
|
}))
|
|
1814
1894
|
);
|
|
@@ -1905,20 +1985,20 @@ function sensitiveSegments(segments) {
|
|
|
1905
1985
|
}
|
|
1906
1986
|
return false;
|
|
1907
1987
|
}
|
|
1908
|
-
var pathSchema =
|
|
1909
|
-
var listSchema =
|
|
1988
|
+
var pathSchema = z4.string().max(4096).default("");
|
|
1989
|
+
var listSchema = z4.object({
|
|
1910
1990
|
path: pathSchema,
|
|
1911
|
-
cursor:
|
|
1991
|
+
cursor: z4.string().uuid().optional()
|
|
1912
1992
|
}).strict();
|
|
1913
|
-
var readSchema =
|
|
1914
|
-
path:
|
|
1915
|
-
startLine:
|
|
1916
|
-
lineCount:
|
|
1993
|
+
var readSchema = z4.object({
|
|
1994
|
+
path: z4.string().min(1).max(4096),
|
|
1995
|
+
startLine: z4.number().int().min(1).max(500001).default(1),
|
|
1996
|
+
lineCount: z4.number().int().min(1).max(200).default(200)
|
|
1917
1997
|
}).strict();
|
|
1918
|
-
var searchSchema =
|
|
1998
|
+
var searchSchema = z4.object({
|
|
1919
1999
|
path: pathSchema,
|
|
1920
|
-
query:
|
|
1921
|
-
cursor:
|
|
2000
|
+
query: z4.string().min(1).max(256),
|
|
2001
|
+
cursor: z4.string().uuid().optional()
|
|
1922
2002
|
}).strict();
|
|
1923
2003
|
var ResearchTools = class {
|
|
1924
2004
|
constructor(parentSessionId, root, sourceMetadata, privateDirectories = [], onError, captureSourceAccess) {
|
|
@@ -2178,7 +2258,7 @@ var ResearchTools = class {
|
|
|
2178
2258
|
const definition = (name, description, schema, run) => ({
|
|
2179
2259
|
name,
|
|
2180
2260
|
description,
|
|
2181
|
-
parameters:
|
|
2261
|
+
parameters: z4.toJSONSchema(schema),
|
|
2182
2262
|
// Only these host-owned read tools bypass prompts; their path policy remains mandatory.
|
|
2183
2263
|
skipPermission: true,
|
|
2184
2264
|
defer: "never",
|
|
@@ -2191,7 +2271,7 @@ var ResearchTools = class {
|
|
|
2191
2271
|
return { textResultForLlm: JSON.stringify(result), resultType: "success" };
|
|
2192
2272
|
} catch (error) {
|
|
2193
2273
|
const knownCode = workbenchErrorDetails(error).code;
|
|
2194
|
-
const code = (error instanceof ResearchError || error instanceof SessionFileReadError) && knownCode !== "UNCLASSIFIED" ? knownCode : error instanceof
|
|
2274
|
+
const code = (error instanceof ResearchError || error instanceof SessionFileReadError) && knownCode !== "UNCLASSIFIED" ? knownCode : error instanceof z4.ZodError ? "RESEARCH_INVALID_ARGUMENT" : "RESEARCH_TOOL_FAILED";
|
|
2195
2275
|
this.onError?.(new ResearchError(code, "The research tool failed", { cause: error }), { stage: name });
|
|
2196
2276
|
return { textResultForLlm: JSON.stringify({ error: code }), resultType: "failure" };
|
|
2197
2277
|
}
|
|
@@ -2353,7 +2433,9 @@ function toErrorDetails(error) {
|
|
|
2353
2433
|
|
|
2354
2434
|
// src/service/transport/relay-socket.ts
|
|
2355
2435
|
import { io } from "socket.io-client";
|
|
2356
|
-
|
|
2436
|
+
import { EventEmitter } from "node:events";
|
|
2437
|
+
function createRelaySocket(uri, options, authorization) {
|
|
2438
|
+
if (authorization !== void 0) return new AuthorizedRelaySocket(uri, options, authorization);
|
|
2357
2439
|
const socket = io(uri, { ...options, autoConnect: false });
|
|
2358
2440
|
socket.on("connect_error", (error) => {
|
|
2359
2441
|
const manager = socket.io;
|
|
@@ -2370,6 +2452,93 @@ function createRelaySocket(uri, options) {
|
|
|
2370
2452
|
if (options.autoConnect !== false) socket.connect();
|
|
2371
2453
|
return socket;
|
|
2372
2454
|
}
|
|
2455
|
+
var AuthorizedRelaySocket = class {
|
|
2456
|
+
constructor(uri, options, authorization) {
|
|
2457
|
+
this.options = options;
|
|
2458
|
+
this.authorization = authorization;
|
|
2459
|
+
if (typeof options.auth === "function") throw new Error("Bearer Relay authentication requires an object handshake.");
|
|
2460
|
+
this.#socket = createRelaySocket(uri, { ...options, autoConnect: false, forceNew: true });
|
|
2461
|
+
this.on = (event, listener) => {
|
|
2462
|
+
this.#events.on(event, listener);
|
|
2463
|
+
};
|
|
2464
|
+
this.emit = this.#socket.emit.bind(this.#socket);
|
|
2465
|
+
this.#socket.onAny((event, ...args) => this.#events.emit(event, ...args));
|
|
2466
|
+
this.#socket.on("connect", () => this.#events.emit("connect"));
|
|
2467
|
+
this.#socket.on("connect_error", (error) => this.#events.emit("connect_error", error));
|
|
2468
|
+
this.#socket.on("disconnect", (reason, details) => this.#events.emit("disconnect", reason, details));
|
|
2469
|
+
if (options.autoConnect !== false) this.connect();
|
|
2470
|
+
}
|
|
2471
|
+
options;
|
|
2472
|
+
authorization;
|
|
2473
|
+
#socket;
|
|
2474
|
+
#events = new EventEmitter();
|
|
2475
|
+
#generation = 0;
|
|
2476
|
+
#wanted = false;
|
|
2477
|
+
#pending = false;
|
|
2478
|
+
#token;
|
|
2479
|
+
#timer;
|
|
2480
|
+
on;
|
|
2481
|
+
emit;
|
|
2482
|
+
get connected() {
|
|
2483
|
+
return this.#socket.connected;
|
|
2484
|
+
}
|
|
2485
|
+
get active() {
|
|
2486
|
+
return this.#pending || this.#socket.active;
|
|
2487
|
+
}
|
|
2488
|
+
get sendBuffer() {
|
|
2489
|
+
return this.#socket.sendBuffer;
|
|
2490
|
+
}
|
|
2491
|
+
get io() {
|
|
2492
|
+
return this.#socket.io;
|
|
2493
|
+
}
|
|
2494
|
+
connect() {
|
|
2495
|
+
this.#wanted = true;
|
|
2496
|
+
if (this.#pending) return;
|
|
2497
|
+
this.#pending = true;
|
|
2498
|
+
const generation = this.#generation;
|
|
2499
|
+
void this.#authorize(generation).finally(() => {
|
|
2500
|
+
if (generation === this.#generation) this.#pending = false;
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2503
|
+
disconnect() {
|
|
2504
|
+
this.#wanted = false;
|
|
2505
|
+
this.#generation++;
|
|
2506
|
+
this.#pending = false;
|
|
2507
|
+
clearTimeout(this.#timer);
|
|
2508
|
+
this.#socket.disconnect();
|
|
2509
|
+
}
|
|
2510
|
+
async #authorize(generation) {
|
|
2511
|
+
try {
|
|
2512
|
+
const credential = await this.authorization.getAccessToken();
|
|
2513
|
+
if (!this.#wanted || generation !== this.#generation) return;
|
|
2514
|
+
if (!Number.isSafeInteger(credential.expiresAt) || credential.expiresAt <= Date.now() || !/^[\x21-\x7e]{1,32768}$/u.test(credential.token)) throw new Error("Invalid access token");
|
|
2515
|
+
const changed2 = credential.token !== this.#token;
|
|
2516
|
+
this.#token = credential.token;
|
|
2517
|
+
if (changed2) {
|
|
2518
|
+
this.#socket.disconnect();
|
|
2519
|
+
this.#socket.io.opts.extraHeaders = {
|
|
2520
|
+
...this.options.extraHeaders,
|
|
2521
|
+
authorization: `Bearer ${credential.token}`
|
|
2522
|
+
};
|
|
2523
|
+
this.#socket.auth = { ...this.options.auth, token: credential.token };
|
|
2524
|
+
}
|
|
2525
|
+
if (!this.#socket.connected) this.#socket.connect();
|
|
2526
|
+
clearTimeout(this.#timer);
|
|
2527
|
+
this.#timer = setTimeout(
|
|
2528
|
+
() => this.connect(),
|
|
2529
|
+
Math.max(1e3, Math.min(6e4, (credential.expiresAt - Date.now()) / 2))
|
|
2530
|
+
);
|
|
2531
|
+
this.#timer.unref();
|
|
2532
|
+
} catch {
|
|
2533
|
+
if (!this.#wanted || generation !== this.#generation) return;
|
|
2534
|
+
clearTimeout(this.#timer);
|
|
2535
|
+
this.#socket.disconnect();
|
|
2536
|
+
const error = new Error("Relay authorization failed. Sign in again on the local AgentKnight page.");
|
|
2537
|
+
error.name = "RelayAuthorizationError";
|
|
2538
|
+
this.#events.emit("connect_error", error);
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
};
|
|
2373
2542
|
|
|
2374
2543
|
// src/service/requests/session-communication.ts
|
|
2375
2544
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -2542,13 +2711,13 @@ var TimelineResponseEncoder = class {
|
|
|
2542
2711
|
machineId;
|
|
2543
2712
|
clientId;
|
|
2544
2713
|
#encoder = new ContentEncoder();
|
|
2545
|
-
async seal(result,
|
|
2714
|
+
async seal(result, request2, options) {
|
|
2546
2715
|
const plaintext = Buffer.from(JSON.stringify(result), "utf8");
|
|
2547
2716
|
const startedAt = performance.now();
|
|
2548
2717
|
const encoded = await this.#encoder.encodeTimelineResult(plaintext, {
|
|
2549
2718
|
enabled: options.enabled && options.recipientClientId !== void 0,
|
|
2550
|
-
...
|
|
2551
|
-
acceptContentEncodings:
|
|
2719
|
+
...request2.acceptContentEncodings === void 0 ? {} : {
|
|
2720
|
+
acceptContentEncodings: request2.acceptContentEncodings
|
|
2552
2721
|
}
|
|
2553
2722
|
});
|
|
2554
2723
|
const encodeDurationMs = performance.now() - startedAt;
|
|
@@ -2642,12 +2811,12 @@ var SessionPublicationScope = class {
|
|
|
2642
2811
|
|
|
2643
2812
|
// src/service/requests/communication-operations.ts
|
|
2644
2813
|
import { promisify as promisify2 } from "node:util";
|
|
2645
|
-
import { constants as
|
|
2814
|
+
import { constants as constants4, gzip as gzip3 } from "node:zlib";
|
|
2646
2815
|
|
|
2647
2816
|
// src/session-git-diff.ts
|
|
2648
2817
|
import { execFile } from "node:child_process";
|
|
2649
2818
|
import { createHash as createHash5, randomUUID as randomUUID3 } from "node:crypto";
|
|
2650
|
-
import { constants as
|
|
2819
|
+
import { constants as constants3 } from "node:fs";
|
|
2651
2820
|
import { chmod, lstat as lstat4, mkdir as mkdir2, open as open2, readlink, realpath as realpath4, rm, stat as stat4, writeFile as writeFile2 } from "node:fs/promises";
|
|
2652
2821
|
import { dirname, isAbsolute as isAbsolute4, join as join5, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
2653
2822
|
|
|
@@ -2882,7 +3051,7 @@ async function readCurrent(root, path, algorithm, work, keepBytes = false) {
|
|
|
2882
3051
|
work.bytes += Number(before.size);
|
|
2883
3052
|
const handle = await open2(
|
|
2884
3053
|
join5(root, ...path.split("/")),
|
|
2885
|
-
|
|
3054
|
+
constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0) | (constants3.O_NONBLOCK ?? 0)
|
|
2886
3055
|
);
|
|
2887
3056
|
try {
|
|
2888
3057
|
const opened = await handle.stat({ bigint: true });
|
|
@@ -3432,22 +3601,22 @@ var TimelineImageCache = class {
|
|
|
3432
3601
|
if (!("attachments" in item) || item.attachments === void 0) return item;
|
|
3433
3602
|
return { ...item, attachments: item.attachments.map((attachment) => this.#reference(sessionId, attachment)) };
|
|
3434
3603
|
};
|
|
3435
|
-
read(sessionId,
|
|
3436
|
-
const key = JSON.stringify([sessionId,
|
|
3604
|
+
read(sessionId, request2) {
|
|
3605
|
+
const key = JSON.stringify([sessionId, request2.sha256]);
|
|
3437
3606
|
const asset = this.#assets.get(key);
|
|
3438
3607
|
if (asset === void 0) throw new TimelineAssetError("IMAGE_ABSENT", "The image is no longer cached on this PC");
|
|
3439
|
-
if (
|
|
3608
|
+
if (request2.offset >= asset.bytes.length) {
|
|
3440
3609
|
throw new TimelineAssetError("IMAGE_OFFSET_INVALID", "The image chunk offset exceeds its length");
|
|
3441
3610
|
}
|
|
3442
3611
|
this.#assets.delete(key);
|
|
3443
3612
|
this.#assets.set(key, asset);
|
|
3444
|
-
const end = Math.min(
|
|
3613
|
+
const end = Math.min(request2.offset + TIMELINE_IMAGE_CHUNK_BYTES, asset.bytes.length);
|
|
3445
3614
|
return TimelineImageChunkSchema.parse({
|
|
3446
|
-
sha256:
|
|
3447
|
-
offset:
|
|
3615
|
+
sha256: request2.sha256,
|
|
3616
|
+
offset: request2.offset,
|
|
3448
3617
|
totalBytes: asset.bytes.length,
|
|
3449
3618
|
mimeType: asset.mimeType,
|
|
3450
|
-
data: asset.bytes.subarray(
|
|
3619
|
+
data: asset.bytes.subarray(request2.offset, end).toString("base64"),
|
|
3451
3620
|
eof: end === asset.bytes.length
|
|
3452
3621
|
});
|
|
3453
3622
|
}
|
|
@@ -3512,15 +3681,15 @@ function hasSignature(bytes, mimeType) {
|
|
|
3512
3681
|
|
|
3513
3682
|
// src/session-image-uploader.ts
|
|
3514
3683
|
import { createHash as createHash7 } from "node:crypto";
|
|
3515
|
-
import { z as
|
|
3684
|
+
import { z as z5 } from "zod";
|
|
3516
3685
|
var MAX_ACTIVE_UPLOADS = 3;
|
|
3517
3686
|
var MAX_JSON_BYTES = 16 * 1024;
|
|
3518
3687
|
var REQUEST_TIMEOUT_MS = 2e4;
|
|
3519
3688
|
var UPLOAD_TIMEOUT_MS = 7e4;
|
|
3520
3689
|
var MAX_GRANT_LIFETIME_MS = 10 * 6e4 + 3e4;
|
|
3521
|
-
var UploaderConfigSchema =
|
|
3690
|
+
var UploaderConfigSchema = z5.object({
|
|
3522
3691
|
relayUrl: SessionImageRelayUrlSchema,
|
|
3523
|
-
relayToken:
|
|
3692
|
+
relayToken: z5.string().min(24).max(4096).regex(/^[\x21-\x7e]+$/u),
|
|
3524
3693
|
userId: IdSchema.refine((value) => /^[\x20-\x7e]+$/u.test(value)),
|
|
3525
3694
|
machineId: IdSchema,
|
|
3526
3695
|
storageAccount: SessionImagesConfigSchema.shape.storageAccount,
|
|
@@ -3528,7 +3697,7 @@ var UploaderConfigSchema = z4.object({
|
|
|
3528
3697
|
});
|
|
3529
3698
|
function safeCause(error) {
|
|
3530
3699
|
if (error instanceof SessionImageUploadError) return error;
|
|
3531
|
-
if (error instanceof
|
|
3700
|
+
if (error instanceof z5.ZodError) return new Error("Schema validation failed.");
|
|
3532
3701
|
const result = new Error("Image operation failed.");
|
|
3533
3702
|
if (error instanceof Error) {
|
|
3534
3703
|
if (["TypeError", "SyntaxError", "AbortError", "TimeoutError"].includes(error.name)) result.name = error.name;
|
|
@@ -3626,11 +3795,11 @@ var SessionImageUploader = class {
|
|
|
3626
3795
|
const bytes = Buffer.from(source);
|
|
3627
3796
|
const dimensions = await this.#dimensions(bytes);
|
|
3628
3797
|
const hash2 = digest(bytes);
|
|
3629
|
-
const
|
|
3798
|
+
const request2 = parse(SessionImageUploadRequestSchema, { ...scope, sizeBytes: bytes.length }, "source");
|
|
3630
3799
|
revalidate("reserve");
|
|
3631
3800
|
const upload = await this.#json(
|
|
3632
3801
|
`${SESSION_IMAGE_API_PATH}/uploads`,
|
|
3633
|
-
|
|
3802
|
+
request2,
|
|
3634
3803
|
201,
|
|
3635
3804
|
SessionImageUploadResultSchema,
|
|
3636
3805
|
"reserve",
|
|
@@ -3863,10 +4032,10 @@ function createCommunicationOperations(options) {
|
|
|
3863
4032
|
operation: TIMELINE_IMAGE_BLOB_OPERATION,
|
|
3864
4033
|
version: TIMELINE_IMAGE_BLOB_VERSION,
|
|
3865
4034
|
schema: TimelineImageBlobRequestSchema,
|
|
3866
|
-
handle: async ({ sha256 },
|
|
4035
|
+
handle: async ({ sha256 }, request2) => {
|
|
3867
4036
|
const assertCurrent = options.captureRequestAccess();
|
|
3868
4037
|
assertCurrent();
|
|
3869
|
-
const result = await imageBlob.publish(
|
|
4038
|
+
const result = await imageBlob.publish(request2.sessionId, sha256, assertCurrent);
|
|
3870
4039
|
assertCurrent();
|
|
3871
4040
|
return SessionCommunicationDataSchema.parse(result);
|
|
3872
4041
|
},
|
|
@@ -3881,11 +4050,11 @@ function createCommunicationOperations(options) {
|
|
|
3881
4050
|
operation: SESSION_RENAME_OPERATION,
|
|
3882
4051
|
version: SESSION_RENAME_VERSION,
|
|
3883
4052
|
schema: SessionRenameDataSchema,
|
|
3884
|
-
handle: async ({ name },
|
|
4053
|
+
handle: async ({ name }, request2) => {
|
|
3885
4054
|
const assertAccess = options.captureRequestAccess();
|
|
3886
4055
|
assertAccess();
|
|
3887
4056
|
return SessionRenameResultDataSchema.parse({
|
|
3888
|
-
name: await renameSession(
|
|
4057
|
+
name: await renameSession(request2.sessionId, name, assertAccess)
|
|
3889
4058
|
});
|
|
3890
4059
|
},
|
|
3891
4060
|
onError: (error) => unsupportedOperation(error) ?? (error instanceof AgentSessionRenameError || error instanceof SessionNotSharedError || error instanceof GroupChatError ? { code: error.code, message: error.message } : { code: "SESSION_RENAME_FAILED", message: "The session could not be renamed" })
|
|
@@ -3896,7 +4065,7 @@ function createCommunicationOperations(options) {
|
|
|
3896
4065
|
operation: GROUP_CHAT_CREATE_OPERATION,
|
|
3897
4066
|
version: GROUP_CHAT_CREATE_VERSION,
|
|
3898
4067
|
schema: GroupChatCreateDataSchema,
|
|
3899
|
-
handle: async ({ peerSessionId },
|
|
4068
|
+
handle: async ({ peerSessionId }, request2) => {
|
|
3900
4069
|
if (adapter.groupChatEnabled === false) throw new GroupChatError("GROUP_CHAT_DISABLED", "Group chat is disabled on the PC.");
|
|
3901
4070
|
const assertRequest = options.captureRequestAccess();
|
|
3902
4071
|
const peer = publications.capture(peerSessionId);
|
|
@@ -3906,7 +4075,7 @@ function createCommunicationOperations(options) {
|
|
|
3906
4075
|
if (!publications.isCurrent(peerSessionId, peer)) throw new SessionNotSharedError();
|
|
3907
4076
|
};
|
|
3908
4077
|
assertAccess();
|
|
3909
|
-
const session = await createGroupChat(
|
|
4078
|
+
const session = await createGroupChat(request2.sessionId, peerSessionId, request2.requestId, assertAccess);
|
|
3910
4079
|
assertAccess();
|
|
3911
4080
|
return SessionCommunicationDataSchema.parse(GroupChatCreateResultDataSchema.parse({ session }));
|
|
3912
4081
|
},
|
|
@@ -3922,10 +4091,10 @@ function createCommunicationOperations(options) {
|
|
|
3922
4091
|
operation: SESSION_GIT_DIFF_OPERATION,
|
|
3923
4092
|
version,
|
|
3924
4093
|
schema: SessionGitDiffDataSchema,
|
|
3925
|
-
handle: async (data,
|
|
4094
|
+
handle: async (data, request2) => {
|
|
3926
4095
|
const assertAccess = options.captureRequestAccess();
|
|
3927
4096
|
assertAccess();
|
|
3928
|
-
const result = await gitDiffReader.read(
|
|
4097
|
+
const result = await gitDiffReader.read(request2.sessionId, data, version);
|
|
3929
4098
|
let response = SessionCommunicationDataSchema.parse(result);
|
|
3930
4099
|
if (version >= SESSION_GIT_DIFF_GZIP_VERSION) {
|
|
3931
4100
|
const bytes = Buffer.from(JSON.stringify(result), "utf8");
|
|
@@ -3933,7 +4102,7 @@ function createCommunicationOperations(options) {
|
|
|
3933
4102
|
response = SessionGitDiffGzipResultDataSchema.parse({
|
|
3934
4103
|
encoding: "gzip",
|
|
3935
4104
|
byteLength: bytes.length,
|
|
3936
|
-
data: (await compress2(bytes, { level:
|
|
4105
|
+
data: (await compress2(bytes, { level: constants4.Z_BEST_SPEED })).toString("base64")
|
|
3937
4106
|
});
|
|
3938
4107
|
}
|
|
3939
4108
|
}
|
|
@@ -3946,9 +4115,9 @@ function createCommunicationOperations(options) {
|
|
|
3946
4115
|
operation: SESSION_DIRECTORY_LIST_OPERATION,
|
|
3947
4116
|
version: SESSION_DIRECTORY_LIST_VERSION,
|
|
3948
4117
|
schema: SessionDirectoryListDataSchema,
|
|
3949
|
-
handle: async ({ path },
|
|
4118
|
+
handle: async ({ path }, request2) => SessionDirectoryListResultDataSchema.parse({
|
|
3950
4119
|
path,
|
|
3951
|
-
...await directoryLister.list(
|
|
4120
|
+
...await directoryLister.list(request2.sessionId, path)
|
|
3952
4121
|
}),
|
|
3953
4122
|
onError: (error) => unsupportedOperation(error) ?? (error instanceof SessionDirectoryError ? { code: error.code, message: error.message } : { code: "DIRECTORY_UNAVAILABLE", message: "The directory is unavailable" })
|
|
3954
4123
|
}),
|
|
@@ -3956,7 +4125,7 @@ function createCommunicationOperations(options) {
|
|
|
3956
4125
|
operation: SESSION_FILE_READ_OPERATION,
|
|
3957
4126
|
version,
|
|
3958
4127
|
schema: SessionFileReadDataSchema,
|
|
3959
|
-
handle: ({ path, rootRevision },
|
|
4128
|
+
handle: ({ path, rootRevision }, request2) => fileReader.read(request2.sessionId, path, rootRevision, version),
|
|
3960
4129
|
onError: (error) => unsupportedOperation(error) ?? {
|
|
3961
4130
|
code: error instanceof SessionFileReadError ? error.code : "FILE_UNAVAILABLE",
|
|
3962
4131
|
message: "The file preview is unavailable"
|
|
@@ -3966,10 +4135,10 @@ function createCommunicationOperations(options) {
|
|
|
3966
4135
|
operation: SESSION_FILE_DOWNLOAD_OPERATION,
|
|
3967
4136
|
version: SESSION_FILE_DOWNLOAD_VERSION,
|
|
3968
4137
|
schema: SessionFileDownloadDataSchema,
|
|
3969
|
-
handle: async ({ path, rootRevision },
|
|
4138
|
+
handle: async ({ path, rootRevision }, request2) => {
|
|
3970
4139
|
const assertAccess = options.captureRequestAccess();
|
|
3971
4140
|
assertAccess();
|
|
3972
|
-
const result = await fileReader.download(
|
|
4141
|
+
const result = await fileReader.download(request2.sessionId, path, rootRevision);
|
|
3973
4142
|
assertAccess();
|
|
3974
4143
|
return result;
|
|
3975
4144
|
},
|
|
@@ -3982,7 +4151,7 @@ function createCommunicationOperations(options) {
|
|
|
3982
4151
|
operation: SESSION_RESOURCE_READ_OPERATION,
|
|
3983
4152
|
version: SESSION_RESOURCE_READ_VERSION,
|
|
3984
4153
|
schema: SessionResourceReadDataSchema,
|
|
3985
|
-
handle: ({ path, rootRevision },
|
|
4154
|
+
handle: ({ path, rootRevision }, request2) => fileReader.readResource(request2.sessionId, path, rootRevision),
|
|
3986
4155
|
onError: (error) => unsupportedOperation(error) ?? {
|
|
3987
4156
|
code: error instanceof SessionFileReadError ? error.code : "FILE_UNAVAILABLE",
|
|
3988
4157
|
message: "The resource is unavailable"
|
|
@@ -3994,8 +4163,8 @@ function createCommunicationOperations(options) {
|
|
|
3994
4163
|
operation: SESSION_PROJECT_IDENTITY_OPERATION,
|
|
3995
4164
|
version: SESSION_PROJECT_IDENTITY_VERSION,
|
|
3996
4165
|
schema: SessionProjectIdentityRequestDataSchema,
|
|
3997
|
-
handle: async (_data,
|
|
3998
|
-
const project = await getSessionProjectIdentity(
|
|
4166
|
+
handle: async (_data, request2) => {
|
|
4167
|
+
const project = await getSessionProjectIdentity(request2.sessionId);
|
|
3999
4168
|
return SessionCommunicationDataSchema.parse(
|
|
4000
4169
|
SessionProjectIdentityResultDataSchema.parse(project === void 0 ? {} : { project })
|
|
4001
4170
|
);
|
|
@@ -4108,10 +4277,10 @@ var SessionCommunicationHandler = class {
|
|
|
4108
4277
|
}
|
|
4109
4278
|
return visible;
|
|
4110
4279
|
}
|
|
4111
|
-
async handle(
|
|
4112
|
-
if (
|
|
4280
|
+
async handle(request2, scope) {
|
|
4281
|
+
if (request2.operation !== TIMELINE_SYNC_OPERATION) return this.#handle(request2, scope);
|
|
4113
4282
|
const started = performance2.now();
|
|
4114
|
-
const parsed = TimelineSyncRequestSchema.safeParse(
|
|
4283
|
+
const parsed = TimelineSyncRequestSchema.safeParse(request2.data);
|
|
4115
4284
|
const mode = parsed.success && parsed.data.watermark !== void 0 ? parsed.data.resume === true ? "resume" : "replay" : "snapshot";
|
|
4116
4285
|
const diagnostics = new OperationDiagnostics();
|
|
4117
4286
|
const lifecycle = {
|
|
@@ -4121,7 +4290,7 @@ var SessionCommunicationHandler = class {
|
|
|
4121
4290
|
emitOutcome: "not-attempted"
|
|
4122
4291
|
};
|
|
4123
4292
|
const fields = () => ({
|
|
4124
|
-
...diagnostics.fields(
|
|
4293
|
+
...diagnostics.fields(request2),
|
|
4125
4294
|
mode,
|
|
4126
4295
|
lifecycleMs: Math.round(performance2.now() - started),
|
|
4127
4296
|
preflightMs: Math.round((lifecycle.preflightEnded ?? performance2.now()) - started),
|
|
@@ -4145,7 +4314,7 @@ var SessionCommunicationHandler = class {
|
|
|
4145
4314
|
if (mode !== "replay") {
|
|
4146
4315
|
this.options.logger.info(fields(), "session.communication.timeline-sync-started");
|
|
4147
4316
|
}
|
|
4148
|
-
await this.#handle(
|
|
4317
|
+
await this.#handle(request2, scope, diagnostics, lifecycle);
|
|
4149
4318
|
}, { measureHandle: false });
|
|
4150
4319
|
} catch (error) {
|
|
4151
4320
|
lifecycle.outcome = "failure";
|
|
@@ -4170,7 +4339,7 @@ var SessionCommunicationHandler = class {
|
|
|
4170
4339
|
}
|
|
4171
4340
|
}
|
|
4172
4341
|
}
|
|
4173
|
-
async #handle(
|
|
4342
|
+
async #handle(request2, scope, diagnostics = new OperationDiagnostics(), lifecycle) {
|
|
4174
4343
|
const { adapter, config, machineId, research, publications, audience, logger, metrics } = this.options;
|
|
4175
4344
|
const reject = (reason) => {
|
|
4176
4345
|
if (lifecycle !== void 0) {
|
|
@@ -4207,13 +4376,13 @@ var SessionCommunicationHandler = class {
|
|
|
4207
4376
|
return;
|
|
4208
4377
|
}
|
|
4209
4378
|
const clientId = scope.clientId;
|
|
4210
|
-
const owner = [config.userId, machineId, clientId,
|
|
4379
|
+
const owner = [config.userId, machineId, clientId, request2.sessionId];
|
|
4211
4380
|
const key = (parts) => createHash8("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 24);
|
|
4212
|
-
const knownSource = this.#researchParents.get(
|
|
4381
|
+
const knownSource = this.#researchParents.get(request2.sessionId) ?? adapter.sessionPublicationSource?.(request2.sessionId) ?? request2.sessionId;
|
|
4213
4382
|
const arrivalPublication = adapter.isSessionVisible?.(knownSource) === true ? publications.capture(knownSource) : void 0;
|
|
4214
|
-
let researchParent = this.#researchParents.get(
|
|
4215
|
-
if (
|
|
4216
|
-
emit("session.communication", sessionCommunicationError(
|
|
4383
|
+
let researchParent = this.#researchParents.get(request2.sessionId);
|
|
4384
|
+
if (request2.operation === "research.create" && request2.data["deferInitialPrompt"] === true && (research?.chat === void 0 || this.options.supportsResearchChat?.(clientId) !== true)) {
|
|
4385
|
+
emit("session.communication", sessionCommunicationError(request2, {
|
|
4217
4386
|
code: "RESEARCH_CHAT_UNSUPPORTED",
|
|
4218
4387
|
message: "Negotiate Side chat transport before deferring the first prompt"
|
|
4219
4388
|
}));
|
|
@@ -4222,17 +4391,17 @@ var SessionCommunicationHandler = class {
|
|
|
4222
4391
|
if (research !== void 0) {
|
|
4223
4392
|
if (lifecycle !== void 0) lifecycle.preflightPhase = "ownership";
|
|
4224
4393
|
try {
|
|
4225
|
-
researchParent = await research.parentSessionId(
|
|
4394
|
+
researchParent = await research.parentSessionId(request2.sessionId) ?? researchParent;
|
|
4226
4395
|
} catch (error) {
|
|
4227
4396
|
reject("ownership-unavailable");
|
|
4228
4397
|
if (lifecycle !== void 0) diagnostics.recordFailure(error, "preflight");
|
|
4229
4398
|
logger.error({
|
|
4230
4399
|
stage: "research.ownership",
|
|
4231
4400
|
ownerKey: key(owner),
|
|
4232
|
-
requestKey: key([...owner,
|
|
4401
|
+
requestKey: key([...owner, request2.requestId]),
|
|
4233
4402
|
error: workbenchErrorDetails(error)
|
|
4234
4403
|
}, "session.operation.failed");
|
|
4235
|
-
emit("session.communication", sessionCommunicationError(
|
|
4404
|
+
emit("session.communication", sessionCommunicationError(request2, {
|
|
4236
4405
|
code: "WORKBENCH_UNAVAILABLE",
|
|
4237
4406
|
message: "The research ownership metadata is unavailable"
|
|
4238
4407
|
}));
|
|
@@ -4241,22 +4410,22 @@ var SessionCommunicationHandler = class {
|
|
|
4241
4410
|
}
|
|
4242
4411
|
if (researchParent !== void 0) {
|
|
4243
4412
|
if (lifecycle !== void 0) lifecycle.preflightPhase = "isolation";
|
|
4244
|
-
const unifiedSync = research?.chat !== void 0 && this.options.supportsResearchChat?.(clientId) === true && (
|
|
4245
|
-
if (!unifiedSync && !["research.timeline", "research.send", "research.abort", "research.delete", "operation.get", "insights.read"].includes(
|
|
4413
|
+
const unifiedSync = research?.chat !== void 0 && this.options.supportsResearchChat?.(clientId) === true && (request2.operation === TIMELINE_SYNC_OPERATION || request2.operation === TIMELINE_IMAGE_OPERATION || request2.operation === TIMELINE_IMAGE_BLOB_OPERATION);
|
|
4414
|
+
if (!unifiedSync && !["research.timeline", "research.send", "research.abort", "research.delete", "operation.get", "insights.read"].includes(request2.operation)) {
|
|
4246
4415
|
reject("research-isolated");
|
|
4247
|
-
emit("session.communication", sessionCommunicationError(
|
|
4416
|
+
emit("session.communication", sessionCommunicationError(request2, {
|
|
4248
4417
|
code: "RESEARCH_SESSION_ISOLATED",
|
|
4249
4418
|
message: "Research sessions require the isolated research operations"
|
|
4250
4419
|
}));
|
|
4251
4420
|
return;
|
|
4252
4421
|
}
|
|
4253
|
-
this.#researchParents.set(
|
|
4422
|
+
this.#researchParents.set(request2.sessionId, researchParent);
|
|
4254
4423
|
if (this.#researchParents.size > 2048) {
|
|
4255
4424
|
const oldest = this.#researchParents.keys().next().value;
|
|
4256
4425
|
if (oldest !== void 0) this.#researchParents.delete(oldest);
|
|
4257
4426
|
}
|
|
4258
4427
|
}
|
|
4259
|
-
const publicationSessionId = researchParent ??
|
|
4428
|
+
const publicationSessionId = researchParent ?? request2.sessionId;
|
|
4260
4429
|
if (lifecycle !== void 0) lifecycle.preflightPhase = "access";
|
|
4261
4430
|
let publication;
|
|
4262
4431
|
let researchAccess;
|
|
@@ -4270,7 +4439,7 @@ var SessionCommunicationHandler = class {
|
|
|
4270
4439
|
}
|
|
4271
4440
|
};
|
|
4272
4441
|
try {
|
|
4273
|
-
if (researchParent !== void 0 ||
|
|
4442
|
+
if (researchParent !== void 0 || request2.operation === "research.list") {
|
|
4274
4443
|
researchAccess = this.options.captureResearchAccess(publicationSessionId);
|
|
4275
4444
|
}
|
|
4276
4445
|
if (researchAccess?.detached !== true) {
|
|
@@ -4280,14 +4449,14 @@ var SessionCommunicationHandler = class {
|
|
|
4280
4449
|
} catch {
|
|
4281
4450
|
reject("not-shared");
|
|
4282
4451
|
const error = new SessionNotSharedError();
|
|
4283
|
-
emit("session.communication", sessionCommunicationError(
|
|
4452
|
+
emit("session.communication", sessionCommunicationError(request2, { code: error.code, message: error.message }));
|
|
4284
4453
|
return;
|
|
4285
4454
|
}
|
|
4286
|
-
const token = clientId === void 0 ||
|
|
4287
|
-
if (
|
|
4455
|
+
const token = clientId === void 0 || request2.operation !== TIMELINE_SYNC_OPERATION ? void 0 : audience.syncToken(clientId, request2.sessionId);
|
|
4456
|
+
if (request2.operation === TIMELINE_SYNC_OPERATION && !audience.confirmed) {
|
|
4288
4457
|
if (lifecycle !== void 0) lifecycle.preflightPhase = "audience";
|
|
4289
4458
|
reject("audience-unconfirmed");
|
|
4290
|
-
const { data: _data, kind: _kind, ...identity2 } =
|
|
4459
|
+
const { data: _data, kind: _kind, ...identity2 } = request2;
|
|
4291
4460
|
emit("session.communication", {
|
|
4292
4461
|
...identity2,
|
|
4293
4462
|
kind: "error",
|
|
@@ -4300,7 +4469,7 @@ var SessionCommunicationHandler = class {
|
|
|
4300
4469
|
lifecycle.preflightPhase = "complete";
|
|
4301
4470
|
lifecycle.lifecyclePhase = "dispatch";
|
|
4302
4471
|
}
|
|
4303
|
-
const response = await diagnostics.run(() => clientId === void 0 ? this.#dispatcher.dispatch(
|
|
4472
|
+
const response = await diagnostics.run(() => clientId === void 0 ? this.#dispatcher.dispatch(request2) : this.#requestContext.run({
|
|
4304
4473
|
clientId,
|
|
4305
4474
|
researchSession: researchParent !== void 0,
|
|
4306
4475
|
assertRequestCurrent: () => {
|
|
@@ -4310,7 +4479,7 @@ var SessionCommunicationHandler = class {
|
|
|
4310
4479
|
if (!publicationCurrent()) throw new SessionNotSharedError();
|
|
4311
4480
|
},
|
|
4312
4481
|
captureWorkbenchAccess: () => {
|
|
4313
|
-
if (researchAccess?.detached === true &&
|
|
4482
|
+
if (researchAccess?.detached === true && request2.operation === "research.send") {
|
|
4314
4483
|
throw new SessionOperationError("RESEARCH_DETACHED", "The research source session was deleted");
|
|
4315
4484
|
}
|
|
4316
4485
|
const check = researchAccess?.assertCurrent ?? this.options.captureWorkbenchAccess(publicationSessionId);
|
|
@@ -4322,12 +4491,12 @@ var SessionCommunicationHandler = class {
|
|
|
4322
4491
|
};
|
|
4323
4492
|
},
|
|
4324
4493
|
workbench: {
|
|
4325
|
-
stage:
|
|
4494
|
+
stage: request2.operation,
|
|
4326
4495
|
ownerKey: key(owner),
|
|
4327
|
-
requestKey: key([...owner,
|
|
4328
|
-
...typeof
|
|
4496
|
+
requestKey: key([...owner, request2.requestId]),
|
|
4497
|
+
...typeof request2.data["operationId"] !== "string" ? {} : { operationKey: key([...owner, request2.data["operationId"]]) }
|
|
4329
4498
|
}
|
|
4330
|
-
}, () => this.#dispatcher.dispatch(
|
|
4499
|
+
}, () => this.#dispatcher.dispatch(request2)));
|
|
4331
4500
|
if (lifecycle !== void 0) lifecycle.lifecyclePhase = "reply-check";
|
|
4332
4501
|
if (!scope.isCurrent()) {
|
|
4333
4502
|
if (lifecycle !== void 0) {
|
|
@@ -4339,12 +4508,12 @@ var SessionCommunicationHandler = class {
|
|
|
4339
4508
|
if (!publicationCurrent()) {
|
|
4340
4509
|
reject("not-shared");
|
|
4341
4510
|
const error = new SessionNotSharedError();
|
|
4342
|
-
emit("session.communication", sessionCommunicationError(
|
|
4511
|
+
emit("session.communication", sessionCommunicationError(request2, { code: error.code, message: error.message }));
|
|
4343
4512
|
return;
|
|
4344
4513
|
}
|
|
4345
|
-
if (
|
|
4346
|
-
if (response.kind === "response") audience.synchronize(clientId,
|
|
4347
|
-
else audience.stopSynchronizing(clientId,
|
|
4514
|
+
if (request2.operation === TIMELINE_SYNC_OPERATION && clientId !== void 0) {
|
|
4515
|
+
if (response.kind === "response") audience.synchronize(clientId, request2.sessionId, token);
|
|
4516
|
+
else audience.stopSynchronizing(clientId, request2.sessionId, token);
|
|
4348
4517
|
}
|
|
4349
4518
|
const emitStarted = performance2.now();
|
|
4350
4519
|
try {
|
|
@@ -4353,35 +4522,35 @@ var SessionCommunicationHandler = class {
|
|
|
4353
4522
|
if (!(error instanceof SecureMessageBudgetError)) throw error;
|
|
4354
4523
|
diagnostics.recordFailure(error, "emit");
|
|
4355
4524
|
diagnostics.durations.emit = performance2.now() - emitStarted;
|
|
4356
|
-
metrics.record(
|
|
4525
|
+
metrics.record(request2, diagnostics, true);
|
|
4357
4526
|
logger.error(
|
|
4358
|
-
{ ...diagnostics.fields(
|
|
4527
|
+
{ ...diagnostics.fields(request2), code: "TRANSPORT_BUDGET_EXCEEDED" },
|
|
4359
4528
|
"session.communication.operation-failed"
|
|
4360
4529
|
);
|
|
4361
|
-
if (clientId !== void 0 &&
|
|
4362
|
-
audience.stopSynchronizing(clientId,
|
|
4530
|
+
if (clientId !== void 0 && request2.operation === TIMELINE_SYNC_OPERATION) {
|
|
4531
|
+
audience.stopSynchronizing(clientId, request2.sessionId, token);
|
|
4363
4532
|
}
|
|
4364
|
-
emit("session.communication", sessionCommunicationError(
|
|
4533
|
+
emit("session.communication", sessionCommunicationError(request2, {
|
|
4365
4534
|
code: "TRANSPORT_BUDGET_EXCEEDED",
|
|
4366
4535
|
message: "Response exceeds the configured transport byte budget"
|
|
4367
4536
|
}));
|
|
4368
4537
|
return;
|
|
4369
4538
|
}
|
|
4370
4539
|
diagnostics.durations.emit = performance2.now() - emitStarted;
|
|
4371
|
-
metrics.record(
|
|
4372
|
-
const errorKey = JSON.stringify([
|
|
4540
|
+
metrics.record(request2, diagnostics, response.kind === "error");
|
|
4541
|
+
const errorKey = JSON.stringify([request2.sessionId, request2.operation, request2.version]);
|
|
4373
4542
|
if (response.kind === "error") {
|
|
4374
4543
|
this.#errors.failure(
|
|
4375
4544
|
errorKey,
|
|
4376
4545
|
Object.assign(new Error(response.error.message), { code: response.error.code }),
|
|
4377
|
-
{ ...diagnostics.fields(
|
|
4546
|
+
{ ...diagnostics.fields(request2), code: response.error.code }
|
|
4378
4547
|
);
|
|
4379
4548
|
} else {
|
|
4380
4549
|
this.#errors.recovered(errorKey);
|
|
4381
4550
|
if (diagnostics.activeMs >= 1e3) {
|
|
4382
|
-
logger.info(diagnostics.fields(
|
|
4551
|
+
logger.info(diagnostics.fields(request2), "session.communication.operation-slow");
|
|
4383
4552
|
} else {
|
|
4384
|
-
logger.debug(diagnostics.fields(
|
|
4553
|
+
logger.debug(diagnostics.fields(request2), "session.communication.operation-completed");
|
|
4385
4554
|
}
|
|
4386
4555
|
}
|
|
4387
4556
|
}
|
|
@@ -4664,32 +4833,32 @@ var SessionOptionsHandler = class {
|
|
|
4664
4833
|
#modelErrors;
|
|
4665
4834
|
#partialModelErrors;
|
|
4666
4835
|
#capabilityErrors;
|
|
4667
|
-
async handle(
|
|
4836
|
+
async handle(request2, scope) {
|
|
4668
4837
|
const { adapter, config, machineId, logger, emit } = this.options;
|
|
4669
4838
|
const diagnostics = new OperationDiagnostics();
|
|
4670
|
-
const errorKey = JSON.stringify([
|
|
4839
|
+
const errorKey = JSON.stringify([request2.machineId, request2.sessionId, request2.workspaceId]);
|
|
4671
4840
|
let availableModels;
|
|
4672
4841
|
let configuration;
|
|
4673
4842
|
let failureStage;
|
|
4674
4843
|
try {
|
|
4675
|
-
if (scope.clientId !== void 0 &&
|
|
4676
|
-
this.options.negotiateAgentControls(scope.clientId,
|
|
4844
|
+
if (scope.clientId !== void 0 && request2.capabilities !== void 0) {
|
|
4845
|
+
this.options.negotiateAgentControls(scope.clientId, request2.capabilities);
|
|
4677
4846
|
}
|
|
4678
|
-
const sessionWorkingDirectories =
|
|
4847
|
+
const sessionWorkingDirectories = request2.sessionId === void 0 ? adapter.listSessions(config.userId, machineId).then((sessions) => sessions.flatMap((session) => session.workingDirectory === void 0 ? [] : [session.workingDirectory])) : Promise.resolve([]);
|
|
4679
4848
|
const environmentDiagnostics = new OperationDiagnostics();
|
|
4680
|
-
const environmentSessionId =
|
|
4849
|
+
const environmentSessionId = request2.sessionId;
|
|
4681
4850
|
const sessionEnvironment = environmentSessionId === void 0 ? Promise.resolve(void 0) : environmentDiagnostics.run(() => adapter.getSessionEnvironment(environmentSessionId)).then((environment3) => {
|
|
4682
4851
|
this.#environmentErrors.recovered(errorKey);
|
|
4683
4852
|
if (environmentDiagnostics.activeMs >= 1e3) {
|
|
4684
4853
|
logger.info(
|
|
4685
|
-
{ ...diagnosticRequest(
|
|
4854
|
+
{ ...diagnosticRequest(request2), ...environmentDiagnostics.details() },
|
|
4686
4855
|
"copilot.session.environment.slow"
|
|
4687
4856
|
);
|
|
4688
4857
|
}
|
|
4689
4858
|
return environment3;
|
|
4690
4859
|
}).catch((error) => {
|
|
4691
4860
|
this.#environmentErrors.failure(errorKey, error, {
|
|
4692
|
-
...diagnosticRequest(
|
|
4861
|
+
...diagnosticRequest(request2),
|
|
4693
4862
|
...environmentDiagnostics.details()
|
|
4694
4863
|
});
|
|
4695
4864
|
return void 0;
|
|
@@ -4698,7 +4867,7 @@ var SessionOptionsHandler = class {
|
|
|
4698
4867
|
let modelFailure;
|
|
4699
4868
|
const planDiagnostics = new OperationDiagnostics();
|
|
4700
4869
|
const readSessionPlan = adapter.readSessionPlan?.bind(adapter);
|
|
4701
|
-
const planSessionId =
|
|
4870
|
+
const planSessionId = request2.sessionId;
|
|
4702
4871
|
const sessionPlan = planSessionId === void 0 || readSessionPlan === void 0 || adapter.getSessionCapabilities?.(planSessionId).supportsPlanRead === false ? Promise.resolve(void 0) : planDiagnostics.run(async () => ConversationItemUpsertSchema.parse({
|
|
4703
4872
|
userId: config.userId,
|
|
4704
4873
|
machineId,
|
|
@@ -4709,14 +4878,14 @@ var SessionOptionsHandler = class {
|
|
|
4709
4878
|
return plan2;
|
|
4710
4879
|
}).catch((error) => {
|
|
4711
4880
|
this.#planErrors.failure(errorKey, error, {
|
|
4712
|
-
...diagnosticRequest(
|
|
4881
|
+
...diagnosticRequest(request2),
|
|
4713
4882
|
...planDiagnostics.details()
|
|
4714
4883
|
});
|
|
4715
4884
|
return void 0;
|
|
4716
4885
|
});
|
|
4717
4886
|
const [workspaceResult, modelResult, configurationResult] = await diagnostics.run(() => Promise.allSettled([
|
|
4718
4887
|
sessionWorkingDirectories.then((workingDirectories) => listSelectableWorkspaces(workingDirectories, config.workspaceRoot)),
|
|
4719
|
-
adapter.listModels(
|
|
4888
|
+
adapter.listModels(request2.sessionId).then((models2) => {
|
|
4720
4889
|
if (models2.length > 0) {
|
|
4721
4890
|
this.#modelErrors.recovered(errorKey);
|
|
4722
4891
|
this.#partialModelErrors.recovered(errorKey);
|
|
@@ -4727,10 +4896,10 @@ var SessionOptionsHandler = class {
|
|
|
4727
4896
|
modelRefreshError = toErrorDetails(error).message.slice(0, 4096) || "Coding-agent models are unavailable.";
|
|
4728
4897
|
const availableModels2 = error instanceof AgentModelListingError ? error.availableModels : [];
|
|
4729
4898
|
if (availableModels2.length === 0) modelFailure = error;
|
|
4730
|
-
(availableModels2.length === 0 ? this.#modelErrors : this.#partialModelErrors).failure(errorKey, error, diagnosticRequest(
|
|
4899
|
+
(availableModels2.length === 0 ? this.#modelErrors : this.#partialModelErrors).failure(errorKey, error, diagnosticRequest(request2));
|
|
4731
4900
|
return availableModels2;
|
|
4732
4901
|
}),
|
|
4733
|
-
|
|
4902
|
+
request2.sessionId === void 0 ? Promise.resolve(void 0) : adapter.getSessionConfiguration(request2.sessionId)
|
|
4734
4903
|
]));
|
|
4735
4904
|
if (modelResult.status === "fulfilled" && modelResult.value.length > 0) availableModels = modelResult.value;
|
|
4736
4905
|
if (configurationResult.status === "fulfilled") configuration = configurationResult.value;
|
|
@@ -4763,24 +4932,24 @@ var SessionOptionsHandler = class {
|
|
|
4763
4932
|
failureStage = "models";
|
|
4764
4933
|
throw modelFailure ?? new Error("No coding-agent models are available. Select an authenticated coding agent on the PC.");
|
|
4765
4934
|
}
|
|
4766
|
-
const progressive =
|
|
4935
|
+
const progressive = request2.sessionId !== void 0 && request2.capabilities?.includes(SESSION_OPTIONS_PROGRESSIVE_CAPABILITY) === true;
|
|
4767
4936
|
const environment2 = progressive ? void 0 : await sessionEnvironment;
|
|
4768
|
-
const worktreeCreationSupported =
|
|
4937
|
+
const worktreeCreationSupported = request2.sessionId === void 0 && request2.capabilities?.includes(SESSION_WORKTREE_CREATION_CAPABILITY) === true;
|
|
4769
4938
|
let worktreeChoices;
|
|
4770
|
-
if (worktreeCreationSupported &&
|
|
4771
|
-
const workspace = workspaces.find((candidate) => candidate.id ===
|
|
4939
|
+
if (worktreeCreationSupported && request2.workspaceId !== void 0) {
|
|
4940
|
+
const workspace = workspaces.find((candidate) => candidate.id === request2.workspaceId);
|
|
4772
4941
|
if (workspace === void 0) {
|
|
4773
4942
|
throw new Error("The selected working directory is no longer available from Desktop folders or existing coding agent sessions.");
|
|
4774
4943
|
}
|
|
4775
4944
|
worktreeChoices = await listSessionWorktreeBranches(workspace.path);
|
|
4776
4945
|
}
|
|
4777
|
-
const capabilities = adapter.getSessionCapabilities?.(
|
|
4946
|
+
const capabilities = adapter.getSessionCapabilities?.(request2.sessionId) ?? adapter;
|
|
4778
4947
|
this.#errors.recovered(errorKey);
|
|
4779
4948
|
const result = {
|
|
4780
4949
|
ok: true,
|
|
4781
|
-
requestId:
|
|
4950
|
+
requestId: request2.requestId,
|
|
4782
4951
|
machineId,
|
|
4783
|
-
...
|
|
4952
|
+
...request2.sessionId === void 0 ? {} : { sessionId: request2.sessionId },
|
|
4784
4953
|
workspaces,
|
|
4785
4954
|
models,
|
|
4786
4955
|
...modelRefreshError === void 0 ? {} : { modelRefreshError },
|
|
@@ -4788,7 +4957,7 @@ var SessionOptionsHandler = class {
|
|
|
4788
4957
|
...worktreeCreationSupported ? { worktreeCreationSupported: true } : {},
|
|
4789
4958
|
...worktreeChoices === void 0 ? {} : { worktreeBranches: worktreeChoices.branches },
|
|
4790
4959
|
...worktreeChoices?.currentBranch === void 0 ? {} : { worktreeCurrentBranch: worktreeChoices.currentBranch },
|
|
4791
|
-
...
|
|
4960
|
+
...request2.sessionId !== void 0 && request2.capabilities?.includes(SESSION_FILE_ATTACHMENTS_CAPABILITY) === true ? { fileAttachmentsSupported: (capabilities.supportsFileAttachments ?? adapter.supportsFileAttachments) === true } : {},
|
|
4792
4961
|
...capabilities.supportsReasoningEffort ? { reasoningEffortConfigurationSupported: true } : {},
|
|
4793
4962
|
...current?.modelId === void 0 ? {} : { currentModelId: current.modelId },
|
|
4794
4963
|
...current === void 0 ? {} : {
|
|
@@ -4807,7 +4976,7 @@ var SessionOptionsHandler = class {
|
|
|
4807
4976
|
if (progressive) {
|
|
4808
4977
|
const environment3 = await sessionEnvironment;
|
|
4809
4978
|
if (!scope.isCurrent()) return;
|
|
4810
|
-
adapter.getSessionCapabilities?.(
|
|
4979
|
+
adapter.getSessionCapabilities?.(request2.sessionId);
|
|
4811
4980
|
emit("session.options.result", {
|
|
4812
4981
|
...result,
|
|
4813
4982
|
...environment3 === void 0 ? {} : { environment: environment3 }
|
|
@@ -4819,18 +4988,18 @@ var SessionOptionsHandler = class {
|
|
|
4819
4988
|
}
|
|
4820
4989
|
} catch (error) {
|
|
4821
4990
|
this.#errors.failure(errorKey, error, {
|
|
4822
|
-
...diagnosticRequest(
|
|
4991
|
+
...diagnosticRequest(request2),
|
|
4823
4992
|
...diagnostics.details(),
|
|
4824
4993
|
failureStage
|
|
4825
4994
|
});
|
|
4826
4995
|
const partial = {};
|
|
4827
|
-
const negotiatedPartial =
|
|
4996
|
+
const negotiatedPartial = request2.capabilities?.includes(SESSION_OPTIONS_PARTIAL_CAPABILITY) === true;
|
|
4828
4997
|
if (negotiatedPartial && failureStage !== void 0) partial.failureStage = failureStage;
|
|
4829
|
-
if (
|
|
4998
|
+
if (request2.sessionId !== void 0 && !isSessionRestoreFailure(error)) {
|
|
4830
4999
|
try {
|
|
4831
|
-
const capabilities = adapter.getSessionCapabilities?.(
|
|
5000
|
+
const capabilities = adapter.getSessionCapabilities?.(request2.sessionId) ?? adapter;
|
|
4832
5001
|
this.#capabilityErrors.recovered(errorKey);
|
|
4833
|
-
if (
|
|
5002
|
+
if (request2.capabilities?.includes(SESSION_FILE_ATTACHMENTS_CAPABILITY) === true) {
|
|
4834
5003
|
partial.fileAttachmentsSupported = (capabilities.supportsFileAttachments ?? adapter.supportsFileAttachments) === true;
|
|
4835
5004
|
}
|
|
4836
5005
|
if (negotiatedPartial) {
|
|
@@ -4846,15 +5015,15 @@ var SessionOptionsHandler = class {
|
|
|
4846
5015
|
}
|
|
4847
5016
|
}
|
|
4848
5017
|
} catch (capabilityError) {
|
|
4849
|
-
this.#capabilityErrors.failure(errorKey, capabilityError, diagnosticRequest(
|
|
5018
|
+
this.#capabilityErrors.failure(errorKey, capabilityError, diagnosticRequest(request2));
|
|
4850
5019
|
}
|
|
4851
5020
|
}
|
|
4852
5021
|
emit("session.options.result", {
|
|
4853
5022
|
...partial,
|
|
4854
5023
|
ok: false,
|
|
4855
|
-
requestId:
|
|
5024
|
+
requestId: request2.requestId,
|
|
4856
5025
|
machineId,
|
|
4857
|
-
...
|
|
5026
|
+
...request2.sessionId === void 0 ? {} : { sessionId: request2.sessionId },
|
|
4858
5027
|
error: sessionRestoreFailure(error) ?? {
|
|
4859
5028
|
code: operationErrorCode(adapter.agentId, "SESSION_OPTIONS", error),
|
|
4860
5029
|
message: toErrorDetails(error).message.slice(0, 1024)
|
|
@@ -4987,39 +5156,39 @@ var SessionCommandsHandler = class {
|
|
|
4987
5156
|
const { adapter } = this.options;
|
|
4988
5157
|
return adapter.supportsSessionDelete ?? adapter.deleteSession !== void 0;
|
|
4989
5158
|
}
|
|
4990
|
-
async create(
|
|
5159
|
+
async create(request2, scope) {
|
|
4991
5160
|
const { adapter, config, machineId, emit } = this.options;
|
|
4992
5161
|
try {
|
|
4993
5162
|
const session = await this.#creations.run({
|
|
4994
|
-
operationId: JSON.stringify([config.userId, machineId, scope.clientId,
|
|
5163
|
+
operationId: JSON.stringify([config.userId, machineId, scope.clientId, request2.requestId]),
|
|
4995
5164
|
fingerprint: JSON.stringify([
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5165
|
+
request2.workspaceId,
|
|
5166
|
+
request2.modelId,
|
|
5167
|
+
request2.agentMode,
|
|
5168
|
+
request2.reasoningEffort,
|
|
5169
|
+
request2.worktree === void 0 ? null : [
|
|
5170
|
+
request2.worktree.branchName ?? "",
|
|
5171
|
+
request2.worktree.baseBranch ?? ""
|
|
5003
5172
|
]
|
|
5004
5173
|
]),
|
|
5005
|
-
execute: () => this.#createSession(
|
|
5174
|
+
execute: () => this.#createSession(request2, scope)
|
|
5006
5175
|
});
|
|
5007
5176
|
if (adapter.isSessionVisible?.(session.sessionId) === false) {
|
|
5008
|
-
throw new Error("The session's coding agent is no longer shared on the PC" + (
|
|
5177
|
+
throw new Error("The session's coding agent is no longer shared on the PC" + (request2.worktree === void 0 ? "" : `. Worktree retained at "${session.workingDirectory}".`));
|
|
5009
5178
|
}
|
|
5010
5179
|
emit("session.create.result", {
|
|
5011
5180
|
ok: true,
|
|
5012
|
-
requestId:
|
|
5181
|
+
requestId: request2.requestId,
|
|
5013
5182
|
machineId,
|
|
5014
5183
|
session,
|
|
5015
|
-
modelId:
|
|
5016
|
-
agentMode:
|
|
5017
|
-
...
|
|
5184
|
+
modelId: request2.modelId,
|
|
5185
|
+
agentMode: request2.agentMode,
|
|
5186
|
+
...request2.reasoningEffort === void 0 ? {} : { reasoningEffort: request2.reasoningEffort }
|
|
5018
5187
|
});
|
|
5019
5188
|
} catch (error) {
|
|
5020
5189
|
emit("session.create.result", {
|
|
5021
5190
|
ok: false,
|
|
5022
|
-
requestId:
|
|
5191
|
+
requestId: request2.requestId,
|
|
5023
5192
|
machineId,
|
|
5024
5193
|
error: {
|
|
5025
5194
|
code: error instanceof OperationConflictError ? "OPERATION_CONFLICT" : error instanceof OperationCapacityError ? "OPERATION_CAPACITY_EXCEEDED" : operationErrorCode(adapter.agentId, "SESSION_CREATE", error),
|
|
@@ -5028,26 +5197,26 @@ var SessionCommandsHandler = class {
|
|
|
5028
5197
|
});
|
|
5029
5198
|
}
|
|
5030
5199
|
}
|
|
5031
|
-
async #createSession(
|
|
5200
|
+
async #createSession(request2, scope) {
|
|
5032
5201
|
const { adapter, config, machineId, logger } = this.options;
|
|
5033
5202
|
const sessions = await adapter.listSessions(config.userId, machineId);
|
|
5034
5203
|
const sessionWorkingDirectories = sessions.flatMap((session2) => session2.workingDirectory === void 0 ? [] : [session2.workingDirectory]);
|
|
5035
|
-
const workspace = await resolveSelectableWorkspace(
|
|
5204
|
+
const workspace = await resolveSelectableWorkspace(request2.workspaceId, sessionWorkingDirectories, config.workspaceRoot);
|
|
5036
5205
|
if (workspace === void 0) {
|
|
5037
5206
|
throw new Error(
|
|
5038
5207
|
"The selected working directory is no longer available from Desktop folders or existing coding agent sessions"
|
|
5039
5208
|
);
|
|
5040
5209
|
}
|
|
5041
|
-
const worktree =
|
|
5210
|
+
const worktree = request2.worktree === void 0 ? void 0 : await createSessionWorktree(workspace.path, request2.worktree.branchName, request2.worktree.baseBranch);
|
|
5042
5211
|
let session;
|
|
5043
5212
|
try {
|
|
5044
5213
|
const created = await adapter.createSession({
|
|
5045
5214
|
userId: config.userId,
|
|
5046
5215
|
machineId,
|
|
5047
5216
|
workingDirectory: worktree?.path ?? workspace.path,
|
|
5048
|
-
modelId:
|
|
5049
|
-
agentMode:
|
|
5050
|
-
...
|
|
5217
|
+
modelId: request2.modelId,
|
|
5218
|
+
agentMode: request2.agentMode,
|
|
5219
|
+
...request2.reasoningEffort === void 0 ? {} : { reasoningEffort: request2.reasoningEffort }
|
|
5051
5220
|
});
|
|
5052
5221
|
session = worktree === void 0 ? created : { ...created, workingDirectory: worktree.path };
|
|
5053
5222
|
if (adapter.isSessionVisible?.(session.sessionId) === false) {
|
|
@@ -5065,38 +5234,38 @@ var SessionCommandsHandler = class {
|
|
|
5065
5234
|
});
|
|
5066
5235
|
return session;
|
|
5067
5236
|
}
|
|
5068
|
-
async delete(
|
|
5237
|
+
async delete(request2, scope) {
|
|
5069
5238
|
const { adapter, machineId, emit, logger } = this.options;
|
|
5070
5239
|
if (!this.supportsSessionDelete || adapter.deleteSession === void 0) {
|
|
5071
5240
|
emit("session.delete.result", {
|
|
5072
5241
|
ok: false,
|
|
5073
|
-
requestId:
|
|
5242
|
+
requestId: request2.requestId,
|
|
5074
5243
|
machineId,
|
|
5075
|
-
sessionId:
|
|
5244
|
+
sessionId: request2.sessionId,
|
|
5076
5245
|
error: { code: "SESSION_DELETE_UNSUPPORTED", message: "Session deletion is not supported yet" }
|
|
5077
5246
|
});
|
|
5078
5247
|
return;
|
|
5079
5248
|
}
|
|
5080
5249
|
try {
|
|
5081
|
-
await adapter.deleteSession(
|
|
5082
|
-
this.options.removeSession(
|
|
5250
|
+
await adapter.deleteSession(request2.sessionId);
|
|
5251
|
+
this.options.removeSession(request2.sessionId);
|
|
5083
5252
|
try {
|
|
5084
5253
|
await this.options.refreshSessions(scope.clientId);
|
|
5085
5254
|
} catch (error) {
|
|
5086
|
-
logger.error({ error: toErrorDetails(error), sessionId:
|
|
5255
|
+
logger.error({ error: toErrorDetails(error), sessionId: request2.sessionId }, "sessions.post-delete-sync.failed");
|
|
5087
5256
|
}
|
|
5088
5257
|
emit("session.delete.result", {
|
|
5089
5258
|
ok: true,
|
|
5090
|
-
requestId:
|
|
5259
|
+
requestId: request2.requestId,
|
|
5091
5260
|
machineId,
|
|
5092
|
-
sessionId:
|
|
5261
|
+
sessionId: request2.sessionId
|
|
5093
5262
|
});
|
|
5094
5263
|
} catch (error) {
|
|
5095
5264
|
emit("session.delete.result", {
|
|
5096
5265
|
ok: false,
|
|
5097
|
-
requestId:
|
|
5266
|
+
requestId: request2.requestId,
|
|
5098
5267
|
machineId,
|
|
5099
|
-
sessionId:
|
|
5268
|
+
sessionId: request2.sessionId,
|
|
5100
5269
|
error: {
|
|
5101
5270
|
code: operationErrorCode(adapter.agentId, "SESSION_DELETE", error),
|
|
5102
5271
|
message: sessionRestoreFailure(error)?.message ?? toErrorDetails(error).message
|
|
@@ -5104,23 +5273,23 @@ var SessionCommandsHandler = class {
|
|
|
5104
5273
|
});
|
|
5105
5274
|
}
|
|
5106
5275
|
}
|
|
5107
|
-
async configure(
|
|
5276
|
+
async configure(request2, scope) {
|
|
5108
5277
|
const { adapter, machineId, emit } = this.options;
|
|
5109
5278
|
try {
|
|
5110
|
-
if (
|
|
5279
|
+
if (request2.configOption !== void 0 && !this.options.supportsAgentControls(scope.clientId)) {
|
|
5111
5280
|
throw new Error("Native agent controls require coding-agent-controls-v1 support");
|
|
5112
5281
|
}
|
|
5113
|
-
const configuration = await adapter.configureSession(
|
|
5114
|
-
...
|
|
5115
|
-
...
|
|
5116
|
-
...
|
|
5117
|
-
...
|
|
5282
|
+
const configuration = await adapter.configureSession(request2.sessionId, {
|
|
5283
|
+
...request2.modelId === void 0 ? {} : { modelId: request2.modelId },
|
|
5284
|
+
...request2.agentMode === void 0 ? {} : { agentMode: request2.agentMode },
|
|
5285
|
+
...request2.reasoningEffort === void 0 ? {} : { reasoningEffort: request2.reasoningEffort },
|
|
5286
|
+
...request2.configOption === void 0 ? {} : { configOption: request2.configOption }
|
|
5118
5287
|
});
|
|
5119
5288
|
emit("session.configure.result", {
|
|
5120
5289
|
ok: true,
|
|
5121
|
-
requestId:
|
|
5290
|
+
requestId: request2.requestId,
|
|
5122
5291
|
machineId,
|
|
5123
|
-
sessionId:
|
|
5292
|
+
sessionId: request2.sessionId,
|
|
5124
5293
|
...configuration.modelId === void 0 ? {} : { modelId: configuration.modelId },
|
|
5125
5294
|
agentMode: configuration.agentMode,
|
|
5126
5295
|
reasoningEffort: configuration.reasoningEffort,
|
|
@@ -5129,9 +5298,9 @@ var SessionCommandsHandler = class {
|
|
|
5129
5298
|
} catch (error) {
|
|
5130
5299
|
emit("session.configure.result", {
|
|
5131
5300
|
ok: false,
|
|
5132
|
-
requestId:
|
|
5301
|
+
requestId: request2.requestId,
|
|
5133
5302
|
machineId,
|
|
5134
|
-
sessionId:
|
|
5303
|
+
sessionId: request2.sessionId,
|
|
5135
5304
|
error: {
|
|
5136
5305
|
code: operationErrorCode(adapter.agentId, "SESSION_CONFIGURE", error),
|
|
5137
5306
|
message: sessionRestoreFailure(error)?.message ?? toErrorDetails(error).message
|
|
@@ -5139,28 +5308,28 @@ var SessionCommandsHandler = class {
|
|
|
5139
5308
|
});
|
|
5140
5309
|
}
|
|
5141
5310
|
}
|
|
5142
|
-
async remote(
|
|
5311
|
+
async remote(request2, scope) {
|
|
5143
5312
|
const { adapter, machineId, emit, logger } = this.options;
|
|
5144
5313
|
try {
|
|
5145
|
-
const status =
|
|
5314
|
+
const status = request2.action === "status" ? await adapter.getSessionRemoteStatus(request2.sessionId) : await adapter.setSessionRemote(request2.sessionId, request2.action === "enable");
|
|
5146
5315
|
emit("session.remote.result", {
|
|
5147
5316
|
ok: true,
|
|
5148
|
-
requestId:
|
|
5317
|
+
requestId: request2.requestId,
|
|
5149
5318
|
machineId,
|
|
5150
|
-
sessionId:
|
|
5319
|
+
sessionId: request2.sessionId,
|
|
5151
5320
|
status
|
|
5152
5321
|
});
|
|
5153
|
-
if (
|
|
5322
|
+
if (request2.action !== "status") {
|
|
5154
5323
|
void this.options.refreshSessions(scope.clientId).catch((error) => {
|
|
5155
|
-
logger.warn({ error: toErrorDetails(error), sessionId:
|
|
5324
|
+
logger.warn({ error: toErrorDetails(error), sessionId: request2.sessionId }, "sessions.post-remote-sync.failed");
|
|
5156
5325
|
});
|
|
5157
5326
|
}
|
|
5158
5327
|
} catch (error) {
|
|
5159
5328
|
emit("session.remote.result", {
|
|
5160
5329
|
ok: false,
|
|
5161
|
-
requestId:
|
|
5330
|
+
requestId: request2.requestId,
|
|
5162
5331
|
machineId,
|
|
5163
|
-
sessionId:
|
|
5332
|
+
sessionId: request2.sessionId,
|
|
5164
5333
|
error: {
|
|
5165
5334
|
code: operationErrorCode(adapter.agentId, "SESSION_REMOTE", error),
|
|
5166
5335
|
message: sessionRestoreFailure(error)?.message ?? toErrorDetails(error).message
|
|
@@ -5168,22 +5337,22 @@ var SessionCommandsHandler = class {
|
|
|
5168
5337
|
});
|
|
5169
5338
|
}
|
|
5170
5339
|
}
|
|
5171
|
-
async abort(
|
|
5340
|
+
async abort(request2) {
|
|
5172
5341
|
const { adapter, machineId, emit } = this.options;
|
|
5173
5342
|
try {
|
|
5174
|
-
await adapter.abortSession(
|
|
5343
|
+
await adapter.abortSession(request2.sessionId);
|
|
5175
5344
|
emit("session.abort.result", {
|
|
5176
5345
|
ok: true,
|
|
5177
|
-
requestId:
|
|
5346
|
+
requestId: request2.requestId,
|
|
5178
5347
|
machineId,
|
|
5179
|
-
sessionId:
|
|
5348
|
+
sessionId: request2.sessionId
|
|
5180
5349
|
});
|
|
5181
5350
|
} catch (error) {
|
|
5182
5351
|
emit("session.abort.result", {
|
|
5183
5352
|
ok: false,
|
|
5184
|
-
requestId:
|
|
5185
|
-
machineId:
|
|
5186
|
-
sessionId:
|
|
5353
|
+
requestId: request2.requestId,
|
|
5354
|
+
machineId: request2.machineId,
|
|
5355
|
+
sessionId: request2.sessionId,
|
|
5187
5356
|
error: {
|
|
5188
5357
|
code: operationErrorCode(adapter.agentId, "ABORT", error),
|
|
5189
5358
|
message: sessionRestoreFailure(error)?.message ?? toErrorDetails(error).message
|
|
@@ -5195,14 +5364,14 @@ var SessionCommandsHandler = class {
|
|
|
5195
5364
|
|
|
5196
5365
|
// src/service/requests/session-prompt.ts
|
|
5197
5366
|
import { createHash as createHash10 } from "node:crypto";
|
|
5198
|
-
function promptOperationFingerprint(
|
|
5199
|
-
const fingerprint = createHash10("sha256").update(
|
|
5367
|
+
function promptOperationFingerprint(request2) {
|
|
5368
|
+
const fingerprint = createHash10("sha256").update(request2.sessionId).update("\0").update(request2.mode).update("\0").update(request2.prompt).update("\0").update(request2.attachments?.map((attachment) => attachment.sha256).join(",") ?? "").update("\0").update(JSON.stringify(request2.fileAttachments?.map(({ name, mimeType, sha256 }) => ({
|
|
5200
5369
|
name,
|
|
5201
5370
|
mimeType,
|
|
5202
5371
|
sha256
|
|
5203
5372
|
})) ?? []));
|
|
5204
|
-
if (
|
|
5205
|
-
fingerprint.update("\0").update(JSON.stringify(
|
|
5373
|
+
if (request2.avatarPersona !== void 0) {
|
|
5374
|
+
fingerprint.update("\0").update(JSON.stringify(request2.avatarPersona));
|
|
5206
5375
|
}
|
|
5207
5376
|
return fingerprint.digest("base64url");
|
|
5208
5377
|
}
|
|
@@ -5218,47 +5387,47 @@ var SessionPromptHandler = class {
|
|
|
5218
5387
|
reset() {
|
|
5219
5388
|
this.#operations.clear();
|
|
5220
5389
|
}
|
|
5221
|
-
async handle(
|
|
5390
|
+
async handle(request2, context) {
|
|
5222
5391
|
const { adapter, machineId, emit, logger } = this.options;
|
|
5223
5392
|
const diagnostics = new OperationDiagnostics();
|
|
5224
5393
|
let replay;
|
|
5225
5394
|
try {
|
|
5226
|
-
if (adapter.isSessionVisible?.(
|
|
5395
|
+
if (adapter.isSessionVisible?.(request2.sessionId) === false) {
|
|
5227
5396
|
throw new Error("This session's coding agent is not shared or is unavailable on the PC");
|
|
5228
5397
|
}
|
|
5229
|
-
if (
|
|
5398
|
+
if (request2.avatarPersona !== void 0 && adapter.agentId !== "copilot" && adapter.agentId !== "managed") {
|
|
5230
5399
|
throw new Error("Avatar personas require Copilot; nothing was submitted");
|
|
5231
5400
|
}
|
|
5232
5401
|
const accepted = await diagnostics.run(() => this.#operations.run({
|
|
5233
|
-
operationId:
|
|
5234
|
-
fingerprint: promptOperationFingerprint(
|
|
5402
|
+
operationId: request2.operationId,
|
|
5403
|
+
fingerprint: promptOperationFingerprint(request2),
|
|
5235
5404
|
retryRejected: (error) => error instanceof PromptPreparationError,
|
|
5236
5405
|
onReplay: (state) => {
|
|
5237
5406
|
replay = state;
|
|
5238
5407
|
logger.debug?.({
|
|
5239
|
-
...diagnosticRequest(
|
|
5408
|
+
...diagnosticRequest(request2),
|
|
5240
5409
|
dedupState: state
|
|
5241
5410
|
}, "session.prompt.deduplicated");
|
|
5242
5411
|
},
|
|
5243
5412
|
execute: () => adapter.sendPrompt(
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5413
|
+
request2.sessionId,
|
|
5414
|
+
request2.prompt,
|
|
5415
|
+
request2.mode,
|
|
5416
|
+
request2.attachments,
|
|
5248
5417
|
this.options.supportsPersistentInteractions(context.clientId),
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
...
|
|
5418
|
+
request2.fileAttachments,
|
|
5419
|
+
request2.operationId,
|
|
5420
|
+
...request2.avatarPersona === void 0 ? [] : [request2.avatarPersona]
|
|
5252
5421
|
)
|
|
5253
5422
|
}));
|
|
5254
5423
|
emit("session.prompt.result", {
|
|
5255
5424
|
ok: true,
|
|
5256
|
-
requestId:
|
|
5257
|
-
operationId:
|
|
5425
|
+
requestId: request2.requestId,
|
|
5426
|
+
operationId: request2.operationId,
|
|
5258
5427
|
machineId,
|
|
5259
|
-
sessionId:
|
|
5428
|
+
sessionId: request2.sessionId,
|
|
5260
5429
|
messageId: accepted.messageId,
|
|
5261
|
-
mode:
|
|
5430
|
+
mode: request2.mode,
|
|
5262
5431
|
deliveryState: accepted.deliveryState,
|
|
5263
5432
|
...accepted.submittedAt !== void 0 && this.options.supportsSubmissionTime(context.clientId) ? { submittedAt: accepted.submittedAt } : {}
|
|
5264
5433
|
});
|
|
@@ -5266,7 +5435,7 @@ var SessionPromptHandler = class {
|
|
|
5266
5435
|
const details = toErrorDetails(error);
|
|
5267
5436
|
const failure = error instanceof OperationConflictError ? { code: "OPERATION_CONFLICT", message: "The operation ID was already used for a different prompt" } : error instanceof OperationCapacityError ? { code: "OPERATION_CAPACITY_EXCEEDED", message: "Too many prompt operations are currently in progress" } : sessionRestoreFailure(error) ?? { code: operationErrorCode(adapter.agentId, "PROMPT", error), message: details.message };
|
|
5268
5437
|
logger.error({
|
|
5269
|
-
...diagnosticRequest(
|
|
5438
|
+
...diagnosticRequest(request2),
|
|
5270
5439
|
...diagnostics.details(),
|
|
5271
5440
|
...diagnosticError(error),
|
|
5272
5441
|
...replay === void 0 ? {} : { dedupState: replay },
|
|
@@ -5274,10 +5443,10 @@ var SessionPromptHandler = class {
|
|
|
5274
5443
|
}, "session.prompt.failed");
|
|
5275
5444
|
emit("session.prompt.result", {
|
|
5276
5445
|
ok: false,
|
|
5277
|
-
requestId:
|
|
5278
|
-
operationId:
|
|
5446
|
+
requestId: request2.requestId,
|
|
5447
|
+
operationId: request2.operationId,
|
|
5279
5448
|
machineId,
|
|
5280
|
-
sessionId:
|
|
5449
|
+
sessionId: request2.sessionId,
|
|
5281
5450
|
error: failure
|
|
5282
5451
|
});
|
|
5283
5452
|
}
|
|
@@ -5290,35 +5459,35 @@ var InteractionResponseHandler = class {
|
|
|
5290
5459
|
this.options = options;
|
|
5291
5460
|
}
|
|
5292
5461
|
options;
|
|
5293
|
-
permission(
|
|
5462
|
+
permission(request2) {
|
|
5294
5463
|
const accepted = this.options.adapter.respondPermission(
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5464
|
+
request2.permissionRequestId,
|
|
5465
|
+
request2.decision,
|
|
5466
|
+
request2.feedback
|
|
5298
5467
|
);
|
|
5299
5468
|
this.options.emit("permission.respond.result", {
|
|
5300
5469
|
ok: accepted,
|
|
5301
|
-
requestId:
|
|
5302
|
-
permissionRequestId:
|
|
5303
|
-
machineId:
|
|
5304
|
-
sessionId:
|
|
5470
|
+
requestId: request2.requestId,
|
|
5471
|
+
permissionRequestId: request2.permissionRequestId,
|
|
5472
|
+
machineId: request2.machineId,
|
|
5473
|
+
sessionId: request2.sessionId,
|
|
5305
5474
|
...accepted ? {} : {
|
|
5306
5475
|
error: { code: "PERMISSION_REQUEST_NOT_FOUND", message: "The permission request is no longer pending" }
|
|
5307
5476
|
}
|
|
5308
5477
|
});
|
|
5309
5478
|
}
|
|
5310
|
-
async interaction(
|
|
5479
|
+
async interaction(request2, scope) {
|
|
5311
5480
|
try {
|
|
5312
|
-
if (
|
|
5481
|
+
if (request2.response.kind === "permission" && request2.response.decision === "approve-always" && !this.options.supportsAgentControls(scope.clientId)) {
|
|
5313
5482
|
throw new Error("Persistent approval requires coding-agent-controls-v1 support");
|
|
5314
5483
|
}
|
|
5315
|
-
const accepted = await this.options.adapter.respondInteraction(
|
|
5484
|
+
const accepted = await this.options.adapter.respondInteraction(request2.interactionRequestId, request2.response);
|
|
5316
5485
|
this.options.emit("interaction.respond.result", {
|
|
5317
5486
|
ok: accepted,
|
|
5318
|
-
requestId:
|
|
5319
|
-
interactionRequestId:
|
|
5320
|
-
machineId:
|
|
5321
|
-
sessionId:
|
|
5487
|
+
requestId: request2.requestId,
|
|
5488
|
+
interactionRequestId: request2.interactionRequestId,
|
|
5489
|
+
machineId: request2.machineId,
|
|
5490
|
+
sessionId: request2.sessionId,
|
|
5322
5491
|
...accepted ? {} : {
|
|
5323
5492
|
error: { code: "INTERACTION_REQUEST_NOT_FOUND", message: "The interaction is no longer pending" }
|
|
5324
5493
|
}
|
|
@@ -5327,16 +5496,16 @@ var InteractionResponseHandler = class {
|
|
|
5327
5496
|
const details = toErrorDetails(error);
|
|
5328
5497
|
this.options.logger.error({
|
|
5329
5498
|
error: details,
|
|
5330
|
-
requestId:
|
|
5331
|
-
interactionRequestId:
|
|
5332
|
-
sessionId:
|
|
5499
|
+
requestId: request2.requestId,
|
|
5500
|
+
interactionRequestId: request2.interactionRequestId,
|
|
5501
|
+
sessionId: request2.sessionId
|
|
5333
5502
|
}, "interaction.respond.failed");
|
|
5334
5503
|
this.options.emit("interaction.respond.result", {
|
|
5335
5504
|
ok: false,
|
|
5336
|
-
requestId:
|
|
5337
|
-
interactionRequestId:
|
|
5338
|
-
machineId:
|
|
5339
|
-
sessionId:
|
|
5505
|
+
requestId: request2.requestId,
|
|
5506
|
+
interactionRequestId: request2.interactionRequestId,
|
|
5507
|
+
machineId: request2.machineId,
|
|
5508
|
+
sessionId: request2.sessionId,
|
|
5340
5509
|
error: { code: "INTERACTION_RESPONSE_FAILED", message: details.message }
|
|
5341
5510
|
});
|
|
5342
5511
|
}
|
|
@@ -5354,37 +5523,37 @@ var SessionTimelinePageHandler = class {
|
|
|
5354
5523
|
}
|
|
5355
5524
|
options;
|
|
5356
5525
|
#errors;
|
|
5357
|
-
async handle(
|
|
5526
|
+
async handle(request2, scope) {
|
|
5358
5527
|
const { adapter, config, machineId, publications, logger } = this.options;
|
|
5359
5528
|
const diagnostics = new OperationDiagnostics();
|
|
5360
|
-
const errorKey = JSON.stringify([
|
|
5529
|
+
const errorKey = JSON.stringify([request2.sessionId, request2.metadataOnly === true]);
|
|
5361
5530
|
let phase = "read";
|
|
5362
5531
|
try {
|
|
5363
|
-
const publication = publications.capture(
|
|
5364
|
-
if (
|
|
5532
|
+
const publication = publications.capture(request2.sessionId);
|
|
5533
|
+
if (request2.assistantPreview === true && adapter.supportsAssistantPreview !== true) {
|
|
5365
5534
|
throw new Error("Session previews are not supported by this runtime");
|
|
5366
5535
|
}
|
|
5367
|
-
if (
|
|
5536
|
+
if (request2.metadataOnly === true && request2.assistantPreview !== true && adapter.supportsSessionListUpdates !== true) {
|
|
5368
5537
|
throw new Error("Passive session metadata is not supported by this runtime");
|
|
5369
5538
|
}
|
|
5370
|
-
const references =
|
|
5371
|
-
let pageSize =
|
|
5539
|
+
const references = request2.imageReferences === true && config.timelineIncrementalEnabled !== false && this.options.imageReferencesEnabled();
|
|
5540
|
+
let pageSize = request2.pageSize;
|
|
5372
5541
|
while (true) {
|
|
5373
5542
|
let itemCount;
|
|
5374
5543
|
try {
|
|
5375
5544
|
phase = "read";
|
|
5376
5545
|
const page = await diagnostics.run(() => measureOperationPhase("read", () => adapter.readSessionTimelinePage(
|
|
5377
|
-
|
|
5546
|
+
request2.sessionId,
|
|
5378
5547
|
{
|
|
5379
5548
|
pageSize,
|
|
5380
|
-
...
|
|
5381
|
-
...
|
|
5549
|
+
...request2.cursor === void 0 ? {} : { cursor: request2.cursor },
|
|
5550
|
+
...request2.metadataOnly === true ? {
|
|
5382
5551
|
metadataOnly: true,
|
|
5383
|
-
...
|
|
5552
|
+
...request2.assistantPreview === true ? { assistantPreview: true } : {}
|
|
5384
5553
|
} : {
|
|
5385
|
-
...references ||
|
|
5554
|
+
...references || request2.cursor !== void 0 || pageSize !== request2.pageSize ? { readOnly: true } : {},
|
|
5386
5555
|
...references ? {
|
|
5387
|
-
imageProjection: { sessionId:
|
|
5556
|
+
imageProjection: { sessionId: request2.sessionId, referenceItem: this.options.referenceItem }
|
|
5388
5557
|
} : {}
|
|
5389
5558
|
}
|
|
5390
5559
|
}
|
|
@@ -5392,25 +5561,25 @@ var SessionTimelinePageHandler = class {
|
|
|
5392
5561
|
itemCount = page.items.length;
|
|
5393
5562
|
if (diagnostics.activeMs >= 1e3) {
|
|
5394
5563
|
logger.info({
|
|
5395
|
-
...diagnosticRequest(
|
|
5564
|
+
...diagnosticRequest(request2),
|
|
5396
5565
|
...diagnostics.details(),
|
|
5397
|
-
metadataOnly:
|
|
5566
|
+
metadataOnly: request2.metadataOnly === true
|
|
5398
5567
|
}, "session.timeline.page.read-slow");
|
|
5399
5568
|
}
|
|
5400
|
-
if (!publications.isCurrent(
|
|
5401
|
-
const latestAssistant =
|
|
5569
|
+
if (!publications.isCurrent(request2.sessionId, publication)) throw new SessionNotSharedError();
|
|
5570
|
+
const latestAssistant = request2.assistantPreview === true ? [...page.items].reverse().find(isContentfulAssistant) : void 0;
|
|
5402
5571
|
const preview = latestAssistant === void 0 ? void 0 : assistantPreview(
|
|
5403
5572
|
latestAssistant,
|
|
5404
|
-
(item) => this.options.referenceItem(
|
|
5573
|
+
(item) => this.options.referenceItem(request2.sessionId, item)
|
|
5405
5574
|
);
|
|
5406
|
-
const latestUser =
|
|
5575
|
+
const latestUser = request2.assistantPreview === true ? [...page.items].reverse().find((item) => item.kind === "human-message" && item.actor === "human") : void 0;
|
|
5407
5576
|
const humanPreview = latestUser === void 0 ? void 0 : userPreview(latestUser);
|
|
5408
5577
|
const responsePage = {
|
|
5409
5578
|
...page,
|
|
5410
5579
|
...preview === void 0 ? {} : { assistantPreview: preview },
|
|
5411
5580
|
...humanPreview === void 0 ? {} : { userPreview: humanPreview },
|
|
5412
|
-
...
|
|
5413
|
-
items:
|
|
5581
|
+
...request2.assistantPreview === true ? { previewsComplete: !page.hasMore } : {},
|
|
5582
|
+
items: request2.metadataOnly === true && request2.assistantPreview === true ? page.items.map((item) => {
|
|
5414
5583
|
if (item.kind === "assistant-message" || item.kind === "human-message") {
|
|
5415
5584
|
return { ...item, content: "", attachments: [] };
|
|
5416
5585
|
}
|
|
@@ -5419,24 +5588,24 @@ var SessionTimelinePageHandler = class {
|
|
|
5419
5588
|
};
|
|
5420
5589
|
const result = {
|
|
5421
5590
|
ok: true,
|
|
5422
|
-
requestId:
|
|
5591
|
+
requestId: request2.requestId,
|
|
5423
5592
|
machineId,
|
|
5424
|
-
sessionId:
|
|
5425
|
-
page: references ? { ...responsePage, items: responsePage.items.map((item) => this.options.referenceItem(
|
|
5593
|
+
sessionId: request2.sessionId,
|
|
5594
|
+
page: references ? { ...responsePage, items: responsePage.items.map((item) => this.options.referenceItem(request2.sessionId, item)) } : responsePage
|
|
5426
5595
|
};
|
|
5427
5596
|
logger.debug({
|
|
5428
|
-
requestId:
|
|
5429
|
-
sessionId:
|
|
5597
|
+
requestId: request2.requestId,
|
|
5598
|
+
sessionId: request2.sessionId,
|
|
5430
5599
|
itemCount: page.items.length
|
|
5431
5600
|
}, "session.timeline.page.ready");
|
|
5432
5601
|
phase = "encode";
|
|
5433
|
-
const { message, metrics } = await this.options.encoder.seal(result,
|
|
5602
|
+
const { message, metrics } = await this.options.encoder.seal(result, request2, {
|
|
5434
5603
|
enabled: config.timelineCompressionEnabled === true,
|
|
5435
5604
|
...scope.clientId === void 0 ? {} : { recipientClientId: scope.clientId },
|
|
5436
5605
|
...config.secureMessagePacketBudget === void 0 ? {} : { packetBudget: config.secureMessagePacketBudget }
|
|
5437
5606
|
});
|
|
5438
5607
|
if (!scope.isCurrent()) return;
|
|
5439
|
-
if (!publications.isCurrent(
|
|
5608
|
+
if (!publications.isCurrent(request2.sessionId, publication)) throw new SessionNotSharedError();
|
|
5440
5609
|
phase = "emit";
|
|
5441
5610
|
this.options.sendSealed(message);
|
|
5442
5611
|
this.options.trafficMetrics.record(message, metrics.plaintextBytes, metrics.sealDurationMs);
|
|
@@ -5446,11 +5615,11 @@ var SessionTimelinePageHandler = class {
|
|
|
5446
5615
|
return;
|
|
5447
5616
|
} catch (error) {
|
|
5448
5617
|
if (!scope.isCurrent()) return;
|
|
5449
|
-
if (!publications.isCurrent(
|
|
5450
|
-
if (phase === "emit" ||
|
|
5618
|
+
if (!publications.isCurrent(request2.sessionId, publication)) throw new SessionNotSharedError();
|
|
5619
|
+
if (phase === "emit" || request2.metadataOnly === true || request2.assistantPreview === true || pageSize <= 25 || !(error instanceof TimelinePageBudgetError || error instanceof SecureMessageBudgetError) || itemCount !== void 0 && itemCount <= 1) throw error;
|
|
5451
5620
|
const nextPageSize = Math.max(25, Math.floor(pageSize / 2));
|
|
5452
5621
|
logger.info(
|
|
5453
|
-
{ ...diagnosticRequest(
|
|
5622
|
+
{ ...diagnosticRequest(request2), pageSize, nextPageSize, phase },
|
|
5454
5623
|
"session.timeline.page.resized"
|
|
5455
5624
|
);
|
|
5456
5625
|
pageSize = nextPageSize;
|
|
@@ -5459,15 +5628,15 @@ var SessionTimelinePageHandler = class {
|
|
|
5459
5628
|
} catch (error) {
|
|
5460
5629
|
if (!scope.isCurrent()) return;
|
|
5461
5630
|
this.#errors.failure(errorKey, error, {
|
|
5462
|
-
...diagnosticRequest(
|
|
5631
|
+
...diagnosticRequest(request2),
|
|
5463
5632
|
...diagnostics.details(),
|
|
5464
5633
|
phase
|
|
5465
5634
|
});
|
|
5466
5635
|
this.options.emit("session.timeline.page.result", {
|
|
5467
5636
|
ok: false,
|
|
5468
|
-
requestId:
|
|
5637
|
+
requestId: request2.requestId,
|
|
5469
5638
|
machineId,
|
|
5470
|
-
sessionId:
|
|
5639
|
+
sessionId: request2.sessionId,
|
|
5471
5640
|
error: sessionRestoreFailure(error) ?? {
|
|
5472
5641
|
code: error instanceof SecureMessageBudgetError || error instanceof TimelinePageBudgetError ? "TRANSPORT_BUDGET_EXCEEDED" : operationErrorCode(adapter.agentId, "TIMELINE_PAGE", error),
|
|
5473
5642
|
message: toErrorDetails(error).message
|
|
@@ -5482,8 +5651,8 @@ import { randomUUID as randomUUID5 } from "node:crypto";
|
|
|
5482
5651
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5483
5652
|
import { Role, TaskState } from "@a2a-js/sdk";
|
|
5484
5653
|
import { ClientFactory, DefaultAgentCardResolver, JsonRpcTransportFactory } from "@a2a-js/sdk/client";
|
|
5485
|
-
import { z as
|
|
5486
|
-
var TextSchema =
|
|
5654
|
+
import { z as z6 } from "zod";
|
|
5655
|
+
var TextSchema = z6.string().max(16e3).refine((text) => text.trim().length > 0);
|
|
5487
5656
|
var HTTP_TIMEOUT_MS = 1e4;
|
|
5488
5657
|
var MAX_RESPONSE_BYTES = 262144;
|
|
5489
5658
|
function relayEndpoint(relayUrl, target) {
|
|
@@ -5520,7 +5689,7 @@ var A2aPeerClient = class {
|
|
|
5520
5689
|
if (url !== endpoint.href && url !== cardUrl) throw new Error("A2A endpoint differs from the configured peer.");
|
|
5521
5690
|
const headers = new Headers(input instanceof Request ? input.headers : void 0);
|
|
5522
5691
|
new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
|
|
5523
|
-
headers.set("authorization", `Bearer ${this.options
|
|
5692
|
+
headers.set("authorization", `Bearer ${await relayRequestToken(this.options)}`);
|
|
5524
5693
|
headers.set("x-agentknight-user-id", this.options.userId);
|
|
5525
5694
|
headers.set("x-agentknight-machine-id", this.options.machineId);
|
|
5526
5695
|
const timeout = new AbortController();
|
|
@@ -5668,7 +5837,7 @@ import {
|
|
|
5668
5837
|
ServerCallContext,
|
|
5669
5838
|
validateVersion
|
|
5670
5839
|
} from "@a2a-js/sdk/server";
|
|
5671
|
-
import { z as
|
|
5840
|
+
import { z as z7 } from "zod";
|
|
5672
5841
|
var MAX_ACTIVE = 4;
|
|
5673
5842
|
var MAX_TASKS = 128;
|
|
5674
5843
|
var MAX_RECEIPTS = 256;
|
|
@@ -5677,52 +5846,52 @@ var TURN_TIMEOUT_MS = 12e4;
|
|
|
5677
5846
|
var SHORT_REQUEST_TIMEOUT_MS = 9e3;
|
|
5678
5847
|
var MAX_TEXT2 = 16e3;
|
|
5679
5848
|
var TASK_WIRE_BUDGET = 6e4;
|
|
5680
|
-
var idSchema =
|
|
5681
|
-
var optionalIdSchema =
|
|
5682
|
-
var historySchema =
|
|
5683
|
-
var emptyMetadataSchema =
|
|
5684
|
-
var tenantSchema =
|
|
5685
|
-
var rpcSchema =
|
|
5686
|
-
jsonrpc:
|
|
5687
|
-
id:
|
|
5688
|
-
method:
|
|
5689
|
-
params:
|
|
5849
|
+
var idSchema = z7.string().min(1).max(256).regex(/^[^\s\u0000-\u001f\u007f]+$/u);
|
|
5850
|
+
var optionalIdSchema = z7.union([z7.literal(""), idSchema]).optional();
|
|
5851
|
+
var historySchema = z7.number().int().min(0).max(128).optional();
|
|
5852
|
+
var emptyMetadataSchema = z7.object({}).strict().optional();
|
|
5853
|
+
var tenantSchema = z7.literal("").optional();
|
|
5854
|
+
var rpcSchema = z7.object({
|
|
5855
|
+
jsonrpc: z7.literal("2.0"),
|
|
5856
|
+
id: z7.union([idSchema, z7.number().int().safe(), z7.null()]),
|
|
5857
|
+
method: z7.string().min(1).max(128),
|
|
5858
|
+
params: z7.unknown()
|
|
5690
5859
|
}).strict();
|
|
5691
|
-
var sendSchema =
|
|
5860
|
+
var sendSchema = z7.object({
|
|
5692
5861
|
tenant: tenantSchema,
|
|
5693
|
-
message:
|
|
5862
|
+
message: z7.object({
|
|
5694
5863
|
messageId: idSchema,
|
|
5695
5864
|
contextId: optionalIdSchema,
|
|
5696
5865
|
taskId: optionalIdSchema,
|
|
5697
|
-
role:
|
|
5698
|
-
parts:
|
|
5699
|
-
text:
|
|
5700
|
-
mediaType:
|
|
5701
|
-
filename:
|
|
5866
|
+
role: z7.union([z7.literal("ROLE_USER"), z7.literal(Role2.ROLE_USER)]),
|
|
5867
|
+
parts: z7.array(z7.object({
|
|
5868
|
+
text: z7.string().max(MAX_TEXT2),
|
|
5869
|
+
mediaType: z7.union([z7.literal(""), z7.literal("text/plain")]).optional(),
|
|
5870
|
+
filename: z7.literal("").optional(),
|
|
5702
5871
|
metadata: emptyMetadataSchema
|
|
5703
5872
|
}).strict()).min(1).max(32),
|
|
5704
5873
|
metadata: emptyMetadataSchema,
|
|
5705
|
-
extensions:
|
|
5706
|
-
referenceTaskIds:
|
|
5874
|
+
extensions: z7.array(z7.never()).optional(),
|
|
5875
|
+
referenceTaskIds: z7.array(z7.never()).optional()
|
|
5707
5876
|
}).strict().refine((message) => {
|
|
5708
5877
|
const text = message.parts.map((part) => part.text).join("\n");
|
|
5709
5878
|
return text.trim().length > 0 && text.length <= MAX_TEXT2;
|
|
5710
5879
|
}, "A message must contain nonempty plain text of at most 16000 characters."),
|
|
5711
|
-
configuration:
|
|
5712
|
-
acceptedOutputModes:
|
|
5713
|
-
returnImmediately:
|
|
5880
|
+
configuration: z7.object({
|
|
5881
|
+
acceptedOutputModes: z7.array(z7.literal("text/plain")).max(1).optional(),
|
|
5882
|
+
returnImmediately: z7.boolean().optional(),
|
|
5714
5883
|
historyLength: historySchema
|
|
5715
5884
|
}).strict().optional(),
|
|
5716
5885
|
metadata: emptyMetadataSchema
|
|
5717
5886
|
}).strict();
|
|
5718
|
-
var getSchema =
|
|
5719
|
-
var cancelSchema =
|
|
5720
|
-
var listSchema2 =
|
|
5887
|
+
var getSchema = z7.object({ tenant: tenantSchema, id: idSchema, historyLength: historySchema }).strict();
|
|
5888
|
+
var cancelSchema = z7.object({ tenant: tenantSchema, id: idSchema, metadata: emptyMetadataSchema }).strict();
|
|
5889
|
+
var listSchema2 = z7.object({
|
|
5721
5890
|
tenant: tenantSchema,
|
|
5722
5891
|
contextId: optionalIdSchema,
|
|
5723
|
-
status:
|
|
5724
|
-
|
|
5725
|
-
|
|
5892
|
+
status: z7.union([
|
|
5893
|
+
z7.number().int().min(0).max(8),
|
|
5894
|
+
z7.enum([
|
|
5726
5895
|
"TASK_STATE_UNSPECIFIED",
|
|
5727
5896
|
"TASK_STATE_SUBMITTED",
|
|
5728
5897
|
"TASK_STATE_WORKING",
|
|
@@ -5734,11 +5903,11 @@ var listSchema2 = z6.object({
|
|
|
5734
5903
|
"TASK_STATE_AUTH_REQUIRED"
|
|
5735
5904
|
])
|
|
5736
5905
|
]).optional(),
|
|
5737
|
-
pageSize:
|
|
5738
|
-
pageToken:
|
|
5906
|
+
pageSize: z7.number().int().min(1).max(100).optional(),
|
|
5907
|
+
pageToken: z7.string().regex(/^(?:|0|[1-9]\d{0,3})$/u).optional(),
|
|
5739
5908
|
historyLength: historySchema,
|
|
5740
|
-
statusTimestampAfter:
|
|
5741
|
-
includeArtifacts:
|
|
5909
|
+
statusTimestampAfter: z7.iso.datetime({ offset: true }).optional(),
|
|
5910
|
+
includeArtifacts: z7.boolean().optional()
|
|
5742
5911
|
}).strict();
|
|
5743
5912
|
function deferred() {
|
|
5744
5913
|
let resolve5 = () => {
|
|
@@ -5880,7 +6049,7 @@ var A2aPeerServer = class {
|
|
|
5880
6049
|
return server.#cancelRequest(params, call, () => super.cancelTask(params, call));
|
|
5881
6050
|
}
|
|
5882
6051
|
}(card, this.#store, {
|
|
5883
|
-
execute: (
|
|
6052
|
+
execute: (request2, bus) => this.#execute(request2, bus),
|
|
5884
6053
|
cancelTask: async (id) => {
|
|
5885
6054
|
const work = this.#work(id);
|
|
5886
6055
|
if (work === void 0 || work.scope !== scope) throw new TaskNotCancelableError();
|
|
@@ -6033,19 +6202,19 @@ var A2aPeerServer = class {
|
|
|
6033
6202
|
throw error;
|
|
6034
6203
|
}
|
|
6035
6204
|
}
|
|
6036
|
-
async #execute(
|
|
6037
|
-
const work = [...this.#active].find((entry) => entry ===
|
|
6205
|
+
async #execute(request2, bus) {
|
|
6206
|
+
const work = [...this.#active].find((entry) => entry === request2.context.state.get("a2aWork"));
|
|
6038
6207
|
if (work === void 0) throw new UnsupportedOperationError("Native task ownership is unavailable.");
|
|
6039
|
-
work.taskId =
|
|
6040
|
-
work.receipt.taskId =
|
|
6041
|
-
const initial = workingTask(
|
|
6208
|
+
work.taskId = request2.taskId;
|
|
6209
|
+
work.receipt.taskId = request2.taskId;
|
|
6210
|
+
const initial = workingTask(request2.taskId, request2.contextId, request2.userMessage);
|
|
6042
6211
|
bus.publish(AgentEvent.task(initial));
|
|
6043
6212
|
try {
|
|
6044
6213
|
let state = TaskState2.TASK_STATE_COMPLETED;
|
|
6045
6214
|
let text;
|
|
6046
6215
|
try {
|
|
6047
6216
|
work.controller.signal.throwIfAborted();
|
|
6048
|
-
const prompt =
|
|
6217
|
+
const prompt = request2.userMessage.parts.map((part) => part.content?.$case === "text" ? part.content.value : "").join("\n");
|
|
6049
6218
|
text = await this.host.runTurn(work.sessionId, prompt, { signal: work.controller.signal, awaitNativeSettlement: true });
|
|
6050
6219
|
if (work.controller.signal.aborted) {
|
|
6051
6220
|
state = work.expired ? TaskState2.TASK_STATE_FAILED : TaskState2.TASK_STATE_CANCELED;
|
|
@@ -6065,8 +6234,8 @@ var A2aPeerServer = class {
|
|
|
6065
6234
|
}
|
|
6066
6235
|
const reply = {
|
|
6067
6236
|
messageId: randomUUID6(),
|
|
6068
|
-
contextId:
|
|
6069
|
-
taskId:
|
|
6237
|
+
contextId: request2.contextId,
|
|
6238
|
+
taskId: request2.taskId,
|
|
6070
6239
|
role: Role2.ROLE_AGENT,
|
|
6071
6240
|
parts: [{ content: { $case: "text", value: text }, mediaType: "text/plain", filename: "", metadata: void 0 }],
|
|
6072
6241
|
metadata: void 0,
|
|
@@ -6075,7 +6244,7 @@ var A2aPeerServer = class {
|
|
|
6075
6244
|
};
|
|
6076
6245
|
let final = {
|
|
6077
6246
|
...initial,
|
|
6078
|
-
history: [
|
|
6247
|
+
history: [request2.userMessage, reply],
|
|
6079
6248
|
status: { state, message: reply, timestamp: (/* @__PURE__ */ new Date()).toISOString() }
|
|
6080
6249
|
};
|
|
6081
6250
|
if (JSON.stringify(Task.toJSON(final)).length > TASK_WIRE_BUDGET) {
|
|
@@ -6090,7 +6259,7 @@ var A2aPeerServer = class {
|
|
|
6090
6259
|
};
|
|
6091
6260
|
final = {
|
|
6092
6261
|
...initial,
|
|
6093
|
-
history: [
|
|
6262
|
+
history: [request2.userMessage, failure],
|
|
6094
6263
|
status: { state: TaskState2.TASK_STATE_FAILED, message: failure, timestamp: (/* @__PURE__ */ new Date()).toISOString() }
|
|
6095
6264
|
};
|
|
6096
6265
|
this.host.reportError(new InvalidAgentResponseError("Native reply exceeds the A2A response size limit."));
|
|
@@ -6237,12 +6406,12 @@ var PeerChatRuntime = class {
|
|
|
6237
6406
|
return this.#runs.size > 0 || this.#jobs.size > 0;
|
|
6238
6407
|
}
|
|
6239
6408
|
async run(rawRequest, signal) {
|
|
6240
|
-
const
|
|
6409
|
+
const request2 = PeerChatRequestSchema.parse(rawRequest);
|
|
6241
6410
|
this.host.assertReady();
|
|
6242
6411
|
signal.throwIfAborted();
|
|
6243
|
-
if (
|
|
6412
|
+
if (request2.targetMachineId === this.host.machineId) throw new Error("Peer chat requires a different PC.");
|
|
6244
6413
|
if (this.#runs.size + this.#incoming.size >= MAX_ACTIVE_TURNS) throw new Error("Peer chat is busy.");
|
|
6245
|
-
const conversation = this.host.createConversation(
|
|
6414
|
+
const conversation = this.host.createConversation(request2);
|
|
6246
6415
|
const controller = new AbortController();
|
|
6247
6416
|
this.#runs.add(controller);
|
|
6248
6417
|
const abort = () => controller.abort(signal.reason);
|
|
@@ -6253,11 +6422,11 @@ var PeerChatRuntime = class {
|
|
|
6253
6422
|
let requests = 0;
|
|
6254
6423
|
let lastExchange;
|
|
6255
6424
|
const job = (async () => {
|
|
6256
|
-
const reply = await this.host.runTurn(
|
|
6425
|
+
const reply = await this.host.runTurn(request2.sessionId, [
|
|
6257
6426
|
"Work with the Copilot session on the other PC using peer_chat_send.",
|
|
6258
6427
|
"Send it a concrete request, use its real reply, then give the user your conclusion.",
|
|
6259
6428
|
"The peer tool returns that session's reply; do not invent or simulate it.",
|
|
6260
|
-
|
|
6429
|
+
request2.prompt
|
|
6261
6430
|
].join("\n\n"), {
|
|
6262
6431
|
signal: controller.signal,
|
|
6263
6432
|
requestPeer: (content) => {
|
|
@@ -6397,8 +6566,8 @@ function projectAgentControls(event, payload, supported) {
|
|
|
6397
6566
|
if (event === "interaction.request") {
|
|
6398
6567
|
const parsed = InteractionRequestPayloadSchema.parse(payload);
|
|
6399
6568
|
if (parsed.request.kind !== "permission") return parsed;
|
|
6400
|
-
const { canApproveAlways: _always, approvalScope: _scope, ...
|
|
6401
|
-
return { ...parsed, request };
|
|
6569
|
+
const { canApproveAlways: _always, approvalScope: _scope, ...request2 } = parsed.request;
|
|
6570
|
+
return { ...parsed, request: request2 };
|
|
6402
6571
|
}
|
|
6403
6572
|
if (event === "session.options.result") {
|
|
6404
6573
|
const parsed = SessionOptionsResultSchema.parse(payload);
|
|
@@ -6457,8 +6626,8 @@ var SnapshotSync = class {
|
|
|
6457
6626
|
reset() {
|
|
6458
6627
|
this.#generation += 1;
|
|
6459
6628
|
for (const requests of [this.#active, this.#pending]) {
|
|
6460
|
-
for (const
|
|
6461
|
-
|
|
6629
|
+
for (const request2 of requests.values()) {
|
|
6630
|
+
request2.reject(new SnapshotSyncCancelledError());
|
|
6462
6631
|
}
|
|
6463
6632
|
requests.clear();
|
|
6464
6633
|
}
|
|
@@ -6489,26 +6658,26 @@ var SnapshotSync = class {
|
|
|
6489
6658
|
this.#active = batch;
|
|
6490
6659
|
try {
|
|
6491
6660
|
const snapshot = await this.#options.read(
|
|
6492
|
-
[...batch.values()].some((
|
|
6661
|
+
[...batch.values()].some((request2) => request2.requireFreshRead)
|
|
6493
6662
|
);
|
|
6494
6663
|
if (generation !== this.#generation) {
|
|
6495
6664
|
continue;
|
|
6496
6665
|
}
|
|
6497
6666
|
await Promise.all(
|
|
6498
|
-
[...batch].map(async ([recipientClientId,
|
|
6667
|
+
[...batch].map(async ([recipientClientId, request2]) => {
|
|
6499
6668
|
try {
|
|
6500
6669
|
await this.#options.send(snapshot, recipientClientId);
|
|
6501
|
-
|
|
6670
|
+
request2.resolve();
|
|
6502
6671
|
} catch (error) {
|
|
6503
|
-
|
|
6672
|
+
request2.reject(error);
|
|
6504
6673
|
} finally {
|
|
6505
6674
|
batch.delete(recipientClientId);
|
|
6506
6675
|
}
|
|
6507
6676
|
})
|
|
6508
6677
|
);
|
|
6509
6678
|
} catch (error) {
|
|
6510
|
-
for (const
|
|
6511
|
-
|
|
6679
|
+
for (const request2 of batch.values()) {
|
|
6680
|
+
request2.reject(error);
|
|
6512
6681
|
}
|
|
6513
6682
|
} finally {
|
|
6514
6683
|
if (this.#active === batch) {
|
|
@@ -6570,49 +6739,49 @@ var SessionWatches = class {
|
|
|
6570
6739
|
get busy() {
|
|
6571
6740
|
return this.#transitions.size > 0;
|
|
6572
6741
|
}
|
|
6573
|
-
async change(
|
|
6742
|
+
async change(request2, clientId, connectionCurrent, report) {
|
|
6574
6743
|
const owner = this.#owners.get(clientId) ?? {
|
|
6575
6744
|
sessions: /* @__PURE__ */ new Set(),
|
|
6576
6745
|
pending: /* @__PURE__ */ new Set()
|
|
6577
6746
|
};
|
|
6578
6747
|
this.#owners.set(clientId, owner);
|
|
6579
|
-
owner.pending.add(
|
|
6748
|
+
owner.pending.add(request2);
|
|
6580
6749
|
const isCurrent = () => connectionCurrent() && this.#owners.get(clientId) === owner;
|
|
6581
|
-
if (!
|
|
6750
|
+
if (!request2.watching) this.options.stopSynchronizing(clientId, request2.sessionId);
|
|
6582
6751
|
try {
|
|
6583
|
-
const publication = this.options.publication.capture(
|
|
6584
|
-
await this.#serialize(
|
|
6752
|
+
const publication = this.options.publication.capture(request2.sessionId);
|
|
6753
|
+
await this.#serialize(request2.sessionId, async () => {
|
|
6585
6754
|
if (!isCurrent()) return;
|
|
6586
|
-
if (!this.options.publication.isCurrent(
|
|
6587
|
-
if (
|
|
6588
|
-
if (!this.#hasWatcher(
|
|
6755
|
+
if (!this.options.publication.isCurrent(request2.sessionId, publication)) throw new SessionNotSharedError();
|
|
6756
|
+
if (request2.watching) {
|
|
6757
|
+
if (!this.#hasWatcher(request2.sessionId)) this.options.invalidate(request2.sessionId);
|
|
6589
6758
|
try {
|
|
6590
|
-
await this.options.watch(
|
|
6591
|
-
if (!this.options.publication.isCurrent(
|
|
6759
|
+
await this.options.watch(request2.sessionId, true);
|
|
6760
|
+
if (!this.options.publication.isCurrent(request2.sessionId, publication)) throw new SessionNotSharedError();
|
|
6592
6761
|
} catch (error) {
|
|
6593
|
-
if (!this.#hasWatcher(
|
|
6762
|
+
if (!this.#hasWatcher(request2.sessionId)) {
|
|
6594
6763
|
try {
|
|
6595
|
-
await this.options.watch(
|
|
6764
|
+
await this.options.watch(request2.sessionId, false);
|
|
6596
6765
|
} catch (cleanupError) {
|
|
6597
6766
|
throw new AggregateError([error, cleanupError], "Failed to watch session and release its follower");
|
|
6598
6767
|
}
|
|
6599
6768
|
}
|
|
6600
6769
|
throw error;
|
|
6601
6770
|
}
|
|
6602
|
-
if (isCurrent()) owner.sessions.add(
|
|
6771
|
+
if (isCurrent()) owner.sessions.add(request2.sessionId);
|
|
6603
6772
|
} else {
|
|
6604
|
-
if (!this.#hasWatcher(
|
|
6605
|
-
this.options.invalidate(
|
|
6606
|
-
await this.options.watch(
|
|
6773
|
+
if (!this.#hasWatcher(request2.sessionId, owner)) {
|
|
6774
|
+
this.options.invalidate(request2.sessionId);
|
|
6775
|
+
await this.options.watch(request2.sessionId, false);
|
|
6607
6776
|
}
|
|
6608
|
-
owner.sessions.delete(
|
|
6777
|
+
owner.sessions.delete(request2.sessionId);
|
|
6609
6778
|
}
|
|
6610
6779
|
});
|
|
6611
6780
|
report({ ok: true, isCurrent });
|
|
6612
6781
|
} catch (error) {
|
|
6613
6782
|
report({ ok: false, isCurrent, error });
|
|
6614
6783
|
} finally {
|
|
6615
|
-
owner.pending.delete(
|
|
6784
|
+
owner.pending.delete(request2);
|
|
6616
6785
|
}
|
|
6617
6786
|
}
|
|
6618
6787
|
removeSession(sessionId) {
|
|
@@ -6658,7 +6827,7 @@ var SessionWatches = class {
|
|
|
6658
6827
|
async #releaseOwners(owners) {
|
|
6659
6828
|
const sessionIds = new Set(owners.flatMap((owner) => [
|
|
6660
6829
|
...owner.sessions,
|
|
6661
|
-
...[...owner.pending].map((
|
|
6830
|
+
...[...owner.pending].map((request2) => request2.sessionId)
|
|
6662
6831
|
]));
|
|
6663
6832
|
const results = await Promise.allSettled([...sessionIds].map(
|
|
6664
6833
|
(sessionId) => this.#serialize(sessionId, async () => {
|
|
@@ -7021,8 +7190,8 @@ var TimelineIncrementalTransport = class {
|
|
|
7021
7190
|
operation: TIMELINE_SYNC_OPERATION,
|
|
7022
7191
|
version: TIMELINE_SYNC_VERSION,
|
|
7023
7192
|
schema: TimelineSyncRequestSchema,
|
|
7024
|
-
handle: async (data,
|
|
7025
|
-
await this.sync(
|
|
7193
|
+
handle: async (data, request2) => SessionCommunicationDataSchema.parse(
|
|
7194
|
+
await this.sync(request2.sessionId, data)
|
|
7026
7195
|
),
|
|
7027
7196
|
onError
|
|
7028
7197
|
}),
|
|
@@ -7030,8 +7199,8 @@ var TimelineIncrementalTransport = class {
|
|
|
7030
7199
|
operation: TIMELINE_IMAGE_OPERATION,
|
|
7031
7200
|
version: TIMELINE_SYNC_VERSION,
|
|
7032
7201
|
schema: TimelineImageRequestSchema,
|
|
7033
|
-
handle: async (data,
|
|
7034
|
-
this.images.read(
|
|
7202
|
+
handle: async (data, request2) => SessionCommunicationDataSchema.parse(
|
|
7203
|
+
this.images.read(request2.sessionId, data)
|
|
7035
7204
|
),
|
|
7036
7205
|
onError
|
|
7037
7206
|
})
|
|
@@ -7156,12 +7325,12 @@ var TimelineIncrementalTransport = class {
|
|
|
7156
7325
|
this.#sessions.clear();
|
|
7157
7326
|
this.images.clear();
|
|
7158
7327
|
}
|
|
7159
|
-
async sync(sessionId,
|
|
7328
|
+
async sync(sessionId, request2) {
|
|
7160
7329
|
if (this.#closed) throw new TimelineAssetError("PC_OFFLINE", "The PC transport is closed");
|
|
7161
7330
|
let state = this.#session(sessionId);
|
|
7162
|
-
const watermark =
|
|
7331
|
+
const watermark = request2.watermark;
|
|
7163
7332
|
recordTimelineSyncDiagnostic({
|
|
7164
|
-
mode: watermark === void 0 ? "snapshot" :
|
|
7333
|
+
mode: watermark === void 0 ? "snapshot" : request2.resume === true ? "resume" : "replay",
|
|
7165
7334
|
...watermark === void 0 ? {} : {
|
|
7166
7335
|
epochMatches: watermark.epoch === state.epoch,
|
|
7167
7336
|
requestedSequence: watermark.sequence
|
|
@@ -7214,12 +7383,12 @@ var TimelineIncrementalTransport = class {
|
|
|
7214
7383
|
}
|
|
7215
7384
|
throw new TimelineAssetError("TIMELINE_BUSY", "Timeline changed during baseline capture; retry synchronization");
|
|
7216
7385
|
}
|
|
7217
|
-
if (
|
|
7386
|
+
if (request2.resume === true && watermark.epoch === state.epoch) {
|
|
7218
7387
|
await this.#refreshHead(sessionId);
|
|
7219
7388
|
state = this.#session(sessionId);
|
|
7220
7389
|
}
|
|
7221
|
-
if (watermark.epoch === state.epoch && watermark.sequence === state.sequence && (
|
|
7222
|
-
await measureOperationPhase("wait", () => this.#wait(state,
|
|
7390
|
+
if (watermark.epoch === state.epoch && watermark.sequence === state.sequence && (request2.waitMs ?? 0) > 0) {
|
|
7391
|
+
await measureOperationPhase("wait", () => this.#wait(state, request2.waitMs ?? 0));
|
|
7223
7392
|
if (this.#closed) throw new TimelineAssetError("PC_OFFLINE", "The PC transport is closed");
|
|
7224
7393
|
state = this.#session(sessionId);
|
|
7225
7394
|
}
|
|
@@ -7721,11 +7890,11 @@ var RelayConnectionDiagnostics = class {
|
|
|
7721
7890
|
function machineAdmittedSecureRequestRoute(schema, admission, handler) {
|
|
7722
7891
|
return {
|
|
7723
7892
|
dispatch: async (payload, context) => {
|
|
7724
|
-
const
|
|
7725
|
-
if (
|
|
7726
|
-
return admission.reject(
|
|
7893
|
+
const request2 = schema.parse(payload);
|
|
7894
|
+
if (request2.machineId !== context.configuredMachineId) {
|
|
7895
|
+
return admission.reject(request2, context);
|
|
7727
7896
|
}
|
|
7728
|
-
await handler(
|
|
7897
|
+
await handler(request2, context);
|
|
7729
7898
|
return void 0;
|
|
7730
7899
|
}
|
|
7731
7900
|
};
|
|
@@ -7768,9 +7937,9 @@ function createPcSecureRequestRouter(options) {
|
|
|
7768
7937
|
"session.communication": machineAdmittedSecureRequestRoute(
|
|
7769
7938
|
SessionCommunicationRequestSchema,
|
|
7770
7939
|
{
|
|
7771
|
-
reject: (
|
|
7940
|
+
reject: (request2) => ({
|
|
7772
7941
|
event: "session.communication",
|
|
7773
|
-
payload: sessionCommunicationError(
|
|
7942
|
+
payload: sessionCommunicationError(request2, wrongPcAgent)
|
|
7774
7943
|
})
|
|
7775
7944
|
},
|
|
7776
7945
|
options.handlers.sessionCommunication
|
|
@@ -7778,12 +7947,12 @@ function createPcSecureRequestRouter(options) {
|
|
|
7778
7947
|
"session.list": machineAdmittedSecureRequestRoute(
|
|
7779
7948
|
SessionListRequestSchema,
|
|
7780
7949
|
{
|
|
7781
|
-
reject: (
|
|
7950
|
+
reject: (request2) => ({
|
|
7782
7951
|
event: "session.list.result",
|
|
7783
7952
|
payload: {
|
|
7784
7953
|
ok: false,
|
|
7785
|
-
requestId:
|
|
7786
|
-
machineId:
|
|
7954
|
+
requestId: request2.requestId,
|
|
7955
|
+
machineId: request2.machineId,
|
|
7787
7956
|
error: wrongPcAgent
|
|
7788
7957
|
}
|
|
7789
7958
|
})
|
|
@@ -7793,13 +7962,13 @@ function createPcSecureRequestRouter(options) {
|
|
|
7793
7962
|
"session.options": machineAdmittedSecureRequestRoute(
|
|
7794
7963
|
SessionOptionsRequestSchema,
|
|
7795
7964
|
{
|
|
7796
|
-
reject: (
|
|
7965
|
+
reject: (request2) => ({
|
|
7797
7966
|
event: "session.options.result",
|
|
7798
7967
|
payload: {
|
|
7799
7968
|
ok: false,
|
|
7800
|
-
requestId:
|
|
7801
|
-
machineId:
|
|
7802
|
-
...
|
|
7969
|
+
requestId: request2.requestId,
|
|
7970
|
+
machineId: request2.machineId,
|
|
7971
|
+
...request2.sessionId === void 0 ? {} : { sessionId: request2.sessionId },
|
|
7803
7972
|
error: wrongPcAgent
|
|
7804
7973
|
}
|
|
7805
7974
|
})
|
|
@@ -7809,12 +7978,12 @@ function createPcSecureRequestRouter(options) {
|
|
|
7809
7978
|
"session.create": machineAdmittedSecureRequestRoute(
|
|
7810
7979
|
SessionCreateRequestSchema,
|
|
7811
7980
|
{
|
|
7812
|
-
reject: (
|
|
7981
|
+
reject: (request2) => ({
|
|
7813
7982
|
event: "session.create.result",
|
|
7814
7983
|
payload: {
|
|
7815
7984
|
ok: false,
|
|
7816
|
-
requestId:
|
|
7817
|
-
machineId:
|
|
7985
|
+
requestId: request2.requestId,
|
|
7986
|
+
machineId: request2.machineId,
|
|
7818
7987
|
error: wrongPcAgent
|
|
7819
7988
|
}
|
|
7820
7989
|
})
|
|
@@ -7824,13 +7993,13 @@ function createPcSecureRequestRouter(options) {
|
|
|
7824
7993
|
"session.delete": machineAdmittedSecureRequestRoute(
|
|
7825
7994
|
SessionDeleteRequestSchema,
|
|
7826
7995
|
{
|
|
7827
|
-
reject: (
|
|
7996
|
+
reject: (request2) => ({
|
|
7828
7997
|
event: "session.delete.result",
|
|
7829
7998
|
payload: {
|
|
7830
7999
|
ok: false,
|
|
7831
|
-
requestId:
|
|
7832
|
-
machineId:
|
|
7833
|
-
sessionId:
|
|
8000
|
+
requestId: request2.requestId,
|
|
8001
|
+
machineId: request2.machineId,
|
|
8002
|
+
sessionId: request2.sessionId,
|
|
7834
8003
|
error: wrongPcAgent
|
|
7835
8004
|
}
|
|
7836
8005
|
})
|
|
@@ -7840,13 +8009,13 @@ function createPcSecureRequestRouter(options) {
|
|
|
7840
8009
|
"session.configure": machineAdmittedSecureRequestRoute(
|
|
7841
8010
|
SessionConfigureRequestSchema,
|
|
7842
8011
|
{
|
|
7843
|
-
reject: (
|
|
8012
|
+
reject: (request2) => ({
|
|
7844
8013
|
event: "session.configure.result",
|
|
7845
8014
|
payload: {
|
|
7846
8015
|
ok: false,
|
|
7847
|
-
requestId:
|
|
7848
|
-
machineId:
|
|
7849
|
-
sessionId:
|
|
8016
|
+
requestId: request2.requestId,
|
|
8017
|
+
machineId: request2.machineId,
|
|
8018
|
+
sessionId: request2.sessionId,
|
|
7850
8019
|
error: wrongPcAgent
|
|
7851
8020
|
}
|
|
7852
8021
|
})
|
|
@@ -7856,13 +8025,13 @@ function createPcSecureRequestRouter(options) {
|
|
|
7856
8025
|
"session.remote": machineAdmittedSecureRequestRoute(
|
|
7857
8026
|
SessionRemoteRequestSchema,
|
|
7858
8027
|
{
|
|
7859
|
-
reject: (
|
|
8028
|
+
reject: (request2) => ({
|
|
7860
8029
|
event: "session.remote.result",
|
|
7861
8030
|
payload: {
|
|
7862
8031
|
ok: false,
|
|
7863
|
-
requestId:
|
|
7864
|
-
machineId:
|
|
7865
|
-
sessionId:
|
|
8032
|
+
requestId: request2.requestId,
|
|
8033
|
+
machineId: request2.machineId,
|
|
8034
|
+
sessionId: request2.sessionId,
|
|
7866
8035
|
error: wrongPcAgent
|
|
7867
8036
|
}
|
|
7868
8037
|
})
|
|
@@ -7872,13 +8041,13 @@ function createPcSecureRequestRouter(options) {
|
|
|
7872
8041
|
"session.timeline.page": machineAdmittedSecureRequestRoute(
|
|
7873
8042
|
SessionTimelinePageRequestSchema,
|
|
7874
8043
|
{
|
|
7875
|
-
reject: (
|
|
8044
|
+
reject: (request2) => ({
|
|
7876
8045
|
event: "session.timeline.page.result",
|
|
7877
8046
|
payload: {
|
|
7878
8047
|
ok: false,
|
|
7879
|
-
requestId:
|
|
7880
|
-
machineId:
|
|
7881
|
-
sessionId:
|
|
8048
|
+
requestId: request2.requestId,
|
|
8049
|
+
machineId: request2.machineId,
|
|
8050
|
+
sessionId: request2.sessionId,
|
|
7882
8051
|
error: wrongPcAgent
|
|
7883
8052
|
}
|
|
7884
8053
|
})
|
|
@@ -7888,14 +8057,14 @@ function createPcSecureRequestRouter(options) {
|
|
|
7888
8057
|
"session.watch": machineAdmittedSecureRequestRoute(
|
|
7889
8058
|
SessionWatchRequestSchema,
|
|
7890
8059
|
{
|
|
7891
|
-
reject: (
|
|
8060
|
+
reject: (request2) => ({
|
|
7892
8061
|
event: "session.watch.result",
|
|
7893
8062
|
payload: {
|
|
7894
8063
|
ok: false,
|
|
7895
|
-
requestId:
|
|
7896
|
-
machineId:
|
|
7897
|
-
sessionId:
|
|
7898
|
-
watching:
|
|
8064
|
+
requestId: request2.requestId,
|
|
8065
|
+
machineId: request2.machineId,
|
|
8066
|
+
sessionId: request2.sessionId,
|
|
8067
|
+
watching: request2.watching,
|
|
7899
8068
|
error: {
|
|
7900
8069
|
code: "MACHINE_ID_MISMATCH",
|
|
7901
8070
|
message: "The watch request targets a different machine"
|
|
@@ -7908,14 +8077,14 @@ function createPcSecureRequestRouter(options) {
|
|
|
7908
8077
|
"session.prompt": machineAdmittedSecureRequestRoute(
|
|
7909
8078
|
SessionPromptRequestSchema,
|
|
7910
8079
|
{
|
|
7911
|
-
reject: (
|
|
8080
|
+
reject: (request2) => ({
|
|
7912
8081
|
event: "session.prompt.result",
|
|
7913
8082
|
payload: {
|
|
7914
8083
|
ok: false,
|
|
7915
|
-
requestId:
|
|
7916
|
-
operationId:
|
|
7917
|
-
machineId:
|
|
7918
|
-
sessionId:
|
|
8084
|
+
requestId: request2.requestId,
|
|
8085
|
+
operationId: request2.operationId,
|
|
8086
|
+
machineId: request2.machineId,
|
|
8087
|
+
sessionId: request2.sessionId,
|
|
7919
8088
|
error: wrongPcAgent
|
|
7920
8089
|
}
|
|
7921
8090
|
})
|
|
@@ -7925,13 +8094,13 @@ function createPcSecureRequestRouter(options) {
|
|
|
7925
8094
|
"session.abort": machineAdmittedSecureRequestRoute(
|
|
7926
8095
|
SessionAbortRequestSchema,
|
|
7927
8096
|
{
|
|
7928
|
-
reject: (
|
|
8097
|
+
reject: (request2) => ({
|
|
7929
8098
|
event: "session.abort.result",
|
|
7930
8099
|
payload: {
|
|
7931
8100
|
ok: false,
|
|
7932
|
-
requestId:
|
|
7933
|
-
machineId:
|
|
7934
|
-
sessionId:
|
|
8101
|
+
requestId: request2.requestId,
|
|
8102
|
+
machineId: request2.machineId,
|
|
8103
|
+
sessionId: request2.sessionId,
|
|
7935
8104
|
error: {
|
|
7936
8105
|
code: "COPILOT_ABORT_FAILED",
|
|
7937
8106
|
message: "The request was routed to the wrong PC Agent"
|
|
@@ -7944,14 +8113,14 @@ function createPcSecureRequestRouter(options) {
|
|
|
7944
8113
|
"interaction.respond": machineAdmittedSecureRequestRoute(
|
|
7945
8114
|
InteractionRespondRequestSchema,
|
|
7946
8115
|
{
|
|
7947
|
-
reject: (
|
|
8116
|
+
reject: (request2) => ({
|
|
7948
8117
|
event: "interaction.respond.result",
|
|
7949
8118
|
payload: {
|
|
7950
8119
|
ok: false,
|
|
7951
|
-
requestId:
|
|
7952
|
-
interactionRequestId:
|
|
7953
|
-
machineId:
|
|
7954
|
-
sessionId:
|
|
8120
|
+
requestId: request2.requestId,
|
|
8121
|
+
interactionRequestId: request2.interactionRequestId,
|
|
8122
|
+
machineId: request2.machineId,
|
|
8123
|
+
sessionId: request2.sessionId,
|
|
7955
8124
|
error: {
|
|
7956
8125
|
code: "MACHINE_ID_MISMATCH",
|
|
7957
8126
|
message: "The interaction targets a different machine"
|
|
@@ -7964,14 +8133,14 @@ function createPcSecureRequestRouter(options) {
|
|
|
7964
8133
|
"permission.respond": machineAdmittedSecureRequestRoute(
|
|
7965
8134
|
PermissionRespondRequestSchema,
|
|
7966
8135
|
{
|
|
7967
|
-
reject: (
|
|
8136
|
+
reject: (request2) => ({
|
|
7968
8137
|
event: "permission.respond.result",
|
|
7969
8138
|
payload: {
|
|
7970
8139
|
ok: false,
|
|
7971
|
-
requestId:
|
|
7972
|
-
permissionRequestId:
|
|
7973
|
-
machineId:
|
|
7974
|
-
sessionId:
|
|
8140
|
+
requestId: request2.requestId,
|
|
8141
|
+
permissionRequestId: request2.permissionRequestId,
|
|
8142
|
+
machineId: request2.machineId,
|
|
8143
|
+
sessionId: request2.sessionId,
|
|
7975
8144
|
error: {
|
|
7976
8145
|
code: "PERMISSION_REQUEST_NOT_FOUND",
|
|
7977
8146
|
message: "The permission request is no longer pending"
|
|
@@ -8125,25 +8294,26 @@ var PcAgent = class {
|
|
|
8125
8294
|
this.#secureRequestRouter = createPcSecureRequestRouter({
|
|
8126
8295
|
configuredMachineId: identity2.machineId,
|
|
8127
8296
|
handlers: {
|
|
8128
|
-
sessionCommunication: (
|
|
8129
|
-
sessionList: (
|
|
8130
|
-
sessionOptions: (
|
|
8131
|
-
sessionCreate: (
|
|
8132
|
-
sessionDelete: (
|
|
8133
|
-
sessionConfigure: (
|
|
8134
|
-
sessionRemote: (
|
|
8135
|
-
sessionTimelinePage: (
|
|
8136
|
-
sessionWatch: (
|
|
8137
|
-
sessionPrompt: (
|
|
8138
|
-
sessionAbort: (
|
|
8139
|
-
interactionRespond: (
|
|
8140
|
-
permissionRespond: (
|
|
8297
|
+
sessionCommunication: (request2) => this.#admitRequest(request2, "session.communication", () => this.#communication.handle(request2, this.#requestScope())),
|
|
8298
|
+
sessionList: (request2) => this.#admitRequest(request2, "session.list.result", () => this.#handleSessionList(request2)),
|
|
8299
|
+
sessionOptions: (request2) => this.#admitRequest(request2, "session.options.result", () => this.#sessionOptions.handle(request2, this.#requestScope())),
|
|
8300
|
+
sessionCreate: (request2) => this.#admitRequest(request2, "session.create.result", () => this.#commands.create(request2, this.#requestScope())),
|
|
8301
|
+
sessionDelete: (request2) => this.#admitRequest(request2, "session.delete.result", () => this.#commands.delete(request2, this.#requestScope())),
|
|
8302
|
+
sessionConfigure: (request2) => this.#admitRequest(request2, "session.configure.result", () => this.#commands.configure(request2, this.#requestScope())),
|
|
8303
|
+
sessionRemote: (request2) => this.#admitRequest(request2, "session.remote.result", () => this.#commands.remote(request2, this.#requestScope())),
|
|
8304
|
+
sessionTimelinePage: (request2) => this.#admitRequest(request2, "session.timeline.page.result", () => this.#timelinePages.handle(request2, this.#requestScope())),
|
|
8305
|
+
sessionWatch: (request2, context) => this.#admitRequest(request2, "session.watch.result", () => this.#handleSessionWatch(request2, context)),
|
|
8306
|
+
sessionPrompt: (request2, context) => this.#admitRequest(request2, "session.prompt.result", () => this.#prompts.handle(request2, context)),
|
|
8307
|
+
sessionAbort: (request2) => this.#admitRequest(request2, "session.abort.result", () => this.#commands.abort(request2)),
|
|
8308
|
+
interactionRespond: (request2) => this.#admitRequest(request2, "interaction.respond.result", () => this.#interactionResponses.interaction(request2, this.#requestScope())),
|
|
8309
|
+
permissionRespond: (request2) => this.#admitRequest(request2, "permission.respond.result", () => this.#interactionResponses.permission(request2))
|
|
8141
8310
|
},
|
|
8142
8311
|
onAdmissionRejected: ({ event, payload }) => {
|
|
8143
8312
|
this.#emitSecure(event, payload);
|
|
8144
8313
|
}
|
|
8145
8314
|
});
|
|
8146
8315
|
const relayUrl = new URL(config.relayUrl);
|
|
8316
|
+
const authorizationArgs = config.relayAuthorization === void 0 ? [] : [config.relayAuthorization];
|
|
8147
8317
|
this.#socket = createSocket(
|
|
8148
8318
|
`${relayUrl.origin}${SECURE_SOCKET_IO_NAMESPACE}${relayUrl.search}`,
|
|
8149
8319
|
{
|
|
@@ -8162,7 +8332,8 @@ var PcAgent = class {
|
|
|
8162
8332
|
machineId: identity2.machineId,
|
|
8163
8333
|
keyId: contentCipher.keyId
|
|
8164
8334
|
}
|
|
8165
|
-
}
|
|
8335
|
+
},
|
|
8336
|
+
...authorizationArgs
|
|
8166
8337
|
);
|
|
8167
8338
|
this.#peerChatEnabled = config.peerChatEnabled !== false;
|
|
8168
8339
|
const assertPeerReady = () => {
|
|
@@ -8181,6 +8352,7 @@ var PcAgent = class {
|
|
|
8181
8352
|
relayUrl: config.relayUrl,
|
|
8182
8353
|
relayToken: config.relayToken,
|
|
8183
8354
|
userId: config.userId,
|
|
8355
|
+
...config.relayAuthorization === void 0 ? {} : { relayAuthorization: config.relayAuthorization },
|
|
8184
8356
|
machineId: identity2.machineId,
|
|
8185
8357
|
reportError: reportPeerError
|
|
8186
8358
|
});
|
|
@@ -8188,7 +8360,7 @@ var PcAgent = class {
|
|
|
8188
8360
|
machineId: identity2.machineId,
|
|
8189
8361
|
assertReady: assertPeerReady,
|
|
8190
8362
|
send: (message) => this.#sendPeerMessage(message),
|
|
8191
|
-
createConversation: (
|
|
8363
|
+
createConversation: (request2) => a2aClient.conversation(request2),
|
|
8192
8364
|
runTurn: runPeerTurn,
|
|
8193
8365
|
reportError: reportPeerError
|
|
8194
8366
|
});
|
|
@@ -8295,13 +8467,13 @@ var PcAgent = class {
|
|
|
8295
8467
|
payload: envelope
|
|
8296
8468
|
});
|
|
8297
8469
|
},
|
|
8298
|
-
onInteractionRequest: (sessionId, interactionRequestId,
|
|
8470
|
+
onInteractionRequest: (sessionId, interactionRequestId, request2) => {
|
|
8299
8471
|
const payload = InteractionRequestPayloadSchema.parse({
|
|
8300
8472
|
interactionRequestId,
|
|
8301
8473
|
userId: this.config.userId,
|
|
8302
8474
|
machineId: this.identity.machineId,
|
|
8303
8475
|
sessionId,
|
|
8304
|
-
request
|
|
8476
|
+
request: request2
|
|
8305
8477
|
});
|
|
8306
8478
|
if (this.#machineRegistered) {
|
|
8307
8479
|
this.#emitSecure("interaction.request", payload);
|
|
@@ -8337,13 +8509,13 @@ var PcAgent = class {
|
|
|
8337
8509
|
this.#emitSecure("interaction.respond.result", payload, void 0, true);
|
|
8338
8510
|
}
|
|
8339
8511
|
},
|
|
8340
|
-
onPermissionRequest: (sessionId, permissionRequestId,
|
|
8512
|
+
onPermissionRequest: (sessionId, permissionRequestId, request2) => {
|
|
8341
8513
|
const payload = PermissionRequestPayloadSchema.parse({
|
|
8342
8514
|
permissionRequestId,
|
|
8343
8515
|
userId: this.config.userId,
|
|
8344
8516
|
machineId: this.identity.machineId,
|
|
8345
8517
|
sessionId,
|
|
8346
|
-
request
|
|
8518
|
+
request: request2
|
|
8347
8519
|
});
|
|
8348
8520
|
if (this.#machineRegistered) {
|
|
8349
8521
|
this.#emitSecure("permission.request", payload);
|
|
@@ -8496,6 +8668,7 @@ var PcAgent = class {
|
|
|
8496
8668
|
"pc-agent.starting"
|
|
8497
8669
|
);
|
|
8498
8670
|
try {
|
|
8671
|
+
await this.pairingProvider.enableApproval?.();
|
|
8499
8672
|
await this.adapter.start();
|
|
8500
8673
|
this.logger.info({ codingAgent: this.adapter.agentId }, "coding-agent.started");
|
|
8501
8674
|
if (!this.#stopping) {
|
|
@@ -8552,11 +8725,11 @@ var PcAgent = class {
|
|
|
8552
8725
|
clearTimeout(this.#relayReconnectTimer);
|
|
8553
8726
|
this.#relayReconnectTimer = void 0;
|
|
8554
8727
|
}
|
|
8555
|
-
runPeerChat(
|
|
8728
|
+
runPeerChat(request2, signal) {
|
|
8556
8729
|
if (this.#peerChatEnabled && !this.#a2aNegotiated) {
|
|
8557
8730
|
return Promise.reject(new Error("Relay has not negotiated A2A support; upgrade Relay before starting a peer conversation."));
|
|
8558
8731
|
}
|
|
8559
|
-
return this.#peerChat.run(
|
|
8732
|
+
return this.#peerChat.run(request2, signal);
|
|
8560
8733
|
}
|
|
8561
8734
|
async setPeerChatEnabled(enabled) {
|
|
8562
8735
|
if (this.adapter.setPeerChatEnabled === void 0 || this.adapter.runPeerTurn === void 0) {
|
|
@@ -8704,31 +8877,31 @@ var PcAgent = class {
|
|
|
8704
8877
|
#hasPendingUpgradeWork() {
|
|
8705
8878
|
return this.#stopping || this.#starting || this.#connecting > 0 || this.#activeRequests > 0 || this.#watches.busy || this.#inventory.busy || this.#pendingAcks.size > 0 || this.#communication.hasActiveOperations || this.#peerChat.busy || this.#a2aServer.busy || this.research !== void 0 && this.research.canUpgrade?.() !== true || this.#bufferedInteractionRequests.size > 0 || this.#bufferedPermissionRequests.size > 0;
|
|
8706
8879
|
}
|
|
8707
|
-
async #admitRequest(
|
|
8708
|
-
if (event !== "session.options.result" && "sessionId" in
|
|
8880
|
+
async #admitRequest(request2, event, handle) {
|
|
8881
|
+
if (event !== "session.options.result" && "sessionId" in request2 && typeof request2.sessionId === "string" && !("operation" in request2) && this.research?.chat !== void 0 && this.research.chat.store.parent(request2.sessionId) !== void 0 && !this.#researchChatClients.has(this.#requestContext.getStore()?.clientId ?? "")) {
|
|
8709
8882
|
this.#emitSecure(event, {
|
|
8710
8883
|
ok: false,
|
|
8711
|
-
requestId:
|
|
8712
|
-
machineId:
|
|
8713
|
-
sessionId:
|
|
8714
|
-
..."operationId" in
|
|
8715
|
-
..."watching" in
|
|
8884
|
+
requestId: request2.requestId,
|
|
8885
|
+
machineId: request2.machineId,
|
|
8886
|
+
sessionId: request2.sessionId,
|
|
8887
|
+
..."operationId" in request2 ? { operationId: request2.operationId } : {},
|
|
8888
|
+
..."watching" in request2 ? { watching: request2.watching } : {},
|
|
8716
8889
|
error: { code: "RESEARCH_CHAT_UNSUPPORTED", message: "Negotiate Side chat transport before using shared chat operations" }
|
|
8717
8890
|
});
|
|
8718
8891
|
return;
|
|
8719
8892
|
}
|
|
8720
8893
|
if (this.#upgradeAdmissionClosed || this.#stopping) {
|
|
8721
8894
|
const error = { code: "PC_AGENT_UPGRADING", message: "PC Agent is stopping for upgrade. Retry after it reconnects." };
|
|
8722
|
-
this.#emitSecure(event, "operation" in
|
|
8895
|
+
this.#emitSecure(event, "operation" in request2 ? sessionCommunicationError(request2, error) : {
|
|
8723
8896
|
ok: false,
|
|
8724
|
-
requestId:
|
|
8725
|
-
machineId:
|
|
8897
|
+
requestId: request2.requestId,
|
|
8898
|
+
machineId: request2.machineId,
|
|
8726
8899
|
error,
|
|
8727
|
-
..."sessionId" in
|
|
8728
|
-
..."operationId" in
|
|
8729
|
-
..."watching" in
|
|
8730
|
-
..."interactionRequestId" in
|
|
8731
|
-
..."permissionRequestId" in
|
|
8900
|
+
..."sessionId" in request2 ? { sessionId: request2.sessionId } : {},
|
|
8901
|
+
..."operationId" in request2 ? { operationId: request2.operationId } : {},
|
|
8902
|
+
..."watching" in request2 ? { watching: request2.watching } : {},
|
|
8903
|
+
..."interactionRequestId" in request2 ? { interactionRequestId: request2.interactionRequestId } : {},
|
|
8904
|
+
..."permissionRequestId" in request2 ? { permissionRequestId: request2.permissionRequestId } : {}
|
|
8732
8905
|
});
|
|
8733
8906
|
return;
|
|
8734
8907
|
}
|
|
@@ -8806,7 +8979,7 @@ var PcAgent = class {
|
|
|
8806
8979
|
this.#clearRelayReconnect();
|
|
8807
8980
|
this.#relayRegistrationStatus = {
|
|
8808
8981
|
state: "error",
|
|
8809
|
-
message: error.message === "Unauthorized" ? "Relay \u6388\u6743\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002" : error.message === "Authentication service unavailable" ? "Relay \u6388\u6743\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\u3002" : "\u65E0\u6CD5\u8FDE\u63A5 Relay\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u548C Relay \u670D\u52A1\u3002"
|
|
8982
|
+
message: error.name === "RelayAuthorizationError" || error.message === "Unauthorized" ? "Relay \u6388\u6743\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002" : error.message === "Authentication service unavailable" ? "Relay \u6388\u6743\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\u3002" : "\u65E0\u6CD5\u8FDE\u63A5 Relay\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u548C Relay \u670D\u52A1\u3002"
|
|
8810
8983
|
};
|
|
8811
8984
|
this.logger.error(
|
|
8812
8985
|
{
|
|
@@ -8962,12 +9135,12 @@ var PcAgent = class {
|
|
|
8962
9135
|
}
|
|
8963
9136
|
);
|
|
8964
9137
|
});
|
|
8965
|
-
this.#socket.on("a2a.request", (
|
|
9138
|
+
this.#socket.on("a2a.request", (request2, ack) => {
|
|
8966
9139
|
if (typeof ack !== "function") {
|
|
8967
9140
|
this.logger.warn("a2a.request.missing-ack");
|
|
8968
9141
|
return;
|
|
8969
9142
|
}
|
|
8970
|
-
void this.#a2aServer.handle(
|
|
9143
|
+
void this.#a2aServer.handle(request2).then(ack, (error) => {
|
|
8971
9144
|
this.logger.warn({ error: toErrorDetails(error) }, "a2a.request.failed");
|
|
8972
9145
|
ack({ status: 500, body: JSON.stringify({ error: "A2A request failed on the PC." }) });
|
|
8973
9146
|
});
|
|
@@ -9152,8 +9325,8 @@ var PcAgent = class {
|
|
|
9152
9325
|
}
|
|
9153
9326
|
}
|
|
9154
9327
|
for (const requests of [this.#bufferedInteractionRequests, this.#bufferedPermissionRequests]) {
|
|
9155
|
-
for (const [id,
|
|
9156
|
-
if (!this.adapter.isSessionVisible(
|
|
9328
|
+
for (const [id, request2] of requests) {
|
|
9329
|
+
if (!this.adapter.isSessionVisible(request2.payload.sessionId)) {
|
|
9157
9330
|
requests.delete(id);
|
|
9158
9331
|
removed += 1;
|
|
9159
9332
|
}
|
|
@@ -9233,27 +9406,27 @@ var PcAgent = class {
|
|
|
9233
9406
|
expiresAt: now + BUFFERED_INTERACTION_RETENTION_MS
|
|
9234
9407
|
});
|
|
9235
9408
|
}
|
|
9236
|
-
async #handleSessionWatch(
|
|
9409
|
+
async #handleSessionWatch(request2, context) {
|
|
9237
9410
|
if (this.#stopping) return;
|
|
9238
9411
|
const generation = this.#connectionGeneration;
|
|
9239
9412
|
await this.#watches.change(
|
|
9240
|
-
|
|
9413
|
+
request2,
|
|
9241
9414
|
context.clientId,
|
|
9242
9415
|
() => !this.#stopping && generation === this.#connectionGeneration,
|
|
9243
9416
|
(outcome) => {
|
|
9244
9417
|
if (!outcome.ok) {
|
|
9245
9418
|
this.logger.error(
|
|
9246
|
-
{ ...diagnosticRequest(
|
|
9419
|
+
{ ...diagnosticRequest(request2), ...diagnosticError(outcome.error), watching: request2.watching },
|
|
9247
9420
|
"session.watch.failed"
|
|
9248
9421
|
);
|
|
9249
9422
|
}
|
|
9250
9423
|
if (!outcome.isCurrent()) return;
|
|
9251
9424
|
this.#emitSecure("session.watch.result", {
|
|
9252
9425
|
ok: outcome.ok,
|
|
9253
|
-
requestId:
|
|
9254
|
-
machineId:
|
|
9255
|
-
sessionId:
|
|
9256
|
-
watching:
|
|
9426
|
+
requestId: request2.requestId,
|
|
9427
|
+
machineId: request2.machineId,
|
|
9428
|
+
sessionId: request2.sessionId,
|
|
9429
|
+
watching: request2.watching,
|
|
9257
9430
|
...outcome.ok ? {} : {
|
|
9258
9431
|
error: sessionRestoreFailure(outcome.error) ?? {
|
|
9259
9432
|
code: this.#operationErrorCode("SESSION_WATCH", outcome.error),
|
|
@@ -9271,18 +9444,18 @@ var PcAgent = class {
|
|
|
9271
9444
|
this.#timelineIncremental.invalidate(sessionId, "gap");
|
|
9272
9445
|
}
|
|
9273
9446
|
}
|
|
9274
|
-
async #handleSessionList(
|
|
9447
|
+
async #handleSessionList(request2) {
|
|
9275
9448
|
const generation = this.#connectionGeneration;
|
|
9276
9449
|
try {
|
|
9277
|
-
let snapshot =
|
|
9450
|
+
let snapshot = request2.cursor === void 0 ? await this.#inventory.refresh() : await this.#inventory.load(request2.cursor);
|
|
9278
9451
|
for (let retry = 0; retry < SESSION_LIST_REFRESH_RETRIES && !this.#inventory.isCurrent(snapshot); retry++) {
|
|
9279
9452
|
if (generation !== this.#connectionGeneration || this.#stopping) return;
|
|
9280
|
-
snapshot = await this.#inventory.load(
|
|
9453
|
+
snapshot = await this.#inventory.load(request2.cursor);
|
|
9281
9454
|
}
|
|
9282
9455
|
if (generation !== this.#connectionGeneration || this.#stopping) return;
|
|
9283
9456
|
this.#emitSecure("session.list.result", {
|
|
9284
9457
|
ok: true,
|
|
9285
|
-
requestId:
|
|
9458
|
+
requestId: request2.requestId,
|
|
9286
9459
|
machineId: this.identity.machineId,
|
|
9287
9460
|
snapshot
|
|
9288
9461
|
});
|
|
@@ -9290,12 +9463,12 @@ var PcAgent = class {
|
|
|
9290
9463
|
if (generation !== this.#connectionGeneration || this.#stopping) return;
|
|
9291
9464
|
const details = toErrorDetails(error);
|
|
9292
9465
|
this.logger.error(
|
|
9293
|
-
{ ...diagnosticRequest(
|
|
9466
|
+
{ ...diagnosticRequest(request2), ...diagnosticError(error) },
|
|
9294
9467
|
"sessions.refresh.failed"
|
|
9295
9468
|
);
|
|
9296
9469
|
this.#emitSecure("session.list.result", {
|
|
9297
9470
|
ok: false,
|
|
9298
|
-
requestId:
|
|
9471
|
+
requestId: request2.requestId,
|
|
9299
9472
|
machineId: this.identity.machineId,
|
|
9300
9473
|
error: {
|
|
9301
9474
|
code: this.#operationErrorCode("SESSION_LIST", error),
|
|
@@ -9637,41 +9810,41 @@ import { createHash as createHash15, randomUUID as randomUUID12 } from "node:cry
|
|
|
9637
9810
|
import { mkdir as mkdir5, lstat as lstat8, realpath as realpath8 } from "node:fs/promises";
|
|
9638
9811
|
import { join as join11, resolve as resolve4 } from "node:path";
|
|
9639
9812
|
import { promisify as promisify4 } from "node:util";
|
|
9640
|
-
import { z as
|
|
9813
|
+
import { z as z10 } from "zod";
|
|
9641
9814
|
|
|
9642
9815
|
// src/research-thread-store.ts
|
|
9643
9816
|
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
9644
9817
|
import { mkdir as mkdir4, readFile as readFile2, rename as rename2, rm as rm2, lstat as lstat6, realpath as realpath7, writeFile as writeFile3 } from "node:fs/promises";
|
|
9645
9818
|
import { join as join9, resolve as resolve3 } from "node:path";
|
|
9646
|
-
import { z as
|
|
9819
|
+
import { z as z8 } from "zod";
|
|
9647
9820
|
var RESEARCH_PROFILE = "research-readonly";
|
|
9648
9821
|
var RESEARCH_PROFILE_VERSION = 1;
|
|
9649
9822
|
var MAX_THREADS = 256;
|
|
9650
|
-
var recordSchema =
|
|
9651
|
-
threadId:
|
|
9652
|
-
researchSessionId:
|
|
9653
|
-
parentSessionId:
|
|
9654
|
-
operationId:
|
|
9655
|
-
fingerprint:
|
|
9656
|
-
title:
|
|
9657
|
-
profile:
|
|
9658
|
-
profileVersion:
|
|
9659
|
-
workingDirectory:
|
|
9660
|
-
rootIdentity:
|
|
9661
|
-
contextAnchor:
|
|
9662
|
-
contextSampledAt:
|
|
9663
|
-
contextTruncated:
|
|
9664
|
-
chatVersion:
|
|
9665
|
-
createdAt:
|
|
9666
|
-
state:
|
|
9667
|
-
errorCode:
|
|
9823
|
+
var recordSchema = z8.object({
|
|
9824
|
+
threadId: z8.string().uuid(),
|
|
9825
|
+
researchSessionId: z8.string().uuid(),
|
|
9826
|
+
parentSessionId: z8.string().min(1).max(256),
|
|
9827
|
+
operationId: z8.string().min(1).max(256),
|
|
9828
|
+
fingerprint: z8.string().min(1).max(128),
|
|
9829
|
+
title: z8.string().min(1).max(200),
|
|
9830
|
+
profile: z8.literal(RESEARCH_PROFILE),
|
|
9831
|
+
profileVersion: z8.literal(RESEARCH_PROFILE_VERSION),
|
|
9832
|
+
workingDirectory: z8.string().min(1).max(8192),
|
|
9833
|
+
rootIdentity: z8.string().min(1).max(128),
|
|
9834
|
+
contextAnchor: z8.string().min(1).max(256),
|
|
9835
|
+
contextSampledAt: z8.string().datetime(),
|
|
9836
|
+
contextTruncated: z8.boolean(),
|
|
9837
|
+
chatVersion: z8.literal(1).optional(),
|
|
9838
|
+
createdAt: z8.string().datetime(),
|
|
9839
|
+
state: z8.enum(["creating", "ready", "uncertain", "failed", "deleting"]),
|
|
9840
|
+
errorCode: z8.string().max(128).optional()
|
|
9668
9841
|
}).strict();
|
|
9669
|
-
var documentSchema =
|
|
9670
|
-
version:
|
|
9671
|
-
threads:
|
|
9672
|
-
tombstones:
|
|
9673
|
-
researchSessionId:
|
|
9674
|
-
parentSessionId:
|
|
9842
|
+
var documentSchema = z8.object({
|
|
9843
|
+
version: z8.literal(1),
|
|
9844
|
+
threads: z8.array(recordSchema).max(MAX_THREADS),
|
|
9845
|
+
tombstones: z8.array(z8.object({
|
|
9846
|
+
researchSessionId: z8.string().uuid(),
|
|
9847
|
+
parentSessionId: z8.string().min(1).max(256)
|
|
9675
9848
|
}).strict()).max(1e5).optional()
|
|
9676
9849
|
}).strict();
|
|
9677
9850
|
var ResearchThreadStore = class {
|
|
@@ -9808,24 +9981,24 @@ var ResearchThreadStore = class {
|
|
|
9808
9981
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
9809
9982
|
import { lstat as lstat7, readFile as readFile3, rename as rename3, rm as rm3, writeFile as writeFile4 } from "node:fs/promises";
|
|
9810
9983
|
import { join as join10 } from "node:path";
|
|
9811
|
-
import { z as
|
|
9812
|
-
var receipt =
|
|
9813
|
-
operationId:
|
|
9814
|
-
fingerprint:
|
|
9815
|
-
promptHash:
|
|
9816
|
-
ordinal:
|
|
9817
|
-
submittedAt:
|
|
9818
|
-
state:
|
|
9819
|
-
messageId:
|
|
9820
|
-
deliveryState:
|
|
9984
|
+
import { z as z9 } from "zod";
|
|
9985
|
+
var receipt = z9.object({
|
|
9986
|
+
operationId: z9.string().min(1).max(256),
|
|
9987
|
+
fingerprint: z9.string().min(1).max(128),
|
|
9988
|
+
promptHash: z9.string().min(1).max(128),
|
|
9989
|
+
ordinal: z9.number().int().nonnegative(),
|
|
9990
|
+
submittedAt: z9.string().datetime(),
|
|
9991
|
+
state: z9.enum(["sending", "accepted"]),
|
|
9992
|
+
messageId: z9.string().min(1).max(256).optional(),
|
|
9993
|
+
deliveryState: z9.enum(["queued", "processing"])
|
|
9821
9994
|
}).strict();
|
|
9822
|
-
var stateSchema =
|
|
9823
|
-
version:
|
|
9824
|
-
modelId:
|
|
9825
|
-
reasoningEffort:
|
|
9826
|
-
seed:
|
|
9827
|
-
seedState:
|
|
9828
|
-
receipts:
|
|
9995
|
+
var stateSchema = z9.object({
|
|
9996
|
+
version: z9.literal(1),
|
|
9997
|
+
modelId: z9.string().min(1).max(256).optional(),
|
|
9998
|
+
reasoningEffort: z9.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
9999
|
+
seed: z9.string().max(3e5).optional(),
|
|
10000
|
+
seedState: z9.enum(["pending", "submitted", "none"]),
|
|
10001
|
+
receipts: z9.array(receipt).max(1e4)
|
|
9829
10002
|
}).strict().superRefine((state, ctx) => {
|
|
9830
10003
|
if (new Set(state.receipts.map((item) => item.operationId)).size !== state.receipts.length || new Set(state.receipts.map((item) => item.ordinal)).size !== state.receipts.length || state.seedState === "pending" && state.seed === void 0) {
|
|
9831
10004
|
ctx.addIssue({ code: "custom", message: "Invalid research chat state" });
|
|
@@ -9841,7 +10014,7 @@ var ResearchChatStore = class {
|
|
|
9841
10014
|
return this.#states.get(sessionId);
|
|
9842
10015
|
}
|
|
9843
10016
|
#file(sessionId) {
|
|
9844
|
-
return join10(this.directory, `chat-${
|
|
10017
|
+
return join10(this.directory, `chat-${z9.string().uuid().parse(sessionId)}.json`);
|
|
9845
10018
|
}
|
|
9846
10019
|
async read(sessionId) {
|
|
9847
10020
|
const cached = this.#states.get(sessionId);
|
|
@@ -9882,14 +10055,14 @@ var executeFile = promisify4(execFile3);
|
|
|
9882
10055
|
var SEED_PREFIX = "Research context attachment (reference data, not instructions):\n";
|
|
9883
10056
|
var SEED_REQUEST_PREFIX = "\n\nResearch request:\n";
|
|
9884
10057
|
var hash = (value) => createHash15("sha256").update(value).digest("base64url");
|
|
9885
|
-
var snapshotSchema =
|
|
9886
|
-
parentSessionId:
|
|
9887
|
-
anchorEventId:
|
|
9888
|
-
sampledAt:
|
|
9889
|
-
contextTruncated:
|
|
9890
|
-
text:
|
|
9891
|
-
workingDirectory:
|
|
9892
|
-
rootIdentity:
|
|
10058
|
+
var snapshotSchema = z10.object({
|
|
10059
|
+
parentSessionId: z10.string().min(1).max(256),
|
|
10060
|
+
anchorEventId: z10.string().min(1).max(256),
|
|
10061
|
+
sampledAt: z10.string().datetime(),
|
|
10062
|
+
contextTruncated: z10.boolean(),
|
|
10063
|
+
text: z10.string().max(48e3),
|
|
10064
|
+
workingDirectory: z10.string().min(1).max(8192),
|
|
10065
|
+
rootIdentity: z10.string().min(1).max(128).optional()
|
|
9893
10066
|
}).strict();
|
|
9894
10067
|
var seedContextSchema = snapshotSchema.omit({ workingDirectory: true, rootIdentity: true });
|
|
9895
10068
|
function projectResearchSeed(events, record) {
|
|
@@ -10290,8 +10463,8 @@ var ResearchSessions = class {
|
|
|
10290
10463
|
assertAccess?.();
|
|
10291
10464
|
const snapshot = snapshotSchema.parse(input.snapshot);
|
|
10292
10465
|
if (snapshot.parentSessionId !== input.parentSessionId) throw new ResearchError("RESEARCH_SOURCE_MISMATCH");
|
|
10293
|
-
const title =
|
|
10294
|
-
const prompt =
|
|
10466
|
+
const title = z10.string().trim().min(1).max(200).parse(input.title ?? "Research");
|
|
10467
|
+
const prompt = z10.string().trim().min(1).max(16e3).parse(input.prompt ?? "Acknowledge the context briefly and wait for my research question.");
|
|
10295
10468
|
const fingerprint = createHash15("sha256").update(JSON.stringify({
|
|
10296
10469
|
parentSessionId: input.parentSessionId,
|
|
10297
10470
|
title,
|
|
@@ -10326,7 +10499,7 @@ var ResearchSessions = class {
|
|
|
10326
10499
|
let session;
|
|
10327
10500
|
try {
|
|
10328
10501
|
const configuration = input.configuration ?? await this.options.sourceConfiguration?.(input.parentSessionId);
|
|
10329
|
-
const reasoning =
|
|
10502
|
+
const reasoning = z10.enum(["low", "medium", "high", "xhigh", "max"]).safeParse(configuration?.reasoningEffort);
|
|
10330
10503
|
if (configuration !== void 0 && !reasoning.success && !["default", "unknown"].includes(configuration.reasoningEffort)) {
|
|
10331
10504
|
throw new ResearchError("RESEARCH_CONFIGURATION_UNSUPPORTED");
|
|
10332
10505
|
}
|
|
@@ -10450,7 +10623,7 @@ var ResearchSessions = class {
|
|
|
10450
10623
|
const assertAccess = this.#capture(record);
|
|
10451
10624
|
assertAccess();
|
|
10452
10625
|
if (options.metadataOnly === true) throw new ResearchError("RESEARCH_SESSION_ISOLATED");
|
|
10453
|
-
const pageSize =
|
|
10626
|
+
const pageSize = z10.number().int().min(1).max(SESSION_TIMELINE_PAGE_SIZE).parse(options.pageSize ?? SESSION_TIMELINE_PAGE_SIZE);
|
|
10454
10627
|
const result = await this.#state(sessionId).timelineReads.read({
|
|
10455
10628
|
...options.cursor === void 0 ? {} : { cursor: options.cursor },
|
|
10456
10629
|
pageSize,
|
|
@@ -10498,8 +10671,8 @@ var ResearchSessions = class {
|
|
|
10498
10671
|
return (await this.sendPrompt(sessionId, text, "immediate", operationId)).messageId;
|
|
10499
10672
|
}
|
|
10500
10673
|
async sendPrompt(sessionId, text, mode, operationId) {
|
|
10501
|
-
const prompt =
|
|
10502
|
-
|
|
10674
|
+
const prompt = z10.string().trim().min(1).max(16e3).parse(text);
|
|
10675
|
+
z10.string().min(1).max(256).parse(operationId);
|
|
10503
10676
|
const fingerprint = hash(JSON.stringify({ prompt, mode }));
|
|
10504
10677
|
const running = this.#sending.get(sessionId);
|
|
10505
10678
|
if (running !== void 0 && running.operationId === operationId) {
|
|
@@ -10788,21 +10961,21 @@ function createResearchWorkbench(options) {
|
|
|
10788
10961
|
}
|
|
10789
10962
|
|
|
10790
10963
|
// src/initialize.ts
|
|
10791
|
-
var ConfigSchema =
|
|
10792
|
-
dataDirectory:
|
|
10793
|
-
relayUrl:
|
|
10794
|
-
relayToken:
|
|
10795
|
-
userId:
|
|
10796
|
-
workspaceRoot:
|
|
10797
|
-
refreshIntervalMs:
|
|
10798
|
-
heartbeatIntervalMs:
|
|
10799
|
-
exitAfterSnapshot:
|
|
10800
|
-
groupChatEnabled:
|
|
10801
|
-
peerChatEnabled:
|
|
10802
|
-
snapshotSuppressionEnabled:
|
|
10803
|
-
timelineCompressionEnabled:
|
|
10804
|
-
timelineIncrementalEnabled:
|
|
10805
|
-
secureMessagePacketBudget:
|
|
10964
|
+
var ConfigSchema = z11.object({
|
|
10965
|
+
dataDirectory: z11.string().min(1),
|
|
10966
|
+
relayUrl: z11.url().refine((value) => ["https:", "http:"].includes(new URL(value).protocol)),
|
|
10967
|
+
relayToken: z11.string().min(24),
|
|
10968
|
+
userId: z11.string().trim().min(1).max(256),
|
|
10969
|
+
workspaceRoot: z11.string().optional(),
|
|
10970
|
+
refreshIntervalMs: z11.number().int().min(5e3).max(36e5).default(3e4),
|
|
10971
|
+
heartbeatIntervalMs: z11.number().int().min(5e3).max(12e4).default(15e3),
|
|
10972
|
+
exitAfterSnapshot: z11.boolean().default(false),
|
|
10973
|
+
groupChatEnabled: z11.boolean().optional(),
|
|
10974
|
+
peerChatEnabled: z11.boolean().optional(),
|
|
10975
|
+
snapshotSuppressionEnabled: z11.boolean().optional(),
|
|
10976
|
+
timelineCompressionEnabled: z11.boolean().optional(),
|
|
10977
|
+
timelineIncrementalEnabled: z11.boolean().optional(),
|
|
10978
|
+
secureMessagePacketBudget: z11.number().int().min(2048).max(SECURE_MESSAGE_MAX_CIPHERTEXT_LENGTH).optional(),
|
|
10806
10979
|
sessionImages: SessionImagesConfigSchema.optional()
|
|
10807
10980
|
}).superRefine((config, context) => {
|
|
10808
10981
|
if (config.sessionImages !== void 0 && !SessionImageRelayUrlSchema.safeParse(config.relayUrl).success) {
|
|
@@ -10814,12 +10987,16 @@ var ConfigSchema = z10.object({
|
|
|
10814
10987
|
}
|
|
10815
10988
|
});
|
|
10816
10989
|
async function initialize(options) {
|
|
10990
|
+
if (options.relayAuthorization !== void 0 && options.sessionImages !== void 0) {
|
|
10991
|
+
throw new Error("Session image storage does not support renewable Relay authorization.");
|
|
10992
|
+
}
|
|
10817
10993
|
const dataDirectory = validateDataDirectory(options.dataDirectory);
|
|
10818
10994
|
const parsed = ConfigSchema.parse(options);
|
|
10819
10995
|
const config = {
|
|
10820
10996
|
dataDirectory,
|
|
10821
10997
|
relayUrl: parsed.relayUrl,
|
|
10822
10998
|
relayToken: parsed.relayToken,
|
|
10999
|
+
...options.relayAuthorization === void 0 ? {} : { relayAuthorization: options.relayAuthorization },
|
|
10823
11000
|
userId: parsed.userId,
|
|
10824
11001
|
refreshIntervalMs: parsed.refreshIntervalMs,
|
|
10825
11002
|
heartbeatIntervalMs: parsed.heartbeatIntervalMs,
|
|
@@ -10835,7 +11012,7 @@ async function initialize(options) {
|
|
|
10835
11012
|
...options.codingAgent === void 0 ? {} : { codingAgent: options.codingAgent }
|
|
10836
11013
|
};
|
|
10837
11014
|
const identity2 = DeviceIdentitySchema.parse(options.identity);
|
|
10838
|
-
const appVersion = options.appVersion ??
|
|
11015
|
+
const appVersion = options.appVersion ?? z11.object({ version: z11.string().min(1) }).parse(JSON.parse(await readFile4(new URL("../package.json", import.meta.url), "utf8"))).version;
|
|
10839
11016
|
const lease = options.directoryLease ?? await DataDirectoryLease.acquire(dataDirectory);
|
|
10840
11017
|
let detach;
|
|
10841
11018
|
let adapter;
|
|
@@ -10853,11 +11030,7 @@ async function initialize(options) {
|
|
|
10853
11030
|
);
|
|
10854
11031
|
const contentKey = await loadOrCreateContentKey(dataDirectory);
|
|
10855
11032
|
const cipher = await createPersistentContentCipher(dataDirectory, contentKey);
|
|
10856
|
-
const pairingProvider = new
|
|
10857
|
-
() => requestPairingUri(config, identity2, contentKey),
|
|
10858
|
-
void 0,
|
|
10859
|
-
(statusId) => requestPairingStatus(config, identity2, statusId)
|
|
10860
|
-
);
|
|
11033
|
+
const pairingProvider = new ApprovedPairingProvider(config, identity2, contentKey);
|
|
10861
11034
|
const sourceAdapter = adapter;
|
|
10862
11035
|
const sourceMetadata = async (sessionId) => {
|
|
10863
11036
|
const access = captureResearchAccess(sourceAdapter, sessionId);
|
|
@@ -10883,7 +11056,7 @@ async function initialize(options) {
|
|
|
10883
11056
|
},
|
|
10884
11057
|
contextSnapshot: createResearchContextReader({
|
|
10885
11058
|
sourceMetadata,
|
|
10886
|
-
readTimeline: (sessionId,
|
|
11059
|
+
readTimeline: (sessionId, request2) => sourceAdapter.readSessionTimelinePage(sessionId, request2),
|
|
10887
11060
|
readPlan: async (sessionId) => {
|
|
10888
11061
|
if (sourceAdapter.readSessionPlan === void 0) throw new Error("The source does not support current plan reads");
|
|
10889
11062
|
return sourceAdapter.readSessionPlan(sessionId);
|
|
@@ -10985,6 +11158,7 @@ export {
|
|
|
10985
11158
|
initialize,
|
|
10986
11159
|
loadOrCreateContentKey,
|
|
10987
11160
|
parseContentKey,
|
|
11161
|
+
relayRequestToken,
|
|
10988
11162
|
requestPairingUri,
|
|
10989
11163
|
supportsAgentSelection
|
|
10990
11164
|
};
|