@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.
Files changed (256) hide show
  1. package/README.md +11 -12
  2. package/bin/agent/Agent.d.ts +31 -16
  3. package/bin/agent/Agent.d.ts.map +1 -1
  4. package/bin/agent/Agent.js +47 -63
  5. package/bin/agent/Agent.js.map +1 -1
  6. package/bin/agent/RemoteAgent.d.ts +6 -6
  7. package/bin/agent/RemoteAgent.d.ts.map +1 -1
  8. package/bin/agent/RemoteAgent.js +377 -267
  9. package/bin/agent/RemoteAgent.js.map +1 -1
  10. package/bin/config/AgentInitializer.d.ts +5 -5
  11. package/bin/config/AgentInitializer.d.ts.map +1 -1
  12. package/bin/config/AgentInitializer.js +15 -13
  13. package/bin/config/AgentInitializer.js.map +1 -1
  14. package/bin/config/Config.d.ts +9 -30
  15. package/bin/config/Config.d.ts.map +1 -1
  16. package/bin/config/Config.js +23 -70
  17. package/bin/config/Config.js.map +1 -1
  18. package/bin/config/Defaults.d.ts.map +1 -1
  19. package/bin/config/Defaults.js +1 -9
  20. package/bin/config/Defaults.js.map +1 -1
  21. package/bin/config/DowncitySchema.d.ts.map +1 -1
  22. package/bin/config/DowncitySchema.js +4 -112
  23. package/bin/config/DowncitySchema.js.map +1 -1
  24. package/bin/config/ExecutionBinding.d.ts +1 -16
  25. package/bin/config/ExecutionBinding.d.ts.map +1 -1
  26. package/bin/config/ExecutionBinding.js +2 -22
  27. package/bin/config/ExecutionBinding.js.map +1 -1
  28. package/bin/config/Paths.d.ts +4 -43
  29. package/bin/config/Paths.d.ts.map +1 -1
  30. package/bin/config/Paths.js +10 -30
  31. package/bin/config/Paths.js.map +1 -1
  32. package/bin/config/PlatformPaths.d.ts +0 -4
  33. package/bin/config/PlatformPaths.d.ts.map +1 -1
  34. package/bin/config/PlatformPaths.js +5 -1
  35. package/bin/config/PlatformPaths.js.map +1 -1
  36. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
  37. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +0 -4
  38. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
  39. package/bin/executor/composer/system/default/InitPrompts.d.ts +1 -1
  40. package/bin/executor/composer/system/default/InitPrompts.js +1 -1
  41. package/bin/executor/composer/system/default/SystemDomain.js +1 -1
  42. package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
  43. package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
  44. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts +1 -1
  45. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +1 -1
  46. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +1 -1
  47. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +1 -1
  48. package/bin/executor/composer/system/default/assets/plugin.prompt.d.ts +1 -1
  49. package/bin/executor/composer/system/default/assets/plugin.prompt.js +1 -1
  50. package/bin/executor/composer/system/default/assets/task.prompt.d.ts +1 -1
  51. package/bin/executor/composer/system/default/assets/task.prompt.js +1 -1
  52. package/bin/executor/messages/ChatMessageMarkupTypes.d.ts +1 -1
  53. package/bin/executor/messages/ChatMessageMarkupTypes.js +1 -1
  54. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +1 -2
  55. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
  56. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +17 -56
  57. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
  58. package/bin/executor/tools/shell/ShellToolBridge.js +1 -1
  59. package/bin/executor/tools/shell/ShellToolBridge.js.map +1 -1
  60. package/bin/executor/tools/shell/ShellToolDefinition.d.ts +2 -2
  61. package/bin/executor/tools/shell/ShellToolFormatting.d.ts +1 -1
  62. package/bin/executor/tools/shell/ShellToolFormatting.js +9 -9
  63. package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
  64. package/bin/executor/tools/shell/ShellToolSchemas.d.ts +7 -75
  65. package/bin/executor/tools/shell/ShellToolSchemas.d.ts.map +1 -1
  66. package/bin/executor/types/SessionHistoryMeta.d.ts +5 -24
  67. package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
  68. package/bin/executor/types/SessionHistoryMeta.js +1 -1
  69. package/bin/executor/types/SessionRun.d.ts +1 -1
  70. package/bin/index.d.ts +5 -6
  71. package/bin/index.d.ts.map +1 -1
  72. package/bin/index.js +6 -5
  73. package/bin/index.js.map +1 -1
  74. package/bin/model/CityModelAdapter.d.ts +23 -0
  75. package/bin/model/CityModelAdapter.d.ts.map +1 -0
  76. package/bin/model/CityModelAdapter.js +338 -0
  77. package/bin/model/CityModelAdapter.js.map +1 -0
  78. package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
  79. package/bin/plugin/core/PluginCommandRequest.js +1 -1
  80. package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
  81. package/bin/plugin/core/PluginLocalExecution.js +4 -8
  82. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  83. package/bin/plugin/types/PluginApi.d.ts +1 -1
  84. package/bin/rpc/Client.d.ts +104 -0
  85. package/bin/rpc/Client.d.ts.map +1 -0
  86. package/bin/rpc/Client.js +300 -0
  87. package/bin/rpc/Client.js.map +1 -0
  88. package/bin/rpc/Server.d.ts +41 -0
  89. package/bin/rpc/Server.d.ts.map +1 -0
  90. package/bin/rpc/Server.js +164 -0
  91. package/bin/rpc/Server.js.map +1 -0
  92. package/bin/runtime/host/daemon/Api.d.ts +1 -1
  93. package/bin/runtime/host/daemon/Client.d.ts +1 -1
  94. package/bin/runtime/host/daemon/Client.d.ts.map +1 -1
  95. package/bin/runtime/host/daemon/Client.js +30 -20
  96. package/bin/runtime/host/daemon/Client.js.map +1 -1
  97. package/bin/runtime/host/daemon/Paths.d.ts +1 -1
  98. package/bin/runtime/host/daemon/Paths.js +1 -1
  99. package/bin/runtime/host/daemon/ProjectSetup.js +2 -2
  100. package/bin/runtime/server/http/control/OverviewRoutes.js +1 -1
  101. package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -1
  102. package/bin/session/Session.d.ts +1 -0
  103. package/bin/session/Session.d.ts.map +1 -1
  104. package/bin/session/Session.js +32 -6
  105. package/bin/session/Session.js.map +1 -1
  106. package/bin/session/SessionTitle.d.ts +49 -0
  107. package/bin/session/SessionTitle.d.ts.map +1 -0
  108. package/bin/session/SessionTitle.js +130 -0
  109. package/bin/session/SessionTitle.js.map +1 -0
  110. package/bin/session/browse/Browse.d.ts +2 -1
  111. package/bin/session/browse/Browse.d.ts.map +1 -1
  112. package/bin/session/browse/Browse.js +18 -15
  113. package/bin/session/browse/Browse.js.map +1 -1
  114. package/bin/session/index.d.ts +3 -2
  115. package/bin/session/index.d.ts.map +1 -1
  116. package/bin/session/index.js +3 -2
  117. package/bin/session/index.js.map +1 -1
  118. package/bin/session/storage/Metadata.d.ts +4 -0
  119. package/bin/session/storage/Metadata.d.ts.map +1 -1
  120. package/bin/session/storage/Metadata.js +12 -25
  121. package/bin/session/storage/Metadata.js.map +1 -1
  122. package/bin/session/storage/Paths.d.ts +0 -4
  123. package/bin/session/storage/Paths.d.ts.map +1 -1
  124. package/bin/session/storage/Paths.js +0 -6
  125. package/bin/session/storage/Paths.js.map +1 -1
  126. package/bin/session/storage/Persistence.d.ts.map +1 -1
  127. package/bin/session/storage/Persistence.js +1 -4
  128. package/bin/session/storage/Persistence.js.map +1 -1
  129. package/bin/types/agent/AgentTypes.d.ts +32 -57
  130. package/bin/types/agent/AgentTypes.d.ts.map +1 -1
  131. package/bin/types/config/AgentProject.d.ts +7 -6
  132. package/bin/types/config/AgentProject.d.ts.map +1 -1
  133. package/bin/types/config/DowncityConfig.d.ts +11 -69
  134. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  135. package/bin/types/config/ExecutionBinding.d.ts +4 -4
  136. package/bin/types/config/ExecutionBinding.js +1 -1
  137. package/bin/types/config/LlmConfig.d.ts +1 -1
  138. package/bin/types/config/Start.d.ts +3 -0
  139. package/bin/types/config/Start.d.ts.map +1 -1
  140. package/bin/types/config/Start.js +2 -0
  141. package/bin/types/config/Start.js.map +1 -1
  142. package/bin/types/runtime/auth/AuthPermission.js +2 -2
  143. package/bin/types/runtime/auth/AuthPermission.js.map +1 -1
  144. package/bin/types/runtime/host/Store.d.ts +10 -227
  145. package/bin/types/runtime/host/Store.d.ts.map +1 -1
  146. package/bin/types/runtime/host/Store.js +7 -0
  147. package/bin/types/runtime/host/Store.js.map +1 -1
  148. package/bin/types/runtime/http/InlineInstant.d.ts +1 -1
  149. package/bin/types/runtime/platform/Platform.d.ts +7 -7
  150. package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
  151. package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
  152. package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
  153. package/bin/utils/Time.d.ts +0 -1
  154. package/bin/utils/Time.d.ts.map +1 -1
  155. package/bin/utils/Time.js +0 -7
  156. package/bin/utils/Time.js.map +1 -1
  157. package/bin/utils/storage/index.d.ts +0 -1
  158. package/bin/utils/storage/index.d.ts.map +1 -1
  159. package/bin/utils/storage/index.js +0 -6
  160. package/bin/utils/storage/index.js.map +1 -1
  161. package/package.json +22 -23
  162. package/src/agent/Agent.ts +57 -73
  163. package/src/agent/RemoteAgent.ts +515 -345
  164. package/src/config/AgentInitializer.ts +15 -13
  165. package/src/config/Config.ts +28 -85
  166. package/src/config/Defaults.ts +1 -9
  167. package/src/config/DowncitySchema.ts +4 -114
  168. package/src/config/ExecutionBinding.ts +2 -24
  169. package/src/config/Paths.ts +10 -43
  170. package/src/config/PlatformPaths.ts +5 -1
  171. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +0 -4
  172. package/src/executor/composer/system/default/InitPrompts.ts +1 -1
  173. package/src/executor/composer/system/default/SystemDomain.ts +1 -1
  174. package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
  175. package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -1
  176. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts +1 -1
  177. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +1 -2
  178. package/src/executor/composer/system/default/assets/plugin.prompt.ts +1 -1
  179. package/src/executor/composer/system/default/assets/plugin.prompt.ts.txt +18 -18
  180. package/src/executor/composer/system/default/assets/task.prompt.ts +1 -1
  181. package/src/executor/composer/system/default/assets/task.prompt.ts.txt +1 -1
  182. package/src/executor/messages/ChatMessageMarkupTypes.ts +1 -1
  183. package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +17 -57
  184. package/src/executor/tools/shell/ShellToolBridge.ts +1 -1
  185. package/src/executor/tools/shell/ShellToolFormatting.ts +9 -9
  186. package/src/executor/types/SessionHistoryMeta.ts +5 -25
  187. package/src/executor/types/SessionRun.ts +1 -1
  188. package/src/index.ts +12 -19
  189. package/src/model/CityModelAdapter.ts +384 -0
  190. package/src/plugin/core/PluginCommandRequest.ts +1 -1
  191. package/src/plugin/core/PluginLocalExecution.ts +4 -8
  192. package/src/plugin/types/PluginApi.ts +1 -1
  193. package/src/rpc/Client.ts +467 -0
  194. package/src/rpc/Server.ts +302 -0
  195. package/src/runtime/host/daemon/Api.ts +1 -1
  196. package/src/runtime/host/daemon/Client.ts +44 -22
  197. package/src/runtime/host/daemon/Paths.ts +1 -1
  198. package/src/runtime/host/daemon/ProjectSetup.ts +2 -2
  199. package/src/runtime/server/http/control/OverviewRoutes.ts +1 -1
  200. package/src/session/Session.ts +40 -6
  201. package/src/session/SessionTitle.ts +192 -0
  202. package/src/session/browse/Browse.ts +22 -13
  203. package/src/session/index.ts +5 -1
  204. package/src/session/storage/Metadata.ts +14 -29
  205. package/src/session/storage/Paths.ts +0 -10
  206. package/src/session/storage/Persistence.ts +1 -4
  207. package/src/types/agent/AgentTypes.ts +33 -62
  208. package/src/types/config/AgentProject.ts +7 -6
  209. package/src/types/config/DowncityConfig.ts +11 -70
  210. package/src/types/config/ExecutionBinding.ts +4 -4
  211. package/src/types/config/LlmConfig.ts +1 -1
  212. package/src/types/config/Start.ts +3 -0
  213. package/src/types/runtime/auth/AuthPermission.ts +2 -2
  214. package/src/types/runtime/host/Store.ts +10 -235
  215. package/src/types/runtime/http/InlineInstant.ts +1 -1
  216. package/src/types/runtime/platform/Platform.ts +7 -7
  217. package/src/types/runtime/platform/PlatformGateway.ts +2 -2
  218. package/src/utils/Time.ts +0 -6
  219. package/src/utils/storage/index.ts +0 -7
  220. package/tsconfig.json +1 -0
  221. package/tsconfig.tsbuildinfo +1 -1
  222. package/bin/config/ConfigEnvResolver.d.ts +0 -22
  223. package/bin/config/ConfigEnvResolver.d.ts.map +0 -1
  224. package/bin/config/ConfigEnvResolver.js +0 -41
  225. package/bin/config/ConfigEnvResolver.js.map +0 -1
  226. package/bin/runtime/server/rpc/Server.d.ts +0 -18
  227. package/bin/runtime/server/rpc/Server.d.ts.map +0 -1
  228. package/bin/runtime/server/rpc/Server.js +0 -315
  229. package/bin/runtime/server/rpc/Server.js.map +0 -1
  230. package/bin/runtime/transport/rpc/Client.d.ts +0 -13
  231. package/bin/runtime/transport/rpc/Client.d.ts.map +0 -1
  232. package/bin/runtime/transport/rpc/Client.js +0 -98
  233. package/bin/runtime/transport/rpc/Client.js.map +0 -1
  234. package/bin/runtime/transport/rpc/Paths.d.ts +0 -14
  235. package/bin/runtime/transport/rpc/Paths.d.ts.map +0 -1
  236. package/bin/runtime/transport/rpc/Paths.js +0 -42
  237. package/bin/runtime/transport/rpc/Paths.js.map +0 -1
  238. package/bin/runtime/transport/rpc/Transport.d.ts +0 -21
  239. package/bin/runtime/transport/rpc/Transport.d.ts.map +0 -1
  240. package/bin/runtime/transport/rpc/Transport.js +0 -30
  241. package/bin/runtime/transport/rpc/Transport.js.map +0 -1
  242. package/bin/types/common/ResolvedConfigValue.d.ts +0 -12
  243. package/bin/types/common/ResolvedConfigValue.d.ts.map +0 -1
  244. package/bin/types/common/ResolvedConfigValue.js +0 -2
  245. package/bin/types/common/ResolvedConfigValue.js.map +0 -1
  246. package/bin/types/runtime/rpc/LocalRpc.d.ts +0 -69
  247. package/bin/types/runtime/rpc/LocalRpc.d.ts.map +0 -1
  248. package/bin/types/runtime/rpc/LocalRpc.js +0 -9
  249. package/bin/types/runtime/rpc/LocalRpc.js.map +0 -1
  250. package/src/config/ConfigEnvResolver.ts +0 -52
  251. package/src/runtime/server/rpc/Server.ts +0 -408
  252. package/src/runtime/transport/rpc/Client.ts +0 -113
  253. package/src/runtime/transport/rpc/Paths.ts +0 -50
  254. package/src/runtime/transport/rpc/Transport.ts +0 -43
  255. package/src/types/common/ResolvedConfigValue.ts +0 -16
  256. package/src/types/runtime/rpc/LocalRpc.ts +0 -72
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 职责说明(中文)
5
5
  * - 对外暴露 `Agent` 这一唯一的本地实例类。
6
- * - 统一承接单个 agent 实例的配置加载、plugin 装配、session 创建、HTTP/RPC 启停。
6
+ * - 统一承接单个 agent 实例的配置加载、plugin 装配、session 创建、RPC 启停。
7
7
  * - 把原先独立的实例内核装配逻辑收敛到 `Agent` 内部,避免 facade 与 core 双层跳转。
8
8
  *
9
9
  * 边界说明(中文)
@@ -13,7 +13,7 @@
13
13
 
14
14
  import fs from "fs-extra";
15
15
  import { nanoid } from "nanoid";
16
- import type { LanguageModel, Tool } from "ai";
16
+ import type { Tool } from "ai";
17
17
  import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
18
18
  import type {
19
19
  AgentContext,
@@ -35,13 +35,13 @@ import type {
35
35
  AgentStartOptions,
36
36
  AgentStartResult,
37
37
  AgentStopResult,
38
- AgentHttpBinding,
39
- AgentHttpStartOptions,
40
38
  AgentRpcBinding,
39
+ AgentRpcStartOptions,
41
40
  AgentSessionCollection,
42
41
  AgentSessionSummaryPage,
43
42
  AgentSessionSystemBlock,
44
43
  } from "@/types/agent/AgentTypes.js";
44
+ import type { AgentModel } from "@/model/CityModelAdapter.js";
45
45
  import { Logger } from "@/utils/logger/Logger.js";
46
46
  import { Session } from "@/session/Session.js";
47
47
  import { DEFAULT_SHIP_PROMPTS } from "@executor/composer/system/default/SystemDomain.js";
@@ -53,7 +53,7 @@ import {
53
53
  createAgentPathRuntime,
54
54
  createAgentPluginConfigRuntime,
55
55
  } from "@/runtime/host/AgentHostRuntime.js";
56
- import { loadDowncityConfig } from "@/config/Config.js";
56
+ import { loadDowncityConfig, resolveAgentEnv } from "@/config/Config.js";
57
57
  import { HookRegistry } from "@/plugin/core/HookRegistry.js";
58
58
  import { PluginRegistry } from "@/plugin/core/PluginRegistry.js";
59
59
  import { isPluginEnabled } from "@/plugin/core/Activation.js";
@@ -61,12 +61,11 @@ import { setShellToolRuntime } from "@executor/tools/shell/ShellToolDefinition.j
61
61
  import { startAllPlugins, stopAllPlugins } from "@/plugin/core/Manager.js";
62
62
  import type { ActionScheduleRuntimeHandle } from "@/plugin/core/ActionScheduleRuntime.js";
63
63
  import { startActionScheduleRuntime } from "@/plugin/core/ActionScheduleRuntime.js";
64
- import { startServer } from "@/runtime/server/http/Server.js";
65
- import { startLocalRpcServer } from "@/runtime/server/rpc/Server.js";
64
+ import { startRpcServer } from "@/rpc/Server.js";
66
65
 
67
66
  function createFallbackSdkConfig(agentId: string): DowncityConfig {
68
67
  return {
69
- name: agentId,
68
+ id: agentId,
70
69
  version: "0.0.0",
71
70
  } as DowncityConfig;
72
71
  }
@@ -126,7 +125,7 @@ export class Agent {
126
125
  private readonly pluginRegistry: PluginRegistry;
127
126
  private readonly config: DowncityConfig;
128
127
  private readonly env: Record<string, string>;
129
- private readonly defaultModel?: LanguageModel;
128
+ private readonly defaultModel?: AgentModel;
130
129
  private readonly pluginInstances: Map<string, BasePlugin>;
131
130
  private readonly sessionCollection: AgentSessionCollection;
132
131
 
@@ -135,7 +134,6 @@ export class Agent {
135
134
  private pluginsStarted = false;
136
135
  private actionScheduleRuntime: ActionScheduleRuntimeHandle | null = null;
137
136
  private startPromise: Promise<AgentStartResult> | null = null;
138
- private httpBinding: AgentHttpBinding | null = null;
139
137
  private rpcBinding: AgentRpcBinding | null = null;
140
138
 
141
139
  constructor(options: AgentOptions) {
@@ -153,7 +151,7 @@ export class Agent {
153
151
 
154
152
  this.logger = new Logger();
155
153
  this.logger.bindProjectRoot(this.path);
156
- this.env = options.env ? { ...options.env } : {};
154
+ this.env = resolveAgentEnv(this.path, options.env);
157
155
  this.instruction = normalizeInstructionInput(options.instruction);
158
156
  this.defaultModel = options.model;
159
157
  this.config = this.loadConfig();
@@ -246,7 +244,7 @@ export class Agent {
246
244
  *
247
245
  * 关键点(中文)
248
246
  * - `start()` 是唯一公开的长期运行生命周期入口。
249
- * - 多次并发调用会复用同一个启动 Promise,避免重复启动 plugins / server
247
+ * - 多次并发调用会复用同一个启动 Promise,避免重复启动 plugins / rpc
250
248
  */
251
249
  async start(options?: AgentStartOptions): Promise<AgentStartResult> {
252
250
  if (this.startPromise) {
@@ -259,17 +257,12 @@ export class Agent {
259
257
  await this.ensurePluginsStarted();
260
258
  }
261
259
 
262
- const httpBinding =
263
- options?.http === false || options?.http === undefined
264
- ? undefined
265
- : await this.startHttp(options.http);
266
260
  const rpcBinding =
267
- options?.rpc === true
268
- ? await this.startRpc()
269
- : undefined;
261
+ options?.rpc === false || options?.rpc === undefined
262
+ ? undefined
263
+ : await this.startRpc(options.rpc);
270
264
 
271
265
  return {
272
- ...(httpBinding ? { http: httpBinding } : {}),
273
266
  ...(rpcBinding ? { rpc: rpcBinding } : {}),
274
267
  pluginsStarted: this.pluginsStarted,
275
268
  };
@@ -286,13 +279,12 @@ export class Agent {
286
279
  * 停止当前 agent 实例的长期运行能力。
287
280
  *
288
281
  * 关键点(中文)
289
- * - 停止顺序保持为 plugins -> rpc -> http,与当前运行语义一致。
282
+ * - 停止顺序保持为 plugins -> rpc,与当前运行语义一致。
290
283
  * - 停止后会清空 `startPromise`,允许后续再次 `start()`。
291
284
  */
292
285
  async stop(): Promise<AgentStopResult> {
293
286
  const pluginsStarted = this.pluginsStarted;
294
287
  const rpcStarted = this.rpcBinding !== null;
295
- const httpStarted = this.httpBinding !== null;
296
288
 
297
289
  if (pluginsStarted) {
298
290
  await this.stopActionScheduleRuntime();
@@ -304,14 +296,9 @@ export class Agent {
304
296
  await this.stopRpc();
305
297
  }
306
298
 
307
- if (httpStarted) {
308
- await this.stopHttp();
309
- }
310
-
311
299
  this.startPromise = null;
312
300
 
313
301
  return {
314
- httpStopped: httpStarted,
315
302
  rpcStopped: rpcStarted,
316
303
  pluginsStopped: pluginsStarted,
317
304
  };
@@ -342,11 +329,42 @@ export class Agent {
342
329
  return this.logger;
343
330
  }
344
331
 
332
+ /**
333
+ * 返回当前 agent runtime。
334
+ *
335
+ * 关键点(中文)
336
+ * - 供宿主在 agent 外部装配 transport(例如 city HTTP gateway)时复用。
337
+ * - 不暴露启动语义,只暴露运行时访问口。
338
+ */
339
+ getRuntime(): AgentRuntime {
340
+ return this.runtime;
341
+ }
342
+
343
+ /**
344
+ * 返回当前 agent context。
345
+ *
346
+ * 关键点(中文)
347
+ * - 供宿主装配 plugin/control 相关外层协议面。
348
+ */
349
+ getContext(): AgentContext {
350
+ return this.agentContext;
351
+ }
352
+
353
+ /**
354
+ * 返回当前 session collection。
355
+ *
356
+ * 关键点(中文)
357
+ * - 供宿主在外层挂载 RemoteAgent transport 时复用。
358
+ */
359
+ getSessionCollection(): AgentSessionCollection {
360
+ return this.sessionCollection;
361
+ }
362
+
345
363
  /**
346
364
  * 确保当前 plugins 已启动。
347
365
  *
348
366
  * 关键点(中文)
349
- * - 这里只负责托管 plugin 的生命周期启动,不隐式启动 HTTP/RPC 能力。
367
+ * - 这里只负责托管 plugin 的生命周期启动,不隐式启动 RPC 能力。
350
368
  * - 启动失败的 plugin 会记录日志,但保留与原行为一致的整体启动流程。
351
369
  */
352
370
  private async ensurePluginsStarted(): Promise<void> {
@@ -396,65 +414,35 @@ export class Agent {
396
414
  }
397
415
 
398
416
  /**
399
- * 启动当前 agent HTTP server。
417
+ * 启动当前 agent 的本机 RPC server。
400
418
  */
401
- private async startHttp(
402
- options?: AgentHttpStartOptions,
403
- ): Promise<AgentHttpBinding> {
404
- if (this.httpBinding) {
405
- return this.httpBinding;
419
+ private async startRpc(
420
+ options?: AgentRpcStartOptions,
421
+ ): Promise<AgentRpcBinding> {
422
+ if (this.rpcBinding) {
423
+ return this.rpcBinding;
406
424
  }
407
425
  const host = String(options?.host || "127.0.0.1").trim() || "127.0.0.1";
408
426
  const port =
409
427
  typeof options?.port === "number" && Number.isInteger(options.port)
410
428
  ? options.port
411
429
  : 15314;
412
- const server = await startServer({
430
+ const server = await startRpcServer({
413
431
  host,
414
432
  port,
415
- getAgentRuntime: () => this.runtime,
416
- getAgentContext: () => this.agentContext,
417
433
  sessionCollection: this.sessionCollection,
418
434
  });
419
- this.httpBinding = {
420
- baseUrl: `http://${host}:${port}`,
435
+ this.rpcBinding = {
436
+ url: `rpc://${host}:${port}`,
421
437
  host,
422
438
  port,
423
439
  server,
424
440
  };
425
- return this.httpBinding;
426
- }
427
-
428
- /**
429
- * 停止当前 agent 的 HTTP server。
430
- */
431
- private async stopHttp(): Promise<void> {
432
- if (!this.httpBinding) return;
433
- const current = this.httpBinding;
434
- this.httpBinding = null;
435
- await current.server.stop();
436
- }
437
-
438
- /**
439
- * 启动当前 agent 的本地 RPC server。
440
- */
441
- private async startRpc(): Promise<AgentRpcBinding> {
442
- if (this.rpcBinding) {
443
- return this.rpcBinding;
444
- }
445
- const server = await startLocalRpcServer({
446
- context: this.agentContext,
447
- runtime: this.runtime,
448
- });
449
- this.rpcBinding = {
450
- endpoint: server.endpoint,
451
- server,
452
- };
453
441
  return this.rpcBinding;
454
442
  }
455
443
 
456
444
  /**
457
- * 停止当前 agent 的本地 RPC server。
445
+ * 停止当前 agent 的本机 RPC server。
458
446
  */
459
447
  private async stopRpc(): Promise<void> {
460
448
  if (!this.rpcBinding) return;
@@ -472,11 +460,7 @@ export class Agent {
472
460
  */
473
461
  private loadConfig(): DowncityConfig {
474
462
  try {
475
- return loadDowncityConfig(this.path, {
476
- projectEnv: this.env,
477
- agentEnv: this.env,
478
- globalEnv: {},
479
- });
463
+ return loadDowncityConfig(this.path);
480
464
  } catch {
481
465
  return createFallbackSdkConfig(this.id);
482
466
  }