@agent-dock/cli 0.3.20 → 0.3.21
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/cli.js +128 -58
- package/dist/cli.js.map +3 -3
- package/package.json +1 -1
- package/public/assets/{ImageLightbox-DNsPlO5F.js → ImageLightbox-CAtzWriv.js} +1 -1
- package/public/assets/{PromptEditor-Bcg5vejB.js → PromptEditor-DIIxWw25.js} +1 -1
- package/public/assets/index-DGQnK45p.css +1 -0
- package/public/assets/{main-XEhA7g5W.js → main-DvU2hFvR.js} +92 -92
- package/public/assets/{sourcesRouter-DmdJRaiV.js → sourcesRouter-DMITEG81.js} +1 -1
- package/public/index.html +3 -3
- package/public/sources-router.html +3 -3
- package/public/assets/index-DhsN4eqd.css +0 -1
- /package/public/assets/{index-CvqHQDB3.js → index-ua9DFgh1.js} +0 -0
package/dist/cli.js
CHANGED
|
@@ -6455,13 +6455,13 @@ __export(session_cli_exports, {
|
|
|
6455
6455
|
streamSessionShow: () => streamSessionShow
|
|
6456
6456
|
});
|
|
6457
6457
|
import { existsSync as existsSync10 } from "node:fs";
|
|
6458
|
-
import { join as
|
|
6458
|
+
import { join as join23, resolve as resolve12 } from "node:path";
|
|
6459
6459
|
function resolveDatabasePath(explicit, cwd = process.cwd()) {
|
|
6460
6460
|
if (explicit) return resolve12(cwd, explicit);
|
|
6461
6461
|
if (process.env.AGENTDOCK_DATABASE_URL) return resolve12(cwd, process.env.AGENTDOCK_DATABASE_URL);
|
|
6462
6462
|
const daemonDir = resolveDaemonDir(cwd);
|
|
6463
6463
|
const recorded = readDaemonStatus(daemonDir)?.database;
|
|
6464
|
-
return recorded ? resolve12(daemonDir, recorded) :
|
|
6464
|
+
return recorded ? resolve12(daemonDir, recorded) : join23(daemonDir, "..", "agentdock.db");
|
|
6465
6465
|
}
|
|
6466
6466
|
function sessionPeerIds(sessions2, sourceId2) {
|
|
6467
6467
|
const source2 = sessions2.find((session) => session.id === sourceId2);
|
|
@@ -19982,8 +19982,8 @@ import Fastify from "fastify";
|
|
|
19982
19982
|
import cors from "@fastify/cors";
|
|
19983
19983
|
import { readFile as readFile13, mkdir as mkdir4, readdir as readdir4, rm as rm2, stat as stat6, writeFile as writeFile4 } from "node:fs/promises";
|
|
19984
19984
|
import { Readable as Readable3 } from "node:stream";
|
|
19985
|
-
import { extname as extname2, join as
|
|
19986
|
-
import { homedir as
|
|
19985
|
+
import { extname as extname2, join as join22, resolve as resolve10, sep as sep3 } from "node:path";
|
|
19986
|
+
import { homedir as homedir16 } from "node:os";
|
|
19987
19987
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
19988
19988
|
|
|
19989
19989
|
// src/lark/routes.ts
|
|
@@ -23990,9 +23990,10 @@ function registerTerminalWebSockets(server, runtime, options = {}) {
|
|
|
23990
23990
|
|
|
23991
23991
|
// src/fs-routes.ts
|
|
23992
23992
|
init_src2();
|
|
23993
|
-
import { realpathSync as realpathSync3 } from "node:fs";
|
|
23993
|
+
import { createReadStream, realpathSync as realpathSync3 } from "node:fs";
|
|
23994
23994
|
import { readdir as readdir3, readFile as readFile11, stat as stat5 } from "node:fs/promises";
|
|
23995
|
-
import {
|
|
23995
|
+
import { homedir as homedir13 } from "node:os";
|
|
23996
|
+
import { basename as basename7, isAbsolute as isAbsolute7, join as join19, relative, sep as sep2 } from "node:path";
|
|
23996
23997
|
|
|
23997
23998
|
// src/fs-paths.ts
|
|
23998
23999
|
import { existsSync as existsSync8, realpathSync as realpathSync2 } from "node:fs";
|
|
@@ -24185,13 +24186,18 @@ var textExtensions = /* @__PURE__ */ new Set([
|
|
|
24185
24186
|
".bib"
|
|
24186
24187
|
]);
|
|
24187
24188
|
var imageExtensions = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"]);
|
|
24189
|
+
var videoExtensions = /* @__PURE__ */ new Set([".mp4", ".webm", ".mov", ".m4v", ".ogv"]);
|
|
24190
|
+
var audioExtensions = /* @__PURE__ */ new Set([".mp3", ".wav", ".m4a", ".aac", ".ogg", ".flac", ".opus"]);
|
|
24188
24191
|
var maxTextPreviewBytes = 1024 * 1024;
|
|
24189
24192
|
var maxDocumentPreviewBytes = 20 * 1024 * 1024;
|
|
24193
|
+
var maxMediaPreviewBytes = 500 * 1024 * 1024;
|
|
24190
24194
|
function previewKindForName(name) {
|
|
24191
24195
|
const lower = name.toLowerCase();
|
|
24192
24196
|
const dot = lower.lastIndexOf(".");
|
|
24193
24197
|
const ext = dot >= 0 ? lower.slice(dot) : lower;
|
|
24194
24198
|
if (imageExtensions.has(ext)) return "image";
|
|
24199
|
+
if (videoExtensions.has(ext)) return "video";
|
|
24200
|
+
if (audioExtensions.has(ext)) return "audio";
|
|
24195
24201
|
if (textExtensions.has(ext)) return "text";
|
|
24196
24202
|
if (ext === ".pdf") return "pdf";
|
|
24197
24203
|
return "unsupported";
|
|
@@ -24206,10 +24212,28 @@ var imageMime = {
|
|
|
24206
24212
|
".svg": "image/svg+xml",
|
|
24207
24213
|
".avif": "image/avif"
|
|
24208
24214
|
};
|
|
24215
|
+
var mediaMime = {
|
|
24216
|
+
".mp4": "video/mp4",
|
|
24217
|
+
".webm": "video/webm",
|
|
24218
|
+
".mov": "video/quicktime",
|
|
24219
|
+
".m4v": "video/x-m4v",
|
|
24220
|
+
".ogv": "video/ogg",
|
|
24221
|
+
".mp3": "audio/mpeg",
|
|
24222
|
+
".wav": "audio/wav",
|
|
24223
|
+
".m4a": "audio/mp4",
|
|
24224
|
+
".aac": "audio/aac",
|
|
24225
|
+
".ogg": "audio/ogg",
|
|
24226
|
+
".flac": "audio/flac",
|
|
24227
|
+
".opus": "audio/opus"
|
|
24228
|
+
};
|
|
24209
24229
|
function imageMimeForName(name) {
|
|
24210
24230
|
const dot = name.toLowerCase().lastIndexOf(".");
|
|
24211
24231
|
return dot >= 0 ? imageMime[name.toLowerCase().slice(dot)] : void 0;
|
|
24212
24232
|
}
|
|
24233
|
+
function mediaMimeForName(name) {
|
|
24234
|
+
const dot = name.toLowerCase().lastIndexOf(".");
|
|
24235
|
+
return dot >= 0 ? mediaMime[name.toLowerCase().slice(dot)] : void 0;
|
|
24236
|
+
}
|
|
24213
24237
|
|
|
24214
24238
|
// src/fs-routes.ts
|
|
24215
24239
|
function badPath(error) {
|
|
@@ -24223,6 +24247,28 @@ function contentDispositionAttachment(filename) {
|
|
|
24223
24247
|
const safeAscii = filename.replace(/[^\x20-\x7e]/g, "_").replace(/["\\]/g, "_");
|
|
24224
24248
|
return `attachment; filename="${safeAscii}"; filename*=UTF-8''${encodeURIComponent(filename)}`;
|
|
24225
24249
|
}
|
|
24250
|
+
function parseSingleByteRange(rangeHeader, totalSize) {
|
|
24251
|
+
if (!rangeHeader.startsWith("bytes=")) return void 0;
|
|
24252
|
+
const spec = rangeHeader.slice("bytes=".length).split(",")[0]?.trim();
|
|
24253
|
+
if (!spec) return "invalid";
|
|
24254
|
+
const match = /^(\d*)-(\d*)$/.exec(spec);
|
|
24255
|
+
if (!match) return "invalid";
|
|
24256
|
+
const [, startText, endText] = match;
|
|
24257
|
+
if (!startText && !endText) return "invalid";
|
|
24258
|
+
if (totalSize === 0) return "invalid";
|
|
24259
|
+
if (!startText) {
|
|
24260
|
+
const suffixLength = Number(endText);
|
|
24261
|
+
if (!Number.isFinite(suffixLength) || suffixLength <= 0) return "invalid";
|
|
24262
|
+
const start2 = Math.max(0, totalSize - suffixLength);
|
|
24263
|
+
return { start: start2, end: totalSize - 1 };
|
|
24264
|
+
}
|
|
24265
|
+
const start = Number(startText);
|
|
24266
|
+
const end = endText ? Math.min(Number(endText), totalSize - 1) : totalSize - 1;
|
|
24267
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || start >= totalSize || end < start) {
|
|
24268
|
+
return "invalid";
|
|
24269
|
+
}
|
|
24270
|
+
return { start, end };
|
|
24271
|
+
}
|
|
24226
24272
|
async function registerFsRoutes(app, runtime, options = {}) {
|
|
24227
24273
|
app.get("/api/sessions/:id/fs/list", async (request) => {
|
|
24228
24274
|
const session = await runtime.getSession(request.params.id);
|
|
@@ -24263,31 +24309,30 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24263
24309
|
}
|
|
24264
24310
|
const userPath = request.query.path;
|
|
24265
24311
|
if (!userPath) throw new RuntimeError("INVALID_PATH", "\u7F3A\u5C11 path \u53C2\u6570", 400);
|
|
24266
|
-
|
|
24312
|
+
const expandedPath = userPath.startsWith("~/") ? join19(options.homeDir ?? homedir13(), userPath.slice(2)) : userPath;
|
|
24313
|
+
if (isSensitivePath(userPath) || isSensitivePath(expandedPath)) {
|
|
24267
24314
|
throw new RuntimeError("SENSITIVE_FILE_BLOCKED", "\u7981\u6B62\u9884\u89C8\u6216\u4E0B\u8F7D\u654F\u611F\u6587\u4EF6", 403);
|
|
24268
24315
|
}
|
|
24269
24316
|
const claim = request.webClaim;
|
|
24270
24317
|
const role = claim?.kind === "session" ? "session" : "master";
|
|
24271
24318
|
let resolved;
|
|
24272
24319
|
try {
|
|
24273
|
-
if (isAbsolute7(
|
|
24274
|
-
const realTarget = realpathSync3(
|
|
24275
|
-
|
|
24276
|
-
|
|
24277
|
-
|
|
24278
|
-
|
|
24279
|
-
|
|
24280
|
-
|
|
24281
|
-
|
|
24282
|
-
|
|
24283
|
-
|
|
24284
|
-
|
|
24285
|
-
"FORBIDDEN",
|
|
24286
|
-
|
|
24287
|
-
403
|
|
24288
|
-
);
|
|
24320
|
+
if (isAbsolute7(expandedPath)) {
|
|
24321
|
+
const realTarget = realpathSync3(expandedPath);
|
|
24322
|
+
if (role === "session") {
|
|
24323
|
+
const roots = allowedReadRoots({
|
|
24324
|
+
role,
|
|
24325
|
+
cwd: session.cwd,
|
|
24326
|
+
sessionId: request.params.id,
|
|
24327
|
+
...options.homeDir ? { homeDir: options.homeDir } : {},
|
|
24328
|
+
...options.tempDir ? { tempDir: options.tempDir } : {},
|
|
24329
|
+
...options.extraMasterRoots ? { extraMasterRoots: options.extraMasterRoots } : {}
|
|
24330
|
+
});
|
|
24331
|
+
if (!isRealPathWithinRoots(realTarget, roots)) {
|
|
24332
|
+
throw new RuntimeError("FORBIDDEN", "\u4F1A\u8BDD\u5206\u4EAB\u94FE\u63A5\u53EA\u80FD\u9884\u89C8\u8BE5\u4F1A\u8BDD\u5DE5\u4F5C\u533A\u53CA\u4E0A\u4F20\u76EE\u5F55\u5185\u7684\u6587\u4EF6", 403);
|
|
24333
|
+
}
|
|
24289
24334
|
}
|
|
24290
|
-
let rel =
|
|
24335
|
+
let rel = expandedPath;
|
|
24291
24336
|
try {
|
|
24292
24337
|
const realCwd = realpathSync3(session.cwd);
|
|
24293
24338
|
if (realTarget === realCwd || realTarget.startsWith(`${realCwd}${sep2}`)) {
|
|
@@ -24297,7 +24342,7 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24297
24342
|
}
|
|
24298
24343
|
resolved = { absolute: realTarget, relative: rel };
|
|
24299
24344
|
} else {
|
|
24300
|
-
resolved = resolveExistingInside(session.cwd,
|
|
24345
|
+
resolved = resolveExistingInside(session.cwd, expandedPath);
|
|
24301
24346
|
}
|
|
24302
24347
|
} catch (error) {
|
|
24303
24348
|
badPath(error);
|
|
@@ -24317,22 +24362,47 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24317
24362
|
const wantDownload = request.query.download === "1" || request.query.download === "true";
|
|
24318
24363
|
const wantText = request.query.format === "text";
|
|
24319
24364
|
if (wantDownload) {
|
|
24320
|
-
|
|
24321
|
-
|
|
24322
|
-
|
|
24323
|
-
const buffer2 = await readFile11(resolved.absolute);
|
|
24324
|
-
reply.header("Content-Type", imageMimeForName(filename) ?? (filename.toLowerCase().endsWith(".pdf") ? "application/pdf" : "application/octet-stream"));
|
|
24365
|
+
const contentType = imageMimeForName(filename) ?? mediaMimeForName(filename) ?? (filename.toLowerCase().endsWith(".pdf") ? "application/pdf" : "application/octet-stream");
|
|
24366
|
+
reply.header("Content-Type", contentType);
|
|
24367
|
+
reply.header("Content-Length", String(info.size));
|
|
24325
24368
|
reply.header("Content-Disposition", contentDispositionAttachment(filename));
|
|
24326
24369
|
reply.header("X-Content-Type-Options", "nosniff");
|
|
24327
24370
|
if (isSvg) reply.header("Content-Security-Policy", "sandbox");
|
|
24328
24371
|
reply.header("Cache-Control", "private, no-store");
|
|
24329
|
-
return reply.send(
|
|
24372
|
+
return reply.send(createReadStream(resolved.absolute));
|
|
24330
24373
|
}
|
|
24331
24374
|
const baseKind = previewKindForName(filename);
|
|
24332
24375
|
const effectiveKind = wantText && (baseKind === "text" || isSvg) ? "text" : baseKind;
|
|
24333
24376
|
if (effectiveKind === "unsupported") {
|
|
24334
24377
|
throw new RuntimeError("UNSUPPORTED_PREVIEW", "\u4E0D\u652F\u6301\u9884\u89C8\u7684\u6587\u4EF6\u7C7B\u578B\uFF0C\u8BF7\u5728\u7EC8\u7AEF\u4E2D\u67E5\u770B\u6216\u4E0B\u8F7D", 415);
|
|
24335
24378
|
}
|
|
24379
|
+
if (effectiveKind === "video" || effectiveKind === "audio") {
|
|
24380
|
+
if (info.size > maxMediaPreviewBytes) {
|
|
24381
|
+
throw new RuntimeError("FILE_TOO_LARGE", `\u97F3\u89C6\u9891\u6587\u4EF6\u8D85\u8FC7 500MB \u9884\u89C8\u4E0A\u9650\uFF08\u5B9E\u9645 ${info.size} \u5B57\u8282\uFF09\uFF0C\u8BF7\u4E0B\u8F7D\u6216\u7528\u672C\u673A\u64AD\u653E\u5668\u67E5\u770B`, 415);
|
|
24382
|
+
}
|
|
24383
|
+
const contentType = mediaMimeForName(filename) ?? "application/octet-stream";
|
|
24384
|
+
reply.header("Content-Type", contentType);
|
|
24385
|
+
reply.header("Accept-Ranges", "bytes");
|
|
24386
|
+
reply.header("X-Content-Type-Options", "nosniff");
|
|
24387
|
+
reply.header("Cache-Control", "private, max-age=60");
|
|
24388
|
+
const rangeHeader = typeof request.headers.range === "string" ? request.headers.range : void 0;
|
|
24389
|
+
if (rangeHeader) {
|
|
24390
|
+
const parsed = parseSingleByteRange(rangeHeader, info.size);
|
|
24391
|
+
if (parsed === "invalid") {
|
|
24392
|
+
reply.code(416);
|
|
24393
|
+
reply.header("Content-Range", `bytes */${info.size}`);
|
|
24394
|
+
return reply.send();
|
|
24395
|
+
}
|
|
24396
|
+
if (parsed) {
|
|
24397
|
+
reply.code(206);
|
|
24398
|
+
reply.header("Content-Range", `bytes ${parsed.start}-${parsed.end}/${info.size}`);
|
|
24399
|
+
reply.header("Content-Length", String(parsed.end - parsed.start + 1));
|
|
24400
|
+
return reply.send(createReadStream(resolved.absolute, { start: parsed.start, end: parsed.end }));
|
|
24401
|
+
}
|
|
24402
|
+
}
|
|
24403
|
+
reply.header("Content-Length", String(info.size));
|
|
24404
|
+
return reply.send(createReadStream(resolved.absolute));
|
|
24405
|
+
}
|
|
24336
24406
|
const maxBytes = effectiveKind === "text" ? maxTextPreviewBytes : maxDocumentPreviewBytes;
|
|
24337
24407
|
if (info.size > maxBytes) {
|
|
24338
24408
|
throw new RuntimeError("FILE_TOO_LARGE", `\u6587\u4EF6\u8D85\u8FC7 ${effectiveKind === "text" ? "1MB" : "20MB"} \u9884\u89C8\u4E0A\u9650\uFF08\u5B9E\u9645 ${info.size} \u5B57\u8282\uFF09\uFF0C\u8BF7\u5728\u7EC8\u7AEF\u4E2D\u67E5\u770B\u6216\u4E0B\u8F7D`, 415);
|
|
@@ -24769,8 +24839,8 @@ var LlmClient = class {
|
|
|
24769
24839
|
|
|
24770
24840
|
// src/llm/detect.ts
|
|
24771
24841
|
import { readFile as readFile12 } from "node:fs/promises";
|
|
24772
|
-
import { homedir as
|
|
24773
|
-
import { join as
|
|
24842
|
+
import { homedir as homedir14 } from "node:os";
|
|
24843
|
+
import { join as join20 } from "node:path";
|
|
24774
24844
|
var stringValue = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
24775
24845
|
async function readJson(path5) {
|
|
24776
24846
|
try {
|
|
@@ -24900,9 +24970,9 @@ function codexCandidate(configText, env) {
|
|
|
24900
24970
|
}
|
|
24901
24971
|
async function detectLlmEndpoints(options = {}) {
|
|
24902
24972
|
const env = options.env ?? process.env;
|
|
24903
|
-
const home = options.home ??
|
|
24973
|
+
const home = options.home ?? homedir14();
|
|
24904
24974
|
const candidates = [];
|
|
24905
|
-
const settings = await readJson(
|
|
24975
|
+
const settings = await readJson(join20(home, ".claude", "settings.json"));
|
|
24906
24976
|
const settingsEnv = settings?.env && typeof settings.env === "object" && !Array.isArray(settings.env) ? settings.env : {};
|
|
24907
24977
|
const fromSettings = anthropicCandidate(settingsEnv, settings?.model, "claude-code:settings", "Claude Code\uFF08settings.json\uFF09");
|
|
24908
24978
|
if (fromSettings) candidates.push(fromSettings);
|
|
@@ -24910,7 +24980,7 @@ async function detectLlmEndpoints(options = {}) {
|
|
|
24910
24980
|
if (fromEnv) candidates.push(fromEnv);
|
|
24911
24981
|
const openai = openAiCandidate(env);
|
|
24912
24982
|
if (openai) candidates.push(openai);
|
|
24913
|
-
const codexConfig = await readText(
|
|
24983
|
+
const codexConfig = await readText(join20(home, ".codex", "config.toml"));
|
|
24914
24984
|
if (codexConfig) {
|
|
24915
24985
|
const codex = codexCandidate(codexConfig, env);
|
|
24916
24986
|
if (codex) candidates.push(codex);
|
|
@@ -25140,16 +25210,16 @@ function registerJsonCompression(app, threshold = JSON_COMPRESSION_THRESHOLD) {
|
|
|
25140
25210
|
// src/web-password.ts
|
|
25141
25211
|
import { randomBytes as randomBytes3, scryptSync, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
25142
25212
|
import { chmodSync as chmodSync2, existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25143
|
-
import { homedir as
|
|
25144
|
-
import { dirname as dirname11, join as
|
|
25213
|
+
import { homedir as homedir15 } from "node:os";
|
|
25214
|
+
import { dirname as dirname11, join as join21 } from "node:path";
|
|
25145
25215
|
var webPasswordFileName = "web-password";
|
|
25146
25216
|
var SCRYPT_N = 16384;
|
|
25147
25217
|
var SCRYPT_R = 8;
|
|
25148
25218
|
var SCRYPT_P = 1;
|
|
25149
25219
|
var KEY_LENGTH = 32;
|
|
25150
25220
|
var minWebPasswordLength = 6;
|
|
25151
|
-
function webPasswordPath(home =
|
|
25152
|
-
return
|
|
25221
|
+
function webPasswordPath(home = homedir15()) {
|
|
25222
|
+
return join21(home, ".agentdock", webPasswordFileName);
|
|
25153
25223
|
}
|
|
25154
25224
|
function hashWebPassword(password) {
|
|
25155
25225
|
const salt = randomBytes3(16);
|
|
@@ -25716,7 +25786,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25716
25786
|
"audio/flac": ".flac",
|
|
25717
25787
|
"application/octet-stream": ""
|
|
25718
25788
|
};
|
|
25719
|
-
const globalUploadRoot =
|
|
25789
|
+
const globalUploadRoot = join22(homedir16(), ".agentdock", "uploads");
|
|
25720
25790
|
const uploadTtlMs = 7 * 24 * 60 * 6e4;
|
|
25721
25791
|
const collectExpiredUploads = async (now2 = Date.now()) => {
|
|
25722
25792
|
let removedFiles = 0;
|
|
@@ -25727,7 +25797,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25727
25797
|
return { removedFiles };
|
|
25728
25798
|
}
|
|
25729
25799
|
for (const sessionDir of sessionDirs) {
|
|
25730
|
-
const directory =
|
|
25800
|
+
const directory = join22(globalUploadRoot, sessionDir);
|
|
25731
25801
|
let names;
|
|
25732
25802
|
try {
|
|
25733
25803
|
names = await readdir4(directory);
|
|
@@ -25735,7 +25805,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25735
25805
|
continue;
|
|
25736
25806
|
}
|
|
25737
25807
|
for (const name of names) {
|
|
25738
|
-
const filePath =
|
|
25808
|
+
const filePath = join22(directory, name);
|
|
25739
25809
|
try {
|
|
25740
25810
|
const info = await stat6(filePath);
|
|
25741
25811
|
if (!info.isFile() || now2 - info.mtimeMs <= uploadTtlMs) continue;
|
|
@@ -25781,10 +25851,10 @@ async function buildApp(runtime, options = {}) {
|
|
|
25781
25851
|
originalName = rawName;
|
|
25782
25852
|
}
|
|
25783
25853
|
const ext = extFromContentType(contentType, originalName);
|
|
25784
|
-
const uploadDir =
|
|
25854
|
+
const uploadDir = join22(globalUploadRoot, session.id);
|
|
25785
25855
|
await mkdir4(uploadDir, { recursive: true });
|
|
25786
25856
|
const filename = `${Date.now()}-${randomBytes4(6).toString("hex")}${ext}`;
|
|
25787
|
-
const filePath =
|
|
25857
|
+
const filePath = join22(uploadDir, filename);
|
|
25788
25858
|
await writeFile4(filePath, buffer);
|
|
25789
25859
|
return reply.code(201).send({ path: filePath, url: `/api/sessions/${session.id}/uploads/${filename}`, filename });
|
|
25790
25860
|
});
|
|
@@ -25795,7 +25865,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25795
25865
|
if (filename.includes("..") || filename.includes("/") || filename.includes("\\")) {
|
|
25796
25866
|
throw new RuntimeError("INVALID_UPLOAD", "Invalid filename", 400);
|
|
25797
25867
|
}
|
|
25798
|
-
const filePath =
|
|
25868
|
+
const filePath = join22(globalUploadRoot, session.id, filename);
|
|
25799
25869
|
const ext = extname2(filename).toLowerCase();
|
|
25800
25870
|
const data = await readFile13(filePath);
|
|
25801
25871
|
reply.header("Content-Type", contentTypes[ext] ?? "application/octet-stream");
|
|
@@ -32474,12 +32544,12 @@ function withContext(percent2) {
|
|
|
32474
32544
|
// src/assistant/cwd.ts
|
|
32475
32545
|
init_src2();
|
|
32476
32546
|
import { accessSync as accessSync3, constants as constants6, statSync as statSync6 } from "node:fs";
|
|
32477
|
-
import { homedir as
|
|
32547
|
+
import { homedir as homedir17 } from "node:os";
|
|
32478
32548
|
import { isAbsolute as isAbsolute8, resolve as resolve11 } from "node:path";
|
|
32479
32549
|
function expandHomePath(value) {
|
|
32480
32550
|
const trimmed = value.trim();
|
|
32481
|
-
if (trimmed === "~") return
|
|
32482
|
-
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return resolve11(
|
|
32551
|
+
if (trimmed === "~") return homedir17();
|
|
32552
|
+
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return resolve11(homedir17(), trimmed.slice(2));
|
|
32483
32553
|
return trimmed;
|
|
32484
32554
|
}
|
|
32485
32555
|
function resolveCwdArgument(value, base = process.cwd()) {
|
|
@@ -34986,23 +35056,23 @@ init_session_cli();
|
|
|
34986
35056
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
34987
35057
|
import { chmodSync as chmodSync3, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync13, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
34988
35058
|
import { createServer } from "node:net";
|
|
34989
|
-
import { delimiter as delimiter2, dirname as dirname13, join as
|
|
35059
|
+
import { delimiter as delimiter2, dirname as dirname13, join as join24, resolve as resolve15 } from "node:path";
|
|
34990
35060
|
init_daemon();
|
|
34991
35061
|
var SANDBOX_FILE = "sandbox.json";
|
|
34992
35062
|
function findRepoRoot(start = process.cwd()) {
|
|
34993
35063
|
let dir = resolve15(start);
|
|
34994
35064
|
for (; ; ) {
|
|
34995
|
-
if (existsSync12(
|
|
35065
|
+
if (existsSync12(join24(dir, "apps", "server", "package.json")) && existsSync12(join24(dir, "pnpm-workspace.yaml"))) return dir;
|
|
34996
35066
|
const parent = dirname13(dir);
|
|
34997
35067
|
if (parent === dir) throw new Error("\u627E\u4E0D\u5230 agent-dock \u6E90\u7801\u4ED3\u5E93\u3002\u8BF7\u5728\u4ED3\u5E93\u76EE\u5F55\u4E0B\u8FD0\u884C agent-dock dev\uFF0C\u6216\u7528 --repo \u6307\u5B9A\u3002");
|
|
34998
35068
|
dir = parent;
|
|
34999
35069
|
}
|
|
35000
35070
|
}
|
|
35001
35071
|
function sandboxPaths(repo, port) {
|
|
35002
|
-
const root4 =
|
|
35003
|
-
return { root: root4, home:
|
|
35072
|
+
const root4 = join24(repo, ".agentdock", "dev");
|
|
35073
|
+
return { root: root4, home: join24(root4, "home"), work: join24(root4, "work"), database: join24(root4, "agentdock.db"), entrypoint: join24(repo, "apps", "server", "dist", "cli.js"), port };
|
|
35004
35074
|
}
|
|
35005
|
-
var shimDir = (sandbox) =>
|
|
35075
|
+
var shimDir = (sandbox) => join24(sandbox.root, "bin");
|
|
35006
35076
|
function sandboxEnv(sandbox, base = process.env) {
|
|
35007
35077
|
const env = {
|
|
35008
35078
|
...base,
|
|
@@ -35028,7 +35098,7 @@ function writeCliShim(sandbox, node = process.execPath) {
|
|
|
35028
35098
|
if (process.platform === "win32") {
|
|
35029
35099
|
const quote2 = (path5) => `"${path5.replace(/%/g, "%%")}"`;
|
|
35030
35100
|
writeFileSync5(
|
|
35031
|
-
|
|
35101
|
+
join24(dir, "agent-dock.cmd"),
|
|
35032
35102
|
`@echo off\r
|
|
35033
35103
|
setlocal DisableDelayedExpansion\r
|
|
35034
35104
|
${quote2(node)} ${quote2(sandbox.entrypoint)} %*\r
|
|
@@ -35036,7 +35106,7 @@ ${quote2(node)} ${quote2(sandbox.entrypoint)} %*\r
|
|
|
35036
35106
|
);
|
|
35037
35107
|
return;
|
|
35038
35108
|
}
|
|
35039
|
-
const file =
|
|
35109
|
+
const file = join24(dir, "agent-dock");
|
|
35040
35110
|
writeFileSync5(file, `#!/bin/sh
|
|
35041
35111
|
exec ${shellQuote5(node)} ${shellQuote5(sandbox.entrypoint)} "$@"
|
|
35042
35112
|
`);
|
|
@@ -35044,7 +35114,7 @@ exec ${shellQuote5(node)} ${shellQuote5(sandbox.entrypoint)} "$@"
|
|
|
35044
35114
|
}
|
|
35045
35115
|
function readSandbox(repo) {
|
|
35046
35116
|
try {
|
|
35047
|
-
return JSON.parse(readFileSync13(
|
|
35117
|
+
return JSON.parse(readFileSync13(join24(repo, ".agentdock", "dev", SANDBOX_FILE), "utf8"));
|
|
35048
35118
|
} catch {
|
|
35049
35119
|
return void 0;
|
|
35050
35120
|
}
|
|
@@ -35071,7 +35141,7 @@ async function devUp(options = {}) {
|
|
|
35071
35141
|
const sandbox = sandboxPaths(repo, port);
|
|
35072
35142
|
if (!existsSync12(sandbox.entrypoint)) throw new Error(`\u6CA1\u6709\u6784\u5EFA\u4EA7\u7269\uFF1A${sandbox.entrypoint}\u3002\u5148\u5728\u4ED3\u5E93\u6839\u76EE\u5F55\u8FD0\u884C pnpm build\u3002`);
|
|
35073
35143
|
for (const dir of [sandbox.home, sandbox.work]) mkdirSync6(dir, { recursive: true });
|
|
35074
|
-
writeFileSync5(
|
|
35144
|
+
writeFileSync5(join24(sandbox.root, SANDBOX_FILE), `${JSON.stringify(sandbox, null, 2)}
|
|
35075
35145
|
`);
|
|
35076
35146
|
writeCliShim(sandbox);
|
|
35077
35147
|
const run2 = options.run ?? defaultRun;
|