@vibedev-si/dsh-vibedev 0.3.3 → 0.3.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/lib/pricing.d.ts CHANGED
@@ -5,6 +5,13 @@
5
5
  * output length plus the summed reference video length, rounded up once.
6
6
  * Estimates are for the user's information; the gateway's receipt is the charge.
7
7
  *
8
+ * Video models priced per video Token (`video_pricing`) are quoted by
9
+ * {@link quoteVideo}: the matching rule's per-second estimate times the output
10
+ * length plus every reference video's length, in exact decimals. The final
11
+ * charge is the provider's billable Tokens times the rule's Token price, so a
12
+ * Token price is never shown as an unconditional per-second price, never as
13
+ * 未定价 and never as free — and what cannot be estimated says so.
14
+ *
8
15
  * A model without a price is "not priced" (未定价), never free: only a price the
9
16
  * catalog states as zero is shown as ¥0.
10
17
  * @module dsh-vibedev/pricing
@@ -38,6 +45,7 @@ export declare function yuan(amount: number): string;
38
45
  export declare function unitSuffix(unit: PriceUnit, kind: MediaKind): Bilingual;
39
46
  /**
40
47
  * A one-line price for listings: `¥0.10 per image`, `¥0.99/s (720p)`; `not priced` without a price.
48
+ * A video Token price lists its rules (`视频 Token 计价:480p 无参考视频 ¥60.06/百万 Token(预计 ¥0.5819/秒)…`).
41
49
  * @param model - the model.
42
50
  * @param lang - the language.
43
51
  * @returns the price line.
@@ -83,3 +91,94 @@ export interface AudioQuote {
83
91
  * @returns the quote; `priced: false` (未定价) when the catalog gives no usable price.
84
92
  */
85
93
  export declare function quoteAudio(model: MediaModel, inputSeconds?: number): AudioQuote;
94
+ /** A video request to quote, before anything is uploaded or submitted. */
95
+ export interface VideoQuoteRequest {
96
+ /** The canonical model id or an alias. */
97
+ readonly model: string;
98
+ /** When absent and the catalog offers exactly one resolution for the model, that one. */
99
+ readonly resolution?: string;
100
+ /** The requested output length. */
101
+ readonly durationSeconds?: number;
102
+ readonly references?: {
103
+ /** One entry per reference video; an absent `durationSeconds` is unknown, not zero. */
104
+ readonly videos?: readonly {
105
+ readonly durationSeconds?: number;
106
+ }[];
107
+ /** Image references, first and last frames included. */
108
+ readonly images?: number;
109
+ /** Reference audios (generating audio is not a reference audio). */
110
+ readonly audios?: number;
111
+ };
112
+ }
113
+ /** The conditions of the rule a quote used. */
114
+ export interface VideoQuoteRule {
115
+ readonly resolution: string;
116
+ readonly referenceVideo?: boolean;
117
+ readonly referenceAudio?: boolean;
118
+ readonly referenceImage?: boolean;
119
+ }
120
+ /** Why a video request has no estimate. */
121
+ export type VideoQuoteReason = 'no-price' | 'unknown-schema' | 'invalid-pricing' | 'no-matching-rule' | 'ambiguous-rules' | 'missing-resolution' | 'missing-duration' | 'unknown-reference-duration' | 'no-estimated-price' | 'invalid-request';
122
+ /** An estimate under video Token pricing; the final charge is the actual video Tokens times the Token price. */
123
+ export interface VideoTokenEstimate {
124
+ readonly status: 'estimate';
125
+ readonly mode: 'video_token';
126
+ readonly model: string;
127
+ readonly currency: 'CNY';
128
+ /** Exact decimal, never rounded (`2.9095`); labels round half up to two decimals. */
129
+ readonly amountCny: string;
130
+ readonly estimatedPricePerSecondCny: number;
131
+ readonly pricePerMillionTokensCny: number;
132
+ readonly outputSeconds: number;
133
+ readonly referenceVideoSeconds: number;
134
+ readonly billedSeconds: number;
135
+ readonly rule: VideoQuoteRule;
136
+ readonly estimateOnly: true;
137
+ readonly finalBasis: 'provider_tokens';
138
+ /** `预计 ¥8.34 · 最终按实际视频 Token 结算`. */
139
+ readonly label: Bilingual;
140
+ /** `¥0.6952/秒 × (7 秒输出 + 5 秒参考视频),¥36.036/百万 Token`. */
141
+ readonly basis: Bilingual;
142
+ }
143
+ /** An estimate from a legacy `media_pricing` price (per second or per generation). */
144
+ export interface VideoLegacyEstimate {
145
+ readonly status: 'estimate';
146
+ readonly mode: 'legacy';
147
+ readonly model: string;
148
+ readonly currency: 'CNY';
149
+ readonly amountCny: string;
150
+ readonly label: Bilingual;
151
+ readonly basis: Bilingual;
152
+ }
153
+ /** No estimate, and why. Under Token pricing this is never "not priced" and never free. */
154
+ export interface VideoQuoteUnavailable {
155
+ readonly status: 'unavailable';
156
+ readonly mode: 'video_token' | 'legacy' | 'none';
157
+ readonly model: string;
158
+ readonly reason: VideoQuoteReason;
159
+ /** The matched rule's Token price, when a rule matched but the amount cannot be estimated. */
160
+ readonly pricePerMillionTokensCny?: number;
161
+ readonly label: Bilingual;
162
+ readonly basis: Bilingual;
163
+ }
164
+ /** What a video request is expected to cost. */
165
+ export type VideoQuote = VideoTokenEstimate | VideoLegacyEstimate | VideoQuoteUnavailable;
166
+ /**
167
+ * Quote a video request from the catalog alone: no upload, no submission.
168
+ *
169
+ * Video Token pricing: the unique most specific rule for the resolution and
170
+ * the presence of reference video, audio and images; its per-second estimate
171
+ * times the output length plus every reference video's length. A model whose
172
+ * `video_pricing` cannot be read gets no estimate and never falls back to its
173
+ * legacy price. Legacy models are quoted as {@link estimateVideo} always did.
174
+ * @param model - the resolved model.
175
+ * @param request - the request.
176
+ * @returns the quote.
177
+ */
178
+ export declare function quoteVideo(model: MediaModel, request: VideoQuoteRequest): VideoQuote;
179
+ /**
180
+ * The estimate a task records: the quote amount half up to two decimals.
181
+ * @param quote - the quote.
182
+ * @returns `8.34`, or undefined without an estimate.
183
+ */
184
+ export declare function quotedCny(quote: VideoQuote): string | undefined;
package/lib/service.d.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import type { AudioForm, AudioRequest } from './audio/request.js';
18
18
  import type { MediaModel } from './gateway/catalog.js';
19
- import type { AudioQuote } from './pricing.js';
19
+ import type { AudioQuote, VideoQuote, VideoQuoteRequest } from './pricing.js';
20
20
  import type { MediaRuntime } from './runtime.js';
21
21
  import type { TaskRecord, TaskStatus } from './tasks/store.js';
22
22
  import type { ImageRequest } from './tools/image.js';
@@ -57,14 +57,18 @@ export interface MediaTaskView {
57
57
  readonly code: string;
58
58
  readonly message: string;
59
59
  };
60
+ /** The gateway's estimate, as given (`3.98`). */
60
61
  readonly estimatedCny?: string;
62
+ /** Only when `settlement` is `settled`: the final charge, exactly as given (`3.98066354`). */
61
63
  readonly chargedCny?: string;
62
64
  /**
63
65
  * `pending`: the result is there, the charge is still being settled (it is
64
- * never generated again); `settled`: `chargedCny` is final.
66
+ * never generated again, and it is neither a failure nor free); `settled`: `chargedCny` is final.
65
67
  */
66
68
  readonly settlement?: 'pending' | 'settled';
67
- /** How it is billed: the unit, the unit price, and the billed length once known. */
69
+ /** Why the settlement is pending (`billing_pending_reason`), while it is. */
70
+ readonly settlementPendingReason?: string;
71
+ /** How it is billed: the unit, the unit price, and the billed length or video Tokens once known. */
68
72
  readonly billing?: TaskRecord['billing'];
69
73
  readonly createdAt: number;
70
74
  readonly updatedAt: number;
@@ -95,6 +99,17 @@ export declare class MediaHostService {
95
99
  * @returns the quote.
96
100
  */
97
101
  audioPrice(model: string, signal?: AbortSignal): Promise<AudioQuote>;
102
+ /**
103
+ * What a video request is expected to cost, from the (cached) catalog alone:
104
+ * nothing is uploaded, submitted or recorded. Video Token pricing gives the
105
+ * matching rule's estimate (`预计 ¥8.34 · 最终按实际视频 Token 结算`) or says why there
106
+ * is none; legacy prices are quoted as before. A model the account does not
107
+ * have is an `invalid-request`; a catalog failure (no sign-in, no network) is thrown.
108
+ * @param request - the model (id or alias), resolution, duration and references.
109
+ * @param signal - cancels the catalog request.
110
+ * @returns the quote, under the model's canonical id.
111
+ */
112
+ videoQuote(request: VideoQuoteRequest, signal?: AbortSignal): Promise<VideoQuote>;
98
113
  /**
99
114
  * Generate images now and save them.
100
115
  * @param request - what to generate.
@@ -4,6 +4,11 @@
4
4
  * receipt and `asset`), and `POST /v1/audio/generations` and
5
5
  * `GET /v1/audio/generations/{id}` (`outputs[]`). Unknown statuses count as
6
6
  * still running; only an explicit terminal status ends a task.
7
+ *
8
+ * Both kinds carry the same settlement facts in `effective`: `billing_status`
9
+ * (`pending`/`settled`), `billing_pending_reason`, `charged_cny` (kept as the
10
+ * exact string given), `billed_tokens` and `estimated_cny`. A completed task
11
+ * whose billing is pending has its result; only the charge is still to come.
7
12
  * @module dsh-vibedev/tasks/remote
8
13
  */
9
14
  /** One produced file as the gateway describes it. */
@@ -36,10 +41,23 @@ export interface RemoteTask {
36
41
  };
37
42
  /** Estimated price at submission (CNY, two decimals). */
38
43
  readonly estimatedCny?: string;
39
- /** Settled charge (CNY); absent until the gateway settles, which is not the same as free. */
44
+ /**
45
+ * Charge (CNY) exactly as the gateway wrote it (`3.98066354`); absent until the gateway
46
+ * reports one, which is not the same as free. Final only while `settlement` is not `pending`.
47
+ */
40
48
  readonly chargedCny?: string;
41
- /** Whether the charge of a finished task has settled; absent when the gateway does not say. */
49
+ /**
50
+ * Whether the charge of a finished task has settled: `effective.billing_status`,
51
+ * `settlement_state`/`settlement_status` or the status `settlement_pending`. An explicit
52
+ * pending wins over anything else in the same answer. Absent when no known word is given.
53
+ */
42
54
  readonly settlement?: 'pending' | 'settled';
55
+ /** The answer carried a billing or settlement status at all (older gateways send none). */
56
+ readonly billingStatusReported: boolean;
57
+ /** Why the settlement is pending (`billing_pending_reason`). */
58
+ readonly settlementPendingReason?: string;
59
+ /** The billable video Tokens the charge is based on (`billed_tokens`). */
60
+ readonly billedTokens?: number;
43
61
  /** The billed original length of the whole task, in seconds (speech). */
44
62
  readonly billedOriginalSeconds?: number;
45
63
  /** The billed input length, in minutes (transcription). */
@@ -60,21 +60,27 @@ export interface TaskRecord {
60
60
  readonly code: string;
61
61
  readonly message: string;
62
62
  };
63
+ /** The gateway's estimate, as given (`3.98`). */
63
64
  readonly estimatedCny?: string;
65
+ /** The final charge, exactly as given (`3.98066354`); recorded only once `settlement` is `settled`. */
64
66
  readonly chargedCny?: string;
65
67
  /**
66
68
  * Whether the charge of a finished task has settled. `pending`: the result is
67
69
  * saved and is never generated again; only the charge is still to come.
68
70
  */
69
71
  readonly settlement?: 'pending' | 'settled';
72
+ /** Why the settlement is pending (`billing_pending_reason`), while it is. */
73
+ readonly settlementPendingReason?: string;
70
74
  /** What an audio task makes (music, podcast or speech). */
71
75
  readonly audioKind?: string;
72
- /** How the task is billed, and the billed length once the gateway reports it. */
76
+ /** How the task is billed, and the billed quantity once the gateway reports it. */
73
77
  readonly billing?: {
74
78
  readonly unit?: string;
75
79
  readonly unitPriceCny?: string;
76
80
  readonly originalSeconds?: number;
77
81
  readonly minutes?: number;
82
+ /** Billable video Tokens (`billed_tokens`). */
83
+ readonly tokens?: number;
78
84
  };
79
85
  readonly finishedAt?: number;
80
86
  }
@@ -145,7 +145,16 @@ export declare class TaskTracker {
145
145
  * @returns how long to wait before the next try, or undefined once the task has been ended.
146
146
  */
147
147
  private afterFailure;
148
- /** The money and billing facts of a gateway answer, merged into what the record already knows. */
148
+ /**
149
+ * The money and billing facts of a gateway answer, merged into what the record already knows.
150
+ *
151
+ * An explicit status decides: `pending` records no charge (a charge reported
152
+ * alongside it is not final, and the task is not free either) and drops one
153
+ * recorded earlier; `settled` records the charge exactly as given. Only an
154
+ * answer that carries no billing or settlement status at all — older gateways —
155
+ * lets a charge imply `settled`. An answer that says nothing leaves what the
156
+ * record holds, so a settled task is never downgraded by it.
157
+ */
149
158
  private moneyOf;
150
159
  /** Record what the gateway says about a task; save the outputs of a finished one. */
151
160
  private apply;
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
9
9
  import type { MediaModel, VideoInput } from '../gateway/catalog.js';
10
+ import type { VideoQuote } from '../pricing.js';
10
11
  import type { MediaCall, MediaRuntime } from '../runtime.js';
11
12
  import type { TaskRecord } from '../tasks/store.js';
12
13
  import type { VideoPlan, VideoRequestOptions } from '../video/plan.js';
@@ -24,6 +25,8 @@ export interface PreparedVideo {
24
25
  readonly inputs: readonly VideoInput[];
25
26
  /** `5 s, 16:9, 720p`, for messages. */
26
27
  readonly shape: string;
28
+ /** What it was confirmed at: the same quote `vibedevMedia.videoQuote` gives. */
29
+ readonly quote: VideoQuote;
27
30
  }
28
31
  /**
29
32
  * Everything before a video submission: choose a model that can serve the
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Exact decimal arithmetic for money. A value is a scaled integer
3
+ * (`units × 10^-scale`, BigInt), so `0.5819 × 5` is `2.9095` and not
4
+ * `2.9094999999999995`. Catalog prices arrive as JSON numbers; a number is read
5
+ * as the decimal it is written as (its shortest round-trip form), which is the
6
+ * literal the gateway sent.
7
+ * @module dsh-vibedev/util/decimal
8
+ */
9
+ /** A decimal number: `units × 10^-scale`. */
10
+ export interface Decimal {
11
+ readonly units: bigint;
12
+ readonly scale: number;
13
+ }
14
+ /**
15
+ * The exact decimal of a finite number (as written by `String`) or a decimal string.
16
+ * @param value - the number or text, such as `0.5819`, `1e-7` or `"3.98066354"`.
17
+ * @returns the decimal.
18
+ * @throws RangeError for anything that is not a finite decimal.
19
+ */
20
+ export declare function decimal(value: number | string): Decimal;
21
+ /** Zero. */
22
+ export declare const ZERO: Decimal;
23
+ /**
24
+ * The sum of two decimals.
25
+ * @param a - the first.
26
+ * @param b - the second.
27
+ * @returns `a + b`, exactly.
28
+ */
29
+ export declare function add(a: Decimal, b: Decimal): Decimal;
30
+ /**
31
+ * The product of two decimals.
32
+ * @param a - the first.
33
+ * @param b - the second.
34
+ * @returns `a × b`, exactly.
35
+ */
36
+ export declare function multiply(a: Decimal, b: Decimal): Decimal;
37
+ /**
38
+ * Round half up (away from zero) to a number of decimals.
39
+ * @param value - the decimal.
40
+ * @param places - decimals to keep.
41
+ * @returns the rounded decimal.
42
+ */
43
+ export declare function roundHalfUp(value: Decimal, places: number): Decimal;
44
+ /**
45
+ * Round up to a whole number (towards positive infinity).
46
+ * @param value - the decimal.
47
+ * @returns the smallest whole number not below it.
48
+ */
49
+ export declare function ceil(value: Decimal): Decimal;
50
+ /**
51
+ * Exact text without trailing zeros (`2.9095`, `5`), padded to at least `minFraction` decimals.
52
+ * @param value - the decimal.
53
+ * @param minFraction - decimals always shown (`5.00` with 2).
54
+ * @returns the text.
55
+ */
56
+ export declare function format(value: Decimal, minFraction?: number): string;
57
+ /**
58
+ * The nearest number, for fields typed as numbers (never for money amounts).
59
+ * @param value - the decimal.
60
+ * @returns the number.
61
+ */
62
+ export declare function toNumber(value: Decimal): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibedev-si/dsh-vibedev",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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",