45 lines
1.6 KiB
TypeScript
45 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:
|
||
"将本地 JSON 渲染数据文件存储到受控路径,返回可供 render_junctions 使用的 render_ref(res-...)。前置步骤:先准备好符合 render_junctions 数据结构的 JSON 文件 { node_area_map, area_ids?, area_colors? },写入本地路径后再调用本工具传入该路径,获取 render_ref 后传给 render_junctions 完成前端渲染。",
|
||
args: {
|
||
reason: tool.schema
|
||
.string()
|
||
.describe(
|
||
"为何需要将此本地渲染数据持久化为 render_ref,以便后续通过 render_junctions 渲染到前端。",
|
||
),
|
||
file_path: tool.schema
|
||
.string()
|
||
.describe(
|
||
"本地 JSON 文件的绝对路径,内容为 render_junctions 所需的数据结构 { node_area_map, area_ids?, area_colors? }。",
|
||
),
|
||
},
|
||
async execute(args, context) {
|
||
const response = await fetch(
|
||
`${internalBaseUrl}/internal/tools/store-render-ref`,
|
||
{
|
||
method: "POST",
|
||
headers: {
|
||
"Content-Type": "application/json",
|
||
"x-agent-internal-token": internalToken,
|
||
},
|
||
body: JSON.stringify({
|
||
session_id: context.sessionID,
|
||
file_path: args.file_path,
|
||
}),
|
||
},
|
||
);
|
||
|
||
const text = await response.text();
|
||
if (!response.ok) {
|
||
throw new Error(text);
|
||
}
|
||
return text;
|
||
},
|
||
});
|