dsh-keys-manager 0.2.3 → 0.2.5

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/domain.d.ts CHANGED
@@ -225,6 +225,28 @@ export interface TransportAccountView {
225
225
  /** Derived from {@link status}: true only while it is `'active'`. */
226
226
  active: boolean;
227
227
  }
228
+ /** One model row a transport route can advertise. */
229
+ export interface TransportCatalogModel {
230
+ id: string;
231
+ name: string;
232
+ }
233
+ /**
234
+ * Catalog plus configured allow-list for one transport route's model picker.
235
+ *
236
+ * `models` is the allow-list; an empty list means the route advertises the
237
+ * full catalog, exactly like its adapter.
238
+ */
239
+ export interface TransportModelsView {
240
+ catalog: TransportCatalogModel[];
241
+ models: string[];
242
+ /**
243
+ * Why the catalog is empty. Rides every read whose catalog accessor is
244
+ * missing, so a remounted or reloaded picker still explains the empty list;
245
+ * absent for every route that does ship a catalog. The one-shot part of this
246
+ * report is the {@link StateView.warnings} entry, not this field.
247
+ */
248
+ warning?: string;
249
+ }
228
250
  /** Complete manager snapshot the UI renders. */
229
251
  export interface StateView {
230
252
  now: number;
@@ -280,7 +302,13 @@ export interface AccountAttemptNotice {
280
302
  }
281
303
  /** Serializable prompt parked on an interactive sign-in attempt. */
282
304
  export interface AccountAttemptPrompt {
283
- kind: 'text' | 'secret' | 'select';
305
+ /**
306
+ * `manual-code` is the out-of-band paste step an OAuth-code flow parks on
307
+ * (a `zcode://` redirect, or the Devin callback address): the dialog masks
308
+ * the field like a `secret`, offers a reveal toggle and carries the paste
309
+ * guidance, unlike a generic `text` prompt.
310
+ */
311
+ kind: 'text' | 'secret' | 'select' | 'manual-code';
284
312
  message: string;
285
313
  placeholder?: string;
286
314
  options?: ReadonlyArray<{
@@ -91,7 +91,12 @@ export interface AuthorizationInteractionLike {
91
91
  code?: string;
92
92
  }): void;
93
93
  prompt(prompt: {
94
- kind?: 'text' | 'secret' | 'select';
94
+ /**
95
+ * The seam itself only ever sends the three pi-ai kinds. `manual-code` is
96
+ * this plugin's own extension: the out-of-band paste step an OAuth-code
97
+ * driver parks on, which the dialog renders with paste guidance.
98
+ */
99
+ kind?: 'text' | 'secret' | 'select' | 'manual-code';
95
100
  message: string;
96
101
  placeholder?: string;
97
102
  options?: ReadonlyArray<{
@@ -150,8 +155,12 @@ export interface TransportGrantLike {
150
155
  access: string;
151
156
  /** Refresh token; absent on a grant that cannot be renewed. */
152
157
  refresh?: string;
153
- /** Epoch ms when the access token expires. */
154
- expires: number;
158
+ /**
159
+ * Epoch ms when the access token expires. Absent on a record the transport
160
+ * resolver accepts as a static bearer; no shipped flow writes one today —
161
+ * the Devin flow always commits a derived expiry.
162
+ */
163
+ expires?: number;
155
164
  email?: string;
156
165
  accountId?: string;
157
166
  }
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AccountAttemptView, KeyTestResult, StateView } from './domain.js';
1
+ import type { AccountAttemptView, KeyTestResult, StateView, TransportModelsView } from './domain.js';
2
2
  import type { CredentialsLike, GenerateOptionsLike, HostContext, KeySelection, RequestErrorAction, AgentRequestPayload, RequestErrorPayload, SettingsLike, StreamChunkLike } from './host-types.js';
3
3
  import { KeysManagerStore } from './store.js';
4
4
  export declare const name = "keys-manager";
@@ -49,7 +49,15 @@ export declare class KeysManagerService {
49
49
  private attemptSequence;
50
50
  private readonly switches;
51
51
  private warnings;
52
+ /** Transport routes already reported as having no shipped catalog. */
53
+ private readonly catalogReports;
52
54
  settings: SettingsLike | undefined;
55
+ /**
56
+ * Test/embedding seam for the in-process sign-in drivers (the same pattern
57
+ * `isolationWaitMs` uses). Production leaves it undefined, so `runSignIn`
58
+ * loads the build artifact lazily on the first attempt.
59
+ */
60
+ private signInAdapter;
53
61
  private rawCredentials;
54
62
  private readonly credentialOriginals;
55
63
  private readonly credentialWrappers;
@@ -659,8 +667,51 @@ export declare class KeysManagerService {
659
667
  * {@link getAccountAttempt} / {@link listAccountAttempts}.
660
668
  */
661
669
  beginAccountLogin(provider: string, alias?: string, targetAccountId?: string): Promise<AccountAttemptView>;
670
+ /**
671
+ * Run one in-process sign-in and commit the static credential it mints.
672
+ *
673
+ * The driver runs outside the mutation queue (design §4.4): it performs
674
+ * provider I/O and parks on prompts, so holding the queue would block every
675
+ * other remote call for minutes. The commit itself re-enters through the
676
+ * public transactional methods, exactly like a remote caller would.
677
+ */
678
+ private driveSignIn;
679
+ /**
680
+ * Turn a minted static credential into pool state.
681
+ *
682
+ * Three shapes, one rule — the credential is a *static* secret, so it is an
683
+ * ordinary `kind: 'api-key'` row with `importedFrom: 'signin:<driver>'`, never
684
+ * a grant:
685
+ *
686
+ * 1. `targetAccountId` → replace that row's literal in place (same id, same
687
+ * ref, same list position).
688
+ * 2. an unmanaged *extra* route → create the route and its first row
689
+ * (`kilo`, whose card is an extra profile).
690
+ * 3. a managed route → append a row (`zai`, a shipped DSH route).
691
+ *
692
+ * The secret passes the same `validateKeyInput` guard `addKey` uses, so an
693
+ * over-long provider token fails as the existing named error.
694
+ */
695
+ private commitSignIn;
696
+ /**
697
+ * Replace a sign-in row's literal in place on re-authentication.
698
+ *
699
+ * Mirrors the recovery half of the grant harvest: the row keeps its id, ref
700
+ * and position, the missing flag a demotion set goes, and a cooldown the OLD
701
+ * credential earned ends with the new one. No row is added and no record is
702
+ * created — the literal is the whole credential.
703
+ */
704
+ private replaceSignInCredential;
662
705
  /** Resolve the attempt's parked prompt with the human's answer. */
663
706
  answerAccountPrompt(attemptId: string, value: string): Promise<void>;
707
+ /**
708
+ * Remote: cancel one interactive attempt.
709
+ *
710
+ * The seam path learns about cancellation from `authorization`; an
711
+ * in-process sign-in has no seam handle, so the login dialog's Cancel calls
712
+ * this. Idempotent: a settled attempt is left alone.
713
+ */
714
+ cancelAccountLogin(attemptId: string): void;
664
715
  /** One attempt's serializable view, or undefined when unknown. */
665
716
  getAccountAttempt(attemptId: string): AccountAttemptView | undefined;
666
717
  /** Remote: poll one attempt's serializable state (T3 dialog channel). */
@@ -718,6 +769,45 @@ export declare class KeysManagerService {
718
769
  removeTransportAccount(route: string): Promise<StateView>;
719
770
  /** The route's removal epoch; absent means never removed. */
720
771
  private transportGenerationOf;
772
+ /**
773
+ * Explain a registered transport flow that has no catalog.
774
+ *
775
+ * An empty list is also the legitimate all-models state, so the only honest
776
+ * way to tell a stale transport build apart is to say so. The message rides
777
+ * every read whose accessor is missing — a once-only gate would leave a
778
+ * remounted or reloaded picker unexplained — while `catalogReports` keeps
779
+ * the state warning to one push per route.
780
+ */
781
+ private reportMissingCatalog;
782
+ /**
783
+ * Remote: read one transport route's catalog and configured allow-list.
784
+ *
785
+ * @remarks
786
+ * The catalog comes from the transports package, because the route's
787
+ * `listModels` answers only the allow-list. An empty allow-list means "all
788
+ * models", so an unreadable settings store must not answer `[]` — a save
789
+ * would then clear a narrowed selection — and it rejects instead.
790
+ */
791
+ transportModels(route: string): Promise<TransportModelsView>;
792
+ /**
793
+ * Remote: replace one transport route's model allow-list.
794
+ *
795
+ * Writes only the route's own `providers.<route>.models` path through the
796
+ * live settings revision; an empty list restores the full catalog.
797
+ */
798
+ saveTransportModels(route: string, models: string[]): Promise<TransportModelsView>;
799
+ /** Refuse a route the transports package does not register. */
800
+ private assertTransportRoute;
801
+ /**
802
+ * One transport route's configured model ids, read from the live settings.
803
+ *
804
+ * @remarks
805
+ * Rejects when the descriptor is unreadable or this plugin's namespace is
806
+ * not mounted: a registered route always owns that namespace, so answering
807
+ * "no models configured" would report the all-models state for a store the
808
+ * host simply could not read.
809
+ */
810
+ private transportModelIds;
721
811
  /**
722
812
  * Drop a grant a withdrawn sign-in wrote after its account was removed.
723
813
  *
@@ -1013,9 +1103,30 @@ export declare class KeysManagerService {
1013
1103
  * flush; see {@link compensateActivationFlush} for that compensation.
1014
1104
  */
1015
1105
  activateAccount(provider: string, accountId: string): Promise<StateView>;
1106
+ /**
1107
+ * The row's own grant payload, recovered from the live projection when the
1108
+ * plugin-scope record is gone. The projection IS the route's credential, so a
1109
+ * matching payload is written back (compare-at-absent) and used immediately.
1110
+ *
1111
+ * `recoveredFromProjection` marks a payload the ownership-verified projection
1112
+ * supplied when the repair write did not persist it: the ref stays absent or
1113
+ * unusable, so a caller that re-reads it must treat the payload as the live
1114
+ * credential instead of a concurrent writer's record. That case also returns
1115
+ * the projection record it validated: a caller that compares before writing
1116
+ * must use this snapshot as its baseline, or the compare would accept a
1117
+ * rotation that landed after the payload was read. It never marks a
1118
+ * projection whose row has been detached or repointed since the snapshot —
1119
+ * that recovery is refused, because the projection then belongs to a
1120
+ * generation this row no longer names. For the same reason a repair the
1121
+ * updater declined (row gone, retiring, or repointed) resolves `undefined`:
1122
+ * the callers' own "missing or unusable" failure is the truthful answer, not
1123
+ * the payload of a generation this row has left behind.
1124
+ */
1125
+ private recoverGrantPayload;
1016
1126
  /**
1017
1127
  * The slow half of an activation, outside the queue: read the row's grant
1018
- * generation, validate it, and capture the projection the route serves now.
1128
+ * generation (recovered from the live projection when its record is gone),
1129
+ * validate it, and capture the projection the route serves now.
1019
1130
  */
1020
1131
  private prepareActivation;
1021
1132
  /** Whether the projection still holds the value this activation read. */
@@ -1196,6 +1307,17 @@ export declare class KeysManagerService {
1196
1307
  private testRouteProfile;
1197
1308
  /** One request pinned to the row's API-key literal. */
1198
1309
  private runApiKeyRowTest;
1310
+ /**
1311
+ * Whether this test may still borrow the route, or the result it must report
1312
+ * instead: the window is live, shutdown has not begun, and the row still
1313
+ * exists, is not retiring, and still names the `grantRef` the test captured.
1314
+ *
1315
+ * Read before the borrow and again after every await that precedes it. The
1316
+ * grant recovery is one: it outlives the isolation deadline on a slow seam,
1317
+ * and a window the watchdog already released no longer compensates its late
1318
+ * borrow (that branch is guarded by `abandonedWindows.get(provider) === window`).
1319
+ */
1320
+ private borrowBarrier;
1199
1321
  /** One request with the row's grant temporarily projected as the route's credential. */
1200
1322
  private runOAuthRowTest;
1201
1323
  /** The refusal an abandoned test reports instead of a stale success. */
@@ -1544,6 +1666,39 @@ export declare class KeysManagerService {
1544
1666
  private createKeyRecord;
1545
1667
  /** Find the first existing key value worth importing. */
1546
1668
  private findImport;
1669
+ /**
1670
+ * The installed catalog's models for one route, normalized for a profile
1671
+ * write, or `undefined` when the seam cannot answer. A `provider`-only
1672
+ * discovery request reads pi-ai's bundled catalog instead of the endpoint,
1673
+ * so materializing a profile for an unconfigured route uses no network and
1674
+ * no credential.
1675
+ */
1676
+ private catalogModelsFor;
1677
+ /**
1678
+ * Write the installed catalog's models into a route's missing profile, or
1679
+ * into one that exists without models. The written profile names no
1680
+ * credential reference and no endpoint: pi-ai falls back to the catalog for
1681
+ * both, and a broker reference here would shadow a stored OAuth grant.
1682
+ *
1683
+ * A profile created while the catalog call was outstanding belongs to the
1684
+ * user, so the write re-reads it and only fills models a working profile
1685
+ * still lacks. `created` distinguishes the node this call created from a
1686
+ * user profile it filled, because rollback may only remove the former.
1687
+ */
1688
+ private materializeCatalogProfile;
1689
+ /**
1690
+ * Repair the profile a row test needs on an already-managed route: a route
1691
+ * adopted before profiles were materialized has none, and a key-pool profile
1692
+ * carried over from Models may lack models.
1693
+ *
1694
+ * Rules: a profile carrying models is never touched; one missing them is
1695
+ * filled; a missing profile is rebuilt only when the record gives no sign of
1696
+ * ever having had one. A pre-fix adoption records neither `hadProfile` nor
1697
+ * `createdProfile`, so a profile the user deletes there cannot be told apart
1698
+ * from a route that never had one — it is rebuilt, and the row test is the
1699
+ * only caller.
1700
+ */
1701
+ private ensureCatalogProfile;
1547
1702
  /** Remote: take over one existing provider route. */
1548
1703
  adoptProvider(provider: string): Promise<StateView>;
1549
1704
  /**
@@ -1577,8 +1732,10 @@ export declare class KeysManagerService {
1577
1732
  * Undo an adoption whose initial binding write was refused (PR review
1578
1733
  * round 2): drop the managed record and its broker entry, delete the
1579
1734
  * plugin-scope copy this call created, and put back a pre-adoption
1580
- * reference that landed despite the refusal. The source credential and the
1581
- * profile's other fields are never touched — adoption only read them.
1735
+ * reference that landed despite the refusal. The source credential is never
1736
+ * touched, and a profile this adoption materialized is removed whole only
1737
+ * while it still holds exactly that materialized node: a user save landing
1738
+ * between the write and the rollback owns the profile, so it keeps it.
1582
1739
  */
1583
1740
  private rollbackAdoption;
1584
1741
  /**
@@ -1597,7 +1754,9 @@ export declare class KeysManagerService {
1597
1754
  * the key that serves it in the same mutation, so the write below is the
1598
1755
  * route's first binding rather than a takeover of a value the user owns.
1599
1756
  */
1600
- addExtraProvider(extraId: string, alias: string, value: string): Promise<StateView>;
1757
+ addExtraProvider(extraId: string, alias: string, value: string,
1758
+ /** Provenance for the first row; `signin:<driver>` for an in-process sign-in. */
1759
+ importedFrom?: string | null): Promise<StateView>;
1601
1760
  /**
1602
1761
  * Restore a managed extra route's declared static headers.
1603
1762
  *
@@ -1618,7 +1777,7 @@ export declare class KeysManagerService {
1618
1777
  /** Add one key; caller already owns the mutation queue. */
1619
1778
  private addKeyLocked;
1620
1779
  /** Remote: add one key to a managed provider. */
1621
- addKey(provider: string, alias: string, value: string): Promise<StateView>;
1780
+ addKey(provider: string, alias: string, value: string, importedFrom?: string | null): Promise<StateView>;
1622
1781
  /** Remote: rename or pause/resume one key. */
1623
1782
  updateKey(provider: string, keyId: string, patch: unknown): Promise<StateView>;
1624
1783
  /** Remote: delete one key, releasing the provider when it was the last one. */