@downcity/agent 1.1.126 → 1.1.135
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/Agent.d.ts +38 -6
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +62 -11
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/AgentRuntimeFactory.d.ts +9 -34
- package/bin/agent/local/AgentRuntimeFactory.d.ts.map +1 -1
- package/bin/agent/local/AgentRuntimeFactory.js +2 -41
- package/bin/agent/local/AgentRuntimeFactory.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +28 -9
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentBackgroundService.d.ts +55 -0
- package/bin/agent/local/services/AgentBackgroundService.d.ts.map +1 -0
- package/bin/agent/local/services/AgentBackgroundService.js +86 -0
- package/bin/agent/local/services/AgentBackgroundService.js.map +1 -0
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +8 -0
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +22 -0
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/index.d.ts +3 -3
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -2
- package/bin/index.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +1 -7
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +0 -63
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +1 -1
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +66 -42
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js +77 -3
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/package.json +3 -3
- package/src/agent/local/Agent.ts +63 -14
- package/src/agent/local/AgentRuntimeFactory.ts +9 -83
- package/src/agent/local/services/AgentAssemblyService.ts +30 -13
- package/src/agent/local/services/AgentBackgroundService.ts +116 -0
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +22 -0
- package/src/index.ts +2 -9
- package/src/session/services/SessionViewService.ts +1 -7
- package/src/types/agent/AgentOptions.ts +0 -69
- package/src/types/agent/AgentTypes.ts +0 -5
- package/src/types/runtime/agent/AgentContext.ts +103 -43
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/agent/local/services/AgentLifecycleService.d.ts +0 -65
- package/bin/agent/local/services/AgentLifecycleService.d.ts.map +0 -1
- package/bin/agent/local/services/AgentLifecycleService.js +0 -140
- package/bin/agent/local/services/AgentLifecycleService.js.map +0 -1
- package/bin/rpc/Server.d.ts +0 -31
- package/bin/rpc/Server.d.ts.map +0 -1
- package/bin/rpc/Server.js +0 -106
- package/bin/rpc/Server.js.map +0 -1
- package/bin/rpc/server/InternalHandlers.d.ts +0 -21
- package/bin/rpc/server/InternalHandlers.d.ts.map +0 -1
- package/bin/rpc/server/InternalHandlers.js +0 -244
- package/bin/rpc/server/InternalHandlers.js.map +0 -1
- package/bin/rpc/server/RequestDispatcher.d.ts +0 -27
- package/bin/rpc/server/RequestDispatcher.d.ts.map +0 -1
- package/bin/rpc/server/RequestDispatcher.js +0 -38
- package/bin/rpc/server/RequestDispatcher.js.map +0 -1
- package/bin/rpc/server/SdkSessionHandlers.d.ts +0 -25
- package/bin/rpc/server/SdkSessionHandlers.d.ts.map +0 -1
- package/bin/rpc/server/SdkSessionHandlers.js +0 -86
- package/bin/rpc/server/SdkSessionHandlers.js.map +0 -1
- package/bin/rpc/server/ServerTypes.d.ts +0 -64
- package/bin/rpc/server/ServerTypes.d.ts.map +0 -1
- package/bin/rpc/server/ServerTypes.js +0 -9
- package/bin/rpc/server/ServerTypes.js.map +0 -1
- package/src/agent/local/services/AgentLifecycleService.ts +0 -198
- package/src/rpc/Server.ts +0 -143
- package/src/rpc/server/InternalHandlers.ts +0 -285
- package/src/rpc/server/RequestDispatcher.ts +0 -67
- package/src/rpc/server/SdkSessionHandlers.ts +0 -106
- package/src/rpc/server/ServerTypes.ts +0 -70
|
@@ -10,7 +10,6 @@ import type { Tool } from "ai";
|
|
|
10
10
|
import type { Shell } from "@downcity/shell";
|
|
11
11
|
import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
|
|
12
12
|
import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
13
|
-
import type { RpcServerInstance } from "@/rpc/Server.js";
|
|
14
13
|
import type {
|
|
15
14
|
AgentManagedSession,
|
|
16
15
|
SessionOptions,
|
|
@@ -112,71 +111,3 @@ export interface AgentOptions {
|
|
|
112
111
|
*/
|
|
113
112
|
env?: Record<string, string>;
|
|
114
113
|
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Agent 启动参数。
|
|
118
|
-
*/
|
|
119
|
-
export interface AgentStartOptions {
|
|
120
|
-
/**
|
|
121
|
-
* 是否启动本机 RPC 服务。
|
|
122
|
-
*
|
|
123
|
-
* 关键点(中文)
|
|
124
|
-
* - `false` 表示不启动。
|
|
125
|
-
* - 传对象时会按给定 host/port 启动。
|
|
126
|
-
* - 省略时默认不启动,避免 SDK 本地嵌入场景误开端口。
|
|
127
|
-
*/
|
|
128
|
-
rpc?: false | AgentRpcStartOptions;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* 是否启动当前 agent 的 plugins。
|
|
132
|
-
*
|
|
133
|
-
* 关键点(中文)
|
|
134
|
-
* - 默认 `true`。
|
|
135
|
-
* - `false` 适合只需要 session 能力、不希望启动后台能力的嵌入场景。
|
|
136
|
-
*/
|
|
137
|
-
plugins?: boolean;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Agent 停止结果快照。
|
|
142
|
-
*/
|
|
143
|
-
export interface AgentStopResult {
|
|
144
|
-
/** 本次是否实际停止了本机 RPC 服务。 */
|
|
145
|
-
rpcStopped: boolean;
|
|
146
|
-
/** 本次是否实际停止了 plugins。 */
|
|
147
|
-
pluginsStopped: boolean;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Agent 启动后的状态快照。
|
|
152
|
-
*/
|
|
153
|
-
export interface AgentStartResult {
|
|
154
|
-
/** 当前 agent 是否已启动本机 RPC 服务。 */
|
|
155
|
-
rpc?: AgentRpcBinding;
|
|
156
|
-
/** 当前 agent 是否已启动 plugins。 */
|
|
157
|
-
pluginsStarted: boolean;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Agent RPC 启动参数。
|
|
162
|
-
*/
|
|
163
|
-
export interface AgentRpcStartOptions {
|
|
164
|
-
/** RPC 监听主机。 */
|
|
165
|
-
host?: string;
|
|
166
|
-
/** RPC 监听端口。 */
|
|
167
|
-
port?: number;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Agent RPC 绑定信息。
|
|
172
|
-
*/
|
|
173
|
-
export interface AgentRpcBinding {
|
|
174
|
-
/** 远程访问地址。 */
|
|
175
|
-
url: string;
|
|
176
|
-
/** 当前 host。 */
|
|
177
|
-
host: string;
|
|
178
|
-
/** 当前 port。 */
|
|
179
|
-
port: number;
|
|
180
|
-
/** RPC server 句柄。 */
|
|
181
|
-
server: RpcServerInstance;
|
|
182
|
-
}
|
|
@@ -19,12 +19,7 @@ export type {
|
|
|
19
19
|
} from "@/types/session/SessionOptions.js";
|
|
20
20
|
export type {
|
|
21
21
|
AgentOptions,
|
|
22
|
-
AgentRpcBinding,
|
|
23
|
-
AgentRpcStartOptions,
|
|
24
22
|
AgentSessionConstructor,
|
|
25
|
-
AgentStartOptions,
|
|
26
|
-
AgentStartResult,
|
|
27
|
-
AgentStopResult,
|
|
28
23
|
} from "@/types/agent/AgentOptions.js";
|
|
29
24
|
export type { RemoteAgentOptions } from "@/types/agent/RemoteAgentOptions.js";
|
|
30
25
|
export type {
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
5
|
* - 这里定义 plugin runtime、plugin、prompt system 共用的统一执行上下文。
|
|
6
|
-
* - `AgentContext`
|
|
6
|
+
* - `AgentContext` 是一个 class,表达“当前一次执行可见的能力面”,不是宿主状态本体。
|
|
7
|
+
* - 同一 agent 实例全程共享同一个 context;plugin、session、executor 都基于它读写状态。
|
|
7
8
|
*
|
|
8
9
|
* 边界说明(中文)
|
|
9
10
|
* - `AgentRuntime` 负责保存长期状态;`AgentContext` 负责把这些状态暴露成执行接口。
|
|
10
|
-
* -
|
|
11
|
+
* - 这里同时声明类型协议与默认实现;plugin 作者拿到的就是这个 class 的实例。
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import type { LanguageModel } from "ai";
|
|
@@ -18,7 +19,7 @@ import type {
|
|
|
18
19
|
AgentPluginConfigRuntime,
|
|
19
20
|
} from "@/types/agent/AgentRuntimeAssembly.js";
|
|
20
21
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
21
|
-
import type {
|
|
22
|
+
import type { JsonValue } from "@/types/common/Json.js";
|
|
22
23
|
import type { AgentPlugins } from "@/plugin/types/Plugin.js";
|
|
23
24
|
import type {
|
|
24
25
|
SessionMetadataV1,
|
|
@@ -216,61 +217,120 @@ export interface SessionCollectionPort {
|
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
/**
|
|
219
|
-
*
|
|
220
|
+
* AgentContext 构造参数。
|
|
221
|
+
*
|
|
222
|
+
* 关键点(中文)
|
|
223
|
+
* - 装配方负责把 runtime / session / plugins 等上层依赖注入进来。
|
|
224
|
+
* - `env` 必须传入 agent 持有的 mutable 共享对象引用,不要在这里克隆。
|
|
220
225
|
*/
|
|
221
|
-
export interface
|
|
222
|
-
/**
|
|
223
|
-
* 当前执行上下文对应的 agent 状态。
|
|
224
|
-
*/
|
|
226
|
+
export interface AgentContextOptions {
|
|
227
|
+
/** 当前执行上下文对应的 agent 状态。 */
|
|
225
228
|
agent: AgentRuntime;
|
|
226
|
-
/**
|
|
227
|
-
* 当前命令工作目录。
|
|
228
|
-
*/
|
|
229
|
+
/** 当前命令工作目录。 */
|
|
229
230
|
cwd: string;
|
|
230
|
-
/**
|
|
231
|
-
* 当前项目根目录。
|
|
232
|
-
*/
|
|
231
|
+
/** 当前项目根目录。 */
|
|
233
232
|
rootPath: string;
|
|
234
|
-
/**
|
|
235
|
-
* 统一日志器。
|
|
236
|
-
*/
|
|
233
|
+
/** 统一日志器。 */
|
|
237
234
|
logger: Logger;
|
|
238
|
-
/**
|
|
239
|
-
* 当前运行时已解析配置。
|
|
240
|
-
*/
|
|
235
|
+
/** 当前运行时已解析配置。 */
|
|
241
236
|
config: DowncityConfig;
|
|
242
237
|
/**
|
|
243
|
-
*
|
|
238
|
+
* 当前 agent env 共享对象引用。
|
|
239
|
+
*
|
|
240
|
+
* 关键点(中文)
|
|
241
|
+
* - 必须是 Agent 持有的同一个 mutable 引用,不要克隆后再传入。
|
|
242
|
+
* - 通过 `agent.setEnv` / `agent.patchEnv` 原地更新会被本 context 立即感知。
|
|
244
243
|
*/
|
|
245
244
|
env: Record<string, string>;
|
|
246
|
-
/**
|
|
247
|
-
* 当前生效的 system 文本集合。
|
|
248
|
-
*/
|
|
245
|
+
/** 当前生效的 system 文本集合。 */
|
|
249
246
|
systems: string[];
|
|
250
|
-
/**
|
|
251
|
-
* 当前可见的路径能力集合。
|
|
252
|
-
*/
|
|
247
|
+
/** 当前可见的路径能力集合。 */
|
|
253
248
|
paths: AgentPathRuntime;
|
|
254
|
-
/**
|
|
255
|
-
* 当前可见的 plugin 配置持久化能力集合。
|
|
256
|
-
*/
|
|
249
|
+
/** 当前可见的 plugin 配置持久化能力集合。 */
|
|
257
250
|
pluginConfig: AgentPluginConfigRuntime;
|
|
251
|
+
/** Session 能力入口。 */
|
|
252
|
+
session: SessionCollectionPort;
|
|
253
|
+
/** Plugin 调用入口。 */
|
|
254
|
+
plugins: AgentPlugins;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 统一执行上下文。
|
|
259
|
+
*
|
|
260
|
+
* 关键点(中文)
|
|
261
|
+
* - 字段全部 readonly,构造一次后语义稳定,避免 plugin 误改。
|
|
262
|
+
* - `env` 引用 agent 级共享 mutable 对象,`...ctx.env` / `ctx.env.FOO` 直接可用。
|
|
263
|
+
* - `invoke` 是构造期组装的 plugin 调用端口,对外仍以 `InvokePluginPort` 形态暴露。
|
|
264
|
+
*/
|
|
265
|
+
export class AgentContext {
|
|
266
|
+
/** 当前执行上下文对应的 agent 状态。 */
|
|
267
|
+
readonly agent: AgentRuntime;
|
|
268
|
+
/** 当前命令工作目录。 */
|
|
269
|
+
readonly cwd: string;
|
|
270
|
+
/** 当前项目根目录。 */
|
|
271
|
+
readonly rootPath: string;
|
|
272
|
+
/** 统一日志器。 */
|
|
273
|
+
readonly logger: Logger;
|
|
274
|
+
/** 当前运行时已解析配置。 */
|
|
275
|
+
readonly config: DowncityConfig;
|
|
276
|
+
/** 当前项目环境变量共享视图。 */
|
|
277
|
+
readonly env: Record<string, string>;
|
|
278
|
+
/** 当前生效的 system 文本集合。 */
|
|
279
|
+
readonly systems: string[];
|
|
280
|
+
/** 当前可见的路径能力集合。 */
|
|
281
|
+
readonly paths: AgentPathRuntime;
|
|
282
|
+
/** 当前可见的 plugin 配置持久化能力集合。 */
|
|
283
|
+
readonly pluginConfig: AgentPluginConfigRuntime;
|
|
284
|
+
/** Session 能力入口。 */
|
|
285
|
+
readonly session: SessionCollectionPort;
|
|
286
|
+
/** Plugin 调用入口。 */
|
|
287
|
+
readonly plugins: AgentPlugins;
|
|
288
|
+
/** 跨 plugin runtime 调用主入口。 */
|
|
289
|
+
readonly invoke: InvokePluginPort;
|
|
290
|
+
|
|
291
|
+
constructor(options: AgentContextOptions) {
|
|
292
|
+
this.agent = options.agent;
|
|
293
|
+
this.cwd = options.cwd;
|
|
294
|
+
this.rootPath = options.rootPath;
|
|
295
|
+
this.logger = options.logger;
|
|
296
|
+
this.config = options.config;
|
|
297
|
+
this.env = options.env;
|
|
298
|
+
this.systems = options.systems;
|
|
299
|
+
this.paths = options.paths;
|
|
300
|
+
this.pluginConfig = options.pluginConfig;
|
|
301
|
+
this.session = options.session;
|
|
302
|
+
this.plugins = options.plugins;
|
|
303
|
+
this.invoke = {
|
|
304
|
+
invoke: (params) => this.invoke_plugin_action(params),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
258
308
|
/**
|
|
259
|
-
*
|
|
309
|
+
* 跨 plugin runtime 调用 action 的内部实现。
|
|
260
310
|
*
|
|
261
311
|
* 关键点(中文)
|
|
262
|
-
* -
|
|
263
|
-
* -
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
312
|
+
* - 统一把 `runAction` 的成功/失败结果归一化为 `InvokePluginResult`。
|
|
313
|
+
* - 这里替代了原 `createAgentContext` 工厂里的胶水匿名函数。
|
|
314
|
+
*/
|
|
315
|
+
private async invoke_plugin_action(
|
|
316
|
+
params: InvokePluginParams,
|
|
317
|
+
): Promise<InvokePluginResult> {
|
|
318
|
+
const result = await this.plugins.runAction({
|
|
319
|
+
plugin: params.plugin,
|
|
320
|
+
action: params.action,
|
|
321
|
+
...(params.payload !== undefined ? { payload: params.payload } : {}),
|
|
322
|
+
});
|
|
323
|
+
if (!result.success) {
|
|
324
|
+
return {
|
|
325
|
+
success: false,
|
|
326
|
+
error: result.error || result.message || "plugin action failed",
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
success: true,
|
|
331
|
+
...(result.data !== undefined ? { data: result.data } : {}),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
274
334
|
}
|
|
275
335
|
|
|
276
336
|
/**
|