@mofeng2223/dsh-claude-provider 0.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/lib/client.js ADDED
@@ -0,0 +1,2911 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@mofeng2223/dsh-claude-provider",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let _deepseek_ai_dsh_client_web_react = require("@deepseek-ai/dsh-client-web-react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ let react = require("react");
10
+ let react_dom = require("react-dom");
11
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
12
+ let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
13
+ let _deepseek_ai_dsh_client_schema_form = require("@deepseek-ai/dsh-client-schema-form");
14
+ //#region lib/types/client/apiKey.js
15
+ /**
16
+ * Browser-side judgement of a typed API key.
17
+ * @module @mofeng2223/dsh-claude-provider/apiKey
18
+ */
19
+ /**
20
+ * Twin of `normalizeApiKey` in `@deepseek-ai/dsh-llm`: printable ASCII, space
21
+ * excluded. Client packages reference only client packages, so the charset
22
+ * rule is mirrored here rather than imported; keep the two in step, as
23
+ * `validateDeepSeekModels` is kept in step with the host's `catalogModel`.
24
+ */
25
+ const LEGAL_API_KEY = /^[\x21-\x7E]+$/;
26
+ /**
27
+ * A pasted `NAME=value` environment line. Two narrowings keep real keys clear
28
+ * of it: the name must be upper-case, so `sk-` forms break at the hyphen, and
29
+ * the `=` must be followed by something other than another `=`, so base64
30
+ * padding on an all-upper-case key (`ABCD==`) is not mistaken for an
31
+ * assignment. This heuristic runs only here — a resolver applying it could
32
+ * lock a user out of a gateway whose key legitimately takes this shape, with
33
+ * the environment refusing it too and no way through.
34
+ */
35
+ const ENV_LINE = /^[A-Z][A-Z0-9_]*=[^=]/;
36
+ /** Whether a value is wrapped in one matching pair of quotes. */
37
+ function isQuoted(value) {
38
+ const first = value[0];
39
+ if (first !== "\"" && first !== "'" && first !== "`") return false;
40
+ return value.length > 1 && value.endsWith(first);
41
+ }
42
+ /**
43
+ * Judge the key input's current value.
44
+ *
45
+ * An empty field is not a failure: every card opens with it empty even when a
46
+ * key is already stored, where it means keep that one. A field holding only
47
+ * whitespace is a failure rather than an empty field, so typed input is never
48
+ * silently discarded.
49
+ * @param draft - the key input's current value, untrimmed.
50
+ * @returns the copy key for a field-level failure, or `undefined` to allow submit.
51
+ */
52
+ function apiKeyFailure(draft) {
53
+ if (draft.length === 0) return void 0;
54
+ const value = draft.trim();
55
+ if (value.length === 0) return "keyBlank";
56
+ if (ENV_LINE.test(value) || isQuoted(value)) return "keyIllegalCharacters";
57
+ if (!LEGAL_API_KEY.test(value)) return "keyIllegalCharacters";
58
+ }
59
+ //#endregion
60
+ //#region \0dsh-css:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-settings-models/src/client/ModelsSection.module.css.mjs
61
+ const css$3 = ".zGbnIq_section{max-width:720px;color:var(--dsw-alias-label-primary);flex-direction:column;gap:12px;display:flex}.zGbnIq_title{color:var(--dsw-alias-label-primary);margin:0;font-size:16px;font-weight:500;line-height:24px}.zGbnIq_intro{color:var(--dsw-alias-label-tertiary);margin:0;font-size:14px;line-height:22px}.zGbnIq_notice{color:var(--dsw-alias-state-warn-label);margin:0;font-size:12px;line-height:18px}.zGbnIq_savedNotice{color:var(--dsw-alias-state-success-primary);margin:0;font-size:12px;line-height:18px}.zGbnIq_rows{flex-direction:column;gap:8px;margin:12px 0 0;padding:0;list-style:none;display:flex}.zGbnIq_rowCard{border:1px solid var(--dsw-alias-border-l2);border-radius:12px;flex-direction:column;gap:12px;padding:12px 14px;display:flex}.zGbnIq_rowHead{align-items:center;gap:10px;display:flex}.zGbnIq_rowIdentity{align-items:center;gap:6px;min-width:0;display:inline-flex}.zGbnIq_rowName{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500;line-height:22px}.zGbnIq_rowTag{border:1px solid var(--dsw-alias-border-l3);color:var(--dsw-alias-label-secondary);border-radius:4px;flex:none;padding:1px 6px;font-size:11px;line-height:16px}.zGbnIq_credentialDot{box-sizing:border-box;border-radius:50%;flex:none;width:8px;height:8px;display:inline-block}.zGbnIq_credentialDotConfigured{background:var(--dsw-alias-state-success-primary)}.zGbnIq_credentialDotMissing{background:var(--dsw-alias-state-error-primary)}.zGbnIq_rowActions{align-items:center;gap:4px;margin-left:auto;display:inline-flex}.zGbnIq_primaryButton,.zGbnIq_secondaryButton,.zGbnIq_addButton{box-sizing:border-box;height:36px;font:inherit;cursor:pointer;border:none;border-radius:18px;justify-content:center;align-items:center;gap:4px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}.zGbnIq_primaryButton{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-foreground)}.zGbnIq_primaryButton:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover)}.zGbnIq_secondaryButton,.zGbnIq_addButton{border:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary);background:0 0}.zGbnIq_secondaryButton:hover:not(:disabled),.zGbnIq_addButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}.zGbnIq_secondaryButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-solid)}.zGbnIq_dangerButton{box-sizing:border-box;height:36px;color:var(--dsw-alias-state-error-primary);font:inherit;cursor:pointer;background:0 0;border:none;border-radius:18px;justify-content:center;align-items:center;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}.zGbnIq_dangerButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger)}.zGbnIq_rowActions .zGbnIq_secondaryButton,.zGbnIq_rowActions .zGbnIq_dangerButton{border-radius:14px;height:28px;padding:0 10px;font-size:12px;line-height:18px}.zGbnIq_primaryButton:disabled,.zGbnIq_secondaryButton:disabled,.zGbnIq_dangerButton:disabled,.zGbnIq_addButton:disabled,.zGbnIq_linkButton:disabled,.zGbnIq_addModelButton:disabled{opacity:.4;cursor:default}.zGbnIq_primaryButton:focus-visible,.zGbnIq_secondaryButton:focus-visible,.zGbnIq_dangerButton:focus-visible,.zGbnIq_addButton:focus-visible,.zGbnIq_linkButton:focus-visible,.zGbnIq_addModelButton:focus-visible,.zGbnIq_iconButton:focus-visible,.zGbnIq_customizedSummary:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-border-l3);outline:none}.zGbnIq_editor{background:var(--dsw-alias-bg-module-platform);border-radius:12px;flex-direction:column;gap:14px;padding:14px 16px;display:flex}.zGbnIq_editorHeader{align-items:baseline;gap:8px;display:flex}.zGbnIq_editorTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500;line-height:22px}.zGbnIq_editorRoute{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.zGbnIq_field{flex-direction:column;gap:6px;display:flex}.zGbnIq_fieldLabel{color:var(--dsw-alias-label-secondary);align-items:center;gap:10px;font-size:12px;font-weight:500;line-height:18px;display:inline-flex}.zGbnIq_linkButton{box-sizing:border-box;height:28px;color:var(--dsw-alias-label-tertiary);font:inherit;cursor:pointer;background:0 0;border:none;border-radius:14px;align-items:center;padding:0 10px;font-size:12px;line-height:18px;display:inline-flex}.zGbnIq_linkButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}.zGbnIq_advancedHint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:18px}.zGbnIq_editorActions{justify-content:flex-end;gap:8px;display:flex}.zGbnIq_addBlock{flex-direction:column;gap:12px;display:flex}.zGbnIq_addActions{flex-wrap:wrap;gap:10px;display:flex}.zGbnIq_addButton{border:1px dashed var(--dsw-alias-border-l3);border-radius:12px;flex:1 1 0;gap:6px;min-width:180px;height:44px}.zGbnIq_addCard,.zGbnIq_setupCard{background:var(--dsw-alias-bg-module-platform);border-radius:12px;flex-direction:column;gap:14px;padding:14px 16px;list-style:none;display:flex}.zGbnIq_addCard .zGbnIq_editor,.zGbnIq_setupCard .zGbnIq_editor{background:0 0;padding:0}.zGbnIq_customized{border-top:1px solid var(--dsw-alias-border-l2);padding-top:10px}.zGbnIq_customizedSummary{cursor:pointer;width:fit-content;color:var(--dsw-alias-label-secondary);border-radius:6px;align-items:center;gap:6px;margin-left:-4px;padding:2px 4px;font-size:12px;font-weight:500;line-height:18px;list-style:none;display:flex}.zGbnIq_customizedSummary::-webkit-details-marker{display:none}.zGbnIq_customizedSummary:before{content:\"\";border-bottom:1.5px solid;border-right:1.5px solid;width:5px;height:5px;transition:transform .12s;transform:rotate(-45deg)translate(-1px,-1px)}.zGbnIq_customized[open]>.zGbnIq_customizedSummary:before{transform:rotate(45deg)translate(-1px,-1px)}.zGbnIq_customizedSummary:hover{color:var(--dsw-alias-label-primary)}.zGbnIq_customizedBody{flex-direction:column;gap:12px;padding-top:12px;display:flex}.zGbnIq_modelCatalog{border-top:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:10px;padding-top:12px;display:flex}.zGbnIq_modelCatalogHeading{flex-direction:column;gap:2px;display:flex}.zGbnIq_modelCatalogTitle{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:500;line-height:18px}.zGbnIq_modelCatalogMeta,.zGbnIq_modelEmpty{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:18px}.zGbnIq_modelList{flex-direction:column;gap:8px;display:flex}.zGbnIq_modelListHead{justify-content:space-between;align-items:flex-start;gap:12px;display:flex}.zGbnIq_modelEntry{border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:6px}.zGbnIq_modelRow{grid-template-columns:minmax(0,1.4fr) minmax(0,1fr) auto auto;align-items:center;gap:6px;display:grid}.zGbnIq_iconButton{box-sizing:border-box;width:28px;height:28px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:none;border-radius:6px;justify-content:center;align-items:center;display:inline-flex}.zGbnIq_iconButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.zGbnIq_iconButton:disabled{cursor:default;opacity:.4}.zGbnIq_iconButtonDanger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger);color:var(--dsw-alias-state-error-primary)}.zGbnIq_modelAdvanced{grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:8px;padding:8px 4px 2px;display:grid}.zGbnIq_modelField{flex-direction:column;gap:4px;display:flex}.zGbnIq_modelFieldLabel{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.zGbnIq_modelEmpty{border:1px dashed var(--dsw-alias-border-l3);text-align:center;border-radius:8px;padding:12px}.zGbnIq_addModelButton{box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);height:28px;color:var(--dsw-alias-label-primary);font:inherit;cursor:pointer;background:0 0;border-radius:14px;align-self:flex-start;align-items:center;gap:4px;padding:0 10px;font-size:12px;line-height:18px;display:inline-flex}.zGbnIq_addModelButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}.zGbnIq_input{box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);width:100%;height:32px;font:inherit;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 10px;font-size:14px;line-height:22px}select.zGbnIq_input{cursor:pointer;max-width:240px}.zGbnIq_input:focus{border-color:var(--dsw-alias-brand-primary);outline:none}.zGbnIq_input::placeholder{color:var(--dsw-alias-label-dimmed)}.zGbnIq_input:disabled{opacity:.6;cursor:default}.zGbnIq_selectInput{appearance:none;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2381858C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E\");background-position:right 12px center;background-repeat:no-repeat;background-size:12px 12px;padding-right:32px}.zGbnIq_error{color:var(--dsw-alias-state-error-primary);margin:0;font-size:12px;line-height:18px}.zGbnIq_deleteDialog{width:min(480px,100%)}.zGbnIq_deleteConfirm:not(:disabled){border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary)}.zGbnIq_deleteConfirm:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger)}.zGbnIq_hiddenLabel{clip:rect(0 0 0 0);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}@media (prefers-reduced-motion:reduce){.zGbnIq_customizedSummary:before{transition:none}}.zGbnIq_fetchDialog{--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2);max-width:520px}.zGbnIq_candidateList{flex-direction:column;gap:2px;max-height:320px;margin:0;padding:0;list-style:none;display:flex;overflow-y:auto}.zGbnIq_candidate{border-radius:6px}.zGbnIq_candidateLabel{cursor:pointer;align-items:center;gap:8px;padding:6px 8px;display:flex}.zGbnIq_candidateId{font-family:var(--ds-font-family-code);overflow-wrap:anywhere;flex:auto;font-size:13px}";
62
+ const tagId$3 = "@mofeng2223/dsh-claude-provider/ModelsSection.module.css";
63
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$3) + "]") === null) {
64
+ const tag = document.createElement("style");
65
+ tag.dataset.plugin = "@mofeng2223/dsh-claude-provider";
66
+ tag.dataset.pluginCss = tagId$3;
67
+ tag.textContent = css$3;
68
+ document.head.appendChild(tag);
69
+ }
70
+ var ModelsSection_module_css_default = {
71
+ "iconButtonDanger": "zGbnIq_iconButtonDanger",
72
+ "editorActions": "zGbnIq_editorActions",
73
+ "error": "zGbnIq_error",
74
+ "modelRow": "zGbnIq_modelRow",
75
+ "section": "zGbnIq_section",
76
+ "linkButton": "zGbnIq_linkButton",
77
+ "hiddenLabel": "zGbnIq_hiddenLabel",
78
+ "rows": "zGbnIq_rows",
79
+ "candidateLabel": "zGbnIq_candidateLabel",
80
+ "input": "zGbnIq_input",
81
+ "notice": "zGbnIq_notice",
82
+ "fetchDialog": "zGbnIq_fetchDialog",
83
+ "candidate": "zGbnIq_candidate",
84
+ "customizedBody": "zGbnIq_customizedBody",
85
+ "modelListHead": "zGbnIq_modelListHead",
86
+ "deleteDialog": "zGbnIq_deleteDialog",
87
+ "modelEntry": "zGbnIq_modelEntry",
88
+ "addModelButton": "zGbnIq_addModelButton",
89
+ "modelCatalogTitle": "zGbnIq_modelCatalogTitle",
90
+ "editorRoute": "zGbnIq_editorRoute",
91
+ "rowCard": "zGbnIq_rowCard",
92
+ "rowName": "zGbnIq_rowName",
93
+ "modelAdvanced": "zGbnIq_modelAdvanced",
94
+ "primaryButton": "zGbnIq_primaryButton",
95
+ "intro": "zGbnIq_intro",
96
+ "rowIdentity": "zGbnIq_rowIdentity",
97
+ "modelCatalog": "zGbnIq_modelCatalog",
98
+ "editorHeader": "zGbnIq_editorHeader",
99
+ "credentialDot": "zGbnIq_credentialDot",
100
+ "dangerButton": "zGbnIq_dangerButton",
101
+ "modelFieldLabel": "zGbnIq_modelFieldLabel",
102
+ "field": "zGbnIq_field",
103
+ "credentialDotConfigured": "zGbnIq_credentialDotConfigured",
104
+ "addBlock": "zGbnIq_addBlock",
105
+ "deleteConfirm": "zGbnIq_deleteConfirm",
106
+ "modelEmpty": "zGbnIq_modelEmpty",
107
+ "editor": "zGbnIq_editor",
108
+ "addButton": "zGbnIq_addButton",
109
+ "candidateList": "zGbnIq_candidateList",
110
+ "secondaryButton": "zGbnIq_secondaryButton",
111
+ "modelCatalogMeta": "zGbnIq_modelCatalogMeta",
112
+ "modelField": "zGbnIq_modelField",
113
+ "customized": "zGbnIq_customized",
114
+ "selectInput": "zGbnIq_selectInput",
115
+ "iconButton": "zGbnIq_iconButton",
116
+ "setupCard": "zGbnIq_setupCard",
117
+ "fieldLabel": "zGbnIq_fieldLabel",
118
+ "rowActions": "zGbnIq_rowActions",
119
+ "addCard": "zGbnIq_addCard",
120
+ "candidateId": "zGbnIq_candidateId",
121
+ "modelCatalogHeading": "zGbnIq_modelCatalogHeading",
122
+ "credentialDotMissing": "zGbnIq_credentialDotMissing",
123
+ "rowTag": "zGbnIq_rowTag",
124
+ "customizedSummary": "zGbnIq_customizedSummary",
125
+ "addActions": "zGbnIq_addActions",
126
+ "editorTitle": "zGbnIq_editorTitle",
127
+ "savedNotice": "zGbnIq_savedNotice",
128
+ "modelList": "zGbnIq_modelList",
129
+ "advancedHint": "zGbnIq_advancedHint",
130
+ "title": "zGbnIq_title",
131
+ "rowHead": "zGbnIq_rowHead"
132
+ };
133
+ //#endregion
134
+ //#region lib/types/client/EditorFooter.js
135
+ /**
136
+ * Render one provider card's action row.
137
+ * @param props - the labels, commit gating, and handlers the owning card supplies.
138
+ * @returns the cancel/commit row.
139
+ */
140
+ function EditorFooter(props) {
141
+ const { t } = props;
142
+ return (0, react_jsx_runtime.jsxs)("div", {
143
+ className: ModelsSection_module_css_default["editorActions"],
144
+ children: [(0, react_jsx_runtime.jsx)("button", {
145
+ type: "button",
146
+ className: ModelsSection_module_css_default["secondaryButton"],
147
+ disabled: props.busy,
148
+ onClick: props.onCancel,
149
+ children: t(props.cancelLabel ?? "cancel")
150
+ }), (0, react_jsx_runtime.jsx)("button", {
151
+ type: "button",
152
+ className: ModelsSection_module_css_default["primaryButton"],
153
+ disabled: props.submitDisabled,
154
+ onClick: props.onSubmit,
155
+ children: props.busy ? t(props.submitBusyLabel) : t(props.submitLabel)
156
+ })]
157
+ });
158
+ }
159
+ //#endregion
160
+ //#region lib/types/client/DeepSeekModelsEditor.js
161
+ /**
162
+ * Curated editor for the direct DeepSeek adapter's advisory model catalog.
163
+ * The settings layer replaces `models` as one array, so the parent supplies
164
+ * the effective inherited rows until the first edit materializes a user
165
+ * override; reset removes that override instead of copying defaults into it.
166
+ */
167
+ /** Row index encoded in an editing-buffer key. */
168
+ function rowOf(key) {
169
+ return Number(key.slice(0, key.indexOf(":")));
170
+ }
171
+ /** Accepted capacity spellings: a decimal count with an optional K/M suffix. */
172
+ const CAPACITY_PATTERN = /^(\d+(?:\.\d+)?)([km])?$/i;
173
+ /** Decimal suffix scales — `1M` is 1000K, matching how model capacities are quoted. */
174
+ const CAPACITY_SCALE = {
175
+ k: 1e3,
176
+ m: 1e6
177
+ };
178
+ /**
179
+ * Read a typed capacity, so a user can write `256K` or `1M` instead of counting
180
+ * zeroes. The stored value stays a plain token count.
181
+ * @param text - raw field text.
182
+ * @returns the count; `undefined` when blank (inherit), `NaN` when unreadable
183
+ * (rejected by {@link validateDeepSeekModels} before any write).
184
+ */
185
+ function parseCapacity(text) {
186
+ const trimmed = text.trim();
187
+ if (trimmed.length === 0) return void 0;
188
+ const match = CAPACITY_PATTERN.exec(trimmed);
189
+ if (match === null) return NaN;
190
+ const suffix = match[2]?.toLowerCase();
191
+ const scale = suffix === "k" || suffix === "m" ? CAPACITY_SCALE[suffix] : 1;
192
+ const scaled = Number(match[1]) * scale;
193
+ const rounded = Math.round(scaled);
194
+ return Math.abs(scaled - rounded) < 1e-6 ? rounded : scaled;
195
+ }
196
+ /**
197
+ * Spell a stored count back in the shortest form that survives a round trip
198
+ * through {@link parseCapacity}; a count that is not a whole number of
199
+ * thousands stays written out.
200
+ * @param value - stored capacity.
201
+ * @returns the field text.
202
+ */
203
+ function formatCapacity(value) {
204
+ if (!Number.isInteger(value) || value <= 0) return String(value);
205
+ if (value % CAPACITY_SCALE.m === 0) return `${String(value / CAPACITY_SCALE.m)}M`;
206
+ if (value % CAPACITY_SCALE.k === 0) return `${String(value / CAPACITY_SCALE.k)}K`;
207
+ return String(value);
208
+ }
209
+ /** Convert a schema-validated catalog value into records without dropping hidden fields. */
210
+ function modelDrafts(value) {
211
+ if (!Array.isArray(value)) return [];
212
+ return value.map((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry) ? entry : {});
213
+ }
214
+ /**
215
+ * Validate adapter constraints that the serialized schema cannot express.
216
+ * @param value - user-owned `models` value, or undefined while inherited.
217
+ * @returns the first invalid row, or undefined when the adapter will accept it.
218
+ */
219
+ function validateDeepSeekModels(value) {
220
+ if (value === void 0) return void 0;
221
+ const models = modelDrafts(value);
222
+ const seen = /* @__PURE__ */ new Set();
223
+ for (const [index, model] of models.entries()) {
224
+ const id = model["id"];
225
+ const trimmed = typeof id === "string" ? id.trim() : void 0;
226
+ if (trimmed === void 0 || trimmed.length === 0) return {
227
+ index,
228
+ key: "modelIdRequired"
229
+ };
230
+ if (seen.has(trimmed)) return {
231
+ index,
232
+ key: "modelIdDuplicate"
233
+ };
234
+ seen.add(trimmed);
235
+ const name = model["name"];
236
+ if (name !== void 0 && (typeof name !== "string" || name.length === 0)) return {
237
+ index,
238
+ key: "modelNameInvalid"
239
+ };
240
+ const contextWindow = model["contextWindow"];
241
+ if (contextWindow !== void 0 && (typeof contextWindow !== "number" || !Number.isInteger(contextWindow) || contextWindow <= 0)) return {
242
+ index,
243
+ key: "modelContextInvalid"
244
+ };
245
+ const maxTokens = model["maxTokens"];
246
+ if (maxTokens !== void 0 && (typeof maxTokens !== "number" || !Number.isInteger(maxTokens) || maxTokens <= 0)) return {
247
+ index,
248
+ key: "modelMaxTokensInvalid"
249
+ };
250
+ }
251
+ }
252
+ /**
253
+ * Render the direct DeepSeek adapter's model catalog: id and display name on
254
+ * each row, capacities behind the row's own disclosure.
255
+ * @param props - effective rows plus the array-level override actions.
256
+ * @returns the catalog editor.
257
+ */
258
+ function DeepSeekModelsEditor(props) {
259
+ const [editing, setEditing] = (0, react.useState)(() => /* @__PURE__ */ new Map());
260
+ const [expanded, setExpanded] = (0, react.useState)(() => /* @__PURE__ */ new Set());
261
+ const update = (index, key, value) => {
262
+ const next = props.models.map((model, at) => {
263
+ const copy = { ...model };
264
+ if (at !== index) return copy;
265
+ if (value === void 0) Reflect.deleteProperty(copy, key);
266
+ else copy[key] = value;
267
+ return copy;
268
+ });
269
+ props.onChange(next);
270
+ };
271
+ const remove = (index) => {
272
+ setEditing((current) => {
273
+ const next = /* @__PURE__ */ new Map();
274
+ for (const [key, text] of current) {
275
+ const at = rowOf(key);
276
+ if (at === index) continue;
277
+ next.set(at > index ? key.replace(/^\d+/, String(at - 1)) : key, text);
278
+ }
279
+ return next;
280
+ });
281
+ setExpanded((current) => {
282
+ const next = /* @__PURE__ */ new Set();
283
+ for (const at of current) {
284
+ if (at === index) continue;
285
+ next.add(at > index ? at - 1 : at);
286
+ }
287
+ return next;
288
+ });
289
+ props.onChange(props.models.filter((_model, at) => at !== index).map((model) => ({ ...model })));
290
+ };
291
+ const reset = () => {
292
+ setEditing(/* @__PURE__ */ new Map());
293
+ setExpanded(/* @__PURE__ */ new Set());
294
+ props.onReset();
295
+ };
296
+ const toggle = (index) => {
297
+ setExpanded((current) => {
298
+ const next = new Set(current);
299
+ if (!next.delete(index)) next.add(index);
300
+ return next;
301
+ });
302
+ };
303
+ /** The field's text: its live keystrokes, else the stored count spelled short. */
304
+ const capacityText = (model, index, field) => {
305
+ const typed = editing.get(`${String(index)}:${field}`);
306
+ if (typed !== void 0) return typed;
307
+ const value = model[field];
308
+ return typeof value === "number" ? formatCapacity(value) : "";
309
+ };
310
+ const settleCapacity = (index, field) => {
311
+ const key = `${String(index)}:${field}`;
312
+ const typed = editing.get(key);
313
+ if (typed === void 0) return;
314
+ const parsed = parseCapacity(typed);
315
+ if (parsed !== void 0 && Number.isNaN(parsed)) return;
316
+ setEditing((current) => {
317
+ const next = new Map(current);
318
+ next.delete(key);
319
+ return next;
320
+ });
321
+ };
322
+ /** One capacity field of one row, rendered inside the row's disclosure. */
323
+ const capacityField = (model, index, field, fallback) => (0, react_jsx_runtime.jsxs)("label", {
324
+ className: ModelsSection_module_css_default["modelField"],
325
+ children: [(0, react_jsx_runtime.jsx)("span", {
326
+ className: ModelsSection_module_css_default["modelFieldLabel"],
327
+ children: props.t(field === "contextWindow" ? "contextWindow" : "maxTokens")
328
+ }), (0, react_jsx_runtime.jsx)("input", {
329
+ className: ModelsSection_module_css_default["input"],
330
+ type: "text",
331
+ inputMode: "numeric",
332
+ value: capacityText(model, index, field),
333
+ placeholder: fallback === void 0 ? props.t(field === "contextWindow" ? "contextWindowPlaceholder" : "maxTokensPlaceholder") : formatCapacity(fallback),
334
+ "aria-label": `${props.t(field === "contextWindow" ? "contextWindow" : "maxTokens")} ${String(index + 1)}`,
335
+ disabled: props.disabled,
336
+ onChange: (event) => {
337
+ const text = event.target.value;
338
+ setEditing((current) => new Map(current).set(`${String(index)}:${field}`, text));
339
+ update(index, field, parseCapacity(text));
340
+ },
341
+ onBlur: () => {
342
+ settleCapacity(index, field);
343
+ }
344
+ })]
345
+ });
346
+ return (0, react_jsx_runtime.jsxs)("section", {
347
+ className: ModelsSection_module_css_default["modelCatalog"],
348
+ "aria-label": props.t("models"),
349
+ children: [
350
+ (0, react_jsx_runtime.jsxs)("div", {
351
+ className: ModelsSection_module_css_default["modelListHead"],
352
+ children: [(0, react_jsx_runtime.jsxs)("div", {
353
+ className: ModelsSection_module_css_default["modelCatalogHeading"],
354
+ children: [(0, react_jsx_runtime.jsx)("span", {
355
+ className: ModelsSection_module_css_default["modelCatalogTitle"],
356
+ children: props.t("models")
357
+ }), (0, react_jsx_runtime.jsx)("span", {
358
+ className: ModelsSection_module_css_default["modelCatalogMeta"],
359
+ children: props.overridden ? props.t("modelsCustomized") : props.t("modelsInherited")
360
+ })]
361
+ }), props.overridden ? (0, react_jsx_runtime.jsx)("button", {
362
+ type: "button",
363
+ className: ModelsSection_module_css_default["linkButton"],
364
+ disabled: props.disabled,
365
+ onClick: reset,
366
+ children: props.t("resetModels")
367
+ }) : null]
368
+ }),
369
+ props.models.length === 0 ? (0, react_jsx_runtime.jsx)("p", {
370
+ className: ModelsSection_module_css_default["modelEmpty"],
371
+ children: props.t("modelsEmpty")
372
+ }) : (0, react_jsx_runtime.jsx)("div", {
373
+ className: ModelsSection_module_css_default["modelList"],
374
+ children: props.models.map((model, index) => (0, react_jsx_runtime.jsxs)("div", {
375
+ className: ModelsSection_module_css_default["modelEntry"],
376
+ children: [(0, react_jsx_runtime.jsxs)("div", {
377
+ className: ModelsSection_module_css_default["modelRow"],
378
+ children: [
379
+ (0, react_jsx_runtime.jsx)("input", {
380
+ className: ModelsSection_module_css_default["input"],
381
+ type: "text",
382
+ value: typeof model["id"] === "string" ? model["id"] : "",
383
+ placeholder: props.t("modelId"),
384
+ "aria-label": `${props.t("modelId")} ${String(index + 1)}`,
385
+ disabled: props.disabled,
386
+ onChange: (event) => {
387
+ update(index, "id", event.target.value);
388
+ },
389
+ onBlur: (event) => {
390
+ const trimmed = event.target.value.trim();
391
+ if (trimmed !== event.target.value) update(index, "id", trimmed);
392
+ }
393
+ }),
394
+ (0, react_jsx_runtime.jsx)("input", {
395
+ className: ModelsSection_module_css_default["input"],
396
+ type: "text",
397
+ value: typeof model["name"] === "string" ? model["name"] : "",
398
+ placeholder: props.t("modelName"),
399
+ "aria-label": `${props.t("modelName")} ${String(index + 1)}`,
400
+ disabled: props.disabled,
401
+ onChange: (event) => {
402
+ update(index, "name", event.target.value === "" ? void 0 : event.target.value);
403
+ }
404
+ }),
405
+ (0, react_jsx_runtime.jsx)("button", {
406
+ type: "button",
407
+ className: ModelsSection_module_css_default["iconButton"],
408
+ "aria-label": `${props.t("modelAdvanced")} ${String(index + 1)}`,
409
+ "aria-expanded": expanded.has(index),
410
+ title: props.t("modelAdvanced"),
411
+ onClick: () => {
412
+ toggle(index);
413
+ },
414
+ children: expanded.has(index) ? (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutline14, {}) : (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutline14, {})
415
+ }),
416
+ (0, react_jsx_runtime.jsx)("button", {
417
+ type: "button",
418
+ className: `${ModelsSection_module_css_default["iconButton"]} ${ModelsSection_module_css_default["iconButtonDanger"]}`,
419
+ "aria-label": `${props.t("removeModel")} ${String(index + 1)}`,
420
+ title: props.t("removeModel"),
421
+ disabled: props.disabled,
422
+ onClick: () => {
423
+ remove(index);
424
+ },
425
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconTrashOutline16, { size: 14 })
426
+ })
427
+ ]
428
+ }), expanded.has(index) ? (0, react_jsx_runtime.jsxs)("div", {
429
+ className: ModelsSection_module_css_default["modelAdvanced"],
430
+ children: [capacityField(model, index, "contextWindow", props.defaultContextWindow), capacityField(model, index, "maxTokens", props.defaultMaxTokens)]
431
+ }) : null]
432
+ }, index))
433
+ }),
434
+ (0, react_jsx_runtime.jsxs)("button", {
435
+ type: "button",
436
+ className: ModelsSection_module_css_default["addModelButton"],
437
+ disabled: props.disabled,
438
+ onClick: () => {
439
+ props.onChange([...props.models.map((model) => ({ ...model })), { id: "" }]);
440
+ },
441
+ children: [(0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 14 }), props.t("addModel")]
442
+ })
443
+ ]
444
+ });
445
+ }
446
+ //#endregion
447
+ //#region lib/types/client/store.js
448
+ /**
449
+ * Models settings page store: one snapshot joining the configurable-provider
450
+ * directory (`llm.providers`), the settings namespaces (`settings.describe`),
451
+ * and the referenced credentials (`credentials.describe`). The host stays the
452
+ * single fact source — every mutation writes through the wire and the page
453
+ * re-renders from the next describe, pushed or refetched.
454
+ */
455
+ /**
456
+ * Any route key walks a dict schema to the same profile node, so the lookup
457
+ * names one that cannot collide with a configured route.
458
+ */
459
+ const PROBE_ROUTE = "\0probe";
460
+ /**
461
+ * Human text for a rejected wire call. A transport failure rejects with an
462
+ * Error; a host or a runtime can reject with anything, and the page still has
463
+ * to say something.
464
+ * @param error - the rejection value.
465
+ * @returns the message to show.
466
+ */
467
+ function messageOf$1(error) {
468
+ return error instanceof Error ? error.message : String(error);
469
+ }
470
+ /**
471
+ * Derive the conventional credential reference for a provider route: the v1
472
+ * page never asks for an environment-variable name, so a typed key stores
473
+ * under this derived reference and the profile records it as `apiKeyEnv`.
474
+ * @param provider - provider route id (e.g. `anthropic`, `minimax-cn`).
475
+ * @returns the derived reference name (e.g. `MINIMAX_CN_API_KEY`).
476
+ */
477
+ function deriveKeyRef(provider) {
478
+ return `${provider.toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_API_KEY`;
479
+ }
480
+ /**
481
+ * The wire protocols a hand-declared route may name, read out of the owning
482
+ * namespace's own schema. This stays a schema read rather than a wire field so
483
+ * the choices the page offers cannot drift from the ones the adapter accepts:
484
+ * both come from the same `Config`.
485
+ * @param namespace - the namespace view whose schema declares the profile shape.
486
+ * @returns the protocol identifiers, or an empty list when the schema has none.
487
+ */
488
+ function protocolChoices(namespace) {
489
+ if (namespace === void 0) return [];
490
+ const list = (0, _deepseek_ai_dsh_client_schema_form.nodeAtPath)((0, _deepseek_ai_dsh_client_schema_form.rehydrateSchema)(namespace.schema), [
491
+ "providers",
492
+ PROBE_ROUTE,
493
+ "api"
494
+ ]);
495
+ if (list?.type !== "union" || list.list === void 0) return [];
496
+ return list.list.map((entry) => entry.value).filter((value) => typeof value === "string");
497
+ }
498
+ /** The credential reference a resolved profile names (its `apiKeyEnv` field). */
499
+ function apiKeyEnvOf(namespace, path) {
500
+ if (namespace === void 0) return void 0;
501
+ const profile = (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.value, path);
502
+ if (typeof profile !== "object" || profile === null) return void 0;
503
+ const ref = profile.apiKeyEnv;
504
+ return typeof ref === "string" && ref.length > 0 ? ref : void 0;
505
+ }
506
+ /** The models settings page controller (one per settings surface). */
507
+ var ModelsSettingsStore = class {
508
+ api;
509
+ /** The snapshot the section renders from (uSES-safe store). */
510
+ store = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
511
+ status: "idle",
512
+ error: null,
513
+ credentialError: null,
514
+ writable: false,
515
+ rows: [],
516
+ namespaces: /* @__PURE__ */ new Map()
517
+ });
518
+ /** Latest load wins; an older response never overwrites a newer one. */
519
+ generation = 0;
520
+ /**
521
+ * @param api - the wire face (settings/credentials/llm domains).
522
+ */
523
+ constructor(api) {
524
+ this.api = api;
525
+ }
526
+ /**
527
+ * Refresh the whole page snapshot: directory and namespaces in parallel,
528
+ * then one batched credential describe over every referenced ref. A
529
+ * failure keeps the last good rows and surfaces the error.
530
+ * @returns nothing; the snapshot carries the outcome.
531
+ */
532
+ async load() {
533
+ const generation = ++this.generation;
534
+ this.store.update((s) => {
535
+ s.status = "loading";
536
+ s.error = null;
537
+ });
538
+ let providers;
539
+ let writable;
540
+ let views;
541
+ try {
542
+ const [providersResponse, settingsResponse] = await Promise.all([this.api.llm.providers({}), this.api.settings.describe({})]);
543
+ if (!providersResponse.result.ok) throw new Error(providersResponse.result.error.message);
544
+ if (!settingsResponse.result.ok) throw new Error(settingsResponse.result.error.message);
545
+ providers = providersResponse.result.value.providers;
546
+ writable = settingsResponse.result.value.writable;
547
+ views = settingsResponse.result.value.namespaces;
548
+ } catch (error) {
549
+ if (generation !== this.generation) return;
550
+ this.store.update((s) => {
551
+ s.status = "error";
552
+ s.error = error instanceof Error ? error.message : String(error);
553
+ });
554
+ return;
555
+ }
556
+ const namespaces = new Map(views.map((view) => [view.ns, view]));
557
+ const rows = providers.map((entry) => {
558
+ const namespace = namespaces.get(entry.settingsNs);
559
+ return {
560
+ entry,
561
+ configured: namespace !== void 0 && (entry.settingsPath.length === 0 || (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.value, entry.settingsPath) !== void 0),
562
+ removable: namespace !== void 0 && entry.settingsPath.length > 0 && (0, _deepseek_ai_dsh_client_schema_form.hasPath)(namespace.user, entry.settingsPath) && !(0, _deepseek_ai_dsh_client_schema_form.hasPath)(namespace.base, entry.settingsPath),
563
+ apiKeyEnv: apiKeyEnvOf(namespace, entry.settingsPath),
564
+ credential: void 0
565
+ };
566
+ });
567
+ const refs = [...new Set(rows.flatMap((row) => row.apiKeyEnv === void 0 ? [] : [row.apiKeyEnv]))];
568
+ let credentials = {};
569
+ let credentialError = null;
570
+ if (refs.length > 0) try {
571
+ const response = await this.api.credentials.describe({ refs });
572
+ if (response.result.ok) credentials = response.result.value.credentials;
573
+ else credentialError = response.result.error.message;
574
+ } catch (error) {
575
+ credentialError = messageOf$1(error);
576
+ }
577
+ if (generation !== this.generation) return;
578
+ this.store.update((s) => {
579
+ s.status = "ready";
580
+ s.error = null;
581
+ s.credentialError = credentialError;
582
+ s.writable = writable;
583
+ s.rows = rows.map((row) => ({
584
+ ...row,
585
+ ...row.apiKeyEnv !== void 0 && credentials[row.apiKeyEnv] !== void 0 ? { credential: credentials[row.apiKeyEnv] } : {}
586
+ }));
587
+ s.namespaces = namespaces;
588
+ });
589
+ }
590
+ };
591
+ /**
592
+ * Whether a joined row can serve model requests as it stands: the route is
593
+ * registered with the adapter registry, and whatever credential its resolved
594
+ * profile names is stored. A profile naming no reference authenticates through
595
+ * the provider's own path (the Bedrock chain, Vertex ADC, a gateway that needs
596
+ * nothing), as does a live route with no settings address at all, so neither
597
+ * owes this page a key.
598
+ * @param row - one joined provider row.
599
+ * @returns whether the user already has this provider to talk to.
600
+ */
601
+ function providerUsable(row) {
602
+ if (!row.entry.active) return false;
603
+ if (row.apiKeyEnv === void 0) return true;
604
+ return row.credential?.configured === true;
605
+ }
606
+ /**
607
+ * Project first-run readiness from the provider/settings/credential join used
608
+ * by the Models page. The step exists to leave the user with a model to talk
609
+ * to, so ANY usable provider ends it; only when none exists does the official
610
+ * DeepSeek route — the one route the prompt can offer a key field for — decide
611
+ * whether prompting can help. A missing official configurable-provider
612
+ * declaration means the adapter is not repairable by navigating to Models.
613
+ * @param state - current shared Models join snapshot.
614
+ * @returns the onboarding state without reading a parallel fact source.
615
+ */
616
+ function onboardingReadiness(state) {
617
+ if ((state.status === "idle" || state.status === "loading") && state.rows.length === 0) return { kind: "loading" };
618
+ if (state.status === "error") return {
619
+ kind: "unavailable",
620
+ reason: "load-failed"
621
+ };
622
+ if (state.rows.some(providerUsable)) return { kind: "provider-ready" };
623
+ const row = state.rows.find((candidate) => candidate.entry.provider === "deepseek-official" && candidate.entry.settingsNs === "llm-deepseek" && candidate.entry.settingsPath.length === 0);
624
+ if (row === void 0) return { kind: "adapter-absent" };
625
+ if (!row.entry.active) return {
626
+ kind: "unavailable",
627
+ reason: "provider-inactive"
628
+ };
629
+ if (state.credentialError !== null || row.credential === void 0) return {
630
+ kind: "unavailable",
631
+ reason: "credentials-unavailable"
632
+ };
633
+ if (!state.writable) return {
634
+ kind: "unavailable",
635
+ reason: "settings-read-only"
636
+ };
637
+ if (!row.credential.writable) return {
638
+ kind: "unavailable",
639
+ reason: "credential-read-only"
640
+ };
641
+ return { kind: "credential-missing" };
642
+ }
643
+ //#endregion
644
+ //#region lib/types/client/ModelListEditor.js
645
+ /**
646
+ * The model list of one pi-ai provider profile, plus the action that asks the
647
+ * provider what it serves.
648
+ *
649
+ * The list is the profile's `models` array as the card holds it: an empty list
650
+ * means "serve this route's built-in catalog", and any entry replaces that
651
+ * catalog, so a row is only ever added deliberately. Fetching asks the endpoint
652
+ * **the form currently shows** — including a key typed but not yet saved — so
653
+ * adding a provider is one pass instead of save-then-return; the reply is
654
+ * candidates the user picks from, never configuration written behind them.
655
+ *
656
+ * A provider that cannot be interrogated (an unreachable endpoint, a protocol
657
+ * with no readable listing) is not a dead end: the failure is shown next to the
658
+ * rows the user can still fill in by hand.
659
+ */
660
+ /** A row's text field, or the empty string when unset or not a string. */
661
+ function textOf(model, key) {
662
+ const value = model[key];
663
+ return typeof value === "string" ? value : "";
664
+ }
665
+ /** A row's numeric field, or `undefined` when unset or not a number. */
666
+ function numberOf(model, key) {
667
+ const value = model[key];
668
+ return typeof value === "number" ? value : void 0;
669
+ }
670
+ /** Disclosure chevron; rotates to point down while its row is open. */
671
+ function IconChevron({ open }) {
672
+ return (0, react_jsx_runtime.jsx)("svg", {
673
+ width: "14",
674
+ height: "14",
675
+ viewBox: "0 0 16 16",
676
+ fill: "none",
677
+ "aria-hidden": true,
678
+ style: {
679
+ transform: open ? "rotate(90deg)" : void 0,
680
+ transition: "transform 120ms ease"
681
+ },
682
+ children: (0, react_jsx_runtime.jsx)("path", {
683
+ d: "M6 3.5L10.5 8L6 12.5",
684
+ stroke: "currentColor",
685
+ strokeWidth: "1.5",
686
+ strokeLinecap: "round",
687
+ strokeLinejoin: "round"
688
+ })
689
+ });
690
+ }
691
+ /** Removal glyph for one model row. */
692
+ function IconTrash() {
693
+ return (0, react_jsx_runtime.jsx)("svg", {
694
+ width: "14",
695
+ height: "14",
696
+ viewBox: "0 0 16 16",
697
+ fill: "none",
698
+ "aria-hidden": true,
699
+ children: (0, react_jsx_runtime.jsx)("path", {
700
+ d: "M2.5 4h11M6.5 4V2.5h3V4M4 4l.7 9a1 1 0 001 .9h4.6a1 1 0 001-.9L12 4M6.5 6.8v4.4M9.5 6.8v4.4",
701
+ stroke: "currentColor",
702
+ strokeWidth: "1.3",
703
+ strokeLinecap: "round",
704
+ strokeLinejoin: "round"
705
+ })
706
+ });
707
+ }
708
+ /**
709
+ * What an empty capacity field is worth, shown as its placeholder so a row left
710
+ * blank does not read as a model with no capacity at all.
711
+ *
712
+ * The magnitudes are the adapter's own route-level fallbacks (`llm-pi-ai`'s
713
+ * `defaultContextWindow` and `defaultMaxTokens`), spelled the way a person
714
+ * would say them. They are a hint, not a mirror: this page counts `K` as 1000,
715
+ * so typing `256K` stores 256000 while leaving the field blank keeps the
716
+ * adapter's 262144. A deployment that overrides those defaults is not
717
+ * reflected here — nothing on this page can read them.
718
+ */
719
+ const CAPACITY_HINT = {
720
+ contextWindow: "256K",
721
+ maxTokens: "32K"
722
+ };
723
+ /**
724
+ * Spell a stored count for a field that may be unset. The spelling itself is
725
+ * {@link formatCapacity}, shared with the DeepSeek catalog editor so both
726
+ * surfaces read and write one K/M vocabulary.
727
+ * @param value - stored capacity, or `undefined` for an unset field.
728
+ * @returns the field text, empty when unset.
729
+ */
730
+ function capacitySpelling(value) {
731
+ return value === void 0 ? "" : formatCapacity(value);
732
+ }
733
+ /** Adopt a candidate, keeping whatever capacities the provider disclosed. */
734
+ function adopt(candidate) {
735
+ return {
736
+ id: candidate.id,
737
+ ...candidate.name === void 0 ? {} : { name: candidate.name },
738
+ ...candidate.contextWindow === void 0 ? {} : { contextWindow: candidate.contextWindow },
739
+ ...candidate.maxTokens === void 0 ? {} : { maxTokens: candidate.maxTokens }
740
+ };
741
+ }
742
+ /**
743
+ * Render the model list with its fetch action.
744
+ * @param props - the drafted rows, probe target, wire face, and copy.
745
+ * @returns the model-list editor.
746
+ */
747
+ function ModelListEditor(props) {
748
+ const { models, onChange, probe, api, t, disabled } = props;
749
+ const [busy, setBusy] = (0, react.useState)(false);
750
+ const [failure, setFailure] = (0, react.useState)(void 0);
751
+ const [candidates, setCandidates] = (0, react.useState)(void 0);
752
+ const [picked, setPicked] = (0, react.useState)(/* @__PURE__ */ new Set());
753
+ const [expanded, setExpanded] = (0, react.useState)(/* @__PURE__ */ new Set());
754
+ const [editing, setEditing] = (0, react.useState)(/* @__PURE__ */ new Map());
755
+ /** Buffer key for one capacity field; the row half moves when rows do. */
756
+ const bufferKey = (index, field) => `${String(index)}:${field}`;
757
+ const editCapacity = (index, field, text) => {
758
+ setEditing((current) => new Map(current).set(bufferKey(index, field), text));
759
+ patch(index, { [field]: parseCapacity(text) });
760
+ };
761
+ /** What a capacity field shows: the buffer while typing, else the stored count. */
762
+ const capacityText = (model, index, field) => editing.get(bufferKey(index, field)) ?? capacitySpelling(numberOf(model, field));
763
+ /** Drop one row's entries and shift the rows after it down, in one pass. */
764
+ const reindexOnRemove = (current, index) => {
765
+ const next = /* @__PURE__ */ new Map();
766
+ for (const [key, value] of current) {
767
+ const at = Number(key.slice(0, key.indexOf(":")));
768
+ if (at === index) continue;
769
+ next.set(at > index ? key.replace(/^\d+/, String(at - 1)) : key, value);
770
+ }
771
+ return next;
772
+ };
773
+ const toggleExpanded = (index) => {
774
+ setExpanded((current) => {
775
+ const next = new Set(current);
776
+ if (!next.delete(index)) next.add(index);
777
+ return next;
778
+ });
779
+ };
780
+ const patch = (index, next) => {
781
+ onChange(models.map((model, at) => {
782
+ if (at !== index) return model;
783
+ const cleared = new Set(Object.entries(next).filter(([, value]) => value === void 0 || value === "").map(([key]) => key));
784
+ return Object.fromEntries(Object.entries({
785
+ ...model,
786
+ ...next
787
+ }).filter(([key]) => !cleared.has(key)));
788
+ }));
789
+ };
790
+ const fetchModels = async () => {
791
+ setBusy(true);
792
+ setFailure(void 0);
793
+ try {
794
+ const response = await api.llm.discoverModels({
795
+ settingsNs: probe.settingsNs,
796
+ ...probe.provider === void 0 ? {} : { provider: probe.provider },
797
+ ...probe.baseURL === void 0 || probe.baseURL.length === 0 ? {} : { baseURL: probe.baseURL },
798
+ ...probe.api === void 0 ? {} : { api: props.thinkingPresets ? CLAUDE_DISCOVERY_API : probe.api },
799
+ ...probe.apiKey === void 0 ? {} : { apiKey: probe.apiKey }
800
+ });
801
+ if (!response.result.ok) {
802
+ setFailure(response.result.error.message);
803
+ return;
804
+ }
805
+ const found = response.result.value.models;
806
+ if (found.length === 0) {
807
+ setFailure(t("fetchEmpty"));
808
+ return;
809
+ }
810
+ const known = new Set(models.map((model) => textOf(model, "id")));
811
+ setCandidates(found);
812
+ setPicked(new Set(found.filter((model) => !known.has(model.id)).map((model) => model.id)));
813
+ } catch (error) {
814
+ setFailure(messageOf$1(error));
815
+ } finally {
816
+ setBusy(false);
817
+ }
818
+ };
819
+ const closePicker = () => {
820
+ setCandidates(void 0);
821
+ setPicked(/* @__PURE__ */ new Set());
822
+ };
823
+ const adoptPicked = () => {
824
+ /* v8 ignore next -- the dialog only renders with candidates loaded */
825
+ if (candidates === void 0) return;
826
+ const byId = new Map(models.map((model) => [textOf(model, "id"), model]));
827
+ for (const candidate of candidates) {
828
+ if (!picked.has(candidate.id)) continue;
829
+ byId.set(candidate.id, byId.get(candidate.id) ?? (props.thinkingPresets ? withFetchedClaudeMetadata(adopt(candidate)) : adopt(candidate)));
830
+ }
831
+ onChange([...byId.values()]);
832
+ closePicker();
833
+ };
834
+ const toggle = (id) => {
835
+ setPicked((current) => {
836
+ const next = new Set(current);
837
+ if (!next.delete(id)) next.add(id);
838
+ return next;
839
+ });
840
+ };
841
+ const askable = probe.provider !== void 0 || probe.baseURL !== void 0 && probe.baseURL.length > 0;
842
+ return (0, react_jsx_runtime.jsxs)("section", {
843
+ className: ModelsSection_module_css_default["modelCatalog"],
844
+ "aria-label": t("models"),
845
+ children: [
846
+ (0, react_jsx_runtime.jsxs)("div", {
847
+ className: ModelsSection_module_css_default["modelListHead"],
848
+ children: [
849
+ (0, react_jsx_runtime.jsxs)("div", {
850
+ className: ModelsSection_module_css_default["modelCatalogHeading"],
851
+ children: [(0, react_jsx_runtime.jsx)("span", {
852
+ className: ModelsSection_module_css_default["modelCatalogTitle"],
853
+ children: t("models")
854
+ }), props.overridden === void 0 ? null : (0, react_jsx_runtime.jsx)("span", {
855
+ className: ModelsSection_module_css_default["modelCatalogMeta"],
856
+ children: props.overridden ? t("modelsCustomized") : t("modelsInherited")
857
+ })]
858
+ }),
859
+ props.overridden === true && props.onReset !== void 0 ? (0, react_jsx_runtime.jsx)("button", {
860
+ type: "button",
861
+ className: ModelsSection_module_css_default["linkButton"],
862
+ disabled,
863
+ onClick: props.onReset,
864
+ children: t("resetModels")
865
+ }) : null,
866
+ (0, react_jsx_runtime.jsx)("button", {
867
+ type: "button",
868
+ className: ModelsSection_module_css_default["linkButton"],
869
+ disabled: disabled || busy || !askable || props.probeBlocked !== void 0,
870
+ title: props.probeBlocked !== void 0 ? t(props.probeBlocked) : askable ? void 0 : t("fetchNeedsBaseUrl"),
871
+ onClick: () => {
872
+ fetchModels();
873
+ },
874
+ children: busy ? t("fetching") : t("fetchModels")
875
+ })
876
+ ]
877
+ }),
878
+ models.length === 0 ? (0, react_jsx_runtime.jsx)("p", {
879
+ className: ModelsSection_module_css_default["modelEmpty"],
880
+ children: t("modelsEmpty")
881
+ }) : null,
882
+ models.map((model, index) => (0, react_jsx_runtime.jsxs)("div", {
883
+ className: ModelsSection_module_css_default["modelEntry"],
884
+ children: [(0, react_jsx_runtime.jsxs)("div", {
885
+ className: ModelsSection_module_css_default["modelRow"],
886
+ children: [
887
+ (0, react_jsx_runtime.jsx)("input", {
888
+ className: ModelsSection_module_css_default["input"],
889
+ type: "text",
890
+ value: textOf(model, "id"),
891
+ placeholder: t("modelId"),
892
+ "aria-label": `${t("modelId")} ${index + 1}`,
893
+ disabled,
894
+ onChange: (event) => {
895
+ patch(index, { id: event.target.value });
896
+ }
897
+ }),
898
+ (0, react_jsx_runtime.jsx)("input", {
899
+ className: ModelsSection_module_css_default["input"],
900
+ type: "text",
901
+ value: textOf(model, "name"),
902
+ placeholder: t("modelName"),
903
+ "aria-label": `${t("modelName")} ${index + 1}`,
904
+ disabled,
905
+ onChange: (event) => {
906
+ patch(index, { name: event.target.value === "" ? void 0 : event.target.value });
907
+ }
908
+ }),
909
+ (0, react_jsx_runtime.jsx)("button", {
910
+ type: "button",
911
+ className: ModelsSection_module_css_default["iconButton"],
912
+ "aria-label": `${t("modelAdvanced")} ${index + 1}`,
913
+ "aria-expanded": expanded.has(index),
914
+ title: t("modelAdvanced"),
915
+ onClick: () => {
916
+ toggleExpanded(index);
917
+ },
918
+ children: (0, react_jsx_runtime.jsx)(IconChevron, { open: expanded.has(index) })
919
+ }),
920
+ (0, react_jsx_runtime.jsx)("button", {
921
+ type: "button",
922
+ className: `${ModelsSection_module_css_default["iconButton"]} ${ModelsSection_module_css_default["iconButtonDanger"]}`,
923
+ "aria-label": `${t("removeModel")} ${index + 1}`,
924
+ title: t("removeModel"),
925
+ disabled,
926
+ onClick: () => {
927
+ onChange(models.filter((_model, at) => at !== index));
928
+ setExpanded((current) => {
929
+ const next = /* @__PURE__ */ new Set();
930
+ for (const at of current) if (at < index) next.add(at);
931
+ else if (at > index) next.add(at - 1);
932
+ return next;
933
+ });
934
+ setEditing((current) => reindexOnRemove(current, index));
935
+ },
936
+ children: (0, react_jsx_runtime.jsx)(IconTrash, {})
937
+ })
938
+ ]
939
+ }), expanded.has(index) ? (0, react_jsx_runtime.jsxs)("div", {
940
+ className: ModelsSection_module_css_default["modelAdvanced"],
941
+ children: [(0, react_jsx_runtime.jsxs)("label", {
942
+ className: ModelsSection_module_css_default["modelField"],
943
+ children: [(0, react_jsx_runtime.jsx)("span", {
944
+ className: ModelsSection_module_css_default["modelFieldLabel"],
945
+ children: t("modelContextWindow")
946
+ }), (0, react_jsx_runtime.jsx)("input", {
947
+ className: ModelsSection_module_css_default["input"],
948
+ type: "text",
949
+ inputMode: "numeric",
950
+ value: capacityText(model, index, "contextWindow"),
951
+ placeholder: CAPACITY_HINT.contextWindow,
952
+ "aria-label": `${t("modelContextWindow")} ${index + 1}`,
953
+ disabled,
954
+ onChange: (event) => {
955
+ editCapacity(index, "contextWindow", event.target.value);
956
+ }
957
+ })]
958
+ }), (0, react_jsx_runtime.jsxs)("label", {
959
+ className: ModelsSection_module_css_default["modelField"],
960
+ children: [(0, react_jsx_runtime.jsx)("span", {
961
+ className: ModelsSection_module_css_default["modelFieldLabel"],
962
+ children: t("modelMaxTokens")
963
+ }), (0, react_jsx_runtime.jsx)("input", {
964
+ className: ModelsSection_module_css_default["input"],
965
+ type: "text",
966
+ inputMode: "numeric",
967
+ value: capacityText(model, index, "maxTokens"),
968
+ placeholder: CAPACITY_HINT.maxTokens,
969
+ "aria-label": `${t("modelMaxTokens")} ${index + 1}`,
970
+ disabled,
971
+ onChange: (event) => {
972
+ editCapacity(index, "maxTokens", event.target.value);
973
+ }
974
+ })]
975
+ }), props.thinkingPresets ? (0, react_jsx_runtime.jsxs)("label", {
976
+ className: ModelsSection_module_css_default["modelField"],
977
+ children: [(0, react_jsx_runtime.jsx)("span", {
978
+ className: ModelsSection_module_css_default["modelFieldLabel"],
979
+ children: t("thinkingPreset")
980
+ }), (0, react_jsx_runtime.jsxs)("select", {
981
+ className: `${ModelsSection_module_css_default["input"]} ${ModelsSection_module_css_default["selectInput"]}`,
982
+ value: thinkingPresetOf(model),
983
+ "aria-label": `${t("thinkingPreset")} ${index + 1}`,
984
+ disabled,
985
+ onChange: (event) => {
986
+ patch(index, { reasoningEfforts: reasoningEffortsForPreset(event.target.value) });
987
+ },
988
+ children: [(0, react_jsx_runtime.jsx)("option", { value: "toggle", children: t("thinkingPresetToggle") }), (0, react_jsx_runtime.jsx)("option", { value: "four", children: t("thinkingPresetFour") }), (0, react_jsx_runtime.jsx)("option", { value: "five", children: t("thinkingPresetFive") })]
989
+ })]
990
+ }) : null]
991
+ }) : null]
992
+ }, index)),
993
+ (0, react_jsx_runtime.jsx)("button", {
994
+ type: "button",
995
+ className: ModelsSection_module_css_default["addModelButton"],
996
+ disabled,
997
+ onClick: () => {
998
+ onChange([...models, props.thinkingPresets ? withDefaultClaudeReasoning({ id: "" }) : { id: "" }]);
999
+ },
1000
+ children: t("addModel")
1001
+ }),
1002
+ failure !== void 0 ? (0, react_jsx_runtime.jsx)("p", {
1003
+ className: ModelsSection_module_css_default["error"],
1004
+ children: failure
1005
+ }) : null,
1006
+ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
1007
+ open: candidates !== void 0,
1008
+ onClose: closePicker,
1009
+ title: t("fetchTitle"),
1010
+ closeLabel: t("close"),
1011
+ description: t("fetchDescription"),
1012
+ className: ModelsSection_module_css_default["fetchDialog"],
1013
+ footer: (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1014
+ variant: "outline",
1015
+ onClick: closePicker,
1016
+ children: t("cancel")
1017
+ }), (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1018
+ variant: "outline",
1019
+ onClick: adoptPicked,
1020
+ children: t("fetchAdopt")
1021
+ })] }),
1022
+ children: (0, react_jsx_runtime.jsx)("ul", {
1023
+ className: ModelsSection_module_css_default["candidateList"],
1024
+ children: (candidates ?? []).map((candidate) => (0, react_jsx_runtime.jsx)("li", {
1025
+ className: ModelsSection_module_css_default["candidate"],
1026
+ children: (0, react_jsx_runtime.jsxs)("label", {
1027
+ className: ModelsSection_module_css_default["candidateLabel"],
1028
+ children: [(0, react_jsx_runtime.jsx)("input", {
1029
+ type: "checkbox",
1030
+ checked: picked.has(candidate.id),
1031
+ onChange: () => {
1032
+ toggle(candidate.id);
1033
+ }
1034
+ }), (0, react_jsx_runtime.jsx)("span", {
1035
+ className: ModelsSection_module_css_default["candidateId"],
1036
+ children: candidate.id
1037
+ })]
1038
+ })
1039
+ }, candidate.id))
1040
+ })
1041
+ })
1042
+ ]
1043
+ });
1044
+ }
1045
+ //#endregion
1046
+ //#region lib/types/client/CustomProviderCard.js
1047
+ /**
1048
+ * The card that declares a provider pi-ai does not ship — an OpenAI-compatible
1049
+ * gateway, a self-hosted server, or a provider newer than the installed
1050
+ * catalog.
1051
+ *
1052
+ * This is a create, not an edit, which is why it is its own card rather than
1053
+ * the provider editor with extra fields: the route id is being *chosen* here,
1054
+ * and the settings address does not exist until it is. One `settings.mutate`
1055
+ * sets the whole profile at `providers.<route>`; the key travels separately
1056
+ * through `credentials.set` under the reference the profile records, exactly as
1057
+ * an existing provider's key does.
1058
+ *
1059
+ * The three fields a hand-declared route cannot default — endpoint, protocol,
1060
+ * and at least one model — are required here rather than at load, so the
1061
+ * failure names the field while the user is still looking at it.
1062
+ *
1063
+ * There is deliberately no reasoning-effort control, here or on the editor
1064
+ * card: effort is a per-MODEL capability, and the models under one provider
1065
+ * disagree about it, so a provider-scoped control can only be set to a value
1066
+ * some of them reject. The composer's model picker offers each model its own
1067
+ * levels instead.
1068
+ */
1069
+ /** The settings namespace a hand-declared provider is written into. */
1070
+ const NS$1 = "llm-pi-ai";
1071
+ /**
1072
+ * A route id usable as a settings key AND as the stem of a credential name.
1073
+ * The leading letter is the second half of that: `deriveKeyRef` uppercases the
1074
+ * id and replaces every non-alphanumeric run with `_`, and a credential
1075
+ * reference is a POSIX shell identifier, which cannot start with a digit. A
1076
+ * digit-leading id passes every check this card makes and then fails at the
1077
+ * credential seam with a raw regular expression the user cannot act on.
1078
+ */
1079
+ const ROUTE_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
1080
+ /**
1081
+ * Render the custom-provider creation card.
1082
+ * @param props - existing routes, protocol choices, wire faces, and copy.
1083
+ * @returns the creation card.
1084
+ */
1085
+ function CustomProviderCard(props) {
1086
+ const { taken, protocols, api, t } = props;
1087
+ const [openedAt] = (0, react.useState)(() => props.revision);
1088
+ const [route, setRoute] = (0, react.useState)("");
1089
+ const [displayName, setDisplayName] = (0, react.useState)("");
1090
+ const [baseURL, setBaseURL] = (0, react.useState)("");
1091
+ const [providerType, setProviderType] = (0, react.useState)("generic");
1092
+ const isAdaptiveClaude = providerType === "claude-adaptive";
1093
+ const [protocol, setProtocol] = (0, react.useState)(protocols[0] ?? "");
1094
+ const [keyDraft, setKeyDraft] = (0, react.useState)("");
1095
+ const [models, setModels] = (0, react.useState)([]);
1096
+ const [busy, setBusy] = (0, react.useState)(false);
1097
+ const [failure, setFailure] = (0, react.useState)(void 0);
1098
+ /**
1099
+ * The profile write landed. Only the key write can still be outstanding, so
1100
+ * the fields that describe the provider are settled and the retry path is
1101
+ * the credential alone.
1102
+ */
1103
+ const [committed, setCommitted] = (0, react.useState)(false);
1104
+ const disabled = props.readOnly || busy;
1105
+ /** Everything but the key stops being editable once the provider exists. */
1106
+ const profileDisabled = disabled || committed;
1107
+ const routeInvalid = route.length > 0 && !ROUTE_PATTERN.test(route);
1108
+ const routeTaken = taken.includes(route);
1109
+ const modelFailure = validateDeepSeekModels(models);
1110
+ const keyFailure = apiKeyFailure(keyDraft);
1111
+ const keyValue = keyDraft.trim();
1112
+ const ready = route.length > 0 && !routeInvalid && !routeTaken && baseURL.length > 0 && models.length > 0 && modelFailure === void 0 && keyFailure === void 0;
1113
+ const hint = failure !== void 0 || ready || keyFailure !== void 0 || route.length === 0 || routeInvalid || routeTaken ? void 0 : baseURL.length === 0 ? t("customNeedsBaseUrl") : modelFailure !== void 0 ? `${t("model")} ${String(modelFailure.index + 1)}: ${t(modelFailure.key)}` : t("customNeedsModels");
1114
+ /** Perform the create, returning a failure message or undefined. */
1115
+ const createOnce = async () => {
1116
+ const keyRef = deriveKeyRef(route);
1117
+ const storesKey = keyValue.length > 0;
1118
+ if (!committed) {
1119
+ const profile = {
1120
+ ...displayName.length === 0 ? {} : { displayName },
1121
+ ...storesKey ? { apiKeyEnv: keyRef } : {},
1122
+ api: isAdaptiveClaude ? "anthropic-messages" : protocol,
1123
+ baseURL,
1124
+ models: models.map((model) => isAdaptiveClaude ? withDefaultClaudeReasoning(model) : { ...model }),
1125
+ ...isAdaptiveClaude ? { reasoning: "high" } : {}
1126
+ };
1127
+ const response = await api.settings.mutate({
1128
+ ns: NS$1,
1129
+ ops: [{
1130
+ op: "set",
1131
+ path: ["providers", route],
1132
+ value: profile
1133
+ }],
1134
+ expectedRevision: openedAt
1135
+ });
1136
+ if (!response.result.ok) return response.result.error.message;
1137
+ setCommitted(true);
1138
+ }
1139
+ if (storesKey) {
1140
+ const stored = await api.credentials.set({
1141
+ ref: keyRef,
1142
+ value: keyValue
1143
+ });
1144
+ if (!stored.result.ok) return stored.result.error.message;
1145
+ }
1146
+ };
1147
+ const create = async () => {
1148
+ setBusy(true);
1149
+ setFailure(void 0);
1150
+ try {
1151
+ const outcome = await createOnce();
1152
+ if (outcome !== void 0) {
1153
+ setFailure(outcome);
1154
+ return;
1155
+ }
1156
+ props.onClose(true);
1157
+ } catch (error) {
1158
+ setFailure(messageOf$1(error));
1159
+ } finally {
1160
+ setBusy(false);
1161
+ }
1162
+ };
1163
+ return (0, react_jsx_runtime.jsxs)("div", {
1164
+ className: ModelsSection_module_css_default["editor"],
1165
+ children: [
1166
+ (0, react_jsx_runtime.jsx)("div", {
1167
+ className: ModelsSection_module_css_default["editorHeader"],
1168
+ children: (0, react_jsx_runtime.jsx)("span", {
1169
+ className: ModelsSection_module_css_default["editorTitle"],
1170
+ children: t("customTitle")
1171
+ })
1172
+ }),
1173
+ (0, react_jsx_runtime.jsxs)("div", {
1174
+ className: ModelsSection_module_css_default["field"],
1175
+ children: [(0, react_jsx_runtime.jsx)("span", {
1176
+ className: ModelsSection_module_css_default["fieldLabel"],
1177
+ children: t("customProviderType")
1178
+ }), (0, react_jsx_runtime.jsxs)("select", {
1179
+ className: `${ModelsSection_module_css_default["input"]} ${ModelsSection_module_css_default["selectInput"]}`,
1180
+ value: providerType,
1181
+ "aria-label": t("customProviderType"),
1182
+ disabled: profileDisabled,
1183
+ onChange: (event) => {
1184
+ const nextType = event.target.value;
1185
+ setProviderType(nextType);
1186
+ if (nextType === "claude-adaptive") {
1187
+ setProtocol("anthropic-messages");
1188
+ setModels((current) => current.map(withDefaultClaudeReasoning));
1189
+ }
1190
+ },
1191
+ children: [(0, react_jsx_runtime.jsx)("option", { value: "generic", children: t("customProviderTypeGeneric") }), (0, react_jsx_runtime.jsx)("option", { value: "claude-adaptive", children: t("customProviderTypeClaude") })]
1192
+ })]
1193
+ }),
1194
+ isAdaptiveClaude ? (0, react_jsx_runtime.jsxs)("p", {
1195
+ className: ModelsSection_module_css_default["savedNotice"],
1196
+ role: "status",
1197
+ children: [t("adaptiveClaudeEnabled"), " ", (0, react_jsx_runtime.jsx)(ClaudeThinkingHelp, { t })]
1198
+ }) : null,
1199
+ (0, react_jsx_runtime.jsxs)("div", {
1200
+ className: ModelsSection_module_css_default["field"],
1201
+ children: [(0, react_jsx_runtime.jsx)("span", {
1202
+ className: ModelsSection_module_css_default["fieldLabel"],
1203
+ children: t("customRoute")
1204
+ }), (0, react_jsx_runtime.jsx)("input", {
1205
+ className: ModelsSection_module_css_default["input"],
1206
+ type: "text",
1207
+ value: route,
1208
+ placeholder: "acme-gateway",
1209
+ "aria-label": t("customRoute"),
1210
+ disabled: profileDisabled,
1211
+ onChange: (event) => {
1212
+ setRoute(event.target.value);
1213
+ }
1214
+ })]
1215
+ }),
1216
+ routeInvalid || routeTaken ? (0, react_jsx_runtime.jsx)("p", {
1217
+ className: ModelsSection_module_css_default["error"],
1218
+ children: t(routeInvalid ? "customRouteInvalid" : "customRouteTaken")
1219
+ }) : (0, react_jsx_runtime.jsx)("p", {
1220
+ className: ModelsSection_module_css_default["advancedHint"],
1221
+ children: t("customRouteHint")
1222
+ }),
1223
+ (0, react_jsx_runtime.jsxs)("div", {
1224
+ className: ModelsSection_module_css_default["field"],
1225
+ children: [(0, react_jsx_runtime.jsx)("span", {
1226
+ className: ModelsSection_module_css_default["fieldLabel"],
1227
+ children: t("customDisplayName")
1228
+ }), (0, react_jsx_runtime.jsx)("input", {
1229
+ className: ModelsSection_module_css_default["input"],
1230
+ type: "text",
1231
+ value: displayName,
1232
+ placeholder: route.length === 0 ? t("customDisplayName") : route,
1233
+ "aria-label": t("customDisplayName"),
1234
+ disabled: profileDisabled,
1235
+ onChange: (event) => {
1236
+ setDisplayName(event.target.value);
1237
+ }
1238
+ })]
1239
+ }),
1240
+ (0, react_jsx_runtime.jsxs)("div", {
1241
+ className: ModelsSection_module_css_default["field"],
1242
+ children: [(0, react_jsx_runtime.jsx)("span", {
1243
+ className: ModelsSection_module_css_default["fieldLabel"],
1244
+ children: t("baseUrl")
1245
+ }), (0, react_jsx_runtime.jsx)("input", {
1246
+ className: ModelsSection_module_css_default["input"],
1247
+ type: "text",
1248
+ value: baseURL,
1249
+ placeholder: "https://gateway.example/v1",
1250
+ "aria-label": t("baseUrl"),
1251
+ disabled: profileDisabled,
1252
+ onChange: (event) => {
1253
+ setBaseURL(event.target.value);
1254
+ }
1255
+ })]
1256
+ }),
1257
+ (0, react_jsx_runtime.jsxs)("div", {
1258
+ className: ModelsSection_module_css_default["field"],
1259
+ children: [(0, react_jsx_runtime.jsx)("span", {
1260
+ className: ModelsSection_module_css_default["fieldLabel"],
1261
+ children: t("customApi")
1262
+ }), (0, react_jsx_runtime.jsx)("select", {
1263
+ className: `${ModelsSection_module_css_default["input"]} ${ModelsSection_module_css_default["selectInput"]}`,
1264
+ value: protocol,
1265
+ "aria-label": t("customApi"),
1266
+ disabled: profileDisabled || isAdaptiveClaude,
1267
+ onChange: (event) => {
1268
+ setProtocol(event.target.value);
1269
+ },
1270
+ children: protocols.map((choice) => (0, react_jsx_runtime.jsx)("option", {
1271
+ value: choice,
1272
+ children: choice
1273
+ }, choice))
1274
+ })]
1275
+ }),
1276
+ (0, react_jsx_runtime.jsxs)("div", {
1277
+ className: ModelsSection_module_css_default["field"],
1278
+ children: [
1279
+ (0, react_jsx_runtime.jsx)("span", {
1280
+ className: ModelsSection_module_css_default["fieldLabel"],
1281
+ children: t("keyInput")
1282
+ }),
1283
+ (0, react_jsx_runtime.jsx)("input", {
1284
+ className: ModelsSection_module_css_default["input"],
1285
+ type: "password",
1286
+ autoComplete: "off",
1287
+ value: keyDraft,
1288
+ placeholder: t("keyPlaceholder"),
1289
+ "aria-label": t("keyInput"),
1290
+ disabled,
1291
+ onChange: (event) => {
1292
+ setKeyDraft(event.target.value);
1293
+ }
1294
+ }),
1295
+ keyFailure === void 0 ? null : (0, react_jsx_runtime.jsx)("p", {
1296
+ className: ModelsSection_module_css_default["error"],
1297
+ children: t(keyFailure === "keyBlank" ? "keyBlankNew" : keyFailure)
1298
+ })
1299
+ ]
1300
+ }),
1301
+ (0, react_jsx_runtime.jsx)(ModelListEditor, {
1302
+ models,
1303
+ onChange: setModels,
1304
+ probe: {
1305
+ settingsNs: NS$1,
1306
+ baseURL,
1307
+ api: protocol,
1308
+ ...keyValue.length === 0 ? {} : { apiKey: keyValue }
1309
+ },
1310
+ probeBlocked: keyFailure === "keyBlank" ? "keyBlankNew" : keyFailure,
1311
+ thinkingPresets: isAdaptiveClaude,
1312
+ api,
1313
+ t,
1314
+ disabled: profileDisabled
1315
+ }),
1316
+ failure !== void 0 ? (0, react_jsx_runtime.jsx)("p", {
1317
+ className: ModelsSection_module_css_default["error"],
1318
+ children: failure
1319
+ }) : null,
1320
+ hint === void 0 ? null : (0, react_jsx_runtime.jsx)("p", {
1321
+ className: ModelsSection_module_css_default["advancedHint"],
1322
+ children: hint
1323
+ }),
1324
+ (0, react_jsx_runtime.jsx)(EditorFooter, {
1325
+ t,
1326
+ busy,
1327
+ submitDisabled: disabled || !ready,
1328
+ submitLabel: "create",
1329
+ submitBusyLabel: "creating",
1330
+ onCancel: () => {
1331
+ props.onClose(committed);
1332
+ },
1333
+ onSubmit: () => {
1334
+ create();
1335
+ }
1336
+ })
1337
+ ]
1338
+ });
1339
+ }
1340
+ //#endregion
1341
+ //#region lib/types/client/ProviderEditor.js
1342
+ /**
1343
+ * One provider's editor card, hand-written per adapter family: the primary
1344
+ * field is a single write-only **API key** input (the page never asks for an
1345
+ * environment-variable name — a typed key stores through `credentials.set`
1346
+ * under the profile's reference, deriving `<ROUTE>_API_KEY` when the profile
1347
+ * has none. The pi-ai profile records that derivation as `apiKeyEnv` only when
1348
+ * a key is entered; a blank key materializes a reference-free profile for
1349
+ * provider-native authentication);
1350
+ * the collapsed 自定义设置 area carries the per-family extras (`baseURL` for
1351
+ * both families, DeepSeek's id/name/context-window model catalog, and the
1352
+ * display name and wire protocol of a pi-ai route the adapter does not ship —
1353
+ * the two fields the create card asked that route for, editable here for the
1354
+ * same reason).
1355
+ * Reasoning effort is deliberately absent: it is a per-MODEL capability, and
1356
+ * the models under one provider disagree about it, so a provider-scoped
1357
+ * control can only be set to a value some of them reject. The composer's
1358
+ * model picker offers each model its own levels; `settings.yaml` keeps the
1359
+ * profile field for a deployment that knows its route. Everything else stays
1360
+ * owned by `settings.yaml`. Profile edits land as minimal `settings.mutate`
1361
+ * path ops against the stored section — the card names only the fields it can
1362
+ * see instead of rebuilding the whole subtree from a partial descriptor.
1363
+ */
1364
+ /** The public DeepSeek endpoint shown as the deepseek base-URL placeholder. */
1365
+ const DEEPSEEK_PUBLIC_BASE_URL = "https://api.deepseek.com";
1366
+ /** A user-section subtree as a plain draft object (absent → empty). */
1367
+ function draftAt(namespace, path) {
1368
+ const subtree = (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.user, path);
1369
+ if (typeof subtree !== "object" || subtree === null || Array.isArray(subtree)) return {};
1370
+ return structuredClone(subtree);
1371
+ }
1372
+ /**
1373
+ * The minimal path ops carrying `after` over `before`, both as the card sees
1374
+ * them. Only keys the card observed are named; fields absent from both sides
1375
+ * produce no op, which is why edits are path-addressed rather than a rebuilt
1376
+ * section.
1377
+ * @param base - path of the edited subtree inside the user section.
1378
+ * @param before - the subtree as loaded, or undefined when it is new.
1379
+ * @param after - the subtree as edited.
1380
+ * @returns ordered set/unset ops; empty when nothing changed.
1381
+ */
1382
+ function pathOps(base, before, after) {
1383
+ const previous = typeof before === "object" && before !== null && !Array.isArray(before) ? before : {};
1384
+ const ops = [];
1385
+ for (const [key, value] of Object.entries(after)) {
1386
+ if (JSON.stringify(previous[key]) === JSON.stringify(value)) continue;
1387
+ ops.push({
1388
+ op: "set",
1389
+ path: [...base, key],
1390
+ value
1391
+ });
1392
+ }
1393
+ for (const key of Object.keys(previous)) if (!(key in after)) ops.push({
1394
+ op: "unset",
1395
+ path: [...base, key]
1396
+ });
1397
+ return ops;
1398
+ }
1399
+ /** The editor layout the owning namespace selects. */
1400
+ function layoutOf(ns) {
1401
+ if (ns === "llm-deepseek") return "deepseek";
1402
+ if (ns === "llm-pi-ai") return "pi-ai";
1403
+ return "unknown";
1404
+ }
1405
+ /** The credential reference this profile resolves keys through. */
1406
+ function refFor(namespace, path, provider) {
1407
+ const profile = (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.value, path);
1408
+ const named = typeof profile === "object" && profile !== null ? profile.apiKeyEnv : void 0;
1409
+ return typeof named === "string" && named.length > 0 ? named : deriveKeyRef(provider);
1410
+ }
1411
+ /**
1412
+ * Render one provider's editing card.
1413
+ * @param props - the addressed profile plus wire faces and copy.
1414
+ * @returns the editor card.
1415
+ */
1416
+ function ProviderEditor(props) {
1417
+ const { namespace, settingsPath, api, t } = props;
1418
+ const [draft, setDraft] = (0, react.useState)(() => draftAt(namespace, settingsPath));
1419
+ const [keyDraft, setKeyDraft] = (0, react.useState)("");
1420
+ const [keyState, setKeyState] = (0, react.useState)(void 0);
1421
+ const [busy, setBusy] = (0, react.useState)(false);
1422
+ const [failure, setFailure] = (0, react.useState)(void 0);
1423
+ const [committedOriginal, setCommittedOriginal] = (0, react.useState)(() => (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.user, settingsPath));
1424
+ const [expectedRevision, setExpectedRevision] = (0, react.useState)(() => namespace.revision);
1425
+ const root = (0, react.useMemo)(() => (0, _deepseek_ai_dsh_client_schema_form.rehydrateSchema)(namespace.schema), [namespace.schema]);
1426
+ const node = (0, react.useMemo)(() => (0, _deepseek_ai_dsh_client_schema_form.nodeAtPath)(root, settingsPath), [root, settingsPath]);
1427
+ const fallback = (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.value, settingsPath);
1428
+ const disabled = props.readOnly || busy;
1429
+ const layout = layoutOf(namespace.ns);
1430
+ const keyRef = refFor(namespace, settingsPath, props.provider);
1431
+ const protocols = (0, react.useMemo)(() => layout === "pi-ai" ? protocolChoices(namespace) : [], [layout, namespace]);
1432
+ (0, react.useEffect)(() => {
1433
+ let stale = false;
1434
+ setKeyState(void 0);
1435
+ api.credentials.describe({ refs: [keyRef] }).then((response) => {
1436
+ if (stale || !response.result.ok) return;
1437
+ setKeyState(response.result.value.credentials[keyRef]);
1438
+ }, () => void 0);
1439
+ return () => {
1440
+ stale = true;
1441
+ };
1442
+ }, [api.credentials, keyRef]);
1443
+ const stringAt = (source, key) => {
1444
+ const value = (0, _deepseek_ai_dsh_client_schema_form.getPath)(source, [key]);
1445
+ return typeof value === "string" && value.trim().length > 0 ? value : void 0;
1446
+ };
1447
+ const setField = (key, next) => {
1448
+ const value = next === void 0 || next.trim().length === 0 ? void 0 : next;
1449
+ setDraft((current) => value === void 0 ? (0, _deepseek_ai_dsh_client_schema_form.deletePath)(current, [key]) : (0, _deepseek_ai_dsh_client_schema_form.setPath)(current, [key], value));
1450
+ };
1451
+ const modelFailure = validateDeepSeekModels((0, _deepseek_ai_dsh_client_schema_form.getPath)(draft, ["models"]));
1452
+ const keyFailure = apiKeyFailure(keyDraft);
1453
+ const keyValue = keyDraft.trim();
1454
+ const shownKeyFailure = (props.credentialRequired === true && keyDraft.length > 0 && keyValue.length === 0 ? "keyRequired" : void 0) ?? keyFailure;
1455
+ const probeApi = stringAt(draft, "api") ?? stringAt(fallback, "api");
1456
+ const probeBaseURL = stringAt(draft, "baseURL") ?? stringAt(fallback, "baseURL");
1457
+ const probe = {
1458
+ settingsNs: namespace.ns,
1459
+ provider: props.provider,
1460
+ ...probeBaseURL === void 0 ? {} : { baseURL: probeBaseURL },
1461
+ ...probeApi === void 0 ? {} : { api: probeApi },
1462
+ ...keyValue.length === 0 ? {} : { apiKey: keyValue }
1463
+ };
1464
+ /**
1465
+ * The write for this card, or a failure message. Every edit travels as
1466
+ * path ops against the STORED section: the draft comes from the redacted
1467
+ * descriptor, so a wholesale replace rebuilt from it could delete fields
1468
+ * outside the card. Ops name only the fields this card can see.
1469
+ */
1470
+ const applyOnce = async () => {
1471
+ const ns = namespace.ns;
1472
+ const next = layout === "pi-ai" && stringAt(draft, "apiKeyEnv") === void 0 && stringAt(fallback, "apiKeyEnv") === void 0 && keyValue.length > 0 ? (0, _deepseek_ai_dsh_client_schema_form.setPath)(draft, ["apiKeyEnv"], keyRef) : draft;
1473
+ if (props.credentialOnly !== true) {
1474
+ const failure = validateDeepSeekModels((0, _deepseek_ai_dsh_client_schema_form.getPath)(next, ["models"]));
1475
+ /* v8 ignore next 3 -- unreachable from the card: the same failure disables submit */
1476
+ if (failure !== void 0) return `${t("model")} ${String(failure.index + 1)}: ${t(failure.key)}`;
1477
+ }
1478
+ /* v8 ignore next -- apply is only reachable from the rendered card, which required a resolved node */
1479
+ if (props.credentialOnly !== true && node !== void 0 && settingsPath.length === 0) {
1480
+ const sectionError = (0, _deepseek_ai_dsh_client_schema_form.validateDraft)(node, next);
1481
+ if (sectionError !== void 0) return sectionError;
1482
+ }
1483
+ const materializesNativeProfile = layout === "pi-ai" && fallback === void 0 && committedOriginal === void 0 && Object.keys(next).length === 0;
1484
+ const ops = props.credentialOnly === true ? [] : materializesNativeProfile ? [{
1485
+ op: "set",
1486
+ path: [...settingsPath],
1487
+ value: {}
1488
+ }] : pathOps(settingsPath, committedOriginal, next);
1489
+ if (ops.length > 0) {
1490
+ const response = await api.settings.mutate({
1491
+ ns,
1492
+ ops,
1493
+ expectedRevision
1494
+ });
1495
+ if (!response.result.ok) return response.result.error.code === "settings-conflict" ? t("conflict") : response.result.error.message;
1496
+ setCommittedOriginal((0, _deepseek_ai_dsh_client_schema_form.getPath)(response.result.value.user, settingsPath));
1497
+ setExpectedRevision(response.result.value.revision);
1498
+ setDraft(next);
1499
+ }
1500
+ if (keyValue.length > 0) {
1501
+ const stored = await api.credentials.set({
1502
+ ref: keyRef,
1503
+ value: keyValue
1504
+ });
1505
+ if (!stored.result.ok) return stored.result.error.message;
1506
+ }
1507
+ setKeyDraft("");
1508
+ };
1509
+ const apply = async () => {
1510
+ setBusy(true);
1511
+ setFailure(void 0);
1512
+ try {
1513
+ const failure = await applyOnce();
1514
+ if (failure !== void 0) {
1515
+ setFailure(failure);
1516
+ return;
1517
+ }
1518
+ props.onClose(true);
1519
+ } catch (error) {
1520
+ setFailure(messageOf$1(error));
1521
+ } finally {
1522
+ setBusy(false);
1523
+ }
1524
+ };
1525
+ if (node === void 0) return (0, react_jsx_runtime.jsx)("p", {
1526
+ className: ModelsSection_module_css_default["error"],
1527
+ children: `${props.provider}: unresolvable settings path`
1528
+ });
1529
+ const keyLocked = keyState?.writable === false;
1530
+ /**
1531
+ * The catalog beneath the user layer: what the composition entry pinned, or
1532
+ * else the schema default that `resolve` would supply. The effective value
1533
+ * cannot answer this — it still carries the stored override until the unset
1534
+ * is applied, so reading it would echo that override straight back the
1535
+ * moment reset drops it, leaving the rows unchanged until a reload.
1536
+ */
1537
+ const inheritedModels = () => {
1538
+ return (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.base, [...settingsPath, "models"]) ?? (0, _deepseek_ai_dsh_client_schema_form.nodeAtPath)(root, [...settingsPath, "models"])?.meta.default;
1539
+ };
1540
+ /**
1541
+ * The curated fields of one known adapter family. The family arrives
1542
+ * narrowed so the per-family branches below are total: an unknown namespace
1543
+ * renders the hint instead and never reaches this body.
1544
+ */
1545
+ const curatedFields = (family) => {
1546
+ const ownsIdentity = family === "pi-ai" && props.declared === true;
1547
+ const customModels = (0, _deepseek_ai_dsh_client_schema_form.getPath)(draft, ["models"]);
1548
+ const modelsOverridden = (0, _deepseek_ai_dsh_client_schema_form.hasPath)(draft, ["models"]);
1549
+ const models = modelDrafts(modelsOverridden ? customModels : inheritedModels());
1550
+ const defaultContextWindow = (0, _deepseek_ai_dsh_client_schema_form.getPath)(fallback, ["defaultContextWindow"]);
1551
+ const defaultMaxTokens = (0, _deepseek_ai_dsh_client_schema_form.getPath)(fallback, ["maxTokens"]);
1552
+ const keyPlaceholder = keyLocked ? t("keyEnvLocked") : keyState?.configured === true && props.credentialRequired !== true ? t("keyStored") : family === "pi-ai" ? t("keyPlaceholderNative") : t("keyPlaceholder");
1553
+ /** What both family editors take: the rows, whose layer owns them, and the two writes. */
1554
+ const catalogProps = {
1555
+ models,
1556
+ overridden: modelsOverridden,
1557
+ t,
1558
+ disabled,
1559
+ onChange: (next) => {
1560
+ setDraft((current) => (0, _deepseek_ai_dsh_client_schema_form.setPath)(current, ["models"], next));
1561
+ },
1562
+ onReset: () => {
1563
+ setDraft((current) => (0, _deepseek_ai_dsh_client_schema_form.deletePath)(current, ["models"]));
1564
+ }
1565
+ };
1566
+ return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsxs)("div", {
1567
+ className: ModelsSection_module_css_default["field"],
1568
+ children: [
1569
+ (0, react_jsx_runtime.jsx)("span", {
1570
+ className: ModelsSection_module_css_default["fieldLabel"],
1571
+ children: t("keyInput")
1572
+ }),
1573
+ (0, react_jsx_runtime.jsx)("input", {
1574
+ className: ModelsSection_module_css_default["input"],
1575
+ type: "password",
1576
+ autoComplete: "off",
1577
+ value: keyDraft,
1578
+ placeholder: keyPlaceholder,
1579
+ "aria-label": t("keyInput"),
1580
+ "aria-invalid": shownKeyFailure !== void 0,
1581
+ required: props.credentialRequired === true,
1582
+ autoFocus: props.autoFocusCredential === true,
1583
+ disabled: disabled || keyLocked,
1584
+ onChange: (event) => {
1585
+ setKeyDraft(event.target.value);
1586
+ }
1587
+ }),
1588
+ shownKeyFailure === void 0 ? null : (0, react_jsx_runtime.jsx)("p", {
1589
+ className: ModelsSection_module_css_default["error"],
1590
+ children: t(shownKeyFailure)
1591
+ })
1592
+ ]
1593
+ }), props.credentialOnly === true ? null : (0, react_jsx_runtime.jsxs)("details", {
1594
+ className: ModelsSection_module_css_default["customized"],
1595
+ children: [(0, react_jsx_runtime.jsx)("summary", {
1596
+ className: ModelsSection_module_css_default["customizedSummary"],
1597
+ children: t("customized")
1598
+ }), (0, react_jsx_runtime.jsxs)("div", {
1599
+ className: ModelsSection_module_css_default["customizedBody"],
1600
+ children: [
1601
+ ownsIdentity ? (0, react_jsx_runtime.jsxs)("div", {
1602
+ className: ModelsSection_module_css_default["field"],
1603
+ children: [(0, react_jsx_runtime.jsx)("span", {
1604
+ className: ModelsSection_module_css_default["fieldLabel"],
1605
+ children: t("customDisplayName")
1606
+ }), (0, react_jsx_runtime.jsx)("input", {
1607
+ className: ModelsSection_module_css_default["input"],
1608
+ type: "text",
1609
+ value: stringAt(draft, "displayName") ?? "",
1610
+ placeholder: stringAt((0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.base, settingsPath), "displayName") ?? props.provider,
1611
+ "aria-label": t("customDisplayName"),
1612
+ disabled,
1613
+ onChange: (event) => {
1614
+ setField("displayName", event.target.value);
1615
+ }
1616
+ })]
1617
+ }) : null,
1618
+ (0, react_jsx_runtime.jsxs)("div", {
1619
+ className: ModelsSection_module_css_default["field"],
1620
+ children: [(0, react_jsx_runtime.jsx)("span", {
1621
+ className: ModelsSection_module_css_default["fieldLabel"],
1622
+ children: t("baseUrl")
1623
+ }), (0, react_jsx_runtime.jsx)("input", {
1624
+ className: ModelsSection_module_css_default["input"],
1625
+ type: "text",
1626
+ value: stringAt(draft, "baseURL") ?? "",
1627
+ placeholder: family === "deepseek" ? DEEPSEEK_PUBLIC_BASE_URL : stringAt(fallback, "baseURL") ?? t("baseUrlDefault"),
1628
+ "aria-label": t("baseUrl"),
1629
+ disabled,
1630
+ onChange: (event) => {
1631
+ setField("baseURL", event.target.value === "" ? void 0 : event.target.value);
1632
+ }
1633
+ })]
1634
+ }),
1635
+ ownsIdentity ? (0, react_jsx_runtime.jsxs)("div", {
1636
+ className: ModelsSection_module_css_default["field"],
1637
+ children: [(0, react_jsx_runtime.jsx)("span", {
1638
+ className: ModelsSection_module_css_default["fieldLabel"],
1639
+ children: t("customApi")
1640
+ }), (0, react_jsx_runtime.jsxs)("select", {
1641
+ className: `${ModelsSection_module_css_default["input"]} ${ModelsSection_module_css_default["selectInput"]}`,
1642
+ value: probeApi ?? "",
1643
+ "aria-label": t("customApi"),
1644
+ disabled,
1645
+ onChange: (event) => {
1646
+ setField("api", event.target.value);
1647
+ },
1648
+ children: [probeApi === void 0 ? (0, react_jsx_runtime.jsx)("option", {
1649
+ value: "",
1650
+ children: t("customApiUnset")
1651
+ }) : null, protocols.map((choice) => (0, react_jsx_runtime.jsx)("option", {
1652
+ value: choice,
1653
+ children: choice
1654
+ }, choice))]
1655
+ })]
1656
+ }) : null,
1657
+ family === "deepseek" ? (0, react_jsx_runtime.jsx)(DeepSeekModelsEditor, {
1658
+ ...catalogProps,
1659
+ defaultContextWindow: typeof defaultContextWindow === "number" ? defaultContextWindow : void 0,
1660
+ defaultMaxTokens: typeof defaultMaxTokens === "number" ? defaultMaxTokens : void 0
1661
+ }) : (0, react_jsx_runtime.jsx)(ModelListEditor, {
1662
+ ...catalogProps,
1663
+ probe,
1664
+ probeBlocked: keyFailure,
1665
+ thinkingPresets: probeApi === "anthropic-messages",
1666
+ api
1667
+ })
1668
+ ]
1669
+ })]
1670
+ })] });
1671
+ };
1672
+ return (0, react_jsx_runtime.jsxs)("div", {
1673
+ className: props.credentialOnly === true ? ModelsSection_module_css_default["addBlock"] : ModelsSection_module_css_default["editor"],
1674
+ children: [
1675
+ props.hideTitle === true ? null : (0, react_jsx_runtime.jsxs)("div", {
1676
+ className: ModelsSection_module_css_default["editorHeader"],
1677
+ children: [(0, react_jsx_runtime.jsx)("span", {
1678
+ className: ModelsSection_module_css_default["editorTitle"],
1679
+ children: props.displayName
1680
+ }), props.provider !== props.displayName ? (0, react_jsx_runtime.jsx)("span", {
1681
+ className: ModelsSection_module_css_default["editorRoute"],
1682
+ children: props.provider
1683
+ }) : null]
1684
+ }),
1685
+ layout === "unknown" ? (0, react_jsx_runtime.jsx)("p", {
1686
+ className: ModelsSection_module_css_default["advancedHint"],
1687
+ children: `${t("advancedHint")} (${namespace.ns})`
1688
+ }) : curatedFields(layout),
1689
+ failure !== void 0 ? (0, react_jsx_runtime.jsx)("p", {
1690
+ className: ModelsSection_module_css_default["error"],
1691
+ children: failure
1692
+ }) : null,
1693
+ props.credentialOnly === true || modelFailure === void 0 ? null : (0, react_jsx_runtime.jsx)("p", {
1694
+ className: ModelsSection_module_css_default["advancedHint"],
1695
+ children: `${t("model")} ${String(modelFailure.index + 1)}: ${t(modelFailure.key)}`
1696
+ }),
1697
+ (0, react_jsx_runtime.jsx)(EditorFooter, {
1698
+ t,
1699
+ busy,
1700
+ submitDisabled: disabled || layout === "unknown" || props.credentialOnly !== true && modelFailure !== void 0 || shownKeyFailure !== void 0 || props.credentialRequired === true && keyValue.length === 0,
1701
+ submitLabel: props.submitLabel ?? "apply",
1702
+ submitBusyLabel: props.submitBusyLabel ?? "applying",
1703
+ ...props.cancelLabel === void 0 ? {} : { cancelLabel: props.cancelLabel },
1704
+ onCancel: () => {
1705
+ props.onClose(false);
1706
+ },
1707
+ onSubmit: () => {
1708
+ apply();
1709
+ }
1710
+ })
1711
+ ]
1712
+ });
1713
+ }
1714
+ //#endregion
1715
+ //#region lib/types/client/ModelsSection.js
1716
+ /**
1717
+ * Models settings section: the provider rows joined from the configurable
1718
+ * directory, settings namespaces, and credential states, with one editor
1719
+ * card at a time. Rows expose only confirmed API-key state through accessible
1720
+ * solid configured or missing dots. A whole-section provider without a
1721
+ * configured key renders as its open setup card instead of a row, but only in
1722
+ * the first-run posture — no provider on the page can serve requests yet — and
1723
+ * only until the user closes that card; the add flow is a card carrying the
1724
+ * dormant-provider select. Each card kind owns its own open state, so closing
1725
+ * one never discards a draft in another. Every mutation writes through the
1726
+ * wire, while a provider removal first requires confirmation; the page
1727
+ * re-renders from pushed invalidations or the post-apply reload.
1728
+ */
1729
+ /** Render an editor for either the setup posture or an expanded provider row. */
1730
+ function renderProviderEditor({ target, ...props }) {
1731
+ return (0, react_jsx_runtime.jsx)(ProviderEditor, {
1732
+ provider: target.provider,
1733
+ displayName: target.displayName,
1734
+ settingsPath: target.settingsPath,
1735
+ ...target.declared === true ? { declared: true } : {},
1736
+ ...props
1737
+ });
1738
+ }
1739
+ /**
1740
+ * Remove one user-added provider and its page-managed credential. Credential
1741
+ * removal comes first so a second-step failure leaves the provider row visible
1742
+ * and the whole operation safely retryable; both unsets are idempotent.
1743
+ * The settings removal names the profile rather than rebuilding its whole
1744
+ * namespace from a partial view.
1745
+ * @param api - settings and credential wire faces.
1746
+ * @param controller - the page store to refresh.
1747
+ * @param target - the provider's settings address and optional managed credential.
1748
+ * @returns the failure message, or undefined once the write and reload landed.
1749
+ */
1750
+ async function removeProviderProfile(api, controller, target) {
1751
+ try {
1752
+ if (target.credentialRef !== void 0) {
1753
+ const credential = await api.credentials.unset({ ref: target.credentialRef });
1754
+ if (!credential.result.ok) return credential.result.error.message;
1755
+ }
1756
+ const response = await api.settings.mutate({
1757
+ ns: target.settingsNs,
1758
+ ops: [{
1759
+ op: "unset",
1760
+ path: [...target.settingsPath]
1761
+ }]
1762
+ });
1763
+ if (!response.result.ok) return response.result.error.message;
1764
+ } catch (error) {
1765
+ return messageOf$1(error);
1766
+ }
1767
+ await controller.load();
1768
+ }
1769
+ /**
1770
+ * Whether a whole-section provider still needs its first key: an unconfigured
1771
+ * credential opens the setup card instead of showing a row. This is the
1772
+ * first-run posture alone — a user who can already reach some provider gets an
1773
+ * ordinary row with the missing-key dot, since nothing here is blocking them.
1774
+ * @param row - the joined provider row.
1775
+ * @param anyUsable - whether any joined row can already serve requests.
1776
+ * @returns whether to render the setup card.
1777
+ */
1778
+ function needsSetup(row, anyUsable) {
1779
+ if (anyUsable) return false;
1780
+ if (row.entry.settingsPath.length > 0) return false;
1781
+ return row.credential?.configured !== true;
1782
+ }
1783
+ function targetOf(row) {
1784
+ const managedRef = deriveKeyRef(row.entry.provider);
1785
+ const credentialRef = row.apiKeyEnv === managedRef && row.credential?.configured === true && row.credential.writable ? managedRef : void 0;
1786
+ return {
1787
+ provider: row.entry.provider,
1788
+ displayName: row.entry.displayName,
1789
+ settingsNs: row.entry.settingsNs,
1790
+ settingsPath: row.entry.settingsPath,
1791
+ ...credentialRef === void 0 ? {} : { credentialRef },
1792
+ ...row.entry.declared === true ? { declared: true } : {}
1793
+ };
1794
+ }
1795
+ const CLAUDE_DISCOVERY_API = "mofeng-anthropic-models";
1796
+ const CLAUDE_FIVE_EFFORTS = Object.freeze({ low: "low", medium: "medium", high: "high", xhigh: "xhigh", max: "max" });
1797
+ const CLAUDE_FOUR_EFFORTS = Object.freeze({ low: "low", medium: "medium", high: "high", max: "max" });
1798
+ const CLAUDE_TOGGLE_EFFORTS = Object.freeze({ off: null, high: "high" });
1799
+ const CLAUDE_KNOWN_MODELS = Object.freeze({
1800
+ "claude-fable-5": Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: "five" }),
1801
+ "claude-haiku-4-5-20251001": Object.freeze({ contextWindow: 200000, maxTokens: 64000, preset: "toggle" }),
1802
+ "claude-haiku-4-5": Object.freeze({ contextWindow: 200000, maxTokens: 64000, preset: "toggle" }),
1803
+ "claude-opus-4-6": Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: "four" }),
1804
+ "claude-opus-4-7": Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: "five" }),
1805
+ "claude-opus-4-8": Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: "five" }),
1806
+ "claude-opus-5": Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: "five" }),
1807
+ "claude-sonnet-4-6": Object.freeze({ contextWindow: 1000000, maxTokens: 64000, preset: "four" }),
1808
+ "claude-sonnet-5": Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: "five" })
1809
+ });
1810
+ function reasoningEffortsForPreset(preset) {
1811
+ if (preset === "toggle") return { ...CLAUDE_TOGGLE_EFFORTS };
1812
+ if (preset === "four") return { ...CLAUDE_FOUR_EFFORTS };
1813
+ return { ...CLAUDE_FIVE_EFFORTS };
1814
+ }
1815
+ function withFetchedClaudeMetadata(model) {
1816
+ const known = CLAUDE_KNOWN_MODELS[model?.id];
1817
+ if (known === undefined) return withDefaultClaudeReasoning(model);
1818
+ return { ...model, contextWindow: known.contextWindow, maxTokens: known.maxTokens, reasoningEfforts: reasoningEffortsForPreset(known.preset) };
1819
+ }
1820
+ function thinkingPresetOf(model) {
1821
+ const efforts = model?.reasoningEfforts;
1822
+ if (efforts !== null && typeof efforts === "object" && !Array.isArray(efforts)) {
1823
+ if (Object.hasOwn(efforts, "off") && !Object.hasOwn(efforts, "low")) return "toggle";
1824
+ if (Object.hasOwn(efforts, "max") && !Object.hasOwn(efforts, "xhigh")) return "four";
1825
+ }
1826
+ return "five";
1827
+ }
1828
+ function withDefaultClaudeReasoning(model) {
1829
+ const efforts = model?.reasoningEfforts;
1830
+ return efforts !== null && typeof efforts === "object" && !Array.isArray(efforts) && Object.keys(efforts).length > 0
1831
+ ? { ...model }
1832
+ : { ...model, reasoningEfforts: reasoningEffortsForPreset("five") };
1833
+ }
1834
+ function ClaudeThinkingHelp(props) {
1835
+ const anchorRef = (0, react.useRef)(null);
1836
+ const tooltipRef = (0, react.useRef)(null);
1837
+ const [open, setOpen] = (0, react.useState)(false);
1838
+ const [position, setPosition] = (0, react.useState)({ left: 12, top: 12, width: 680 });
1839
+ (0, react.useLayoutEffect)(() => {
1840
+ if (!open) return;
1841
+ const place = () => {
1842
+ const anchor = anchorRef.current;
1843
+ if (anchor === null) return;
1844
+ const rect = anchor.getBoundingClientRect();
1845
+ const width = Math.max(280, Math.min(680, window.innerWidth - 24));
1846
+ const height = tooltipRef.current?.offsetHeight ?? 120;
1847
+ const left = Math.max(12, Math.min(rect.left, window.innerWidth - width - 12));
1848
+ const below = rect.bottom + 8;
1849
+ const top = below + height <= window.innerHeight - 12 ? below : Math.max(12, rect.top - height - 8);
1850
+ setPosition({ left, top, width });
1851
+ };
1852
+ place();
1853
+ window.addEventListener("resize", place);
1854
+ window.addEventListener("scroll", place, true);
1855
+ return () => {
1856
+ window.removeEventListener("resize", place);
1857
+ window.removeEventListener("scroll", place, true);
1858
+ };
1859
+ }, [open]);
1860
+ const tooltip = open && typeof document !== "undefined" ? (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)("span", {
1861
+ ref: tooltipRef,
1862
+ className: "mofeng-thinking-tooltip",
1863
+ role: "tooltip",
1864
+ style: position,
1865
+ children: props.t("adaptiveClaudeHelp").split("\n").map((line, index) => (0, react_jsx_runtime.jsx)("span", { children: line }, index))
1866
+ }), document.body) : null;
1867
+ return (0, react_jsx_runtime.jsxs)(react.Fragment, {
1868
+ children: [(0, react_jsx_runtime.jsxs)("span", {
1869
+ ref: anchorRef,
1870
+ className: "mofeng-thinking-help",
1871
+ "aria-label": props.t("adaptiveClaudeHelpLabel"),
1872
+ tabIndex: 0,
1873
+ onMouseEnter: () => setOpen(true),
1874
+ onMouseLeave: () => setOpen(false),
1875
+ onFocus: () => setOpen(true),
1876
+ onBlur: () => setOpen(false),
1877
+ children: ["!", tooltip]
1878
+ }), (0, react_jsx_runtime.jsx)("style", {
1879
+ children: ".mofeng-thinking-help{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border:1px solid currentColor;border-radius:50%;font-size:11px;font-weight:700;line-height:1;cursor:help;vertical-align:middle}.mofeng-thinking-tooltip{position:fixed;z-index:2147483647;display:flex;flex-direction:column;gap:5px;box-sizing:border-box;padding:9px 12px;border:1px solid rgba(255,255,255,.18);border-radius:7px;background:#25282d;color:#f5f6f7;font-size:13px;font-weight:400;line-height:1.45;text-align:left;box-shadow:0 6px 20px rgba(0,0,0,.26);pointer-events:none}.mofeng-thinking-tooltip>span{display:block;white-space:normal;overflow-wrap:anywhere}"
1880
+ })]
1881
+ });
1882
+ }
1883
+ function isClaudeProvider(row, state) {
1884
+ if (row.entry.settingsNs !== "llm-pi-ai") return false;
1885
+ const namespace = state.namespaces.get("llm-pi-ai");
1886
+ if (namespace === void 0) return false;
1887
+ const profile = (0, _deepseek_ai_dsh_client_schema_form.getPath)(namespace.value, row.entry.settingsPath);
1888
+ return profile !== null && typeof profile === "object" && profile.api === "anthropic-messages" && Array.isArray(profile.models) && profile.models.length > 0;
1889
+ }
1890
+ /** Stable visible and accessible identity for one provider target. */
1891
+ function providerTargetLabel(target) {
1892
+ return target.provider === target.displayName ? target.provider : `${target.displayName} (${target.provider})`;
1893
+ }
1894
+ /** Replace the one provider placeholder in localized destructive-action copy. */
1895
+ function providerCopy(template, target) {
1896
+ return template.replace("{provider}", () => providerTargetLabel(target));
1897
+ }
1898
+ /**
1899
+ * Render the Models section content column.
1900
+ * @param props - slot-delivered injected dependencies.
1901
+ * @returns the section, or null while the shell has not injected yet.
1902
+ */
1903
+ function ModelsSection(props) {
1904
+ const { controller, useSnapshot, api, t } = props;
1905
+ if (controller === void 0 || useSnapshot === void 0 || api === void 0 || t === void 0) return null;
1906
+ return (0, react_jsx_runtime.jsx)(Loaded, { injected: {
1907
+ controller,
1908
+ useSnapshot,
1909
+ api,
1910
+ t
1911
+ } });
1912
+ }
1913
+ function Loaded({ injected }) {
1914
+ const { controller, api, t } = injected;
1915
+ const state = injected.useSnapshot((snapshot) => snapshot);
1916
+ const [editing, setEditing] = (0, react.useState)(void 0);
1917
+ const [adding, setAdding] = (0, react.useState)(false);
1918
+ const [deleteTarget, setDeleteTarget] = (0, react.useState)(void 0);
1919
+ const [deleting, setDeleting] = (0, react.useState)(false);
1920
+ const [deleteFailure, setDeleteFailure] = (0, react.useState)(void 0);
1921
+ const [savedTarget, setSavedTarget] = (0, react.useState)(void 0);
1922
+ const [declaring, setDeclaring] = (0, react.useState)(false);
1923
+ const [dismissedSetup, setDismissedSetup] = (0, react.useState)(() => /* @__PURE__ */ new Set());
1924
+ const announceSaved = (target) => {
1925
+ controller.load().then(() => {
1926
+ setSavedTarget(target);
1927
+ });
1928
+ };
1929
+ const closeEditor = (changed, target) => {
1930
+ setEditing(void 0);
1931
+ setAdding(false);
1932
+ setDeclaring(false);
1933
+ if (changed) announceSaved(target);
1934
+ };
1935
+ /**
1936
+ * Close a setup card, which owns none of the state above: the row-editor,
1937
+ * add, and declare cards each own one of those, so clearing them here would
1938
+ * discard a draft the user opened beside this card. Dismissal is this card's
1939
+ * own — the provider falls back to an ordinary row for the rest of the
1940
+ * session, and reopens through Edit.
1941
+ */
1942
+ const closeSetup = (changed, target) => {
1943
+ setDismissedSetup((previous) => new Set([...previous, target.provider]));
1944
+ if (changed) announceSaved(target);
1945
+ };
1946
+ const closeDelete = () => {
1947
+ if (deleting) return;
1948
+ setDeleteTarget(void 0);
1949
+ setDeleteFailure(void 0);
1950
+ };
1951
+ const confirmDelete = () => {
1952
+ /* v8 ignore next -- the action only renders with a target and is disabled while a deletion is pending */
1953
+ if (deleteTarget === void 0 || deleting) return;
1954
+ setDeleting(true);
1955
+ setDeleteFailure(void 0);
1956
+ removeProviderProfile(api, controller, deleteTarget).then((failure) => {
1957
+ if (failure !== void 0) {
1958
+ setDeleteFailure(failure);
1959
+ return;
1960
+ }
1961
+ setDeleteTarget(void 0);
1962
+ }).finally(() => {
1963
+ setDeleting(false);
1964
+ });
1965
+ };
1966
+ if (state.status === "idle") controller.load();
1967
+ if (state.status === "error") {
1968
+ /* v8 ignore next -- an error status always carries text; the fallback satisfies the nullable type */
1969
+ const errorText = state.error ?? "";
1970
+ return (0, react_jsx_runtime.jsxs)("div", {
1971
+ className: ModelsSection_module_css_default["section"],
1972
+ children: [(0, react_jsx_runtime.jsx)("p", {
1973
+ className: ModelsSection_module_css_default["error"],
1974
+ children: `${t("loadFailed")}: ${errorText}`
1975
+ }), (0, react_jsx_runtime.jsx)("button", {
1976
+ type: "button",
1977
+ className: ModelsSection_module_css_default["secondaryButton"],
1978
+ onClick: () => {
1979
+ controller.load();
1980
+ },
1981
+ children: t("retry")
1982
+ })]
1983
+ });
1984
+ }
1985
+ const savedRow = savedTarget === void 0 ? void 0 : state.rows.find((row) => row.entry.provider === savedTarget.provider);
1986
+ const savedIdentity = savedRow === void 0 ? savedTarget : {
1987
+ provider: savedRow.entry.provider,
1988
+ displayName: savedRow.entry.displayName
1989
+ };
1990
+ const anyUsable = state.rows.some(providerUsable);
1991
+ const configured = state.rows.filter((row) => row.configured);
1992
+ const addable = state.rows.filter((row) => !row.configured && row.entry.settingsNs !== "");
1993
+ const addTarget = adding ? editing : void 0;
1994
+ const addNamespace = addTarget === void 0 ? void 0 : state.namespaces.get(addTarget.settingsNs);
1995
+ const protocols = protocolChoices(state.namespaces.get("llm-pi-ai"));
1996
+ return (0, react_jsx_runtime.jsxs)("div", {
1997
+ className: ModelsSection_module_css_default["section"],
1998
+ children: [
1999
+ (0, react_jsx_runtime.jsx)("h2", {
2000
+ className: ModelsSection_module_css_default["title"],
2001
+ children: t("title")
2002
+ }),
2003
+ (0, react_jsx_runtime.jsx)("p", {
2004
+ className: ModelsSection_module_css_default["intro"],
2005
+ children: t("intro")
2006
+ }),
2007
+ !state.writable && state.status === "ready" ? (0, react_jsx_runtime.jsx)("p", {
2008
+ className: ModelsSection_module_css_default["notice"],
2009
+ children: t("readOnly")
2010
+ }) : null,
2011
+ savedIdentity === void 0 ? null : (0, react_jsx_runtime.jsx)("p", {
2012
+ className: ModelsSection_module_css_default["savedNotice"],
2013
+ role: "status",
2014
+ "aria-live": "polite",
2015
+ children: providerCopy(t("savedProvider"), savedIdentity)
2016
+ }),
2017
+ (0, react_jsx_runtime.jsx)("ul", {
2018
+ className: ModelsSection_module_css_default["rows"],
2019
+ children: configured.map((row) => {
2020
+ const target = targetOf(row);
2021
+ const namespace = state.namespaces.get(target.settingsNs);
2022
+ /* v8 ignore next -- the join marks a row configured only when its namespace resolved */
2023
+ if (namespace === void 0) return null;
2024
+ if (needsSetup(row, anyUsable) && !dismissedSetup.has(row.entry.provider)) return (0, react_jsx_runtime.jsx)("li", {
2025
+ className: ModelsSection_module_css_default["setupCard"],
2026
+ children: renderProviderEditor({
2027
+ target,
2028
+ namespace,
2029
+ api,
2030
+ t,
2031
+ readOnly: !state.writable,
2032
+ onClose: (changed) => {
2033
+ closeSetup(changed, target);
2034
+ }
2035
+ })
2036
+ }, row.entry.provider);
2037
+ const open = !adding && editing?.provider === row.entry.provider;
2038
+ const adaptiveClaude = isClaudeProvider(row, state);
2039
+ const credentialConfigured = row.credential?.configured === true;
2040
+ const credentialMissing = !credentialConfigured && row.apiKeyEnv !== void 0 && row.credential?.configured === false;
2041
+ return (0, react_jsx_runtime.jsxs)("li", {
2042
+ className: ModelsSection_module_css_default["rowCard"],
2043
+ children: [(0, react_jsx_runtime.jsxs)("div", {
2044
+ className: ModelsSection_module_css_default["rowHead"],
2045
+ children: [(0, react_jsx_runtime.jsxs)("span", {
2046
+ className: ModelsSection_module_css_default["rowIdentity"],
2047
+ children: [
2048
+ (0, react_jsx_runtime.jsx)("span", {
2049
+ className: ModelsSection_module_css_default["rowName"],
2050
+ children: row.entry.displayName
2051
+ }),
2052
+ row.entry.declared === true ? (0, react_jsx_runtime.jsx)("span", {
2053
+ className: ModelsSection_module_css_default["rowTag"],
2054
+ children: t("customTag")
2055
+ }) : null,
2056
+ adaptiveClaude ? (0, react_jsx_runtime.jsx)("span", {
2057
+ className: ModelsSection_module_css_default["rowTag"],
2058
+ children: t("adaptiveClaudeTag")
2059
+ }) : null,
2060
+ credentialConfigured ? (0, react_jsx_runtime.jsx)("span", {
2061
+ className: `${ModelsSection_module_css_default["credentialDot"]} ${ModelsSection_module_css_default["credentialDotConfigured"]}`,
2062
+ role: "img",
2063
+ "aria-label": t("credentialConfigured"),
2064
+ title: t("credentialConfigured")
2065
+ }) : credentialMissing ? (0, react_jsx_runtime.jsx)("span", {
2066
+ className: `${ModelsSection_module_css_default["credentialDot"]} ${ModelsSection_module_css_default["credentialDotMissing"]}`,
2067
+ role: "img",
2068
+ "aria-label": t("credentialMissing"),
2069
+ title: t("credentialMissing")
2070
+ }) : null
2071
+ ]
2072
+ }), (0, react_jsx_runtime.jsxs)("span", {
2073
+ className: ModelsSection_module_css_default["rowActions"],
2074
+ children: [(0, react_jsx_runtime.jsx)("button", {
2075
+ type: "button",
2076
+ className: ModelsSection_module_css_default["secondaryButton"],
2077
+ "aria-label": providerCopy(t("editProvider"), target),
2078
+ onClick: () => {
2079
+ setSavedTarget(void 0);
2080
+ setDeclaring(false);
2081
+ setAdding(false);
2082
+ setEditing(open ? void 0 : target);
2083
+ },
2084
+ children: t("edit")
2085
+ }), row.removable ? (0, react_jsx_runtime.jsx)("button", {
2086
+ type: "button",
2087
+ className: ModelsSection_module_css_default["dangerButton"],
2088
+ "aria-label": providerCopy(t("removeProvider"), target),
2089
+ disabled: !state.writable,
2090
+ onClick: () => {
2091
+ setSavedTarget(void 0);
2092
+ setDeleteFailure(void 0);
2093
+ setDeleteTarget(target);
2094
+ },
2095
+ children: t("remove")
2096
+ }) : null]
2097
+ })]
2098
+ }), open ? renderProviderEditor({
2099
+ target,
2100
+ namespace,
2101
+ api,
2102
+ t,
2103
+ readOnly: !state.writable,
2104
+ onClose: (changed) => {
2105
+ closeEditor(changed, target);
2106
+ }
2107
+ }) : null]
2108
+ }, row.entry.provider);
2109
+ })
2110
+ }),
2111
+ (0, react_jsx_runtime.jsx)("div", {
2112
+ className: ModelsSection_module_css_default["addBlock"],
2113
+ children: addTarget !== void 0 && addNamespace !== void 0 ? (0, react_jsx_runtime.jsxs)("div", {
2114
+ className: ModelsSection_module_css_default["addCard"],
2115
+ children: [(0, react_jsx_runtime.jsxs)("div", {
2116
+ className: ModelsSection_module_css_default["field"],
2117
+ children: [(0, react_jsx_runtime.jsx)("span", {
2118
+ className: ModelsSection_module_css_default["fieldLabel"],
2119
+ children: t("provider")
2120
+ }), (0, react_jsx_runtime.jsx)("select", {
2121
+ className: `${ModelsSection_module_css_default["input"]} ${ModelsSection_module_css_default["selectInput"]}`,
2122
+ value: addTarget.provider,
2123
+ "aria-label": t("provider"),
2124
+ onChange: (event) => {
2125
+ const row = addable.find((candidate) => candidate.entry.provider === event.target.value);
2126
+ /* v8 ignore next -- the select only lists addable rows */
2127
+ if (row === void 0) return;
2128
+ setEditing(targetOf(row));
2129
+ },
2130
+ children: addable.map((row) => (0, react_jsx_runtime.jsx)("option", {
2131
+ value: row.entry.provider,
2132
+ children: row.entry.displayName
2133
+ }, row.entry.provider))
2134
+ })]
2135
+ }), (0, react_jsx_runtime.jsx)(ProviderEditor, {
2136
+ provider: addTarget.provider,
2137
+ displayName: addTarget.displayName,
2138
+ hideTitle: true,
2139
+ namespace: addNamespace,
2140
+ settingsPath: addTarget.settingsPath,
2141
+ api,
2142
+ t,
2143
+ readOnly: !state.writable,
2144
+ onClose: (changed) => {
2145
+ closeEditor(changed, addTarget);
2146
+ }
2147
+ }, addTarget.provider)]
2148
+ }) : declaring ? (0, react_jsx_runtime.jsx)("div", {
2149
+ className: ModelsSection_module_css_default["addCard"],
2150
+ children: (0, react_jsx_runtime.jsx)(CustomProviderCard, {
2151
+ taken: state.rows.map((row) => row.entry.provider),
2152
+ protocols,
2153
+ /* v8 ignore next -- the card only opens from a button disabled without this namespace */
2154
+ revision: state.namespaces.get("llm-pi-ai")?.revision ?? 0,
2155
+ api,
2156
+ t,
2157
+ readOnly: !state.writable,
2158
+ onClose: (changed) => {
2159
+ setDeclaring(false);
2160
+ if (changed) controller.load();
2161
+ }
2162
+ })
2163
+ }) : (0, react_jsx_runtime.jsxs)("div", {
2164
+ className: ModelsSection_module_css_default["addActions"],
2165
+ children: [(0, react_jsx_runtime.jsxs)("button", {
2166
+ type: "button",
2167
+ className: ModelsSection_module_css_default["addButton"],
2168
+ disabled: addable.length === 0 || !state.writable,
2169
+ onClick: () => {
2170
+ const first = addable[0];
2171
+ /* v8 ignore next -- the button is disabled while nothing is addable */
2172
+ if (first === void 0) return;
2173
+ setSavedTarget(void 0);
2174
+ setDeclaring(false);
2175
+ setAdding(true);
2176
+ setEditing(targetOf(first));
2177
+ },
2178
+ children: [(0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 14 }), t("add")]
2179
+ }), (0, react_jsx_runtime.jsxs)("button", {
2180
+ type: "button",
2181
+ className: ModelsSection_module_css_default["addButton"],
2182
+ disabled: protocols.length === 0 || !state.writable,
2183
+ onClick: () => {
2184
+ setSavedTarget(void 0);
2185
+ setAdding(false);
2186
+ setEditing(void 0);
2187
+ setDeclaring(true);
2188
+ },
2189
+ children: [(0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 14 }), t("customAdd")]
2190
+ })]
2191
+ })
2192
+ }),
2193
+ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
2194
+ open: deleteTarget !== void 0,
2195
+ onClose: closeDelete,
2196
+ title: deleteTarget === void 0 ? "" : providerCopy(t("deleteTitle"), deleteTarget),
2197
+ closeLabel: t("close"),
2198
+ description: deleteTarget === void 0 ? "" : providerCopy(deleteTarget.credentialRef === void 0 ? t("deleteDescription") : t("deleteDescriptionWithCredential"), deleteTarget),
2199
+ className: ModelsSection_module_css_default["deleteDialog"],
2200
+ footer: (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2201
+ variant: "outline",
2202
+ autoFocus: true,
2203
+ disabled: deleting,
2204
+ onClick: closeDelete,
2205
+ children: t("cancel")
2206
+ }), (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2207
+ variant: "outline",
2208
+ className: ModelsSection_module_css_default["deleteConfirm"],
2209
+ disabled: deleting,
2210
+ onClick: confirmDelete,
2211
+ children: deleteTarget === void 0 ? "" : providerCopy(deleting ? t("deleting") : t("deleteConfirm"), deleteTarget)
2212
+ })] }),
2213
+ children: deleteFailure === void 0 ? null : (0, react_jsx_runtime.jsx)("p", {
2214
+ className: ModelsSection_module_css_default["error"],
2215
+ children: deleteFailure
2216
+ })
2217
+ })
2218
+ ]
2219
+ });
2220
+ }
2221
+ //#endregion
2222
+ //#region \0dsh-css:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-settings-models/src/client/OnboardingModal.module.css.mjs
2223
+ const css$2 = ".jLrgrW_dialog{width:min(600px,100%);padding:0}.jLrgrW_content{box-sizing:border-box;flex-direction:column;max-height:calc(100vh - 48px);padding:28px;display:flex;overflow-y:auto}.jLrgrW_title{color:var(--dsw-alias-label-primary);outline:none;margin:0;font-size:20px;font-weight:500;line-height:28px}.jLrgrW_body{margin-top:20px}@media (width<=560px){.jLrgrW_content{padding:24px}}";
2224
+ const tagId$2 = "@mofeng2223/dsh-claude-provider/OnboardingModal.module.css";
2225
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
2226
+ const tag = document.createElement("style");
2227
+ tag.dataset.plugin = "@mofeng2223/dsh-claude-provider";
2228
+ tag.dataset.pluginCss = tagId$2;
2229
+ tag.textContent = css$2;
2230
+ document.head.appendChild(tag);
2231
+ }
2232
+ var OnboardingModal_module_css_default = {
2233
+ "body": "jLrgrW_body",
2234
+ "title": "jLrgrW_title",
2235
+ "dialog": "jLrgrW_dialog",
2236
+ "content": "jLrgrW_content"
2237
+ };
2238
+ //#endregion
2239
+ //#region lib/types/client/OnboardingModal.js
2240
+ /** Shared modal chrome for every step registered by this onboarding plugin. */
2241
+ const ignoreImplicitDismiss = () => {};
2242
+ /**
2243
+ * Render a blocking onboarding dialog and keep the application root inert.
2244
+ * @param props.title - accessible and visible dialog title.
2245
+ * @param props.focusTitle - focus the title when the step has no form control.
2246
+ * @param props.children - step-owned body and actions.
2247
+ * @returns the body-portaled modal.
2248
+ */
2249
+ function OnboardingModal({ title, focusTitle = false, children }) {
2250
+ const titleRef = (0, react.useRef)(null);
2251
+ (0, react.useEffect)(() => {
2252
+ const appRoot = document.getElementById("root");
2253
+ if (appRoot === null) return;
2254
+ const previous = appRoot.inert;
2255
+ appRoot.inert = true;
2256
+ return () => {
2257
+ appRoot.inert = previous;
2258
+ };
2259
+ }, []);
2260
+ (0, react.useEffect)(() => {
2261
+ if (focusTitle) titleRef.current?.focus();
2262
+ }, [focusTitle]);
2263
+ return (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
2264
+ open: true,
2265
+ title,
2266
+ onClose: ignoreImplicitDismiss,
2267
+ headless: true,
2268
+ className: OnboardingModal_module_css_default.dialog,
2269
+ children: (0, react_jsx_runtime.jsxs)("div", {
2270
+ className: OnboardingModal_module_css_default.content,
2271
+ children: [(0, react_jsx_runtime.jsx)("h2", {
2272
+ ref: titleRef,
2273
+ className: OnboardingModal_module_css_default.title,
2274
+ tabIndex: focusTitle ? -1 : void 0,
2275
+ children: title
2276
+ }), (0, react_jsx_runtime.jsx)("div", {
2277
+ className: OnboardingModal_module_css_default.body,
2278
+ children
2279
+ })]
2280
+ })
2281
+ });
2282
+ }
2283
+ //#endregion
2284
+ //#region \0dsh-css:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-settings-models/src/client/DeepSeekOnboardingDialog.module.css.mjs
2285
+ const css$1 = ".GL8Viq_description{color:var(--dsw-alias-label-secondary);margin:0;font-size:14px;line-height:24px}.GL8Viq_editor{margin-top:24px}@media (width<=560px){.GL8Viq_editor{margin-top:20px}}";
2286
+ const tagId$1 = "@mofeng2223/dsh-claude-provider/DeepSeekOnboardingDialog.module.css";
2287
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
2288
+ const tag = document.createElement("style");
2289
+ tag.dataset.plugin = "@mofeng2223/dsh-claude-provider";
2290
+ tag.dataset.pluginCss = tagId$1;
2291
+ tag.textContent = css$1;
2292
+ document.head.appendChild(tag);
2293
+ }
2294
+ var DeepSeekOnboardingDialog_module_css_default = {
2295
+ "description": "GL8Viq_description",
2296
+ "editor": "GL8Viq_editor"
2297
+ };
2298
+ //#endregion
2299
+ //#region lib/types/client/DeepSeekOnboardingDialog.js
2300
+ /**
2301
+ * Official-DeepSeek first-run step. Readiness comes from the same
2302
+ * provider/settings/credential join as the Models page: any provider the user
2303
+ * can already talk to ends the step, and only a user with none is offered the
2304
+ * official DeepSeek route. The step reuses that page's credential editor in
2305
+ * the onboarding plugin's shared modal, so the key is entered once.
2306
+ */
2307
+ /* v8 ignore next 3 -- closed-union defaults only defend future source widening */
2308
+ function assertNever(_value) {
2309
+ throw new Error("unexpected DeepSeek onboarding state");
2310
+ }
2311
+ /**
2312
+ * Prompt a first-run user for the official DeepSeek credential while no
2313
+ * provider can serve requests and that credential is writable.
2314
+ * @param props - settings-shell owner state and Models feature dependencies.
2315
+ * @returns the onboarding modal or null when onboarding needs no intervention.
2316
+ */
2317
+ function DeepSeekOnboardingDialog(props) {
2318
+ const { complete, controller, useModels, api, t } = props;
2319
+ const state = useModels((snapshot) => snapshot);
2320
+ const readiness = onboardingReadiness(state);
2321
+ (0, react.useEffect)(() => {
2322
+ if (state.status === "idle") controller.load();
2323
+ }, [controller, state.status]);
2324
+ (0, react.useEffect)(() => {
2325
+ if (readiness.kind === "adapter-absent" || readiness.kind === "provider-ready" || readiness.kind === "unavailable") complete();
2326
+ }, [complete, readiness.kind]);
2327
+ switch (readiness.kind) {
2328
+ case "loading":
2329
+ case "adapter-absent":
2330
+ case "provider-ready":
2331
+ case "unavailable": return null;
2332
+ case "credential-missing": break;
2333
+ /* v8 ignore next -- every current readiness variant is handled above */
2334
+ default: return assertNever(readiness);
2335
+ }
2336
+ const row = state.rows.find((candidate) => candidate.entry.provider === "deepseek-official" && candidate.entry.settingsNs === "llm-deepseek" && candidate.entry.settingsPath.length === 0);
2337
+ const namespace = state.namespaces.get("llm-deepseek");
2338
+ /* v8 ignore next 2 -- credential-missing is derived only from this exact joined row. */
2339
+ if (row === void 0 || namespace === void 0) return null;
2340
+ const finishCredential = (changed) => {
2341
+ if (!changed) {
2342
+ complete();
2343
+ return;
2344
+ }
2345
+ controller.load();
2346
+ };
2347
+ return (0, react_jsx_runtime.jsxs)(OnboardingModal, {
2348
+ title: t("onboardingTitle"),
2349
+ children: [(0, react_jsx_runtime.jsx)("p", {
2350
+ className: DeepSeekOnboardingDialog_module_css_default.description,
2351
+ children: t("onboardingDescription")
2352
+ }), (0, react_jsx_runtime.jsx)("div", {
2353
+ className: DeepSeekOnboardingDialog_module_css_default.editor,
2354
+ children: (0, react_jsx_runtime.jsx)(ProviderEditor, {
2355
+ provider: row.entry.provider,
2356
+ displayName: row.entry.displayName,
2357
+ namespace,
2358
+ settingsPath: row.entry.settingsPath,
2359
+ api,
2360
+ t,
2361
+ readOnly: false,
2362
+ hideTitle: true,
2363
+ credentialOnly: true,
2364
+ credentialRequired: true,
2365
+ autoFocusCredential: true,
2366
+ cancelLabel: "onboardingLater",
2367
+ submitLabel: "onboardingSave",
2368
+ submitBusyLabel: "onboardingSaving",
2369
+ onClose: finishCredential
2370
+ })
2371
+ })]
2372
+ });
2373
+ }
2374
+ //#endregion
2375
+ //#region \0dsh-css:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-settings-models/src/client/WelcomeNotice.module.css.mjs
2376
+ const css = ".t1T8VW_copy{color:var(--dsw-alias-label-secondary);font-size:14px;line-height:24px}.t1T8VW_copy p{margin:0}.t1T8VW_copy p+p{margin-top:12px}.t1T8VW_error{color:var(--dsw-alias-state-error-primary);margin:16px 0 0;font-size:14px;line-height:22px}.t1T8VW_actions{justify-content:flex-end;margin-top:24px;display:flex}.t1T8VW_primary{min-width:120px}@media (width<=560px){.t1T8VW_primary{width:100%}}";
2377
+ const tagId = "@mofeng2223/dsh-claude-provider/WelcomeNotice.module.css";
2378
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
2379
+ const tag = document.createElement("style");
2380
+ tag.dataset.plugin = "@mofeng2223/dsh-claude-provider";
2381
+ tag.dataset.pluginCss = tagId;
2382
+ tag.textContent = css;
2383
+ document.head.appendChild(tag);
2384
+ }
2385
+ var WelcomeNotice_module_css_default = {
2386
+ "error": "t1T8VW_error",
2387
+ "primary": "t1T8VW_primary",
2388
+ "copy": "t1T8VW_copy",
2389
+ "actions": "t1T8VW_actions"
2390
+ };
2391
+ //#endregion
2392
+ //#region lib/types/client/WelcomeNotice.js
2393
+ /** Product-wide, versioned internal-testing notice. */
2394
+ /**
2395
+ * Render the current notice until its exact copy version is acknowledged.
2396
+ * @param props - settings-shell owner state and welcome dependencies.
2397
+ * @returns the welcome modal or null while the step decides not to show.
2398
+ */
2399
+ function WelcomeNotice(props) {
2400
+ const { complete, controller, useWelcome, t } = props;
2401
+ const state = useWelcome((snapshot) => snapshot);
2402
+ const finished = (0, react.useRef)(false);
2403
+ const finish = (0, react.useCallback)(() => {
2404
+ if (finished.current) return;
2405
+ finished.current = true;
2406
+ complete();
2407
+ }, [complete]);
2408
+ (0, react.useEffect)(() => {
2409
+ if (state.status === "idle") controller.load();
2410
+ }, [controller, state.status]);
2411
+ (0, react.useEffect)(() => {
2412
+ if (state.acknowledged) finish();
2413
+ }, [finish, state.acknowledged]);
2414
+ if (state.status === "idle" || state.status === "loading" || state.acknowledged) return null;
2415
+ const acknowledge = async () => {
2416
+ if (await controller.acknowledge()) finish();
2417
+ };
2418
+ const paragraphs = t("welcomeBody").split("\n\n");
2419
+ return (0, react_jsx_runtime.jsxs)(OnboardingModal, {
2420
+ title: t("welcomeTitle"),
2421
+ focusTitle: true,
2422
+ children: [
2423
+ (0, react_jsx_runtime.jsx)("div", {
2424
+ className: WelcomeNotice_module_css_default.copy,
2425
+ children: paragraphs.map((paragraph) => (0, react_jsx_runtime.jsx)("p", { children: paragraph }, paragraph))
2426
+ }),
2427
+ state.error === null ? null : (0, react_jsx_runtime.jsx)("p", {
2428
+ className: WelcomeNotice_module_css_default.error,
2429
+ role: "alert",
2430
+ children: t("welcomeError")
2431
+ }),
2432
+ (0, react_jsx_runtime.jsx)("div", {
2433
+ className: WelcomeNotice_module_css_default.actions,
2434
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2435
+ variant: "primary",
2436
+ className: WelcomeNotice_module_css_default.primary,
2437
+ disabled: state.status === "saving",
2438
+ onClick: () => {
2439
+ acknowledge();
2440
+ },
2441
+ children: t("welcomeContinue")
2442
+ })
2443
+ })
2444
+ ]
2445
+ });
2446
+ }
2447
+ //#endregion
2448
+ //#region lib/types/onboarding-copy.js
2449
+ /** Durable settings namespace for product-wide GUI onboarding facts. */
2450
+ const WELCOME_NOTICE_SETTINGS_NAMESPACE = "ui-onboarding";
2451
+ /** Field storing the last welcome notice version the user acknowledged. */
2452
+ const WELCOME_NOTICE_ACK_FIELD = "welcomeNoticeVersion";
2453
+ /**
2454
+ * Bump only when the notice changes materially and every user should see it
2455
+ * again. The acknowledgement is compared for exact equality.
2456
+ */
2457
+ const WELCOME_NOTICE_VERSION = "2026-08-13.1";
2458
+ /** The complete editable internal-testing notice in both supported GUI locales. */
2459
+ const WELCOME_NOTICE_COPY = {
2460
+ zh: {
2461
+ title: "内测声明",
2462
+ body: "DeepSeek Harness 目前的 0.1 版本仍处在面向 Harness 开发者进行测试的阶段,还有许多地方需要持续改进和打磨,希望听取广大开发者的反馈建议。预计 DeepSeek Harness 的核心插件以及基础 API 都会在接下来的一段时间内快速迭代、持续演化。\n\n我们期待与全球开发者一起,在开源、开放、可复用、可组合的基础设施之上,共同探索智能上限。欢迎全球 Harness 开发者加入 DSH 插件生态。",
2463
+ continueLabel: "继续"
2464
+ },
2465
+ en: {
2466
+ title: "Internal Testing Notice",
2467
+ body: "DeepSeek Harness 0.1 remains in testing for Harness developers. Many areas need further improvement, and we welcome feedback from the developer community. DeepSeek Harness's core plugins and foundational APIs will continue to evolve rapidly over the coming months.\n\nWe look forward to exploring the limits of intelligence with developers around the world, building on open-source, open, reusable, and composable infrastructure. We welcome Harness developers everywhere to join the DSH plugin ecosystem.",
2468
+ continueLabel: "Continue"
2469
+ }
2470
+ };
2471
+ //#endregion
2472
+ //#region lib/types/client/welcome-store.js
2473
+ /** Welcome-notice state, durable when the browser may use Host settings. */
2474
+ function messageOf(error) {
2475
+ return error instanceof Error ? error.message : String(error);
2476
+ }
2477
+ function acknowledgementOf(view) {
2478
+ if (typeof view.value !== "object" || view.value === null) return void 0;
2479
+ const value = view.value[WELCOME_NOTICE_ACK_FIELD];
2480
+ return typeof value === "string" ? value : void 0;
2481
+ }
2482
+ /** Coordinates durable Host acknowledgement or a process-local remote fallback. */
2483
+ var WelcomeNoticeStore = class {
2484
+ api;
2485
+ persistence;
2486
+ /** uSES-safe state source shared by the registered welcome step. */
2487
+ store = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
2488
+ status: "idle",
2489
+ acknowledged: false,
2490
+ error: null
2491
+ });
2492
+ generation = 0;
2493
+ /**
2494
+ * @param api - settings wire face used for durable reads and writes.
2495
+ * @param persistence - remote browsers use memory because settings is loopback-only.
2496
+ */
2497
+ constructor(api, persistence = "host") {
2498
+ this.api = api;
2499
+ this.persistence = persistence;
2500
+ }
2501
+ /** Load the acknowledgement from Host settings or initialize process-local state. */
2502
+ async load() {
2503
+ const generation = ++this.generation;
2504
+ if (this.persistence === "memory") {
2505
+ this.store.update((state) => {
2506
+ state.status = "ready";
2507
+ state.error = null;
2508
+ });
2509
+ return;
2510
+ }
2511
+ this.store.update((state) => {
2512
+ state.status = "loading";
2513
+ state.error = null;
2514
+ });
2515
+ try {
2516
+ const response = await this.api.settings.describe({});
2517
+ if (!response.result.ok) throw new Error(response.result.error.message);
2518
+ const view = response.result.value.namespaces.find((candidate) => candidate.ns === WELCOME_NOTICE_SETTINGS_NAMESPACE);
2519
+ if (view === void 0) throw new Error("welcome acknowledgement settings are unavailable");
2520
+ if (generation !== this.generation) return;
2521
+ this.store.update((state) => {
2522
+ state.status = "ready";
2523
+ state.acknowledged = acknowledgementOf(view) === WELCOME_NOTICE_VERSION;
2524
+ state.error = null;
2525
+ });
2526
+ } catch (error) {
2527
+ if (generation !== this.generation) return;
2528
+ this.store.update((state) => {
2529
+ state.status = "error";
2530
+ state.acknowledged = false;
2531
+ state.error = messageOf(error);
2532
+ });
2533
+ }
2534
+ }
2535
+ /**
2536
+ * Persist this copy version, or advance only this process for a remote browser.
2537
+ * @returns true when the selected persistence mode accepted the acknowledgement.
2538
+ */
2539
+ async acknowledge() {
2540
+ const generation = ++this.generation;
2541
+ if (this.persistence === "memory") {
2542
+ this.store.update((state) => {
2543
+ state.status = "ready";
2544
+ state.acknowledged = true;
2545
+ state.error = null;
2546
+ });
2547
+ return true;
2548
+ }
2549
+ this.store.update((state) => {
2550
+ state.status = "saving";
2551
+ state.error = null;
2552
+ });
2553
+ try {
2554
+ const response = await this.api.settings.mutate({
2555
+ ns: WELCOME_NOTICE_SETTINGS_NAMESPACE,
2556
+ ops: [{
2557
+ op: "set",
2558
+ path: [WELCOME_NOTICE_ACK_FIELD],
2559
+ value: WELCOME_NOTICE_VERSION
2560
+ }]
2561
+ });
2562
+ if (!response.result.ok) throw new Error(response.result.error.message);
2563
+ if (generation === this.generation) this.store.update((state) => {
2564
+ state.status = "ready";
2565
+ state.acknowledged = true;
2566
+ state.error = null;
2567
+ });
2568
+ return true;
2569
+ } catch (error) {
2570
+ if (generation === this.generation) this.store.update((state) => {
2571
+ state.status = "error";
2572
+ state.acknowledged = false;
2573
+ state.error = messageOf(error);
2574
+ });
2575
+ return false;
2576
+ }
2577
+ }
2578
+ };
2579
+ /**
2580
+ * Refresh only after welcome state has left idle. A memory-mode load retains
2581
+ * acknowledgement so reconnect does not reopen a process-local notice.
2582
+ * @param controller - welcome state owner whose current status decides whether to load.
2583
+ */
2584
+ function refreshWelcomeIfLoaded(controller) {
2585
+ if (controller.store.getSnapshot().status === "idle") return;
2586
+ controller.load();
2587
+ }
2588
+ //#endregion
2589
+ //#region lib/types/client/locales.js
2590
+ /** Copy dictionaries for the Models settings section. */
2591
+ /** English strings (the key-set source of truth for this pair). */
2592
+ const en = {
2593
+ nav: "Models",
2594
+ title: "Models",
2595
+ intro: "Enter your API keys to use models from the following providers.",
2596
+ edit: "Edit",
2597
+ editProvider: "Edit {provider}",
2598
+ remove: "Delete",
2599
+ removeProvider: "Delete {provider}",
2600
+ deleteTitle: "Delete {provider}?",
2601
+ deleteDescription: "Deleting {provider} removes its configuration. Any credential it uses is managed elsewhere and will be kept.",
2602
+ deleteDescriptionWithCredential: "Deleting {provider} removes its configuration and stored API key.",
2603
+ deleteConfirm: "Delete {provider}",
2604
+ deleting: "Deleting {provider}…",
2605
+ add: "Add provider",
2606
+ provider: "Provider",
2607
+ close: "Close",
2608
+ cancel: "Cancel",
2609
+ apply: "Apply",
2610
+ applying: "Applying…",
2611
+ savedProvider: "Saved {provider}.",
2612
+ credentialConfigured: "API key configured",
2613
+ credentialMissing: "API key missing",
2614
+ readOnly: "The settings document is read-only in this deployment.",
2615
+ loadFailed: "Loading the provider directory failed",
2616
+ conflict: "Someone else changed these settings while this card was open. Close it and reopen to edit the current values.",
2617
+ retry: "Retry",
2618
+ keyInput: "API key",
2619
+ keyPlaceholder: "Enter your API key",
2620
+ keyPlaceholderNative: "Enter an API key, or leave blank to use environment authentication",
2621
+ keyStored: "Configured — enter a new value to replace",
2622
+ keyEnvLocked: "Provided by the launch environment (read-only)",
2623
+ customized: "Customized settings",
2624
+ baseUrl: "Base URL",
2625
+ baseUrlDefault: "Provider default",
2626
+ models: "Models",
2627
+ modelsInherited: "Using the adapter defaults",
2628
+ modelsCustomized: "Customized model catalog",
2629
+ resetModels: "Restore defaults",
2630
+ model: "Model",
2631
+ modelId: "Model ID",
2632
+ modelName: "Display name",
2633
+ modelNamePlaceholder: "Uses the model ID when empty",
2634
+ contextWindow: "Context window",
2635
+ contextWindowPlaceholder: "Uses the provider default",
2636
+ maxTokens: "Max output tokens",
2637
+ maxTokensPlaceholder: "Uses the provider default",
2638
+ modelAdvanced: "Capacities",
2639
+ addModel: "Add model",
2640
+ removeModel: "Delete model",
2641
+ modelsEmpty: "No models will be shown in the selector. Unlisted IDs can still be sent directly.",
2642
+ keyBlank: "Enter the API key, or leave the field empty to keep the stored one.",
2643
+ keyBlankNew: "Enter the API key, or leave the field empty if this provider authenticates another way.",
2644
+ keyIllegalCharacters: "This API key is not in a valid format. Please check it.",
2645
+ modelIdRequired: "Model ID is required.",
2646
+ modelIdDuplicate: "Model ID must be unique.",
2647
+ modelNameInvalid: "Display name cannot be empty.",
2648
+ modelContextInvalid: "Context window must be a positive count, like 131072, 256K, or 1M.",
2649
+ modelMaxTokensInvalid: "Max output tokens must be a positive count, like 8192, 64K, or 1M.",
2650
+ advancedHint: "Other fields live in settings.yaml; edit that section directly.",
2651
+ modelCapacityInvalid: "A capacity must be a number, optionally suffixed K or M.",
2652
+ modelDuplicate: "Each model ID may appear once.",
2653
+ modelContextWindow: "Context window",
2654
+ modelMaxTokens: "Max output tokens",
2655
+ fetchModels: "Fetch available models",
2656
+ fetching: "Asking the provider…",
2657
+ fetchNeedsBaseUrl: "Enter the base URL first, then fetch.",
2658
+ fetchEmpty: "The provider listed no models. Add them by hand.",
2659
+ fetchTitle: "Choose models to add",
2660
+ fetchDescription: "These are the models this provider has available. Choose the ones to add.",
2661
+ fetchAdopt: "Add selected",
2662
+ customAdd: "Add a custom provider",
2663
+ customTitle: "Custom provider",
2664
+ customTag: "Custom",
2665
+ customProviderType: "Provider type",
2666
+ customProviderTypeGeneric: "Generic custom provider",
2667
+ customProviderTypeClaude: "Custom Claude provider",
2668
+ adaptiveClaudeEnabled: "Choose a thinking mode for each model. New models default to five levels.",
2669
+ adaptiveClaudeHelpLabel: "Thinking mode help",
2670
+ adaptiveClaudeHelp: "Five (low / medium / high / xhigh / max): Fable 5, Opus 5, Opus 4.8, Opus 4.7, Sonnet 5\nFour (low / medium / high / max): Opus 4.6, Sonnet 4.6\nOn / Off: Haiku 4.5",
2671
+ adaptiveClaudeTag: "Claude configured",
2672
+ thinkingPreset: "Thinking mode",
2673
+ thinkingPresetToggle: "On / Off",
2674
+ thinkingPresetFour: "Four levels",
2675
+ thinkingPresetFive: "Five levels (default)",
2676
+ customRoute: "Provider ID",
2677
+ customRouteHint: "Lowercase identifier, starting with a letter, that uniquely names this provider in requests and as its credential name.",
2678
+ customRouteInvalid: "Start with a lowercase letter; then lowercase letters, digits, and dashes.",
2679
+ customRouteTaken: "A provider already uses this ID.",
2680
+ customDisplayName: "Display name",
2681
+ customApi: "API protocol",
2682
+ customApiUnset: "Not selected",
2683
+ customNeedsBaseUrl: "A custom provider needs a base URL.",
2684
+ customNeedsModels: "A custom provider needs at least one model.",
2685
+ create: "Create provider",
2686
+ creating: "Creating…",
2687
+ welcomeTitle: WELCOME_NOTICE_COPY.en.title,
2688
+ welcomeBody: WELCOME_NOTICE_COPY.en.body,
2689
+ welcomeContinue: WELCOME_NOTICE_COPY.en.continueLabel,
2690
+ welcomeError: "The acknowledgement could not be saved. Please try again.",
2691
+ onboardingTitle: "Add an API key to get started",
2692
+ onboardingDescription: "Configure the official DeepSeek provider to start building.",
2693
+ onboardingLater: "Configure later",
2694
+ onboardingSave: "Save and continue",
2695
+ onboardingSaving: "Saving…",
2696
+ keyRequired: "Enter an API key to continue."
2697
+ };
2698
+ /** Chinese strings (same keys as {@link en}). */
2699
+ const zh = {
2700
+ nav: "模型",
2701
+ title: "模型",
2702
+ intro: "填入各提供方的 API 密钥即可使用其模型。",
2703
+ edit: "编辑",
2704
+ editProvider: "编辑 {provider}",
2705
+ remove: "删除",
2706
+ removeProvider: "删除 {provider}",
2707
+ deleteTitle: "删除 {provider}?",
2708
+ deleteDescription: "删除 {provider} 会移除其配置;其使用的凭证(如有)由其他位置管理,将会保留。",
2709
+ deleteDescriptionWithCredential: "删除 {provider} 会移除其配置和存储的 API 密钥。",
2710
+ deleteConfirm: "删除 {provider}",
2711
+ deleting: "正在删除 {provider}…",
2712
+ add: "添加提供方",
2713
+ provider: "提供方",
2714
+ close: "关闭",
2715
+ cancel: "取消",
2716
+ apply: "保存",
2717
+ applying: "保存中…",
2718
+ savedProvider: "已保存 {provider}。",
2719
+ credentialConfigured: "API 密钥已配置",
2720
+ credentialMissing: "API 密钥缺失",
2721
+ readOnly: "当前部署的设置文档为只读。",
2722
+ loadFailed: "加载提供方目录失败",
2723
+ conflict: "这张卡片打开期间,这些设置已被其他地方改动。请关闭后重新打开,在当前值上编辑。",
2724
+ retry: "重试",
2725
+ keyInput: "API 密钥",
2726
+ keyPlaceholder: "输入 API 密钥",
2727
+ keyPlaceholderNative: "输入 API 密钥,或留空使用环境认证",
2728
+ keyStored: "已配置——输入新值可替换",
2729
+ keyEnvLocked: "由启动环境提供(只读)",
2730
+ customized: "自定义设置",
2731
+ baseUrl: "API 地址",
2732
+ baseUrlDefault: "提供方默认",
2733
+ models: "模型目录",
2734
+ modelsInherited: "正在使用适配器默认模型",
2735
+ modelsCustomized: "已自定义模型目录",
2736
+ resetModels: "恢复默认模型",
2737
+ model: "模型",
2738
+ modelId: "模型 ID",
2739
+ modelName: "显示名称",
2740
+ modelNamePlaceholder: "留空时使用模型 ID",
2741
+ contextWindow: "上下文窗口",
2742
+ contextWindowPlaceholder: "使用提供方默认值",
2743
+ maxTokens: "最大输出 token 数",
2744
+ maxTokensPlaceholder: "使用提供方默认值",
2745
+ modelAdvanced: "容量",
2746
+ addModel: "添加模型",
2747
+ removeModel: "删除模型",
2748
+ modelsEmpty: "模型选择器中将不显示任何模型;目录外 ID 仍可直接发送。",
2749
+ keyBlank: "请输入 API 密钥;留空则保持已存储的密钥。",
2750
+ keyBlankNew: "请输入 API 密钥;若该提供方以其他方式鉴权,可以留空。",
2751
+ keyIllegalCharacters: "该 API 密钥格式错误,请检查。",
2752
+ modelIdRequired: "模型 ID 不能为空。",
2753
+ modelIdDuplicate: "模型 ID 不能重复。",
2754
+ modelNameInvalid: "显示名称不能为空。",
2755
+ modelContextInvalid: "上下文窗口必须是正数,例如 131072、256K 或 1M。",
2756
+ modelMaxTokensInvalid: "最大输出 token 数必须是正数,例如 8192、64K 或 1M。",
2757
+ advancedHint: "其余字段在 settings.yaml 中,请直接编辑对应段。",
2758
+ modelCapacityInvalid: "容量需为数字,可加 K 或 M 后缀。",
2759
+ modelDuplicate: "每个模型 ID 只能出现一次。",
2760
+ modelContextWindow: "上下文窗口",
2761
+ modelMaxTokens: "最大输出 token",
2762
+ fetchModels: "获取可用模型",
2763
+ fetching: "正在询问提供方…",
2764
+ fetchNeedsBaseUrl: "请先填写 API 地址,再获取。",
2765
+ fetchEmpty: "该提供方没有列出任何模型,请手动添加。",
2766
+ fetchTitle: "选择要添加的模型",
2767
+ fetchDescription: "以下是模型提供方的可用模型,勾选要添加的模型。",
2768
+ fetchAdopt: "添加所选",
2769
+ customAdd: "添加自定义提供方",
2770
+ customTitle: "自定义提供方",
2771
+ customTag: "自定义",
2772
+ customProviderType: "供应商类型",
2773
+ customProviderTypeGeneric: "通用自定义供应商",
2774
+ customProviderTypeClaude: "自定义 Claude 供应商",
2775
+ adaptiveClaudeEnabled: "每个模型可单独选择思考模式;新增模型默认使用五档。",
2776
+ adaptiveClaudeHelpLabel: "思考模式说明",
2777
+ adaptiveClaudeHelp: "五档(低 / 中 / 高 / 超高 / 最大):Fable 5、Opus 5、Opus 4.8、Opus 4.7、Sonnet 5\n四档(低 / 中 / 高 / 最大):Opus 4.6、Sonnet 4.6\n开启 / 关闭:Haiku 4.5",
2778
+ adaptiveClaudeTag: "Claude 已适配",
2779
+ thinkingPreset: "思考模式",
2780
+ thinkingPresetToggle: "开启 / 关闭",
2781
+ thinkingPresetFour: "四档",
2782
+ thinkingPresetFive: "五档(默认)",
2783
+ customRoute: "Provider ID",
2784
+ customRouteHint: "以小写字母开头的标识,在请求中唯一标识该提供方,并用于派生凭据名。",
2785
+ customRouteInvalid: "需以小写字母开头,之后可用小写字母、数字和短横线。",
2786
+ customRouteTaken: "已有提供方使用了这个 ID。",
2787
+ customDisplayName: "显示名称",
2788
+ customApi: "API 协议",
2789
+ customApiUnset: "未选择",
2790
+ customNeedsBaseUrl: "自定义提供方需要填写 API 地址。",
2791
+ customNeedsModels: "自定义提供方至少需要一个模型。",
2792
+ create: "创建提供方",
2793
+ creating: "创建中…",
2794
+ welcomeTitle: WELCOME_NOTICE_COPY.zh.title,
2795
+ welcomeBody: WELCOME_NOTICE_COPY.zh.body,
2796
+ welcomeContinue: WELCOME_NOTICE_COPY.zh.continueLabel,
2797
+ welcomeError: "暂时无法保存确认状态,请重试。",
2798
+ onboardingTitle: "添加一个 API Key 开始使用",
2799
+ onboardingDescription: "配置 DeepSeek 官方模型,即可开始使用。",
2800
+ onboardingLater: "稍后配置",
2801
+ onboardingSave: "保存并继续",
2802
+ onboardingSaving: "保存中…",
2803
+ keyRequired: "请输入 API 密钥后继续。"
2804
+ };
2805
+ //#endregion
2806
+ //#region lib/types/client/index.js
2807
+ /** Dictionary namespace owned by this plugin. */
2808
+ const NS = "settings.models";
2809
+ /**
2810
+ * Refetch the page snapshot only after its first load: an unopened Models
2811
+ * page must not fetch on background invalidations.
2812
+ * @param controller - the page store.
2813
+ */
2814
+ function refreshIfLoaded(controller) {
2815
+ if (controller.store.getSnapshot().status === "idle") return;
2816
+ controller.load();
2817
+ }
2818
+ /**
2819
+ * Required services (cordis fiber inject). The target slot is declared by
2820
+ * ui-settings' apply, whose activation order relative to this one is NOT
2821
+ * constrained; registration depends on each slot through `slots.inject()`.
2822
+ */
2823
+ const inject = [
2824
+ "slots",
2825
+ "locale",
2826
+ "connection",
2827
+ "remote"
2828
+ ];
2829
+ /**
2830
+ * Register the Models section once the `settings.section` declaration is on
2831
+ * the ledger, wire its store to the connection, and keep it fresh on every
2832
+ * pushed invalidation (settings, credentials, or provider topology).
2833
+ * @param ctx - client root context.
2834
+ */
2835
+ function apply(ctx) {
2836
+ ctx.effect(() => ctx.locale.register(NS, {
2837
+ zh,
2838
+ en
2839
+ }), "ui-settings-models: copy dictionaries");
2840
+ const connection = ctx.get("connection");
2841
+ const controller = new ModelsSettingsStore(connection.api);
2842
+ const useSnapshot = (0, _deepseek_ai_dsh_client_web_react.bindSnapshotSelector)(controller.store);
2843
+ const t = ctx.locale.bind(NS);
2844
+ const injected = () => ({
2845
+ controller,
2846
+ useSnapshot,
2847
+ api: connection.api,
2848
+ t
2849
+ });
2850
+ const deepSeekOnboardingInjected = () => ({
2851
+ controller,
2852
+ hooks: { models: controller.store },
2853
+ api: connection.api,
2854
+ t
2855
+ });
2856
+ const welcomeController = new WelcomeNoticeStore(connection.api, connection.isLoopback ? "host" : "memory");
2857
+ const welcomeInjected = () => ({
2858
+ controller: welcomeController,
2859
+ hooks: { welcome: welcomeController.store },
2860
+ t
2861
+ });
2862
+ ctx.effect(() => {
2863
+ const refreshModels = () => {
2864
+ refreshIfLoaded(controller);
2865
+ };
2866
+ const refreshAll = () => {
2867
+ refreshModels();
2868
+ refreshWelcomeIfLoaded(welcomeController);
2869
+ };
2870
+ const disposers = [
2871
+ ctx.remote.$on("settings/document-updated", (ns) => {
2872
+ refreshModels();
2873
+ if (ns === "ui-onboarding") refreshWelcomeIfLoaded(welcomeController);
2874
+ }),
2875
+ ctx.remote.$on("credentials/updated", refreshModels),
2876
+ ctx.remote.$on("llm/adapters-updated", refreshModels),
2877
+ ctx.on("connection/reset", refreshAll)
2878
+ ];
2879
+ return () => {
2880
+ for (const dispose of disposers) dispose();
2881
+ };
2882
+ }, "ui-settings-models: pushed invalidations");
2883
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
2884
+ name: "settings.section",
2885
+ id: "models",
2886
+ order: 10,
2887
+ label: () => t("nav"),
2888
+ inject: injected
2889
+ }, ModelsSection));
2890
+ ctx.slots.inject("settings.onboarding", () => ctx.slots.register({
2891
+ name: "settings.onboarding",
2892
+ id: "welcome-notice",
2893
+ order: -100,
2894
+ inject: welcomeInjected
2895
+ }, WelcomeNotice));
2896
+ ctx.slots.inject("settings.onboarding", () => ctx.slots.register({
2897
+ name: "settings.onboarding",
2898
+ id: "deepseek-official",
2899
+ order: 0,
2900
+ inject: deepSeekOnboardingInjected
2901
+ }, DeepSeekOnboardingDialog));
2902
+ }
2903
+ //#endregion
2904
+ exports.apply = apply;
2905
+ exports.inject = inject;
2906
+ exports.refreshIfLoaded = refreshIfLoaded;
2907
+ return module.exports;
2908
+ }
2909
+ });
2910
+
2911
+ //# sourceMappingURL=client.js.map