@downcity/agent 1.1.43 → 1.1.51

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 (171) hide show
  1. package/README.md +6 -8
  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 +4 -4
  11. package/bin/config/AgentInitializer.d.ts.map +1 -1
  12. package/bin/config/AgentInitializer.js +14 -12
  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 +3 -111
  23. package/bin/config/DowncitySchema.js.map +1 -1
  24. package/bin/config/ExecutionBinding.d.ts +0 -15
  25. package/bin/config/ExecutionBinding.d.ts.map +1 -1
  26. package/bin/config/ExecutionBinding.js +1 -21
  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/system/default/assets/init/PROFILE.md.d.ts +1 -1
  37. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +1 -1
  38. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +1 -1
  39. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +1 -1
  40. package/bin/executor/tools/shell/ShellToolFormatting.js +2 -2
  41. package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
  42. package/bin/executor/types/SessionRun.d.ts +1 -1
  43. package/bin/index.d.ts +4 -6
  44. package/bin/index.d.ts.map +1 -1
  45. package/bin/index.js +5 -5
  46. package/bin/index.js.map +1 -1
  47. package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
  48. package/bin/plugin/core/PluginCommandRequest.js +1 -1
  49. package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
  50. package/bin/plugin/core/PluginLocalExecution.js +4 -8
  51. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  52. package/bin/plugin/types/PluginApi.d.ts +1 -1
  53. package/bin/rpc/Client.d.ts +104 -0
  54. package/bin/rpc/Client.d.ts.map +1 -0
  55. package/bin/rpc/Client.js +300 -0
  56. package/bin/rpc/Client.js.map +1 -0
  57. package/bin/rpc/Server.d.ts +41 -0
  58. package/bin/rpc/Server.d.ts.map +1 -0
  59. package/bin/rpc/Server.js +164 -0
  60. package/bin/rpc/Server.js.map +1 -0
  61. package/bin/runtime/host/daemon/Api.d.ts +1 -1
  62. package/bin/runtime/host/daemon/Client.d.ts +1 -1
  63. package/bin/runtime/host/daemon/Client.d.ts.map +1 -1
  64. package/bin/runtime/host/daemon/Client.js +30 -20
  65. package/bin/runtime/host/daemon/Client.js.map +1 -1
  66. package/bin/runtime/server/http/control/OverviewRoutes.js +1 -1
  67. package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -1
  68. package/bin/session/index.d.ts +1 -1
  69. package/bin/session/index.d.ts.map +1 -1
  70. package/bin/session/index.js +1 -1
  71. package/bin/session/index.js.map +1 -1
  72. package/bin/session/storage/Paths.d.ts +0 -4
  73. package/bin/session/storage/Paths.d.ts.map +1 -1
  74. package/bin/session/storage/Paths.js +0 -6
  75. package/bin/session/storage/Paths.js.map +1 -1
  76. package/bin/types/agent/AgentTypes.d.ts +23 -52
  77. package/bin/types/agent/AgentTypes.d.ts.map +1 -1
  78. package/bin/types/config/AgentProject.d.ts +6 -5
  79. package/bin/types/config/AgentProject.d.ts.map +1 -1
  80. package/bin/types/config/DowncityConfig.d.ts +8 -66
  81. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  82. package/bin/types/config/LlmConfig.d.ts +1 -1
  83. package/bin/types/config/Start.d.ts +3 -0
  84. package/bin/types/config/Start.d.ts.map +1 -1
  85. package/bin/types/config/Start.js +2 -0
  86. package/bin/types/config/Start.js.map +1 -1
  87. package/bin/types/runtime/host/Store.d.ts +7 -50
  88. package/bin/types/runtime/host/Store.d.ts.map +1 -1
  89. package/bin/types/runtime/platform/Platform.d.ts +6 -6
  90. package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
  91. package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
  92. package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
  93. package/bin/utils/Time.d.ts +0 -1
  94. package/bin/utils/Time.d.ts.map +1 -1
  95. package/bin/utils/Time.js +0 -7
  96. package/bin/utils/Time.js.map +1 -1
  97. package/bin/utils/storage/index.d.ts +0 -1
  98. package/bin/utils/storage/index.d.ts.map +1 -1
  99. package/bin/utils/storage/index.js +0 -6
  100. package/bin/utils/storage/index.js.map +1 -1
  101. package/package.json +4 -6
  102. package/src/agent/Agent.ts +54 -71
  103. package/src/agent/RemoteAgent.ts +515 -345
  104. package/src/config/AgentInitializer.ts +14 -12
  105. package/src/config/Config.ts +28 -85
  106. package/src/config/Defaults.ts +1 -9
  107. package/src/config/DowncitySchema.ts +3 -113
  108. package/src/config/ExecutionBinding.ts +1 -23
  109. package/src/config/Paths.ts +10 -43
  110. package/src/config/PlatformPaths.ts +5 -1
  111. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts +1 -1
  112. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +1 -2
  113. package/src/executor/tools/shell/ShellToolFormatting.ts +2 -2
  114. package/src/executor/types/SessionRun.ts +1 -1
  115. package/src/index.ts +7 -14
  116. package/src/plugin/core/PluginCommandRequest.ts +1 -1
  117. package/src/plugin/core/PluginLocalExecution.ts +4 -8
  118. package/src/plugin/types/PluginApi.ts +1 -1
  119. package/src/rpc/Client.ts +467 -0
  120. package/src/rpc/Server.ts +302 -0
  121. package/src/runtime/host/daemon/Api.ts +1 -1
  122. package/src/runtime/host/daemon/Client.ts +44 -22
  123. package/src/runtime/server/http/control/OverviewRoutes.ts +1 -1
  124. package/src/session/index.ts +0 -1
  125. package/src/session/storage/Paths.ts +0 -10
  126. package/src/types/agent/AgentTypes.ts +23 -57
  127. package/src/types/config/AgentProject.ts +6 -5
  128. package/src/types/config/DowncityConfig.ts +8 -67
  129. package/src/types/config/LlmConfig.ts +1 -1
  130. package/src/types/config/Start.ts +3 -0
  131. package/src/types/runtime/host/Store.ts +7 -53
  132. package/src/types/runtime/platform/Platform.ts +6 -6
  133. package/src/types/runtime/platform/PlatformGateway.ts +2 -2
  134. package/src/utils/Time.ts +0 -6
  135. package/src/utils/storage/index.ts +0 -7
  136. package/tsconfig.tsbuildinfo +1 -1
  137. package/bin/config/ConfigEnvResolver.d.ts +0 -22
  138. package/bin/config/ConfigEnvResolver.d.ts.map +0 -1
  139. package/bin/config/ConfigEnvResolver.js +0 -41
  140. package/bin/config/ConfigEnvResolver.js.map +0 -1
  141. package/bin/runtime/server/rpc/Server.d.ts +0 -18
  142. package/bin/runtime/server/rpc/Server.d.ts.map +0 -1
  143. package/bin/runtime/server/rpc/Server.js +0 -315
  144. package/bin/runtime/server/rpc/Server.js.map +0 -1
  145. package/bin/runtime/transport/rpc/Client.d.ts +0 -13
  146. package/bin/runtime/transport/rpc/Client.d.ts.map +0 -1
  147. package/bin/runtime/transport/rpc/Client.js +0 -98
  148. package/bin/runtime/transport/rpc/Client.js.map +0 -1
  149. package/bin/runtime/transport/rpc/Paths.d.ts +0 -14
  150. package/bin/runtime/transport/rpc/Paths.d.ts.map +0 -1
  151. package/bin/runtime/transport/rpc/Paths.js +0 -42
  152. package/bin/runtime/transport/rpc/Paths.js.map +0 -1
  153. package/bin/runtime/transport/rpc/Transport.d.ts +0 -21
  154. package/bin/runtime/transport/rpc/Transport.d.ts.map +0 -1
  155. package/bin/runtime/transport/rpc/Transport.js +0 -30
  156. package/bin/runtime/transport/rpc/Transport.js.map +0 -1
  157. package/bin/types/common/ResolvedConfigValue.d.ts +0 -12
  158. package/bin/types/common/ResolvedConfigValue.d.ts.map +0 -1
  159. package/bin/types/common/ResolvedConfigValue.js +0 -2
  160. package/bin/types/common/ResolvedConfigValue.js.map +0 -1
  161. package/bin/types/runtime/rpc/LocalRpc.d.ts +0 -69
  162. package/bin/types/runtime/rpc/LocalRpc.d.ts.map +0 -1
  163. package/bin/types/runtime/rpc/LocalRpc.js +0 -9
  164. package/bin/types/runtime/rpc/LocalRpc.js.map +0 -1
  165. package/src/config/ConfigEnvResolver.ts +0 -52
  166. package/src/runtime/server/rpc/Server.ts +0 -408
  167. package/src/runtime/transport/rpc/Client.ts +0 -113
  168. package/src/runtime/transport/rpc/Paths.ts +0 -50
  169. package/src/runtime/transport/rpc/Transport.ts +0 -43
  170. package/src/types/common/ResolvedConfigValue.ts +0 -16
  171. package/src/types/runtime/rpc/LocalRpc.ts +0 -72
@@ -149,9 +149,15 @@ export interface DowncityPluginConfigMap {
149
149
 
150
150
  export interface DowncityConfig {
151
151
  $schema?: string;
152
- name: string;
152
+ /**
153
+ * agent 唯一标识。
154
+ *
155
+ * 关键点(中文)
156
+ * - `@downcity/agent` 只关心稳定标识,不承担展示名语义。
157
+ * - 该字段同时用于 session/runtime/storage 目录归属。
158
+ */
159
+ id: string;
153
160
  version: string;
154
- description?: string;
155
161
  /**
156
162
  * Runtime startup configuration used by `downcity agent start`.
157
163
  * CLI flags (if provided) take precedence over this config.
@@ -195,69 +201,4 @@ export interface DowncityConfig {
195
201
  * - 对于项目内 `downcity.json`,通常不需要显式写 provider/model 明细。
196
202
  */
197
203
  llm?: LlmConfig;
198
- /**
199
- * 上下文管理(工程向配置)。
200
- *
201
- * 说明
202
- * - 对话消息以 UIMessage[] 为唯一事实源(`.downcity/agents/<agentId>/sessions/<sessionId>/messages/messages.jsonl`)。
203
- * - Agent 每次执行直接把 UIMessage[] 转成 ModelMessage[] 作为 messages 输入。
204
- * - 超出上下文窗口时会自动 compact(更早段压缩为摘要 + 保留最近窗口)。
205
- */
206
- context?: {
207
- /**
208
- * messages(唯一上下文消息来源)的 compact 策略。
209
- */
210
- messages?: {
211
- /**
212
- * 历史兼容字段(保留)。
213
- *
214
- * 说明(中文)
215
- * - 当前默认策略按 `compactRatio` 压缩前段消息。
216
- * - 该字段仍会写入 compact 元信息,便于观测与旧配置兼容。
217
- *
218
- * 默认:30
219
- */
220
- keepLastMessages?: number;
221
- /**
222
- * 输入预算(近似 token 数)。
223
- *
224
- * 说明(中文)
225
- * - 这里是近似值,用于在调用 provider 前提前触发 compact
226
- * - 实际超窗仍会被 provider 拒绝并进入 retry(更激进 compact)
227
- *
228
- * 默认:128000
229
- */
230
- maxInputTokensApprox?: number;
231
- /**
232
- * compact 时是否归档被折叠的原始消息段(写入 messages/archive/)。
233
- * 默认:true
234
- */
235
- archiveOnCompact?: boolean;
236
-
237
- /**
238
- * 前段压缩比例(0-1)。
239
- *
240
- * 说明(中文)
241
- * - 触发 compact 后,优先压缩最早一段消息。
242
- * - `0.5` 代表优先压缩“最早 50% 的 UIMessage”。
243
- * - 实际切分会做边界保护(至少保留 1 条最近消息)。
244
- *
245
- * 默认:0.5
246
- */
247
- compactRatio?: number;
248
- };
249
- /**
250
- * 记忆管理配置。
251
- *
252
- * 设计目标
253
- * - 默认开启,开箱即用(零配置)
254
- * - 仅保留总开关,避免复杂配置负担
255
- */
256
- memory?: {
257
- /**
258
- * 是否启用 memory plugin。
259
- */
260
- enabled?: boolean;
261
- };
262
- };
263
204
  }
@@ -47,7 +47,7 @@ export interface LlmProviderConfig {
47
47
  baseUrl?: string;
48
48
  /**
49
49
  * Provider API 密钥。
50
- * 建议使用 `${ENV_VAR}` 形式,启动时会自动解析环境变量。
50
+ * 建议由 Console 模型池直接保存,或由宿主在运行时显式注入 env 后再回退读取。
51
51
  */
52
52
  apiKey?: string;
53
53
  }
@@ -4,6 +4,8 @@
4
4
  * 字段说明(中文)
5
5
  * - `port`/`host`:主 API 服务监听地址。
6
6
  * - `agent start/restart` 中的 `port` 由 console 自动分配(CLI 不再暴露 `--port`)。
7
+ * - `rpcPort`:Agent 本机 RPC 监听端口。
8
+ * - 属于内部启动参数,通常由 city 自动分配,不面向普通用户。
7
9
  * - `daemon`:兼容旧参数(显式声明后台/前台)。
8
10
  * - `foreground`:显式前台启动。
9
11
  */
@@ -11,6 +13,7 @@
11
13
  export interface StartOptions {
12
14
  port?: number | string;
13
15
  host?: string;
16
+ rpcPort?: number | string;
14
17
  daemon?: boolean | string;
15
18
  foreground?: boolean | string;
16
19
  }
@@ -190,11 +190,6 @@ export interface UpsertModelInput {
190
190
  isPaused?: boolean;
191
191
  }
192
192
 
193
- /**
194
- * Env 条目作用域。
195
- */
196
- export type StoredEnvScope = "global" | "agent";
197
-
198
193
  /**
199
194
  * 平台环境变量记录。
200
195
  */
@@ -203,18 +198,10 @@ export interface StoredEnvEntry {
203
198
  * Env 作用域。
204
199
  *
205
200
  * 关键点(中文)
206
- * - `global` 表示平台控制面全局共享变量。
207
- * - `agent` 表示仅某个 agent 可见的私有变量。
208
- */
209
- scope: StoredEnvScope;
210
- /**
211
- * Agent 唯一标识(使用 projectRoot 绝对路径)。
212
- *
213
- * 关键点(中文)
214
- * - 仅当 `scope=agent` 时有值。
215
- * - `scope=global` 时为空。
201
+ * - 当前版本只保留 `global` 单一作用域。
202
+ * - 所有平台 Env 都视为宿主级共享变量,由宿主决定是否注入具体运行实例。
216
203
  */
217
- agentId?: string;
204
+ scope: "global";
218
205
  /**
219
206
  * 环境变量 key(例如 `OPENAI_API_KEY`)。
220
207
  */
@@ -247,16 +234,12 @@ export interface StoredEnvEntry {
247
234
  export interface UpsertEnvEntryInput {
248
235
  /**
249
236
  * Env 作用域。
250
- */
251
- scope: StoredEnvScope;
252
- /**
253
- * Agent 唯一标识(projectRoot)。
254
237
  *
255
238
  * 关键点(中文)
256
- * - `scope=agent` 时必填。
257
- * - `scope=global` 时忽略。
239
+ * - 当前只允许写入 `global`。
240
+ * - 保留该字段是为了让宿主侧调用点显式表达“这是平台全局 env 写入”。
258
241
  */
259
- agentId?: string;
242
+ scope: "global";
260
243
  /**
261
244
  * 环境变量 key。
262
245
  */
@@ -276,42 +259,13 @@ export interface UpsertEnvEntryInput {
276
259
 
277
260
  /**
278
261
  * 全局环境变量记录。
279
- *
280
- * 关键点(中文)
281
- * - 作为统一 `StoredEnvEntry` 的别名保留。
282
- * - 调用方可继续按全局 env 语义使用。
283
262
  */
284
263
  export type StoredGlobalEnvEntry = StoredEnvEntry;
285
264
 
286
- /**
287
- * Agent 私有环境变量记录。
288
- *
289
- * 关键点(中文)
290
- * - 作为统一 `StoredEnvEntry` 的别名保留。
291
- * - 调用方可继续按 agent env 语义使用。
292
- */
293
- export type StoredAgentEnvEntry = StoredEnvEntry;
294
-
295
265
  /**
296
266
  * 全局环境变量写入参数。
297
- *
298
- * 关键点(中文)
299
- * - 作为统一 `UpsertEnvEntryInput` 的别名保留。
300
- */
301
- export type UpsertGlobalEnvEntryInput = Omit<UpsertEnvEntryInput, "scope" | "agentId">;
302
-
303
- /**
304
- * Agent 私有环境变量写入参数。
305
- *
306
- * 关键点(中文)
307
- * - 作为统一 `UpsertEnvEntryInput` 的别名保留。
308
267
  */
309
- export type UpsertAgentEnvEntryInput = Omit<UpsertEnvEntryInput, "scope"> & {
310
- /**
311
- * Agent 唯一标识(projectRoot)。
312
- */
313
- agentId: string;
314
- };
268
+ export type UpsertGlobalEnvEntryInput = Omit<UpsertEnvEntryInput, "scope">;
315
269
 
316
270
  /**
317
271
  * Channel Account 记录。
@@ -17,9 +17,9 @@ export interface PlatformAgentOption {
17
17
  id: string;
18
18
 
19
19
  /**
20
- * agent 显示名称(优先 downcity.json.name,回退目录名)。
20
+ * agent 项目自身的稳定标识(优先 downcity.json.id,回退目录名推导)。
21
21
  */
22
- name: string;
22
+ agentId: string;
23
23
 
24
24
  /**
25
25
  * agent 项目根目录(绝对路径)。
@@ -173,9 +173,9 @@ export interface PlatformAgentDirectoryInspection {
173
173
  running: boolean;
174
174
 
175
175
  /**
176
- * 展示名称(优先 downcity.json.name,回退目录名)。
176
+ * 当前目录解析出的 agent id(若存在)。
177
177
  */
178
- displayName: string;
178
+ agentId?: string;
179
179
 
180
180
  /**
181
181
  * 当前读取到的主模型 ID(若存在)。
@@ -336,9 +336,9 @@ export interface PlatformConfigStatusResponse {
336
336
  selectedAgentId: string;
337
337
 
338
338
  /**
339
- * 当前选中的 agent 名称(可能为空)。
339
+ * 当前选中的 agent 项目 id(即 `downcity.json.id`,可能为空)。
340
340
  */
341
- selectedAgentName: string;
341
+ selectedAgentProjectId: string;
342
342
 
343
343
  /**
344
344
  * 配置文件状态列表。
@@ -135,9 +135,9 @@ export interface PlatformAgentShipStartConfig {
135
135
  */
136
136
  export interface PlatformAgentShipJson {
137
137
  /**
138
- * agent 展示名称。
138
+ * agent 稳定标识。
139
139
  */
140
- name?: unknown;
140
+ id?: unknown;
141
141
 
142
142
  /**
143
143
  * 执行配置。
package/src/utils/Time.ts CHANGED
@@ -10,12 +10,6 @@ export function getTimestamp(): string {
10
10
  return new Date().toISOString();
11
11
  }
12
12
 
13
- export function formatDuration(ms: number): string {
14
- if (ms < 1000) return `${ms}ms`;
15
- if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
16
- return `${(ms / 60000).toFixed(1)}m`;
17
- }
18
-
19
13
  export function resolveRuntimeTimezone(): string {
20
14
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
21
15
  return String(timezone || "").trim() || "UTC";
@@ -17,10 +17,3 @@ export async function ensureDir(dir: string): Promise<void> {
17
17
  export async function saveJson(filePath: string, data: JsonValue | object): Promise<void> {
18
18
  await fs.writeJson(filePath, data, { spaces: 2 });
19
19
  }
20
-
21
- export async function loadJson<T>(filePath: string): Promise<T | null> {
22
- if (!fs.existsSync(filePath)) {
23
- return null;
24
- }
25
- return fs.readJson(filePath) as Promise<T>;
26
- }