@agent-dock/cli 0.3.20 → 0.3.22
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 +259 -112
- package/dist/cli.js.map +3 -3
- package/package.json +1 -1
- package/public/assets/{ImageLightbox-DNsPlO5F.js → ImageLightbox-DSVEjfab.js} +1 -1
- package/public/assets/{PromptEditor-Bcg5vejB.js → PromptEditor-B6CITkrn.js} +1 -1
- package/public/assets/index-3nnaeOjV.css +1 -0
- package/public/assets/{main-D9RIexrF.css → main-C2yUVOI3.css} +1 -1
- package/public/assets/{main-XEhA7g5W.js → main-Vf3EflnQ.js} +296 -286
- package/public/assets/{sourcesRouter-DmdJRaiV.js → sourcesRouter-DCf9D_Rs.js} +1 -1
- package/public/index.html +4 -4
- package/public/sources-router.html +3 -3
- package/public/assets/index-DhsN4eqd.css +0 -1
- /package/public/assets/{index-CvqHQDB3.js → index-CWUiS-aC.js} +0 -0
package/dist/cli.js
CHANGED
|
@@ -260,9 +260,9 @@ function normalizeUsageDateBound(raw, endOfDay) {
|
|
|
260
260
|
const parsed = new Date(trimmed);
|
|
261
261
|
return Number.isNaN(parsed.getTime()) ? void 0 : parsed.toISOString();
|
|
262
262
|
}
|
|
263
|
-
function computeTps(outputTokens,
|
|
263
|
+
function computeTps(outputTokens, generationMs) {
|
|
264
264
|
if (!generationMs || !Number.isFinite(generationMs) || generationMs <= 0) return null;
|
|
265
|
-
const generated = Math.max(0, outputTokens)
|
|
265
|
+
const generated = Math.max(0, outputTokens);
|
|
266
266
|
if (generated <= 0) return null;
|
|
267
267
|
return Math.round(generated / (generationMs / 1e3) * 10) / 10;
|
|
268
268
|
}
|
|
@@ -278,7 +278,7 @@ function rowToTotals(row) {
|
|
|
278
278
|
const sessionCount = Number(row?.session_count ?? 0);
|
|
279
279
|
const totalGenerationMs = Number(row?.total_generation_ms ?? 0);
|
|
280
280
|
const totalDurationMs = Number(row?.total_duration_ms ?? 0);
|
|
281
|
-
const avgTps = computeTps(Number(row?.gen_output_tokens ?? 0),
|
|
281
|
+
const avgTps = computeTps(Number(row?.gen_output_tokens ?? 0), totalGenerationMs);
|
|
282
282
|
return {
|
|
283
283
|
inputTokens,
|
|
284
284
|
outputTokens,
|
|
@@ -424,7 +424,7 @@ function createUsageRepository(sqlite) {
|
|
|
424
424
|
durationMs: row.duration_ms,
|
|
425
425
|
generationMs: row.generation_ms,
|
|
426
426
|
ttftMs: row.ttft_ms,
|
|
427
|
-
tps: computeTps(row.output_tokens, row.
|
|
427
|
+
tps: computeTps(row.output_tokens, row.generation_ms),
|
|
428
428
|
createdAt: row.created_at
|
|
429
429
|
}));
|
|
430
430
|
let lastTps = null;
|
|
@@ -614,8 +614,7 @@ var init_usage = __esm({
|
|
|
614
614
|
COUNT(DISTINCT u.session_id) AS session_count,
|
|
615
615
|
COALESCE(SUM(CASE WHEN u.generation_ms > 0 THEN u.generation_ms ELSE 0 END), 0) AS total_generation_ms,
|
|
616
616
|
COALESCE(SUM(CASE WHEN u.duration_ms > 0 THEN u.duration_ms ELSE 0 END), 0) AS total_duration_ms,
|
|
617
|
-
COALESCE(SUM(CASE WHEN u.generation_ms > 0 THEN u.output_tokens ELSE 0 END), 0) AS gen_output_tokens
|
|
618
|
-
COALESCE(SUM(CASE WHEN u.generation_ms > 0 THEN u.thought_tokens ELSE 0 END), 0) AS gen_thought_tokens
|
|
617
|
+
COALESCE(SUM(CASE WHEN u.generation_ms > 0 THEN u.output_tokens ELSE 0 END), 0) AS gen_output_tokens
|
|
619
618
|
`;
|
|
620
619
|
}
|
|
621
620
|
});
|
|
@@ -6455,13 +6454,13 @@ __export(session_cli_exports, {
|
|
|
6455
6454
|
streamSessionShow: () => streamSessionShow
|
|
6456
6455
|
});
|
|
6457
6456
|
import { existsSync as existsSync10 } from "node:fs";
|
|
6458
|
-
import { join as
|
|
6457
|
+
import { join as join23, resolve as resolve12 } from "node:path";
|
|
6459
6458
|
function resolveDatabasePath(explicit, cwd = process.cwd()) {
|
|
6460
6459
|
if (explicit) return resolve12(cwd, explicit);
|
|
6461
6460
|
if (process.env.AGENTDOCK_DATABASE_URL) return resolve12(cwd, process.env.AGENTDOCK_DATABASE_URL);
|
|
6462
6461
|
const daemonDir = resolveDaemonDir(cwd);
|
|
6463
6462
|
const recorded = readDaemonStatus(daemonDir)?.database;
|
|
6464
|
-
return recorded ? resolve12(daemonDir, recorded) :
|
|
6463
|
+
return recorded ? resolve12(daemonDir, recorded) : join23(daemonDir, "..", "agentdock.db");
|
|
6465
6464
|
}
|
|
6466
6465
|
function sessionPeerIds(sessions2, sourceId2) {
|
|
6467
6466
|
const source2 = sessions2.find((session) => session.id === sourceId2);
|
|
@@ -17658,6 +17657,95 @@ var AgentIdleTimeoutError = class extends Error {
|
|
|
17658
17657
|
}
|
|
17659
17658
|
timeoutMs;
|
|
17660
17659
|
};
|
|
17660
|
+
function normalizeAcpxUsageEntry(entry) {
|
|
17661
|
+
const toNonNeg = (value) => {
|
|
17662
|
+
const n = Number(value ?? 0);
|
|
17663
|
+
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
17664
|
+
};
|
|
17665
|
+
const inputTokens = toNonNeg(entry.input_tokens);
|
|
17666
|
+
const rawOutput = toNonNeg(entry.output_tokens);
|
|
17667
|
+
const cacheReadTokens = toNonNeg(entry.cache_read_input_tokens);
|
|
17668
|
+
const cacheWriteTokens = toNonNeg(entry.cache_creation_input_tokens);
|
|
17669
|
+
const thoughtTokens = toNonNeg(entry.thought_tokens);
|
|
17670
|
+
const rawTotal = toNonNeg(entry.total_tokens);
|
|
17671
|
+
const baseSum = inputTokens + rawOutput + cacheReadTokens + cacheWriteTokens;
|
|
17672
|
+
const thoughtExcludedFromOutput = thoughtTokens > 0 && rawTotal > 0 && rawTotal === baseSum + thoughtTokens;
|
|
17673
|
+
const outputTokens = thoughtExcludedFromOutput ? rawOutput + thoughtTokens : rawOutput;
|
|
17674
|
+
const totalTokens = rawTotal > 0 ? rawTotal : inputTokens + outputTokens + cacheReadTokens + cacheWriteTokens;
|
|
17675
|
+
return { inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, thoughtTokens, totalTokens };
|
|
17676
|
+
}
|
|
17677
|
+
var TurnTimingTracker = class {
|
|
17678
|
+
constructor(turnStartedAt) {
|
|
17679
|
+
this.turnStartedAt = turnStartedAt;
|
|
17680
|
+
}
|
|
17681
|
+
turnStartedAt;
|
|
17682
|
+
firstOutputAt;
|
|
17683
|
+
llmActiveMs = 0;
|
|
17684
|
+
activeSegmentStart;
|
|
17685
|
+
activeToolCallIds = /* @__PURE__ */ new Set();
|
|
17686
|
+
pendingPermissionIds = /* @__PURE__ */ new Set();
|
|
17687
|
+
get activeToolCount() {
|
|
17688
|
+
return this.activeToolCallIds.size;
|
|
17689
|
+
}
|
|
17690
|
+
closeSegment(at) {
|
|
17691
|
+
if (this.activeSegmentStart !== void 0) {
|
|
17692
|
+
this.llmActiveMs += Math.max(0, at - this.activeSegmentStart);
|
|
17693
|
+
this.activeSegmentStart = void 0;
|
|
17694
|
+
}
|
|
17695
|
+
}
|
|
17696
|
+
startSegmentIfReady(at) {
|
|
17697
|
+
if (this.activeSegmentStart !== void 0) return;
|
|
17698
|
+
if (this.activeToolCallIds.size > 0 || this.pendingPermissionIds.size > 0) return;
|
|
17699
|
+
this.activeSegmentStart = at;
|
|
17700
|
+
}
|
|
17701
|
+
onPermissionPending(id, at) {
|
|
17702
|
+
this.pendingPermissionIds.add(id);
|
|
17703
|
+
this.closeSegment(at);
|
|
17704
|
+
}
|
|
17705
|
+
onPermissionResolved(id, at) {
|
|
17706
|
+
this.pendingPermissionIds.delete(id);
|
|
17707
|
+
if (this.firstOutputAt !== void 0) this.startSegmentIfReady(at);
|
|
17708
|
+
}
|
|
17709
|
+
onEvent(event, at) {
|
|
17710
|
+
const toolCallId = typeof event.data?.id === "string" ? event.data.id : void 0;
|
|
17711
|
+
if (event.type === "permission_request") {
|
|
17712
|
+
const status = event.data?.status;
|
|
17713
|
+
if (toolCallId && (!status || status === "pending")) this.onPermissionPending(toolCallId, at);
|
|
17714
|
+
return;
|
|
17715
|
+
}
|
|
17716
|
+
if (event.type === "tool_call") {
|
|
17717
|
+
if (this.firstOutputAt === void 0) this.firstOutputAt = at;
|
|
17718
|
+
this.closeSegment(at);
|
|
17719
|
+
if (toolCallId) this.activeToolCallIds.add(toolCallId);
|
|
17720
|
+
return;
|
|
17721
|
+
}
|
|
17722
|
+
if (event.type === "tool_result") {
|
|
17723
|
+
if (toolCallId) {
|
|
17724
|
+
this.activeToolCallIds.delete(toolCallId);
|
|
17725
|
+
this.pendingPermissionIds.delete(toolCallId);
|
|
17726
|
+
} else {
|
|
17727
|
+
this.activeToolCallIds.clear();
|
|
17728
|
+
}
|
|
17729
|
+
if (this.firstOutputAt !== void 0) this.startSegmentIfReady(at);
|
|
17730
|
+
return;
|
|
17731
|
+
}
|
|
17732
|
+
if (event.type === "text" || event.type === "thinking") {
|
|
17733
|
+
if (this.firstOutputAt === void 0) this.firstOutputAt = at;
|
|
17734
|
+
if (this.pendingPermissionIds.size === 0 && this.activeSegmentStart === void 0) {
|
|
17735
|
+
this.activeSegmentStart = at;
|
|
17736
|
+
}
|
|
17737
|
+
}
|
|
17738
|
+
}
|
|
17739
|
+
finish(streamEndedAt, finishedAt = streamEndedAt) {
|
|
17740
|
+
this.closeSegment(streamEndedAt);
|
|
17741
|
+
const durationMs = Math.max(1, finishedAt - this.turnStartedAt);
|
|
17742
|
+
return {
|
|
17743
|
+
durationMs,
|
|
17744
|
+
...this.llmActiveMs > 0 ? { generationMs: Math.min(durationMs, this.llmActiveMs) } : {},
|
|
17745
|
+
...this.firstOutputAt !== void 0 ? { ttftMs: Math.max(0, this.firstOutputAt - this.turnStartedAt) } : {}
|
|
17746
|
+
};
|
|
17747
|
+
}
|
|
17748
|
+
};
|
|
17661
17749
|
var AcpxAdapter = class {
|
|
17662
17750
|
constructor(agent, options) {
|
|
17663
17751
|
this.agent = agent;
|
|
@@ -17691,6 +17779,7 @@ var AcpxAdapter = class {
|
|
|
17691
17779
|
if (this.permissionMode === "full-trust") return { outcome: "allow_once" };
|
|
17692
17780
|
if (this.permissionMode === "deny-all") return { outcome: "reject_once" };
|
|
17693
17781
|
if (this.permissionMode === "approve-reads" && /read|search|fetch/i.test(String(request.inferredKind ?? ""))) return { outcome: "allow_once" };
|
|
17782
|
+
this.activeTiming?.onPermissionPending(id, Date.now());
|
|
17694
17783
|
this.options.onEvent({ type: "permission_request", data: { id, toolCallId: raw.toolCall?.toolCallId, title: raw.toolCall?.title ?? "Permission required", options: raw.options ?? [], status: "pending" } });
|
|
17695
17784
|
return new Promise((resolve17) => this.pendingPermissions.set(id, resolve17));
|
|
17696
17785
|
}
|
|
@@ -17702,6 +17791,7 @@ var AcpxAdapter = class {
|
|
|
17702
17791
|
sessionStore;
|
|
17703
17792
|
handle;
|
|
17704
17793
|
turn;
|
|
17794
|
+
activeTiming;
|
|
17705
17795
|
pendingPermissions = /* @__PURE__ */ new Map();
|
|
17706
17796
|
sessionKey;
|
|
17707
17797
|
reportedTitle;
|
|
@@ -17855,21 +17945,16 @@ var AcpxAdapter = class {
|
|
|
17855
17945
|
for (const key of newKeys) {
|
|
17856
17946
|
const entry = reqMap[key];
|
|
17857
17947
|
if (!entry || typeof entry !== "object") continue;
|
|
17858
|
-
const
|
|
17859
|
-
|
|
17860
|
-
|
|
17861
|
-
|
|
17862
|
-
|
|
17863
|
-
|
|
17864
|
-
|
|
17865
|
-
if (Number.isFinite(out) && out > 0) outputTokens += out;
|
|
17866
|
-
if (Number.isFinite(cRead) && cRead > 0) cacheReadTokens += cRead;
|
|
17867
|
-
if (Number.isFinite(cWrite) && cWrite > 0) cacheWriteTokens += cWrite;
|
|
17868
|
-
if (Number.isFinite(thought) && thought > 0) thoughtTokens += thought;
|
|
17869
|
-
if (Number.isFinite(total) && total > 0) totalTokens += total;
|
|
17948
|
+
const normalized2 = normalizeAcpxUsageEntry(entry);
|
|
17949
|
+
inputTokens += normalized2.inputTokens;
|
|
17950
|
+
outputTokens += normalized2.outputTokens;
|
|
17951
|
+
cacheReadTokens += normalized2.cacheReadTokens;
|
|
17952
|
+
cacheWriteTokens += normalized2.cacheWriteTokens;
|
|
17953
|
+
thoughtTokens += normalized2.thoughtTokens;
|
|
17954
|
+
totalTokens += normalized2.totalTokens;
|
|
17870
17955
|
}
|
|
17871
17956
|
if (totalTokens <= 0 && inputTokens <= 0 && outputTokens <= 0) return;
|
|
17872
|
-
if (totalTokens <= 0) totalTokens = inputTokens + outputTokens + cacheReadTokens + cacheWriteTokens
|
|
17957
|
+
if (totalTokens <= 0) totalTokens = inputTokens + outputTokens + cacheReadTokens + cacheWriteTokens;
|
|
17873
17958
|
const afterCost = typeof record?.cumulative_cost?.amount === "number" && Number.isFinite(record.cumulative_cost.amount) ? record.cumulative_cost.amount : void 0;
|
|
17874
17959
|
const costUsd = afterCost !== void 0 && afterCost > prevCostUsd ? Math.round((afterCost - prevCostUsd) * 1e6) / 1e6 : void 0;
|
|
17875
17960
|
this.options.onEvent({
|
|
@@ -17896,25 +17981,16 @@ var AcpxAdapter = class {
|
|
|
17896
17981
|
const beforeRecord = await this.sessionStore.load(this.sessionKey).catch(() => void 0);
|
|
17897
17982
|
const prevUsageKeys = new Set(Object.keys(beforeRecord?.request_token_usage ?? {}));
|
|
17898
17983
|
const prevCostUsd = typeof beforeRecord?.cumulative_cost?.amount === "number" && Number.isFinite(beforeRecord.cumulative_cost.amount) ? beforeRecord.cumulative_cost.amount : 0;
|
|
17899
|
-
const
|
|
17900
|
-
|
|
17901
|
-
let activeOutputMs = 0;
|
|
17902
|
-
let outputSegmentStart;
|
|
17903
|
-
const closeOutputSegment = (at) => {
|
|
17904
|
-
if (outputSegmentStart !== void 0) {
|
|
17905
|
-
activeOutputMs += Math.max(0, at - outputSegmentStart);
|
|
17906
|
-
outputSegmentStart = void 0;
|
|
17907
|
-
}
|
|
17908
|
-
};
|
|
17984
|
+
const timing = new TurnTimingTracker(Date.now());
|
|
17985
|
+
this.activeTiming = timing;
|
|
17909
17986
|
const { idle: idleTimeoutMs, toolCall: toolCallTimeoutMs } = resolveTurnTimeouts(this.agent.timeout);
|
|
17910
17987
|
const turn = this.runtime.startTurn({ handle: this.handle, text: prompt, mode: "prompt", requestId, timeoutMs: 0 });
|
|
17911
17988
|
this.turn = turn;
|
|
17912
17989
|
try {
|
|
17913
17990
|
const iterator = turn.events[Symbol.asyncIterator]();
|
|
17914
|
-
const activeToolCallIds = /* @__PURE__ */ new Set();
|
|
17915
17991
|
while (true) {
|
|
17916
17992
|
let timer;
|
|
17917
|
-
const effectiveTimeout =
|
|
17993
|
+
const effectiveTimeout = timing.activeToolCount > 0 ? toolCallTimeoutMs : idleTimeoutMs;
|
|
17918
17994
|
const idle = new Promise((_resolve, reject2) => {
|
|
17919
17995
|
timer = setTimeout(() => reject2(new AgentIdleTimeoutError(effectiveTimeout)), effectiveTimeout);
|
|
17920
17996
|
});
|
|
@@ -17933,35 +18009,20 @@ var AcpxAdapter = class {
|
|
|
17933
18009
|
if (next.done) break;
|
|
17934
18010
|
const normalized2 = normalizeAcpxEvent(next.value);
|
|
17935
18011
|
if (normalized2) {
|
|
17936
|
-
|
|
17937
|
-
const toolCallId = typeof normalized2.data?.id === "string" ? normalized2.data.id : void 0;
|
|
17938
|
-
if (normalized2.type === "tool_call") {
|
|
17939
|
-
if (activeToolCallIds.size === 0) closeOutputSegment(eventAt);
|
|
17940
|
-
if (toolCallId) activeToolCallIds.add(toolCallId);
|
|
17941
|
-
} else if (normalized2.type === "tool_result") {
|
|
17942
|
-
if (toolCallId) activeToolCallIds.delete(toolCallId);
|
|
17943
|
-
else activeToolCallIds.clear();
|
|
17944
|
-
} else if ((normalized2.type === "text" || normalized2.type === "thinking") && activeToolCallIds.size === 0) {
|
|
17945
|
-
if (firstOutputAt === void 0) firstOutputAt = eventAt;
|
|
17946
|
-
if (outputSegmentStart === void 0) outputSegmentStart = eventAt;
|
|
17947
|
-
}
|
|
18012
|
+
timing.onEvent(normalized2, Date.now());
|
|
17948
18013
|
this.options.onEvent(normalized2);
|
|
17949
18014
|
}
|
|
17950
18015
|
}
|
|
17951
18016
|
const streamEndedAt = Date.now();
|
|
17952
|
-
closeOutputSegment(streamEndedAt);
|
|
17953
18017
|
const result = await turn.result;
|
|
17954
18018
|
if (result.status === "failed") throw new Error(result.error.message);
|
|
17955
18019
|
const finishedAt = Date.now();
|
|
17956
18020
|
await this.reportAgentTitle();
|
|
17957
|
-
await this.reportTurnUsage(prevUsageKeys, prevCostUsd, requestId,
|
|
17958
|
-
durationMs: Math.max(1, finishedAt - turnStartedAt),
|
|
17959
|
-
...activeOutputMs > 0 ? { generationMs: activeOutputMs } : {},
|
|
17960
|
-
...firstOutputAt !== void 0 ? { ttftMs: Math.max(0, firstOutputAt - turnStartedAt) } : {}
|
|
17961
|
-
});
|
|
18021
|
+
await this.reportTurnUsage(prevUsageKeys, prevCostUsd, requestId, timing.finish(streamEndedAt, finishedAt));
|
|
17962
18022
|
this.options.onEvent({ type: "completed", data: { stopReason: result.stopReason ?? result.status } });
|
|
17963
18023
|
} finally {
|
|
17964
18024
|
if (this.turn === turn) this.turn = void 0;
|
|
18025
|
+
if (this.activeTiming === timing) this.activeTiming = void 0;
|
|
17965
18026
|
}
|
|
17966
18027
|
}
|
|
17967
18028
|
async send(prompt) {
|
|
@@ -18002,6 +18063,7 @@ var AcpxAdapter = class {
|
|
|
18002
18063
|
const resolve17 = this.pendingPermissions.get(id);
|
|
18003
18064
|
if (!resolve17) return false;
|
|
18004
18065
|
this.pendingPermissions.delete(id);
|
|
18066
|
+
this.activeTiming?.onPermissionResolved(id, Date.now());
|
|
18005
18067
|
resolve17({ outcome: approved ? "allow_once" : "reject_once" });
|
|
18006
18068
|
return true;
|
|
18007
18069
|
}
|
|
@@ -19982,8 +20044,8 @@ import Fastify from "fastify";
|
|
|
19982
20044
|
import cors from "@fastify/cors";
|
|
19983
20045
|
import { readFile as readFile13, mkdir as mkdir4, readdir as readdir4, rm as rm2, stat as stat6, writeFile as writeFile4 } from "node:fs/promises";
|
|
19984
20046
|
import { Readable as Readable3 } from "node:stream";
|
|
19985
|
-
import { extname as extname2, join as
|
|
19986
|
-
import { homedir as
|
|
20047
|
+
import { extname as extname2, join as join22, resolve as resolve10, sep as sep3 } from "node:path";
|
|
20048
|
+
import { homedir as homedir16 } from "node:os";
|
|
19987
20049
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
19988
20050
|
|
|
19989
20051
|
// src/lark/routes.ts
|
|
@@ -22750,8 +22812,10 @@ var toNonNegInt = (value) => {
|
|
|
22750
22812
|
const num = Number(value ?? 0);
|
|
22751
22813
|
return Number.isFinite(num) && num > 0 ? Math.round(num) : 0;
|
|
22752
22814
|
};
|
|
22753
|
-
function createUsageBackfiller(target) {
|
|
22815
|
+
function createUsageBackfiller(target, options = {}) {
|
|
22754
22816
|
const scannedMtime = /* @__PURE__ */ new Map();
|
|
22817
|
+
const minIntervalMs = Math.max(0, options.minIntervalMs ?? 6e4);
|
|
22818
|
+
let lastSyncedAt = 0;
|
|
22755
22819
|
let inFlight5;
|
|
22756
22820
|
async function runOnce() {
|
|
22757
22821
|
const sessions2 = await target.listSessions();
|
|
@@ -22779,12 +22843,14 @@ function createUsageBackfiller(target) {
|
|
|
22779
22843
|
if (!reqMap || typeof reqMap !== "object") continue;
|
|
22780
22844
|
const entries = Object.entries(reqMap).map(([requestId, raw]) => {
|
|
22781
22845
|
const inputTokens = toNonNegInt(raw?.input_tokens);
|
|
22782
|
-
const
|
|
22846
|
+
const rawOutput = toNonNegInt(raw?.output_tokens);
|
|
22783
22847
|
const cacheReadTokens = toNonNegInt(raw?.cache_read_input_tokens);
|
|
22784
22848
|
const cacheWriteTokens = toNonNegInt(raw?.cache_creation_input_tokens);
|
|
22785
22849
|
const thoughtTokens = toNonNegInt(raw?.thought_tokens);
|
|
22786
22850
|
const rawTotal = toNonNegInt(raw?.total_tokens);
|
|
22787
|
-
const
|
|
22851
|
+
const baseSum = inputTokens + rawOutput + cacheReadTokens + cacheWriteTokens;
|
|
22852
|
+
const outputTokens = thoughtTokens > 0 && rawTotal > 0 && rawTotal === baseSum + thoughtTokens ? rawOutput + thoughtTokens : rawOutput;
|
|
22853
|
+
const totalTokens = rawTotal > 0 ? rawTotal : inputTokens + outputTokens + cacheReadTokens + cacheWriteTokens;
|
|
22788
22854
|
return { requestId, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, thoughtTokens, totalTokens };
|
|
22789
22855
|
}).filter((item) => item.totalTokens > 0 || item.inputTokens > 0 || item.outputTokens > 0);
|
|
22790
22856
|
if (!entries.length) continue;
|
|
@@ -22820,9 +22886,12 @@ function createUsageBackfiller(target) {
|
|
|
22820
22886
|
return inserted;
|
|
22821
22887
|
}
|
|
22822
22888
|
return {
|
|
22823
|
-
async sync() {
|
|
22889
|
+
async sync(force = false) {
|
|
22890
|
+
const nowMs = Date.now();
|
|
22891
|
+
if (!force && lastSyncedAt > 0 && nowMs - lastSyncedAt < minIntervalMs) return 0;
|
|
22824
22892
|
if (!inFlight5) {
|
|
22825
22893
|
inFlight5 = runOnce().finally(() => {
|
|
22894
|
+
lastSyncedAt = Date.now();
|
|
22826
22895
|
inFlight5 = void 0;
|
|
22827
22896
|
});
|
|
22828
22897
|
}
|
|
@@ -23990,9 +24059,10 @@ function registerTerminalWebSockets(server, runtime, options = {}) {
|
|
|
23990
24059
|
|
|
23991
24060
|
// src/fs-routes.ts
|
|
23992
24061
|
init_src2();
|
|
23993
|
-
import { realpathSync as realpathSync3 } from "node:fs";
|
|
24062
|
+
import { createReadStream, realpathSync as realpathSync3 } from "node:fs";
|
|
23994
24063
|
import { readdir as readdir3, readFile as readFile11, stat as stat5 } from "node:fs/promises";
|
|
23995
|
-
import {
|
|
24064
|
+
import { homedir as homedir13 } from "node:os";
|
|
24065
|
+
import { basename as basename7, isAbsolute as isAbsolute7, join as join19, relative, sep as sep2 } from "node:path";
|
|
23996
24066
|
|
|
23997
24067
|
// src/fs-paths.ts
|
|
23998
24068
|
import { existsSync as existsSync8, realpathSync as realpathSync2 } from "node:fs";
|
|
@@ -24185,13 +24255,18 @@ var textExtensions = /* @__PURE__ */ new Set([
|
|
|
24185
24255
|
".bib"
|
|
24186
24256
|
]);
|
|
24187
24257
|
var imageExtensions = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"]);
|
|
24258
|
+
var videoExtensions = /* @__PURE__ */ new Set([".mp4", ".webm", ".mov", ".m4v", ".ogv"]);
|
|
24259
|
+
var audioExtensions = /* @__PURE__ */ new Set([".mp3", ".wav", ".m4a", ".aac", ".ogg", ".flac", ".opus"]);
|
|
24188
24260
|
var maxTextPreviewBytes = 1024 * 1024;
|
|
24189
24261
|
var maxDocumentPreviewBytes = 20 * 1024 * 1024;
|
|
24262
|
+
var maxMediaPreviewBytes = 500 * 1024 * 1024;
|
|
24190
24263
|
function previewKindForName(name) {
|
|
24191
24264
|
const lower = name.toLowerCase();
|
|
24192
24265
|
const dot = lower.lastIndexOf(".");
|
|
24193
24266
|
const ext = dot >= 0 ? lower.slice(dot) : lower;
|
|
24194
24267
|
if (imageExtensions.has(ext)) return "image";
|
|
24268
|
+
if (videoExtensions.has(ext)) return "video";
|
|
24269
|
+
if (audioExtensions.has(ext)) return "audio";
|
|
24195
24270
|
if (textExtensions.has(ext)) return "text";
|
|
24196
24271
|
if (ext === ".pdf") return "pdf";
|
|
24197
24272
|
return "unsupported";
|
|
@@ -24206,10 +24281,28 @@ var imageMime = {
|
|
|
24206
24281
|
".svg": "image/svg+xml",
|
|
24207
24282
|
".avif": "image/avif"
|
|
24208
24283
|
};
|
|
24284
|
+
var mediaMime = {
|
|
24285
|
+
".mp4": "video/mp4",
|
|
24286
|
+
".webm": "video/webm",
|
|
24287
|
+
".mov": "video/quicktime",
|
|
24288
|
+
".m4v": "video/x-m4v",
|
|
24289
|
+
".ogv": "video/ogg",
|
|
24290
|
+
".mp3": "audio/mpeg",
|
|
24291
|
+
".wav": "audio/wav",
|
|
24292
|
+
".m4a": "audio/mp4",
|
|
24293
|
+
".aac": "audio/aac",
|
|
24294
|
+
".ogg": "audio/ogg",
|
|
24295
|
+
".flac": "audio/flac",
|
|
24296
|
+
".opus": "audio/opus"
|
|
24297
|
+
};
|
|
24209
24298
|
function imageMimeForName(name) {
|
|
24210
24299
|
const dot = name.toLowerCase().lastIndexOf(".");
|
|
24211
24300
|
return dot >= 0 ? imageMime[name.toLowerCase().slice(dot)] : void 0;
|
|
24212
24301
|
}
|
|
24302
|
+
function mediaMimeForName(name) {
|
|
24303
|
+
const dot = name.toLowerCase().lastIndexOf(".");
|
|
24304
|
+
return dot >= 0 ? mediaMime[name.toLowerCase().slice(dot)] : void 0;
|
|
24305
|
+
}
|
|
24213
24306
|
|
|
24214
24307
|
// src/fs-routes.ts
|
|
24215
24308
|
function badPath(error) {
|
|
@@ -24223,6 +24316,28 @@ function contentDispositionAttachment(filename) {
|
|
|
24223
24316
|
const safeAscii = filename.replace(/[^\x20-\x7e]/g, "_").replace(/["\\]/g, "_");
|
|
24224
24317
|
return `attachment; filename="${safeAscii}"; filename*=UTF-8''${encodeURIComponent(filename)}`;
|
|
24225
24318
|
}
|
|
24319
|
+
function parseSingleByteRange(rangeHeader, totalSize) {
|
|
24320
|
+
if (!rangeHeader.startsWith("bytes=")) return void 0;
|
|
24321
|
+
const spec = rangeHeader.slice("bytes=".length).split(",")[0]?.trim();
|
|
24322
|
+
if (!spec) return "invalid";
|
|
24323
|
+
const match = /^(\d*)-(\d*)$/.exec(spec);
|
|
24324
|
+
if (!match) return "invalid";
|
|
24325
|
+
const [, startText, endText] = match;
|
|
24326
|
+
if (!startText && !endText) return "invalid";
|
|
24327
|
+
if (totalSize === 0) return "invalid";
|
|
24328
|
+
if (!startText) {
|
|
24329
|
+
const suffixLength = Number(endText);
|
|
24330
|
+
if (!Number.isFinite(suffixLength) || suffixLength <= 0) return "invalid";
|
|
24331
|
+
const start2 = Math.max(0, totalSize - suffixLength);
|
|
24332
|
+
return { start: start2, end: totalSize - 1 };
|
|
24333
|
+
}
|
|
24334
|
+
const start = Number(startText);
|
|
24335
|
+
const end = endText ? Math.min(Number(endText), totalSize - 1) : totalSize - 1;
|
|
24336
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || start >= totalSize || end < start) {
|
|
24337
|
+
return "invalid";
|
|
24338
|
+
}
|
|
24339
|
+
return { start, end };
|
|
24340
|
+
}
|
|
24226
24341
|
async function registerFsRoutes(app, runtime, options = {}) {
|
|
24227
24342
|
app.get("/api/sessions/:id/fs/list", async (request) => {
|
|
24228
24343
|
const session = await runtime.getSession(request.params.id);
|
|
@@ -24263,31 +24378,30 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24263
24378
|
}
|
|
24264
24379
|
const userPath = request.query.path;
|
|
24265
24380
|
if (!userPath) throw new RuntimeError("INVALID_PATH", "\u7F3A\u5C11 path \u53C2\u6570", 400);
|
|
24266
|
-
|
|
24381
|
+
const expandedPath = userPath.startsWith("~/") ? join19(options.homeDir ?? homedir13(), userPath.slice(2)) : userPath;
|
|
24382
|
+
if (isSensitivePath(userPath) || isSensitivePath(expandedPath)) {
|
|
24267
24383
|
throw new RuntimeError("SENSITIVE_FILE_BLOCKED", "\u7981\u6B62\u9884\u89C8\u6216\u4E0B\u8F7D\u654F\u611F\u6587\u4EF6", 403);
|
|
24268
24384
|
}
|
|
24269
24385
|
const claim = request.webClaim;
|
|
24270
24386
|
const role = claim?.kind === "session" ? "session" : "master";
|
|
24271
24387
|
let resolved;
|
|
24272
24388
|
try {
|
|
24273
|
-
if (isAbsolute7(
|
|
24274
|
-
const realTarget = realpathSync3(
|
|
24275
|
-
|
|
24276
|
-
|
|
24277
|
-
|
|
24278
|
-
|
|
24279
|
-
|
|
24280
|
-
|
|
24281
|
-
|
|
24282
|
-
|
|
24283
|
-
|
|
24284
|
-
|
|
24285
|
-
"FORBIDDEN",
|
|
24286
|
-
|
|
24287
|
-
403
|
|
24288
|
-
);
|
|
24389
|
+
if (isAbsolute7(expandedPath)) {
|
|
24390
|
+
const realTarget = realpathSync3(expandedPath);
|
|
24391
|
+
if (role === "session") {
|
|
24392
|
+
const roots = allowedReadRoots({
|
|
24393
|
+
role,
|
|
24394
|
+
cwd: session.cwd,
|
|
24395
|
+
sessionId: request.params.id,
|
|
24396
|
+
...options.homeDir ? { homeDir: options.homeDir } : {},
|
|
24397
|
+
...options.tempDir ? { tempDir: options.tempDir } : {},
|
|
24398
|
+
...options.extraMasterRoots ? { extraMasterRoots: options.extraMasterRoots } : {}
|
|
24399
|
+
});
|
|
24400
|
+
if (!isRealPathWithinRoots(realTarget, roots)) {
|
|
24401
|
+
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);
|
|
24402
|
+
}
|
|
24289
24403
|
}
|
|
24290
|
-
let rel =
|
|
24404
|
+
let rel = expandedPath;
|
|
24291
24405
|
try {
|
|
24292
24406
|
const realCwd = realpathSync3(session.cwd);
|
|
24293
24407
|
if (realTarget === realCwd || realTarget.startsWith(`${realCwd}${sep2}`)) {
|
|
@@ -24297,7 +24411,7 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24297
24411
|
}
|
|
24298
24412
|
resolved = { absolute: realTarget, relative: rel };
|
|
24299
24413
|
} else {
|
|
24300
|
-
resolved = resolveExistingInside(session.cwd,
|
|
24414
|
+
resolved = resolveExistingInside(session.cwd, expandedPath);
|
|
24301
24415
|
}
|
|
24302
24416
|
} catch (error) {
|
|
24303
24417
|
badPath(error);
|
|
@@ -24317,22 +24431,47 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24317
24431
|
const wantDownload = request.query.download === "1" || request.query.download === "true";
|
|
24318
24432
|
const wantText = request.query.format === "text";
|
|
24319
24433
|
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"));
|
|
24434
|
+
const contentType = imageMimeForName(filename) ?? mediaMimeForName(filename) ?? (filename.toLowerCase().endsWith(".pdf") ? "application/pdf" : "application/octet-stream");
|
|
24435
|
+
reply.header("Content-Type", contentType);
|
|
24436
|
+
reply.header("Content-Length", String(info.size));
|
|
24325
24437
|
reply.header("Content-Disposition", contentDispositionAttachment(filename));
|
|
24326
24438
|
reply.header("X-Content-Type-Options", "nosniff");
|
|
24327
24439
|
if (isSvg) reply.header("Content-Security-Policy", "sandbox");
|
|
24328
24440
|
reply.header("Cache-Control", "private, no-store");
|
|
24329
|
-
return reply.send(
|
|
24441
|
+
return reply.send(createReadStream(resolved.absolute));
|
|
24330
24442
|
}
|
|
24331
24443
|
const baseKind = previewKindForName(filename);
|
|
24332
24444
|
const effectiveKind = wantText && (baseKind === "text" || isSvg) ? "text" : baseKind;
|
|
24333
24445
|
if (effectiveKind === "unsupported") {
|
|
24334
24446
|
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
24447
|
}
|
|
24448
|
+
if (effectiveKind === "video" || effectiveKind === "audio") {
|
|
24449
|
+
if (info.size > maxMediaPreviewBytes) {
|
|
24450
|
+
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);
|
|
24451
|
+
}
|
|
24452
|
+
const contentType = mediaMimeForName(filename) ?? "application/octet-stream";
|
|
24453
|
+
reply.header("Content-Type", contentType);
|
|
24454
|
+
reply.header("Accept-Ranges", "bytes");
|
|
24455
|
+
reply.header("X-Content-Type-Options", "nosniff");
|
|
24456
|
+
reply.header("Cache-Control", "private, max-age=60");
|
|
24457
|
+
const rangeHeader = typeof request.headers.range === "string" ? request.headers.range : void 0;
|
|
24458
|
+
if (rangeHeader) {
|
|
24459
|
+
const parsed = parseSingleByteRange(rangeHeader, info.size);
|
|
24460
|
+
if (parsed === "invalid") {
|
|
24461
|
+
reply.code(416);
|
|
24462
|
+
reply.header("Content-Range", `bytes */${info.size}`);
|
|
24463
|
+
return reply.send();
|
|
24464
|
+
}
|
|
24465
|
+
if (parsed) {
|
|
24466
|
+
reply.code(206);
|
|
24467
|
+
reply.header("Content-Range", `bytes ${parsed.start}-${parsed.end}/${info.size}`);
|
|
24468
|
+
reply.header("Content-Length", String(parsed.end - parsed.start + 1));
|
|
24469
|
+
return reply.send(createReadStream(resolved.absolute, { start: parsed.start, end: parsed.end }));
|
|
24470
|
+
}
|
|
24471
|
+
}
|
|
24472
|
+
reply.header("Content-Length", String(info.size));
|
|
24473
|
+
return reply.send(createReadStream(resolved.absolute));
|
|
24474
|
+
}
|
|
24336
24475
|
const maxBytes = effectiveKind === "text" ? maxTextPreviewBytes : maxDocumentPreviewBytes;
|
|
24337
24476
|
if (info.size > maxBytes) {
|
|
24338
24477
|
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 +24908,8 @@ var LlmClient = class {
|
|
|
24769
24908
|
|
|
24770
24909
|
// src/llm/detect.ts
|
|
24771
24910
|
import { readFile as readFile12 } from "node:fs/promises";
|
|
24772
|
-
import { homedir as
|
|
24773
|
-
import { join as
|
|
24911
|
+
import { homedir as homedir14 } from "node:os";
|
|
24912
|
+
import { join as join20 } from "node:path";
|
|
24774
24913
|
var stringValue = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
24775
24914
|
async function readJson(path5) {
|
|
24776
24915
|
try {
|
|
@@ -24900,9 +25039,9 @@ function codexCandidate(configText, env) {
|
|
|
24900
25039
|
}
|
|
24901
25040
|
async function detectLlmEndpoints(options = {}) {
|
|
24902
25041
|
const env = options.env ?? process.env;
|
|
24903
|
-
const home = options.home ??
|
|
25042
|
+
const home = options.home ?? homedir14();
|
|
24904
25043
|
const candidates = [];
|
|
24905
|
-
const settings = await readJson(
|
|
25044
|
+
const settings = await readJson(join20(home, ".claude", "settings.json"));
|
|
24906
25045
|
const settingsEnv = settings?.env && typeof settings.env === "object" && !Array.isArray(settings.env) ? settings.env : {};
|
|
24907
25046
|
const fromSettings = anthropicCandidate(settingsEnv, settings?.model, "claude-code:settings", "Claude Code\uFF08settings.json\uFF09");
|
|
24908
25047
|
if (fromSettings) candidates.push(fromSettings);
|
|
@@ -24910,7 +25049,7 @@ async function detectLlmEndpoints(options = {}) {
|
|
|
24910
25049
|
if (fromEnv) candidates.push(fromEnv);
|
|
24911
25050
|
const openai = openAiCandidate(env);
|
|
24912
25051
|
if (openai) candidates.push(openai);
|
|
24913
|
-
const codexConfig = await readText(
|
|
25052
|
+
const codexConfig = await readText(join20(home, ".codex", "config.toml"));
|
|
24914
25053
|
if (codexConfig) {
|
|
24915
25054
|
const codex = codexCandidate(codexConfig, env);
|
|
24916
25055
|
if (codex) candidates.push(codex);
|
|
@@ -25140,16 +25279,16 @@ function registerJsonCompression(app, threshold = JSON_COMPRESSION_THRESHOLD) {
|
|
|
25140
25279
|
// src/web-password.ts
|
|
25141
25280
|
import { randomBytes as randomBytes3, scryptSync, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
25142
25281
|
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
|
|
25282
|
+
import { homedir as homedir15 } from "node:os";
|
|
25283
|
+
import { dirname as dirname11, join as join21 } from "node:path";
|
|
25145
25284
|
var webPasswordFileName = "web-password";
|
|
25146
25285
|
var SCRYPT_N = 16384;
|
|
25147
25286
|
var SCRYPT_R = 8;
|
|
25148
25287
|
var SCRYPT_P = 1;
|
|
25149
25288
|
var KEY_LENGTH = 32;
|
|
25150
25289
|
var minWebPasswordLength = 6;
|
|
25151
|
-
function webPasswordPath(home =
|
|
25152
|
-
return
|
|
25290
|
+
function webPasswordPath(home = homedir15()) {
|
|
25291
|
+
return join21(home, ".agentdock", webPasswordFileName);
|
|
25153
25292
|
}
|
|
25154
25293
|
function hashWebPassword(password) {
|
|
25155
25294
|
const salt = randomBytes3(16);
|
|
@@ -25716,7 +25855,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25716
25855
|
"audio/flac": ".flac",
|
|
25717
25856
|
"application/octet-stream": ""
|
|
25718
25857
|
};
|
|
25719
|
-
const globalUploadRoot =
|
|
25858
|
+
const globalUploadRoot = join22(homedir16(), ".agentdock", "uploads");
|
|
25720
25859
|
const uploadTtlMs = 7 * 24 * 60 * 6e4;
|
|
25721
25860
|
const collectExpiredUploads = async (now2 = Date.now()) => {
|
|
25722
25861
|
let removedFiles = 0;
|
|
@@ -25727,7 +25866,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25727
25866
|
return { removedFiles };
|
|
25728
25867
|
}
|
|
25729
25868
|
for (const sessionDir of sessionDirs) {
|
|
25730
|
-
const directory =
|
|
25869
|
+
const directory = join22(globalUploadRoot, sessionDir);
|
|
25731
25870
|
let names;
|
|
25732
25871
|
try {
|
|
25733
25872
|
names = await readdir4(directory);
|
|
@@ -25735,7 +25874,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25735
25874
|
continue;
|
|
25736
25875
|
}
|
|
25737
25876
|
for (const name of names) {
|
|
25738
|
-
const filePath =
|
|
25877
|
+
const filePath = join22(directory, name);
|
|
25739
25878
|
try {
|
|
25740
25879
|
const info = await stat6(filePath);
|
|
25741
25880
|
if (!info.isFile() || now2 - info.mtimeMs <= uploadTtlMs) continue;
|
|
@@ -25781,10 +25920,10 @@ async function buildApp(runtime, options = {}) {
|
|
|
25781
25920
|
originalName = rawName;
|
|
25782
25921
|
}
|
|
25783
25922
|
const ext = extFromContentType(contentType, originalName);
|
|
25784
|
-
const uploadDir =
|
|
25923
|
+
const uploadDir = join22(globalUploadRoot, session.id);
|
|
25785
25924
|
await mkdir4(uploadDir, { recursive: true });
|
|
25786
25925
|
const filename = `${Date.now()}-${randomBytes4(6).toString("hex")}${ext}`;
|
|
25787
|
-
const filePath =
|
|
25926
|
+
const filePath = join22(uploadDir, filename);
|
|
25788
25927
|
await writeFile4(filePath, buffer);
|
|
25789
25928
|
return reply.code(201).send({ path: filePath, url: `/api/sessions/${session.id}/uploads/${filename}`, filename });
|
|
25790
25929
|
});
|
|
@@ -25795,9 +25934,17 @@ async function buildApp(runtime, options = {}) {
|
|
|
25795
25934
|
if (filename.includes("..") || filename.includes("/") || filename.includes("\\")) {
|
|
25796
25935
|
throw new RuntimeError("INVALID_UPLOAD", "Invalid filename", 400);
|
|
25797
25936
|
}
|
|
25798
|
-
const filePath =
|
|
25937
|
+
const filePath = join22(globalUploadRoot, session.id, filename);
|
|
25799
25938
|
const ext = extname2(filename).toLowerCase();
|
|
25800
|
-
|
|
25939
|
+
let data;
|
|
25940
|
+
try {
|
|
25941
|
+
data = await readFile13(filePath);
|
|
25942
|
+
} catch (error) {
|
|
25943
|
+
if (error?.code === "ENOENT") {
|
|
25944
|
+
throw new RuntimeError("UPLOAD_NOT_FOUND", "Upload not found", 404);
|
|
25945
|
+
}
|
|
25946
|
+
throw error;
|
|
25947
|
+
}
|
|
25801
25948
|
reply.header("Content-Type", contentTypes[ext] ?? "application/octet-stream");
|
|
25802
25949
|
reply.header("Cache-Control", "public, max-age=31536000, immutable");
|
|
25803
25950
|
reply.header("Content-Disposition", `attachment; filename="${filename}"`);
|
|
@@ -32474,12 +32621,12 @@ function withContext(percent2) {
|
|
|
32474
32621
|
// src/assistant/cwd.ts
|
|
32475
32622
|
init_src2();
|
|
32476
32623
|
import { accessSync as accessSync3, constants as constants6, statSync as statSync6 } from "node:fs";
|
|
32477
|
-
import { homedir as
|
|
32624
|
+
import { homedir as homedir17 } from "node:os";
|
|
32478
32625
|
import { isAbsolute as isAbsolute8, resolve as resolve11 } from "node:path";
|
|
32479
32626
|
function expandHomePath(value) {
|
|
32480
32627
|
const trimmed = value.trim();
|
|
32481
|
-
if (trimmed === "~") return
|
|
32482
|
-
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return resolve11(
|
|
32628
|
+
if (trimmed === "~") return homedir17();
|
|
32629
|
+
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return resolve11(homedir17(), trimmed.slice(2));
|
|
32483
32630
|
return trimmed;
|
|
32484
32631
|
}
|
|
32485
32632
|
function resolveCwdArgument(value, base = process.cwd()) {
|
|
@@ -34986,23 +35133,23 @@ init_session_cli();
|
|
|
34986
35133
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
34987
35134
|
import { chmodSync as chmodSync3, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync13, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
34988
35135
|
import { createServer } from "node:net";
|
|
34989
|
-
import { delimiter as delimiter2, dirname as dirname13, join as
|
|
35136
|
+
import { delimiter as delimiter2, dirname as dirname13, join as join24, resolve as resolve15 } from "node:path";
|
|
34990
35137
|
init_daemon();
|
|
34991
35138
|
var SANDBOX_FILE = "sandbox.json";
|
|
34992
35139
|
function findRepoRoot(start = process.cwd()) {
|
|
34993
35140
|
let dir = resolve15(start);
|
|
34994
35141
|
for (; ; ) {
|
|
34995
|
-
if (existsSync12(
|
|
35142
|
+
if (existsSync12(join24(dir, "apps", "server", "package.json")) && existsSync12(join24(dir, "pnpm-workspace.yaml"))) return dir;
|
|
34996
35143
|
const parent = dirname13(dir);
|
|
34997
35144
|
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
35145
|
dir = parent;
|
|
34999
35146
|
}
|
|
35000
35147
|
}
|
|
35001
35148
|
function sandboxPaths(repo, port) {
|
|
35002
|
-
const root4 =
|
|
35003
|
-
return { root: root4, home:
|
|
35149
|
+
const root4 = join24(repo, ".agentdock", "dev");
|
|
35150
|
+
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
35151
|
}
|
|
35005
|
-
var shimDir = (sandbox) =>
|
|
35152
|
+
var shimDir = (sandbox) => join24(sandbox.root, "bin");
|
|
35006
35153
|
function sandboxEnv(sandbox, base = process.env) {
|
|
35007
35154
|
const env = {
|
|
35008
35155
|
...base,
|
|
@@ -35028,7 +35175,7 @@ function writeCliShim(sandbox, node = process.execPath) {
|
|
|
35028
35175
|
if (process.platform === "win32") {
|
|
35029
35176
|
const quote2 = (path5) => `"${path5.replace(/%/g, "%%")}"`;
|
|
35030
35177
|
writeFileSync5(
|
|
35031
|
-
|
|
35178
|
+
join24(dir, "agent-dock.cmd"),
|
|
35032
35179
|
`@echo off\r
|
|
35033
35180
|
setlocal DisableDelayedExpansion\r
|
|
35034
35181
|
${quote2(node)} ${quote2(sandbox.entrypoint)} %*\r
|
|
@@ -35036,7 +35183,7 @@ ${quote2(node)} ${quote2(sandbox.entrypoint)} %*\r
|
|
|
35036
35183
|
);
|
|
35037
35184
|
return;
|
|
35038
35185
|
}
|
|
35039
|
-
const file =
|
|
35186
|
+
const file = join24(dir, "agent-dock");
|
|
35040
35187
|
writeFileSync5(file, `#!/bin/sh
|
|
35041
35188
|
exec ${shellQuote5(node)} ${shellQuote5(sandbox.entrypoint)} "$@"
|
|
35042
35189
|
`);
|
|
@@ -35044,7 +35191,7 @@ exec ${shellQuote5(node)} ${shellQuote5(sandbox.entrypoint)} "$@"
|
|
|
35044
35191
|
}
|
|
35045
35192
|
function readSandbox(repo) {
|
|
35046
35193
|
try {
|
|
35047
|
-
return JSON.parse(readFileSync13(
|
|
35194
|
+
return JSON.parse(readFileSync13(join24(repo, ".agentdock", "dev", SANDBOX_FILE), "utf8"));
|
|
35048
35195
|
} catch {
|
|
35049
35196
|
return void 0;
|
|
35050
35197
|
}
|
|
@@ -35071,7 +35218,7 @@ async function devUp(options = {}) {
|
|
|
35071
35218
|
const sandbox = sandboxPaths(repo, port);
|
|
35072
35219
|
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
35220
|
for (const dir of [sandbox.home, sandbox.work]) mkdirSync6(dir, { recursive: true });
|
|
35074
|
-
writeFileSync5(
|
|
35221
|
+
writeFileSync5(join24(sandbox.root, SANDBOX_FILE), `${JSON.stringify(sandbox, null, 2)}
|
|
35075
35222
|
`);
|
|
35076
35223
|
writeCliShim(sandbox);
|
|
35077
35224
|
const run2 = options.run ?? defaultRun;
|