@goodandready/dsh-subscriptions 0.6.56 → 0.6.57

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.
@@ -94,6 +94,8 @@ export const Config = z.object({
94
94
  .description('Custom model catalog for Codex.'),
95
95
  claudeSystemPrefix: z.string().volatile().default('')
96
96
  .description('System prompt prefix for Claude.'),
97
+ claudeCcVersion: z.string().volatile().default('')
98
+ .description('Claude Code version header for billing attribution (default: 2.1.289.7e2).'),
97
99
  claudeModels: z.array(z.any()).volatile().default([])
98
100
  .description('Custom model catalog for Claude.'),
99
101
  grokModels: z.array(z.any()).volatile().default([])
package/lib/usage.js CHANGED
@@ -3,8 +3,9 @@ export function numberOrNull(value) {
3
3
  return Number.isFinite(n) ? n : null
4
4
  }
5
5
 
6
- export function windowPercent(obj) {
6
+ export function windowPercent(obj, key) {
7
7
  if (!obj || typeof obj !== 'object') return null
8
+ if (key === 'extra_usage' || (obj.monthly_limit != null && obj.used_credits != null)) return null
8
9
  return numberOrNull(
9
10
  obj.utilization ?? obj.used_percent ?? obj.usedPercent ?? obj.creditUsagePercent ?? obj.used_percentage,
10
11
  )
@@ -12,9 +13,9 @@ export function windowPercent(obj) {
12
13
 
13
14
  export function deepestUsedPercent(obj) {
14
15
  let max = null
15
- function walk(value, depth) {
16
+ function walk(value, key, depth) {
16
17
  if (!value || typeof value !== 'object' || depth > 8) return
17
- const here = windowPercent(value)
18
+ const here = windowPercent(value, key)
18
19
  if (here != null) max = max == null ? here : Math.max(max, here)
19
20
  const remaining = numberOrNull(value.remainingFraction)
20
21
  if (remaining != null) {
@@ -26,11 +27,11 @@ export function deepestUsedPercent(obj) {
26
27
  const used = usedFrac * 100
27
28
  max = max == null ? used : Math.max(max, used)
28
29
  }
29
- for (const child of Object.values(value)) {
30
- if (child && typeof child === 'object') walk(child, depth + 1)
30
+ for (const [k, child] of Object.entries(value)) {
31
+ if (child && typeof child === 'object') walk(child, k, depth + 1)
31
32
  }
32
33
  }
33
- walk(obj, 0)
34
+ walk(obj, '', 0)
34
35
  return max
35
36
  }
36
37
 
@@ -81,6 +82,7 @@ const WINDOW_LABELS = {
81
82
  secondary_window: { zh: "7天", en: "7d" },
82
83
  monthly: { zh: "月度", en: "month" },
83
84
  credits: { zh: "点数", en: "credits" },
85
+ extra_usage: { zh: "额外用量", en: "extra" },
84
86
  }
85
87
 
86
88
  export function windowLabel(id) {
@@ -56,6 +56,7 @@ export function defaults() {
56
56
  return {
57
57
  clientId: '9d1c250a-e61b-44d9-88ed-5944d1962f5e',
58
58
  redirectUri: 'https://console.anthropic.com/oauth/code/callback',
59
+ claudeCcVersion: '2.1.289.7e2',
59
60
  models: [
60
61
  { id: 'claude-opus-5', name: 'Claude Opus 5' },
61
62
  { id: 'claude-sonnet-5', name: 'Claude Sonnet 5' },
@@ -137,7 +138,9 @@ export async function listModels(blob, cfg, fetchImpl) {
137
138
  "Accept": "application/json",
138
139
  "anthropic-version": "2023-06-01",
139
140
  }
140
- if (blob.accessToken.startsWith("sk-ant-")) {
141
+ if (blob.accessToken.startsWith("sk-ant-oat") || blob.accessToken.startsWith("sk-ant-ort")) {
142
+ headers["Authorization"] = `Bearer ${blob.accessToken}`
143
+ } else if (blob.accessToken.startsWith("sk-ant-")) {
141
144
  headers["x-api-key"] = blob.accessToken
142
145
  } else {
143
146
  headers["Authorization"] = `Bearer ${blob.accessToken}`
@@ -200,9 +203,37 @@ export async function usage(blob, _cfg, fetchImpl) {
200
203
  }
201
204
  }
202
205
 
206
+ export function makeClaudeBillingHeader(cfg) {
207
+ const ccVersion = (cfg && cfg.claudeCcVersion) || '2.1.289.7e2'
208
+ const cch = (globalThis.__DSH_CC_H__ || (() => {
209
+ globalThis.__DSH_CC_H__ = Math.random().toString(16).slice(2, 6)
210
+ return globalThis.__DSH_CC_H__
211
+ })())
212
+ const turnIndex = (globalThis.__DSH_CC_TURN__ = (globalThis.__DSH_CC_TURN__ || 0) + 1)
213
+ return `x-anthropic-billing-header: cc_version=${ccVersion}; cc_entrypoint=sdk-cli; cch=${cch}; cc_turn_origin=sdk; cc_prompt_index=0; cc_turn_index=${turnIndex};`
214
+ }
215
+
216
+ export function applyClaudeBillingHeader(payload, cfg) {
217
+ if (process.env.CLAUDE_CODE_ATTRIBUTION_HEADER === '0') return payload
218
+ if (!payload) return payload
219
+ const headerText = makeClaudeBillingHeader(cfg)
220
+ const headerBlock = { type: 'text', text: headerText }
221
+ if (Array.isArray(payload.system)) {
222
+ if (!payload.system.some((b) => typeof b === 'object' && b && typeof b.text === 'string' && b.text.startsWith('x-anthropic-billing-header:'))) {
223
+ payload.system = [headerBlock, ...payload.system]
224
+ }
225
+ } else if (typeof payload.system === 'string' && payload.system.trim()) {
226
+ payload.system = [headerBlock, { type: 'text', text: payload.system }]
227
+ } else if (!payload.system) {
228
+ payload.system = [headerBlock]
229
+ }
230
+ return payload
231
+ }
232
+
203
233
  export async function* streamOnce({ blob, options, fetchImpl, headers, config, signal }) {
204
234
  const payload = anthropicPayload(options, config.systemPrefix || IDENTITY)
205
235
  applyClaudeThinking(payload, options)
236
+ applyClaudeBillingHeader(payload, config)
206
237
  const res = await fetchImpl(API, {
207
238
  method: 'POST',
208
239
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-subscriptions",
3
- "version": "0.6.56",
3
+ "version": "0.6.57",
4
4
  "description": "Use ChatGPT Codex, Claude, Grok, Antigravity, Kimi, GLM, Cursor, Kiro, Copilot, Qwen, ERNIE, Spark, JetBrains, Perplexity, Replit, and Cody subscriptions as DeepSeek Harness LLM providers via OAuth.",
5
5
  "license": "MIT",
6
6
  "type": "module",