import {tool, ToolResult} from "@opencode-ai/plugin"; export const add = tool({ description: "Add two numbers", args: { a: tool.schema.number().describe("First number"), b: tool.schema.number().describe("Second number"), }, async execute(args) { return `${args.a + args.b}`; }, }); export const multiply = tool({ description: "Multiply two numbers", args: { a: tool.schema.number().describe("First number"), b: tool.schema.number().describe("Second number"), }, async execute(args) { return `${args.a * args.b}`; }, }); interface IpResponse { status: number; message: string; ip: string; userAgent: string; } export const get_my_ip = tool({ description: "Get my IP", args: {}, async execute(args): Promise { const timeoutMs = 10_000; const abortController = new AbortController(); const timeoutHandler = setTimeout(() => { abortController.abort( `Fetch timeout: ${timeoutMs} ms`, ); }, timeoutMs); try { const ipResp = await fetch("https://hatter.ink/ip/ip.jsonp", { signal: abortController.signal, }); const ipResponse = await ipResp.json() as IpResponse; return ipResponse.ip; } finally { clearTimeout(timeoutHandler); } }, });