@laoyuehanni/dsh-token-usage 0.3.7

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.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +178 -0
  3. package/README.zh.md +182 -0
  4. package/cordis.patch.yml +7 -0
  5. package/lib/client/CostDeltaFlyLabel.d.ts +8 -0
  6. package/lib/client/CostDeltaFlyLabel.d.ts.map +1 -0
  7. package/lib/client/CostDeltaFlyLabel.js +24 -0
  8. package/lib/client/CostDeltaFlyLabel.js.map +1 -0
  9. package/lib/client/HitRateText.d.ts +21 -0
  10. package/lib/client/HitRateText.d.ts.map +1 -0
  11. package/lib/client/HitRateText.js +16 -0
  12. package/lib/client/HitRateText.js.map +1 -0
  13. package/lib/client/QuotaButton.d.ts +70 -0
  14. package/lib/client/QuotaButton.d.ts.map +1 -0
  15. package/lib/client/QuotaButton.js +346 -0
  16. package/lib/client/QuotaButton.js.map +1 -0
  17. package/lib/client/SessionStatsChip.d.ts +47 -0
  18. package/lib/client/SessionStatsChip.d.ts.map +1 -0
  19. package/lib/client/SessionStatsChip.js +141 -0
  20. package/lib/client/SessionStatsChip.js.map +1 -0
  21. package/lib/client/StatCard.d.ts +26 -0
  22. package/lib/client/StatCard.d.ts.map +1 -0
  23. package/lib/client/StatCard.js +10 -0
  24. package/lib/client/StatCard.js.map +1 -0
  25. package/lib/client/TokenUsageCard.d.ts +41 -0
  26. package/lib/client/TokenUsageCard.d.ts.map +1 -0
  27. package/lib/client/TokenUsageCard.js +164 -0
  28. package/lib/client/TokenUsageCard.js.map +1 -0
  29. package/lib/client/TokenUsageSection.d.ts +32 -0
  30. package/lib/client/TokenUsageSection.d.ts.map +1 -0
  31. package/lib/client/TokenUsageSection.js +266 -0
  32. package/lib/client/TokenUsageSection.js.map +1 -0
  33. package/lib/client/TrendChart.d.ts +53 -0
  34. package/lib/client/TrendChart.d.ts.map +1 -0
  35. package/lib/client/TrendChart.js +141 -0
  36. package/lib/client/TrendChart.js.map +1 -0
  37. package/lib/client/UsageView.d.ts +42 -0
  38. package/lib/client/UsageView.d.ts.map +1 -0
  39. package/lib/client/UsageView.js +158 -0
  40. package/lib/client/UsageView.js.map +1 -0
  41. package/lib/client/async-resource.d.ts +54 -0
  42. package/lib/client/async-resource.d.ts.map +1 -0
  43. package/lib/client/async-resource.js +90 -0
  44. package/lib/client/async-resource.js.map +1 -0
  45. package/lib/client/card-form.d.ts +171 -0
  46. package/lib/client/card-form.d.ts.map +1 -0
  47. package/lib/client/card-form.js +300 -0
  48. package/lib/client/card-form.js.map +1 -0
  49. package/lib/client/cost-inflate-motion.d.ts +17 -0
  50. package/lib/client/cost-inflate-motion.d.ts.map +1 -0
  51. package/lib/client/cost-inflate-motion.js +61 -0
  52. package/lib/client/cost-inflate-motion.js.map +1 -0
  53. package/lib/client/cost-inflate.d.ts +28 -0
  54. package/lib/client/cost-inflate.d.ts.map +1 -0
  55. package/lib/client/cost-inflate.js +49 -0
  56. package/lib/client/cost-inflate.js.map +1 -0
  57. package/lib/client/day.d.ts +49 -0
  58. package/lib/client/day.d.ts.map +1 -0
  59. package/lib/client/day.js +84 -0
  60. package/lib/client/day.js.map +1 -0
  61. package/lib/client/format.d.ts +120 -0
  62. package/lib/client/format.d.ts.map +1 -0
  63. package/lib/client/format.js +163 -0
  64. package/lib/client/format.js.map +1 -0
  65. package/lib/client/index.d.ts +26 -0
  66. package/lib/client/index.d.ts.map +1 -0
  67. package/lib/client/index.js +131 -0
  68. package/lib/client/index.js.map +1 -0
  69. package/lib/client/locales.d.ts +131 -0
  70. package/lib/client/locales.d.ts.map +1 -0
  71. package/lib/client/locales.js +230 -0
  72. package/lib/client/locales.js.map +1 -0
  73. package/lib/client/quota-format.d.ts +69 -0
  74. package/lib/client/quota-format.d.ts.map +1 -0
  75. package/lib/client/quota-format.js +147 -0
  76. package/lib/client/quota-format.js.map +1 -0
  77. package/lib/client/session-stats.d.ts +105 -0
  78. package/lib/client/session-stats.d.ts.map +1 -0
  79. package/lib/client/session-stats.js +142 -0
  80. package/lib/client/session-stats.js.map +1 -0
  81. package/lib/client/trend-chart/axis.d.ts +21 -0
  82. package/lib/client/trend-chart/axis.d.ts.map +1 -0
  83. package/lib/client/trend-chart/axis.js +33 -0
  84. package/lib/client/trend-chart/axis.js.map +1 -0
  85. package/lib/client/trend-chart/bucket.d.ts +24 -0
  86. package/lib/client/trend-chart/bucket.d.ts.map +1 -0
  87. package/lib/client/trend-chart/bucket.js +28 -0
  88. package/lib/client/trend-chart/bucket.js.map +1 -0
  89. package/lib/client/trend-chart/index.d.ts +12 -0
  90. package/lib/client/trend-chart/index.d.ts.map +1 -0
  91. package/lib/client/trend-chart/index.js +9 -0
  92. package/lib/client/trend-chart/index.js.map +1 -0
  93. package/lib/client/trend-chart/points.d.ts +46 -0
  94. package/lib/client/trend-chart/points.d.ts.map +1 -0
  95. package/lib/client/trend-chart/points.js +82 -0
  96. package/lib/client/trend-chart/points.js.map +1 -0
  97. package/lib/client/trend-chart/scale.d.ts +47 -0
  98. package/lib/client/trend-chart/scale.d.ts.map +1 -0
  99. package/lib/client/trend-chart/scale.js +75 -0
  100. package/lib/client/trend-chart/scale.js.map +1 -0
  101. package/lib/client/use-color-scheme.d.ts +18 -0
  102. package/lib/client/use-color-scheme.d.ts.map +1 -0
  103. package/lib/client/use-color-scheme.js +37 -0
  104. package/lib/client/use-color-scheme.js.map +1 -0
  105. package/lib/client/use-cost-inflate.d.ts +33 -0
  106. package/lib/client/use-cost-inflate.d.ts.map +1 -0
  107. package/lib/client/use-cost-inflate.js +108 -0
  108. package/lib/client/use-cost-inflate.js.map +1 -0
  109. package/lib/client.js +3892 -0
  110. package/lib/client.js.map +1 -0
  111. package/lib/index.d.ts +132 -0
  112. package/lib/index.d.ts.map +1 -0
  113. package/lib/index.js +599 -0
  114. package/lib/index.js.map +1 -0
  115. package/lib/migrate.d.ts +60 -0
  116. package/lib/migrate.d.ts.map +1 -0
  117. package/lib/migrate.js +126 -0
  118. package/lib/migrate.js.map +1 -0
  119. package/lib/pricing.d.ts +212 -0
  120. package/lib/pricing.d.ts.map +1 -0
  121. package/lib/pricing.js +492 -0
  122. package/lib/pricing.js.map +1 -0
  123. package/lib/quota/adapters/deepseek-balance.d.ts +18 -0
  124. package/lib/quota/adapters/deepseek-balance.d.ts.map +1 -0
  125. package/lib/quota/adapters/deepseek-balance.js +76 -0
  126. package/lib/quota/adapters/deepseek-balance.js.map +1 -0
  127. package/lib/quota/adapters/kimi.d.ts +26 -0
  128. package/lib/quota/adapters/kimi.d.ts.map +1 -0
  129. package/lib/quota/adapters/kimi.js +91 -0
  130. package/lib/quota/adapters/kimi.js.map +1 -0
  131. package/lib/quota/adapters/minimax.d.ts +24 -0
  132. package/lib/quota/adapters/minimax.d.ts.map +1 -0
  133. package/lib/quota/adapters/minimax.js +136 -0
  134. package/lib/quota/adapters/minimax.js.map +1 -0
  135. package/lib/quota/adapters/opencode-go.d.ts +25 -0
  136. package/lib/quota/adapters/opencode-go.d.ts.map +1 -0
  137. package/lib/quota/adapters/opencode-go.js +105 -0
  138. package/lib/quota/adapters/opencode-go.js.map +1 -0
  139. package/lib/quota/adapters/openrouter.d.ts +15 -0
  140. package/lib/quota/adapters/openrouter.d.ts.map +1 -0
  141. package/lib/quota/adapters/openrouter.js +54 -0
  142. package/lib/quota/adapters/openrouter.js.map +1 -0
  143. package/lib/quota/adapters/zhipu.d.ts +38 -0
  144. package/lib/quota/adapters/zhipu.d.ts.map +1 -0
  145. package/lib/quota/adapters/zhipu.js +246 -0
  146. package/lib/quota/adapters/zhipu.js.map +1 -0
  147. package/lib/quota/credentials.d.ts +79 -0
  148. package/lib/quota/credentials.d.ts.map +1 -0
  149. package/lib/quota/credentials.js +130 -0
  150. package/lib/quota/credentials.js.map +1 -0
  151. package/lib/quota/http.d.ts +49 -0
  152. package/lib/quota/http.d.ts.map +1 -0
  153. package/lib/quota/http.js +114 -0
  154. package/lib/quota/http.js.map +1 -0
  155. package/lib/quota/provider-tracking.d.ts +45 -0
  156. package/lib/quota/provider-tracking.d.ts.map +1 -0
  157. package/lib/quota/provider-tracking.js +52 -0
  158. package/lib/quota/provider-tracking.js.map +1 -0
  159. package/lib/quota/quota-route.d.ts +22 -0
  160. package/lib/quota/quota-route.d.ts.map +1 -0
  161. package/lib/quota/quota-route.js +57 -0
  162. package/lib/quota/quota-route.js.map +1 -0
  163. package/lib/quota/quota-service.d.ts +54 -0
  164. package/lib/quota/quota-service.d.ts.map +1 -0
  165. package/lib/quota/quota-service.js +171 -0
  166. package/lib/quota/quota-service.js.map +1 -0
  167. package/lib/quota/registry.d.ts +24 -0
  168. package/lib/quota/registry.d.ts.map +1 -0
  169. package/lib/quota/registry.js +38 -0
  170. package/lib/quota/registry.js.map +1 -0
  171. package/lib/quota/types.d.ts +79 -0
  172. package/lib/quota/types.d.ts.map +1 -0
  173. package/lib/quota/types.js +24 -0
  174. package/lib/quota/types.js.map +1 -0
  175. package/lib/record-cache.d.ts +38 -0
  176. package/lib/record-cache.d.ts.map +1 -0
  177. package/lib/record-cache.js +143 -0
  178. package/lib/record-cache.js.map +1 -0
  179. package/lib/rollup.d.ts +52 -0
  180. package/lib/rollup.d.ts.map +1 -0
  181. package/lib/rollup.js +117 -0
  182. package/lib/rollup.js.map +1 -0
  183. package/lib/stats-route.d.ts +88 -0
  184. package/lib/stats-route.d.ts.map +1 -0
  185. package/lib/stats-route.js +313 -0
  186. package/lib/stats-route.js.map +1 -0
  187. package/lib/stats.d.ts +158 -0
  188. package/lib/stats.d.ts.map +1 -0
  189. package/lib/stats.js +426 -0
  190. package/lib/stats.js.map +1 -0
  191. package/lib/sync-state.d.ts +27 -0
  192. package/lib/sync-state.d.ts.map +1 -0
  193. package/lib/sync-state.js +56 -0
  194. package/lib/sync-state.js.map +1 -0
  195. package/lib/sync.d.ts +74 -0
  196. package/lib/sync.d.ts.map +1 -0
  197. package/lib/sync.js +64 -0
  198. package/lib/sync.js.map +1 -0
  199. package/lib/trend-bucket.d.ts +48 -0
  200. package/lib/trend-bucket.d.ts.map +1 -0
  201. package/lib/trend-bucket.js +87 -0
  202. package/lib/trend-bucket.js.map +1 -0
  203. package/lib/usage-log.d.ts +64 -0
  204. package/lib/usage-log.d.ts.map +1 -0
  205. package/lib/usage-log.js +144 -0
  206. package/lib/usage-log.js.map +1 -0
  207. package/lib/usage-record.d.ts +59 -0
  208. package/lib/usage-record.d.ts.map +1 -0
  209. package/lib/usage-record.js +115 -0
  210. package/lib/usage-record.js.map +1 -0
  211. package/lib/wire.d.ts +452 -0
  212. package/lib/wire.d.ts.map +1 -0
  213. package/lib/wire.js +144 -0
  214. package/lib/wire.js.map +1 -0
  215. package/package.json +100 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/quota/http.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAsB,EAAE,GAAW,EAAE,UAAkC,EAAE;IACvG,IAAI,QAAkB,CAAA;IACtB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,EAAE;YACnD,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5D,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qEAAqE;QACrE,+DAA+D;QAC/D,MAAM,IAAI,eAAe,CAAC,SAAS,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,C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,MAAM,CAAC,OAA2B;IAChD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,SAAS,CAAA;IAC7D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAA;QACpD,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Live provider tracking (node half): which LLM provider route the active
3
+ * session is using, fed from the session events the host already emits.
4
+ * `request/context` arrives when a request dispatches (provider known
5
+ * before the first token); `assistant/message` re-confirms it from the
6
+ * message provenance. The map is deliberately in-memory: quota is about
7
+ * the provider in use NOW, and a restart re-seeds from the next event or
8
+ * the default-model selection.
9
+ *
10
+ * @module token-usage/quota/provider-tracking
11
+ */
12
+ /** One observed provider use of a session. */
13
+ export interface ProviderSighting {
14
+ /** Provider route key (`zai-coding-cn`, `deepseek-official`, …). */
15
+ provider: string;
16
+ /** Model id the request used. */
17
+ model: string;
18
+ /** When the sighting happened, epoch ms. */
19
+ at: number;
20
+ }
21
+ /** In-memory session → latest sighting map with a global fallback. */
22
+ export declare class ProviderTracker {
23
+ #private;
24
+ /** Record that a session used a provider (later sightings win). */
25
+ observe(sessionId: string, provider: string, model: string, at?: number): void;
26
+ /** The session's latest sighting, else the most recent sighting of any
27
+ * session (a brand-new session inherits the last provider in use — the
28
+ * shell's own default-then-remembered behavior). */
29
+ sightingOf(sessionId: string | undefined): ProviderSighting | undefined;
30
+ }
31
+ /**
32
+ * Resolve the provider route a quota query should target: the tracker's
33
+ * sighting first (the active session's or the global last), else the
34
+ * host's default model selection (the `agent-default-model` settings
35
+ * section — what a brand-new, never-requesting session would use).
36
+ * @param input - the tracker, the asking session, and a thunk reading the
37
+ * default selection's `provider` (undefined when no default is stored).
38
+ * @returns the route key, or undefined when nothing determinable exists.
39
+ */
40
+ export declare function resolveCurrentProvider(input: {
41
+ tracker: ProviderTracker;
42
+ sessionId?: string;
43
+ defaultProvider?: () => string | undefined;
44
+ }): string | undefined;
45
+ //# sourceMappingURL=provider-tracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-tracking.d.ts","sourceRoot":"","sources":["../../src/quota/provider-tracking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAA;IAChB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAA;CACX;AAED,sEAAsE;AACtE,qBAAa,eAAe;;IAI1B,mEAAmE;IACnE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAE,MAAmB,GAAG,IAAI;IAO1F;;wDAEoD;IACpD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS;CAOxE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;CAC3C,GAAG,MAAM,GAAG,SAAS,CAKrB"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Live provider tracking (node half): which LLM provider route the active
3
+ * session is using, fed from the session events the host already emits.
4
+ * `request/context` arrives when a request dispatches (provider known
5
+ * before the first token); `assistant/message` re-confirms it from the
6
+ * message provenance. The map is deliberately in-memory: quota is about
7
+ * the provider in use NOW, and a restart re-seeds from the next event or
8
+ * the default-model selection.
9
+ *
10
+ * @module token-usage/quota/provider-tracking
11
+ */
12
+ /** In-memory session → latest sighting map with a global fallback. */
13
+ export class ProviderTracker {
14
+ #bySession = new Map();
15
+ #last;
16
+ /** Record that a session used a provider (later sightings win). */
17
+ observe(sessionId, provider, model, at = Date.now()) {
18
+ if (sessionId === '' || provider === '')
19
+ return;
20
+ const sighting = { provider, model, at };
21
+ this.#bySession.set(sessionId, sighting);
22
+ this.#last = sighting;
23
+ }
24
+ /** The session's latest sighting, else the most recent sighting of any
25
+ * session (a brand-new session inherits the last provider in use — the
26
+ * shell's own default-then-remembered behavior). */
27
+ sightingOf(sessionId) {
28
+ if (sessionId !== undefined && sessionId !== '') {
29
+ const scoped = this.#bySession.get(sessionId);
30
+ if (scoped !== undefined)
31
+ return scoped;
32
+ }
33
+ return this.#last;
34
+ }
35
+ }
36
+ /**
37
+ * Resolve the provider route a quota query should target: the tracker's
38
+ * sighting first (the active session's or the global last), else the
39
+ * host's default model selection (the `agent-default-model` settings
40
+ * section — what a brand-new, never-requesting session would use).
41
+ * @param input - the tracker, the asking session, and a thunk reading the
42
+ * default selection's `provider` (undefined when no default is stored).
43
+ * @returns the route key, or undefined when nothing determinable exists.
44
+ */
45
+ export function resolveCurrentProvider(input) {
46
+ const sighting = input.tracker.sightingOf(input.sessionId);
47
+ if (sighting !== undefined)
48
+ return sighting.provider;
49
+ const fallback = input.defaultProvider?.();
50
+ return fallback !== undefined && fallback !== '' ? fallback : undefined;
51
+ }
52
+ //# sourceMappingURL=provider-tracking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-tracking.js","sourceRoot":"","sources":["../../src/quota/provider-tracking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,sEAAsE;AACtE,MAAM,OAAO,eAAe;IACjB,UAAU,GAAG,IAAI,GAAG,EAA4B,CAAA;IACzD,KAAK,CAA8B;IAEnC,mEAAmE;IACnE,OAAO,CAAC,SAAiB,EAAE,QAAgB,EAAE,KAAa,EAAE,KAAa,IAAI,CAAC,GAAG,EAAE;QACjF,IAAI,SAAS,KAAK,EAAE,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAM;QAC/C,MAAM,QAAQ,GAAqB,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;QAC1D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAA;IACvB,CAAC;IAED;;wDAEoD;IACpD,UAAU,CAAC,SAA6B;QACtC,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC7C,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAA;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAItC;IACC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAC1D,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC,QAAQ,CAAA;IACpD,MAAM,QAAQ,GAAG,KAAK,CAAC,eAAe,EAAE,EAAE,CAAA;IAC1C,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAA;AACzE,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The quota HTTP route of the token-usage plugin: a webServer exact route
3
+ * serving the current provider's quota payload at `/token-usage/quota`.
4
+ * The browser half's input-bar button polls it (`?session=<id>`); the
5
+ * same-origin guard mirrors the stats route's.
6
+ *
7
+ * @module token-usage/quota/quota-route
8
+ */
9
+ import type { WebRoute } from '@deepseek-ai/dsh-host-webserver';
10
+ import { type QuotaPayload } from '../wire.ts';
11
+ /** The quota endpoint path, exported for tests and the client half. */
12
+ export { QUOTA_PATH } from '../wire.ts';
13
+ /**
14
+ * Build the quota route over the orchestration service.
15
+ * @param snapshot - resolves the payload for one asking session (the
16
+ * `session` query parameter, undefined when absent) and its model chip's
17
+ * current selection (the `provider` query parameter, undefined when the
18
+ * browser could not read one).
19
+ * @returns the exact GET route answering the quota JSON.
20
+ */
21
+ export declare function createQuotaRoute(snapshot: (sessionId: string | undefined, providerHint: string | undefined) => Promise<QuotaPayload>): WebRoute;
22
+ //# sourceMappingURL=quota-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota-route.d.ts","sourceRoot":"","sources":["../../src/quota/quota-route.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAG1D,uEAAuE;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,QAAQ,CAkC/I"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The quota HTTP route of the token-usage plugin: a webServer exact route
3
+ * serving the current provider's quota payload at `/token-usage/quota`.
4
+ * The browser half's input-bar button polls it (`?session=<id>`); the
5
+ * same-origin guard mirrors the stats route's.
6
+ *
7
+ * @module token-usage/quota/quota-route
8
+ */
9
+ import { QUOTA_PATH } from "../wire.js";
10
+ import { isSameOriginFetch } from "../stats-route.js";
11
+ /** The quota endpoint path, exported for tests and the client half. */
12
+ export { QUOTA_PATH } from "../wire.js";
13
+ /**
14
+ * Build the quota route over the orchestration service.
15
+ * @param snapshot - resolves the payload for one asking session (the
16
+ * `session` query parameter, undefined when absent) and its model chip's
17
+ * current selection (the `provider` query parameter, undefined when the
18
+ * browser could not read one).
19
+ * @returns the exact GET route answering the quota JSON.
20
+ */
21
+ export function createQuotaRoute(snapshot) {
22
+ return {
23
+ kind: 'exact',
24
+ path: QUOTA_PATH,
25
+ handler: async (req, res) => {
26
+ if (req.method !== 'GET') {
27
+ res.writeHead(405, { 'content-type': 'text/plain; charset=utf-8' });
28
+ res.end('method not allowed');
29
+ return;
30
+ }
31
+ if (!isSameOriginFetch(req)) {
32
+ res.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' });
33
+ res.end('forbidden');
34
+ return;
35
+ }
36
+ const params = new URL(req.url ?? '/', 'http://localhost').searchParams;
37
+ const pick = (key) => {
38
+ const value = params.get(key);
39
+ return value === null || value === '' ? undefined : value;
40
+ };
41
+ try {
42
+ const payload = await snapshot(pick('session'), pick('provider'));
43
+ res.writeHead(200, {
44
+ 'content-type': 'application/json; charset=utf-8',
45
+ // The payload changes with the provider's own meters; never cache.
46
+ 'cache-control': 'no-store',
47
+ });
48
+ res.end(JSON.stringify(payload));
49
+ }
50
+ catch (error) {
51
+ res.writeHead(500, { 'content-type': 'application/json; charset=utf-8' });
52
+ res.end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
53
+ }
54
+ },
55
+ };
56
+ }
57
+ //# sourceMappingURL=quota-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota-route.js","sourceRoot":"","sources":["../../src/quota/quota-route.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,UAAU,EAAqB,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,uEAAuE;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,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,CAAC,OAAO,CAAC,CAAC,CAAA;YAClC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,iCAAiC,EAAE,CAAC,CAAA;gBACzE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;YAC5F,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Quota orchestration service (node half): resolve the current provider,
3
+ * route it through the adapter registry, resolve credentials, and serve
4
+ * normalized {@link QuotaPayload}s with a per-provider TTL cache and
5
+ * in-flight dedupe so N open sessions polling never hammer a provider's
6
+ * quota endpoint.
7
+ *
8
+ * Cache policy: ok results cache per provider for `cacheTtlMs` (default
9
+ * 45s — under the client's poll cadence, so a poll usually hits memory).
10
+ * Error results do not cache, so the panel's retry / open-to-refresh
11
+ * actually re-queries; in-flight callers still collapse into one outbound
12
+ * request. `no-provider` / `unsupported` resolutions are pure settings
13
+ * reads and never cache. A provider CHANGE invalidates by key (cache is
14
+ * keyed by route), so switching providers serves fresh at once.
15
+ *
16
+ * @module token-usage/quota/quota-service
17
+ */
18
+ import type { QuotaPayload } from '../wire.ts';
19
+ import { type ResolvedQuotaCredentials } from './credentials.ts';
20
+ /** The seams the service runs over (index.ts wires the host services in). */
21
+ export interface QuotaServiceDeps {
22
+ /** Route key of the provider the asking session uses, if determinable. */
23
+ resolveProvider: (sessionId: string | undefined) => string | undefined;
24
+ /** Credential chain seam; see credentials.ts. */
25
+ resolveCredentials: (provider: string) => Promise<ResolvedQuotaCredentials>;
26
+ /** Transport (global fetch in production, a stub in tests). */
27
+ fetchFn?: typeof fetch;
28
+ /** The poll cadence stamped on every payload (seconds). */
29
+ intervalSec?: number;
30
+ /** Ok-result cache lifetime; tests shrink it. Errors never cache. */
31
+ cacheTtlMs?: number;
32
+ /** Clock seam; tests freeze it. */
33
+ now?: () => number;
34
+ }
35
+ /** The quota orchestration service. */
36
+ export declare class QuotaService {
37
+ #private;
38
+ constructor(deps: QuotaServiceDeps);
39
+ /** The poll cadence every payload carries. */
40
+ get intervalSec(): number;
41
+ /**
42
+ * The payload for one asking session: hidden variants short-circuit
43
+ * without any network; a supported provider serves its cached window
44
+ * set or queries it (deduped per provider while in flight).
45
+ * @param sessionId - the asking conversation session ('' / undefined
46
+ * when the caller has no session context).
47
+ * @param providerHint - the provider the session's model chip currently
48
+ * selects (the host-reported NEXT selection), when the browser could read
49
+ * one. It wins over the request tracker: the chip is the user's live
50
+ * intent, and the next `request/context` event makes the tracker agree.
51
+ */
52
+ snapshot(sessionId?: string, providerHint?: string): Promise<QuotaPayload>;
53
+ }
54
+ //# sourceMappingURL=quota-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota-service.d.ts","sourceRoot":"","sources":["../../src/quota/quota-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAgB,YAAY,EAAiB,MAAM,YAAY,CAAA;AAI3E,OAAO,EAAsB,KAAK,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAOpF,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GAAG,SAAS,CAAA;IACtE,iDAAiD;IACjD,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAA;IAC3E,+DAA+D;IAC/D,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;IACtB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CACnB;AA+CD,uCAAuC;AACvC,qBAAa,YAAY;;gBAKX,IAAI,EAAE,gBAAgB;IAIlC,8CAA8C;IAC9C,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;;;;;;;;OAUG;IACG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAsGjF"}
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Quota orchestration service (node half): resolve the current provider,
3
+ * route it through the adapter registry, resolve credentials, and serve
4
+ * normalized {@link QuotaPayload}s with a per-provider TTL cache and
5
+ * in-flight dedupe so N open sessions polling never hammer a provider's
6
+ * quota endpoint.
7
+ *
8
+ * Cache policy: ok results cache per provider for `cacheTtlMs` (default
9
+ * 45s — under the client's poll cadence, so a poll usually hits memory).
10
+ * Error results do not cache, so the panel's retry / open-to-refresh
11
+ * actually re-queries; in-flight callers still collapse into one outbound
12
+ * request. `no-provider` / `unsupported` resolutions are pure settings
13
+ * reads and never cache. A provider CHANGE invalidates by key (cache is
14
+ * keyed by route), so switching providers serves fresh at once.
15
+ *
16
+ * @module token-usage/quota/quota-service
17
+ */
18
+ import { resolveQuotaAdapter } from "./registry.js";
19
+ import { QuotaQueryError } from "./types.js";
20
+ import { withCatalogBaseUrl } from "./credentials.js";
21
+ /** Default cache lifetime of one provider's ok result. */
22
+ const DEFAULT_CACHE_TTL_MS = 45_000;
23
+ /** Per-query deadline: quota endpoints are small; anything slower is dead. */
24
+ const QUERY_TIMEOUT_MS = 10_000;
25
+ /** Map any thrown adapter failure onto the wire's error vocabulary. */
26
+ function toQuotaFailure(provider, providerName, adapter, error, intervalSec, now) {
27
+ const normalized = error instanceof QuotaQueryError
28
+ ? { kind: error.kind, message: error.message }
29
+ : { kind: 'parse', message: error instanceof Error ? error.message : String(error) };
30
+ return {
31
+ status: 'error',
32
+ provider,
33
+ ...(providerName !== undefined ? { providerName } : {}),
34
+ adapterId: adapter.id,
35
+ fetchedAt: now,
36
+ intervalSec,
37
+ error: normalized,
38
+ };
39
+ }
40
+ /**
41
+ * The display name for a resolved adapter: the route's own name when the
42
+ * route key is one of the adapter's catalog routes; a host-matched custom
43
+ * route keeps its user-chosen alias but qualified by the adapter's family
44
+ * label — the quota belongs to the family, and an alias like "OpenAI"
45
+ * must not claim OpenCode Go windows as its own.
46
+ */
47
+ function displayNameOf(provider, credentials, adapter) {
48
+ if (adapter.routes === undefined || adapter.routes.includes(provider))
49
+ return credentials.displayName;
50
+ return `${credentials.displayName ?? provider} · ${adapter.label}`;
51
+ }
52
+ /** The quota orchestration service. */
53
+ export class QuotaService {
54
+ #deps;
55
+ #cache = new Map();
56
+ #inflight = new Map();
57
+ constructor(deps) {
58
+ this.#deps = deps;
59
+ }
60
+ /** The poll cadence every payload carries. */
61
+ get intervalSec() {
62
+ return this.#deps.intervalSec ?? 60;
63
+ }
64
+ /**
65
+ * The payload for one asking session: hidden variants short-circuit
66
+ * without any network; a supported provider serves its cached window
67
+ * set or queries it (deduped per provider while in flight).
68
+ * @param sessionId - the asking conversation session ('' / undefined
69
+ * when the caller has no session context).
70
+ * @param providerHint - the provider the session's model chip currently
71
+ * selects (the host-reported NEXT selection), when the browser could read
72
+ * one. It wins over the request tracker: the chip is the user's live
73
+ * intent, and the next `request/context` event makes the tracker agree.
74
+ */
75
+ async snapshot(sessionId, providerHint) {
76
+ const provider = providerHint !== undefined && providerHint !== ''
77
+ ? providerHint
78
+ : this.#deps.resolveProvider(sessionId);
79
+ if (provider === undefined) {
80
+ return { status: 'no-provider', intervalSec: this.intervalSec };
81
+ }
82
+ const credentials = withCatalogBaseUrl(provider, await this.#deps.resolveCredentials(provider));
83
+ const adapter = resolveQuotaAdapter({
84
+ provider,
85
+ ...(credentials.baseUrl !== undefined ? { baseUrl: credentials.baseUrl } : {}),
86
+ });
87
+ if (adapter === undefined) {
88
+ return {
89
+ status: 'unsupported',
90
+ provider,
91
+ ...(credentials.displayName !== undefined ? { providerName: credentials.displayName } : {}),
92
+ intervalSec: this.intervalSec,
93
+ };
94
+ }
95
+ const providerName = displayNameOf(provider, credentials, adapter);
96
+ if (credentials.apiKey === undefined) {
97
+ return {
98
+ status: 'error',
99
+ provider,
100
+ ...(providerName !== undefined ? { providerName } : {}),
101
+ adapterId: adapter.id,
102
+ fetchedAt: this.#now(),
103
+ intervalSec: this.intervalSec,
104
+ error: {
105
+ kind: 'no-credential',
106
+ message: credentials.apiKeyEnv ?? provider,
107
+ },
108
+ };
109
+ }
110
+ const cached = this.#cached(provider);
111
+ if (cached !== undefined)
112
+ return cached;
113
+ const running = this.#inflight.get(provider);
114
+ if (running !== undefined)
115
+ return running;
116
+ const query = this.#query(provider, providerName, credentials, adapter);
117
+ this.#inflight.set(provider, query);
118
+ try {
119
+ return await query;
120
+ }
121
+ finally {
122
+ this.#inflight.delete(provider);
123
+ }
124
+ }
125
+ /** The fresh-or-cached ok result, or a live error, of one provider query. */
126
+ async #query(provider, providerName, credentials, adapter) {
127
+ try {
128
+ const result = await adapter.query({
129
+ provider,
130
+ ...(credentials.baseUrl !== undefined ? { baseUrl: credentials.baseUrl } : {}),
131
+ apiKey: credentials.apiKey ?? '',
132
+ signal: AbortSignal.timeout(QUERY_TIMEOUT_MS),
133
+ ...(this.#deps.fetchFn !== undefined ? { fetchFn: this.#deps.fetchFn } : { fetchFn: globalThis.fetch }),
134
+ });
135
+ const payload = {
136
+ status: 'ok',
137
+ provider,
138
+ ...(providerName !== undefined ? { providerName } : {}),
139
+ adapterId: adapter.id,
140
+ fetchedAt: this.#now(),
141
+ intervalSec: this.intervalSec,
142
+ ...(result.planTier !== undefined ? { planTier: result.planTier } : {}),
143
+ windows: result.windows,
144
+ };
145
+ this.#cache.set(provider, { at: this.#now(), payload });
146
+ return payload;
147
+ }
148
+ catch (error) {
149
+ // Errors do not cache: the panel's retry must actually re-query.
150
+ this.#cache.delete(provider);
151
+ return toQuotaFailure(provider, providerName, adapter, error, this.intervalSec, this.#now());
152
+ }
153
+ }
154
+ /** The unexpired ok cache entry of a provider, if one exists. */
155
+ #cached(provider) {
156
+ const entry = this.#cache.get(provider);
157
+ if (entry === undefined)
158
+ return undefined;
159
+ const ttl = this.#deps.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
160
+ if (this.#now() - entry.at >= ttl) {
161
+ this.#cache.delete(provider);
162
+ return undefined;
163
+ }
164
+ return entry.payload;
165
+ }
166
+ /** The service clock. */
167
+ #now() {
168
+ return this.#deps.now?.() ?? Date.now();
169
+ }
170
+ }
171
+ //# sourceMappingURL=quota-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota-service.js","sourceRoot":"","sources":["../../src/quota/quota-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAiC,MAAM,kBAAkB,CAAA;AAEpF,0DAA0D;AAC1D,MAAM,oBAAoB,GAAG,MAAM,CAAA;AACnC,8EAA8E;AAC9E,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAwB/B,uEAAuE;AACvE,SAAS,cAAc,CACrB,QAAgB,EAChB,YAAgC,EAChC,OAAqB,EACrB,KAAc,EACd,WAAmB,EACnB,GAAW;IAEX,MAAM,UAAU,GAAG,KAAK,YAAY,eAAe;QACjD,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;QAC9C,CAAC,CAAC,EAAE,IAAI,EAAE,OAAgB,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAA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Q,CAAC,CAAA;YAC5B,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,KAAK,CAAC,OAAO,CAAA;IACtB,CAAC;IAED,yBAAyB;IACzB,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAA;IACzC,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The quota adapter registry (node half): the ordered table every provider
3
+ * route resolves through. Adding a provider is one adapter file plus one
4
+ * line here — see docs/decisions/proposed/0001-quota-provider-adapter.md.
5
+ *
6
+ * Adapters are mutually exclusive by construction (distinct hosts / route
7
+ * keys), so order only breaks ties for a hypothetical overlap; keep the
8
+ * coding plans ahead of the balance meters so a shared-host route prefers
9
+ * the richer windows.
10
+ *
11
+ * @module token-usage/quota/registry
12
+ */
13
+ import type { QuotaAdapter, QuotaMatchInput } from './types.ts';
14
+ /** Every built-in adapter, most specific first. */
15
+ export declare const QUOTA_ADAPTERS: readonly QuotaAdapter[];
16
+ /**
17
+ * The adapter handling one provider route, or undefined when none does
18
+ * (the `unsupported` payload variant). Resolution reads each adapter's
19
+ * `matches` — host signal first, route key second; see the adapter docs.
20
+ * @param input - the provider route key and its resolvable base URL.
21
+ * @returns the owning adapter, or undefined.
22
+ */
23
+ export declare function resolveQuotaAdapter(input: QuotaMatchInput): QuotaAdapter | undefined;
24
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/quota/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE/D,mDAAmD;AACnD,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAOjD,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,YAAY,GAAG,SAAS,CAEpF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The quota adapter registry (node half): the ordered table every provider
3
+ * route resolves through. Adding a provider is one adapter file plus one
4
+ * line here — see docs/decisions/proposed/0001-quota-provider-adapter.md.
5
+ *
6
+ * Adapters are mutually exclusive by construction (distinct hosts / route
7
+ * keys), so order only breaks ties for a hypothetical overlap; keep the
8
+ * coding plans ahead of the balance meters so a shared-host route prefers
9
+ * the richer windows.
10
+ *
11
+ * @module token-usage/quota/registry
12
+ */
13
+ import { deepseekBalanceAdapter } from "./adapters/deepseek-balance.js";
14
+ import { kimiAdapter } from "./adapters/kimi.js";
15
+ import { minimaxAdapter } from "./adapters/minimax.js";
16
+ import { opencodeGoAdapter } from "./adapters/opencode-go.js";
17
+ import { openrouterAdapter } from "./adapters/openrouter.js";
18
+ import { zhipuAdapter } from "./adapters/zhipu.js";
19
+ /** Every built-in adapter, most specific first. */
20
+ export const QUOTA_ADAPTERS = [
21
+ zhipuAdapter,
22
+ kimiAdapter,
23
+ minimaxAdapter,
24
+ opencodeGoAdapter,
25
+ deepseekBalanceAdapter,
26
+ openrouterAdapter,
27
+ ];
28
+ /**
29
+ * The adapter handling one provider route, or undefined when none does
30
+ * (the `unsupported` payload variant). Resolution reads each adapter's
31
+ * `matches` — host signal first, route key second; see the adapter docs.
32
+ * @param input - the provider route key and its resolvable base URL.
33
+ * @returns the owning adapter, or undefined.
34
+ */
35
+ export function resolveQuotaAdapter(input) {
36
+ return QUOTA_ADAPTERS.find(adapter => adapter.matches(input));
37
+ }
38
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/quota/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGlD,mDAAmD;AACnD,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,YAAY;IACZ,WAAW;IACX,cAAc;IACd,iBAAiB;IACjB,sBAAsB;IACtB,iBAAiB;CAClB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAsB;IACxD,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The provider quota adapter contract (node half). One adapter owns one
3
+ * provider family's quota endpoint: how to decide the route belongs to it
4
+ * (`matches`) and how to query + normalize the response into the wire's
5
+ * `QuotaWindow` vocabulary (`query`). The registry routes by provider route
6
+ * key and base-URL host; adding a provider is one new file plus one
7
+ * registry line — the shape cc-switch's `coding_plan.rs` proved out.
8
+ *
9
+ * Endpoint/field knowledge here comes from the cc-switch provider-usage
10
+ * research (PROVIDER_USAGE_RESEARCH.md), whose endpoints are lifted from
11
+ * working implementations.
12
+ *
13
+ * @module token-usage/quota/types
14
+ */
15
+ import type { QuotaErrorKind, QuotaWindow } from '../wire.ts';
16
+ /** What an adapter sees when deciding whether it handles a route. */
17
+ export interface QuotaMatchInput {
18
+ /** Provider route key exactly as session events carry it — the pi-ai
19
+ * settings dict key (`zai-coding-cn`, `minimax`, a user-declared name)
20
+ * or the direct adapter's `deepseek-official`. */
21
+ provider: string;
22
+ /** The provider's inference base URL when one is resolvable (the
23
+ * settings profile's `baseURL` override, else the catalog default);
24
+ * undefined when neither is known. */
25
+ baseUrl?: string;
26
+ }
27
+ /** Everything one adapter query needs; the service resolves and injects. */
28
+ export interface QuotaQueryContext {
29
+ /** Provider route key (for diagnostics and per-provider behavior). */
30
+ provider: string;
31
+ /** Resolved inference base URL (may influence host/station choice). */
32
+ baseUrl?: string;
33
+ /** The provider's API key, resolved through the credentials seam. */
34
+ apiKey: string;
35
+ /** Deadline signal; the service stamps one per query. */
36
+ signal?: AbortSignal;
37
+ /** Transport to use — global fetch in production, a stub in tests. */
38
+ fetchFn: typeof fetch;
39
+ }
40
+ /** What one adapter query returns; the service layers identity metadata. */
41
+ export interface QuotaQueryResult {
42
+ windows: QuotaWindow[];
43
+ /** Plan tier label when the provider reports one (Zhipu `data.level`). */
44
+ planTier?: string;
45
+ }
46
+ /** One provider family's quota integration. */
47
+ export interface QuotaAdapter {
48
+ /** Stable id surfaced in diagnostics (`zhipu-coding-plan`, …). */
49
+ id: string;
50
+ /** Human-readable family label — diagnostics, and the qualifier the
51
+ * service appends to a host-matched custom route's display name. */
52
+ label: string;
53
+ /** Route keys this adapter owns by catalog identity (the pi-ai settings
54
+ * dict keys). A route that matched without being listed here is a
55
+ * host-matched custom name — the service qualifies its display name
56
+ * with {@link QuotaAdapter.label} so an alias cannot claim another
57
+ * family's windows. Absent means the adapter claims every match. */
58
+ routes?: readonly string[];
59
+ /**
60
+ * Whether this adapter handles the route. The base-URL host is the
61
+ * stronger signal: a user-declared pi-ai route can carry any name while
62
+ * pointing at a known coding-plan endpoint, so adapters check the host
63
+ * first and treat the route key as the secondary signal. Conversely a
64
+ * route key must only match when it is unambiguous (the pi-ai
65
+ * `moonshotai` routes are the standard API, not Kimi For Coding, so the
66
+ * kimi adapter matches on host or the catalog route `kimi-coding`).
67
+ */
68
+ matches(input: QuotaMatchInput): boolean;
69
+ /** Query the provider's quota endpoint and normalize the windows.
70
+ * Transport failures throw {@link QuotaQueryError} with the normalized
71
+ * kind; anything else is treated as a parse failure by the service. */
72
+ query(ctx: QuotaQueryContext): Promise<QuotaQueryResult>;
73
+ }
74
+ /** A quota query failure with its normalized wire kind. */
75
+ export declare class QuotaQueryError extends Error {
76
+ readonly kind: QuotaErrorKind;
77
+ constructor(kind: QuotaErrorKind, message: string);
78
+ }
79
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/quota/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7D,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B;;sDAEkD;IAClD,QAAQ,EAAE,MAAM,CAAA;IAChB;;0CAEsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAA;IAChB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAA;IACd,yDAAyD;IACzD,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,sEAAsE;IACtE,OAAO,EAAE,OAAO,KAAK,CAAA;CACtB;AAED,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAA;IACV;wEACoE;IACpE,KAAK,EAAE,MAAM,CAAA;IACb;;;;wEAIoE;IACpE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1B;;;;;;;;OAQG;IACH,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAA;IACxC;;2EAEuE;IACvE,KAAK,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;CACzD;AAED,2DAA2D;AAC3D,qBAAa,eAAgB,SAAQ,KAAK;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc;gBAApB,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM;CAI3D"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The provider quota adapter contract (node half). One adapter owns one
3
+ * provider family's quota endpoint: how to decide the route belongs to it
4
+ * (`matches`) and how to query + normalize the response into the wire's
5
+ * `QuotaWindow` vocabulary (`query`). The registry routes by provider route
6
+ * key and base-URL host; adding a provider is one new file plus one
7
+ * registry line — the shape cc-switch's `coding_plan.rs` proved out.
8
+ *
9
+ * Endpoint/field knowledge here comes from the cc-switch provider-usage
10
+ * research (PROVIDER_USAGE_RESEARCH.md), whose endpoints are lifted from
11
+ * working implementations.
12
+ *
13
+ * @module token-usage/quota/types
14
+ */
15
+ /** A quota query failure with its normalized wire kind. */
16
+ export class QuotaQueryError extends Error {
17
+ kind;
18
+ constructor(kind, message) {
19
+ super(message);
20
+ this.kind = kind;
21
+ this.name = 'QuotaQueryError';
22
+ }
23
+ }
24
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/quota/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAkEH,2DAA2D;AAC3D,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACnB;IAArB,YAAqB,IAAoB,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAA;QADK,SAAI,GAAJ,IAAI,CAAgB;QAEvC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF"}