bailian-kb-dsh 0.1.18

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.
@@ -0,0 +1,1052 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "bailian-kb-dsh",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ //#region src/web/bailian-card-controller.ts
11
+ /** The credential references this page addresses, keyed by their ref names. */
12
+ const BAILIAN_CARD_REFS = [
13
+ "DASHSCOPE_API_KEY",
14
+ "BAILIAN_WORKSPACE_ID",
15
+ "BAILIAN_DEFAULT_RETRIEVE_AGENT_ID",
16
+ "BAILIAN_DEFAULT_CHAT_AGENT_ID"
17
+ ];
18
+ /** Credential reference → settings-section field, for the hybrid controls. */
19
+ const SETTINGS_FIELDS = {
20
+ BAILIAN_WORKSPACE_ID: "workspaceId",
21
+ BAILIAN_DEFAULT_RETRIEVE_AGENT_ID: "defaultRetrieveAgentId",
22
+ BAILIAN_DEFAULT_CHAT_AGENT_ID: "defaultChatAgentId"
23
+ };
24
+ /** The text a field's control shows when its draft is untouched. */
25
+ function echoedValue(state, key) {
26
+ const field = SETTINGS_FIELDS[key];
27
+ if (field === void 0 || state.settings.status !== "ready") return "";
28
+ return state.settings.values[field] ?? "";
29
+ }
30
+ /** Whether one field stages a change a save would write. */
31
+ function staged(state, key) {
32
+ const draft = state.drafts[key];
33
+ if (draft === void 0) return false;
34
+ if (SETTINGS_FIELDS[key] !== void 0 && state.settings.status === "ready") return draft !== echoedValue(state, key);
35
+ return draft !== "";
36
+ }
37
+ /** Whether any field stages a change (enables Save/Discard). */
38
+ function dirtyOf(state) {
39
+ return BAILIAN_CARD_REFS.some((key) => staged(state, key));
40
+ }
41
+ /** Bridge the settings bridge route and the credentials domain onto the page. */
42
+ var BailianCardController = class {
43
+ api;
44
+ store;
45
+ /**
46
+ * @param api - wire face used for the three credential references.
47
+ */
48
+ constructor(api) {
49
+ this.api = api;
50
+ this.store = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
51
+ drafts: {
52
+ DASHSCOPE_API_KEY: void 0,
53
+ BAILIAN_WORKSPACE_ID: void 0,
54
+ BAILIAN_DEFAULT_RETRIEVE_AGENT_ID: void 0,
55
+ BAILIAN_DEFAULT_CHAT_AGENT_ID: void 0
56
+ },
57
+ credentials: {
58
+ DASHSCOPE_API_KEY: {
59
+ configured: false,
60
+ writable: true
61
+ },
62
+ BAILIAN_WORKSPACE_ID: {
63
+ configured: false,
64
+ writable: true
65
+ },
66
+ BAILIAN_DEFAULT_RETRIEVE_AGENT_ID: {
67
+ configured: false,
68
+ writable: true
69
+ },
70
+ BAILIAN_DEFAULT_CHAT_AGENT_ID: {
71
+ configured: false,
72
+ writable: true
73
+ }
74
+ },
75
+ settings: {
76
+ status: "loading",
77
+ writable: false,
78
+ values: {}
79
+ },
80
+ saving: false,
81
+ clearing: false,
82
+ failed: false,
83
+ autofill: "idle",
84
+ autofillLoginUrl: void 0,
85
+ cache: {
86
+ status: "loading",
87
+ searchCount: 0,
88
+ chatCount: 0,
89
+ total: 0,
90
+ truncated: false,
91
+ stale: true,
92
+ search: [],
93
+ chat: [],
94
+ refreshing: false
95
+ }
96
+ });
97
+ this.fetchSettings();
98
+ this.fetchServices();
99
+ this.read();
100
+ }
101
+ /**
102
+ * Fetch the current settings from the Host bridge route. Called at
103
+ * construction and after every mutation (save, clear).
104
+ */
105
+ async fetchSettings() {
106
+ try {
107
+ const resp = await fetch("/bailian-kb/settings");
108
+ if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
109
+ const value = await resp.json();
110
+ this.store.update((draft) => {
111
+ draft.settings = {
112
+ status: "ready",
113
+ writable: true,
114
+ values: {
115
+ ...typeof value.workspaceId === "string" ? { workspaceId: value.workspaceId } : {},
116
+ ...typeof value.defaultRetrieveAgentId === "string" ? { defaultRetrieveAgentId: value.defaultRetrieveAgentId } : {},
117
+ ...typeof value.defaultChatAgentId === "string" ? { defaultChatAgentId: value.defaultChatAgentId } : {}
118
+ }
119
+ };
120
+ });
121
+ } catch (_fetchFailure) {
122
+ this.store.update((draft) => {
123
+ draft.settings = {
124
+ status: "unavailable",
125
+ writable: false,
126
+ values: {}
127
+ };
128
+ });
129
+ }
130
+ }
131
+ /**
132
+ * Read the service cache snapshot from the Host bridge route.
133
+ * @param force - POST instead of GET, making the Host refetch regardless of TTL.
134
+ */
135
+ async fetchServices(force = false) {
136
+ if (force) this.store.update((draft) => {
137
+ draft.cache.refreshing = true;
138
+ });
139
+ try {
140
+ const resp = await fetch("/bailian-kb/services", { method: force ? "POST" : "GET" });
141
+ if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
142
+ const value = await resp.json();
143
+ this.store.update((draft) => {
144
+ draft.cache.refreshing = false;
145
+ if (value.configured !== true) {
146
+ draft.cache.status = "unconfigured";
147
+ return;
148
+ }
149
+ draft.cache.status = "ready";
150
+ draft.cache.fetchedAt = value.status?.fetchedAt;
151
+ draft.cache.searchCount = value.status?.searchCount ?? 0;
152
+ draft.cache.chatCount = value.status?.chatCount ?? 0;
153
+ draft.cache.total = value.status?.total ?? 0;
154
+ draft.cache.truncated = value.status?.truncated === true;
155
+ draft.cache.stale = value.status?.stale === true;
156
+ draft.cache.search = value.search ?? [];
157
+ draft.cache.chat = value.chat ?? [];
158
+ });
159
+ } catch (_routeFailure) {
160
+ this.store.update((draft) => {
161
+ draft.cache.refreshing = false;
162
+ draft.cache.status = "unavailable";
163
+ });
164
+ }
165
+ }
166
+ /** Force a refresh, bypassing the TTL, and show the updated numbers. */
167
+ async refreshServices() {
168
+ if (this.store.getSnapshot().cache.refreshing) return;
169
+ await this.fetchServices(true);
170
+ }
171
+ /**
172
+ * Pin or clear one scene's default service.
173
+ *
174
+ * Clearing delegates to {@link clearDefaultAgent}, which removes the value from
175
+ * the settings user layer AND the credential store — without the second
176
+ * removal the fallback chain would resurrect what the user just cleared.
177
+ * @param scene - which tool's default to set.
178
+ * @param agentId - the service id to pin, or undefined to clear.
179
+ */
180
+ async selectDefaultAgent(scene, agentId) {
181
+ const key = scene === "search" ? "BAILIAN_DEFAULT_RETRIEVE_AGENT_ID" : "BAILIAN_DEFAULT_CHAT_AGENT_ID";
182
+ if (agentId === void 0) {
183
+ await this.clearDefaultAgent(key);
184
+ return;
185
+ }
186
+ const field = scene === "search" ? "defaultRetrieveAgentId" : "defaultChatAgentId";
187
+ this.store.update((draft) => {
188
+ draft.saving = true;
189
+ });
190
+ try {
191
+ const resp = await fetch("/bailian-kb/settings", {
192
+ method: "POST",
193
+ headers: { "Content-Type": "application/json" },
194
+ body: JSON.stringify({ [field]: agentId })
195
+ });
196
+ if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
197
+ this.store.update((draft) => {
198
+ draft.failed = false;
199
+ });
200
+ } catch (_writeFailure) {
201
+ this.store.update((draft) => {
202
+ draft.failed = true;
203
+ });
204
+ } finally {
205
+ this.store.update((draft) => {
206
+ draft.saving = false;
207
+ });
208
+ await this.fetchSettings();
209
+ }
210
+ }
211
+ /**
212
+ * Stage one draft; any edit clears the failure mark so the banner does not
213
+ * outlive the correction it asks for.
214
+ * @param key - the field's credential reference.
215
+ * @param text - the staged text.
216
+ */
217
+ edit(key, text) {
218
+ this.store.update((draft) => {
219
+ draft.drafts[key] = text;
220
+ draft.failed = false;
221
+ });
222
+ }
223
+ /**
224
+ * Write every staged draft through its domain: echoing fields go to the
225
+ * settings user layer via the bridge route (blank = removal, falling back
226
+ * to entry config and the credential store), write-only fields go to
227
+ * `credentials.set`. A refused credential write keeps its draft; a refused
228
+ * settings write self-heals by re-fetching the Host value.
229
+ */
230
+ async save() {
231
+ const state = this.store.getSnapshot();
232
+ if (state.saving || !dirtyOf(state)) return;
233
+ this.store.update((draft) => {
234
+ draft.saving = true;
235
+ });
236
+ let failed = false;
237
+ const settingsPatch = {};
238
+ let hasSettingsWrite = false;
239
+ const credentialWrites = [];
240
+ const settled = [];
241
+ for (const key of BAILIAN_CARD_REFS) {
242
+ if (!staged(state, key)) continue;
243
+ const text = state.drafts[key];
244
+ const field = SETTINGS_FIELDS[key];
245
+ if (field !== void 0 && state.settings.status === "ready") {
246
+ settingsPatch[field] = text === "" ? null : text;
247
+ hasSettingsWrite = true;
248
+ settled.push(key);
249
+ continue;
250
+ }
251
+ credentialWrites.push((async () => {
252
+ try {
253
+ if ((await this.api.credentials.set({
254
+ ref: key,
255
+ value: text
256
+ })).result.ok) settled.push(key);
257
+ else failed = true;
258
+ } catch (_credentialWriteFailure) {
259
+ failed = true;
260
+ }
261
+ })());
262
+ }
263
+ if (hasSettingsWrite) try {
264
+ await this.saveSettings(settingsPatch);
265
+ } catch (_settingsWriteFailure) {
266
+ failed = true;
267
+ }
268
+ await Promise.all(credentialWrites);
269
+ this.store.update((draft) => {
270
+ draft.saving = false;
271
+ draft.failed = failed;
272
+ for (const key of settled) draft.drafts[key] = void 0;
273
+ });
274
+ await this.fetchSettings();
275
+ await this.read();
276
+ }
277
+ /** Drop every staged draft and the failure mark. */
278
+ discard() {
279
+ this.store.update((draft) => {
280
+ for (const ref of BAILIAN_CARD_REFS) draft.drafts[ref] = void 0;
281
+ draft.failed = false;
282
+ });
283
+ }
284
+ /**
285
+ * Fetch credentials by signing in to the Bailian console. The Host drives
286
+ * the console browser login itself, always requesting a freshly issued api
287
+ * key, then persists the key into the credential store and the workspace id
288
+ * into the settings section — so both values belong to the account that just
289
+ * signed in, and the plain key never rides the wire to this page.
290
+ *
291
+ * Deliberately does NOT adopt the bl CLI's stored login: that path can pair
292
+ * one account's key with another account's workspace id, and nothing would
293
+ * flag the mismatch until a knowledge-base call fails.
294
+ */
295
+ async autofill() {
296
+ const phase = this.store.getSnapshot().autofill;
297
+ if (phase === "running" || phase === "awaitingLogin") return;
298
+ this.store.update((draft) => {
299
+ draft.autofill = "running";
300
+ draft.autofillLoginUrl = void 0;
301
+ });
302
+ await this.runConsoleLogin();
303
+ await this.fetchSettings();
304
+ await this.read();
305
+ }
306
+ /**
307
+ * Ask the Host to open the console login page, then poll for the outcome.
308
+ * The Host persists the credentials itself when the callback lands, always
309
+ * requesting a freshly issued key — so the key and the workspace id both come
310
+ * from the account signing in.
311
+ */
312
+ async runConsoleLogin() {
313
+ let started;
314
+ try {
315
+ started = await this.postAutofill("login");
316
+ } catch (_routeFailure) {
317
+ this.store.update((draft) => {
318
+ draft.autofill = "failed";
319
+ });
320
+ return;
321
+ }
322
+ if (started.status !== "started" && started.status !== "already-running") {
323
+ this.store.update((draft) => {
324
+ draft.autofill = "failed";
325
+ });
326
+ return;
327
+ }
328
+ this.store.update((draft) => {
329
+ draft.autofill = "awaitingLogin";
330
+ draft.autofillLoginUrl = started.loginUrl;
331
+ });
332
+ await this.pollConsoleLogin();
333
+ }
334
+ /**
335
+ * Poll the Host until the console login resolves. Bounded so a login the
336
+ * user abandons does not leave the button spinning forever; the Host keeps
337
+ * its own (longer) timeout, so a late callback still persists and shows up
338
+ * on the next page read.
339
+ */
340
+ async pollConsoleLogin() {
341
+ const deadline = Date.now() + 3e5;
342
+ while (Date.now() < deadline) {
343
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
344
+ let phase;
345
+ try {
346
+ phase = (await this.postAutofill("loginStatus")).phase;
347
+ } catch (_pollFailure) {
348
+ continue;
349
+ }
350
+ if (phase === "done") {
351
+ this.store.update((draft) => {
352
+ draft.autofill = "done";
353
+ draft.autofillLoginUrl = void 0;
354
+ });
355
+ return;
356
+ }
357
+ if (phase === "failed") {
358
+ this.store.update((draft) => {
359
+ draft.autofill = "failed";
360
+ draft.autofillLoginUrl = void 0;
361
+ });
362
+ return;
363
+ }
364
+ }
365
+ this.store.update((draft) => {
366
+ draft.autofill = "failed";
367
+ });
368
+ }
369
+ /**
370
+ * Remove the stored default service from every writable layer — the
371
+ * settings user layer AND the credential store, so the fallback chain does
372
+ * not resurrect the value the user just cleared. Both removals are
373
+ * idempotent; the credential unset is skipped when nothing is stored there.
374
+ * @param key - which default service credential to clear.
375
+ */
376
+ async clearDefaultAgent(key) {
377
+ const settingsField = key === "BAILIAN_DEFAULT_RETRIEVE_AGENT_ID" ? "defaultRetrieveAgentId" : "defaultChatAgentId";
378
+ const state = this.store.getSnapshot();
379
+ if (state.clearing) return;
380
+ this.store.update((draft) => {
381
+ draft.clearing = true;
382
+ });
383
+ let failed = false;
384
+ if (state.settings.status === "ready") try {
385
+ await this.saveSettings({ [settingsField]: null });
386
+ } catch (_settingsWriteFailure) {
387
+ failed = true;
388
+ }
389
+ if (state.credentials[key].configured) try {
390
+ if (!(await this.api.credentials.unset({ ref: key })).result.ok) failed = true;
391
+ } catch (_credentialWriteFailure) {
392
+ failed = true;
393
+ }
394
+ this.store.update((draft) => {
395
+ draft.clearing = false;
396
+ draft.failed = failed;
397
+ draft.drafts[key] = void 0;
398
+ });
399
+ await this.fetchSettings();
400
+ await this.read();
401
+ }
402
+ /**
403
+ * Re-read after the Host reports a change to a reference this page watches.
404
+ *
405
+ * A value can be written from somewhere else — the Models page addresses
406
+ * DASHSCOPE_API_KEY too, and the file store accepts external edits — so
407
+ * without this the badges keep reporting a state the Host already replaced.
408
+ * (Settings-document changes reach the page through the scope instead.)
409
+ * @param ref - the reference the Host reports as changed.
410
+ */
411
+ refresh(ref) {
412
+ if (!BAILIAN_CARD_REFS.includes(ref)) return;
413
+ this.read();
414
+ }
415
+ /**
416
+ * Build the face the page's slot registration injects.
417
+ * @returns the page's snapshot and its actions.
418
+ */
419
+ inject() {
420
+ return {
421
+ hooks: { bailianCard: this.store },
422
+ edit: (key, text) => {
423
+ this.edit(key, text);
424
+ },
425
+ save: () => this.save(),
426
+ discard: () => {
427
+ this.discard();
428
+ },
429
+ clearDefaultAgent: (key) => this.clearDefaultAgent(key),
430
+ autofill: () => this.autofill(),
431
+ refreshServices: () => this.refreshServices(),
432
+ selectDefaultAgent: (scene, agentId) => this.selectDefaultAgent(scene, agentId)
433
+ };
434
+ }
435
+ /**
436
+ * Post one autofill action to the Host bridge route.
437
+ * @param action - `login` starts the console browser flow; `loginStatus`
438
+ * reads that flow's progress.
439
+ * @returns the route's JSON answer.
440
+ */
441
+ async postAutofill(action) {
442
+ const resp = await fetch("/bailian-kb/autofill", {
443
+ method: "POST",
444
+ headers: { "Content-Type": "application/json" },
445
+ body: JSON.stringify({ action })
446
+ });
447
+ if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
448
+ return resp.json();
449
+ }
450
+ /**
451
+ * Send a settings patch to the Host bridge route. `null`-valued keys are
452
+ * removals (the field falls back to the entry config and then the
453
+ * credential store); other values are merged into the user layer.
454
+ * @param patch - the partial settings update.
455
+ */
456
+ async saveSettings(patch) {
457
+ const resp = await fetch("/bailian-kb/settings", {
458
+ method: "POST",
459
+ headers: { "Content-Type": "application/json" },
460
+ body: JSON.stringify(patch)
461
+ });
462
+ if (!resp.ok) {
463
+ const body = await resp.json().catch(() => ({}));
464
+ throw new Error(body.error ?? `HTTP ${resp.status}`);
465
+ }
466
+ }
467
+ /**
468
+ * Ask the credentials domain about all three references and publish the
469
+ * answer. A failed read keeps the last known state: the page stays usable
470
+ * and a write still reaches the Host.
471
+ */
472
+ async read() {
473
+ let response;
474
+ try {
475
+ response = await this.api.credentials.describe({ refs: [...BAILIAN_CARD_REFS] });
476
+ } catch (_credentialReadFailure) {
477
+ return;
478
+ }
479
+ if (!response.result.ok) return;
480
+ const view = response.result.value.credentials;
481
+ this.store.update((draft) => {
482
+ for (const ref of BAILIAN_CARD_REFS) draft.credentials[ref] = {
483
+ configured: view[ref]?.configured ?? false,
484
+ writable: view[ref]?.writable ?? true
485
+ };
486
+ });
487
+ }
488
+ };
489
+ //#endregion
490
+ //#region \0dsh-css:/Users/zeyufeng/Documents/Code/workspace/cli/packages/bailian-kb-dsh/src/web/BailianCard.module.css.mjs
491
+ const css = "._0Ot3vW_section{max-width:720px;color:var(--dsw-alias-label-primary);flex-direction:column;gap:12px;display:flex}._0Ot3vW_headRow{align-items:center;gap:10px;display:flex}._0Ot3vW_title{color:var(--dsw-alias-label-primary);margin:0;font-size:16px;font-weight:500;line-height:24px}._0Ot3vW_intro{color:var(--dsw-alias-label-tertiary);margin:0;font-size:14px;line-height:22px}._0Ot3vW_form{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;margin-top:12px;padding:4px 16px 12px}._0Ot3vW_autofillRow{align-items:center;gap:10px;display:flex}._0Ot3vW_pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}._0Ot3vW_notice{color:var(--dsw-alias-state-warn-label);margin:8px 0 0;font-size:12px;line-height:18px}._0Ot3vW_field{flex-direction:column;gap:6px;padding:12px 0;display:flex}._0Ot3vW_field+._0Ot3vW_field{border-top:1px solid var(--dsw-alias-border-l2)}._0Ot3vW_head{align-items:center;gap:8px;display:flex}._0Ot3vW_label{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:1.5}._0Ot3vW_labelWrap{flex:1;align-items:center;gap:8px;min-width:0;display:flex}._0Ot3vW_getLink{color:var(--dsw-alias-brand-primary);white-space:nowrap;flex:none;font-size:12px;line-height:1.5;text-decoration:none}._0Ot3vW_getLink:hover{text-decoration:underline}._0Ot3vW_badges{align-items:center;gap:8px;display:inline-flex}._0Ot3vW_badge{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}._0Ot3vW_badgeSuccess{white-space:nowrap;background:var(--dsw-alias-state-success-tertiary);color:var(--dsw-alias-state-success-primary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}._0Ot3vW_badgeMuted{white-space:nowrap;color:var(--dsw-alias-label-tertiary);border-radius:999px;padding:1px 8px;font-size:11px;line-height:17px}._0Ot3vW_clear{font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;padding:0;font-size:12px;line-height:1.5}._0Ot3vW_clear:hover:not(:disabled){color:var(--dsw-alias-label-primary)}._0Ot3vW_clear:disabled{cursor:default}._0Ot3vW_input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}._0Ot3vW_input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}._0Ot3vW_input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}._0Ot3vW_hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}._0Ot3vW_autofillNoticeSuccess{color:var(--dsw-alias-state-success-primary);margin:0;font-size:12px;line-height:1.5}._0Ot3vW_advancedSection{border-top:none}._0Ot3vW_field+._0Ot3vW_advancedSection,._0Ot3vW_notice+._0Ot3vW_advancedSection{border-top:1px solid var(--dsw-alias-border-l2)}._0Ot3vW_advancedToggle{width:100%;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;background:0 0;border:none;justify-content:space-between;align-items:center;padding:12px 0;font-size:13px;font-weight:500;line-height:1.5;display:flex}._0Ot3vW_advancedToggle:hover{color:var(--dsw-alias-label-secondary)}._0Ot3vW_advancedToggle:after{content:\"\";border-bottom:1.5px solid;border-right:1.5px solid;width:6px;height:6px;transition:transform .2s;display:inline-block;transform:translateY(-2px)rotate(45deg)}._0Ot3vW_advancedToggle[aria-expanded=true]:after{transform:translateY(1px)rotate(-135deg)}._0Ot3vW_advancedFields{flex-direction:column;display:flex}._0Ot3vW_advancedFields ._0Ot3vW_field:first-child{border-top:1px solid var(--dsw-alias-border-l2);padding-top:0}._0Ot3vW_footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 0;display:flex}._0Ot3vW_failed{min-width:0;color:var(--dsw-alias-label-error);flex:1;margin:0;font-size:12px;line-height:1.5}._0Ot3vW_discard,._0Ot3vW_save{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}._0Ot3vW_discard{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}._0Ot3vW_discard:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}._0Ot3vW_save{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}._0Ot3vW_discard:disabled,._0Ot3vW_save:disabled{opacity:.4;cursor:default}._0Ot3vW_discard:focus-visible,._0Ot3vW_save:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}";
492
+ const tagId = "bailian-kb-dsh/BailianCard.module.css";
493
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
494
+ const tag = document.createElement("style");
495
+ tag.dataset.plugin = "bailian-kb-dsh";
496
+ tag.dataset.pluginCss = tagId;
497
+ tag.textContent = css;
498
+ document.head.appendChild(tag);
499
+ }
500
+ var BailianCard_module_css_default = {
501
+ "autofillRow": "_0Ot3vW_autofillRow",
502
+ "failed": "_0Ot3vW_failed",
503
+ "footer": "_0Ot3vW_footer",
504
+ "field": "_0Ot3vW_field",
505
+ "badge": "_0Ot3vW_badge",
506
+ "intro": "_0Ot3vW_intro",
507
+ "advancedSection": "_0Ot3vW_advancedSection",
508
+ "labelWrap": "_0Ot3vW_labelWrap",
509
+ "advancedToggle": "_0Ot3vW_advancedToggle",
510
+ "advancedFields": "_0Ot3vW_advancedFields",
511
+ "clear": "_0Ot3vW_clear",
512
+ "save": "_0Ot3vW_save",
513
+ "pending": "_0Ot3vW_pending",
514
+ "form": "_0Ot3vW_form",
515
+ "getLink": "_0Ot3vW_getLink",
516
+ "head": "_0Ot3vW_head",
517
+ "badgeSuccess": "_0Ot3vW_badgeSuccess",
518
+ "input": "_0Ot3vW_input",
519
+ "section": "_0Ot3vW_section",
520
+ "title": "_0Ot3vW_title",
521
+ "headRow": "_0Ot3vW_headRow",
522
+ "label": "_0Ot3vW_label",
523
+ "notice": "_0Ot3vW_notice",
524
+ "badgeMuted": "_0Ot3vW_badgeMuted",
525
+ "hint": "_0Ot3vW_hint",
526
+ "autofillNoticeSuccess": "_0Ot3vW_autofillNoticeSuccess",
527
+ "discard": "_0Ot3vW_discard",
528
+ "badges": "_0Ot3vW_badges"
529
+ };
530
+ //#endregion
531
+ //#region src/web/BailianCard.tsx
532
+ /**
533
+ * The Bailian knowledge-base settings page: one section page in the
534
+ * Settings left nav. The workspace, default-retrieval-service and
535
+ * default-chat-service ids echo from the `bailian-kb` settings section
536
+ * while the scope is ready (clearing one falls back down the resolution
537
+ * chain), and degrade to write-only credential controls otherwise; the
538
+ * API key is always write-only — it drafts behind a password mask,
539
+ * starts blank, and reports only configured/unconfigured.
540
+ */
541
+ /** Bailian console URL that lets the user create or copy an API key. */
542
+ const BAILIAN_CONSOLE_API_KEY_URL = "https://bailian.console.aliyun.com/cn-beijing?tab=globalset#/efm/api_key";
543
+ const ADVANCED_FIELDS = [{
544
+ key: "DASHSCOPE_API_KEY",
545
+ labelKey: "apiKey",
546
+ getKey: "apiKeyGet",
547
+ hintKey: "apiKeyHint",
548
+ fallbackHintKey: "apiKeyHint",
549
+ setKey: "apiKeySet",
550
+ unsetKey: "apiKeyUnset",
551
+ secret: true,
552
+ advanced: true,
553
+ getUrl: BAILIAN_CONSOLE_API_KEY_URL
554
+ }, {
555
+ key: "BAILIAN_WORKSPACE_ID",
556
+ labelKey: "workspaceId",
557
+ getKey: "workspaceIdGet",
558
+ hintKey: "workspaceIdHint",
559
+ fallbackHintKey: "workspaceIdHintFallback",
560
+ setKey: "workspaceIdSet",
561
+ unsetKey: "workspaceIdUnset",
562
+ secret: false,
563
+ advanced: true,
564
+ getUrl: BAILIAN_CONSOLE_API_KEY_URL
565
+ }].filter((field) => field.advanced);
566
+ /** Whether both the API key and the workspace id already hold values. */
567
+ function fullyConfigured(state) {
568
+ const apiKeyConfigured = state.credentials.DASHSCOPE_API_KEY.configured;
569
+ const workspaceConfigured = state.credentials.BAILIAN_WORKSPACE_ID.configured || echoedValue(state, "BAILIAN_WORKSPACE_ID") !== "";
570
+ return apiKeyConfigured && workspaceConfigured;
571
+ }
572
+ /**
573
+ * Render the Bailian section page.
574
+ * @param props - locale copy, the page snapshot, and its actions.
575
+ * @returns the section page.
576
+ */
577
+ function BailianCard(props) {
578
+ const { t } = props;
579
+ const [advancedOpen, setAdvancedOpen] = (0, react.useState)(false);
580
+ const state = props.useBailianCard((snapshot) => snapshot);
581
+ const dirty = dirtyOf(state);
582
+ const busy = state.saving || state.clearing;
583
+ const autofillBusy = state.autofill === "running" || state.autofill === "awaitingLogin";
584
+ let autofillNotice;
585
+ let autofillNoticeSuccess = false;
586
+ if (state.autofill === "done") {
587
+ autofillNotice = "autofillDone";
588
+ autofillNoticeSuccess = true;
589
+ } else if (state.autofill === "awaitingLogin") autofillNotice = "autofillAwaitingLogin";
590
+ else if (state.autofill === "failed") autofillNotice = "autofillFailed";
591
+ else if (fullyConfigured(state)) {
592
+ autofillNotice = "autofillConfigured";
593
+ autofillNoticeSuccess = true;
594
+ }
595
+ const renderField = (field) => {
596
+ const credential = state.credentials[field.key];
597
+ const echo = SETTINGS_FIELDS[field.key] !== void 0 && state.settings.status === "ready";
598
+ const echoed = echoedValue(state, field.key);
599
+ const value = state.drafts[field.key] ?? (echo ? echoed : "");
600
+ const disabled = busy || (echo ? !state.settings.writable : !credential.writable);
601
+ const badge = echo ? echoed !== "" ? void 0 : credential.configured ? {
602
+ label: t("fallbackConfigured"),
603
+ set: true
604
+ } : {
605
+ label: t(field.unsetKey),
606
+ set: false
607
+ } : credential.configured ? {
608
+ label: credential.writable ? t(field.setKey) : t("fromEnv"),
609
+ set: true
610
+ } : {
611
+ label: t(field.unsetKey),
612
+ set: false
613
+ };
614
+ const showClear = (field.key === "BAILIAN_DEFAULT_RETRIEVE_AGENT_ID" || field.key === "BAILIAN_DEFAULT_CHAT_AGENT_ID") && (credential.configured || echo && echoed !== "");
615
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
616
+ className: BailianCard_module_css_default.field,
617
+ children: [
618
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
619
+ className: BailianCard_module_css_default.head,
620
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
621
+ className: BailianCard_module_css_default.labelWrap,
622
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
623
+ className: BailianCard_module_css_default.label,
624
+ htmlFor: `bailian-kb-${field.key}`,
625
+ children: t(field.labelKey)
626
+ }), field.getUrl !== void 0 && field.getKey !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
627
+ className: BailianCard_module_css_default.getLink,
628
+ href: field.getUrl,
629
+ target: "_blank",
630
+ rel: "noreferrer",
631
+ children: t(field.getKey)
632
+ }) : null]
633
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
634
+ className: BailianCard_module_css_default.badges,
635
+ children: [showClear ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
636
+ type: "button",
637
+ className: BailianCard_module_css_default.clear,
638
+ disabled: busy,
639
+ onClick: () => {
640
+ props.clearDefaultAgent(field.key);
641
+ },
642
+ children: t(state.clearing ? "clearing" : "clear")
643
+ }) : null, badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
644
+ className: badge.set ? BailianCard_module_css_default.badgeSuccess : BailianCard_module_css_default.badgeMuted,
645
+ children: badge.label
646
+ }) : null]
647
+ })]
648
+ }),
649
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
650
+ id: `bailian-kb-${field.key}`,
651
+ className: BailianCard_module_css_default.input,
652
+ type: field.secret ? "password" : "text",
653
+ autoComplete: "off",
654
+ value,
655
+ disabled,
656
+ onChange: (event) => {
657
+ props.edit(field.key, event.target.value);
658
+ }
659
+ }),
660
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
661
+ className: BailianCard_module_css_default.hint,
662
+ children: t(echo ? field.hintKey : field.fallbackHintKey)
663
+ })
664
+ ]
665
+ }, field.key);
666
+ };
667
+ /**
668
+ * One scene's default-service picker — the sole control for that setting.
669
+ *
670
+ * The cached list is the menu, but a value already pinned outside this list
671
+ * (the fetch is capped, so an older service can be absent) is prepended as its
672
+ * own option: dropping it would make the panel silently forget a live setting.
673
+ */
674
+ function renderPicker(scene) {
675
+ const cache = state.cache;
676
+ const entries = scene === "search" ? cache.search : cache.chat;
677
+ const pinned = scene === "search" ? state.settings.values.defaultRetrieveAgentId : state.settings.values.defaultChatAgentId;
678
+ const isPinned = pinned !== void 0 && pinned !== "";
679
+ const pinnedIsListed = isPinned && entries.some((entry) => entry.agent_id === pinned);
680
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
681
+ className: BailianCard_module_css_default.field,
682
+ children: [
683
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
684
+ className: BailianCard_module_css_default.head,
685
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
686
+ className: BailianCard_module_css_default.label,
687
+ children: t(scene === "search" ? "retrieveAgentId" : "chatAgentId")
688
+ }), isPinned ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
689
+ type: "button",
690
+ className: BailianCard_module_css_default.clear,
691
+ disabled: busy,
692
+ onClick: () => {
693
+ props.selectDefaultAgent(scene, void 0);
694
+ },
695
+ children: t(state.clearing ? "clearing" : "pickerClear")
696
+ }) : null]
697
+ }),
698
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
699
+ className: BailianCard_module_css_default.input,
700
+ value: pinned ?? "",
701
+ disabled: busy || cache.status !== "ready",
702
+ onChange: (event) => {
703
+ const next = event.target.value;
704
+ props.selectDefaultAgent(scene, next === "" ? void 0 : next);
705
+ },
706
+ children: [
707
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
708
+ value: "",
709
+ children: t("pickerNone")
710
+ }),
711
+ isPinned && !pinnedIsListed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
712
+ value: pinned,
713
+ children: pinned
714
+ }) : null,
715
+ entries.map((entry) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
716
+ value: entry.agent_id,
717
+ children: entry.agent_name === "" ? entry.agent_id : entry.agent_name
718
+ }, entry.agent_id))
719
+ ]
720
+ }),
721
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
722
+ className: BailianCard_module_css_default.hint,
723
+ children: entries.length === 0 ? t("cacheEmpty") : t(scene === "search" ? "retrieveAgentIdHint" : "chatAgentIdHint")
724
+ })
725
+ ]
726
+ });
727
+ }
728
+ /**
729
+ * The service-cache diagnostics: last fetch, per-scene counts, refresh.
730
+ *
731
+ * This stays OUTSIDE the advanced fold on purpose. It is the answer to "why did
732
+ * the agent stop retrieving" — an empty workspace and a stale list look
733
+ * identical from the outside, and before this the only way to tell them apart
734
+ * was reading the cache JSON off disk.
735
+ */
736
+ function renderCacheStatus() {
737
+ const cache = state.cache;
738
+ if (cache.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
739
+ className: BailianCard_module_css_default.hint,
740
+ children: t("cacheLoading")
741
+ });
742
+ if (cache.status === "unconfigured") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
743
+ className: BailianCard_module_css_default.notice,
744
+ children: t("cacheUnconfigured")
745
+ });
746
+ if (cache.status === "unavailable") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
747
+ className: BailianCard_module_css_default.notice,
748
+ children: t("cacheUnavailable")
749
+ });
750
+ const fetched = cache.fetchedAt === void 0 ? t("cacheNever") : new Date(cache.fetchedAt).toLocaleString();
751
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
752
+ className: BailianCard_module_css_default.field,
753
+ children: [
754
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
755
+ className: BailianCard_module_css_default.head,
756
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
757
+ className: BailianCard_module_css_default.label,
758
+ children: t("cacheTitle")
759
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
760
+ type: "button",
761
+ className: BailianCard_module_css_default.clear,
762
+ disabled: cache.refreshing,
763
+ onClick: () => {
764
+ props.refreshServices();
765
+ },
766
+ children: t(cache.refreshing ? "cacheRefreshing" : "cacheRefresh")
767
+ })]
768
+ }),
769
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
770
+ className: BailianCard_module_css_default.hint,
771
+ children: [
772
+ t("cacheFetchedAt"),
773
+ ": ",
774
+ fetched,
775
+ cache.stale ? ` (${t("cacheStale")})` : "",
776
+ " · ",
777
+ t("cacheSearchCount"),
778
+ ": ",
779
+ cache.searchCount,
780
+ " · ",
781
+ t("cacheChatCount"),
782
+ ": ",
783
+ cache.chatCount
784
+ ]
785
+ }),
786
+ cache.truncated ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
787
+ className: BailianCard_module_css_default.notice,
788
+ children: t("cacheTruncated")
789
+ }) : null,
790
+ cache.searchCount === 0 && cache.chatCount === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
791
+ className: BailianCard_module_css_default.notice,
792
+ children: t("cacheEmpty")
793
+ }) : null,
794
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
795
+ className: BailianCard_module_css_default.hint,
796
+ children: t("cacheHint")
797
+ })
798
+ ]
799
+ });
800
+ }
801
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
802
+ className: BailianCard_module_css_default.section,
803
+ children: [
804
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
805
+ className: BailianCard_module_css_default.headRow,
806
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
807
+ className: BailianCard_module_css_default.title,
808
+ children: t("title")
809
+ }), dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
810
+ className: BailianCard_module_css_default.pending,
811
+ children: t("unsaved")
812
+ }) : null]
813
+ }),
814
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
815
+ className: BailianCard_module_css_default.intro,
816
+ children: t("description")
817
+ }),
818
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
819
+ className: BailianCard_module_css_default.autofillRow,
820
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
821
+ type: "button",
822
+ className: BailianCard_module_css_default.discard,
823
+ disabled: busy || autofillBusy,
824
+ onClick: () => {
825
+ props.autofill();
826
+ },
827
+ children: t(state.autofill === "running" ? "autofilling" : "autofill")
828
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
829
+ className: autofillNoticeSuccess ? BailianCard_module_css_default.autofillNoticeSuccess : BailianCard_module_css_default.hint,
830
+ children: [autofillNotice !== void 0 ? t(autofillNotice) : t("autofillHint"), state.autofillLoginUrl !== void 0 && state.autofillLoginUrl !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [" ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
831
+ href: state.autofillLoginUrl,
832
+ target: "_blank",
833
+ rel: "noreferrer",
834
+ children: t("autofillOpenUrl")
835
+ })] }) : null]
836
+ })]
837
+ }),
838
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
839
+ className: BailianCard_module_css_default.form,
840
+ children: [
841
+ state.settings.status === "unavailable" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
842
+ className: BailianCard_module_css_default.notice,
843
+ children: t("settingsUnavailable")
844
+ }) : null,
845
+ renderCacheStatus(),
846
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
847
+ className: BailianCard_module_css_default.advancedSection,
848
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
849
+ type: "button",
850
+ className: BailianCard_module_css_default.advancedToggle,
851
+ "aria-expanded": advancedOpen,
852
+ onClick: () => {
853
+ setAdvancedOpen((open) => !open);
854
+ },
855
+ children: t("advancedConfig")
856
+ }), advancedOpen ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
857
+ className: BailianCard_module_css_default.advancedFields,
858
+ children: [
859
+ ADVANCED_FIELDS.map(renderField),
860
+ renderPicker("search"),
861
+ renderPicker("chat"),
862
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
863
+ className: BailianCard_module_css_default.footer,
864
+ children: [
865
+ state.failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
866
+ className: BailianCard_module_css_default.failed,
867
+ role: "status",
868
+ children: t("saveFailed")
869
+ }) : null,
870
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
871
+ type: "button",
872
+ className: BailianCard_module_css_default.discard,
873
+ disabled: !dirty || busy,
874
+ onClick: props.discard,
875
+ children: t("discard")
876
+ }),
877
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
878
+ type: "button",
879
+ className: BailianCard_module_css_default.save,
880
+ disabled: !dirty || busy,
881
+ onClick: () => {
882
+ props.save();
883
+ },
884
+ children: t(state.saving ? "saving" : "save")
885
+ })
886
+ ]
887
+ })
888
+ ]
889
+ }) : null]
890
+ })
891
+ ]
892
+ })
893
+ ]
894
+ });
895
+ }
896
+ //#endregion
897
+ //#region src/web/locales.ts
898
+ /** English copy. */
899
+ const en = {
900
+ nav: "Bailian KB",
901
+ title: "Bailian knowledge base",
902
+ description: "Account for the knowledge tools: API key, workspace, and default services.",
903
+ settingsUnavailable: "The settings document is not reachable from this browser; values below are write-only and stored in the credential store.",
904
+ fallbackConfigured: "Falling back to a configured credential-store value.",
905
+ apiKey: "API key",
906
+ apiKeyHint: "DashScope API key. Stored in the credentials store and never shown again; leave blank to keep the current one.",
907
+ apiKeySet: "A key is configured.",
908
+ apiKeyUnset: "No key is configured; knowledge tools fail until one is.",
909
+ apiKeyGet: "Get",
910
+ workspaceId: "Workspace id",
911
+ workspaceIdHint: "Bailian workspace id — the subdomain of your endpoints. Stored in the settings document; clear and save to fall back to the credential store.",
912
+ workspaceIdHintFallback: "Bailian workspace id — the subdomain of your endpoints. Leave blank to keep the current one.",
913
+ workspaceIdSet: "A workspace is configured.",
914
+ workspaceIdUnset: "No workspace is configured; knowledge tools fail until one is.",
915
+ workspaceIdGet: "Get",
916
+ retrieveAgentId: "Default retrieval service",
917
+ retrieveAgentIdHint: "The agent_id kb_search falls back to. Left unset, the injected catalog lists every deployed service instead.",
918
+ chatAgentId: "Default Q&A service",
919
+ chatAgentIdHint: "The agent_id kb_chat falls back to. Left unset, the injected catalog lists every deployed service instead.",
920
+ fromEnv: "Set by the environment (read-only here)",
921
+ clear: "Clear default",
922
+ clearing: "Clearing…",
923
+ save: "Save",
924
+ saving: "Saving…",
925
+ discard: "Discard",
926
+ unsaved: "Unsaved",
927
+ saveFailed: "The Host did not accept these values; they were left for you to correct.",
928
+ advancedConfig: "Advanced configuration",
929
+ autofill: "Fetch from console login",
930
+ autofilling: "Starting…",
931
+ autofillHint: "Sign in to the Bailian console to fill in that account’s API key and workspace id.",
932
+ autofillDone: "Credentials adopted; the fields below reflect the new values.",
933
+ autofillAwaitingLogin: "Waiting for the Bailian console login to finish in a browser on the host machine…",
934
+ autofillOpenUrl: "Open the login page manually",
935
+ autofillFailed: "Auto-fill failed — the credential may be locked by an environment variable, the Host refused the write, or the login was abandoned.",
936
+ autofillConfigured: "Configured. Click button to fetch this account’s API key and workspace id again.",
937
+ cacheTitle: "Retrieval service cache",
938
+ cacheHint: "The service list injected into each conversation. Refreshes on its own; refresh here when you have just created a service and want it picked up now.",
939
+ cacheLoading: "Reading…",
940
+ cacheUnconfigured: "Set a workspace id first.",
941
+ cacheUnavailable: "Not reachable from this browser.",
942
+ cacheFetchedAt: "Last fetched",
943
+ cacheNever: "never",
944
+ cacheStale: "refresh due",
945
+ cacheSearchCount: "Retrieval services",
946
+ cacheChatCount: "Q&A services",
947
+ cacheTruncated: "List truncated — the workspace holds more than were fetched.",
948
+ cacheEmpty: "No deployed services cached. If you just created one, refresh.",
949
+ cacheRefresh: "Refresh",
950
+ cacheRefreshing: "Refreshing…",
951
+ pickerNone: "Not set — the full list is injected instead",
952
+ pickerClear: "Clear"
953
+ };
954
+ /** Simplified Chinese copy. */
955
+ const zh = {
956
+ nav: "百炼知识库",
957
+ title: "百炼知识库",
958
+ description: "知识库工具的账号信息:API 密钥、工作空间与默认服务。",
959
+ settingsUnavailable: "当前浏览器无法访问设置文档;以下字段仅可写入凭据存储,不回显。",
960
+ fallbackConfigured: "回退:凭据存储中已有值。",
961
+ apiKey: "API 密钥",
962
+ apiKeyHint: "DashScope API key。保存在凭据存储中且不会再次显示;留空表示保持当前值。",
963
+ apiKeySet: "已配置密钥。",
964
+ apiKeyUnset: "未配置密钥;配置前知识库工具不可用。",
965
+ apiKeyGet: "去获取",
966
+ workspaceId: "工作空间 ID",
967
+ workspaceIdHint: "百炼工作空间 ID,即终端节点地址的子域名。存入设置文档;清空并保存则回退到凭据存储。",
968
+ workspaceIdHintFallback: "百炼工作空间 ID,即终端节点地址的子域名。留空表示保持当前值。",
969
+ workspaceIdSet: "已配置工作空间。",
970
+ workspaceIdUnset: "未配置工作空间;配置前知识库工具不可用。",
971
+ workspaceIdGet: "去获取",
972
+ retrieveAgentId: "默认检索服务",
973
+ retrieveAgentIdHint: "kb_search 缺省使用的 agent_id。不设置时,注入的清单会列出全部已部署服务。",
974
+ chatAgentId: "默认对话服务",
975
+ chatAgentIdHint: "kb_chat 缺省使用的 agent_id。不设置时,注入的清单会列出全部已部署服务。",
976
+ fromEnv: "来自环境变量(此处只读)",
977
+ clear: "清除默认",
978
+ clearing: "清除中…",
979
+ save: "保存",
980
+ saving: "保存中…",
981
+ discard: "放弃",
982
+ unsaved: "未保存",
983
+ saveFailed: "宿主未接受这些值,已保留供你修改。",
984
+ advancedConfig: "高级配置",
985
+ autofill: "自动获取",
986
+ autofilling: "启动中…",
987
+ autofillHint: "登录百炼控制台,自动填入该账号的 API 密钥与工作空间 ID。",
988
+ autofillDone: "已回填凭据,下方字段已更新。",
989
+ autofillAwaitingLogin: "等待在宿主机浏览器中完成百炼控制台登录…",
990
+ autofillOpenUrl: "手动打开登录页",
991
+ autofillFailed: "自动获取失败——凭据可能被环境变量锁定、宿主拒绝了写入,或登录未完成。",
992
+ autofillConfigured: "已配置完成,点击按钮重新获取该账号的 API 密钥与工作空间 ID。",
993
+ cacheTitle: "检索服务缓存",
994
+ cacheHint: "注入到每次对话的服务清单。会自动刷新;刚建完服务想立即生效时在这里刷一下。",
995
+ cacheLoading: "读取中…",
996
+ cacheUnconfigured: "请先设置工作空间 ID。",
997
+ cacheUnavailable: "当前浏览器无法访问。",
998
+ cacheFetchedAt: "上次拉取",
999
+ cacheNever: "尚未拉取",
1000
+ cacheStale: "待刷新",
1001
+ cacheSearchCount: "检索服务",
1002
+ cacheChatCount: "问答服务",
1003
+ cacheTruncated: "清单已截断 —— 工作空间里的服务多于已拉取的数量。",
1004
+ cacheEmpty: "缓存里没有已部署的服务。如果刚创建过,请刷新。",
1005
+ cacheRefresh: "刷新",
1006
+ cacheRefreshing: "刷新中…",
1007
+ pickerNone: "未设置 —— 会注入完整清单",
1008
+ pickerClear: "清空"
1009
+ };
1010
+ //#endregion
1011
+ //#region src/web/index.ts
1012
+ /** Dictionary namespace owned by this plugin. */
1013
+ const NS = "tool-bailian-kb";
1014
+ /** Required services (cordis fiber inject). */
1015
+ const inject = [
1016
+ "slots",
1017
+ "locale",
1018
+ "connection",
1019
+ "remote"
1020
+ ];
1021
+ /**
1022
+ * Mount the Bailian section page into the Settings left nav.
1023
+ * @param ctx - the browser plugin context.
1024
+ */
1025
+ function apply(ctx) {
1026
+ const { api } = ctx.get("connection");
1027
+ ctx.effect(() => ctx.locale.register(NS, {
1028
+ zh,
1029
+ en
1030
+ }), "tool-bailian-kb: dictionaries");
1031
+ const t = ctx.locale.bind(NS);
1032
+ const card = new BailianCardController(api);
1033
+ ctx.effect(() => ctx.remote.$on("credentials/updated", (ref) => {
1034
+ card.refresh(ref);
1035
+ }), "tool-bailian-kb: credential invalidations");
1036
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
1037
+ name: "settings.section",
1038
+ id: "bailian-kb",
1039
+ order: 20,
1040
+ label: () => t("nav"),
1041
+ locale: NS,
1042
+ inject: () => card.inject()
1043
+ }, BailianCard));
1044
+ }
1045
+ //#endregion
1046
+ exports.apply = apply;
1047
+ exports.inject = inject;
1048
+ return module.exports;
1049
+ }
1050
+ });
1051
+
1052
+ //# sourceMappingURL=client.js.map