@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,16 +1,22 @@
1
+ import {
2
+ projectNativeImage
3
+ } from "./chunk-MB34W52S.js";
4
+ import "./chunk-UTF7KLMJ.js";
5
+ import "./chunk-ES2N66EH.js";
6
+ import "./chunk-35OF2ZNS.js";
1
7
  import {
2
8
  latestPreviewItems
3
- } from "./chunk-H4SHMWQ6.js";
9
+ } from "./chunk-WAPJZKUK.js";
4
10
  import {
5
11
  UnsupportedAgentOperationError
6
- } from "./chunk-7CNBPLNE.js";
7
- import "./chunk-7OGTK7KB.js";
12
+ } from "./chunk-IRYEOV62.js";
13
+ import "./chunk-J63A5OLO.js";
8
14
  import {
9
15
  ConversationItemSchema,
10
16
  PromptImageAttachmentSchema,
11
17
  SESSION_TIMELINE_PAGE_SIZE,
12
18
  SessionSummarySchema
13
- } from "./chunk-P2PH5KMV.js";
19
+ } from "./chunk-F5YCEWE4.js";
14
20
 
15
21
  // src/acp-adapter.ts
16
22
  import { spawn } from "node:child_process";
@@ -131,6 +137,9 @@ var AcpCodingAgentAdapter = class {
131
137
  get supportsSessionDelete() {
132
138
  return this.#capabilities.sessionCapabilities?.delete != null;
133
139
  }
140
+ get supportsImageAttachments() {
141
+ return this.#capabilities.promptCapabilities?.image === true;
142
+ }
134
143
  async canUpgrade() {
135
144
  return this.#started && !this.#stopping && this.#fatalError === void 0 && this.#permissions.size === 0 && [...this.#sessions.values()].every((session) => session.active === void 0 && session.queue.length === 0 && session.loading === void 0 && !session.writeInProgress && session.persistenceError === void 0 && !session.items.some((item) => item.kind === "activity-group" && item.status === "running"));
136
145
  }
@@ -719,6 +728,10 @@ var AcpCodingAgentAdapter = class {
719
728
  const turnId = session.active?.id;
720
729
  if (!turnId) return;
721
730
  if (update.sessionUpdate === "agent_message_chunk") {
731
+ if (update.content.type === "image") {
732
+ this.#projectImage(session, turnId, update.messageId ?? "message", update.content);
733
+ return;
734
+ }
722
735
  if (update.content.type !== "text") {
723
736
  this.#notice(session, turnId, "warning", "Unsupported agent content", update.content.type);
724
737
  return;
@@ -757,6 +770,13 @@ var AcpCodingAgentAdapter = class {
757
770
  timestamp: step?.timestamp ?? previous?.timestamp ?? base.timestamp
758
771
  }]
759
772
  });
773
+ if (status === "completed") {
774
+ for (const block of update.content ?? []) {
775
+ if (block.type === "content" && block.content.type === "image") {
776
+ this.#projectImage(session, turnId, update.toolCallId, block.content);
777
+ }
778
+ }
779
+ }
760
780
  } else if (update.sessionUpdate === "plan") {
761
781
  const id = hash(`${session.summary.sessionId}:plan`);
762
782
  const previous = session.items.find((item) => item.id === id);
@@ -775,6 +795,23 @@ var AcpCodingAgentAdapter = class {
775
795
  });
776
796
  }
777
797
  }
798
+ #projectImage(session, turnId, source, image) {
799
+ const attachment = projectNativeImage(image.data, image.mimeType);
800
+ if (!attachment) {
801
+ this.#notice(session, turnId, "warning", "Unsupported agent image", "The image format or size is not supported");
802
+ return;
803
+ }
804
+ const id = hash(`${turnId}:image:${source}:${attachment.sha256}`);
805
+ if (session.items.some((item) => item.id === id)) return;
806
+ this.#upsert(session, {
807
+ ...this.#base(id, turnId),
808
+ kind: "assistant-message",
809
+ actor: "assistant",
810
+ content: "",
811
+ final: true,
812
+ attachments: [attachment]
813
+ });
814
+ }
778
815
  #permission(request, signal) {
779
816
  const session = this.#sessions.get(request.sessionId);
780
817
  if (!session?.active || session.active.cancelled || this.#stopping || signal.aborted) {
@@ -6,13 +6,13 @@ import {
6
6
  ConversationNormalizer,
7
7
  ConversationToolLifecycles,
8
8
  assistantMessageId
9
- } from "./chunk-ZNQ2I5EF.js";
9
+ } from "./chunk-LU73CEHE.js";
10
10
  import {
11
11
  isContentfulAssistant
12
- } from "./chunk-H4SHMWQ6.js";
12
+ } from "./chunk-WAPJZKUK.js";
13
13
  import {
14
14
  SessionOperationError
15
- } from "./chunk-7OGTK7KB.js";
15
+ } from "./chunk-J63A5OLO.js";
16
16
  import {
17
17
  IdSchema,
18
18
  SESSION_DIRECTORY_LIST_OPERATION,
@@ -48,7 +48,7 @@ import {
48
48
  WorkbenchReasoningPageSchema,
49
49
  WorkbenchReasoningRequestSchema,
50
50
  isSafeSessionDirectoryPath
51
- } from "./chunk-P2PH5KMV.js";
51
+ } from "./chunk-F5YCEWE4.js";
52
52
 
53
53
  // src/session-image-uploader.ts
54
54
  import { createHash } from "node:crypto";
@@ -1611,14 +1611,6 @@ async function resolveGitProjectIdentity(workingDirectory, env = gitEnvironment(
1611
1611
  };
1612
1612
  }
1613
1613
 
1614
- // src/prompt-preparation-error.ts
1615
- var PromptPreparationError = class extends Error {
1616
- constructor(cause) {
1617
- super(cause instanceof Error ? cause.message : "Prompt preparation failed", { cause });
1618
- this.name = "PromptPreparationError";
1619
- }
1620
- };
1621
-
1622
1614
  // src/session-project-identity.ts
1623
1615
  import { realpath as realpath3, stat as stat2 } from "node:fs/promises";
1624
1616
  import { isAbsolute as isAbsolute3 } from "node:path";
@@ -2371,7 +2363,6 @@ export {
2371
2363
  sanitizeGitRemoteUrl,
2372
2364
  NotGitDirectoryError,
2373
2365
  resolveGitProjectIdentity,
2374
- PromptPreparationError,
2375
2366
  SESSION_PROJECT_IDENTITY_CONCURRENCY,
2376
2367
  SessionProjectIdentityError,
2377
2368
  SessionProjectIdentityReader,
@@ -0,0 +1,275 @@
1
+ // src/copilot-session-compatibility.ts
2
+ import {
3
+ appendFile,
4
+ mkdir,
5
+ readFile,
6
+ readdir,
7
+ rename,
8
+ rm,
9
+ stat,
10
+ writeFile
11
+ } from "node:fs/promises";
12
+ import { homedir } from "node:os";
13
+ import {
14
+ dirname,
15
+ isAbsolute,
16
+ join,
17
+ relative,
18
+ resolve,
19
+ sep
20
+ } from "node:path";
21
+ import {
22
+ CopilotClient
23
+ } from "@github/copilot-sdk";
24
+ import { z } from "zod";
25
+ var SessionIdSchema = z.string().min(1).max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/u);
26
+ var PermissionModeSchema = z.enum(["manual", "allow-all"]);
27
+ var PermissionEventSchema = z.object({
28
+ type: z.literal("session.permissions_changed"),
29
+ data: z.object({
30
+ previousMode: PermissionModeSchema,
31
+ mode: PermissionModeSchema,
32
+ previousAllowAllPermissions: z.boolean().optional(),
33
+ allowAllPermissions: z.boolean().optional()
34
+ }).passthrough()
35
+ }).passthrough();
36
+ var PERMISSION_EVENT_MARKER = '"type":"session.permissions_changed"';
37
+ var PERMISSION_SCHEMA_MISMATCH = /Session file is corrupted \(line \d+: (?:missing field `previousAllowAllPermissions`|(?:data\.)?previousAllowAllPermissions: Required)\)/u;
38
+ var VIRTUAL_SESSION_STATE_PATH = process.platform === "win32" ? "C:\\agentknight-session-state" : "/agentknight-session-state";
39
+ function normalizeCopilotSessionEvents(content) {
40
+ const output = [];
41
+ let migratedEventCount = 0;
42
+ let outputCursor = 0;
43
+ let searchCursor = 0;
44
+ let marker = content.indexOf(PERMISSION_EVENT_MARKER, searchCursor);
45
+ while (marker !== -1) {
46
+ const lineStart = content.lastIndexOf("\n", marker - 1) + 1;
47
+ const nextNewline = content.indexOf("\n", marker);
48
+ const lineEnd = nextNewline === -1 ? content.length : nextNewline;
49
+ const hasCarriageReturn = lineEnd > lineStart && content.charCodeAt(lineEnd - 1) === 13;
50
+ const jsonEnd = hasCarriageReturn ? lineEnd - 1 : lineEnd;
51
+ const parsed = PermissionEventSchema.safeParse(
52
+ JSON.parse(content.slice(lineStart, jsonEnd))
53
+ );
54
+ if (parsed.success && parsed.data.data.previousAllowAllPermissions === void 0 && parsed.data.data.allowAllPermissions === void 0) {
55
+ output.push(
56
+ content.slice(outputCursor, lineStart),
57
+ JSON.stringify({
58
+ ...parsed.data,
59
+ data: {
60
+ ...parsed.data.data,
61
+ previousAllowAllPermissions: parsed.data.data.previousMode === "allow-all",
62
+ allowAllPermissions: parsed.data.data.mode === "allow-all"
63
+ }
64
+ }),
65
+ hasCarriageReturn ? "\r" : ""
66
+ );
67
+ outputCursor = lineEnd;
68
+ migratedEventCount += 1;
69
+ }
70
+ searchCursor = lineEnd;
71
+ marker = content.indexOf(PERMISSION_EVENT_MARKER, searchCursor);
72
+ }
73
+ if (migratedEventCount === 0) {
74
+ return { content, migratedEventCount };
75
+ }
76
+ output.push(content.slice(outputCursor));
77
+ return { content: output.join(""), migratedEventCount };
78
+ }
79
+ async function resumeWithCopilotSessionCompatibility(resume, resumeCompatibleSession) {
80
+ try {
81
+ return await resume();
82
+ } catch (resumeError) {
83
+ if (!(resumeError instanceof Error) || !PERMISSION_SCHEMA_MISMATCH.test(resumeError.message)) {
84
+ throw resumeError;
85
+ }
86
+ return resumeCompatibleSession();
87
+ }
88
+ }
89
+ var CopilotSessionCompatibilityClient = class {
90
+ #environment;
91
+ #workingDirectory;
92
+ #client;
93
+ #starting;
94
+ constructor(environment = process.env, workingDirectory = process.cwd()) {
95
+ this.#environment = environment;
96
+ this.#workingDirectory = workingDirectory;
97
+ }
98
+ async resumeSession(sessionId, config) {
99
+ const safeSessionId = SessionIdSchema.parse(sessionId);
100
+ const client = await this.#getClient();
101
+ return client.resumeSession(safeSessionId, {
102
+ ...config,
103
+ // The overlay provides files only; disabling Session Store avoids routing
104
+ // SQLite through a provider that intentionally does not implement it.
105
+ enableSessionStore: false,
106
+ createSessionFsProvider: () => createLocalSessionProvider(
107
+ safeSessionId,
108
+ this.#environment,
109
+ VIRTUAL_SESSION_STATE_PATH
110
+ )
111
+ });
112
+ }
113
+ async stop() {
114
+ const client = this.#client;
115
+ const starting = this.#starting;
116
+ this.#client = void 0;
117
+ this.#starting = void 0;
118
+ if (client !== void 0) {
119
+ return client.stop();
120
+ }
121
+ if (starting === void 0) {
122
+ return [];
123
+ }
124
+ try {
125
+ return (await starting).stop();
126
+ } catch (error) {
127
+ return [error instanceof Error ? error : new Error(String(error))];
128
+ }
129
+ }
130
+ async forceStop() {
131
+ const client = this.#client;
132
+ const starting = this.#starting;
133
+ this.#client = void 0;
134
+ this.#starting = void 0;
135
+ if (client !== void 0) {
136
+ await client.forceStop();
137
+ } else if (starting !== void 0) {
138
+ await (await starting).forceStop();
139
+ }
140
+ }
141
+ #getClient() {
142
+ if (this.#client !== void 0) {
143
+ return Promise.resolve(this.#client);
144
+ }
145
+ if (this.#starting !== void 0) {
146
+ return this.#starting;
147
+ }
148
+ const client = new CopilotClient({
149
+ mode: "copilot-cli",
150
+ sessionFs: {
151
+ conventions: process.platform === "win32" ? "windows" : "posix",
152
+ initialCwd: this.#workingDirectory,
153
+ sessionStatePath: VIRTUAL_SESSION_STATE_PATH
154
+ }
155
+ });
156
+ const starting = client.start().then(
157
+ () => {
158
+ if (this.#starting === starting) {
159
+ this.#client = client;
160
+ this.#starting = void 0;
161
+ }
162
+ return client;
163
+ },
164
+ async (error) => {
165
+ if (this.#starting === starting) {
166
+ this.#starting = void 0;
167
+ }
168
+ await client.forceStop();
169
+ throw error;
170
+ }
171
+ );
172
+ this.#starting = starting;
173
+ return starting;
174
+ }
175
+ };
176
+ function resolveCopilotSessionDirectory(sessionId, environment = process.env) {
177
+ const safeSessionId = SessionIdSchema.parse(sessionId);
178
+ if (safeSessionId.endsWith(".") || /^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\.|$)/iu.test(safeSessionId)) {
179
+ throw new Error("Expected a safe Copilot session identifier");
180
+ }
181
+ const configuredHome = environment.COPILOT_HOME?.trim();
182
+ const copilotHome = resolve(
183
+ configuredHome === void 0 || configuredHome.length === 0 ? join(homedir(), ".copilot") : configuredHome
184
+ );
185
+ return join(copilotHome, "session-state", safeSessionId);
186
+ }
187
+ function createLocalSessionProvider(sessionId, environment, virtualSessionStatePath) {
188
+ const sessionDirectory = resolveCopilotSessionDirectory(sessionId, environment);
189
+ const virtualRoot = resolve(virtualSessionStatePath);
190
+ const resolveProviderPath = (path) => {
191
+ const resolvedPath = resolve(path);
192
+ const relativeToVirtualRoot = relative(virtualRoot, resolvedPath);
193
+ const isWithinVirtualRoot = relativeToVirtualRoot === "" || !relativeToVirtualRoot.startsWith(`..${sep}`) && relativeToVirtualRoot !== ".." && !isAbsolute(relativeToVirtualRoot);
194
+ const actualPath = isWithinVirtualRoot ? resolve(sessionDirectory, relativeToVirtualRoot) : resolvedPath;
195
+ return {
196
+ actualPath,
197
+ isEventLog: isWithinVirtualRoot && relativeToVirtualRoot.replaceAll("\\", "/") === "events.jsonl"
198
+ };
199
+ };
200
+ return {
201
+ async readFile(path) {
202
+ const resolved = resolveProviderPath(path);
203
+ const content = await readFile(resolved.actualPath, "utf8");
204
+ return resolved.isEventLog ? normalizeCopilotSessionEvents(content).content : content;
205
+ },
206
+ async writeFile(path, content, mode) {
207
+ const { actualPath } = resolveProviderPath(path);
208
+ await mkdir(dirname(actualPath), { recursive: true });
209
+ await writeFile(actualPath, content, { encoding: "utf8", mode });
210
+ },
211
+ async appendFile(path, content, mode) {
212
+ const { actualPath } = resolveProviderPath(path);
213
+ await mkdir(dirname(actualPath), { recursive: true });
214
+ await appendFile(actualPath, content, { encoding: "utf8", mode });
215
+ },
216
+ async exists(path) {
217
+ const { actualPath } = resolveProviderPath(path);
218
+ try {
219
+ await stat(actualPath);
220
+ return true;
221
+ } catch (error) {
222
+ if (isNodeError(error, "ENOENT")) {
223
+ return false;
224
+ }
225
+ throw error;
226
+ }
227
+ },
228
+ async stat(path) {
229
+ const { actualPath } = resolveProviderPath(path);
230
+ const value = await stat(actualPath);
231
+ return {
232
+ isFile: value.isFile(),
233
+ isDirectory: value.isDirectory(),
234
+ size: value.size,
235
+ mtime: value.mtime.toISOString(),
236
+ birthtime: value.birthtime.toISOString()
237
+ };
238
+ },
239
+ async mkdir(path, recursive, mode) {
240
+ const { actualPath } = resolveProviderPath(path);
241
+ await mkdir(actualPath, { recursive, mode });
242
+ },
243
+ async readdir(path) {
244
+ const { actualPath } = resolveProviderPath(path);
245
+ return readdir(actualPath);
246
+ },
247
+ async readdirWithTypes(path) {
248
+ const { actualPath } = resolveProviderPath(path);
249
+ return (await readdir(actualPath, { withFileTypes: true })).map(
250
+ (entry) => ({
251
+ name: entry.name,
252
+ type: entry.isDirectory() ? "directory" : "file"
253
+ })
254
+ );
255
+ },
256
+ async rm(path, recursive, force) {
257
+ const { actualPath } = resolveProviderPath(path);
258
+ await rm(actualPath, { recursive, force });
259
+ },
260
+ async rename(source, destination) {
261
+ const { actualPath: sourcePath } = resolveProviderPath(source);
262
+ const { actualPath: destinationPath } = resolveProviderPath(destination);
263
+ await rename(sourcePath, destinationPath);
264
+ }
265
+ };
266
+ }
267
+ function isNodeError(error, code) {
268
+ return error instanceof Error && "code" in error && error.code === code;
269
+ }
270
+
271
+ export {
272
+ resumeWithCopilotSessionCompatibility,
273
+ CopilotSessionCompatibilityClient,
274
+ resolveCopilotSessionDirectory
275
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SessionOperationError
3
- } from "./chunk-7OGTK7KB.js";
3
+ } from "./chunk-J63A5OLO.js";
4
4
 
5
5
  // src/adapters/copilot/runtime/session-identity.ts
6
6
  function assertMainSessionId(sessionId) {
@@ -0,0 +1,109 @@
1
+ import {
2
+ resolveCopilotSessionDirectory
3
+ } from "./chunk-35OF2ZNS.js";
4
+ import {
5
+ PromptFileAttachmentSchema,
6
+ PromptImageAttachmentSchema
7
+ } from "./chunk-F5YCEWE4.js";
8
+
9
+ // src/prompt-attachments.ts
10
+ import { createHash, randomUUID } from "node:crypto";
11
+ import { lstat, mkdir, realpath, rm, writeFile } from "node:fs/promises";
12
+ import { basename, dirname, join } from "node:path";
13
+ function validatePromptAttachments(images, files) {
14
+ const validateBytes = (attachment) => {
15
+ const bytes = Buffer.from(attachment.data, "base64");
16
+ if (bytes.byteLength !== attachment.byteLength || createHash("sha256").update(bytes).digest("hex") !== attachment.sha256) {
17
+ throw new Error("Attachment failed integrity validation");
18
+ }
19
+ return bytes;
20
+ };
21
+ return {
22
+ images: images.map((input) => {
23
+ const attachment = PromptImageAttachmentSchema.parse(input);
24
+ validateBytes(attachment);
25
+ return {
26
+ type: "blob",
27
+ data: attachment.data,
28
+ mimeType: attachment.mimeType,
29
+ displayName: attachment.name
30
+ };
31
+ }),
32
+ files: files.map((input) => {
33
+ const attachment = PromptFileAttachmentSchema.parse(input);
34
+ return { attachment, bytes: validateBytes(attachment) };
35
+ })
36
+ };
37
+ }
38
+ function hasCode(error, code) {
39
+ return error instanceof Error && "code" in error && error.code === code;
40
+ }
41
+ async function uploadDirectory(sessionDirectory, create) {
42
+ const home = dirname(dirname(sessionDirectory));
43
+ if (create) {
44
+ await mkdir(home, { recursive: true, mode: 448 });
45
+ }
46
+ let directory;
47
+ try {
48
+ directory = await realpath(home);
49
+ } catch (error) {
50
+ if (!create && hasCode(error, "ENOENT")) return void 0;
51
+ throw error;
52
+ }
53
+ for (const segment of [basename(dirname(sessionDirectory)), basename(sessionDirectory), "agentknight-uploads"]) {
54
+ directory = join(directory, segment);
55
+ if (create) {
56
+ try {
57
+ await mkdir(directory, { mode: 448 });
58
+ } catch (error) {
59
+ if (!hasCode(error, "EEXIST")) throw error;
60
+ }
61
+ }
62
+ try {
63
+ const info = await lstat(directory);
64
+ if (info.isSymbolicLink() || !info.isDirectory()) {
65
+ throw new Error("Attachment storage must be a real session directory");
66
+ }
67
+ } catch (error) {
68
+ if (!create && hasCode(error, "ENOENT")) return void 0;
69
+ throw error;
70
+ }
71
+ }
72
+ return directory;
73
+ }
74
+ async function stagePromptAttachments(sessionId, validated, sessionDirectory = resolveCopilotSessionDirectory(sessionId)) {
75
+ if (validated.files.length === 0) return validated.images;
76
+ const root = await uploadDirectory(sessionDirectory, true);
77
+ if (root === void 0) throw new Error("Attachment storage is unavailable");
78
+ const batchDirectory = join(root, randomUUID());
79
+ await mkdir(batchDirectory, { mode: 448 });
80
+ try {
81
+ const attachments = [...validated.images];
82
+ for (const [index, { attachment, bytes }] of validated.files.entries()) {
83
+ const name = attachment.name.replace(/[^a-zA-Z0-9._-]/gu, "_").slice(-100).replace(/[. ]+$/u, "");
84
+ const path = join(batchDirectory, `${index}-${name || "file"}`);
85
+ await writeFile(path, bytes, { flag: "wx", mode: 384, flush: true });
86
+ attachments.push({ type: "file", path, displayName: attachment.name });
87
+ }
88
+ return attachments;
89
+ } catch (error) {
90
+ try {
91
+ await rm(batchDirectory, { recursive: true, force: true });
92
+ } catch (cleanupError) {
93
+ throw new AggregateError([error, cleanupError], "Failed to stage and clean up prompt attachments");
94
+ }
95
+ throw error;
96
+ }
97
+ }
98
+ async function deletePromptAttachments(sessionDirectory) {
99
+ const directory = await uploadDirectory(sessionDirectory, false);
100
+ if (directory !== void 0) {
101
+ await rm(directory, { recursive: true, force: true });
102
+ }
103
+ }
104
+
105
+ export {
106
+ validatePromptAttachments,
107
+ stagePromptAttachments,
108
+ deletePromptAttachments
109
+ };
@@ -66,6 +66,9 @@ var SessionSummarySchema = z4.object({
66
66
  machineId: IdSchema,
67
67
  summary: z4.string().max(4096).optional(),
68
68
  renameSupported: z4.boolean().optional(),
69
+ deleteSupported: z4.boolean().optional(),
70
+ imageAttachmentsSupported: z4.boolean().optional(),
71
+ fileAttachmentsSupported: z4.boolean().optional(),
69
72
  workingDirectory: z4.string().max(32768).optional(),
70
73
  gitRoot: z4.string().max(32768).optional(),
71
74
  repository: z4.string().max(1024).optional(),
@@ -3144,6 +3147,11 @@ var WebCopilotRequestSchema = z37.object({
3144
3147
  proof: MobileIdentityProofSchema,
3145
3148
  request: WebCopilotActionSchema
3146
3149
  }).strict();
3150
+ var WebCopilotBrowserRequestSchema = z37.object({
3151
+ browserSession: z37.literal(true),
3152
+ userId: z37.string().min(1).max(256),
3153
+ request: WebCopilotActionSchema
3154
+ }).strict();
3147
3155
  var WebCopilotDeviceSchema = z37.object({
3148
3156
  deviceCode: secret,
3149
3157
  userCode: z37.string().regex(/^[A-Z0-9]{4}-[A-Z0-9]{4}$/),
@@ -3352,6 +3360,7 @@ export {
3352
3360
  BYTES_PER_KIB,
3353
3361
  FILE_TRANSFER_CAPABILITY,
3354
3362
  FILE_MAX_BYTES,
3363
+ INLINE_IMAGE_MAX_BYTES,
3355
3364
  FILE_TRANSFER_PACKET_BYTES,
3356
3365
  IdSchema,
3357
3366
  SessionImageStorageSchema,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  SessionOperationError
3
- } from "./chunk-7OGTK7KB.js";
3
+ } from "./chunk-J63A5OLO.js";
4
4
  import {
5
5
  SESSION_NAME_MAX_LENGTH,
6
6
  SessionNameSchema
7
- } from "./chunk-P2PH5KMV.js";
7
+ } from "./chunk-F5YCEWE4.js";
8
8
 
9
9
  // src/coding-agent-adapter.ts
10
10
  var CODING_AGENT_IDS = ["copilot", "pi", "codex", "claude", "acp"];
@@ -34,6 +34,8 @@ function captureWorkbenchAccess(adapter, sessionId) {
34
34
  }
35
35
  });
36
36
  }
37
+ var SessionDeletionRejectedError = class extends Error {
38
+ };
37
39
  var UnsupportedAgentOperationError = class extends Error {
38
40
  code = "AGENT_OPERATION_UNSUPPORTED";
39
41
  constructor(agentId, operation) {
@@ -66,6 +68,7 @@ export {
66
68
  AgentModelListingError,
67
69
  captureResearchAccess,
68
70
  captureWorkbenchAccess,
71
+ SessionDeletionRejectedError,
69
72
  UnsupportedAgentOperationError,
70
73
  AgentSessionRenameError,
71
74
  validateSessionName
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SessionCommunicationDataSchema,
3
3
  WorkbenchOperationStatusSchema
4
- } from "./chunk-P2PH5KMV.js";
4
+ } from "./chunk-F5YCEWE4.js";
5
5
 
6
6
  // src/session-operations.ts
7
7
  import { createHash, randomUUID } from "node:crypto";