dsh-plugin-subscription-usage 0.0.0-stage → 0.1.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/LICENSE +22 -0
- package/README.md +38 -2
- package/cordis.patch.yml +5 -0
- package/icon.svg +9 -0
- package/lib/auth/claude-code-creds.d.ts +23 -0
- package/lib/auth/claude-code-creds.js +172 -0
- package/lib/auth/device-flow.d.ts +55 -0
- package/lib/auth/device-flow.js +177 -0
- package/lib/auth/jwt.d.ts +10 -0
- package/lib/auth/jwt.js +25 -0
- package/lib/auth/oauth-flow.d.ts +91 -0
- package/lib/auth/oauth-flow.js +227 -0
- package/lib/auth/pkce.d.ts +31 -0
- package/lib/auth/pkce.js +35 -0
- package/lib/auth/rpc.d.ts +233 -0
- package/lib/auth/rpc.js +501 -0
- package/lib/auth/store.d.ts +198 -0
- package/lib/auth/store.js +473 -0
- package/lib/client/Footer.d.ts +3 -0
- package/lib/client/Footer.js +73 -0
- package/lib/client/Gauge.d.ts +28 -0
- package/lib/client/Gauge.js +139 -0
- package/lib/client/ImageGallery.d.ts +54 -0
- package/lib/client/ImageGallery.js +112 -0
- package/lib/client/ImageGenerateToolview.d.ts +48 -0
- package/lib/client/ImageGenerateToolview.js +130 -0
- package/lib/client/Notice.d.ts +15 -0
- package/lib/client/Notice.js +93 -0
- package/lib/client/ProviderCard.d.ts +35 -0
- package/lib/client/ProviderCard.js +240 -0
- package/lib/client/SpeedSelect.d.ts +72 -0
- package/lib/client/SpeedSelect.js +214 -0
- package/lib/client/Usage.d.ts +7 -0
- package/lib/client/Usage.js +83 -0
- package/lib/client/VideoGenerateToolview.d.ts +42 -0
- package/lib/client/VideoGenerateToolview.js +172 -0
- package/lib/client/context.d.ts +16 -0
- package/lib/client/context.js +11 -0
- package/lib/client/fast-command.d.ts +2 -0
- package/lib/client/fast-command.js +4 -0
- package/lib/client/hooks.d.ts +2 -0
- package/lib/client/hooks.js +10 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.js +113 -0
- package/lib/client/locales.d.ts +139 -0
- package/lib/client/locales.js +267 -0
- package/lib/client/meter.d.ts +91 -0
- package/lib/client/meter.js +196 -0
- package/lib/client/prefs.d.ts +51 -0
- package/lib/client/prefs.js +71 -0
- package/lib/client/rpc.d.ts +161 -0
- package/lib/client/rpc.js +31 -0
- package/lib/client/store.d.ts +67 -0
- package/lib/client/store.js +129 -0
- package/lib/client/styles.d.ts +7 -0
- package/lib/client/styles.js +176 -0
- package/lib/client.js +3933 -0
- package/lib/client.js.map +1 -0
- package/lib/compat.d.ts +55 -0
- package/lib/compat.js +20 -0
- package/lib/http.d.ts +134 -0
- package/lib/http.js +431 -0
- package/lib/index.d.ts +121 -0
- package/lib/index.js +13210 -0
- package/lib/json-text.d.ts +2 -0
- package/lib/json-text.js +4 -0
- package/lib/model-defaults.d.ts +23 -0
- package/lib/model-defaults.js +238 -0
- package/lib/model-speeds.d.ts +10 -0
- package/lib/model-speeds.js +48 -0
- package/lib/models-directory.d.ts +17 -0
- package/lib/models-directory.js +25 -0
- package/lib/provider-settings.d.ts +55 -0
- package/lib/provider-settings.js +215 -0
- package/lib/providers/account-preferences.d.ts +46 -0
- package/lib/providers/account-preferences.js +188 -0
- package/lib/providers/accounts.d.ts +113 -0
- package/lib/providers/accounts.js +142 -0
- package/lib/providers/antigravity-oauth-client.d.ts +7 -0
- package/lib/providers/antigravity-oauth-client.js +7 -0
- package/lib/providers/antigravity.d.ts +119 -0
- package/lib/providers/antigravity.js +552 -0
- package/lib/providers/catalog-refresh.d.ts +4 -0
- package/lib/providers/catalog-refresh.js +30 -0
- package/lib/providers/catalog-store.d.ts +47 -0
- package/lib/providers/catalog-store.js +283 -0
- package/lib/providers/claude-cli-version.d.ts +15 -0
- package/lib/providers/claude-cli-version.js +24 -0
- package/lib/providers/claude.d.ts +212 -0
- package/lib/providers/claude.js +726 -0
- package/lib/providers/codex-client-version.d.ts +8 -0
- package/lib/providers/codex-client-version.js +17 -0
- package/lib/providers/codex-search.d.ts +29 -0
- package/lib/providers/codex-search.js +198 -0
- package/lib/providers/codex.d.ts +253 -0
- package/lib/providers/codex.js +930 -0
- package/lib/providers/common.d.ts +415 -0
- package/lib/providers/common.js +679 -0
- package/lib/providers/copilot.d.ts +365 -0
- package/lib/providers/copilot.js +956 -0
- package/lib/providers/grok.d.ts +214 -0
- package/lib/providers/grok.js +750 -0
- package/lib/providers/image-pool.d.ts +30 -0
- package/lib/providers/image-pool.js +89 -0
- package/lib/providers/npm-cli-version.d.ts +56 -0
- package/lib/providers/npm-cli-version.js +98 -0
- package/lib/providers/pool-family.d.ts +56 -0
- package/lib/providers/pool-family.js +45 -0
- package/lib/providers/pool-health.d.ts +91 -0
- package/lib/providers/pool-health.js +164 -0
- package/lib/providers/pool-usage.d.ts +106 -0
- package/lib/providers/pool-usage.js +302 -0
- package/lib/providers/pool.d.ts +115 -0
- package/lib/providers/pool.js +461 -0
- package/lib/providers/rate-limit.d.ts +192 -0
- package/lib/providers/rate-limit.js +338 -0
- package/lib/providers/replay.d.ts +4 -0
- package/lib/providers/replay.js +37 -0
- package/lib/providers/reset-redemption.d.ts +20 -0
- package/lib/providers/reset-redemption.js +70 -0
- package/lib/tools/image-generate.d.ts +128 -0
- package/lib/tools/image-generate.js +438 -0
- package/lib/tools/registration.d.ts +15 -0
- package/lib/tools/registration.js +24 -0
- package/lib/tools/video-generate.d.ts +89 -0
- package/lib/tools/video-generate.js +257 -0
- package/lib/tools/x-search.d.ts +58 -0
- package/lib/tools/x-search.js +197 -0
- package/lib/translate/anthropic.d.ts +180 -0
- package/lib/translate/anthropic.js +534 -0
- package/lib/translate/antigravity-images.d.ts +11 -0
- package/lib/translate/antigravity-images.js +62 -0
- package/lib/translate/antigravity-schema.d.ts +4 -0
- package/lib/translate/antigravity-schema.js +145 -0
- package/lib/translate/antigravity-thinking.d.ts +5 -0
- package/lib/translate/antigravity-thinking.js +44 -0
- package/lib/translate/antigravity.d.ts +120 -0
- package/lib/translate/antigravity.js +412 -0
- package/lib/translate/chat-completions.d.ts +120 -0
- package/lib/translate/chat-completions.js +382 -0
- package/lib/translate/resolved.d.ts +98 -0
- package/lib/translate/resolved.js +186 -0
- package/lib/translate/responses.d.ts +192 -0
- package/lib/translate/responses.js +443 -0
- package/lib/translate/sse.d.ts +21 -0
- package/lib/translate/sse.js +62 -0
- package/lib/usage/headers.d.ts +21 -0
- package/lib/usage/headers.js +64 -0
- package/lib/usage/pace.d.ts +53 -0
- package/lib/usage/pace.js +48 -0
- package/lib/usage/service.d.ts +64 -0
- package/lib/usage/service.js +104 -0
- package/lib/usage-providers/common.d.ts +23 -0
- package/lib/usage-providers/common.js +28 -0
- package/lib/usage-providers/index.d.ts +42 -0
- package/lib/usage-providers/index.js +71 -0
- package/lib/usage-providers/keys.d.ts +11 -0
- package/lib/usage-providers/keys.js +52 -0
- package/lib/usage-providers/kimi.d.ts +4 -0
- package/lib/usage-providers/kimi.js +52 -0
- package/lib/usage-providers/ollama-cloud.d.ts +4 -0
- package/lib/usage-providers/ollama-cloud.js +42 -0
- package/lib/usage-providers/zai.d.ts +5 -0
- package/lib/usage-providers/zai.js +53 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +115 -4
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-plugin-subscription-usage: register OAuth-subscription LLM providers
|
|
3
|
+
* (ChatGPT/Codex, Claude, Grok, GitHub Copilot, Google Antigravity) on `ctx.llm`, and expose the `/subscriptions-auth`
|
|
4
|
+
* RPC channel the web Settings page uses to run the logins. The token store
|
|
5
|
+
* lives at `~/.dsh/plugins/subscriptions/auth.json`; the channel registers only when
|
|
6
|
+
* a host `connection` service exists, so headless compositions load fine.
|
|
7
|
+
* @module dsh-plugin-subscriptions
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
+
import z from '@deepseek-ai/schemastery';
|
|
11
|
+
import type { ProviderId } from './auth/store.js';
|
|
12
|
+
import type { ModelEntry } from './providers/common.js';
|
|
13
|
+
import type { RateLimitConfig } from './providers/rate-limit.js';
|
|
14
|
+
import type { PromptCacheTtl } from './translate/anthropic.js';
|
|
15
|
+
import type { CliVersion, NpmCliVersionCache } from './providers/npm-cli-version.js';
|
|
16
|
+
export type { AccountPreferences, ProviderPreferences } from './provider-settings.js';
|
|
17
|
+
import type { PoolMemberRef } from './providers/pool-family.js';
|
|
18
|
+
import type { AntigravityRuntimeConfig } from './providers/antigravity.js';
|
|
19
|
+
export type { ModelEntry, ProviderUsage, UsageWindow } from './providers/common.js';
|
|
20
|
+
export type { RateLimitConfig, RateLimitWait } from './providers/rate-limit.js';
|
|
21
|
+
export type { ProviderStatus } from './auth/rpc.js';
|
|
22
|
+
export type { AntigravitySession, ClaudeSession, CodexSession, CopilotSession, GrokSession, ProviderId } from './auth/store.js';
|
|
23
|
+
export declare const name = "dsh-plugin-subscription-usage";
|
|
24
|
+
export declare const inject: string[];
|
|
25
|
+
/** Default maximum provider idle time while one stream read is outstanding. */
|
|
26
|
+
export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
27
|
+
/** Bound on one pool quota poll — member selection must not hang on a usage endpoint. */
|
|
28
|
+
export declare const POOL_USAGE_TIMEOUT_MS = 10000;
|
|
29
|
+
export { withTimeout } from './providers/common.js';
|
|
30
|
+
/** Plugin config, validated by the same-named schemastery schema. */
|
|
31
|
+
export interface Config {
|
|
32
|
+
/** Codex /models client_version override; does not change account entitlements. */
|
|
33
|
+
codexClientVersion?: string;
|
|
34
|
+
/** Provider routes to register; defaults to every supported provider. */
|
|
35
|
+
providers?: ProviderId[];
|
|
36
|
+
/** Maximum provider idle time while one stream read is outstanding (default five minutes). */
|
|
37
|
+
streamIdleTimeoutMs?: number;
|
|
38
|
+
/**
|
|
39
|
+
* How long Anthropic keeps the Claude conversation cache after its last use:
|
|
40
|
+
* `'5m'` (default, the API's own default) or `'1h'`. One hour writes cache
|
|
41
|
+
* entries at 2× the input price instead of 1.25×, and pays off when you
|
|
42
|
+
* regularly pause longer than five minutes between messages. Claude only;
|
|
43
|
+
* compaction and session-title requests always stay on five minutes.
|
|
44
|
+
*/
|
|
45
|
+
claudePromptCacheTtl?: PromptCacheTtl;
|
|
46
|
+
/** Whether and how long a route waits out a closed rate-limit window. */
|
|
47
|
+
rateLimit?: RateLimitConfig;
|
|
48
|
+
/** Advisory model catalogs overriding the built-in defaults, per provider. */
|
|
49
|
+
models?: {
|
|
50
|
+
codex?: ModelEntry[];
|
|
51
|
+
claude?: ModelEntry[];
|
|
52
|
+
grok?: ModelEntry[];
|
|
53
|
+
copilot?: ModelEntry[];
|
|
54
|
+
antigravity?: ModelEntry[];
|
|
55
|
+
};
|
|
56
|
+
/** Antigravity-specific OAuth and endpoint configuration. */
|
|
57
|
+
antigravity?: AntigravityRuntimeConfig & {
|
|
58
|
+
/** Google OAuth client id. May instead be supplied as ANTIGRAVITY_CLIENT_ID. */
|
|
59
|
+
clientId?: string;
|
|
60
|
+
/** Google OAuth client secret, when required by the client registration. */
|
|
61
|
+
clientSecret?: string;
|
|
62
|
+
};
|
|
63
|
+
/** Usage display preferences, editable live from the Models page. */
|
|
64
|
+
usage?: ReturnType<typeof usageVolatileSchema>;
|
|
65
|
+
/** Same-subscription account pools (and optional extra tier models). */
|
|
66
|
+
pool?: {
|
|
67
|
+
/** Enable account pooling (default true; needs ≥2 accounts of one provider). */
|
|
68
|
+
enabled?: boolean;
|
|
69
|
+
/** Member selection: plain priority failover, or quota-aware urgency scheduling. */
|
|
70
|
+
strategy?: 'priority' | 'quota_aware' | 'quota_normalized';
|
|
71
|
+
/** A challenger must out-score the sticky member by this factor to take over (default 2). */
|
|
72
|
+
switchMargin?: number;
|
|
73
|
+
/** Auto-pool every catalog model across a provider's logged-in accounts (default true). */
|
|
74
|
+
autoAccounts?: boolean;
|
|
75
|
+
/** @deprecated Use {@link autoAccounts}. */
|
|
76
|
+
autoFamilies?: boolean;
|
|
77
|
+
/** Explicit account lists for one catalog model (same provider); replaces the auto pool. */
|
|
78
|
+
families?: Record<string, PoolMemberRef[]>;
|
|
79
|
+
/** Extra picker entries with heterogeneous fallbacks, listed under the first member's provider. */
|
|
80
|
+
tiers?: Record<string, PoolMemberRef[]>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether the composer shows usage (the current model's provider plus the
|
|
85
|
+
* `pinned` ones) and whether quota reads as `left` or `used`. Profiles saved
|
|
86
|
+
* before `composer` existed carry a `gauge` mode; the Client reads `off` as
|
|
87
|
+
* hidden and unsets it on the next change.
|
|
88
|
+
*/
|
|
89
|
+
declare const usagePreferencesSchema: z<Schemastery.ObjectS<NoInfer<{
|
|
90
|
+
composer: z<boolean, boolean, "defined">;
|
|
91
|
+
pinned: z<("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], ("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], "defined">;
|
|
92
|
+
display: z<"used" | "left", "used" | "left", "defined">;
|
|
93
|
+
paceWarnings: z<boolean, boolean, "defined">;
|
|
94
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
95
|
+
composer: z<boolean, boolean, "defined">;
|
|
96
|
+
pinned: z<("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], ("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], "defined">;
|
|
97
|
+
display: z<"used" | "left", "used" | "left", "defined">;
|
|
98
|
+
paceWarnings: z<boolean, boolean, "defined">;
|
|
99
|
+
}>>, "plain">;
|
|
100
|
+
/** Usage display preferences as the plugin reads them. */
|
|
101
|
+
export type UsagePreferences = ReturnType<typeof usagePreferencesSchema>;
|
|
102
|
+
declare const usageVolatileSchema: z<NoInfer<Schemastery.ObjectS<NoInfer<{
|
|
103
|
+
composer: z<boolean, boolean, "defined">;
|
|
104
|
+
pinned: z<("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], ("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], "defined">;
|
|
105
|
+
display: z<"used" | "left", "used" | "left", "defined">;
|
|
106
|
+
paceWarnings: z<boolean, boolean, "defined">;
|
|
107
|
+
}>>>, NoInfer<Schemastery.ObjectT<NoInfer<{
|
|
108
|
+
composer: z<boolean, boolean, "defined">;
|
|
109
|
+
pinned: z<("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], ("zai" | "ollama-cloud" | "kimi" | "codex" | "claude" | "grok" | "copilot" | "antigravity")[], "defined">;
|
|
110
|
+
display: z<"used" | "left", "used" | "left", "defined">;
|
|
111
|
+
paceWarnings: z<boolean, boolean, "defined">;
|
|
112
|
+
}>>>, "volatile">;
|
|
113
|
+
export declare const Config: z<Config>;
|
|
114
|
+
/**
|
|
115
|
+
* Read the CLI version a route presents for the Settings page. The first
|
|
116
|
+
* lookup is awaited (bounded by its own 5s deadline) so a slow registry is
|
|
117
|
+
* not misreported as a fallback; a later refresh is waited on only briefly,
|
|
118
|
+
* because the whole page waits on `status`, and the last result shows.
|
|
119
|
+
*/
|
|
120
|
+
export declare function presentedVersion(cache: Pick<NpmCliVersionCache, 'resolve' | 'current'>, waitMs?: number): () => Promise<CliVersion | undefined>;
|
|
121
|
+
export declare function apply(ctx: Context, config: Config): void;
|