init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { tool } from "@opencode-ai/plugin";
|
||||
|
||||
const internalBaseUrl = process.env.TJWATER_AGENT_INTERNAL_BASE_URL ?? "http://127.0.0.1:8788";
|
||||
const internalToken = process.env.TJWATER_AGENT_INTERNAL_TOKEN ?? "";
|
||||
|
||||
export default tool({
|
||||
description:
|
||||
"Call the TJWater backend API through the local agent bridge. Provide path, optional method, and query arguments.",
|
||||
args: {
|
||||
path: tool.schema.string().describe("Target backend API path, starting with '/'."),
|
||||
method: tool.schema
|
||||
.string()
|
||||
.optional()
|
||||
.describe("HTTP method. Defaults to GET."),
|
||||
arguments: tool.schema
|
||||
.record(tool.schema.string(), tool.schema.unknown())
|
||||
.optional()
|
||||
.describe("Query arguments object."),
|
||||
},
|
||||
async execute(args, context) {
|
||||
const response = await fetch(`${internalBaseUrl}/internal/tools/dynamic-http-call`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-agent-internal-token": internalToken,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sessionId: context.sessionID,
|
||||
path: args.path,
|
||||
method: args.method,
|
||||
arguments: args.arguments,
|
||||
}),
|
||||
});
|
||||
|
||||
const text = await response.text();
|
||||
if (!response.ok) {
|
||||
throw new Error(text);
|
||||
}
|
||||
return text;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user