@agentknight/sdk 0.9.47 → 0.9.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,12 +4,12 @@ import {
4
4
  PeerChatRequestSchema,
5
5
  PeerChatResultSchema,
6
6
  validateDataDirectory
7
- } from "./chunks/chunk-GRXWNM6S.js";
7
+ } from "./chunks/chunk-7HZ5UZSC.js";
8
8
  import {
9
9
  AgentSelectionSchema,
10
10
  assertSelectionSnapshotFits,
11
11
  supportsAgentSelection
12
- } from "./chunks/chunk-DCY33KQC.js";
12
+ } from "./chunks/chunk-YFLDTX2W.js";
13
13
  import {
14
14
  ConversationNormalizer,
15
15
  LiveTimelineProjection,
@@ -31,22 +31,22 @@ import {
31
31
  resolveGitProjectIdentity,
32
32
  sessionRestoreFailure,
33
33
  validateOperationResponse
34
- } from "./chunks/chunk-MUKGV7IE.js";
34
+ } from "./chunks/chunk-RX7VGB3T.js";
35
35
  import {
36
36
  GROUP_CHAT_MAX_TURNS,
37
37
  GroupChatError
38
- } from "./chunks/chunk-OPUBIQCO.js";
38
+ } from "./chunks/chunk-H6FG5CCS.js";
39
39
  import {
40
40
  detectClaude,
41
41
  detectCopilot,
42
42
  detectPi,
43
43
  hasLocalExecutable
44
- } from "./chunks/chunk-EIFNERXM.js";
44
+ } from "./chunks/chunk-T6226JFS.js";
45
45
  import {
46
46
  assistantPreview,
47
47
  isContentfulAssistant,
48
48
  userPreview
49
- } from "./chunks/chunk-QBKKQQCB.js";
49
+ } from "./chunks/chunk-6VEMXJW4.js";
50
50
  import {
51
51
  AgentModelListingError,
52
52
  AgentSessionRenameError,
@@ -57,7 +57,7 @@ import {
57
57
  UnsupportedAgentOperationError,
58
58
  captureResearchAccess,
59
59
  captureWorkbenchAccess
60
- } from "./chunks/chunk-7A2SQAZ7.js";
60
+ } from "./chunks/chunk-R5LSWHRH.js";
61
61
  import {
62
62
  A2aRelayRequestSchema,
63
63
  A2aRelayResponseSchema,
@@ -98,6 +98,8 @@ import {
98
98
  PeerMessageSchema,
99
99
  PermissionRequestPayloadSchema,
100
100
  PermissionRespondRequestSchema,
101
+ ProtocolErrorSchema,
102
+ RELAY_DISCONNECT_EVENT,
101
103
  RESEARCH_CHAT_CAPABILITY,
102
104
  SCHEDULES_CAPABILITY,
103
105
  SCHEDULE_OPERATIONS,
@@ -241,7 +243,7 @@ import {
241
243
  sessionCommunicationError,
242
244
  sessionCommunicationOperationCapability,
243
245
  workbenchCapability
244
- } from "./chunks/chunk-DUMC5F2D.js";
246
+ } from "./chunks/chunk-BDKVGENQ.js";
245
247
 
246
248
  // src/initialize.ts
247
249
  import { createHash as createHash16 } from "node:crypto";
@@ -279,7 +281,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
279
281
  switch (engine.kind) {
280
282
  case "managed": {
281
283
  if (owner === void 0) throw new Error("Managed coding agents require the PC owner identity");
282
- const { ManagedCodingAgentAdapter } = await import("./chunks/managed-agent-adapter-UYLBGRNG.js");
284
+ const { ManagedCodingAgentAdapter } = await import("./chunks/managed-agent-adapter-GTFFRVMM.js");
283
285
  return new ManagedCodingAgentAdapter({
284
286
  dataDirectory: config.dataDirectory,
285
287
  owner,
@@ -315,13 +317,13 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
315
317
  kind: "codex",
316
318
  ...engine.codexCommand === void 0 ? {} : { command: engine.codexCommand }
317
319
  }
318
- }, onDiagnostic)
320
+ }, onDiagnostic, owner)
319
321
  },
320
322
  {
321
323
  id: "claude",
322
324
  name: codingAgentPresentation("claude").name,
323
325
  detect: detectClaude,
324
- create: () => createCodingAgentAdapter({ ...config, codingAgent: { kind: "claude" } }, onDiagnostic)
326
+ create: () => createCodingAgentAdapter({ ...config, codingAgent: { kind: "claude" } }, onDiagnostic, owner)
325
327
  },
326
328
  {
327
329
  id: "acp",
@@ -336,7 +338,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
336
338
  });
337
339
  }
338
340
  case "copilot": {
339
- const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-JXWQKOIV.js");
341
+ const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-RSL5GJYO.js");
340
342
  if (owner !== void 0) {
341
343
  return new GithubCopilotAdapter(void 0, void 0, void 0, {
342
344
  dataDirectory: config.dataDirectory,
@@ -356,28 +358,30 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
356
358
  }
357
359
  case "pi": {
358
360
  assertPiRuntimeSupported();
359
- const { PiCodingAgentAdapter } = await import("./chunks/pi-adapter-XLQHILYF.js");
361
+ const { PiCodingAgentAdapter } = await import("./chunks/pi-adapter-WGHEJ5WA.js");
360
362
  return new PiCodingAgentAdapter(
361
363
  engine.agentDirectory === void 0 ? {} : { agentDirectory: resolve(engine.agentDirectory) }
362
364
  );
363
365
  }
364
366
  case "codex": {
365
- const { CodexCodingAgentAdapter } = await import("./chunks/codex-adapter-IR5E7AMV.js");
367
+ const { CodexCodingAgentAdapter } = await import("./chunks/codex-adapter-5XC3CAAT.js");
366
368
  return new CodexCodingAgentAdapter({
367
369
  dataDirectory: resolve(config.dataDirectory, "coding-agents"),
370
+ ...owner === void 0 ? {} : { nativeSessionOwner: owner },
368
371
  ...engine.command === void 0 ? {} : { command: engine.command },
369
372
  ...onDiagnostic === void 0 ? {} : { onDiagnostic }
370
373
  });
371
374
  }
372
375
  case "claude": {
373
- const { ClaudeCodingAgentAdapter } = await import("./chunks/claude-adapter-YHNFRQLV.js");
376
+ const { ClaudeCodingAgentAdapter } = await import("./chunks/claude-adapter-WCIDCXOP.js");
374
377
  return new ClaudeCodingAgentAdapter({
375
378
  dataDirectory: resolve(config.dataDirectory, "coding-agents"),
379
+ ...owner === void 0 ? {} : { nativeSessionOwner: owner },
376
380
  ...onDiagnostic === void 0 ? {} : { onDiagnostic }
377
381
  });
378
382
  }
379
383
  case "acp": {
380
- const { AcpCodingAgentAdapter } = await import("./chunks/acp-adapter-IH6MP7JE.js");
384
+ const { AcpCodingAgentAdapter } = await import("./chunks/acp-adapter-2ZBDMHA3.js");
381
385
  return new AcpCodingAgentAdapter({
382
386
  command: engine.command,
383
387
  args: engine.args,
@@ -8025,6 +8029,7 @@ var BUFFERED_INTERACTION_RETENTION_MS = 5 * 60 * 1e3;
8025
8029
  var INVENTORY_REFRESH_DEBOUNCE_MS = 100;
8026
8030
  var SESSION_LIST_REFRESH_RETRIES = 2;
8027
8031
  var TRAFFIC_METRICS_INTERVAL_MS = 6e4;
8032
+ var RELAY_RECONNECT_INTERVAL_MS = 15 * 6e4;
8028
8033
  var PcAgent = class {
8029
8034
  constructor(config, identity2, appVersion, adapter, logger, pairingProvider, contentCipher, research, createSocket = createRelaySocket, onPairing) {
8030
8035
  this.config = config;
@@ -8460,6 +8465,10 @@ var PcAgent = class {
8460
8465
  #refreshTimer;
8461
8466
  #inventoryRefreshTimer;
8462
8467
  #trafficMetricsTimer;
8468
+ #relayReconnectTimer;
8469
+ #relayDisconnected = false;
8470
+ #relayDisconnectCode;
8471
+ #started = false;
8463
8472
  #machineRegistered = false;
8464
8473
  #initialSyncGeneration;
8465
8474
  #connecting = 0;
@@ -8519,7 +8528,10 @@ var PcAgent = class {
8519
8528
  try {
8520
8529
  await this.adapter.start();
8521
8530
  this.logger.info({ codingAgent: this.adapter.agentId }, "coding-agent.started");
8522
- if (!this.#stopping) this.#socket.connect();
8531
+ if (!this.#stopping) {
8532
+ this.#started = true;
8533
+ this.#socket.connect();
8534
+ }
8523
8535
  } finally {
8524
8536
  this.#starting = false;
8525
8537
  }
@@ -8527,6 +8539,49 @@ var PcAgent = class {
8527
8539
  waitUntilStopped() {
8528
8540
  return this.#stopped;
8529
8541
  }
8542
+ reconnectRelay() {
8543
+ if (!this.#started || this.#stopping || this.#upgradeAdmissionClosed) {
8544
+ throw new Error("PC Agent is not available for Relay reconnection.");
8545
+ }
8546
+ if (this.#relayRegistrationStatus.state === "connecting" || this.#socket.connected && this.#machineRegistered) return;
8547
+ this.#connectRelay("manual");
8548
+ }
8549
+ disconnectRelay() {
8550
+ if (!this.#started || this.#stopping || this.#upgradeAdmissionClosed) {
8551
+ throw new Error("PC Agent is not available for Relay disconnection.");
8552
+ }
8553
+ if (this.#relayDisconnected) return;
8554
+ this.#relayDisconnected = true;
8555
+ this.#clearRelayReconnect();
8556
+ this.#connectionGeneration += 1;
8557
+ this.#socket.disconnect();
8558
+ this.#relayRegistrationStatus = { state: "disconnected", message: "\u5DF2\u65AD\u5F00 Relay \u8FDE\u63A5\u3002" };
8559
+ this.logger.info("relay.disconnect.requested");
8560
+ }
8561
+ #connectRelay(source) {
8562
+ this.#clearRelayReconnect();
8563
+ this.#relayDisconnected = false;
8564
+ if (this.#socket.connected) this.#socket.disconnect();
8565
+ this.#relayDisconnectCode = void 0;
8566
+ this.#relayRegistrationStatus = { state: "connecting", message: "\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5 Relay\u3002" };
8567
+ this.logger.info({ source }, "relay.reconnect.requested");
8568
+ this.#socket.connect();
8569
+ }
8570
+ #scheduleRelayReconnect() {
8571
+ if (this.#stopping || this.#relayDisconnected || this.#socket.active || this.#socket.connected || this.#relayReconnectTimer !== void 0) return;
8572
+ this.logger.info({ delayMs: RELAY_RECONNECT_INTERVAL_MS }, "relay.reconnect.scheduled");
8573
+ this.#relayReconnectTimer = setTimeout(() => {
8574
+ this.#relayReconnectTimer = void 0;
8575
+ if (this.#stopping || this.#relayDisconnected || this.#socket.active || this.#socket.connected) return;
8576
+ if (this.#upgradeAdmissionClosed) this.#scheduleRelayReconnect();
8577
+ else this.#connectRelay("automatic");
8578
+ }, RELAY_RECONNECT_INTERVAL_MS);
8579
+ this.#relayReconnectTimer.unref();
8580
+ }
8581
+ #clearRelayReconnect() {
8582
+ clearTimeout(this.#relayReconnectTimer);
8583
+ this.#relayReconnectTimer = void 0;
8584
+ }
8530
8585
  runPeerChat(request, signal) {
8531
8586
  if (this.#peerChatEnabled && !this.#a2aNegotiated) {
8532
8587
  return Promise.reject(new Error("Relay has not negotiated A2A support; upgrade Relay before starting a peer conversation."));
@@ -8725,6 +8780,7 @@ var PcAgent = class {
8725
8780
  this.#a2aNegotiated = false;
8726
8781
  this.#connectionGeneration += 1;
8727
8782
  this.#cancelSnapshotSync();
8783
+ this.#clearRelayReconnect();
8728
8784
  this.#clearTimers();
8729
8785
  this.#socket.disconnect();
8730
8786
  this.#prompts.reset();
@@ -8760,11 +8816,13 @@ var PcAgent = class {
8760
8816
  }
8761
8817
  #bindSocketEvents() {
8762
8818
  this.#socket.on("connect", () => {
8763
- if (this.#stopping) {
8819
+ if (this.#stopping || this.#relayDisconnected) {
8764
8820
  this.#socket.disconnect();
8765
8821
  return;
8766
8822
  }
8767
8823
  const generation = ++this.#connectionGeneration;
8824
+ this.#clearRelayReconnect();
8825
+ this.#relayDisconnectCode = void 0;
8768
8826
  this.#machineRegistered = false;
8769
8827
  this.#initialSyncGeneration = void 0;
8770
8828
  this.#relayRegistrationStatus = {
@@ -8774,9 +8832,11 @@ var PcAgent = class {
8774
8832
  void this.#onConnected(generation);
8775
8833
  });
8776
8834
  this.#socket.on("connect_error", (error) => {
8835
+ if (this.#stopping || this.#relayDisconnected) return;
8836
+ this.#clearRelayReconnect();
8777
8837
  this.#relayRegistrationStatus = {
8778
8838
  state: "error",
8779
- message: error.message
8839
+ 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"
8780
8840
  };
8781
8841
  this.logger.error(
8782
8842
  {
@@ -8786,6 +8846,7 @@ var PcAgent = class {
8786
8846
  },
8787
8847
  "relay.connect.failed"
8788
8848
  );
8849
+ if (error.message === "Authentication service unavailable") this.#scheduleRelayReconnect();
8789
8850
  });
8790
8851
  this.#socket.on("disconnect", (reason, details) => {
8791
8852
  const diagnostics = this.#relayDiagnostics.disconnected(reason, details);
@@ -8807,10 +8868,14 @@ var PcAgent = class {
8807
8868
  this.#researchChatClients.clear();
8808
8869
  this.#assistantPreviewClients.clear();
8809
8870
  this.#agentControlClients.clear();
8810
- this.#relayRegistrationStatus = {
8871
+ this.#relayRegistrationStatus = this.#relayDisconnected ? {
8872
+ state: "disconnected",
8873
+ message: "\u5DF2\u65AD\u5F00 Relay \u8FDE\u63A5\u3002"
8874
+ } : {
8811
8875
  state: "error",
8812
- message: `Relay \u8FDE\u63A5\u5DF2\u65AD\u5F00\uFF1A${reason}`
8876
+ message: this.#relayDisconnectCode === "MACHINE_REPLACED" ? "\u53E6\u4E00 PC \u8FDE\u63A5\u5DF2\u6CE8\u518C\u6B64\u7535\u8111\uFF0C\u81EA\u52A8\u91CD\u8FDE\u5DF2\u6682\u505C\u3002" : this.#relayDisconnectCode === "AUTHORIZATION_REVOKED" ? "Relay \u6388\u6743\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002" : this.#relayDisconnectCode === "AUTH_SERVICE_UNAVAILABLE" ? "Relay \u6388\u6743\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u5C06\u7A0D\u540E\u91CD\u8FDE\u3002" : "Relay \u8FDE\u63A5\u5DF2\u65AD\u5F00\u3002"
8813
8877
  };
8878
+ this.#clearRelayReconnect();
8814
8879
  this.#clearTimers();
8815
8880
  void this.#watches.releaseAll().catch((error) => {
8816
8881
  this.logger.error(
@@ -8822,10 +8887,23 @@ var PcAgent = class {
8822
8887
  ...diagnostics,
8823
8888
  transport: relayTransport(this.#socket.io.engine?.transport?.name),
8824
8889
  socketActive: this.#socket.active,
8825
- stopping: this.#stopping
8890
+ stopping: this.#stopping,
8891
+ ...this.#relayDisconnectCode === void 0 ? {} : { disconnectCode: this.#relayDisconnectCode }
8826
8892
  }, "relay.disconnected");
8893
+ if (reason === "io server disconnect" && this.#relayDisconnectCode === "AUTH_SERVICE_UNAVAILABLE") {
8894
+ this.#scheduleRelayReconnect();
8895
+ }
8827
8896
  });
8828
8897
  this.#socket.on("protocol.error", (error) => {
8898
+ const parsed = ProtocolErrorSchema.safeParse(error);
8899
+ if (parsed.success && parsed.data.event === RELAY_DISCONNECT_EVENT) {
8900
+ const code = parsed.data.code;
8901
+ if (code === "AUTH_SERVICE_UNAVAILABLE" || code === "AUTHORIZATION_REVOKED" || code === "MACHINE_REPLACED") {
8902
+ this.#relayDisconnectCode = code;
8903
+ this.logger.error({ code }, "relay.protocol.error");
8904
+ return;
8905
+ }
8906
+ }
8829
8907
  this.logger.error(error, "relay.protocol.error");
8830
8908
  });
8831
8909
  this.#socket.on("peer.message", (delivery) => {
@@ -10881,7 +10959,7 @@ async function initialize(options) {
10881
10959
  }
10882
10960
  async getStatus() {
10883
10961
  const { ready, busy } = await this.getUpgradeStatus();
10884
- const state = this.isStopping ? "stopped" : this.#started === void 0 ? "initialized" : ready ? "ready" : this.relayRegistrationStatus.state === "error" ? "error" : "connecting";
10962
+ const state = this.isStopping ? "stopped" : this.#started === void 0 ? "initialized" : ready ? "ready" : this.relayRegistrationStatus.state === "disconnected" ? "disconnected" : this.relayRegistrationStatus.state === "error" ? "error" : "connecting";
10885
10963
  return { state, busy };
10886
10964
  }
10887
10965
  }
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-GRXWNM6S.js";
7
- import "./chunks/chunk-DUMC5F2D.js";
6
+ } from "./chunks/chunk-7HZ5UZSC.js";
7
+ import "./chunks/chunk-BDKVGENQ.js";
8
8
  export {
9
9
  DataDirectoryLease,
10
10
  PEER_CHAT_TIMEOUT_MS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentknight/sdk",
3
- "version": "0.9.47",
3
+ "version": "0.9.48",
4
4
  "description": "AgentKnight runtime SDK for local and remote coding sessions",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -51,8 +51,8 @@
51
51
  "esbuild": "0.28.2",
52
52
  "rollup": "4.63.5",
53
53
  "rollup-plugin-dts": "6.5.1",
54
- "@agentknight/protocol": "0.1.0",
55
- "@agentknight/shared": "0.1.0"
54
+ "@agentknight/shared": "0.1.0",
55
+ "@agentknight/protocol": "0.1.0"
56
56
  },
57
57
  "optionalDependencies": {
58
58
  "@anthropic-ai/claude-agent-sdk": "0.3.310",