@vibedev-si/dsh-vibedev 0.3.3 → 0.3.5

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.
@@ -5,11 +5,13 @@
5
5
  *
6
6
  * - `GET /api/dsh-vibedev/account` — where the credential comes from (the
7
7
  * app's account, the plugin's own sign-in, a development key, or none), who
8
- * is signed in, the balance, a sign-in waiting for the browser, and how many
9
- * VibeDev models the pickers list; `?fresh=1` reads the balance again;
10
- * `?since=<revision>` holds the request until the person or the balance
11
- * changes (a charge is read again right after it ends), so the pages show a
12
- * new balance within seconds instead of on their next minute poll;
8
+ * is signed in, the balance (what can be spent, and what running tasks hold),
9
+ * when it was read, a sign-in waiting for the browser, and how many VibeDev
10
+ * models the pickers list; `?fresh=1` reads the balance again (a read that
11
+ * fails keeps the last balance, says when it was read, and says the read
12
+ * failed); `?since=<revision>` holds the request until the person or the
13
+ * balance changes (a charge is read again right after it ends), so the pages
14
+ * show a new balance within seconds instead of on their next minute poll;
13
15
  * - `POST /api/dsh-vibedev/account/sign-in` — `{ open?: boolean }`: start the
14
16
  * plugin's own sign-in; answers the authorization link (`open: false` leaves
15
17
  * opening it to the page);
@@ -36,11 +38,20 @@ export interface AccountView {
36
38
  readonly email?: string;
37
39
  readonly nickname?: string;
38
40
  };
39
- /** The balance, when it could be read. */
41
+ /**
42
+ * The balance, when it could be read: `amount` is what can be spent (the gateway's `balance`), `frozen` what
43
+ * running tasks hold (`frozen_balance`: a video or batch-image task moves a hold there when it is submitted and
44
+ * settles it when it ends; absent when the gateway does not say), both in `currency`.
45
+ */
40
46
  readonly balance?: {
41
47
  readonly amount: string;
42
48
  readonly currency: string;
49
+ readonly frozen?: string;
43
50
  };
51
+ /** When the balance shown was read from the gateway (epoch ms): the last read that succeeded. */
52
+ readonly readAt?: number;
53
+ /** The latest read of the balance failed (epoch ms), after `readAt`: the balance shown, if any, is the older one. */
54
+ readonly readFailedAt?: number;
44
55
  /** A sign-in waiting for the browser. */
45
56
  readonly pending?: {
46
57
  readonly url: string;
@@ -102,6 +113,10 @@ export declare class AccountService {
102
113
  private epoch;
103
114
  /** When the last read after a charge started, to space them out. */
104
115
  private lastSpendReadAt;
116
+ /** The last read that succeeded, kept for the pages while a later read fails. */
117
+ private lastGood;
118
+ /** The latest read failed, after the last one that succeeded. */
119
+ private failure;
105
120
  /**
106
121
  * @param options - origin, credential chain, the plugin's sign-in and the route's model state.
107
122
  */
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The network latency from this Host to the VibeDev gateway, for the balance
3
+ * card (`POST /api/dsh-vibedev/latency`; `?fresh=1` measures again within the
4
+ * minute a measurement is kept).
5
+ *
6
+ * It times `GET {origin}/health` — no credential, no database on the gateway,
7
+ * and left out of its access log — from the Host process, over the same fetch
8
+ * (and so the same network path and proxy settings) the plugin's gateway and
9
+ * model requests use: one request first, untimed, to set up the connection
10
+ * (DNS, TCP, TLS), then four in a row on that connection, each given 5 s. The
11
+ * answer is their median, each of them, the first request's time and when it
12
+ * ended; or why it stopped (no answer in time, no connection, an HTTP status).
13
+ * This is how far away the gateway is on the network, not how fast a model is.
14
+ *
15
+ * One measurement runs at a time, and a result is reused for a minute.
16
+ * @module dsh-vibedev/account/latency
17
+ */
18
+ import type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';
19
+ /** Path of the latency route. */
20
+ export declare const LATENCY_ROUTE = "/api/dsh-vibedev/latency";
21
+ /** Why a measurement stopped. */
22
+ export type LatencyErrorKind = 'timeout' | 'network' | 'http';
23
+ /** One measurement. Times are whole milliseconds. */
24
+ export interface LatencyResult {
25
+ /** Median of the timed requests, when every request answered. */
26
+ readonly medianMs?: number;
27
+ /** Each timed request, in order (those that answered before one failed, on a failure). */
28
+ readonly samplesMs: readonly number[];
29
+ /** The first, untimed request, connection setup included; absent when it failed. */
30
+ readonly warmupMs?: number;
31
+ /** When the measurement ended (epoch ms). */
32
+ readonly measuredAt: number;
33
+ /** Why it stopped: no answer within 5 s, no connection (or a redirect), or an HTTP status other than 2xx. */
34
+ readonly error?: {
35
+ readonly kind: LatencyErrorKind;
36
+ readonly status?: number;
37
+ };
38
+ }
39
+ /** What the probe needs. */
40
+ export interface LatencyProbeOptions {
41
+ readonly origin: string;
42
+ readonly userAgent: string;
43
+ /** The fetch the plugin's gateway requests use (the global one unless a test passes its own). */
44
+ readonly fetch?: typeof globalThis.fetch;
45
+ /** Wall clock (epoch ms), for `measuredAt` and the minute a result is kept. */
46
+ readonly now?: () => number;
47
+ /** Monotonic clock (ms) one request is timed with. */
48
+ readonly clock?: () => number;
49
+ /** The per-request deadline (a test seam for `AbortSignal.timeout`). */
50
+ readonly timeout?: (ms: number) => AbortSignal;
51
+ /** The untimed pause before each timed request (a test seam). */
52
+ readonly pause?: () => Promise<void>;
53
+ }
54
+ /** Measures the network latency to the gateway. */
55
+ export declare class LatencyProbe {
56
+ private readonly options;
57
+ private last;
58
+ private running;
59
+ private readonly now;
60
+ private readonly clock;
61
+ /**
62
+ * @param options - the gateway origin, the plugin's user agent, and the fetch and clock seams.
63
+ */
64
+ constructor(options: LatencyProbeOptions);
65
+ /**
66
+ * The latency, measured now or within the last minute. One measurement runs at a time: a call while one runs
67
+ * shares it.
68
+ * @param fresh - measure again even when the last result is younger than a minute.
69
+ * @returns the result (a failure is a result too, with its error).
70
+ */
71
+ measure(fresh?: boolean): Promise<LatencyResult>;
72
+ private run;
73
+ /** One `GET /health`, timed until its body has been read (which also lets the connection be reused). */
74
+ private once;
75
+ }
76
+ /**
77
+ * The latency route.
78
+ * @param probe - the probe.
79
+ * @returns routes for the client connection.
80
+ */
81
+ export declare function latencyRoutes(probe: LatencyProbe): ConnectionFetchRoute[];
@@ -108,6 +108,37 @@ export interface MediaPricing {
108
108
  readonly amount: number;
109
109
  };
110
110
  }
111
+ /**
112
+ * One video Token price rule (`video_pricing.rules[]`). A condition that is
113
+ * absent matches anything; `false` means the request must carry none of that
114
+ * reference, `true` at least one. First and last frames count as images.
115
+ */
116
+ export interface VideoTokenRule {
117
+ /** The exact resolution tier, such as `480p`. */
118
+ readonly resolution: string;
119
+ readonly referenceVideo?: boolean;
120
+ readonly referenceAudio?: boolean;
121
+ readonly referenceImage?: boolean;
122
+ /** The final selling price: CNY per 1,000,000 billable video Tokens (>= 0). */
123
+ readonly pricePerMillionTokensCny: number;
124
+ /** The provisional estimate per second of output plus reference video; absent is unknown, never zero. */
125
+ readonly estimatedPricePerSecondCny?: number;
126
+ }
127
+ /**
128
+ * A video model's Token pricing (`video_pricing`, schema 1): the charge is the
129
+ * provider's billable video Tokens times the matching rule's price; the
130
+ * per-second figure only estimates it before the task runs.
131
+ */
132
+ export interface VideoTokenPricing {
133
+ readonly schemaVersion: 1;
134
+ readonly currency: 'CNY';
135
+ readonly finalBasis: 'provider_tokens';
136
+ readonly estimateBasis: 'output_plus_reference_video_seconds';
137
+ readonly estimateOnly: boolean;
138
+ readonly rules: readonly VideoTokenRule[];
139
+ }
140
+ /** Why a model's `video_pricing` cannot be used: a schema this plugin does not read, or a malformed object. */
141
+ export type VideoPricingIssue = 'unknown-schema' | 'invalid';
111
142
  /** What an audio model does, as the catalog declares it (`audio.generation_kind`). */
112
143
  export declare const AUDIO_GENERATION_KINDS: readonly ["music", "podcast", "speech", "transcription"];
113
144
  export type AudioGenerationKind = typeof AUDIO_GENERATION_KINDS[number];
@@ -172,6 +203,13 @@ export interface MediaModel {
172
203
  readonly endpoints: readonly string[];
173
204
  readonly inputModalities: readonly string[];
174
205
  readonly pricing?: MediaPricing;
206
+ /** Video Token pricing (`video_pricing`); a model with it is never quoted from `pricing`. */
207
+ readonly videoPricing?: VideoTokenPricing;
208
+ /**
209
+ * Set instead of `videoPricing` when the catalog sends `video_pricing` this plugin
210
+ * cannot use. Such a model has no estimate at all: it never falls back to `pricing`.
211
+ */
212
+ readonly videoPricingIssue?: VideoPricingIssue;
175
213
  readonly video?: VideoCapabilities;
176
214
  readonly audio?: AudioCapabilities;
177
215
  }
@@ -195,6 +233,16 @@ export declare function effectiveVideoModes(video: VideoCapabilities): Partial<R
195
233
  * @returns the declared capabilities; `generationKind` is absent unless declared.
196
234
  */
197
235
  export declare function parseAudioCapabilities(raw: Json): AudioCapabilities;
236
+ /**
237
+ * Parse `video_pricing`. Every rule is checked: one unreadable rule makes the
238
+ * whole object unusable, since dropping it could make another rule look unique.
239
+ * @param value - the entry's `video_pricing`.
240
+ * @returns the pricing, the reason it cannot be used, or nothing when the entry has none.
241
+ */
242
+ export declare function parseVideoPricing(value: unknown): {
243
+ videoPricing?: VideoTokenPricing;
244
+ videoPricingIssue?: VideoPricingIssue;
245
+ };
198
246
  /**
199
247
  * Parse a `/v1/models` body into its media models.
200
248
  * @param body - `{data:[...]}` or a bare array.
package/lib/index.d.ts CHANGED
@@ -26,13 +26,15 @@ export { MediaError } from './gateway/errors.js';
26
26
  export { MediaHostService } from './service.js';
27
27
  export type { HostTarget, MediaOutputView, MediaTaskView } from './service.js';
28
28
  export type { AudioForm, AudioFormField, AudioMakeKind, AudioRequest } from './audio/request.js';
29
- export type { AudioQuote } from './pricing.js';
29
+ export type { AudioQuote, Bilingual, VideoLegacyEstimate, VideoQuote, VideoQuoteReason, VideoQuoteRequest, VideoQuoteRule, VideoQuoteUnavailable, VideoTokenEstimate, } from './pricing.js';
30
30
  export type { ImageRequest } from './tools/image.js';
31
31
  export type { VideoRequest } from './tools/video.js';
32
32
  export { parseMediaCatalog } from './gateway/catalog.js';
33
- export type { AudioCapabilities, AudioGenerationKind, MediaModel, PriceUnit, VideoCapabilities, VideoMode } from './gateway/catalog.js';
33
+ export type { AudioCapabilities, AudioGenerationKind, MediaModel, PriceUnit, VideoCapabilities, VideoMode, VideoPricingIssue, VideoTokenPricing, VideoTokenRule, } from './gateway/catalog.js';
34
34
  export { ACCOUNT_ROUTE_PREFIX, AccountService } from './account/index.js';
35
35
  export type { AccountSource, AccountView } from './account/index.js';
36
+ export { LATENCY_ROUTE } from './account/latency.js';
37
+ export type { LatencyErrorKind, LatencyResult } from './account/latency.js';
36
38
  export { GATEWAY_SEARCH_PROVIDER_ID as SEARCH_PROVIDER_ID } from './search/provider.js';
37
39
  export { INSUFFICIENT_BALANCE_CODE, SIGN_IN_REQUIRED_CODE, VIBEDEV_ROUTE } from './llm/index.js';
38
40
  /** The package version, sent in the `User-Agent` the gateway attributes plugin traffic by. */