oc-plugin-litellm-budget 0.2.0 → 0.4.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/package.json +1 -1
- package/tui.tsx +23 -2
package/package.json
CHANGED
package/tui.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
|
|
3
3
|
import { createSignal, onCleanup, Show } from "solid-js"
|
|
4
|
+
import { readFileSync } from "fs"
|
|
5
|
+
import { join } from "path"
|
|
6
|
+
import { homedir } from "os"
|
|
4
7
|
|
|
5
8
|
const POLL_MS = 60_000
|
|
6
9
|
|
|
@@ -11,9 +14,27 @@ type QuotaData = {
|
|
|
11
14
|
tpm: number
|
|
12
15
|
}
|
|
13
16
|
|
|
17
|
+
const readKeyFromConfig = (): string => {
|
|
18
|
+
const paths = [
|
|
19
|
+
join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode", "opencode.json"),
|
|
20
|
+
join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode", "opencode.jsonc"),
|
|
21
|
+
]
|
|
22
|
+
for (const p of paths) {
|
|
23
|
+
try {
|
|
24
|
+
const raw = readFileSync(p, "utf8")
|
|
25
|
+
const clean = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "")
|
|
26
|
+
const d = JSON.parse(clean)
|
|
27
|
+
const k = d?.provider?.binetz?.options?.apiKey
|
|
28
|
+
if (k && typeof k === "string" && k !== "{env:BINETZ_REMOTE_CONFIG_TOKEN}") return k
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
return ""
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
const getConfig = () => {
|
|
15
|
-
const
|
|
16
|
-
const key =
|
|
35
|
+
const envKey = process.env.LITELLM_API_KEY || process.env.OPENAI_API_KEY || process.env.BINETZ_REMOTE_CONFIG_TOKEN || ""
|
|
36
|
+
const key = envKey || readKeyFromConfig()
|
|
37
|
+
const url = process.env.LITELLM_BASE_URL || process.env.OPENAI_BASE_URL || (key ? "https://litellm.binetz.com" : "")
|
|
17
38
|
return { url: url.replace(/\/+$/, ""), key }
|
|
18
39
|
}
|
|
19
40
|
|