@downcity/agent 1.1.71 → 1.1.73
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/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
- package/bin/index.d.ts +2 -6
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -5
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/PluginCatalog.js +2 -2
- package/bin/plugin/core/PluginCatalog.js.map +1 -1
- package/bin/rpc/Client.d.ts +2 -2
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Server.js +2 -2
- package/bin/rpc/Server.js.map +1 -1
- package/bin/runtime/auth/AuthEnv.d.ts.map +1 -0
- package/bin/runtime/auth/AuthEnv.js.map +1 -0
- package/bin/runtime/auth/CliAuthStateStore.d.ts.map +1 -0
- package/bin/runtime/auth/CliAuthStateStore.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/AuthControlService.d.ts +3 -3
- package/bin/runtime/control/AuthControlService.d.ts.map +1 -0
- package/bin/runtime/control/AuthControlService.js.map +1 -0
- package/bin/runtime/control/CommonHelpers.d.ts.map +1 -0
- package/bin/runtime/control/CommonHelpers.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/ExecuteBySession.d.ts +4 -4
- package/bin/runtime/control/ExecuteBySession.d.ts.map +1 -0
- package/bin/runtime/control/ExecuteBySession.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/ExecuteInput.d.ts +1 -1
- package/bin/runtime/control/ExecuteInput.d.ts.map +1 -0
- package/bin/runtime/{server/http/control → control}/ExecuteInput.js +2 -2
- package/bin/runtime/control/ExecuteInput.js.map +1 -0
- package/bin/runtime/control/Helpers.d.ts.map +1 -0
- package/bin/runtime/control/Helpers.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/MessageTimeline.d.ts +2 -2
- package/bin/runtime/control/MessageTimeline.d.ts.map +1 -0
- package/bin/runtime/{server/http/control → control}/MessageTimeline.js +2 -2
- package/bin/runtime/control/MessageTimeline.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/SessionSummaryStore.d.ts +2 -2
- package/bin/runtime/control/SessionSummaryStore.d.ts.map +1 -0
- package/bin/runtime/{server/http/control → control}/SessionSummaryStore.js +1 -1
- package/bin/runtime/control/SessionSummaryStore.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/TaskStore.d.ts +1 -1
- package/bin/runtime/control/TaskStore.d.ts.map +1 -0
- package/bin/runtime/{server/http/control → control}/TaskStore.js +1 -1
- package/bin/runtime/control/TaskStore.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/types/AuthControl.d.ts +1 -1
- package/bin/runtime/control/types/AuthControl.d.ts.map +1 -0
- package/bin/runtime/control/types/AuthControl.js.map +1 -0
- package/bin/runtime/control/types/ControlSessionExecute.d.ts.map +1 -0
- package/bin/runtime/control/types/ControlSessionExecute.js.map +1 -0
- package/bin/runtime/{server/http/control → control}/types/ControlViewData.d.ts +1 -1
- package/bin/runtime/control/types/ControlViewData.d.ts.map +1 -0
- package/bin/runtime/control/types/ControlViewData.js.map +1 -0
- package/bin/runtime/host/ProjectSetup.d.ts.map +1 -0
- package/bin/runtime/host/{daemon/ProjectSetup.js → ProjectSetup.js} +1 -1
- package/bin/runtime/host/ProjectSetup.js.map +1 -0
- package/bin/types/runtime/platform/PlatformGateway.d.ts +3 -16
- package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -1
- package/src/executor/tools/shell/ShellToolFormatting.ts +1 -1
- package/src/index.ts +1 -17
- package/src/plugin/core/PluginCatalog.ts +2 -2
- package/src/rpc/Client.ts +2 -2
- package/src/rpc/Server.ts +3 -3
- package/src/runtime/{server/http/control → control}/AuthControlService.ts +1 -1
- package/src/runtime/{server/http/control → control}/ExecuteBySession.ts +1 -1
- package/src/runtime/{server/http/control → control}/ExecuteInput.ts +1 -1
- package/src/runtime/{server/http/control → control}/MessageTimeline.ts +1 -1
- package/src/runtime/{server/http/control → control}/SessionSummaryStore.ts +1 -1
- package/src/runtime/{server/http/control → control}/TaskStore.ts +1 -1
- package/src/types/runtime/platform/PlatformGateway.ts +3 -17
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/runtime/host/daemon/Api.d.ts +0 -60
- package/bin/runtime/host/daemon/Api.d.ts.map +0 -1
- package/bin/runtime/host/daemon/Api.js +0 -10
- package/bin/runtime/host/daemon/Api.js.map +0 -1
- package/bin/runtime/host/daemon/Client.d.ts +0 -17
- package/bin/runtime/host/daemon/Client.d.ts.map +0 -1
- package/bin/runtime/host/daemon/Client.js +0 -168
- package/bin/runtime/host/daemon/Client.js.map +0 -1
- package/bin/runtime/host/daemon/Paths.d.ts +0 -20
- package/bin/runtime/host/daemon/Paths.d.ts.map +0 -1
- package/bin/runtime/host/daemon/Paths.js +0 -23
- package/bin/runtime/host/daemon/Paths.js.map +0 -1
- package/bin/runtime/host/daemon/ProjectSetup.d.ts.map +0 -1
- package/bin/runtime/host/daemon/ProjectSetup.js.map +0 -1
- package/bin/runtime/server/http/Server.d.ts +0 -48
- package/bin/runtime/server/http/Server.d.ts.map +0 -1
- package/bin/runtime/server/http/Server.js +0 -129
- package/bin/runtime/server/http/Server.js.map +0 -1
- package/bin/runtime/server/http/auth/AuthEnv.d.ts.map +0 -1
- package/bin/runtime/server/http/auth/AuthEnv.js.map +0 -1
- package/bin/runtime/server/http/auth/CliAuthStateStore.d.ts.map +0 -1
- package/bin/runtime/server/http/auth/CliAuthStateStore.js.map +0 -1
- package/bin/runtime/server/http/control/AuthControlService.d.ts.map +0 -1
- package/bin/runtime/server/http/control/AuthControlService.js.map +0 -1
- package/bin/runtime/server/http/control/CommonHelpers.d.ts.map +0 -1
- package/bin/runtime/server/http/control/CommonHelpers.js.map +0 -1
- package/bin/runtime/server/http/control/ControlApiRoutes.d.ts +0 -14
- package/bin/runtime/server/http/control/ControlApiRoutes.d.ts.map +0 -1
- package/bin/runtime/server/http/control/ControlApiRoutes.js +0 -25
- package/bin/runtime/server/http/control/ControlApiRoutes.js.map +0 -1
- package/bin/runtime/server/http/control/ControlAuthorizationRoutes.d.ts +0 -17
- package/bin/runtime/server/http/control/ControlAuthorizationRoutes.d.ts.map +0 -1
- package/bin/runtime/server/http/control/ControlAuthorizationRoutes.js +0 -84
- package/bin/runtime/server/http/control/ControlAuthorizationRoutes.js.map +0 -1
- package/bin/runtime/server/http/control/ControlRouter.d.ts +0 -35
- package/bin/runtime/server/http/control/ControlRouter.d.ts.map +0 -1
- package/bin/runtime/server/http/control/ControlRouter.js +0 -28
- package/bin/runtime/server/http/control/ControlRouter.js.map +0 -1
- package/bin/runtime/server/http/control/ExecuteBySession.d.ts.map +0 -1
- package/bin/runtime/server/http/control/ExecuteBySession.js.map +0 -1
- package/bin/runtime/server/http/control/ExecuteInput.d.ts.map +0 -1
- package/bin/runtime/server/http/control/ExecuteInput.js.map +0 -1
- package/bin/runtime/server/http/control/Helpers.d.ts.map +0 -1
- package/bin/runtime/server/http/control/Helpers.js.map +0 -1
- package/bin/runtime/server/http/control/MessageTimeline.d.ts.map +0 -1
- package/bin/runtime/server/http/control/MessageTimeline.js.map +0 -1
- package/bin/runtime/server/http/control/OverviewRoutes.d.ts +0 -13
- package/bin/runtime/server/http/control/OverviewRoutes.d.ts.map +0 -1
- package/bin/runtime/server/http/control/OverviewRoutes.js +0 -101
- package/bin/runtime/server/http/control/OverviewRoutes.js.map +0 -1
- package/bin/runtime/server/http/control/SessionRoutes.d.ts +0 -14
- package/bin/runtime/server/http/control/SessionRoutes.d.ts.map +0 -1
- package/bin/runtime/server/http/control/SessionRoutes.js +0 -334
- package/bin/runtime/server/http/control/SessionRoutes.js.map +0 -1
- package/bin/runtime/server/http/control/SessionSummaryStore.d.ts.map +0 -1
- package/bin/runtime/server/http/control/SessionSummaryStore.js.map +0 -1
- package/bin/runtime/server/http/control/TaskRoutes.d.ts +0 -13
- package/bin/runtime/server/http/control/TaskRoutes.d.ts.map +0 -1
- package/bin/runtime/server/http/control/TaskRoutes.js +0 -364
- package/bin/runtime/server/http/control/TaskRoutes.js.map +0 -1
- package/bin/runtime/server/http/control/TaskStore.d.ts.map +0 -1
- package/bin/runtime/server/http/control/TaskStore.js.map +0 -1
- package/bin/runtime/server/http/control/types/AuthControl.d.ts.map +0 -1
- package/bin/runtime/server/http/control/types/AuthControl.js.map +0 -1
- package/bin/runtime/server/http/control/types/ControlRoutes.d.ts +0 -28
- package/bin/runtime/server/http/control/types/ControlRoutes.d.ts.map +0 -1
- package/bin/runtime/server/http/control/types/ControlRoutes.js +0 -9
- package/bin/runtime/server/http/control/types/ControlRoutes.js.map +0 -1
- package/bin/runtime/server/http/control/types/ControlSessionExecute.d.ts.map +0 -1
- package/bin/runtime/server/http/control/types/ControlSessionExecute.js.map +0 -1
- package/bin/runtime/server/http/control/types/ControlViewData.d.ts.map +0 -1
- package/bin/runtime/server/http/control/types/ControlViewData.js.map +0 -1
- package/bin/runtime/server/http/execute/execute.d.ts +0 -25
- package/bin/runtime/server/http/execute/execute.d.ts.map +0 -1
- package/bin/runtime/server/http/execute/execute.js +0 -63
- package/bin/runtime/server/http/execute/execute.js.map +0 -1
- package/bin/runtime/server/http/health/health.d.ts +0 -14
- package/bin/runtime/server/http/health/health.d.ts.map +0 -1
- package/bin/runtime/server/http/health/health.js +0 -24
- package/bin/runtime/server/http/health/health.js.map +0 -1
- package/bin/runtime/server/http/plugins/plugins.d.ts +0 -25
- package/bin/runtime/server/http/plugins/plugins.d.ts.map +0 -1
- package/bin/runtime/server/http/plugins/plugins.js +0 -114
- package/bin/runtime/server/http/plugins/plugins.js.map +0 -1
- package/bin/runtime/server/http/sdk/Router.d.ts +0 -14
- package/bin/runtime/server/http/sdk/Router.d.ts.map +0 -1
- package/bin/runtime/server/http/sdk/Router.js +0 -18
- package/bin/runtime/server/http/sdk/Router.js.map +0 -1
- package/bin/runtime/server/http/sdk/SessionRoutes.d.ts +0 -15
- package/bin/runtime/server/http/sdk/SessionRoutes.d.ts.map +0 -1
- package/bin/runtime/server/http/sdk/SessionRoutes.js +0 -249
- package/bin/runtime/server/http/sdk/SessionRoutes.js.map +0 -1
- package/bin/runtime/server/http/static/static.d.ts +0 -25
- package/bin/runtime/server/http/static/static.d.ts.map +0 -1
- package/bin/runtime/server/http/static/static.js +0 -99
- package/bin/runtime/server/http/static/static.js.map +0 -1
- package/bin/types/config/Start.d.ts +0 -19
- package/bin/types/config/Start.d.ts.map +0 -1
- package/bin/types/config/Start.js +0 -13
- package/bin/types/config/Start.js.map +0 -1
- package/bin/types/runtime/daemon/Daemon.d.ts +0 -46
- package/bin/types/runtime/daemon/Daemon.d.ts.map +0 -1
- package/bin/types/runtime/daemon/Daemon.js +0 -14
- package/bin/types/runtime/daemon/Daemon.js.map +0 -1
- package/src/runtime/host/daemon/Api.ts +0 -64
- package/src/runtime/host/daemon/Client.ts +0 -204
- package/src/runtime/host/daemon/Paths.ts +0 -33
- package/src/runtime/server/http/Server.ts +0 -183
- package/src/runtime/server/http/control/ControlApiRoutes.ts +0 -29
- package/src/runtime/server/http/control/ControlAuthorizationRoutes.ts +0 -103
- package/src/runtime/server/http/control/ControlRouter.ts +0 -47
- package/src/runtime/server/http/control/OverviewRoutes.ts +0 -115
- package/src/runtime/server/http/control/SessionRoutes.ts +0 -427
- package/src/runtime/server/http/control/TaskRoutes.ts +0 -436
- package/src/runtime/server/http/control/types/ControlRoutes.ts +0 -31
- package/src/runtime/server/http/execute/execute.ts +0 -97
- package/src/runtime/server/http/health/health.ts +0 -27
- package/src/runtime/server/http/plugins/plugins.ts +0 -150
- package/src/runtime/server/http/sdk/Router.ts +0 -22
- package/src/runtime/server/http/sdk/SessionRoutes.ts +0 -300
- package/src/runtime/server/http/static/static.ts +0 -120
- package/src/types/config/Start.ts +0 -19
- package/src/types/runtime/daemon/Daemon.ts +0 -53
- /package/bin/runtime/{server/http/auth → auth}/AuthEnv.d.ts +0 -0
- /package/bin/runtime/{server/http/auth → auth}/AuthEnv.js +0 -0
- /package/bin/runtime/{server/http/auth → auth}/CliAuthStateStore.d.ts +0 -0
- /package/bin/runtime/{server/http/auth → auth}/CliAuthStateStore.js +0 -0
- /package/bin/runtime/{server/http/control → control}/AuthControlService.js +0 -0
- /package/bin/runtime/{server/http/control → control}/CommonHelpers.d.ts +0 -0
- /package/bin/runtime/{server/http/control → control}/CommonHelpers.js +0 -0
- /package/bin/runtime/{server/http/control → control}/ExecuteBySession.js +0 -0
- /package/bin/runtime/{server/http/control → control}/Helpers.d.ts +0 -0
- /package/bin/runtime/{server/http/control → control}/Helpers.js +0 -0
- /package/bin/runtime/{server/http/control → control}/types/AuthControl.js +0 -0
- /package/bin/runtime/{server/http/control → control}/types/ControlSessionExecute.d.ts +0 -0
- /package/bin/runtime/{server/http/control → control}/types/ControlSessionExecute.js +0 -0
- /package/bin/runtime/{server/http/control → control}/types/ControlViewData.js +0 -0
- /package/bin/runtime/host/{daemon/ProjectSetup.d.ts → ProjectSetup.d.ts} +0 -0
- /package/src/runtime/{server/http/auth → auth}/AuthEnv.ts +0 -0
- /package/src/runtime/{server/http/auth → auth}/CliAuthStateStore.ts +0 -0
- /package/src/runtime/{server/http/control → control}/CommonHelpers.ts +0 -0
- /package/src/runtime/{server/http/control → control}/Helpers.ts +0 -0
- /package/src/runtime/{server/http/control → control}/types/AuthControl.ts +0 -0
- /package/src/runtime/{server/http/control → control}/types/ControlSessionExecute.ts +0 -0
- /package/src/runtime/{server/http/control → control}/types/ControlViewData.ts +0 -0
- /package/src/runtime/host/{daemon/ProjectSetup.ts → ProjectSetup.ts} +0 -0
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Control 任务与日志路由。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 聚合 tasks/runs/logs 相关接口。
|
|
6
|
-
* - 任务动作统一复用 task plugin runtime command,不在 UI 层重复实现业务语义。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import fs from "fs-extra";
|
|
10
|
-
import { basename, dirname, join } from "path";
|
|
11
|
-
import { getDowncityTasksDirPath } from "@/config/Paths.js";
|
|
12
|
-
import { runPluginCommand } from "@/plugin/core/Manager.js";
|
|
13
|
-
import type { ControlRouteRegistrationParams } from "@/runtime/server/http/control/types/ControlRoutes.js";
|
|
14
|
-
import {
|
|
15
|
-
buildControlRouteAliases,
|
|
16
|
-
decodeMaybe,
|
|
17
|
-
toLimit,
|
|
18
|
-
toOptionalString,
|
|
19
|
-
} from "./CommonHelpers.js";
|
|
20
|
-
import {
|
|
21
|
-
TASK_RUN_DIR_REGEX,
|
|
22
|
-
listTaskRuns,
|
|
23
|
-
readRecentLogs,
|
|
24
|
-
readTaskRunDetail,
|
|
25
|
-
} from "./Helpers.js";
|
|
26
|
-
|
|
27
|
-
type TaskListItem = {
|
|
28
|
-
title?: string;
|
|
29
|
-
status?: string;
|
|
30
|
-
taskMdPath?: string;
|
|
31
|
-
lastRunTimestamp?: string;
|
|
32
|
-
[key: string]: unknown;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function resolveTaskIdFromTaskMdPath(taskMdPath: unknown): string {
|
|
36
|
-
const text = String(taskMdPath || "").trim();
|
|
37
|
-
if (!text) return "";
|
|
38
|
-
return basename(dirname(text));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function listTasksViaPlugin(params: {
|
|
42
|
-
routes: ControlRouteRegistrationParams;
|
|
43
|
-
status?: string;
|
|
44
|
-
}): Promise<TaskListItem[]> {
|
|
45
|
-
const result = await params.routes.getAgentContext().plugins.runAction({
|
|
46
|
-
plugin: "task",
|
|
47
|
-
action: "list",
|
|
48
|
-
payload: params.status ? { status: params.status } : undefined,
|
|
49
|
-
});
|
|
50
|
-
if (!result.success) {
|
|
51
|
-
throw new Error(result.error || result.message || "task list failed");
|
|
52
|
-
}
|
|
53
|
-
const data =
|
|
54
|
-
result.data && typeof result.data === "object" && !Array.isArray(result.data)
|
|
55
|
-
? result.data as { tasks?: TaskListItem[] }
|
|
56
|
-
: {};
|
|
57
|
-
return Array.isArray(data.tasks) ? data.tasks : [];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function resolveTaskIdByTitleViaPlugin(params: {
|
|
61
|
-
routes: ControlRouteRegistrationParams;
|
|
62
|
-
title: string;
|
|
63
|
-
}): Promise<string> {
|
|
64
|
-
const title = String(params.title || "").trim();
|
|
65
|
-
const tasks = await listTasksViaPlugin({ routes: params.routes });
|
|
66
|
-
const matched = tasks.filter((task) => String(task.title || "").trim() === title);
|
|
67
|
-
if (matched.length !== 1) throw new Error(`Task not found: ${title}`);
|
|
68
|
-
const taskId = resolveTaskIdFromTaskMdPath(matched[0]?.taskMdPath);
|
|
69
|
-
if (!taskId) throw new Error(`Task id not found: ${title}`);
|
|
70
|
-
return taskId;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 读取任务当前是否仍在执行。
|
|
75
|
-
*/
|
|
76
|
-
async function readTaskRunningState(params: {
|
|
77
|
-
projectRoot: string;
|
|
78
|
-
routes: ControlRouteRegistrationParams;
|
|
79
|
-
title: string;
|
|
80
|
-
lastRunTimestamp?: string;
|
|
81
|
-
}): Promise<boolean> {
|
|
82
|
-
const title = String(params.title || "").trim();
|
|
83
|
-
const timestamp = String(params.lastRunTimestamp || "").trim();
|
|
84
|
-
if (!title || !timestamp || !TASK_RUN_DIR_REGEX.test(timestamp)) return false;
|
|
85
|
-
|
|
86
|
-
let taskId = "";
|
|
87
|
-
try {
|
|
88
|
-
taskId = await resolveTaskIdByTitleViaPlugin({
|
|
89
|
-
routes: params.routes,
|
|
90
|
-
title,
|
|
91
|
-
});
|
|
92
|
-
} catch {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const progressPath = join(
|
|
97
|
-
getDowncityTasksDirPath(params.projectRoot),
|
|
98
|
-
taskId,
|
|
99
|
-
timestamp,
|
|
100
|
-
"run-progress.json",
|
|
101
|
-
);
|
|
102
|
-
const progress = (await fs.readJson(progressPath).catch(() => null)) as {
|
|
103
|
-
status?: string;
|
|
104
|
-
} | null;
|
|
105
|
-
return String(progress?.status || "").trim().toLowerCase() === "running";
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 注册任务与日志路由。
|
|
110
|
-
*/
|
|
111
|
-
export function registerControlTaskRoutes(
|
|
112
|
-
params: ControlRouteRegistrationParams,
|
|
113
|
-
): void {
|
|
114
|
-
const { app } = params;
|
|
115
|
-
|
|
116
|
-
for (const routePath of buildControlRouteAliases("/tasks")) {
|
|
117
|
-
app.get(routePath, async (c) => {
|
|
118
|
-
try {
|
|
119
|
-
const runtime = params.getAgentRuntime();
|
|
120
|
-
const status = toOptionalString(c.req.query("status"));
|
|
121
|
-
const tasks = await listTasksViaPlugin({
|
|
122
|
-
routes: params,
|
|
123
|
-
...(status ? { status } : {}),
|
|
124
|
-
});
|
|
125
|
-
const tasksWithRunning = await Promise.all(
|
|
126
|
-
tasks.map(async (task) => {
|
|
127
|
-
const running = await readTaskRunningState({
|
|
128
|
-
projectRoot: runtime.rootPath,
|
|
129
|
-
routes: params,
|
|
130
|
-
title: String(task.title || "").trim(),
|
|
131
|
-
lastRunTimestamp: task.lastRunTimestamp,
|
|
132
|
-
});
|
|
133
|
-
return running ? { ...task, running } : task;
|
|
134
|
-
}),
|
|
135
|
-
);
|
|
136
|
-
return c.json({
|
|
137
|
-
success: true,
|
|
138
|
-
tasks: tasksWithRunning,
|
|
139
|
-
});
|
|
140
|
-
} catch (error) {
|
|
141
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
for (const routePath of buildControlRouteAliases("/tasks/run")) {
|
|
147
|
-
app.post(routePath, async (c) => {
|
|
148
|
-
try {
|
|
149
|
-
const body = (await c.req.json().catch(() => ({}))) as {
|
|
150
|
-
title?: string;
|
|
151
|
-
reason?: string;
|
|
152
|
-
};
|
|
153
|
-
const title = String(body.title || "").trim();
|
|
154
|
-
if (!title) {
|
|
155
|
-
return c.json({ success: false, error: "Invalid title" }, 400);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const reason = toOptionalString(body.reason);
|
|
159
|
-
const result = await runPluginCommand({
|
|
160
|
-
pluginName: "task",
|
|
161
|
-
command: "run",
|
|
162
|
-
payload: {
|
|
163
|
-
title,
|
|
164
|
-
...(reason ? { reason } : {}),
|
|
165
|
-
},
|
|
166
|
-
context: params.getAgentContext(),
|
|
167
|
-
});
|
|
168
|
-
return c.json(result, result.success ? 200 : 400);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
for (const routePath of buildControlRouteAliases("/tasks/:title/status")) {
|
|
176
|
-
app.post(routePath, async (c) => {
|
|
177
|
-
try {
|
|
178
|
-
const title = decodeMaybe(String(c.req.param("title") || "").trim());
|
|
179
|
-
const body = (await c.req.json().catch(() => ({}))) as {
|
|
180
|
-
status?: string;
|
|
181
|
-
};
|
|
182
|
-
const status = String(body.status || "").trim();
|
|
183
|
-
if (!title) {
|
|
184
|
-
return c.json({ success: false, error: "Invalid title" }, 400);
|
|
185
|
-
}
|
|
186
|
-
if (!["enabled", "paused", "disabled"].includes(status)) {
|
|
187
|
-
return c.json({ success: false, error: "Invalid status" }, 400);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const result = await runPluginCommand({
|
|
191
|
-
pluginName: "task",
|
|
192
|
-
command: "status",
|
|
193
|
-
payload: {
|
|
194
|
-
title,
|
|
195
|
-
status,
|
|
196
|
-
},
|
|
197
|
-
context: params.getAgentContext(),
|
|
198
|
-
});
|
|
199
|
-
if (!result.success) {
|
|
200
|
-
return c.json(
|
|
201
|
-
{ success: false, error: result.message || "task status update failed" },
|
|
202
|
-
400,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
const data =
|
|
206
|
-
result.data && typeof result.data === "object" && !Array.isArray(result.data)
|
|
207
|
-
? result.data
|
|
208
|
-
: {};
|
|
209
|
-
return c.json({
|
|
210
|
-
success: true,
|
|
211
|
-
...data,
|
|
212
|
-
});
|
|
213
|
-
} catch (error) {
|
|
214
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
for (const routePath of buildControlRouteAliases("/tasks/:title")) {
|
|
220
|
-
app.delete(routePath, async (c) => {
|
|
221
|
-
try {
|
|
222
|
-
const title = decodeMaybe(String(c.req.param("title") || "").trim());
|
|
223
|
-
if (!title) {
|
|
224
|
-
return c.json({ success: false, error: "Invalid title" }, 400);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const result = await runPluginCommand({
|
|
228
|
-
pluginName: "task",
|
|
229
|
-
command: "delete",
|
|
230
|
-
payload: {
|
|
231
|
-
title,
|
|
232
|
-
},
|
|
233
|
-
context: params.getAgentContext(),
|
|
234
|
-
});
|
|
235
|
-
if (!result.success) {
|
|
236
|
-
return c.json({ success: false, error: result.message || "task delete failed" }, 400);
|
|
237
|
-
}
|
|
238
|
-
const data =
|
|
239
|
-
result.data && typeof result.data === "object" && !Array.isArray(result.data)
|
|
240
|
-
? result.data
|
|
241
|
-
: {};
|
|
242
|
-
return c.json({
|
|
243
|
-
success: true,
|
|
244
|
-
...data,
|
|
245
|
-
});
|
|
246
|
-
} catch (error) {
|
|
247
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
for (const routePath of buildControlRouteAliases("/tasks/:title/runs/:timestamp")) {
|
|
253
|
-
app.delete(routePath, async (c) => {
|
|
254
|
-
try {
|
|
255
|
-
const runtime = params.getAgentRuntime();
|
|
256
|
-
const title = decodeMaybe(String(c.req.param("title") || "").trim());
|
|
257
|
-
const timestamp = String(c.req.param("timestamp") || "").trim();
|
|
258
|
-
if (!title) {
|
|
259
|
-
return c.json({ success: false, error: "Invalid title" }, 400);
|
|
260
|
-
}
|
|
261
|
-
if (!TASK_RUN_DIR_REGEX.test(timestamp)) {
|
|
262
|
-
return c.json({ success: false, error: "Invalid timestamp" }, 400);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
let taskId = "";
|
|
266
|
-
try {
|
|
267
|
-
taskId = await resolveTaskIdByTitleViaPlugin({
|
|
268
|
-
routes: params,
|
|
269
|
-
title,
|
|
270
|
-
});
|
|
271
|
-
} catch {
|
|
272
|
-
return c.json({ success: false, error: "Task not found" }, 404);
|
|
273
|
-
}
|
|
274
|
-
const runDir = join(getDowncityTasksDirPath(runtime.rootPath), taskId, timestamp);
|
|
275
|
-
if (!(await fs.pathExists(runDir))) {
|
|
276
|
-
return c.json({ success: false, error: "Run not found" }, 404);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const progressPath = join(runDir, "run-progress.json");
|
|
280
|
-
const progress = (await fs.readJson(progressPath).catch(() => null)) as {
|
|
281
|
-
status?: string;
|
|
282
|
-
} | null;
|
|
283
|
-
if (String(progress?.status || "").trim().toLowerCase() === "running") {
|
|
284
|
-
return c.json(
|
|
285
|
-
{ success: false, error: "Run is still in progress and cannot be deleted" },
|
|
286
|
-
409,
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
await fs.remove(runDir);
|
|
291
|
-
return c.json({
|
|
292
|
-
success: true,
|
|
293
|
-
title,
|
|
294
|
-
timestamp,
|
|
295
|
-
deleted: true,
|
|
296
|
-
});
|
|
297
|
-
} catch (error) {
|
|
298
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
for (const routePath of buildControlRouteAliases("/tasks/:title/runs")) {
|
|
304
|
-
app.delete(routePath, async (c) => {
|
|
305
|
-
try {
|
|
306
|
-
const runtime = params.getAgentRuntime();
|
|
307
|
-
const title = decodeMaybe(String(c.req.param("title") || "").trim());
|
|
308
|
-
if (!title) {
|
|
309
|
-
return c.json({ success: false, error: "Invalid title" }, 400);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
let taskId = "";
|
|
313
|
-
try {
|
|
314
|
-
taskId = await resolveTaskIdByTitleViaPlugin({
|
|
315
|
-
routes: params,
|
|
316
|
-
title,
|
|
317
|
-
});
|
|
318
|
-
} catch {
|
|
319
|
-
return c.json({ success: false, error: "Task not found" }, 404);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const taskDir = join(getDowncityTasksDirPath(runtime.rootPath), taskId);
|
|
323
|
-
if (!(await fs.pathExists(taskDir))) {
|
|
324
|
-
return c.json({
|
|
325
|
-
success: true,
|
|
326
|
-
title,
|
|
327
|
-
deletedCount: 0,
|
|
328
|
-
skippedRunningCount: 0,
|
|
329
|
-
deletedTimestamps: [],
|
|
330
|
-
skippedRunningTimestamps: [],
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const entries = await fs.readdir(taskDir, { withFileTypes: true });
|
|
335
|
-
const timestamps = entries
|
|
336
|
-
.filter((x) => x.isDirectory() && TASK_RUN_DIR_REGEX.test(x.name))
|
|
337
|
-
.map((x) => x.name)
|
|
338
|
-
.sort();
|
|
339
|
-
const deletedTimestamps: string[] = [];
|
|
340
|
-
const skippedRunningTimestamps: string[] = [];
|
|
341
|
-
|
|
342
|
-
for (const timestamp of timestamps) {
|
|
343
|
-
const runDir = join(taskDir, timestamp);
|
|
344
|
-
const progressPath = join(runDir, "run-progress.json");
|
|
345
|
-
const progress = (await fs.readJson(progressPath).catch(() => null)) as {
|
|
346
|
-
status?: string;
|
|
347
|
-
} | null;
|
|
348
|
-
if (String(progress?.status || "").trim().toLowerCase() === "running") {
|
|
349
|
-
skippedRunningTimestamps.push(timestamp);
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
await fs.remove(runDir);
|
|
353
|
-
deletedTimestamps.push(timestamp);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
return c.json({
|
|
357
|
-
success: true,
|
|
358
|
-
title,
|
|
359
|
-
deletedCount: deletedTimestamps.length,
|
|
360
|
-
skippedRunningCount: skippedRunningTimestamps.length,
|
|
361
|
-
deletedTimestamps,
|
|
362
|
-
skippedRunningTimestamps,
|
|
363
|
-
});
|
|
364
|
-
} catch (error) {
|
|
365
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
app.get(routePath, async (c) => {
|
|
370
|
-
try {
|
|
371
|
-
const runtime = params.getAgentRuntime();
|
|
372
|
-
const title = decodeMaybe(String(c.req.param("title") || "").trim());
|
|
373
|
-
if (!title) {
|
|
374
|
-
return c.json({ success: false, error: "Invalid title" }, 400);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const limit = toLimit(c.req.query("limit"), 50);
|
|
378
|
-
const runs = await listTaskRuns({
|
|
379
|
-
projectRoot: runtime.rootPath,
|
|
380
|
-
title,
|
|
381
|
-
limit,
|
|
382
|
-
});
|
|
383
|
-
return c.json({ success: true, title, runs });
|
|
384
|
-
} catch (error) {
|
|
385
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
for (const routePath of buildControlRouteAliases("/tasks/:title/runs/:timestamp")) {
|
|
391
|
-
app.get(routePath, async (c) => {
|
|
392
|
-
try {
|
|
393
|
-
const runtime = params.getAgentRuntime();
|
|
394
|
-
const title = decodeMaybe(String(c.req.param("title") || "").trim());
|
|
395
|
-
const timestamp = String(c.req.param("timestamp") || "").trim();
|
|
396
|
-
if (!title) {
|
|
397
|
-
return c.json({ success: false, error: "Invalid title" }, 400);
|
|
398
|
-
}
|
|
399
|
-
if (!TASK_RUN_DIR_REGEX.test(timestamp)) {
|
|
400
|
-
return c.json({ success: false, error: "Invalid timestamp" }, 400);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
const detail = await readTaskRunDetail({
|
|
404
|
-
projectRoot: runtime.rootPath,
|
|
405
|
-
title,
|
|
406
|
-
timestamp,
|
|
407
|
-
});
|
|
408
|
-
if (!detail) {
|
|
409
|
-
return c.json({ success: false, error: "Run not found" }, 404);
|
|
410
|
-
}
|
|
411
|
-
return c.json({ success: true, ...detail });
|
|
412
|
-
} catch (error) {
|
|
413
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
for (const routePath of buildControlRouteAliases("/logs")) {
|
|
419
|
-
app.get(routePath, async (c) => {
|
|
420
|
-
try {
|
|
421
|
-
const runtime = params.getAgentRuntime();
|
|
422
|
-
const limit = toLimit(c.req.query("limit"), 200);
|
|
423
|
-
const logs = await readRecentLogs({
|
|
424
|
-
projectRoot: runtime.rootPath,
|
|
425
|
-
limit,
|
|
426
|
-
});
|
|
427
|
-
return c.json({
|
|
428
|
-
success: true,
|
|
429
|
-
logs,
|
|
430
|
-
});
|
|
431
|
-
} catch (error) {
|
|
432
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Control 路由注册类型定义。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 统一描述单 agent 控制面路由的公共依赖。
|
|
6
|
-
* - 各路由模块共享同一份入参,避免重复声明与漂移。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Hono } from "hono";
|
|
10
|
-
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
11
|
-
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Control 路由注册入参。
|
|
15
|
-
*/
|
|
16
|
-
export interface ControlRouteRegistrationParams {
|
|
17
|
-
/**
|
|
18
|
-
* Hono 应用实例。
|
|
19
|
-
*/
|
|
20
|
-
app: Hono;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 读取当前 agent 状态。
|
|
24
|
-
*/
|
|
25
|
-
getAgentRuntime: () => AgentRuntime;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 读取当前统一执行上下文。
|
|
29
|
-
*/
|
|
30
|
-
getAgentContext: () => AgentContext;
|
|
31
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 执行入口路由模块。
|
|
3
|
-
*
|
|
4
|
-
* 职责说明:
|
|
5
|
-
* 1. 接收 `/api/execute` 请求。
|
|
6
|
-
* 2. 完成请求解析、context 注入、agent 执行与结果回写。
|
|
7
|
-
* 3. 统一处理接口层错误返回。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Hono } from "hono";
|
|
11
|
-
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 执行入口路由参数。
|
|
15
|
-
*/
|
|
16
|
-
type ExecuteRouterOptions = {
|
|
17
|
-
/**
|
|
18
|
-
* 读取当前 agent runtime。
|
|
19
|
-
*/
|
|
20
|
-
getAgentRuntime: () => AgentRuntime;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 创建执行入口路由。
|
|
25
|
-
*/
|
|
26
|
-
export function createExecuteRouter(
|
|
27
|
-
options: ExecuteRouterOptions,
|
|
28
|
-
): Hono {
|
|
29
|
-
const router = new Hono();
|
|
30
|
-
|
|
31
|
-
router.post("/api/execute", async (c) => {
|
|
32
|
-
let bodyText = "";
|
|
33
|
-
try {
|
|
34
|
-
bodyText = await c.req.text();
|
|
35
|
-
} catch {
|
|
36
|
-
return c.json(
|
|
37
|
-
{ success: false, message: "Unable to read request body" },
|
|
38
|
-
400,
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!bodyText) {
|
|
43
|
-
return c.json({ success: false, message: "Request body is empty" }, 400);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let body: {
|
|
47
|
-
instructions?: string;
|
|
48
|
-
chatId?: string;
|
|
49
|
-
userId?: string;
|
|
50
|
-
actorId?: string;
|
|
51
|
-
messageId?: string;
|
|
52
|
-
};
|
|
53
|
-
try {
|
|
54
|
-
body = JSON.parse(bodyText) as typeof body;
|
|
55
|
-
} catch {
|
|
56
|
-
return c.json(
|
|
57
|
-
{
|
|
58
|
-
success: false,
|
|
59
|
-
message: `JSON parse failed: ${bodyText.substring(0, 50)}...`,
|
|
60
|
-
},
|
|
61
|
-
400,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const instructions = body?.instructions;
|
|
66
|
-
const chatId =
|
|
67
|
-
typeof body?.chatId === "string" && body.chatId.trim()
|
|
68
|
-
? body.chatId.trim()
|
|
69
|
-
: "default";
|
|
70
|
-
if (!instructions) {
|
|
71
|
-
return c.json(
|
|
72
|
-
{ success: false, message: "Missing instructions field" },
|
|
73
|
-
400,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
const sessionId = `api:chat:${chatId}`;
|
|
79
|
-
const agentState = options.getAgentRuntime();
|
|
80
|
-
const session = agentState.getSession(sessionId);
|
|
81
|
-
const turn = await session.prompt({
|
|
82
|
-
query: String(instructions),
|
|
83
|
-
});
|
|
84
|
-
const result = await turn.finished;
|
|
85
|
-
|
|
86
|
-
return c.json({
|
|
87
|
-
success: result.success,
|
|
88
|
-
...(result.error ? { error: result.error } : {}),
|
|
89
|
-
assistantMessage: result.assistantMessage,
|
|
90
|
-
});
|
|
91
|
-
} catch (error) {
|
|
92
|
-
return c.json({ success: false, message: String(error) }, 500);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return router;
|
|
97
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 健康检查路由模块。
|
|
3
|
-
*
|
|
4
|
-
* 职责说明:
|
|
5
|
-
* 1. 提供基础健康检查接口。
|
|
6
|
-
* 2. 提供当前进程状态接口。
|
|
7
|
-
* 3. 不依赖业务域实现。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Hono } from "hono";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 健康检查路由。
|
|
14
|
-
*/
|
|
15
|
-
export const healthRouter = new Hono();
|
|
16
|
-
|
|
17
|
-
healthRouter.get("/health", (c) => {
|
|
18
|
-
return c.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
healthRouter.get("/api/status", (c) => {
|
|
22
|
-
return c.json({
|
|
23
|
-
name: "downcity",
|
|
24
|
-
status: "running",
|
|
25
|
-
timestamp: new Date().toISOString(),
|
|
26
|
-
});
|
|
27
|
-
});
|