@inferhub/opencode-usage 0.1.2 → 0.1.3
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/dist/index.js +1 -1
- package/dist/tui.js +45 -38
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ export const InferHubUsagePlugin = async (ctx, options) => {
|
|
|
35
35
|
return {
|
|
36
36
|
tool: {
|
|
37
37
|
inferhub_usage: tool({
|
|
38
|
-
description: "Show InferHub balance
|
|
38
|
+
description: "Show InferHub balance and session/today/all-time usage for the current account",
|
|
39
39
|
args: {},
|
|
40
40
|
async execute() {
|
|
41
41
|
try {
|
package/dist/tui.js
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OpenCode TUI plugin —
|
|
2
|
+
* OpenCode TUI plugin — same InferHub status line as Claude Code.
|
|
3
3
|
*
|
|
4
4
|
* Install:
|
|
5
|
-
*
|
|
6
|
-
* # or in opencode.json:
|
|
7
|
-
* { "plugin": ["opencode-inferhub-usage", "opencode-inferhub-usage/tui"] }
|
|
8
|
-
*
|
|
9
|
-
* Note: TUI plugins require OpenCode's TUI module export (`./tui`). If the
|
|
10
|
-
* runtime version only supports server plugins, the server tool still works.
|
|
5
|
+
* { "plugin": ["@inferhub/opencode-usage", "@inferhub/opencode-usage/tui"] }
|
|
11
6
|
*/
|
|
12
|
-
import { fetchAccountUsageAuto, formatStatusLine, money,
|
|
7
|
+
import { fetchAccountUsageAuto, formatStatusLine, money, } from "@inferhub/usage";
|
|
13
8
|
let cached = null;
|
|
14
|
-
let
|
|
15
|
-
let
|
|
9
|
+
let openCodeSessionId = null;
|
|
10
|
+
let model = null;
|
|
16
11
|
async function refresh() {
|
|
17
12
|
try {
|
|
18
|
-
const { usage } = await fetchAccountUsageAuto({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
const { usage } = await fetchAccountUsageAuto({
|
|
14
|
+
window: "day",
|
|
15
|
+
// Prefer OpenCode's session id when known so sess matches Claude semantics
|
|
16
|
+
sessionId: openCodeSessionId || undefined,
|
|
17
|
+
});
|
|
18
|
+
// If we asked for a specific session and API returned something else / empty,
|
|
19
|
+
// strip mismatched session (same rule as Claude statusline).
|
|
20
|
+
if (openCodeSessionId) {
|
|
21
|
+
const got = usage.session?.id ? String(usage.session.id) : "";
|
|
22
|
+
if (got !== openCodeSessionId && !got.includes(openCodeSessionId)) {
|
|
23
|
+
usage.session = null;
|
|
24
|
+
}
|
|
25
|
+
else if (usage.session) {
|
|
26
|
+
usage.session.id = openCodeSessionId;
|
|
27
|
+
}
|
|
22
28
|
}
|
|
29
|
+
else {
|
|
30
|
+
// No OpenCode session id → don't show account-latest sess (avoids jumping)
|
|
31
|
+
usage.session = null;
|
|
32
|
+
}
|
|
33
|
+
cached = usage;
|
|
23
34
|
return usage;
|
|
24
35
|
}
|
|
25
36
|
catch {
|
|
@@ -28,55 +39,51 @@ async function refresh() {
|
|
|
28
39
|
}
|
|
29
40
|
function line() {
|
|
30
41
|
if (!cached)
|
|
31
|
-
return "
|
|
32
|
-
return formatStatusLine(cached, {
|
|
33
|
-
sessionCostUsd: sessionCost,
|
|
34
|
-
model: sessionModel,
|
|
35
|
-
});
|
|
42
|
+
return "InferHub · loading…";
|
|
43
|
+
return formatStatusLine(cached, { model });
|
|
36
44
|
}
|
|
37
45
|
export async function tui(api) {
|
|
38
46
|
void refresh();
|
|
39
|
-
const timer = setInterval(() => void refresh(),
|
|
47
|
+
const timer = setInterval(() => void refresh(), 30_000);
|
|
40
48
|
const offIdle = api.event.on("session.idle", () => void refresh());
|
|
49
|
+
const offCreated = api.event.on("session.created", (ev) => {
|
|
50
|
+
const info = ev?.properties?.info ?? ev?.info ?? ev?.properties ?? {};
|
|
51
|
+
const id = info.id || info.sessionID || info.sessionId || ev?.properties?.sessionID;
|
|
52
|
+
if (typeof id === "string" && id)
|
|
53
|
+
openCodeSessionId = id;
|
|
54
|
+
void refresh();
|
|
55
|
+
});
|
|
41
56
|
const offUpd = api.event.on("session.updated", (ev) => {
|
|
42
57
|
const info = ev?.properties?.info ?? ev?.info ?? {};
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
const id = info.id || info.sessionID || info.sessionId;
|
|
59
|
+
if (typeof id === "string" && id)
|
|
60
|
+
openCodeSessionId = id;
|
|
45
61
|
if (typeof info.model === "string")
|
|
46
|
-
|
|
62
|
+
model = info.model;
|
|
47
63
|
if (info.model?.id)
|
|
48
|
-
|
|
64
|
+
model = info.model.id;
|
|
65
|
+
void refresh();
|
|
49
66
|
});
|
|
50
67
|
api.lifecycle.onDispose(() => {
|
|
51
68
|
clearInterval(timer);
|
|
52
69
|
offIdle();
|
|
70
|
+
offCreated();
|
|
53
71
|
offUpd();
|
|
54
72
|
});
|
|
55
|
-
// Prefer slots when the host supports Solid slot plugins.
|
|
56
73
|
try {
|
|
57
74
|
api.slots.register({
|
|
58
75
|
name: "inferhub-usage",
|
|
59
|
-
// Hosts that accept render functions will display these; others ignore.
|
|
60
76
|
slots: {
|
|
77
|
+
// Same string Claude shows, everywhere we can place it.
|
|
61
78
|
home_footer: () => line(),
|
|
62
|
-
sidebar_footer: () =>
|
|
63
|
-
|
|
64
|
-
return "IH …";
|
|
65
|
-
return `bal ${money(cached.balance.amount_usdc)} · all ${money(cached.all_time.spend_usdc)} · top ${shortModel(cached.top_model?.model)}`;
|
|
66
|
-
},
|
|
67
|
-
sidebar_content: () => {
|
|
68
|
-
if (!cached)
|
|
69
|
-
return "InferHub usage loading…";
|
|
70
|
-
const sess = sessionCost != null ? money(sessionCost) : "—";
|
|
71
|
-
return `IH session ${sess} · day ${money(cached.window.spend_usdc)} · ${cached.window.requests} req`;
|
|
72
|
-
},
|
|
79
|
+
sidebar_footer: () => line(),
|
|
80
|
+
sidebar_content: () => line(),
|
|
73
81
|
},
|
|
74
82
|
});
|
|
75
83
|
}
|
|
76
84
|
catch {
|
|
77
85
|
// Slot API unavailable — server tool still works.
|
|
78
86
|
}
|
|
79
|
-
// Toast on first successful load when balance is low.
|
|
80
87
|
void refresh().then((u) => {
|
|
81
88
|
if (u && Number(u.balance.amount_usdc) < 0.5) {
|
|
82
89
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inferhub/opencode-usage",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "OpenCode plugin: InferHub balance, session/day/all-time usage, top model",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"prepublishOnly": "npm run build"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@inferhub/usage": "^0.1.
|
|
27
|
+
"@inferhub/usage": "^0.1.11",
|
|
28
28
|
"@opencode-ai/plugin": "^1.17.18"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|