@downcity/agent 1.1.71 → 1.1.72
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/tools/shell/ShellToolFormatting.js +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
- package/bin/index.d.ts +1 -4
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -5
- package/bin/index.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/package.json +3 -3
- package/src/executor/tools/shell/ShellToolFormatting.ts +1 -1
- package/src/index.ts +1 -15
- 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/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/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/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,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin 路由模块。
|
|
3
|
-
*
|
|
4
|
-
* 职责说明:
|
|
5
|
-
* 1. 提供 plugin catalog / state / availability 接口。
|
|
6
|
-
* 2. 提供 plugin lifecycle 控制接口。
|
|
7
|
-
* 3. 提供 plugin command / action 桥接接口。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Hono } from "hono";
|
|
11
|
-
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
12
|
-
import {
|
|
13
|
-
controlPluginState,
|
|
14
|
-
listPluginStates,
|
|
15
|
-
} from "@/plugin/core/PluginStateController.js";
|
|
16
|
-
import type { PluginStateControlAction } from "@/plugin/types/Plugin.js";
|
|
17
|
-
import { parsePluginCommandRequestBody } from "@/plugin/core/PluginCommandRequest.js";
|
|
18
|
-
import { runPluginCommand } from "@/plugin/core/PluginActionRunner.js";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Plugin 路由参数。
|
|
22
|
-
*/
|
|
23
|
-
type PluginsRouterOptions = {
|
|
24
|
-
/**
|
|
25
|
-
* 读取当前 agent 执行上下文。
|
|
26
|
-
*/
|
|
27
|
-
getAgentContext: () => AgentContext;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 创建 plugin 路由。
|
|
32
|
-
*/
|
|
33
|
-
export function createPluginsRouter(
|
|
34
|
-
options: PluginsRouterOptions,
|
|
35
|
-
): Hono {
|
|
36
|
-
const router = new Hono();
|
|
37
|
-
|
|
38
|
-
router.get("/api/plugins/catalog", (c) => {
|
|
39
|
-
return c.json({
|
|
40
|
-
success: true,
|
|
41
|
-
plugins: options.getAgentContext().plugins.list(),
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
router.get("/api/plugins/list", (c) => {
|
|
46
|
-
return c.json({
|
|
47
|
-
success: true,
|
|
48
|
-
plugins: listPluginStates({
|
|
49
|
-
context: options.getAgentContext(),
|
|
50
|
-
}),
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
router.post("/api/plugins/control", async (c) => {
|
|
55
|
-
const body = await c.req.json().catch(() => null);
|
|
56
|
-
const pluginName = String(body?.pluginName || "").trim();
|
|
57
|
-
const action = String(body?.action || "")
|
|
58
|
-
.trim()
|
|
59
|
-
.toLowerCase();
|
|
60
|
-
|
|
61
|
-
if (!pluginName) {
|
|
62
|
-
return c.json({ success: false, error: "pluginName is required" }, 400);
|
|
63
|
-
}
|
|
64
|
-
if (!action) {
|
|
65
|
-
return c.json({ success: false, error: "action is required" }, 400);
|
|
66
|
-
}
|
|
67
|
-
if (!["start", "stop", "restart", "status"].includes(action)) {
|
|
68
|
-
return c.json({ success: false, error: "invalid action" }, 400);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const result = await controlPluginState({
|
|
72
|
-
pluginName,
|
|
73
|
-
action: action as PluginStateControlAction,
|
|
74
|
-
context: options.getAgentContext(),
|
|
75
|
-
});
|
|
76
|
-
return c.json(result, result.success ? 200 : 400);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
router.post("/api/plugins/command", async (c) => {
|
|
80
|
-
const body = await c.req.json().catch(() => null);
|
|
81
|
-
let requestBody;
|
|
82
|
-
try {
|
|
83
|
-
requestBody = parsePluginCommandRequestBody(body);
|
|
84
|
-
} catch (error) {
|
|
85
|
-
return c.json({ success: false, error: String(error) }, 400);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!requestBody.pluginName) {
|
|
89
|
-
return c.json({ success: false, error: "pluginName is required" }, 400);
|
|
90
|
-
}
|
|
91
|
-
if (!requestBody.command) {
|
|
92
|
-
return c.json({ success: false, error: "command is required" }, 400);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const result = await runPluginCommand({
|
|
96
|
-
pluginName: requestBody.pluginName,
|
|
97
|
-
command: requestBody.command,
|
|
98
|
-
payload: requestBody.payload,
|
|
99
|
-
schedule: requestBody.schedule,
|
|
100
|
-
context: options.getAgentContext(),
|
|
101
|
-
});
|
|
102
|
-
return c.json(result, result.success ? 200 : 400);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
router.post("/api/plugins/availability", async (c) => {
|
|
106
|
-
const body = await c.req.json().catch(() => null);
|
|
107
|
-
const pluginName = String(body?.pluginName || "").trim();
|
|
108
|
-
|
|
109
|
-
if (!pluginName) {
|
|
110
|
-
return c.json({ success: false, error: "pluginName is required" }, 400);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const availability =
|
|
114
|
-
await options.getAgentContext().plugins.availability(pluginName);
|
|
115
|
-
return c.json({
|
|
116
|
-
success: true,
|
|
117
|
-
pluginName,
|
|
118
|
-
availability,
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
router.post("/api/plugins/action", async (c) => {
|
|
123
|
-
const body = await c.req.json().catch(() => null);
|
|
124
|
-
const pluginName = String(body?.pluginName || "").trim();
|
|
125
|
-
const actionName = String(body?.actionName || "").trim();
|
|
126
|
-
|
|
127
|
-
if (!pluginName) {
|
|
128
|
-
return c.json({ success: false, error: "pluginName is required" }, 400);
|
|
129
|
-
}
|
|
130
|
-
if (!actionName) {
|
|
131
|
-
return c.json({ success: false, error: "actionName is required" }, 400);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const result = await options.getAgentContext().plugins.runAction({
|
|
135
|
-
plugin: pluginName,
|
|
136
|
-
action: actionName,
|
|
137
|
-
payload: body?.payload,
|
|
138
|
-
});
|
|
139
|
-
return c.json(
|
|
140
|
-
{
|
|
141
|
-
...result,
|
|
142
|
-
pluginName,
|
|
143
|
-
actionName,
|
|
144
|
-
},
|
|
145
|
-
result.success ? 200 : 400,
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
return router;
|
|
150
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK HTTP 路由入口模块。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里专门承载 `RemoteAgent` 对应的最小 SDK transport。
|
|
6
|
-
* - 路由面围绕 Session actor 公开能力展开,不混入 control UI 语义。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { Hono } from "hono";
|
|
10
|
-
import type { AgentSessionCollection } from "@/types/agent/AgentTypes.js";
|
|
11
|
-
import { registerSdkSessionRoutes } from "@/runtime/server/http/sdk/SessionRoutes.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 创建 SDK HTTP router。
|
|
15
|
-
*/
|
|
16
|
-
export function createSdkRouter(
|
|
17
|
-
sessionCollection: AgentSessionCollection,
|
|
18
|
-
): Hono {
|
|
19
|
-
const router = new Hono();
|
|
20
|
-
registerSdkSessionRoutes(router, sessionCollection);
|
|
21
|
-
return router;
|
|
22
|
-
}
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK HTTP session 路由。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这组路由面向 `RemoteAgent`,只暴露最小 Session actor 使用面。
|
|
6
|
-
* - 当前公开输入收口到 `prompt()`,公开输出收口到 `events` 长连接。
|
|
7
|
-
* - 不复用 control API 的控制台语义,避免 transport 面混入非 SDK 约束。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Hono } from "hono";
|
|
11
|
-
import type {
|
|
12
|
-
AgentListSessionsInput,
|
|
13
|
-
AgentSessionCollection,
|
|
14
|
-
} from "@/types/agent/AgentTypes.js";
|
|
15
|
-
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
16
|
-
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
17
|
-
|
|
18
|
-
const NDJSON_CONTENT_TYPE = "application/x-ndjson; charset=utf-8";
|
|
19
|
-
const SDK_EVENTS_READY_FRAME = {
|
|
20
|
-
type: "sdk-events-ready",
|
|
21
|
-
} as const;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 注册 SDK session 路由。
|
|
25
|
-
*/
|
|
26
|
-
export function registerSdkSessionRoutes(
|
|
27
|
-
app: Hono,
|
|
28
|
-
sessionCollection: AgentSessionCollection,
|
|
29
|
-
): void {
|
|
30
|
-
app.get("/api/sdk/sessions", async (c) => {
|
|
31
|
-
try {
|
|
32
|
-
const input: AgentListSessionsInput = {
|
|
33
|
-
...(c.req.query("limit") ? { limit: Number(c.req.query("limit")) } : {}),
|
|
34
|
-
...(c.req.query("cursor") ? { cursor: c.req.query("cursor") } : {}),
|
|
35
|
-
...(c.req.query("query") ? { query: c.req.query("query") } : {}),
|
|
36
|
-
};
|
|
37
|
-
const page = await sessionCollection.listSessions(input);
|
|
38
|
-
return c.json({
|
|
39
|
-
success: true,
|
|
40
|
-
page,
|
|
41
|
-
sessions: page.items,
|
|
42
|
-
});
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return c.json(
|
|
45
|
-
{
|
|
46
|
-
success: false,
|
|
47
|
-
error: error instanceof Error ? error.message : String(error),
|
|
48
|
-
},
|
|
49
|
-
500,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
app.post("/api/sdk/sessions", async (c) => {
|
|
55
|
-
try {
|
|
56
|
-
const body = (await c.req.json().catch(() => ({}))) as {
|
|
57
|
-
sessionId?: unknown;
|
|
58
|
-
};
|
|
59
|
-
const session = await sessionCollection.createSession({
|
|
60
|
-
...(body.sessionId ? { sessionId: String(body.sessionId).trim() } : {}),
|
|
61
|
-
});
|
|
62
|
-
return c.json({
|
|
63
|
-
success: true,
|
|
64
|
-
session: await session.getInfo(),
|
|
65
|
-
});
|
|
66
|
-
} catch (error) {
|
|
67
|
-
return c.json(
|
|
68
|
-
{
|
|
69
|
-
success: false,
|
|
70
|
-
error: error instanceof Error ? error.message : String(error),
|
|
71
|
-
},
|
|
72
|
-
500,
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
app.get("/api/sdk/sessions/:sessionId", async (c) => {
|
|
78
|
-
try {
|
|
79
|
-
const sessionId = String(c.req.param("sessionId") || "").trim();
|
|
80
|
-
if (!sessionId) {
|
|
81
|
-
return c.json({ success: false, error: "Missing sessionId" }, 400);
|
|
82
|
-
}
|
|
83
|
-
const session = await sessionCollection.getSession(sessionId);
|
|
84
|
-
return c.json({
|
|
85
|
-
success: true,
|
|
86
|
-
session: await session.getInfo(),
|
|
87
|
-
});
|
|
88
|
-
} catch (error) {
|
|
89
|
-
return c.json(
|
|
90
|
-
{
|
|
91
|
-
success: false,
|
|
92
|
-
error: error instanceof Error ? error.message : String(error),
|
|
93
|
-
},
|
|
94
|
-
500,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
app.post("/api/sdk/sessions/:sessionId/prompt", async (c) => {
|
|
100
|
-
try {
|
|
101
|
-
const sessionId = String(c.req.param("sessionId") || "").trim();
|
|
102
|
-
if (!sessionId) {
|
|
103
|
-
return c.json({ success: false, error: "Missing sessionId" }, 400);
|
|
104
|
-
}
|
|
105
|
-
const body = (await c.req.json()) as AgentSessionPromptInput;
|
|
106
|
-
const session = await sessionCollection.getSession(sessionId);
|
|
107
|
-
const turn = await session.prompt(body);
|
|
108
|
-
return c.json({
|
|
109
|
-
success: true,
|
|
110
|
-
turn: {
|
|
111
|
-
id: turn.id,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
} catch (error) {
|
|
115
|
-
return c.json(
|
|
116
|
-
{
|
|
117
|
-
success: false,
|
|
118
|
-
error: error instanceof Error ? error.message : String(error),
|
|
119
|
-
},
|
|
120
|
-
500,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
app.get("/api/sdk/sessions/:sessionId/events", async (c) => {
|
|
126
|
-
const sessionId = String(c.req.param("sessionId") || "").trim();
|
|
127
|
-
if (!sessionId) {
|
|
128
|
-
return c.json({ success: false, error: "Missing sessionId" }, 400);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const session = await sessionCollection.getSession(sessionId);
|
|
133
|
-
const encoder = new TextEncoder();
|
|
134
|
-
const requestSignal = c.req.raw.signal;
|
|
135
|
-
|
|
136
|
-
let cleanupEventsConnection = (): void => {};
|
|
137
|
-
const stream = new ReadableStream<Uint8Array>({
|
|
138
|
-
cancel() {
|
|
139
|
-
cleanupEventsConnection();
|
|
140
|
-
},
|
|
141
|
-
start(controller) {
|
|
142
|
-
const writeLine = (value: unknown): void => {
|
|
143
|
-
controller.enqueue(encoder.encode(`${JSON.stringify(value)}\n`));
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const unsubscribe = session.subscribe((event) => {
|
|
147
|
-
writeLine(event);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const closeStream = (): void => {
|
|
151
|
-
cleanupEventsConnection();
|
|
152
|
-
try {
|
|
153
|
-
controller.close();
|
|
154
|
-
} catch {
|
|
155
|
-
// ignore duplicate close attempts
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
cleanupEventsConnection = (): void => {
|
|
160
|
-
unsubscribe();
|
|
161
|
-
requestSignal.removeEventListener("abort", closeStream);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
if (requestSignal.aborted) {
|
|
165
|
-
closeStream();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
requestSignal.addEventListener("abort", closeStream, { once: true });
|
|
170
|
-
writeLine(SDK_EVENTS_READY_FRAME);
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return new Response(stream, {
|
|
175
|
-
status: 200,
|
|
176
|
-
headers: {
|
|
177
|
-
"Content-Type": NDJSON_CONTENT_TYPE,
|
|
178
|
-
"Cache-Control": "no-cache, no-transform",
|
|
179
|
-
"X-Accel-Buffering": "no",
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
} catch (error) {
|
|
183
|
-
return c.json(
|
|
184
|
-
{
|
|
185
|
-
success: false,
|
|
186
|
-
error: error instanceof Error ? error.message : String(error),
|
|
187
|
-
},
|
|
188
|
-
500,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
app.get("/api/sdk/sessions/:sessionId/history", async (c) => {
|
|
194
|
-
try {
|
|
195
|
-
const sessionId = String(c.req.param("sessionId") || "").trim();
|
|
196
|
-
if (!sessionId) {
|
|
197
|
-
return c.json({ success: false, error: "Missing sessionId" }, 400);
|
|
198
|
-
}
|
|
199
|
-
const session = await sessionCollection.getSession(sessionId);
|
|
200
|
-
const history = await session.history({
|
|
201
|
-
...(c.req.query("limit") ? { limit: Number(c.req.query("limit")) } : {}),
|
|
202
|
-
...(c.req.query("cursor") ? { cursor: c.req.query("cursor") } : {}),
|
|
203
|
-
...(c.req.query("order")
|
|
204
|
-
? { order: c.req.query("order") as "asc" | "desc" }
|
|
205
|
-
: {}),
|
|
206
|
-
...(c.req.query("view")
|
|
207
|
-
? { view: c.req.query("view") as "message" | "timeline" }
|
|
208
|
-
: {}),
|
|
209
|
-
});
|
|
210
|
-
return c.json({
|
|
211
|
-
success: true,
|
|
212
|
-
history,
|
|
213
|
-
});
|
|
214
|
-
} catch (error) {
|
|
215
|
-
return c.json(
|
|
216
|
-
{
|
|
217
|
-
success: false,
|
|
218
|
-
error: error instanceof Error ? error.message : String(error),
|
|
219
|
-
},
|
|
220
|
-
500,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
app.get("/api/sdk/sessions/:sessionId/messages", async (c) => {
|
|
226
|
-
try {
|
|
227
|
-
const sessionId = String(c.req.param("sessionId") || "").trim();
|
|
228
|
-
if (!sessionId) {
|
|
229
|
-
return c.json({ success: false, error: "Missing sessionId" }, 400);
|
|
230
|
-
}
|
|
231
|
-
const session = await sessionCollection.getSession(sessionId);
|
|
232
|
-
const history = await session.history({
|
|
233
|
-
view: "message",
|
|
234
|
-
});
|
|
235
|
-
return c.json({
|
|
236
|
-
success: true,
|
|
237
|
-
messages: history.items,
|
|
238
|
-
history,
|
|
239
|
-
});
|
|
240
|
-
} catch (error) {
|
|
241
|
-
return c.json(
|
|
242
|
-
{
|
|
243
|
-
success: false,
|
|
244
|
-
error: error instanceof Error ? error.message : String(error),
|
|
245
|
-
},
|
|
246
|
-
500,
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
app.get("/api/sdk/sessions/:sessionId/system", async (c) => {
|
|
252
|
-
try {
|
|
253
|
-
const sessionId = String(c.req.param("sessionId") || "").trim();
|
|
254
|
-
if (!sessionId) {
|
|
255
|
-
return c.json({ success: false, error: "Missing sessionId" }, 400);
|
|
256
|
-
}
|
|
257
|
-
const session = await sessionCollection.getSession(sessionId);
|
|
258
|
-
return c.json({
|
|
259
|
-
success: true,
|
|
260
|
-
system: await session.system(),
|
|
261
|
-
});
|
|
262
|
-
} catch (error) {
|
|
263
|
-
return c.json(
|
|
264
|
-
{
|
|
265
|
-
success: false,
|
|
266
|
-
error: error instanceof Error ? error.message : String(error),
|
|
267
|
-
},
|
|
268
|
-
500,
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
app.post("/api/sdk/sessions/:sessionId/fork", async (c) => {
|
|
274
|
-
try {
|
|
275
|
-
const sessionId = String(c.req.param("sessionId") || "").trim();
|
|
276
|
-
if (!sessionId) {
|
|
277
|
-
return c.json({ success: false, error: "Missing sessionId" }, 400);
|
|
278
|
-
}
|
|
279
|
-
const body = (await c.req.json().catch(() => ({}))) as {
|
|
280
|
-
messageId?: unknown;
|
|
281
|
-
};
|
|
282
|
-
const session = await sessionCollection.getSession(sessionId);
|
|
283
|
-
const forked = await session.fork(
|
|
284
|
-
String(body.messageId || "").trim() || undefined,
|
|
285
|
-
);
|
|
286
|
-
return c.json({
|
|
287
|
-
success: true,
|
|
288
|
-
session: await forked.getInfo(),
|
|
289
|
-
});
|
|
290
|
-
} catch (error) {
|
|
291
|
-
return c.json(
|
|
292
|
-
{
|
|
293
|
-
success: false,
|
|
294
|
-
error: error instanceof Error ? error.message : String(error),
|
|
295
|
-
},
|
|
296
|
-
500,
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 静态资源路由模块。
|
|
3
|
-
*
|
|
4
|
-
* 职责说明:
|
|
5
|
-
* 1. 提供根目录前端静态文件访问。
|
|
6
|
-
* 2. 提供 `.downcity/public` 的受限文件暴露。
|
|
7
|
-
* 3. 只处理静态资源协议,不承载业务逻辑。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Hono } from "hono";
|
|
11
|
-
import fs from "fs-extra";
|
|
12
|
-
import path from "path";
|
|
13
|
-
import { getDowncityPublicDirPath } from "@/config/Paths.js";
|
|
14
|
-
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 静态资源路由参数。
|
|
18
|
-
*/
|
|
19
|
-
type StaticRouterOptions = {
|
|
20
|
-
/**
|
|
21
|
-
* 读取当前 agent runtime。
|
|
22
|
-
*/
|
|
23
|
-
getAgentRuntime: () => AgentRuntime;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 创建静态资源路由。
|
|
28
|
-
*/
|
|
29
|
-
export function createStaticRouter(
|
|
30
|
-
options: StaticRouterOptions,
|
|
31
|
-
): Hono {
|
|
32
|
-
const router = new Hono();
|
|
33
|
-
|
|
34
|
-
router.get("/", async (c) => {
|
|
35
|
-
const indexPath = path.join(options.getAgentRuntime().rootPath, "public", "index.html");
|
|
36
|
-
if (await fs.pathExists(indexPath)) {
|
|
37
|
-
const content = await fs.readFile(indexPath, "utf-8");
|
|
38
|
-
return c.body(content, 200, {
|
|
39
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
40
|
-
"Cache-Control": "no-cache",
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return c.text("Downcity Agent Server", 200);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
router.get("/styles.css", async (c) => {
|
|
47
|
-
const cssPath = path.join(options.getAgentRuntime().rootPath, "public", "styles.css");
|
|
48
|
-
if (await fs.pathExists(cssPath)) {
|
|
49
|
-
const content = await fs.readFile(cssPath, "utf-8");
|
|
50
|
-
return c.body(content, 200, {
|
|
51
|
-
"Content-Type": "text/css; charset=utf-8",
|
|
52
|
-
"Cache-Control": "no-cache",
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return c.text("Not Found", 404);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
router.get("/app.js", async (c) => {
|
|
59
|
-
const jsPath = path.join(options.getAgentRuntime().rootPath, "public", "app.js");
|
|
60
|
-
if (await fs.pathExists(jsPath)) {
|
|
61
|
-
const content = await fs.readFile(jsPath, "utf-8");
|
|
62
|
-
return c.body(content, 200, {
|
|
63
|
-
"Content-Type": "application/javascript; charset=utf-8",
|
|
64
|
-
"Cache-Control": "no-cache",
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return c.text("Not Found", 404);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
router.get("/downcity/public/*", async (c) => {
|
|
71
|
-
const root = getDowncityPublicDirPath(options.getAgentRuntime().rootPath);
|
|
72
|
-
const prefix = "/downcity/public/";
|
|
73
|
-
const requestPath = c.req.path;
|
|
74
|
-
const rel = requestPath.startsWith(prefix)
|
|
75
|
-
? requestPath.slice(prefix.length)
|
|
76
|
-
: "";
|
|
77
|
-
if (!rel) return c.text("Not Found", 404);
|
|
78
|
-
|
|
79
|
-
const full = path.resolve(root, rel);
|
|
80
|
-
const rootResolved = path.resolve(root);
|
|
81
|
-
if (full !== rootResolved && !full.startsWith(rootResolved + path.sep)) {
|
|
82
|
-
return c.text("Forbidden", 403);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
const stat = await fs.stat(full);
|
|
87
|
-
if (!stat.isFile()) return c.text("Not Found", 404);
|
|
88
|
-
} catch {
|
|
89
|
-
return c.text("Not Found", 404);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const ext = path.extname(full).toLowerCase();
|
|
93
|
-
const contentType =
|
|
94
|
-
ext === ".html"
|
|
95
|
-
? "text/html; charset=utf-8"
|
|
96
|
-
: ext === ".css"
|
|
97
|
-
? "text/css; charset=utf-8"
|
|
98
|
-
: ext === ".js"
|
|
99
|
-
? "application/javascript; charset=utf-8"
|
|
100
|
-
: ext === ".json"
|
|
101
|
-
? "application/json; charset=utf-8"
|
|
102
|
-
: ext === ".txt" || ext === ".md"
|
|
103
|
-
? "text/plain; charset=utf-8"
|
|
104
|
-
: ext === ".pdf"
|
|
105
|
-
? "application/pdf"
|
|
106
|
-
: ext === ".png"
|
|
107
|
-
? "image/png"
|
|
108
|
-
: ext === ".jpg" || ext === ".jpeg"
|
|
109
|
-
? "image/jpeg"
|
|
110
|
-
: "application/octet-stream";
|
|
111
|
-
|
|
112
|
-
const buf = await fs.readFile(full);
|
|
113
|
-
return c.body(buf, 200, {
|
|
114
|
-
"Content-Type": contentType,
|
|
115
|
-
"Cache-Control": "no-cache",
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
return router;
|
|
120
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 后台常驻(daemon)相关类型与常量。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里统一描述 agent daemon 的 pid/log/meta 文件命名与元信息结构。
|
|
6
|
-
* - city 全局后台的运行时文件命名不放在这里,而是放到 city 包的 process/registry 路径模块。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/** daemon pid 文件名。 */
|
|
10
|
-
export const DAEMON_PID_FILENAME = "downcity.pid";
|
|
11
|
-
/** daemon 日志文件名。 */
|
|
12
|
-
export const DAEMON_LOG_FILENAME = "downcity.daemon.log";
|
|
13
|
-
/** daemon 元数据文件名。 */
|
|
14
|
-
export const DAEMON_META_FILENAME = "downcity.daemon.json";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* daemon 元数据文件结构。
|
|
18
|
-
*/
|
|
19
|
-
export interface DaemonMeta {
|
|
20
|
-
/** 当前 daemon 进程的操作系统 pid。 */
|
|
21
|
-
pid: number;
|
|
22
|
-
/** daemon 所属 agent 项目的绝对路径。 */
|
|
23
|
-
projectRoot: string;
|
|
24
|
-
/** daemon 启动时间(ISO 时间字符串)。 */
|
|
25
|
-
startedAt: string;
|
|
26
|
-
/** 启动 daemon 时使用的命令。 */
|
|
27
|
-
command: string;
|
|
28
|
-
/** 启动 daemon 时使用的参数列表。 */
|
|
29
|
-
args: string[];
|
|
30
|
-
/** 当前 node 可执行文件路径。 */
|
|
31
|
-
node: string;
|
|
32
|
-
/** 当前运行平台。 */
|
|
33
|
-
platform: NodeJS.Platform;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* daemon 进入 stale 状态的诊断项。
|
|
38
|
-
*/
|
|
39
|
-
export interface DaemonStaleReason {
|
|
40
|
-
/**
|
|
41
|
-
* 机器可读的原因编码。
|
|
42
|
-
*/
|
|
43
|
-
code:
|
|
44
|
-
| "process_not_alive"
|
|
45
|
-
| "meta_missing"
|
|
46
|
-
| "meta_invalid"
|
|
47
|
-
| "meta_pid_mismatch"
|
|
48
|
-
| "meta_project_mismatch";
|
|
49
|
-
/**
|
|
50
|
-
* 面向用户展示的原因说明。
|
|
51
|
-
*/
|
|
52
|
-
message: string;
|
|
53
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|