@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.
- package/dist/chunks/{acp-adapter-MBYKOCA2.js → acp-adapter-RZX5SUB3.js} +4 -4
- package/dist/chunks/chunk-35OF2ZNS.js +275 -0
- package/dist/chunks/chunk-4XT65OSG.js +72 -0
- package/dist/chunks/{chunk-A4YCCQ3I.js → chunk-AWVC5NX4.js} +1 -1
- package/dist/chunks/chunk-B777YB6E.js +109 -0
- package/dist/chunks/{chunk-7CNBPLNE.js → chunk-CFQQOAQV.js} +5 -2
- package/dist/chunks/{chunk-P2PH5KMV.js → chunk-DWTXWVIA.js} +6 -0
- package/dist/chunks/{chunk-ZNQ2I5EF.js → chunk-EDYVCZIR.js} +11 -132
- package/dist/chunks/{chunk-3AMFPDE5.js → chunk-FY4XTWUF.js} +4 -4
- package/dist/chunks/{chunk-H4SHMWQ6.js → chunk-IXGVSREH.js} +1 -1
- package/dist/chunks/{chunk-SIFCCGXF.js → chunk-LCA2MWOQ.js} +2 -2
- package/dist/chunks/{chunk-ALUQLM54.js → chunk-MB3H6HEI.js} +2 -2
- package/dist/chunks/{chunk-CHKNC6PD.js → chunk-Q5OUZJCZ.js} +1 -1
- package/dist/chunks/{chunk-7OGTK7KB.js → chunk-UHRUQM4D.js} +1 -1
- package/dist/chunks/chunk-VIWTNPVC.js +66 -0
- package/dist/chunks/chunk-Y6NCJB55.js +302 -0
- package/dist/chunks/{claude-adapter-D3JWXMNX.js → claude-adapter-FQSQIYUY.js} +4 -4
- package/dist/chunks/{codex-adapter-655KHW7H.js → codex-adapter-TOXSRT2W.js} +4 -4
- package/dist/chunks/{copilot-adapter-EZUXHBE3.js → copilot-adapter-KUCX7XQW.js} +56 -148
- package/dist/chunks/{managed-agent-adapter-BOJNEJ75.js → managed-agent-adapter-LGBRXDGP.js} +33 -24
- package/dist/chunks/{pi-adapter-LAD5GOCP.js → pi-adapter-RXNZSE4F.js} +330 -53
- package/dist/configuration.js +5 -5
- package/dist/index.js +20 -31
- package/dist/runtime.js +2 -2
- package/dist/session-analytics-worker.js +7 -5
- package/package.json +1 -1
- package/dist/chunks/chunk-CM5LVXVL.js +0 -572
- package/dist/chunks/chunk-XPHAIOKN.js +0 -64
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
latestPreviewItems
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IXGVSREH.js";
|
|
4
4
|
import {
|
|
5
5
|
UnsupportedAgentOperationError
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-CFQQOAQV.js";
|
|
7
|
+
import "./chunk-UHRUQM4D.js";
|
|
8
8
|
import {
|
|
9
9
|
ConversationItemSchema,
|
|
10
10
|
PromptImageAttachmentSchema,
|
|
11
11
|
SESSION_TIMELINE_PAGE_SIZE,
|
|
12
12
|
SessionSummarySchema
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-DWTXWVIA.js";
|
|
14
14
|
|
|
15
15
|
// src/acp-adapter.ts
|
|
16
16
|
import { spawn } from "node:child_process";
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
INLINE_IMAGE_MAX_BYTES
|
|
3
|
+
} from "./chunk-DWTXWVIA.js";
|
|
4
|
+
|
|
5
|
+
// src/timeline-image-content.ts
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
var imageMimeTypes = /* @__PURE__ */ new Set(["image/gif", "image/jpeg", "image/png", "image/webp"]);
|
|
8
|
+
function normalizeImageMimeType(value) {
|
|
9
|
+
const lower = value.toLowerCase();
|
|
10
|
+
return lower === "image/jpg" ? "image/jpeg" : lower;
|
|
11
|
+
}
|
|
12
|
+
function hasImageSignature(bytes, mimeType) {
|
|
13
|
+
switch (mimeType) {
|
|
14
|
+
case "image/png":
|
|
15
|
+
return bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]));
|
|
16
|
+
case "image/jpeg":
|
|
17
|
+
return bytes.subarray(0, 3).equals(Buffer.from([255, 216, 255]));
|
|
18
|
+
case "image/gif":
|
|
19
|
+
return ["GIF87a", "GIF89a"].includes(bytes.subarray(0, 6).toString("ascii"));
|
|
20
|
+
case "image/webp":
|
|
21
|
+
return bytes.subarray(0, 4).toString("ascii") === "RIFF" && bytes.subarray(8, 12).toString("ascii") === "WEBP";
|
|
22
|
+
default:
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function decodeTimelineImage(value, mimeType, source) {
|
|
27
|
+
if (!imageMimeTypes.has(mimeType)) return { failure: { source, reason: "mime-unsupported", mimeType } };
|
|
28
|
+
const dataUrl = /^data:([^;,]+);base64,(.*)$/isu.exec(value);
|
|
29
|
+
const payload = dataUrl?.[2] ?? value;
|
|
30
|
+
if (dataUrl && normalizeImageMimeType(dataUrl[1] ?? "") !== mimeType || !/^[A-Za-z0-9+/_-]+={0,2}$/u.test(payload) || payload.length % 4 === 1) {
|
|
31
|
+
return { failure: { source, reason: "data-invalid", mimeType } };
|
|
32
|
+
}
|
|
33
|
+
const byteLength = Math.floor(payload.replace(/=+$/u, "").length * 3 / 4);
|
|
34
|
+
if (byteLength > INLINE_IMAGE_MAX_BYTES) {
|
|
35
|
+
return { failure: { source, reason: "data-too-large", mimeType, actualByteLength: byteLength } };
|
|
36
|
+
}
|
|
37
|
+
const normalized = payload.replaceAll("-", "+").replaceAll("_", "/");
|
|
38
|
+
const bytes = Buffer.from(normalized, "base64");
|
|
39
|
+
const data = bytes.toString("base64");
|
|
40
|
+
if (data.replace(/=+$/u, "") !== normalized.replace(/=+$/u, "")) {
|
|
41
|
+
return { failure: { source, reason: "data-invalid", mimeType } };
|
|
42
|
+
}
|
|
43
|
+
if (bytes.length === 0) return { failure: { source, reason: "data-empty", mimeType, actualByteLength: 0 } };
|
|
44
|
+
if (!hasImageSignature(bytes, mimeType)) {
|
|
45
|
+
return { failure: { source, reason: "signature-mismatch", mimeType, actualByteLength: bytes.length } };
|
|
46
|
+
}
|
|
47
|
+
return { data, byteLength: bytes.length, sha256: createHash("sha256").update(bytes).digest("hex") };
|
|
48
|
+
}
|
|
49
|
+
function splitTimelineImages(images, size) {
|
|
50
|
+
const groups = [];
|
|
51
|
+
let group = [];
|
|
52
|
+
let bytes = 0;
|
|
53
|
+
for (const image of images) {
|
|
54
|
+
const length = size(image);
|
|
55
|
+
if (group.length > 0 && (group.length >= 4 || bytes + length > INLINE_IMAGE_MAX_BYTES)) {
|
|
56
|
+
groups.push(group);
|
|
57
|
+
group = [];
|
|
58
|
+
bytes = 0;
|
|
59
|
+
}
|
|
60
|
+
group.push(image);
|
|
61
|
+
bytes += length;
|
|
62
|
+
}
|
|
63
|
+
if (group.length > 0) groups.push(group);
|
|
64
|
+
return groups;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
normalizeImageMimeType,
|
|
69
|
+
hasImageSignature,
|
|
70
|
+
decodeTimelineImage,
|
|
71
|
+
splitTimelineImages
|
|
72
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveCopilotSessionDirectory
|
|
3
|
+
} from "./chunk-35OF2ZNS.js";
|
|
4
|
+
import {
|
|
5
|
+
PromptFileAttachmentSchema,
|
|
6
|
+
PromptImageAttachmentSchema
|
|
7
|
+
} from "./chunk-DWTXWVIA.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
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionOperationError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UHRUQM4D.js";
|
|
4
4
|
import {
|
|
5
5
|
SESSION_NAME_MAX_LENGTH,
|
|
6
6
|
SessionNameSchema
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-DWTXWVIA.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
|
|
@@ -3144,6 +3144,11 @@ var WebCopilotRequestSchema = z37.object({
|
|
|
3144
3144
|
proof: MobileIdentityProofSchema,
|
|
3145
3145
|
request: WebCopilotActionSchema
|
|
3146
3146
|
}).strict();
|
|
3147
|
+
var WebCopilotBrowserRequestSchema = z37.object({
|
|
3148
|
+
browserSession: z37.literal(true),
|
|
3149
|
+
userId: z37.string().min(1).max(256),
|
|
3150
|
+
request: WebCopilotActionSchema
|
|
3151
|
+
}).strict();
|
|
3147
3152
|
var WebCopilotDeviceSchema = z37.object({
|
|
3148
3153
|
deviceCode: secret,
|
|
3149
3154
|
userCode: z37.string().regex(/^[A-Z0-9]{4}-[A-Z0-9]{4}$/),
|
|
@@ -3352,6 +3357,7 @@ export {
|
|
|
3352
3357
|
BYTES_PER_KIB,
|
|
3353
3358
|
FILE_TRANSFER_CAPABILITY,
|
|
3354
3359
|
FILE_MAX_BYTES,
|
|
3360
|
+
INLINE_IMAGE_MAX_BYTES,
|
|
3355
3361
|
FILE_TRANSFER_PACKET_BYTES,
|
|
3356
3362
|
IdSchema,
|
|
3357
3363
|
SessionImageStorageSchema,
|