@vibedev-si/dsh-vibedev 0.3.10 → 0.5.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.
Files changed (47) hide show
  1. package/README.md +141 -7
  2. package/THIRD-PARTY-NOTICES.txt +1 -1
  3. package/client/client.account-center.js +13151 -0
  4. package/client/client.js +3417 -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/gateway/errors.d.ts +29 -1
  17. package/lib/gateway/http.d.ts +6 -0
  18. package/lib/host-locales.d.ts +4 -0
  19. package/lib/index.d.ts +14 -0
  20. package/lib/index.js +4619 -1976
  21. package/lib/{node-D58f7Ea6.js → node-CcLPV4RA.js} +4 -4
  22. package/lib/{node-Br-0fshF.js → node-vkDR3GtK.js} +2 -2
  23. package/lib/pricing.d.ts +21 -1
  24. package/lib/service.d.ts +51 -9
  25. package/lib/tasks/progress.d.ts +96 -0
  26. package/lib/tasks/remote.d.ts +15 -8
  27. package/lib/tasks/store.d.ts +59 -9
  28. package/lib/tasks/tracker.d.ts +51 -45
  29. package/lib/tools/image.d.ts +1 -0
  30. package/lib/tools/video.d.ts +3 -0
  31. package/lib/util/files.d.ts +2 -0
  32. package/locale/en.json +13 -0
  33. package/locale/zh.json +13 -0
  34. package/node_modules/@vibedev-si/dsh-ecosystem/LICENSE +22 -0
  35. package/node_modules/@vibedev-si/dsh-ecosystem/README.md +154 -0
  36. package/node_modules/@vibedev-si/dsh-ecosystem/catalog/catalog.json +167 -0
  37. package/node_modules/@vibedev-si/dsh-ecosystem/catalog-updates.js +326 -0
  38. package/node_modules/@vibedev-si/dsh-ecosystem/catalog-validator.js +263 -0
  39. package/node_modules/@vibedev-si/dsh-ecosystem/client.js +2816 -0
  40. package/node_modules/@vibedev-si/dsh-ecosystem/cordis.patch.yml +5 -0
  41. package/node_modules/@vibedev-si/dsh-ecosystem/icon.svg +5 -0
  42. package/node_modules/@vibedev-si/dsh-ecosystem/index.js +169 -0
  43. package/node_modules/@vibedev-si/dsh-ecosystem/locale/en.json +6 -0
  44. package/node_modules/@vibedev-si/dsh-ecosystem/locale/zh.json +6 -0
  45. package/node_modules/@vibedev-si/dsh-ecosystem/package.json +75 -0
  46. package/node_modules/@vibedev-si/dsh-ecosystem/remote-catalog.js +212 -0
  47. package/package.json +12 -1
@@ -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
  *
package/lib/service.d.ts CHANGED
@@ -18,9 +18,11 @@ import type { AudioForm, AudioRequest } from './audio/request.js';
18
18
  import type { MediaModel } from './gateway/catalog.js';
19
19
  import type { AudioQuote, VideoQuote, VideoQuoteRequest } from './pricing.js';
20
20
  import type { MediaRuntime } from './runtime.js';
21
+ import type { TaskQueue, TaskStage, TaskTiming } from './tasks/progress.js';
21
22
  import type { TaskRecord, TaskStatus } from './tasks/store.js';
22
23
  import type { ImageRequest } from './tools/image.js';
23
24
  import type { VideoRequest } from './tools/video.js';
25
+ import type { AccountCenterPage, MediaAccountContext, SafeTaskError } from './contracts.js';
24
26
  /** Where a host request runs and where its results go. */
25
27
  export interface HostTarget {
26
28
  /** The workspace; relative input paths resolve against it. */
@@ -45,6 +47,18 @@ export interface MediaOutputView {
45
47
  }
46
48
  /** A video or audio task, as host callers see it. */
47
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;
48
62
  readonly id: string;
49
63
  readonly kind: TaskRecord['kind'];
50
64
  /** For audio: music, podcast or speech. */
@@ -52,11 +66,22 @@ export interface MediaTaskView {
52
66
  readonly model: string;
53
67
  readonly status: TaskStatus;
54
68
  readonly progress?: string;
69
+ /**
70
+ * What a running task is doing: `submitting` (not yet confirmed, or not yet
71
+ * submitted upstream), `queued`, `generating`, or `saving` (archived by the
72
+ * gateway or downloaded here). Finished tasks have none; read `status`.
73
+ */
74
+ readonly stage?: TaskStage;
75
+ /**
76
+ * The gateway's timing facts of a running task, every time in epoch
77
+ * milliseconds of this machine's clock (corrected by the gateway's
78
+ * `server_time`). Absent while the gateway gives none, and on finished tasks.
79
+ */
80
+ readonly timing?: TaskTiming;
81
+ /** The gateway's queue position of a running task; each part only when known. Absent on finished tasks. */
82
+ readonly queue?: TaskQueue;
55
83
  readonly outputs?: readonly MediaOutputView[];
56
- readonly error?: {
57
- readonly code: string;
58
- readonly message: string;
59
- };
84
+ readonly error?: SafeTaskError;
60
85
  /** The gateway's estimate, as given (`3.98`). */
61
86
  readonly estimatedCny?: string;
62
87
  /** Only when `settlement` is `settled`: the final charge, exactly as given (`3.98066354`). */
@@ -76,7 +101,22 @@ export interface MediaTaskView {
76
101
  export declare class MediaHostService {
77
102
  private readonly runtime;
78
103
  readonly version: string;
79
- 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>;
80
120
  private call;
81
121
  /**
82
122
  * The media models this account can use (cached briefly; renewed after a sign-in, sign-out or account switch).
@@ -132,15 +172,15 @@ export declare class MediaHostService {
132
172
  /**
133
173
  * Submit a video. The plugin follows the task in the background and saves
134
174
  * the video when it finishes; watch it with {@link task} and {@link onTask}.
135
- * A submission the gateway did not confirm is resent in the background
136
- * under the same key, so it is reported as a task still being submitted
137
- * 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.
138
177
  * @param request - what to generate.
139
178
  * @param target - the workspace and where the video goes.
140
179
  * @param signal - cancels the preparation and the submission.
141
180
  * @returns the task.
142
181
  */
143
182
  startVideo(request: VideoRequest, target: HostTarget, signal: AbortSignal): Promise<MediaTaskView>;
183
+ private startVideoScoped;
144
184
  /**
145
185
  * Submit music, a podcast episode or speech. Fields are checked against
146
186
  * what the model declares before anything is uploaded or charged; speech
@@ -155,6 +195,7 @@ export declare class MediaHostService {
155
195
  * @returns the task.
156
196
  */
157
197
  startAudio(request: AudioRequest, target: HostTarget, signal: AbortSignal): Promise<MediaTaskView>;
198
+ private startAudioScoped;
158
199
  private submit;
159
200
  /**
160
201
  * A task's current state, as recorded (no request to the gateway).
@@ -163,7 +204,8 @@ export declare class MediaHostService {
163
204
  */
164
205
  task(id: string): Promise<MediaTaskView | undefined>;
165
206
  /**
166
- * 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
167
209
  * finished task gets fresh links and its missing files are downloaded
168
210
  * again, and a pending settlement is read again. A running task is followed.
169
211
  * @param id - the task id.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Generation progress of video and audio tasks: the gateway's `timing`,
3
+ * `queue` and `next_poll_after_seconds`, normalized to this machine's clock,
4
+ * the stage callers show, and the coarse wording of the time left.
5
+ *
6
+ * Every fact is optional. A field of the wrong type, a negative number or an
7
+ * unknown word is dropped on its own; it never fails the task. Without any of
8
+ * them, tasks are followed and described exactly as before.
9
+ * @module dsh-vibedev/tasks/progress
10
+ */
11
+ /** The gateway's phase, after its aliases are read. */
12
+ export type TaskPhase = 'pending_submit' | 'queued' | 'generating' | 'archiving' | 'done';
13
+ /** What a running task is doing, as callers show it; finished tasks have none. */
14
+ export type TaskStage = 'submitting' | 'queued' | 'generating' | 'saving';
15
+ /** The gateway's timing facts, with every time in epoch milliseconds of this machine's clock. */
16
+ export interface TaskTiming {
17
+ readonly phase?: TaskPhase;
18
+ /** When the task started. */
19
+ readonly startedAt?: number;
20
+ /** When the current phase started. */
21
+ readonly phaseStartedAt?: number;
22
+ /** When the result is expected to be downloadable: the answer's arrival plus `estimated_remaining_seconds`. */
23
+ readonly estimatedCompletionAt?: number;
24
+ /** A cautious completion time: the answer's arrival plus `remaining_p90_seconds`. */
25
+ readonly p90CompletionAt?: number;
26
+ readonly estimateSource?: 'upstream' | 'history';
27
+ readonly confidence?: 'high' | 'medium' | 'low';
28
+ /** The provider's own progress, 0–1; present only when the provider reports one. */
29
+ readonly progress?: number;
30
+ /** When this machine received these facts. */
31
+ readonly observedAt: number;
32
+ }
33
+ /** A task's place in the gateway's queue; each part only when the gateway knows it. */
34
+ export interface TaskQueue {
35
+ readonly position?: number;
36
+ readonly positionMin?: number;
37
+ readonly positionMax?: number;
38
+ }
39
+ /** The progress facts of one gateway answer. */
40
+ export interface ProgressFacts {
41
+ readonly timing?: TaskTiming;
42
+ readonly queue?: TaskQueue;
43
+ /** The gateway's suggested wait before the next query, already kept within 2–30 seconds. */
44
+ readonly nextPollAfterSeconds?: number;
45
+ }
46
+ type Json = Record<string, unknown>;
47
+ /**
48
+ * Read the progress facts of a task answer.
49
+ * @param raw - the parsed task answer.
50
+ * @param receivedAt - when this machine received it (epoch ms); the anchor of every time.
51
+ * @returns only the facts the answer gives in a readable form.
52
+ */
53
+ export declare function parseProgress(raw: Json, receivedAt: number): ProgressFacts;
54
+ /** The local download of a finished task's results is recorded under this progress line. */
55
+ export declare const SAVING_PROGRESS = "saving the result";
56
+ /**
57
+ * The stage of a task: `submitting` while the gateway has not confirmed it or
58
+ * has not submitted it upstream, `saving` while the result is archived by the
59
+ * gateway or downloaded here, `queued`, and otherwise `generating`.
60
+ * @param task - the task's status, progress line and timing.
61
+ * @returns the stage, or undefined for a finished task.
62
+ */
63
+ export declare function stageOf(task: {
64
+ readonly status: string;
65
+ readonly progress?: string;
66
+ readonly timing?: TaskTiming;
67
+ }): TaskStage | undefined;
68
+ /** An English and a Chinese wording of the same fact. */
69
+ export interface Words {
70
+ readonly en: string;
71
+ readonly zh: string;
72
+ }
73
+ /**
74
+ * The time left, in coarse words: under a minute, about N minutes, or slower
75
+ * than estimated once the estimate has passed. An estimate the gateway marks
76
+ * as low confidence is not stated.
77
+ * @param timing - the task's timing.
78
+ * @param now - this machine's clock (epoch ms).
79
+ * @returns the wording, or undefined without a usable estimate.
80
+ */
81
+ export declare function remainingWords(timing: TaskTiming | undefined, now: number): Words | undefined;
82
+ /**
83
+ * How a running task with progress facts reads: stage, queue position, the
84
+ * provider's progress and the time left, in English with the Chinese wording
85
+ * after it (`queued, position 3 in the queue, about 2 min left (排队中 · 第 3 位 · 约 2 分钟)`).
86
+ * @param task - the task's status, progress line, timing and queue.
87
+ * @param now - this machine's clock (epoch ms).
88
+ * @returns the wording, or undefined when the task is finished or carries no progress facts.
89
+ */
90
+ export declare function progressWords(task: {
91
+ readonly status: string;
92
+ readonly progress?: string;
93
+ readonly timing?: TaskTiming;
94
+ readonly queue?: TaskQueue;
95
+ }, now: number): string | undefined;
96
+ export {};
@@ -9,8 +9,15 @@
9
9
  * (`pending`/`settled`), `billing_pending_reason`, `charged_cny` (kept as the
10
10
  * exact string given), `billed_tokens` and `estimated_cny`. A completed task
11
11
  * whose billing is pending has its result; only the charge is still to come.
12
+ *
13
+ * Newer gateways add progress facts (`timing`, `queue`,
14
+ * `next_poll_after_seconds`), read by {@link parseProgress} against the time
15
+ * the answer arrived.
12
16
  * @module dsh-vibedev/tasks/remote
13
17
  */
18
+ import type { ProgressFacts } from './progress.js';
19
+ import type { SafeTaskError } from '../contracts.js';
20
+ import type { TaskRecord } from './store.js';
14
21
  /** One produced file as the gateway describes it. */
15
22
  export interface RemoteOutput {
16
23
  /** Position in `outputs[]`, for `/content?index=N`. */
@@ -23,8 +30,9 @@ export interface RemoteOutput {
23
30
  /** The provider's original length this output is billed on, when it differs from playback (speech). */
24
31
  readonly originalSeconds?: number;
25
32
  }
26
- /** A task's state. */
27
- export interface RemoteTask {
33
+ /** A task's state, with the progress facts of the answer when the gateway gives them. */
34
+ export interface RemoteTask extends ProgressFacts {
35
+ readonly receipt?: Pick<TaskRecord, 'submissionState' | 'billingState' | 'billingSource' | 'subscriptionId' | 'quoteId' | 'pricingVersion' | 'reservedAmount' | 'settledAmount' | 'releasedAmount'>;
28
36
  readonly id: string;
29
37
  /**
30
38
  * `completed` also covers `settlement_pending`: the result exists and is
@@ -35,10 +43,7 @@ export interface RemoteTask {
35
43
  readonly status: string;
36
44
  /** Percent done, when the gateway reports it. */
37
45
  readonly progress?: number;
38
- readonly error?: {
39
- readonly code: string;
40
- readonly message: string;
41
- };
46
+ readonly error?: SafeTaskError;
42
47
  /** Estimated price at submission (CNY, two decimals). */
43
48
  readonly estimatedCny?: string;
44
49
  /**
@@ -67,12 +72,14 @@ export interface RemoteTask {
67
72
  /**
68
73
  * Read a video task.
69
74
  * @param body - the parsed answer.
75
+ * @param receivedAt - when this machine received it (epoch ms), the anchor of its progress times.
70
76
  * @returns the task, or undefined when the answer names no task id.
71
77
  */
72
- export declare function parseVideoTask(body: unknown): RemoteTask | undefined;
78
+ export declare function parseVideoTask(body: unknown, receivedAt?: number): RemoteTask | undefined;
73
79
  /**
74
80
  * Read a music or podcast task.
75
81
  * @param body - the parsed answer.
82
+ * @param receivedAt - when this machine received it (epoch ms), the anchor of its progress times.
76
83
  * @returns the task, or undefined when the answer names no task id.
77
84
  */
78
- export declare function parseAudioTask(body: unknown): RemoteTask | undefined;
85
+ export declare function parseAudioTask(body: unknown, receivedAt?: number): RemoteTask | undefined;
@@ -2,13 +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
  */
11
+ import type { TaskQueue, TaskTiming } from './progress.js';
12
+ import type { SafeTaskError } from '../contracts.js';
12
13
  /** What a task produces. */
13
14
  export type TaskKind = 'video' | 'audio';
14
15
  /**
@@ -36,6 +37,31 @@ export interface TaskOutput {
36
37
  export interface TaskRecord {
37
38
  /** Local id; also the `Idempotency-Key` of the submission. */
38
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;
39
65
  readonly kind: TaskKind;
40
66
  readonly model: string;
41
67
  /** A short description for listings (a prompt excerpt). */
@@ -54,12 +80,13 @@ export interface TaskRecord {
54
80
  readonly gatewayId?: string;
55
81
  readonly status: TaskStatus;
56
82
  readonly progress?: string;
83
+ /** The gateway's latest timing facts, on this machine's clock; only while the task runs and the gateway gives them. */
84
+ readonly timing?: TaskTiming;
85
+ /** The gateway's latest queue position; only while the task runs and the gateway gives one. */
86
+ readonly queue?: TaskQueue;
57
87
  /** Outputs saved so far; a finished task lists every output. */
58
88
  readonly outputs?: readonly TaskOutput[];
59
- readonly error?: {
60
- readonly code: string;
61
- readonly message: string;
62
- };
89
+ readonly error?: SafeTaskError;
63
90
  /** The gateway's estimate, as given (`3.98`). */
64
91
  readonly estimatedCny?: string;
65
92
  /** The final charge, exactly as given (`3.98066354`); recorded only once `settlement` is `settled`. */
@@ -94,12 +121,34 @@ export declare function isFinished(record: Pick<TaskRecord, 'status'>): boolean;
94
121
  export declare class TaskStore {
95
122
  private readonly directory;
96
123
  private readonly now;
124
+ private readonly resolveScope?;
97
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;
98
132
  /**
99
133
  * @param directory - the plugin state directory.
100
134
  * @param now - clock.
101
135
  */
102
- 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>;
103
152
  private get dir();
104
153
  private file;
105
154
  /** Run one change to a task after the previous change to it in this process. */
@@ -152,4 +201,5 @@ export declare class TaskStore {
152
201
  */
153
202
  release(id: string, holder: string): Promise<void>;
154
203
  private prune;
204
+ private retainReceipt;
155
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
  /**
@@ -156,24 +153,33 @@ export declare class TaskTracker {
156
153
  * record holds, so a settled task is never downgraded by it.
157
154
  */
158
155
  private moneyOf;
156
+ /**
157
+ * The progress facts to record from an answer. Each answer replaces the
158
+ * last one's, so a fact it no longer gives is removed; a record that never
159
+ * had any (an older gateway) is left untouched.
160
+ */
161
+ private progressFactsOf;
159
162
  /** Record what the gateway says about a task; save the outputs of a finished one. */
160
163
  private apply;
161
164
  /**
162
- * 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
163
167
  * fresh links (signed links expire), files that are missing locally are
164
168
  * downloaded again, and a pending settlement is read again. Nothing is ever
165
- * 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.
166
170
  * A task still running is followed as usual.
167
171
  * @param id - the local task id.
168
172
  * @param signal - cancels the query.
169
173
  * @returns the task after the query.
170
174
  */
171
175
  refresh(id: string, signal?: AbortSignal): Promise<TaskRecord>;
176
+ private refreshScoped;
172
177
  /**
173
178
  * Save every output not saved yet, recording each one as it lands. A
174
179
  * shutdown mid-download throws, so the task stays open and is resumed.
175
180
  */
176
181
  private saveOutputs;
182
+ private existingOutputs;
177
183
  /** Use a returned signed URL verbatim and without the app token; old gateways without a URL use `/content`. */
178
184
  private fetchOutput;
179
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`. */