dsh-model-think-level 2.0.2 → 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.
- package/README.md +49 -23
- package/lib/balance.d.ts +44 -0
- package/lib/client/ComposerSlider.d.ts +19 -0
- package/lib/client/ConfigPane.d.ts +47 -0
- package/lib/client/EffortEditor.d.ts +34 -16
- package/lib/client/KeyManager.d.ts +2 -2
- package/lib/client/balance-client.d.ts +34 -0
- package/lib/client/capacity.d.ts +20 -4
- package/lib/client/configured-inputs.d.ts +11 -2
- package/lib/client/events.d.ts +31 -2
- package/lib/client/fingerprint-runner.d.ts +13 -1
- package/lib/client/image-config-client.d.ts +75 -0
- package/lib/client/injection/autofill-run.d.ts +2 -2
- package/lib/client/injection/config-button-seat.d.ts +96 -0
- package/lib/client/injection/create-key-seat.d.ts +3 -3
- package/lib/client/injection/create-keys-pane.d.ts +4 -2
- package/lib/client/injection/editor-tab-bar.d.ts +1 -1
- package/lib/client/injection/editor-tabs.d.ts +1 -1
- package/lib/client/injection/image-card.d.ts +85 -0
- package/lib/client/injection/imagegen-completion.d.ts +43 -0
- package/lib/client/injection/imagegen-entry.d.ts +22 -0
- package/lib/client/injection/key-prefetch.d.ts +44 -0
- package/lib/client/injection/key-reveal.d.ts +2 -3
- package/lib/client/injection/models-page-editor.d.ts +59 -28
- package/lib/client/injection/models-page.d.ts +15 -3
- package/lib/client/injection/provider-balance.d.ts +83 -0
- package/lib/client/injection/provider-endpoints.d.ts +2 -2
- package/lib/client/injection/row-drag.d.ts +7 -0
- package/lib/client/injection/staged-keys.d.ts +24 -12
- package/lib/client/key-manager-client.d.ts +70 -18
- package/lib/client/locales.d.ts +65 -15
- package/lib/client/ops.d.ts +12 -2
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/types.d.ts +21 -3
- package/lib/client.js +721 -78
- package/lib/client.js.map +4 -4
- package/lib/constants.d.ts +58 -0
- package/lib/detection.d.ts +7 -0
- package/lib/fingerprint/estimate.d.ts +16 -0
- package/lib/fingerprint/run.d.ts +24 -0
- package/lib/fingerprint/store.d.ts +2 -2
- package/lib/fingerprint/verdict.d.ts +53 -3
- package/lib/headers-core.d.ts +3 -1
- package/lib/headers-fetch.d.ts +25 -0
- package/lib/image/command.d.ts +84 -0
- package/lib/image/config.d.ts +150 -0
- package/lib/image/generate.d.ts +135 -0
- package/lib/image/legacy-cleanup.d.ts +29 -0
- package/lib/image/sizes.d.ts +28 -0
- package/lib/image/tool.d.ts +107 -0
- package/lib/index.js +3876 -1745
- package/lib/index.js.map +4 -4
- package/lib/key-index.d.ts +37 -7
- package/lib/key-probe.d.ts +39 -99
- package/lib/key-refs.d.ts +43 -19
- package/lib/key-route-core.d.ts +100 -32
- package/lib/key-serves.d.ts +81 -0
- package/lib/knowledge.d.ts +21 -0
- package/lib/listing.d.ts +18 -20
- package/lib/multi-key-listing.d.ts +3 -3
- package/package.json +1 -8
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Models-page title-row seat: the 「生图服务」 button at the right end of
|
|
3
|
+
* the 「模型」 heading line, opening the plugin's image-service config pane.
|
|
4
|
+
*
|
|
5
|
+
* The official `settings.action` slot lands in the DIALOG's top bar (beside
|
|
6
|
+
* 「打开配置文件」), not on the heading — and the Models page itself exposes
|
|
7
|
+
* only footer/provider-card/sign-in slots. So the seat is built the way
|
|
8
|
+
* add-card.ts builds its pane host: a plugin-owned `div.bre-config-host`
|
|
9
|
+
* appended to the heading's row, compare-before-write, idempotent via the
|
|
10
|
+
* host node's presence.
|
|
11
|
+
*
|
|
12
|
+
* The heading anchor is deliberately a pure function ({@link findModelsTitleRow})
|
|
13
|
+
* with fixture tests, and it FAILS CLOSED: on any structural drift it returns
|
|
14
|
+
* null and the button does not render — a wrong element must never receive a
|
|
15
|
+
* plugin button.
|
|
16
|
+
*
|
|
17
|
+
* This anchor rides a DOM coincidence (the host's Models page heading is the
|
|
18
|
+
* sole element whose whole text reads 「模型」/“Models” in the section that
|
|
19
|
+
* carries the provider row cards). The host nests the cards in a `ul` and
|
|
20
|
+
* puts the heading as its SIBLING in `div.jrmgQW_section`; an earlier host
|
|
21
|
+
* version kept both as direct children of the content column. The anchor
|
|
22
|
+
* therefore climbs from the cards to the nearest scope that holds the heading,
|
|
23
|
+
* instead of assuming the cards' parent is the content column. The coincidence
|
|
24
|
+
* is asserted by tests/fixtures; when a host change breaks it, the function
|
|
25
|
+
* returns null and the fallback is the `settings.action` slot (see the design's
|
|
26
|
+
* §4.1 备选).
|
|
27
|
+
*
|
|
28
|
+
* @module dsh-model-think-level/client/injection/config-button-seat
|
|
29
|
+
*/
|
|
30
|
+
import { createElement } from 'react';
|
|
31
|
+
import { type ForeignMount } from './mount.js';
|
|
32
|
+
/**
|
|
33
|
+
* Locate the Models page's title LINE, or null. Two gates, both required:
|
|
34
|
+
* 1. the current surface carries the provider-row-card family (the Models
|
|
35
|
+
* page's own anchors — a dialog or panel without them is another page);
|
|
36
|
+
* 2. climbing from the cards to the nearest ancestor that also holds the
|
|
37
|
+
* heading (the host puts `h2.jrmgQW_title` beside `ul.jrmgQW_rows` inside
|
|
38
|
+
* `div.jrmgQW_section`), exactly one element reads as the heading copy and
|
|
39
|
+
* is not a row/nav label.
|
|
40
|
+
* Returns the heading's line element (the heading itself when the host gives
|
|
41
|
+
* it no wrapper), so the seat can append to the line's right end.
|
|
42
|
+
*/
|
|
43
|
+
export declare function findModelsTitleRow(root: ParentNode): HTMLElement | null;
|
|
44
|
+
/** The seat's host class (one per Models page, like add-card's pane host). */
|
|
45
|
+
export declare const CONFIG_HOST_CLASS = "bre-config-host";
|
|
46
|
+
/**
|
|
47
|
+
* The class that turns the anchor into the title LINE (flex + vertical
|
|
48
|
+
* centring), so the seat sits at the line's right end via `margin-left:auto`
|
|
49
|
+
* even when the host gives the heading no wrapper of its own. Plugin-owned and
|
|
50
|
+
* removed with the seat.
|
|
51
|
+
*
|
|
52
|
+
* The same two declarations are ALSO written inline by
|
|
53
|
+
* {@link ensureConfigButtonSeat}: the host is React, and its next render of the
|
|
54
|
+
* heading sets `className` back to the hashed title class, silently dropping
|
|
55
|
+
* this class. Inline styles are not part of the host's vdom, so they survive
|
|
56
|
+
* that render — without them the seat keeps existing while the line stops being
|
|
57
|
+
* a flex row, and the button slides back next to the 「模型」 text until the
|
|
58
|
+
* seat happens to be rebuilt.
|
|
59
|
+
*/
|
|
60
|
+
export declare const CONFIG_TITLE_LINE_CLASS = "bre-config-title-line";
|
|
61
|
+
/** What the seat needs. `onOpen` opens the config pane. */
|
|
62
|
+
export interface ConfigButtonSeatDeps {
|
|
63
|
+
/** The plugin's translator. */
|
|
64
|
+
readonly t: (key: string, params?: Record<string, unknown>) => string;
|
|
65
|
+
/** Open the config pane (the button's single job). */
|
|
66
|
+
readonly onOpen: () => void;
|
|
67
|
+
}
|
|
68
|
+
/** One scan's seat state: the row the seat lives on and its React root. */
|
|
69
|
+
export interface ConfigButtonSeatState {
|
|
70
|
+
readonly mounts: Map<HTMLElement, ForeignMount>;
|
|
71
|
+
}
|
|
72
|
+
export declare function createConfigButtonSeatState(): ConfigButtonSeatState;
|
|
73
|
+
/**
|
|
74
|
+
* Ensure the title line carries the button — and, just as important, still
|
|
75
|
+
* LOOKS like a line. Idempotent in the settled case, with one re-assertion:
|
|
76
|
+
* when the host re-rendered the heading and reset `className` (dropping the
|
|
77
|
+
* flex class but leaving our seat in place), the line mechanics are put back
|
|
78
|
+
* instead of trusting the class.
|
|
79
|
+
*/
|
|
80
|
+
export declare function ensureConfigButtonSeat(row: HTMLElement, deps: ConfigButtonSeatDeps, state: ConfigButtonSeatState): void;
|
|
81
|
+
/** Take one line's seat down (restoring the host's own line styling). */
|
|
82
|
+
export declare function dropSeat(row: HTMLElement, state: ConfigButtonSeatState): void;
|
|
83
|
+
/** Take every seat down, including strays a dead fiber left behind. */
|
|
84
|
+
export declare function teardownConfigButtonSeats(state: ConfigButtonSeatState): void;
|
|
85
|
+
/**
|
|
86
|
+
* The 「生图服务」 button: a round icon-only seat. The copy lives only in the
|
|
87
|
+
* button's attributes (`title` tooltip + `aria-label`), never as a text node —
|
|
88
|
+
* the Models page heading line is tight, and a labelled pill there competed
|
|
89
|
+
* with the host's own title. The circle keeps the same hit area as the pills
|
|
90
|
+
* beside it (28px) while the label stays available on hover and to assistive
|
|
91
|
+
* tech.
|
|
92
|
+
*/
|
|
93
|
+
export declare function ConfigButton(props: {
|
|
94
|
+
t: (key: string) => string;
|
|
95
|
+
onOpen: () => void;
|
|
96
|
+
}): ReturnType<typeof createElement>;
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* list by — the id is being typed, and the drafts wait in the session ledger
|
|
8
8
|
* (`staged-keys`) for the route the card's own 保存 declares — so the list is
|
|
9
9
|
* the draft pane (`create-keys-pane`), not the host-backed one. Second, the
|
|
10
|
-
* official box
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* official box mirrors the first enabled list key: the create card uses its
|
|
11
|
+
* own draft for Fetch models and 保存. The ledger reuses that saved key and
|
|
12
|
+
* stores the rest of the list once the route is declared.
|
|
13
13
|
*
|
|
14
14
|
* The field keeps the edit card's managed-field handover: `bre-key-managed`
|
|
15
15
|
* stands the official input down (the list below says the same thing once per
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import type { ReactNode } from 'react';
|
|
24
24
|
import type { Translate } from '@deepseek-ai/dsh-client-ui-slots';
|
|
25
25
|
import type { RemoteApi } from '../types.js';
|
|
26
|
-
import { type DraftKeyStore, type StagedKeysState } from './staged-keys.js';
|
|
26
|
+
import { type DraftKeyStore, type StagedKeysState, type StagedKeyDraft } from './staged-keys.js';
|
|
27
27
|
export interface CreateKeysPaneProps {
|
|
28
28
|
/** The plugin's seat right after the official key field; the id read and the
|
|
29
29
|
* input listener both resolve the card from it. */
|
|
@@ -41,6 +41,8 @@ export interface CreateKeysPaneProps {
|
|
|
41
41
|
routeIdLabels: () => readonly string[];
|
|
42
42
|
/** The session's deferred-key ledger. */
|
|
43
43
|
staged: StagedKeysState;
|
|
44
|
+
/** Mirror the enabled draft key into the official form used by Fetch models. */
|
|
45
|
+
onChange?: (drafts: readonly StagedKeyDraft[]) => void;
|
|
44
46
|
}
|
|
45
47
|
/** 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;
|
|
48
|
+
export declare function CreateKeysPane({ host, store, api, t, routeIdLabels, staged, onChange }: CreateKeysPaneProps): ReactNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The provider editor's segmented control
|
|
3
|
-
* (供应商配置 / 模型配置 /
|
|
3
|
+
* (供应商配置 / 模型配置 / 高级配置 / 指纹检测).
|
|
4
4
|
*
|
|
5
5
|
* This is the bar the editor-tabs pass drives. It lives HERE, in the plugin's
|
|
6
6
|
* own React subtree, rather than being built by the pass and inserted into the
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
*
|
|
47
47
|
* @module dsh-model-think-level/client/injection/editor-tabs
|
|
48
48
|
*/
|
|
49
|
-
declare const TAB_IDS: readonly ["provider", "models", "
|
|
49
|
+
declare const TAB_IDS: readonly ["provider", "models", "advanced", "fingerprint"];
|
|
50
50
|
/** A tab id, as both the bar and the card attribute spell it. */
|
|
51
51
|
export type EditorTabId = (typeof TAB_IDS)[number];
|
|
52
52
|
/** The tab ids, in display order, for the tab-bar component. */
|
|
@@ -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
|
|
105
|
-
*
|
|
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;
|
|
@@ -96,6 +96,14 @@ export interface HostLabels {
|
|
|
96
96
|
contextWindow: readonly string[];
|
|
97
97
|
/** The disclosure's max-output input ("Max output" / "最大输出"). */
|
|
98
98
|
maxOutput: readonly string[];
|
|
99
|
+
/**
|
|
100
|
+
* The model list's add button ("Add model" / "添加模型"). Clicking it appends
|
|
101
|
+
* a row and focuses its first input, and the browser's own scroll into view
|
|
102
|
+
* (plus the anchoring around the growth) is what made the whole card appear
|
|
103
|
+
* to squeeze upward — the capture-phase pin wired on it answers that (see
|
|
104
|
+
* {@link wireAddModelRepin}).
|
|
105
|
+
*/
|
|
106
|
+
addModel: readonly string[];
|
|
99
107
|
}
|
|
100
108
|
/** The join the injector renders from. */
|
|
101
109
|
export interface InjectorDeps {
|
|
@@ -107,7 +115,10 @@ export interface InjectorDeps {
|
|
|
107
115
|
*/
|
|
108
116
|
api: RemoteApi;
|
|
109
117
|
/** Read the pi-ai namespace plus writability from the settings join. */
|
|
110
|
-
describeNamespace(
|
|
118
|
+
describeNamespace(options?: {
|
|
119
|
+
fresh?: boolean;
|
|
120
|
+
allowStale?: boolean;
|
|
121
|
+
}): Promise<SettingsJoin>;
|
|
111
122
|
/** Localized copy. */
|
|
112
123
|
t: (key: string, params?: Record<string, string | number>) => string;
|
|
113
124
|
/**
|
|
@@ -124,7 +135,7 @@ export interface InjectorDeps {
|
|
|
124
135
|
* browser half hangs its autofill complement here: "the user stopped
|
|
125
136
|
* editing" is the only moment this side may safely write the document.
|
|
126
137
|
*/
|
|
127
|
-
onIdle?(): void;
|
|
138
|
+
onIdle?(join?: SettingsJoin): void;
|
|
128
139
|
/** Wake the debounced scan after provider-wide adaptation stages a row. */
|
|
129
140
|
onPendingChanged?(): void;
|
|
130
141
|
/**
|
|
@@ -159,6 +170,8 @@ export interface EditorMountProps {
|
|
|
159
170
|
effortsUnset?: boolean;
|
|
160
171
|
/** The model's current input-modality declaration. */
|
|
161
172
|
input?: InputModalities;
|
|
173
|
+
/** Whether the model is declared an image generator (生图). */
|
|
174
|
+
imageGen?: boolean;
|
|
162
175
|
/** The model's stored compat block (passthrough; the editor merges suggestions over it). */
|
|
163
176
|
compat?: CompatSuggestion;
|
|
164
177
|
/** The model's stored per-model default-effort pick, when one is set. */
|
|
@@ -176,10 +189,6 @@ export interface EditorMountProps {
|
|
|
176
189
|
* DOM, never a kernel version.
|
|
177
190
|
*/
|
|
178
191
|
officialInputTypes?: boolean;
|
|
179
|
-
/** The card reports whether it still covers the official capacity and
|
|
180
|
-
* input-type fields: it does while its thinking switch is on, and steps
|
|
181
|
-
* aside when the switch turns the card off. */
|
|
182
|
-
onCoverageChange?: (covered: boolean) => void;
|
|
183
192
|
api: EffortEditorApi;
|
|
184
193
|
readOnly: boolean;
|
|
185
194
|
t: (key: string, params?: Record<string, string | number>) => string;
|
|
@@ -268,6 +277,11 @@ export interface ScanState {
|
|
|
268
277
|
disclosureWired: WeakSet<Element>;
|
|
269
278
|
/** Provider-row Edit buttons already wired for the top re-pin. */
|
|
270
279
|
editWired: WeakSet<Element>;
|
|
280
|
+
/** The model lists' add-model buttons already wired for the top re-pin. */
|
|
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>;
|
|
271
285
|
}
|
|
272
286
|
/**
|
|
273
287
|
* One staged declaration: the level set plus the suggestion's compat block and
|
|
@@ -285,6 +299,11 @@ export interface StagedDeclaration {
|
|
|
285
299
|
efforts: Exclude<EffortWriteIntent, undefined>;
|
|
286
300
|
compat?: CompatSuggestion;
|
|
287
301
|
input?: InputModalities;
|
|
302
|
+
/**
|
|
303
|
+
* The image-generation part, when the staging carried one: true marks the
|
|
304
|
+
* row 生图, false clears the marker. Undefined touches nothing.
|
|
305
|
+
*/
|
|
306
|
+
imageGen?: boolean;
|
|
288
307
|
defaultEffort?: string | null;
|
|
289
308
|
}
|
|
290
309
|
/**
|
|
@@ -317,7 +336,12 @@ export declare function stageEffortsInto(state: ScanState, route: string, modelI
|
|
|
317
336
|
* declaration" on an unsaved route) and stores as such: the staged flush
|
|
318
337
|
* reads it back verbatim, exactly like the saved-row seam does.
|
|
319
338
|
*/
|
|
320
|
-
input?: InputModalities | null, defaultEffort?: string | null
|
|
339
|
+
input?: InputModalities | null, defaultEffort?: string | null,
|
|
340
|
+
/**
|
|
341
|
+
* The image-generation part as the write carried it: true marks the row 生图,
|
|
342
|
+
* false or null clears the marker, undefined touches nothing.
|
|
343
|
+
*/
|
|
344
|
+
imageGen?: boolean | null): void;
|
|
321
345
|
/**
|
|
322
346
|
* Record (or replace) the write an on-screen editor asked for while the
|
|
323
347
|
* official card held the document. The latest intent for a row wins: the user
|
|
@@ -390,6 +414,8 @@ export interface EffectiveStagedIntents {
|
|
|
390
414
|
efforts: EffortWriteIntent;
|
|
391
415
|
compat?: CompatSuggestion;
|
|
392
416
|
input?: InputModalities;
|
|
417
|
+
/** The staged image-generation intent, when it is a change. */
|
|
418
|
+
imageGen?: boolean;
|
|
393
419
|
/** The staged default-effort pick, when the staging carried one. */
|
|
394
420
|
defaultEffort?: string | null;
|
|
395
421
|
}
|
|
@@ -449,15 +475,7 @@ export declare function hideOfficialReasoning(container: HTMLElement): void;
|
|
|
449
475
|
* proves it — so an inline `display` the host wrote itself is left as it is.
|
|
450
476
|
*/
|
|
451
477
|
export declare function showOfficialReasoning(container: HTMLElement): void;
|
|
452
|
-
/**
|
|
453
|
-
* Stand the official context-window / max-output labels and the input-types
|
|
454
|
-
* fieldset down for a row whose editor renders those same decisions.
|
|
455
|
-
*
|
|
456
|
-
* Only DIRECT children of the disclosure are touched: the editor's own inputs
|
|
457
|
-
* (and its own modality pills) live inside `.bre-effort-slot`, which carries
|
|
458
|
-
* neither class stem. The marker attribute distinguishes this hide from one the
|
|
459
|
-
* host wrote itself, exactly like {@link hideOfficialReasoning}.
|
|
460
|
-
*/
|
|
478
|
+
/** Stand both official copies down. Used when the editor leaves the row. */
|
|
461
479
|
export declare function hideOfficialCapacityChrome(container: HTMLElement): void;
|
|
462
480
|
/** Hand the official capacity/input-type chrome back when the editor goes. */
|
|
463
481
|
export declare function showOfficialCapacityChrome(container: HTMLElement): void;
|
|
@@ -493,18 +511,21 @@ export declare function officialImageCheckboxOf(container: HTMLElement, imageLab
|
|
|
493
511
|
*/
|
|
494
512
|
export declare function echoOfficialModality(container: HTMLElement, image: boolean, imageLabels: readonly string[]): boolean;
|
|
495
513
|
/**
|
|
496
|
-
* The modality intent a row's own write
|
|
497
|
-
* input-types control has been
|
|
514
|
+
* The modality intent a row's own write carries, after the official
|
|
515
|
+
* input-types control has been MIRRORED with the verdict.
|
|
498
516
|
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
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.
|
|
508
529
|
*/
|
|
509
530
|
export declare function officialModalityIntent(container: HTMLElement | undefined, input: InputModalities | null | undefined, imageLabels: readonly string[]): InputModalities | null | undefined;
|
|
510
531
|
/**
|
|
@@ -711,7 +732,7 @@ export declare function suppressScrollAnchoring(node: HTMLElement, windowMs?: nu
|
|
|
711
732
|
* offset is no longer the one this loop left is being scrolled by somebody
|
|
712
733
|
* else, and is skipped rather than fought.
|
|
713
734
|
*/
|
|
714
|
-
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;
|
|
715
736
|
/**
|
|
716
737
|
* Start recording where a click inside a model list leaves its scroll host.
|
|
717
738
|
*
|
|
@@ -770,6 +791,16 @@ export declare function unwatchModelListOffsets(): void;
|
|
|
770
791
|
* @param windowMs - how long each found card stays pinned.
|
|
771
792
|
*/
|
|
772
793
|
export declare function pinModelListCards(root: HTMLElement, windowMs?: number): void;
|
|
794
|
+
/**
|
|
795
|
+
* The model list's add-model buttons, found by the host's own copy.
|
|
796
|
+
*
|
|
797
|
+
* Matched like every other official control — by the resolved dictionary copy,
|
|
798
|
+
* never by a class — but through BOTH channels the button may carry: an
|
|
799
|
+
* aria-label when the host gave it one, else its own text content (the DSH
|
|
800
|
+
* host renders it as a plain labelled button). Buttons inside this plugin's
|
|
801
|
+
* own DOM are skipped, exactly like the Edit buttons above.
|
|
802
|
+
*/
|
|
803
|
+
export declare function addModelTriggersOf(scope: HTMLElement, labels: HostLabels): HTMLElement[];
|
|
773
804
|
/**
|
|
774
805
|
* Scan the settings DOM for official model rows and reconcile the injected
|
|
775
806
|
* editors. Idempotent: existing editors are left alone, new disclosures get
|
|
@@ -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
|
-
/**
|
|
29
|
-
|
|
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;
|