@agentknight/sdk 0.9.68 → 0.9.72

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.
Files changed (30) hide show
  1. package/dist/chunks/{acp-adapter-RZX5SUB3.js → acp-adapter-PCNN2NAJ.js} +41 -4
  2. package/dist/chunks/{chunk-Y6NCJB55.js → chunk-23BKGY5J.js} +4 -4
  3. package/dist/chunks/{chunk-UHRUQM4D.js → chunk-2UHBY25U.js} +1 -1
  4. package/dist/chunks/{chunk-CFQQOAQV.js → chunk-36KL4FSH.js} +2 -2
  5. package/dist/chunks/{chunk-FY4XTWUF.js → chunk-5BDFZ3AS.js} +4 -13
  6. package/dist/chunks/{chunk-DWTXWVIA.js → chunk-5FJJZCP6.js} +683 -629
  7. package/dist/chunks/{chunk-B777YB6E.js → chunk-DXHAKWGO.js} +2 -2
  8. package/dist/chunks/{chunk-35OF2ZNS.js → chunk-E5VHBC55.js} +14 -0
  9. package/dist/chunks/{chunk-MB3H6HEI.js → chunk-FQ26TSDG.js} +2 -2
  10. package/dist/chunks/{chunk-Q5OUZJCZ.js → chunk-GRUDMHEJ.js} +1 -1
  11. package/dist/chunks/{chunk-AWVC5NX4.js → chunk-I42IONUU.js} +1 -1
  12. package/dist/chunks/{chunk-4XT65OSG.js → chunk-KPHWVNKP.js} +46 -3
  13. package/dist/chunks/{chunk-EDYVCZIR.js → chunk-PAJZL5ST.js} +7 -2
  14. package/dist/chunks/{chunk-LCA2MWOQ.js → chunk-TFUSRA2B.js} +2 -2
  15. package/dist/chunks/chunk-UTF7KLMJ.js +11 -0
  16. package/dist/chunks/chunk-VEJLENEQ.js +174 -0
  17. package/dist/chunks/chunk-VOR4AECB.js +78 -0
  18. package/dist/chunks/{claude-adapter-FQSQIYUY.js → claude-adapter-A4LPYQ2Z.js} +296 -223
  19. package/dist/chunks/{codex-adapter-TOXSRT2W.js → codex-adapter-AFGS7MPX.js} +249 -66
  20. package/dist/chunks/{copilot-adapter-KUCX7XQW.js → copilot-adapter-NXJTI2HY.js} +27 -70
  21. package/dist/chunks/{managed-agent-adapter-LGBRXDGP.js → managed-agent-adapter-4C2PWD4V.js} +9 -7
  22. package/dist/chunks/{pi-adapter-RXNZSE4F.js → pi-adapter-EZOIK5RA.js} +7 -9
  23. package/dist/configuration.js +4 -4
  24. package/dist/index.d.ts +153 -8
  25. package/dist/index.js +183 -57
  26. package/dist/runtime.js +2 -2
  27. package/dist/session-analytics-worker.js +6 -7
  28. package/package.json +2 -3
  29. package/dist/chunks/chunk-IXGVSREH.js +0 -48
  30. package/dist/chunks/chunk-T6226JFS.js +0 -55
package/dist/index.js CHANGED
@@ -3,14 +3,14 @@ import {
3
3
  detectCopilot,
4
4
  detectPi,
5
5
  hasLocalExecutable
6
- } from "./chunks/chunk-T6226JFS.js";
6
+ } from "./chunks/chunk-VEJLENEQ.js";
7
7
  import {
8
8
  DataDirectoryLease,
9
9
  PEER_CHAT_TIMEOUT_MS,
10
10
  PeerChatRequestSchema,
11
11
  PeerChatResultSchema,
12
12
  validateDataDirectory
13
- } from "./chunks/chunk-Q5OUZJCZ.js";
13
+ } from "./chunks/chunk-GRUDMHEJ.js";
14
14
  import {
15
15
  DeviceIdentitySchema,
16
16
  codingAgentPresentation,
@@ -20,12 +20,11 @@ import {
20
20
  AgentSelectionSchema,
21
21
  assertSelectionSnapshotFits,
22
22
  supportsAgentSelection
23
- } from "./chunks/chunk-LCA2MWOQ.js";
23
+ } from "./chunks/chunk-TFUSRA2B.js";
24
24
  import {
25
25
  LiveTimelineProjection,
26
26
  OperationDiagnostics,
27
27
  OperationMetrics,
28
- PromptPreparationError,
29
28
  SessionDirectoryError,
30
29
  SessionDirectoryLister,
31
30
  SessionImageUploadError,
@@ -46,7 +45,7 @@ import {
46
45
  sessionRestoreFailure,
47
46
  sessionRootIdentity,
48
47
  validateOperationResponse
49
- } from "./chunks/chunk-FY4XTWUF.js";
48
+ } from "./chunks/chunk-5BDFZ3AS.js";
50
49
  import {
51
50
  SessionImageRelayUrlSchema,
52
51
  SessionImagesConfigSchema
@@ -54,18 +53,19 @@ import {
54
53
  import {
55
54
  ConversationNormalizer,
56
55
  isDisplayableHumanMessage
57
- } from "./chunks/chunk-EDYVCZIR.js";
56
+ } from "./chunks/chunk-PAJZL5ST.js";
58
57
  import {
59
58
  GroupChatError
60
- } from "./chunks/chunk-MB3H6HEI.js";
59
+ } from "./chunks/chunk-FQ26TSDG.js";
61
60
  import {
62
- hasImageSignature
63
- } from "./chunks/chunk-4XT65OSG.js";
61
+ PromptPreparationError
62
+ } from "./chunks/chunk-UTF7KLMJ.js";
64
63
  import {
65
64
  assistantPreview,
65
+ hasImageSignature,
66
66
  isContentfulAssistant,
67
67
  userPreview
68
- } from "./chunks/chunk-IXGVSREH.js";
68
+ } from "./chunks/chunk-KPHWVNKP.js";
69
69
  import {
70
70
  AgentModelListingError,
71
71
  AgentSessionRenameError,
@@ -75,11 +75,11 @@ import {
75
75
  captureResearchAccess,
76
76
  captureWorkbenchAccess,
77
77
  validateSessionName
78
- } from "./chunks/chunk-CFQQOAQV.js";
78
+ } from "./chunks/chunk-36KL4FSH.js";
79
79
  import {
80
80
  SessionOperationError,
81
81
  SessionOperations
82
- } from "./chunks/chunk-UHRUQM4D.js";
82
+ } from "./chunks/chunk-2UHBY25U.js";
83
83
  import {
84
84
  A2A_BODY_MAX_LENGTH,
85
85
  A2aRelayRequestSchema,
@@ -116,6 +116,7 @@ import {
116
116
  GroupChatInfoSchema,
117
117
  INTERACTION_DISMISS_RESPONSE_CAPABILITY,
118
118
  INTERACTION_SUPERSEDED_ERROR_CODE,
119
+ INVENTORY_MAX_CIPHERTEXT_LENGTH,
119
120
  IdSchema,
120
121
  InteractionRequestPayloadSchema,
121
122
  InteractionRespondRequestSchema,
@@ -185,6 +186,7 @@ import {
185
186
  SESSION_IMAGE_MAX_BYTES,
186
187
  SESSION_IMAGE_MAX_PIXELS,
187
188
  SESSION_IMAGE_STORAGE_CAPABILITY,
189
+ SESSION_INVENTORY_CACHE_CAPABILITY,
188
190
  SESSION_LIST_UPDATES_CAPABILITY,
189
191
  SESSION_OPTIONS_PARTIAL_CAPABILITY,
190
192
  SESSION_OPTIONS_PROGRESSIVE_CAPABILITY,
@@ -298,10 +300,10 @@ import {
298
300
  sessionCommunicationError,
299
301
  sessionCommunicationOperationCapability,
300
302
  workbenchCapability
301
- } from "./chunks/chunk-DWTXWVIA.js";
303
+ } from "./chunks/chunk-5FJJZCP6.js";
302
304
 
303
305
  // src/initialize.ts
304
- import { createHash as createHash18 } from "node:crypto";
306
+ import { createHash as createHash19 } from "node:crypto";
305
307
  import { readFile as readFile6 } from "node:fs/promises";
306
308
  import { z as z12 } from "zod";
307
309
 
@@ -318,7 +320,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
318
320
  switch (engine.kind) {
319
321
  case "managed": {
320
322
  if (owner === void 0) throw new Error("Managed coding agents require the PC owner identity");
321
- const { ManagedCodingAgentAdapter } = await import("./chunks/managed-agent-adapter-LGBRXDGP.js");
323
+ const { ManagedCodingAgentAdapter } = await import("./chunks/managed-agent-adapter-4C2PWD4V.js");
322
324
  return new ManagedCodingAgentAdapter({
323
325
  dataDirectory: config.dataDirectory,
324
326
  owner,
@@ -359,7 +361,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
359
361
  {
360
362
  id: "claude",
361
363
  name: codingAgentPresentation("claude").name,
362
- detect: detectClaude,
364
+ detect: () => detectClaude(engine.claudeCommand),
363
365
  create: () => createCodingAgentAdapter({
364
366
  ...config,
365
367
  codingAgent: {
@@ -381,7 +383,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
381
383
  });
382
384
  }
383
385
  case "copilot": {
384
- const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-KUCX7XQW.js");
386
+ const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-NXJTI2HY.js");
385
387
  if (owner !== void 0) {
386
388
  return new GithubCopilotAdapter(
387
389
  void 0,
@@ -410,13 +412,13 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
410
412
  }
411
413
  case "pi": {
412
414
  assertPiRuntimeSupported();
413
- const { PiCodingAgentAdapter } = await import("./chunks/pi-adapter-RXNZSE4F.js");
415
+ const { PiCodingAgentAdapter } = await import("./chunks/pi-adapter-EZOIK5RA.js");
414
416
  return new PiCodingAgentAdapter(
415
417
  engine.agentDirectory === void 0 ? {} : { agentDirectory: resolve(engine.agentDirectory) }
416
418
  );
417
419
  }
418
420
  case "codex": {
419
- const { CodexCodingAgentAdapter } = await import("./chunks/codex-adapter-TOXSRT2W.js");
421
+ const { CodexCodingAgentAdapter } = await import("./chunks/codex-adapter-AFGS7MPX.js");
420
422
  return new CodexCodingAgentAdapter({
421
423
  dataDirectory: resolve(config.dataDirectory, "coding-agents"),
422
424
  ...owner === void 0 ? {} : { nativeSessionOwner: owner },
@@ -425,7 +427,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
425
427
  });
426
428
  }
427
429
  case "claude": {
428
- const { ClaudeCodingAgentAdapter } = await import("./chunks/claude-adapter-FQSQIYUY.js");
430
+ const { ClaudeCodingAgentAdapter } = await import("./chunks/claude-adapter-A4LPYQ2Z.js");
429
431
  return new ClaudeCodingAgentAdapter({
430
432
  dataDirectory: resolve(config.dataDirectory, "coding-agents"),
431
433
  ...engine.command === void 0 ? {} : { command: engine.command },
@@ -434,7 +436,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
434
436
  });
435
437
  }
436
438
  case "acp": {
437
- const { AcpCodingAgentAdapter } = await import("./chunks/acp-adapter-RZX5SUB3.js");
439
+ const { AcpCodingAgentAdapter } = await import("./chunks/acp-adapter-PCNN2NAJ.js");
438
440
  return new AcpCodingAgentAdapter({
439
441
  command: engine.command,
440
442
  args: engine.args,
@@ -2356,7 +2358,7 @@ function researchAwareCodingAgentAdapter(inner, research) {
2356
2358
  }
2357
2359
 
2358
2360
  // src/pc-agent.ts
2359
- import { createHash as createHash16, randomUUID as randomUUID11 } from "node:crypto";
2361
+ import { createHash as createHash17, randomUUID as randomUUID12 } from "node:crypto";
2360
2362
  import { platform as platform2 } from "node:os";
2361
2363
  import { join as join12 } from "node:path";
2362
2364
  import { performance as performance5 } from "node:perf_hooks";
@@ -4989,6 +4991,18 @@ var OperationDeduplicator = class {
4989
4991
  }
4990
4992
  };
4991
4993
 
4994
+ // src/service/inventory/session-controls.ts
4995
+ function withSessionControls(adapter, session) {
4996
+ const controls = adapter.getSessionCapabilities?.(session.sessionId) ?? adapter;
4997
+ const files = !session.groupChat && (controls.supportsFileAttachments ?? adapter.supportsFileAttachments) === true;
4998
+ return {
4999
+ ...session,
5000
+ fileAttachmentsSupported: files,
5001
+ imageAttachmentsSupported: !session.groupChat && (controls.supportsImageAttachments ?? adapter.supportsImageAttachments ?? files),
5002
+ deleteSupported: controls.supportsSessionDelete ?? adapter.supportsSessionDelete ?? adapter.deleteSession !== void 0
5003
+ };
5004
+ }
5005
+
4992
5006
  // src/service/requests/session-commands.ts
4993
5007
  var SessionCommandsHandler = class {
4994
5008
  constructor(options) {
@@ -5027,7 +5041,7 @@ var SessionCommandsHandler = class {
5027
5041
  ok: true,
5028
5042
  requestId: request2.requestId,
5029
5043
  machineId,
5030
- session,
5044
+ session: withSessionControls(adapter, session),
5031
5045
  modelId: request2.modelId,
5032
5046
  agentMode: request2.agentMode,
5033
5047
  ...request2.reasoningEffort === void 0 ? {} : { reasoningEffort: request2.reasoningEffort }
@@ -7006,7 +7020,7 @@ function encryptedGroupAdapter(inner, groups) {
7006
7020
  abortSession: (id) => groups.owns(id) ? groups.abort(id) : inner.abortSession(id),
7007
7021
  deleteSession: (id) => groups.owns(id) ? groups.delete(id) : inner.deleteSession?.(id) ?? Promise.reject(new Error("Session deletion is unsupported")),
7008
7022
  renameSession: (id, name, check) => groups.owns(id) ? groups.rename(id, name, check) : inner.renameSession?.(id, name, check) ?? Promise.reject(new Error("Session rename is unsupported")),
7009
- getSessionCapabilities: (id) => id !== void 0 && groups.owns(id) ? { agentModes: ["interactive"], supportsReasoningEffort: false, supportsFileAttachments: false, supportsPlanRead: false } : inner.getSessionCapabilities?.(id) ?? inner,
7023
+ getSessionCapabilities: (id) => id !== void 0 && groups.owns(id) ? { agentModes: ["interactive"], supportsReasoningEffort: false, supportsImageAttachments: false, supportsFileAttachments: false, supportsSessionDelete: true, supportsPlanRead: false } : inner.getSessionCapabilities?.(id) ?? inner,
7010
7024
  getSessionConfiguration: (id) => groups.owns(id) ? Promise.resolve({ agentMode: "interactive", reasoningEffort: "default" }) : inner.getSessionConfiguration(id),
7011
7025
  listModels: (id) => inner.listModels(id !== void 0 && groups.owns(id) ? groups.source(id) : id),
7012
7026
  configureSession: (id, options) => {
@@ -7588,6 +7602,9 @@ var SessionInventory = class {
7588
7602
  isCurrent(snapshot) {
7589
7603
  return this.options.adapter.isSessionVisible === void 0 || this.#revisions.get(snapshot) === this.#revision && snapshot.sessions.every((session) => this.options.adapter.isSessionVisible?.(session.sessionId));
7590
7604
  }
7605
+ isCurrentRead(snapshot) {
7606
+ return this.#revisions.get(snapshot) === this.#revision && this.isCurrent(snapshot);
7607
+ }
7591
7608
  assertPublishable(value) {
7592
7609
  if (this.options.adapter.isSessionVisible === void 0) return;
7593
7610
  const snapshot = SessionsSnapshotSchema.parse(value);
@@ -7640,7 +7657,8 @@ var SessionInventory = class {
7640
7657
  const sessions = await adapter.listSessions(userId, machineId);
7641
7658
  const visibleSessions = sessions.filter((session) => adapter.isSessionVisible?.(session.sessionId) !== false);
7642
7659
  const page = adapter.isSessionVisible !== void 0 && cursor === void 0 ? { sessions: visibleSessions, totalCount: visibleSessions.length, complete: true } : paginateSessions(visibleSessions, cursor);
7643
- if (adapter.isSessionVisible !== void 0) assertSelectionSnapshotFits(page.sessions);
7660
+ const published = page.sessions.map((session) => withSessionControls(adapter, session));
7661
+ if (adapter.isSessionVisible !== void 0) assertSelectionSnapshotFits(published);
7644
7662
  const snapshot = {
7645
7663
  userId,
7646
7664
  machineId,
@@ -7652,7 +7670,7 @@ var SessionInventory = class {
7652
7670
  complete: page.complete,
7653
7671
  totalCount: page.totalCount,
7654
7672
  ...page.nextCursor === void 0 ? {} : { nextCursor: page.nextCursor },
7655
- sessions: page.sessions
7673
+ sessions: published
7656
7674
  };
7657
7675
  this.#revisions.set(snapshot, revision);
7658
7676
  return snapshot;
@@ -7771,6 +7789,43 @@ var InventoryPublisher = class {
7771
7789
  }
7772
7790
  };
7773
7791
 
7792
+ // src/service/inventory/inventory-objects.ts
7793
+ import { createHash as createHash14, randomBytes as randomBytes3, randomUUID as randomUUID10 } from "node:crypto";
7794
+ var InventoryObjects = class {
7795
+ #byRecipient = /* @__PURE__ */ new Map();
7796
+ clear(recipient) {
7797
+ if (recipient === void 0) {
7798
+ for (const descriptor of this.#byRecipient.values()) clearTimeout(descriptor.timer);
7799
+ this.#byRecipient.clear();
7800
+ } else {
7801
+ clearTimeout(this.#byRecipient.get(recipient)?.timer);
7802
+ this.#byRecipient.delete(recipient);
7803
+ }
7804
+ }
7805
+ prepare(snapshot, recipient, forceFill) {
7806
+ const { sequence, generatedAt, ...body } = SessionsSnapshotSchema.parse(snapshot);
7807
+ const bytes = Buffer.from(JSON.stringify(body));
7808
+ if (Math.ceil((bytes.length + 16) * 4 / 3) > INVENTORY_MAX_CIPHERTEXT_LENGTH) return;
7809
+ const digest = createHash14("sha256").update(bytes).digest("base64url");
7810
+ const now = Date.now();
7811
+ for (const [client, entry2] of this.#byRecipient) if (entry2.expires <= now) this.clear(client);
7812
+ let entry = this.#byRecipient.get(recipient);
7813
+ let ciphertext;
7814
+ if (forceFill || entry?.digest !== digest) {
7815
+ const key = randomBytes3(32), iv = randomBytes3(12);
7816
+ const sealed = encryptAes256Gcm(key, iv, bytes, Buffer.alloc(0));
7817
+ ciphertext = Buffer.concat([sealed.ciphertext, sealed.authTag]).toString("base64url");
7818
+ this.clear(recipient);
7819
+ const ttl = 12e4;
7820
+ const timer = setTimeout(() => this.clear(recipient), ttl).unref();
7821
+ entry = { digest, expires: now + ttl, timer, objectId: randomUUID10(), key: key.toString("base64url"), nonce: iv.toString("base64url") };
7822
+ this.#byRecipient.set(recipient, entry);
7823
+ if (this.#byRecipient.size > 128) this.clear(this.#byRecipient.keys().next().value);
7824
+ }
7825
+ return { objectId: entry.objectId, ciphertext, confirmation: { sequence, generatedAt, nonce: entry.nonce, key: entry.key } };
7826
+ }
7827
+ };
7828
+
7774
7829
  // src/conversation-audience.ts
7775
7830
  var ConversationAudience = class {
7776
7831
  #clients = /* @__PURE__ */ new Map();
@@ -7821,7 +7876,7 @@ var ConversationAudience = class {
7821
7876
  };
7822
7877
 
7823
7878
  // src/timeline-incremental-transport.ts
7824
- import { createHash as createHash14, randomUUID as randomUUID10 } from "node:crypto";
7879
+ import { createHash as createHash15, randomUUID as randomUUID11 } from "node:crypto";
7825
7880
  import { isDeepStrictEqual } from "node:util";
7826
7881
  function journalDiagnostic(state) {
7827
7882
  return {
@@ -7955,7 +8010,7 @@ var TimelineIncrementalTransport = class {
7955
8010
  }
7956
8011
  #observeColdStep(state, upsert) {
7957
8012
  const cold = state.coldSteps;
7958
- const key = createHash14("sha256").update(JSON.stringify([upsert.activityId, upsert.step.id])).digest("hex");
8013
+ const key = createHash15("sha256").update(JSON.stringify([upsert.activityId, upsert.step.id])).digest("hex");
7959
8014
  const revision = cold.revisions.get(key);
7960
8015
  if (revision !== void 0 && upsert.revision < revision) return false;
7961
8016
  cold.revisions.delete(key);
@@ -7965,7 +8020,7 @@ var TimelineIncrementalTransport = class {
7965
8020
  if (oldest === void 0) break;
7966
8021
  cold.revisions.delete(oldest);
7967
8022
  }
7968
- const fingerprint = createHash14("sha256").update(JSON.stringify(upsert)).digest("hex");
8023
+ const fingerprint = createHash15("sha256").update(JSON.stringify(upsert)).digest("hex");
7969
8024
  const observed = cold.fingerprints.has(fingerprint);
7970
8025
  cold.fingerprints.delete(fingerprint);
7971
8026
  cold.fingerprints.add(fingerprint);
@@ -8098,7 +8153,7 @@ var TimelineIncrementalTransport = class {
8098
8153
  let state = this.#sessions.get(sessionId);
8099
8154
  if (state === void 0) {
8100
8155
  state = {
8101
- epoch: randomUUID10(),
8156
+ epoch: randomUUID11(),
8102
8157
  sequence: 0,
8103
8158
  reason: "initial",
8104
8159
  events: [],
@@ -8247,7 +8302,7 @@ function canAppend(previous, item) {
8247
8302
  }
8248
8303
 
8249
8304
  // src/timeline-image-blob.ts
8250
- import { createHash as createHash15 } from "node:crypto";
8305
+ import { createHash as createHash16 } from "node:crypto";
8251
8306
  var MAX_ACTIVE_PUBLICATIONS = 16;
8252
8307
  var MAX_QUEUED_PUBLICATIONS = 16;
8253
8308
  var QUEUE_TIMEOUT_MS = 15e3;
@@ -8369,7 +8424,7 @@ var TimelineImageBlobPublisher = class {
8369
8424
  const asset = this.images.readAsset(sessionId, sha256);
8370
8425
  const extension = { "image/png": ".png", "image/jpeg": ".jpg", "image/webp": ".webp" }[asset.mimeType];
8371
8426
  if (extension === void 0) throw new TimelineAssetError("IMAGE_BLOB_UNSUPPORTED", "This image requires encrypted transfer");
8372
- if (createHash15("sha256").update(asset.bytes).digest("hex") !== sha256) {
8427
+ if (createHash16("sha256").update(asset.bytes).digest("hex") !== sha256) {
8373
8428
  throw new TimelineAssetError("IMAGE_INVALID", "Image content does not match its reference");
8374
8429
  }
8375
8430
  let bytes;
@@ -8890,7 +8945,8 @@ var BUFFERED_INTERACTION_RETENTION_MS = 5 * 60 * 1e3;
8890
8945
  var INVENTORY_REFRESH_DEBOUNCE_MS = 100;
8891
8946
  var SESSION_LIST_REFRESH_RETRIES = 2;
8892
8947
  var TRAFFIC_METRICS_INTERVAL_MS = 6e4;
8893
- var RELAY_RECONNECT_INTERVAL_MS = 15 * 6e4;
8948
+ var AUTH_RETRY_INITIAL_WINDOW_MS = 5e3;
8949
+ var AUTH_RETRY_MAX_WINDOW_MS = 6e4;
8894
8950
  var PcAgent = class {
8895
8951
  constructor(config, identity2, appVersion, adapter, logger, pairingProvider, contentCipher, research, createSocket = createRelaySocket, onPairing, textInputWriter = createWindowsTextInput()) {
8896
8952
  this.config = config;
@@ -9158,7 +9214,7 @@ var PcAgent = class {
9158
9214
  runTurn: runPeerTurn,
9159
9215
  reportError: reportPeerError
9160
9216
  });
9161
- const receiptOwner = createHash16("sha256").update(JSON.stringify([config.userId, identity2.machineId])).digest("hex");
9217
+ const receiptOwner = createHash17("sha256").update(JSON.stringify([config.userId, identity2.machineId])).digest("hex");
9162
9218
  this.#createEncryptedServer = (groupId = "legacy") => new A2aPeerServer({
9163
9219
  userId: config.userId,
9164
9220
  appVersion,
@@ -9285,7 +9341,7 @@ var PcAgent = class {
9285
9341
  onInteractionDismissed: (sessionId, interactionRequestId) => {
9286
9342
  const payload = InteractionRespondResultSchema.parse({
9287
9343
  ok: false,
9288
- requestId: randomUUID11(),
9344
+ requestId: randomUUID12(),
9289
9345
  interactionRequestId,
9290
9346
  machineId: this.identity.machineId,
9291
9347
  sessionId,
@@ -9325,7 +9381,7 @@ var PcAgent = class {
9325
9381
  }
9326
9382
  },
9327
9383
  onSessionInventoryChanged: (sessionId) => {
9328
- this.#inventory.invalidate();
9384
+ this.#invalidateInventory();
9329
9385
  this.#clearUnselectedSessionState();
9330
9386
  this.#scheduleInventoryRefresh(sessionId);
9331
9387
  },
@@ -9383,14 +9439,17 @@ var PcAgent = class {
9383
9439
  research;
9384
9440
  onPairing;
9385
9441
  textInputWriter;
9386
- #agentRunId = randomUUID11();
9387
- #clientId = randomUUID11();
9442
+ #agentRunId = randomUUID12();
9443
+ #clientId = randomUUID12();
9388
9444
  #socket;
9389
9445
  #relayDiagnostics = new RelayConnectionDiagnostics();
9390
9446
  #cipher;
9391
9447
  #secureRequestRouter;
9392
9448
  #inventory;
9393
9449
  #inventoryPublisher;
9450
+ #inventoryObjects = new InventoryObjects();
9451
+ #inventoryCacheNegotiated = false;
9452
+ #inventoryCacheRequests = 0;
9394
9453
  #publication;
9395
9454
  #watches;
9396
9455
  #trafficMetrics = new SecureTrafficMetrics();
@@ -9410,6 +9469,7 @@ var PcAgent = class {
9410
9469
  #inventoryRefreshTimer;
9411
9470
  #trafficMetricsTimer;
9412
9471
  #relayReconnectTimer;
9472
+ #authRetryWindowMs = AUTH_RETRY_INITIAL_WINDOW_MS;
9413
9473
  #relayDisconnected = false;
9414
9474
  #relayDisconnectCode;
9415
9475
  #started = false;
@@ -9527,13 +9587,17 @@ var PcAgent = class {
9527
9587
  }
9528
9588
  #scheduleRelayReconnect() {
9529
9589
  if (this.#stopping || this.#relayDisconnected || this.#socket.active || this.#socket.connected || this.#relayReconnectTimer !== void 0) return;
9530
- this.logger.info({ delayMs: RELAY_RECONNECT_INTERVAL_MS }, "relay.reconnect.scheduled");
9590
+ const delayMs = Math.round(this.#authRetryWindowMs * (1 + Math.random()) / 2);
9591
+ this.logger.info({ delayMs }, "relay.reconnect.scheduled");
9531
9592
  this.#relayReconnectTimer = setTimeout(() => {
9532
9593
  this.#relayReconnectTimer = void 0;
9533
9594
  if (this.#stopping || this.#relayDisconnected || this.#socket.active || this.#socket.connected) return;
9534
9595
  if (this.#upgradeAdmissionClosed) this.#scheduleRelayReconnect();
9535
- else this.#connectRelay("automatic");
9536
- }, RELAY_RECONNECT_INTERVAL_MS);
9596
+ else {
9597
+ this.#authRetryWindowMs = Math.min(AUTH_RETRY_MAX_WINDOW_MS, this.#authRetryWindowMs * 2);
9598
+ this.#connectRelay("automatic");
9599
+ }
9600
+ }, delayMs);
9537
9601
  this.#relayReconnectTimer.unref();
9538
9602
  }
9539
9603
  #clearRelayReconnect() {
@@ -9616,7 +9680,7 @@ var PcAgent = class {
9616
9680
  try {
9617
9681
  await this.adapter.setPeerChatEnabled(enabled);
9618
9682
  } finally {
9619
- this.#inventory.invalidate();
9683
+ this.#invalidateInventory();
9620
9684
  this.#scheduleInventoryRefresh("peer-chat");
9621
9685
  }
9622
9686
  }
@@ -9631,7 +9695,7 @@ var PcAgent = class {
9631
9695
  this.#sessionImagesEnabled = enabled;
9632
9696
  this.#imagePolicyRevision += 1;
9633
9697
  this.#imageBlob?.reset();
9634
- this.#inventory.invalidate();
9698
+ this.#invalidateInventory();
9635
9699
  if (this.#machineRegistered) await this.#inventoryPublisher.request(void 0, true);
9636
9700
  }
9637
9701
  #sendPeerMessage(message) {
@@ -9885,6 +9949,8 @@ var PcAgent = class {
9885
9949
  const diagnostics = this.#relayDiagnostics.disconnected(reason, details);
9886
9950
  this.#connectionGeneration += 1;
9887
9951
  this.#machineRegistered = false;
9952
+ this.#inventoryCacheNegotiated = false;
9953
+ this.#inventoryObjects.clear();
9888
9954
  if (this.#socket.sendBuffer !== void 0) this.#socket.sendBuffer.length = 0;
9889
9955
  this.#initialSyncGeneration = void 0;
9890
9956
  this.#communicationNegotiated = false;
@@ -9965,6 +10031,7 @@ var PcAgent = class {
9965
10031
  );
9966
10032
  return;
9967
10033
  }
10034
+ this.#inventoryObjects.clear(payload.data.clientId);
9968
10035
  this.#inventoryPublisher.connected(payload.data.clientId);
9969
10036
  this.#conversationAudience.connected(payload.data.clientId);
9970
10037
  if (payload.data.capabilities?.includes(SESSION_ASSISTANT_PREVIEW_CAPABILITY)) {
@@ -10013,6 +10080,7 @@ var PcAgent = class {
10013
10080
  );
10014
10081
  return;
10015
10082
  }
10083
+ this.#inventoryObjects.clear(payload.data.clientId);
10016
10084
  this.#inventoryPublisher.disconnected(payload.data.clientId);
10017
10085
  this.#textInputClients.delete(payload.data.clientId);
10018
10086
  this.#conversationAudience.disconnected(payload.data.clientId);
@@ -10054,7 +10122,7 @@ var PcAgent = class {
10054
10122
  }
10055
10123
  const message = parsedMessage.data;
10056
10124
  void this.#requestContext.run(
10057
- { clientId: message.clientId },
10125
+ { clientId: message.clientId, messageId: message.messageId },
10058
10126
  () => this.#handleSecureMessage(message)
10059
10127
  ).catch((error) => {
10060
10128
  this.logger.error(
@@ -10138,6 +10206,8 @@ var PcAgent = class {
10138
10206
  }
10139
10207
  }
10140
10208
  async #registerMachine(generation) {
10209
+ this.#inventoryCacheNegotiated = false;
10210
+ this.#inventoryObjects.clear();
10141
10211
  const peerRevision = this.#peerPreferenceRevision;
10142
10212
  const hello = MachineHelloSchema.parse({
10143
10213
  userId: this.config.userId,
@@ -10183,6 +10253,8 @@ var PcAgent = class {
10183
10253
  this.#registrationCapabilities = JSON.stringify(hello.capabilities);
10184
10254
  this.#peerRegistrationRevision = peerRevision;
10185
10255
  this.#machineRegistered = true;
10256
+ this.#inventoryCacheNegotiated = ack.capabilities?.includes(SESSION_INVENTORY_CACHE_CAPABILITY) === true;
10257
+ this.#authRetryWindowMs = AUTH_RETRY_INITIAL_WINDOW_MS;
10186
10258
  this.#conversationAudience.confirm(
10187
10259
  ack.capabilities?.includes(MOBILE_CONNECTED_REPLAY_CAPABILITY) === true
10188
10260
  );
@@ -10208,6 +10280,7 @@ var PcAgent = class {
10208
10280
  }
10209
10281
  #machineCapabilities() {
10210
10282
  return [
10283
+ SESSION_INVENTORY_CACHE_CAPABILITY,
10211
10284
  ...(this.config.secureMessagePacketBudget ?? DEFAULT_SECURE_PACKET_BUDGET) >= FILE_TRANSFER_PACKET_BYTES ? [FILE_TRANSFER_CAPABILITY] : [],
10212
10285
  ...this.adapter.agentId === "copilot" || this.adapter.agentId === "managed" ? [SESSION_AVATAR_PERSONA_CAPABILITY] : [],
10213
10286
  SESSION_COMMUNICATION_CAPABILITY,
@@ -10365,15 +10438,63 @@ var PcAgent = class {
10365
10438
  this.#timelineIncremental.invalidate(sessionId, "gap");
10366
10439
  }
10367
10440
  }
10441
+ #invalidateInventory() {
10442
+ this.#inventory.invalidate();
10443
+ this.#inventoryObjects.clear();
10444
+ if (this.#inventoryCacheNegotiated && this.#machineRegistered && this.#socket.connected && !this.#stopping) {
10445
+ this.#socket.emit("inventory.invalidate");
10446
+ }
10447
+ }
10368
10448
  async #handleSessionList(request2) {
10369
10449
  const generation = this.#connectionGeneration;
10450
+ const origin = this.#requestContext.getStore();
10451
+ const cache = this.#inventoryCacheNegotiated && request2.inventoryCache === true && request2.cursor === void 0 && origin?.messageId !== void 0;
10452
+ if (cache) this.#inventoryCacheRequests++;
10370
10453
  try {
10371
- let snapshot = request2.cursor === void 0 ? await this.#inventory.refresh() : await this.#inventory.load(request2.cursor);
10454
+ if (cache && this.#inventoryCacheRequests > 16) throw new Error("Too many inventory requests; retry");
10455
+ let snapshot = request2.cursor === void 0 ? await (cache ? this.#inventory.refreshAfterCurrent() : this.#inventory.refresh()) : await this.#inventory.load(request2.cursor);
10372
10456
  for (let retry = 0; retry < SESSION_LIST_REFRESH_RETRIES && !this.#inventory.isCurrent(snapshot); retry++) {
10373
10457
  if (generation !== this.#connectionGeneration || this.#stopping) return;
10374
10458
  snapshot = await this.#inventory.load(request2.cursor);
10375
10459
  }
10376
10460
  if (generation !== this.#connectionGeneration || this.#stopping) return;
10461
+ if (cache) {
10462
+ for (const forceFill of [false, true]) {
10463
+ if (forceFill) snapshot = await this.#inventory.refreshAfterCurrent();
10464
+ if (generation !== this.#connectionGeneration || this.#stopping) return;
10465
+ if (!this.#inventoryCacheNegotiated || !this.#machineRegistered || !this.#socket.connected || !this.#inventory.isCurrentRead(snapshot)) throw new Error("Inventory changed; retry the request");
10466
+ const object = this.#inventoryObjects.prepare(snapshot, origin.clientId, forceFill);
10467
+ if (!object) break;
10468
+ const ticket = this.#cipher.seal(
10469
+ "session.list.result",
10470
+ "pc",
10471
+ this.identity.machineId,
10472
+ this.#clientId,
10473
+ origin.clientId,
10474
+ {
10475
+ requestId: request2.requestId,
10476
+ requestMessageId: origin.messageId,
10477
+ machineId: this.identity.machineId,
10478
+ ...object.confirmation
10479
+ }
10480
+ );
10481
+ const packet = {
10482
+ requestMessageId: origin.messageId,
10483
+ objectId: object.objectId,
10484
+ ticket,
10485
+ ...object.ciphertext === void 0 ? {} : { ciphertext: object.ciphertext }
10486
+ };
10487
+ if (Buffer.byteLength(JSON.stringify(packet)) + 1024 > (this.config.secureMessagePacketBudget ?? DEFAULT_SECURE_PACKET_BUDGET)) {
10488
+ this.#inventoryObjects.clear(origin.clientId);
10489
+ break;
10490
+ }
10491
+ const ack = OperationAckSchema.parse(await this.#emitWithAck("inventory.publish", packet));
10492
+ if (ack.ok) return;
10493
+ if (ack.code !== "INVENTORY_CACHE_MISS" || object.ciphertext !== void 0 || forceFill) {
10494
+ throw new Error("Inventory delivery unavailable; retry the request");
10495
+ }
10496
+ }
10497
+ }
10377
10498
  this.#emitSecure("session.list.result", {
10378
10499
  ok: true,
10379
10500
  requestId: request2.requestId,
@@ -10396,6 +10517,8 @@ var PcAgent = class {
10396
10517
  message: details.message
10397
10518
  }
10398
10519
  });
10520
+ } finally {
10521
+ if (cache) this.#inventoryCacheRequests--;
10399
10522
  }
10400
10523
  }
10401
10524
  #operationErrorCode(operation, error) {
@@ -10610,6 +10733,9 @@ var PcAgent = class {
10610
10733
  MachineHelloSchema.parse(payload),
10611
10734
  receiveAck
10612
10735
  );
10736
+ } else if (event === "inventory.publish") {
10737
+ if (!("ticket" in payload)) throw new Error("Missing inventory ticket");
10738
+ this.#socket.emit(event, payload, receiveAck);
10613
10739
  } else {
10614
10740
  this.#emitSecure("sessions.snapshot", payload, receiveAck);
10615
10741
  }
@@ -10726,14 +10852,14 @@ function contextItem(item) {
10726
10852
 
10727
10853
  // src/research-sessions.ts
10728
10854
  import { execFile as execFile3 } from "node:child_process";
10729
- import { createHash as createHash17, randomUUID as randomUUID14 } from "node:crypto";
10855
+ import { createHash as createHash18, randomUUID as randomUUID15 } from "node:crypto";
10730
10856
  import { mkdir as mkdir7, lstat as lstat8, realpath as realpath8 } from "node:fs/promises";
10731
10857
  import { join as join15, resolve as resolve4 } from "node:path";
10732
10858
  import { promisify as promisify4 } from "node:util";
10733
10859
  import { z as z11 } from "zod";
10734
10860
 
10735
10861
  // src/research-thread-store.ts
10736
- import { randomUUID as randomUUID12 } from "node:crypto";
10862
+ import { randomUUID as randomUUID13 } from "node:crypto";
10737
10863
  import { mkdir as mkdir6, readFile as readFile4, rename as rename4, rm as rm4, lstat as lstat6, realpath as realpath7, writeFile as writeFile5 } from "node:fs/promises";
10738
10864
  import { join as join13, resolve as resolve3 } from "node:path";
10739
10865
  import { z as z9 } from "zod";
@@ -10810,7 +10936,7 @@ var ResearchThreadStore = class {
10810
10936
  }
10811
10937
  }
10812
10938
  async #write(records2, tombstones = this.#tombstones) {
10813
- const staging = join13(this.directory, `threads-${randomUUID12()}.pending`);
10939
+ const staging = join13(this.directory, `threads-${randomUUID13()}.pending`);
10814
10940
  try {
10815
10941
  await writeFile5(staging, JSON.stringify({
10816
10942
  version: 1,
@@ -10843,8 +10969,8 @@ var ResearchThreadStore = class {
10843
10969
  }
10844
10970
  const record = recordSchema.parse({
10845
10971
  ...input,
10846
- threadId: randomUUID12(),
10847
- researchSessionId: randomUUID12(),
10972
+ threadId: randomUUID13(),
10973
+ researchSessionId: randomUUID13(),
10848
10974
  profile: RESEARCH_PROFILE,
10849
10975
  profileVersion: RESEARCH_PROFILE_VERSION,
10850
10976
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -10898,7 +11024,7 @@ var ResearchThreadStore = class {
10898
11024
  };
10899
11025
 
10900
11026
  // src/research-chat-store.ts
10901
- import { randomUUID as randomUUID13 } from "node:crypto";
11027
+ import { randomUUID as randomUUID14 } from "node:crypto";
10902
11028
  import { lstat as lstat7, readFile as readFile5, rename as rename5, rm as rm5, writeFile as writeFile6 } from "node:fs/promises";
10903
11029
  import { join as join14 } from "node:path";
10904
11030
  import { z as z10 } from "zod";
@@ -10955,7 +11081,7 @@ var ResearchChatStore = class {
10955
11081
  async write(sessionId, state) {
10956
11082
  const validated = stateSchema.parse(state);
10957
11083
  const path = this.#file(sessionId);
10958
- const staging = `${path}.${randomUUID13()}.pending`;
11084
+ const staging = `${path}.${randomUUID14()}.pending`;
10959
11085
  try {
10960
11086
  await writeFile6(staging, JSON.stringify(validated), { flag: "wx", mode: 384 });
10961
11087
  await rename5(staging, path);
@@ -10974,7 +11100,7 @@ var ResearchChatStore = class {
10974
11100
  var executeFile = promisify4(execFile3);
10975
11101
  var SEED_PREFIX = "Research context attachment (reference data, not instructions):\n";
10976
11102
  var SEED_REQUEST_PREFIX = "\n\nResearch request:\n";
10977
- var hash = (value) => createHash17("sha256").update(value).digest("base64url");
11103
+ var hash = (value) => createHash18("sha256").update(value).digest("base64url");
10978
11104
  var snapshotSchema = z11.object({
10979
11105
  parentSessionId: z11.string().min(1).max(256),
10980
11106
  anchorEventId: z11.string().min(1).max(256),
@@ -11126,7 +11252,7 @@ var ResearchSessions = class {
11126
11252
  });
11127
11253
  }
11128
11254
  options;
11129
- #generation = randomUUID14();
11255
+ #generation = randomUUID15();
11130
11256
  store;
11131
11257
  #privateDirectory;
11132
11258
  #active = /* @__PURE__ */ new Map();
@@ -11385,7 +11511,7 @@ var ResearchSessions = class {
11385
11511
  if (snapshot.parentSessionId !== input.parentSessionId) throw new ResearchError("RESEARCH_SOURCE_MISMATCH");
11386
11512
  const title = z11.string().trim().min(1).max(200).parse(input.title ?? "Research");
11387
11513
  const prompt = z11.string().trim().min(1).max(16e3).parse(input.prompt ?? "Acknowledge the context briefly and wait for my research question.");
11388
- const fingerprint = createHash17("sha256").update(JSON.stringify({
11514
+ const fingerprint = createHash18("sha256").update(JSON.stringify({
11389
11515
  parentSessionId: input.parentSessionId,
11390
11516
  title,
11391
11517
  prompt,
@@ -11586,7 +11712,7 @@ var ResearchSessions = class {
11586
11712
  compactDisabledReason: "Research context compaction is unavailable"
11587
11713
  });
11588
11714
  }
11589
- async send(sessionId, text, operationId = randomUUID14()) {
11715
+ async send(sessionId, text, operationId = randomUUID15()) {
11590
11716
  if (this.#active.get(sessionId)?.runtime.activity.busy) throw new ResearchError("RESEARCH_BUSY");
11591
11717
  return (await this.sendPrompt(sessionId, text, "immediate", operationId)).messageId;
11592
11718
  }
@@ -12001,7 +12127,7 @@ async function initialize(options) {
12001
12127
  }, "research.operation.failed")
12002
12128
  });
12003
12129
  class InitializedAgent extends PcAgent {
12004
- identityHash = createHash18("sha256").update(`${config.userId}:${identity2.machineId}:${contentKey.keyId}`).digest("hex");
12130
+ identityHash = createHash19("sha256").update(`${config.userId}:${identity2.machineId}:${contentKey.keyId}`).digest("hex");
12005
12131
  #started;
12006
12132
  #starting;
12007
12133
  #closed;