@agentknight/sdk 0.9.64 → 0.9.69

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 (29) hide show
  1. package/dist/chunks/{acp-adapter-MBYKOCA2.js → acp-adapter-VJ2OUSBS.js} +41 -4
  2. package/dist/chunks/{chunk-3AMFPDE5.js → chunk-2D34UDII.js} +4 -13
  3. package/dist/chunks/chunk-35OF2ZNS.js +275 -0
  4. package/dist/chunks/{chunk-A4YCCQ3I.js → chunk-5QYL6NKJ.js} +1 -1
  5. package/dist/chunks/chunk-ES2N66EH.js +109 -0
  6. package/dist/chunks/{chunk-P2PH5KMV.js → chunk-F5YCEWE4.js} +9 -0
  7. package/dist/chunks/{chunk-7CNBPLNE.js → chunk-IRYEOV62.js} +5 -2
  8. package/dist/chunks/{chunk-7OGTK7KB.js → chunk-J63A5OLO.js} +1 -1
  9. package/dist/chunks/chunk-LA6A4TUM.js +302 -0
  10. package/dist/chunks/{chunk-ZNQ2I5EF.js → chunk-LU73CEHE.js} +11 -132
  11. package/dist/chunks/chunk-MB34W52S.js +78 -0
  12. package/dist/chunks/{chunk-CHKNC6PD.js → chunk-MH7FDSTY.js} +1 -1
  13. package/dist/chunks/{chunk-ALUQLM54.js → chunk-Q5NNNSU2.js} +2 -2
  14. package/dist/chunks/chunk-UTF7KLMJ.js +11 -0
  15. package/dist/chunks/chunk-WAPJZKUK.js +115 -0
  16. package/dist/chunks/{chunk-SIFCCGXF.js → chunk-ZAU2MYQI.js} +2 -2
  17. package/dist/chunks/{claude-adapter-D3JWXMNX.js → claude-adapter-FZNLF5XN.js} +240 -27
  18. package/dist/chunks/{codex-adapter-655KHW7H.js → codex-adapter-5ZVOAT6O.js} +249 -66
  19. package/dist/chunks/{copilot-adapter-EZUXHBE3.js → copilot-adapter-V6RAQ4WK.js} +58 -149
  20. package/dist/chunks/{managed-agent-adapter-RIXRCURU.js → managed-agent-adapter-THUSTKRW.js} +35 -24
  21. package/dist/chunks/{pi-adapter-LAD5GOCP.js → pi-adapter-EHCSR5I2.js} +329 -54
  22. package/dist/configuration.js +4 -4
  23. package/dist/index.d.ts +15 -8
  24. package/dist/index.js +37 -35
  25. package/dist/runtime.js +2 -2
  26. package/dist/session-analytics-worker.js +6 -5
  27. package/package.json +3 -3
  28. package/dist/chunks/chunk-CM5LVXVL.js +0 -572
  29. package/dist/chunks/chunk-H4SHMWQ6.js +0 -48
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  LiveTimelineProjection,
3
3
  NotGitDirectoryError,
4
- PromptPreparationError,
5
4
  SESSION_PROJECT_IDENTITY_CONCURRENCY,
6
5
  SessionDirectoryLister,
7
6
  SessionProjectIdentityError,
@@ -18,46 +17,54 @@ import {
18
17
  recordTimelineSyncDiagnostic,
19
18
  resolveGitProjectIdentity,
20
19
  sanitizeGitRemoteUrl
21
- } from "./chunk-3AMFPDE5.js";
20
+ } from "./chunk-2D34UDII.js";
22
21
  import "./chunk-IJPJQF7S.js";
23
22
  import {
24
23
  AnalyticsIndexResultSchema,
25
24
  AnalyticsReplySchema,
26
- CopilotSessionCompatibilityClient,
27
25
  openSessionEventLog,
28
- readSessionUpdatePage,
29
- resolveCopilotSessionDirectory,
30
- resumeWithCopilotSessionCompatibility
31
- } from "./chunk-CM5LVXVL.js";
26
+ readSessionUpdatePage
27
+ } from "./chunk-LA6A4TUM.js";
32
28
  import {
33
29
  ConversationNormalizer,
34
30
  isDisplayableHumanMessage
35
- } from "./chunk-ZNQ2I5EF.js";
31
+ } from "./chunk-LU73CEHE.js";
36
32
  import {
37
33
  assertMainSessionId,
38
34
  isResearchSessionId
39
- } from "./chunk-A4YCCQ3I.js";
35
+ } from "./chunk-5QYL6NKJ.js";
40
36
  import {
41
37
  GroupChatError,
42
38
  GroupChatMessageSchema,
43
39
  GroupChatRuntime
44
- } from "./chunk-ALUQLM54.js";
45
- import "./chunk-H4SHMWQ6.js";
40
+ } from "./chunk-Q5NNNSU2.js";
41
+ import {
42
+ PromptPreparationError
43
+ } from "./chunk-UTF7KLMJ.js";
44
+ import {
45
+ deletePromptAttachments,
46
+ stagePromptAttachments,
47
+ validatePromptAttachments
48
+ } from "./chunk-ES2N66EH.js";
49
+ import {
50
+ CopilotSessionCompatibilityClient,
51
+ resolveCopilotSessionDirectory,
52
+ resumeWithCopilotSessionCompatibility
53
+ } from "./chunk-35OF2ZNS.js";
54
+ import "./chunk-WAPJZKUK.js";
46
55
  import {
47
56
  AgentSessionRenameError,
48
57
  TimelinePageBudgetError,
49
58
  validateSessionName
50
- } from "./chunk-7CNBPLNE.js";
59
+ } from "./chunk-IRYEOV62.js";
51
60
  import {
52
61
  SessionOperationError
53
- } from "./chunk-7OGTK7KB.js";
62
+ } from "./chunk-J63A5OLO.js";
54
63
  import {
55
64
  ConversationItemSchema,
56
65
  CopilotModelOptionSchema,
57
66
  CurrentReasoningEffortSchema,
58
67
  InteractionResponseSchema,
59
- PromptFileAttachmentSchema,
60
- PromptImageAttachmentSchema,
61
68
  ReasoningEffortSchema,
62
69
  SESSION_TIMELINE_PAGE_SIZE,
63
70
  SessionAnalyticsResultSchema,
@@ -74,14 +81,14 @@ import {
74
81
  WorkbenchScheduleProposalSchema,
75
82
  WorkbenchScheduleSnapshotSchema,
76
83
  WorkbenchTelemetrySchema
77
- } from "./chunk-P2PH5KMV.js";
84
+ } from "./chunk-F5YCEWE4.js";
78
85
 
79
86
  // src/copilot-adapter.ts
80
- import { createHash as createHash4, randomUUID as randomUUID6 } from "node:crypto";
87
+ import { createHash as createHash3, randomUUID as randomUUID5 } from "node:crypto";
81
88
  import { existsSync, statSync } from "node:fs";
82
- import { readFile as readFile2, realpath as realpath2, stat } from "node:fs/promises";
89
+ import { readFile as readFile2, realpath, stat } from "node:fs/promises";
83
90
  import { createRequire } from "node:module";
84
- import { basename as basename2, dirname as dirname2, extname, isAbsolute, join as join3, relative, resolve } from "node:path";
91
+ import { basename, dirname, extname, isAbsolute, join as join2, relative, resolve } from "node:path";
85
92
 
86
93
  // src/adapters/copilot/runtime/client-runtime.ts
87
94
  var CopilotClientRuntime = class {
@@ -560,104 +567,6 @@ async function applyAvatarPersona(session, persona, busy = false) {
560
567
 
561
568
  // src/adapters/copilot/runtime/session-connections.ts
562
569
  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
570
  var SessionConnections = class {
662
571
  constructor(ports) {
663
572
  this.ports = ports;
@@ -1762,14 +1671,14 @@ import {
1762
1671
  import { z as z5 } from "zod";
1763
1672
 
1764
1673
  // src/session-schedules.ts
1765
- import { randomUUID as randomUUID3 } from "node:crypto";
1674
+ import { randomUUID as randomUUID2 } from "node:crypto";
1766
1675
  import { defineTool } from "@github/copilot-sdk";
1767
1676
  import { z as z3 } from "zod";
1768
1677
 
1769
1678
  // 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";
1679
+ import { createHash, randomUUID } from "node:crypto";
1680
+ import { lstat, mkdir, open, readFile, rename, rm } from "node:fs/promises";
1681
+ import { join } from "node:path";
1773
1682
  import { z } from "zod";
1774
1683
  var Document = z.object({
1775
1684
  version: z.literal(1),
@@ -1782,7 +1691,7 @@ var ScheduleDraftStore = class {
1782
1691
  directory;
1783
1692
  #locks = /* @__PURE__ */ new Map();
1784
1693
  #path(sessionId) {
1785
- return join2(this.directory, `${createHash2("sha256").update(sessionId).digest("hex")}.json`);
1694
+ return join(this.directory, `${createHash("sha256").update(sessionId).digest("hex")}.json`);
1786
1695
  }
1787
1696
  async list(sessionId) {
1788
1697
  await this.#locks.get(sessionId);
@@ -1791,7 +1700,7 @@ var ScheduleDraftStore = class {
1791
1700
  async #read(sessionId) {
1792
1701
  try {
1793
1702
  const path = this.#path(sessionId);
1794
- const metadata = await lstat2(path);
1703
+ const metadata = await lstat(path);
1795
1704
  if (metadata.isSymbolicLink() || metadata.size > 8 * 1024 * 1024) throw new Error("Invalid draft document");
1796
1705
  const value = JSON.parse(await readFile(path, "utf8"));
1797
1706
  return Document.parse(value).drafts;
@@ -1803,9 +1712,9 @@ var ScheduleDraftStore = class {
1803
1712
  async update(sessionId, change) {
1804
1713
  const work = (this.#locks.get(sessionId) ?? Promise.resolve()).then(async () => {
1805
1714
  const value = Document.parse({ version: 1, drafts: change(await this.#read(sessionId)) });
1806
- await mkdir2(this.directory, { recursive: true, mode: 448 });
1715
+ await mkdir(this.directory, { recursive: true, mode: 448 });
1807
1716
  const target = this.#path(sessionId);
1808
- const staging = `${target}.${randomUUID2()}.pending`;
1717
+ const staging = `${target}.${randomUUID()}.pending`;
1809
1718
  try {
1810
1719
  const file = await open(staging, "wx", 384);
1811
1720
  try {
@@ -1818,7 +1727,7 @@ var ScheduleDraftStore = class {
1818
1727
  } catch (error) {
1819
1728
  throw new SessionOperationError("SCHEDULE_DRAFT_STORE_UNAVAILABLE", "Schedule drafts could not be saved", { cause: error });
1820
1729
  } finally {
1821
- await rm2(staging, { force: true });
1730
+ await rm(staging, { force: true });
1822
1731
  }
1823
1732
  });
1824
1733
  const settled = work.then(() => void 0, () => void 0);
@@ -1832,7 +1741,7 @@ var ScheduleDraftStore = class {
1832
1741
  async remove(sessionId) {
1833
1742
  const work = (this.#locks.get(sessionId) ?? Promise.resolve()).then(async () => {
1834
1743
  try {
1835
- await rm2(this.#path(sessionId), { force: true });
1744
+ await rm(this.#path(sessionId), { force: true });
1836
1745
  } catch (error) {
1837
1746
  throw new SessionOperationError("SCHEDULE_DRAFT_STORE_UNAVAILABLE", "Schedule drafts could not be removed", { cause: error });
1838
1747
  }
@@ -2104,7 +2013,7 @@ var SessionSchedules = class {
2104
2013
  const { session, connection } = await this.#active(sessionId);
2105
2014
  const proposal = await this.#validate(session, input);
2106
2015
  this.#check(sessionId, connection);
2107
- const draft = { ...proposal, id: randomUUID3(), createdAt: (/* @__PURE__ */ new Date()).toISOString() };
2016
+ const draft = { ...proposal, id: randomUUID2(), createdAt: (/* @__PURE__ */ new Date()).toISOString() };
2108
2017
  await this.#drafts.update(sessionId, (drafts) => {
2109
2018
  this.#check(sessionId, connection);
2110
2019
  if (drafts.length >= 100) throw unavailable("SCHEDULE_DRAFT_LIMIT", "Dismiss an existing draft before proposing another");
@@ -2565,7 +2474,7 @@ var SessionAnalytics = class {
2565
2474
 
2566
2475
  // src/adapters/copilot/interactions/interaction-broker.ts
2567
2476
  import "@github/copilot-sdk";
2568
- import { randomUUID as randomUUID4 } from "node:crypto";
2477
+ import { randomUUID as randomUUID3 } from "node:crypto";
2569
2478
 
2570
2479
  // src/adapters/copilot/interactions/permission-policy.ts
2571
2480
  import "@github/copilot-sdk";
@@ -2865,7 +2774,7 @@ var InteractionBroker = class {
2865
2774
  new Error(`No mobile handler is available for ${request.kind}`)
2866
2775
  );
2867
2776
  }
2868
- const interactionRequestId = randomUUID4();
2777
+ const interactionRequestId = randomUUID3();
2869
2778
  return new Promise((resolve2, reject) => {
2870
2779
  const cancel = () => {
2871
2780
  if (unavailable2 === void 0) {
@@ -3014,7 +2923,7 @@ var InteractionBroker = class {
3014
2923
  }
3015
2924
  );
3016
2925
  }
3017
- const permissionRequestId = randomUUID4();
2926
+ const permissionRequestId = randomUUID3();
3018
2927
  return new Promise((resolve2) => {
3019
2928
  const timer = setTimeout(() => {
3020
2929
  this.#pendingPermissions.delete(permissionRequestId);
@@ -3321,7 +3230,7 @@ var InteractionRequests = class {
3321
3230
  // src/adapters/copilot/interactions/mcp-auth-coordinator.ts
3322
3231
  import "@github/copilot-sdk";
3323
3232
  import { execFile } from "node:child_process";
3324
- import { createHash as createHash3 } from "node:crypto";
3233
+ import { createHash as createHash2 } from "node:crypto";
3325
3234
  import { promisify } from "node:util";
3326
3235
  function deferMcpAuthResponseToRpc() {
3327
3236
  return new Promise(() => {
@@ -3378,7 +3287,7 @@ var McpAuthCoordinator = class {
3378
3287
  (existing?.revision ?? 0) + 1
3379
3288
  );
3380
3289
  const item = ConversationItemSchema.parse({
3381
- id: `mcp-auth:${createHash3("sha256").update(serverName).digest("hex")}`,
3290
+ id: `mcp-auth:${createHash2("sha256").update(serverName).digest("hex")}`,
3382
3291
  kind: "notice",
3383
3292
  revision,
3384
3293
  turnId: existing?.turnId ?? sessionId,
@@ -3535,7 +3444,7 @@ var McpAuthCoordinator = class {
3535
3444
  };
3536
3445
 
3537
3446
  // src/peer-session.ts
3538
- import { randomUUID as randomUUID5 } from "node:crypto";
3447
+ import { randomUUID as randomUUID4 } from "node:crypto";
3539
3448
  import { z as z4 } from "zod";
3540
3449
  var PeerTurnTextSchema = z4.string().min(1).max(16e3).refine((text) => text.trim().length > 0);
3541
3450
  var PeerTurnPromptSchema = z4.string().min(1).max(1e5).refine((text) => text.trim().length > 0);
@@ -3575,7 +3484,7 @@ var PeerSessionTurn = class {
3575
3484
  signal.addEventListener("abort", this.#cancel, { once: true });
3576
3485
  }
3577
3486
  cancelNative;
3578
- source = `agentknight-peer:${randomUUID5()}`;
3487
+ source = `agentknight-peer:${randomUUID4()}`;
3579
3488
  response;
3580
3489
  done = new AbortController();
3581
3490
  inputObserved = false;
@@ -3751,16 +3660,16 @@ function assertCopilotInProcessRuntime() {
3751
3660
  const target = `${platform}-${process.arch}`;
3752
3661
  const files = [];
3753
3662
  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"));
3663
+ const directory = dirname(resolve(entrypoint));
3664
+ const adjacent = join2(directory, "runtime.node");
3665
+ files.push(existsSync(adjacent) ? adjacent : join2(directory, "prebuilds", target, "runtime.node"));
3757
3666
  } else {
3758
3667
  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);
3668
+ const directory = dirname(sdkRequire.resolve(`@github/copilot-sdk-${target}/package.json`));
3669
+ const prebuild = join2(directory, "prebuilds", target);
3761
3670
  files.push(
3762
- join3(prebuild, "runtime.node"),
3763
- join3(prebuild, process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime")
3671
+ join2(prebuild, "runtime.node"),
3672
+ join2(prebuild, process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime")
3764
3673
  );
3765
3674
  }
3766
3675
  for (const path of files) {
@@ -4794,7 +4703,7 @@ var GithubCopilotAdapter = class {
4794
4703
  if (!models.some((model) => model.id === options.modelId)) {
4795
4704
  throw new Error(`Copilot model is not available: ${options.modelId}`);
4796
4705
  }
4797
- const sessionId = randomUUID6();
4706
+ const sessionId = randomUUID5();
4798
4707
  this.#upgradeSessionIds.add(sessionId);
4799
4708
  this.#upgradeRevision += 1;
4800
4709
  this.#sessions.getOrCreate(sessionId);
@@ -5168,9 +5077,9 @@ var GithubCopilotAdapter = class {
5168
5077
  "Open this session on the paired mobile device before presenting HTML"
5169
5078
  );
5170
5079
  }
5171
- const workspaceRoot = await realpath2(workingDirectory);
5080
+ const workspaceRoot = await realpath(workingDirectory);
5172
5081
  const requestedPath = resolve(workspaceRoot, path);
5173
- const resolvedPath = await realpath2(requestedPath);
5082
+ const resolvedPath = await realpath(requestedPath);
5174
5083
  const relativePath = relative(workspaceRoot, resolvedPath);
5175
5084
  if (relativePath.length === 0 || relativePath.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || relativePath === ".." || isAbsolute(relativePath)) {
5176
5085
  throw new Error("HTML preview path must remain inside the session workspace");
@@ -5193,21 +5102,21 @@ var GithubCopilotAdapter = class {
5193
5102
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
5194
5103
  sourceEventIds: [sourceEventId],
5195
5104
  actor: "assistant",
5196
- content: `HTML preview: ${basename2(resolvedPath)}`,
5105
+ content: `HTML preview: ${basename(resolvedPath)}`,
5197
5106
  attachments: [
5198
5107
  {
5199
5108
  kind: "html",
5200
- name: basename2(resolvedPath),
5109
+ name: basename(resolvedPath),
5201
5110
  mimeType: "text/html",
5202
5111
  data: bytes.toString("base64"),
5203
5112
  byteLength: bytes.byteLength,
5204
- sha256: createHash4("sha256").update(bytes).digest("hex")
5113
+ sha256: createHash3("sha256").update(bytes).digest("hex")
5205
5114
  }
5206
5115
  ],
5207
5116
  final: true
5208
5117
  });
5209
5118
  this.#emitTransientConversationItem(sessionId, item);
5210
- return `Published ${basename2(resolvedPath)} to the AgentKnight session timeline.`;
5119
+ return `Published ${basename(resolvedPath)} to the AgentKnight session timeline.`;
5211
5120
  }
5212
5121
  });
5213
5122
  }
@@ -1,28 +1,29 @@
1
1
  import {
2
2
  AgentSelectionSchema,
3
3
  assertSelectionSnapshotFits
4
- } from "./chunk-SIFCCGXF.js";
4
+ } from "./chunk-ZAU2MYQI.js";
5
5
  import {
6
6
  isResearchSessionId
7
- } from "./chunk-A4YCCQ3I.js";
7
+ } from "./chunk-5QYL6NKJ.js";
8
8
  import {
9
9
  GroupChatError
10
- } from "./chunk-ALUQLM54.js";
10
+ } from "./chunk-Q5NNNSU2.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-IRYEOV62.js";
19
20
  import {
20
21
  SessionOperationError
21
- } from "./chunk-7OGTK7KB.js";
22
+ } from "./chunk-J63A5OLO.js";
22
23
  import {
23
24
  InteractionResponseSchema,
24
25
  SessionSummarySchema
25
- } from "./chunk-P2PH5KMV.js";
26
+ } from "./chunk-F5YCEWE4.js";
26
27
 
27
28
  // src/managed-agent-adapter.ts
28
29
  import { createHash, randomUUID } from "node:crypto";
@@ -393,6 +394,8 @@ var ManagedCodingAgentAdapter = class {
393
394
  const route = this.#route(id);
394
395
  return {
395
396
  supportsFileAttachments: route.runtime.supportsFileAttachments === true,
397
+ supportsImageAttachments: route.runtime.supportsImageAttachments ?? route.runtime.supportsFileAttachments === true,
398
+ supportsSessionDelete: route.runtime.supportsSessionDelete === true && route.runtime.deleteSession !== void 0,
396
399
  ...route.runtime.getSessionCapabilities?.(route.nativeId) ?? {
397
400
  agentModes: route.runtime.agentModes,
398
401
  supportsReasoningEffort: route.runtime.supportsReasoningEffort,
@@ -693,30 +696,35 @@ var ManagedCodingAgentAdapter = class {
693
696
  deleteSession(id) {
694
697
  return this.#exclusive(async () => {
695
698
  const route = this.#route(id);
696
- if (!route.runtime.supportsSessionDelete || !route.runtime.deleteSession) {
699
+ if (!route.runtime.supportsSessionDelete || !route.runtime.deleteSession || route.runtime.getSessionCapabilities?.(route.nativeId).supportsSessionDelete === false) {
697
700
  throw new UnsupportedAgentOperationError(route.provider.candidate.id, "session deletion");
698
701
  }
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
- });
702
+ const previous = this.#deleted;
703
+ const previousEpoch = this.#epoch(id);
704
+ const deleted = /* @__PURE__ */ new Set([...previous, id]);
705
+ await this.#persistDeletions(deleted);
705
706
  this.#deleted = deleted;
706
- this.#epochs.set(id, this.#epoch(id) + 1);
707
+ this.#epochs.set(id, previousEpoch + 1);
707
708
  this.#inventoryChanged();
708
709
  try {
709
710
  this.#assertStarted();
710
711
  if (route.provider.runtime !== route.runtime) throw new Error("Agent disconnected while deleting a session");
711
712
  await route.runtime.deleteSession(route.nativeId);
712
713
  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
- });
714
+ await this.#persistDeletions(deleted, confirmed);
718
715
  this.#confirmedDeleted = confirmed;
719
716
  } catch (error) {
717
+ if (error instanceof SessionDeletionRejectedError) {
718
+ try {
719
+ await this.#persistDeletions(previous);
720
+ } catch (rollbackError) {
721
+ throw new AggregateError([error, rollbackError], "Unable to restore the managed session after deletion was rejected");
722
+ }
723
+ this.#deleted = previous;
724
+ this.#epochs.set(id, previousEpoch);
725
+ this.#inventoryChanged();
726
+ throw error;
727
+ }
720
728
  await this.#revoke(id);
721
729
  throw error;
722
730
  }
@@ -876,6 +884,13 @@ var ManagedCodingAgentAdapter = class {
876
884
  #deletedPath() {
877
885
  return join(this.#directory, "managed-session-deletions.json");
878
886
  }
887
+ #persistDeletions(deleted, confirmed = this.#confirmedDeleted) {
888
+ return this.#persistFile(this.#deletedPath(), {
889
+ version: 1,
890
+ deletedSessionIds: [...deleted],
891
+ ...confirmed.size === 0 ? {} : { confirmedDeletedSessionIds: [...confirmed] }
892
+ });
893
+ }
879
894
  #owner(id) {
880
895
  const match = managedSessionIdPattern.exec(id);
881
896
  return match ? this.#providers.find((provider) => provider.candidate.id === match[1]) : void 0;
@@ -990,11 +1005,7 @@ var ManagedCodingAgentAdapter = class {
990
1005
  }));
991
1006
  this.#assertStarted();
992
1007
  if (confirmed.size !== this.#confirmedDeleted.size) {
993
- await this.#persistFile(this.#deletedPath(), {
994
- version: 1,
995
- deletedSessionIds: [...this.#deleted],
996
- confirmedDeletedSessionIds: [...confirmed]
997
- });
1008
+ await this.#persistDeletions(this.#deleted, confirmed);
998
1009
  this.#confirmedDeleted = confirmed;
999
1010
  this.#inventoryChanged();
1000
1011
  }