@vibedev-si/dsh-vibedev 0.3.11 → 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 (46) hide show
  1. package/README.md +122 -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 +13 -0
  20. package/lib/index.js +2808 -412
  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 +36 -9
  25. package/lib/tasks/remote.d.ts +4 -4
  26. package/lib/tasks/store.d.ts +54 -9
  27. package/lib/tasks/tracker.d.ts +45 -45
  28. package/lib/tools/image.d.ts +1 -0
  29. package/lib/tools/video.d.ts +3 -0
  30. package/lib/util/files.d.ts +2 -0
  31. package/locale/en.json +13 -0
  32. package/locale/zh.json +13 -0
  33. package/node_modules/@vibedev-si/dsh-ecosystem/LICENSE +22 -0
  34. package/node_modules/@vibedev-si/dsh-ecosystem/README.md +154 -0
  35. package/node_modules/@vibedev-si/dsh-ecosystem/catalog/catalog.json +167 -0
  36. package/node_modules/@vibedev-si/dsh-ecosystem/catalog-updates.js +326 -0
  37. package/node_modules/@vibedev-si/dsh-ecosystem/catalog-validator.js +263 -0
  38. package/node_modules/@vibedev-si/dsh-ecosystem/client.js +2816 -0
  39. package/node_modules/@vibedev-si/dsh-ecosystem/cordis.patch.yml +5 -0
  40. package/node_modules/@vibedev-si/dsh-ecosystem/icon.svg +5 -0
  41. package/node_modules/@vibedev-si/dsh-ecosystem/index.js +169 -0
  42. package/node_modules/@vibedev-si/dsh-ecosystem/locale/en.json +6 -0
  43. package/node_modules/@vibedev-si/dsh-ecosystem/locale/zh.json +6 -0
  44. package/node_modules/@vibedev-si/dsh-ecosystem/package.json +75 -0
  45. package/node_modules/@vibedev-si/dsh-ecosystem/remote-catalog.js +212 -0
  46. package/package.json +12 -1
package/cordis.patch.yml CHANGED
@@ -3,3 +3,8 @@
3
3
  - insert:
4
4
  - id: dsh-vibedev
5
5
  name: '@vibedev-si/dsh-vibedev'
6
+ # An explicit ecosystem row (including a disabled one) owns its configuration.
7
+ # Read full group data so the result does not depend on plugin load order.
8
+ - id: vibedev-ecosystem-companion
9
+ name: '@vibedev-si/dsh-ecosystem'
10
+ disabled: !!js "!!ctx.get('loader') && [...ctx.get('loader').entries()].some(entry => { const contains = rows => rows.some(row => row.id !== 'vibedev-ecosystem-companion' && row.name === '@vibedev-si/dsh-ecosystem' || row.group && Array.isArray(row.config) && contains(row.config)); return contains(entry.parent.data); })"
@@ -0,0 +1,22 @@
1
+ /** Fixed native account reads/actions; no renderer-selected URL or method. */
2
+ export declare const BUSINESS_READ_PATHS: readonly ["payment/config", "payment/checkout-info", "payment/plans", "payment/limits", "payment/orders/my", "payment/orders/detail", "payment/orders/refund-eligible-providers", "redeem/history", "affiliate", "profile", "actions/status"];
3
+ export type BusinessReadPath = typeof BUSINESS_READ_PATHS[number];
4
+ export declare const BUSINESS_ACTIONS: readonly ["payment/create", "payment/cancel", "payment/refund", "payment/verify", "redeem/apply", "affiliate/refresh", "affiliate/transfer", "profile/update"];
5
+ export type BusinessActionKind = typeof BUSINESS_ACTIONS[number];
6
+ export interface ParsedBusinessAction {
7
+ wire: string;
8
+ method: 'POST' | 'PUT';
9
+ payload: Record<string, unknown>;
10
+ }
11
+ export declare const validOperationId: (value: unknown) => value is string;
12
+ /** HTTPS payment links are server-issued; QR payment schemes are never navigated automatically. */
13
+ export declare function safeBusinessUrl(value: unknown, qr?: boolean): string | undefined;
14
+ export declare function safeAvatarUrl(value: unknown): string | undefined;
15
+ export declare function businessQuery(path: BusinessReadPath, params: URLSearchParams): {
16
+ wire: string;
17
+ query: URLSearchParams;
18
+ fresh: boolean;
19
+ } | undefined;
20
+ export declare function validateBusinessAction(kind: BusinessActionKind, body: unknown): ParsedBusinessAction | undefined;
21
+ export declare function projectBusinessRead(path: BusinessReadPath, value: unknown): unknown;
22
+ export declare function projectBusinessReceipt(value: unknown): unknown;
@@ -0,0 +1,6 @@
1
+ import type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';
2
+ import type { AccountService } from './index.js';
3
+ import type { GatewayHttp } from '../gateway/http.js';
4
+ /** The buffered wire body must be unambiguous before it is canonicalized and fingerprinted. */
5
+ export declare function uniqueBusinessJson(raw: string): unknown;
6
+ export declare function accountBusinessActionsRoutes(http: GatewayHttp, account: AccountService): ConnectionFetchRoute[];
@@ -0,0 +1,12 @@
1
+ export declare const CENTER_READ_PATHS: readonly ["auth/me", "usage", "usage/dashboard/stats", "usage/dashboard/trend", "usage/dashboard/models", "subscriptions/summary", "entitlements", "usage/stats", "usage/details", "usage/errors", "usage/errors/detail", "usage/dashboard/snapshot-v2", "groups/available", "user/platform-quotas", "subscriptions", "subscriptions/progress", "model-plaza", "channel-monitor-v2/dimensions", "channel-monitor-v2/snapshot", "channel-monitor-v2/models", "channel-monitor-v2/matrix", "channel-monitor-v2/errors", "channel-monitors/status", "channel-monitors/detail", "payment/config", "payment/checkout-info", "payment/plans", "payment/limits", "payment/orders/my", "payment/orders/detail", "payment/orders/refund-eligible-providers", "redeem/history", "affiliate", "profile", "actions/status"];
2
+ export type CenterReadPath = typeof CENTER_READ_PATHS[number];
3
+ export declare function positiveCenterId(value: string): boolean;
4
+ /** Returns undefined for any unsupported/duplicate/invalid parameter. */
5
+ export declare function centerQuery(path: CenterReadPath, params: URLSearchParams): {
6
+ wire: string;
7
+ query: URLSearchParams;
8
+ fresh: boolean;
9
+ } | undefined;
10
+ /** Legacy summary only: monetary weekly fields become a percentage, never a five-hour window. */
11
+ export declare function projectAccountData(value: unknown): unknown;
12
+ export declare function projectCenterRoute(path: CenterReadPath, value: unknown): unknown;
@@ -0,0 +1,10 @@
1
+ /** Fixed, authenticated monitor reads. This projection also protects admin AppTokens. */
2
+ export declare const MONITOR_READ_PATHS: readonly ["channel-monitor-v2/dimensions", "channel-monitor-v2/snapshot", "channel-monitor-v2/models", "channel-monitor-v2/matrix", "channel-monitor-v2/errors", "channel-monitors/status", "channel-monitors/detail"];
3
+ export type MonitorReadPath = typeof MONITOR_READ_PATHS[number];
4
+ export declare function projectMonitorRoute(path: string, value: unknown): unknown;
5
+ /** Repeated dimensions are retained; scalar duplicates and caller-selected scopes fail closed. */
6
+ export declare function validateMonitorQuery(path: string, params: URLSearchParams): {
7
+ wire: string;
8
+ query: URLSearchParams;
9
+ fresh: boolean;
10
+ } | undefined;
@@ -0,0 +1,5 @@
1
+ /** Only public DNS HTTPS references become navigable links. No credentials, IPs or local hosts. */
2
+ export declare function publicReferenceUrl(value: unknown): string | undefined;
3
+ export declare function projectModelPlaza(value: unknown): unknown;
4
+ /** Duplicate, unknown, identity and unbounded catalog filters fail closed. */
5
+ export declare function validateModelPlazaQuery(params: URLSearchParams): URLSearchParams | undefined;
@@ -0,0 +1,7 @@
1
+ /** Read-only, field-allowlisted Host bridge. Credentials never enter the client response. */
2
+ import type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';
3
+ import type { AccountService } from './index.js';
4
+ import type { GatewayHttp } from '../gateway/http.js';
5
+ export { CENTER_READ_PATHS, projectAccountData } from './center-contract.js';
6
+ export declare const CENTER_PREFIX = "/api/dsh-vibedev/account-center";
7
+ export declare function accountCenterRoutes(http: GatewayHttp, account: AccountService): ConnectionFetchRoute[];
@@ -28,12 +28,19 @@ import type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';
28
28
  import type { CredentialChain } from '../auth/credentials.js';
29
29
  import type { PluginLogin, SignInAttempt } from '../auth/login.js';
30
30
  import type { GatewayCredential } from '../gateway/http.js';
31
+ import type { AccountCenterPage } from '../contracts.js';
31
32
  /** Path prefix of the plugin's Host routes. */
32
33
  export declare const ACCOUNT_ROUTE_PREFIX = "/api/dsh-vibedev/account";
33
34
  /** Where the active credential comes from. */
34
35
  export type AccountSource = 'host' | 'plugin' | 'key' | 'none';
35
36
  /** What the account pages render. */
36
37
  export interface AccountView {
38
+ readonly accountCenter?: {
39
+ readonly id: string;
40
+ readonly page: AccountCenterPage;
41
+ readonly revision: number;
42
+ readonly expiresAt: number;
43
+ };
37
44
  readonly source: AccountSource;
38
45
  /** The signed-in person, when known. */
39
46
  readonly user?: {
@@ -111,6 +118,9 @@ export interface AccountServiceOptions {
111
118
  readonly refreshCatalog?: () => Promise<void>;
112
119
  /** Present the VibeDev account as the app's main account. */
113
120
  readonly primary?: boolean;
121
+ /** A stable user became known after startup or an account change. */
122
+ readonly identityAvailable?: (userId: string) => void;
123
+ readonly identityInvalidated?: () => void;
114
124
  readonly fetch?: typeof globalThis.fetch;
115
125
  readonly now?: () => number;
116
126
  /** Timer seams for the reads after a charge and the long poll. */
@@ -120,6 +130,10 @@ export interface AccountServiceOptions {
120
130
  /** The account state behind the pages. */
121
131
  export declare class AccountService {
122
132
  private readonly options;
133
+ private announcedUserId?;
134
+ private navigation;
135
+ openAccountCenter(page?: AccountCenterPage): void;
136
+ consumeNavigation(id: string): boolean;
123
137
  private balanceCache;
124
138
  /** A background read of a stale balance, so only one runs at a time. */
125
139
  private revalidating;
@@ -798,7 +798,7 @@ function redactSensitive(body) {
798
798
  */
799
799
  async function checkCredentialsFileSafety(path, onWarn = (m) => console.warn(`anthropic-sdk: ${m}`)) {
800
800
  if (typeof process === "undefined" || process.platform === "win32") return;
801
- const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
801
+ const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
802
802
  let resolved = path;
803
803
  let st;
804
804
  try {
@@ -818,7 +818,7 @@ async function checkCredentialsFileSafety(path, onWarn = (m) => console.warn(`an
818
818
  * Creates the parent directory with mode 0700 and the file with mode 0600.
819
819
  */
820
820
  async function writeCredentialsFileAtomic(targetPath, data) {
821
- const { fs, path } = await import("./node-Br-0fshF.js").then((n) => n.i);
821
+ const { fs, path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
822
822
  const dir = path.dirname(targetPath);
823
823
  await fs.promises.mkdir(dir, {
824
824
  recursive: true,
@@ -1128,7 +1128,7 @@ const loadConfigWithSource = async (profile) => {
1128
1128
  const profileName = profile ?? await getActiveProfileName();
1129
1129
  if (profileName === null) return null;
1130
1130
  validateProfileName(profileName);
1131
- const { fs, path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1131
+ const { fs, path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1132
1132
  const configPath = path.join(rootConfigPath, "configs", `${profileName}.json`);
1133
1133
  let configRaw;
1134
1134
  try {
@@ -1205,12 +1205,12 @@ const getCredentialsPath = async (config, profile) => {
1205
1205
  const profileName = profile ?? await getActiveProfileName();
1206
1206
  if (!profileName) return null;
1207
1207
  validateProfileName(profileName);
1208
- const { path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1208
+ const { path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1209
1209
  return path.join(rootConfigPath, "credentials", `${profileName}.json`);
1210
1210
  };
1211
1211
  const getRootConfigPath = async () => {
1212
1212
  if (!supportsLocalConfigFiles()) return null;
1213
- const { path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1213
+ const { path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1214
1214
  const configDir = readEnv("ANTHROPIC_CONFIG_DIR");
1215
1215
  if (configDir) return configDir;
1216
1216
  if (getPlatformHeaders()["X-Stainless-OS"] === "Windows") {
@@ -1235,7 +1235,7 @@ const getActiveProfileName = async () => {
1235
1235
  if (!rootConfigPath) return null;
1236
1236
  const profileName = readEnv("ANTHROPIC_PROFILE");
1237
1237
  if (profileName) return profileName;
1238
- const { fs, path } = await import("./node-Br-0fshF.js").then((n) => n.i);
1238
+ const { fs, path } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1239
1239
  const filePath = path.join(rootConfigPath, "active_config");
1240
1240
  try {
1241
1241
  return (await fs.promises.readFile(filePath, "utf-8")).trim() || "default";
@@ -1253,7 +1253,7 @@ const getActiveProfileName = async () => {
1253
1253
  function identityTokenFromFile(path) {
1254
1254
  if (!path) throw new AnthropicError("Identity token file path is empty");
1255
1255
  return async () => {
1256
- const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
1256
+ const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1257
1257
  let content;
1258
1258
  try {
1259
1259
  content = await fs.promises.readFile(path, "utf-8");
@@ -1341,7 +1341,7 @@ function oidcFederationProvider(config) {
1341
1341
  */
1342
1342
  function userOAuthProvider(config) {
1343
1343
  return async (opts) => {
1344
- const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
1344
+ const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1345
1345
  await checkCredentialsFileSafety(config.credentialsPath, config.onSafetyWarning);
1346
1346
  let raw;
1347
1347
  try {
@@ -1518,7 +1518,7 @@ function resolveIdentityTokenProvider(auth) {
1518
1518
  */
1519
1519
  function cachedExchangeProvider(exchange, credentialsPath, onCacheWriteError, onSafetyWarning) {
1520
1520
  return async (opts) => {
1521
- const { fs } = await import("./node-Br-0fshF.js").then((n) => n.i);
1521
+ const { fs } = await import("./node-vkDR3GtK.js").then((n) => n.i);
1522
1522
  await checkCredentialsFileSafety(credentialsPath, onSafetyWarning);
1523
1523
  let existing;
1524
1524
  try {
@@ -5211,7 +5211,7 @@ _EnvironmentWorker_signal = /* @__PURE__ */ new WeakMap(), _EnvironmentWorker_in
5211
5211
  const ctrl = new AbortController();
5212
5212
  const detachExternal = linkAbort(externalSignal, ctrl);
5213
5213
  const lease = new Lease(ctrl);
5214
- const agentToolset = await import("./node-D58f7Ea6.js");
5214
+ const agentToolset = await import("./node-CcLPV4RA.js");
5215
5215
  let leaseTtlMs;
5216
5216
  let runner;
5217
5217
  const heartbeatPromise = heartbeatLoop(sessionClient, work, lease, log, this.requestOptions, (ttlMs) => {
@@ -13469,4 +13469,4 @@ function mapStopReason(reason, stopDetails) {
13469
13469
  //#endregion
13470
13470
  export { checkMemorySyncInterval as a, decodeUTF8 as c, AnthropicError as d, __classPrivateFieldGet as f, MIN_MEMORY_SYNC_INTERVAL_MS as i, encodeUTF8 as l, promiseWithResolvers as n, isStatus as o, __classPrivateFieldSet as p, DEFAULT_MEMORY_SYNC_INTERVAL_MS as r, loggerFor as s, stream, streamSimple, anthropic_messages_exports as t, ToolError as u };
13471
13471
 
13472
- //# sourceMappingURL=anthropic-messages-BgIfgjNt.js.map
13472
+ //# sourceMappingURL=anthropic-messages-QcnVMGaA.js.map
@@ -0,0 +1,134 @@
1
+ /** Wire types for CONTRACT-V1.md. Synthetic fixtures are not live capabilities. */
2
+ export type Capability = 'errors-v1' | 'account-center-read-v1' | 'account-center-write-v1' | 'web-session-v1' | 'media-quotes-v1' | 'image-idempotency-v1' | 'subscription-billing-v1';
3
+ export type DecimalAmount = string;
4
+ export type ErrorCategory = 'authentication' | 'access_restricted' | 'billing' | 'model_unavailable' | 'invalid_input' | 'content_rejected' | 'rate_limited' | 'service_unavailable' | 'submission_uncertain' | 'internal_error';
5
+ export type Stage = 'auth' | 'catalog' | 'quote' | 'upload' | 'submit' | 'poll' | 'generation' | 'download' | 'settle';
6
+ export type SubmissionState = 'not_submitted' | 'submitting' | 'accepted' | 'unknown' | 'rejected';
7
+ export type BillingState = 'not_charged' | 'reserved' | 'settled' | 'released' | 'unknown';
8
+ export type RetryAction = 'none' | 'retry_same_key' | 'reconcile' | 'poll' | 'download' | 'modify_input' | 'reauthenticate';
9
+ export interface GatewayError {
10
+ type: string;
11
+ code: string;
12
+ gateway_code: string;
13
+ category: ErrorCategory;
14
+ message: string;
15
+ stage: Stage;
16
+ request_id: string;
17
+ task_id: string | null;
18
+ operation_id?: string;
19
+ retryable: boolean;
20
+ retry_action: RetryAction;
21
+ retry_after_seconds?: number | null;
22
+ submission_state: SubmissionState;
23
+ billing_state: BillingState;
24
+ }
25
+ export interface Envelope<T> {
26
+ code: 0;
27
+ message: string;
28
+ data: T;
29
+ }
30
+ export interface Balance {
31
+ currency: 'CNY';
32
+ available_amount: DecimalAmount;
33
+ frozen_amount: DecimalAmount;
34
+ total_amount: DecimalAmount;
35
+ }
36
+ export interface QuotaWindow {
37
+ state: 'available' | 'exhausted' | 'unlimited' | 'not_started';
38
+ remaining_percent: number | null;
39
+ resets_at: string | null;
40
+ }
41
+ export interface Subscription {
42
+ id: string;
43
+ name: string;
44
+ status: 'active' | 'expired' | 'revoked' | 'pending';
45
+ expires_at: string | null;
46
+ priority: number;
47
+ windows: {
48
+ five_hour: QuotaWindow;
49
+ seven_day: QuotaWindow;
50
+ };
51
+ usable: boolean;
52
+ blocking_reasons: {
53
+ code: string;
54
+ window?: string;
55
+ retry_at?: string | null;
56
+ }[];
57
+ }
58
+ export interface AccountFeatures {
59
+ available_channels: boolean;
60
+ channel_status: boolean;
61
+ model_prices?: boolean;
62
+ recharge: boolean;
63
+ redeem: boolean;
64
+ affiliate: boolean;
65
+ profile: boolean;
66
+ }
67
+ export interface Entitlements {
68
+ contract_version: '1.0';
69
+ revision: string;
70
+ server_time: string;
71
+ capabilities: Capability[];
72
+ balance: Balance;
73
+ subscriptions: Subscription[];
74
+ features: AccountFeatures;
75
+ subscription_billing_enabled: boolean;
76
+ subscription_snapshot_available: boolean;
77
+ }
78
+ export type AccountPage = 'dashboard' | 'usage' | 'subscriptions' | 'available_channels' | 'channel_status' | 'model_prices' | 'recharge' | 'orders' | 'redeem' | 'affiliate' | 'profile';
79
+ export interface MediaAccountContext {
80
+ gatewayOrigin: string;
81
+ userId?: string;
82
+ revision?: string;
83
+ signedIn: boolean;
84
+ }
85
+ export type MediaKind = 'video' | 'audio' | 'image';
86
+ export interface BillingSource {
87
+ kind: 'subscription' | 'balance';
88
+ subscription_id: string | null;
89
+ }
90
+ export interface VideoQuoteRequest {
91
+ kind: 'video';
92
+ model: string;
93
+ operation_id: string;
94
+ parameters: {
95
+ mode: string;
96
+ duration_seconds: number;
97
+ resolution: string;
98
+ ratio: string;
99
+ generate_audio?: boolean;
100
+ reference_image_count?: number;
101
+ reference_video_seconds?: number;
102
+ reference_audio_seconds?: number;
103
+ };
104
+ preferred_billing_source?: BillingSource | null;
105
+ }
106
+ export interface MediaQuote {
107
+ object: 'media.quote';
108
+ quote_id: string;
109
+ operation_id: string;
110
+ kind: MediaKind;
111
+ model: string;
112
+ currency: 'CNY';
113
+ estimated_amount: DecimalAmount;
114
+ reservation_amount: DecimalAmount | null;
115
+ unit: 'token_million' | 'video_token_million' | 'output_second' | 'original_audio_second' | 'image' | 'request';
116
+ unit_price: DecimalAmount;
117
+ basis: Record<string, string | number | boolean | null>;
118
+ billing_source: BillingSource;
119
+ pricing_version: string;
120
+ expires_at: string;
121
+ is_estimate: boolean;
122
+ final_usage_basis: 'provider_reported' | 'fixed';
123
+ fallback_allowed: boolean;
124
+ }
125
+ export interface MediaOperation {
126
+ operation_id: string;
127
+ kind: MediaKind;
128
+ task_id: string | null;
129
+ submission_state: SubmissionState;
130
+ billing_state: BillingState;
131
+ status: string;
132
+ result_available: boolean;
133
+ error: GatewayError | null;
134
+ }
@@ -0,0 +1,34 @@
1
+ /** CONTRACT-V1.md 1.0.0-rc.1. Capabilities describe implemented support, never authorization. */
2
+ export declare const CLIENT_CAPABILITIES: readonly ["errors-v1", "media-quotes-v1"];
3
+ export type ErrorCategory = 'authentication' | 'access_restricted' | 'billing' | 'model_unavailable' | 'invalid_input' | 'content_rejected' | 'rate_limited' | 'service_unavailable' | 'submission_uncertain' | 'internal_error';
4
+ export type ErrorStage = 'auth' | 'catalog' | 'quote' | 'upload' | 'submit' | 'poll' | 'generation' | 'download' | 'settle';
5
+ export type SubmissionState = 'not_submitted' | 'submitting' | 'accepted' | 'unknown' | 'rejected';
6
+ export type BillingState = 'not_charged' | 'reserved' | 'settled' | 'released' | 'unknown';
7
+ export interface BillingSource {
8
+ readonly kind: 'balance' | 'subscription';
9
+ readonly subscriptionId?: string | null;
10
+ }
11
+ export declare const ACCOUNT_PAGES: readonly ["dashboard", "usage", "subscriptions", "available_channels", "channel_status", "model_prices", "recharge", "orders", "redeem", "affiliate", "profile"];
12
+ export type AccountCenterPage = typeof ACCOUNT_PAGES[number];
13
+ export declare const NATIVE_ACCOUNT_PAGES: Set<"dashboard" | "usage" | "subscriptions" | "available_channels" | "channel_status" | "model_prices" | "recharge" | "orders" | "redeem" | "affiliate" | "profile">;
14
+ export declare function normalizeAccountPage(page: AccountCenterPage): AccountCenterPage;
15
+ export interface MediaAccountContext {
16
+ readonly gatewayOrigin: string;
17
+ readonly userId?: string;
18
+ readonly revision?: string;
19
+ readonly signedIn: boolean;
20
+ }
21
+ export interface SafeTaskError {
22
+ readonly code: string;
23
+ readonly message: string;
24
+ readonly category?: string;
25
+ readonly stage?: string;
26
+ readonly requestId?: string;
27
+ readonly taskId?: string;
28
+ readonly operationId?: string;
29
+ readonly retryable?: boolean;
30
+ readonly retryAction?: string;
31
+ readonly retryAfterSeconds?: number;
32
+ readonly submissionState?: string;
33
+ readonly billingState?: string;
34
+ }
@@ -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,8 @@ export interface GatewayHttpOptions {
39
39
  }
40
40
  /** One request. */
41
41
  export interface GatewayRequest {
42
+ /** Rechecked after credential resolution and before every send. */
43
+ readonly isCurrentAccount?: () => Promise<boolean>;
42
44
  readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
43
45
  /** JSON body; serialized with `content-type: application/json`. */
44
46
  readonly json?: unknown;
@@ -75,6 +77,10 @@ export declare function abortError(signal?: AbortSignal): MediaError;
75
77
  export declare class GatewayHttp {
76
78
  private readonly options;
77
79
  readonly origin: string;
80
+ private readonly snapshots;
81
+ invalidateAccountSnapshots(): void;
82
+ /** One Host-only capability snapshot shared by quotes and the account bridge. */
83
+ entitlements(scope: string, request?: GatewayRequest, fresh?: boolean): Promise<unknown>;
78
84
  /**
79
85
  * @param options - origin, credential plane, user agent and test seams.
80
86
  */
@@ -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';
@@ -60,6 +61,12 @@ export interface Config {
60
61
  * the balance card, the account menu or Settings (each of those reads the catalog too, at most once a minute).
61
62
  */
62
63
  catalogRefreshMinutes: number;
64
+ /** Same-key media submission recovery window; applies only to newly created operations. */
65
+ resendWindowMs: number;
66
+ /** Initial same-key attempts, including the first dispatch. */
67
+ submitAttempts: number;
68
+ /** Additional background same-key checks; zero disables background POST reconciliation. */
69
+ reconcileAttempts: number;
63
70
  /** Ask the user before each paid request. */
64
71
  confirmSpending: Volatile<boolean>;
65
72
  /** Output folder, relative to the workspace (or absolute). */
@@ -89,6 +96,9 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
89
96
  preferredModels: Schema<string[], string[], "defined">;
90
97
  openBrowserOnSignIn: Schema<boolean, boolean, "defined">;
91
98
  catalogRefreshMinutes: Schema<number, number, "defined">;
99
+ resendWindowMs: Schema<number, number, "defined">;
100
+ submitAttempts: Schema<number, number, "defined">;
101
+ reconcileAttempts: Schema<number, number, "defined">;
92
102
  confirmSpending: Schema<boolean, boolean, "volatile-defined">;
93
103
  outputDir: Schema<string, string, "volatile-defined">;
94
104
  imageModel: Schema<string, string, "volatile-defined">;
@@ -109,6 +119,9 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
109
119
  preferredModels: Schema<string[], string[], "defined">;
110
120
  openBrowserOnSignIn: Schema<boolean, boolean, "defined">;
111
121
  catalogRefreshMinutes: Schema<number, number, "defined">;
122
+ resendWindowMs: Schema<number, number, "defined">;
123
+ submitAttempts: Schema<number, number, "defined">;
124
+ reconcileAttempts: Schema<number, number, "defined">;
112
125
  confirmSpending: Schema<boolean, boolean, "volatile-defined">;
113
126
  outputDir: Schema<string, string, "volatile-defined">;
114
127
  imageModel: Schema<string, string, "volatile-defined">;