@downcity/agent 1.1.135 → 1.1.148
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/README.md +2 -2
- package/bin/agent/local/Agent.d.ts +3 -21
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +3 -30
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/ProjectSetup.js +2 -2
- package/bin/agent/local/ProjectSetup.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +1 -6
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +13 -20
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentSessionManager.d.ts +16 -7
- package/bin/agent/local/services/AgentSessionManager.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessionManager.js +83 -8
- package/bin/agent/local/services/AgentSessionManager.js.map +1 -1
- package/bin/agent/remote/RemoteAgent.d.ts +9 -13
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +23 -24
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +11 -4
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +15 -3
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +9 -1
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +7 -3
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +65 -2
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +5 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +12 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/config/AgentInitializer.d.ts +2 -2
- package/bin/config/AgentInitializer.js +2 -2
- package/bin/executor/Executor.d.ts +5 -0
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +34 -0
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/default/InitPrompts.d.ts +1 -1
- package/bin/executor/composer/system/default/InitPrompts.js +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +2 -2
- package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +16 -0
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.d.ts +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.js +1 -1
- package/bin/executor/types/SessionExecutor.d.ts +8 -0
- package/bin/executor/types/SessionExecutor.d.ts.map +1 -1
- package/bin/index.d.ts +2 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/Activation.d.ts +0 -2
- package/bin/plugin/core/Activation.d.ts.map +1 -1
- package/bin/plugin/core/Activation.js +1 -1
- package/bin/plugin/core/Activation.js.map +1 -1
- package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
- package/bin/plugin/core/PluginCommandRequest.js +1 -1
- package/bin/plugin/core/PluginStateController.d.ts +0 -5
- package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
- package/bin/plugin/core/PluginStateController.js +1 -5
- package/bin/plugin/core/PluginStateController.js.map +1 -1
- package/bin/plugin/types/PluginApi.d.ts +1 -1
- package/bin/plugin/types/PluginApi.js +1 -1
- package/bin/rpc/Client.d.ts +17 -1
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +47 -0
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +5 -0
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +7 -0
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +9 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +81 -3
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +3 -3
- package/bin/session/index.d.ts.map +1 -1
- package/bin/session/index.js +3 -3
- package/bin/session/index.js.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +13 -0
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +82 -5
- package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
- package/bin/session/services/SessionTurnService.d.ts +5 -0
- package/bin/session/services/SessionTurnService.d.ts.map +1 -1
- package/bin/session/services/SessionTurnService.js +10 -1
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +15 -0
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +15 -1
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +24 -0
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +34 -0
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +5 -0
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +4 -0
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +2 -1
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +13 -4
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +62 -0
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +8 -0
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
- package/bin/types/platform/Store.d.ts +2 -2
- package/bin/types/platform/Store.js +2 -2
- package/bin/types/rpc/RpcProtocol.d.ts +37 -5
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.js +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +36 -11
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js +26 -8
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/runtime/platform/Platform.d.ts +8 -8
- package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
- package/bin/types/sdk/AgentSessionStop.d.ts +36 -0
- package/bin/types/sdk/AgentSessionStop.d.ts.map +1 -0
- package/bin/types/sdk/AgentSessionStop.js +9 -0
- package/bin/types/sdk/AgentSessionStop.js.map +1 -0
- package/package.json +3 -3
- package/scripts/city-model-tool-loop.test.mjs +2 -2
- package/scripts/session-prompt-runtime.test.mjs +59 -0
- package/src/agent/local/Agent.ts +3 -41
- package/src/agent/local/ProjectSetup.ts +2 -2
- package/src/agent/local/services/AgentAssemblyService.ts +17 -28
- package/src/agent/local/services/AgentSessionManager.ts +127 -13
- package/src/agent/remote/RemoteAgent.ts +25 -34
- package/src/agent/remote/RemoteSession.ts +21 -6
- package/src/agent/remote/RemoteTransport.ts +14 -0
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +100 -2
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +26 -0
- package/src/config/AgentInitializer.ts +2 -2
- package/src/executor/Executor.ts +33 -0
- package/src/executor/composer/system/default/InitPrompts.ts +1 -1
- package/src/executor/composer/system/default/SystemDomain.ts +2 -2
- package/src/executor/core-engine/CoreEngineRunner.ts +21 -0
- package/src/executor/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/executor/types/SessionExecutor.ts +2 -1
- package/src/index.ts +6 -1
- package/src/plugin/core/Activation.ts +1 -3
- package/src/plugin/core/PluginCommandRequest.ts +1 -1
- package/src/plugin/core/PluginStateController.ts +1 -10
- package/src/plugin/types/PluginApi.ts +1 -1
- package/src/rpc/Client.ts +61 -0
- package/src/session/Session.ts +9 -0
- package/src/session/browse/Browse.ts +103 -3
- package/src/session/index.ts +7 -0
- package/src/session/runtime/SessionPromptRuntime.ts +100 -5
- package/src/session/services/SessionTurnService.ts +13 -1
- package/src/session/storage/Metadata.ts +23 -1
- package/src/session/storage/Paths.ts +70 -0
- package/src/session/storage/RuntimeSessionPort.ts +9 -0
- package/src/types/agent/AgentTypes.ts +6 -0
- package/src/types/agent/SessionActor.ts +21 -3
- package/src/types/agent/SessionTypes.ts +68 -0
- package/src/types/config/DowncityConfig.ts +1 -1
- package/src/types/executor/SessionRunContext.ts +9 -0
- package/src/types/platform/Store.ts +2 -2
- package/src/types/rpc/RpcProtocol.ts +46 -4
- package/src/types/runtime/agent/AgentContext.ts +41 -14
- package/src/types/runtime/platform/Platform.ts +8 -8
- package/src/types/runtime/platform/PlatformGateway.ts +2 -2
- package/src/types/sdk/AgentSessionStop.ts +39 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/agent/local/AgentRuntimeFactory.d.ts +0 -47
- package/bin/agent/local/AgentRuntimeFactory.d.ts.map +0 -1
- package/bin/agent/local/AgentRuntimeFactory.js +0 -34
- package/bin/agent/local/AgentRuntimeFactory.js.map +0 -1
- package/bin/types/runtime/agent/AgentRuntime.d.ts +0 -79
- package/bin/types/runtime/agent/AgentRuntime.d.ts.map +0 -1
- package/bin/types/runtime/agent/AgentRuntime.js +0 -13
- package/bin/types/runtime/agent/AgentRuntime.js.map +0 -1
- package/src/agent/local/AgentRuntimeFactory.ts +0 -78
- package/src/types/runtime/agent/AgentRuntime.ts +0 -84
|
@@ -333,3 +333,71 @@ export interface AgentSessionForkInput {
|
|
|
333
333
|
*/
|
|
334
334
|
messageId?: string;
|
|
335
335
|
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* 归档单个 session 的输入参数。
|
|
339
|
+
*/
|
|
340
|
+
export interface AgentArchiveSessionInput {
|
|
341
|
+
/**
|
|
342
|
+
* 要归档的 session id。
|
|
343
|
+
*
|
|
344
|
+
* 关键点(中文)
|
|
345
|
+
* - 必须指向当前 agent 下已存在的未归档 session。
|
|
346
|
+
* - 正在执行中的 session 不允许归档。
|
|
347
|
+
*/
|
|
348
|
+
id: string;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* 列出已归档 session 的输入参数。
|
|
353
|
+
*/
|
|
354
|
+
export interface AgentArchiveSessionsInput {
|
|
355
|
+
/**
|
|
356
|
+
* 当前页返回上限。
|
|
357
|
+
*
|
|
358
|
+
* 说明(中文)
|
|
359
|
+
* - 省略时由 SDK 使用默认值。
|
|
360
|
+
*/
|
|
361
|
+
limit?: number;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 分页游标。
|
|
365
|
+
*
|
|
366
|
+
* 说明(中文)
|
|
367
|
+
* - 当前使用 SDK 自身生成的透明字符串游标。
|
|
368
|
+
* - 调用方只负责透传,不应自行解析其内部格式。
|
|
369
|
+
*/
|
|
370
|
+
cursor?: string;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 关键词过滤。
|
|
374
|
+
*
|
|
375
|
+
* 说明(中文)
|
|
376
|
+
* - 推荐用于匹配 `sessionId`、标题与预览文本。
|
|
377
|
+
* - 属于轻量包含匹配,不承诺复杂搜索语义。
|
|
378
|
+
*/
|
|
379
|
+
query?: string;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* 归档单个 session 的结果。
|
|
384
|
+
*/
|
|
385
|
+
export interface AgentArchiveSessionResult {
|
|
386
|
+
/** 被归档的 session id。 */
|
|
387
|
+
sessionId: string;
|
|
388
|
+
/** 归档时间戳(ms)。 */
|
|
389
|
+
archivedAt: number;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 列出已归档 session 的结果。
|
|
394
|
+
*/
|
|
395
|
+
export interface AgentArchiveSessionsResult extends AgentSessionSummaryPage {}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 清空归档目录的结果。
|
|
399
|
+
*/
|
|
400
|
+
export interface AgentCleanArchiveResult {
|
|
401
|
+
/** 被永久删除的归档 session id 列表。 */
|
|
402
|
+
removedSessionIds: string[];
|
|
403
|
+
}
|
|
@@ -135,7 +135,7 @@ export interface DowncityConfig {
|
|
|
135
135
|
id: string;
|
|
136
136
|
version: string;
|
|
137
137
|
/**
|
|
138
|
-
* Runtime startup configuration used by `
|
|
138
|
+
* Runtime startup configuration used by `downcity agent start`.
|
|
139
139
|
* CLI flags (if provided) take precedence over this config.
|
|
140
140
|
*/
|
|
141
141
|
start?: {
|
|
@@ -66,6 +66,15 @@ export interface SessionRunContext {
|
|
|
66
66
|
*/
|
|
67
67
|
onUiMessageChunkCallback?: SessionUiMessageChunkCallback;
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* 当前 turn 的取消信号。
|
|
71
|
+
*
|
|
72
|
+
* 关键点(中文)
|
|
73
|
+
* - `session.stop()` 会触发该 signal。
|
|
74
|
+
* - 模型流、tool-loop 与长耗时 composer 应优先监听它,尽快结束当前 turn。
|
|
75
|
+
*/
|
|
76
|
+
abortSignal?: AbortSignal;
|
|
77
|
+
|
|
69
78
|
/**
|
|
70
79
|
* 本轮运行中待并入下一 step 的 user 消息。
|
|
71
80
|
*
|
|
@@ -4,13 +4,19 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 该文件只描述本机 RPC 的线协议,不包含 socket 或业务执行逻辑。
|
|
6
6
|
* - Client 与 Server 共享同一份 request/frame 类型,避免协议两边漂移。
|
|
7
|
-
* - 字段名保持现有协议格式,兼容已发布的
|
|
7
|
+
* - 字段名保持现有协议格式,兼容已发布的 downcity 托管 runtime 调用。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type {
|
|
11
11
|
AgentCreateSessionInput,
|
|
12
12
|
AgentListSessionsInput,
|
|
13
|
+
AgentArchiveSessionInput,
|
|
14
|
+
AgentArchiveSessionsInput,
|
|
15
|
+
AgentArchiveSessionResult,
|
|
16
|
+
AgentArchiveSessionsResult,
|
|
17
|
+
AgentCleanArchiveResult,
|
|
13
18
|
AgentSessionHistoryInput,
|
|
19
|
+
AgentSessionStopResult,
|
|
14
20
|
AgentSessionSystemSnapshot,
|
|
15
21
|
} from "@/types/agent/AgentTypes.js";
|
|
16
22
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
@@ -24,13 +30,13 @@ import type { ShellApprovalMode } from "@downcity/shell";
|
|
|
24
30
|
*
|
|
25
31
|
* 关键点(中文)
|
|
26
32
|
* - `sdk.*` 面向 RemoteAgent 的稳定会话 SDK。
|
|
27
|
-
* - `internal.*` 面向
|
|
33
|
+
* - `internal.*` 面向 downcity 本机管理通道。
|
|
28
34
|
*/
|
|
29
35
|
export type RpcRequest =
|
|
30
36
|
| {
|
|
31
37
|
/** 请求 id,用于匹配响应。 */
|
|
32
38
|
id: string;
|
|
33
|
-
/** 列出
|
|
39
|
+
/** 列出 sessions。 */
|
|
34
40
|
method: "sdk.sessions.list";
|
|
35
41
|
/** 列表过滤与分页参数。 */
|
|
36
42
|
params?: AgentListSessionsInput;
|
|
@@ -46,7 +52,7 @@ export type RpcRequest =
|
|
|
46
52
|
| {
|
|
47
53
|
/** 请求 id,用于匹配响应。 */
|
|
48
54
|
id: string;
|
|
49
|
-
/**
|
|
55
|
+
/** 获取 session。 */
|
|
50
56
|
method: "sdk.sessions.get";
|
|
51
57
|
/** 目标 session 参数。 */
|
|
52
58
|
params: {
|
|
@@ -54,6 +60,31 @@ export type RpcRequest =
|
|
|
54
60
|
sessionId: string;
|
|
55
61
|
};
|
|
56
62
|
}
|
|
63
|
+
| {
|
|
64
|
+
/** 请求 id,用于匹配响应。 */
|
|
65
|
+
id: string;
|
|
66
|
+
/** 归档 session。 */
|
|
67
|
+
method: "sdk.sessions.archive";
|
|
68
|
+
/** 归档参数。 */
|
|
69
|
+
params: {
|
|
70
|
+
/** 目标 session id。 */
|
|
71
|
+
sessionId: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
| {
|
|
75
|
+
/** 请求 id,用于匹配响应。 */
|
|
76
|
+
id: string;
|
|
77
|
+
/** 列出已归档 sessions。 */
|
|
78
|
+
method: "sdk.sessions.archived.list";
|
|
79
|
+
/** 列表过滤与分页参数。 */
|
|
80
|
+
params?: AgentArchiveSessionsInput;
|
|
81
|
+
}
|
|
82
|
+
| {
|
|
83
|
+
/** 请求 id,用于匹配响应。 */
|
|
84
|
+
id: string;
|
|
85
|
+
/** 清空已归档 sessions。 */
|
|
86
|
+
method: "sdk.sessions.archived.clean";
|
|
87
|
+
}
|
|
57
88
|
| {
|
|
58
89
|
/** 请求 id,用于匹配响应。 */
|
|
59
90
|
id: string;
|
|
@@ -67,6 +98,17 @@ export type RpcRequest =
|
|
|
67
98
|
input: AgentSessionPromptInput;
|
|
68
99
|
};
|
|
69
100
|
}
|
|
101
|
+
| {
|
|
102
|
+
/** 请求 id,用于匹配响应。 */
|
|
103
|
+
id: string;
|
|
104
|
+
/** 停止当前 session turn。 */
|
|
105
|
+
method: "sdk.sessions.stop";
|
|
106
|
+
/** 停止参数。 */
|
|
107
|
+
params: {
|
|
108
|
+
/** 目标 session id。 */
|
|
109
|
+
sessionId: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
70
112
|
| {
|
|
71
113
|
/** 请求 id,用于匹配响应。 */
|
|
72
114
|
id: string;
|
|
@@ -3,17 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
5
|
* - 这里定义 plugin runtime、plugin、prompt system 共用的统一执行上下文。
|
|
6
|
-
* - `AgentContext` 是一个 class
|
|
6
|
+
* - `AgentContext` 是一个 class,表达"当前一次执行可见的能力面",不是宿主状态本体。
|
|
7
7
|
* - 同一 agent 实例全程共享同一个 context;plugin、session、executor 都基于它读写状态。
|
|
8
|
-
*
|
|
9
|
-
* 边界说明(中文)
|
|
10
|
-
* - `AgentRuntime` 负责保存长期状态;`AgentContext` 负责把这些状态暴露成执行接口。
|
|
11
|
-
* - 这里同时声明类型协议与默认实现;plugin 作者拿到的就是这个 class 的实例。
|
|
12
8
|
*/
|
|
13
9
|
|
|
14
10
|
import type { LanguageModel } from "ai";
|
|
15
11
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
16
|
-
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
17
12
|
import type {
|
|
18
13
|
AgentPathRuntime,
|
|
19
14
|
AgentPluginConfigRuntime,
|
|
@@ -21,6 +16,7 @@ import type {
|
|
|
21
16
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
22
17
|
import type { JsonValue } from "@/types/common/Json.js";
|
|
23
18
|
import type { AgentPlugins } from "@/plugin/types/Plugin.js";
|
|
19
|
+
import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
|
|
24
20
|
import type {
|
|
25
21
|
SessionMetadataV1,
|
|
26
22
|
SessionMessageV1,
|
|
@@ -31,6 +27,7 @@ import type {
|
|
|
31
27
|
} from "@/executor/types/SessionRun.js";
|
|
32
28
|
import type { SessionHistoryStore } from "@/executor/store/history/SessionHistoryStore.js";
|
|
33
29
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
30
|
+
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
34
31
|
import type {
|
|
35
32
|
AgentSessionEvent,
|
|
36
33
|
AgentSessionSubscriber,
|
|
@@ -97,9 +94,10 @@ export interface SessionExecutorPort {
|
|
|
97
94
|
* 请求取消当前正在执行的 turn。
|
|
98
95
|
*
|
|
99
96
|
* 关键点(中文)
|
|
100
|
-
* -
|
|
101
|
-
* -
|
|
97
|
+
* - 返回 `true` 表示已发出取消请求。
|
|
98
|
+
* - 返回 `false` 表示当前没有可取消的执行。
|
|
102
99
|
*/
|
|
100
|
+
stop(): boolean;
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
/**
|
|
@@ -126,6 +124,10 @@ export interface SessionPort {
|
|
|
126
124
|
* - 返回值只有在当前输入被绑定到某个 turn 后才会兑现。
|
|
127
125
|
*/
|
|
128
126
|
prompt(input: AgentSessionPromptInput): Promise<AgentSessionTurnHandle>;
|
|
127
|
+
/**
|
|
128
|
+
* 停止当前 turn,并取消尚未被吸收的排队 prompt。
|
|
129
|
+
*/
|
|
130
|
+
stop(): Promise<AgentSessionStopResult>;
|
|
129
131
|
/**
|
|
130
132
|
* 订阅当前 session 后续产生的 future 事件。
|
|
131
133
|
*
|
|
@@ -220,12 +222,10 @@ export interface SessionCollectionPort {
|
|
|
220
222
|
* AgentContext 构造参数。
|
|
221
223
|
*
|
|
222
224
|
* 关键点(中文)
|
|
223
|
-
* - 装配方负责把
|
|
225
|
+
* - 装配方负责把 session / plugins 等上层依赖注入进来。
|
|
224
226
|
* - `env` 必须传入 agent 持有的 mutable 共享对象引用,不要在这里克隆。
|
|
225
227
|
*/
|
|
226
228
|
export interface AgentContextOptions {
|
|
227
|
-
/** 当前执行上下文对应的 agent 状态。 */
|
|
228
|
-
agent: AgentRuntime;
|
|
229
229
|
/** 当前命令工作目录。 */
|
|
230
230
|
cwd: string;
|
|
231
231
|
/** 当前项目根目录。 */
|
|
@@ -248,6 +248,8 @@ export interface AgentContextOptions {
|
|
|
248
248
|
paths: AgentPathRuntime;
|
|
249
249
|
/** 当前可见的 plugin 配置持久化能力集合。 */
|
|
250
250
|
pluginConfig: AgentPluginConfigRuntime;
|
|
251
|
+
/** 当前 agent 持有的插件实例集合。 */
|
|
252
|
+
pluginInstances: Map<string, BasePlugin>;
|
|
251
253
|
/** Session 能力入口。 */
|
|
252
254
|
session: SessionCollectionPort;
|
|
253
255
|
/** Plugin 调用入口。 */
|
|
@@ -263,8 +265,6 @@ export interface AgentContextOptions {
|
|
|
263
265
|
* - `invoke` 是构造期组装的 plugin 调用端口,对外仍以 `InvokePluginPort` 形态暴露。
|
|
264
266
|
*/
|
|
265
267
|
export class AgentContext {
|
|
266
|
-
/** 当前执行上下文对应的 agent 状态。 */
|
|
267
|
-
readonly agent: AgentRuntime;
|
|
268
268
|
/** 当前命令工作目录。 */
|
|
269
269
|
readonly cwd: string;
|
|
270
270
|
/** 当前项目根目录。 */
|
|
@@ -281,6 +281,8 @@ export class AgentContext {
|
|
|
281
281
|
readonly paths: AgentPathRuntime;
|
|
282
282
|
/** 当前可见的 plugin 配置持久化能力集合。 */
|
|
283
283
|
readonly pluginConfig: AgentPluginConfigRuntime;
|
|
284
|
+
/** 当前 agent 持有的插件实例集合。 */
|
|
285
|
+
readonly pluginInstances: Map<string, BasePlugin>;
|
|
284
286
|
/** Session 能力入口。 */
|
|
285
287
|
readonly session: SessionCollectionPort;
|
|
286
288
|
/** Plugin 调用入口。 */
|
|
@@ -289,7 +291,6 @@ export class AgentContext {
|
|
|
289
291
|
readonly invoke: InvokePluginPort;
|
|
290
292
|
|
|
291
293
|
constructor(options: AgentContextOptions) {
|
|
292
|
-
this.agent = options.agent;
|
|
293
294
|
this.cwd = options.cwd;
|
|
294
295
|
this.rootPath = options.rootPath;
|
|
295
296
|
this.logger = options.logger;
|
|
@@ -298,6 +299,7 @@ export class AgentContext {
|
|
|
298
299
|
this.systems = options.systems;
|
|
299
300
|
this.paths = options.paths;
|
|
300
301
|
this.pluginConfig = options.pluginConfig;
|
|
302
|
+
this.pluginInstances = options.pluginInstances;
|
|
301
303
|
this.session = options.session;
|
|
302
304
|
this.plugins = options.plugins;
|
|
303
305
|
this.invoke = {
|
|
@@ -305,6 +307,31 @@ export class AgentContext {
|
|
|
305
307
|
};
|
|
306
308
|
}
|
|
307
309
|
|
|
310
|
+
/**
|
|
311
|
+
* 读取指定 sessionId 对应的 session 端口。
|
|
312
|
+
*
|
|
313
|
+
* 关键点(中文)
|
|
314
|
+
* - 返回值是统一的 `SessionPort`,而不是裸 `Executor`。
|
|
315
|
+
* - 这样 HTTP / plugin runtime / chat queue / contact 等入口都能复用同一层会话装配与执行兜底。
|
|
316
|
+
*/
|
|
317
|
+
getSession(sessionId: string): SessionPort {
|
|
318
|
+
return this.session.get(sessionId);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 返回当前执行中的 sessionId 列表。
|
|
323
|
+
*/
|
|
324
|
+
listExecutingSessionIds(): string[] {
|
|
325
|
+
return this.session.listExecutingSessionIds();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 返回当前执行中的 session 数量。
|
|
330
|
+
*/
|
|
331
|
+
getExecutingSessionCount(): number {
|
|
332
|
+
return this.session.getExecutingSessionCount();
|
|
333
|
+
}
|
|
334
|
+
|
|
308
335
|
/**
|
|
309
336
|
* 跨 plugin runtime 调用 action 的内部实现。
|
|
310
337
|
*
|
|
@@ -27,7 +27,7 @@ export interface PlatformAgentOption {
|
|
|
27
27
|
projectRoot: string;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* 当前
|
|
30
|
+
* 当前 downcity 托管的 Agent 进程是否存活。
|
|
31
31
|
*/
|
|
32
32
|
running: boolean;
|
|
33
33
|
|
|
@@ -62,12 +62,12 @@ export interface PlatformAgentOption {
|
|
|
62
62
|
stoppedAt?: string;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
* 当前读取到的
|
|
65
|
+
* 当前读取到的 downcity 托管进程 pid(仅 running=true 时有值)。
|
|
66
66
|
*/
|
|
67
67
|
daemonPid?: number;
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* downcity 托管进程日志路径(用于排障展示)。
|
|
71
71
|
*/
|
|
72
72
|
logPath?: string;
|
|
73
73
|
|
|
@@ -168,7 +168,7 @@ export interface PlatformAgentDirectoryInspection {
|
|
|
168
168
|
knownAgent: boolean;
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
|
-
* 若已登记,当前
|
|
171
|
+
* 若已登记,当前 downcity 托管进程是否运行中。
|
|
172
172
|
*/
|
|
173
173
|
running: boolean;
|
|
174
174
|
|
|
@@ -356,7 +356,7 @@ export interface ManagedAgentRegistryEntry {
|
|
|
356
356
|
projectRoot: string;
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
* registry 最近一次记录的
|
|
359
|
+
* registry 最近一次记录的 downcity 托管进程 pid。
|
|
360
360
|
*/
|
|
361
361
|
pid: number;
|
|
362
362
|
|
|
@@ -402,7 +402,7 @@ export interface ManagedAgentRegistryV1 {
|
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
/**
|
|
405
|
-
* `
|
|
405
|
+
* `downcity agent list --running` 输出可复用的受管 agent 运行态视图。
|
|
406
406
|
*/
|
|
407
407
|
export interface ManagedAgentProcessView {
|
|
408
408
|
/**
|
|
@@ -416,7 +416,7 @@ export interface ManagedAgentProcessView {
|
|
|
416
416
|
registeredPid: number;
|
|
417
417
|
|
|
418
418
|
/**
|
|
419
|
-
* 当前实际存活的
|
|
419
|
+
* 当前实际存活的 downcity 托管进程 pid。
|
|
420
420
|
*/
|
|
421
421
|
daemonPid: number;
|
|
422
422
|
|
|
@@ -436,7 +436,7 @@ export interface ManagedAgentProcessView {
|
|
|
436
436
|
updatedAt: string;
|
|
437
437
|
|
|
438
438
|
/**
|
|
439
|
-
*
|
|
439
|
+
* downcity 托管进程日志文件路径。
|
|
440
440
|
*/
|
|
441
441
|
logPath: string;
|
|
442
442
|
}
|
|
@@ -106,12 +106,12 @@ export interface PlatformAgentShipPluginsConfig {
|
|
|
106
106
|
*/
|
|
107
107
|
export interface PlatformAgentShipStartConfig {
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
109
|
+
* downcity Agent HTTP gateway host。
|
|
110
110
|
*/
|
|
111
111
|
host?: unknown;
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* downcity Agent HTTP gateway port。
|
|
115
115
|
*/
|
|
116
116
|
port?: unknown;
|
|
117
117
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Session stop 类型定义。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - `session.stop()` 用于停止当前正在执行的 turn。
|
|
6
|
+
* - 尚未被当前 turn 吸收的排队 prompt 会被取消,不会自动开启下一轮。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Session stop 的最终结果。
|
|
11
|
+
*/
|
|
12
|
+
export interface AgentSessionStopResult {
|
|
13
|
+
/**
|
|
14
|
+
* 本次调用是否实际停止了活跃 turn 或取消了排队 prompt。
|
|
15
|
+
*/
|
|
16
|
+
stopped: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 被停止的当前 turn 标识。
|
|
20
|
+
*
|
|
21
|
+
* 说明(中文)
|
|
22
|
+
* - 当前没有活跃 turn 时不会返回该字段。
|
|
23
|
+
* - 如果只是清空尚未启动的队列,也不会返回该字段。
|
|
24
|
+
*/
|
|
25
|
+
turnId?: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 本次 stop 取消的未绑定 prompt 数量。
|
|
29
|
+
*
|
|
30
|
+
* 说明(中文)
|
|
31
|
+
* - 已经被当前 turn 吸收的 prompt 不计入这里,它们会随当前 turn 一起结束。
|
|
32
|
+
*/
|
|
33
|
+
cancelledQueuedPrompts: number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 本次 stop 的归因。
|
|
37
|
+
*/
|
|
38
|
+
reason: "stopped" | "idle";
|
|
39
|
+
}
|