@downcity/agent 1.1.113 → 1.1.119
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 +39 -0
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +53 -0
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +4 -0
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +18 -2
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentLifecycleService.d.ts +6 -0
- package/bin/agent/local/services/AgentLifecycleService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentLifecycleService.js +4 -0
- package/bin/agent/local/services/AgentLifecycleService.js.map +1 -1
- package/bin/agent/remote/RemoteAgent.d.ts +35 -1
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +37 -1
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +22 -0
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +17 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +63 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +16 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +18 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +7 -1
- package/bin/executor/Executor.js.map +1 -1
- package/bin/index.d.ts +0 -1
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +0 -1
- package/bin/index.js.map +1 -1
- package/bin/rpc/Client.d.ts +28 -0
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +63 -0
- package/bin/rpc/Client.js.map +1 -1
- package/bin/rpc/server/InternalHandlers.d.ts.map +1 -1
- package/bin/rpc/server/InternalHandlers.js +54 -0
- package/bin/rpc/server/InternalHandlers.js.map +1 -1
- package/bin/rpc/server/ServerTypes.d.ts +5 -0
- package/bin/rpc/server/ServerTypes.d.ts.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +9 -0
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +2 -2
- package/bin/types/config/DowncityConfig.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +53 -0
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/package.json +4 -3
- package/scripts/linux-bubblewrap-sandbox.test.mjs +1 -1
- package/scripts/shell-sandbox-preflight.test.mjs +1 -1
- package/src/agent/local/Agent.ts +68 -0
- package/src/agent/local/services/AgentAssemblyService.ts +23 -2
- package/src/agent/local/services/AgentLifecycleService.ts +11 -0
- package/src/agent/remote/RemoteAgent.ts +54 -1
- package/src/agent/remote/RemoteTransport.ts +23 -0
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +101 -0
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +35 -0
- package/src/executor/Executor.ts +12 -2
- package/src/index.ts +0 -1
- package/src/rpc/Client.ts +80 -0
- package/src/rpc/server/InternalHandlers.ts +55 -0
- package/src/rpc/server/ServerTypes.ts +5 -0
- package/src/types/agent/AgentOptions.ts +10 -0
- package/src/types/config/DowncityConfig.ts +2 -2
- package/src/types/rpc/RpcProtocol.ts +59 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/executor/tools/shell/ShellToolBridge.d.ts +0 -79
- package/bin/executor/tools/shell/ShellToolBridge.d.ts.map +0 -1
- package/bin/executor/tools/shell/ShellToolBridge.js +0 -320
- package/bin/executor/tools/shell/ShellToolBridge.js.map +0 -1
- package/bin/executor/tools/shell/ShellToolDefinition.d.ts +0 -116
- package/bin/executor/tools/shell/ShellToolDefinition.d.ts.map +0 -1
- package/bin/executor/tools/shell/ShellToolDefinition.js +0 -369
- package/bin/executor/tools/shell/ShellToolDefinition.js.map +0 -1
- package/bin/executor/tools/shell/ShellToolFormatting.d.ts +0 -17
- package/bin/executor/tools/shell/ShellToolFormatting.d.ts.map +0 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js +0 -36
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +0 -1
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts +0 -61
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts.map +0 -1
- package/bin/executor/tools/shell/ShellToolSchemas.js +0 -130
- package/bin/executor/tools/shell/ShellToolSchemas.js.map +0 -1
- package/bin/executor/tools/shell/types/Shell.d.ts +0 -115
- package/bin/executor/tools/shell/types/Shell.d.ts.map +0 -1
- package/bin/executor/tools/shell/types/Shell.js +0 -9
- package/bin/executor/tools/shell/types/Shell.js.map +0 -1
- package/bin/executor/tools/shell/types/ShellPlugin.d.ts +0 -258
- package/bin/executor/tools/shell/types/ShellPlugin.d.ts.map +0 -1
- package/bin/executor/tools/shell/types/ShellPlugin.js +0 -9
- package/bin/executor/tools/shell/types/ShellPlugin.js.map +0 -1
- package/bin/sandbox/LinuxBubblewrapSandbox.d.ts +0 -19
- package/bin/sandbox/LinuxBubblewrapSandbox.d.ts.map +0 -1
- package/bin/sandbox/LinuxBubblewrapSandbox.js +0 -186
- package/bin/sandbox/LinuxBubblewrapSandbox.js.map +0 -1
- package/bin/sandbox/MacOsSeatbeltSandbox.d.ts +0 -16
- package/bin/sandbox/MacOsSeatbeltSandbox.d.ts.map +0 -1
- package/bin/sandbox/MacOsSeatbeltSandbox.js +0 -154
- package/bin/sandbox/MacOsSeatbeltSandbox.js.map +0 -1
- package/bin/sandbox/SandboxConfigResolver.d.ts +0 -37
- package/bin/sandbox/SandboxConfigResolver.d.ts.map +0 -1
- package/bin/sandbox/SandboxConfigResolver.js +0 -130
- package/bin/sandbox/SandboxConfigResolver.js.map +0 -1
- package/bin/sandbox/SandboxPreflight.d.ts +0 -73
- package/bin/sandbox/SandboxPreflight.d.ts.map +0 -1
- package/bin/sandbox/SandboxPreflight.js +0 -122
- package/bin/sandbox/SandboxPreflight.js.map +0 -1
- package/bin/sandbox/SandboxRunner.d.ts +0 -61
- package/bin/sandbox/SandboxRunner.d.ts.map +0 -1
- package/bin/sandbox/SandboxRunner.js +0 -107
- package/bin/sandbox/SandboxRunner.js.map +0 -1
- package/bin/sandbox/UnrestrictedSandbox.d.ts +0 -16
- package/bin/sandbox/UnrestrictedSandbox.d.ts.map +0 -1
- package/bin/sandbox/UnrestrictedSandbox.js +0 -39
- package/bin/sandbox/UnrestrictedSandbox.js.map +0 -1
- package/bin/sandbox/types/Sandbox.d.ts +0 -130
- package/bin/sandbox/types/Sandbox.d.ts.map +0 -1
- package/bin/sandbox/types/Sandbox.js +0 -10
- package/bin/sandbox/types/Sandbox.js.map +0 -1
- package/bin/sandbox/types/SandboxRuntime.d.ts +0 -370
- package/bin/sandbox/types/SandboxRuntime.d.ts.map +0 -1
- package/bin/sandbox/types/SandboxRuntime.js +0 -10
- package/bin/sandbox/types/SandboxRuntime.js.map +0 -1
- package/src/executor/tools/shell/ShellToolBridge.ts +0 -412
- package/src/executor/tools/shell/ShellToolDefinition.ts +0 -524
- package/src/executor/tools/shell/ShellToolFormatting.ts +0 -34
- package/src/executor/tools/shell/ShellToolSchemas.ts +0 -139
- package/src/executor/tools/shell/types/Shell.ts +0 -123
- package/src/executor/tools/shell/types/ShellPlugin.ts +0 -278
- package/src/sandbox/LinuxBubblewrapSandbox.ts +0 -222
- package/src/sandbox/MacOsSeatbeltSandbox.ts +0 -191
- package/src/sandbox/SandboxConfigResolver.ts +0 -152
- package/src/sandbox/SandboxPreflight.ts +0 -205
- package/src/sandbox/SandboxRunner.ts +0 -151
- package/src/sandbox/UnrestrictedSandbox.ts +0 -53
- package/src/sandbox/types/Sandbox.ts +0 -144
- package/src/sandbox/types/SandboxRuntime.ts +0 -440
|
@@ -24,6 +24,14 @@ import type {
|
|
|
24
24
|
RemoteAgentTransport,
|
|
25
25
|
TransportSubscription,
|
|
26
26
|
} from "@/agent/remote/RemoteTransport.js";
|
|
27
|
+
import type {
|
|
28
|
+
ShellApprovalMode,
|
|
29
|
+
ShellApprovalDecisionResult,
|
|
30
|
+
ShellApprovalModeUpdateResult,
|
|
31
|
+
ShellApprovalModeOption,
|
|
32
|
+
ShellSessionApprovalModeView,
|
|
33
|
+
ShellApprovalView,
|
|
34
|
+
} from "@downcity/shell";
|
|
27
35
|
|
|
28
36
|
type SdkEventsReadyFrame = {
|
|
29
37
|
/** SDK HTTP events 连接内部 ready 标记。 */
|
|
@@ -264,6 +272,99 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
264
272
|
}
|
|
265
273
|
return payload;
|
|
266
274
|
}
|
|
275
|
+
|
|
276
|
+
async approvals(): Promise<ShellApprovalView[]> {
|
|
277
|
+
const payload = await read_http_json<{
|
|
278
|
+
success?: boolean;
|
|
279
|
+
error?: string;
|
|
280
|
+
approvals?: ShellApprovalView[];
|
|
281
|
+
}>(`${this.base_url}/api/shell/approvals`, {
|
|
282
|
+
headers: this.headers(),
|
|
283
|
+
});
|
|
284
|
+
if (!payload.success || !Array.isArray(payload.approvals)) {
|
|
285
|
+
throw new Error(String(payload.error || "Remote shell approvals failed"));
|
|
286
|
+
}
|
|
287
|
+
return payload.approvals;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async approval_modes(): Promise<ShellApprovalModeOption[]> {
|
|
291
|
+
const payload = await read_http_json<{
|
|
292
|
+
success?: boolean;
|
|
293
|
+
error?: string;
|
|
294
|
+
modes?: ShellApprovalModeOption[];
|
|
295
|
+
}>(`${this.base_url}/api/shell/approval-modes`, {
|
|
296
|
+
headers: this.headers(),
|
|
297
|
+
});
|
|
298
|
+
if (!payload.success || !Array.isArray(payload.modes)) {
|
|
299
|
+
throw new Error(String(payload.error || "Remote shell approval modes failed"));
|
|
300
|
+
}
|
|
301
|
+
return payload.modes;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
|
|
305
|
+
const session_id = String(input.session_id || "").trim();
|
|
306
|
+
const payload = await read_http_json<{
|
|
307
|
+
success?: boolean;
|
|
308
|
+
error?: string;
|
|
309
|
+
session_id?: string;
|
|
310
|
+
mode?: ShellApprovalMode;
|
|
311
|
+
}>(`${this.base_url}/api/shell/approval-mode?session_id=${encodeURIComponent(session_id)}`, {
|
|
312
|
+
headers: this.headers(),
|
|
313
|
+
});
|
|
314
|
+
if (!payload.success || !payload.session_id || !payload.mode) {
|
|
315
|
+
throw new Error(String(payload.error || "Remote shell approval mode failed"));
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
session_id: payload.session_id,
|
|
319
|
+
mode: payload.mode,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async set_approval_mode(input: {
|
|
324
|
+
session_id: string;
|
|
325
|
+
mode: ShellApprovalMode;
|
|
326
|
+
}): Promise<ShellApprovalModeUpdateResult> {
|
|
327
|
+
const payload = await read_http_json<ShellApprovalModeUpdateResult & {
|
|
328
|
+
error?: string;
|
|
329
|
+
}>(`${this.base_url}/api/shell/approval-mode`, {
|
|
330
|
+
method: "POST",
|
|
331
|
+
headers: this.headers({
|
|
332
|
+
"Content-Type": "application/json",
|
|
333
|
+
}),
|
|
334
|
+
body: JSON.stringify(input),
|
|
335
|
+
});
|
|
336
|
+
if (payload.success !== true) {
|
|
337
|
+
throw new Error(String(payload.error || "Remote shell approval mode update failed"));
|
|
338
|
+
}
|
|
339
|
+
return payload;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
343
|
+
return await this.run_shell_decision("approve", input.approval_id);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
347
|
+
return await this.run_shell_decision("deny", input.approval_id);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private async run_shell_decision(
|
|
351
|
+
action: "approve" | "deny",
|
|
352
|
+
approval_id: string,
|
|
353
|
+
): Promise<ShellApprovalDecisionResult> {
|
|
354
|
+
const payload = await read_http_json<ShellApprovalDecisionResult & {
|
|
355
|
+
error?: string;
|
|
356
|
+
}>(`${this.base_url}/api/shell/${action}`, {
|
|
357
|
+
method: "POST",
|
|
358
|
+
headers: this.headers({
|
|
359
|
+
"Content-Type": "application/json",
|
|
360
|
+
}),
|
|
361
|
+
body: JSON.stringify({ approval_id }),
|
|
362
|
+
});
|
|
363
|
+
if (typeof payload.success !== "boolean") {
|
|
364
|
+
throw new Error(String(payload.error || `Remote shell ${action} failed`));
|
|
365
|
+
}
|
|
366
|
+
return payload;
|
|
367
|
+
}
|
|
267
368
|
}
|
|
268
369
|
|
|
269
370
|
async function read_http_json<T>(input: string, init?: RequestInit): Promise<T> {
|
|
@@ -25,6 +25,14 @@ import type {
|
|
|
25
25
|
RemoteAgentTransport,
|
|
26
26
|
TransportSubscription,
|
|
27
27
|
} from "@/agent/remote/RemoteTransport.js";
|
|
28
|
+
import type {
|
|
29
|
+
ShellApprovalMode,
|
|
30
|
+
ShellApprovalDecisionResult,
|
|
31
|
+
ShellApprovalModeUpdateResult,
|
|
32
|
+
ShellApprovalModeOption,
|
|
33
|
+
ShellSessionApprovalModeView,
|
|
34
|
+
ShellApprovalView,
|
|
35
|
+
} from "@downcity/shell";
|
|
28
36
|
|
|
29
37
|
/**
|
|
30
38
|
* 本机 RPC transport。
|
|
@@ -113,6 +121,33 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
113
121
|
});
|
|
114
122
|
}
|
|
115
123
|
|
|
124
|
+
async approvals(): Promise<ShellApprovalView[]> {
|
|
125
|
+
return await this.client.list_shell_approvals();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async approval_modes(): Promise<ShellApprovalModeOption[]> {
|
|
129
|
+
return await this.client.list_shell_approval_modes();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
|
|
133
|
+
return await this.client.get_shell_approval_mode(input.session_id);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async set_approval_mode(input: {
|
|
137
|
+
session_id: string;
|
|
138
|
+
mode: ShellApprovalMode;
|
|
139
|
+
}): Promise<ShellApprovalModeUpdateResult> {
|
|
140
|
+
return await this.client.set_shell_approval_mode(input);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
144
|
+
return await this.client.approve_shell_approval(input.approval_id);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
148
|
+
return await this.client.deny_shell_approval(input.approval_id);
|
|
149
|
+
}
|
|
150
|
+
|
|
116
151
|
async close(): Promise<void> {
|
|
117
152
|
await this.client.close();
|
|
118
153
|
}
|
package/src/executor/Executor.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { streamText, type LanguageModel, type Tool } from "ai";
|
|
11
|
+
import { withShellRunScope } from "@downcity/shell";
|
|
11
12
|
import { SessionHistoryWriter } from "@executor/composer/history/SessionHistoryWriter.js";
|
|
12
13
|
import type { SessionHistoryComposer } from "@executor/composer/history/SessionHistoryComposer.js";
|
|
13
14
|
import type { SessionHistoryStore } from "@/executor/store/history/SessionHistoryStore.js";
|
|
@@ -267,7 +268,15 @@ export class Executor implements SessionExecutor {
|
|
|
267
268
|
runContext: run_context,
|
|
268
269
|
},
|
|
269
270
|
async () =>
|
|
270
|
-
await
|
|
271
|
+
await withShellRunScope(
|
|
272
|
+
{
|
|
273
|
+
run_context: {
|
|
274
|
+
session_id: run_context.sessionId,
|
|
275
|
+
...(run_context.turnId ? { turn_id: run_context.turnId } : {}),
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
async () =>
|
|
279
|
+
await this.recovery_policy.run_with_retry({
|
|
271
280
|
query,
|
|
272
281
|
model: this.resolveModelOrThrow(),
|
|
273
282
|
run_context,
|
|
@@ -293,7 +302,8 @@ export class Executor implements SessionExecutor {
|
|
|
293
302
|
model,
|
|
294
303
|
next_run_context,
|
|
295
304
|
),
|
|
296
|
-
|
|
305
|
+
}),
|
|
306
|
+
),
|
|
297
307
|
);
|
|
298
308
|
return result;
|
|
299
309
|
} finally {
|
package/src/index.ts
CHANGED
package/src/rpc/Client.ts
CHANGED
|
@@ -37,6 +37,14 @@ import type {
|
|
|
37
37
|
RpcSessionSubscription,
|
|
38
38
|
RpcSystemPromptPayload,
|
|
39
39
|
} from "@/types/rpc/RpcProtocol.js";
|
|
40
|
+
import type {
|
|
41
|
+
ShellApprovalMode,
|
|
42
|
+
ShellApprovalDecisionResult,
|
|
43
|
+
ShellApprovalModeUpdateResult,
|
|
44
|
+
ShellApprovalModeOption,
|
|
45
|
+
ShellSessionApprovalModeView,
|
|
46
|
+
ShellApprovalView,
|
|
47
|
+
} from "@downcity/shell";
|
|
40
48
|
|
|
41
49
|
export type {
|
|
42
50
|
RpcClientEndpoint,
|
|
@@ -358,6 +366,78 @@ export class RpcClient {
|
|
|
358
366
|
});
|
|
359
367
|
}
|
|
360
368
|
|
|
369
|
+
/**
|
|
370
|
+
* 列出 shell approvals。
|
|
371
|
+
*/
|
|
372
|
+
async list_shell_approvals(): Promise<ShellApprovalView[]> {
|
|
373
|
+
const data = await this.request<{ approvals: ShellApprovalView[] }>({
|
|
374
|
+
method: "internal.shell.approvals",
|
|
375
|
+
});
|
|
376
|
+
return Array.isArray(data.approvals) ? data.approvals : [];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* 列出 shell approval 模式。
|
|
381
|
+
*/
|
|
382
|
+
async list_shell_approval_modes(): Promise<ShellApprovalModeOption[]> {
|
|
383
|
+
const data = await this.request<{ modes: ShellApprovalModeOption[] }>({
|
|
384
|
+
method: "internal.shell.approvalModes",
|
|
385
|
+
});
|
|
386
|
+
return Array.isArray(data.modes) ? data.modes : [];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* 读取 shell approval 模式。
|
|
391
|
+
*/
|
|
392
|
+
async get_shell_approval_mode(session_id: string): Promise<ShellSessionApprovalModeView> {
|
|
393
|
+
return await this.request<ShellSessionApprovalModeView>({
|
|
394
|
+
method: "internal.shell.approvalMode",
|
|
395
|
+
params: {
|
|
396
|
+
sessionId: session_id,
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* 设置 shell approval 模式。
|
|
403
|
+
*/
|
|
404
|
+
async set_shell_approval_mode(input: {
|
|
405
|
+
session_id: string;
|
|
406
|
+
mode: ShellApprovalMode;
|
|
407
|
+
}): Promise<ShellApprovalModeUpdateResult> {
|
|
408
|
+
return await this.request<ShellApprovalModeUpdateResult>({
|
|
409
|
+
method: "internal.shell.setApprovalMode",
|
|
410
|
+
params: {
|
|
411
|
+
sessionId: input.session_id,
|
|
412
|
+
mode: input.mode,
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* 批准 shell approval。
|
|
419
|
+
*/
|
|
420
|
+
async approve_shell_approval(approval_id: string): Promise<ShellApprovalDecisionResult> {
|
|
421
|
+
return await this.request<ShellApprovalDecisionResult>({
|
|
422
|
+
method: "internal.shell.approve",
|
|
423
|
+
params: {
|
|
424
|
+
approvalId: approval_id,
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* 拒绝 shell approval。
|
|
431
|
+
*/
|
|
432
|
+
async deny_shell_approval(approval_id: string): Promise<ShellApprovalDecisionResult> {
|
|
433
|
+
return await this.request<ShellApprovalDecisionResult>({
|
|
434
|
+
method: "internal.shell.deny",
|
|
435
|
+
params: {
|
|
436
|
+
approvalId: approval_id,
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
361
441
|
/**
|
|
362
442
|
* 关闭底层连接。
|
|
363
443
|
*/
|
|
@@ -154,11 +154,66 @@ export async function handleInternalRpcRequest(params: {
|
|
|
154
154
|
});
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
|
+
case "internal.shell.approvals": {
|
|
158
|
+
const shell = requireShell(options);
|
|
159
|
+
write_success(request.id, {
|
|
160
|
+
approvals: shell.approvals(),
|
|
161
|
+
});
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
case "internal.shell.approvalModes": {
|
|
165
|
+
const shell = requireShell(options);
|
|
166
|
+
write_success(request.id, {
|
|
167
|
+
modes: shell.approval_modes(),
|
|
168
|
+
});
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
case "internal.shell.approvalMode": {
|
|
172
|
+
const shell = requireShell(options);
|
|
173
|
+
const result = shell.approval_mode({
|
|
174
|
+
session_id: String(request.params.sessionId || "").trim(),
|
|
175
|
+
});
|
|
176
|
+
write_success(request.id, result);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
case "internal.shell.setApprovalMode": {
|
|
180
|
+
const shell = requireShell(options);
|
|
181
|
+
const result = shell.set_approval_mode({
|
|
182
|
+
session_id: String(request.params.sessionId || "").trim(),
|
|
183
|
+
mode: request.params.mode,
|
|
184
|
+
});
|
|
185
|
+
write_success(request.id, result);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
case "internal.shell.approve": {
|
|
189
|
+
const shell = requireShell(options);
|
|
190
|
+
const result = await shell.approve({
|
|
191
|
+
approval_id: String(request.params.approvalId || "").trim(),
|
|
192
|
+
});
|
|
193
|
+
write_success(request.id, result);
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
case "internal.shell.deny": {
|
|
197
|
+
const shell = requireShell(options);
|
|
198
|
+
const result = await shell.deny({
|
|
199
|
+
approval_id: String(request.params.approvalId || "").trim(),
|
|
200
|
+
});
|
|
201
|
+
write_success(request.id, result);
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
157
204
|
default:
|
|
158
205
|
return false;
|
|
159
206
|
}
|
|
160
207
|
}
|
|
161
208
|
|
|
209
|
+
function requireShell(options: RpcRequestHandlerOptions) {
|
|
210
|
+
const shell = options.getShell?.();
|
|
211
|
+
if (!shell) {
|
|
212
|
+
throw new Error("Agent RPC server was started without Shell");
|
|
213
|
+
}
|
|
214
|
+
return shell;
|
|
215
|
+
}
|
|
216
|
+
|
|
162
217
|
function requireAgentContext(options: RpcRequestHandlerOptions): AgentContext {
|
|
163
218
|
const context = options.getAgentContext?.();
|
|
164
219
|
if (!context) {
|
|
@@ -10,6 +10,7 @@ import type { AgentSessionCollection } from "@/types/agent/AgentTypes.js";
|
|
|
10
10
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
11
11
|
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
12
12
|
import type { RpcEventFrame } from "@/types/rpc/RpcProtocol.js";
|
|
13
|
+
import type { Shell } from "@downcity/shell";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* RPC Server 启动参数。
|
|
@@ -25,6 +26,8 @@ export interface RpcServerStartOptions {
|
|
|
25
26
|
getAgentContext?: () => AgentContext;
|
|
26
27
|
/** Agent 运行态访问口。 */
|
|
27
28
|
getAgentRuntime?: () => AgentRuntime;
|
|
29
|
+
/** Shell 访问口。 */
|
|
30
|
+
getShell?: () => Shell | undefined;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
/**
|
|
@@ -37,6 +40,8 @@ export interface RpcRequestHandlerOptions {
|
|
|
37
40
|
getAgentContext?: () => AgentContext;
|
|
38
41
|
/** Agent 运行态访问口。 */
|
|
39
42
|
getAgentRuntime?: () => AgentRuntime;
|
|
43
|
+
/** Shell 访问口。 */
|
|
44
|
+
getShell?: () => Shell | undefined;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
/**
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { Tool } from "ai";
|
|
10
|
+
import type { Shell } from "@downcity/shell";
|
|
10
11
|
import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
|
|
11
12
|
import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
12
13
|
import type { RpcServerInstance } from "@/rpc/Server.js";
|
|
@@ -51,6 +52,15 @@ export interface AgentOptions {
|
|
|
51
52
|
*/
|
|
52
53
|
tools?: Record<string, Tool>;
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* 当前 agent 内建 shell 能力。
|
|
57
|
+
*
|
|
58
|
+
* 关键点(中文)
|
|
59
|
+
* - Shell 不是 plugin,而是 agent 直接挂载的内建工具对象。
|
|
60
|
+
* - 未传入时,Agent 不会自动注入 shell tools。
|
|
61
|
+
*/
|
|
62
|
+
shell?: Shell;
|
|
63
|
+
|
|
54
64
|
/**
|
|
55
65
|
* 调用方显式传入的静态基础指令。
|
|
56
66
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type { LlmConfig } from "@/types/config/LlmConfig.js";
|
|
9
9
|
import type { ExecutionBindingConfig } from "@/types/config/ExecutionBinding.js";
|
|
10
10
|
import type { JsonObject } from "@/types/common/Json.js";
|
|
11
|
-
import type { SandboxProjectConfig } from "
|
|
11
|
+
import type { SandboxProjectConfig } from "@downcity/shell/sandbox/types/Sandbox.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 单个聊天渠道配置。
|
|
@@ -165,7 +165,7 @@ export interface DowncityConfig {
|
|
|
165
165
|
* shell / CLI 执行 sandbox 配置。
|
|
166
166
|
*
|
|
167
167
|
* 关键点(中文)
|
|
168
|
-
* -
|
|
168
|
+
* - 当前只作用于内建 shell 这条命令执行链。
|
|
169
169
|
* - 这里不表达审批、用户授权与复杂策略系统,只表达最小边界。
|
|
170
170
|
*/
|
|
171
171
|
sandbox?: SandboxProjectConfig;
|
|
@@ -17,6 +17,7 @@ import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
|
17
17
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
18
18
|
import type { JsonObject, JsonValue } from "@/types/common/Json.js";
|
|
19
19
|
import type { PluginStateControlAction } from "@/plugin/types/Plugin.js";
|
|
20
|
+
import type { ShellApprovalMode } from "@downcity/shell";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* RPC 请求。
|
|
@@ -231,6 +232,64 @@ export type RpcRequest =
|
|
|
231
232
|
/** action payload。 */
|
|
232
233
|
payload?: JsonValue;
|
|
233
234
|
};
|
|
235
|
+
}
|
|
236
|
+
| {
|
|
237
|
+
/** 请求 id,用于匹配响应。 */
|
|
238
|
+
id: string;
|
|
239
|
+
/** 列出 shell approvals。 */
|
|
240
|
+
method: "internal.shell.approvals";
|
|
241
|
+
}
|
|
242
|
+
| {
|
|
243
|
+
/** 请求 id,用于匹配响应。 */
|
|
244
|
+
id: string;
|
|
245
|
+
/** 列出 shell approval 模式。 */
|
|
246
|
+
method: "internal.shell.approvalModes";
|
|
247
|
+
}
|
|
248
|
+
| {
|
|
249
|
+
/** 请求 id,用于匹配响应。 */
|
|
250
|
+
id: string;
|
|
251
|
+
/** 读取 shell approval 模式。 */
|
|
252
|
+
method: "internal.shell.approvalMode";
|
|
253
|
+
/** session 参数。 */
|
|
254
|
+
params: {
|
|
255
|
+
/** session id。 */
|
|
256
|
+
sessionId: string;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
| {
|
|
260
|
+
/** 请求 id,用于匹配响应。 */
|
|
261
|
+
id: string;
|
|
262
|
+
/** 设置 shell approval 模式。 */
|
|
263
|
+
method: "internal.shell.setApprovalMode";
|
|
264
|
+
/** session 模式参数。 */
|
|
265
|
+
params: {
|
|
266
|
+
/** session id。 */
|
|
267
|
+
sessionId: string;
|
|
268
|
+
/** approval 模式。 */
|
|
269
|
+
mode: ShellApprovalMode;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
| {
|
|
273
|
+
/** 请求 id,用于匹配响应。 */
|
|
274
|
+
id: string;
|
|
275
|
+
/** 批准 shell approval。 */
|
|
276
|
+
method: "internal.shell.approve";
|
|
277
|
+
/** approval 参数。 */
|
|
278
|
+
params: {
|
|
279
|
+
/** approval id。 */
|
|
280
|
+
approvalId: string;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
| {
|
|
284
|
+
/** 请求 id,用于匹配响应。 */
|
|
285
|
+
id: string;
|
|
286
|
+
/** 拒绝 shell approval。 */
|
|
287
|
+
method: "internal.shell.deny";
|
|
288
|
+
/** approval 参数。 */
|
|
289
|
+
params: {
|
|
290
|
+
/** approval id。 */
|
|
291
|
+
approvalId: string;
|
|
292
|
+
};
|
|
234
293
|
};
|
|
235
294
|
|
|
236
295
|
/**
|