@mars-sea/dsh-commandcode-provider 0.2.4 → 0.4.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/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
2
  import { GenerateOptions, LlmAdapter, LlmModelInfo, LlmResolvedModelInfo, ResolvedRetryPolicy, StreamChunk } from "@deepseek-ai/dsh-llm";
3
3
  import { CredentialRef } from "@deepseek-ai/dsh-credentials";
4
+ import { TypertRemoteService, TypertSchema } from "@deepseek-ai/dsh-typert-protocol";
4
5
  import { Context } from "@deepseek-ai/cordis";
5
6
  import { AttachmentStore } from "@deepseek-ai/dsh-attachment";
6
7
  import { CommandDefinition } from "@deepseek-ai/dsh-commands";
@@ -70,6 +71,56 @@ declare function compareByPlan(a: {
70
71
  id: string;
71
72
  name: string;
72
73
  }): number;
74
+ /**
75
+ * Subscription plan table, synced from the official CLI bundle's plan maps
76
+ * (`Nn`/`$n` in command-code@1.26.0 `dist/cli.mjs`): subscription `planId`
77
+ * prefix → display name and the plan's monthly credit total. This is the
78
+ * account's own subscription (from `/alpha/billing/subscriptions`) — distinct
79
+ * from {@link KNOWN_PLANS}, which maps catalog models to their minimum tier.
80
+ *
81
+ * `tierWeight` is plugin-added (not from the CLI maps): the plan's rank on
82
+ * the {@link PLAN_ORDER} scale, used by the picker's plan filter
83
+ * ({@link modelVisibleInPlan}) to hide models above the account's tier.
84
+ */
85
+ declare const KNOWN_SUBSCRIPTION_PLANS: Readonly<Record<string, {
86
+ name: string;
87
+ monthlyCredits: number;
88
+ tierWeight: number;
89
+ }>>;
90
+ /**
91
+ * Resolve a subscription `planId` (e.g. `individual-pro-v1`) to its display
92
+ * name and monthly credit total, mirroring the CLI's `getPlanInfo`:
93
+ * normalize (lowercase, `_` → `-`), then longest-prefix match so
94
+ * `individual-pro-v1` wins over `individual-pro`. Unknown ids return
95
+ * `undefined`.
96
+ */
97
+ declare function subscriptionPlanInfo(planId: string): {
98
+ name: string;
99
+ monthlyCredits: number;
100
+ tierWeight: number;
101
+ } | undefined;
102
+ /**
103
+ * The billing facts the picker's plan filter needs, fetched by mirroring the
104
+ * CLI's `createBilling` flow (whoami → orgId, then `/alpha/billing/subscriptions`
105
+ * for the plan id and `/alpha/billing/credits` for the on-demand balances).
106
+ */
107
+ interface CommandCodeBillingAccess {
108
+ /** Account plan tier weight on the {@link PLAN_ORDER} scale; undefined when the plan is unknown. */
109
+ tierWeight: number | undefined;
110
+ /**
111
+ * Purchased + free on-demand credit balance. The official access model
112
+ * (`evaluateModelAccess` in the CLI) allows every model when the account
113
+ * holds any on-demand credits — the plan gate only applies at zero balance.
114
+ */
115
+ onDemandCredits: number;
116
+ }
117
+ /**
118
+ * Whether the picker lists `modelId` for an account with the given billing
119
+ * access. Fails open at every uncertainty: no billing data, an unknown plan,
120
+ * or a model outside {@link KNOWN_PLANS} all keep the model visible — the
121
+ * server remains the final gate (`403 MODEL_NOT_IN_PLAN`).
122
+ */
123
+ declare function modelVisibleInPlan(modelId: string, access: CommandCodeBillingAccess | undefined): boolean;
73
124
  /**
74
125
  * Active pricing deals per the official pricing page
75
126
  * (`/docs/resources/pricing-limits#deals`). Each entry records the model's
@@ -95,10 +146,38 @@ interface KnownDeal {
95
146
  free?: boolean;
96
147
  }
97
148
  declare const KNOWN_DEALS: Readonly<Record<string, KnownDeal>>;
149
+ /**
150
+ * Models with time-of-day (peak/off-peak) pricing, per the official pricing
151
+ * page (`/docs/resources/pricing-limits`). Since 2026-08-16 16:00 UTC, DeepSeek
152
+ * charges by the hour: peak hours are 01:00–04:00 and 06:00–10:00 UTC (7h/day,
153
+ * full price); the other 17 hours are off-peak at half price. The picker shows
154
+ * the *current* state as a compact label (`Peak`/`Half`) matching the English
155
+ * noun style of the other markers (`Image`, `FREE`), so a developer can tell at
156
+ * a glance whether calling the model right now is cheap or expensive.
157
+ *
158
+ * Keep in sync with the official pricing page when the model set or the peak
159
+ * windows change (see the dsh-commandcode-upstream skill).
160
+ */
161
+ declare const KNOWN_PEAK_PRICING: ReadonlySet<string>;
162
+ /**
163
+ * Whether `now` (defaults to `Date.now()`) falls in a peak-pricing hour for
164
+ * time-of-day-priced models. `undefined` for models outside the snapshot.
165
+ */
166
+ declare function peakPricingState(modelId: string, now?: number): 'peak' | 'off-peak' | undefined;
167
+ /**
168
+ * Compact label for the current peak/off-peak state: `Peak` (full price) or
169
+ * `Half` (off-peak, half price). These English nouns match the picker's other
170
+ * markers (`Go`, `Image`, `FREE`), and since they appear only on time-of-day
171
+ * priced models they double as a "priced by the hour" signal. Returns undefined
172
+ * for models without time-of-day pricing.
173
+ */
174
+ declare function peakPricingLabel(modelId: string, now?: number): string | undefined;
98
175
  declare const COMMAND_CODE_CLI_VERSION = "1.26.0";
99
176
  declare const DEFAULT_API_BASE = "https://api.commandcode.ai";
100
177
  declare const DEFAULT_GENERATE_MAX_TOKENS = 64000;
101
178
  declare const DEFAULT_MAX_OUTPUT_TOKENS = 65536;
179
+ /** How long the picker's plan-filter billing facts stay cached before refetching. */
180
+ declare const BILLING_ACCESS_TTL_MS: number;
102
181
  /** Head-of-request timeout: how long to wait for the first response byte. */
103
182
  declare const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
104
183
  /** Stream idle timeout: a generation that stalls this long is a dead connection. */
@@ -124,9 +203,10 @@ declare function dealLabel(modelId: string, now?: number): string | undefined;
124
203
  declare function formatContext(contextWindow: number | undefined): string | undefined;
125
204
  /**
126
205
  * Compact one-line summary for the model picker: plan tier, then any active
127
- * deal (discount or FREE), then `Image` for Vision-capable models, then the
128
- * context window. Text-only models simply omit the Image marker "Text only"
129
- * adds nothing the picker needs to show.
206
+ * deal (discount or FREE), then the current peak/off-peak state (`Peak`/`Half`)
207
+ * for time-of-day-priced models, then `Image` for Vision-capable models, then
208
+ * the context window. Text-only models simply omit the Image marker "Text
209
+ * only" adds nothing the picker needs to show.
130
210
  */
131
211
  declare function capabilityDescription(modelId: string, contextWindow?: number, now?: number): string;
132
212
  declare function projectSlugFromPath(pathName: string): string;
@@ -148,6 +228,13 @@ interface CommandCodeConnectionOptions {
148
228
  requestTimeoutMs: number;
149
229
  /** Milliseconds a stream may stall before it is treated as a dead connection (default 300s). */
150
230
  streamIdleTimeoutMs: number;
231
+ /**
232
+ * Whether the picker hides models above the account's subscription tier
233
+ * (default true). The filter fails open: unknown plan, billing-endpoint
234
+ * failure, a positive on-demand credit balance, or an unmapped model all
235
+ * keep the full catalog visible. Set false to always list every model.
236
+ */
237
+ filterModelsByPlan?: boolean;
151
238
  }
152
239
  /**
153
240
  * Resolve the durable attachment service, or undefined when the host does not
@@ -204,11 +291,25 @@ interface CommandCodeCredits {
204
291
  resetAt: number;
205
292
  };
206
293
  }
294
+ /** Subscription plan state from `/alpha/billing/subscriptions`. */
295
+ interface CommandCodePlan {
296
+ /** Raw subscription plan id (e.g. `individual-pro`); empty when unreported. */
297
+ planId: string;
298
+ /** Display name (e.g. `Pro`); falls back to the raw id for unknown plans. */
299
+ name: string;
300
+ /** Raw subscription status (`active`, `trialing`, `past_due`, …); empty when unreported. */
301
+ status: string;
302
+ /** The plan's monthly credit total per {@link KNOWN_SUBSCRIPTION_PLANS}; null for unknown plans. */
303
+ monthlyCredits: number | null;
304
+ /** Billing period end in millis; 0 when the endpoint did not report one. */
305
+ currentPeriodEnd: number;
306
+ }
207
307
  /** Everything the usage endpoints report, fetched together. */
208
308
  interface CommandCodeUsageReport {
209
309
  account?: CommandCodeAccount;
210
310
  usage?: CommandCodeUsage;
211
311
  credits?: CommandCodeCredits;
312
+ plan?: CommandCodePlan;
212
313
  /** Endpoint failures degrade the report instead of failing it. */
213
314
  failures: string[];
214
315
  }
@@ -217,6 +318,8 @@ declare class CommandCodeAdapter<C extends CommandCodeConnectionOptions = Comman
217
318
  private catalog;
218
319
  private readonly fetchImpl;
219
320
  private readonly resolveAttachments;
321
+ private billingAccess;
322
+ private billingAccessInflight;
220
323
  constructor(deps: CommandCodeAdapterDeps<C>);
221
324
  /**
222
325
  * Command Code is a metered subscription API: 429 (rate limit) and 5xx
@@ -231,9 +334,28 @@ declare class CommandCodeAdapter<C extends CommandCodeConnectionOptions = Comman
231
334
  private loadCatalog;
232
335
  listModels(provider: string): Promise<readonly LlmModelInfo[]>;
233
336
  resolveModel(provider: string, model: string, signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
337
+ /** The headers every authenticated account endpoint shares. */
338
+ private accountHeaders;
339
+ /**
340
+ * The billing facts behind the picker's plan filter, cached for
341
+ * {@link BILLING_ACCESS_TTL_MS} and shared across concurrent callers.
342
+ * `undefined` means "unknown — show everything" (fail-open).
343
+ */
344
+ private loadBillingAccess;
345
+ /**
346
+ * The billing facts behind the picker's plan filter, mirroring the CLI's
347
+ * `createBilling` flow: whoami yields the org id, then the subscriptions
348
+ * and credits endpoints answer in parallel. The plan id is honored only
349
+ * when the subscription reports an active-ish status (the CLI's rule); when
350
+ * the subscriptions endpoint fails entirely, `credits.planId` is the
351
+ * fallback (the CLI stamps plan identity from it too). Any failure resolves
352
+ * to `undefined` (fail-open) rather than breaking the picker.
353
+ */
354
+ private fetchBillingAccess;
234
355
  /**
235
- * Fetch account, usage, and credit state from the Command Code account
236
- * endpoints (`/alpha/whoami`, `/alpha/usage/summary`, `/alpha/billing/credits`).
356
+ * Fetch account, usage, credit, and subscription state from the Command
357
+ * Code account endpoints (`/alpha/whoami`, `/alpha/usage/summary`,
358
+ * `/alpha/billing/credits`, `/alpha/billing/subscriptions`).
237
359
  * Each endpoint degrades independently: a failed one lands in `failures`
238
360
  * while the rest still report, so a transient outage never blanks the whole
239
361
  * view. Requires a usable API key (throws `MISSING_CREDENTIAL` otherwise).
@@ -253,6 +375,47 @@ declare function commandDefinition<C extends CommandCodeConnectionOptions>(deps:
253
375
  /** Register the command on `ctx.commands` (called from the plugin entry). */
254
376
  declare function applyCommands<C extends CommandCodeConnectionOptions>(ctx: Context, deps: CommandCodeCommandDeps<C>): void;
255
377
  //#endregion
378
+ //#region src/usage-remote.d.ts
379
+ /** Everything the usage service needs beyond its Cordis context. */
380
+ interface CommandCodeUsageDeps<C extends CommandCodeConnectionOptions = CommandCodeConnectionOptions> {
381
+ /** The registered adapter (for getUsage). */
382
+ adapter: CommandCodeAdapter<C>;
383
+ }
384
+ /**
385
+ * The Remote receiver: a Cordis service the Gateway resolves by key
386
+ * (`commandcodeUsage`) and binds to the wire namespace (`commandcode`). The
387
+ * base class stamps the `typertRemote` binding the Gateway validates on every
388
+ * dispatch; no decorators are needed because the descriptor is registered
389
+ * explicitly (strict path) rather than discovered from source markers.
390
+ */
391
+ declare class CommandCodeUsageService<C extends CommandCodeConnectionOptions = CommandCodeConnectionOptions> extends TypertRemoteService {
392
+ private readonly deps;
393
+ constructor(ctx: Context, deps: CommandCodeUsageDeps<C>);
394
+ /**
395
+ * Account, usage, and credit state for the settings page's account card.
396
+ * Degrades per endpoint like the `/commandcode` command (failures land in
397
+ * `report.failures`); throws `MISSING_CREDENTIAL` when no key resolves, which
398
+ * the Gateway folds into the failure branch the page renders as a hint.
399
+ */
400
+ report(): Promise<CommandCodeUsageReport>;
401
+ }
402
+ /**
403
+ * Provide the usage service and register its Remote descriptor. The registry
404
+ * contribution is tied to this fiber's lifetime: the registry's own
405
+ * `register()` effect would otherwise outlive the plugin.
406
+ */
407
+ declare function applyUsageRemote<C extends CommandCodeConnectionOptions>(ctx: Context, deps: CommandCodeUsageDeps<C>): void;
408
+ //#endregion
409
+ //#region src/usage-wire.d.ts
410
+ /** Canonical `<namespace>/<method>` endpoint of the usage report Remote. */
411
+ declare const USAGE_REPORT_ENDPOINT = "commandcode/report";
412
+ /**
413
+ * The strict result codec both halves attach to the descriptor. Hand-rolled:
414
+ * the client bundle may not require a schema library, and `TypertSchema` is
415
+ * deliberately minimal so one `parse` function satisfies it.
416
+ */
417
+ declare const usageReportSchema: TypertSchema<CommandCodeUsageReport>;
418
+ //#endregion
256
419
  //#region src/index.d.ts
257
420
  declare const name = "llm-commandcode";
258
421
  declare const inject: string[];
@@ -282,6 +445,13 @@ interface Config {
282
445
  requestTimeoutMs?: number;
283
446
  /** Milliseconds a stream may stall before being treated as a dead connection; defaults to 300s. */
284
447
  streamIdleTimeoutMs?: number;
448
+ /**
449
+ * Whether the model picker hides models above the account's subscription
450
+ * tier; defaults to true. The filter fails open (unknown plan, billing
451
+ * endpoint failure, or a positive on-demand credit balance all keep the
452
+ * full catalog visible). Set false to always list every model.
453
+ */
454
+ filterModelsByPlan?: boolean;
285
455
  }
286
456
  declare const Config: z<Config>;
287
457
  /** One resolution's complete request facts: connection plus credential reference. */
@@ -297,5 +467,5 @@ interface ResolvedCommandCodeOptions extends CommandCodeConnectionOptions {
297
467
  declare function resolveAdapterOptions(config: Config): ResolvedCommandCodeOptions;
298
468
  declare function apply(ctx: Context, config: Config): void;
299
469
  //#endregion
300
- export { COMMAND_CODE_CLI_VERSION, CommandCodeAdapter, type CommandCodeAdapterDeps, type CommandCodeCommandDeps, type CommandCodeConnectionOptions, type CommandCodeUsageReport, Config, DEFAULT_API_BASE, DEFAULT_GENERATE_MAX_TOKENS, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_MODELS_CACHE_PATH, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, KNOWN_DEALS, KNOWN_EFFORTS, KNOWN_IMAGE_MODELS, KNOWN_PLANS, KNOWN_THINKING_MODELS, PLAN_LABELS, PLAN_ORDER, PROVIDER, type ResolveAttachments, ResolvedCommandCodeOptions, apply, applyCommands, capabilityDescription, commandDefinition, compareByPlan, dealLabel, formatContext, inject, name, planLabel, projectSlugFromPath, resolveAdapterOptions, resolveAuthFileApiKey };
470
+ export { BILLING_ACCESS_TTL_MS, COMMAND_CODE_CLI_VERSION, CommandCodeAdapter, type CommandCodeAdapterDeps, type CommandCodeBillingAccess, type CommandCodeCommandDeps, type CommandCodeConnectionOptions, type CommandCodeUsageDeps, type CommandCodeUsageReport, CommandCodeUsageService, Config, DEFAULT_API_BASE, DEFAULT_GENERATE_MAX_TOKENS, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_MODELS_CACHE_PATH, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, KNOWN_DEALS, KNOWN_EFFORTS, KNOWN_IMAGE_MODELS, KNOWN_PEAK_PRICING, KNOWN_PLANS, KNOWN_SUBSCRIPTION_PLANS, KNOWN_THINKING_MODELS, PLAN_LABELS, PLAN_ORDER, PROVIDER, type ResolveAttachments, ResolvedCommandCodeOptions, USAGE_REPORT_ENDPOINT, apply, applyCommands, applyUsageRemote, capabilityDescription, commandDefinition, compareByPlan, dealLabel, formatContext, inject, modelVisibleInPlan, name, peakPricingLabel, peakPricingState, planLabel, projectSlugFromPath, resolveAdapterOptions, resolveAuthFileApiKey, subscriptionPlanInfo, usageReportSchema };
301
471
  //# sourceMappingURL=index.d.ts.map