@agentknight/sdk 0.9.62 → 0.9.68

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-MBYKOCA2.js → acp-adapter-RZX5SUB3.js} +4 -4
  2. package/dist/chunks/chunk-35OF2ZNS.js +275 -0
  3. package/dist/chunks/chunk-4XT65OSG.js +72 -0
  4. package/dist/chunks/{chunk-A4YCCQ3I.js → chunk-AWVC5NX4.js} +1 -1
  5. package/dist/chunks/chunk-B777YB6E.js +109 -0
  6. package/dist/chunks/{chunk-7CNBPLNE.js → chunk-CFQQOAQV.js} +5 -2
  7. package/dist/chunks/{chunk-P2PH5KMV.js → chunk-DWTXWVIA.js} +6 -0
  8. package/dist/chunks/{chunk-ZNQ2I5EF.js → chunk-EDYVCZIR.js} +11 -132
  9. package/dist/chunks/{chunk-3AMFPDE5.js → chunk-FY4XTWUF.js} +4 -4
  10. package/dist/chunks/{chunk-H4SHMWQ6.js → chunk-IXGVSREH.js} +1 -1
  11. package/dist/chunks/{chunk-SIFCCGXF.js → chunk-LCA2MWOQ.js} +2 -2
  12. package/dist/chunks/{chunk-ALUQLM54.js → chunk-MB3H6HEI.js} +2 -2
  13. package/dist/chunks/{chunk-CHKNC6PD.js → chunk-Q5OUZJCZ.js} +1 -1
  14. package/dist/chunks/{chunk-7OGTK7KB.js → chunk-UHRUQM4D.js} +1 -1
  15. package/dist/chunks/chunk-VIWTNPVC.js +66 -0
  16. package/dist/chunks/chunk-Y6NCJB55.js +302 -0
  17. package/dist/chunks/{claude-adapter-D3JWXMNX.js → claude-adapter-FQSQIYUY.js} +4 -4
  18. package/dist/chunks/{codex-adapter-655KHW7H.js → codex-adapter-TOXSRT2W.js} +4 -4
  19. package/dist/chunks/{copilot-adapter-EZUXHBE3.js → copilot-adapter-KUCX7XQW.js} +56 -148
  20. package/dist/chunks/{managed-agent-adapter-BOJNEJ75.js → managed-agent-adapter-LGBRXDGP.js} +33 -24
  21. package/dist/chunks/{pi-adapter-LAD5GOCP.js → pi-adapter-RXNZSE4F.js} +330 -53
  22. package/dist/configuration.js +5 -5
  23. package/dist/index.js +20 -31
  24. package/dist/runtime.js +2 -2
  25. package/dist/session-analytics-worker.js +7 -5
  26. package/package.json +1 -1
  27. package/dist/chunks/chunk-CM5LVXVL.js +0 -572
  28. package/dist/chunks/chunk-XPHAIOKN.js +0 -64
@@ -3,19 +3,19 @@ import {
3
3
  } from "./chunk-T6226JFS.js";
4
4
  import {
5
5
  latestPreviewItems
6
- } from "./chunk-H4SHMWQ6.js";
6
+ } from "./chunk-IXGVSREH.js";
7
7
  import {
8
8
  UnsupportedAgentOperationError,
9
9
  validateSessionName
10
- } from "./chunk-7CNBPLNE.js";
11
- import "./chunk-7OGTK7KB.js";
10
+ } from "./chunk-CFQQOAQV.js";
11
+ import "./chunk-UHRUQM4D.js";
12
12
  import {
13
13
  ConversationItemSchema,
14
14
  InteractionRequestSchema,
15
15
  InteractionResponseSchema,
16
16
  SESSION_TIMELINE_PAGE_SIZE,
17
17
  SessionSummarySchema
18
- } from "./chunk-P2PH5KMV.js";
18
+ } from "./chunk-DWTXWVIA.js";
19
19
 
20
20
  // src/claude-adapter.ts
21
21
  import { randomUUID as randomUUID2 } from "node:crypto";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  latestPreviewItems
3
- } from "./chunk-H4SHMWQ6.js";
3
+ } from "./chunk-IXGVSREH.js";
4
4
  import {
5
5
  UnsupportedAgentOperationError
6
- } from "./chunk-7CNBPLNE.js";
7
- import "./chunk-7OGTK7KB.js";
6
+ } from "./chunk-CFQQOAQV.js";
7
+ import "./chunk-UHRUQM4D.js";
8
8
  import {
9
9
  ConversationItemSchema,
10
10
  InteractionRequestSchema,
11
11
  SESSION_TIMELINE_PAGE_SIZE,
12
12
  SessionSummarySchema
13
- } from "./chunk-P2PH5KMV.js";
13
+ } from "./chunk-DWTXWVIA.js";
14
14
 
15
15
  // src/codex-adapter.ts
16
16
  import { randomUUID } from "node:crypto";
@@ -18,46 +18,52 @@ import {
18
18
  recordTimelineSyncDiagnostic,
19
19
  resolveGitProjectIdentity,
20
20
  sanitizeGitRemoteUrl
21
- } from "./chunk-3AMFPDE5.js";
21
+ } from "./chunk-FY4XTWUF.js";
22
22
  import "./chunk-IJPJQF7S.js";
23
23
  import {
24
24
  AnalyticsIndexResultSchema,
25
25
  AnalyticsReplySchema,
26
- CopilotSessionCompatibilityClient,
27
26
  openSessionEventLog,
28
- readSessionUpdatePage,
29
- resolveCopilotSessionDirectory,
30
- resumeWithCopilotSessionCompatibility
31
- } from "./chunk-CM5LVXVL.js";
27
+ readSessionUpdatePage
28
+ } from "./chunk-Y6NCJB55.js";
32
29
  import {
33
30
  ConversationNormalizer,
34
31
  isDisplayableHumanMessage
35
- } from "./chunk-ZNQ2I5EF.js";
32
+ } from "./chunk-EDYVCZIR.js";
36
33
  import {
37
34
  assertMainSessionId,
38
35
  isResearchSessionId
39
- } from "./chunk-A4YCCQ3I.js";
36
+ } from "./chunk-AWVC5NX4.js";
40
37
  import {
41
38
  GroupChatError,
42
39
  GroupChatMessageSchema,
43
40
  GroupChatRuntime
44
- } from "./chunk-ALUQLM54.js";
45
- import "./chunk-H4SHMWQ6.js";
41
+ } from "./chunk-MB3H6HEI.js";
42
+ import {
43
+ deletePromptAttachments,
44
+ stagePromptAttachments,
45
+ validatePromptAttachments
46
+ } from "./chunk-B777YB6E.js";
47
+ import {
48
+ CopilotSessionCompatibilityClient,
49
+ resolveCopilotSessionDirectory,
50
+ resumeWithCopilotSessionCompatibility
51
+ } from "./chunk-35OF2ZNS.js";
52
+ import "./chunk-4XT65OSG.js";
53
+ import "./chunk-IXGVSREH.js";
46
54
  import {
47
55
  AgentSessionRenameError,
48
56
  TimelinePageBudgetError,
49
57
  validateSessionName
50
- } from "./chunk-7CNBPLNE.js";
58
+ } from "./chunk-CFQQOAQV.js";
51
59
  import {
52
60
  SessionOperationError
53
- } from "./chunk-7OGTK7KB.js";
61
+ } from "./chunk-UHRUQM4D.js";
54
62
  import {
55
63
  ConversationItemSchema,
56
64
  CopilotModelOptionSchema,
57
65
  CurrentReasoningEffortSchema,
58
66
  InteractionResponseSchema,
59
- PromptFileAttachmentSchema,
60
- PromptImageAttachmentSchema,
61
67
  ReasoningEffortSchema,
62
68
  SESSION_TIMELINE_PAGE_SIZE,
63
69
  SessionAnalyticsResultSchema,
@@ -74,14 +80,14 @@ import {
74
80
  WorkbenchScheduleProposalSchema,
75
81
  WorkbenchScheduleSnapshotSchema,
76
82
  WorkbenchTelemetrySchema
77
- } from "./chunk-P2PH5KMV.js";
83
+ } from "./chunk-DWTXWVIA.js";
78
84
 
79
85
  // src/copilot-adapter.ts
80
- import { createHash as createHash4, randomUUID as randomUUID6 } from "node:crypto";
86
+ import { createHash as createHash3, randomUUID as randomUUID5 } from "node:crypto";
81
87
  import { existsSync, statSync } from "node:fs";
82
- import { readFile as readFile2, realpath as realpath2, stat } from "node:fs/promises";
88
+ import { readFile as readFile2, realpath, stat } from "node:fs/promises";
83
89
  import { createRequire } from "node:module";
84
- import { basename as basename2, dirname as dirname2, extname, isAbsolute, join as join3, relative, resolve } from "node:path";
90
+ import { basename, dirname, extname, isAbsolute, join as join2, relative, resolve } from "node:path";
85
91
 
86
92
  // src/adapters/copilot/runtime/client-runtime.ts
87
93
  var CopilotClientRuntime = class {
@@ -560,104 +566,6 @@ async function applyAvatarPersona(session, persona, busy = false) {
560
566
 
561
567
  // src/adapters/copilot/runtime/session-connections.ts
562
568
  import "@github/copilot-sdk";
563
-
564
- // src/prompt-attachments.ts
565
- import { createHash, randomUUID } from "node:crypto";
566
- import { lstat, mkdir, realpath, rm, writeFile } from "node:fs/promises";
567
- import { basename, dirname, join } from "node:path";
568
- function validatePromptAttachments(images, files) {
569
- const validateBytes = (attachment) => {
570
- const bytes = Buffer.from(attachment.data, "base64");
571
- if (bytes.byteLength !== attachment.byteLength || createHash("sha256").update(bytes).digest("hex") !== attachment.sha256) {
572
- throw new Error("Attachment failed integrity validation");
573
- }
574
- return bytes;
575
- };
576
- return {
577
- images: images.map((input) => {
578
- const attachment = PromptImageAttachmentSchema.parse(input);
579
- validateBytes(attachment);
580
- return {
581
- type: "blob",
582
- data: attachment.data,
583
- mimeType: attachment.mimeType,
584
- displayName: attachment.name
585
- };
586
- }),
587
- files: files.map((input) => {
588
- const attachment = PromptFileAttachmentSchema.parse(input);
589
- return { attachment, bytes: validateBytes(attachment) };
590
- })
591
- };
592
- }
593
- function hasCode(error, code) {
594
- return error instanceof Error && "code" in error && error.code === code;
595
- }
596
- async function uploadDirectory(sessionDirectory, create) {
597
- const home = dirname(dirname(sessionDirectory));
598
- if (create) {
599
- await mkdir(home, { recursive: true, mode: 448 });
600
- }
601
- let directory;
602
- try {
603
- directory = await realpath(home);
604
- } catch (error) {
605
- if (!create && hasCode(error, "ENOENT")) return void 0;
606
- throw error;
607
- }
608
- for (const segment of ["session-state", basename(sessionDirectory), "agentknight-uploads"]) {
609
- directory = join(directory, segment);
610
- if (create) {
611
- try {
612
- await mkdir(directory, { mode: 448 });
613
- } catch (error) {
614
- if (!hasCode(error, "EEXIST")) throw error;
615
- }
616
- }
617
- try {
618
- const info = await lstat(directory);
619
- if (info.isSymbolicLink() || !info.isDirectory()) {
620
- throw new Error("Attachment storage must be a real session directory");
621
- }
622
- } catch (error) {
623
- if (!create && hasCode(error, "ENOENT")) return void 0;
624
- throw error;
625
- }
626
- }
627
- return directory;
628
- }
629
- async function stagePromptAttachments(sessionId, validated) {
630
- if (validated.files.length === 0) return validated.images;
631
- const root = await uploadDirectory(resolveCopilotSessionDirectory(sessionId), true);
632
- if (root === void 0) throw new Error("Attachment storage is unavailable");
633
- const batchDirectory = join(root, randomUUID());
634
- await mkdir(batchDirectory, { mode: 448 });
635
- try {
636
- const attachments = [...validated.images];
637
- for (const [index, { attachment, bytes }] of validated.files.entries()) {
638
- const name = attachment.name.replace(/[^a-zA-Z0-9._-]/gu, "_").slice(-100).replace(/[. ]+$/u, "");
639
- const path = join(batchDirectory, `${index}-${name || "file"}`);
640
- await writeFile(path, bytes, { flag: "wx", mode: 384, flush: true });
641
- attachments.push({ type: "file", path, displayName: attachment.name });
642
- }
643
- return attachments;
644
- } catch (error) {
645
- try {
646
- await rm(batchDirectory, { recursive: true, force: true });
647
- } catch (cleanupError) {
648
- throw new AggregateError([error, cleanupError], "Failed to stage and clean up prompt attachments");
649
- }
650
- throw error;
651
- }
652
- }
653
- async function deletePromptAttachments(sessionDirectory) {
654
- const directory = await uploadDirectory(sessionDirectory, false);
655
- if (directory !== void 0) {
656
- await rm(directory, { recursive: true, force: true });
657
- }
658
- }
659
-
660
- // src/adapters/copilot/runtime/session-connections.ts
661
569
  var SessionConnections = class {
662
570
  constructor(ports) {
663
571
  this.ports = ports;
@@ -1762,14 +1670,14 @@ import {
1762
1670
  import { z as z5 } from "zod";
1763
1671
 
1764
1672
  // src/session-schedules.ts
1765
- import { randomUUID as randomUUID3 } from "node:crypto";
1673
+ import { randomUUID as randomUUID2 } from "node:crypto";
1766
1674
  import { defineTool } from "@github/copilot-sdk";
1767
1675
  import { z as z3 } from "zod";
1768
1676
 
1769
1677
  // src/schedule-draft-store.ts
1770
- import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
1771
- import { lstat as lstat2, mkdir as mkdir2, open, readFile, rename, rm as rm2 } from "node:fs/promises";
1772
- import { join as join2 } from "node:path";
1678
+ import { createHash, randomUUID } from "node:crypto";
1679
+ import { lstat, mkdir, open, readFile, rename, rm } from "node:fs/promises";
1680
+ import { join } from "node:path";
1773
1681
  import { z } from "zod";
1774
1682
  var Document = z.object({
1775
1683
  version: z.literal(1),
@@ -1782,7 +1690,7 @@ var ScheduleDraftStore = class {
1782
1690
  directory;
1783
1691
  #locks = /* @__PURE__ */ new Map();
1784
1692
  #path(sessionId) {
1785
- return join2(this.directory, `${createHash2("sha256").update(sessionId).digest("hex")}.json`);
1693
+ return join(this.directory, `${createHash("sha256").update(sessionId).digest("hex")}.json`);
1786
1694
  }
1787
1695
  async list(sessionId) {
1788
1696
  await this.#locks.get(sessionId);
@@ -1791,7 +1699,7 @@ var ScheduleDraftStore = class {
1791
1699
  async #read(sessionId) {
1792
1700
  try {
1793
1701
  const path = this.#path(sessionId);
1794
- const metadata = await lstat2(path);
1702
+ const metadata = await lstat(path);
1795
1703
  if (metadata.isSymbolicLink() || metadata.size > 8 * 1024 * 1024) throw new Error("Invalid draft document");
1796
1704
  const value = JSON.parse(await readFile(path, "utf8"));
1797
1705
  return Document.parse(value).drafts;
@@ -1803,9 +1711,9 @@ var ScheduleDraftStore = class {
1803
1711
  async update(sessionId, change) {
1804
1712
  const work = (this.#locks.get(sessionId) ?? Promise.resolve()).then(async () => {
1805
1713
  const value = Document.parse({ version: 1, drafts: change(await this.#read(sessionId)) });
1806
- await mkdir2(this.directory, { recursive: true, mode: 448 });
1714
+ await mkdir(this.directory, { recursive: true, mode: 448 });
1807
1715
  const target = this.#path(sessionId);
1808
- const staging = `${target}.${randomUUID2()}.pending`;
1716
+ const staging = `${target}.${randomUUID()}.pending`;
1809
1717
  try {
1810
1718
  const file = await open(staging, "wx", 384);
1811
1719
  try {
@@ -1818,7 +1726,7 @@ var ScheduleDraftStore = class {
1818
1726
  } catch (error) {
1819
1727
  throw new SessionOperationError("SCHEDULE_DRAFT_STORE_UNAVAILABLE", "Schedule drafts could not be saved", { cause: error });
1820
1728
  } finally {
1821
- await rm2(staging, { force: true });
1729
+ await rm(staging, { force: true });
1822
1730
  }
1823
1731
  });
1824
1732
  const settled = work.then(() => void 0, () => void 0);
@@ -1832,7 +1740,7 @@ var ScheduleDraftStore = class {
1832
1740
  async remove(sessionId) {
1833
1741
  const work = (this.#locks.get(sessionId) ?? Promise.resolve()).then(async () => {
1834
1742
  try {
1835
- await rm2(this.#path(sessionId), { force: true });
1743
+ await rm(this.#path(sessionId), { force: true });
1836
1744
  } catch (error) {
1837
1745
  throw new SessionOperationError("SCHEDULE_DRAFT_STORE_UNAVAILABLE", "Schedule drafts could not be removed", { cause: error });
1838
1746
  }
@@ -2104,7 +2012,7 @@ var SessionSchedules = class {
2104
2012
  const { session, connection } = await this.#active(sessionId);
2105
2013
  const proposal = await this.#validate(session, input);
2106
2014
  this.#check(sessionId, connection);
2107
- const draft = { ...proposal, id: randomUUID3(), createdAt: (/* @__PURE__ */ new Date()).toISOString() };
2015
+ const draft = { ...proposal, id: randomUUID2(), createdAt: (/* @__PURE__ */ new Date()).toISOString() };
2108
2016
  await this.#drafts.update(sessionId, (drafts) => {
2109
2017
  this.#check(sessionId, connection);
2110
2018
  if (drafts.length >= 100) throw unavailable("SCHEDULE_DRAFT_LIMIT", "Dismiss an existing draft before proposing another");
@@ -2565,7 +2473,7 @@ var SessionAnalytics = class {
2565
2473
 
2566
2474
  // src/adapters/copilot/interactions/interaction-broker.ts
2567
2475
  import "@github/copilot-sdk";
2568
- import { randomUUID as randomUUID4 } from "node:crypto";
2476
+ import { randomUUID as randomUUID3 } from "node:crypto";
2569
2477
 
2570
2478
  // src/adapters/copilot/interactions/permission-policy.ts
2571
2479
  import "@github/copilot-sdk";
@@ -2865,7 +2773,7 @@ var InteractionBroker = class {
2865
2773
  new Error(`No mobile handler is available for ${request.kind}`)
2866
2774
  );
2867
2775
  }
2868
- const interactionRequestId = randomUUID4();
2776
+ const interactionRequestId = randomUUID3();
2869
2777
  return new Promise((resolve2, reject) => {
2870
2778
  const cancel = () => {
2871
2779
  if (unavailable2 === void 0) {
@@ -3014,7 +2922,7 @@ var InteractionBroker = class {
3014
2922
  }
3015
2923
  );
3016
2924
  }
3017
- const permissionRequestId = randomUUID4();
2925
+ const permissionRequestId = randomUUID3();
3018
2926
  return new Promise((resolve2) => {
3019
2927
  const timer = setTimeout(() => {
3020
2928
  this.#pendingPermissions.delete(permissionRequestId);
@@ -3321,7 +3229,7 @@ var InteractionRequests = class {
3321
3229
  // src/adapters/copilot/interactions/mcp-auth-coordinator.ts
3322
3230
  import "@github/copilot-sdk";
3323
3231
  import { execFile } from "node:child_process";
3324
- import { createHash as createHash3 } from "node:crypto";
3232
+ import { createHash as createHash2 } from "node:crypto";
3325
3233
  import { promisify } from "node:util";
3326
3234
  function deferMcpAuthResponseToRpc() {
3327
3235
  return new Promise(() => {
@@ -3378,7 +3286,7 @@ var McpAuthCoordinator = class {
3378
3286
  (existing?.revision ?? 0) + 1
3379
3287
  );
3380
3288
  const item = ConversationItemSchema.parse({
3381
- id: `mcp-auth:${createHash3("sha256").update(serverName).digest("hex")}`,
3289
+ id: `mcp-auth:${createHash2("sha256").update(serverName).digest("hex")}`,
3382
3290
  kind: "notice",
3383
3291
  revision,
3384
3292
  turnId: existing?.turnId ?? sessionId,
@@ -3535,7 +3443,7 @@ var McpAuthCoordinator = class {
3535
3443
  };
3536
3444
 
3537
3445
  // src/peer-session.ts
3538
- import { randomUUID as randomUUID5 } from "node:crypto";
3446
+ import { randomUUID as randomUUID4 } from "node:crypto";
3539
3447
  import { z as z4 } from "zod";
3540
3448
  var PeerTurnTextSchema = z4.string().min(1).max(16e3).refine((text) => text.trim().length > 0);
3541
3449
  var PeerTurnPromptSchema = z4.string().min(1).max(1e5).refine((text) => text.trim().length > 0);
@@ -3575,7 +3483,7 @@ var PeerSessionTurn = class {
3575
3483
  signal.addEventListener("abort", this.#cancel, { once: true });
3576
3484
  }
3577
3485
  cancelNative;
3578
- source = `agentknight-peer:${randomUUID5()}`;
3486
+ source = `agentknight-peer:${randomUUID4()}`;
3579
3487
  response;
3580
3488
  done = new AbortController();
3581
3489
  inputObserved = false;
@@ -3751,16 +3659,16 @@ function assertCopilotInProcessRuntime() {
3751
3659
  const target = `${platform}-${process.arch}`;
3752
3660
  const files = [];
3753
3661
  if (entrypoint) {
3754
- const directory = dirname2(resolve(entrypoint));
3755
- const adjacent = join3(directory, "runtime.node");
3756
- files.push(existsSync(adjacent) ? adjacent : join3(directory, "prebuilds", target, "runtime.node"));
3662
+ const directory = dirname(resolve(entrypoint));
3663
+ const adjacent = join2(directory, "runtime.node");
3664
+ files.push(existsSync(adjacent) ? adjacent : join2(directory, "prebuilds", target, "runtime.node"));
3757
3665
  } else {
3758
3666
  const sdkRequire = createRequire(require2.resolve("@github/copilot-sdk"));
3759
- const directory = dirname2(sdkRequire.resolve(`@github/copilot-sdk-${target}/package.json`));
3760
- const prebuild = join3(directory, "prebuilds", target);
3667
+ const directory = dirname(sdkRequire.resolve(`@github/copilot-sdk-${target}/package.json`));
3668
+ const prebuild = join2(directory, "prebuilds", target);
3761
3669
  files.push(
3762
- join3(prebuild, "runtime.node"),
3763
- join3(prebuild, process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime")
3670
+ join2(prebuild, "runtime.node"),
3671
+ join2(prebuild, process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime")
3764
3672
  );
3765
3673
  }
3766
3674
  for (const path of files) {
@@ -4794,7 +4702,7 @@ var GithubCopilotAdapter = class {
4794
4702
  if (!models.some((model) => model.id === options.modelId)) {
4795
4703
  throw new Error(`Copilot model is not available: ${options.modelId}`);
4796
4704
  }
4797
- const sessionId = randomUUID6();
4705
+ const sessionId = randomUUID5();
4798
4706
  this.#upgradeSessionIds.add(sessionId);
4799
4707
  this.#upgradeRevision += 1;
4800
4708
  this.#sessions.getOrCreate(sessionId);
@@ -5168,9 +5076,9 @@ var GithubCopilotAdapter = class {
5168
5076
  "Open this session on the paired mobile device before presenting HTML"
5169
5077
  );
5170
5078
  }
5171
- const workspaceRoot = await realpath2(workingDirectory);
5079
+ const workspaceRoot = await realpath(workingDirectory);
5172
5080
  const requestedPath = resolve(workspaceRoot, path);
5173
- const resolvedPath = await realpath2(requestedPath);
5081
+ const resolvedPath = await realpath(requestedPath);
5174
5082
  const relativePath = relative(workspaceRoot, resolvedPath);
5175
5083
  if (relativePath.length === 0 || relativePath.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || relativePath === ".." || isAbsolute(relativePath)) {
5176
5084
  throw new Error("HTML preview path must remain inside the session workspace");
@@ -5193,21 +5101,21 @@ var GithubCopilotAdapter = class {
5193
5101
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
5194
5102
  sourceEventIds: [sourceEventId],
5195
5103
  actor: "assistant",
5196
- content: `HTML preview: ${basename2(resolvedPath)}`,
5104
+ content: `HTML preview: ${basename(resolvedPath)}`,
5197
5105
  attachments: [
5198
5106
  {
5199
5107
  kind: "html",
5200
- name: basename2(resolvedPath),
5108
+ name: basename(resolvedPath),
5201
5109
  mimeType: "text/html",
5202
5110
  data: bytes.toString("base64"),
5203
5111
  byteLength: bytes.byteLength,
5204
- sha256: createHash4("sha256").update(bytes).digest("hex")
5112
+ sha256: createHash3("sha256").update(bytes).digest("hex")
5205
5113
  }
5206
5114
  ],
5207
5115
  final: true
5208
5116
  });
5209
5117
  this.#emitTransientConversationItem(sessionId, item);
5210
- return `Published ${basename2(resolvedPath)} to the AgentKnight session timeline.`;
5118
+ return `Published ${basename(resolvedPath)} to the AgentKnight session timeline.`;
5211
5119
  }
5212
5120
  });
5213
5121
  }
@@ -1,28 +1,29 @@
1
1
  import {
2
2
  AgentSelectionSchema,
3
3
  assertSelectionSnapshotFits
4
- } from "./chunk-SIFCCGXF.js";
4
+ } from "./chunk-LCA2MWOQ.js";
5
5
  import {
6
6
  isResearchSessionId
7
- } from "./chunk-A4YCCQ3I.js";
7
+ } from "./chunk-AWVC5NX4.js";
8
8
  import {
9
9
  GroupChatError
10
- } from "./chunk-ALUQLM54.js";
10
+ } from "./chunk-MB3H6HEI.js";
11
11
  import {
12
12
  AgentModelListingError,
13
13
  AgentSessionRenameError,
14
14
  CODING_AGENT_IDS,
15
+ SessionDeletionRejectedError,
15
16
  UnsupportedAgentOperationError,
16
17
  captureWorkbenchAccess,
17
18
  validateSessionName
18
- } from "./chunk-7CNBPLNE.js";
19
+ } from "./chunk-CFQQOAQV.js";
19
20
  import {
20
21
  SessionOperationError
21
- } from "./chunk-7OGTK7KB.js";
22
+ } from "./chunk-UHRUQM4D.js";
22
23
  import {
23
24
  InteractionResponseSchema,
24
25
  SessionSummarySchema
25
- } from "./chunk-P2PH5KMV.js";
26
+ } from "./chunk-DWTXWVIA.js";
26
27
 
27
28
  // src/managed-agent-adapter.ts
28
29
  import { createHash, randomUUID } from "node:crypto";
@@ -696,27 +697,32 @@ var ManagedCodingAgentAdapter = class {
696
697
  if (!route.runtime.supportsSessionDelete || !route.runtime.deleteSession) {
697
698
  throw new UnsupportedAgentOperationError(route.provider.candidate.id, "session deletion");
698
699
  }
699
- const deleted = /* @__PURE__ */ new Set([...this.#deleted, id]);
700
- await this.#persistFile(this.#deletedPath(), {
701
- version: 1,
702
- deletedSessionIds: [...deleted],
703
- ...this.#confirmedDeleted.size === 0 ? {} : { confirmedDeletedSessionIds: [...this.#confirmedDeleted] }
704
- });
700
+ const previous = this.#deleted;
701
+ const previousEpoch = this.#epoch(id);
702
+ const deleted = /* @__PURE__ */ new Set([...previous, id]);
703
+ await this.#persistDeletions(deleted);
705
704
  this.#deleted = deleted;
706
- this.#epochs.set(id, this.#epoch(id) + 1);
705
+ this.#epochs.set(id, previousEpoch + 1);
707
706
  this.#inventoryChanged();
708
707
  try {
709
708
  this.#assertStarted();
710
709
  if (route.provider.runtime !== route.runtime) throw new Error("Agent disconnected while deleting a session");
711
710
  await route.runtime.deleteSession(route.nativeId);
712
711
  const confirmed = /* @__PURE__ */ new Set([...this.#confirmedDeleted, id]);
713
- await this.#persistFile(this.#deletedPath(), {
714
- version: 1,
715
- deletedSessionIds: [...this.#deleted],
716
- confirmedDeletedSessionIds: [...confirmed]
717
- });
712
+ await this.#persistDeletions(deleted, confirmed);
718
713
  this.#confirmedDeleted = confirmed;
719
714
  } catch (error) {
715
+ if (error instanceof SessionDeletionRejectedError) {
716
+ try {
717
+ await this.#persistDeletions(previous);
718
+ } catch (rollbackError) {
719
+ throw new AggregateError([error, rollbackError], "Unable to restore the managed session after deletion was rejected");
720
+ }
721
+ this.#deleted = previous;
722
+ this.#epochs.set(id, previousEpoch);
723
+ this.#inventoryChanged();
724
+ throw error;
725
+ }
720
726
  await this.#revoke(id);
721
727
  throw error;
722
728
  }
@@ -876,6 +882,13 @@ var ManagedCodingAgentAdapter = class {
876
882
  #deletedPath() {
877
883
  return join(this.#directory, "managed-session-deletions.json");
878
884
  }
885
+ #persistDeletions(deleted, confirmed = this.#confirmedDeleted) {
886
+ return this.#persistFile(this.#deletedPath(), {
887
+ version: 1,
888
+ deletedSessionIds: [...deleted],
889
+ ...confirmed.size === 0 ? {} : { confirmedDeletedSessionIds: [...confirmed] }
890
+ });
891
+ }
879
892
  #owner(id) {
880
893
  const match = managedSessionIdPattern.exec(id);
881
894
  return match ? this.#providers.find((provider) => provider.candidate.id === match[1]) : void 0;
@@ -938,7 +951,7 @@ var ManagedCodingAgentAdapter = class {
938
951
  const available = await provider.candidate.detect();
939
952
  if (!available) {
940
953
  provider.available = false;
941
- provider.error = "Agent is not installed or configured";
954
+ provider.error = void 0;
942
955
  await this.#retire(provider);
943
956
  return;
944
957
  }
@@ -990,11 +1003,7 @@ var ManagedCodingAgentAdapter = class {
990
1003
  }));
991
1004
  this.#assertStarted();
992
1005
  if (confirmed.size !== this.#confirmedDeleted.size) {
993
- await this.#persistFile(this.#deletedPath(), {
994
- version: 1,
995
- deletedSessionIds: [...this.#deleted],
996
- confirmedDeletedSessionIds: [...confirmed]
997
- });
1006
+ await this.#persistDeletions(this.#deleted, confirmed);
998
1007
  this.#confirmedDeleted = confirmed;
999
1008
  this.#inventoryChanged();
1000
1009
  }