From 81570d063890c947cc961c5ab739a494055d86a6 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Wed, 22 Apr 2026 22:26:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=82=20Update=20.gitignore=20and=20READ?= =?UTF-8?q?ME.md=20for=20better=20project=20configuration=20and=20document?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + README.md | 10 +++ demo.ts | 40 +++++++++++ deno.json | 7 ++ deno.lock | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 262 insertions(+) create mode 100644 demo.ts create mode 100644 deno.json create mode 100644 deno.lock diff --git a/.gitignore b/.gitignore index d4777d2..7ec1f27 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.idea/ +.opencode/ + # ---> macOS # General .DS_Store diff --git a/README.md b/README.md index 6198512..6452479 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # opencode-custom-tool-demo +> https://opencode.ai/docs/zh-cn/custom-tools/ +> - 本地定义:将工具文件放在项目的 .opencode/tools/ 目录中。 +> - 全局定义:将工具文件放在 ~/.config/opencode/tools/ 中。 + +Install tool: + +```shell +mkdir -p .opencode/tools/ +ln -s demo.ts .opencode/tools/demo.ts +``` \ No newline at end of file diff --git a/demo.ts b/demo.ts new file mode 100644 index 0000000..5916a56 --- /dev/null +++ b/demo.ts @@ -0,0 +1,40 @@ +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 ipResp = await fetch("https://hatter.ink/ip/ip.jsonp"); + const ipResponse = await ipResp.json() as IpResponse; + return ipResponse.ip; + }, +}); diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..a712969 --- /dev/null +++ b/deno.json @@ -0,0 +1,7 @@ +{ + "tasks": { + }, + "imports": { + "@opencode-ai/plugin": "npm:@opencode-ai/plugin" + } +} diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..d8c2616 --- /dev/null +++ b/deno.lock @@ -0,0 +1,202 @@ +{ + "version": "5", + "specifiers": { + "npm:@opencode-ai/plugin@*": "1.14.20" + }, + "npm": { + "@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.3": { + "integrity": "sha512-QZHtlVgbAdy2zAqNA9Gu1UpIuI8Xvsd1v8ic6B2pZmeFnFcMWiPLfWXh7TVw4eGEZ/C9TH281KwhVoeQUKbyjw==", + "os": ["darwin"], + "cpu": ["arm64"], + "tarball": "https://registry.npmmirror.com/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-3.0.3.tgz" + }, + "@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.3": { + "integrity": "sha512-mdzd3AVzYKuUmiWOQ8GNhl64/IoFGol569zNRdkLReh6LRLHOXxU4U8eq0JwaD8iFHdVGqSy4IjFL4reoWCDFw==", + "os": ["darwin"], + "cpu": ["x64"], + "tarball": "https://registry.npmmirror.com/@msgpackr-extract/msgpackr-extract-darwin-x64/-/msgpackr-extract-darwin-x64-3.0.3.tgz" + }, + "@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.3": { + "integrity": "sha512-YxQL+ax0XqBJDZiKimS2XQaf+2wDGVa1enVRGzEvLLVFeqa5kx2bWbtcSXgsxjQB7nRqqIGFIcLteF/sHeVtQg==", + "os": ["linux"], + "cpu": ["arm64"], + "tarball": "https://registry.npmmirror.com/@msgpackr-extract/msgpackr-extract-linux-arm64/-/msgpackr-extract-linux-arm64-3.0.3.tgz" + }, + "@msgpackr-extract/msgpackr-extract-linux-arm@3.0.3": { + "integrity": "sha512-fg0uy/dG/nZEXfYilKoRe7yALaNmHoYeIoJuJ7KJ+YyU2bvY8vPv27f7UKhGRpY6euFYqEVhxCFZgAUNQBM3nw==", + "os": ["linux"], + "cpu": ["arm"], + "tarball": "https://registry.npmmirror.com/@msgpackr-extract/msgpackr-extract-linux-arm/-/msgpackr-extract-linux-arm-3.0.3.tgz" + }, + "@msgpackr-extract/msgpackr-extract-linux-x64@3.0.3": { + "integrity": "sha512-cvwNfbP07pKUfq1uH+S6KJ7dT9K8WOE4ZiAcsrSes+UY55E/0jLYc+vq+DO7jlmqRb5zAggExKm0H7O/CBaesg==", + "os": ["linux"], + "cpu": ["x64"], + "tarball": "https://registry.npmmirror.com/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-3.0.3.tgz" + }, + "@msgpackr-extract/msgpackr-extract-win32-x64@3.0.3": { + "integrity": "sha512-x0fWaQtYp4E6sktbsdAqnehxDgEc/VwM7uLsRCYWaiGu0ykYdZPiS8zCWdnjHwyiumousxfBm4SO31eXqwEZhQ==", + "os": ["win32"], + "cpu": ["x64"], + "tarball": "https://registry.npmmirror.com/@msgpackr-extract/msgpackr-extract-win32-x64/-/msgpackr-extract-win32-x64-3.0.3.tgz" + }, + "@opencode-ai/plugin@1.14.20": { + "integrity": "sha512-txRfm6Y2DBqFxJtgo63vj5//d7TJS7/angWELUEQcsSK0llfvmVp60gox4e8zIwpGjDcDP9A4qO6oNe++pockg==", + "dependencies": [ + "@opencode-ai/sdk", + "effect", + "zod" + ], + "tarball": "https://registry.npmmirror.com/@opencode-ai/plugin/-/plugin-1.14.20.tgz" + }, + "@opencode-ai/sdk@1.14.20": { + "integrity": "sha512-kPZP1An1ZdWOfLfDYhNjh665HX4RcI8au6Lzjn0FktoQ3RpWHq1WXRLHrJO8rJqwWvQDOzS48cXt9jbr+uwQiA==", + "dependencies": [ + "cross-spawn" + ], + "tarball": "https://registry.npmmirror.com/@opencode-ai/sdk/-/sdk-1.14.20.tgz" + }, + "@standard-schema/spec@1.1.0": { + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "tarball": "https://registry.npmmirror.com/@standard-schema/spec/-/spec-1.1.0.tgz" + }, + "cross-spawn@7.0.6": { + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dependencies": [ + "path-key", + "shebang-command", + "which" + ], + "tarball": "https://registry.npmmirror.com/cross-spawn/-/cross-spawn-7.0.6.tgz" + }, + "detect-libc@2.1.2": { + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "tarball": "https://registry.npmmirror.com/detect-libc/-/detect-libc-2.1.2.tgz" + }, + "effect@4.0.0-beta.48": { + "integrity": "sha512-MMAM/ZabuNdNmgXiin+BAanQXK7qM8mlt7nfXDoJ/Gn9V8i89JlCq+2N0AiWmqFLXjGLA0u3FjiOjSOYQk5uMw==", + "dependencies": [ + "@standard-schema/spec", + "fast-check", + "find-my-way-ts", + "ini", + "kubernetes-types", + "msgpackr", + "multipasta", + "toml", + "uuid", + "yaml" + ], + "tarball": "https://registry.npmmirror.com/effect/-/effect-4.0.0-beta.48.tgz" + }, + "fast-check@4.7.0": { + "integrity": "sha512-NsZRtqvSSoCP0HbNjUD+r1JH8zqZalyp6gLY9e7OYs7NK9b6AHOs2baBFeBG7bVNsuoukh89x2Yg3rPsul8ziQ==", + "dependencies": [ + "pure-rand" + ], + "tarball": "https://registry.npmmirror.com/fast-check/-/fast-check-4.7.0.tgz" + }, + "find-my-way-ts@0.1.6": { + "integrity": "sha512-a85L9ZoXtNAey3Y6Z+eBWW658kO/MwR7zIafkIUPUMf3isZG0NCs2pjW2wtjxAKuJPxMAsHUIP4ZPGv0o5gyTA==", + "tarball": "https://registry.npmmirror.com/find-my-way-ts/-/find-my-way-ts-0.1.6.tgz" + }, + "ini@6.0.0": { + "integrity": "sha512-IBTdIkzZNOpqm7q3dRqJvMaldXjDHWkEDfrwGEQTs5eaQMWV+djAhR+wahyNNMAa+qpbDUhBMVt4ZKNwpPm7xQ==", + "tarball": "https://registry.npmmirror.com/ini/-/ini-6.0.0.tgz" + }, + "isexe@2.0.0": { + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "tarball": "https://registry.npmmirror.com/isexe/-/isexe-2.0.0.tgz" + }, + "kubernetes-types@1.30.0": { + "integrity": "sha512-Dew1okvhM/SQcIa2rcgujNndZwU8VnSapDgdxlYoB84ZlpAD43U6KLAFqYo17ykSFGHNPrg0qry0bP+GJd9v7Q==", + "tarball": "https://registry.npmmirror.com/kubernetes-types/-/kubernetes-types-1.30.0.tgz" + }, + "msgpackr-extract@3.0.3": { + "integrity": "sha512-P0efT1C9jIdVRefqjzOQ9Xml57zpOXnIuS+csaB4MdZbTdmGDLo8XhzBG1N7aO11gKDDkJvBLULeFTo46wwreA==", + "dependencies": [ + "node-gyp-build-optional-packages" + ], + "optionalDependencies": [ + "@msgpackr-extract/msgpackr-extract-darwin-arm64", + "@msgpackr-extract/msgpackr-extract-darwin-x64", + "@msgpackr-extract/msgpackr-extract-linux-arm", + "@msgpackr-extract/msgpackr-extract-linux-arm64", + "@msgpackr-extract/msgpackr-extract-linux-x64", + "@msgpackr-extract/msgpackr-extract-win32-x64" + ], + "scripts": true, + "bin": true, + "tarball": "https://registry.npmmirror.com/msgpackr-extract/-/msgpackr-extract-3.0.3.tgz" + }, + "msgpackr@1.11.10": { + "integrity": "sha512-iCZNq+HszvF+fC3anCm4nBmWEnbeIAfpDs6IStAEKhQ2YSgkjzVG2FF9XJqwwQh5bH3N9OUTUt4QwVN6MLMLtA==", + "optionalDependencies": [ + "msgpackr-extract" + ], + "tarball": "https://registry.npmmirror.com/msgpackr/-/msgpackr-1.11.10.tgz" + }, + "multipasta@0.2.7": { + "integrity": "sha512-KPA58d68KgGil15oDqXjkUBEBYc00XvbPj5/X+dyzeo/lWm9Nc25pQRlf1D+gv4OpK7NM0J1odrbu9JNNGvynA==", + "tarball": "https://registry.npmmirror.com/multipasta/-/multipasta-0.2.7.tgz" + }, + "node-gyp-build-optional-packages@5.2.2": { + "integrity": "sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw==", + "dependencies": [ + "detect-libc" + ], + "bin": true, + "tarball": "https://registry.npmmirror.com/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.2.2.tgz" + }, + "path-key@3.1.1": { + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "tarball": "https://registry.npmmirror.com/path-key/-/path-key-3.1.1.tgz" + }, + "pure-rand@8.4.0": { + "integrity": "sha512-IoM8YF/jY0hiugFo/wOWqfmarlE6J0wc6fDK1PhftMk7MGhVZl88sZimmqBBFomLOCSmcCCpsfj7wXASCpvK9A==", + "tarball": "https://registry.npmmirror.com/pure-rand/-/pure-rand-8.4.0.tgz" + }, + "shebang-command@2.0.0": { + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dependencies": [ + "shebang-regex" + ], + "tarball": "https://registry.npmmirror.com/shebang-command/-/shebang-command-2.0.0.tgz" + }, + "shebang-regex@3.0.0": { + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "tarball": "https://registry.npmmirror.com/shebang-regex/-/shebang-regex-3.0.0.tgz" + }, + "toml@4.1.1": { + "integrity": "sha512-EBJnVBr3dTXdA89WVFoAIPUqkBjxPMwRqsfuo1r240tKFHXv3zgca4+NJib/h6TyvGF7vOawz0jGuryJCdNHrw==", + "tarball": "https://registry.npmmirror.com/toml/-/toml-4.1.1.tgz" + }, + "uuid@13.0.0": { + "integrity": "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w==", + "bin": true, + "tarball": "https://registry.npmmirror.com/uuid/-/uuid-13.0.0.tgz" + }, + "which@2.0.2": { + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dependencies": [ + "isexe" + ], + "bin": true, + "tarball": "https://registry.npmmirror.com/which/-/which-2.0.2.tgz" + }, + "yaml@2.8.3": { + "integrity": "sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg==", + "bin": true, + "tarball": "https://registry.npmmirror.com/yaml/-/yaml-2.8.3.tgz" + }, + "zod@4.1.8": { + "integrity": "sha512-5R1P+WwQqmmMIEACyzSvo4JXHY5WiAFHRMg+zBZKgKS+Q1viRa0C1hmUKtHltoIFKtIdki3pRxkmpP74jnNYHQ==", + "tarball": "https://registry.npmmirror.com/zod/-/zod-4.1.8.tgz" + } + }, + "workspace": { + "dependencies": [ + "npm:@opencode-ai/plugin@*" + ] + } +}