54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { tool } from "@opencode-ai/plugin";
|
|
|
|
const internalBaseUrl =
|
|
process.env.TJWATER_AGENT_INTERNAL_BASE_URL ?? "http://127.0.0.1:8787";
|
|
const internalToken = process.env.TJWATER_AGENT_INTERNAL_TOKEN ?? "";
|
|
|
|
export default tool({
|
|
description:
|
|
"在当前对话专属的 Landlock 沙箱中运行 Shell 命令。只能读写当前对话工作区,不能访问网络、密钥、其他对话或应用源码。",
|
|
args: {
|
|
command: tool.schema.string().describe("需要在沙箱中执行的 Shell 命令。"),
|
|
description: tool.schema
|
|
.string()
|
|
.optional()
|
|
.describe("面向用户的简短命令说明。"),
|
|
timeout: tool.schema
|
|
.number()
|
|
.optional()
|
|
.describe("超时秒数,默认 120,最大 1800。"),
|
|
},
|
|
async execute(args, context) {
|
|
await context.ask({
|
|
permission: "bash",
|
|
patterns: [args.command],
|
|
always: [args.command],
|
|
metadata: {
|
|
command: args.command,
|
|
...(args.description ? { description: args.description } : {}),
|
|
},
|
|
});
|
|
const response = await fetch(
|
|
`${internalBaseUrl}/internal/tools/sandbox-shell`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"x-agent-internal-token": internalToken,
|
|
},
|
|
body: JSON.stringify({
|
|
session_id: context.sessionID,
|
|
command: args.command,
|
|
description: args.description,
|
|
timeout: args.timeout,
|
|
}),
|
|
},
|
|
);
|
|
const text = await response.text();
|
|
if (!response.ok) {
|
|
throw new Error(text);
|
|
}
|
|
return text;
|
|
},
|
|
});
|