@agentknight/sdk 0.9.69 → 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 (28) hide show
  1. package/dist/chunks/{acp-adapter-VJ2OUSBS.js → acp-adapter-PCNN2NAJ.js} +7 -7
  2. package/dist/chunks/{chunk-LA6A4TUM.js → chunk-23BKGY5J.js} +4 -4
  3. package/dist/chunks/{chunk-J63A5OLO.js → chunk-2UHBY25U.js} +1 -1
  4. package/dist/chunks/{chunk-IRYEOV62.js → chunk-36KL4FSH.js} +2 -2
  5. package/dist/chunks/{chunk-2D34UDII.js → chunk-5BDFZ3AS.js} +4 -4
  6. package/dist/chunks/{chunk-F5YCEWE4.js → chunk-5FJJZCP6.js} +680 -629
  7. package/dist/chunks/{chunk-ES2N66EH.js → chunk-DXHAKWGO.js} +2 -2
  8. package/dist/chunks/{chunk-35OF2ZNS.js → chunk-E5VHBC55.js} +14 -0
  9. package/dist/chunks/{chunk-Q5NNNSU2.js → chunk-FQ26TSDG.js} +2 -2
  10. package/dist/chunks/{chunk-MH7FDSTY.js → chunk-GRUDMHEJ.js} +1 -1
  11. package/dist/chunks/{chunk-5QYL6NKJ.js → chunk-I42IONUU.js} +1 -1
  12. package/dist/chunks/{chunk-WAPJZKUK.js → chunk-KPHWVNKP.js} +1 -1
  13. package/dist/chunks/{chunk-LU73CEHE.js → chunk-PAJZL5ST.js} +7 -2
  14. package/dist/chunks/{chunk-ZAU2MYQI.js → chunk-TFUSRA2B.js} +2 -2
  15. package/dist/chunks/chunk-VEJLENEQ.js +174 -0
  16. package/dist/chunks/{chunk-MB34W52S.js → chunk-VOR4AECB.js} +3 -3
  17. package/dist/chunks/{claude-adapter-FZNLF5XN.js → claude-adapter-A4LPYQ2Z.js} +71 -211
  18. package/dist/chunks/{codex-adapter-5ZVOAT6O.js → codex-adapter-AFGS7MPX.js} +7 -7
  19. package/dist/chunks/{copilot-adapter-V6RAQ4WK.js → copilot-adapter-NXJTI2HY.js} +24 -68
  20. package/dist/chunks/{managed-agent-adapter-THUSTKRW.js → managed-agent-adapter-4C2PWD4V.js} +6 -6
  21. package/dist/chunks/{pi-adapter-EHCSR5I2.js → pi-adapter-EZOIK5RA.js} +6 -6
  22. package/dist/configuration.js +4 -4
  23. package/dist/index.d.ts +138 -0
  24. package/dist/index.js +163 -50
  25. package/dist/runtime.js +2 -2
  26. package/dist/session-analytics-worker.js +6 -6
  27. package/package.json +4 -5
  28. 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-MH7FDSTY.js";
13
+ } from "./chunks/chunk-GRUDMHEJ.js";
14
14
  import {
15
15
  DeviceIdentitySchema,
16
16
  codingAgentPresentation,
@@ -20,7 +20,7 @@ import {
20
20
  AgentSelectionSchema,
21
21
  assertSelectionSnapshotFits,
22
22
  supportsAgentSelection
23
- } from "./chunks/chunk-ZAU2MYQI.js";
23
+ } from "./chunks/chunk-TFUSRA2B.js";
24
24
  import {
25
25
  LiveTimelineProjection,
26
26
  OperationDiagnostics,
@@ -45,7 +45,7 @@ import {
45
45
  sessionRestoreFailure,
46
46
  sessionRootIdentity,
47
47
  validateOperationResponse
48
- } from "./chunks/chunk-2D34UDII.js";
48
+ } from "./chunks/chunk-5BDFZ3AS.js";
49
49
  import {
50
50
  SessionImageRelayUrlSchema,
51
51
  SessionImagesConfigSchema
@@ -53,10 +53,10 @@ import {
53
53
  import {
54
54
  ConversationNormalizer,
55
55
  isDisplayableHumanMessage
56
- } from "./chunks/chunk-LU73CEHE.js";
56
+ } from "./chunks/chunk-PAJZL5ST.js";
57
57
  import {
58
58
  GroupChatError
59
- } from "./chunks/chunk-Q5NNNSU2.js";
59
+ } from "./chunks/chunk-FQ26TSDG.js";
60
60
  import {
61
61
  PromptPreparationError
62
62
  } from "./chunks/chunk-UTF7KLMJ.js";
@@ -65,7 +65,7 @@ import {
65
65
  hasImageSignature,
66
66
  isContentfulAssistant,
67
67
  userPreview
68
- } from "./chunks/chunk-WAPJZKUK.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-IRYEOV62.js";
78
+ } from "./chunks/chunk-36KL4FSH.js";
79
79
  import {
80
80
  SessionOperationError,
81
81
  SessionOperations
82
- } from "./chunks/chunk-J63A5OLO.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-F5YCEWE4.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-THUSTKRW.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-V6RAQ4WK.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-EHCSR5I2.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-5ZVOAT6O.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-FZNLF5XN.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-VJ2OUSBS.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";
@@ -7600,6 +7602,9 @@ var SessionInventory = class {
7600
7602
  isCurrent(snapshot) {
7601
7603
  return this.options.adapter.isSessionVisible === void 0 || this.#revisions.get(snapshot) === this.#revision && snapshot.sessions.every((session) => this.options.adapter.isSessionVisible?.(session.sessionId));
7602
7604
  }
7605
+ isCurrentRead(snapshot) {
7606
+ return this.#revisions.get(snapshot) === this.#revision && this.isCurrent(snapshot);
7607
+ }
7603
7608
  assertPublishable(value) {
7604
7609
  if (this.options.adapter.isSessionVisible === void 0) return;
7605
7610
  const snapshot = SessionsSnapshotSchema.parse(value);
@@ -7784,6 +7789,43 @@ var InventoryPublisher = class {
7784
7789
  }
7785
7790
  };
7786
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
+
7787
7829
  // src/conversation-audience.ts
7788
7830
  var ConversationAudience = class {
7789
7831
  #clients = /* @__PURE__ */ new Map();
@@ -7834,7 +7876,7 @@ var ConversationAudience = class {
7834
7876
  };
7835
7877
 
7836
7878
  // src/timeline-incremental-transport.ts
7837
- import { createHash as createHash14, randomUUID as randomUUID10 } from "node:crypto";
7879
+ import { createHash as createHash15, randomUUID as randomUUID11 } from "node:crypto";
7838
7880
  import { isDeepStrictEqual } from "node:util";
7839
7881
  function journalDiagnostic(state) {
7840
7882
  return {
@@ -7968,7 +8010,7 @@ var TimelineIncrementalTransport = class {
7968
8010
  }
7969
8011
  #observeColdStep(state, upsert) {
7970
8012
  const cold = state.coldSteps;
7971
- 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");
7972
8014
  const revision = cold.revisions.get(key);
7973
8015
  if (revision !== void 0 && upsert.revision < revision) return false;
7974
8016
  cold.revisions.delete(key);
@@ -7978,7 +8020,7 @@ var TimelineIncrementalTransport = class {
7978
8020
  if (oldest === void 0) break;
7979
8021
  cold.revisions.delete(oldest);
7980
8022
  }
7981
- const fingerprint = createHash14("sha256").update(JSON.stringify(upsert)).digest("hex");
8023
+ const fingerprint = createHash15("sha256").update(JSON.stringify(upsert)).digest("hex");
7982
8024
  const observed = cold.fingerprints.has(fingerprint);
7983
8025
  cold.fingerprints.delete(fingerprint);
7984
8026
  cold.fingerprints.add(fingerprint);
@@ -8111,7 +8153,7 @@ var TimelineIncrementalTransport = class {
8111
8153
  let state = this.#sessions.get(sessionId);
8112
8154
  if (state === void 0) {
8113
8155
  state = {
8114
- epoch: randomUUID10(),
8156
+ epoch: randomUUID11(),
8115
8157
  sequence: 0,
8116
8158
  reason: "initial",
8117
8159
  events: [],
@@ -8260,7 +8302,7 @@ function canAppend(previous, item) {
8260
8302
  }
8261
8303
 
8262
8304
  // src/timeline-image-blob.ts
8263
- import { createHash as createHash15 } from "node:crypto";
8305
+ import { createHash as createHash16 } from "node:crypto";
8264
8306
  var MAX_ACTIVE_PUBLICATIONS = 16;
8265
8307
  var MAX_QUEUED_PUBLICATIONS = 16;
8266
8308
  var QUEUE_TIMEOUT_MS = 15e3;
@@ -8382,7 +8424,7 @@ var TimelineImageBlobPublisher = class {
8382
8424
  const asset = this.images.readAsset(sessionId, sha256);
8383
8425
  const extension = { "image/png": ".png", "image/jpeg": ".jpg", "image/webp": ".webp" }[asset.mimeType];
8384
8426
  if (extension === void 0) throw new TimelineAssetError("IMAGE_BLOB_UNSUPPORTED", "This image requires encrypted transfer");
8385
- if (createHash15("sha256").update(asset.bytes).digest("hex") !== sha256) {
8427
+ if (createHash16("sha256").update(asset.bytes).digest("hex") !== sha256) {
8386
8428
  throw new TimelineAssetError("IMAGE_INVALID", "Image content does not match its reference");
8387
8429
  }
8388
8430
  let bytes;
@@ -8903,7 +8945,8 @@ var BUFFERED_INTERACTION_RETENTION_MS = 5 * 60 * 1e3;
8903
8945
  var INVENTORY_REFRESH_DEBOUNCE_MS = 100;
8904
8946
  var SESSION_LIST_REFRESH_RETRIES = 2;
8905
8947
  var TRAFFIC_METRICS_INTERVAL_MS = 6e4;
8906
- var RELAY_RECONNECT_INTERVAL_MS = 15 * 6e4;
8948
+ var AUTH_RETRY_INITIAL_WINDOW_MS = 5e3;
8949
+ var AUTH_RETRY_MAX_WINDOW_MS = 6e4;
8907
8950
  var PcAgent = class {
8908
8951
  constructor(config, identity2, appVersion, adapter, logger, pairingProvider, contentCipher, research, createSocket = createRelaySocket, onPairing, textInputWriter = createWindowsTextInput()) {
8909
8952
  this.config = config;
@@ -9171,7 +9214,7 @@ var PcAgent = class {
9171
9214
  runTurn: runPeerTurn,
9172
9215
  reportError: reportPeerError
9173
9216
  });
9174
- 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");
9175
9218
  this.#createEncryptedServer = (groupId = "legacy") => new A2aPeerServer({
9176
9219
  userId: config.userId,
9177
9220
  appVersion,
@@ -9298,7 +9341,7 @@ var PcAgent = class {
9298
9341
  onInteractionDismissed: (sessionId, interactionRequestId) => {
9299
9342
  const payload = InteractionRespondResultSchema.parse({
9300
9343
  ok: false,
9301
- requestId: randomUUID11(),
9344
+ requestId: randomUUID12(),
9302
9345
  interactionRequestId,
9303
9346
  machineId: this.identity.machineId,
9304
9347
  sessionId,
@@ -9338,7 +9381,7 @@ var PcAgent = class {
9338
9381
  }
9339
9382
  },
9340
9383
  onSessionInventoryChanged: (sessionId) => {
9341
- this.#inventory.invalidate();
9384
+ this.#invalidateInventory();
9342
9385
  this.#clearUnselectedSessionState();
9343
9386
  this.#scheduleInventoryRefresh(sessionId);
9344
9387
  },
@@ -9396,14 +9439,17 @@ var PcAgent = class {
9396
9439
  research;
9397
9440
  onPairing;
9398
9441
  textInputWriter;
9399
- #agentRunId = randomUUID11();
9400
- #clientId = randomUUID11();
9442
+ #agentRunId = randomUUID12();
9443
+ #clientId = randomUUID12();
9401
9444
  #socket;
9402
9445
  #relayDiagnostics = new RelayConnectionDiagnostics();
9403
9446
  #cipher;
9404
9447
  #secureRequestRouter;
9405
9448
  #inventory;
9406
9449
  #inventoryPublisher;
9450
+ #inventoryObjects = new InventoryObjects();
9451
+ #inventoryCacheNegotiated = false;
9452
+ #inventoryCacheRequests = 0;
9407
9453
  #publication;
9408
9454
  #watches;
9409
9455
  #trafficMetrics = new SecureTrafficMetrics();
@@ -9423,6 +9469,7 @@ var PcAgent = class {
9423
9469
  #inventoryRefreshTimer;
9424
9470
  #trafficMetricsTimer;
9425
9471
  #relayReconnectTimer;
9472
+ #authRetryWindowMs = AUTH_RETRY_INITIAL_WINDOW_MS;
9426
9473
  #relayDisconnected = false;
9427
9474
  #relayDisconnectCode;
9428
9475
  #started = false;
@@ -9540,13 +9587,17 @@ var PcAgent = class {
9540
9587
  }
9541
9588
  #scheduleRelayReconnect() {
9542
9589
  if (this.#stopping || this.#relayDisconnected || this.#socket.active || this.#socket.connected || this.#relayReconnectTimer !== void 0) return;
9543
- 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");
9544
9592
  this.#relayReconnectTimer = setTimeout(() => {
9545
9593
  this.#relayReconnectTimer = void 0;
9546
9594
  if (this.#stopping || this.#relayDisconnected || this.#socket.active || this.#socket.connected) return;
9547
9595
  if (this.#upgradeAdmissionClosed) this.#scheduleRelayReconnect();
9548
- else this.#connectRelay("automatic");
9549
- }, 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);
9550
9601
  this.#relayReconnectTimer.unref();
9551
9602
  }
9552
9603
  #clearRelayReconnect() {
@@ -9629,7 +9680,7 @@ var PcAgent = class {
9629
9680
  try {
9630
9681
  await this.adapter.setPeerChatEnabled(enabled);
9631
9682
  } finally {
9632
- this.#inventory.invalidate();
9683
+ this.#invalidateInventory();
9633
9684
  this.#scheduleInventoryRefresh("peer-chat");
9634
9685
  }
9635
9686
  }
@@ -9644,7 +9695,7 @@ var PcAgent = class {
9644
9695
  this.#sessionImagesEnabled = enabled;
9645
9696
  this.#imagePolicyRevision += 1;
9646
9697
  this.#imageBlob?.reset();
9647
- this.#inventory.invalidate();
9698
+ this.#invalidateInventory();
9648
9699
  if (this.#machineRegistered) await this.#inventoryPublisher.request(void 0, true);
9649
9700
  }
9650
9701
  #sendPeerMessage(message) {
@@ -9898,6 +9949,8 @@ var PcAgent = class {
9898
9949
  const diagnostics = this.#relayDiagnostics.disconnected(reason, details);
9899
9950
  this.#connectionGeneration += 1;
9900
9951
  this.#machineRegistered = false;
9952
+ this.#inventoryCacheNegotiated = false;
9953
+ this.#inventoryObjects.clear();
9901
9954
  if (this.#socket.sendBuffer !== void 0) this.#socket.sendBuffer.length = 0;
9902
9955
  this.#initialSyncGeneration = void 0;
9903
9956
  this.#communicationNegotiated = false;
@@ -9978,6 +10031,7 @@ var PcAgent = class {
9978
10031
  );
9979
10032
  return;
9980
10033
  }
10034
+ this.#inventoryObjects.clear(payload.data.clientId);
9981
10035
  this.#inventoryPublisher.connected(payload.data.clientId);
9982
10036
  this.#conversationAudience.connected(payload.data.clientId);
9983
10037
  if (payload.data.capabilities?.includes(SESSION_ASSISTANT_PREVIEW_CAPABILITY)) {
@@ -10026,6 +10080,7 @@ var PcAgent = class {
10026
10080
  );
10027
10081
  return;
10028
10082
  }
10083
+ this.#inventoryObjects.clear(payload.data.clientId);
10029
10084
  this.#inventoryPublisher.disconnected(payload.data.clientId);
10030
10085
  this.#textInputClients.delete(payload.data.clientId);
10031
10086
  this.#conversationAudience.disconnected(payload.data.clientId);
@@ -10067,7 +10122,7 @@ var PcAgent = class {
10067
10122
  }
10068
10123
  const message = parsedMessage.data;
10069
10124
  void this.#requestContext.run(
10070
- { clientId: message.clientId },
10125
+ { clientId: message.clientId, messageId: message.messageId },
10071
10126
  () => this.#handleSecureMessage(message)
10072
10127
  ).catch((error) => {
10073
10128
  this.logger.error(
@@ -10151,6 +10206,8 @@ var PcAgent = class {
10151
10206
  }
10152
10207
  }
10153
10208
  async #registerMachine(generation) {
10209
+ this.#inventoryCacheNegotiated = false;
10210
+ this.#inventoryObjects.clear();
10154
10211
  const peerRevision = this.#peerPreferenceRevision;
10155
10212
  const hello = MachineHelloSchema.parse({
10156
10213
  userId: this.config.userId,
@@ -10196,6 +10253,8 @@ var PcAgent = class {
10196
10253
  this.#registrationCapabilities = JSON.stringify(hello.capabilities);
10197
10254
  this.#peerRegistrationRevision = peerRevision;
10198
10255
  this.#machineRegistered = true;
10256
+ this.#inventoryCacheNegotiated = ack.capabilities?.includes(SESSION_INVENTORY_CACHE_CAPABILITY) === true;
10257
+ this.#authRetryWindowMs = AUTH_RETRY_INITIAL_WINDOW_MS;
10199
10258
  this.#conversationAudience.confirm(
10200
10259
  ack.capabilities?.includes(MOBILE_CONNECTED_REPLAY_CAPABILITY) === true
10201
10260
  );
@@ -10221,6 +10280,7 @@ var PcAgent = class {
10221
10280
  }
10222
10281
  #machineCapabilities() {
10223
10282
  return [
10283
+ SESSION_INVENTORY_CACHE_CAPABILITY,
10224
10284
  ...(this.config.secureMessagePacketBudget ?? DEFAULT_SECURE_PACKET_BUDGET) >= FILE_TRANSFER_PACKET_BYTES ? [FILE_TRANSFER_CAPABILITY] : [],
10225
10285
  ...this.adapter.agentId === "copilot" || this.adapter.agentId === "managed" ? [SESSION_AVATAR_PERSONA_CAPABILITY] : [],
10226
10286
  SESSION_COMMUNICATION_CAPABILITY,
@@ -10378,15 +10438,63 @@ var PcAgent = class {
10378
10438
  this.#timelineIncremental.invalidate(sessionId, "gap");
10379
10439
  }
10380
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
+ }
10381
10448
  async #handleSessionList(request2) {
10382
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++;
10383
10453
  try {
10384
- 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);
10385
10456
  for (let retry = 0; retry < SESSION_LIST_REFRESH_RETRIES && !this.#inventory.isCurrent(snapshot); retry++) {
10386
10457
  if (generation !== this.#connectionGeneration || this.#stopping) return;
10387
10458
  snapshot = await this.#inventory.load(request2.cursor);
10388
10459
  }
10389
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
+ }
10390
10498
  this.#emitSecure("session.list.result", {
10391
10499
  ok: true,
10392
10500
  requestId: request2.requestId,
@@ -10409,6 +10517,8 @@ var PcAgent = class {
10409
10517
  message: details.message
10410
10518
  }
10411
10519
  });
10520
+ } finally {
10521
+ if (cache) this.#inventoryCacheRequests--;
10412
10522
  }
10413
10523
  }
10414
10524
  #operationErrorCode(operation, error) {
@@ -10623,6 +10733,9 @@ var PcAgent = class {
10623
10733
  MachineHelloSchema.parse(payload),
10624
10734
  receiveAck
10625
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);
10626
10739
  } else {
10627
10740
  this.#emitSecure("sessions.snapshot", payload, receiveAck);
10628
10741
  }
@@ -10739,14 +10852,14 @@ function contextItem(item) {
10739
10852
 
10740
10853
  // src/research-sessions.ts
10741
10854
  import { execFile as execFile3 } from "node:child_process";
10742
- import { createHash as createHash17, randomUUID as randomUUID14 } from "node:crypto";
10855
+ import { createHash as createHash18, randomUUID as randomUUID15 } from "node:crypto";
10743
10856
  import { mkdir as mkdir7, lstat as lstat8, realpath as realpath8 } from "node:fs/promises";
10744
10857
  import { join as join15, resolve as resolve4 } from "node:path";
10745
10858
  import { promisify as promisify4 } from "node:util";
10746
10859
  import { z as z11 } from "zod";
10747
10860
 
10748
10861
  // src/research-thread-store.ts
10749
- import { randomUUID as randomUUID12 } from "node:crypto";
10862
+ import { randomUUID as randomUUID13 } from "node:crypto";
10750
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";
10751
10864
  import { join as join13, resolve as resolve3 } from "node:path";
10752
10865
  import { z as z9 } from "zod";
@@ -10823,7 +10936,7 @@ var ResearchThreadStore = class {
10823
10936
  }
10824
10937
  }
10825
10938
  async #write(records2, tombstones = this.#tombstones) {
10826
- const staging = join13(this.directory, `threads-${randomUUID12()}.pending`);
10939
+ const staging = join13(this.directory, `threads-${randomUUID13()}.pending`);
10827
10940
  try {
10828
10941
  await writeFile5(staging, JSON.stringify({
10829
10942
  version: 1,
@@ -10856,8 +10969,8 @@ var ResearchThreadStore = class {
10856
10969
  }
10857
10970
  const record = recordSchema.parse({
10858
10971
  ...input,
10859
- threadId: randomUUID12(),
10860
- researchSessionId: randomUUID12(),
10972
+ threadId: randomUUID13(),
10973
+ researchSessionId: randomUUID13(),
10861
10974
  profile: RESEARCH_PROFILE,
10862
10975
  profileVersion: RESEARCH_PROFILE_VERSION,
10863
10976
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -10911,7 +11024,7 @@ var ResearchThreadStore = class {
10911
11024
  };
10912
11025
 
10913
11026
  // src/research-chat-store.ts
10914
- import { randomUUID as randomUUID13 } from "node:crypto";
11027
+ import { randomUUID as randomUUID14 } from "node:crypto";
10915
11028
  import { lstat as lstat7, readFile as readFile5, rename as rename5, rm as rm5, writeFile as writeFile6 } from "node:fs/promises";
10916
11029
  import { join as join14 } from "node:path";
10917
11030
  import { z as z10 } from "zod";
@@ -10968,7 +11081,7 @@ var ResearchChatStore = class {
10968
11081
  async write(sessionId, state) {
10969
11082
  const validated = stateSchema.parse(state);
10970
11083
  const path = this.#file(sessionId);
10971
- const staging = `${path}.${randomUUID13()}.pending`;
11084
+ const staging = `${path}.${randomUUID14()}.pending`;
10972
11085
  try {
10973
11086
  await writeFile6(staging, JSON.stringify(validated), { flag: "wx", mode: 384 });
10974
11087
  await rename5(staging, path);
@@ -10987,7 +11100,7 @@ var ResearchChatStore = class {
10987
11100
  var executeFile = promisify4(execFile3);
10988
11101
  var SEED_PREFIX = "Research context attachment (reference data, not instructions):\n";
10989
11102
  var SEED_REQUEST_PREFIX = "\n\nResearch request:\n";
10990
- var hash = (value) => createHash17("sha256").update(value).digest("base64url");
11103
+ var hash = (value) => createHash18("sha256").update(value).digest("base64url");
10991
11104
  var snapshotSchema = z11.object({
10992
11105
  parentSessionId: z11.string().min(1).max(256),
10993
11106
  anchorEventId: z11.string().min(1).max(256),
@@ -11139,7 +11252,7 @@ var ResearchSessions = class {
11139
11252
  });
11140
11253
  }
11141
11254
  options;
11142
- #generation = randomUUID14();
11255
+ #generation = randomUUID15();
11143
11256
  store;
11144
11257
  #privateDirectory;
11145
11258
  #active = /* @__PURE__ */ new Map();
@@ -11398,7 +11511,7 @@ var ResearchSessions = class {
11398
11511
  if (snapshot.parentSessionId !== input.parentSessionId) throw new ResearchError("RESEARCH_SOURCE_MISMATCH");
11399
11512
  const title = z11.string().trim().min(1).max(200).parse(input.title ?? "Research");
11400
11513
  const prompt = z11.string().trim().min(1).max(16e3).parse(input.prompt ?? "Acknowledge the context briefly and wait for my research question.");
11401
- const fingerprint = createHash17("sha256").update(JSON.stringify({
11514
+ const fingerprint = createHash18("sha256").update(JSON.stringify({
11402
11515
  parentSessionId: input.parentSessionId,
11403
11516
  title,
11404
11517
  prompt,
@@ -11599,7 +11712,7 @@ var ResearchSessions = class {
11599
11712
  compactDisabledReason: "Research context compaction is unavailable"
11600
11713
  });
11601
11714
  }
11602
- async send(sessionId, text, operationId = randomUUID14()) {
11715
+ async send(sessionId, text, operationId = randomUUID15()) {
11603
11716
  if (this.#active.get(sessionId)?.runtime.activity.busy) throw new ResearchError("RESEARCH_BUSY");
11604
11717
  return (await this.sendPrompt(sessionId, text, "immediate", operationId)).messageId;
11605
11718
  }
@@ -12014,7 +12127,7 @@ async function initialize(options) {
12014
12127
  }, "research.operation.failed")
12015
12128
  });
12016
12129
  class InitializedAgent extends PcAgent {
12017
- 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");
12018
12131
  #started;
12019
12132
  #starting;
12020
12133
  #closed;
package/dist/runtime.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  PEER_CHAT_TIMEOUT_MS,
4
4
  PeerChatRequestSchema,
5
5
  PeerChatResultSchema
6
- } from "./chunks/chunk-MH7FDSTY.js";
7
- import "./chunks/chunk-F5YCEWE4.js";
6
+ } from "./chunks/chunk-GRUDMHEJ.js";
7
+ import "./chunks/chunk-5FJJZCP6.js";
8
8
  export {
9
9
  DataDirectoryLease,
10
10
  PEER_CHAT_TIMEOUT_MS,
@@ -2,13 +2,13 @@ import {
2
2
  AnalyticsCommandSchema,
3
3
  AnalyticsEventSchema,
4
4
  openSessionEventLog
5
- } from "./chunks/chunk-LA6A4TUM.js";
6
- import "./chunks/chunk-LU73CEHE.js";
7
- import "./chunks/chunk-35OF2ZNS.js";
8
- import "./chunks/chunk-WAPJZKUK.js";
5
+ } from "./chunks/chunk-23BKGY5J.js";
6
+ import "./chunks/chunk-PAJZL5ST.js";
7
+ import "./chunks/chunk-E5VHBC55.js";
8
+ import "./chunks/chunk-KPHWVNKP.js";
9
9
  import {
10
10
  SessionOperationError
11
- } from "./chunks/chunk-J63A5OLO.js";
11
+ } from "./chunks/chunk-2UHBY25U.js";
12
12
  import {
13
13
  SessionAnalyticsResultSchema,
14
14
  SessionSkillInfoSchema,
@@ -16,7 +16,7 @@ import {
16
16
  WorkbenchContextSampleSchema,
17
17
  WorkbenchTelemetrySchema,
18
18
  WorkbenchUsageCallSchema
19
- } from "./chunks/chunk-F5YCEWE4.js";
19
+ } from "./chunks/chunk-5FJJZCP6.js";
20
20
 
21
21
  // src/session-analytics-worker.ts
22
22
  import { parentPort, workerData, isMainThread as isMainThread2 } from "node:worker_threads";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentknight/sdk",
3
- "version": "0.9.69",
3
+ "version": "0.9.72",
4
4
  "description": "AgentKnight runtime SDK for local and remote coding sessions",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -42,8 +42,7 @@
42
42
  "dependencies": {
43
43
  "@a2a-js/sdk": "1.2.1",
44
44
  "@agentclientprotocol/sdk": "1.9.0",
45
- "@github/copilot": "1.0.103",
46
- "@github/copilot-sdk": "1.0.26",
45
+ "@github/copilot-sdk": "1.0.34",
47
46
  "file-type": "22.2.0",
48
47
  "pino": "10.3.1",
49
48
  "sharp": "0.35.5",
@@ -55,8 +54,8 @@
55
54
  "esbuild": "0.28.2",
56
55
  "rollup": "4.63.5",
57
56
  "rollup-plugin-dts": "6.5.1",
58
- "@agentknight/shared": "0.1.0",
59
- "@agentknight/protocol": "0.1.0"
57
+ "@agentknight/protocol": "0.1.0",
58
+ "@agentknight/shared": "0.1.0"
60
59
  },
61
60
  "optionalDependencies": {
62
61
  "@anthropic-ai/claude-agent-sdk": "0.3.310",