@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
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The gateway Fetch registration a profile selects as `web.fetchProvider:
3
+ * vibedev-gateway`: the signed-in account's advertised `web-fetch-v1`
4
+ * capability decides between extracted content and the local HTTP provider the
5
+ * host has mounted.
6
+ *
7
+ * One fetch is bound to the account and gateway it started under: it reads the
8
+ * VibeDev user id and the gateway origin once, re-reads both after the
9
+ * capability, after the credential, before the POST and after a renewal, and
10
+ * ends with `ACCOUNT_CHANGED` when either moved. A credential is only ever
11
+ * taken from the same account read that proves the user id it is checked
12
+ * against, so another account's token cannot be paired with this operation
13
+ * even while the account changes hands around those reads. It also spends one
14
+ * total client deadline across the identity read, the capability read, the
15
+ * credential, the POST, a renewal and the local fallback, so no stage can
16
+ * restart the budget.
17
+ *
18
+ * The host still owns selection. A profile pinned to `http` never reaches this
19
+ * provider; a profile pinned to `vibedev-gateway` gets the host's own mounted
20
+ * fetch provider when the account definitely advertises no such capability —
21
+ * never a copy built from defaults, and a host that mounts none fails with a
22
+ * named error instead of a silent local fetch. A failed or refused capability
23
+ * read is an error: it is never read as absence, and no supplier, budget or
24
+ * policy refusal falls back.
25
+ * @module dsh-vibedev/fetch/wiring
26
+ */
27
+ import type { WebFetchProvider, WebFetchRequest, WebFetchResult } from '@deepseek-ai/dsh-web';
28
+ import type { AccountIdentity } from '../account/index.js';
29
+ import type { GatewayCredential } from '../gateway/http.js';
30
+ /** Stable id the provider registers under; a profile selects it as `web.fetchProvider`. */
31
+ export declare const GATEWAY_FETCH_PROVIDER_ID = "vibedev-gateway";
32
+ /** One operation's capability request, handed to the account's entitlement reader. */
33
+ export interface GatewayFetchCapabilityRequest {
34
+ /** Bounds this read, including a re-read after a 401. */
35
+ readonly signal?: AbortSignal;
36
+ /** Whether the operation's account is still current, checked by the reader before each send. */
37
+ readonly isCurrentAccount?: () => Promise<boolean>;
38
+ /** The operation-bound credential: read together with the account it is verified against, and re-read the same way. */
39
+ readonly resolveCredential: () => Promise<GatewayCredential | undefined>;
40
+ }
41
+ /** What the registration needs from the plugin. */
42
+ export interface GatewayFetchWiringOptions {
43
+ /** Read the gateway origin in effect; it heads the account-scoped entitlement key, and a change ends an operation. */
44
+ readonly origin: () => string;
45
+ /** `User-Agent` sent to the gateway. */
46
+ readonly userAgent: string;
47
+ /** Who is signed in now; one read supplies both the credential and the `userId` it belongs to. */
48
+ readonly identity: () => Promise<AccountIdentity>;
49
+ /**
50
+ * `GatewayHttp.entitlements`: one account-scoped capability snapshot per scope. The request carries this operation's
51
+ * bound credential and account guard, so the reader cannot send, or re-read after a 401, another account's token.
52
+ */
53
+ readonly entitlements: (scope: string, request: GatewayFetchCapabilityRequest) => Promise<unknown>;
54
+ /** Renew a credential the gateway itself rejected, so its owner can refresh it. */
55
+ readonly rejectCredential: (credential: GatewayCredential) => Promise<void>;
56
+ /**
57
+ * Read the local provider the host has mounted right now; asked only when the account advertises no capability. It
58
+ * answers the live registration, so a host that reloads its `http` provider with other limits is followed without
59
+ * the plugin holding a copy. Omitted together with `local` when the host cannot hand its provider to plugins (an
60
+ * official DSH host has no `getFetchProvider`): the fallback then fails with `WEB_FETCH_LOCAL_PROVIDER_UNREACHABLE`.
61
+ */
62
+ readonly resolveLocal?: () => WebFetchProvider | undefined;
63
+ /** An explicitly supplied local provider (tests and direct consumers); it wins over {@link GatewayFetchWiringOptions.resolveLocal}. */
64
+ readonly local?: WebFetchProvider;
65
+ /** Total client deadline for one fetch; the documented 40 s when omitted. */
66
+ readonly timeoutMs?: number;
67
+ /**
68
+ * The registration owner's lifetime. Aborting it — the plugin fiber unloading, a gateway or configuration reload —
69
+ * ends every operation this registration is running without a resend; a replacement registration gets its own.
70
+ */
71
+ readonly owner?: AbortSignal;
72
+ }
73
+ /** `vibedev-gateway`: gateway extraction when advertised, the host's local fetch only when definitely absent. */
74
+ export declare class GatewayFetchWiring implements WebFetchProvider {
75
+ private readonly options;
76
+ readonly id = "vibedev-gateway";
77
+ /**
78
+ * @param options - account, credential, gateway and local-provider dependencies.
79
+ */
80
+ constructor(options: GatewayFetchWiringOptions);
81
+ /** Always usable: a missing account or capability fails with a named error, never as an unselected provider. */
82
+ available(): boolean;
83
+ /**
84
+ * Fetch through the advertised gateway lane, or through the local provider
85
+ * when the account advertises no `web-fetch-v1`.
86
+ * @param request - the URL to retrieve.
87
+ * @param caller - cancels the client wait; the supplier outcome is never promised.
88
+ * @returns the gateway extraction or the local HTTP result.
89
+ */
90
+ fetch(request: WebFetchRequest, caller?: AbortSignal): Promise<WebFetchResult>;
91
+ /**
92
+ * Run one account-bound operation under the fetch's total signal.
93
+ * @param request - the URL to retrieve.
94
+ * @param signal - the operation's deadline and cancellation.
95
+ * @returns the extraction or the local result.
96
+ */
97
+ private operate;
98
+ /**
99
+ * The provider that takes over a fetch the gateway does not cover: the host's mounted local provider at the moment
100
+ * the capability is found absent (or the explicitly supplied one), never a copy built from defaults.
101
+ * @returns the provider the negotiation delegates to, resolving the host's current registration when it is called.
102
+ */
103
+ private fallback;
104
+ /** Read the account and gateway this fetch runs under; a signed-out or unidentified account has its own error. */
105
+ private startedIdentity;
106
+ /**
107
+ * One identity read supplies both the credential and the user id, so the two cannot disagree; it is accepted only
108
+ * for the account and gateway this fetch started under.
109
+ * @param started - the account and gateway the operation was bound to.
110
+ * @returns the verified credential and the user it belongs to.
111
+ */
112
+ private currentIdentity;
113
+ /**
114
+ * End the operation unless the same account is still signed in on the same gateway.
115
+ * @param started - the account and gateway the operation was bound to.
116
+ */
117
+ private sameIdentity;
118
+ /**
119
+ * The credential for one request of this operation, taken from the identity that is verified against it.
120
+ * @param started - the account and gateway the operation was bound to.
121
+ * @returns the credential of the verified identity.
122
+ */
123
+ private verifiedCredential;
124
+ }
@@ -7,6 +7,14 @@
7
7
  import { HarnessError } from '@deepseek-ai/dsh-llm';
8
8
  /** Machine-readable detail carried next to the message. */
9
9
  export interface MediaErrorDetails {
10
+ readonly category?: string;
11
+ readonly stage?: string;
12
+ readonly requestId?: string;
13
+ readonly taskId?: string;
14
+ readonly operationId?: string;
15
+ readonly retryAt?: string;
16
+ readonly retryAfterSeconds?: number;
17
+ readonly billingState?: string;
10
18
  /** HTTP status when the gateway answered. */
11
19
  readonly status?: number;
12
20
  /** Whether the same request may succeed later. */
@@ -19,7 +27,7 @@ export interface MediaErrorDetails {
19
27
  readonly rechargeUrl?: string;
20
28
  /** How long the gateway asked the client to wait. */
21
29
  readonly retryAfterMs?: number;
22
- /** The gateway was full and created nothing (a busy 429/503). */
30
+ /** The gateway reported busy; this alone proves no submission or billing outcome. */
23
31
  readonly busy?: boolean;
24
32
  /**
25
33
  * The gateway's structured submission state: `rejected` (the provider refused
@@ -59,8 +67,23 @@ export declare class MediaError extends HarnessError {
59
67
  */
60
68
  constructor(message: string, code: string, details?: MediaErrorDetails, options?: ErrorOptions);
61
69
  }
70
+ /** Only for local validators executed before media creation; never wrap gateway or dispatch errors. */
71
+ export declare function localInputError(message: string, code: string, details?: Pick<MediaErrorDetails, 'field' | 'rule'>): MediaError;
72
+ /** Unknown submission codes outrank weaker provider/service categories. */
73
+ export declare function normalizeErrorCategory(value: string | undefined, code?: string): string | undefined;
74
+ /** An unknown stage is omitted rather than exposing a provider's private vocabulary. */
75
+ export declare function normalizeErrorStage(value: string | undefined): string | undefined;
62
76
  /** The parts of a gateway error body the plugin reads, whatever its shape. */
63
77
  export interface GatewayFailure {
78
+ readonly gatewayCode?: string;
79
+ readonly category?: string;
80
+ readonly stage?: string;
81
+ readonly requestId?: string;
82
+ readonly taskId?: string;
83
+ readonly operationId?: string;
84
+ readonly retryAt?: string;
85
+ readonly retryAfterSeconds?: number;
86
+ readonly billingState?: string;
64
87
  readonly code?: string;
65
88
  readonly message?: string;
66
89
  readonly field?: string;
@@ -96,3 +119,8 @@ export declare function parseGatewayFailure(body: unknown): GatewayFailure;
96
119
  export declare function retryAfterMs(header: string | null, now?: number): number | undefined;
97
120
  /** `(CODE: message)`, for appending the gateway's own words to a message. */
98
121
  export declare function gatewayWords(failure: GatewayFailure): string;
122
+ /** One safe presentation for HTTP, SDK finishes and asynchronous task errors. */
123
+ export declare function safeGatewayMessage(failure: GatewayFailure): string;
124
+ export declare function gatewayFailureWithHeaders(body: unknown, headers: Headers): GatewayFailure;
125
+ export declare function isUserAuthenticationFailure(failure: GatewayFailure): boolean;
126
+ export declare function sdkGatewayFailure(message: string, headers?: Readonly<Record<string, string>>): GatewayFailure | undefined;
@@ -39,6 +39,14 @@ export interface GatewayHttpOptions {
39
39
  }
40
40
  /** One request. */
41
41
  export interface GatewayRequest {
42
+ /** Rechecked after credential resolution, before every send and before a rejected credential is renewed. */
43
+ readonly isCurrentAccount?: () => Promise<boolean>;
44
+ /**
45
+ * Resolve this request's credential instead of the client's default plane. The gateway Fetch registration uses it
46
+ * to hand out only a credential read together with the account it was verified against: every first read and every
47
+ * re-read after a 401 goes through it. Omitted, the client's own resolver serves every request as before.
48
+ */
49
+ readonly resolveCredential?: () => Promise<GatewayCredential | undefined>;
42
50
  readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
43
51
  /** JSON body; serialized with `content-type: application/json`. */
44
52
  readonly json?: unknown;
@@ -75,6 +83,16 @@ export declare function abortError(signal?: AbortSignal): MediaError;
75
83
  export declare class GatewayHttp {
76
84
  private readonly options;
77
85
  readonly origin: string;
86
+ /** One capability snapshot; `bound` marks a read whose own credential was verified against the scope. */
87
+ private readonly snapshots;
88
+ invalidateAccountSnapshots(): void;
89
+ /**
90
+ * One Host-only capability snapshot shared by quotes and the account bridge. A request that supplies its own
91
+ * operation-bound credential (`resolveCredential`) is served only a snapshot a scoped read created: an ordinary
92
+ * read's answer was verified by its caller's guard alone and can belong to another account after an account
93
+ * change, so it must not decide a bounded operation's capability.
94
+ */
95
+ entitlements(scope: string, request?: GatewayRequest, fresh?: boolean): Promise<unknown>;
78
96
  /**
79
97
  * @param options - origin, credential plane, user agent and test seams.
80
98
  */
@@ -98,6 +116,12 @@ export declare class GatewayHttp {
98
116
  * @returns the parsed body.
99
117
  */
100
118
  json<T = unknown>(path: string, request?: GatewayRequest): Promise<T>;
119
+ /**
120
+ * Read the credential one request carries, through the request's resolver when it has one.
121
+ * @param resolve - the request's scoped resolver, else the client's default credential plane.
122
+ * @returns the credential.
123
+ * @throws {@link MediaError} `NOT_SIGNED_IN` when no credential is available.
124
+ */
101
125
  private credential;
102
126
  private attempt;
103
127
  }
@@ -0,0 +1,4 @@
1
+ /** Host callers do not carry the UI locale. Use English by default; both shipped dictionaries remain available. */
2
+ import en from '../locale/en.json';
3
+ export type HostMessageKey = keyof typeof en.mediaErrors;
4
+ export declare function hostMessage(key: HostMessageKey, locale?: 'en' | 'zh'): string;
package/lib/index.d.ts CHANGED
@@ -31,6 +31,7 @@ export type { AudioForm, AudioFormField, AudioMakeKind, AudioRequest } from './a
31
31
  export type { AudioQuote, Bilingual, VideoLegacyEstimate, VideoQuote, VideoQuoteReason, VideoQuoteRequest, VideoQuoteRule, VideoQuoteUnavailable, VideoTokenEstimate, } from './pricing.js';
32
32
  export type { ImageRequest } from './tools/image.js';
33
33
  export type { VideoRequest } from './tools/video.js';
34
+ export type { MediaAccountContext, AccountCenterPage, SafeTaskError } from './contracts.js';
34
35
  export { parseMediaCatalog } from './gateway/catalog.js';
35
36
  export type { AudioCapabilities, AudioGenerationKind, MediaModel, PriceUnit, VideoCapabilities, VideoMode, VideoPricingIssue, VideoTokenPricing, VideoTokenRule, } from './gateway/catalog.js';
36
37
  export { ACCOUNT_ROUTE_PREFIX, AccountService } from './account/index.js';
@@ -39,6 +40,9 @@ export { LATENCY_ROUTE } from './account/latency.js';
39
40
  export type { LatencyErrorKind, LatencyResult } from './account/latency.js';
40
41
  export { FEEDBACK_ATTACHMENT_ROUTE, FEEDBACK_ROUTE } from './feedback/index.js';
41
42
  export { GATEWAY_SEARCH_PROVIDER_ID as SEARCH_PROVIDER_ID } from './search/provider.js';
43
+ export { GATEWAY_FETCH_PROVIDER_ID as FETCH_PROVIDER_ID } from './fetch/wiring.js';
44
+ export { GatewayFetchProvider, NegotiatedGatewayFetchProvider, readGatewayFetchCapability } from './fetch/provider.js';
45
+ export type { GatewayFetchCapability, GatewayFetchOptions, GatewayExtractionResult, NegotiatedGatewayFetchOptions } from './fetch/provider.js';
42
46
  export { INSUFFICIENT_BALANCE_CODE, SIGN_IN_REQUIRED_CODE, VIBEDEV_ROUTE, VIBEDEV_RELAY_ROUTE } from './llm/index.js';
43
47
  /** The package version, sent in the `User-Agent` the gateway attributes plugin traffic by. */
44
48
  export declare const version: string;
@@ -60,6 +64,12 @@ export interface Config {
60
64
  * the balance card, the account menu or Settings (each of those reads the catalog too, at most once a minute).
61
65
  */
62
66
  catalogRefreshMinutes: number;
67
+ /** Same-key media submission recovery window; applies only to newly created operations. */
68
+ resendWindowMs: number;
69
+ /** Initial same-key attempts, including the first dispatch. */
70
+ submitAttempts: number;
71
+ /** Additional background same-key checks; zero disables background POST reconciliation. */
72
+ reconcileAttempts: number;
63
73
  /** Ask the user before each paid request. */
64
74
  confirmSpending: Volatile<boolean>;
65
75
  /** Output folder, relative to the workspace (or absolute). */
@@ -77,6 +87,11 @@ export interface Config {
77
87
  client: string;
78
88
  /** The VibeDev account is the app's main account: its row leads the sidebar foot and Settings (the VibeDev app). */
79
89
  primary: boolean;
90
+ /**
91
+ * Register the gateway's extracted-content Fetch as the provider `vibedev-gateway`. Registration does not select
92
+ * it: the host keeps its own fetch unless a profile sets `web.fetchProvider: vibedev-gateway`.
93
+ */
94
+ gatewayFetch: boolean;
80
95
  /** Environment variable holding a development key, used only while nobody is signed in. */
81
96
  apiKeyEnv: string;
82
97
  /** Where tasks and the plugin's own sign-in are kept; empty for `<harness home>/dsh-media`. */
@@ -89,6 +104,9 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
89
104
  preferredModels: Schema<string[], string[], "defined">;
90
105
  openBrowserOnSignIn: Schema<boolean, boolean, "defined">;
91
106
  catalogRefreshMinutes: Schema<number, number, "defined">;
107
+ resendWindowMs: Schema<number, number, "defined">;
108
+ submitAttempts: Schema<number, number, "defined">;
109
+ reconcileAttempts: Schema<number, number, "defined">;
92
110
  confirmSpending: Schema<boolean, boolean, "volatile-defined">;
93
111
  outputDir: Schema<string, string, "volatile-defined">;
94
112
  imageModel: Schema<string, string, "volatile-defined">;
@@ -100,6 +118,7 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
100
118
  gatewayOrigin: Schema<string, string, "defined">;
101
119
  client: Schema<string, string, "defined">;
102
120
  primary: Schema<boolean, boolean, "defined">;
121
+ gatewayFetch: Schema<boolean, boolean, "defined">;
103
122
  apiKeyEnv: Schema<string, string, "defined">;
104
123
  stateDir: Schema<string, string, "defined">;
105
124
  }>>, Schemastery.ObjectT<NoInfer<{
@@ -109,6 +128,9 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
109
128
  preferredModels: Schema<string[], string[], "defined">;
110
129
  openBrowserOnSignIn: Schema<boolean, boolean, "defined">;
111
130
  catalogRefreshMinutes: Schema<number, number, "defined">;
131
+ resendWindowMs: Schema<number, number, "defined">;
132
+ submitAttempts: Schema<number, number, "defined">;
133
+ reconcileAttempts: Schema<number, number, "defined">;
112
134
  confirmSpending: Schema<boolean, boolean, "volatile-defined">;
113
135
  outputDir: Schema<string, string, "volatile-defined">;
114
136
  imageModel: Schema<string, string, "volatile-defined">;
@@ -120,6 +142,7 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
120
142
  gatewayOrigin: Schema<string, string, "defined">;
121
143
  client: Schema<string, string, "defined">;
122
144
  primary: Schema<boolean, boolean, "defined">;
145
+ gatewayFetch: Schema<boolean, boolean, "defined">;
123
146
  apiKeyEnv: Schema<string, string, "defined">;
124
147
  stateDir: Schema<string, string, "defined">;
125
148
  }>>, "plain">;