dsh-model-think-level 1.1.8 → 2.0.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.
package/README.md CHANGED
@@ -25,6 +25,44 @@ DSH 的第三方模型补齐思考等级:在官方 Models 页每个模型行
25
25
 
26
26
  不要删除整个供应商配置,也不要将包含 API key 的配置文件贴到公开 issue。
27
27
 
28
+ ## 多密钥与按模型分流
29
+
30
+ 同一个供应商可以登记多把密钥,请求进来时按「模型 → 密钥」自动分流:
31
+
32
+ - 密钥按列表顺序排队。一个模型如果多把密钥都能访问,先走列表靠前的那把;某把密钥对某模型请求失败(401/403/408/429/5xx)时,自动换下一把能访问该模型的密钥重试;400/404/422 这类请求本身的问题不重试,直接返回。被拒的那把密钥会记住这次失败(时长取自 `Retry-After`,没有就按「太频繁」60 秒、「额度耗尽」30 分钟、「连接被拒」60 秒推算,重复失败翻倍并封顶),下次请求自动排到健康密钥后面;冷却只是排序,密钥永远不会被真正丢弃——全体都在冷却时仍按原顺序尝试。
33
+ - 密钥能访问哪些模型可自动探测(密钥面板的「探测模型」按钮会逐一读取每把密钥各自的 `/models` 列表并记录),也可在「模型」里手动填写覆盖。探测按「这把密钥实际会被派到哪些协议/地址」进行,见下节。
34
+ - 未探测过的密钥视为「通吃」,可以服务任何模型;探测后只服务列表内的模型。
35
+ - 每把密钥行首有一个圆形对勾开关:亮起表示参与路由,灰色表示暂停使用。停用只是把密钥移出分流池,别名、模型清单与协议指定全部保留,重新点亮即恢复;最后一把启用中的密钥不允许停用(否则请求会回落到适配器自身的单密钥路径,仍然用刚被停用的那把签名)。
36
+ - 插件自身元数据保存在 DSH 数据目录的 `dsh-model-think-level/key-index.json`,只记录引用、别名、模型清单、协议指定与启停状态,绝不保存密钥值(密钥值始终由 DSH 凭据库保管)。
37
+ - 新增供应商的表单也是这套卡片式密钥列表(不再是单个密钥输入框):密钥先暂存在本页,点「创建」供应商落库后自动写入,第一把自动成为启用密钥;挂载前已敲进官方输入框的值会自动收进列表第一行。刷新页面会丢弃草稿,与表单自身行为一致;若 id 撞上已存在的供应商,草稿不会写入对方。
38
+
39
+ ### 按密钥切换协议与多地址
40
+
41
+ 有些供应商同一把密钥只在某一种线上协议下可用(例如同一家既有 OpenAI Chat Completions 端点、又有 Anthropic Messages 端点)。插件支持在密钥面板里给每把密钥单独指定协议:
42
+
43
+ - 「这个密钥可用的协议」有「自动(按模型)」「Anthropic」「Chat Completions」「Responses」「Gemini」五档,默认「自动(按模型)」——每个请求按模型自己所属的协议族挑线路:claude 系模型走 Anthropic 地址、gemini 系走 Gemini 地址(前提是供应商配置了对应族的地址),其余模型沿用该供应商自身配置的协议。
44
+ - 给某把密钥指定协议后,命中该密钥的请求会真正换用对应的线上协议(不只是换 URL/鉴权头:请求体也按该协议重新编码),由插件在 pi-ai 适配层重新派发到 `@earendil-works/pi-ai` 的对应协议实现。
45
+ - 供应商可以按「地址家族」配置最多三个基础地址:一个 OpenAI 系(Chat Completions / Responses 共用)、一个 Anthropic 系、一个 Gemini 系。供应商卡片「API 地址」下方的「更多端点」会展开当前协议家族之外的其他家族地址行。密钥指定协议后,就用与之匹配的那个地址;「自动」档的密钥按模型所属族使用对应地址,模型不属任何已配地址的族时仍使用供应商自身的 `baseURL`。
46
+ - 若密钥指定的协议跨了地址家族(如 OpenAI 系 ↔ Anthropic 系 ↔ Gemini 系)而供应商**没有**配置该家族的地址,这条指定不会生效:请求仍用供应商自身的协议和 `baseURL`,只由这把密钥签名。把 OpenAI 格式的请求体发到 Anthropic/Gemini 家族的地址只会换来网关的 `404`/`400`(模型根本不会被调用),所以宁可不换。这条在**每次调用时**都重新判定,供应商地址补上后同一个模型立刻换用该协议的密钥。「自动」档同理:某族没有地址就回落到供应商自身的协议。
47
+ - 自动挑错线路有记忆:某族地址对一个模型返回了「还没产生内容就失败」(典型如网关 404)后,这个 (供应商, 模型) 组合的自动解析不再挑那一族,改用供应商自身协议,直到插件进程重启;成功过的线路也会被记住并优先使用。钉选协议的密钥不受这层记忆影响——钉选表达的是用户的明确意图,其失败只说明凭据问题。
48
+ - 两把密钥指定了不同协议(或「自动」档解析出了不同协议)时,先试哪把不再取决于列表顺序,而是按「这个模型看起来属于哪一族」排:模型名(含 `anthropic/`、`openai/`、`google/gemini-…` 这类前缀或裸名,`gemini`/`gemma` 开头的名字属于 Gemini 族)与密钥协议的家族一致者优先,其次是以本密钥自身地址就能直接服务的,再次是不一致但能回落到供应商主地址的,最后是跨族且没有自己地址的。请求会从排第一的密钥的协议开始——切协议意味着换请求体形状,一次只切一把密钥,失败后按此顺序换下一把。
49
+ - 同一协议(wire)的密钥会被当作一个池:先把这个池里的密钥都用完再换 wire,因为同一把密钥失败通常与协议无关;跨 wire 的切换排在池之后,且只有在上一次失败的请求还没开始产生内容时才会做。
50
+ - 请求进行到一半再失败(已经开始流式输出、或调用方已经主动取消)不会触发换密钥——客户端已经消费了已经发出的内容,重放只会产生重复输出。
51
+ - 密钥面板的「模型」选择改为可点选的真实模型清单(探测得到的模型做成多选胶囊),选中的模型才交给这把密钥;下面的「全部模型」表示不做限制。该项与其它操作按钮一样只在悬停时显示。
52
+ - 「探测模型」现在按协议探测,而不是把每把密钥都按供应商默认协议问一遍:
53
+ - 没指定协议的密钥,分别问供应商自身协议的地址、以及供应商配置了的其他族地址(配了几族就问几族),得到的模型取并集——这正是它实际会被派到的几条线。
54
+ - 指定了协议的密钥只问它自己那条线:同族指定仍用供应商主地址,跨族指定必须用该族的基础地址。
55
+ - 跨族指定但供应商没配该族地址的密钥会被**跳过**,原有模型清单保持不变(不会因为问不到就被清空)。
56
+ - 供应商本身的协议既不是 Chat Completions / Responses 也不是 Anthropic Messages(插件说不出的协议)时不猜地址,直接提示无法探测;除非面板里配了某一族的基础地址,那就只问配了地址的那几族。
57
+ - 探测结果在响应里逐条返回(协议、脱敏后的地址、HTTP 状态、模型数、失败原因),每把密钥的结果互不影响:一族被拒不影响另一族把模型写进清单。
58
+ - 模型页供应商卡片的「获取模型」走同一套合并:按上面的规则问过每把密钥实际会被派到的几条线后取并集。**单个密钥也一样**——只要供应商配置了多个地址(或该密钥指定了协议),获取到的就是全部地址上模型的并集,而不是只有供应商自身协议那一份;供应商卡里原配的那把密钥(从未在密钥面板列出过的)同样按「自动(按模型)」参与这条合并。
59
+
60
+ ### Gemini 原生协议
61
+
62
+ - 「Gemini」档指 Google 原生协议(`gemini model: generateContent / streamGenerateContent`,鉴权用 `x-goog-api-key`)。受 DSH 宿主适配层限制,供应商卡片的「API 协议」下拉里不会有 Gemini;原生访问一律通过「更多端点里的 Gemini 地址行 + 密钥指定 Gemini」完成,供应商自身的协议保持 OpenAI/Anthropic 三选一即可(纯 Gemini 网关可把主地址指向该网关任意可答路径)。
63
+ - Gemini 地址需包含版本段(官方为 `https://generativelanguage.googleapis.com/v1beta`);只填裸域名时插件会自动补 `/v1beta`,路径非空则按网关自己的拼写使用。列表探测走原生 `GET {地址}/models?pageSize=1000`,模型名会剥掉 `models/` 前缀,只保留支持 `generateContent` 的条目。
64
+ - 思考等级沿用模型上声明的档位:pi-ai 会把 low/medium/high 翻译成 Gemini 的 `thinkingLevel`(Gemini 3 / Gemma 4)或 `thinkingBudget`(2.5 系);在插件的 Thinking 编辑器里为 gemini 模型声明等级后原生请求即会携带。
65
+
28
66
  ## 开发与验证
29
67
 
30
68
  使用 Node.js `^22.19.0 || >=24`。依次运行 `npm ci`、`npm run typecheck`、`npm test`、`npm run build`、`npm run check:package`。测试最多并行 4 个 worker,以控制 DOM 测试的内存占用;仍使用 Vitest 默认超时。
@@ -20,19 +20,19 @@ export interface ComposerSliderProps {
20
20
  configuredInputs?: ConfiguredInputs;
21
21
  /** Localized copy (the plugin's bound translator). */
22
22
  t: Translator;
23
- /**
24
- * Re-measure hook. The official card measures itself from its own layout
25
- * effect (`[open, pane, state]`) and only re-runs on a window `resize`, so a
26
- * body that grows here must ask the injector to re-place it — in the same
27
- * frame, never from a deferred task.
28
- */
29
- onLayoutChange?: () => void;
30
23
  }
31
24
  /** Provider label: the SDK face names it differently across kernel lines. */
32
25
  export declare function providerLabelOf(group: DirectoryGroupLike): string;
33
26
  /**
34
- * Render the model row and the reasoning-level row. Both values come from the
35
- * store; the commit travels through {@link ModelDirectoryLike.select}
27
+ * The ramp colour at `t` in 0..1 — the hue a ladder stop at that fraction of
28
+ * the track wears. Every stop of every ladder length lands on the same
29
+ * continuous cool→hot scale, so the colour alone reads as the effort's
30
+ * intensity whatever the ladder spells its levels.
31
+ */
32
+ export declare function effortRampColor(t: number): string;
33
+ /**
34
+ * Render the model switcher and the reasoning-level footer. Both values come
35
+ * from the store; the commit travels through {@link ModelDirectoryLike.select}
36
36
  * (optimistic, rolled back on refusal).
37
37
  */
38
38
  export declare function ComposerSlider(props: ComposerSliderProps): ReactNode;
@@ -5,12 +5,15 @@
5
5
  * everything arrives through a plain props face, so it stays testable in
6
6
  * isolation. The draft/intent rules live in the client/effort module.
7
7
  *
8
- * Suggestion feedback is ZONED: provenance + confidence form their own line;
9
- * capacity references render as a separate read-only block explicitly marked
10
- * "never auto-filled" -- the official capacity inputs above stay untouched.
11
- * The apply/reset actions sit at the very bottom and own every section.
12
- *
13
- * @module dsh-model-think-level/EffortEditor
8
+ * The redesign's shape: one head line (the master switch, the "declared N ·
9
+ * default X" state, and the applied suggestion's provenance pill), the level
10
+ * ladder as a row of toggle pills with the armed levels' wire spellings in a
11
+ * compact row beneath, and the default pick and input modality as pill rows in
12
+ * two columns. The capacities are editable here: the two fields mirror the
13
+ * official row's own context-window / max-output inputs and write straight back
14
+ * into them, so this card and the official disclosure are one draft with one
15
+ * Save (a blank field hands the model back to the catalogue value). The
16
+ * apply/reset actions sit at the very bottom and own every section.
14
17
  */
15
18
  import type { ReactNode } from 'react';
16
19
  import type { CompatSuggestion, InputModalities, ReasoningEfforts } from '../knowledge.js';
@@ -1,6 +1,7 @@
1
1
  /**
2
- * The API-key list: one provider's keys, which one is in use, and the one
3
- * inline form that adds, relabels or replaces a key.
2
+ * The API-key list: one provider's keys, the model scope each key serves, the
3
+ * wire protocol each key speaks, the provider's two base URLs, and the one
4
+ * inline form that adds, relabels, replaces a key or edits its scope.
4
5
  *
5
6
  * Rendered inline under the official key field (see `injection/key-manager`),
6
7
  * not as a floating panel: the field's label already says "API key", so its list
@@ -11,18 +12,35 @@
11
12
  * The list is a view over host state and holds no truth of its own — every
12
13
  * mutation answers with the whole list, and the list is adopted as it arrives
13
14
  * (`adopt`), so the GUI can never drift from what the settings document and the
14
- * credential store actually say. Three facts it deliberately reflects:
15
+ * credential store actually say. The facts it reflects:
15
16
  *
16
- * - **the key in use is the profile's reference.** Choosing a row writes
17
- * `providers.<route>.apiKeyEnv`, so it holds for every request the route
18
- * makes, not only the ones this GUI starts. Exactly one key is in use per
19
- * provider, which is why the mark at the head of a row is a radio.
17
+ * - **every key switched on is active.** The keys are ordered by preference,
18
+ * the first one that can serve a model signs it, a model only one key lists
19
+ * sticks to that key, and a failed request fails over to the next capable
20
+ * key. Each row opens with a circular check that switches the key into or
21
+ * out of that pool: lit is in use, grey is paused — with the label, scope
22
+ * and protocol pin kept for the switch back on. Which key signs a request
23
+ * is decided by the model's scope, not by a row's position, so with several
24
+ * keys there is no "default" seat to mark any more.
25
+ * - **each key shows the models it serves.** Picked as chips from the models
26
+ * the route already offers — never the provider's whole catalog — so no one
27
+ * has to recall a model id, and an empty scope means "catch-all", serving
28
+ * whatever is left. The scope summary shares the hover-revealed action tray,
29
+ * so a resting row stays quiet.
30
+ * - **each key may pin a wire protocol.** A key that pins a protocol speaks
31
+ * that API shape (Anthropic Messages, Chat Completions or Responses) instead
32
+ * of the provider's default, and uses the matching base URL. A key left on
33
+ * "auto" speaks each model's own wire: claude models against the Anthropic
34
+ * address, gemini models against the Gemini one, the rest the provider's
35
+ * protocol — wherever that address is configured. The protocol picker lives
36
+ * in the same hover-revealed action tray as the other actions.
20
37
  * - **a value is shown masked, or not at all.** The host reads the stored
21
38
  * secret and answers a head-and-tail preview; the middle never leaves it,
22
39
  * and the eye beside the field stays the one gesture that reveals a value.
23
- * - **one form serves all three edits.** Adding, relabelling and replacing a
24
- * value differ only in which fields it shows, so they share a form rendered
25
- * as the row below the row they act on — for an add, the list's last row.
40
+ * - **one form serves all edits.** Adding, relabelling, replacing a value and
41
+ * editing a scope differ only in which fields the form shows, so they share
42
+ * one form rendered as the row below the row they act on — for an add, the
43
+ * list's last row.
26
44
  *
27
45
  * @module dsh-model-think-level/client/KeyManager
28
46
  */
@@ -38,6 +56,14 @@ export interface KeyManagerProps {
38
56
  readonly t: Translate;
39
57
  /** Transport; injectable for tests. */
40
58
  readonly client?: KeyManagerClient | undefined;
59
+ /**
60
+ * Draft mode — the create-provider card's list over an in-memory store
61
+ * instead of the host's. Rows read as "saved on create" rather than probed,
62
+ * the model-scope action is gone (the provider has no models to pick from
63
+ * before it exists), and every protocol is offered (the address a pin rides
64
+ * is the card's own Base URL field, which no endpoint family reports yet).
65
+ */
66
+ readonly draft?: boolean | undefined;
41
67
  }
42
68
  /**
43
69
  * Render the key list for one provider route.
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The protocol menu a key's picker opens.
3
+ *
4
+ * A native `<select>` was the first shape of this control, but the OS draws its
5
+ * list and no page can put an explanation beside an option — and these options
6
+ * are not self-describing: "Chat Completions" and "Responses" are the same
7
+ * provider's two wires, and which one a key should use is a question about the
8
+ * models behind it, not about the acronym. The menu therefore renders its own
9
+ * list: one row per protocol, the protocol's name, and the line that says what
10
+ * it is for. The row in force takes the accent tint and accent ink — and no
11
+ * tick: a tick makes the picked row wider than its neighbours, so the list would
12
+ * shift under the pointer at the very moment of the pick (选中只高亮,不加对勾).
13
+ *
14
+ * It is portalled onto `<body>`: the key list clips its own overflow, so a menu
15
+ * drawn inside the row would be cut off by the panel it belongs to. Fixed
16
+ * positioning against the trigger's rect keeps it attached while the settings
17
+ * page scrolls, and it closes on an outside press, on Escape, and on a pick.
18
+ *
19
+ * @module dsh-model-think-level/client/ProtocolMenu
20
+ */
21
+ import type { ReactNode } from 'react';
22
+ /** One choice: the protocol's stored value, its name, and what it is for. */
23
+ export interface ProtocolOption {
24
+ /** The value written to the key index ('' = follow the provider's own). */
25
+ readonly value: string;
26
+ /** The protocol's name, as the row reads it. */
27
+ readonly title: string;
28
+ /** One line saying what the protocol is for. */
29
+ readonly hint: string;
30
+ }
31
+ /** Props of {@link ProtocolMenu}. */
32
+ export interface ProtocolMenuProps {
33
+ /** The trigger the menu hangs off. */
34
+ readonly anchor: HTMLElement;
35
+ /** The menu's own heading. */
36
+ readonly label: string;
37
+ /** The choices, in order; the pinned one keeps its own seat (see offeredProtocols). */
38
+ readonly options: readonly ProtocolOption[];
39
+ /** The value currently in force ('' for the provider's own protocol). */
40
+ readonly selected: string;
41
+ /** Called with the picked value; the menu closes itself afterwards. */
42
+ readonly onPick: (value: string) => void;
43
+ /** Called when the menu wants to close without a pick. */
44
+ readonly onClose: () => void;
45
+ }
46
+ /**
47
+ * Render the protocol menu for one key row.
48
+ * @param props - see {@link ProtocolMenuProps}.
49
+ * @returns the menu, portalled onto `<body>`.
50
+ */
51
+ export declare function ProtocolMenu(props: ProtocolMenuProps): ReactNode;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The one document-level event the browser half uses to keep its two separate
3
+ * React roots in step.
4
+ *
5
+ * The provider card and the key list are mounted independently: the card owns the
6
+ * two base URLs (`endpoints`) of a route, and the key list decides which protocols
7
+ * a key may pin from those very addresses. Neither can call the other, so the card
8
+ * says what changed and the list re-reads.
9
+ *
10
+ * A plain string, so the host half can import it too without pulling in DOM code.
11
+ *
12
+ * @module dsh-model-think-level/client/events
13
+ */
14
+ /** Fired on `document` when a route's two base URLs changed. */
15
+ export declare const ENDPOINTS_CHANGED_EVENT = "bre:endpoints-changed";
16
+ /** What {@link ENDPOINTS_CHANGED_EVENT} carries. */
17
+ export interface EndpointsChangedDetail {
18
+ /** The route whose addresses moved. */
19
+ readonly route: string;
20
+ /** Its OpenAI-family base URL, '' when unset. */
21
+ readonly openai: string;
22
+ /** Its Anthropic-family base URL, '' when unset. */
23
+ readonly anthropic: string;
24
+ /** Its Gemini-family base URL, '' when unset (absent from older events). */
25
+ readonly gemini?: string;
26
+ }
@@ -28,6 +28,7 @@ import type { ReactNode } from 'react';
28
28
  import type { Translate } from '@deepseek-ai/dsh-client-ui-slots';
29
29
  import { type ForeignMount } from './mount.js';
30
30
  import type { StagedHeadersState } from './staged-headers.js';
31
+ import type { StagedKeysState } from './staged-keys.js';
31
32
  import type { RemoteApi } from '../types.js';
32
33
  export interface AddCardDeps {
33
34
  /** The plugin's own translator, for the tab labels and the pane's copy. */
@@ -38,6 +39,9 @@ export interface AddCardDeps {
38
39
  routeIdLabels: () => readonly string[];
39
40
  /** The session's deferred-header ledger (see `staged-headers`). */
40
41
  staged: StagedHeadersState;
42
+ /** The session's deferred-key ledger (see `staged-keys`): the drafts the
43
+ * custom form's key list stages, waiting for the route this card declares. */
44
+ stagedKeys: StagedKeysState;
41
45
  /** The plugin's locale-refresh seam, so the pane's copy follows a language
42
46
  * switch exactly as the seats the official slot mounts do. */
43
47
  refreshed: (children: () => ReactNode) => ReactNode;
@@ -51,3 +51,18 @@ export interface CreateCardPaneProps {
51
51
  }
52
52
  /** One create card's pane: its bar, and the headers pane once there is a route. */
53
53
  export declare function CreateCardPane({ host, api, t, routeIdLabels, staged }: CreateCardPaneProps): ReactNode;
54
+ /**
55
+ * The element whose typing can change the provider id: the panel this pane is
56
+ * mounted in, widened to the create card around it.
57
+ *
58
+ * The id field is the official form's, and which half of the card renders it is
59
+ * not something this pane may assume: the read is by label (never by position),
60
+ * so the card-wide scope can only ever find the SAME field the panel scope
61
+ * would — the difference is that it still finds it when the host puts that field
62
+ * outside the custom half. Shared with the create card's key-list pane, which
63
+ * needs the same live id for the same reason.
64
+ */
65
+ export declare function routeScopeOf(host: HTMLElement | null): HTMLElement | null;
66
+ /** The provider id the card's form currently holds, read by the official label.
67
+ * Shared with the create card's key-list pane. */
68
+ export declare function readRoute(host: HTMLElement | null, routeIdLabels: () => readonly string[]): string;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The create card's key-list seat: the official key field hands its input
3
+ * over to the plugin, and the DRAFT key list renders inline directly under it.
4
+ *
5
+ * The mirror of the edit card's seat (`injection/key-manager`), with two
6
+ * differences the create card forces. First, there is no route to key the
7
+ * list by — the id is being typed, and the drafts wait in the session ledger
8
+ * (`staged-keys`) for the route the card's own 保存 declares — so the list is
9
+ * the draft pane (`create-keys-pane`), not the host-backed one. Second, a
10
+ * value the user had already typed into the official box when this seat
11
+ * appears is SEED: taken out of the official form — which would otherwise save
12
+ * it as the provider's single key beside the list — and shown as the first
13
+ * draft row it becomes.
14
+ *
15
+ * The field keeps the edit card's managed-field handover: `bre-key-managed`
16
+ * stands the official input down (the list below says the same thing once per
17
+ * key), the input stays in the DOM — the host's form still owns it — and
18
+ * unmanaging the field brings the official box back.
19
+ *
20
+ * @module dsh-model-think-level/client/injection/create-key-seat
21
+ */
22
+ import type { ReactNode } from 'react';
23
+ import type { Translate } from '@deepseek-ai/dsh-client-ui-slots';
24
+ import type { StagedKeysState } from './staged-keys.js';
25
+ import type { RemoteApi } from '../types.js';
26
+ /** What a reconcile tells the field's key list. */
27
+ export interface CreateKeySeatDeps {
28
+ /** Copy for the list and its failure boundary. */
29
+ readonly t: Translate;
30
+ /** The write seam, for the pane's route-baseline reads. */
31
+ readonly api: RemoteApi;
32
+ /** The official labels of the form's provider-id field, by locale. */
33
+ readonly routeIdLabels: () => readonly string[];
34
+ /** The session's deferred-key ledger. */
35
+ readonly staged: StagedKeysState;
36
+ /** The plugin's locale-refresh seam, so the list's copy follows a language
37
+ * switch exactly as the seats the official slot mounts do. */
38
+ readonly refreshed: (children: () => ReactNode) => ReactNode;
39
+ }
40
+ /**
41
+ * Mount the draft key list into a field, replacing whatever this module
42
+ * mounted there before. Idempotent: a field whose list is already up is left
43
+ * exactly as it is (only its region mirror is re-asserted, so a tab pass that
44
+ * tags the field after the fact brings the list into its pane too), and a
45
+ * field with no key input is handed to {@link resetCreateKeySeat}.
46
+ */
47
+ export declare function enhanceCreateKeySeat(field: HTMLElement, deps: CreateKeySeatDeps): void;
48
+ /**
49
+ * Drop the list of one field, leaving the official field exactly as the page
50
+ * rendered it: the managed-field mark goes, and the official input comes back.
51
+ */
52
+ export declare function resetCreateKeySeat(field: HTMLElement): void;
53
+ /** Drop every list this module mounted. */
54
+ export declare function teardownCreateKeySeats(): void;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The create-provider card's API-key list: the SAME card list the edit card
3
+ * runs ({@link KeyManager}), over a DRAFT store instead of the host's.
4
+ *
5
+ * The provider this list edits does not exist yet — the id the user is typing
6
+ * is declared by the card's own 保存 — so the host's key route would refuse
7
+ * every call. The list therefore runs on {@link createDraftKeyClient}, whose
8
+ * answers come from an in-memory store the seat seeds, and every change is
9
+ * filed with the session ledger (`staged-keys`) the moment there is a route to
10
+ * file it under. The ledger — not this pane — decides when those drafts may be
11
+ * written: the create landing is the only thing that may trigger the write,
12
+ * and it is also the proof the write is allowed.
13
+ *
14
+ * The route plumbing mirrors the card's 高级配置 pane (`create-card-pane`)
15
+ * exactly, because it solves the same problem against the same field: the id
16
+ * belongs to the official form's React state, so the DOM input event is the
17
+ * only notice this pane gets, the read is by label, and a retyped id MOVES the
18
+ * held list (the old key never comes back — the user is declaring the provider
19
+ * they ended up naming).
20
+ *
21
+ * @module dsh-model-think-level/client/injection/create-keys-pane
22
+ */
23
+ import type { ReactNode } from 'react';
24
+ import type { Translate } from '@deepseek-ai/dsh-client-ui-slots';
25
+ import type { RemoteApi } from '../types.js';
26
+ import { type DraftKeyStore, type StagedKeysState } from './staged-keys.js';
27
+ export interface CreateKeysPaneProps {
28
+ /** The plugin's seat right after the official key field; the id read and the
29
+ * input listener both resolve the card from it. */
30
+ host: {
31
+ readonly current: HTMLDivElement | null;
32
+ };
33
+ /** The working store the seat created (and seeded with a value the user had
34
+ * already typed into the official box, if there was one). */
35
+ store: DraftKeyStore;
36
+ /** The write seam, for the route-baseline reads. */
37
+ api: RemoteApi;
38
+ /** The plugin's translator. */
39
+ t: Translate;
40
+ /** The official labels of the form's provider-id field, by locale. */
41
+ routeIdLabels: () => readonly string[];
42
+ /** The session's deferred-key ledger. */
43
+ staged: StagedKeysState;
44
+ }
45
+ /** One create card's key list: the draft list itself, wired to the live id. */
46
+ export declare function CreateKeysPane({ host, store, api, t, routeIdLabels, staged }: CreateKeysPaneProps): ReactNode;
@@ -82,3 +82,15 @@ export declare function resetKeyField(field: HTMLElement): void;
82
82
  * than uncovering an empty box.
83
83
  */
84
84
  export declare function loadProviderKey(route: string): Promise<string | undefined>;
85
+ /**
86
+ * Write into a React-controlled input the way the user's own typing would: the
87
+ * prototype setter bypasses React's value tracker (an instance-level override),
88
+ * and the bubbling `input` event then lets the official component take the
89
+ * value into its draft state — so a re-render keeps it instead of reverting to
90
+ * the empty draft.
91
+ *
92
+ * The create card's key-list pane uses the same gesture to take a value the
93
+ * user had already typed out of the official box when the draft list takes
94
+ * the field over.
95
+ */
96
+ export declare function writeInputValue(input: HTMLInputElement, value: string): void;
@@ -86,6 +86,16 @@ export interface HostLabels {
86
86
  * {@link echoOfficialModality}.
87
87
  */
88
88
  inputImage: readonly string[];
89
+ /**
90
+ * The disclosure's context-window input ("Context window" / "上下文窗口").
91
+ * Matched against the input's own aria-label when it carries one, else
92
+ * against the text of the label wrapping it — the DSH host renders the field
93
+ * label-wrapped with no aria-label of its own. The first copy is what a
94
+ * suggestion's capacities echo into: see {@link echoOfficialCapacities}.
95
+ */
96
+ contextWindow: readonly string[];
97
+ /** The disclosure's max-output input ("Max output" / "最大输出"). */
98
+ maxOutput: readonly string[];
89
99
  }
90
100
  /** The join the injector renders from. */
91
101
  export interface InjectorDeps {
@@ -482,6 +492,79 @@ export declare function echoOfficialModality(container: HTMLElement, image: bool
482
492
  * untouched.
483
493
  */
484
494
  export declare function officialModalityIntent(container: HTMLElement | undefined, input: InputModalities | null | undefined, imageLabels: readonly string[]): InputModalities | null | undefined;
495
+ /**
496
+ * The official capacity inputs of one row's disclosure (context window, max
497
+ * output), or whatever of them could be identified.
498
+ *
499
+ * Two anchors, most specific first, plus a positional floor:
500
+ * 1. an input whose own aria-label starts with the field's copy — the same
501
+ * prefix match every other official control is found by;
502
+ * 2. an input whose WRAPPING LABEL's text carries the copy — the DSH host
503
+ * renders these fields label-wrapped with no aria-label of their own;
504
+ * 3. the disclosure's remaining plain inputs in document order, first =
505
+ * context window, second = max output. The floor only answers for a row
506
+ * whose labels matched nothing (an unnamed host variant); the DSH
507
+ * disclosure holds exactly these two inputs.
508
+ *
509
+ * The plugin's own editor sits inside the same disclosure, and a folded-row
510
+ * visit scopes the search to the whole row (head inputs included), so both are
511
+ * kept out of the candidate set: the editor by its `data-plugin` root, the row
512
+ * head's Model ID / Display name by their aria-labels.
513
+ */
514
+ export interface OfficialCapacityInputs {
515
+ contextWindow?: HTMLInputElement;
516
+ maxOutput?: HTMLInputElement;
517
+ }
518
+ export declare function officialCapacityInputsOf(scope: HTMLElement, labels: HostLabels): OfficialCapacityInputs;
519
+ /**
520
+ * Print a suggestion's reference capacities on the official inputs of one row.
521
+ *
522
+ * Like the modality echo, this edits the official form's own DRAFT — the inputs
523
+ * render the card's state, not the settings document, so writing the document
524
+ * could never show a value in them before the card is saved and reopened. The
525
+ * value goes through the native setter and a bubbled `input` event so React's
526
+ * controlled input carries it into the draft, and the card's own Save is what
527
+ * persists it. That is also why the capacities never ride the plugin's document
528
+ * write: two writers for one field would let a held write land after that Save
529
+ * and revert whatever the user chose in the meantime.
530
+ *
531
+ * FILL-ONLY: an input that already holds a positive number is a user decision
532
+ * and keeps its place — auto-adapt fills blanks, it does not overwrite.
533
+ * @returns which of the two fields actually landed a value.
534
+ */
535
+ export declare function echoOfficialCapacities(scope: HTMLElement, labels: HostLabels, values: {
536
+ contextWindow?: number;
537
+ maxTokens?: number;
538
+ }): {
539
+ contextWindow: boolean;
540
+ maxOutput: boolean;
541
+ };
542
+ /**
543
+ * Read the official capacity inputs as the row's form currently holds them.
544
+ *
545
+ * The editor's two fields seed from this rather than from a suggestion: the
546
+ * numbers belong to the form's draft (the catalogue's value, the user's own
547
+ * typing, or a suggestion already echoed into it), and the draft is the only
548
+ * place they exist before the card is saved.
549
+ */
550
+ export declare function readOfficialCapacities(scope: HTMLElement, labels: HostLabels): {
551
+ contextWindow?: number;
552
+ maxTokens?: number;
553
+ };
554
+ /**
555
+ * Write the editor's capacity fields into the official inputs — the USER's own
556
+ * typing, so unlike {@link echoOfficialCapacities} this one overwrites, and
557
+ * `undefined` empties the field (a capacity that inherits the catalogue value
558
+ * again instead of being pinned). A key the caller omits is left untouched.
559
+ * @returns which of the two fields the write actually changed.
560
+ */
561
+ export declare function writeOfficialCapacities(scope: HTMLElement, labels: HostLabels, next: {
562
+ contextWindow?: number | undefined;
563
+ maxTokens?: number | undefined;
564
+ }): {
565
+ contextWindow: boolean;
566
+ maxOutput: boolean;
567
+ };
485
568
  /**
486
569
  * One model row a card shows on screen: what the walk needs to name it, plus
487
570
  * the row element itself, so a verdict about its modality can be printed on
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Provider-card layout and dual endpoints (user items 3, 4, 6, 7).
3
+ *
4
+ * The official card renders its route fields in a fixed order — display name,
5
+ * base URL, API protocol — and offers a single base URL. This module reshapes
6
+ * that card in place on every scan. It is idempotent, so a React re-render
7
+ * self-heals on the next pass — the same pattern `hideOfficialReasoning` uses:
8
+ *
9
+ * - **the fields are re-ordered** to display name → API protocol → base URL,
10
+ * so the protocol sits above the address it governs.
11
+ * - **the API protocol is picked from cards.** The official `<select>` is kept
12
+ * as the value the host reads, but it is hidden behind a row of plugin cards —
13
+ * one per protocol, the one in force highlighted — so every choice is visible
14
+ * without opening a dropdown (user item 1).
15
+ * - **the address is labelled by protocol family.** The official base-URL
16
+ * input is prefixed with "OpenAI"/"Anthropic" according to the protocol the
17
+ * card currently selects, seated immediately LEFT of the input on its own
18
+ * line — never stacked above it — so the tag reads as the field's prefix.
19
+ * - **extra endpoints can be added.** A grey "更多端点" text button directly
20
+ * under the API address — where the rows it reveals appear — opens one more
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
24
+ * index, which is what a key pinned to that family signs against.
25
+ *
26
+ * The add card carries the same three fields, so the same decoration applies to
27
+ * it — "添加供应商" is not left behind (user item 6).
28
+ *
29
+ * @module dsh-model-think-level/client/injection/provider-endpoints
30
+ */
31
+ import { type KeyManagerClient } from '../key-manager-client.js';
32
+ /** The card-field label anchors this module needs, as the host spells them. */
33
+ export interface EndpointLabels {
34
+ /** The provider-id field (names the route). */
35
+ readonly routeId: readonly string[];
36
+ /** The display-name field. */
37
+ readonly modelName: readonly string[];
38
+ /** The base-URL field. */
39
+ readonly baseUrl: readonly string[];
40
+ /** The API-protocol field. */
41
+ readonly apiProtocol: readonly string[];
42
+ }
43
+ /** The transport and copy an injection needs. */
44
+ export interface EndpointDeps {
45
+ /** Transport; injectable for tests. */
46
+ readonly client?: KeyManagerClient | undefined;
47
+ /** Copy for the injected controls. */
48
+ readonly t: (key: string, params?: Record<string, string | number>) => string;
49
+ }
50
+ /**
51
+ * Reshape one provider card: field order, protocol cards, address label, the
52
+ * 更多端点 toggle and the extra endpoint rows. Safe to call on every scan.
53
+ * @param card - the official card element.
54
+ * @param labels - the host's resolved label anchors.
55
+ * @param deps - the transport and copy.
56
+ */
57
+ export declare function decorateProviderCard(card: HTMLElement, labels: EndpointLabels, deps: EndpointDeps): void;
58
+ /**
59
+ * Hand the protocol selects back to the host (called on teardown): a hidden select
60
+ * is this module's doing, so it must not outlive the module.
61
+ */
62
+ export declare function forgetEndpointCache(): void;
63
+ /**
64
+ * Hand the provider cards back to the host entirely (called on teardown): every
65
+ * node and attribute this module injected — the hidden protocol selects, the
66
+ * protocol card groups, the family tags, the 更多端点 toggle and the extra
67
+ * address rows — comes out, so a disabled plugin leaves the official card
68
+ * exactly as the page built it.
69
+ */
70
+ export declare function teardownProviderEndpoints(): void;