dsh-model-think-level 2.0.3 → 2.1.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 (55) hide show
  1. package/README.md +38 -22
  2. package/lib/balance.d.ts +44 -0
  3. package/lib/client/ComposerSlider.d.ts +19 -0
  4. package/lib/client/ConfigPane.d.ts +47 -0
  5. package/lib/client/EffortEditor.d.ts +1 -8
  6. package/lib/client/KeyManager.d.ts +2 -2
  7. package/lib/client/balance-client.d.ts +34 -0
  8. package/lib/client/events.d.ts +31 -2
  9. package/lib/client/image-config-client.d.ts +75 -0
  10. package/lib/client/injection/autofill-run.d.ts +2 -2
  11. package/lib/client/injection/config-button-seat.d.ts +96 -0
  12. package/lib/client/injection/create-key-seat.d.ts +3 -3
  13. package/lib/client/injection/create-keys-pane.d.ts +4 -2
  14. package/lib/client/injection/editor-tab-bar.d.ts +1 -1
  15. package/lib/client/injection/editor-tabs.d.ts +1 -1
  16. package/lib/client/injection/image-card.d.ts +85 -0
  17. package/lib/client/injection/imagegen-completion.d.ts +43 -0
  18. package/lib/client/injection/imagegen-entry.d.ts +22 -0
  19. package/lib/client/injection/key-prefetch.d.ts +44 -0
  20. package/lib/client/injection/key-reveal.d.ts +2 -3
  21. package/lib/client/injection/models-page-editor.d.ts +24 -27
  22. package/lib/client/injection/models-page.d.ts +15 -3
  23. package/lib/client/injection/provider-balance.d.ts +83 -0
  24. package/lib/client/injection/provider-endpoints.d.ts +2 -2
  25. package/lib/client/injection/row-drag.d.ts +7 -0
  26. package/lib/client/injection/staged-keys.d.ts +24 -12
  27. package/lib/client/key-manager-client.d.ts +68 -17
  28. package/lib/client/locales.d.ts +60 -6
  29. package/lib/client/ops.d.ts +1 -0
  30. package/lib/client/styles.d.ts +1 -1
  31. package/lib/client/types.d.ts +4 -1
  32. package/lib/client.js +672 -13
  33. package/lib/client.js.map +4 -4
  34. package/lib/constants.d.ts +45 -0
  35. package/lib/fingerprint/estimate.d.ts +16 -0
  36. package/lib/fingerprint/run.d.ts +6 -0
  37. package/lib/fingerprint/store.d.ts +2 -2
  38. package/lib/fingerprint/verdict.d.ts +24 -0
  39. package/lib/headers-core.d.ts +3 -1
  40. package/lib/headers-fetch.d.ts +25 -0
  41. package/lib/image/command.d.ts +84 -0
  42. package/lib/image/config.d.ts +150 -0
  43. package/lib/image/generate.d.ts +135 -0
  44. package/lib/image/legacy-cleanup.d.ts +29 -0
  45. package/lib/image/sizes.d.ts +28 -0
  46. package/lib/image/tool.d.ts +107 -0
  47. package/lib/index.js +3666 -1534
  48. package/lib/index.js.map +4 -4
  49. package/lib/key-index.d.ts +37 -7
  50. package/lib/key-probe.d.ts +42 -17
  51. package/lib/key-refs.d.ts +43 -19
  52. package/lib/key-route-core.d.ts +100 -32
  53. package/lib/key-serves.d.ts +81 -0
  54. package/lib/listing.d.ts +18 -20
  55. package/package.json +1 -8
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The keyed image card: the `tool.call.toolview` entry that renders the
3
+ * `generate_image` tool's result as actual pictures in the conversation.
4
+ *
5
+ * Without this entry the generic tool row shows only the result's TEXT — its
6
+ * image body (`imageCardModel`) is hard-wired to `read_image` — so the
7
+ * generated image would never be visible even though the durable result
8
+ * carries it. The card therefore reads the image blocks straight from the
9
+ * persisted result content and renders them through the OFFICIAL
10
+ * `tool.call.images` child slot (`dsh-client-ui-attachment`'s gallery), which
11
+ * needs no plugin-owned fetch route: the bytes load through the host's own
12
+ * attachment pipeline. Declaring `tool.call.images` under `children` is what
13
+ * authorizes the entry's `renderSlot` to dispatch it.
14
+ *
15
+ * The card is registered under the tool name the HOST reports (the config
16
+ * route's `tool.name`), because a dsh-image-gen install can own the plain
17
+ * `generate_image` key — the host then registers this plugin's tool under the
18
+ * fallback name, and the card must follow the tool, never the wishful name.
19
+ *
20
+ * @module dsh-model-think-level/client/injection/image-card
21
+ */
22
+ import type { ReactNode } from 'react';
23
+ import type { ClientContext } from '../types.js';
24
+ import type { Translate } from '@deepseek-ai/dsh-client-ui-slots';
25
+ /** One attachment reference as the official gallery consumes it. */
26
+ interface ImageRefLike {
27
+ readonly attachment: {
28
+ readonly attachmentId: string;
29
+ readonly mediaType: string;
30
+ readonly bytes: number;
31
+ readonly width: number;
32
+ readonly height: number;
33
+ readonly name?: string;
34
+ };
35
+ }
36
+ /** The block face the toolview slot occurrence carries, narrowed to what this card reads. */
37
+ interface ToolBlockLike {
38
+ /** Settled marker: a running call carries `phase` instead. */
39
+ readonly kind?: string;
40
+ readonly phase?: string;
41
+ readonly content?: readonly {
42
+ readonly type: string;
43
+ readonly text?: string;
44
+ readonly attachment?: ImageRefLike['attachment'];
45
+ }[];
46
+ readonly resultView?: {
47
+ readonly content?: readonly {
48
+ readonly type: string;
49
+ readonly text?: string;
50
+ readonly attachment?: ImageRefLike['attachment'];
51
+ }[];
52
+ };
53
+ readonly meta?: {
54
+ readonly model?: string;
55
+ readonly paramsUsed?: {
56
+ readonly size?: string;
57
+ readonly quality?: string;
58
+ readonly n?: number;
59
+ };
60
+ readonly revisions?: readonly string[];
61
+ readonly images?: readonly {
62
+ readonly filePath?: string;
63
+ }[];
64
+ };
65
+ }
66
+ /** The occurrence props the Tool row hands a keyed toolview entry. */
67
+ interface ImageCardProps {
68
+ readonly block?: ToolBlockLike;
69
+ readonly renderSlot?: (name: string, props: Record<string, unknown>) => ReactNode;
70
+ readonly loadImage?: (ref: ImageRefLike['attachment']) => unknown;
71
+ }
72
+ /** The image attachments one settled result carries, in order. */
73
+ export declare function imageRefsOf(block: ToolBlockLike | undefined): readonly ImageRefLike[];
74
+ /** The card component: gallery through the official slot, caption under it. */
75
+ export declare function ImageToolCard(props: ImageCardProps & {
76
+ t: Translate;
77
+ }): ReactNode;
78
+ /**
79
+ * Register the image card under the tool name the host reports. The name is
80
+ * a host-side fact (the collision fallback may have renamed the tool), so the
81
+ * registration waits for one config read when the cache is cold; a host that
82
+ * never answers leaves no card and the generic row stays.
83
+ */
84
+ export declare function registerImageCard(ctx: ClientContext, t: Translate): void;
85
+ export {};
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The `/生图` completion source's pure candidate logic (§4.8, 一期 = model-level).
3
+ *
4
+ * Two levels after the `/生图` trigger:
5
+ * 1. the first token completes to an image model (label and full id, fuzzy
6
+ * over both, the default marked);
7
+ * 2. after a model token (一期 stub): the param candidates arrive in 二期 —
8
+ * an empty list keeps the menu from showing a stale "nothing".
9
+ *
10
+ * Pure string logic — no DOM, no services — so the candidates are unit-testable
11
+ * against the exact strings the menu will render.
12
+ *
13
+ * @module dsh-model-think-level/client/injection/imagegen-completion
14
+ */
15
+ /** One completion candidate as the menu renders it. */
16
+ export interface ImagegenCandidate {
17
+ /** The rendered line (what the user sees). */
18
+ readonly label: string;
19
+ /** What lands in the draft when picked. */
20
+ readonly insertText: string;
21
+ /** The candidate's class of thing (model | param) — ordering/uses tests. */
22
+ readonly kind: 'model' | 'param';
23
+ /** Extra hint shown beside the label, when one exists. */
24
+ readonly hint?: string;
25
+ }
26
+ /** A model the completion offers, straight from the config view's rows. */
27
+ export interface CompletionModel {
28
+ readonly id: string;
29
+ readonly label: string;
30
+ readonly isDefault: boolean;
31
+ }
32
+ /**
33
+ * The candidates for the text after `/生图`. A leading model token (or its
34
+ * prefix) completes to models; everything else is the prompt — no candidates
35
+ * (the command itself runs without completion noise over free text).
36
+ */
37
+ export declare function imagegenCandidates(text: string, models: readonly CompletionModel[]): readonly ImagegenCandidate[];
38
+ /**
39
+ * The `/生图` word itself, as the top-level slash completion shows it (the
40
+ * menu that lists commands). Kept beside the candidates so the command's
41
+ * display and its completion can never drift apart.
42
+ */
43
+ export declare function imagegenCommandCandidate(): ImagegenCandidate;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The image-generation entry's service wiring (the client's only jobs in the
3
+ * v3 design — the switcher badges are already shipped in ComposerSlider, and
4
+ * point-select stays `directory.select` untouched):
5
+ *
6
+ * 1. the `/生图` completion source over the host input-trigger pipeline
7
+ * (`/` trigger, model-level candidates), registered ONLY when the host
8
+ * exposes the service — an older kernel just loses the completion, never
9
+ * the command itself;
10
+ * 2. a 30s-cached read of the image config, so a burst of completions costs
11
+ * one route read.
12
+ *
13
+ * @module dsh-model-think-level/client/injection/imagegen-entry
14
+ */
15
+ import type { ClientContext } from '../types.js';
16
+ /** Invalidate the cached model list (a settings change can add/remove rows). */
17
+ export declare function invalidateImagegenModels(): void;
18
+ /**
19
+ * Register the completion source. @returns the disposer (a no-op when the
20
+ * host has no input-trigger service to register with).
21
+ */
22
+ export declare function registerImagegenCompletion(ctx: ClientContext): () => void;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Warming the key lists before any card opens.
3
+ *
4
+ * The key panel paints its rows from the last successful read and revalidates
5
+ * in the background, so an expansion is instant exactly as long as the route's
6
+ * list has been read once on this page. Nothing reads it before the first
7
+ * expansion, though — the user's first 编辑 on a freshly opened Models page
8
+ * paid the whole read latency (a settings read plus one credential resolve per
9
+ * key, behind the host's serialised settings service) as a visible "正在读取密
10
+ * 钥…" line, every session, on every route.
11
+ *
12
+ * This pass asks once per provider per page opening, fire-and-forget, the same
13
+ * moment the page's provider list first shows: the read is what an expansion
14
+ * would have asked for anyway, only earlier and off the critical path. It is
15
+ * the balance chip's timing contract (one read per provider per opening), put
16
+ * to work for the key panel. No interval, no polling — a failed warm-up is
17
+ * simply retried by the panel's own mount read when the card opens.
18
+ *
19
+ * @module dsh-model-think-level/client/injection/key-prefetch
20
+ */
21
+ import type { KeyManagerClient } from '../key-manager-client.js';
22
+ import type { HostLabels } from './models-page-editor.js';
23
+ /** Per-session bookkeeping (one instance lives in `models-page.ts`). */
24
+ export interface KeyPrefetchState {
25
+ /** Routes already asked during THIS page opening. */
26
+ readonly requested: Set<string>;
27
+ /** Whether the provider list was present in the previous pass. */
28
+ visible: boolean;
29
+ }
30
+ /** A fresh state for one page instance. */
31
+ export declare function createKeyPrefetchState(): KeyPrefetchState;
32
+ /** What the pass needs from its host. */
33
+ export interface KeyPrefetchDeps {
34
+ /** The official `settings.models` label sets, resolved fresh on every scan. */
35
+ readonly labels: () => HostLabels;
36
+ /** Transport; injectable for tests. */
37
+ readonly client?: KeyManagerClient;
38
+ }
39
+ /**
40
+ * Visit the provider list once per scan: on a (re)opened page, ask the host for
41
+ * each visible provider's key list, once, and let the panel's cache hold the
42
+ * answer until an expansion needs it.
43
+ */
44
+ export declare function reconcileKeyPrefetch(root: HTMLElement, deps: KeyPrefetchDeps, state: KeyPrefetchState): void;
@@ -101,8 +101,7 @@ export declare function loadProviderKey(route: string): Promise<string | undefin
101
101
  * value into its draft state — so a re-render keeps it instead of reverting to
102
102
  * the empty draft.
103
103
  *
104
- * The create card's key-list pane uses the same gesture to take a value the
105
- * user had already typed out of the official box when the draft list takes
106
- * the field over.
104
+ * The create card uses the same gesture to mirror its enabled draft key into
105
+ * the official form, so Fetch models and Save use the key shown in the list.
107
106
  */
108
107
  export declare function writeInputValue(input: HTMLInputElement, value: string): void;
@@ -115,7 +115,10 @@ export interface InjectorDeps {
115
115
  */
116
116
  api: RemoteApi;
117
117
  /** Read the pi-ai namespace plus writability from the settings join. */
118
- describeNamespace(): Promise<SettingsJoin>;
118
+ describeNamespace(options?: {
119
+ fresh?: boolean;
120
+ allowStale?: boolean;
121
+ }): Promise<SettingsJoin>;
119
122
  /** Localized copy. */
120
123
  t: (key: string, params?: Record<string, string | number>) => string;
121
124
  /**
@@ -132,7 +135,7 @@ export interface InjectorDeps {
132
135
  * browser half hangs its autofill complement here: "the user stopped
133
136
  * editing" is the only moment this side may safely write the document.
134
137
  */
135
- onIdle?(): void;
138
+ onIdle?(join?: SettingsJoin): void;
136
139
  /** Wake the debounced scan after provider-wide adaptation stages a row. */
137
140
  onPendingChanged?(): void;
138
141
  /**
@@ -186,10 +189,6 @@ export interface EditorMountProps {
186
189
  * DOM, never a kernel version.
187
190
  */
188
191
  officialInputTypes?: boolean;
189
- /** The card reports whether it still covers the official capacity and
190
- * input-type fields: it does while its thinking switch is on, and steps
191
- * aside when the switch turns the card off. */
192
- onCoverageChange?: (covered: boolean) => void;
193
192
  api: EffortEditorApi;
194
193
  readOnly: boolean;
195
194
  t: (key: string, params?: Record<string, string | number>) => string;
@@ -280,6 +279,9 @@ export interface ScanState {
280
279
  editWired: WeakSet<Element>;
281
280
  /** The model lists' add-model buttons already wired for the top re-pin. */
282
281
  addModelWired: WeakSet<Element>;
282
+ /** The provider list's own add-provider button already wired for the top
283
+ * re-pin — the click that replaces the button with the new-provider card. */
284
+ addProviderWired: WeakSet<Element>;
283
285
  }
284
286
  /**
285
287
  * One staged declaration: the level set plus the suggestion's compat block and
@@ -473,15 +475,7 @@ export declare function hideOfficialReasoning(container: HTMLElement): void;
473
475
  * proves it — so an inline `display` the host wrote itself is left as it is.
474
476
  */
475
477
  export declare function showOfficialReasoning(container: HTMLElement): void;
476
- /**
477
- * Stand the official context-window / max-output labels and the input-types
478
- * fieldset down for a row whose editor renders those same decisions.
479
- *
480
- * Only DIRECT children of the disclosure are touched: the editor's own inputs
481
- * (and its own modality pills) live inside `.bre-effort-slot`, which carries
482
- * neither class stem. The marker attribute distinguishes this hide from one the
483
- * host wrote itself, exactly like {@link hideOfficialReasoning}.
484
- */
478
+ /** Stand both official copies down. Used when the editor leaves the row. */
485
479
  export declare function hideOfficialCapacityChrome(container: HTMLElement): void;
486
480
  /** Hand the official capacity/input-type chrome back when the editor goes. */
487
481
  export declare function showOfficialCapacityChrome(container: HTMLElement): void;
@@ -517,18 +511,21 @@ export declare function officialImageCheckboxOf(container: HTMLElement, imageLab
517
511
  */
518
512
  export declare function echoOfficialModality(container: HTMLElement, image: boolean, imageLabels: readonly string[]): boolean;
519
513
  /**
520
- * The modality intent a row's own write may carry, once the official
521
- * input-types control has been offered the verdict.
514
+ * The modality intent a row's own write carries, after the official
515
+ * input-types control has been MIRRORED with the verdict.
522
516
  *
523
- * `undefined` out means the write states nothing about the modality: either it
524
- * never carried one, or the official control took the verdict over. A row with
525
- * no such control — a legacy kernel, or a row the user has left folded — hands
526
- * its intent through unchanged, which keeps the document write as the way the
527
- * verdict travels.
528
- *
529
- * `null` is the plugin's deliberate UNSET, which the official control cannot
530
- * express at all (it knows only text and text+image): it passes through
531
- * untouched.
517
+ * The official checkbox renders the official card's own DRAFT, not the
518
+ * settings document — so a document write of the plugin's can never tick it
519
+ * before the card is saved and reopened, and the box has to be clicked for the
520
+ * user to see the verdict in the official form. That click is a mirror, never a
521
+ * handover: the row's own declaration still travels its write (or its staging),
522
+ * because the plugin's 支持模态 pills and the composer's vision badge both read
523
+ * the DOCUMENT. Dropping the intent once the box took the click — what this
524
+ * function used to do — left a bulk-adapted new provider with an unselected
525
+ * modality everywhere the user could see it.
526
+ *
527
+ * `null` (the plugin's deliberate UNSET) is untouched: the official control
528
+ * cannot express it at all.
532
529
  */
533
530
  export declare function officialModalityIntent(container: HTMLElement | undefined, input: InputModalities | null | undefined, imageLabels: readonly string[]): InputModalities | null | undefined;
534
531
  /**
@@ -735,7 +732,7 @@ export declare function suppressScrollAnchoring(node: HTMLElement, windowMs?: nu
735
732
  * offset is no longer the one this loop left is being scrolled by somebody
736
733
  * else, and is skipped rather than fought.
737
734
  */
738
- export declare function absorbDelta(chain: readonly HTMLElement[], watched: Set<HTMLElement>, lastSet: Map<HTMLElement, number>, delta: number): void;
735
+ export declare function absorbDelta(chain: readonly HTMLElement[], watched: Set<HTMLElement>, lastSet: Map<HTMLElement, number>, delta: number, priority?: readonly HTMLElement[]): void;
739
736
  /**
740
737
  * Start recording where a click inside a model list leaves its scroll host.
741
738
  *
@@ -16,7 +16,12 @@
16
16
  import type { ReactNode } from 'react';
17
17
  import type { Translate } from '@deepseek-ai/dsh-client-ui-slots';
18
18
  import { type HostLabels, type ScanState } from './models-page-editor.js';
19
- import type { ClientContext, RemoteApi } from '../types.js';
19
+ import type { ClientContext, RemoteApi, SettingsJoin } from '../types.js';
20
+ /** The Models-page title-row seat (the 「配置」 button) needs only copy + open. */
21
+ export interface ConfigSeatDeps {
22
+ readonly t: Translate;
23
+ readonly onOpen: () => void;
24
+ }
20
25
  /** What the Models-page injection needs from its host. */
21
26
  export interface ModelsPageDeps {
22
27
  /** The client root context. */
@@ -25,10 +30,17 @@ export interface ModelsPageDeps {
25
30
  api: RemoteApi;
26
31
  /** The plugin's locale-bound translator. */
27
32
  t: Translate;
28
- /** Run once per idle pass, after everything the session held back landed. */
29
- onIdle: () => void;
33
+ /**
34
+ * Run once per idle pass, after everything the session held back landed.
35
+ * The pass's own snapshot (a fresh wire read taken when the official card
36
+ * just closed) is handed over so a complement that needs to look at the
37
+ * document does not pay a second round trip for the same view.
38
+ */
39
+ onIdle: (join?: SettingsJoin) => void;
30
40
  /** Wrap a subtree so it re-translates on a language switch. */
31
41
  refreshed: (children: () => ReactNode) => ReactNode;
42
+ /** Present when the Models-page title row should carry the 「配置」 button. */
43
+ configSeat?: ConfigSeatDeps;
32
44
  }
33
45
  /** The Models-page injection's face. */
34
46
  export interface ModelsPageInjection {
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The balance chip in front of a provider's enable switch (Models page).
3
+ *
4
+ * The row shows the amount the provider's own balance endpoint answered, and
5
+ * nothing at all when that provider has no balance endpoint configured — the
6
+ * chip is decoration, not a control, so it must never invent a value or a
7
+ * placeholder. The URL lives in the plugin's key index (written from the
8
+ * provider card's 余额 row) and the host does the authenticated call
9
+ * (`../balance-client.ts`).
10
+ *
11
+ * Timing is deliberate: ONE read per provider per page opening. The Models page
12
+ * is the only place the list exists, so there is nothing to fetch while the
13
+ * user is elsewhere; when the provider list disappears the session is marked
14
+ * closed, and opening the page again starts one fresh read per provider. There
15
+ * is no interval and no polling — a second read inside the same opening only
16
+ * happens when the balance URL itself was written (see
17
+ * {@link invalidateProviderBalance}).
18
+ *
19
+ * A failed read does NOT throw the last answer away: the chip keeps the last
20
+ * successful amount (requirement: show the previous value when nothing new
21
+ * arrived). Only a route that has never answered falls back to the failed chip,
22
+ * and only when its endpoint really is configured — otherwise nothing is shown.
23
+ *
24
+ * The chip is placed immediately BEFORE the switch — the switch belongs to the
25
+ * provider's state, the balance is context for it — and the position is
26
+ * re-asserted on every scan, because the official row can re-render its action
27
+ * group at any time.
28
+ *
29
+ * @module dsh-model-think-level/client/injection/provider-balance
30
+ */
31
+ import { type BalanceReading } from '../../balance.js';
32
+ import { type BalanceClient } from '../balance-client.js';
33
+ import type { HostLabels } from './models-page-editor.js';
34
+ /** Per-session bookkeeping (one instance lives in `models-page.ts`). */
35
+ export interface ProviderBalanceState {
36
+ /** Route → the last successful reading (kept across a failed re-read). */
37
+ readonly readings: Map<string, BalanceReading>;
38
+ /** Route → the last failure's reason, for routes with no reading yet. */
39
+ readonly errors: Map<string, string>;
40
+ /** Routes already asked during THIS page opening. */
41
+ readonly requested: Set<string>;
42
+ /** Routes with a read in flight. */
43
+ readonly inflight: Set<string>;
44
+ /** Routes invalidated while a read was in flight (re-read on settle). */
45
+ readonly pending: Set<string>;
46
+ /** Whether the provider list was present in the previous pass. */
47
+ visible: boolean;
48
+ }
49
+ /** What the chip needs from its host. */
50
+ export interface ProviderBalanceDeps {
51
+ /** The plugin's own translator, for the chip's label and tooltip. */
52
+ readonly t: (key: string, params?: Record<string, string | number>) => string;
53
+ /** The official `settings.models` label sets, resolved fresh on every scan. */
54
+ readonly labels: () => HostLabels;
55
+ /** Transport; injectable for tests. */
56
+ readonly client?: BalanceClient;
57
+ /**
58
+ * Ask the page for one more reconcile after an answer landed for a row that
59
+ * is no longer in the DOM (the page was closed and reopened while the read
60
+ * was in flight). Without it that answer would wait for an unrelated
61
+ * mutation to reach the new row.
62
+ */
63
+ readonly repaint?: () => void;
64
+ }
65
+ /** A fresh state for one page instance. */
66
+ export declare function createProviderBalanceState(): ProviderBalanceState;
67
+ /**
68
+ * Visit every provider row: paint what is known, and ask once per page opening
69
+ * for a route that has not been asked in this opening.
70
+ *
71
+ * A missing provider list means the Models page is closed (or not rendered):
72
+ * the opening is over, so the next presence starts a new read session. No
73
+ * request is made from this function while the list is absent.
74
+ */
75
+ export declare function reconcileProviderBalance(root: HTMLElement, deps: ProviderBalanceDeps, state: ProviderBalanceState): void;
76
+ /**
77
+ * Forget one route's session, so the next reconcile reads it now.
78
+ * A balance URL was just written (or cleared): the old amount belongs to the
79
+ * old endpoint, and waiting for a page reopening would leave the chip lying.
80
+ */
81
+ export declare function invalidateProviderBalance(state: ProviderBalanceState, route: string): void;
82
+ /** Remove every chip (the fiber is going away). */
83
+ export declare function teardownProviderBalance(): void;
@@ -19,8 +19,8 @@
19
19
  * - **extra endpoints can be added.** A grey "更多端点" text button directly
20
20
  * under the API address — where the rows it reveals appear — opens one more
21
21
  * address row for EVERY family the selected protocol does not serve
22
- * (Anthropic and Gemini under an OpenAI protocol, OpenAI and Gemini under
23
- * Anthropic). They persist to the route's `endpoints` in this plugin's key
22
+ * (Anthropic under an OpenAI protocol, OpenAI under Anthropic). They persist
23
+ * to the route's `endpoints` in this plugin's key
24
24
  * index, which is what a key pinned to that family signs against.
25
25
  *
26
26
  * The add card carries the same three fields, so the same decoration applies to
@@ -163,6 +163,13 @@ export declare function scrollHostOf(node: HTMLElement): HTMLElement | undefined
163
163
  * range away exactly like a deletion inside a small panel would.
164
164
  */
165
165
  export declare function scrollChainOf(node: HTMLElement): HTMLElement[];
166
+ /**
167
+ * Every declared scroll container that can hold `node` after layout changes,
168
+ * nearest first, plus the page scroller. Unlike {@link scrollChainOf}, this
169
+ * includes auto/scroll containers before they overflow so a card can be pinned
170
+ * across the same render that creates their scroll range.
171
+ */
172
+ export declare function scrollContainerCandidatesOf(node: HTMLElement): HTMLElement[];
166
173
  /** The pixels per frame `host` should scroll while the pointer is at `clientY`. */
167
174
  export declare function edgeScrollStep(host: HTMLElement, clientY: number): number;
168
175
  /**
@@ -53,14 +53,14 @@ export interface StagedKeyDraft {
53
53
  readonly enabled: boolean;
54
54
  }
55
55
  /** How far the drain got with one draft: its host reference once the value
56
- * landed, and whether the metadata after it has landed too. */
56
+ * landed, and the draft fields the host currently holds for it. */
57
57
  interface StagedKeyLanding {
58
58
  /** The draft this landing belongs to ({@link StagedKeyDraft.ref}). */
59
59
  readonly ref: string;
60
- /** The reference the host minted when it stored the value. */
60
+ /** The reference the host minted or reused when it stored the value. */
61
61
  readonly hostRef: string;
62
- /** Whether the protocol pin and the switch-off have landed too. */
63
- done: boolean;
62
+ /** Snapshot of the fields currently applied to the host reference. */
63
+ draft: StagedKeyDraft;
64
64
  }
65
65
  /** One pane's held key list, keyed by the route it will be written to. */
66
66
  export interface StagedKeyIntent {
@@ -68,13 +68,16 @@ export interface StagedKeyIntent {
68
68
  drafts: readonly StagedKeyDraft[];
69
69
  /** Which drafts have already landed, with the host references they landed as. */
70
70
  readonly landed: StagedKeyLanding[];
71
- /** Whether this route was already declared when the intent was staged. */
71
+ /** Changes whenever the pane replaces this intent's desired draft list. */
72
+ revision: number;
73
+ /** Whether this route was already declared when this card first asked. */
72
74
  declaredBefore?: boolean;
73
75
  /** When the pane that staged this intent unmounted, if it has. */
74
76
  releasedAt?: number;
75
- /** Whether the drain has already said — once — that this route has no
76
- * baseline, the one holding state that ends in silence. */
77
+ /** Whether a missing pre-save baseline has already been reported. */
77
78
  noted?: boolean;
79
+ /** A post-save route exists, but its pre-save ownership is unknown. */
80
+ baselineMissing?: boolean;
78
81
  /** Failed drain passes since the last one that wrote something. */
79
82
  attempts: number;
80
83
  }
@@ -83,12 +86,17 @@ export interface StagedKeysState {
83
86
  /** Held drafts, by route. Readable so a test (and the console) can see what
84
87
  * the session is still holding. */
85
88
  readonly intents: Map<string, StagedKeyIntent>;
86
- /** What each route's baseline read found, kept for the session so a list
87
- * restaged after the drain retired its intent does not have to ask again. */
89
+ /** The first successful pre-save answer for each route. */
88
90
  readonly baseline: Map<string, boolean>;
89
- /** One drain at a time: an unmount's release-triggered flush and a scan's
90
- * drain must not both walk the ledger and write the same route. */
91
+ /** Baseline reads currently in flight. */
92
+ readonly baselinePending: Set<string>;
93
+ /** Baseline reads that failed before producing a pre-save answer. */
94
+ readonly baselineFailures: Set<string>;
95
+ /** Active intents keep late add references available to a restaged route. */
96
+ readonly activeIntents: Map<string, StagedKeyIntent>;
97
+ /** One drain at a time, with another pass requested on concurrent edits. */
91
98
  draining: boolean;
99
+ drainAgain: boolean;
92
100
  }
93
101
  /** A fresh, empty ledger. */
94
102
  export declare function createStagedKeysState(): StagedKeysState;
@@ -105,7 +113,7 @@ export declare function createStagedKeysState(): StagedKeysState;
105
113
  * @param drafts - the complete draft list.
106
114
  */
107
115
  export declare function stageKeys(state: StagedKeysState, route: string, drafts: readonly StagedKeyDraft[]): void;
108
- /** Drop the drafts held for one route. */
116
+ /** Drop the drafts for a route; an active request will stop after it settles. */
109
117
  export declare function withdrawKeys(state: StagedKeysState, route: string): void;
110
118
  /**
111
119
  * Mark one route's drafts as orphaned: the pane that staged them is gone and
@@ -118,6 +126,10 @@ export declare function releaseKeys(state: StagedKeysState, route: string): void
118
126
  * intent does not ask twice.
119
127
  */
120
128
  export declare function markKeysRouteBaseline(state: StagedKeysState, route: string, declared: boolean): void;
129
+ /** Mark a baseline read as in flight before issuing the pre-save request. */
130
+ export declare function beginKeysRouteBaseline(state: StagedKeysState, route: string): boolean;
131
+ /** Record a failed baseline read without allowing a later route state to replace it. */
132
+ export declare function failKeysRouteBaseline(state: StagedKeysState, route: string): void;
121
133
  /**
122
134
  * Whether `route` still needs its baseline read.
123
135
  * @returns True when the pane should ask the settings document.