@downcity/agent 1.1.212 → 1.1.216

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 (102) hide show
  1. package/README.md +3 -3
  2. package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +1 -1
  3. package/bin/agent/local/AgentRuntimeAssembly.js +2 -2
  4. package/bin/agent/local/AgentRuntimeAssembly.js.map +1 -1
  5. package/bin/agent/local/ProjectSetup.d.ts +0 -1
  6. package/bin/agent/local/ProjectSetup.d.ts.map +1 -1
  7. package/bin/agent/local/ProjectSetup.js +4 -17
  8. package/bin/agent/local/ProjectSetup.js.map +1 -1
  9. package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
  10. package/bin/agent/local/services/AgentAssemblyService.js +6 -11
  11. package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
  12. package/bin/config/AgentEnv.d.ts +9 -0
  13. package/bin/config/AgentEnv.d.ts.map +1 -0
  14. package/bin/config/AgentEnv.js +48 -0
  15. package/bin/config/AgentEnv.js.map +1 -0
  16. package/bin/config/AgentInitializer.d.ts +2 -10
  17. package/bin/config/AgentInitializer.d.ts.map +1 -1
  18. package/bin/config/AgentInitializer.js +17 -49
  19. package/bin/config/AgentInitializer.js.map +1 -1
  20. package/bin/config/EnvFile.d.ts +1 -1
  21. package/bin/config/EnvFile.js +1 -1
  22. package/bin/config/ExecutionBinding.d.ts +1 -1
  23. package/bin/config/ExecutionBinding.js +2 -2
  24. package/bin/config/ExecutionBinding.js.map +1 -1
  25. package/bin/config/Paths.d.ts +0 -66
  26. package/bin/config/Paths.d.ts.map +1 -1
  27. package/bin/config/Paths.js +0 -80
  28. package/bin/config/Paths.js.map +1 -1
  29. package/bin/index.d.ts +4 -5
  30. package/bin/index.d.ts.map +1 -1
  31. package/bin/index.js +2 -3
  32. package/bin/index.js.map +1 -1
  33. package/bin/plugin/core/PluginLocalExecution.js +2 -2
  34. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  35. package/bin/types/agent/AgentOptions.d.ts +12 -3
  36. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  37. package/bin/types/common/EnvFile.d.ts +1 -1
  38. package/bin/types/common/EnvFile.js +1 -1
  39. package/bin/types/config/DowncityConfig.d.ts +3 -21
  40. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  41. package/bin/types/config/ExecutionBinding.d.ts +1 -1
  42. package/bin/types/config/ExecutionBinding.js +1 -1
  43. package/bin/types/runtime/platform/Platform.d.ts +4 -12
  44. package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
  45. package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -122
  46. package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
  47. package/bin/types/runtime/platform/PlatformGateway.js +0 -7
  48. package/bin/types/runtime/platform/PlatformGateway.js.map +1 -1
  49. package/bin/utils/logger/FormatRequest.js +1 -1
  50. package/bin/utils/logger/FormatRequest.js.map +1 -1
  51. package/package.json +3 -3
  52. package/scripts/agent-env.test.mjs +101 -0
  53. package/src/agent/local/AgentRuntimeAssembly.ts +4 -2
  54. package/src/agent/local/ProjectSetup.ts +3 -22
  55. package/src/agent/local/services/AgentAssemblyService.ts +6 -10
  56. package/src/config/AgentEnv.ts +49 -0
  57. package/src/config/AgentInitializer.ts +18 -61
  58. package/src/config/EnvFile.ts +1 -1
  59. package/src/config/ExecutionBinding.ts +2 -2
  60. package/src/config/Paths.ts +0 -89
  61. package/src/index.ts +12 -16
  62. package/src/plugin/core/PluginLocalExecution.ts +2 -2
  63. package/src/types/agent/AgentOptions.ts +13 -3
  64. package/src/types/common/EnvFile.ts +1 -1
  65. package/src/types/config/DowncityConfig.ts +3 -22
  66. package/src/types/config/ExecutionBinding.ts +1 -1
  67. package/src/types/runtime/platform/Platform.ts +4 -14
  68. package/src/types/runtime/platform/PlatformGateway.ts +2 -138
  69. package/src/utils/logger/FormatRequest.ts +1 -1
  70. package/tsconfig.tsbuildinfo +1 -1
  71. package/bin/config/Config.d.ts +0 -27
  72. package/bin/config/Config.d.ts.map +0 -1
  73. package/bin/config/Config.js +0 -128
  74. package/bin/config/Config.js.map +0 -1
  75. package/bin/executor/composer/system/default/InitPromptAssets.d.ts +0 -16
  76. package/bin/executor/composer/system/default/InitPromptAssets.d.ts.map +0 -1
  77. package/bin/executor/composer/system/default/InitPromptAssets.js +0 -18
  78. package/bin/executor/composer/system/default/InitPromptAssets.js.map +0 -1
  79. package/bin/executor/composer/system/default/InitPrompts.d.ts +0 -9
  80. package/bin/executor/composer/system/default/InitPrompts.d.ts.map +0 -1
  81. package/bin/executor/composer/system/default/InitPrompts.js +0 -9
  82. package/bin/executor/composer/system/default/InitPrompts.js.map +0 -1
  83. package/bin/executor/composer/system/default/StaticPromptCatalog.d.ts +0 -50
  84. package/bin/executor/composer/system/default/StaticPromptCatalog.d.ts.map +0 -1
  85. package/bin/executor/composer/system/default/StaticPromptCatalog.js +0 -227
  86. package/bin/executor/composer/system/default/StaticPromptCatalog.js.map +0 -1
  87. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts +0 -7
  88. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +0 -1
  89. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +0 -8
  90. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +0 -1
  91. package/bin/executor/composer/system/default/assets/init/SOUL.md.d.ts +0 -7
  92. package/bin/executor/composer/system/default/assets/init/SOUL.md.d.ts.map +0 -1
  93. package/bin/executor/composer/system/default/assets/init/SOUL.md.js +0 -8
  94. package/bin/executor/composer/system/default/assets/init/SOUL.md.js.map +0 -1
  95. package/src/config/Config.ts +0 -146
  96. package/src/executor/composer/system/default/InitPromptAssets.ts +0 -20
  97. package/src/executor/composer/system/default/InitPrompts.ts +0 -11
  98. package/src/executor/composer/system/default/StaticPromptCatalog.ts +0 -291
  99. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts +0 -9
  100. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +0 -16
  101. package/src/executor/composer/system/default/assets/init/SOUL.md.ts +0 -9
  102. package/src/executor/composer/system/default/assets/init/SOUL.md.ts.txt +0 -87
package/src/index.ts CHANGED
@@ -146,11 +146,6 @@ export type {
146
146
  SessionComposerOptions,
147
147
  } from "./types/session/SessionComposerOptions.js";
148
148
  export { transformPromptsIntoSystemMessages } from "./executor/composer/system/default/PromptRenderer.js";
149
- export {
150
- loadStaticSystemPrompts,
151
- StaticPromptCatalog,
152
- } from "./executor/composer/system/default/StaticPromptCatalog.js";
153
-
154
149
  // 通用 plugin 宿主工具
155
150
  export {
156
151
  buildStaticPluginAvailability,
@@ -198,10 +193,12 @@ export type {
198
193
  // 项目与配置集成
199
194
  export {
200
195
  initializeAgentProject,
201
- isAgentProjectInitialized,
202
196
  normalizeDefaultAgentId,
203
197
  } from "./config/AgentInitializer.js";
204
- export { loadDowncityConfig } from "./config/Config.js";
198
+ export {
199
+ load_project_dotenv,
200
+ resolve_agent_env,
201
+ } from "./config/AgentEnv.js";
205
202
  export {
206
203
  getDowncityChatHistoryPath,
207
204
  getDowncitySessionMessagesPath,
@@ -238,7 +235,14 @@ export type {
238
235
  export type { ExecutionBindingConfig } from "./types/config/ExecutionBinding.js";
239
236
 
240
237
  // 配置与模型类型
241
- export type { DowncityConfig } from "./types/config/DowncityConfig.js";
238
+ export type {
239
+ DowncityChatChannelConfig,
240
+ DowncityChatPluginChannelsConfig,
241
+ DowncityChatPluginConfig,
242
+ DowncityChatPluginQueueConfig,
243
+ DowncityConfig,
244
+ DowncityPluginConfigMap,
245
+ } from "./types/config/DowncityConfig.js";
242
246
  export type {
243
247
  LlmConfig,
244
248
  LlmModelConfig,
@@ -266,14 +270,6 @@ export type {
266
270
 
267
271
  export type {
268
272
  PlatformAgentChatChannelStatus,
269
- PlatformAgentShipChatChannelsConfig,
270
- PlatformAgentShipChatPluginConfig,
271
- PlatformAgentShipExecutionAgentConfig,
272
- PlatformAgentShipExecutionConfig,
273
- PlatformAgentShipJson,
274
- PlatformAgentShipPluginsConfig,
275
- PlatformAgentShipSingleChannelConfig,
276
- PlatformAgentShipStartConfig,
277
273
  } from "./types/runtime/platform/PlatformGateway.js";
278
274
 
279
275
  // Inline instant 协议类型
@@ -9,7 +9,7 @@
9
9
 
10
10
  import path from "node:path";
11
11
  import { logger as defaultLogger } from "@/utils/logger/Logger.js";
12
- import { resolveAgentEnv } from "@/config/Config.js";
12
+ import { resolve_agent_env } from "@/config/AgentEnv.js";
13
13
  import { findPluginByName } from "@/plugin/core/PluginCatalog.js";
14
14
  import {
15
15
  createAgentPathRuntime,
@@ -39,7 +39,7 @@ export function createLocalPluginCommandContext(
39
39
  ): PluginCommandContext {
40
40
  const projectRoot = typeof input === "string" ? input : input.projectRoot;
41
41
  const rootPath = path.resolve(String(projectRoot || "").trim() || ".");
42
- const env = resolveAgentEnv(rootPath);
42
+ const env = resolve_agent_env(rootPath);
43
43
  const config = typeof input === "string" || !input.config
44
44
  ? createFallbackSdkConfig(path.basename(rootPath) || "agent")
45
45
  : input.config;
@@ -11,6 +11,7 @@ import type { Shell } from "@downcity/shell";
11
11
  import type { Plugin } from "@/types/plugin/PluginDefinition.js";
12
12
  import type { AgentModel } from "@/model/CityModelAdapter.js";
13
13
  import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
14
+ import type { AgentPluginConfigRuntime } from "@/types/agent/AgentRuntimeAssembly.js";
14
15
  import type {
15
16
  AgentManagedSession,
16
17
  SessionOptions,
@@ -66,7 +67,7 @@ export interface AgentOptions {
66
67
  *
67
68
  * 关键点(中文)
68
69
  * - `instruction` 是稳定、缓存友好的 system 前缀,不做动态变量替换。
69
- * - SDK 不主动读取 `PROFILE.md` / `SOUL.md`;这类项目文件应由 city 或调用方读取后传入。
70
+ * - 项目目录不再提供隐式 prompt 文件;调用方需要的指令必须显式传入。
70
71
  * - 未传入时,SDK 会使用包内最小 core instruction 作为 fallback。
71
72
  */
72
73
  instruction?: string | string[];
@@ -116,8 +117,17 @@ export interface AgentOptions {
116
117
  * 宿主显式传入的运行时配置。
117
118
  *
118
119
  * 关键点(中文)
119
- * - SDK 不要求项目目录存在 `downcity.json`。
120
- * - CLI / Console 可从自己的配置存储读取后传入这里。
120
+ * - SDK 不读取项目配置文件。
121
+ * - CLI / Console 从自己的全局配置存储读取后传入这里。
121
122
  */
122
123
  config?: DowncityConfig;
124
+
125
+ /**
126
+ * 宿主提供的 plugin 配置持久化能力。
127
+ *
128
+ * 关键点(中文)
129
+ * - SDK 默认会拒绝持久化操作;CLI 等宿主可在这里接入自己的全局数据库。
130
+ * - plugin 只依赖该稳定接口,不感知 SQLite、文件或远端服务等具体实现。
131
+ */
132
+ plugin_config?: AgentPluginConfigRuntime;
123
133
  }
@@ -2,7 +2,7 @@
2
2
  * Env 文件工具相关类型定义。
3
3
  *
4
4
  * 职责说明(中文)
5
- * - 统一描述 `.env` / `.env.example` 写入工具使用的最小数据结构。
5
+ * - 统一描述项目 `.env` 写入工具使用的最小数据结构。
6
6
  * - 避免工具模块直接内联匿名对象,便于后续在其他初始化流程中复用。
7
7
  * - 这里只描述“文件写入条目”,不承载运行时环境变量快照语义。
8
8
  */
@@ -74,20 +74,6 @@ export interface DowncityChatPluginQueueConfig {
74
74
  mergeMaxWaitMs?: number;
75
75
  }
76
76
 
77
- /**
78
- * 聊天插件出站控制配置。
79
- */
80
- export interface DowncityChatPluginEgressConfig {
81
- /**
82
- * 单次 agent run 内,`chat_send` 允许调用的最大次数。
83
- */
84
- chatSendMaxCallsPerRun?: number;
85
- /**
86
- * 是否启用 `chat_send` 幂等去重(基于 inbound messageId + 回复内容 hash)。
87
- */
88
- chatSendIdempotency?: boolean;
89
- }
90
-
91
77
  /**
92
78
  * 聊天插件配置。
93
79
  */
@@ -96,10 +82,6 @@ export interface DowncityChatPluginConfig {
96
82
  * Chat 调度队列(按 chatKey 分 lane)。
97
83
  */
98
84
  queue?: DowncityChatPluginQueueConfig;
99
- /**
100
- * 出站(egress)控制:用于限制工具发送、避免重复与无限循环刷屏。
101
- */
102
- egress?: DowncityChatPluginEgressConfig;
103
85
  /**
104
86
  * 消息平台 channel 配置。
105
87
  */
@@ -107,7 +89,7 @@ export interface DowncityChatPluginConfig {
107
89
  }
108
90
 
109
91
  /**
110
- * downcity.json 中的插件配置映射。
92
+ * Agent 全局配置中的插件配置映射。
111
93
  */
112
94
  export interface DowncityPluginConfigMap {
113
95
  /**
@@ -124,7 +106,6 @@ export interface DowncityPluginConfigMap {
124
106
  }
125
107
 
126
108
  export interface DowncityConfig {
127
- $schema?: string;
128
109
  /**
129
110
  * agent 唯一标识。
130
111
  *
@@ -147,7 +128,7 @@ export interface DowncityConfig {
147
128
  *
148
129
  * 关键点(中文)
149
130
  * - 所有可配置能力统一收敛到 `plugins`,不再保留独立 `services` 域。
150
- * - 需要持久化到项目文件的 plugin 配置(例如 `plugins.chat.channels`)放在这里。
131
+ * - 需要持久化的 plugin 配置(例如 `plugins.chat.channels`)由宿主写入全局配置存储。
151
132
  * - key 为 plugin 名称,value 为对应插件的结构化配置对象。
152
133
  * - 当前阶段允许各 plugin 自定义字段,但必须保持 JSON 可序列化。
153
134
  */
@@ -166,7 +147,7 @@ export interface DowncityConfig {
166
147
  * 关键点(中文)
167
148
  * - `@downcity/agent` 本地 SDK 不直接消费该字段。
168
149
  * - 宿主侧(例如 `downcity`)可读取该字段控制模型工厂行为,例如 `llm.logMessages`。
169
- * - 对于项目内 `downcity.json`,通常不需要显式写 provider/model 明细。
150
+ * - 该字段通常由宿主平台装配,不由 Agent SDK 解析。
170
151
  */
171
152
  llm?: LlmConfig;
172
153
  }
@@ -4,7 +4,7 @@
4
4
  * 关键点(中文)
5
5
  * - 项目运行入口只有一种执行模式:`api`。
6
6
  * - 绑定 City AIService 暴露的模型 ID。
7
- * - 该类型是项目 `downcity.json` 中唯一的执行配置。
7
+ * - 该类型是 Agent 全局配置中的执行绑定结构。
8
8
  */
9
9
 
10
10
  /**
@@ -17,7 +17,7 @@ export interface PlatformAgentOption {
17
17
  id: string;
18
18
 
19
19
  /**
20
- * agent 项目自身的稳定标识(优先 downcity.json.id,回退目录名推导)。
20
+ * Agent 全局配置中的稳定标识。
21
21
  */
22
22
  agentId: string;
23
23
 
@@ -90,7 +90,7 @@ export interface PlatformAgentOption {
90
90
  }>;
91
91
 
92
92
  /**
93
- * 当前 agent 绑定的 console 模型 ID(downcity.json.execution.modelId)。
93
+ * 当前 Agent 全局配置绑定的模型 ID
94
94
  */
95
95
  modelId?: string;
96
96
  }
@@ -154,16 +154,6 @@ export interface PlatformAgentDirectoryInspection {
154
154
  */
155
155
  initialized: boolean;
156
156
 
157
- /**
158
- * `downcity.json` 是否存在。
159
- */
160
- hasShipJson: boolean;
161
-
162
- /**
163
- * `PROFILE.md` 是否存在。
164
- */
165
- hasProfileMd: boolean;
166
-
167
157
  /** 该目录是否已出现在 managed agent registry 中。 */
168
158
  knownAgent: boolean;
169
159
 
@@ -266,7 +256,7 @@ export interface ControlPlaneRuntimeStatus {
266
256
  */
267
257
  export interface PlatformConfigFileStatusItem {
268
258
  /**
269
- * 配置文件逻辑名称(例如 `ship_json`、`control_plane_pid`)。
259
+ * 配置状态逻辑名称(例如 `agent_config`、`control_plane_pid`)。
270
260
  */
271
261
  key: string;
272
262
 
@@ -336,7 +326,7 @@ export interface PlatformConfigStatusResponse {
336
326
  selectedAgentId: string;
337
327
 
338
328
  /**
339
- * 当前选中的 agent 项目 id(即 `downcity.json.id`,可能为空)。
329
+ * 当前选中的 Agent 配置 id(可能为空)。
340
330
  */
341
331
  selectedAgentProjectId: string;
342
332
 
@@ -1,146 +1,10 @@
1
1
  /**
2
- * 平台控制面读取 agent 项目配置与 runtime 状态时使用的宽松类型。
2
+ * 平台控制面读取 Agent runtime 状态时使用的宽松类型。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 仅承载平台 gateway / control plane 内部使用的结构化类型。
6
- * - 所有字段保持宽松输入,便于兼容磁盘 JSON 与运行时 API 的非强约束数据。
6
+ * - 所有字段保持宽松输入,便于兼容运行时 API 的非强约束数据。
7
7
  */
8
-
9
- /**
10
- * downcity.json 中的 ACP agent 配置。
11
- */
12
- export interface PlatformAgentShipExecutionAgentConfig {
13
- /**
14
- * ACP agent 类型。
15
- */
16
- type?: unknown;
17
- /**
18
- * 自定义启动命令。
19
- */
20
- command?: unknown;
21
- /**
22
- * 自定义启动参数。
23
- */
24
- args?: unknown;
25
- /**
26
- * 自定义环境变量。
27
- */
28
- env?: unknown;
29
- }
30
-
31
- /**
32
- * downcity.json 中的 execution 配置。
33
- */
34
- export interface PlatformAgentShipExecutionConfig {
35
- /**
36
- * 执行模式。
37
- */
38
- type?: unknown;
39
- /**
40
- * 模型执行模式下的模型 ID。
41
- */
42
- modelId?: unknown;
43
- /**
44
- * ACP 执行模式下的 agent 配置。
45
- */
46
- agent?: PlatformAgentShipExecutionAgentConfig;
47
- }
48
-
49
- /**
50
- * 单个聊天渠道配置。
51
- */
52
- export interface PlatformAgentShipSingleChannelConfig {
53
- /**
54
- * 渠道是否启用。
55
- */
56
- enabled?: unknown;
57
-
58
- /**
59
- * 绑定的渠道账户 id。
60
- */
61
- channelAccountId?: unknown;
62
- }
63
-
64
- /**
65
- * 聊天插件渠道配置集合。
66
- */
67
- export interface PlatformAgentShipChatChannelsConfig {
68
- /**
69
- * Telegram 渠道配置。
70
- */
71
- telegram?: PlatformAgentShipSingleChannelConfig;
72
-
73
- /**
74
- * 飞书渠道配置。
75
- */
76
- feishu?: PlatformAgentShipSingleChannelConfig;
77
-
78
- /**
79
- * QQ 渠道配置。
80
- */
81
- qq?: PlatformAgentShipSingleChannelConfig;
82
- }
83
-
84
- /**
85
- * 聊天插件配置。
86
- */
87
- export interface PlatformAgentShipChatPluginConfig {
88
- /**
89
- * 渠道配置集合。
90
- */
91
- channels?: PlatformAgentShipChatChannelsConfig;
92
- }
93
-
94
- /**
95
- * downcity.json 中的 plugins 配置。
96
- */
97
- export interface PlatformAgentShipPluginsConfig {
98
- /**
99
- * chat 插件配置。
100
- */
101
- chat?: PlatformAgentShipChatPluginConfig;
102
- }
103
-
104
- /**
105
- * downcity.json 中的启动配置。
106
- */
107
- export interface PlatformAgentShipStartConfig {
108
- /**
109
- * downcity Agent HTTP gateway host。
110
- */
111
- host?: unknown;
112
-
113
- /**
114
- * downcity Agent HTTP gateway port。
115
- */
116
- port?: unknown;
117
- }
118
-
119
- /**
120
- * downcity.json 宽松结构。
121
- */
122
- export interface PlatformAgentShipJson {
123
- /**
124
- * agent 稳定标识。
125
- */
126
- id?: unknown;
127
-
128
- /**
129
- * 执行配置。
130
- */
131
- execution?: PlatformAgentShipExecutionConfig;
132
-
133
- /**
134
- * 插件配置。
135
- */
136
- plugins?: PlatformAgentShipPluginsConfig;
137
-
138
- /**
139
- * 启动配置。
140
- */
141
- start?: PlatformAgentShipStartConfig;
142
- }
143
-
144
8
  /**
145
9
  * chat plugin status 返回中的单渠道状态。
146
10
  */
@@ -335,7 +335,7 @@ export function parseFetchRequestForLog(
335
335
  } | null {
336
336
  // 关键注释:这里的 maxChars 不用于“整体截断请求日志”,仅作为 payload 兜底 stringify 的保护上限。
337
337
  const maxChars = 12000;
338
- // 统一开关:只由 downcity.json 的 llm.logMessages 控制(由宿主模型工厂读取)。
338
+ // 统一开关:只由宿主配置的 llm.logMessages 控制(由宿主模型工厂读取)。
339
339
  // 这里不支持额外的“更敏感 payload”开关,避免不一致与误配置。
340
340
  const includePayload = false;
341
341