@tokensize/opencode 0.3.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/package.json +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TokenSize
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# `@tokensize/opencode`
|
|
2
|
+
|
|
3
|
+
OpenCode plugin for TokenSize. It adds explicit `tokensize_status`, `tokensize_connect`, `tokensize_route`, `tokensize_execute`, and `tokensize_feedback` tools backed by the canonical `@tokensize/agent-client`.
|
|
4
|
+
|
|
5
|
+
Add the exact release to `opencode.json`:
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"$schema": "https://opencode.ai/config.json",
|
|
10
|
+
"plugin": ["@tokensize/opencode@0.3.0-beta.0"],
|
|
11
|
+
"permission": {
|
|
12
|
+
"tokensize_status": "allow",
|
|
13
|
+
"tokensize_route": "allow",
|
|
14
|
+
"tokensize_connect": "ask",
|
|
15
|
+
"tokensize_execute": "ask",
|
|
16
|
+
"tokensize_feedback": "allow"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
OpenCode execution is inspect-only in this beta. The plugin cannot broaden OpenCode permissions or route back into OpenCode itself.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { tool } from "@opencode-ai/plugin";
|
|
3
|
+
import { TokenSizeClient } from "@tokensize/agent-client";
|
|
4
|
+
var TokenSizePlugin = async ({ directory, worktree }) => {
|
|
5
|
+
const client = new TokenSizeClient({ clientSurface: "opencode-plugin", rootHarness: "opencode", rootActive: true });
|
|
6
|
+
const contextDirectory = worktree ?? directory;
|
|
7
|
+
return {
|
|
8
|
+
tool: {
|
|
9
|
+
tokensize_status: tool({
|
|
10
|
+
description: "Inspect locally discovered coding harnesses, models, normalized allowances, and cache freshness.",
|
|
11
|
+
args: { refresh: tool.schema.boolean().optional(), verbose: tool.schema.boolean().optional() },
|
|
12
|
+
async execute(args) {
|
|
13
|
+
return JSON.stringify(await client.status(args), null, 2);
|
|
14
|
+
}
|
|
15
|
+
}),
|
|
16
|
+
tokensize_connect: tool({
|
|
17
|
+
description: "Open the TokenSize browser authorization flow and save the approved credential locally.",
|
|
18
|
+
args: {},
|
|
19
|
+
async execute() {
|
|
20
|
+
await client.connect("opencode-plugin");
|
|
21
|
+
return "TokenSize connected. Credentials remain local.";
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
tokensize_route: tool({
|
|
25
|
+
description: "Preview a privacy-safe TokenSize route; prompts are not shared by default.",
|
|
26
|
+
args: {
|
|
27
|
+
task: tool.schema.string().min(1).max(12e3),
|
|
28
|
+
role: tool.schema.string().optional(),
|
|
29
|
+
permission: tool.schema.string().optional(),
|
|
30
|
+
objective: tool.schema.string().optional(),
|
|
31
|
+
sharePrompt: tool.schema.boolean().optional(),
|
|
32
|
+
refresh: tool.schema.boolean().optional()
|
|
33
|
+
},
|
|
34
|
+
async execute(args) {
|
|
35
|
+
return JSON.stringify(await client.route({ ...args, role: args.role, permission: args.permission, objective: args.objective }), null, 2);
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
tokensize_execute: tool({
|
|
39
|
+
description: "Execute an approved inspect-only local route receipt for the exact task it was created for.",
|
|
40
|
+
args: { receiptId: tool.schema.string().min(36).max(36), task: tool.schema.string().min(1).max(12e3) },
|
|
41
|
+
async execute(args) {
|
|
42
|
+
return JSON.stringify(await client.execute({ ...args, cwd: contextDirectory }), null, 2);
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
tokensize_feedback: tool({
|
|
46
|
+
description: "Send content-free feedback for a recent TokenSize route receipt.",
|
|
47
|
+
args: {
|
|
48
|
+
receiptId: tool.schema.string().min(36).max(36),
|
|
49
|
+
rating: tool.schema.number().int().min(1).max(5),
|
|
50
|
+
modelChoice: tool.schema.string().min(1).max(20),
|
|
51
|
+
wouldUseAgain: tool.schema.boolean(),
|
|
52
|
+
task: tool.schema.string().max(12e3).optional()
|
|
53
|
+
},
|
|
54
|
+
async execute(args) {
|
|
55
|
+
return JSON.stringify(await client.feedback({ receiptId: args.receiptId, rating: args.rating, modelChoice: args.modelChoice, wouldUseAgain: args.wouldUseAgain, task: args.task }), null, 2);
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
tokensize_run_status: tool({
|
|
59
|
+
description: "Read the Run document for a delegation \u2014 live status, event timeline, approvals, dashboard URL \u2014 or list recent runs. Report the runId and dashboard link instead of pasting route JSON into chat.",
|
|
60
|
+
args: {
|
|
61
|
+
runId: tool.schema.string().min(36).max(36).optional(),
|
|
62
|
+
limit: tool.schema.number().int().min(1).max(100).optional()
|
|
63
|
+
},
|
|
64
|
+
async execute(args) {
|
|
65
|
+
if (args.runId) {
|
|
66
|
+
const document = await client.runDocument(args.runId);
|
|
67
|
+
return JSON.stringify({ ...document, dashboard: `https://tokensize.dev/runs/${args.runId}` }, null, 2);
|
|
68
|
+
}
|
|
69
|
+
return JSON.stringify(await client.runs({ limit: args.limit }), null, 2);
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
var index_default = TokenSizePlugin;
|
|
76
|
+
export {
|
|
77
|
+
TokenSizePlugin,
|
|
78
|
+
index_default as default
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { type Plugin, tool } from \"@opencode-ai/plugin\";\nimport { TokenSizeClient } from \"@tokensize/agent-client\";\n\nconst TokenSizePlugin: Plugin = async ({ directory, worktree }) => {\n\tconst client = new TokenSizeClient({ clientSurface: \"opencode-plugin\", rootHarness: \"opencode\", rootActive: true });\n\tconst contextDirectory = worktree ?? directory;\n\treturn {\n\t\ttool: {\n\t\t\ttokensize_status: tool({\n\t\t\t\tdescription: \"Inspect locally discovered coding harnesses, models, normalized allowances, and cache freshness.\",\n\t\t\t\targs: { refresh: tool.schema.boolean().optional(), verbose: tool.schema.boolean().optional() },\n\t\t\t\tasync execute(args: { refresh?: boolean; verbose?: boolean }) {\n\t\t\t\t\treturn JSON.stringify(await client.status(args), null, 2);\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttokensize_connect: tool({\n\t\t\t\tdescription: \"Open the TokenSize browser authorization flow and save the approved credential locally.\",\n\t\t\t\targs: {},\n\t\t\t\tasync execute() {\n\t\t\t\t\tawait client.connect(\"opencode-plugin\");\n\t\t\t\t\treturn \"TokenSize connected. Credentials remain local.\";\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttokensize_route: tool({\n\t\t\t\tdescription: \"Preview a privacy-safe TokenSize route; prompts are not shared by default.\",\n\t\t\t\targs: {\n\t\t\t\t\ttask: tool.schema.string().min(1).max(12_000),\n\t\t\t\t\trole: tool.schema.string().optional(),\n\t\t\t\t\tpermission: tool.schema.string().optional(),\n\t\t\t\t\tobjective: tool.schema.string().optional(),\n\t\t\t\t\tsharePrompt: tool.schema.boolean().optional(),\n\t\t\t\t\trefresh: tool.schema.boolean().optional(),\n\t\t\t\t},\n\t\t\t\tasync execute(args: { task: string; role?: never; permission?: never; objective?: never; sharePrompt?: boolean; refresh?: boolean }) {\n\t\t\t\t\treturn JSON.stringify(await client.route({ ...args, role: args.role, permission: args.permission, objective: args.objective }), null, 2);\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttokensize_execute: tool({\n\t\t\t\tdescription: \"Execute an approved inspect-only local route receipt for the exact task it was created for.\",\n\t\t\t\targs: { receiptId: tool.schema.string().min(36).max(36), task: tool.schema.string().min(1).max(12_000) },\n\t\t\t\tasync execute(args: { receiptId: string; task: string }) {\n\t\t\t\t\treturn JSON.stringify(await client.execute({ ...args, cwd: contextDirectory }), null, 2);\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttokensize_feedback: tool({\n\t\t\t\tdescription: \"Send content-free feedback for a recent TokenSize route receipt.\",\n\t\t\t\targs: {\n\t\t\t\t\treceiptId: tool.schema.string().min(36).max(36),\n\t\t\t\t\trating: tool.schema.number().int().min(1).max(5),\n\t\t\t\t\tmodelChoice: tool.schema.string().min(1).max(20),\n\t\t\t\t\twouldUseAgain: tool.schema.boolean(),\n\t\t\t\t\ttask: tool.schema.string().max(12_000).optional(),\n\t\t\t\t},\n\t\t\t\tasync execute(args: { receiptId: string; rating: number; modelChoice: string; wouldUseAgain: boolean; task?: string }) {\n\t\t\t\t\treturn JSON.stringify(await client.feedback({ receiptId: args.receiptId, rating: args.rating as 1 | 2 | 3 | 4 | 5, modelChoice: args.modelChoice as \"right\" | \"acceptable\" | \"wrong\", wouldUseAgain: args.wouldUseAgain, task: args.task }), null, 2);\n\t\t\t\t},\n\t\t\t}),\n\t\t\ttokensize_run_status: tool({\n\t\t\t\tdescription: \"Read the Run document for a delegation — live status, event timeline, approvals, dashboard URL — or list recent runs. Report the runId and dashboard link instead of pasting route JSON into chat.\",\n\t\t\t\targs: {\n\t\t\t\t\trunId: tool.schema.string().min(36).max(36).optional(),\n\t\t\t\t\tlimit: tool.schema.number().int().min(1).max(100).optional(),\n\t\t\t\t},\n\t\t\t\tasync execute(args: { runId?: string; limit?: number }) {\n\t\t\t\t\tif (args.runId) {\n\t\t\t\t\t\tconst document = await client.runDocument(args.runId);\n\t\t\t\t\t\treturn JSON.stringify({ ...document, dashboard: `https://tokensize.dev/runs/${args.runId}` }, null, 2);\n\t\t\t\t\t}\n\t\t\t\t\treturn JSON.stringify(await client.runs({ limit: args.limit }), null, 2);\n\t\t\t\t},\n\t\t\t}),\n\t\t},\n\t};\n};\n\nexport { TokenSizePlugin };\nexport default TokenSizePlugin;\n"],"mappings":";AAAA,SAAsB,YAAY;AAClC,SAAS,uBAAuB;AAEhC,IAAM,kBAA0B,OAAO,EAAE,WAAW,SAAS,MAAM;AAClE,QAAM,SAAS,IAAI,gBAAgB,EAAE,eAAe,mBAAmB,aAAa,YAAY,YAAY,KAAK,CAAC;AAClH,QAAM,mBAAmB,YAAY;AACrC,SAAO;AAAA,IACN,MAAM;AAAA,MACL,kBAAkB,KAAK;AAAA,QACtB,aAAa;AAAA,QACb,MAAM,EAAE,SAAS,KAAK,OAAO,QAAQ,EAAE,SAAS,GAAG,SAAS,KAAK,OAAO,QAAQ,EAAE,SAA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,CAAC;AAAA,IACF;AAAA,EACD;AACD;AAGA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokensize/opencode",
|
|
3
|
+
"version": "0.3.0-beta.0",
|
|
4
|
+
"description": "TokenSize routing tools for OpenCode",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
|
9
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
10
|
+
"repository": { "type": "git", "url": "git+https://github.com/tokensize/tokensize.git", "directory": "packages/opencode" },
|
|
11
|
+
"homepage": "https://tokensize.dev",
|
|
12
|
+
"keywords": ["opencode", "ai", "agents", "delegation", "routing"],
|
|
13
|
+
"publishConfig": { "access": "public", "provenance": true, "tag": "beta" },
|
|
14
|
+
"engines": { "node": ">=20" },
|
|
15
|
+
"scripts": { "prebuild": "npm --prefix ../.. run build --workspace @tokensize/agent-client", "build": "tsup", "typecheck": "tsc --noEmit", "test": "vitest run", "prepack": "npm run build", "prepublishOnly": "npm run typecheck && npm test" },
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@opencode-ai/plugin": "1.18.3",
|
|
18
|
+
"@tokensize/agent-client": "0.3.0-beta.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": { "@types/node": "^26.1.1", "tsup": "^8.5.0", "typescript": "^5.5.2", "vitest": "^4.1.10" },
|
|
21
|
+
"license": "MIT"
|
|
22
|
+
}
|