@downcity/agent 1.1.43 → 1.1.62
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/README.md +11 -12
- package/bin/agent/Agent.d.ts +31 -16
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +47 -63
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/RemoteAgent.d.ts +6 -6
- package/bin/agent/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/RemoteAgent.js +377 -267
- package/bin/agent/RemoteAgent.js.map +1 -1
- package/bin/config/AgentInitializer.d.ts +5 -5
- package/bin/config/AgentInitializer.d.ts.map +1 -1
- package/bin/config/AgentInitializer.js +15 -13
- package/bin/config/AgentInitializer.js.map +1 -1
- package/bin/config/Config.d.ts +9 -30
- package/bin/config/Config.d.ts.map +1 -1
- package/bin/config/Config.js +23 -70
- package/bin/config/Config.js.map +1 -1
- package/bin/config/Defaults.d.ts.map +1 -1
- package/bin/config/Defaults.js +1 -9
- package/bin/config/Defaults.js.map +1 -1
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +4 -112
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/config/ExecutionBinding.d.ts +1 -16
- package/bin/config/ExecutionBinding.d.ts.map +1 -1
- package/bin/config/ExecutionBinding.js +2 -22
- package/bin/config/ExecutionBinding.js.map +1 -1
- package/bin/config/Paths.d.ts +4 -43
- package/bin/config/Paths.d.ts.map +1 -1
- package/bin/config/Paths.js +10 -30
- package/bin/config/Paths.js.map +1 -1
- package/bin/config/PlatformPaths.d.ts +0 -4
- package/bin/config/PlatformPaths.d.ts.map +1 -1
- package/bin/config/PlatformPaths.js +5 -1
- package/bin/config/PlatformPaths.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +0 -4
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
- package/bin/executor/composer/system/default/InitPrompts.d.ts +1 -1
- package/bin/executor/composer/system/default/InitPrompts.js +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.js +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.d.ts +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.js +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +1 -2
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +17 -56
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolBridge.js +1 -1
- package/bin/executor/tools/shell/ShellToolBridge.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolDefinition.d.ts +2 -2
- package/bin/executor/tools/shell/ShellToolFormatting.d.ts +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js +9 -9
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts +7 -75
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +5 -24
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.js +1 -1
- package/bin/executor/types/SessionRun.d.ts +1 -1
- package/bin/index.d.ts +5 -6
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +6 -5
- package/bin/index.js.map +1 -1
- package/bin/model/CityModelAdapter.d.ts +23 -0
- package/bin/model/CityModelAdapter.d.ts.map +1 -0
- package/bin/model/CityModelAdapter.js +338 -0
- package/bin/model/CityModelAdapter.js.map +1 -0
- package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
- package/bin/plugin/core/PluginCommandRequest.js +1 -1
- package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +4 -8
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/types/PluginApi.d.ts +1 -1
- package/bin/rpc/Client.d.ts +104 -0
- package/bin/rpc/Client.d.ts.map +1 -0
- package/bin/rpc/Client.js +300 -0
- package/bin/rpc/Client.js.map +1 -0
- package/bin/rpc/Server.d.ts +41 -0
- package/bin/rpc/Server.d.ts.map +1 -0
- package/bin/rpc/Server.js +164 -0
- package/bin/rpc/Server.js.map +1 -0
- package/bin/runtime/host/daemon/Api.d.ts +1 -1
- package/bin/runtime/host/daemon/Client.d.ts +1 -1
- package/bin/runtime/host/daemon/Client.d.ts.map +1 -1
- package/bin/runtime/host/daemon/Client.js +30 -20
- package/bin/runtime/host/daemon/Client.js.map +1 -1
- package/bin/runtime/host/daemon/Paths.d.ts +1 -1
- package/bin/runtime/host/daemon/Paths.js +1 -1
- package/bin/runtime/host/daemon/ProjectSetup.js +2 -2
- package/bin/runtime/server/http/control/OverviewRoutes.js +1 -1
- package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -1
- package/bin/session/Session.d.ts +1 -0
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +32 -6
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +49 -0
- package/bin/session/SessionTitle.d.ts.map +1 -0
- package/bin/session/SessionTitle.js +130 -0
- package/bin/session/SessionTitle.js.map +1 -0
- package/bin/session/browse/Browse.d.ts +2 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +18 -15
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +3 -2
- package/bin/session/index.d.ts.map +1 -1
- package/bin/session/index.js +3 -2
- package/bin/session/index.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +4 -0
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +12 -25
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +0 -4
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +0 -6
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/Persistence.js +1 -4
- package/bin/session/storage/Persistence.js.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +32 -57
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/config/AgentProject.d.ts +7 -6
- package/bin/types/config/AgentProject.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +11 -69
- package/bin/types/config/DowncityConfig.d.ts.map +1 -1
- package/bin/types/config/ExecutionBinding.d.ts +4 -4
- package/bin/types/config/ExecutionBinding.js +1 -1
- package/bin/types/config/LlmConfig.d.ts +1 -1
- package/bin/types/config/Start.d.ts +3 -0
- package/bin/types/config/Start.d.ts.map +1 -1
- package/bin/types/config/Start.js +2 -0
- package/bin/types/config/Start.js.map +1 -1
- package/bin/types/runtime/auth/AuthPermission.js +2 -2
- package/bin/types/runtime/auth/AuthPermission.js.map +1 -1
- package/bin/types/runtime/host/Store.d.ts +10 -227
- package/bin/types/runtime/host/Store.d.ts.map +1 -1
- package/bin/types/runtime/host/Store.js +7 -0
- package/bin/types/runtime/host/Store.js.map +1 -1
- package/bin/types/runtime/http/InlineInstant.d.ts +1 -1
- package/bin/types/runtime/platform/Platform.d.ts +7 -7
- package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
- package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
- package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
- package/bin/utils/Time.d.ts +0 -1
- package/bin/utils/Time.d.ts.map +1 -1
- package/bin/utils/Time.js +0 -7
- package/bin/utils/Time.js.map +1 -1
- package/bin/utils/storage/index.d.ts +0 -1
- package/bin/utils/storage/index.d.ts.map +1 -1
- package/bin/utils/storage/index.js +0 -6
- package/bin/utils/storage/index.js.map +1 -1
- package/package.json +22 -23
- package/src/agent/Agent.ts +57 -73
- package/src/agent/RemoteAgent.ts +515 -345
- package/src/config/AgentInitializer.ts +15 -13
- package/src/config/Config.ts +28 -85
- package/src/config/Defaults.ts +1 -9
- package/src/config/DowncitySchema.ts +4 -114
- package/src/config/ExecutionBinding.ts +2 -24
- package/src/config/Paths.ts +10 -43
- package/src/config/PlatformPaths.ts +5 -1
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +0 -4
- package/src/executor/composer/system/default/InitPrompts.ts +1 -1
- package/src/executor/composer/system/default/SystemDomain.ts +1 -1
- 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/composer/system/default/assets/init/PROFILE.md.ts +1 -1
- package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +1 -2
- package/src/executor/composer/system/default/assets/plugin.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/plugin.prompt.ts.txt +18 -18
- package/src/executor/composer/system/default/assets/task.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/task.prompt.ts.txt +1 -1
- package/src/executor/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +17 -57
- package/src/executor/tools/shell/ShellToolBridge.ts +1 -1
- package/src/executor/tools/shell/ShellToolFormatting.ts +9 -9
- package/src/executor/types/SessionHistoryMeta.ts +5 -25
- package/src/executor/types/SessionRun.ts +1 -1
- package/src/index.ts +12 -19
- package/src/model/CityModelAdapter.ts +384 -0
- package/src/plugin/core/PluginCommandRequest.ts +1 -1
- package/src/plugin/core/PluginLocalExecution.ts +4 -8
- package/src/plugin/types/PluginApi.ts +1 -1
- package/src/rpc/Client.ts +467 -0
- package/src/rpc/Server.ts +302 -0
- package/src/runtime/host/daemon/Api.ts +1 -1
- package/src/runtime/host/daemon/Client.ts +44 -22
- package/src/runtime/host/daemon/Paths.ts +1 -1
- package/src/runtime/host/daemon/ProjectSetup.ts +2 -2
- package/src/runtime/server/http/control/OverviewRoutes.ts +1 -1
- package/src/session/Session.ts +40 -6
- package/src/session/SessionTitle.ts +192 -0
- package/src/session/browse/Browse.ts +22 -13
- package/src/session/index.ts +5 -1
- package/src/session/storage/Metadata.ts +14 -29
- package/src/session/storage/Paths.ts +0 -10
- package/src/session/storage/Persistence.ts +1 -4
- package/src/types/agent/AgentTypes.ts +33 -62
- package/src/types/config/AgentProject.ts +7 -6
- package/src/types/config/DowncityConfig.ts +11 -70
- package/src/types/config/ExecutionBinding.ts +4 -4
- package/src/types/config/LlmConfig.ts +1 -1
- package/src/types/config/Start.ts +3 -0
- package/src/types/runtime/auth/AuthPermission.ts +2 -2
- package/src/types/runtime/host/Store.ts +10 -235
- package/src/types/runtime/http/InlineInstant.ts +1 -1
- package/src/types/runtime/platform/Platform.ts +7 -7
- package/src/types/runtime/platform/PlatformGateway.ts +2 -2
- package/src/utils/Time.ts +0 -6
- package/src/utils/storage/index.ts +0 -7
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/config/ConfigEnvResolver.d.ts +0 -22
- package/bin/config/ConfigEnvResolver.d.ts.map +0 -1
- package/bin/config/ConfigEnvResolver.js +0 -41
- package/bin/config/ConfigEnvResolver.js.map +0 -1
- package/bin/runtime/server/rpc/Server.d.ts +0 -18
- package/bin/runtime/server/rpc/Server.d.ts.map +0 -1
- package/bin/runtime/server/rpc/Server.js +0 -315
- package/bin/runtime/server/rpc/Server.js.map +0 -1
- package/bin/runtime/transport/rpc/Client.d.ts +0 -13
- package/bin/runtime/transport/rpc/Client.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Client.js +0 -98
- package/bin/runtime/transport/rpc/Client.js.map +0 -1
- package/bin/runtime/transport/rpc/Paths.d.ts +0 -14
- package/bin/runtime/transport/rpc/Paths.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Paths.js +0 -42
- package/bin/runtime/transport/rpc/Paths.js.map +0 -1
- package/bin/runtime/transport/rpc/Transport.d.ts +0 -21
- package/bin/runtime/transport/rpc/Transport.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Transport.js +0 -30
- package/bin/runtime/transport/rpc/Transport.js.map +0 -1
- package/bin/types/common/ResolvedConfigValue.d.ts +0 -12
- package/bin/types/common/ResolvedConfigValue.d.ts.map +0 -1
- package/bin/types/common/ResolvedConfigValue.js +0 -2
- package/bin/types/common/ResolvedConfigValue.js.map +0 -1
- package/bin/types/runtime/rpc/LocalRpc.d.ts +0 -69
- package/bin/types/runtime/rpc/LocalRpc.d.ts.map +0 -1
- package/bin/types/runtime/rpc/LocalRpc.js +0 -9
- package/bin/types/runtime/rpc/LocalRpc.js.map +0 -1
- package/src/config/ConfigEnvResolver.ts +0 -52
- package/src/runtime/server/rpc/Server.ts +0 -408
- package/src/runtime/transport/rpc/Client.ts +0 -113
- package/src/runtime/transport/rpc/Paths.ts +0 -50
- package/src/runtime/transport/rpc/Transport.ts +0 -43
- package/src/types/common/ResolvedConfigValue.ts +0 -16
- package/src/types/runtime/rpc/LocalRpc.ts +0 -72
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Source: src/executor/composer/system/default/assets/plugin.prompt.ts.txt
|
|
7
|
-
const TEXT_MODULE_CONTENT = "# Plugin State\n\n你正在一个基于 plugin 的执行环境中工作。\n\n## 可用命令总览\n- plugin 状态管理(统一使用 `
|
|
7
|
+
const TEXT_MODULE_CONTENT = "# Plugin State\n\n你正在一个基于 plugin 的执行环境中工作。\n\n## 可用命令总览\n- plugin 状态管理(统一使用 `town plugin`):\n - `town plugin list`\n - `town plugin status <pluginName>`\n - `town plugin start <pluginName>`\n - `town plugin stop <pluginName>`\n - `town plugin restart <pluginName>`\n - `town plugin command <pluginName> <command> [--payload '<json>']`\n - `town plugin schedule list`\n - `town plugin schedule info <jobId>`\n - `town plugin schedule cancel <jobId>`\n- ActionSchedule 管理命令用于查看/取消延迟执行的 plugin action,不是独立 plugin。\n- 当前内建托管 plugin:`shell` / `chat` / `task` / `memory` / `contact`。\n- 当前内建本地 plugin:`auth` / `skill` / `asr` / `tts`。\n- 模块级 action 命令:\n - `town shell <action> ...`\n - `town chat <action> ...`\n - `town task <action> ...`\n - `town memory <action> ...`\n - `town plugin action <plugin> <action> ...`\n - `town skill <action> ...`\n - `town asr <action> ...`\n - `town tts <action> ...`\n\n具体 plugin 的执行参考对应文档。\n";
|
|
8
8
|
|
|
9
9
|
export default TEXT_MODULE_CONTENT;
|
|
@@ -3,27 +3,27 @@
|
|
|
3
3
|
你正在一个基于 plugin 的执行环境中工作。
|
|
4
4
|
|
|
5
5
|
## 可用命令总览
|
|
6
|
-
- plugin 状态管理(统一使用 `
|
|
7
|
-
- `
|
|
8
|
-
- `
|
|
9
|
-
- `
|
|
10
|
-
- `
|
|
11
|
-
- `
|
|
12
|
-
- `
|
|
13
|
-
- `
|
|
14
|
-
- `
|
|
15
|
-
- `
|
|
6
|
+
- plugin 状态管理(统一使用 `town plugin`):
|
|
7
|
+
- `town plugin list`
|
|
8
|
+
- `town plugin status <pluginName>`
|
|
9
|
+
- `town plugin start <pluginName>`
|
|
10
|
+
- `town plugin stop <pluginName>`
|
|
11
|
+
- `town plugin restart <pluginName>`
|
|
12
|
+
- `town plugin command <pluginName> <command> [--payload '<json>']`
|
|
13
|
+
- `town plugin schedule list`
|
|
14
|
+
- `town plugin schedule info <jobId>`
|
|
15
|
+
- `town plugin schedule cancel <jobId>`
|
|
16
16
|
- ActionSchedule 管理命令用于查看/取消延迟执行的 plugin action,不是独立 plugin。
|
|
17
17
|
- 当前内建托管 plugin:`shell` / `chat` / `task` / `memory` / `contact`。
|
|
18
18
|
- 当前内建本地 plugin:`auth` / `skill` / `asr` / `tts`。
|
|
19
19
|
- 模块级 action 命令:
|
|
20
|
-
- `
|
|
21
|
-
- `
|
|
22
|
-
- `
|
|
23
|
-
- `
|
|
24
|
-
- `
|
|
25
|
-
- `
|
|
26
|
-
- `
|
|
27
|
-
- `
|
|
20
|
+
- `town shell <action> ...`
|
|
21
|
+
- `town chat <action> ...`
|
|
22
|
+
- `town task <action> ...`
|
|
23
|
+
- `town memory <action> ...`
|
|
24
|
+
- `town plugin action <plugin> <action> ...`
|
|
25
|
+
- `town skill <action> ...`
|
|
26
|
+
- `town asr <action> ...`
|
|
27
|
+
- `town tts <action> ...`
|
|
28
28
|
|
|
29
29
|
具体 plugin 的执行参考对应文档。
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Source: src/executor/composer/system/default/assets/task.prompt.ts.txt
|
|
7
|
-
const TEXT_MODULE_CONTENT = "你正在执行 Task 系统内部任务(非聊天会话)。\n\n运行约束(关键):\n- 当前上下文用于任务执行与审计,不是用户聊天回合。\n- 除非任务正文明确要求,否则不要调用 `
|
|
7
|
+
const TEXT_MODULE_CONTENT = "你正在执行 Task 系统内部任务(非聊天会话)。\n\n运行约束(关键):\n- 当前上下文用于任务执行与审计,不是用户聊天回合。\n- 除非任务正文明确要求,否则不要调用 `town chat send` 或任何外部渠道发送动作。\n- 不要把自己当作“即时对话客服”;优先完成任务目标并输出可审计结果。\n- 允许在执行过程中产生必要的中间说明,但你**最后一条 assistant 返回**会被系统直接当作 `output.md` 与最终发送内容。\n\n输出原则:\n- 你的最后一条 assistant 返回必须是“任务交付物本身”。\n- 最后一条 assistant 返回不要包含过程汇报、状态说明、任务管理说明或发送说明。\n- 优先返回可复用、结构化、简洁的结果内容。\n- 不要回显冗长原始日志;必要时给摘要与关键结论。\n- 如任务输入要求固定格式(例如 JSON),严格遵守该格式。\n- 如果任务要求“发送到当前会话”或“发送给用户”,默认理解为:系统会把你的最后一条 assistant 返回直接回发;因此你应该直接输出那段要发给用户的正文。\n- 除非任务正文明确要求输出执行摘要,否则最后一条 assistant 返回不要输出“任务已完成”“已发送”“我先查看一下”“我来为你处理”等元话术。\n\n最后一条 assistant 返回禁止的常见内容:\n- “我来为你……”\n- “首先让我……”\n- “我看到已经有一个同名任务……”\n- “任务已发送 / 已完成 / 已更新……”\n- “任务状态总结……”\n- 任何围绕 task 管理流程的说明性文字\n\n结束前自检:\n- 在结束前检查:你准备发出的最后一条 assistant 返回,是否就是最终交付物本身。\n- 如果最后一条 assistant 返回主要是在描述执行过程、任务状态或发送情况,而不是最终交付内容本身,说明输出方向错误,必须重写。\n- 如果删掉“我来”“首先”“已发送”“任务状态”这类句子后几乎没有剩余内容,说明这不是合格的 task 输出。\n\n上下文原则:\n- 该任务上下文是独立执行上下文,不继承聊天对话目标。\n- 如与系统其他提示冲突,以“任务执行上下文规则”为准。\n";
|
|
8
8
|
|
|
9
9
|
export default TEXT_MODULE_CONTENT;
|
|
@@ -194,29 +194,9 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
194
194
|
await fs.ensureFile(this.getMessagesFilePath());
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
private
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
for (const raw of input) {
|
|
201
|
-
const id = typeof raw === "string" ? raw.trim() : "";
|
|
202
|
-
if (!id) continue;
|
|
203
|
-
out.push(id);
|
|
204
|
-
}
|
|
205
|
-
return Array.from(new Set(out)).slice(0, 2000);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private normalizeSdkConfig(
|
|
209
|
-
input: SessionHistoryMetaV1["sdkConfig"],
|
|
210
|
-
): SessionHistoryMetaV1["sdkConfig"] {
|
|
211
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
212
|
-
return undefined;
|
|
213
|
-
}
|
|
214
|
-
const modelLabel =
|
|
215
|
-
typeof input.modelLabel === "string" ? input.modelLabel.trim() : "";
|
|
216
|
-
if (!modelLabel) return undefined;
|
|
217
|
-
return {
|
|
218
|
-
modelLabel,
|
|
219
|
-
};
|
|
197
|
+
private normalizeText(input: unknown): string | undefined {
|
|
198
|
+
const value = typeof input === "string" ? input.trim() : "";
|
|
199
|
+
return value || undefined;
|
|
220
200
|
}
|
|
221
201
|
|
|
222
202
|
private async readMetaUnsafe(): Promise<SessionHistoryMetaV1> {
|
|
@@ -235,24 +215,15 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
235
215
|
...(typeof raw.createdAt === "number" && Number.isFinite(raw.createdAt)
|
|
236
216
|
? { createdAt: raw.createdAt }
|
|
237
217
|
: {}),
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
...(typeof raw.lastArchiveId === "string" && raw.lastArchiveId.trim()
|
|
241
|
-
? { lastArchiveId: raw.lastArchiveId.trim() }
|
|
242
|
-
: {}),
|
|
243
|
-
...(typeof raw.keepLastMessages === "number" &&
|
|
244
|
-
Number.isFinite(raw.keepLastMessages)
|
|
245
|
-
? { keepLastMessages: raw.keepLastMessages }
|
|
246
|
-
: {}),
|
|
247
|
-
...(typeof raw.maxInputTokensApprox === "number" &&
|
|
248
|
-
Number.isFinite(raw.maxInputTokensApprox)
|
|
249
|
-
? { maxInputTokensApprox: raw.maxInputTokensApprox }
|
|
218
|
+
...(this.normalizeText(raw.timezone)
|
|
219
|
+
? { timezone: this.normalizeText(raw.timezone) }
|
|
250
220
|
: {}),
|
|
251
|
-
|
|
252
|
-
|
|
221
|
+
updatedAt: typeof raw.updatedAt === "number" ? raw.updatedAt : 0,
|
|
222
|
+
...(this.normalizeText(raw.title)
|
|
223
|
+
? { title: this.normalizeText(raw.title) }
|
|
253
224
|
: {}),
|
|
254
|
-
...(this.
|
|
255
|
-
? {
|
|
225
|
+
...(this.normalizeText(raw.modelLabel)
|
|
226
|
+
? { modelLabel: this.normalizeText(raw.modelLabel) }
|
|
256
227
|
: {}),
|
|
257
228
|
};
|
|
258
229
|
} catch {
|
|
@@ -261,7 +232,6 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
261
232
|
sessionId: this.sessionId,
|
|
262
233
|
createdAt: Date.now(),
|
|
263
234
|
updatedAt: 0,
|
|
264
|
-
pinnedSkillIds: [],
|
|
265
235
|
};
|
|
266
236
|
}
|
|
267
237
|
}
|
|
@@ -276,26 +246,16 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
276
246
|
...(typeof next.createdAt === "number" && Number.isFinite(next.createdAt)
|
|
277
247
|
? { createdAt: next.createdAt }
|
|
278
248
|
: {}),
|
|
249
|
+
...(this.normalizeText(next.timezone)
|
|
250
|
+
? { timezone: this.normalizeText(next.timezone) }
|
|
251
|
+
: {}),
|
|
279
252
|
updatedAt:
|
|
280
253
|
typeof next.updatedAt === "number" ? next.updatedAt : Date.now(),
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
? { lastArchiveId: next.lastArchiveId.trim() }
|
|
284
|
-
: {}),
|
|
285
|
-
...(typeof next.keepLastMessages === "number" &&
|
|
286
|
-
Number.isFinite(next.keepLastMessages)
|
|
287
|
-
? { keepLastMessages: next.keepLastMessages }
|
|
288
|
-
: {}),
|
|
289
|
-
...(typeof next.maxInputTokensApprox === "number" &&
|
|
290
|
-
Number.isFinite(next.maxInputTokensApprox)
|
|
291
|
-
? { maxInputTokensApprox: next.maxInputTokensApprox }
|
|
292
|
-
: {}),
|
|
293
|
-
...(typeof next.compactRatio === "number" &&
|
|
294
|
-
Number.isFinite(next.compactRatio)
|
|
295
|
-
? { compactRatio: next.compactRatio }
|
|
254
|
+
...(this.normalizeText(next.title)
|
|
255
|
+
? { title: this.normalizeText(next.title) }
|
|
296
256
|
: {}),
|
|
297
|
-
...(this.
|
|
298
|
-
? {
|
|
257
|
+
...(this.normalizeText(next.modelLabel)
|
|
258
|
+
? { modelLabel: this.normalizeText(next.modelLabel) }
|
|
299
259
|
: {}),
|
|
300
260
|
};
|
|
301
261
|
await fs.writeJson(this.getMetaFilePath(), normalized, { spaces: 2 });
|
|
@@ -75,7 +75,7 @@ function tryParseJsonObject(raw: string): JsonObject | null {
|
|
|
75
75
|
function shouldEnableCommandBridge(command: string): boolean {
|
|
76
76
|
const raw = String(command || "").trim();
|
|
77
77
|
if (!raw) return false;
|
|
78
|
-
return /(?:^|\s)(?:city|
|
|
78
|
+
return /(?:^|\s)(?:city|town)(?:\s|$)/i.test(raw);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
async function injectUserTextMessage(params: {
|
|
@@ -33,7 +33,7 @@ function applyEnvMap(
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* 对 `
|
|
36
|
+
* 对 `town chat send` 命令做前置安全校验。
|
|
37
37
|
*
|
|
38
38
|
* 关键点(中文)
|
|
39
39
|
* - 历史上模型会把长文本直接拼进多行 shell 命令,导致后续行被 zsh 当作独立命令解析。
|
|
@@ -42,20 +42,20 @@ function applyEnvMap(
|
|
|
42
42
|
*/
|
|
43
43
|
export function validateChatSendCommand(cmd: string): string | null {
|
|
44
44
|
const source = String(cmd ?? "");
|
|
45
|
-
if (!/\
|
|
45
|
+
if (!/\bbay\s+chat\s+send\b/.test(source)) return null;
|
|
46
46
|
if (!/[\r\n]/.test(source)) return null;
|
|
47
|
-
if (/\
|
|
47
|
+
if (/\bbay\s+chat\s+send\b[\s\S]*\s--stdin(?:\s|$)/.test(source)) {
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
|
-
if (/\
|
|
50
|
+
if (/\bbay\s+chat\s+send\b[\s\S]*\s--text(?:\s|$)/.test(source)) {
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
|
-
if (/\
|
|
53
|
+
if (/\bbay\s+chat\s+send\b[\s\S]*\s--text-file(?:\s|$)/.test(source)) {
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
56
56
|
return [
|
|
57
|
-
"Unsafe `
|
|
58
|
-
"If your message is multi-line, use `
|
|
57
|
+
"Unsafe `town chat send` command: real newlines are not allowed.",
|
|
58
|
+
"If your message is multi-line, use `town chat send --stdin` (with heredoc/pipe), `--text-file`, or explicit `--text`.",
|
|
59
59
|
].join(" ");
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -75,8 +75,8 @@ export function buildShellContextEnv(
|
|
|
75
75
|
|
|
76
76
|
applyEnvMap(env, injected);
|
|
77
77
|
setEnvString(env, "DC_SESSION_ID", contextCtx?.sessionId);
|
|
78
|
-
setEnvString(env, "
|
|
79
|
-
setEnvString(env, "
|
|
78
|
+
setEnvString(env, "DC_CITY_HOST", process.env.DC_CITY_HOST);
|
|
79
|
+
setEnvString(env, "DC_CITY_PORT", process.env.DC_CITY_PORT);
|
|
80
80
|
stripInvocationAuthEnv(env);
|
|
81
81
|
|
|
82
82
|
return env;
|
|
@@ -3,21 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 存储位置:`.downcity/agents/<encodedAgentId>/sessions/<encodedSessionId>/messages/meta.json`
|
|
6
|
-
* - 用于保存
|
|
6
|
+
* - 用于保存 session 列表、详情和索引所需的轻量元信息
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* SDK Session 配置摘要。
|
|
11
|
-
*
|
|
12
|
-
* 关键点(中文)
|
|
13
|
-
* - 这里只存可稳定序列化、仅用于回显/索引的轻量配置摘要。
|
|
14
|
-
* - 例如本地注入的 `LanguageModel` 实例本身不可序列化,因此仅记录其可读标签。
|
|
15
|
-
*/
|
|
16
|
-
export type SessionHistorySdkConfigV1 = {
|
|
17
|
-
/** 当前 session 绑定模型的可读标签。 */
|
|
18
|
-
modelLabel?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
9
|
export type SessionHistoryMetaV1 = {
|
|
22
10
|
/** schema 版本。 */
|
|
23
11
|
v: 1;
|
|
@@ -31,16 +19,8 @@ export type SessionHistoryMetaV1 = {
|
|
|
31
19
|
timezone?: string;
|
|
32
20
|
/** 最近一次更新元信息的时间戳(ms)。 */
|
|
33
21
|
updatedAt: number;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
/** 最近一次 compact 生效的保留消息数。 */
|
|
39
|
-
keepLastMessages?: number;
|
|
40
|
-
/** 最近一次 compact 生效的输入 token 近似上限。 */
|
|
41
|
-
maxInputTokensApprox?: number;
|
|
42
|
-
/** 最近一次 compact 生效的前段压缩比例。 */
|
|
43
|
-
compactRatio?: number;
|
|
44
|
-
/** SDK 侧的轻量配置摘要。 */
|
|
45
|
-
sdkConfig?: SessionHistorySdkConfigV1;
|
|
22
|
+
/** 当前 session 持久化标题。 */
|
|
23
|
+
title?: string;
|
|
24
|
+
/** 当前 session 绑定模型的可读标签。 */
|
|
25
|
+
modelLabel?: string;
|
|
46
26
|
};
|
|
@@ -65,7 +65,7 @@ export type SessionAssistantStepCallback = (
|
|
|
65
65
|
*
|
|
66
66
|
* 关键点(中文)
|
|
67
67
|
* - 这里直接复用 AI SDK 的 `UIMessageChunk` 结构,避免在 session 内核层再复制一套协议。
|
|
68
|
-
* - SDK / HTTP
|
|
68
|
+
* - SDK / HTTP 若需要自己的事件模型,应在更上层做映射。
|
|
69
69
|
*/
|
|
70
70
|
export type SessionUiMessageChunk = UIMessageChunk;
|
|
71
71
|
|
package/src/index.ts
CHANGED
|
@@ -10,16 +10,20 @@
|
|
|
10
10
|
// Agent 入口
|
|
11
11
|
export { Agent } from "./agent/Agent.js";
|
|
12
12
|
export { RemoteAgent } from "./agent/RemoteAgent.js";
|
|
13
|
+
export {
|
|
14
|
+
inferAgentModelLabel,
|
|
15
|
+
normalizeAgentModel,
|
|
16
|
+
} from "./model/CityModelAdapter.js";
|
|
13
17
|
export type {
|
|
14
18
|
AgentSessionCollection,
|
|
19
|
+
AgentModel,
|
|
15
20
|
AgentSessionActor,
|
|
16
21
|
AgentSession,
|
|
17
22
|
AgentCreateSessionInput,
|
|
18
23
|
AgentListSessionsInput,
|
|
19
24
|
AgentOptions,
|
|
20
|
-
AgentHttpBinding,
|
|
21
|
-
AgentHttpStartOptions,
|
|
22
25
|
AgentRpcBinding,
|
|
26
|
+
AgentRpcStartOptions,
|
|
23
27
|
AgentStartOptions,
|
|
24
28
|
AgentStartResult,
|
|
25
29
|
AgentStopResult,
|
|
@@ -103,10 +107,11 @@ export {
|
|
|
103
107
|
registerPluginActionCommandsForCli,
|
|
104
108
|
} from "./plugin/core/PluginCommand.js";
|
|
105
109
|
|
|
106
|
-
// Agent
|
|
110
|
+
// Agent RPC 集成
|
|
111
|
+
export { startRpcServer } from "./rpc/Server.js";
|
|
112
|
+
|
|
113
|
+
// 宿主 HTTP gateway 集成
|
|
107
114
|
export { startServer } from "./runtime/server/http/Server.js";
|
|
108
|
-
export { startLocalRpcServer } from "./runtime/server/rpc/Server.js";
|
|
109
|
-
export { callAgentTransport } from "./runtime/transport/rpc/Transport.js";
|
|
110
115
|
|
|
111
116
|
// Runtime plugin 运行集成
|
|
112
117
|
export {
|
|
@@ -127,7 +132,7 @@ export { persistProjectPluginConfig } from "./plugin/core/ProjectConfigStore.js"
|
|
|
127
132
|
export {
|
|
128
133
|
initializeAgentProject,
|
|
129
134
|
isAgentProjectInitialized,
|
|
130
|
-
|
|
135
|
+
normalizeDefaultAgentId,
|
|
131
136
|
} from "./config/AgentInitializer.js";
|
|
132
137
|
export { loadDowncityConfig } from "./config/Config.js";
|
|
133
138
|
export {
|
|
@@ -193,7 +198,7 @@ export type {
|
|
|
193
198
|
PlatformAgentShipStartConfig,
|
|
194
199
|
} from "./types/runtime/platform/PlatformGateway.js";
|
|
195
200
|
|
|
196
|
-
// Daemon
|
|
201
|
+
// Daemon 协议类型
|
|
197
202
|
export {
|
|
198
203
|
DAEMON_LOG_FILENAME,
|
|
199
204
|
DAEMON_META_FILENAME,
|
|
@@ -203,10 +208,6 @@ export type {
|
|
|
203
208
|
DaemonMeta,
|
|
204
209
|
DaemonStaleReason,
|
|
205
210
|
} from "./types/runtime/daemon/Daemon.js";
|
|
206
|
-
export type {
|
|
207
|
-
LocalRpcRequest,
|
|
208
|
-
LocalRpcResponse,
|
|
209
|
-
} from "./types/runtime/rpc/LocalRpc.js";
|
|
210
211
|
|
|
211
212
|
// Inline instant 协议类型
|
|
212
213
|
export type {
|
|
@@ -281,21 +282,13 @@ export type {
|
|
|
281
282
|
|
|
282
283
|
// Platform store 类型
|
|
283
284
|
export type {
|
|
284
|
-
StoredAgentEnvEntry,
|
|
285
285
|
StoredChannelAccount,
|
|
286
286
|
StoredChannelAccountChannel,
|
|
287
287
|
StoredEnvEntry,
|
|
288
|
-
StoredEnvScope,
|
|
289
288
|
StoredGlobalEnvEntry,
|
|
290
|
-
StoredModel,
|
|
291
|
-
StoredModelProvider,
|
|
292
|
-
StoredProviderMeta,
|
|
293
|
-
UpsertAgentEnvEntryInput,
|
|
294
289
|
UpsertChannelAccountInput,
|
|
295
290
|
UpsertEnvEntryInput,
|
|
296
291
|
UpsertGlobalEnvEntryInput,
|
|
297
|
-
UpsertModelInput,
|
|
298
|
-
UpsertModelProviderInput,
|
|
299
292
|
} from "./types/runtime/host/Store.js";
|
|
300
293
|
|
|
301
294
|
// HTTP auth 协议类型
|