opencode-plugin-model-cost 0.0.0-stage → 1.0.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/README.md +16 -2
- package/dist/tui.js +64 -0
- package/package.json +29 -4
- package/src/index.ts +6 -0
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenCode Model Cost
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An OpenCode TUI plugin that displays the selected model's input and output prices below the prompt. Prices come from OpenCode's model catalog and are shown in USD per million tokens. If a model exposes tiered pricing without a standard rate, the plugin displays `tiered pricing`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
After publishing the package to npm, add it to the `plugins` array in your OpenCode configuration:
|
|
8
|
+
|
|
9
|
+
```jsonc
|
|
10
|
+
{
|
|
11
|
+
"plugins": ["opencode-plugin-model-cost@1.0.0"]
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Build
|
|
16
|
+
|
|
17
|
+
From this directory, run `npm install` and `npm run build`. `npm pack` and `npm publish` build the TUI entrypoint automatically.
|
package/dist/tui.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createTextNode as _$createTextNode } from "@opentui/solid";
|
|
2
|
+
import { insertNode as _$insertNode } from "@opentui/solid";
|
|
3
|
+
import { insert as _$insert } from "@opentui/solid";
|
|
4
|
+
import { memo as _$memo } from "@opentui/solid";
|
|
5
|
+
import { setProp as _$setProp } from "@opentui/solid";
|
|
6
|
+
import { createElement as _$createElement } from "@opentui/solid";
|
|
7
|
+
import { createComponent as _$createComponent } from "@opentui/solid";
|
|
8
|
+
/** @jsxImportSource @opentui/solid */
|
|
9
|
+
import { Plugin } from "@opencode/plugin/tui";
|
|
10
|
+
import { createEffect, Show } from "solid-js";
|
|
11
|
+
export default Plugin.define({
|
|
12
|
+
id: "model-cost",
|
|
13
|
+
setup(ctx) {
|
|
14
|
+
return ctx.ui.slot({
|
|
15
|
+
append: "prompt.footer",
|
|
16
|
+
render: input => {
|
|
17
|
+
const location = () => (input.sessionID ? ctx.data.session.get(input.sessionID)?.location : undefined) ?? ctx.location ?? ctx.data.location.default();
|
|
18
|
+
createEffect(() => {
|
|
19
|
+
void ctx.data.location.model.sync(location()).catch(error => {
|
|
20
|
+
console.error("[model-cost] failed to load models", error);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
const selectedModel = () => ctx.ui.model.current();
|
|
24
|
+
const modelInfo = () => {
|
|
25
|
+
const selected = selectedModel();
|
|
26
|
+
if (!selected) return;
|
|
27
|
+
return (ctx.data.location.model.list(location()) ?? []).find(model => model.providerID === selected.providerID && model.modelID === selected.modelID);
|
|
28
|
+
};
|
|
29
|
+
const pricing = () => {
|
|
30
|
+
const costs = modelInfo()?.cost ?? [];
|
|
31
|
+
const standardCost = costs.find(cost => !cost.tier);
|
|
32
|
+
if (standardCost) {
|
|
33
|
+
const formatPrice = price => new Intl.NumberFormat("en-US", {
|
|
34
|
+
style: "currency",
|
|
35
|
+
currency: "USD",
|
|
36
|
+
minimumFractionDigits: 2,
|
|
37
|
+
maximumFractionDigits: 6
|
|
38
|
+
}).format(price);
|
|
39
|
+
return `${formatPrice(standardCost.input)}/${formatPrice(standardCost.output)} per 1M tokens`;
|
|
40
|
+
}
|
|
41
|
+
return costs.length > 0 ? "tiered pricing" : "pricing unavailable";
|
|
42
|
+
};
|
|
43
|
+
return _$createComponent(Show, {
|
|
44
|
+
get when() {
|
|
45
|
+
return selectedModel();
|
|
46
|
+
},
|
|
47
|
+
children: selected => (() => {
|
|
48
|
+
var _el$ = _$createElement("box"),
|
|
49
|
+
_el$2 = _$createElement("text"),
|
|
50
|
+
_el$3 = _$createTextNode(` (`),
|
|
51
|
+
_el$4 = _$createTextNode(`)`);
|
|
52
|
+
_$insertNode(_el$, _el$2);
|
|
53
|
+
_$setProp(_el$, "flexDirection", "row");
|
|
54
|
+
_$insertNode(_el$2, _el$3);
|
|
55
|
+
_$insertNode(_el$2, _el$4);
|
|
56
|
+
_$insert(_el$2, () => modelInfo()?.name ?? selected().modelID, _el$3);
|
|
57
|
+
_$insert(_el$2, pricing, _el$4);
|
|
58
|
+
return _el$;
|
|
59
|
+
})()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-plugin-model-cost",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Displays the active model's input and output prices in the OpenCode TUI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./tui": "./dist/tui.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/index.ts",
|
|
12
|
+
"dist/tui.js"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "node scripts/build-tui.mjs",
|
|
16
|
+
"prepack": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@opencode/plugin": "latest"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@babel/core": "^7.29.7",
|
|
23
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
24
|
+
"babel-preset-solid": "^1.9.16"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@opentui/core": ">=0.8.4",
|
|
28
|
+
"@opentui/solid": ">=0.8.4",
|
|
29
|
+
"solid-js": ">=1.9.0"
|
|
30
|
+
}
|
|
31
|
+
}
|