@downcity/agent 1.1.217 → 1.1.224
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 +1 -34
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +1 -44
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +35 -2
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentSessions.d.ts +6 -0
- package/bin/agent/local/services/AgentSessions.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessions.js +43 -4
- package/bin/agent/local/services/AgentSessions.js.map +1 -1
- package/bin/agent/remote/RemoteAgent.d.ts +1 -35
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +1 -37
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +26 -41
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +75 -107
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +15 -27
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +10 -21
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +24 -46
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +10 -20
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +10 -16
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +2 -2
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/types/SessionHistoryPaths.d.ts +1 -1
- package/bin/executor/types/SessionRecords.d.ts +2 -0
- package/bin/executor/types/SessionRecords.d.ts.map +1 -1
- package/bin/executor/types/SessionRecords.js.map +1 -1
- package/bin/index.d.ts +6 -3
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -0
- package/bin/index.js.map +1 -1
- package/bin/rpc/Client.d.ts +12 -34
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +31 -70
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +22 -4
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +95 -21
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +49 -18
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts +51 -0
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts.map +1 -0
- package/bin/session/recorder/JsonlSessionMessageStore.js +231 -0
- package/bin/session/recorder/JsonlSessionMessageStore.js.map +1 -0
- package/bin/session/recorder/SessionMessageCodec.d.ts +20 -0
- package/bin/session/recorder/SessionMessageCodec.d.ts.map +1 -0
- package/bin/session/recorder/SessionMessageCodec.js +257 -0
- package/bin/session/recorder/SessionMessageCodec.js.map +1 -0
- package/bin/session/recorder/SessionRecorder.d.ts +186 -0
- package/bin/session/recorder/SessionRecorder.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorder.js +655 -0
- package/bin/session/recorder/SessionRecorder.js.map +1 -0
- package/bin/session/recorder/SessionRecorderCompaction.d.ts +18 -0
- package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorderCompaction.js +142 -0
- package/bin/session/recorder/SessionRecorderCompaction.js.map +1 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +66 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.js +195 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.js.map +1 -0
- package/bin/session/runtime/SessionEventHub.d.ts +12 -5
- package/bin/session/runtime/SessionEventHub.d.ts.map +1 -1
- package/bin/session/runtime/SessionEventHub.js +11 -6
- package/bin/session/runtime/SessionEventHub.js.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +9 -15
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +48 -30
- package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +9 -5
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +138 -74
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.d.ts +6 -7
- package/bin/session/services/SessionTurnService.d.ts.map +1 -1
- package/bin/session/services/SessionTurnService.js +84 -60
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +8 -3
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +10 -5
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +1 -1
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +2 -2
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts +6 -0
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/Persistence.js +7 -0
- package/bin/session/storage/Persistence.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +3 -3
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +2 -2
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +15 -5
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +48 -61
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +5 -4
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/session/SessionApproval.d.ts +97 -0
- package/bin/types/session/SessionApproval.d.ts.map +1 -0
- package/bin/types/session/SessionApproval.js +7 -0
- package/bin/types/session/SessionApproval.js.map +1 -0
- package/bin/types/session/SessionMessage.d.ts +223 -0
- package/bin/types/session/SessionMessage.d.ts.map +1 -0
- package/bin/types/session/SessionMessage.js +8 -0
- package/bin/types/session/SessionMessage.js.map +1 -0
- package/bin/types/session/SessionMutation.d.ts +116 -0
- package/bin/types/session/SessionMutation.d.ts.map +1 -0
- package/bin/types/session/SessionMutation.js +19 -0
- package/bin/types/session/SessionMutation.js.map +1 -0
- package/bin/types/session/SessionOptions.d.ts +9 -0
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/package.json +3 -3
- package/scripts/agent-env.test.mjs +4 -4
- package/scripts/remote-session-reconnect.test.mjs +7 -3
- package/scripts/session-action-message.test.mjs +98 -27
- package/scripts/session-history-inflight.test.mjs +2 -2
- package/scripts/session-list-title.test.mjs +6 -19
- package/scripts/session-prompt-runtime.test.mjs +7 -19
- package/scripts/session-recorder.test.mjs +199 -0
- package/scripts/session-title-event.test.mjs +10 -18
- package/src/agent/local/Agent.ts +1 -55
- package/src/agent/local/services/AgentAssemblyService.ts +39 -3
- package/src/agent/local/services/AgentSessions.ts +48 -3
- package/src/agent/remote/RemoteAgent.ts +1 -54
- package/src/agent/remote/RemoteSession.ts +106 -136
- package/src/agent/remote/RemoteTransport.ts +30 -30
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +52 -77
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +30 -34
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +2 -2
- package/src/executor/types/SessionHistoryPaths.ts +1 -1
- package/src/executor/types/SessionRecords.ts +2 -0
- package/src/index.ts +36 -10
- package/src/rpc/Client.ts +58 -95
- package/src/session/Session.ts +128 -37
- package/src/session/browse/Browse.ts +51 -22
- package/src/session/recorder/JsonlSessionMessageStore.ts +246 -0
- package/src/session/recorder/SessionMessageCodec.ts +284 -0
- package/src/session/recorder/SessionRecorder.ts +871 -0
- package/src/session/recorder/SessionRecorderCompaction.ts +188 -0
- package/src/session/recorder/SessionRecorderHistoryStore.ts +276 -0
- package/src/session/runtime/SessionEventHub.ts +25 -12
- package/src/session/runtime/SessionPromptRuntime.ts +60 -43
- package/src/session/services/SessionStateService.ts +159 -86
- package/src/session/services/SessionTurnService.ts +91 -73
- package/src/session/services/SessionViewService.ts +25 -13
- package/src/session/storage/Paths.ts +2 -2
- package/src/session/storage/Persistence.ts +13 -0
- package/src/session/storage/RuntimeSessionPort.ts +8 -9
- package/src/types/agent/SessionActor.ts +31 -8
- package/src/types/rpc/RpcProtocol.ts +44 -67
- package/src/types/runtime/agent/AgentContext.ts +9 -7
- package/src/types/session/SessionApproval.ts +108 -0
- package/src/types/session/SessionMessage.ts +253 -0
- package/src/types/session/SessionMutation.ts +141 -0
- package/src/types/session/SessionOptions.ts +25 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/session/SessionEventMapper.d.ts +0 -32
- package/bin/session/SessionEventMapper.d.ts.map +0 -1
- package/bin/session/SessionEventMapper.js +0 -131
- package/bin/session/SessionEventMapper.js.map +0 -1
- package/bin/types/sdk/AgentSessionEvent.d.ts +0 -302
- package/bin/types/sdk/AgentSessionEvent.d.ts.map +0 -1
- package/bin/types/sdk/AgentSessionEvent.js +0 -9
- package/bin/types/sdk/AgentSessionEvent.js.map +0 -1
- package/bin/types/sdk/InternalUiChunkEvent.d.ts +0 -100
- package/bin/types/sdk/InternalUiChunkEvent.d.ts.map +0 -1
- package/bin/types/sdk/InternalUiChunkEvent.js +0 -9
- package/bin/types/sdk/InternalUiChunkEvent.js.map +0 -1
- package/scripts/session-history-archive.test.mjs +0 -188
- package/src/session/SessionEventMapper.ts +0 -148
- package/src/types/sdk/AgentSessionEvent.ts +0 -370
- package/src/types/sdk/InternalUiChunkEvent.ts +0 -108
package/src/agent/local/Agent.ts
CHANGED
|
@@ -15,12 +15,6 @@ import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
|
15
15
|
import type { AgentOptions } from "@/types/agent/AgentOptions.js";
|
|
16
16
|
import type { AgentSessions as AgentSessionsApi } from "@/types/agent/SessionActor.js";
|
|
17
17
|
import type {
|
|
18
|
-
ShellApprovalMode,
|
|
19
|
-
ShellApprovalDecisionResult,
|
|
20
|
-
ShellApprovalModeUpdateResult,
|
|
21
|
-
ShellApprovalModeOption,
|
|
22
|
-
ShellSessionApprovalModeView,
|
|
23
|
-
ShellApprovalView,
|
|
24
18
|
Shell,
|
|
25
19
|
} from "@downcity/shell";
|
|
26
20
|
import { Logger } from "@/utils/logger/Logger.js";
|
|
@@ -122,55 +116,6 @@ export class Agent {
|
|
|
122
116
|
await this.backgroundService.dispose();
|
|
123
117
|
}
|
|
124
118
|
|
|
125
|
-
/**
|
|
126
|
-
* 列出当前 shell pending approvals。
|
|
127
|
-
*/
|
|
128
|
-
approvals(): ShellApprovalView[] {
|
|
129
|
-
return this.shell?.approvals() || [];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 列出当前 shell 显式设置过的 approval 模式。
|
|
134
|
-
*/
|
|
135
|
-
approval_modes(): ShellApprovalModeOption[] {
|
|
136
|
-
return this.shell?.approval_modes() || [];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 读取当前 shell 指定 session 的 approval 模式。
|
|
141
|
-
*/
|
|
142
|
-
approval_mode(input: { session_id: string }): ShellSessionApprovalModeView {
|
|
143
|
-
if (!this.shell) throw new Error("Agent shell is not configured");
|
|
144
|
-
return this.shell.approval_mode(input);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 设置当前 shell 指定 session 的 approval 模式。
|
|
149
|
-
*/
|
|
150
|
-
set_approval_mode(input: {
|
|
151
|
-
session_id: string;
|
|
152
|
-
mode: ShellApprovalMode;
|
|
153
|
-
}): ShellApprovalModeUpdateResult {
|
|
154
|
-
if (!this.shell) throw new Error("Agent shell is not configured");
|
|
155
|
-
return this.shell.set_approval_mode(input);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* 批准当前 shell pending approval。
|
|
160
|
-
*/
|
|
161
|
-
async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
162
|
-
if (!this.shell) throw new Error("Agent shell is not configured");
|
|
163
|
-
return await this.shell.approve(input);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* 拒绝当前 shell pending approval。
|
|
168
|
-
*/
|
|
169
|
-
async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
170
|
-
if (!this.shell) throw new Error("Agent shell is not configured");
|
|
171
|
-
return await this.shell.deny(input);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
119
|
/**
|
|
175
120
|
* 更新当前 SDK Agent 的静态基础指令。
|
|
176
121
|
*/
|
|
@@ -260,6 +205,7 @@ export class Agent {
|
|
|
260
205
|
tools: this.tools || assembly.tools,
|
|
261
206
|
logger: this.logger || assembly.logger,
|
|
262
207
|
get_agent_context: () => this.agentContext ?? assembly.agent_context,
|
|
208
|
+
get_shell: () => this.shell,
|
|
263
209
|
get_instruction: () => this.instruction,
|
|
264
210
|
ensure_agent_ready: async () => {
|
|
265
211
|
await this.backgroundService.ready();
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
} from "@executor/tools/plugin/PluginToolDefinition.js";
|
|
33
33
|
import type { AgentManagedSession } from "@/types/session/SessionOptions.js";
|
|
34
34
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
35
|
-
import type {
|
|
35
|
+
import type { SessionApprovalRuntimeEvent } from "@/types/session/SessionApproval.js";
|
|
36
36
|
|
|
37
37
|
type AgentAssemblyServiceOptions = {
|
|
38
38
|
/**
|
|
@@ -215,10 +215,12 @@ export class AgentAssemblyService {
|
|
|
215
215
|
env,
|
|
216
216
|
agent_id: id,
|
|
217
217
|
logger,
|
|
218
|
-
emit_event: (event) => {
|
|
218
|
+
emit_event: async (event) => {
|
|
219
219
|
const session_id = String(event.session_id || "").trim();
|
|
220
220
|
if (!session_id) return;
|
|
221
|
-
|
|
221
|
+
const approval_event = normalize_approval_runtime_event(event);
|
|
222
|
+
if (!approval_event) return;
|
|
223
|
+
await agent_context!.session.get(session_id).publishEvent(approval_event);
|
|
222
224
|
},
|
|
223
225
|
});
|
|
224
226
|
Object.assign(tools, shell.tools);
|
|
@@ -269,3 +271,37 @@ export class AgentAssemblyService {
|
|
|
269
271
|
return false;
|
|
270
272
|
}
|
|
271
273
|
}
|
|
274
|
+
|
|
275
|
+
function normalize_approval_runtime_event(
|
|
276
|
+
event: Record<string, unknown>,
|
|
277
|
+
): SessionApprovalRuntimeEvent | null {
|
|
278
|
+
if (event.type === "tool-approval-request") {
|
|
279
|
+
return {
|
|
280
|
+
type: "tool-approval-request",
|
|
281
|
+
turn_id: String(event.turnId || ""),
|
|
282
|
+
tool_call_id: String(event.toolCallId || ""),
|
|
283
|
+
tool_name: String(event.toolName || "unknown"),
|
|
284
|
+
approval_id: String(event.approvalId || ""),
|
|
285
|
+
command: String(event.cmd || ""),
|
|
286
|
+
cwd: String(event.cwd || ""),
|
|
287
|
+
reason: String(event.reason || ""),
|
|
288
|
+
operation:
|
|
289
|
+
event.operation === "start" || event.operation === "write"
|
|
290
|
+
? event.operation
|
|
291
|
+
: "exec",
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (event.type === "tool-approval-result") {
|
|
295
|
+
const decision = event.decision === "approved" || event.decision === "denied"
|
|
296
|
+
? event.decision
|
|
297
|
+
: "expired";
|
|
298
|
+
return {
|
|
299
|
+
type: "tool-approval-result",
|
|
300
|
+
turn_id: String(event.turnId || ""),
|
|
301
|
+
tool_call_id: String(event.toolCallId || ""),
|
|
302
|
+
approval_id: String(event.approvalId || ""),
|
|
303
|
+
decision,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
@@ -39,6 +39,8 @@ import {
|
|
|
39
39
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
40
40
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
41
41
|
import { createInstructionSystemBlocks } from "@/agent/local/AgentInstructions.js";
|
|
42
|
+
import type { Shell } from "@downcity/shell";
|
|
43
|
+
import type { SessionApproval } from "@/types/session/SessionApproval.js";
|
|
42
44
|
|
|
43
45
|
function decodeMaybe(input: string): string {
|
|
44
46
|
try {
|
|
@@ -77,6 +79,9 @@ type AgentSessionsOptions = {
|
|
|
77
79
|
*/
|
|
78
80
|
get_agent_context: () => AgentContext;
|
|
79
81
|
|
|
82
|
+
/** 延迟读取当前 Agent 挂载的 Shell Runtime。 */
|
|
83
|
+
get_shell: () => Shell | undefined;
|
|
84
|
+
|
|
80
85
|
/**
|
|
81
86
|
* 当前静态 instruction 文本集合。
|
|
82
87
|
*/
|
|
@@ -113,6 +118,7 @@ export class AgentSessions implements AgentSessionsApi<AgentSession> {
|
|
|
113
118
|
private readonly tools: Record<string, Tool>;
|
|
114
119
|
private readonly logger: Logger;
|
|
115
120
|
private readonly get_agent_context: AgentSessionsOptions["get_agent_context"];
|
|
121
|
+
private readonly get_shell: AgentSessionsOptions["get_shell"];
|
|
116
122
|
private readonly get_instruction: AgentSessionsOptions["get_instruction"];
|
|
117
123
|
private readonly ensure_agent_ready: AgentSessionsOptions["ensure_agent_ready"];
|
|
118
124
|
private readonly default_model?: AgentModel;
|
|
@@ -128,6 +134,7 @@ export class AgentSessions implements AgentSessionsApi<AgentSession> {
|
|
|
128
134
|
this.tools = options.tools;
|
|
129
135
|
this.logger = options.logger;
|
|
130
136
|
this.get_agent_context = options.get_agent_context;
|
|
137
|
+
this.get_shell = options.get_shell;
|
|
131
138
|
this.get_instruction = options.get_instruction;
|
|
132
139
|
this.ensure_agent_ready = options.ensure_agent_ready;
|
|
133
140
|
this.default_model = options.default_model;
|
|
@@ -348,19 +355,57 @@ export class AgentSessions implements AgentSessionsApi<AgentSession> {
|
|
|
348
355
|
await this.apply_session_defaults(session);
|
|
349
356
|
},
|
|
350
357
|
...(this.resolve_model ? { resolve_model: this.resolve_model } : {}),
|
|
358
|
+
list_approvals: async (session_id) => this.list_session_approvals(session_id),
|
|
359
|
+
get_approval_mode: async (session_id) => {
|
|
360
|
+
const shell = this.require_shell();
|
|
361
|
+
return shell.approval_mode({ session_id });
|
|
362
|
+
},
|
|
363
|
+
set_approval_mode: async (session_id, { mode }) => {
|
|
364
|
+
const shell = this.require_shell();
|
|
365
|
+
return shell.set_approval_mode({ session_id, mode });
|
|
366
|
+
},
|
|
367
|
+
resolve_approval: async (session_id, { approval_id, decision }) => {
|
|
368
|
+
const approval = this.list_session_approvals(session_id)
|
|
369
|
+
.find((item) => item.approval_id === approval_id);
|
|
370
|
+
if (!approval) return { success: false, approval_id, decision };
|
|
371
|
+
return decision === "approved"
|
|
372
|
+
? await this.require_shell().approve({ approval_id })
|
|
373
|
+
: await this.require_shell().deny({ approval_id });
|
|
374
|
+
},
|
|
351
375
|
});
|
|
352
376
|
this.sessions_by_id.set(resolved_session_id, created);
|
|
353
377
|
return created;
|
|
354
378
|
}
|
|
355
379
|
|
|
380
|
+
private require_shell(): Shell {
|
|
381
|
+
const shell = this.get_shell();
|
|
382
|
+
if (!shell) throw new Error("Session shell is not configured");
|
|
383
|
+
return shell;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
private list_session_approvals(session_id: string): SessionApproval[] {
|
|
387
|
+
return (this.get_shell()?.approvals() || [])
|
|
388
|
+
.filter((approval) => approval.session_id === session_id)
|
|
389
|
+
.map((approval) => ({
|
|
390
|
+
approval_id: approval.approval_id,
|
|
391
|
+
session_id,
|
|
392
|
+
...(approval.turn_id ? { turn_id: approval.turn_id } : {}),
|
|
393
|
+
...(approval.tool_call_id ? { tool_call_id: approval.tool_call_id } : {}),
|
|
394
|
+
tool_name: approval.tool_name,
|
|
395
|
+
command: approval.cmd,
|
|
396
|
+
cwd: approval.cwd,
|
|
397
|
+
reason: approval.reason,
|
|
398
|
+
operation: approval.operation,
|
|
399
|
+
created_at: approval.created_at,
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
|
|
356
403
|
private async apply_session_defaults(
|
|
357
404
|
session: AgentManagedSession,
|
|
358
405
|
): Promise<void> {
|
|
359
406
|
if (this.configured_session_ids.has(session.id)) return;
|
|
360
407
|
const persisted_model_id = String(session.config.modelId || "").trim();
|
|
361
|
-
if (persisted_model_id && this.
|
|
362
|
-
await session.set({ modelId: persisted_model_id });
|
|
363
|
-
} else if (this.default_model) {
|
|
408
|
+
if (!persisted_model_id && this.default_model) {
|
|
364
409
|
await session.set({
|
|
365
410
|
model: this.default_model,
|
|
366
411
|
...(this.default_model_id ? { modelId: this.default_model_id } : {}),
|
|
@@ -23,14 +23,6 @@ import type {
|
|
|
23
23
|
RemoteAgentPluginActionInput,
|
|
24
24
|
RemoteAgentPluginActionResult,
|
|
25
25
|
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
26
|
-
import type {
|
|
27
|
-
ShellApprovalMode,
|
|
28
|
-
ShellApprovalDecisionResult,
|
|
29
|
-
ShellApprovalModeUpdateResult,
|
|
30
|
-
ShellApprovalModeOption,
|
|
31
|
-
ShellSessionApprovalModeView,
|
|
32
|
-
ShellApprovalView,
|
|
33
|
-
} from "@downcity/shell";
|
|
34
26
|
import type { RemoteAgentTransport } from "@/agent/remote/RemoteTransport.js";
|
|
35
27
|
import { RemoteSession } from "@/agent/remote/RemoteSession.js";
|
|
36
28
|
import { create_remote_agent_transport } from "@/agent/remote/TransportFactory.js";
|
|
@@ -57,7 +49,7 @@ export class RemoteAgent {
|
|
|
57
49
|
*
|
|
58
50
|
* 关键点(中文)
|
|
59
51
|
* - 这是 RemoteAgent 顶层能力,不绑定某个 session。
|
|
60
|
-
* - Shell approval
|
|
52
|
+
* - Shell approval 通过具体 RemoteSession 处理。
|
|
61
53
|
*/
|
|
62
54
|
async runPluginAction(
|
|
63
55
|
input: RemoteAgentPluginActionInput,
|
|
@@ -77,51 +69,6 @@ export class RemoteAgent {
|
|
|
77
69
|
});
|
|
78
70
|
}
|
|
79
71
|
|
|
80
|
-
/**
|
|
81
|
-
* 列出远程 Agent 的 shell pending approvals。
|
|
82
|
-
*/
|
|
83
|
-
async approvals(): Promise<ShellApprovalView[]> {
|
|
84
|
-
return await this.transport.approvals();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 列出远程 Agent 显式设置过的 shell approval 模式。
|
|
89
|
-
*/
|
|
90
|
-
async approval_modes(): Promise<ShellApprovalModeOption[]> {
|
|
91
|
-
return await this.transport.approval_modes();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 读取远程 Agent 指定 session 的 shell approval 模式。
|
|
96
|
-
*/
|
|
97
|
-
async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
|
|
98
|
-
return await this.transport.approval_mode(input);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 设置远程 Agent 指定 session 的 shell approval 模式。
|
|
103
|
-
*/
|
|
104
|
-
async set_approval_mode(input: {
|
|
105
|
-
session_id: string;
|
|
106
|
-
mode: ShellApprovalMode;
|
|
107
|
-
}): Promise<ShellApprovalModeUpdateResult> {
|
|
108
|
-
return await this.transport.set_approval_mode(input);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 批准远程 Agent 的 shell approval。
|
|
113
|
-
*/
|
|
114
|
-
async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
115
|
-
return await this.transport.approve(input);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 拒绝远程 Agent 的 shell approval。
|
|
120
|
-
*/
|
|
121
|
-
async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
122
|
-
return await this.transport.deny(input);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
72
|
/**
|
|
126
73
|
* 关闭远程 transport。
|
|
127
74
|
*
|