fix(agent): isolate conversation workspaces
This commit is contained in:
@@ -3,12 +3,25 @@ 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 ?? "";
|
||||
const importDirectory =
|
||||
process.env.RESULT_REF_IMPORT_DIR ?? "./data/result-imports";
|
||||
|
||||
type StoreRenderRefArgs = {
|
||||
file_path?: unknown;
|
||||
filePath?: unknown;
|
||||
};
|
||||
|
||||
export function resolveStoreRenderFilePath(args: StoreRenderRefArgs): string {
|
||||
if (typeof args.file_path === "string" && args.file_path.trim() !== "") {
|
||||
return args.file_path;
|
||||
}
|
||||
if (typeof args.filePath === "string" && args.filePath.trim() !== "") {
|
||||
return args.filePath;
|
||||
}
|
||||
throw new Error("file_path is required");
|
||||
}
|
||||
|
||||
export default tool({
|
||||
description:
|
||||
`导入 ${importDirectory} 下的受控 JSON 包装文件并返回 render_ref。文件必须是 { metadata: object, location: { file_path: string }, data: { node_area_map, area_ids?, area_colors? } },location.file_path 必须与传入的绝对路径完全一致。只接受该目录内的真实文件,不接受目录外路径或指向目录外的符号链接。`,
|
||||
"导入当前对话工作目录下的受控 JSON 包装文件并返回 render_ref。文件必须是 { metadata: object, location: { file_path: string }, data: { node_area_map, area_ids?, area_colors? } },location.file_path 必须与传入的绝对路径完全一致。只接受当前对话工作目录内的真实文件,不接受其他对话目录、目录外路径或指向目录外的符号链接。",
|
||||
args: {
|
||||
reason: tool.schema
|
||||
.string()
|
||||
@@ -17,11 +30,17 @@ export default tool({
|
||||
),
|
||||
file_path: tool.schema
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
`位于 ${importDirectory} 内的包装 JSON 文件绝对路径。必须包含 metadata、location.file_path 和 data;data 才是 render_junctions 使用的 { node_area_map, area_ids?, area_colors? }。`,
|
||||
"位于当前对话工作目录内的包装 JSON 文件绝对路径。必须包含 metadata、location.file_path 和 data;data 才是 render_junctions 使用的 { node_area_map, area_ids?, area_colors? }。",
|
||||
),
|
||||
filePath: tool.schema
|
||||
.string()
|
||||
.optional()
|
||||
.describe("兼容旧调用的参数名;新调用应优先使用 file_path。"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
const filePath = resolveStoreRenderFilePath(args);
|
||||
const response = await fetch(
|
||||
`${internalBaseUrl}/internal/tools/store-render-ref`,
|
||||
{
|
||||
@@ -32,7 +51,7 @@ export default tool({
|
||||
},
|
||||
body: JSON.stringify({
|
||||
session_id: context.sessionID,
|
||||
file_path: args.file_path,
|
||||
file_path: filePath,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user