@vibedev-si/dsh-vibedev 0.8.1 → 0.9.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.
@@ -28,6 +28,7 @@ import { LlmAdapter } from '@deepseek-ai/dsh-llm';
28
28
  import type { GenerateOptions, ImageAttachmentAccess, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, PreparedAdapterCall, ResolvedRetryPolicy, StreamChunk } from '@deepseek-ai/dsh-llm';
29
29
  import type { AttachmentStore, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
30
30
  import type { GatewayModel } from './catalog.js';
31
+ import { type ActivePromotion } from './promotions.js';
31
32
  import { type ClaudeCacheTtl } from './cache-ttl.js';
32
33
  /** The credential for one request. */
33
34
  export interface GatewayCredential {
@@ -97,6 +98,12 @@ export interface GatewayAdapterOptions {
97
98
  }) => void;
98
99
  /** A request reached the gateway and ended, however it ended: it may have been charged. */
99
100
  readonly onRequestEnded?: () => void;
101
+ /**
102
+ * The promotions the gateway currently runs for this account's price group, as the
103
+ * model list labels them. Absent, slow or failing means no label and never an error:
104
+ * the picker keeps working offline exactly as it did before.
105
+ */
106
+ readonly promotions?: () => Promise<readonly ActivePromotion[]>;
100
107
  }
101
108
  /**
102
109
  * The gateway as an LLM adapter. Each operation reads the current catalog, so a refresh reaches
@@ -113,6 +120,8 @@ export declare class GatewayAdapter extends LlmAdapter {
113
120
  providerInfo(provider: string): LlmProviderInfo;
114
121
  providerRetryPolicy(provider: string): ResolvedRetryPolicy | undefined;
115
122
  listModels(provider: string): Promise<readonly LlmModelInfo[]>;
123
+ /** The promotions keyed by model id, or none when they cannot be read. */
124
+ private promotions;
116
125
  resolveModel(provider: string, model: string, _signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
117
126
  private modelInfo;
118
127
  prepareCall(provider: string, model: string, _signal?: AbortSignal): Promise<PreparedAdapterCall>;
@@ -23,6 +23,7 @@ import type { Context } from '@deepseek-ai/cordis';
23
23
  import type { GatewayCredential } from './adapter.js';
24
24
  import type { GatewayModel } from './catalog.js';
25
25
  import type { ClaudeCacheTtl } from './cache-ttl.js';
26
+ import type { ActivePromotion } from './promotions.js';
26
27
  export { GatewayAdapter, INSUFFICIENT_BALANCE_CODE, SIGN_IN_REQUIRED_CODE } from './adapter.js';
27
28
  export type { GatewayAdapterOptions, GatewayCredential } from './adapter.js';
28
29
  export { parseCatalog } from './catalog.js';
@@ -56,6 +57,11 @@ export interface GatewayModelsOptions {
56
57
  readonly claudeCacheTtl?: () => ClaudeCacheTtl;
57
58
  /** A model request that may have been charged ended (the account reads the balance again). */
58
59
  readonly onRequestEnded?: () => void;
60
+ /**
61
+ * The gateway's current 「限时特惠」 promotions for this account's price group, which
62
+ * label the models they cover. Optional: without it, or when it fails, no model is labelled.
63
+ */
64
+ readonly promotions?: () => Promise<readonly ActivePromotion[]>;
59
65
  }
60
66
  /** The route's live state, for status lines and tests. */
61
67
  export interface GatewayModels {
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The gateway's 「模型限时特惠」 list, read from the public
3
+ * `GET /api/v1/model-plaza/promotions` and narrowed to the account's own
4
+ * pricing group.
5
+ *
6
+ * The gateway answers every visitor with the same configuration and leaves the
7
+ * business rules to the backend: a promotion applies to the groups it names, and
8
+ * the discount itself is granted by the gateway only for the managed keys it
9
+ * hosts. This module therefore only decides *which* label the app may show:
10
+ *
11
+ * - nothing is shown before the account's price group is known, so a signed-out
12
+ * app never advertises a promotion it cannot grant;
13
+ * - `group_ids` must name that group, and the activity window is read from the
14
+ * response (`starts_at`/`ends_at`), never from a constant here;
15
+ * - a failed, slow or malformed read hides the label instead of failing the
16
+ * model list, which is what keeps the picker working offline.
17
+ *
18
+ * A label is presentation only: no price is computed from it, and the usage
19
+ * records carry the gateway's own `promotion_discount`.
20
+ *
21
+ * @module dsh-vibedev/llm/promotions
22
+ */
23
+ import type { LlmModelBadge } from '@deepseek-ai/dsh-llm';
24
+ import type { GatewayHttp } from '../gateway/http.js';
25
+ /** Where the gateway publishes the promotions; public, no credential needed. */
26
+ export declare const PROMOTIONS_PATH = "/api/v1/model-plaza/promotions";
27
+ /** The catalog that names the account's own price group. */
28
+ export declare const PRICE_CONTEXT_PATH = "/v1/account/model-plaza";
29
+ /** How long one answer stays usable, as the product requires. */
30
+ export declare const PROMOTION_CACHE_MS: number;
31
+ /** How long a failed read stays quiet before the next attempt. */
32
+ export declare const PROMOTION_FAILURE_TTL_MS = 60000;
33
+ /** The label when the gateway names none. */
34
+ export declare const DEFAULT_PROMOTION_BADGE = "\u9650\u65F6\u7279\u60E0";
35
+ /** The same label for an English surface. */
36
+ export declare const DEFAULT_PROMOTION_BADGE_EN = "Limited-time offer";
37
+ /** One spending tier: from `prev_spend_min` on, `discount_rate` applies for that day. */
38
+ export interface PromotionTier {
39
+ readonly prevSpendMin: number;
40
+ readonly discountRate: number;
41
+ }
42
+ /** One promotion that currently applies to the account's price group. */
43
+ export interface ActivePromotion {
44
+ /** The model id the label belongs to; matched exactly, never by prefix. */
45
+ readonly model: string;
46
+ readonly badge: string;
47
+ /** The gateway's own sentence describing the activity. */
48
+ readonly description: string;
49
+ /** Yuan of discounted spend allowed per day, when the activity caps it. */
50
+ readonly dailyCap?: number;
51
+ /** The activity window exactly as the gateway stated it. */
52
+ readonly startsAt: string;
53
+ readonly endsAt: string;
54
+ readonly tiers: readonly PromotionTier[];
55
+ }
56
+ /** A promotion as read, with the facts needed to decide whether it applies. */
57
+ interface ParsedPromotion extends ActivePromotion {
58
+ readonly groupIds: readonly number[];
59
+ readonly startsAtMs: number;
60
+ readonly endsAtMs: number;
61
+ }
62
+ export interface PromotionServiceOptions {
63
+ readonly http: GatewayHttp;
64
+ /** Clock, for tests and for the activity window. */
65
+ readonly now?: () => number;
66
+ readonly cacheMs?: number;
67
+ readonly failureTtlMs?: number;
68
+ readonly timeoutMs?: number;
69
+ }
70
+ /**
71
+ * One entry of the public list, or undefined when it cannot be shown safely.
72
+ * @param value - one `data[]` entry of the gateway answer.
73
+ * @returns the promotion with its window resolved, or undefined.
74
+ */
75
+ export declare function parsePromotion(value: unknown): ParsedPromotion | undefined;
76
+ /** The selector label for one promotion, with an English surface covered too. */
77
+ export declare function promotionBadge(promotion: ActivePromotion): LlmModelBadge;
78
+ /**
79
+ * Reads the promotions, narrows them to the account's price group and answers
80
+ * from a five-minute cache. Every failure answers "none", never an error.
81
+ */
82
+ export declare class PromotionService {
83
+ private readonly options;
84
+ private value;
85
+ private group;
86
+ private loadedAt;
87
+ private failedAt;
88
+ private inflight;
89
+ private readonly now;
90
+ private readonly cacheMs;
91
+ private readonly failureTtlMs;
92
+ private readonly timeoutMs;
93
+ constructor(options: PromotionServiceOptions);
94
+ /** The last resolved promotions; empty until a read succeeds. */
95
+ snapshot(): readonly ActivePromotion[];
96
+ /** The price group the last successful read used, when it knew one. */
97
+ snapshotGroup(): number | undefined;
98
+ /**
99
+ * Forget what was read, because the account it was read for changed. The next
100
+ * listing reads again for the group that account belongs to.
101
+ */
102
+ reset(): void;
103
+ /** Start the first read without waiting for anyone who lists models. */
104
+ warm(): void;
105
+ /**
106
+ * The promotions that currently apply, from the cache when it is fresh.
107
+ * @returns the applicable promotions, or none when they cannot be read.
108
+ */
109
+ current(): Promise<readonly ActivePromotion[]>;
110
+ /**
111
+ * Like {@link current}, but a read that has not finished in time answers from
112
+ * the last snapshot, so a listing is never held up by a slow gateway.
113
+ * @param ms - how long a caller is willing to wait.
114
+ * @returns the promotions, or the last known ones.
115
+ */
116
+ currentWithin(ms: number): Promise<readonly ActivePromotion[]>;
117
+ /** One read: the account's group, the public list, then the activity window. */
118
+ private load;
119
+ /** The pricing group the account center already prices this account with. */
120
+ private priceGroup;
121
+ /** The public list. `anonymous` keeps a signed-out or broken sign-in from changing the answer. */
122
+ private list;
123
+ }
124
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibedev-si/dsh-vibedev",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "VibeDev 账号与模型:在 DeepSeek Harness 里登录 VibeDev,与 DeepSeek 账号并存,使用 VibeDev 网关的模型(Claude、GPT 等),并生成图片、视频、音乐和播客 · VibeDev account and models for DeepSeek Harness: sign in to VibeDev next to the DeepSeek account and use the VibeDev gateway's models (Claude, GPT and more), plus image, video, music and podcast generation",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",