@goodandready/dsh-clinebot 0.5.32 → 0.6.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/CHANGELOG.md +31 -0
- package/README.md +63 -36
- package/README.ru.md +3 -1
- package/README.zh.md +3 -1
- package/lib/adapter-messages.js +237 -0
- package/lib/adapter-stream.js +292 -0
- package/lib/adapter.js +616 -0
- package/lib/client.js +2564 -924
- package/lib/cline-client.js +15 -6
- package/lib/config.js +266 -233
- package/lib/credential-refs.js +104 -84
- package/lib/index.js +569 -502
- package/lib/model-prices.js +117 -0
- package/lib/provider-sync.js +404 -387
- package/lib/proxy-token.js +187 -140
- package/lib/routes/accounts.js +523 -403
- package/lib/routes/models.js +2 -1
- package/lib/routes/proxy.js +8 -27
- package/lib/routes/settings.js +63 -2
- package/lib/services.js +55 -0
- package/lib/stats-storage.js +364 -166
- package/lib/transport/cline-transport.js +314 -0
- package/lib/tui-settings.js +158 -0
- package/lib/updater.js +5 -1
- package/package.json +113 -77
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local cost estimates for ClinePass models.
|
|
3
|
+
*
|
|
4
|
+
* ClinePass is a subscription, not a per-token invoice surface. These figures
|
|
5
|
+
* are explicit ESTIMATES used only for the composer read-out and local
|
|
6
|
+
* analytics; users can replace any rate through `priceOverrides`. A model with
|
|
7
|
+
* no known or overridden rate stays `unpriced` rather than being shown as $0.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const PRICE_TABLE_VERSION = 1
|
|
11
|
+
|
|
12
|
+
const OPEN_WEIGHT = Object.freeze({ input: 0.15, output: 0.6, cacheRead: 0.003, cacheWrite: null })
|
|
13
|
+
const CLAUDE = Object.freeze({ input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 })
|
|
14
|
+
const PREMIUM = Object.freeze({ input: 2.5, output: 10, cacheRead: 0.25, cacheWrite: null })
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolve one model's rates, preferring a user override.
|
|
18
|
+
* @param {string} modelId
|
|
19
|
+
* @param {Record<string, { input?: number, output?: number, cacheRead?: number, cacheWrite?: number }>} [overrides]
|
|
20
|
+
* @returns {{ input: number, output: number, cacheRead: number|null, cacheWrite: number|null, source: string } | null}
|
|
21
|
+
*/
|
|
22
|
+
export function resolveModelPrice(modelId, overrides = {}) {
|
|
23
|
+
const id = String(modelId || '').toLowerCase()
|
|
24
|
+
const override = overrides && typeof overrides === 'object' ? overrides[modelId] : undefined
|
|
25
|
+
if (override && typeof override === 'object') {
|
|
26
|
+
return {
|
|
27
|
+
input: Math.max(0, Number(override.input) || 0),
|
|
28
|
+
output: Math.max(0, Number(override.output) || 0),
|
|
29
|
+
cacheRead: override.cacheRead === undefined || override.cacheRead === null ? null : Math.max(0, Number(override.cacheRead) || 0),
|
|
30
|
+
cacheWrite: override.cacheWrite === undefined || override.cacheWrite === null ? null : Math.max(0, Number(override.cacheWrite) || 0),
|
|
31
|
+
source: 'override',
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!id) return null
|
|
35
|
+
if (id.includes('claude')) return { ...CLAUDE, source: 'estimate' }
|
|
36
|
+
if (id.includes('gpt-') || id.includes('o3') || id.includes('o4')) return { ...PREMIUM, source: 'estimate' }
|
|
37
|
+
if (/(deepseek|glm|kimi|qwen|minimax|mimo|llama|mistral)/.test(id)) return { ...OPEN_WEIGHT, source: 'estimate' }
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Estimate one request's USD cost from its token buckets.
|
|
43
|
+
*
|
|
44
|
+
* `promptTokens` includes cached input; cache buckets are priced separately.
|
|
45
|
+
* Reasoning tokens are already part of `completionTokens` in the OpenAI wire.
|
|
46
|
+
*
|
|
47
|
+
* @param {{
|
|
48
|
+
* model: string,
|
|
49
|
+
* promptTokens?: number,
|
|
50
|
+
* completionTokens?: number,
|
|
51
|
+
* reasoningTokens?: number,
|
|
52
|
+
* cacheReadTokens?: number,
|
|
53
|
+
* cacheWriteTokens?: number,
|
|
54
|
+
* overrides?: Record<string, unknown>,
|
|
55
|
+
* }} entry
|
|
56
|
+
* @returns {{ usd: number, priced: boolean, breakdown: { input: number, output: number, cacheRead: number, cacheWrite: number } }}
|
|
57
|
+
*/
|
|
58
|
+
export function estimateCost({
|
|
59
|
+
model,
|
|
60
|
+
promptTokens = 0,
|
|
61
|
+
completionTokens = 0,
|
|
62
|
+
reasoningTokens = 0,
|
|
63
|
+
cacheReadTokens = 0,
|
|
64
|
+
cacheWriteTokens = 0,
|
|
65
|
+
overrides = {},
|
|
66
|
+
}) {
|
|
67
|
+
const price = resolveModelPrice(model, overrides)
|
|
68
|
+
if (!price) {
|
|
69
|
+
return { usd: 0, priced: false, breakdown: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } }
|
|
70
|
+
}
|
|
71
|
+
const prompt = Math.max(0, Number(promptTokens) || 0)
|
|
72
|
+
const cacheRead = Math.max(0, Number(cacheReadTokens) || 0)
|
|
73
|
+
const cacheWrite = Math.max(0, Number(cacheWriteTokens) || 0)
|
|
74
|
+
const uncachedInput = Math.max(0, prompt - cacheRead - cacheWrite)
|
|
75
|
+
const output = Math.max(0, Number(completionTokens) || 0)
|
|
76
|
+
const breakdown = {
|
|
77
|
+
input: (uncachedInput * price.input) / 1_000_000,
|
|
78
|
+
output: (output * price.output) / 1_000_000,
|
|
79
|
+
cacheRead: price.cacheRead === null ? 0 : (cacheRead * price.cacheRead) / 1_000_000,
|
|
80
|
+
cacheWrite: price.cacheWrite === null ? 0 : (cacheWrite * price.cacheWrite) / 1_000_000,
|
|
81
|
+
}
|
|
82
|
+
const usd = breakdown.input + breakdown.output + breakdown.cacheRead + breakdown.cacheWrite
|
|
83
|
+
return { usd, priced: true, breakdown }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Public price table for the browser composer read-out.
|
|
88
|
+
* @param {Record<string, unknown>} [overrides]
|
|
89
|
+
* @returns {{ version: number, currency: string, models: Array<Record<string, unknown>> }}
|
|
90
|
+
*/
|
|
91
|
+
export function priceTable(overrides = {}, modelIds = []) {
|
|
92
|
+
const rows = new Map()
|
|
93
|
+
for (const modelId of Array.isArray(modelIds) ? modelIds : []) {
|
|
94
|
+
const price = resolveModelPrice(modelId, overrides)
|
|
95
|
+
if (!price) continue
|
|
96
|
+
rows.set(modelId, {
|
|
97
|
+
id: modelId,
|
|
98
|
+
input: price.input,
|
|
99
|
+
output: price.output,
|
|
100
|
+
cacheRead: price.cacheRead,
|
|
101
|
+
cacheWrite: price.cacheWrite,
|
|
102
|
+
source: price.source,
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
for (const [modelId, rates] of Object.entries(overrides || {})) {
|
|
106
|
+
if (rows.has(modelId) || !rates || typeof rates !== 'object') continue
|
|
107
|
+
rows.set(modelId, {
|
|
108
|
+
id: modelId,
|
|
109
|
+
input: Math.max(0, Number(rates.input) || 0),
|
|
110
|
+
output: Math.max(0, Number(rates.output) || 0),
|
|
111
|
+
cacheRead: rates.cacheRead === undefined ? null : Math.max(0, Number(rates.cacheRead) || 0),
|
|
112
|
+
cacheWrite: rates.cacheWrite === undefined ? null : Math.max(0, Number(rates.cacheWrite) || 0),
|
|
113
|
+
source: 'override',
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
return { version: PRICE_TABLE_VERSION, currency: 'USD', models: [...rows.values()] }
|
|
117
|
+
}
|