@downcity/agent 1.1.79 → 1.1.82
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 +1 -1
- package/bin/agent/local/Agent.d.ts +8 -121
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +63 -381
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/AgentRuntimeFactory.d.ts +2 -2
- package/bin/agent/local/AgentRuntimeFactory.d.ts.map +1 -1
- package/bin/agent/local/AgentRuntimeFactory.js +2 -23
- package/bin/agent/local/AgentRuntimeFactory.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +112 -0
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -0
- package/bin/agent/local/services/AgentAssemblyService.js +135 -0
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -0
- package/bin/agent/local/services/AgentLifecycleService.d.ts +59 -0
- package/bin/agent/local/services/AgentLifecycleService.d.ts.map +1 -0
- package/bin/agent/local/services/AgentLifecycleService.js +136 -0
- package/bin/agent/local/services/AgentLifecycleService.js.map +1 -0
- package/bin/agent/local/services/AgentSessionManager.d.ts +106 -0
- package/bin/agent/local/services/AgentSessionManager.d.ts.map +1 -0
- package/bin/agent/local/services/AgentSessionManager.js +182 -0
- package/bin/agent/local/services/AgentSessionManager.js.map +1 -0
- package/bin/executor/Executor.d.ts +7 -24
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +73 -361
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/SessionRunScope.d.ts +18 -34
- package/bin/executor/SessionRunScope.d.ts.map +1 -1
- package/bin/executor/SessionRunScope.js +42 -28
- package/bin/executor/SessionRunScope.js.map +1 -1
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts +5 -3
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts.map +1 -1
- package/bin/executor/composer/context/LocalSessionContextComposer.js +11 -18
- package/bin/executor/composer/context/LocalSessionContextComposer.js.map +1 -1
- package/bin/executor/composer/context/SessionContextComposer.d.ts +8 -3
- package/bin/executor/composer/context/SessionContextComposer.d.ts.map +1 -1
- package/bin/executor/composer/system/SessionSystemComposer.d.ts +2 -1
- package/bin/executor/composer/system/SessionSystemComposer.d.ts.map +1 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +2 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts.map +1 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js +2 -4
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +62 -0
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -0
- package/bin/executor/core-engine/CoreEngineRunner.js +309 -0
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -0
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +5 -0
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js +2 -4
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +1 -1
- package/bin/executor/services/ExecutorInflightService.d.ts +39 -0
- package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -0
- package/bin/executor/services/ExecutorInflightService.js +75 -0
- package/bin/executor/services/ExecutorInflightService.js.map +1 -0
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +103 -0
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -0
- package/bin/executor/services/ExecutorRecoveryPolicy.js +87 -0
- package/bin/executor/services/ExecutorRecoveryPolicy.js.map +1 -0
- package/bin/executor/tools/plugin/PluginToolBridge.d.ts +19 -0
- package/bin/executor/tools/plugin/PluginToolBridge.d.ts.map +1 -0
- package/bin/executor/tools/plugin/PluginToolBridge.js +143 -0
- package/bin/executor/tools/plugin/PluginToolBridge.js.map +1 -0
- package/bin/executor/tools/plugin/PluginToolDefinition.d.ts +32 -0
- package/bin/executor/tools/plugin/PluginToolDefinition.d.ts.map +1 -0
- package/bin/executor/tools/plugin/PluginToolDefinition.js +27 -0
- package/bin/executor/tools/plugin/PluginToolDefinition.js.map +1 -0
- package/bin/executor/tools/plugin/PluginToolSchemas.d.ts +14 -0
- package/bin/executor/tools/plugin/PluginToolSchemas.d.ts.map +1 -0
- package/bin/executor/tools/plugin/PluginToolSchemas.js +19 -0
- package/bin/executor/tools/plugin/PluginToolSchemas.js.map +1 -0
- package/bin/executor/tools/plugin/types/PluginTool.d.ts +39 -0
- package/bin/executor/tools/plugin/types/PluginTool.d.ts.map +1 -0
- package/bin/executor/tools/plugin/types/PluginTool.js +9 -0
- package/bin/executor/tools/plugin/types/PluginTool.js.map +1 -0
- package/bin/executor/tools/shell/ShellToolBridge.js +3 -3
- package/bin/executor/tools/shell/ShellToolBridge.js.map +1 -1
- package/bin/executor/types/SessionRun.d.ts +18 -0
- package/bin/executor/types/SessionRun.d.ts.map +1 -1
- package/bin/index.d.ts +10 -1
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +3 -0
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/BasePlugin.d.ts +2 -2
- package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
- package/bin/plugin/core/BasePlugin.js.map +1 -1
- package/bin/plugin/core/ImagePlugin.d.ts +56 -0
- package/bin/plugin/core/ImagePlugin.d.ts.map +1 -0
- package/bin/plugin/core/ImagePlugin.js +109 -0
- package/bin/plugin/core/ImagePlugin.js.map +1 -0
- package/bin/session/Session.d.ts +25 -84
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +162 -367
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionSystemBuilder.d.ts +2 -1
- package/bin/session/SessionSystemBuilder.d.ts.map +1 -1
- package/bin/session/SessionSystemBuilder.js +2 -3
- package/bin/session/SessionSystemBuilder.js.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +132 -0
- package/bin/session/services/SessionStateService.d.ts.map +1 -0
- package/bin/session/services/SessionStateService.js +242 -0
- package/bin/session/services/SessionStateService.js.map +1 -0
- package/bin/session/services/SessionTurnService.d.ts +66 -0
- package/bin/session/services/SessionTurnService.d.ts.map +1 -0
- package/bin/session/services/SessionTurnService.js +137 -0
- package/bin/session/services/SessionTurnService.js.map +1 -0
- package/bin/session/services/SessionViewService.d.ts +106 -0
- package/bin/session/services/SessionViewService.d.ts.map +1 -0
- package/bin/session/services/SessionViewService.js +198 -0
- package/bin/session/services/SessionViewService.js.map +1 -0
- package/bin/types/agent/AgentOptions.d.ts +18 -0
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +3 -1
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +66 -0
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -0
- package/bin/types/executor/SessionRunContext.js +10 -0
- package/bin/types/executor/SessionRunContext.js.map +1 -0
- package/bin/types/plugin/ImagePlugin.d.ts +94 -0
- package/bin/types/plugin/ImagePlugin.d.ts.map +1 -0
- package/bin/types/plugin/ImagePlugin.js +10 -0
- package/bin/types/plugin/ImagePlugin.js.map +1 -0
- package/bin/types/session/SessionComposerOptions.d.ts +90 -0
- package/bin/types/session/SessionComposerOptions.d.ts.map +1 -0
- package/bin/types/session/SessionComposerOptions.js +10 -0
- package/bin/types/session/SessionComposerOptions.js.map +1 -0
- package/bin/types/session/SessionLocalState.d.ts +35 -0
- package/bin/types/session/SessionLocalState.d.ts.map +1 -0
- package/bin/types/session/SessionLocalState.js +10 -0
- package/bin/types/session/SessionLocalState.js.map +1 -0
- package/bin/types/session/SessionOptions.d.ts +85 -0
- package/bin/types/session/SessionOptions.d.ts.map +1 -0
- package/bin/types/session/SessionOptions.js +10 -0
- package/bin/types/session/SessionOptions.js.map +1 -0
- package/package.json +1 -1
- package/src/agent/local/Agent.ts +74 -433
- package/src/agent/local/AgentRuntimeFactory.ts +4 -25
- package/src/agent/local/services/AgentAssemblyService.ts +268 -0
- package/src/agent/local/services/AgentLifecycleService.ts +187 -0
- package/src/agent/local/services/AgentSessionManager.ts +290 -0
- package/src/executor/Executor.ts +103 -441
- package/src/executor/README.md +4 -4
- package/src/executor/SessionRunScope.ts +47 -71
- package/src/executor/composer/context/LocalSessionContextComposer.ts +24 -20
- package/src/executor/composer/context/SessionContextComposer.ts +13 -3
- package/src/executor/composer/system/SessionSystemComposer.ts +2 -1
- package/src/executor/composer/system/default/DefaultSessionSystemComposer.ts +3 -4
- package/src/executor/core-engine/CoreEngineRunner.ts +433 -0
- package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +7 -5
- package/src/executor/services/ExecutorInflightService.ts +101 -0
- package/src/executor/services/ExecutorRecoveryPolicy.ts +213 -0
- package/src/executor/tools/plugin/PluginToolBridge.ts +161 -0
- package/src/executor/tools/plugin/PluginToolDefinition.ts +32 -0
- package/src/executor/tools/plugin/PluginToolSchemas.ts +20 -0
- package/src/executor/tools/plugin/types/PluginTool.ts +41 -0
- package/src/executor/tools/shell/ShellToolBridge.ts +3 -3
- package/src/executor/types/SessionRun.ts +20 -0
- package/src/index.ts +33 -0
- package/src/plugin/core/BasePlugin.ts +2 -2
- package/src/plugin/core/ImagePlugin.ts +128 -0
- package/src/session/Session.ts +216 -500
- package/src/session/SessionSystemBuilder.ts +3 -3
- package/src/session/services/SessionStateService.ts +341 -0
- package/src/session/services/SessionTurnService.ts +202 -0
- package/src/session/services/SessionViewService.ts +323 -0
- package/src/types/agent/AgentOptions.ts +25 -0
- package/src/types/agent/AgentTypes.ts +10 -0
- package/src/types/agent/SessionTypes.ts +1 -0
- package/src/types/executor/SessionRunContext.ts +76 -0
- package/src/types/plugin/ImagePlugin.ts +103 -0
- package/src/types/session/SessionComposerOptions.ts +107 -0
- package/src/types/session/SessionLocalState.ts +40 -0
- package/src/types/session/SessionOptions.ts +99 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentSessionManager:本地 Agent session 管理服务。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 统一管理 session 缓存、创建、恢复、默认配置注入与 session collection。
|
|
6
|
+
* - 该服务只负责 session 生命周期与查询,不负责 plugin / RPC 启停。
|
|
7
|
+
* - Session 对象创建细节集中在这里,避免 facade 和 lifecycle 重复依赖 Session 构造逻辑。
|
|
8
|
+
*/
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
import { nanoid } from "nanoid";
|
|
11
|
+
import { Session } from "../../../session/Session.js";
|
|
12
|
+
import { getSdkAgentSessionDirPath, listAgentSessionSummaryPage, } from "../../../session/index.js";
|
|
13
|
+
import { isPluginEnabled } from "../../../plugin/core/Activation.js";
|
|
14
|
+
import { createInstructionSystemBlocks } from "../../../agent/local/AgentInstructions.js";
|
|
15
|
+
/**
|
|
16
|
+
* 本地 Agent session 管理服务。
|
|
17
|
+
*/
|
|
18
|
+
export class AgentSessionManager {
|
|
19
|
+
agent_id;
|
|
20
|
+
project_root;
|
|
21
|
+
tools;
|
|
22
|
+
logger;
|
|
23
|
+
runtime;
|
|
24
|
+
get_agent_context;
|
|
25
|
+
get_instruction;
|
|
26
|
+
plugin_instances;
|
|
27
|
+
default_model;
|
|
28
|
+
SessionClass;
|
|
29
|
+
sessions_by_id = new Map();
|
|
30
|
+
configured_session_ids = new Set();
|
|
31
|
+
session_collection;
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this.agent_id = options.agent_id;
|
|
34
|
+
this.project_root = options.project_root;
|
|
35
|
+
this.tools = options.tools;
|
|
36
|
+
this.logger = options.logger;
|
|
37
|
+
this.runtime = options.runtime;
|
|
38
|
+
this.get_agent_context = options.get_agent_context;
|
|
39
|
+
this.get_instruction = options.get_instruction;
|
|
40
|
+
this.plugin_instances = options.plugin_instances;
|
|
41
|
+
this.default_model = options.default_model;
|
|
42
|
+
this.SessionClass = options.SessionClass || Session;
|
|
43
|
+
this.session_collection = {
|
|
44
|
+
createSession: async (input) => await this.create_session(input),
|
|
45
|
+
getSession: async (session_id) => await this.get_session(session_id),
|
|
46
|
+
listSessions: async (input) => await this.list_sessions(input),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 返回当前缓存的 session 实例。
|
|
51
|
+
*/
|
|
52
|
+
list_cached_sessions() {
|
|
53
|
+
return [...this.sessions_by_id.values()];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 返回对外暴露的 session collection。
|
|
57
|
+
*/
|
|
58
|
+
get_session_collection() {
|
|
59
|
+
return this.session_collection;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 获取或创建一个 session runtime port。
|
|
63
|
+
*/
|
|
64
|
+
get_session_port(session_id) {
|
|
65
|
+
return this.get_or_create_session({
|
|
66
|
+
session_id,
|
|
67
|
+
}).getRuntimePort();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 新建一个 session。
|
|
71
|
+
*/
|
|
72
|
+
async create_session(input) {
|
|
73
|
+
const explicit_session_id = String(input?.sessionId || "").trim() || undefined;
|
|
74
|
+
if (explicit_session_id &&
|
|
75
|
+
(this.sessions_by_id.has(explicit_session_id) ||
|
|
76
|
+
(await fs.pathExists(getSdkAgentSessionDirPath(this.project_root, this.agent_id, explicit_session_id))))) {
|
|
77
|
+
throw new Error(`Session "${explicit_session_id}" already exists`);
|
|
78
|
+
}
|
|
79
|
+
const session = this.get_or_create_session({
|
|
80
|
+
session_id: explicit_session_id,
|
|
81
|
+
});
|
|
82
|
+
await session.initialize();
|
|
83
|
+
await this.apply_session_defaults(session);
|
|
84
|
+
return session;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 获取一个已存在的 session。
|
|
88
|
+
*/
|
|
89
|
+
async get_session(session_id) {
|
|
90
|
+
const resolved_session_id = String(session_id || "").trim();
|
|
91
|
+
if (!resolved_session_id) {
|
|
92
|
+
throw new Error("getSession requires a non-empty sessionId");
|
|
93
|
+
}
|
|
94
|
+
const session_dir_path = getSdkAgentSessionDirPath(this.project_root, this.agent_id, resolved_session_id);
|
|
95
|
+
if (!this.sessions_by_id.has(resolved_session_id) &&
|
|
96
|
+
!(await fs.pathExists(session_dir_path))) {
|
|
97
|
+
throw new Error(`Session "${resolved_session_id}" not found`);
|
|
98
|
+
}
|
|
99
|
+
const session = this.get_or_create_session({
|
|
100
|
+
session_id: resolved_session_id,
|
|
101
|
+
});
|
|
102
|
+
await session.initialize();
|
|
103
|
+
await this.apply_session_defaults(session);
|
|
104
|
+
return session;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 列出当前 agent 的 session 摘要页。
|
|
108
|
+
*/
|
|
109
|
+
async list_sessions(input) {
|
|
110
|
+
return await listAgentSessionSummaryPage({
|
|
111
|
+
projectRoot: this.project_root,
|
|
112
|
+
agentId: this.agent_id,
|
|
113
|
+
input,
|
|
114
|
+
executingSessionIds: new Set(this.runtime.listExecutingSessionIds()),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
get_or_create_session(input) {
|
|
118
|
+
const resolved_session_id = String(input?.session_id || "").trim() ||
|
|
119
|
+
`session-${Date.now()}-${nanoid(8)}`;
|
|
120
|
+
const cached = this.sessions_by_id.get(resolved_session_id);
|
|
121
|
+
if (cached)
|
|
122
|
+
return cached;
|
|
123
|
+
const created = new this.SessionClass({
|
|
124
|
+
agentId: this.agent_id,
|
|
125
|
+
projectRoot: this.project_root,
|
|
126
|
+
sessionId: resolved_session_id,
|
|
127
|
+
tools: this.tools,
|
|
128
|
+
logger: this.logger,
|
|
129
|
+
getInstructionSystemBlocks: () => this.load_instruction_system_blocks(),
|
|
130
|
+
getManagedPluginSystemBlocks: async () => [],
|
|
131
|
+
getPluginSystemBlocks: async () => await this.load_plugin_system_blocks(),
|
|
132
|
+
ensureConfigured: async (session) => {
|
|
133
|
+
await this.apply_session_defaults(session);
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
this.sessions_by_id.set(resolved_session_id, created);
|
|
137
|
+
return created;
|
|
138
|
+
}
|
|
139
|
+
async apply_session_defaults(session) {
|
|
140
|
+
if (this.configured_session_ids.has(session.id))
|
|
141
|
+
return;
|
|
142
|
+
if (this.default_model) {
|
|
143
|
+
await session.set({
|
|
144
|
+
model: this.default_model,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
this.configured_session_ids.add(session.id);
|
|
148
|
+
}
|
|
149
|
+
load_instruction_system_blocks() {
|
|
150
|
+
return createInstructionSystemBlocks(this.get_instruction(), this.project_root);
|
|
151
|
+
}
|
|
152
|
+
async load_plugin_system_blocks() {
|
|
153
|
+
const context = this.get_agent_context();
|
|
154
|
+
const out = [];
|
|
155
|
+
for (const plugin of this.plugin_instances.values()) {
|
|
156
|
+
if (typeof plugin.system !== "function")
|
|
157
|
+
continue;
|
|
158
|
+
try {
|
|
159
|
+
if (!isPluginEnabled({ plugin, context }))
|
|
160
|
+
continue;
|
|
161
|
+
if (typeof plugin.availability === "function") {
|
|
162
|
+
const availability = await plugin.availability(context);
|
|
163
|
+
if (!availability.available)
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const text = String(await plugin.system(context)).trim();
|
|
167
|
+
if (!text)
|
|
168
|
+
continue;
|
|
169
|
+
out.push({
|
|
170
|
+
source: "plugin",
|
|
171
|
+
name: plugin.name,
|
|
172
|
+
content: text,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// 单个 plugin system 失败不应阻断 SDK session 主链路。
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=AgentSessionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentSessionManager.js","sourceR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G,CAAC;IACb,CAAC;CACF"}
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
import { type LanguageModel, type Tool } from "ai";
|
|
10
10
|
import type { SessionHistoryComposer } from "./composer/history/SessionHistoryComposer.js";
|
|
11
11
|
import type { SessionHistoryStore } from "../executor/store/history/SessionHistoryStore.js";
|
|
12
|
-
import type { SessionRunScope } from "./SessionRunScope.js";
|
|
13
12
|
import type { SessionCompactionComposer } from "./composer/compaction/SessionCompactionComposer.js";
|
|
14
13
|
import type { SessionContextComposer } from "./composer/context/SessionContextComposer.js";
|
|
15
14
|
import type { SessionSystemComposer } from "./composer/system/SessionSystemComposer.js";
|
|
@@ -17,6 +16,7 @@ import type { Logger } from "../utils/logger/Logger.js";
|
|
|
17
16
|
import type { JsonObject } from "../types/common/Json.js";
|
|
18
17
|
import type { SessionMessageV1 } from "../executor/types/SessionMessages.js";
|
|
19
18
|
import type { SessionExecutor } from "../executor/types/SessionExecutor.js";
|
|
19
|
+
import type { SessionRunContext } from "../types/executor/SessionRunContext.js";
|
|
20
20
|
import type { SessionRunResult } from "../executor/types/SessionRun.js";
|
|
21
21
|
type ExecutorOptions = {
|
|
22
22
|
/**
|
|
@@ -79,8 +79,10 @@ export declare class Executor implements SessionExecutor {
|
|
|
79
79
|
private readonly systemComposer;
|
|
80
80
|
protected readonly contextComposer: SessionContextComposer;
|
|
81
81
|
private readonly historyWriter;
|
|
82
|
+
private readonly inflight_service;
|
|
83
|
+
private readonly recovery_policy;
|
|
84
|
+
private readonly core_engine_runner;
|
|
82
85
|
private executing;
|
|
83
|
-
private retryCount;
|
|
84
86
|
constructor(options: ExecutorOptions);
|
|
85
87
|
/**
|
|
86
88
|
* 返回当前 session 是否正在执行。
|
|
@@ -125,10 +127,6 @@ export declare class Executor implements SessionExecutor {
|
|
|
125
127
|
fallbackText?: string;
|
|
126
128
|
extra?: JsonObject;
|
|
127
129
|
}): Promise<void>;
|
|
128
|
-
/**
|
|
129
|
-
* 把 step/tool 过程增量写入当前运行中的 assistant 快照。
|
|
130
|
-
*/
|
|
131
|
-
private appendAssistantStepPartsToInflight;
|
|
132
130
|
/**
|
|
133
131
|
* 运行当前 session 的一次请求。
|
|
134
132
|
*
|
|
@@ -138,14 +136,8 @@ export declare class Executor implements SessionExecutor {
|
|
|
138
136
|
*/
|
|
139
137
|
run(params: {
|
|
140
138
|
query: string;
|
|
141
|
-
|
|
142
|
-
onAssistantStepCallback?: SessionRunScope["onAssistantStepCallback"];
|
|
143
|
-
onUiMessageChunkCallback?: SessionRunScope["onUiMessageChunkCallback"];
|
|
139
|
+
runContext?: SessionRunContext;
|
|
144
140
|
}): Promise<SessionRunResult>;
|
|
145
|
-
/**
|
|
146
|
-
* 执行一次 session run(带可压缩错误重试)。
|
|
147
|
-
*/
|
|
148
|
-
private runWithRetry;
|
|
149
141
|
/**
|
|
150
142
|
* 调用 Composer 组装当前轮执行输入。
|
|
151
143
|
*/
|
|
@@ -155,22 +147,13 @@ export declare class Executor implements SessionExecutor {
|
|
|
155
147
|
*/
|
|
156
148
|
private executePreparedRun;
|
|
157
149
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* 关键点(中文)
|
|
161
|
-
* - CoreEngine 是 Executor 内部机制,不是第二个 Executor 实例。
|
|
162
|
-
* - 这里只返回最终 assistant message;是否写入长期 history 由外层 Session/Service 决定。
|
|
163
|
-
* - 运行中生成的内部续写 user message 只进入本轮内存态,不直接落盘。
|
|
150
|
+
* 归一化本轮显式运行上下文。
|
|
164
151
|
*/
|
|
165
|
-
private
|
|
152
|
+
private createRunContext;
|
|
166
153
|
/**
|
|
167
154
|
* 读取当前 session 模型。
|
|
168
155
|
*/
|
|
169
156
|
private resolveModelOrThrow;
|
|
170
|
-
/**
|
|
171
|
-
* 重置当前 run 级状态。
|
|
172
|
-
*/
|
|
173
|
-
private resetRunState;
|
|
174
157
|
}
|
|
175
158
|
export {};
|
|
176
159
|
//# sourceMappingURL=Executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Executor.d.ts","sourceRoot":"","sources":["../../src/executor/Executor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAc,KAAK,aAAa,EAAE,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AACnG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"Executor.d.ts","sourceRoot":"","sources":["../../src/executor/Executor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAc,KAAK,aAAa,EAAE,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AACnG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iDAAiD,CAAC;AAM3F,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4DAA4D,CAAC;AAC5G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AACnG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAC;AAGhG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAExC,KAAK,eAAe,GAAG;IACrB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,YAAY,EAAE,mBAAmB,CAAC;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