@downcity/agent 1.1.175 → 1.1.179
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/bin/agent/local/AgentPluginFactory.d.ts +4 -2
- package/bin/agent/local/AgentPluginFactory.d.ts.map +1 -1
- package/bin/agent/local/AgentPluginFactory.js +4 -6
- package/bin/agent/local/AgentPluginFactory.js.map +1 -1
- package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +1 -1
- package/bin/agent/local/AgentRuntimeAssembly.js +3 -8
- package/bin/agent/local/AgentRuntimeAssembly.js.map +1 -1
- package/bin/agent/local/ProjectSetup.d.ts +1 -1
- package/bin/agent/local/ProjectSetup.d.ts.map +1 -1
- package/bin/agent/local/ProjectSetup.js +2 -6
- package/bin/agent/local/ProjectSetup.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +2 -3
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +9 -14
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentBackgroundService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentBackgroundService.js +5 -6
- package/bin/agent/local/services/AgentBackgroundService.js.map +1 -1
- package/bin/agent/local/services/AgentSessionManager.d.ts +2 -2
- package/bin/agent/local/services/AgentSessionManager.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessionManager.js +1 -28
- package/bin/agent/local/services/AgentSessionManager.js.map +1 -1
- package/bin/config/AgentInitializer.d.ts +4 -4
- package/bin/config/AgentInitializer.d.ts.map +1 -1
- package/bin/config/AgentInitializer.js +7 -49
- package/bin/config/AgentInitializer.js.map +1 -1
- package/bin/config/DowncitySchema.d.ts +3 -4
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +1 -2
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +1 -2
- package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
- package/bin/index.d.ts +0 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -4
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/Activation.d.ts +6 -5
- package/bin/plugin/core/Activation.d.ts.map +1 -1
- package/bin/plugin/core/Activation.js +9 -9
- package/bin/plugin/core/Activation.js.map +1 -1
- package/bin/plugin/core/BasePlugin.d.ts +5 -4
- package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
- package/bin/plugin/core/BasePlugin.js +7 -4
- package/bin/plugin/core/BasePlugin.js.map +1 -1
- package/bin/plugin/core/HookRegistry.d.ts +4 -0
- package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
- package/bin/plugin/core/HookRegistry.js +40 -0
- package/bin/plugin/core/HookRegistry.js.map +1 -1
- package/bin/plugin/core/Manager.d.ts +1 -1
- package/bin/plugin/core/Manager.d.ts.map +1 -1
- package/bin/plugin/core/Manager.js +1 -1
- package/bin/plugin/core/Manager.js.map +1 -1
- package/bin/plugin/core/PluginActionRunner.d.ts +13 -7
- package/bin/plugin/core/PluginActionRunner.d.ts.map +1 -1
- package/bin/plugin/core/PluginActionRunner.js +46 -111
- package/bin/plugin/core/PluginActionRunner.js.map +1 -1
- package/bin/plugin/core/PluginCatalog.d.ts +1 -1
- package/bin/plugin/core/PluginCatalog.d.ts.map +1 -1
- package/bin/plugin/core/PluginCatalog.js +1 -21
- package/bin/plugin/core/PluginCatalog.js.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.d.ts +12 -2
- package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +18 -24
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +60 -7
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +269 -42
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/plugin/core/PluginStateController.d.ts +11 -36
- package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
- package/bin/plugin/core/PluginStateController.js +45 -190
- package/bin/plugin/core/PluginStateController.js.map +1 -1
- package/bin/plugin/types/Plugin.d.ts +1 -1
- package/bin/plugin/types/Plugin.d.ts.map +1 -1
- package/bin/plugin/types/PluginState.d.ts +1 -1
- package/bin/plugin/types/PluginState.d.ts.map +1 -1
- package/bin/plugin/types/Plugins.d.ts +12 -12
- package/bin/plugin/types/Plugins.d.ts.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +12 -3
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentRuntimeAssembly.d.ts +1 -1
- package/bin/types/config/AgentProject.d.ts +6 -14
- package/bin/types/config/AgentProject.d.ts.map +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +23 -2
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.d.ts +47 -36
- package/bin/types/plugin/PluginState.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.js +4 -3
- package/bin/types/plugin/PluginState.js.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +3 -3
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/package.json +3 -3
- package/src/agent/local/AgentPluginFactory.ts +8 -8
- package/src/agent/local/AgentRuntimeAssembly.ts +3 -9
- package/src/agent/local/ProjectSetup.ts +1 -8
- package/src/agent/local/services/AgentAssemblyService.ts +13 -23
- package/src/agent/local/services/AgentBackgroundService.ts +5 -6
- package/src/agent/local/services/AgentSessionManager.ts +4 -26
- package/src/config/AgentInitializer.ts +7 -57
- package/src/config/DowncitySchema.ts +3 -4
- package/src/executor/composer/system/default/SystemDomain.ts +1 -2
- 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/index.ts +1 -8
- package/src/plugin/core/Activation.ts +10 -10
- package/src/plugin/core/BasePlugin.ts +9 -6
- package/src/plugin/core/HookRegistry.ts +41 -0
- package/src/plugin/core/Manager.ts +0 -2
- package/src/plugin/core/PluginActionRunner.ts +52 -133
- package/src/plugin/core/PluginCatalog.ts +1 -23
- package/src/plugin/core/PluginLocalExecution.ts +30 -25
- package/src/plugin/core/PluginRegistry.ts +298 -44
- package/src/plugin/core/PluginStateController.ts +45 -235
- package/src/plugin/types/Plugin.ts +2 -1
- package/src/plugin/types/PluginState.ts +2 -1
- package/src/plugin/types/Plugins.ts +12 -12
- package/src/types/agent/AgentOptions.ts +13 -3
- package/src/types/agent/AgentRuntimeAssembly.ts +1 -1
- package/src/types/config/AgentProject.ts +7 -15
- package/src/types/plugin/PluginRuntime.ts +23 -2
- package/src/types/plugin/PluginState.ts +50 -43
- package/src/types/runtime/agent/AgentContext.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/config/Defaults.d.ts +0 -21
- package/bin/config/Defaults.d.ts.map +0 -1
- package/bin/config/Defaults.js +0 -47
- package/bin/config/Defaults.js.map +0 -1
- package/bin/plugin/core/ProjectConfigStore.d.ts +0 -84
- package/bin/plugin/core/ProjectConfigStore.d.ts.map +0 -1
- package/bin/plugin/core/ProjectConfigStore.js +0 -89
- package/bin/plugin/core/ProjectConfigStore.js.map +0 -1
- package/src/config/Defaults.ts +0 -49
- package/src/plugin/core/ProjectConfigStore.ts +0 -155
|
@@ -1,68 +1,79 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Plugin
|
|
2
|
+
* Plugin 注册状态类型。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - Plugin 只属于 Agent:注册即生效,卸载即不可见。
|
|
6
|
+
* - 不再暴露 start / stop / restart 这类生命周期状态。
|
|
7
|
+
* - `error` 只表示最近一次注册后运行发生错误,方便开发者诊断。
|
|
7
8
|
*/
|
|
9
|
+
import type { Plugin } from "../../types/plugin/PluginDefinition.js";
|
|
8
10
|
/**
|
|
9
|
-
* Plugin
|
|
10
|
-
*
|
|
11
|
-
* 说明(中文)
|
|
12
|
-
* - `starting` / `stopping` 仅用于生命周期过渡态。
|
|
13
|
-
* - `error` 表示最近一次 lifecycle / command / action 执行失败后留下的状态标记。
|
|
11
|
+
* Plugin 当前可观察状态。
|
|
14
12
|
*/
|
|
15
|
-
export type PluginState = "
|
|
13
|
+
export type PluginState = "ready" | "error";
|
|
16
14
|
/**
|
|
17
|
-
*
|
|
15
|
+
* 单个已注册 plugin 的运行时记录。
|
|
18
16
|
*/
|
|
19
|
-
export interface
|
|
20
|
-
/**
|
|
17
|
+
export interface PluginRuntimeRecord {
|
|
18
|
+
/** 当前 plugin 实例。 */
|
|
19
|
+
plugin: Plugin;
|
|
20
|
+
/** 当前可观察状态。 */
|
|
21
21
|
state: PluginState;
|
|
22
|
+
/** plugin 注册时间(毫秒时间戳)。 */
|
|
23
|
+
registered_at: number;
|
|
22
24
|
/** 最近一次状态更新时间(毫秒时间戳)。 */
|
|
23
|
-
|
|
25
|
+
updated_at: number;
|
|
24
26
|
/** 最近一次错误信息。 */
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
lastCommand?: string;
|
|
28
|
-
/** 最近一次执行命令的时间(毫秒时间戳)。 */
|
|
29
|
-
lastCommandAt?: number;
|
|
30
|
-
/** 当前串行控制链。 */
|
|
27
|
+
last_error?: string;
|
|
28
|
+
/** 当前串行变更链。 */
|
|
31
29
|
chain: Promise<void>;
|
|
30
|
+
/** lifecycle.start 是否已经执行成功。 */
|
|
31
|
+
lifecycle_started: boolean;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* 单个 plugin
|
|
34
|
+
* 单个 plugin 注册快照。
|
|
35
35
|
*/
|
|
36
|
-
export interface
|
|
36
|
+
export interface PluginSnapshot {
|
|
37
37
|
/** plugin 名称。 */
|
|
38
38
|
name: string;
|
|
39
|
-
/**
|
|
39
|
+
/** plugin 标题。 */
|
|
40
|
+
title: string;
|
|
41
|
+
/** plugin 描述。 */
|
|
42
|
+
description: string;
|
|
43
|
+
/** 当前注册后的可用状态。 */
|
|
44
|
+
status: PluginState;
|
|
45
|
+
/** 兼容旧字段的状态别名。 */
|
|
40
46
|
state: PluginState;
|
|
41
|
-
/**
|
|
47
|
+
/** 注册时间(毫秒时间戳)。 */
|
|
48
|
+
registered_at: number;
|
|
49
|
+
/** 最近更新时间(毫秒时间戳)。 */
|
|
50
|
+
updated_at: number;
|
|
51
|
+
/** 兼容旧字段的最近更新时间。 */
|
|
42
52
|
updatedAt: number;
|
|
43
|
-
/**
|
|
53
|
+
/** 最近错误。 */
|
|
54
|
+
last_error?: string;
|
|
55
|
+
/** 兼容旧字段的最近错误。 */
|
|
44
56
|
lastError?: string;
|
|
45
|
-
/** 最近一次执行的命令名。 */
|
|
46
|
-
lastCommand?: string;
|
|
47
|
-
/** 最近一次执行命令的时间(毫秒时间戳)。 */
|
|
48
|
-
lastCommandAt?: number;
|
|
49
|
-
/** 是否支持主动生命周期。 */
|
|
50
|
-
supportsLifecycle: boolean;
|
|
51
|
-
/** 是否支持 command/action。 */
|
|
52
|
-
supportsCommand: boolean;
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
55
|
-
* plugin
|
|
59
|
+
* 兼容旧名称的 plugin 快照类型。
|
|
60
|
+
*/
|
|
61
|
+
export type PluginStateSnapshot = PluginSnapshot;
|
|
62
|
+
/**
|
|
63
|
+
* 兼容旧控制动作类型。
|
|
64
|
+
*
|
|
65
|
+
* 说明(中文)
|
|
66
|
+
* - 控制面只保留状态查询与卸载。
|
|
56
67
|
*/
|
|
57
|
-
export type PluginStateControlAction = "
|
|
68
|
+
export type PluginStateControlAction = "register" | "unregister" | "status";
|
|
58
69
|
/**
|
|
59
|
-
* plugin
|
|
70
|
+
* plugin 控制结果。
|
|
60
71
|
*/
|
|
61
72
|
export interface PluginStateControlResult {
|
|
62
73
|
/** 控制动作是否成功。 */
|
|
63
74
|
success: boolean;
|
|
64
75
|
/** 成功或失败后返回的最新 plugin 快照。 */
|
|
65
|
-
plugin?:
|
|
76
|
+
plugin?: PluginSnapshot;
|
|
66
77
|
/** 失败时的错误信息。 */
|
|
67
78
|
error?: string;
|
|
68
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginState.d.ts","sourceRoot":"","sources":["../../../src/types/plugin/PluginState.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"PluginState.d.ts","sourceRoot":"","sources":["../../../src/types/plugin/PluginState.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe;IACf,KAAK,EAAE,WAAW,CAAC;IACnB,0BAA0B;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe;IACf,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,gCAAgC;IAChC,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB;IAClB,MAAM,EAAE,WAAW,CAAC;IACpB,kBAAkB;IAClB,KAAK,EAAE,WAAW,CAAC;IACnB,mBAAmB;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,qBAAqB;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,GAChC,UAAU,GACV,YAAY,GACZ,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,gBAAgB;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,gBAAgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Plugin
|
|
2
|
+
* Plugin 注册状态类型。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - Plugin 只属于 Agent:注册即生效,卸载即不可见。
|
|
6
|
+
* - 不再暴露 start / stop / restart 这类生命周期状态。
|
|
7
|
+
* - `error` 只表示最近一次注册后运行发生错误,方便开发者诊断。
|
|
7
8
|
*/
|
|
8
9
|
export {};
|
|
9
10
|
//# sourceMappingURL=PluginState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginState.js","sourceRoot":"","sources":["../../../src/types/plugin/PluginState.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"PluginState.js","sourceRoot":"","sources":["../../../src/types/plugin/PluginState.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -12,7 +12,7 @@ import type { AgentPathRuntime, AgentPluginConfigRuntime } from "../../../types/
|
|
|
12
12
|
import type { DowncityConfig } from "../../../types/config/DowncityConfig.js";
|
|
13
13
|
import type { JsonValue } from "../../../types/common/Json.js";
|
|
14
14
|
import type { AgentPlugins } from "../../../plugin/types/Plugin.js";
|
|
15
|
-
import type {
|
|
15
|
+
import type { Plugin } from "../../../types/plugin/PluginDefinition.js";
|
|
16
16
|
import type { SessionMetadataV1, SessionMessageV1 } from "../../../executor/types/SessionMessages.js";
|
|
17
17
|
import type { SessionRunInput, SessionRunResult } from "../../../executor/types/SessionRun.js";
|
|
18
18
|
import type { SessionHistoryStore } from "../../../executor/store/history/SessionHistoryStore.js";
|
|
@@ -227,7 +227,7 @@ export interface AgentContextOptions {
|
|
|
227
227
|
/** 当前可见的 plugin 配置持久化能力集合。 */
|
|
228
228
|
pluginConfig: AgentPluginConfigRuntime;
|
|
229
229
|
/** 当前 agent 持有的插件实例集合。 */
|
|
230
|
-
pluginInstances: Map<string,
|
|
230
|
+
pluginInstances: Map<string, Plugin>;
|
|
231
231
|
/** Session 能力入口。 */
|
|
232
232
|
session: SessionCollectionPort;
|
|
233
233
|
/** Plugin 调用入口。 */
|
|
@@ -259,7 +259,7 @@ export declare class AgentContext {
|
|
|
259
259
|
/** 当前可见的 plugin 配置持久化能力集合。 */
|
|
260
260
|
readonly pluginConfig: AgentPluginConfigRuntime;
|
|
261
261
|
/** 当前 agent 持有的插件实例集合。 */
|
|
262
|
-
readonly pluginInstances: Map<string,
|
|
262
|
+
readonly pluginInstances: Map<string, Plugin>;
|
|
263
263
|
/** Session 能力入口。 */
|
|
264
264
|
readonly session: SessionCollectionPort;
|
|
265
265
|
/** Plugin 调用入口。 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentContext.d.ts","sourceRoot":"","sources":["../../../../src/types/runtime/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"AgentContext.d.ts","sourceRoot":"","sources":["../../../../src/types/runtime/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iDAAiD,CAAC;AAC3F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACj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AAY,CAAC;IAC/B,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;gBAEtB,OAAO,EAAE,mBAAmB;IAiBxC;;;;;;OAMG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW;IAI1C;;OAEG;IACH,uBAAuB,IAAI,MAAM,EAAE;IAInC;;OAEG;IACH,wBAAwB,IAAI,MAAM;IAIlC;;;;;;OAMG;YACW,oBAAoB;CAmBnC;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;CACtC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentContext.js","sourceRoot":"","sources":["../../../../src/types/runtime/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2PH;;;;;;;GAOG;AACH,MAAM,OAAO,YAAY;IACvB,gBAAgB;IACP,GAAG,CAAS;IACrB,eAAe;IACN,QAAQ,CAAS;IAC1B,aAAa;IACJ,MAAM,CAAS;IACxB,kBAAkB;IACT,MAAM,CAAiB;IAChC,oBAAoB;IACX,GAAG,CAAyB;IACrC,yBAAyB;IAChB,OAAO,CAAW;IAC3B,mBAAmB;IACV,KAAK,CAAmB;IACjC,8BAA8B;IACrB,YAAY,CAA2B;IAChD,0BAA0B;IACjB,eAAe,
|
|
1
|
+
{"version":3,"file":"AgentContext.js","sourceRoot":"","sources":["../../../../src/types/runtime/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2PH;;;;;;;GAOG;AACH,MAAM,OAAO,YAAY;IACvB,gBAAgB;IACP,GAAG,CAAS;IACrB,eAAe;IACN,QAAQ,CAAS;IAC1B,aAAa;IACJ,MAAM,CAAS;IACxB,kBAAkB;IACT,MAAM,CAAiB;IAChC,oBAAoB;IACX,GAAG,CAAyB;IACrC,yBAAyB;IAChB,OAAO,CAAW;IAC3B,mBA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wBAAwB,EAAE,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,oBAAoB,CAChC,MAA0B;QAE1B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YAC1C,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrE,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,OAAO,IAAI,sBAAsB;aAChE,CAAC;QACJ,CAAC;QACD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5D,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@downcity/agent",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.179",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Downcity Agent 运行时 — 单 Agent 执行壳与本机 RPC 能力",
|
|
6
6
|
"main": "./bin/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@ai-sdk/openai-compatible": "^2.0.48",
|
|
20
|
-
"@downcity/shell": "^0.1.
|
|
21
|
-
"@downcity/type": "0.1.
|
|
20
|
+
"@downcity/shell": "^0.1.51",
|
|
21
|
+
"@downcity/type": "0.1.85",
|
|
22
22
|
"ai": "^6.0.193",
|
|
23
23
|
"commander": "^15.0.0",
|
|
24
24
|
"dotenv": "^17.4.2",
|
|
@@ -6,18 +6,19 @@
|
|
|
6
6
|
* - Agent 仍然持有长期状态;这里不创建新的运行时层级。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { Plugin } from "@/types/plugin/PluginDefinition.js";
|
|
10
10
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
11
11
|
import { HookRegistry } from "@/plugin/core/HookRegistry.js";
|
|
12
12
|
import { PluginRegistry } from "@/plugin/core/PluginRegistry.js";
|
|
13
|
-
import { isPluginEnabled } from "@/plugin/core/Activation.js";
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* 创建 plugin registry 的参数。
|
|
17
16
|
*/
|
|
18
17
|
export interface CreateAgentPluginRegistryOptions {
|
|
19
18
|
/** 当前 agent 显式注册的 plugin 实例。 */
|
|
20
|
-
plugins:
|
|
19
|
+
plugins: Plugin[];
|
|
20
|
+
/** 当前 agent plugin 实例集合。 */
|
|
21
|
+
plugin_instances: Map<string, Plugin>;
|
|
21
22
|
/** 延迟读取当前 AgentContext。 */
|
|
22
23
|
get_context: () => AgentContext;
|
|
23
24
|
}
|
|
@@ -32,20 +33,19 @@ export function createAgentPluginRegistry(
|
|
|
32
33
|
const hook_registry = new HookRegistry({
|
|
33
34
|
contextResolver: options.get_context,
|
|
34
35
|
pluginEnabledChecker: (plugin_name) => {
|
|
35
|
-
|
|
36
|
-
return
|
|
37
|
-
? isPluginEnabled({ plugin, context: options.get_context() })
|
|
38
|
-
: false;
|
|
36
|
+
void options;
|
|
37
|
+
return plugin_registry_ref?.isReady(plugin_name) || false;
|
|
39
38
|
},
|
|
40
39
|
});
|
|
41
40
|
const registry = new PluginRegistry({
|
|
42
41
|
contextResolver: options.get_context,
|
|
43
42
|
hookRegistry: hook_registry,
|
|
43
|
+
pluginInstances: options.plugin_instances,
|
|
44
44
|
});
|
|
45
45
|
plugin_registry_ref = registry;
|
|
46
46
|
|
|
47
47
|
for (const plugin of options.plugins) {
|
|
48
|
-
registry.
|
|
48
|
+
registry.mount(plugin);
|
|
49
49
|
}
|
|
50
50
|
return registry;
|
|
51
51
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* - agent runtime 负责创建这些宿主能力对象,再注入到 AgentRuntime。
|
|
6
6
|
* - plugin runtime / session / plugin 作者 API 只消费这些对象,不直接依赖具体宿主实现。
|
|
7
7
|
* - 当前先收敛路径与 plugin 配置持久化两类宿主能力。
|
|
8
|
+
* - SDK 默认不把 plugin 配置写回项目文件;宿主如 CLI 可接管持久化。
|
|
8
9
|
*/
|
|
9
10
|
import {
|
|
10
11
|
getCacheDirPath,
|
|
@@ -18,12 +19,10 @@ import {
|
|
|
18
19
|
getDowncitySessionDirPath,
|
|
19
20
|
getDowncitySessionRootDirPath,
|
|
20
21
|
} from "@/config/Paths.js";
|
|
21
|
-
import { persistProjectPluginConfig } from "@/plugin/core/ProjectConfigStore.js";
|
|
22
22
|
import type {
|
|
23
23
|
AgentPathRuntime,
|
|
24
24
|
AgentPluginConfigRuntime,
|
|
25
25
|
} from "@/types/agent/AgentRuntimeAssembly.js";
|
|
26
|
-
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* 创建当前项目的路径能力集合。
|
|
@@ -57,13 +56,8 @@ export function createAgentPathRuntime(
|
|
|
57
56
|
export function createAgentPluginConfigRuntime(projectRoot: string): AgentPluginConfigRuntime {
|
|
58
57
|
const rootPath = String(projectRoot || "").trim();
|
|
59
58
|
return {
|
|
60
|
-
async persistProjectPlugins(
|
|
61
|
-
return
|
|
62
|
-
projectRoot: rootPath,
|
|
63
|
-
sections: {
|
|
64
|
-
...(plugins !== undefined ? { plugins } : {}),
|
|
65
|
-
},
|
|
66
|
-
});
|
|
59
|
+
async persistProjectPlugins(): Promise<string> {
|
|
60
|
+
return rootPath;
|
|
67
61
|
},
|
|
68
62
|
};
|
|
69
63
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ProjectSetup:本地 Agent 启动前项目结构准备模块。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - 统一校验初始化必要文件(PROFILE.md
|
|
5
|
+
* - 统一校验初始化必要文件(PROFILE.md)。
|
|
6
6
|
* - 统一确保 `.downcity/*` 目录结构存在,避免调用方重复拼装目录逻辑。
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
getDowncityDataDirPath,
|
|
18
18
|
getDowncityDebugDirPath,
|
|
19
19
|
getDowncityDirPath,
|
|
20
|
-
getDowncityJsonPath,
|
|
21
20
|
getDowncityProfileDirPath,
|
|
22
21
|
getDowncityPublicDirPath,
|
|
23
22
|
getDowncityTasksDirPath,
|
|
@@ -35,12 +34,6 @@ function ensureContextFiles(projectRoot: string): void {
|
|
|
35
34
|
process.exit(1);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
if (!fs.existsSync(getDowncityJsonPath(projectRoot))) {
|
|
39
|
-
console.error(
|
|
40
|
-
'❌ downcity.json does not exist. Please run "downcity agent create" first',
|
|
41
|
-
);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
37
|
}
|
|
45
38
|
|
|
46
39
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { LanguageModel, Tool } from "ai";
|
|
11
|
-
import type {
|
|
11
|
+
import type { Plugin } from "@/types/plugin/PluginDefinition.js";
|
|
12
12
|
import { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
13
13
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
14
14
|
import type { AgentPlugins } from "@/plugin/types/Plugin.js";
|
|
@@ -101,7 +101,7 @@ export interface AgentAssemblyResult {
|
|
|
101
101
|
/**
|
|
102
102
|
* 当前 plugin 实例集合。
|
|
103
103
|
*/
|
|
104
|
-
plugin_instances: Map<string,
|
|
104
|
+
plugin_instances: Map<string, Plugin>;
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* 当前 plugin 注册表。
|
|
@@ -165,16 +165,15 @@ export class AgentAssemblyService {
|
|
|
165
165
|
const env = resolveAgentEnv(path, this.options.env);
|
|
166
166
|
const instruction = normalizeInstructionInput(this.options.instruction);
|
|
167
167
|
const config = this.load_config(id, path);
|
|
168
|
-
const plugin_instances = new Map<string,
|
|
169
|
-
|
|
170
|
-
this.register_plugins(plugin_instances, this.options.plugins || []);
|
|
168
|
+
const plugin_instances = new Map<string, Plugin>();
|
|
171
169
|
|
|
172
170
|
// 关键点(中文)
|
|
173
171
|
// - plugin_registry 仍然延迟读取 agent_context(避免循环依赖)。
|
|
174
172
|
// - context 一构造完就赋值,registry 第一次读 get_context 时已经是非空。
|
|
175
173
|
let agent_context: AgentContext | undefined;
|
|
176
174
|
const plugin_registry = createAgentPluginRegistry({
|
|
177
|
-
plugins: [
|
|
175
|
+
plugins: this.options.plugins || [],
|
|
176
|
+
plugin_instances,
|
|
178
177
|
get_context: () => {
|
|
179
178
|
if (!agent_context) {
|
|
180
179
|
throw new Error("AgentContext is not assembled yet");
|
|
@@ -248,6 +247,13 @@ export class AgentAssemblyService {
|
|
|
248
247
|
}
|
|
249
248
|
|
|
250
249
|
private load_config(agent_id: string, project_root: string): DowncityConfig {
|
|
250
|
+
if (this.options.config) {
|
|
251
|
+
return {
|
|
252
|
+
...this.options.config,
|
|
253
|
+
id: String(this.options.config.id || "").trim() || agent_id,
|
|
254
|
+
version: String(this.options.config.version || "").trim() || "1.0.0",
|
|
255
|
+
};
|
|
256
|
+
}
|
|
251
257
|
try {
|
|
252
258
|
return loadDowncityConfig(project_root);
|
|
253
259
|
} catch {
|
|
@@ -255,27 +261,11 @@ export class AgentAssemblyService {
|
|
|
255
261
|
}
|
|
256
262
|
}
|
|
257
263
|
|
|
258
|
-
private register_plugins(
|
|
259
|
-
plugin_instances: Map<string, BasePlugin>,
|
|
260
|
-
plugins: BasePlugin[],
|
|
261
|
-
): void {
|
|
262
|
-
for (const plugin of plugins) {
|
|
263
|
-
const name = String(plugin?.name || "").trim();
|
|
264
|
-
if (!name) {
|
|
265
|
-
throw new Error("Agent received a plugin without a valid name");
|
|
266
|
-
}
|
|
267
|
-
if (plugin_instances.has(name)) {
|
|
268
|
-
throw new Error(`Duplicate plugin registration: ${name}`);
|
|
269
|
-
}
|
|
270
|
-
plugin_instances.set(name, plugin);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
264
|
/**
|
|
275
265
|
* 判断是否需要自动注册 plugin_call tool。
|
|
276
266
|
*/
|
|
277
267
|
private should_register_plugin_call_tool(
|
|
278
|
-
plugin_instances: Map<string,
|
|
268
|
+
plugin_instances: Map<string, Plugin>,
|
|
279
269
|
): boolean {
|
|
280
270
|
for (const plugin of plugin_instances.values()) {
|
|
281
271
|
if (
|
|
@@ -11,7 +11,6 @@ import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
|
11
11
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
12
12
|
import type { ActionScheduleRuntimeHandle } from "@/plugin/core/ActionScheduleRuntime.js";
|
|
13
13
|
import { startActionScheduleRuntime } from "@/plugin/core/ActionScheduleRuntime.js";
|
|
14
|
-
import { startAllPlugins, stopAllPlugins } from "@/plugin/core/Manager.js";
|
|
15
14
|
import type { Shell } from "@downcity/shell";
|
|
16
15
|
|
|
17
16
|
type AgentBackgroundServiceOptions = {
|
|
@@ -73,7 +72,7 @@ export class AgentBackgroundService {
|
|
|
73
72
|
}
|
|
74
73
|
if (this.plugins_started) {
|
|
75
74
|
await this.stop_action_schedule_runtime();
|
|
76
|
-
await
|
|
75
|
+
await this.agent_context.plugins.unregisterAll();
|
|
77
76
|
this.plugins_started = false;
|
|
78
77
|
}
|
|
79
78
|
await this.get_shell?.()?.dispose();
|
|
@@ -85,12 +84,12 @@ export class AgentBackgroundService {
|
|
|
85
84
|
|
|
86
85
|
private async ensure_plugins_started(): Promise<void> {
|
|
87
86
|
if (this.plugins_started) return;
|
|
88
|
-
const
|
|
87
|
+
const snapshots = await this.agent_context.plugins.startAll();
|
|
89
88
|
this.plugins_started = true;
|
|
90
|
-
for (const item of
|
|
91
|
-
if (
|
|
89
|
+
for (const item of snapshots) {
|
|
90
|
+
if (item.status === "error") {
|
|
92
91
|
this.logger.error(
|
|
93
|
-
`Plugin start failed: ${item.
|
|
92
|
+
`Plugin start failed: ${item.name} - ${item.last_error || "unknown error"}`,
|
|
94
93
|
);
|
|
95
94
|
}
|
|
96
95
|
}
|
|
@@ -37,8 +37,7 @@ import {
|
|
|
37
37
|
} from "@/session/index.js";
|
|
38
38
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
39
39
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
40
|
-
import type {
|
|
41
|
-
import { isPluginEnabled } from "@/plugin/core/Activation.js";
|
|
40
|
+
import type { Plugin } from "@/types/plugin/PluginDefinition.js";
|
|
42
41
|
import { createInstructionSystemBlocks } from "@/agent/local/AgentInstructions.js";
|
|
43
42
|
|
|
44
43
|
function decodeMaybe(input: string): string {
|
|
@@ -86,7 +85,7 @@ type AgentSessionManagerOptions = {
|
|
|
86
85
|
/**
|
|
87
86
|
* 当前 plugin 实例集合。
|
|
88
87
|
*/
|
|
89
|
-
plugin_instances: Map<string,
|
|
88
|
+
plugin_instances: Map<string, Plugin>;
|
|
90
89
|
|
|
91
90
|
/**
|
|
92
91
|
* 当前默认模型实例。
|
|
@@ -109,7 +108,7 @@ export class AgentSessionManager {
|
|
|
109
108
|
private readonly logger: Logger;
|
|
110
109
|
private readonly get_agent_context: AgentSessionManagerOptions["get_agent_context"];
|
|
111
110
|
private readonly get_instruction: AgentSessionManagerOptions["get_instruction"];
|
|
112
|
-
private readonly plugin_instances: Map<string,
|
|
111
|
+
private readonly plugin_instances: Map<string, Plugin>;
|
|
113
112
|
private readonly default_model?: AgentModel;
|
|
114
113
|
private readonly SessionClass: AgentSessionConstructor;
|
|
115
114
|
private readonly sessions_by_id = new Map<string, AgentManagedSession>();
|
|
@@ -378,27 +377,6 @@ export class AgentSessionManager {
|
|
|
378
377
|
}
|
|
379
378
|
|
|
380
379
|
private async load_plugin_system_blocks(): Promise<AgentSessionSystemBlock[]> {
|
|
381
|
-
|
|
382
|
-
const out: AgentSessionSystemBlock[] = [];
|
|
383
|
-
for (const plugin of this.plugin_instances.values()) {
|
|
384
|
-
if (typeof plugin.system !== "function") continue;
|
|
385
|
-
try {
|
|
386
|
-
if (!isPluginEnabled({ plugin, context })) continue;
|
|
387
|
-
if (typeof plugin.availability === "function") {
|
|
388
|
-
const availability = await plugin.availability(context);
|
|
389
|
-
if (!availability.available) continue;
|
|
390
|
-
}
|
|
391
|
-
const text = String(await plugin.system(context)).trim();
|
|
392
|
-
if (!text) continue;
|
|
393
|
-
out.push({
|
|
394
|
-
source: "plugin",
|
|
395
|
-
name: plugin.name,
|
|
396
|
-
content: text,
|
|
397
|
-
});
|
|
398
|
-
} catch {
|
|
399
|
-
// 单个 plugin system 失败不应阻断 SDK session 主链路。
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return out;
|
|
380
|
+
return await this.get_agent_context().plugins.systemBlocks();
|
|
403
381
|
}
|
|
404
382
|
}
|