@downcity/agent 1.1.175 → 1.1.178

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 (139) hide show
  1. package/bin/agent/local/AgentPluginFactory.d.ts +4 -2
  2. package/bin/agent/local/AgentPluginFactory.d.ts.map +1 -1
  3. package/bin/agent/local/AgentPluginFactory.js +4 -6
  4. package/bin/agent/local/AgentPluginFactory.js.map +1 -1
  5. package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +1 -1
  6. package/bin/agent/local/AgentRuntimeAssembly.js +3 -8
  7. package/bin/agent/local/AgentRuntimeAssembly.js.map +1 -1
  8. package/bin/agent/local/ProjectSetup.d.ts +1 -1
  9. package/bin/agent/local/ProjectSetup.d.ts.map +1 -1
  10. package/bin/agent/local/ProjectSetup.js +2 -6
  11. package/bin/agent/local/ProjectSetup.js.map +1 -1
  12. package/bin/agent/local/services/AgentAssemblyService.d.ts +2 -3
  13. package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
  14. package/bin/agent/local/services/AgentAssemblyService.js +9 -14
  15. package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
  16. package/bin/agent/local/services/AgentBackgroundService.d.ts.map +1 -1
  17. package/bin/agent/local/services/AgentBackgroundService.js +5 -6
  18. package/bin/agent/local/services/AgentBackgroundService.js.map +1 -1
  19. package/bin/agent/local/services/AgentSessionManager.d.ts +2 -2
  20. package/bin/agent/local/services/AgentSessionManager.d.ts.map +1 -1
  21. package/bin/agent/local/services/AgentSessionManager.js +1 -28
  22. package/bin/agent/local/services/AgentSessionManager.js.map +1 -1
  23. package/bin/config/AgentInitializer.d.ts +4 -4
  24. package/bin/config/AgentInitializer.d.ts.map +1 -1
  25. package/bin/config/AgentInitializer.js +7 -49
  26. package/bin/config/AgentInitializer.js.map +1 -1
  27. package/bin/config/DowncitySchema.d.ts +3 -4
  28. package/bin/config/DowncitySchema.d.ts.map +1 -1
  29. package/bin/config/DowncitySchema.js +1 -2
  30. package/bin/config/DowncitySchema.js.map +1 -1
  31. package/bin/executor/composer/system/default/SystemDomain.d.ts.map +1 -1
  32. package/bin/executor/composer/system/default/SystemDomain.js +1 -2
  33. package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
  34. package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
  35. package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
  36. package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
  37. package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
  38. package/bin/index.d.ts +0 -2
  39. package/bin/index.d.ts.map +1 -1
  40. package/bin/index.js +1 -4
  41. package/bin/index.js.map +1 -1
  42. package/bin/plugin/core/Activation.d.ts +6 -5
  43. package/bin/plugin/core/Activation.d.ts.map +1 -1
  44. package/bin/plugin/core/Activation.js +9 -9
  45. package/bin/plugin/core/Activation.js.map +1 -1
  46. package/bin/plugin/core/BasePlugin.d.ts +5 -4
  47. package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
  48. package/bin/plugin/core/BasePlugin.js +7 -4
  49. package/bin/plugin/core/BasePlugin.js.map +1 -1
  50. package/bin/plugin/core/HookRegistry.d.ts +4 -0
  51. package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
  52. package/bin/plugin/core/HookRegistry.js +40 -0
  53. package/bin/plugin/core/HookRegistry.js.map +1 -1
  54. package/bin/plugin/core/Manager.d.ts +1 -1
  55. package/bin/plugin/core/Manager.d.ts.map +1 -1
  56. package/bin/plugin/core/Manager.js +1 -1
  57. package/bin/plugin/core/Manager.js.map +1 -1
  58. package/bin/plugin/core/PluginActionRunner.d.ts +13 -7
  59. package/bin/plugin/core/PluginActionRunner.d.ts.map +1 -1
  60. package/bin/plugin/core/PluginActionRunner.js +46 -111
  61. package/bin/plugin/core/PluginActionRunner.js.map +1 -1
  62. package/bin/plugin/core/PluginCatalog.d.ts +1 -1
  63. package/bin/plugin/core/PluginCatalog.d.ts.map +1 -1
  64. package/bin/plugin/core/PluginCatalog.js +1 -21
  65. package/bin/plugin/core/PluginCatalog.js.map +1 -1
  66. package/bin/plugin/core/PluginLocalExecution.d.ts +12 -2
  67. package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
  68. package/bin/plugin/core/PluginLocalExecution.js +18 -24
  69. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  70. package/bin/plugin/core/PluginRegistry.d.ts +60 -7
  71. package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
  72. package/bin/plugin/core/PluginRegistry.js +269 -42
  73. package/bin/plugin/core/PluginRegistry.js.map +1 -1
  74. package/bin/plugin/core/PluginStateController.d.ts +11 -36
  75. package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
  76. package/bin/plugin/core/PluginStateController.js +45 -190
  77. package/bin/plugin/core/PluginStateController.js.map +1 -1
  78. package/bin/plugin/types/Plugin.d.ts +1 -1
  79. package/bin/plugin/types/Plugin.d.ts.map +1 -1
  80. package/bin/plugin/types/PluginState.d.ts +1 -1
  81. package/bin/plugin/types/PluginState.d.ts.map +1 -1
  82. package/bin/plugin/types/Plugins.d.ts +12 -12
  83. package/bin/plugin/types/Plugins.d.ts.map +1 -1
  84. package/bin/types/agent/AgentOptions.d.ts +12 -3
  85. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  86. package/bin/types/agent/AgentRuntimeAssembly.d.ts +1 -1
  87. package/bin/types/config/AgentProject.d.ts +6 -14
  88. package/bin/types/config/AgentProject.d.ts.map +1 -1
  89. package/bin/types/plugin/PluginRuntime.d.ts +23 -2
  90. package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
  91. package/bin/types/plugin/PluginState.d.ts +47 -36
  92. package/bin/types/plugin/PluginState.d.ts.map +1 -1
  93. package/bin/types/plugin/PluginState.js +4 -3
  94. package/bin/types/plugin/PluginState.js.map +1 -1
  95. package/bin/types/runtime/agent/AgentContext.d.ts +3 -3
  96. package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
  97. package/bin/types/runtime/agent/AgentContext.js.map +1 -1
  98. package/package.json +3 -3
  99. package/src/agent/local/AgentPluginFactory.ts +8 -8
  100. package/src/agent/local/AgentRuntimeAssembly.ts +3 -9
  101. package/src/agent/local/ProjectSetup.ts +1 -8
  102. package/src/agent/local/services/AgentAssemblyService.ts +13 -23
  103. package/src/agent/local/services/AgentBackgroundService.ts +5 -6
  104. package/src/agent/local/services/AgentSessionManager.ts +4 -26
  105. package/src/config/AgentInitializer.ts +7 -57
  106. package/src/config/DowncitySchema.ts +3 -4
  107. package/src/executor/composer/system/default/SystemDomain.ts +1 -2
  108. package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
  109. package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -1
  110. package/src/index.ts +1 -8
  111. package/src/plugin/core/Activation.ts +10 -10
  112. package/src/plugin/core/BasePlugin.ts +9 -6
  113. package/src/plugin/core/HookRegistry.ts +41 -0
  114. package/src/plugin/core/Manager.ts +0 -2
  115. package/src/plugin/core/PluginActionRunner.ts +52 -133
  116. package/src/plugin/core/PluginCatalog.ts +1 -23
  117. package/src/plugin/core/PluginLocalExecution.ts +30 -25
  118. package/src/plugin/core/PluginRegistry.ts +298 -44
  119. package/src/plugin/core/PluginStateController.ts +45 -235
  120. package/src/plugin/types/Plugin.ts +2 -1
  121. package/src/plugin/types/PluginState.ts +2 -1
  122. package/src/plugin/types/Plugins.ts +12 -12
  123. package/src/types/agent/AgentOptions.ts +13 -3
  124. package/src/types/agent/AgentRuntimeAssembly.ts +1 -1
  125. package/src/types/config/AgentProject.ts +7 -15
  126. package/src/types/plugin/PluginRuntime.ts +23 -2
  127. package/src/types/plugin/PluginState.ts +50 -43
  128. package/src/types/runtime/agent/AgentContext.ts +3 -3
  129. package/tsconfig.tsbuildinfo +1 -1
  130. package/bin/config/Defaults.d.ts +0 -21
  131. package/bin/config/Defaults.d.ts.map +0 -1
  132. package/bin/config/Defaults.js +0 -47
  133. package/bin/config/Defaults.js.map +0 -1
  134. package/bin/plugin/core/ProjectConfigStore.d.ts +0 -84
  135. package/bin/plugin/core/ProjectConfigStore.d.ts.map +0 -1
  136. package/bin/plugin/core/ProjectConfigStore.js +0 -89
  137. package/bin/plugin/core/ProjectConfigStore.js.map +0 -1
  138. package/src/config/Defaults.ts +0 -49
  139. package/src/plugin/core/ProjectConfigStore.ts +0 -155
@@ -1,144 +1,29 @@
1
1
  /**
2
- * PluginStateController:主动型 plugin 状态控制与状态记录模块。
2
+ * Plugin 注册状态兼容控制模块。
3
+ *
4
+ * 关键点(中文)
5
+ * - 新模型中 plugin 只有注册 / 卸载,不再暴露 start / stop / restart。
6
+ * - 该模块保留旧内部函数名,方便 RPC、CLI 与内建 plugin 渐进迁移。
3
7
  */
4
8
 
5
9
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
6
10
  import type {
7
- PluginLifecycle,
8
- PluginState,
9
11
  PluginStateControlAction,
10
12
  PluginStateControlResult,
11
- PluginStateRecord,
12
13
  PluginStateSnapshot,
13
14
  } from "@/plugin/types/Plugin.js";
14
- import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
15
-
16
- function nowMs(): number {
17
- return Date.now();
18
- }
19
-
20
- function resolveLifecycle(plugin: BasePlugin): PluginLifecycle | undefined {
21
- return plugin.lifecycle;
22
- }
23
-
24
- /**
25
- * 列出当前进程内可见的主动型 plugin 实例。
26
- */
27
- export function listPluginInstances(input?: {
28
- context?: AgentContext;
29
- }): BasePlugin[] {
30
- const contextPlugins = input?.context?.pluginInstances;
31
- if (contextPlugins instanceof Map && contextPlugins.size > 0) {
32
- return [...contextPlugins.values()];
33
- }
34
- return [];
35
- }
36
-
37
- /**
38
- * 按名称解析主动型 plugin 实例。
39
- */
40
- export function resolvePluginByName(
41
- name: string,
42
- input?: {
43
- context?: AgentContext;
44
- },
45
- ): BasePlugin | null {
46
- const key = String(name || "").trim();
47
- if (!key) return null;
48
- return listPluginInstances(input).find((plugin) => plugin.name === key) || null;
49
- }
50
-
51
- /**
52
- * 确保 plugin 对应的状态记录存在。
53
- */
54
- export function ensurePluginStateRecord(
55
- plugin: BasePlugin,
56
- ): PluginStateRecord {
57
- return plugin.pluginStateRecord;
58
- }
59
-
60
- function hasCommandActions(plugin: BasePlugin): boolean {
61
- return Object.values(plugin.actions).some((action) => Boolean(action.command));
62
- }
63
-
64
- /**
65
- * 把内部 record 映射为对外快照。
66
- */
67
- export function toPluginStateSnapshot(
68
- record: PluginStateRecord,
69
- plugin: BasePlugin,
70
- ): PluginStateSnapshot {
71
- const lifecycle = resolveLifecycle(plugin);
72
- return {
73
- name: plugin.name,
74
- state: record.state,
75
- updatedAt: record.updatedAt,
76
- ...(record.lastError ? { lastError: record.lastError } : {}),
77
- ...(record.lastCommand ? { lastCommand: record.lastCommand } : {}),
78
- ...(typeof record.lastCommandAt === "number"
79
- ? { lastCommandAt: record.lastCommandAt }
80
- : {}),
81
- supportsLifecycle: Boolean(lifecycle?.start || lifecycle?.stop),
82
- supportsCommand: Boolean(lifecycle?.command) || hasCommandActions(plugin),
83
- };
84
- }
85
-
86
- async function runSerialByPlugin(
87
- record: PluginStateRecord,
88
- step: () => Promise<void> | void,
89
- ): Promise<void> {
90
- const next = record.chain.then(() => Promise.resolve(step()));
91
- record.chain = next.then(
92
- () => undefined,
93
- () => undefined,
94
- );
95
- await next;
96
- }
97
-
98
- /**
99
- * 标记 plugin 当前状态。
100
- */
101
- export function markPluginState(
102
- record: PluginStateRecord,
103
- state: PluginState,
104
- error?: string,
105
- ): void {
106
- record.state = state;
107
- record.updatedAt = nowMs();
108
- if (error) {
109
- record.lastError = error;
110
- return;
111
- }
112
- delete record.lastError;
113
- }
114
15
 
115
16
  /**
116
- * 标记最近一次 plugin command。
117
- */
118
- export function markPluginCommand(
119
- record: PluginStateRecord,
120
- command: string,
121
- ): void {
122
- record.lastCommand = command;
123
- record.lastCommandAt = nowMs();
124
- record.updatedAt = nowMs();
125
- }
126
-
127
- /**
128
- * 列出全部主动型 plugin 状态快照。
17
+ * 列出当前 Agent 已注册 plugin 快照。
129
18
  */
130
19
  export function listPluginStates(input?: {
131
20
  context?: AgentContext;
132
21
  }): PluginStateSnapshot[] {
133
- return listPluginInstances(input)
134
- .map((plugin) =>
135
- toPluginStateSnapshot(ensurePluginStateRecord(plugin), plugin),
136
- )
137
- .sort((a, b) => a.name.localeCompare(b.name));
22
+ return input?.context?.plugins.snapshots() || [];
138
23
  }
139
24
 
140
25
  /**
141
- * 判断指定主动型 plugin 是否处于运行中。
26
+ * 判断指定 plugin 是否已注册且 ready。
142
27
  */
143
28
  export function isPluginRunning(
144
29
  pluginName: string,
@@ -146,154 +31,79 @@ export function isPluginRunning(
146
31
  context?: AgentContext;
147
32
  },
148
33
  ): boolean {
149
- const plugin = resolvePluginByName(pluginName, input);
150
- if (!plugin) return false;
151
- return ensurePluginStateRecord(plugin).state === "running";
152
- }
153
-
154
- async function startPluginInternal(
155
- plugin: BasePlugin,
156
- context: AgentContext,
157
- ): Promise<PluginStateControlResult> {
158
- const record = ensurePluginStateRecord(plugin);
159
- const lifecycle = resolveLifecycle(plugin);
160
- try {
161
- await runSerialByPlugin(record, async () => {
162
- if (record.state === "running") return;
163
- markPluginState(record, "starting");
164
- try {
165
- await lifecycle?.start?.(context);
166
- markPluginState(record, "running");
167
- } catch (error) {
168
- markPluginState(record, "error", String(error));
169
- throw error;
170
- }
171
- });
172
- return {
173
- success: true,
174
- plugin: toPluginStateSnapshot(record, plugin),
175
- };
176
- } catch (error) {
177
- return {
178
- success: false,
179
- plugin: toPluginStateSnapshot(record, plugin),
180
- error: String(error),
181
- };
182
- }
183
- }
184
-
185
- async function stopPluginInternal(
186
- plugin: BasePlugin,
187
- context: AgentContext,
188
- ): Promise<PluginStateControlResult> {
189
- const record = ensurePluginStateRecord(plugin);
190
- const lifecycle = resolveLifecycle(plugin);
191
- try {
192
- await runSerialByPlugin(record, async () => {
193
- if (record.state === "stopped") return;
194
- markPluginState(record, "stopping");
195
- try {
196
- await lifecycle?.stop?.(context);
197
- markPluginState(record, "stopped");
198
- } catch (error) {
199
- markPluginState(record, "error", String(error));
200
- throw error;
201
- }
202
- });
203
- return {
204
- success: true,
205
- plugin: toPluginStateSnapshot(record, plugin),
206
- };
207
- } catch (error) {
208
- return {
209
- success: false,
210
- plugin: toPluginStateSnapshot(record, plugin),
211
- error: String(error),
212
- };
213
- }
34
+ return input?.context?.plugins.status(pluginName)?.status === "ready";
214
35
  }
215
36
 
216
37
  /**
217
- * 执行单个主动型 plugin 状态控制动作。
38
+ * 执行兼容 plugin 控制动作。
218
39
  */
219
40
  export async function controlPluginState(params: {
220
41
  pluginName: string;
221
42
  action: PluginStateControlAction;
222
43
  context: AgentContext;
223
44
  }): Promise<PluginStateControlResult> {
224
- const plugin = resolvePluginByName(params.pluginName, {
225
- context: params.context,
226
- });
227
- if (!plugin) {
45
+ const pluginName = String(params.pluginName || "").trim();
46
+ if (!pluginName) {
228
47
  return {
229
48
  success: false,
230
- error: `Unknown plugin: ${params.pluginName}`,
49
+ error: "pluginName is required",
231
50
  };
232
51
  }
233
52
 
234
- if (params.action === "status") {
235
- const record = ensurePluginStateRecord(plugin);
236
- return {
237
- success: true,
238
- plugin: toPluginStateSnapshot(record, plugin),
239
- };
240
- }
241
-
242
- if (params.action === "start") {
243
- return await startPluginInternal(plugin, params.context);
53
+ const action = String(params.action || "").trim().toLowerCase();
54
+ if (action === "status" || action === "start" || action === "restart") {
55
+ const plugin = params.context.plugins.status(pluginName);
56
+ return plugin
57
+ ? { success: true, plugin }
58
+ : { success: false, error: `Unknown plugin: ${pluginName}` };
244
59
  }
245
60
 
246
- if (params.action === "stop") {
247
- return await stopPluginInternal(plugin, params.context);
61
+ if (action === "unregister" || action === "stop") {
62
+ const plugin = params.context.plugins.status(pluginName) || undefined;
63
+ const success = await params.context.plugins.unregister(pluginName);
64
+ return success
65
+ ? { success: true, ...(plugin ? { plugin } : {}) }
66
+ : { success: false, error: `Unknown plugin: ${pluginName}` };
248
67
  }
249
68
 
250
- const stopResult = await stopPluginInternal(plugin, params.context);
251
- if (!stopResult.success) return stopResult;
252
- return await startPluginInternal(plugin, params.context);
69
+ return {
70
+ success: false,
71
+ error: `Unsupported plugin control action: ${params.action}`,
72
+ };
253
73
  }
254
74
 
255
75
  /**
256
- * 启动当前上下文中全部主动型 plugin。
76
+ * 启动当前上下文中全部已挂载 plugin。
257
77
  */
258
78
  export async function startAllPlugins(context: AgentContext): Promise<{
259
79
  success: boolean;
260
80
  results: PluginStateControlResult[];
261
81
  }> {
262
- const results: PluginStateControlResult[] = [];
263
- for (const plugin of listPluginInstances({ context })) {
264
- results.push(
265
- await controlPluginState({
266
- pluginName: plugin.name,
267
- action: "start",
268
- context,
269
- }),
270
- );
271
- }
82
+ const snapshots = await context.plugins.startAll();
272
83
  return {
273
- success: results.every((item) => item.success),
274
- results,
84
+ success: snapshots.every((item) => item.status === "ready"),
85
+ results: snapshots.map((plugin) => ({
86
+ success: plugin.status === "ready",
87
+ plugin,
88
+ ...(plugin.last_error ? { error: plugin.last_error } : {}),
89
+ })),
275
90
  };
276
91
  }
277
92
 
278
93
  /**
279
- * 停止当前上下文中全部主动型 plugin。
94
+ * 卸载当前上下文中全部 plugin。
280
95
  */
281
96
  export async function stopAllPlugins(context: AgentContext): Promise<{
282
97
  success: boolean;
283
98
  results: PluginStateControlResult[];
284
99
  }> {
285
- const results: PluginStateControlResult[] = [];
286
- for (const plugin of listPluginInstances({ context })) {
287
- results.push(
288
- await controlPluginState({
289
- pluginName: plugin.name,
290
- action: "stop",
291
- context,
292
- }),
293
- );
294
- }
100
+ const snapshots = context.plugins.snapshots();
101
+ await context.plugins.unregisterAll();
295
102
  return {
296
- success: results.every((item) => item.success),
297
- results,
103
+ success: true,
104
+ results: snapshots.map((plugin) => ({
105
+ success: true,
106
+ plugin,
107
+ })),
298
108
  };
299
109
  }
@@ -10,7 +10,8 @@ export type {
10
10
  PluginState,
11
11
  PluginStateControlAction,
12
12
  PluginStateControlResult,
13
- PluginStateRecord,
13
+ PluginRuntimeRecord,
14
+ PluginSnapshot,
14
15
  PluginStateSnapshot,
15
16
  } from "@/types/plugin/PluginState.js";
16
17
  export type {
@@ -6,6 +6,7 @@ export type {
6
6
  PluginState,
7
7
  PluginStateControlAction,
8
8
  PluginStateControlResult,
9
- PluginStateRecord,
9
+ PluginRuntimeRecord,
10
+ PluginSnapshot,
10
11
  PluginStateSnapshot,
11
12
  } from "@/types/plugin/PluginState.js";
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type { JsonValue } from "@/types/common/Json.js";
6
6
 
7
- export type PluginControlAction = "start" | "stop" | "restart" | "status";
7
+ export type PluginControlAction = "status" | "unregister";
8
8
 
9
9
  /**
10
10
  * 单个 plugin 的对外状态视图。
@@ -12,20 +12,20 @@ export type PluginControlAction = "start" | "stop" | "restart" | "status";
12
12
  export type PluginStateView = {
13
13
  /** plugin 稳定名称。 */
14
14
  name: string;
15
- /** 当前运行状态。 */
16
- state: "running" | "stopped" | "starting" | "stopping" | "error";
17
- /** 最近一次状态更新时间(毫秒时间戳)。 */
15
+ /** 当前注册状态。 */
16
+ state: "ready" | "error";
17
+ /** 当前注册状态。 */
18
+ status: "ready" | "error";
19
+ /** 注册时间(毫秒时间戳)。 */
20
+ registered_at: number;
21
+ /** 最近更新时间(毫秒时间戳)。 */
22
+ updated_at: number;
23
+ /** 兼容旧字段的最近一次状态更新时间。 */
18
24
  updatedAt: number;
19
25
  /** 最近一次错误信息。 */
20
26
  lastError?: string;
21
- /** 最近一次执行的命令名称。 */
22
- lastCommand?: string;
23
- /** 最近一次执行命令的时间(毫秒时间戳)。 */
24
- lastCommandAt?: number;
25
- /** 当前 plugin 是否支持显式 start/stop 生命周期控制。 */
26
- supportsLifecycle: boolean;
27
- /** 当前 plugin 是否支持 command/action 调用。 */
28
- supportsCommand: boolean;
27
+ /** 最近一次错误信息。 */
28
+ last_error?: string;
29
29
  };
30
30
 
31
31
  /**
@@ -8,8 +8,9 @@
8
8
 
9
9
  import type { Tool } from "ai";
10
10
  import type { Shell } from "@downcity/shell";
11
- import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
11
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
12
12
  import type { AgentModel } from "@/model/CityModelAdapter.js";
13
+ import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
13
14
  import type {
14
15
  AgentManagedSession,
15
16
  SessionOptions,
@@ -84,12 +85,12 @@ export interface AgentOptions {
84
85
  * 当前 agent 显式持有的插件实例集合。
85
86
  *
86
87
  * 关键点(中文)
87
- * - 这里接收已经实例化好的 `BasePlugin` 对象,而不是 plugin class。
88
+ * - 这里接收已经创建好的 `Plugin` 对象,而不是 plugin class。
88
89
  * - `Agent` 会在构造阶段按名称注册这些实例,并自动绑定到当前 runtime。
89
90
  * - 同名 plugin 会直接报错,避免 action / hook / resolve 行为被静默覆盖。
90
91
  * - SDK 不再自动注入任何 built-in plugin;需要的能力都应由宿主显式传入。
91
92
  */
92
- plugins?: BasePlugin[];
93
+ plugins?: Plugin[];
93
94
 
94
95
  /**
95
96
  * 当前 agent 使用的本地 Session 类。
@@ -110,4 +111,13 @@ export interface AgentOptions {
110
111
  * - 覆盖后的最终 env 会参与配置解析与运行时上下文装配,但不会回写到宿主环境。
111
112
  */
112
113
  env?: Record<string, string>;
114
+
115
+ /**
116
+ * 宿主显式传入的运行时配置。
117
+ *
118
+ * 关键点(中文)
119
+ * - SDK 不要求项目目录存在 `downcity.json`。
120
+ * - CLI / Console 可从自己的配置存储读取后传入这里。
121
+ */
122
+ config?: DowncityConfig;
113
123
  }
@@ -68,7 +68,7 @@ export interface AgentPathRuntime {
68
68
  */
69
69
  export interface AgentPluginConfigRuntime {
70
70
  /**
71
- * 将当前 `plugins` 配置块写回项目 `downcity.json`。
71
+ * 将当前 `plugins` 配置块写回宿主配置存储。
72
72
  */
73
73
  persistProjectPlugins(plugins: DowncityConfig["plugins"] | undefined): Promise<string>;
74
74
  }
@@ -7,7 +7,6 @@
7
7
  */
8
8
 
9
9
  import type { ExecutionBindingConfig } from "@/types/config/ExecutionBinding.js";
10
- import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
11
10
 
12
11
  /**
13
12
  * 可选的 chat channel 标识。
@@ -28,7 +27,7 @@ export interface AgentProjectInitializationInput {
28
27
  *
29
28
  * 关键点(中文)
30
29
  * - 为空时会自动回退到目录名推导出的默认 id。
31
- * - 该字段会直接写入 `downcity.json.id`。
30
+ * - CLI 可把该字段写入自己的全局配置存储。
32
31
  */
33
32
  id?: string;
34
33
 
@@ -40,26 +39,14 @@ export interface AgentProjectInitializationInput {
40
39
  */
41
40
  execution: ExecutionBindingConfig;
42
41
 
43
- /**
44
- * 需要一并写入项目的 plugin 配置补丁。
45
- *
46
- * 说明(中文)
47
- * - 这里只承载初始化时的最小配置,不负责 city 级 plugin lifecycle。
48
- */
49
- plugins?: DowncityConfig["plugins"];
50
-
51
42
  /**
52
43
  * 需要启用的 chat channels。
53
44
  *
54
45
  * 关键点(中文)
55
- * - 仅写入用户选择的渠道,未选择的渠道不会写入 `downcity.json`。
46
+ * - SDK 初始化器只返回选择结果,不负责配置持久化。
56
47
  */
57
48
  channels?: AgentProjectChannel[];
58
49
 
59
- /**
60
- * 是否允许覆盖已存在的 `downcity.json`。
61
- */
62
- forceOverwriteShipJson?: boolean;
63
50
  }
64
51
 
65
52
  /**
@@ -81,6 +68,11 @@ export interface AgentProjectInitializationResult {
81
68
  */
82
69
  channels: AgentProjectChannel[];
83
70
 
71
+ /**
72
+ * 最终选择的 City AIService 模型 ID。
73
+ */
74
+ modelId?: string;
75
+
84
76
  /**
85
77
  * 本次实际创建/写入的文件列表。
86
78
  */
@@ -13,6 +13,9 @@ import type {
13
13
  import type { JsonValue } from "@/types/common/Json.js";
14
14
  import type { PluginActionResult } from "@/types/plugin/PluginAction.js";
15
15
  import type { PluginActionExample } from "@/types/plugin/PluginAction.js";
16
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
17
+ import type { AgentSessionSystemBlock } from "@/types/agent/AgentTypes.js";
18
+ import type { PluginSnapshot } from "@/types/plugin/PluginState.js";
16
19
 
17
20
  /**
18
21
  * Plugin 概览视图。
@@ -80,9 +83,9 @@ export interface PluginReadView {
80
83
  * Plugin 可用性结果。
81
84
  */
82
85
  export interface PluginAvailability {
83
- /** Plugin 是否启用。 */
86
+ /** Plugin 是否已注册。 */
84
87
  enabled: boolean;
85
- /** Plugin 当前是否可用。 */
88
+ /** Plugin 当前环境是否可用。 */
86
89
  available: boolean;
87
90
  /** 不可用原因列表。 */
88
91
  reasons: string[];
@@ -92,6 +95,22 @@ export interface PluginAvailability {
92
95
  * 当前 Agent 可用的 plugin 调用面。
93
96
  */
94
97
  export interface AgentPlugins {
98
+ /** 注册或替换一个 plugin。 */
99
+ register(plugin: Plugin): Promise<PluginSnapshot>;
100
+ /** 卸载一个 plugin。 */
101
+ unregister(pluginName: string): Promise<boolean>;
102
+ /** 启动全部已挂载 plugin lifecycle。 */
103
+ startAll(): Promise<PluginSnapshot[]>;
104
+ /** 卸载全部 plugin。 */
105
+ unregisterAll(): Promise<void>;
106
+ /** 判断 plugin 是否已注册。 */
107
+ has(pluginName: string): boolean;
108
+ /** 读取单个 plugin 定义。 */
109
+ get(pluginName: string): Plugin | null;
110
+ /** 读取单个 plugin 注册快照。 */
111
+ status(pluginName: string): PluginSnapshot | null;
112
+ /** 列出全部已注册 plugin 快照。 */
113
+ snapshots(): PluginSnapshot[];
95
114
  /** 列出全部已注册 plugin。 */
96
115
  list(): PluginView[];
97
116
  /** 读取 plugin / action metadata。 */
@@ -112,6 +131,8 @@ export interface AgentPlugins {
112
131
  /** Action Payload(可选)。 */
113
132
  payload?: JsonValue;
114
133
  }): Promise<PluginActionResult<JsonValue>>;
134
+ /** 读取当前生效的 plugin system blocks。 */
135
+ systemBlocks(): Promise<AgentSessionSystemBlock[]>;
115
136
  /** 运行 pipeline 点,按顺序链式变换值。 */
116
137
  pipeline<T = JsonValue>(pointName: string, value: T): Promise<T>;
117
138
  /** 运行 guard 点;任一插件抛错即终止。 */