@mars-sea/dsh-commandcode-provider 0.11.8 → 0.11.9

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.
package/lib/index.d.ts CHANGED
@@ -340,6 +340,11 @@ declare class CommandCodeAdapter<C extends CommandCodeConnectionOptions = Comman
340
340
  * failure accounting: the billing probe fails open silently, the usage
341
341
  * report books failures per endpoint. Non-2xx and non-record bodies come
342
342
  * back without a record; only a transport throw propagates to the caller.
343
+ *
344
+ * `timeoutMs` is the caller's budget for this one request. The default is the
345
+ * CATALOG probe's short cap, which fits the picker's fail-open reads; the
346
+ * usage report deliberately passes the connection's own request budget so an
347
+ * account query is not held to a stricter (and invisible) limit than chat.
343
348
  */
344
349
  private fetchEndpointJson;
345
350
  /**
@@ -411,6 +416,20 @@ declare class CommandCodeAdapter<C extends CommandCodeConnectionOptions = Comman
411
416
  * view. Requires a usable API key (throws `MISSING_CREDENTIAL` otherwise).
412
417
  * Pass `apiKey` to report on a specific account of a multi-account pool;
413
418
  * the default resolves the currently active account.
419
+ *
420
+ * Two failure modes are NOT "the network is down", and the report must say
421
+ * so rather than let {@link classifyTotalFailure} blame the connection:
422
+ *
423
+ * - A key that no HTTP header can carry (a stray newline from a paste, a
424
+ * full-width character) makes `fetch` throw a `TypeError` **before any
425
+ * I/O**, for every endpoint at once. The chat path refuses such a key
426
+ * through `assertUsableApiKey`; this path must too, and it answers
427
+ * `blocked: 'invalid-key'` instead of four phantom transport failures.
428
+ * - The four endpoints get the SAME per-request budget as a chat call
429
+ * (`connection.requestTimeoutMs`, default 60 s), not the catalog's 10 s
430
+ * probe budget: on a slow link a 10 s cap made every account query time
431
+ * out while chat kept working, which is exactly a "check your network"
432
+ * banner that never clears.
414
433
  */
415
434
  getUsage(apiKey?: string): Promise<CommandCodeUsageReport>;
416
435
  /**
@@ -1372,7 +1391,10 @@ declare function validateCommandApiKey(fetchImpl: typeof fetch, apiBase: string,
1372
1391
  /**
1373
1392
  * One browser-login attempt machine. Single-flight by design: `begin()` while
1374
1393
  * waiting returns the live attempt's status instead of starting a second one;
1375
- * a terminal state makes the next `begin()` start fresh.
1394
+ * a start that is still binding its port is REJOINED through
1395
+ * {@link CommandCodeLoginFlow.begin}'s in-flight promise, because the status
1396
+ * face cannot say `waiting` until that bind settles; a terminal state makes the
1397
+ * next `begin()` start fresh.
1376
1398
  */
1377
1399
  declare class CommandCodeLoginFlow {
1378
1400
  private readonly deps;
@@ -1390,6 +1412,17 @@ declare class CommandCodeLoginFlow {
1390
1412
  * the user cancelled and flipping the page back to success.
1391
1413
  */
1392
1414
  private attemptSeq;
1415
+ /**
1416
+ * The start currently binding a port, if any. Every `begin()` that arrives
1417
+ * before it settles joins it: two independent starts would each bind their
1418
+ * own loopback server, and only the LAST one is reachable by
1419
+ * {@link CommandCodeLoginFlow.teardown} — the orphan keeps listening and
1420
+ * answering `/callback` for the process's lifetime, and ten of them exhaust
1421
+ * the port window so browser login dies until the Host restarts.
1422
+ */
1423
+ private starting;
1424
+ /** A `cancel()` that arrived while a start was still binding (see {@link CommandCodeLoginFlow.cancel}). */
1425
+ private cancelPending;
1393
1426
  private disposed;
1394
1427
  constructor(deps: CommandCodeLoginFlowDeps);
1395
1428
  /** Subscribe to state transitions. @returns the disposer. */
@@ -1402,7 +1435,18 @@ declare class CommandCodeLoginFlow {
1402
1435
  * Rejects only when the flow cannot start at all (no free port, disposed).
1403
1436
  */
1404
1437
  begin(): Promise<CommandCodeLoginStatus>;
1405
- /** Cancel a waiting attempt; terminal states are untouched. */
1438
+ /**
1439
+ * The binding half of {@link CommandCodeLoginFlow.begin}: one attempt, one
1440
+ * server, one published `waiting` status. Callers reach it only through
1441
+ * `begin()`'s single-flight fence.
1442
+ */
1443
+ private startAttempt;
1444
+ /**
1445
+ * Cancel a waiting attempt; terminal states are untouched. A start that is
1446
+ * still binding a port is flagged instead of ignored — it cannot be torn
1447
+ * down from here (its server does not exist yet), so `startAttempt` observes
1448
+ * the flag once the bind settles and retires it.
1449
+ */
1406
1450
  cancel(): void;
1407
1451
  /** Stop everything; a waiting attempt ends cancelled. Idempotent. */
1408
1452
  dispose(): void;
@@ -1478,10 +1522,20 @@ declare function selectCommandCodeSearchProvider(web: WebRuntime, enable: boolea
1478
1522
  * configured, leave auto-select" and must round-trip untouched: writing the
1479
1523
  * factory default instead would still override a sibling plugin's own
1480
1524
  * constructor-time pin.
1525
+ *
1526
+ * `preexisting` is the one fact `displaced` cannot carry: an `undefined`
1527
+ * `displaced` means EITHER "the field was unset when we took over" (give
1528
+ * `undefined` back on disable) OR "the field already read `commandcode`"
1529
+ * (touch nothing on disable — see {@link applyCommandCodeSearchSelection}).
1530
+ * Collapsing the two is what turned a user's own `searchProvider: commandcode`
1531
+ * pin into an auto-select — and then into `WEB_PROVIDER_AMBIGUOUS` on every
1532
+ * search — the moment this plugin was disabled or unloaded.
1481
1533
  */
1482
1534
  interface CommandCodeSearchSelection {
1483
1535
  owner: boolean;
1484
1536
  displaced: string | undefined;
1537
+ /** Whether the field already read `commandcode` when this plugin first took it over. */
1538
+ preexisting: boolean;
1485
1539
  }
1486
1540
  /** Fresh selection state: the plugin starts out not owning the selection. */
1487
1541
  declare function commandCodeSearchSelection(): CommandCodeSearchSelection;
@@ -1500,8 +1554,14 @@ declare function commandCodeSearchSelection(): CommandCodeSearchSelection;
1500
1554
  * auto-select — already says what the user wants.
1501
1555
  * - When the field already reads `commandcode` at first touch (e.g. a
1502
1556
  * surviving runtime the plugin did not set, or a manual
1503
- * `searchProvider: commandcode` pin), `displaced` stays undefined so the
1504
- * later disable is a no-op rather than a guess at the factory default.
1557
+ * `searchProvider: commandcode` pin), `displaced` stays undefined and
1558
+ * `preexisting` is set, so the later disable is a no-op rather than a guess
1559
+ * at the factory default. A "no-op" means the field is left ALONE: writing
1560
+ * that `undefined` back would destroy the user's own pin, and dsh-web reads
1561
+ * a cleared `searchProviderId` as auto-select — where a second usable
1562
+ * provider (the shipped `deepseek-official` is usable whenever a DeepSeek
1563
+ * key resolves) makes EVERY later search throw
1564
+ * `WEB_PROVIDER_AMBIGUOUS`.
1505
1565
  *
1506
1566
  * Never throws: like the low-level rewrite, a hardened runtime shape degrades
1507
1567
  * to registered-but-unselected.
@@ -1825,7 +1885,35 @@ interface Config {
1825
1885
  */
1826
1886
  lang?: string;
1827
1887
  }
1888
+ /**
1889
+ * The 0.1.7-generation schema: every field volatile except the
1890
+ * composition-only `apiKey` secret.
1891
+ *
1892
+ * dsh 0.1.7's settings forms are projected from the schema's `meta.volatile`
1893
+ * nodes, so an unmarked field would be invisible to AND unwritable from the
1894
+ * settings page and refused by form-edit path validation — and on that
1895
+ * generation the loader hands `apply()` a live reference per marked field,
1896
+ * committing later writes without remounting this fiber (the
1897
+ * `loader/volatile-update` listener at the bottom of `apply` covers the facts
1898
+ * that are not re-derived per read). The mark is inert on engines whose
1899
+ * schemastery predates `.volatile()`.
1900
+ */
1828
1901
  declare const Config: z<Config>;
1902
+ /**
1903
+ * The ≤0.1.6-generation registration schema: the same fields, NO volatile
1904
+ * marks.
1905
+ *
1906
+ * The legacy `installSection(owner, ns, schema, entry, hooks)` re-validates the
1907
+ * `entry` it is handed (`register()` → `resolve()` → `schema(mergeLayers(base,
1908
+ * section))`) and its `describe()` structuredClones that same `entry`. Since
1909
+ * schemastery ≥3.18.3 creates references at parse time on EVERY generation —
1910
+ * `dsh-settings` through 0.1.6 declares `schemastery: ^3.18.2`, so old engines
1911
+ * freshly installed today resolve 3.18.3 — a marked schema plus the raw
1912
+ * reference-carrying `config` is a boot-time `ValidationError` there. This
1913
+ * schema is therefore unmarked, and `apply` pairs it with
1914
+ * `unwrapVolatileConfig(config)`.
1915
+ */
1916
+ declare const LegacySettingsSchema: z<Config>;
1829
1917
  /** One resolution's complete request facts: connection plus credential reference. */
1830
1918
  interface ResolvedCommandCodeOptions extends CommandCodeConnectionOptions {
1831
1919
  apiKeyEnv: CredentialRef;
@@ -1839,5 +1927,5 @@ interface ResolvedCommandCodeOptions extends CommandCodeConnectionOptions {
1839
1927
  declare function resolveAdapterOptions(config: Config): ResolvedCommandCodeOptions;
1840
1928
  declare function apply(ctx: Context, config: Config): void;
1841
1929
  //#endregion
1842
- export { ACTIVE_ACCOUNT_AUTO, type ApiKeyValidation, BILLING_ACCESS_TTL_MS, COMMANDCODE_SEARCH_PROVIDER_ID, COMMAND_CODE_CLI_VERSION, type CommandCodeAccountConfig, CommandCodeAccountPool, type CommandCodeAccountSlot, type CommandCodeAccountState, type CommandCodeAccountUsage, type CommandCodeAccountsReport, CommandCodeAdapter, type CommandCodeAdapterDeps, type CommandCodeBillingAccess, type CommandCodeCommandDeps, type CommandCodeConnectionOptions, type CommandCodeLoginCredentials, type CommandCodeLoginFailureReason, CommandCodeLoginFlow, type CommandCodeLoginFlowDeps, type CommandCodeLoginStatus, type CommandCodeModelAccountRule, CommandCodeSearchProvider, type CommandCodeSearchProviderDeps, type CommandCodeSearchSelection, type CommandCodeTuiSettingsDeps, type CommandCodeUsageDeps, type CommandCodeUsageReport, CommandCodeUsageService, Config, DEFAULT_API_BASE, DEFAULT_GENERATE_MAX_TOKENS, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_MODELS_CACHE_PATH, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_WEB_SEARCH_PROVIDER_ID, KNOWN_DEALS, KNOWN_EFFORTS, KNOWN_IMAGE_MODELS, KNOWN_PEAK_PRICING, KNOWN_PLANS, KNOWN_SUBSCRIPTION_PLANS, KNOWN_THINKING_MODELS, LANG_AUTO, LOGIN_ALLOWED_ORIGINS, LOGIN_BEGIN_ENDPOINT, LOGIN_BODY_LIMIT_BYTES, LOGIN_CANCEL_ENDPOINT, LOGIN_MAX_PORT_ATTEMPTS, LOGIN_START_PORT, LOGIN_STATUS_ENDPOINT, LOGIN_TIMEOUT_MS, type LoginFlowFacade, PLAN_LABELS, PLAN_ORDER, PROVIDER, type ResolveAttachments, ResolvedCommandCodeOptions, type TuiSettingsField, type TuiSettingsFieldOption, type TuiSettingsFieldWrite, type TuiSettingsGroup, type TuiSettingsSection, type TuiSettingsSectionsService, USAGE_REPORT_ENDPOINT, accountUsable, apply, applyCommandCodeSearchSelection, applyCommandCodeTuiSettings, applyCommands, applyUsageRemote, buildCommandAuthUrl, buildCommandCodeTuiSection, capabilityDescription, commandCodeSearchSelection, commandDefinition, compareByPlan, dealLabel, formatContext, inject, loginStatusSchema, matchModelRule, modelVisibleInPlan, name, parseLoginStatus, peakPricingLabel, peakPricingState, planLabel, projectSlugFromPath, resolveAdapterOptions, resolveAuthFileApiKey, selectAccountForModel, selectActiveAccount, selectCommandCodeSearchProvider, studioBaseForApiBase, subscriptionPlanInfo, usageReportSchema, validateCommandApiKey };
1930
+ export { ACTIVE_ACCOUNT_AUTO, type ApiKeyValidation, BILLING_ACCESS_TTL_MS, COMMANDCODE_SEARCH_PROVIDER_ID, COMMAND_CODE_CLI_VERSION, type CommandCodeAccountConfig, CommandCodeAccountPool, type CommandCodeAccountSlot, type CommandCodeAccountState, type CommandCodeAccountUsage, type CommandCodeAccountsReport, CommandCodeAdapter, type CommandCodeAdapterDeps, type CommandCodeBillingAccess, type CommandCodeCommandDeps, type CommandCodeConnectionOptions, type CommandCodeLoginCredentials, type CommandCodeLoginFailureReason, CommandCodeLoginFlow, type CommandCodeLoginFlowDeps, type CommandCodeLoginStatus, type CommandCodeModelAccountRule, CommandCodeSearchProvider, type CommandCodeSearchProviderDeps, type CommandCodeSearchSelection, type CommandCodeTuiSettingsDeps, type CommandCodeUsageDeps, type CommandCodeUsageReport, CommandCodeUsageService, Config, DEFAULT_API_BASE, DEFAULT_GENERATE_MAX_TOKENS, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_MODELS_CACHE_PATH, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_WEB_SEARCH_PROVIDER_ID, KNOWN_DEALS, KNOWN_EFFORTS, KNOWN_IMAGE_MODELS, KNOWN_PEAK_PRICING, KNOWN_PLANS, KNOWN_SUBSCRIPTION_PLANS, KNOWN_THINKING_MODELS, LANG_AUTO, LOGIN_ALLOWED_ORIGINS, LOGIN_BEGIN_ENDPOINT, LOGIN_BODY_LIMIT_BYTES, LOGIN_CANCEL_ENDPOINT, LOGIN_MAX_PORT_ATTEMPTS, LOGIN_START_PORT, LOGIN_STATUS_ENDPOINT, LOGIN_TIMEOUT_MS, LegacySettingsSchema, type LoginFlowFacade, PLAN_LABELS, PLAN_ORDER, PROVIDER, type ResolveAttachments, ResolvedCommandCodeOptions, type TuiSettingsField, type TuiSettingsFieldOption, type TuiSettingsFieldWrite, type TuiSettingsGroup, type TuiSettingsSection, type TuiSettingsSectionsService, USAGE_REPORT_ENDPOINT, accountUsable, apply, applyCommandCodeSearchSelection, applyCommandCodeTuiSettings, applyCommands, applyUsageRemote, buildCommandAuthUrl, buildCommandCodeTuiSection, capabilityDescription, commandCodeSearchSelection, commandDefinition, compareByPlan, dealLabel, formatContext, inject, loginStatusSchema, matchModelRule, modelVisibleInPlan, name, parseLoginStatus, peakPricingLabel, peakPricingState, planLabel, projectSlugFromPath, resolveAdapterOptions, resolveAuthFileApiKey, selectAccountForModel, selectActiveAccount, selectCommandCodeSearchProvider, studioBaseForApiBase, subscriptionPlanInfo, usageReportSchema, validateCommandApiKey };
1843
1931
  //# sourceMappingURL=index.d.ts.map