@downcity/agent 1.1.111 → 1.1.118
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 +22 -0
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +31 -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 +26 -1
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +40 -0
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +14 -1
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +11 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +54 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +10 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +16 -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/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
- package/bin/index.d.ts +1 -2
- 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 +13 -0
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +31 -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 +30 -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/agent/AgentTypes.d.ts +1 -0
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/agent/RemoteAgentPluginAction.d.ts +46 -0
- package/bin/types/agent/RemoteAgentPluginAction.d.ts.map +1 -0
- package/bin/types/agent/RemoteAgentPluginAction.js +9 -0
- package/bin/types/agent/RemoteAgentPluginAction.js.map +1 -0
- 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 +25 -0
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionEvent.d.ts +24 -4
- package/bin/types/sdk/AgentSessionEvent.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 +38 -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 +52 -0
- package/src/agent/remote/RemoteTransport.ts +16 -0
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +83 -0
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +28 -0
- package/src/executor/Executor.ts +12 -2
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -0
- package/src/index.ts +2 -1
- package/src/rpc/Client.ts +38 -0
- package/src/rpc/server/InternalHandlers.ts +31 -0
- package/src/rpc/server/ServerTypes.ts +5 -0
- package/src/types/agent/AgentOptions.ts +10 -0
- package/src/types/agent/AgentTypes.ts +4 -0
- package/src/types/agent/RemoteAgentPluginAction.ts +52 -0
- package/src/types/config/DowncityConfig.ts +2 -2
- package/src/types/rpc/RpcProtocol.ts +28 -0
- package/src/types/sdk/AgentSessionEvent.ts +28 -4
- 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 -114
- package/bin/executor/tools/shell/ShellToolDefinition.d.ts.map +0 -1
- package/bin/executor/tools/shell/ShellToolDefinition.js +0 -367
- 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 -60
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts.map +0 -1
- package/bin/executor/tools/shell/ShellToolSchemas.js +0 -126
- package/bin/executor/tools/shell/ShellToolSchemas.js.map +0 -1
- package/bin/executor/tools/shell/types/Shell.d.ts +0 -109
- 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 -252
- 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 -521
- package/src/executor/tools/shell/ShellToolFormatting.ts +0 -34
- package/src/executor/tools/shell/ShellToolSchemas.ts +0 -135
- package/src/executor/tools/shell/types/Shell.ts +0 -116
- package/src/executor/tools/shell/types/ShellPlugin.ts +0 -271
- 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
|
@@ -15,9 +15,15 @@ import type {
|
|
|
15
15
|
AgentSessionInfo,
|
|
16
16
|
AgentSessionSummaryPage,
|
|
17
17
|
AgentSessionSystemSnapshot,
|
|
18
|
+
RemoteAgentPluginActionInput,
|
|
19
|
+
RemoteAgentPluginActionResult,
|
|
18
20
|
} from "@/types/agent/AgentTypes.js";
|
|
19
21
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
20
22
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
23
|
+
import type {
|
|
24
|
+
ShellApprovalDecisionResult,
|
|
25
|
+
ShellApprovalView,
|
|
26
|
+
} from "@downcity/shell";
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* Transport 持有的事件订阅句柄。
|
|
@@ -66,6 +72,16 @@ export type RemoteAgentTransport = RemoteSessionTransport & {
|
|
|
66
72
|
create_session(input?: AgentCreateSessionInput): Promise<AgentSessionInfo>;
|
|
67
73
|
/** 列出 sessions。 */
|
|
68
74
|
list_sessions(input?: AgentListSessionsInput): Promise<AgentSessionSummaryPage>;
|
|
75
|
+
/** 执行远程 Agent runtime 内的 plugin action。 */
|
|
76
|
+
run_plugin_action(
|
|
77
|
+
input: RemoteAgentPluginActionInput,
|
|
78
|
+
): Promise<RemoteAgentPluginActionResult>;
|
|
79
|
+
/** 列出 shell approvals。 */
|
|
80
|
+
approvals(): Promise<ShellApprovalView[]>;
|
|
81
|
+
/** 批准 shell approval。 */
|
|
82
|
+
approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult>;
|
|
83
|
+
/** 拒绝 shell approval。 */
|
|
84
|
+
deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult>;
|
|
69
85
|
/** 关闭 transport 持有的长期连接。 */
|
|
70
86
|
close?(): Promise<void>;
|
|
71
87
|
};
|
|
@@ -15,6 +15,8 @@ import type {
|
|
|
15
15
|
AgentSessionInfo,
|
|
16
16
|
AgentSessionSummaryPage,
|
|
17
17
|
AgentSessionSystemSnapshot,
|
|
18
|
+
RemoteAgentPluginActionInput,
|
|
19
|
+
RemoteAgentPluginActionResult,
|
|
18
20
|
} from "@/types/agent/AgentTypes.js";
|
|
19
21
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
20
22
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
@@ -22,6 +24,10 @@ import type {
|
|
|
22
24
|
RemoteAgentTransport,
|
|
23
25
|
TransportSubscription,
|
|
24
26
|
} from "@/agent/remote/RemoteTransport.js";
|
|
27
|
+
import type {
|
|
28
|
+
ShellApprovalDecisionResult,
|
|
29
|
+
ShellApprovalView,
|
|
30
|
+
} from "@downcity/shell";
|
|
25
31
|
|
|
26
32
|
type SdkEventsReadyFrame = {
|
|
27
33
|
/** SDK HTTP events 连接内部 ready 标记。 */
|
|
@@ -239,6 +245,70 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
239
245
|
}
|
|
240
246
|
return payload.page;
|
|
241
247
|
}
|
|
248
|
+
|
|
249
|
+
async run_plugin_action(
|
|
250
|
+
input: RemoteAgentPluginActionInput,
|
|
251
|
+
): Promise<RemoteAgentPluginActionResult> {
|
|
252
|
+
const payload = await read_http_action_json<RemoteAgentPluginActionResult>(
|
|
253
|
+
`${this.base_url}/api/plugins/action`,
|
|
254
|
+
{
|
|
255
|
+
method: "POST",
|
|
256
|
+
headers: this.headers({
|
|
257
|
+
"Content-Type": "application/json",
|
|
258
|
+
}),
|
|
259
|
+
body: JSON.stringify({
|
|
260
|
+
pluginName: input.plugin,
|
|
261
|
+
actionName: input.action,
|
|
262
|
+
...(input.payload !== undefined ? { payload: input.payload } : {}),
|
|
263
|
+
}),
|
|
264
|
+
},
|
|
265
|
+
);
|
|
266
|
+
if (typeof payload.success !== "boolean") {
|
|
267
|
+
throw new Error("Remote plugin action returned an invalid response");
|
|
268
|
+
}
|
|
269
|
+
return payload;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async approvals(): Promise<ShellApprovalView[]> {
|
|
273
|
+
const payload = await read_http_json<{
|
|
274
|
+
success?: boolean;
|
|
275
|
+
error?: string;
|
|
276
|
+
approvals?: ShellApprovalView[];
|
|
277
|
+
}>(`${this.base_url}/api/shell/approvals`, {
|
|
278
|
+
headers: this.headers(),
|
|
279
|
+
});
|
|
280
|
+
if (!payload.success || !Array.isArray(payload.approvals)) {
|
|
281
|
+
throw new Error(String(payload.error || "Remote shell approvals failed"));
|
|
282
|
+
}
|
|
283
|
+
return payload.approvals;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
287
|
+
return await this.run_shell_decision("approve", input.approval_id);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
291
|
+
return await this.run_shell_decision("deny", input.approval_id);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private async run_shell_decision(
|
|
295
|
+
action: "approve" | "deny",
|
|
296
|
+
approval_id: string,
|
|
297
|
+
): Promise<ShellApprovalDecisionResult> {
|
|
298
|
+
const payload = await read_http_json<ShellApprovalDecisionResult & {
|
|
299
|
+
error?: string;
|
|
300
|
+
}>(`${this.base_url}/api/shell/${action}`, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
headers: this.headers({
|
|
303
|
+
"Content-Type": "application/json",
|
|
304
|
+
}),
|
|
305
|
+
body: JSON.stringify({ approval_id }),
|
|
306
|
+
});
|
|
307
|
+
if (typeof payload.success !== "boolean") {
|
|
308
|
+
throw new Error(String(payload.error || `Remote shell ${action} failed`));
|
|
309
|
+
}
|
|
310
|
+
return payload;
|
|
311
|
+
}
|
|
242
312
|
}
|
|
243
313
|
|
|
244
314
|
async function read_http_json<T>(input: string, init?: RequestInit): Promise<T> {
|
|
@@ -251,6 +321,19 @@ async function read_http_json<T>(input: string, init?: RequestInit): Promise<T>
|
|
|
251
321
|
return payload;
|
|
252
322
|
}
|
|
253
323
|
|
|
324
|
+
async function read_http_action_json<T extends { success?: boolean }>(
|
|
325
|
+
input: string,
|
|
326
|
+
init?: RequestInit,
|
|
327
|
+
): Promise<T> {
|
|
328
|
+
const response = await fetch(input, init);
|
|
329
|
+
const payload = (await response.json().catch(() => ({}))) as T;
|
|
330
|
+
if (!response.ok && typeof payload.success !== "boolean") {
|
|
331
|
+
const message = extract_error_message(payload);
|
|
332
|
+
throw new Error(message || `HTTP ${response.status}`);
|
|
333
|
+
}
|
|
334
|
+
return payload;
|
|
335
|
+
}
|
|
336
|
+
|
|
254
337
|
async function consume_http_event_stream(params: {
|
|
255
338
|
body: ReadableStream<Uint8Array>;
|
|
256
339
|
abort_controller: AbortController;
|
|
@@ -15,6 +15,8 @@ import type {
|
|
|
15
15
|
AgentSessionInfo,
|
|
16
16
|
AgentSessionSummaryPage,
|
|
17
17
|
AgentSessionSystemSnapshot,
|
|
18
|
+
RemoteAgentPluginActionInput,
|
|
19
|
+
RemoteAgentPluginActionResult,
|
|
18
20
|
} from "@/types/agent/AgentTypes.js";
|
|
19
21
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
20
22
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
@@ -23,6 +25,10 @@ import type {
|
|
|
23
25
|
RemoteAgentTransport,
|
|
24
26
|
TransportSubscription,
|
|
25
27
|
} from "@/agent/remote/RemoteTransport.js";
|
|
28
|
+
import type {
|
|
29
|
+
ShellApprovalDecisionResult,
|
|
30
|
+
ShellApprovalView,
|
|
31
|
+
} from "@downcity/shell";
|
|
26
32
|
|
|
27
33
|
/**
|
|
28
34
|
* 本机 RPC transport。
|
|
@@ -101,6 +107,28 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
101
107
|
return await this.client.list_sessions(input);
|
|
102
108
|
}
|
|
103
109
|
|
|
110
|
+
async run_plugin_action(
|
|
111
|
+
input: RemoteAgentPluginActionInput,
|
|
112
|
+
): Promise<RemoteAgentPluginActionResult> {
|
|
113
|
+
return await this.client.run_internal_plugin_action({
|
|
114
|
+
plugin_name: input.plugin,
|
|
115
|
+
action_name: input.action,
|
|
116
|
+
...(input.payload !== undefined ? { payload: input.payload } : {}),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async approvals(): Promise<ShellApprovalView[]> {
|
|
121
|
+
return await this.client.list_shell_approvals();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
125
|
+
return await this.client.approve_shell_approval(input.approval_id);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
|
|
129
|
+
return await this.client.deny_shell_approval(input.approval_id);
|
|
130
|
+
}
|
|
131
|
+
|
|
104
132
|
async close(): Promise<void> {
|
|
105
133
|
await this.client.close();
|
|
106
134
|
}
|
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 {
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Source: src/executor/composer/system/default/assets/core.prompt.ts.txt
|
|
7
|
-
const TEXT_MODULE_CONTENT = "你拥有且仅拥有当前项目 {{project_path}} 的使用权和修改权。当前年份是 {{current_year}} 年。\n1. `.downcity/` 是 Downcity 的运行时数据目录(通常不需要你手动读取/修改;系统会自动写入与注入)。结构与逻辑如下:\n - `.downcity/agents/<agentId>/sessions/` 是会话消息。\n - `.downcity/memory/` 是中长期记忆。\n - `.downcity/profile/Primary.md`、`.downcity/profile/other.md`:全局 profile 记忆;存在时会自动作为 system prompt 注入。\n - `.downcity/public/`:对外静态资源目录,通过 `GET /downcity/public/<path>` 访问;用于给外部访问的路径。不要存放敏感信息,Agent HTTP gateway 会把 `.downcity/public/` 暴露为 HTTP 静态资源:`GET /downcity/public/<path>`,你可以把该 URL 发给用户用于下载/查看生成的文件(注意不要暴露敏感信息)。\n - `.downcity/logs/<YYYY-MM-DD>.jsonl`:运行日志(JSONL);用于排查问题,避免把原始日志整段贴给用户。\n - `.downcity/.cache/`:幂等/去重缓存(ingress/egress);不要手动改。\n - `.downcity/.debug/`:调试产物(托管进程 pid/log/meta、适配器事件抓取等);仅在排查问题时查看。\n - `.downcity/data/`:小型持久化数据(预留)。\n - `.downcity/task/`:Task 目录。\n - `.downcity/sandbox/`:当前 agent 的本地命令执行 sandbox HOME/cache/tmp;shell 与 script 命令会共享它。\n2. PROFILE.md + SOUL.md + downcity.json 是你的一些配置文件,你不需要读取。\n\n# 最重要\n【关于命令执行工具】(重要)\n- 短命令、一次性命令优先使用 `shell_exec`。\n- 长任务、需要中途查状态、需要 stdin 交互时,使用 `shell_start` / `shell_status` / `shell_read` / `shell_write` / `shell_wait` / `shell_close`。\n- 先用 `shell_start` 启动命令并拿到 `shell_id`。\n- `shell_id` 是 shell 会话标识;它不是 chat `session_id`。\n- 长任务期间,优先使用 `shell_status` 查询进度,或使用 `shell_wait` 等待状态变化;不要自己写高频空轮询循环。\n- 只有在确实需要原始增量输出时,才使用 `shell_read` 按 `from_cursor` 继续读取。\n- 需要向进程 stdin 输入内容时,使用 `shell_write`。\n- 命令会话完成后若不再需要,使用 `shell_close` 主动释放资源。\n- 不要把原始超长 shell 输出直接转发给用户,应先总结。\n- shell 命令默认在 Safe Sandbox 中执行:项目目录可读写,网络可用,HOME 指向 `.downcity/sandbox/`,真实用户 HOME 与系统目录不可写。\n- 安装 Python 依赖时优先使用项目内 `.venv`,不要使用 `pip install --user`。\n- 需要全局安装、写宿主目录、访问宿主级能力时,可以请求 `sandbox: \"unrestricted\"`;必须提供清楚的 `reason`,等待用户确认后才能执行。\n- 不要尝试 `sudo`、Xcode Command Line Tools 安装、修改 SSH/keychain/shell profile,或执行明显破坏性命令;这些请求即使使用 unrestricted sandbox 也会被拒绝。\n- 用户拒绝 unrestricted sandbox 请求后,不要反复请求同一命令,应解释影响并给出项目内替代方案。\n- 下载模型、工具缓存、临时状态应自然落在 `.downcity/sandbox/` 或项目目录中,不要假设可复用真实用户缓存。\n\n# 默认决策与澄清\n- 默认先执行,再沟通:对低风险、可回滚、用户意图已经足够明显的请求,优先基于当前日期、时区、聊天上下文与常见默认值直接执行,不要在事件标题、默认平台、显然的时间表达上反复追问。\n- 只有当“缺失信息会实质改变结果”时才追问;例如:会影响日期/对象/金额/账户/发送目标,或会触发不可逆、高风险、涉隐私操作。\n- 处理时间表达时,优先使用当前环境提供的 `current_date`、`current_time` 与 `timezone`;如果入站 `<info>` 明确提供了 `user_timezone`,则优先按 `user_timezone` 解析,否则按 runtime clock 的 `timezone` 解析。像“今天/明天/下午两点/提前两小时”这类表达,应先解析为绝对时间,再执行,并在回复里明确写出绝对日期时间。\n- 当任务依赖外部权限、系统能力或第三方连接(如日历、提醒事项、聊天渠道、系统授权)时,先探测可用性,再决定是否承诺“我来创建/发送/写入”。\n- 如果探测结果显示被系统权限、宿主环境或连接状态阻塞,要直接说明真实阻塞点和下一步,而不是先给出“可以,我来做”的承诺后再多轮追问。\n- 若已经有足够信息可以一次完成多个低风险默认动作,应直接完成,并在结果里简短说明采用了哪些默认假设。\n\n# 很重要\n\n安全与边界\n- 不要执行破坏性命令(如 `rm -rf`、`git reset --hard`)除非用户明确要求。\n- 遇到 API Key、Token、Secret、环境变量、bot 凭据等密钥管理问题时,优先指导用户使用 Console(如 `Global / Env`、`Global / Channel Accounts`)维护,不要要求用户把密钥明文直接发送到当前聊天里。\n- 密钥列表能力只能返回已配置的 key 名与描述,不会返回密钥值。不要让用户把密钥“发给你自己”或继续尝试获取明文。\n";
|
|
7
|
+
const TEXT_MODULE_CONTENT = "你拥有且仅拥有当前项目 {{project_path}} 的使用权和修改权。当前年份是 {{current_year}} 年。\n1. `.downcity/` 是 Downcity 的运行时数据目录(通常不需要你手动读取/修改;系统会自动写入与注入)。结构与逻辑如下:\n - `.downcity/agents/<agentId>/sessions/` 是会话消息。\n - `.downcity/memory/` 是中长期记忆。\n - `.downcity/profile/Primary.md`、`.downcity/profile/other.md`:全局 profile 记忆;存在时会自动作为 system prompt 注入。\n - `.downcity/public/`:对外静态资源目录,通过 `GET /downcity/public/<path>` 访问;用于给外部访问的路径。不要存放敏感信息,Agent HTTP gateway 会把 `.downcity/public/` 暴露为 HTTP 静态资源:`GET /downcity/public/<path>`,你可以把该 URL 发给用户用于下载/查看生成的文件(注意不要暴露敏感信息)。\n - `.downcity/logs/<YYYY-MM-DD>.jsonl`:运行日志(JSONL);用于排查问题,避免把原始日志整段贴给用户。\n - `.downcity/.cache/`:幂等/去重缓存(ingress/egress);不要手动改。\n - `.downcity/.debug/`:调试产物(托管进程 pid/log/meta、适配器事件抓取等);仅在排查问题时查看。\n - `.downcity/data/`:小型持久化数据(预留)。\n - `.downcity/task/`:Task 目录。\n - `.downcity/sandbox/`:当前 agent 的本地命令执行 sandbox HOME/cache/tmp;shell 与 script 命令会共享它。\n2. PROFILE.md + SOUL.md + downcity.json 是你的一些配置文件,你不需要读取。\n\n# 最重要\n【关于命令执行工具】(重要)\n- 短命令、一次性命令优先使用 `shell_exec`。\n- 长任务、需要中途查状态、需要 stdin 交互时,使用 `shell_start` / `shell_status` / `shell_read` / `shell_write` / `shell_wait` / `shell_close`。\n- 先用 `shell_start` 启动命令并拿到 `shell_id`。\n- `shell_id` 是 shell 会话标识;它不是 chat `session_id`。\n- 长任务期间,优先使用 `shell_status` 查询进度,或使用 `shell_wait` 等待状态变化;不要自己写高频空轮询循环。\n- 只有在确实需要原始增量输出时,才使用 `shell_read` 按 `from_cursor` 继续读取。\n- 需要向进程 stdin 输入内容时,使用 `shell_write`。\n- 向 unrestricted shell session 使用 `shell_write` 时,每一次写入都必须提供清楚的 `reason`,并等待用户确认;`shell_start` 的审批只授权启动进程,不授权后续 stdin 写入。\n- 命令会话完成后若不再需要,使用 `shell_close` 主动释放资源。\n- 不要把原始超长 shell 输出直接转发给用户,应先总结。\n- shell 命令默认在 Safe Sandbox 中执行:项目目录可读写,网络可用,HOME 指向 `.downcity/sandbox/`,真实用户 HOME 与系统目录不可写。\n- 安装 Python 依赖时优先使用项目内 `.venv`,不要使用 `pip install --user`。\n- 需要全局安装、写宿主目录、访问宿主级能力时,可以请求 `sandbox: \"unrestricted\"`;必须提供清楚的 `reason`,等待用户确认后才能执行。\n- 不要尝试 `sudo`、Xcode Command Line Tools 安装、修改 SSH/keychain/shell profile,或执行明显破坏性命令;这些请求即使使用 unrestricted sandbox 也会被拒绝。\n- 用户拒绝 unrestricted sandbox 请求后,不要反复请求同一命令,应解释影响并给出项目内替代方案。\n- 下载模型、工具缓存、临时状态应自然落在 `.downcity/sandbox/` 或项目目录中,不要假设可复用真实用户缓存。\n\n# 默认决策与澄清\n- 默认先执行,再沟通:对低风险、可回滚、用户意图已经足够明显的请求,优先基于当前日期、时区、聊天上下文与常见默认值直接执行,不要在事件标题、默认平台、显然的时间表达上反复追问。\n- 只有当“缺失信息会实质改变结果”时才追问;例如:会影响日期/对象/金额/账户/发送目标,或会触发不可逆、高风险、涉隐私操作。\n- 处理时间表达时,优先使用当前环境提供的 `current_date`、`current_time` 与 `timezone`;如果入站 `<info>` 明确提供了 `user_timezone`,则优先按 `user_timezone` 解析,否则按 runtime clock 的 `timezone` 解析。像“今天/明天/下午两点/提前两小时”这类表达,应先解析为绝对时间,再执行,并在回复里明确写出绝对日期时间。\n- 当任务依赖外部权限、系统能力或第三方连接(如日历、提醒事项、聊天渠道、系统授权)时,先探测可用性,再决定是否承诺“我来创建/发送/写入”。\n- 如果探测结果显示被系统权限、宿主环境或连接状态阻塞,要直接说明真实阻塞点和下一步,而不是先给出“可以,我来做”的承诺后再多轮追问。\n- 若已经有足够信息可以一次完成多个低风险默认动作,应直接完成,并在结果里简短说明采用了哪些默认假设。\n\n# 很重要\n\n安全与边界\n- 不要执行破坏性命令(如 `rm -rf`、`git reset --hard`)除非用户明确要求。\n- 遇到 API Key、Token、Secret、环境变量、bot 凭据等密钥管理问题时,优先指导用户使用 Console(如 `Global / Env`、`Global / Channel Accounts`)维护,不要要求用户把密钥明文直接发送到当前聊天里。\n- 密钥列表能力只能返回已配置的 key 名与描述,不会返回密钥值。不要让用户把密钥“发给你自己”或继续尝试获取明文。\n";
|
|
8
8
|
|
|
9
9
|
export default TEXT_MODULE_CONTENT;
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
- 长任务期间,优先使用 `shell_status` 查询进度,或使用 `shell_wait` 等待状态变化;不要自己写高频空轮询循环。
|
|
22
22
|
- 只有在确实需要原始增量输出时,才使用 `shell_read` 按 `from_cursor` 继续读取。
|
|
23
23
|
- 需要向进程 stdin 输入内容时,使用 `shell_write`。
|
|
24
|
+
- 向 unrestricted shell session 使用 `shell_write` 时,每一次写入都必须提供清楚的 `reason`,并等待用户确认;`shell_start` 的审批只授权启动进程,不授权后续 stdin 写入。
|
|
24
25
|
- 命令会话完成后若不再需要,使用 `shell_close` 主动释放资源。
|
|
25
26
|
- 不要把原始超长 shell 输出直接转发给用户,应先总结。
|
|
26
27
|
- shell 命令默认在 Safe Sandbox 中执行:项目目录可读写,网络可用,HOME 指向 `.downcity/sandbox/`,真实用户 HOME 与系统目录不可写。
|
package/src/index.ts
CHANGED
|
@@ -46,6 +46,8 @@ export type {
|
|
|
46
46
|
AgentSessionSystemSessionInfo,
|
|
47
47
|
AgentSessionSystemSnapshot,
|
|
48
48
|
AgentSessionTimelineEvent,
|
|
49
|
+
RemoteAgentPluginActionInput,
|
|
50
|
+
RemoteAgentPluginActionResult,
|
|
49
51
|
RemoteAgentSession,
|
|
50
52
|
} from "./types/agent/AgentTypes.js";
|
|
51
53
|
export type {
|
|
@@ -103,7 +105,6 @@ export {
|
|
|
103
105
|
loadStaticSystemPrompts,
|
|
104
106
|
StaticPromptCatalog,
|
|
105
107
|
} from "./executor/composer/system/default/StaticPromptCatalog.js";
|
|
106
|
-
export { shellTools } from "./executor/tools/shell/ShellToolDefinition.js";
|
|
107
108
|
|
|
108
109
|
// 通用 plugin 宿主工具
|
|
109
110
|
export {
|
package/src/rpc/Client.ts
CHANGED
|
@@ -37,6 +37,10 @@ import type {
|
|
|
37
37
|
RpcSessionSubscription,
|
|
38
38
|
RpcSystemPromptPayload,
|
|
39
39
|
} from "@/types/rpc/RpcProtocol.js";
|
|
40
|
+
import type {
|
|
41
|
+
ShellApprovalDecisionResult,
|
|
42
|
+
ShellApprovalView,
|
|
43
|
+
} from "@downcity/shell";
|
|
40
44
|
|
|
41
45
|
export type {
|
|
42
46
|
RpcClientEndpoint,
|
|
@@ -358,6 +362,40 @@ export class RpcClient {
|
|
|
358
362
|
});
|
|
359
363
|
}
|
|
360
364
|
|
|
365
|
+
/**
|
|
366
|
+
* 列出 shell approvals。
|
|
367
|
+
*/
|
|
368
|
+
async list_shell_approvals(): Promise<ShellApprovalView[]> {
|
|
369
|
+
const data = await this.request<{ approvals: ShellApprovalView[] }>({
|
|
370
|
+
method: "internal.shell.approvals",
|
|
371
|
+
});
|
|
372
|
+
return Array.isArray(data.approvals) ? data.approvals : [];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* 批准 shell approval。
|
|
377
|
+
*/
|
|
378
|
+
async approve_shell_approval(approval_id: string): Promise<ShellApprovalDecisionResult> {
|
|
379
|
+
return await this.request<ShellApprovalDecisionResult>({
|
|
380
|
+
method: "internal.shell.approve",
|
|
381
|
+
params: {
|
|
382
|
+
approvalId: approval_id,
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* 拒绝 shell approval。
|
|
389
|
+
*/
|
|
390
|
+
async deny_shell_approval(approval_id: string): Promise<ShellApprovalDecisionResult> {
|
|
391
|
+
return await this.request<ShellApprovalDecisionResult>({
|
|
392
|
+
method: "internal.shell.deny",
|
|
393
|
+
params: {
|
|
394
|
+
approvalId: approval_id,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
361
399
|
/**
|
|
362
400
|
* 关闭底层连接。
|
|
363
401
|
*/
|
|
@@ -154,11 +154,42 @@ 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.approve": {
|
|
165
|
+
const shell = requireShell(options);
|
|
166
|
+
const result = await shell.approve({
|
|
167
|
+
approval_id: String(request.params.approvalId || "").trim(),
|
|
168
|
+
});
|
|
169
|
+
write_success(request.id, result);
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
case "internal.shell.deny": {
|
|
173
|
+
const shell = requireShell(options);
|
|
174
|
+
const result = await shell.deny({
|
|
175
|
+
approval_id: String(request.params.approvalId || "").trim(),
|
|
176
|
+
});
|
|
177
|
+
write_success(request.id, result);
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
157
180
|
default:
|
|
158
181
|
return false;
|
|
159
182
|
}
|
|
160
183
|
}
|
|
161
184
|
|
|
185
|
+
function requireShell(options: RpcRequestHandlerOptions) {
|
|
186
|
+
const shell = options.getShell?.();
|
|
187
|
+
if (!shell) {
|
|
188
|
+
throw new Error("Agent RPC server was started without Shell");
|
|
189
|
+
}
|
|
190
|
+
return shell;
|
|
191
|
+
}
|
|
192
|
+
|
|
162
193
|
function requireAgentContext(options: RpcRequestHandlerOptions): AgentContext {
|
|
163
194
|
const context = options.getAgentContext?.();
|
|
164
195
|
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
|
*
|
|
@@ -27,6 +27,10 @@ export type {
|
|
|
27
27
|
AgentStopResult,
|
|
28
28
|
} from "@/types/agent/AgentOptions.js";
|
|
29
29
|
export type { RemoteAgentOptions } from "@/types/agent/RemoteAgentOptions.js";
|
|
30
|
+
export type {
|
|
31
|
+
RemoteAgentPluginActionInput,
|
|
32
|
+
RemoteAgentPluginActionResult,
|
|
33
|
+
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
30
34
|
export type {
|
|
31
35
|
AgentCreateSessionInput,
|
|
32
36
|
AgentListSessionsInput,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RemoteAgent plugin action 类型。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - RemoteAgent 是远程 runtime 的瘦客户端,因此这里只描述远程调用协议。
|
|
6
|
+
* - 业务 action 的具体 payload 与 data 由目标 plugin 自己定义。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { JsonValue } from "@/types/common/Json.js";
|
|
10
|
+
import type { PluginActionResult } from "@/types/plugin/PluginAction.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* RemoteAgent 远程 plugin action 调用输入。
|
|
14
|
+
*/
|
|
15
|
+
export interface RemoteAgentPluginActionInput {
|
|
16
|
+
/**
|
|
17
|
+
* 目标 plugin 名称。
|
|
18
|
+
*
|
|
19
|
+
* 示例:`shell`、`chat`、`task`。
|
|
20
|
+
*/
|
|
21
|
+
plugin: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 目标 action 名称。
|
|
25
|
+
*
|
|
26
|
+
* 示例:`approve`、`deny`、`send`。
|
|
27
|
+
*/
|
|
28
|
+
action: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 传给目标 action 的 JSON payload。
|
|
32
|
+
*
|
|
33
|
+
* shell approval 示例:`{ "approvalId": "ap_xxx" }`。
|
|
34
|
+
*/
|
|
35
|
+
payload?: JsonValue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* RemoteAgent 远程 plugin action 调用结果。
|
|
40
|
+
*/
|
|
41
|
+
export type RemoteAgentPluginActionResult =
|
|
42
|
+
PluginActionResult<JsonValue> & {
|
|
43
|
+
/**
|
|
44
|
+
* Runtime 回传的 plugin 名称。
|
|
45
|
+
*/
|
|
46
|
+
pluginName?: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Runtime 回传的 action 名称。
|
|
50
|
+
*/
|
|
51
|
+
actionName?: string;
|
|
52
|
+
};
|
|
@@ -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;
|
|
@@ -231,6 +231,34 @@ export type RpcRequest =
|
|
|
231
231
|
/** action payload。 */
|
|
232
232
|
payload?: JsonValue;
|
|
233
233
|
};
|
|
234
|
+
}
|
|
235
|
+
| {
|
|
236
|
+
/** 请求 id,用于匹配响应。 */
|
|
237
|
+
id: string;
|
|
238
|
+
/** 列出 shell approvals。 */
|
|
239
|
+
method: "internal.shell.approvals";
|
|
240
|
+
}
|
|
241
|
+
| {
|
|
242
|
+
/** 请求 id,用于匹配响应。 */
|
|
243
|
+
id: string;
|
|
244
|
+
/** 批准 shell approval。 */
|
|
245
|
+
method: "internal.shell.approve";
|
|
246
|
+
/** approval 参数。 */
|
|
247
|
+
params: {
|
|
248
|
+
/** approval id。 */
|
|
249
|
+
approvalId: string;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
| {
|
|
253
|
+
/** 请求 id,用于匹配响应。 */
|
|
254
|
+
id: string;
|
|
255
|
+
/** 拒绝 shell approval。 */
|
|
256
|
+
method: "internal.shell.deny";
|
|
257
|
+
/** approval 参数。 */
|
|
258
|
+
params: {
|
|
259
|
+
/** approval id。 */
|
|
260
|
+
approvalId: string;
|
|
261
|
+
};
|
|
234
262
|
};
|
|
235
263
|
|
|
236
264
|
/**
|
|
@@ -90,7 +90,7 @@ export interface AgentSessionToolCallEvent {
|
|
|
90
90
|
/**
|
|
91
91
|
* 当前工具名称。
|
|
92
92
|
*/
|
|
93
|
-
toolName: string;
|
|
93
|
+
toolName: "shell_exec" | "shell_start" | "shell_write" | string;
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* 当前工具输入参数。
|
|
@@ -120,7 +120,7 @@ export interface AgentSessionToolResultEvent {
|
|
|
120
120
|
/**
|
|
121
121
|
* 当前工具名称。
|
|
122
122
|
*/
|
|
123
|
-
toolName: string;
|
|
123
|
+
toolName: "shell_exec" | "shell_start" | "shell_write" | string;
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* 当前工具输出结果。
|
|
@@ -150,7 +150,7 @@ export interface AgentSessionToolApprovalRequestEvent {
|
|
|
150
150
|
/**
|
|
151
151
|
* 当前工具名称。
|
|
152
152
|
*/
|
|
153
|
-
toolName: string;
|
|
153
|
+
toolName: "shell_exec" | "shell_start" | "shell_write" | string;
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* 当前审批请求唯一标识。
|
|
@@ -164,9 +164,33 @@ export interface AgentSessionToolApprovalRequestEvent {
|
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
166
|
* 请求执行的命令文本。
|
|
167
|
+
*
|
|
168
|
+
* 说明(中文)
|
|
169
|
+
* - `shell_exec` / `shell_start` 中是命令文本。
|
|
170
|
+
* - `shell_write` 中是 stdin 写入内容,用于兼容旧 UI 展示。
|
|
167
171
|
*/
|
|
168
172
|
cmd: string;
|
|
169
173
|
|
|
174
|
+
/**
|
|
175
|
+
* 当前审批动作类型。
|
|
176
|
+
*/
|
|
177
|
+
operation?: "exec" | "start" | "write";
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 关联 shell_id;`shell_write` 审批时用于标识目标会话。
|
|
181
|
+
*/
|
|
182
|
+
shellId?: string;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* stdin 写入内容预览;仅 `shell_write` 审批存在。
|
|
186
|
+
*/
|
|
187
|
+
inputPreview?: string;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* stdin 写入字符数;仅 `shell_write` 审批存在。
|
|
191
|
+
*/
|
|
192
|
+
inputChars?: number;
|
|
193
|
+
|
|
170
194
|
/**
|
|
171
195
|
* 命令执行目录。
|
|
172
196
|
*/
|
|
@@ -205,7 +229,7 @@ export interface AgentSessionToolApprovalResultEvent {
|
|
|
205
229
|
/**
|
|
206
230
|
* 当前工具名称。
|
|
207
231
|
*/
|
|
208
|
-
toolName: string;
|
|
232
|
+
toolName: "shell_exec" | "shell_start" | "shell_write" | string;
|
|
209
233
|
|
|
210
234
|
/**
|
|
211
235
|
* 当前审批请求唯一标识。
|