sidekick-shared 0.24.2 → 0.24.4
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 +412 -0
- package/LICENSE +21 -0
- package/README.md +87 -16
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -7
- package/dist/modelContext.js +1 -0
- package/dist/modelInfo.js +146 -14
- package/dist/observedContextWindows.d.ts +7 -4
- package/dist/observedContextWindows.js +34 -7
- package/dist/paths.d.ts +36 -1
- package/dist/paths.js +59 -3
- package/dist/peakHours.d.ts +16 -2
- package/dist/peakHours.js +18 -3
- package/dist/pricingCatalog.d.ts +7 -3
- package/dist/pricingCatalog.js +3 -2
- package/dist/zaiQuota.d.ts +87 -0
- package/dist/zaiQuota.js +49 -0
- package/dist/zaiQuotaWatcher.d.ts +7 -0
- package/dist/zaiQuotaWatcher.js +3 -0
- package/package.json +60 -2
package/dist/pricingCatalog.d.ts
CHANGED
|
@@ -18,8 +18,12 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { type ModelPricing } from './modelInfo';
|
|
20
20
|
export interface HydrateOptions {
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Directory for the on-disk cache. Defaults to the Sidekick config dir,
|
|
23
|
+
* which honors `SIDEKICK_CONFIG_DIR` and `setConfigDir()` — pass this only
|
|
24
|
+
* to place the cache somewhere outside the config root.
|
|
25
|
+
*/
|
|
26
|
+
cacheDir?: string;
|
|
23
27
|
/** Inject a fetch implementation (tests, custom agents). Defaults to `globalThis.fetch`. */
|
|
24
28
|
fetchImpl?: typeof fetch;
|
|
25
29
|
/** Cache TTL in ms. Default 24h. */
|
|
@@ -52,7 +56,7 @@ export declare const LITELLM_CATALOG_URL = "https://raw.githubusercontent.com/Be
|
|
|
52
56
|
*
|
|
53
57
|
* Always resolves — never throws. Offline-safe.
|
|
54
58
|
*/
|
|
55
|
-
export declare function hydratePricingCatalog(options
|
|
59
|
+
export declare function hydratePricingCatalog(options?: HydrateOptions): Promise<HydrateResult>;
|
|
56
60
|
/**
|
|
57
61
|
* Convert a LiteLLM catalog payload to our `ModelPricing` override map.
|
|
58
62
|
* Exported for tests; rarely called directly.
|
package/dist/pricingCatalog.js
CHANGED
|
@@ -59,6 +59,7 @@ const node_fs_1 = require("node:fs");
|
|
|
59
59
|
const path = __importStar(require("node:path"));
|
|
60
60
|
const modelContext_1 = require("./modelContext");
|
|
61
61
|
const modelInfo_1 = require("./modelInfo");
|
|
62
|
+
const paths_1 = require("./paths");
|
|
62
63
|
// ── Constants ──
|
|
63
64
|
exports.LITELLM_CATALOG_URL = 'https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json';
|
|
64
65
|
const CACHE_FILE_NAME = 'pricing-catalog.json';
|
|
@@ -75,8 +76,8 @@ const DEFAULT_TIMEOUT_MS = 3_000;
|
|
|
75
76
|
*
|
|
76
77
|
* Always resolves — never throws. Offline-safe.
|
|
77
78
|
*/
|
|
78
|
-
async function hydratePricingCatalog(options) {
|
|
79
|
-
const { cacheDir, fetchImpl = globalThis.fetch, ttlMs = DEFAULT_TTL_MS, timeoutMs = DEFAULT_TIMEOUT_MS, url = exports.LITELLM_CATALOG_URL, logger, } = options;
|
|
79
|
+
async function hydratePricingCatalog(options = {}) {
|
|
80
|
+
const { cacheDir = (0, paths_1.getConfigDir)(), fetchImpl = globalThis.fetch, ttlMs = DEFAULT_TTL_MS, timeoutMs = DEFAULT_TIMEOUT_MS, url = exports.LITELLM_CATALOG_URL, logger, } = options;
|
|
80
81
|
const cachePath = path.join(cacheDir, CACHE_FILE_NAME);
|
|
81
82
|
const now = Date.now();
|
|
82
83
|
// 1. Fresh cache?
|
package/dist/zaiQuota.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ import type { QuotaState } from './quota';
|
|
|
27
27
|
* "One prompt ≈ one query; each prompt is estimated to invoke the model
|
|
28
28
|
* 15–20 times." We use the midpoint (17.5) when converting observed
|
|
29
29
|
* assistant turns into prompt equivalents.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
32
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
33
|
+
* for backward compatibility only and drifts from actual billing.
|
|
30
34
|
*/
|
|
31
35
|
export declare const ZAI_TIER_BUDGETS: {
|
|
32
36
|
readonly lite: {
|
|
@@ -42,20 +46,43 @@ export declare const ZAI_TIER_BUDGETS: {
|
|
|
42
46
|
readonly weekly: 8000;
|
|
43
47
|
};
|
|
44
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
51
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
52
|
+
* for backward compatibility only and drifts from actual billing.
|
|
53
|
+
*/
|
|
45
54
|
export type ZaiTier = 'lite' | 'pro' | 'max';
|
|
46
55
|
/**
|
|
47
56
|
* Midpoint of z.ai's documented "15–20 model invocations per prompt" range.
|
|
48
57
|
* Used to convert accumulated assistant turns into prompt equivalents.
|
|
49
58
|
* Calibration note: this constant may need per-tier adjustment after
|
|
50
59
|
* real-world validation against the z.ai web UI.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
62
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
63
|
+
* for backward compatibility only and drifts from actual billing.
|
|
51
64
|
*/
|
|
52
65
|
export declare const ZAI_PROMPT_INVOCATIONS = 17.5;
|
|
53
66
|
/**
|
|
54
67
|
* Provider IDs that OpenCode tags on z.ai-routed messages.
|
|
55
68
|
* `zai-coding-plan` is the Coding Plan key; `zai` is the bare API key.
|
|
69
|
+
*
|
|
70
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
71
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
72
|
+
* for backward compatibility only and drifts from actual billing.
|
|
56
73
|
*/
|
|
57
74
|
export declare const ZAI_PROVIDER_IDS: readonly ["zai", "zai-coding-plan"];
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
77
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
78
|
+
* for backward compatibility only and drifts from actual billing.
|
|
79
|
+
*/
|
|
58
80
|
export type ZaiProviderId = (typeof ZAI_PROVIDER_IDS)[number];
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
83
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
84
|
+
* for backward compatibility only and drifts from actual billing.
|
|
85
|
+
*/
|
|
59
86
|
export declare function isZaiProviderId(value: unknown): value is ZaiProviderId;
|
|
60
87
|
/**
|
|
61
88
|
* Minimal description of a z.ai-routed assistant turn needed to accumulate
|
|
@@ -64,6 +91,10 @@ export declare function isZaiProviderId(value: unknown): value is ZaiProviderId;
|
|
|
64
91
|
* provider comparability; cost is omitted (always 0 for z.ai).
|
|
65
92
|
*
|
|
66
93
|
* `timestampMs` is when the assistant turn completed (epoch milliseconds).
|
|
94
|
+
*
|
|
95
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
96
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
97
|
+
* for backward compatibility only and drifts from actual billing.
|
|
67
98
|
*/
|
|
68
99
|
export interface ZaiAssistantTurn {
|
|
69
100
|
timestampMs: number;
|
|
@@ -74,6 +105,11 @@ export interface ZaiAssistantTurn {
|
|
|
74
105
|
cacheWriteTokens: number;
|
|
75
106
|
reasoningTokens: number;
|
|
76
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
110
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
111
|
+
* for backward compatibility only and drifts from actual billing.
|
|
112
|
+
*/
|
|
77
113
|
export interface ZaiAccumulatedUsage {
|
|
78
114
|
/** Number of z.ai assistant turns inside the 5-hour window. */
|
|
79
115
|
fiveHourTurns: number;
|
|
@@ -96,6 +132,10 @@ export interface ZaiAccumulatedUsage {
|
|
|
96
132
|
* Sums the token fields of a single turn into a scalar.
|
|
97
133
|
* Cache reads are weighted at 0.1× (Anthropic convention) to avoid
|
|
98
134
|
* over-counting repeated context. Output and reasoning tokens are weighted 1×.
|
|
135
|
+
*
|
|
136
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
137
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
138
|
+
* for backward compatibility only and drifts from actual billing.
|
|
99
139
|
*/
|
|
100
140
|
export declare function turnTokenWeight(turn: Pick<ZaiAssistantTurn, 'inputTokens' | 'outputTokens' | 'cacheReadTokens' | 'cacheWriteTokens' | 'reasoningTokens'>): number;
|
|
101
141
|
/**
|
|
@@ -104,6 +144,10 @@ export declare function turnTokenWeight(turn: Pick<ZaiAssistantTurn, 'inputToken
|
|
|
104
144
|
* Pure & stateless: the caller is responsible for passing the relevant turns.
|
|
105
145
|
* Turns outside the 7-day window are ignored; turns inside the 7-day window
|
|
106
146
|
* but outside the 5-hour window still count toward weekly usage.
|
|
147
|
+
*
|
|
148
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
149
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
150
|
+
* for backward compatibility only and drifts from actual billing.
|
|
107
151
|
*/
|
|
108
152
|
export declare function accumulateZaiUsage(turns: readonly ZaiAssistantTurn[], nowMs?: number): ZaiAccumulatedUsage;
|
|
109
153
|
/**
|
|
@@ -113,8 +157,17 @@ export declare function accumulateZaiUsage(turns: readonly ZaiAssistantTurn[], n
|
|
|
113
157
|
* the user must be on a higher tier. This under-detects at the start of a
|
|
114
158
|
* weekly cycle (a Max user looks identical to a Lite user until they cross
|
|
115
159
|
* 400 prompts/week), so callers should still expose an explicit override.
|
|
160
|
+
*
|
|
161
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
162
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
163
|
+
* for backward compatibility only and drifts from actual billing.
|
|
116
164
|
*/
|
|
117
165
|
export declare function resolveZaiTier(configured: ZaiTier | 'auto', accumulated: ZaiAccumulatedUsage): ZaiTier;
|
|
166
|
+
/**
|
|
167
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
168
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
169
|
+
* for backward compatibility only and drifts from actual billing.
|
|
170
|
+
*/
|
|
118
171
|
export interface InferZaiQuotaStateOptions {
|
|
119
172
|
/** ISO timestamp to stamp on the sample. Default: now. */
|
|
120
173
|
capturedAt?: string;
|
|
@@ -138,9 +191,23 @@ export interface InferZaiQuotaStateOptions {
|
|
|
138
191
|
* - `sevenDay.resetsAt` ← first turn in window + 7d (documented as
|
|
139
192
|
* "7 days from order time" — order time is unknown, so this is a
|
|
140
193
|
* lower bound at best).
|
|
194
|
+
*
|
|
195
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
196
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
197
|
+
* for backward compatibility only and drifts from actual billing.
|
|
141
198
|
*/
|
|
142
199
|
export declare function inferZaiQuotaState(accumulated: ZaiAccumulatedUsage, tier: ZaiTier, options?: InferZaiQuotaStateOptions): QuotaState;
|
|
200
|
+
/**
|
|
201
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
202
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
203
|
+
* for backward compatibility only and drifts from actual billing.
|
|
204
|
+
*/
|
|
143
205
|
export type ZaiQuotaErrorKind = 'exhausted' | 'fup' | 'expired' | 'invalid';
|
|
206
|
+
/**
|
|
207
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
208
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
209
|
+
* for backward compatibility only and drifts from actual billing.
|
|
210
|
+
*/
|
|
144
211
|
export interface ZaiQuotaError {
|
|
145
212
|
kind: ZaiQuotaErrorKind;
|
|
146
213
|
/** ISO timestamp parsed from `${next_flush_time}` in the error message, if present. */
|
|
@@ -159,6 +226,10 @@ export interface ZaiQuotaError {
|
|
|
159
226
|
* `YYYY-MM-DD HH:mm:ss` form defensively.
|
|
160
227
|
*
|
|
161
228
|
* Returns `null` when the code is not a quota-related business error.
|
|
229
|
+
*
|
|
230
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
231
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
232
|
+
* for backward compatibility only and drifts from actual billing.
|
|
162
233
|
*/
|
|
163
234
|
export declare function parseZaiQuotaError(error: {
|
|
164
235
|
code?: string | number;
|
|
@@ -171,17 +242,29 @@ export declare function parseZaiQuotaError(error: {
|
|
|
171
242
|
* Handles ISO 8601 (`2025-01-31T14:00:00Z`), space-separated
|
|
172
243
|
* (`2025-01-31 14:00:00`), and epoch-seconds (1234567890) forms.
|
|
173
244
|
* Returns undefined when no parseable timestamp is found.
|
|
245
|
+
*
|
|
246
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
247
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
248
|
+
* for backward compatibility only and drifts from actual billing.
|
|
174
249
|
*/
|
|
175
250
|
export declare function extractNextFlushTime(message: string): string | undefined;
|
|
176
251
|
/**
|
|
177
252
|
* Builds an unavailable z.ai `QuotaState` for the cold-start case where
|
|
178
253
|
* no z.ai traffic has been observed yet.
|
|
254
|
+
*
|
|
255
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
256
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
257
|
+
* for backward compatibility only and drifts from actual billing.
|
|
179
258
|
*/
|
|
180
259
|
export declare function makeUnavailableZaiQuotaState(error?: string, tier?: ZaiTier, capturedAt?: string): QuotaState;
|
|
181
260
|
/**
|
|
182
261
|
* Shape of a row returned by `OpenCodeDatabase.getAssistantMessagesByProviderId`.
|
|
183
262
|
* Defined here to keep the sidekick-shared helper self-contained without
|
|
184
263
|
* leaking the OpenCode db module into the public quota surface.
|
|
264
|
+
*
|
|
265
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
266
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
267
|
+
* for backward compatibility only and drifts from actual billing.
|
|
185
268
|
*/
|
|
186
269
|
export interface ZaiOpenCodeRow {
|
|
187
270
|
timeCreated: number;
|
|
@@ -202,6 +285,10 @@ export interface ZaiOpenCodeRow {
|
|
|
202
285
|
*
|
|
203
286
|
* Returns `{ turns, errors }` so callers can replay them through
|
|
204
287
|
* `ZaiQuotaWatcher.ingestAssistantTurns` and `ingestError`.
|
|
288
|
+
*
|
|
289
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
290
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
291
|
+
* for backward compatibility only and drifts from actual billing.
|
|
205
292
|
*/
|
|
206
293
|
export declare function rowsToZaiTurnsAndErrors(rows: readonly ZaiOpenCodeRow[]): {
|
|
207
294
|
turns: ZaiAssistantTurn[];
|
package/dist/zaiQuota.js
CHANGED
|
@@ -18,6 +18,10 @@ exports.rowsToZaiTurnsAndErrors = rowsToZaiTurnsAndErrors;
|
|
|
18
18
|
* "One prompt ≈ one query; each prompt is estimated to invoke the model
|
|
19
19
|
* 15–20 times." We use the midpoint (17.5) when converting observed
|
|
20
20
|
* assistant turns into prompt equivalents.
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
23
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
24
|
+
* for backward compatibility only and drifts from actual billing.
|
|
21
25
|
*/
|
|
22
26
|
exports.ZAI_TIER_BUDGETS = {
|
|
23
27
|
lite: { fiveHour: 80, weekly: 400 },
|
|
@@ -29,6 +33,10 @@ exports.ZAI_TIER_BUDGETS = {
|
|
|
29
33
|
* Used to convert accumulated assistant turns into prompt equivalents.
|
|
30
34
|
* Calibration note: this constant may need per-tier adjustment after
|
|
31
35
|
* real-world validation against the z.ai web UI.
|
|
36
|
+
*
|
|
37
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
38
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
39
|
+
* for backward compatibility only and drifts from actual billing.
|
|
32
40
|
*/
|
|
33
41
|
exports.ZAI_PROMPT_INVOCATIONS = 17.5;
|
|
34
42
|
const FIVE_HOUR_MS = 5 * 3_600_000;
|
|
@@ -36,8 +44,17 @@ const SEVEN_DAY_MS = 7 * 86_400_000;
|
|
|
36
44
|
/**
|
|
37
45
|
* Provider IDs that OpenCode tags on z.ai-routed messages.
|
|
38
46
|
* `zai-coding-plan` is the Coding Plan key; `zai` is the bare API key.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
49
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
50
|
+
* for backward compatibility only and drifts from actual billing.
|
|
39
51
|
*/
|
|
40
52
|
exports.ZAI_PROVIDER_IDS = ['zai', 'zai-coding-plan'];
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
55
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
56
|
+
* for backward compatibility only and drifts from actual billing.
|
|
57
|
+
*/
|
|
41
58
|
function isZaiProviderId(value) {
|
|
42
59
|
return value === 'zai' || value === 'zai-coding-plan';
|
|
43
60
|
}
|
|
@@ -45,6 +62,10 @@ function isZaiProviderId(value) {
|
|
|
45
62
|
* Sums the token fields of a single turn into a scalar.
|
|
46
63
|
* Cache reads are weighted at 0.1× (Anthropic convention) to avoid
|
|
47
64
|
* over-counting repeated context. Output and reasoning tokens are weighted 1×.
|
|
65
|
+
*
|
|
66
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
67
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
68
|
+
* for backward compatibility only and drifts from actual billing.
|
|
48
69
|
*/
|
|
49
70
|
function turnTokenWeight(turn) {
|
|
50
71
|
return (turn.inputTokens +
|
|
@@ -59,6 +80,10 @@ function turnTokenWeight(turn) {
|
|
|
59
80
|
* Pure & stateless: the caller is responsible for passing the relevant turns.
|
|
60
81
|
* Turns outside the 7-day window are ignored; turns inside the 7-day window
|
|
61
82
|
* but outside the 5-hour window still count toward weekly usage.
|
|
83
|
+
*
|
|
84
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
85
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
86
|
+
* for backward compatibility only and drifts from actual billing.
|
|
62
87
|
*/
|
|
63
88
|
function accumulateZaiUsage(turns, nowMs = Date.now()) {
|
|
64
89
|
const fiveHourCutoff = nowMs - FIVE_HOUR_MS;
|
|
@@ -104,6 +129,10 @@ function accumulateZaiUsage(turns, nowMs = Date.now()) {
|
|
|
104
129
|
* the user must be on a higher tier. This under-detects at the start of a
|
|
105
130
|
* weekly cycle (a Max user looks identical to a Lite user until they cross
|
|
106
131
|
* 400 prompts/week), so callers should still expose an explicit override.
|
|
132
|
+
*
|
|
133
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
134
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
135
|
+
* for backward compatibility only and drifts from actual billing.
|
|
107
136
|
*/
|
|
108
137
|
function resolveZaiTier(configured, accumulated) {
|
|
109
138
|
if (configured !== 'auto')
|
|
@@ -128,6 +157,10 @@ function resolveZaiTier(configured, accumulated) {
|
|
|
128
157
|
* - `sevenDay.resetsAt` ← first turn in window + 7d (documented as
|
|
129
158
|
* "7 days from order time" — order time is unknown, so this is a
|
|
130
159
|
* lower bound at best).
|
|
160
|
+
*
|
|
161
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
162
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
163
|
+
* for backward compatibility only and drifts from actual billing.
|
|
131
164
|
*/
|
|
132
165
|
function inferZaiQuotaState(accumulated, tier, options = {}) {
|
|
133
166
|
const budget = exports.ZAI_TIER_BUDGETS[tier];
|
|
@@ -185,6 +218,10 @@ const ZAI_ERROR_CODES = {
|
|
|
185
218
|
* `YYYY-MM-DD HH:mm:ss` form defensively.
|
|
186
219
|
*
|
|
187
220
|
* Returns `null` when the code is not a quota-related business error.
|
|
221
|
+
*
|
|
222
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
223
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
224
|
+
* for backward compatibility only and drifts from actual billing.
|
|
188
225
|
*/
|
|
189
226
|
function parseZaiQuotaError(error) {
|
|
190
227
|
if (!error)
|
|
@@ -203,6 +240,10 @@ function parseZaiQuotaError(error) {
|
|
|
203
240
|
* Handles ISO 8601 (`2025-01-31T14:00:00Z`), space-separated
|
|
204
241
|
* (`2025-01-31 14:00:00`), and epoch-seconds (1234567890) forms.
|
|
205
242
|
* Returns undefined when no parseable timestamp is found.
|
|
243
|
+
*
|
|
244
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
245
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
246
|
+
* for backward compatibility only and drifts from actual billing.
|
|
206
247
|
*/
|
|
207
248
|
function extractNextFlushTime(message) {
|
|
208
249
|
if (!message)
|
|
@@ -236,6 +277,10 @@ function extractNextFlushTime(message) {
|
|
|
236
277
|
/**
|
|
237
278
|
* Builds an unavailable z.ai `QuotaState` for the cold-start case where
|
|
238
279
|
* no z.ai traffic has been observed yet.
|
|
280
|
+
*
|
|
281
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
282
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
283
|
+
* for backward compatibility only and drifts from actual billing.
|
|
239
284
|
*/
|
|
240
285
|
function makeUnavailableZaiQuotaState(error = 'No z.ai usage observed yet', tier = 'lite', capturedAt = new Date().toISOString()) {
|
|
241
286
|
return {
|
|
@@ -259,6 +304,10 @@ function makeUnavailableZaiQuotaState(error = 'No z.ai usage observed yet', tier
|
|
|
259
304
|
*
|
|
260
305
|
* Returns `{ turns, errors }` so callers can replay them through
|
|
261
306
|
* `ZaiQuotaWatcher.ingestAssistantTurns` and `ingestError`.
|
|
307
|
+
*
|
|
308
|
+
* @deprecated Use `resolveZaiQuota()` from `zaiQuotaApi`, which reads z.ai's
|
|
309
|
+
* authoritative quota endpoint. This observed-traffic estimator is retained
|
|
310
|
+
* for backward compatibility only and drifts from actual billing.
|
|
262
311
|
*/
|
|
263
312
|
function rowsToZaiTurnsAndErrors(rows) {
|
|
264
313
|
const turns = [];
|
|
@@ -10,6 +10,10 @@ type TierResolver = (configured: ZaiTier | 'auto', accumulated: ZaiAccumulatedUs
|
|
|
10
10
|
type SnapshotReader = (providerId: ZaiSnapshotProvider, accountId: string) => QuotaState | null;
|
|
11
11
|
type SnapshotWriter = (providerId: ZaiSnapshotProvider, accountId: string, quota: QuotaState) => void;
|
|
12
12
|
type HistoryAppender = (sample: QuotaHistorySample) => void | Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Unreachable from every package entrypoint and no longer used by
|
|
15
|
+
* product code. Use `resolveZaiQuota()` from `zaiQuotaApi` instead.
|
|
16
|
+
*/
|
|
13
17
|
export interface ZaiQuotaWatcherOptions {
|
|
14
18
|
/** Configured tier. Default: `'auto'` (heuristic from observed usage). */
|
|
15
19
|
tier?: ZaiTier | 'auto';
|
|
@@ -39,6 +43,9 @@ export interface ZaiQuotaWatcherOptions {
|
|
|
39
43
|
* for every observed z.ai assistant turn, and `ingestError` whenever a
|
|
40
44
|
* z.ai business error is observed. The watcher debounces recompute and
|
|
41
45
|
* emits via `onUpdate` / `onQuotaUpdate`.
|
|
46
|
+
*
|
|
47
|
+
* @deprecated Unreachable from every package entrypoint and no longer used by
|
|
48
|
+
* product code. Use `resolveZaiQuota()` from `zaiQuotaApi` instead.
|
|
42
49
|
*/
|
|
43
50
|
export declare class ZaiQuotaWatcher implements Disposable {
|
|
44
51
|
private readonly tier;
|
package/dist/zaiQuotaWatcher.js
CHANGED
|
@@ -37,6 +37,9 @@ function enrichZaiState(state) {
|
|
|
37
37
|
* for every observed z.ai assistant turn, and `ingestError` whenever a
|
|
38
38
|
* z.ai business error is observed. The watcher debounces recompute and
|
|
39
39
|
* emits via `onUpdate` / `onQuotaUpdate`.
|
|
40
|
+
*
|
|
41
|
+
* @deprecated Unreachable from every package entrypoint and no longer used by
|
|
42
|
+
* product code. Use `resolveZaiQuota()` from `zaiQuotaApi` instead.
|
|
40
43
|
*/
|
|
41
44
|
class ZaiQuotaWatcher {
|
|
42
45
|
tier;
|
package/package.json
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sidekick-shared",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.4",
|
|
4
4
|
"description": "Shared data access layer for Sidekick — readers, types, providers, credentials, quota",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"codex-cli",
|
|
8
|
+
"opencode",
|
|
9
|
+
"session-monitor",
|
|
10
|
+
"token-usage",
|
|
11
|
+
"quota",
|
|
12
|
+
"jsonl",
|
|
13
|
+
"ai-coding-assistant",
|
|
14
|
+
"agent-hub",
|
|
15
|
+
"zod-schemas"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://cesarandreslopez.github.io/sidekick-agent-hub/",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/cesarandreslopez/sidekick-agent-hub",
|
|
21
|
+
"directory": "sidekick-shared"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/cesarandreslopez/sidekick-agent-hub/issues"
|
|
25
|
+
},
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Cesar Andres Lopez",
|
|
28
|
+
"email": "cesarandreslopez@gmail.com"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20.0.0"
|
|
32
|
+
},
|
|
5
33
|
"main": "dist/index.js",
|
|
6
34
|
"types": "dist/index.d.ts",
|
|
7
35
|
"exports": {
|
|
@@ -47,8 +75,38 @@
|
|
|
47
75
|
},
|
|
48
76
|
"./package.json": "./package.json"
|
|
49
77
|
},
|
|
78
|
+
"typesVersions": {
|
|
79
|
+
"*": {
|
|
80
|
+
"browser": [
|
|
81
|
+
"dist/browser.d.ts"
|
|
82
|
+
],
|
|
83
|
+
"node": [
|
|
84
|
+
"dist/node.d.ts"
|
|
85
|
+
],
|
|
86
|
+
"schemas": [
|
|
87
|
+
"dist/schemas/index.d.ts"
|
|
88
|
+
],
|
|
89
|
+
"phrases": [
|
|
90
|
+
"dist/phrases.d.ts"
|
|
91
|
+
],
|
|
92
|
+
"modelContext": [
|
|
93
|
+
"dist/modelContext.d.ts"
|
|
94
|
+
],
|
|
95
|
+
"modelInfo": [
|
|
96
|
+
"dist/modelInfo.d.ts"
|
|
97
|
+
],
|
|
98
|
+
"formatting": [
|
|
99
|
+
"dist/formatting.d.ts"
|
|
100
|
+
],
|
|
101
|
+
"statusline": [
|
|
102
|
+
"dist/statusline/index.d.ts"
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
50
106
|
"files": [
|
|
51
|
-
"dist"
|
|
107
|
+
"dist",
|
|
108
|
+
"CHANGELOG.md",
|
|
109
|
+
"LICENSE"
|
|
52
110
|
],
|
|
53
111
|
"sideEffects": false,
|
|
54
112
|
"publishConfig": {
|