@vibedev-si/dsh-vibedev 0.3.11 → 0.5.2

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.
Files changed (51) hide show
  1. package/README.md +193 -10
  2. package/THIRD-PARTY-NOTICES.txt +1 -1
  3. package/client/client.account-center.js +13555 -0
  4. package/client/client.js +3503 -878
  5. package/cordis.patch.yml +5 -0
  6. package/lib/account/center-business-contract.d.ts +22 -0
  7. package/lib/account/center-business.d.ts +6 -0
  8. package/lib/account/center-contract.d.ts +12 -0
  9. package/lib/account/center-monitor-contract.d.ts +10 -0
  10. package/lib/account/center-price-contract.d.ts +5 -0
  11. package/lib/account/center.d.ts +7 -0
  12. package/lib/account/index.d.ts +14 -0
  13. package/lib/{anthropic-messages-BgIfgjNt.js → anthropic-messages-QcnVMGaA.js} +11 -11
  14. package/lib/contract-v1.types.d.ts +134 -0
  15. package/lib/contracts.d.ts +34 -0
  16. package/lib/fetch/host-web.d.ts +34 -0
  17. package/lib/fetch/provider.d.ts +125 -0
  18. package/lib/fetch/wiring.d.ts +124 -0
  19. package/lib/gateway/errors.d.ts +29 -1
  20. package/lib/gateway/http.d.ts +24 -0
  21. package/lib/host-locales.d.ts +4 -0
  22. package/lib/index.d.ts +23 -0
  23. package/lib/index.js +3630 -505
  24. package/lib/{node-D58f7Ea6.js → node-CcLPV4RA.js} +4 -4
  25. package/lib/{node-Br-0fshF.js → node-vkDR3GtK.js} +2 -2
  26. package/lib/pricing.d.ts +21 -1
  27. package/lib/search/provider.d.ts +28 -5
  28. package/lib/service.d.ts +36 -9
  29. package/lib/tasks/remote.d.ts +4 -4
  30. package/lib/tasks/store.d.ts +54 -9
  31. package/lib/tasks/tracker.d.ts +45 -45
  32. package/lib/tools/image.d.ts +1 -0
  33. package/lib/tools/video.d.ts +3 -0
  34. package/lib/util/files.d.ts +2 -0
  35. package/locale/en.json +13 -0
  36. package/locale/zh.json +13 -0
  37. package/node_modules/@vibedev-si/dsh-ecosystem/LICENSE +22 -0
  38. package/node_modules/@vibedev-si/dsh-ecosystem/README.md +154 -0
  39. package/node_modules/@vibedev-si/dsh-ecosystem/catalog/catalog.json +167 -0
  40. package/node_modules/@vibedev-si/dsh-ecosystem/catalog-updates.js +326 -0
  41. package/node_modules/@vibedev-si/dsh-ecosystem/catalog-validator.js +263 -0
  42. package/node_modules/@vibedev-si/dsh-ecosystem/client.js +2816 -0
  43. package/node_modules/@vibedev-si/dsh-ecosystem/cordis.patch.yml +5 -0
  44. package/node_modules/@vibedev-si/dsh-ecosystem/icon.svg +5 -0
  45. package/node_modules/@vibedev-si/dsh-ecosystem/index.js +169 -0
  46. package/node_modules/@vibedev-si/dsh-ecosystem/locale/en.json +6 -0
  47. package/node_modules/@vibedev-si/dsh-ecosystem/locale/zh.json +6 -0
  48. package/node_modules/@vibedev-si/dsh-ecosystem/package.json +75 -0
  49. package/node_modules/@vibedev-si/dsh-ecosystem/remote-catalog.js +212 -0
  50. package/package.json +41 -24
  51. package/scripts/verify-fetch-joint.mjs +72 -0
@@ -1,9 +1,9 @@
1
- import { a as path$1, n as crypto$1, o as stream, r as fs$3, s as util, t as child_process } from "./node-Br-0fshF.js";
2
- import { a as checkMemorySyncInterval, c as decodeUTF8, d as AnthropicError, f as __classPrivateFieldGet, l as encodeUTF8, n as promiseWithResolvers, o as isStatus, p as __classPrivateFieldSet, s as loggerFor, u as ToolError } from "./anthropic-messages-BgIfgjNt.js";
1
+ import { a as path$1, n as crypto$1, o as stream, r as fs$3, s as util, t as child_process } from "./node-vkDR3GtK.js";
2
+ import { a as checkMemorySyncInterval, c as decodeUTF8, d as AnthropicError, f as __classPrivateFieldGet, l as encodeUTF8, n as promiseWithResolvers, o as isStatus, p as __classPrivateFieldSet, s as loggerFor, u as ToolError } from "./anthropic-messages-QcnVMGaA.js";
3
3
  import * as fssync from "node:fs";
4
+ import * as crypto from "node:crypto";
4
5
  import * as path from "node:path";
5
6
  import * as fs from "node:fs/promises";
6
- import * as crypto from "node:crypto";
7
7
  import * as cp from "node:child_process";
8
8
  import * as readline from "node:readline";
9
9
  //#region node_modules/@anthropic-ai/sdk/helpers/beta/json-schema.mjs
@@ -2400,4 +2400,4 @@ async function findRg() {
2400
2400
  //#endregion
2401
2401
  export { MEMORY_FLUSH_TIMEOUT_MS, SessionMemoryError, SessionMemoryStores, betaAgentToolset20260401, setupSkills };
2402
2402
 
2403
- //# sourceMappingURL=node-D58f7Ea6.js.map
2403
+ //# sourceMappingURL=node-CcLPV4RA.js.map
@@ -1,7 +1,7 @@
1
1
  import { C as __exportAll } from "./transform-messages-Csvf2ItW.js";
2
2
  import * as fs from "node:fs";
3
- import * as path from "node:path";
4
3
  import * as crypto from "node:crypto";
4
+ import * as path from "node:path";
5
5
  import * as stream from "node:stream";
6
6
  import * as child_process from "node:child_process";
7
7
  import * as util from "node:util";
@@ -22,4 +22,4 @@ var node_exports = /* @__PURE__ */ __exportAll({
22
22
  //#endregion
23
23
  export { path as a, node_exports as i, crypto as n, stream as o, fs as r, util as s, child_process as t };
24
24
 
25
- //# sourceMappingURL=node-Br-0fshF.js.map
25
+ //# sourceMappingURL=node-vkDR3GtK.js.map
package/lib/pricing.d.ts CHANGED
@@ -93,6 +93,10 @@ export interface AudioQuote {
93
93
  export declare function quoteAudio(model: MediaModel, inputSeconds?: number): AudioQuote;
94
94
  /** A video request to quote, before anything is uploaded or submitted. */
95
95
  export interface VideoQuoteRequest {
96
+ readonly operationId?: string;
97
+ readonly mode?: string;
98
+ readonly aspectRatio?: string;
99
+ readonly generateAudio?: boolean;
96
100
  /** The canonical model id or an alias. */
97
101
  readonly model: string;
98
102
  /** When absent and the catalog offers exactly one resolution for the model, that one. */
@@ -162,7 +166,23 @@ export interface VideoQuoteUnavailable {
162
166
  readonly basis: Bilingual;
163
167
  }
164
168
  /** What a video request is expected to cost. */
165
- export type VideoQuote = VideoTokenEstimate | VideoLegacyEstimate | VideoQuoteUnavailable;
169
+ export type VideoGatewayEstimate = Omit<VideoLegacyEstimate, 'mode'> & {
170
+ readonly mode: 'video_token' | 'legacy';
171
+ } & Partial<Omit<VideoTokenEstimate, keyof VideoLegacyEstimate>>;
172
+ export type VideoQuote = (VideoTokenEstimate | VideoLegacyEstimate | VideoGatewayEstimate | VideoQuoteUnavailable) & {
173
+ readonly operationId?: string;
174
+ readonly quoteId?: string;
175
+ readonly pricingVersion?: string;
176
+ readonly expiresAt?: string;
177
+ readonly unit?: string;
178
+ readonly unitPrice?: string;
179
+ readonly isEstimate?: boolean;
180
+ readonly reservationAmount?: string | null;
181
+ readonly billingSource?: {
182
+ readonly kind: 'balance' | 'subscription';
183
+ readonly subscriptionId?: string | null;
184
+ };
185
+ };
166
186
  /**
167
187
  * Quote a video request from the catalog alone: no upload, no submission.
168
188
  *
@@ -6,15 +6,17 @@
6
6
  *
7
7
  * The gateway asks clients to send searches one at a time and to wait as
8
8
  * `Retry-After` says, so the provider queues searches (`web_search` runs one
9
- * call's queries in parallel) and waits out short rate-limit and busy answers
10
- * before giving up. A token the gateway rejects is reported back to where it
11
- * came from, which renews it, and the search is retried once.
9
+ * call's queries in parallel). Only explicitly retryable short 429/503 responses
10
+ * are retried, at most twice; platform-account and budget failures stop immediately.
11
+ * Genuine user-token refusals can renew that token once. Other failures preserve
12
+ * the signed-in account and their gateway code, category, field and retry facts.
12
13
  *
13
14
  * Ported from the VibeDev app's own search package
14
15
  * (`@vibedev/dsh-web-search-gateway`, provider.ts); here the credential is the
15
16
  * plugin's (host account, its own sign-in, or a development key).
16
17
  * @module dsh-vibedev/search/provider
17
18
  */
19
+ import { WebError } from '@deepseek-ai/dsh-web';
18
20
  import type { WebSearchProvider, WebSearchRequest, WebSearchResult } from '@deepseek-ai/dsh-web';
19
21
  import type { GatewayCredential } from '../gateway/http.js';
20
22
  /** Stable id the provider registers under; a profile selects it as `web.searchProvider`. */
@@ -40,6 +42,26 @@ export interface GatewaySearchOptions {
40
42
  /** Delay used for `Retry-After`; defaults to a timer that the search's signal cancels. */
41
43
  readonly sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
42
44
  }
45
+ /** Safe search diagnostics; an absent Retry-After remains unknown. */
46
+ export interface SearchErrorDetails {
47
+ readonly status: number;
48
+ readonly code?: string;
49
+ readonly category?: string;
50
+ readonly retryable?: boolean;
51
+ readonly field?: string;
52
+ readonly maxCharacters?: number;
53
+ readonly retryAfterMs?: number;
54
+ }
55
+ /** A WebError that retains the gateway's search refusal and recovery facts. */
56
+ export declare class GatewaySearchError extends WebError {
57
+ readonly details: SearchErrorDetails;
58
+ /**
59
+ * @param message - sanitized refusal with a safe next action.
60
+ * @param code - exact gateway code, or the existing credential-specific fallback.
61
+ * @param details - status and explicitly supplied diagnostic facts, without credentials or query text.
62
+ */
63
+ constructor(message: string, code: string, details: SearchErrorDetails);
64
+ }
43
65
  /**
44
66
  * Milliseconds a `Retry-After` header asks for: delta seconds or an HTTP date.
45
67
  * @param header - the header value, or null when absent.
@@ -48,10 +70,11 @@ export interface GatewaySearchOptions {
48
70
  */
49
71
  export declare function searchRetryAfterMs(header: string | null, now?: number): number | undefined;
50
72
  /**
51
- * The request body: the query and, when bounded, the result count within the gateway's limits.
52
- * Any other field makes the gateway answer 400.
73
+ * The request body contains only the query and an optional bounded result count.
74
+ * Filters remain in the expression; it is never truncated or split into more searches.
53
75
  * @param request - the seam request.
54
76
  * @returns the JSON body.
77
+ * @throws GatewaySearchError before dispatch if the complete expression exceeds 128 Unicode code points.
55
78
  */
56
79
  export declare function requestBody(request: WebSearchRequest): string;
57
80
  /**
package/lib/service.d.ts CHANGED
@@ -22,6 +22,7 @@ import type { TaskQueue, TaskStage, TaskTiming } from './tasks/progress.js';
22
22
  import type { TaskRecord, TaskStatus } from './tasks/store.js';
23
23
  import type { ImageRequest } from './tools/image.js';
24
24
  import type { VideoRequest } from './tools/video.js';
25
+ import type { AccountCenterPage, MediaAccountContext, SafeTaskError } from './contracts.js';
25
26
  /** Where a host request runs and where its results go. */
26
27
  export interface HostTarget {
27
28
  /** The workspace; relative input paths resolve against it. */
@@ -46,6 +47,18 @@ export interface MediaOutputView {
46
47
  }
47
48
  /** A video or audio task, as host callers see it. */
48
49
  export interface MediaTaskView {
50
+ readonly operationId?: string;
51
+ readonly taskId?: string;
52
+ readonly submissionState?: string;
53
+ readonly billingState?: string;
54
+ readonly billingSource?: 'balance' | 'subscription';
55
+ readonly subscriptionId?: string;
56
+ readonly nextPollAfterSeconds?: number;
57
+ readonly quoteId?: string;
58
+ readonly pricingVersion?: string;
59
+ readonly reservedAmount?: string;
60
+ readonly settledAmount?: string;
61
+ readonly releasedAmount?: string;
49
62
  readonly id: string;
50
63
  readonly kind: TaskRecord['kind'];
51
64
  /** For audio: music, podcast or speech. */
@@ -68,10 +81,7 @@ export interface MediaTaskView {
68
81
  /** The gateway's queue position of a running task; each part only when known. Absent on finished tasks. */
69
82
  readonly queue?: TaskQueue;
70
83
  readonly outputs?: readonly MediaOutputView[];
71
- readonly error?: {
72
- readonly code: string;
73
- readonly message: string;
74
- };
84
+ readonly error?: SafeTaskError;
75
85
  /** The gateway's estimate, as given (`3.98`). */
76
86
  readonly estimatedCny?: string;
77
87
  /** Only when `settlement` is `settled`: the final charge, exactly as given (`3.98066354`). */
@@ -91,7 +101,22 @@ export interface MediaTaskView {
91
101
  export declare class MediaHostService {
92
102
  private readonly runtime;
93
103
  readonly version: string;
94
- constructor(runtime: MediaRuntime, version: string);
104
+ private readonly accountHooks?;
105
+ private readonly boundQuotes;
106
+ /** Current initialized account only; images have no durable local lookup contract. */
107
+ supportsDurableTaskLookup(kind: 'video' | 'audio'): boolean;
108
+ readonly capabilities: readonly ["errors-v1", "media-quotes-v1"];
109
+ constructor(runtime: MediaRuntime, version: string, accountHooks?: {
110
+ account: () => Promise<MediaAccountContext>;
111
+ open: (page: AccountCenterPage) => void;
112
+ refresh: () => void;
113
+ } | undefined);
114
+ account(): Promise<MediaAccountContext>;
115
+ openAccountCenter(options?: {
116
+ readonly page?: AccountCenterPage;
117
+ }): void;
118
+ refreshAccount(): void;
119
+ quoteVideo(request: VideoQuoteRequest, signal?: AbortSignal): Promise<VideoQuote>;
95
120
  private call;
96
121
  /**
97
122
  * The media models this account can use (cached briefly; renewed after a sign-in, sign-out or account switch).
@@ -147,15 +172,15 @@ export declare class MediaHostService {
147
172
  /**
148
173
  * Submit a video. The plugin follows the task in the background and saves
149
174
  * the video when it finishes; watch it with {@link task} and {@link onTask}.
150
- * A submission the gateway did not confirm is resent in the background
151
- * under the same key, so it is reported as a task still being submitted
152
- * rather than as a failure.
175
+ * An unconfirmed submission is preserved under its original operation key.
176
+ * Recovery may check only the original key and persisted body within its budget.
153
177
  * @param request - what to generate.
154
178
  * @param target - the workspace and where the video goes.
155
179
  * @param signal - cancels the preparation and the submission.
156
180
  * @returns the task.
157
181
  */
158
182
  startVideo(request: VideoRequest, target: HostTarget, signal: AbortSignal): Promise<MediaTaskView>;
183
+ private startVideoScoped;
159
184
  /**
160
185
  * Submit music, a podcast episode or speech. Fields are checked against
161
186
  * what the model declares before anything is uploaded or charged; speech
@@ -170,6 +195,7 @@ export declare class MediaHostService {
170
195
  * @returns the task.
171
196
  */
172
197
  startAudio(request: AudioRequest, target: HostTarget, signal: AbortSignal): Promise<MediaTaskView>;
198
+ private startAudioScoped;
173
199
  private submit;
174
200
  /**
175
201
  * A task's current state, as recorded (no request to the gateway).
@@ -178,7 +204,8 @@ export declare class MediaHostService {
178
204
  */
179
205
  task(id: string): Promise<MediaTaskView | undefined>;
180
206
  /**
181
- * Ask the gateway about a task again — a query, never a submission: a
207
+ * Ask the gateway about the same task again: a budgeted original-key check
208
+ * while unconfirmed, and only a query once a task ID is known. A
182
209
  * finished task gets fresh links and its missing files are downloaded
183
210
  * again, and a pending settlement is read again. A running task is followed.
184
211
  * @param id - the task id.
@@ -16,6 +16,8 @@
16
16
  * @module dsh-vibedev/tasks/remote
17
17
  */
18
18
  import type { ProgressFacts } from './progress.js';
19
+ import type { SafeTaskError } from '../contracts.js';
20
+ import type { TaskRecord } from './store.js';
19
21
  /** One produced file as the gateway describes it. */
20
22
  export interface RemoteOutput {
21
23
  /** Position in `outputs[]`, for `/content?index=N`. */
@@ -30,6 +32,7 @@ export interface RemoteOutput {
30
32
  }
31
33
  /** A task's state, with the progress facts of the answer when the gateway gives them. */
32
34
  export interface RemoteTask extends ProgressFacts {
35
+ readonly receipt?: Pick<TaskRecord, 'submissionState' | 'billingState' | 'billingSource' | 'subscriptionId' | 'quoteId' | 'pricingVersion' | 'reservedAmount' | 'settledAmount' | 'releasedAmount'>;
33
36
  readonly id: string;
34
37
  /**
35
38
  * `completed` also covers `settlement_pending`: the result exists and is
@@ -40,10 +43,7 @@ export interface RemoteTask extends ProgressFacts {
40
43
  readonly status: string;
41
44
  /** Percent done, when the gateway reports it. */
42
45
  readonly progress?: number;
43
- readonly error?: {
44
- readonly code: string;
45
- readonly message: string;
46
- };
46
+ readonly error?: SafeTaskError;
47
47
  /** Estimated price at submission (CNY, two decimals). */
48
48
  readonly estimatedCny?: string;
49
49
  /**
@@ -2,14 +2,14 @@
2
2
  * The durable list of video and audio tasks, one file per task under
3
3
  * `<state dir>/tasks/`, so harness processes sharing a home never overwrite
4
4
  * each other's tasks. A task is recorded before it is submitted, under the id
5
- * that doubles as its `Idempotency-Key`: a submission cut short is resent under
6
- * the same key (the gateway returns the original task instead of creating a
7
- * second one), and a task still running when the host restarts is followed to
8
- * the end. A claim file names the process following a task, so two processes
5
+ * that doubles as its `Idempotency-Key`. A submission cut short stays unknown
6
+ * with bounded checks using only its original key and saved body. A known gateway task is queried after
7
+ * restart to recover its result. A claim file names the process following a task, so two processes
9
8
  * never poll and download the same one.
10
9
  * @module dsh-vibedev/tasks/store
11
10
  */
12
11
  import type { TaskQueue, TaskTiming } from './progress.js';
12
+ import type { SafeTaskError } from '../contracts.js';
13
13
  /** What a task produces. */
14
14
  export type TaskKind = 'video' | 'audio';
15
15
  /**
@@ -37,6 +37,31 @@ export interface TaskOutput {
37
37
  export interface TaskRecord {
38
38
  /** Local id; also the `Idempotency-Key` of the submission. */
39
39
  readonly id: string;
40
+ /** Hashed gateway/account namespace; never a credential. Absent in legacy stores. */
41
+ readonly accountScope?: string;
42
+ /** Copied from the pre-account gateway store; the original remains untouched. */
43
+ readonly migratedFrom?: 'gateway-tasks-v1';
44
+ readonly requestFingerprint?: string;
45
+ /** Durable same-key recovery budget, consumed before dispatch and never reset by restart/refresh. */
46
+ readonly recovery?: {
47
+ readonly deadlineAt: number;
48
+ readonly initialLimit: number;
49
+ readonly backgroundLimit: number;
50
+ readonly initialAttempts: number;
51
+ readonly backgroundAttempts: number;
52
+ readonly nextAttemptAt: number;
53
+ readonly stopped?: 'ambiguous' | 'rejected_after_unknown';
54
+ };
55
+ readonly submissionState?: string;
56
+ readonly billingState?: string;
57
+ readonly billingSource?: 'balance' | 'subscription';
58
+ readonly subscriptionId?: string;
59
+ readonly nextPollAfterSeconds?: number;
60
+ readonly quoteId?: string;
61
+ readonly pricingVersion?: string;
62
+ readonly reservedAmount?: string;
63
+ readonly settledAmount?: string;
64
+ readonly releasedAmount?: string;
40
65
  readonly kind: TaskKind;
41
66
  readonly model: string;
42
67
  /** A short description for listings (a prompt excerpt). */
@@ -61,10 +86,7 @@ export interface TaskRecord {
61
86
  readonly queue?: TaskQueue;
62
87
  /** Outputs saved so far; a finished task lists every output. */
63
88
  readonly outputs?: readonly TaskOutput[];
64
- readonly error?: {
65
- readonly code: string;
66
- readonly message: string;
67
- };
89
+ readonly error?: SafeTaskError;
68
90
  /** The gateway's estimate, as given (`3.98`). */
69
91
  readonly estimatedCny?: string;
70
92
  /** The final charge, exactly as given (`3.98066354`); recorded only once `settlement` is `settled`. */
@@ -99,12 +121,34 @@ export declare function isFinished(record: Pick<TaskRecord, 'status'>): boolean;
99
121
  export declare class TaskStore {
100
122
  private readonly directory;
101
123
  private readonly now;
124
+ private readonly resolveScope?;
102
125
  private readonly chains;
126
+ private readonly scopes;
127
+ private readonly legacyRecords;
128
+ private readonly migrations;
129
+ private verifiedScope?;
130
+ private scopeEpoch;
131
+ private readonly activeScope;
103
132
  /**
104
133
  * @param directory - the plugin state directory.
105
134
  * @param now - clock.
106
135
  */
107
- constructor(directory: string, now?: () => number);
136
+ constructor(directory: string, now?: () => number, resolveScope?: (() => Promise<string | undefined>) | undefined);
137
+ /** Resolve once per operation, so a switch while writing cannot move an old record into the new account. */
138
+ private scoped;
139
+ private resolveCurrentScope;
140
+ /** Synchronous capability, valid only after an awaited account-scoped lookup initialized this scope. */
141
+ supportsDurableTaskLookup(kind: TaskKind): boolean;
142
+ invalidateScope(): void;
143
+ /** Bind legacy files once, without rewriting or removing the released plugin's records. */
144
+ private prepareLegacy;
145
+ currentScope(): Promise<string | undefined>;
146
+ /** Bind a whole asynchronous operation to its initial account's files. */
147
+ withScope<T>(run: () => Promise<T>): Promise<T>;
148
+ /** Namespaces in-memory polling/claim keys just like the durable records. */
149
+ scopeKey(id: string): string;
150
+ boundStore(): TaskStore;
151
+ isCurrent(record: TaskRecord): Promise<boolean>;
108
152
  private get dir();
109
153
  private file;
110
154
  /** Run one change to a task after the previous change to it in this process. */
@@ -157,4 +201,5 @@ export declare class TaskStore {
157
201
  */
158
202
  release(id: string, holder: string): Promise<void>;
159
203
  private prune;
204
+ private retainReceipt;
160
205
  }
@@ -5,21 +5,13 @@
5
5
  * background job, so a task keeps being followed after its job is stopped and
6
6
  * after the host restarts.
7
7
  *
8
- * Money rules, and the rule that one operation creates at most one task:
9
- *
10
- * - A submission is settled by the gateway's structured verdict
11
- * (`submission_state` and `retry_action`) first, and only by the HTTP status
12
- * when it sends none. `rejected`/`retry_action: none` is final: the reason is
13
- * saved and nothing is sent again — not by the tool, not by the background
14
- * loop, not after a restart. `retryable` on its own never authorizes creating
15
- * another task.
16
- * - An unknown outcome keeps the record and settles it under the SAME key and
17
- * the SAME body, which the gateway answers with the original task when there
18
- * is one. A new key is minted only for a new request the user asks for.
19
- * - Once a gateway task id is known the task is only polled; a failed poll
20
- * never submits anything.
21
- * - A refusal that left nothing under the key ends the record as failed with
22
- * the gateway's own reason, so the person sees why.
8
+ * Submission and billing facts are separate. Unknown/submitting states,
9
+ * uncertainty categories and known unknown codes take precedence over weaker
10
+ * refusal hints. Neither retryable nor retry_action authorizes a creation POST.
11
+ * An unconfirmed operation remains recorded and is checked only under its
12
+ * original key and saved body within a durable time/attempt budget;
13
+ * once a gateway task id is known, recovery only queries that task. Billing is
14
+ * shown only from explicit gateway receipts.
23
15
  * @module dsh-vibedev/tasks/tracker
24
16
  */
25
17
  import type { GatewayHttp } from '../gateway/http.js';
@@ -35,12 +27,12 @@ export interface TrackerOptions {
35
27
  readonly sleep?: (ms: number, signal: AbortSignal) => Promise<void>;
36
28
  /** Give up on a task this long after it was created. Defaults to 3 hours. */
37
29
  readonly maxAgeMs?: number;
38
- /**
39
- * How long an unconfirmed submission is reconciled under its own key before
40
- * the task is given up. Defaults to 5 minutes: this settles what became of
41
- * that one submission, it never creates another task.
42
- */
30
+ /** Same-key recovery window, including the initial attempts. Defaults to 5 minutes (0.3.11). */
43
31
  readonly resendWindowMs?: number;
32
+ /** Total initial same-key attempts including the first dispatch. Defaults to 3 (0.3.11). */
33
+ readonly submitAttempts?: number;
34
+ /** Additional background same-key checks. Defaults to 30 (0.3.11 failure limit); 0 disables background POSTs. */
35
+ readonly reconcileAttempts?: number;
44
36
  /** Download attempts for a finished task before its links are reported instead. Defaults to 5. */
45
37
  readonly downloadAttempts?: number;
46
38
  /** The largest output downloaded. Defaults to 2 GiB. */
@@ -54,29 +46,17 @@ export interface TrackerOptions {
54
46
  * How a failed submission may be taken further.
55
47
  *
56
48
  * - `rejected`: the request is refused for good (a parameter refusal, a
57
- * provider-side rejection, a key conflict); nothing exists under the key and
58
- * nothing may be created again for this operation.
59
- * - `reconcile`: the outcome is unknown — the same key and the same body are
60
- * sent again only to settle what became of that one submission. This never
61
- * mints a new key and never asks the provider for a new task.
62
- * - `wait`: nothing was created and the same request may be sent later (busy,
63
- * rate limited, no balance); the key stays the same.
49
+ * provider-side rejection, a key conflict); no automatic resend is permitted.
50
+ * This verdict alone makes no claim about billing.
51
+ * - `reconcile`: the outcome remains unknown. Preserve the operation and allow
52
+ * only budgeted checks with the original key and persisted body.
53
+ * - `wait`: a legacy retry hint; it does not prove the request was not submitted.
64
54
  */
65
55
  export type SubmissionRecovery = 'rejected' | 'reconcile' | 'wait';
66
56
  /**
67
- * What a failed submission means.
68
- *
69
- * The two STOP rules are read before anything that would keep the operation
70
- * alive, so no verdict can talk the plugin into sending a refused request
71
- * again: `retry_action: none` (the provider refused it) and
72
- * `VIDEO_SUBMISSION_AMBIGUOUS` (the gateway's key answers this forever) end the
73
- * operation even when the same answer also says the outcome is unknown.
74
- *
75
- * After those, the gateway's structured verdict decides, and only when it
76
- * sends none do the HTTP status and the older codes. `retryable` says recovery
77
- * is still needed; it never authorizes creating another task.
78
- * @param error - the failure.
79
- * @returns how it may be taken further.
57
+ * Unknown submission facts take precedence over refusal/retry hints. A retry
58
+ * limit, retryable=false or an unqualified 5xx cannot prove a rejection.
59
+ * Reconciliation always retains the original operation key.
80
60
  */
81
61
  export declare function submissionRecovery(error: unknown): SubmissionRecovery;
82
62
  /**
@@ -88,10 +68,16 @@ export declare function progressLine(task: RemoteTask): string;
88
68
  /** Follows tasks; one poll loop per task. */
89
69
  export declare class TaskTracker {
90
70
  private readonly options;
71
+ private readonly reconciliations;
72
+ private readonly pendingListeners;
91
73
  private readonly following;
92
74
  private readonly submissions;
75
+ private readonly submissionFingerprints;
93
76
  private readonly listeners;
94
77
  private readonly claims;
78
+ private readonly claimAcquisitions;
79
+ private readonly claimReleases;
80
+ private disposing?;
95
81
  private readonly downloadFailures;
96
82
  private readonly controller;
97
83
  private readonly holder;
@@ -106,13 +92,20 @@ export declare class TaskTracker {
106
92
  /**
107
93
  * Record and submit a new task. An outright refusal of the first attempt
108
94
  * throws and leaves no record. When the outcome stays open, the task stays
109
- * recorded and is resent in the background, and this throws `SUBMISSION_UNCONFIRMED`.
95
+ * recorded as unknown and checked only under the original key and saved body.
110
96
  * @param draft - the task, with status `submitting`.
111
97
  * @param signal - cancels waiting for the submission.
112
98
  * @returns the accepted task.
113
99
  */
114
100
  submit(draft: TaskRecord, signal?: AbortSignal): Promise<TaskRecord>;
101
+ private submitScoped;
115
102
  private runSubmission;
103
+ private budget;
104
+ private waitInitialRecovery;
105
+ private keepUnknown;
106
+ private reconcileOnce;
107
+ private reconcileClaimed;
108
+ private expireUnknown;
116
109
  /**
117
110
  * Follow a recorded task until it ends or the tracker is disposed. A task
118
111
  * still being submitted is followed once its submission settles.
@@ -120,6 +113,7 @@ export declare class TaskTracker {
120
113
  * @returns the task at the end (or at disposal, still running).
121
114
  */
122
115
  follow(id: string): Promise<TaskRecord>;
116
+ private followScoped;
123
117
  private followQuietly;
124
118
  /**
125
119
  * Hear about every change to one task.
@@ -128,16 +122,19 @@ export declare class TaskTracker {
128
122
  * @returns unsubscribe.
129
123
  */
130
124
  onUpdate(id: string, listener: (record: TaskRecord) => void): () => void;
125
+ private bindListener;
131
126
  /** Follow every task that has not ended, as after a restart. */
132
127
  resume(): Promise<void>;
133
128
  /** Stop all polling and give up this process's claims; tasks stay recorded and are resumed next time. */
134
- dispose(): void;
129
+ dispose(): Promise<void>;
130
+ private disposeAll;
135
131
  private notify;
136
132
  private update;
137
133
  private finish;
138
134
  /** Hold (or keep) this process's claim on a task, renewing it while held. */
139
135
  private holdClaim;
140
- private dropClaim;
136
+ private acquireClaim;
137
+ private releaseHeldClaim;
141
138
  private releaseClaim;
142
139
  private loop;
143
140
  /**
@@ -165,21 +162,24 @@ export declare class TaskTracker {
165
162
  /** Record what the gateway says about a task; save the outputs of a finished one. */
166
163
  private apply;
167
164
  /**
168
- * Ask the gateway about a task again, by query only: a finished task gets
165
+ * Ask about the same task again: an unconfirmed operation may consume one
166
+ * budgeted original-key/body check; a finished task gets
169
167
  * fresh links (signed links expire), files that are missing locally are
170
168
  * downloaded again, and a pending settlement is read again. Nothing is ever
171
- * submitted from here, so a failed query or download cannot create a task.
169
+ * submitted under a new key, so a failed query/download never starts a new operation.
172
170
  * A task still running is followed as usual.
173
171
  * @param id - the local task id.
174
172
  * @param signal - cancels the query.
175
173
  * @returns the task after the query.
176
174
  */
177
175
  refresh(id: string, signal?: AbortSignal): Promise<TaskRecord>;
176
+ private refreshScoped;
178
177
  /**
179
178
  * Save every output not saved yet, recording each one as it lands. A
180
179
  * shutdown mid-download throws, so the task stays open and is resumed.
181
180
  */
182
181
  private saveOutputs;
182
+ private existingOutputs;
183
183
  /** Use a returned signed URL verbatim and without the app token; old gateways without a URL use `/content`. */
184
184
  private fetchOutput;
185
185
  }
@@ -7,6 +7,7 @@ import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
7
7
  import type { MediaCall, MediaRuntime } from '../runtime.js';
8
8
  /** One image request, as the tool and host callers make it. */
9
9
  export interface ImageRequest {
10
+ readonly operationId?: string;
10
11
  readonly prompt: string;
11
12
  readonly model?: string;
12
13
  /** `WIDTHxHEIGHT` or `auto`. */
@@ -14,6 +14,9 @@ import type { VideoPlan, VideoRequestOptions } from '../video/plan.js';
14
14
  /** One video request, as the tool and host callers make it. */
15
15
  export interface VideoRequest extends VideoRequestOptions {
16
16
  readonly model?: string;
17
+ /** Stable id for one caller operation; retrying it recovers the original task. */
18
+ readonly operationId?: string;
19
+ readonly quoteId?: string;
17
20
  }
18
21
  /** A video request checked, uploaded and priced, ready to submit. */
19
22
  export interface PreparedVideo {
@@ -5,6 +5,8 @@
5
5
  * never leaves a half-written or empty file under a final name.
6
6
  * @module dsh-vibedev/util/files
7
7
  */
8
+ /** A remembered result is usable only while its nonempty file still exists. */
9
+ export declare function savedFileExists(path: string | undefined): Promise<boolean>;
8
10
  /**
9
11
  * The harness home: `$DSH_HOME` when set (VibeDev sets it to its own home),
10
12
  * else `~/.dsh`, the same rule the harness itself applies.
package/locale/en.json CHANGED
@@ -2,5 +2,18 @@
2
2
  "meta": {
3
3
  "title": "VibeDev Account & Models",
4
4
  "description": "Sign in to VibeDev (next to the DeepSeek account) to use the VibeDev gateway's models (Claude, GPT and more) in the model picker, and let the agent generate images, videos, music and podcasts and transcribe speech; paid from your VibeDev balance."
5
+ },
6
+ "mediaErrors": {
7
+ "operationIdentifier": "The operation identifier must contain 8-80 letters, numbers, underscores or hyphens.",
8
+ "quoteUnavailable": "The quote response could not be verified. Refresh the quote.",
9
+ "quoteMismatch": "The quote does not match this operation or has expired. Request a new quote.",
10
+ "accountChanged": "The account changed. The original task is preserved.",
11
+ "imageUncertain": "The image submission outcome is unknown. Check the original operation before generating again.",
12
+ "lookupUnavailable": "Local task records are temporarily unavailable. Keep the original operation identifier and retry the lookup.",
13
+ "accountUnavailable": "Unable to confirm the VibeDev account. Refresh account information and try again; original tasks are preserved.",
14
+ "pollBilling": "Progress is temporarily unavailable. Check account billing; the original task is preserved.",
15
+ "pollUnavailable": "Progress is temporarily unavailable. The original task is preserved.",
16
+ "downloadFailed": "Generation completed, but the result could not be downloaded. Retry the download without generating again.",
17
+ "submissionUncertain": "This operation needs confirmation. Keep operation {operationId}. Only its original key and saved request are checked within a limited recovery budget; a new operation will not be created automatically. Check the original task or account usage before generating again."
5
18
  }
6
19
  }
package/locale/zh.json CHANGED
@@ -2,5 +2,18 @@
2
2
  "meta": {
3
3
  "title": "VibeDev 账号与模型",
4
4
  "description": "登录 VibeDev 账号(与 DeepSeek 账号并存),在模型选择器里使用 VibeDev 网关的模型(Claude、GPT 等),并让 Agent 生成图片、视频、音乐和播客、转写语音;费用从 VibeDev 余额扣除。"
5
+ },
6
+ "mediaErrors": {
7
+ "operationIdentifier": "操作编号须为8–80个字母、数字、下划线或连字符。",
8
+ "quoteUnavailable": "报价响应无法确认,请刷新报价。",
9
+ "quoteMismatch": "报价与当前操作不匹配或已过期,请重新询价。",
10
+ "accountChanged": "账号已切换,原任务已保留。",
11
+ "imageUncertain": "图片提交结果待确认,请核对原请求,勿重复生成。",
12
+ "lookupUnavailable": "本地任务记录暂时无法读取,请保留原操作编号后重试。",
13
+ "accountUnavailable": "暂时无法确认 VibeDev 账户,请刷新账户信息后再试;原任务已保留。",
14
+ "pollBilling": "暂时无法获取进度,请查看账户计费状态;原任务已保留。",
15
+ "pollUnavailable": "暂时无法获取进度,原任务已保留。",
16
+ "downloadFailed": "生成已完成,但结果下载失败。请重试下载,勿重复生成。",
17
+ "submissionUncertain": "此操作结果待确认,请保留原操作编号 {operationId}。插件只会在有限核对预算内使用原编号和已保存请求核对,不会自动创建新操作;请核对原任务或账户用量后再决定是否重新生成。"
5
18
  }
6
19
  }
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VibeDev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+