Files
opencode-custom-tool-demo/demo.ts

41 lines
941 B
TypeScript

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<ToolResult> {
const ipResp = await fetch("https://hatter.ink/ip/ip.jsonp");
const ipResponse = await ipResp.json() as IpResponse;
return ipResponse.ip;
},
});