@mars-sea/dsh-commandcode-provider 0.10.3 → 0.10.4

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
@@ -441,7 +441,20 @@ declare class CommandCodeAccountPool {
441
441
  * key until the stored credential changes.
442
442
  */
443
443
  markRejected(apiKey: string, rejection: AccountRejection): void;
444
- /** One account's key: literal → credential seam → auth file (default slot). */
444
+ /**
445
+ * One account's key: literal → credential seam → auth file (default slot).
446
+ *
447
+ * Every source is normalized here, at the single point where a slot's key
448
+ * enters the pool. The adapter sends the key through the harness's
449
+ * `assertUsableApiKey()`, which trims it — a stored key from the credentials
450
+ * seam, a `.env` line, or a shell export all pick up surrounding whitespace
451
+ * — and reports that trimmed form back to `markRejected()`. Returning the
452
+ * raw value would file every 429/401 mark under a key no later lookup can
453
+ * find: rotation would re-offer the same account, the account card would show
454
+ * no mark, and the usage endpoints would 401 while chat kept working.
455
+ * Normalizing once makes resolution, probing, marking, and the request path
456
+ * agree on one string.
457
+ */
445
458
  private resolveSlotKey;
446
459
  /** Hand out the chosen account's key. */
447
460
  private pick;
@@ -1022,6 +1035,14 @@ declare class CommandCodeLoginFlow {
1022
1035
  private timer;
1023
1036
  /** Settle hooks of the live attempt's callback promise. */
1024
1037
  private settle;
1038
+ /**
1039
+ * Attempt generation. A delivered callback keeps validating the key
1040
+ * asynchronously (`complete()`), and that window is open to a cancel or a
1041
+ * fresh `begin()`; the generation lets a late completion recognize that it
1042
+ * no longer owns the status face and stop instead of storing a credential
1043
+ * the user cancelled and flipping the page back to success.
1044
+ */
1045
+ private attemptSeq;
1025
1046
  private disposed;
1026
1047
  constructor(deps: CommandCodeLoginFlowDeps);
1027
1048
  /** Subscribe to state transitions. @returns the disposer. */
@@ -1052,8 +1073,19 @@ declare class CommandCodeLoginFlow {
1052
1073
  private handleCallback;
1053
1074
  /** Answer a decisive callback, stop listening, and settle the attempt. */
1054
1075
  private settleAttempt;
1055
- /** Post-validation completion: whoami check, then hand-off to storage. */
1076
+ /**
1077
+ * Post-validation completion: whoami check, then hand-off to storage.
1078
+ *
1079
+ * Every step re-checks {@link ownsAttempt} first: the whoami round-trip and
1080
+ * the credential write are awaits, and the user may cancel (or start another
1081
+ * attempt) while one is in flight. A completion that no longer owns the
1082
+ * attempt must not write the key or publish a status — otherwise cancel
1083
+ * would report "cancelled" while the credential landed anyway, and the page
1084
+ * would silently flip to success.
1085
+ */
1056
1086
  private complete;
1087
+ /** Whether one attempt still owns the status face (not cancelled, replaced, or disposed). */
1088
+ private ownsAttempt;
1057
1089
  /** Map a tagged settle rejection onto the status face. */
1058
1090
  private failFrom;
1059
1091
  private clearTimer;
@@ -1154,6 +1186,145 @@ declare class CommandCodeSearchProvider implements WebSearchProvider {
1154
1186
  private resolveKey;
1155
1187
  }
1156
1188
  //#endregion
1189
+ //#region src/tui-settings.d.ts
1190
+ /** Provider-owned translations for one title, label, or hint. */
1191
+ interface TuiLocalizedText {
1192
+ readonly zh?: string;
1193
+ readonly en?: string;
1194
+ }
1195
+ /** Control kinds the dsh-TUI settings screen knows how to render. */
1196
+ type TuiSettingsFieldKind = 'text' | 'number' | 'boolean' | 'select';
1197
+ /** One choice of an options-bearing field. */
1198
+ interface TuiSettingsFieldOption {
1199
+ /** Stored value. */
1200
+ readonly value: string;
1201
+ /** Display label (English; also the fallback). */
1202
+ readonly label: string;
1203
+ /** Provider-owned translations for the label. */
1204
+ readonly descriptions?: TuiLocalizedText;
1205
+ }
1206
+ /** The write one field's draft stages when the section is saved. */
1207
+ type TuiSettingsFieldWrite = {
1208
+ readonly kind: 'set';
1209
+ readonly value: unknown;
1210
+ } | {
1211
+ readonly kind: 'clear';
1212
+ };
1213
+ /** One editable field inside a section. */
1214
+ interface TuiSettingsField {
1215
+ /** Key path from the section root, in the settings service's `mutate` vocabulary. */
1216
+ readonly path: readonly string[];
1217
+ /** Short field label (English; also the fallback). */
1218
+ readonly label: string;
1219
+ /** Provider-owned translations for the label. */
1220
+ readonly descriptions?: TuiLocalizedText;
1221
+ /** Optional one-line help rendered under the field. */
1222
+ readonly hint?: string;
1223
+ /** Provider-owned translations for the hint. */
1224
+ readonly hintDescriptions?: TuiLocalizedText;
1225
+ /** Optional group id; grouped fields render on that group's subpage. */
1226
+ readonly group?: string;
1227
+ readonly kind: TuiSettingsFieldKind;
1228
+ /**
1229
+ * Choices for an options-bearing field. A `text` field that carries options
1230
+ * is the TUI's own "preset plus custom value" shape: `←`/`→` cycle the
1231
+ * presets while Enter opens the text editor.
1232
+ */
1233
+ readonly options?: readonly TuiSettingsFieldOption[];
1234
+ /** Input placeholder for `kind: 'text' | 'number'`. */
1235
+ readonly placeholder?: string;
1236
+ /**
1237
+ * Credential control: the literal never rides the settings document — the
1238
+ * draft starts blank on every open, a blank draft writes nothing, and a
1239
+ * typed draft writes through the credentials seam under `ref`.
1240
+ */
1241
+ readonly secret?: {
1242
+ readonly ref: string;
1243
+ };
1244
+ /** Render a stored value as draft text. */
1245
+ readonly format?: (value: unknown) => string;
1246
+ /** The write a draft text stages; `undefined` marks the draft invalid. */
1247
+ readonly parse?: (text: string) => TuiSettingsFieldWrite | undefined;
1248
+ }
1249
+ /** Optional navigation group inside one section. */
1250
+ interface TuiSettingsGroup {
1251
+ /** Stable identifier, unique inside the section. */
1252
+ readonly id: string;
1253
+ /** Group title (English; also the fallback). */
1254
+ readonly title: string;
1255
+ /** Provider-owned translations for the title. */
1256
+ readonly descriptions?: TuiLocalizedText;
1257
+ }
1258
+ /** One plugin's section inside the dsh-TUI settings screen. */
1259
+ interface TuiSettingsSection {
1260
+ /** Settings namespace this section edits. */
1261
+ readonly ns: string;
1262
+ /** Section title (English; also the fallback). */
1263
+ readonly title: string;
1264
+ /** Provider-owned translations for the title. */
1265
+ readonly descriptions?: TuiLocalizedText;
1266
+ /** Optional navigation groups, in display order. */
1267
+ readonly groups?: readonly TuiSettingsGroup[];
1268
+ /** Editable fields, in display order. */
1269
+ readonly fields: readonly TuiSettingsField[];
1270
+ }
1271
+ /** The slice of the `tuiSettingsSections` service this module uses. */
1272
+ interface TuiSettingsSectionsService {
1273
+ /** Declare a section; the returned disposer withdraws it. */
1274
+ register(section: TuiSettingsSection): () => void;
1275
+ }
1276
+ /** The selector value meaning "no pinned account — follow rotation order". */
1277
+ declare const ACTIVE_ACCOUNT_AUTO = "auto";
1278
+ /** The selector value meaning "no language override — follow the shell locale". */
1279
+ declare const LANG_AUTO = "auto";
1280
+ /** Everything the section needs from the plugin entry. */
1281
+ interface CommandCodeTuiSettingsDeps {
1282
+ /** The plugin's settings namespace (`llm-commandcode`). */
1283
+ ns: string;
1284
+ /** Section title; defaults to `Command Code`. */
1285
+ title?: string;
1286
+ /**
1287
+ * The credential reference the API-key field writes through, read per
1288
+ * registration so a `Config.apiKeyEnv` change re-targets the field instead
1289
+ * of silently writing to the old reference.
1290
+ */
1291
+ apiKeyRef: () => string;
1292
+ /**
1293
+ * Account slots for the active-account selector, in rotation order, read
1294
+ * per registration. A changed list re-registers the section (see
1295
+ * {@link applyCommandCodeTuiSettings}).
1296
+ */
1297
+ accountSlots: () => readonly {
1298
+ id: string;
1299
+ label: string;
1300
+ }[];
1301
+ }
1302
+ /**
1303
+ * Build the section descriptor. Pure, so tests can pin the exact fields
1304
+ * without a dsh-TUI host.
1305
+ *
1306
+ * Field choices worth keeping: the two option-bearing fields (`activeAccount`,
1307
+ * `lang`) are `text` + `options` rather than `select`, because a `select`
1308
+ * cannot express "unset" — cycling only ever lands on a declared option, so a
1309
+ * `select` would strand the user on a pinned value with no way back to
1310
+ * automatic. The `auto` sentinel plus a `parse` that clears the path keeps the
1311
+ * unset state reachable. The two booleans format their EFFECTIVE default
1312
+ * (`filterModelsByPlan` unset means true at the adapter), so a fresh install
1313
+ * reads true instead of the screen's "(empty)".
1314
+ */
1315
+ declare function buildCommandCodeTuiSection(deps: CommandCodeTuiSettingsDeps): TuiSettingsSection;
1316
+ /**
1317
+ * Register the Command Code section on a dsh-TUI host.
1318
+ *
1319
+ * @param ctx - the context of an activated `tuiSettingsSections` injection.
1320
+ * @param deps - plugin-owned facts the section reads.
1321
+ * @returns a refresh function that re-registers the section when a fact it
1322
+ * renders changed (the plugin entry calls it from its settings `onChange`
1323
+ * hook), or `undefined` when the seam is unusable. The returned function is
1324
+ * inert after the fiber is torn down.
1325
+ */
1326
+ declare function applyCommandCodeTuiSettings(ctx: Context, deps: CommandCodeTuiSettingsDeps): (() => void) | undefined;
1327
+ //#endregion
1157
1328
  //#region src/index.d.ts
1158
1329
  declare const name = "llm-commandcode";
1159
1330
  declare const inject: string[];
@@ -1265,5 +1436,5 @@ interface ResolvedCommandCodeOptions extends CommandCodeConnectionOptions {
1265
1436
  declare function resolveAdapterOptions(config: Config): ResolvedCommandCodeOptions;
1266
1437
  declare function apply(ctx: Context, config: Config): void;
1267
1438
  //#endregion
1268
- export { 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 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, 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, USAGE_REPORT_ENDPOINT, accountUsable, apply, applyCommandCodeSearchSelection, applyCommands, applyUsageRemote, buildCommandAuthUrl, 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 };
1439
+ 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 };
1269
1440
  //# sourceMappingURL=index.d.ts.map