@vibedev-si/dsh-vibedev 0.3.5 → 0.3.7

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.
@@ -0,0 +1,128 @@
1
+ /**
2
+ * The feedback upload contract: `POST {origin}/v1/account/feedback` with the
3
+ * account's credential (the one `GET /v1/account/auth/me` carries) and a
4
+ * strict JSON body — the gateway refuses unknown fields, so a body holds
5
+ * nothing else. Limits: text at most 4,000 code points, an attachment at most
6
+ * 256 KiB of UTF-8, the whole body at most 300 KiB; short fields carry no
7
+ * control characters. Text and attachments are measured as the gateway stores
8
+ * them, with U+0000 as U+FFFD.
9
+ * @module dsh-vibedev/feedback/wire
10
+ */
11
+ /** Gateway path of the upload. */
12
+ export declare const FEEDBACK_PATH = "/v1/account/feedback";
13
+ /** The categories DeepSeek Harness files feedback under (`FEEDBACK_CATEGORIES` in @deepseek-ai/dsh-command-feedback). */
14
+ export declare const FEEDBACK_CATEGORIES: readonly ["task-result", "instruction-following", "product-interaction", "service-stability", "resource-cost", "security-privacy-permission", "other"];
15
+ export type FeedbackCategory = typeof FEEDBACK_CATEGORIES[number];
16
+ /** Where the feedback came from: a rated assistant message, `/feedback`, or the account menu's dialog. */
17
+ export type FeedbackSource = 'message' | 'command' | 'menu';
18
+ export type FeedbackRating = 'up' | 'down';
19
+ export declare const MAX_TEXT_CODE_POINTS = 4000;
20
+ export declare const MAX_ATTACHMENT_BYTES = 262144;
21
+ export declare const MAX_BODY_BYTES = 307200;
22
+ /** Which app and environment sent it. */
23
+ export interface FeedbackClient {
24
+ /** `vibedev-desktop`, `vibedev-web`, or another client's own name (1..64). */
25
+ readonly app: string;
26
+ readonly appVersion?: string;
27
+ readonly dshVersion?: string;
28
+ readonly pluginVersion?: string;
29
+ readonly os?: {
30
+ readonly platform: string;
31
+ readonly version: string;
32
+ readonly arch: string;
33
+ };
34
+ readonly locale?: string;
35
+ }
36
+ /** What the feedback is about, by reference only. */
37
+ export interface FeedbackContext {
38
+ readonly sessionRef?: string;
39
+ readonly messageRef?: string;
40
+ }
41
+ /** Something the user chose to send along. */
42
+ export interface FeedbackAttachment {
43
+ readonly kind: 'turn-excerpt' | 'error-log';
44
+ /** Only ever sent after the user ticked the box that sends it. */
45
+ readonly consent: true;
46
+ readonly content: string;
47
+ }
48
+ /** One upload. `id` is the idempotency key: a retry resends the same id with the identical body. */
49
+ export interface FeedbackBody {
50
+ readonly id: string;
51
+ readonly source: FeedbackSource;
52
+ readonly rating?: FeedbackRating | null;
53
+ readonly category?: FeedbackCategory | null;
54
+ readonly text?: string;
55
+ readonly client: FeedbackClient;
56
+ readonly context?: FeedbackContext;
57
+ readonly attachment?: FeedbackAttachment;
58
+ }
59
+ /** What one piece of feedback says, before it gets an id and the client facts. */
60
+ export interface FeedbackDraft {
61
+ readonly source: FeedbackSource;
62
+ readonly rating?: FeedbackRating;
63
+ readonly category?: FeedbackCategory;
64
+ readonly text?: string;
65
+ readonly context?: FeedbackContext;
66
+ readonly attachment?: FeedbackAttachment;
67
+ }
68
+ /**
69
+ * Free text as the gateway stores and measures it: U+0000 becomes U+FFFD (PostgreSQL text cannot hold it), three bytes
70
+ * instead of one, before any limit is checked (submission.go sanitizeFreeText, then the size checks). Measuring the
71
+ * text as stored keeps an attachment near 256 KiB with NULs in it from being refused as too large.
72
+ * @param value - the text.
73
+ * @returns the text as it will be stored.
74
+ */
75
+ export declare function asStored(value: string): string;
76
+ /**
77
+ * A short field as the gateway accepts it: no control characters, trimmed, at most `max` code points.
78
+ * @param value - anything.
79
+ * @param max - the longest value, in code points.
80
+ * @returns the field, or undefined when nothing is left.
81
+ */
82
+ export declare function shortField(value: unknown, max: number): string | undefined;
83
+ /**
84
+ * Free text as the gateway accepts it: line breaks and tabs kept, U+0000 as the U+FFFD the gateway stores, other
85
+ * control characters dropped, trimmed, at most 4,000 code points.
86
+ * @param value - anything.
87
+ * @returns the text, or undefined when blank.
88
+ */
89
+ export declare function feedbackText(value: unknown): string | undefined;
90
+ /** The number of code points, the unit the gateway counts text in. */
91
+ export declare function codePoints(text: string): number;
92
+ /**
93
+ * Whether a value is one of the feedback categories.
94
+ * @param value - anything.
95
+ * @returns true for a category.
96
+ */
97
+ export declare function isCategory(value: unknown): value is FeedbackCategory;
98
+ /**
99
+ * Text cut to at most `maxBytes` of UTF-8 on a code-point boundary, with a marker when anything was cut.
100
+ * @param content - the text.
101
+ * @param maxBytes - the budget.
102
+ * @returns the text, unchanged when it fits.
103
+ */
104
+ export declare function fitUtf8(content: string, maxBytes: number): string;
105
+ /**
106
+ * Whether a draft says anything the gateway accepts: text, a rating or a category.
107
+ * @param draft - the draft.
108
+ * @returns true when it can be sent.
109
+ */
110
+ export declare function isSendable(draft: FeedbackDraft): boolean;
111
+ /**
112
+ * The body for a draft: only the fields the contract names, none of them empty; the attachment cut to its limit and
113
+ * then, if need be, to what the whole body allows.
114
+ * @param id - the idempotency key.
115
+ * @param draft - what the feedback says.
116
+ * @param client - which app sent it.
117
+ * @returns the body.
118
+ */
119
+ export declare function feedbackBody(id: string, draft: FeedbackDraft, client: FeedbackClient): FeedbackBody;
120
+ /**
121
+ * The same draft with its attachment cut to half (after the gateway refused the body as too large).
122
+ * @param body - the refused body.
123
+ * @param id - the new body's id (a changed body is a new upload).
124
+ * @returns the smaller body, or undefined when there is no attachment left to cut.
125
+ */
126
+ export declare function halveAttachment(body: FeedbackBody, id: string): FeedbackBody | undefined;
127
+ /** The size of a body on the wire. */
128
+ export declare function bodyBytes(body: FeedbackBody): number;
@@ -8,6 +8,21 @@
8
8
  * the returned upload headers when an upload is needed, `POST /{id}/complete`.
9
9
  * An asset the library already holds is read back through `/refresh`, which
10
10
  * also carries its measured duration.
11
+ *
12
+ * The gateway keeps one asset per account, purpose and digest
13
+ * (media/service.go CreateUpload): every upload of the same bytes is handed the
14
+ * same pending asset, the first PUT claims it, and the others are answered
15
+ * 409 `MEDIA_ASSET_NOT_READY` ("media upload is unavailable" on the PUT,
16
+ * "media upload is already in progress" on a later `uploads`). So inside the
17
+ * Host one upload of a file serves every caller that wants it at the same time
18
+ * (by purpose and digest), and a 409 from another process — or the coming
19
+ * `MEDIA_ASSET_UPLOAD_IN_PROGRESS` — means another upload of the same bytes is
20
+ * under way: the library waits for it (Retry-After, else 1 s doubling to 10 s,
21
+ * two minutes at most) by asking `uploads` again, which hands back the asset
22
+ * once it is ready, still answers 409 while it is not, and hands out a fresh
23
+ * upload when the other one ended without the file (failed or expired) — the
24
+ * library then uploads once more itself. `/refresh` cannot tell those apart (it
25
+ * answers 409 for a failed asset too).
11
26
  * @module dsh-vibedev/gateway/assets
12
27
  */
13
28
  import type { GatewayHttp } from './http.js';
@@ -34,28 +49,46 @@ export type AssetPurpose = 'video_reference' | 'audio_reference' | (string & {})
34
49
  * @returns the asset facts, or undefined when the answer names no usable URL.
35
50
  */
36
51
  export declare function parseAsset(body: unknown, fallbackType: string): Omit<UploadedAsset, 'sha256' | 'bytes'> | undefined;
52
+ /** Construction options; the sleep is a test seam. */
53
+ export interface MediaLibraryOptions {
54
+ /** Wait, ending early when the signal aborts. */
55
+ readonly sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
56
+ }
37
57
  /** Uploads references and remembers them for the life of the plugin. */
38
58
  export declare class MediaLibrary {
39
59
  private readonly http;
40
60
  private readonly now;
61
+ private readonly options;
41
62
  private readonly cache;
63
+ private readonly flights;
64
+ /** Bumped by {@link clear}: an upload of the previous account does not land in the cache. */
65
+ private generation;
42
66
  /**
43
67
  * @param http - the gateway client.
44
- * @param now - clock, for expiry checks.
68
+ * @param now - clock, for expiry checks and the wait for another upload.
69
+ * @param options - the sleep (a test seam).
45
70
  */
46
- constructor(http: GatewayHttp, now?: () => number);
71
+ constructor(http: GatewayHttp, now?: () => number, options?: MediaLibraryOptions);
47
72
  /** Forget every remembered asset, as after an account change: assets belong to the account that uploaded them. */
48
73
  clear(): void;
49
74
  /**
50
- * Upload one loaded input, or reuse the asset the library already holds.
75
+ * Upload one loaded input, or reuse the asset the library already holds. Callers that ask for the same file
76
+ * (purpose and digest) at the same time share one upload; one that gives up leaves it running for the others.
51
77
  * @param media - the loaded input.
52
78
  * @param purpose - the asset purpose.
53
- * @param signal - cancels the upload.
79
+ * @param signal - cancels this caller's wait (and the upload, once no caller waits on it).
54
80
  * @returns the asset.
55
81
  */
56
82
  upload(media: LoadedMedia, purpose: AssetPurpose, signal?: AbortSignal): Promise<UploadedAsset>;
83
+ /** Wait on a shared upload; giving up answers this caller at once and stops the upload when nobody else waits. */
84
+ private join;
85
+ /** Refresh a remembered asset about to expire, else upload the file — waiting for another upload of it when one is under way. */
86
+ private resolve;
87
+ /** `POST /uploads`: the asset when the library already holds the file, else the upload it hands out. */
88
+ private declare;
89
+ /** PUT the bytes where `uploads` said, then `complete`. */
90
+ private put;
57
91
  private expiring;
58
- private remember;
59
92
  private refresh;
60
93
  private read;
61
94
  }
@@ -158,6 +158,12 @@ export interface AudioReferenceLimits {
158
158
  readonly exclusiveWith?: readonly string[];
159
159
  /** The media-library purpose references are uploaded under, when the catalog names one. */
160
160
  readonly purpose?: string;
161
+ /**
162
+ * How each reference goes in `references`: `object` names its input, `{"audio_url": "<url>"}` — Seed's union of
163
+ * speaker, audio and image inputs, which a model declaring those inputs (`reference_audio_input`,
164
+ * `reference_image_input`, `speaker_input`) takes; `url` is the plain link, for a declaration without them.
165
+ */
166
+ readonly form: 'url' | 'object';
161
167
  }
162
168
  /** One output format a speech model can write, with the sample rates it takes in that format. */
163
169
  export interface AudioOutputFormat {
@@ -183,6 +189,11 @@ export interface AudioCapabilities {
183
189
  /** Declared choices for enumerated fields (`gender`, `genre`, …), under their wire names. */
184
190
  readonly choices?: Readonly<Record<string, readonly string[]>>;
185
191
  readonly maxPromptChars?: number;
192
+ /**
193
+ * The fields of an object watermark (`watermark: {"aigc_watermark": true}`), when the model declares the watermark
194
+ * that way (Seed's `watermark_fields`); absent, the watermark is a boolean.
195
+ */
196
+ readonly watermarkFields?: readonly string[];
186
197
  /** Transcription input limits. */
187
198
  readonly maxInputBytes?: number;
188
199
  readonly maxInputSeconds?: number;
@@ -13,6 +13,8 @@ export interface MediaErrorDetails {
13
13
  readonly retryable?: boolean;
14
14
  /** The request field the failure names, when the gateway says which. */
15
15
  readonly field?: string;
16
+ /** The rule that field broke (`unknown_field`, `too_long`, …), when the gateway says which. */
17
+ readonly rule?: string;
16
18
  /** Where the user tops up, on a balance refusal. */
17
19
  readonly rechargeUrl?: string;
18
20
  /** How long the gateway asked the client to wait. */
@@ -39,6 +41,8 @@ export interface MediaErrorDetails {
39
41
  readonly estimatedCny?: string;
40
42
  readonly availableCny?: string;
41
43
  readonly pendingCny?: string;
44
+ /** The media library asset a media-asset answer is about (`error.asset_id`). */
45
+ readonly assetId?: string;
42
46
  }
43
47
  /**
44
48
  * One failure, with a stable `code` to route on and a message to show. It is a
@@ -60,6 +64,7 @@ export interface GatewayFailure {
60
64
  readonly code?: string;
61
65
  readonly message?: string;
62
66
  readonly field?: string;
67
+ readonly rule?: string;
63
68
  readonly retryable?: boolean;
64
69
  readonly submissionState?: string;
65
70
  readonly retryAction?: string;
@@ -69,13 +74,15 @@ export interface GatewayFailure {
69
74
  readonly estimatedCny?: string;
70
75
  readonly availableCny?: string;
71
76
  readonly pendingCny?: string;
77
+ readonly assetId?: string;
72
78
  }
73
79
  /**
74
80
  * Read a gateway error body. The gateway answers in several shapes: OpenAI's
75
81
  * `{error:{code,message,type}}`, its own `{error:{code,message,retryable,field}}`,
76
- * the account API's `{code,message,reason}`, and a top-level `recharge_url` on
77
- * balance refusals. Media admission refusals add `active`/`limit` (task limit)
78
- * or `estimated_cny`/`available_cny`/`pending_cny` (balance).
82
+ * the account API's `{code,message,reason,metadata}` (a validation refusal names
83
+ * the field and the rule there: `metadata: {field, rule}`), and a top-level
84
+ * `recharge_url` on balance refusals. Media admission refusals add
85
+ * `active`/`limit` (task limit) or `estimated_cny`/`available_cny`/`pending_cny` (balance).
79
86
  * @param body - the parsed JSON body, or undefined when it was not JSON.
80
87
  * @returns the fields found.
81
88
  */
@@ -59,6 +59,18 @@ export interface GatewayRequest {
59
59
  }
60
60
  /** The message for a call made while nobody is signed in. */
61
61
  export declare const SIGN_IN_MESSAGE: string;
62
+ /**
63
+ * Wait, ending early (with {@link abortError}) when the signal aborts.
64
+ * @param ms - how long.
65
+ * @param signal - cancels the wait.
66
+ */
67
+ export declare function delay(ms: number, signal?: AbortSignal): Promise<void>;
68
+ /**
69
+ * The error a cancelled media request ends with.
70
+ * @param signal - the signal that aborted; its reason is the cause.
71
+ * @returns the error (`ABORTED`).
72
+ */
73
+ export declare function abortError(signal?: AbortSignal): MediaError;
62
74
  /** Gateway HTTP client. */
63
75
  export declare class GatewayHttp {
64
76
  private readonly options;
package/lib/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export { ACCOUNT_ROUTE_PREFIX, AccountService } from './account/index.js';
35
35
  export type { AccountSource, AccountView } from './account/index.js';
36
36
  export { LATENCY_ROUTE } from './account/latency.js';
37
37
  export type { LatencyErrorKind, LatencyResult } from './account/latency.js';
38
+ export { FEEDBACK_ATTACHMENT_ROUTE, FEEDBACK_ROUTE } from './feedback/index.js';
38
39
  export { GATEWAY_SEARCH_PROVIDER_ID as SEARCH_PROVIDER_ID } from './search/provider.js';
39
40
  export { INSUFFICIENT_BALANCE_CODE, SIGN_IN_REQUIRED_CODE, VIBEDEV_ROUTE } from './llm/index.js';
40
41
  /** The package version, sent in the `User-Agent` the gateway attributes plugin traffic by. */
@@ -48,7 +49,10 @@ export interface Config {
48
49
  preferredModels: string[];
49
50
  /** Open the system browser when a sign-in starts (off: the page opens the link itself). */
50
51
  openBrowserOnSignIn: boolean;
51
- /** Minutes between catalog reads while the app runs. */
52
+ /**
53
+ * Minutes between catalog reads while the app runs: the fallback that keeps the pickers current when nobody opens
54
+ * the balance card, the account menu or Settings (each of those reads the catalog too, at most once a minute).
55
+ */
52
56
  catalogRefreshMinutes: number;
53
57
  /** Ask the user before each paid request. */
54
58
  confirmSpending: Volatile<boolean>;