dsh-session-webhook 0.0.0-stage → 0.2.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,1755 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-session-webhook",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ "use strict";
7
+ var __create = Object.create;
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __getProtoOf = Object.getPrototypeOf;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
+
35
+ // src/client/main.ts
36
+ var main_exports = {};
37
+ __export(main_exports, {
38
+ __test__: () => __test__,
39
+ apply: () => apply,
40
+ inject: () => inject
41
+ });
42
+ module.exports = __toCommonJS(main_exports);
43
+
44
+ // src/client/dialog.tsx
45
+ var React = __toESM(require("react"), 1);
46
+
47
+ // src/client/rpc.ts
48
+ var RPC_ENDPOINT = "session-inject-rpc";
49
+ var RpcError = class extends Error {
50
+ code;
51
+ constructor(code, message) {
52
+ super(message);
53
+ this.name = "RpcError";
54
+ this.code = code;
55
+ }
56
+ };
57
+ function asRecord(value) {
58
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return null;
59
+ return value;
60
+ }
61
+ function messageOf(error) {
62
+ if (error !== null && typeof error === "object" && "message" in error) {
63
+ const message = error.message;
64
+ if (typeof message === "string" && message !== "") return message;
65
+ }
66
+ return String(error);
67
+ }
68
+ function isConnection(value) {
69
+ const record = asRecord(value);
70
+ if (record === null) return false;
71
+ const rpc = asRecord(record.rpc);
72
+ return rpc !== null && typeof rpc.call === "function";
73
+ }
74
+ function createRpc(ctx) {
75
+ return async function rpc(method, payload, signal) {
76
+ const connection = typeof ctx.get === "function" ? ctx.get("connection") : void 0;
77
+ if (!isConnection(connection)) {
78
+ throw new RpcError(
79
+ "connection-unavailable",
80
+ "session-inject: the browser Connection service is unavailable"
81
+ );
82
+ }
83
+ const result = await connection.rpc.call(
84
+ "/api",
85
+ RPC_ENDPOINT,
86
+ { method, payload: payload ?? {} },
87
+ signal
88
+ );
89
+ const envelope = asRecord(result);
90
+ if (envelope === null || envelope.ok !== true) {
91
+ const failure = asRecord(envelope?.error);
92
+ const code = typeof failure?.code === "string" ? failure.code : "unknown-error";
93
+ const message = typeof failure?.message === "string" ? failure.message : "management call failed";
94
+ throw new RpcError(code, message);
95
+ }
96
+ return envelope.value;
97
+ };
98
+ }
99
+
100
+ // src/client/dialog.tsx
101
+ var import_jsx_runtime = require("react/jsx-runtime");
102
+ var MODES = ["steer", "queue", "passive"];
103
+ var dialogState = { open: false, sessionId: null, displayTitle: "" };
104
+ var listeners = /* @__PURE__ */ new Set();
105
+ function subscribe(listener) {
106
+ listeners.add(listener);
107
+ return () => {
108
+ listeners.delete(listener);
109
+ };
110
+ }
111
+ function snapshot() {
112
+ return dialogState;
113
+ }
114
+ function emit() {
115
+ for (const listener of [...listeners]) listener();
116
+ }
117
+ function openDialog(sessionId, displayTitle) {
118
+ dialogState = { open: true, sessionId, displayTitle };
119
+ emit();
120
+ }
121
+ function closeDialog() {
122
+ dialogState = { open: false, sessionId: dialogState.sessionId, displayTitle: "" };
123
+ emit();
124
+ }
125
+ function useDialog() {
126
+ return React.useSyncExternalStore(subscribe, snapshot, snapshot);
127
+ }
128
+ function lastUsedLabel(value, t) {
129
+ if (value === null || value === "") return t("dialog.neverUsed");
130
+ try {
131
+ return t("dialog.lastUsed", { time: new Date(value).toLocaleString() });
132
+ } catch {
133
+ return value;
134
+ }
135
+ }
136
+ async function copyText(text) {
137
+ try {
138
+ if (navigator.clipboard?.writeText) {
139
+ await navigator.clipboard.writeText(text);
140
+ return true;
141
+ }
142
+ } catch {
143
+ }
144
+ try {
145
+ const area = document.createElement("textarea");
146
+ area.value = text;
147
+ area.style.position = "fixed";
148
+ area.style.opacity = "0";
149
+ document.body.appendChild(area);
150
+ area.select();
151
+ const ok = document.execCommand("copy");
152
+ document.body.removeChild(area);
153
+ return ok;
154
+ } catch {
155
+ return false;
156
+ }
157
+ }
158
+ function readMode(value) {
159
+ return value === "queue" || value === "passive" ? value : "steer";
160
+ }
161
+ function readHook(value) {
162
+ const record = asRecord(value);
163
+ if (record === null || typeof record.id !== "string" || typeof record.name !== "string") return null;
164
+ const tags = [];
165
+ if (Array.isArray(record.tags)) {
166
+ for (const tag of record.tags) if (typeof tag === "string") tags.push(tag);
167
+ }
168
+ return {
169
+ id: record.id,
170
+ name: record.name,
171
+ tags,
172
+ defaultMode: readMode(record.defaultMode),
173
+ enabled: record.enabled !== false,
174
+ maskedUrl: typeof record.maskedUrl === "string" ? record.maskedUrl : "",
175
+ lastUsedAt: typeof record.lastUsedAt === "string" ? record.lastUsedAt : null,
176
+ lastStatus: record.lastStatus === "delivered" || record.lastStatus === "failed" ? record.lastStatus : null,
177
+ deliveryCount: typeof record.deliveryCount === "number" ? record.deliveryCount : 0,
178
+ // 存量记录没有 createdBy 时按界面创建处理(与 Host 侧口径一致)。
179
+ createdBy: record.createdBy === "agent" ? "agent" : "ui",
180
+ archived: record.archived === true
181
+ };
182
+ }
183
+ function readHooks(value) {
184
+ const record = asRecord(value);
185
+ if (record === null || !Array.isArray(record.hooks)) return [];
186
+ const hooks = [];
187
+ for (const entry of record.hooks) {
188
+ const hook = readHook(entry);
189
+ if (hook !== null) hooks.push(hook);
190
+ }
191
+ return hooks;
192
+ }
193
+ function readUrlFiles(value) {
194
+ const record = asRecord(value);
195
+ if (record === null) return [];
196
+ const files = [];
197
+ for (const [name, path] of Object.entries(record)) {
198
+ if (typeof path === "string" && path !== "") files.push({ name, path });
199
+ }
200
+ return files;
201
+ }
202
+ function readCreated(value) {
203
+ const record = asRecord(value);
204
+ const hook = readHook(record?.hook);
205
+ const defaultBase = typeof record?.defaultBase === "string" ? record.defaultBase : "";
206
+ return {
207
+ hookId: hook === null ? null : hook.id,
208
+ url: typeof record?.url === "string" ? record.url : "",
209
+ defaultBase,
210
+ urlFiles: readUrlFiles(record?.urlFiles)
211
+ };
212
+ }
213
+ function IconLink() {
214
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
215
+ "svg",
216
+ {
217
+ viewBox: "0 0 16 16",
218
+ width: 14,
219
+ height: 14,
220
+ "aria-hidden": true,
221
+ fill: "none",
222
+ stroke: "currentColor",
223
+ strokeWidth: 1.4,
224
+ strokeLinecap: "round",
225
+ children: [
226
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2 8h7" }),
227
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 5 9.5 8l-3 3" }),
228
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: 10.5, y: 3.5, width: 3, height: 9, rx: 1.5 })
229
+ ]
230
+ }
231
+ );
232
+ }
233
+ function WebhookMenuItem(props) {
234
+ const menu = typeof props.useMenuOpenState === "function" ? props.useMenuOpenState() : void 0;
235
+ const setMenuOpen = Array.isArray(menu) && typeof menu[1] === "function" ? menu[1] : () => {
236
+ };
237
+ const open = props.openWebhooks ?? openDialog;
238
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
239
+ "button",
240
+ {
241
+ type: "button",
242
+ role: "menuitem",
243
+ className: "si-menu-row",
244
+ onClick: () => {
245
+ setMenuOpen(false);
246
+ open(props.sessionId, props.displayTitle ?? "");
247
+ },
248
+ children: [
249
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-menu-icon", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconLink, {}) }),
250
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-menu-label", children: props.t("menu.open") })
251
+ ]
252
+ }
253
+ );
254
+ }
255
+ function WebhookDialog(props) {
256
+ const state = useDialog();
257
+ if (!state.open || state.sessionId === null) return null;
258
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
259
+ WebhookPanel,
260
+ {
261
+ t: props.t,
262
+ rpc: props.rpc,
263
+ sessionId: state.sessionId,
264
+ displayTitle: state.displayTitle,
265
+ onClose: closeDialog
266
+ },
267
+ state.sessionId
268
+ );
269
+ }
270
+ function WebhookPanel(props) {
271
+ const { t, rpc, sessionId, displayTitle, onClose } = props;
272
+ const [hooks, setHooks] = React.useState(null);
273
+ const [error, setError] = React.useState(null);
274
+ const [busy, setBusy] = React.useState(false);
275
+ const [created, setCreated] = React.useState(null);
276
+ const [revealed, setRevealed] = React.useState({});
277
+ const [copied, setCopied] = React.useState(null);
278
+ const [name, setName] = React.useState("");
279
+ const [tags, setTags] = React.useState("");
280
+ const [mode, setMode] = React.useState("steer");
281
+ const [renaming, setRenaming] = React.useState(null);
282
+ const [renameValue, setRenameValue] = React.useState("");
283
+ const [confirming, setConfirming] = React.useState(null);
284
+ const refresh = React.useCallback(async () => {
285
+ try {
286
+ const value = await rpc("hooks/list", { sessionId });
287
+ setHooks(readHooks(value));
288
+ setError(null);
289
+ } catch (failure) {
290
+ setError(messageOf(failure));
291
+ setHooks([]);
292
+ }
293
+ }, [rpc, sessionId]);
294
+ React.useEffect(() => {
295
+ void refresh();
296
+ }, [refresh]);
297
+ React.useEffect(() => {
298
+ const onKey = (event) => {
299
+ if (event.key === "Escape") onClose();
300
+ };
301
+ window.addEventListener("keydown", onKey);
302
+ return () => window.removeEventListener("keydown", onKey);
303
+ }, [onClose]);
304
+ const guard = React.useCallback(async (operation) => {
305
+ setBusy(true);
306
+ try {
307
+ await operation();
308
+ } catch (failure) {
309
+ setError(messageOf(failure));
310
+ } finally {
311
+ setBusy(false);
312
+ }
313
+ }, []);
314
+ const create = () => {
315
+ void guard(async () => {
316
+ const value = await rpc("hooks/create", { sessionId, name: name.trim(), tags, defaultMode: mode });
317
+ setCreated(readCreated(value));
318
+ setName("");
319
+ setTags("");
320
+ await refresh();
321
+ });
322
+ };
323
+ const toggle = (hook) => {
324
+ void guard(async () => {
325
+ await rpc("hooks/update", { hookId: hook.id, enabled: !hook.enabled });
326
+ await refresh();
327
+ });
328
+ };
329
+ const revoke = (hook) => {
330
+ void guard(async () => {
331
+ await rpc("hooks/revoke", { hookId: hook.id });
332
+ setConfirming(null);
333
+ setCreated((current) => current !== null && current.hookId === hook.id ? null : current);
334
+ setRevealed((current) => {
335
+ if (!(hook.id in current)) return current;
336
+ const next = { ...current };
337
+ delete next[hook.id];
338
+ return next;
339
+ });
340
+ await refresh();
341
+ });
342
+ };
343
+ const reveal = (hook) => {
344
+ void guard(async () => {
345
+ const value = await rpc("hooks/reveal", { hookId: hook.id });
346
+ const url = asRecord(value)?.url;
347
+ if (typeof url === "string") setRevealed((current) => ({ ...current, [hook.id]: url }));
348
+ });
349
+ };
350
+ const rename = (hook) => {
351
+ void guard(async () => {
352
+ await rpc("hooks/update", { hookId: hook.id, name: renameValue.trim() });
353
+ setRenaming(null);
354
+ await refresh();
355
+ });
356
+ };
357
+ const copy = async (text, id) => {
358
+ if (await copyText(text)) {
359
+ setCopied(id);
360
+ setTimeout(() => setCopied((current) => current === id ? null : current), 1600);
361
+ }
362
+ };
363
+ const archived = hooks !== null && hooks.some((hook) => hook.archived);
364
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
365
+ "div",
366
+ {
367
+ className: "si-backdrop",
368
+ onMouseDown: (event) => {
369
+ if (event.target === event.currentTarget) onClose();
370
+ },
371
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-panel", role: "dialog", "aria-modal": "true", "aria-label": t("dialog.title"), children: [
372
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-head", children: [
373
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
374
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-title", children: t("dialog.title") }),
375
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-sub", children: `${displayTitle !== "" ? displayTitle : sessionId} · ${t("dialog.subtitle")}` })
376
+ ] }),
377
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-close", "aria-label": t("dialog.close"), onClick: onClose, children: "✕" })
378
+ ] }),
379
+ archived ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-warn", children: t("dialog.archived") }) : null,
380
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-form", children: [
381
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
382
+ "input",
383
+ {
384
+ className: "si-input si-name",
385
+ value: name,
386
+ placeholder: t("dialog.namePlaceholder"),
387
+ onChange: (event) => setName(event.target.value)
388
+ }
389
+ ),
390
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
391
+ "input",
392
+ {
393
+ className: "si-input si-tags",
394
+ value: tags,
395
+ placeholder: t("dialog.tagsPlaceholder"),
396
+ onChange: (event) => setTags(event.target.value)
397
+ }
398
+ ),
399
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-modes", role: "group", "aria-label": t("dialog.modeLabel"), children: MODES.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "si-mode-wrap", children: [
400
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
401
+ "button",
402
+ {
403
+ type: "button",
404
+ className: `si-mode${mode === entry ? " si-mode-active" : ""}`,
405
+ "aria-pressed": mode === entry,
406
+ onClick: () => setMode(entry),
407
+ children: t(`mode.${entry}.label`)
408
+ }
409
+ ),
410
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-tip", role: "tooltip", children: t(`mode.${entry}.hint`) })
411
+ ] }, entry)) }),
412
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
413
+ "button",
414
+ {
415
+ type: "button",
416
+ className: "si-btn si-btn-primary",
417
+ disabled: busy || name.trim() === "",
418
+ onClick: create,
419
+ children: t("dialog.create")
420
+ }
421
+ )
422
+ ] }),
423
+ created === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
424
+ CreatedBlock,
425
+ {
426
+ t,
427
+ created,
428
+ copied: copied === "created",
429
+ onCopy: () => {
430
+ void copy(created.url, "created");
431
+ },
432
+ onDismiss: () => setCreated(null)
433
+ }
434
+ ),
435
+ error === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-error", children: t("dialog.error", { message: error }) }),
436
+ hooks === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-empty", children: "…" }) : hooks.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-empty", children: t("dialog.empty") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-list", children: hooks.map((hook) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
437
+ Row,
438
+ {
439
+ t,
440
+ hook,
441
+ busy,
442
+ copied,
443
+ revealed,
444
+ confirming,
445
+ renaming,
446
+ renameValue,
447
+ setRenameValue,
448
+ onReveal: () => reveal(hook),
449
+ onCopy: () => {
450
+ void copy(revealed[hook.id] ?? "", hook.id);
451
+ },
452
+ onToggle: () => toggle(hook),
453
+ onAskRevoke: () => setConfirming(hook.id),
454
+ onCancelRevoke: () => setConfirming(null),
455
+ onRevoke: () => revoke(hook),
456
+ onStartRename: () => {
457
+ setRenaming(hook.id);
458
+ setRenameValue(hook.name);
459
+ },
460
+ onCancelRename: () => setRenaming(null),
461
+ onRename: () => rename(hook)
462
+ },
463
+ hook.id
464
+ )) }),
465
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-note", children: t("dialog.securityNote") })
466
+ ] })
467
+ }
468
+ );
469
+ }
470
+ function CreatedBlock(props) {
471
+ const { t, created } = props;
472
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-created", children: [
473
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: t("dialog.createdTitle") }),
474
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-created-url", children: created.url }),
475
+ created.defaultBase === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-created-base", children: t("dialog.createdBase", { name: created.defaultBase }) }),
476
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-inline", children: [
477
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", onClick: props.onCopy, children: props.copied ? t("dialog.copied") : t("dialog.copy") }),
478
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", onClick: props.onDismiss, children: t("dialog.close") })
479
+ ] }),
480
+ created.urlFiles.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-created-files", children: [
481
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: t("dialog.urlFilesTitle") }),
482
+ created.urlFiles.map((file) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-created-file", children: [
483
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-created-file-name", children: file.name }),
484
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-created-file-path", children: file.path })
485
+ ] }, file.name))
486
+ ] }) : null,
487
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: t("dialog.curlHint") }),
488
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "si-code", children: `curl -s -X POST '${created.url}' \\
489
+ -H 'content-type: application/json' \\
490
+ -d '{"text":"hello","mode":"steer","source":"curl"}'` })
491
+ ] });
492
+ }
493
+ var DIALOG_LOCALE = {
494
+ en: {
495
+ "dialog.createdBy.agent": "Created by agent",
496
+ "dialog.createdBase": "Default base: {name}",
497
+ "dialog.urlFilesTitle": "URL files per base:"
498
+ },
499
+ zh: {
500
+ "dialog.createdBy.agent": "由 agent 创建",
501
+ "dialog.createdBase": "默认入口:{name}",
502
+ "dialog.urlFilesTitle": "各入口的 URL 文件:"
503
+ }
504
+ };
505
+ function Row(props) {
506
+ const {
507
+ t,
508
+ hook,
509
+ busy,
510
+ copied,
511
+ revealed,
512
+ confirming,
513
+ renaming,
514
+ renameValue,
515
+ setRenameValue,
516
+ onReveal,
517
+ onCopy,
518
+ onToggle,
519
+ onAskRevoke,
520
+ onCancelRevoke,
521
+ onRevoke,
522
+ onStartRename,
523
+ onCancelRename,
524
+ onRename
525
+ } = props;
526
+ const editing = renaming === hook.id;
527
+ const asking = confirming === hook.id;
528
+ const url = revealed[hook.id];
529
+ const agentCreated = hook.createdBy === "agent";
530
+ const meta = [
531
+ lastUsedLabel(hook.lastUsedAt, t),
532
+ hook.lastStatus === "delivered" ? t("dialog.statusDelivered") : null,
533
+ hook.lastStatus === "failed" ? t("dialog.statusFailed") : null,
534
+ t("dialog.deliveryCount", { count: hook.deliveryCount })
535
+ ].filter((part) => part !== null).join(" · ");
536
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-row", children: [
537
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-row-main", children: [
538
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-row-head", children: [
539
+ editing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
540
+ "input",
541
+ {
542
+ className: "si-input si-name",
543
+ value: renameValue,
544
+ autoFocus: true,
545
+ onChange: (event) => setRenameValue(event.target.value),
546
+ onKeyDown: (event) => {
547
+ if (event.key === "Enter") onRename();
548
+ }
549
+ }
550
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-row-name", children: hook.name }),
551
+ agentCreated ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-badge si-badge-agent", children: t("dialog.createdBy.agent") }) : null,
552
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "si-mode-wrap", children: [
553
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-badge", children: t(`mode.${hook.defaultMode}.label`) }),
554
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-tip", role: "tooltip", children: t(`mode.${hook.defaultMode}.hint`) })
555
+ ] }),
556
+ hook.enabled ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-badge", children: t("dialog.disabled") }),
557
+ hook.tags.map((tag) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "si-tag", children: tag }, `tag-${tag}`))
558
+ ] }),
559
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-url", children: url ?? hook.maskedUrl }),
560
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "si-meta", children: meta })
561
+ ] }),
562
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "si-row-actions", children: [
563
+ editing ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
564
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
565
+ "button",
566
+ {
567
+ type: "button",
568
+ className: "si-btn",
569
+ disabled: busy || renameValue.trim() === "",
570
+ onClick: onRename,
571
+ children: t("dialog.save")
572
+ }
573
+ ),
574
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", onClick: onCancelRename, children: t("dialog.cancel") })
575
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", onClick: onStartRename, children: t("dialog.rename") }),
576
+ url === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", onClick: onReveal, children: t("dialog.reveal") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", onClick: onCopy, children: copied === hook.id ? t("dialog.copied") : t("dialog.copy") }),
577
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", disabled: busy, onClick: onToggle, children: hook.enabled ? t("dialog.disable") : t("dialog.enable") }),
578
+ asking ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
579
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
580
+ "button",
581
+ {
582
+ type: "button",
583
+ className: "si-btn si-btn-danger",
584
+ disabled: busy,
585
+ onClick: onRevoke,
586
+ children: t("dialog.revoke")
587
+ }
588
+ ),
589
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn", onClick: onCancelRevoke, children: t("dialog.cancel") })
590
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "si-btn si-btn-danger", onClick: onAskRevoke, children: t("dialog.revoke") })
591
+ ] })
592
+ ] });
593
+ }
594
+
595
+ // src/client/settings.tsx
596
+ var React2 = __toESM(require("react"), 1);
597
+ var import_jsx_runtime2 = require("react/jsx-runtime");
598
+ var DIRECT_BASE = "direct";
599
+ var NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
600
+ var DEFAULT_BASE_PATH = "/api/session-inject";
601
+ var DEFAULT_LIMITS = {
602
+ maxBodyBytes: 1024 * 1024,
603
+ maxTextBytes: 64 * 1024,
604
+ ratePerMinute: 60
605
+ };
606
+ var LIMIT_FIELDS = ["maxBodyBytes", "maxTextBytes", "ratePerMinute"];
607
+ var LIMIT_BOUNDS = {
608
+ maxBodyBytes: { min: 1024, max: 64 * 1024 * 1024 },
609
+ maxTextBytes: { min: 1, max: 1024 * 1024 },
610
+ ratePerMinute: { min: 1, max: 6e3 }
611
+ };
612
+ var BASE_NAME_MAX = 48;
613
+ var BASE_COUNT_MAX = 20;
614
+ var CONFIG_LAYER_KEYS = ["publicBaseUrls", "defaultBase", "limits"];
615
+ function numberOr(value, fallback) {
616
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
617
+ }
618
+ function readUrlLayer(value) {
619
+ const record = asRecord(value);
620
+ if (record === null) return void 0;
621
+ const urls = {};
622
+ for (const [name, url] of Object.entries(record)) {
623
+ if (typeof url === "string") urls[name] = url;
624
+ }
625
+ return urls;
626
+ }
627
+ function readLimitLayer(value) {
628
+ const record = asRecord(value);
629
+ if (record === null) return void 0;
630
+ const limits = {};
631
+ for (const field of LIMIT_FIELDS) {
632
+ const raw = record[field];
633
+ if (typeof raw === "number" && Number.isFinite(raw)) limits[field] = raw;
634
+ }
635
+ return limits;
636
+ }
637
+ function readLayer(value) {
638
+ const record = asRecord(value);
639
+ if (record === null) return {};
640
+ const layer = {};
641
+ const publicBaseUrls = readUrlLayer(record.publicBaseUrls);
642
+ if (publicBaseUrls !== void 0) layer.publicBaseUrls = publicBaseUrls;
643
+ if (typeof record.defaultBase === "string" && record.defaultBase !== "") layer.defaultBase = record.defaultBase;
644
+ const limits = readLimitLayer(record.limits);
645
+ if (limits !== void 0 && Object.keys(limits).length > 0) layer.limits = limits;
646
+ return layer;
647
+ }
648
+ function readEffective(value) {
649
+ const record = asRecord(value) ?? {};
650
+ const publicBaseUrls = {};
651
+ const rawUrls = asRecord(record.publicBaseUrls);
652
+ if (rawUrls !== null) {
653
+ for (const [name, url] of Object.entries(rawUrls)) {
654
+ if (typeof url === "string") publicBaseUrls[name] = url;
655
+ }
656
+ }
657
+ const rawLimits = asRecord(record.limits) ?? {};
658
+ return {
659
+ publicBaseUrls,
660
+ defaultBase: typeof record.defaultBase === "string" && record.defaultBase !== "" ? record.defaultBase : DIRECT_BASE,
661
+ limits: {
662
+ maxBodyBytes: numberOr(rawLimits.maxBodyBytes, DEFAULT_LIMITS.maxBodyBytes),
663
+ maxTextBytes: numberOr(rawLimits.maxTextBytes, DEFAULT_LIMITS.maxTextBytes),
664
+ ratePerMinute: numberOr(rawLimits.ratePerMinute, DEFAULT_LIMITS.ratePerMinute)
665
+ }
666
+ };
667
+ }
668
+ function readConfig(value) {
669
+ const record = asRecord(value) ?? {};
670
+ const basePath = typeof record.basePath === "string" && record.basePath !== "" ? record.basePath : DEFAULT_BASE_PATH;
671
+ const directOrigin = typeof record.directOrigin === "string" && record.directOrigin !== "" ? record.directOrigin : null;
672
+ const directError = typeof record.directError === "string" && record.directError !== "" ? record.directError : null;
673
+ const layered = asRecord(record.effective) !== null;
674
+ if (layered) {
675
+ return {
676
+ yaml: readLayer(record.yaml),
677
+ settings: readLayer(record.settings),
678
+ effective: readEffective(record.effective),
679
+ directOrigin,
680
+ directError,
681
+ basePath
682
+ };
683
+ }
684
+ return {
685
+ yaml: {},
686
+ settings: {},
687
+ effective: readEffective(record),
688
+ directOrigin,
689
+ directError,
690
+ basePath
691
+ };
692
+ }
693
+ function hasBase(layer, name) {
694
+ return layer.publicBaseUrls !== void 0 && Object.hasOwn(layer.publicBaseUrls, name);
695
+ }
696
+ function draftFromConfig(snapshot2) {
697
+ const effectiveBases = snapshot2.effective.publicBaseUrls;
698
+ const directOrigin = hasBase(snapshot2.settings, DIRECT_BASE) ? "settings" : hasBase(snapshot2.yaml, DIRECT_BASE) ? "yaml" : "implicit";
699
+ const rows = [{
700
+ id: DIRECT_BASE,
701
+ name: DIRECT_BASE,
702
+ url: effectiveBases[DIRECT_BASE] ?? "",
703
+ origin: directOrigin,
704
+ edited: false
705
+ }];
706
+ for (const [name, url] of Object.entries(effectiveBases)) {
707
+ if (name === DIRECT_BASE) continue;
708
+ const origin = hasBase(snapshot2.settings, name) ? "settings" : "yaml";
709
+ rows.push({ id: name, name, url, origin, edited: false });
710
+ }
711
+ const names = new Set(rows.map((row) => row.name));
712
+ const defaultBase = names.has(snapshot2.effective.defaultBase) ? snapshot2.effective.defaultBase : DIRECT_BASE;
713
+ return {
714
+ rows,
715
+ defaultBase,
716
+ maxBodyBytes: String(snapshot2.effective.limits.maxBodyBytes),
717
+ maxTextBytes: String(snapshot2.effective.limits.maxTextBytes),
718
+ ratePerMinute: String(snapshot2.effective.limits.ratePerMinute)
719
+ };
720
+ }
721
+ function isDraftDirty(draft, snapshot2) {
722
+ const pristine = draftFromConfig(snapshot2);
723
+ if (draft.defaultBase !== pristine.defaultBase) return true;
724
+ if (draft.maxBodyBytes !== pristine.maxBodyBytes) return true;
725
+ if (draft.maxTextBytes !== pristine.maxTextBytes) return true;
726
+ if (draft.ratePerMinute !== pristine.ratePerMinute) return true;
727
+ if (draft.rows.length !== pristine.rows.length) return true;
728
+ for (let i = 0; i < draft.rows.length; i += 1) {
729
+ const a = draft.rows[i];
730
+ const b = pristine.rows[i];
731
+ if (a.name.trim() !== b.name.trim()) return true;
732
+ if (a.url.trim() !== b.url.trim()) return true;
733
+ }
734
+ return false;
735
+ }
736
+ var EMPTY_DRAFT = {
737
+ rows: [{ id: DIRECT_BASE, name: DIRECT_BASE, url: "", origin: "implicit", edited: false }],
738
+ defaultBase: DIRECT_BASE,
739
+ maxBodyBytes: String(DEFAULT_LIMITS.maxBodyBytes),
740
+ maxTextBytes: String(DEFAULT_LIMITS.maxTextBytes),
741
+ ratePerMinute: String(DEFAULT_LIMITS.ratePerMinute)
742
+ };
743
+ var rowSequence = 0;
744
+ function nextRowId() {
745
+ rowSequence += 1;
746
+ return `row-${rowSequence}`;
747
+ }
748
+ function updateBaseRow(draft, id, patch) {
749
+ return {
750
+ ...draft,
751
+ rows: draft.rows.map((row) => row.id === id ? { ...row, ...patch, edited: true } : row)
752
+ };
753
+ }
754
+ function addBaseRow(draft) {
755
+ return {
756
+ ...draft,
757
+ rows: [...draft.rows, { id: nextRowId(), name: "", url: "", origin: "settings", edited: true }]
758
+ };
759
+ }
760
+ function lastRowId(draft) {
761
+ return draft.rows[draft.rows.length - 1]?.id;
762
+ }
763
+ function removeBaseRow(draft, id) {
764
+ if (id === DIRECT_BASE) return draft;
765
+ const removed = draft.rows.find((row) => row.id === id);
766
+ const rows = draft.rows.filter((row) => row.id !== id);
767
+ const defaultBase = removed !== void 0 && draft.defaultBase === removed.name ? DIRECT_BASE : draft.defaultBase;
768
+ return { ...draft, rows, defaultBase };
769
+ }
770
+ function resetDirectRow(draft) {
771
+ return {
772
+ ...draft,
773
+ rows: draft.rows.map((row) => row.id === DIRECT_BASE ? { ...row, url: "", edited: false } : row)
774
+ };
775
+ }
776
+ function setDefaultBase(draft, name) {
777
+ return { ...draft, defaultBase: name };
778
+ }
779
+ function setLimitField(draft, field, value) {
780
+ return { ...draft, [field]: value };
781
+ }
782
+ function normalizeBaseUrl(raw) {
783
+ const trimmed = raw.trim().replace(/\/+$/, "");
784
+ if (trimmed === "") return null;
785
+ let parsed;
786
+ try {
787
+ parsed = new URL(trimmed);
788
+ } catch {
789
+ return null;
790
+ }
791
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
792
+ if (parsed.search !== "" || parsed.hash !== "") return null;
793
+ if (parsed.username !== "" || parsed.password !== "") return null;
794
+ return `${parsed.origin}${parsed.pathname.replace(/\/+$/, "")}`;
795
+ }
796
+ function rowIsFromYaml(snapshot2, name) {
797
+ return hasBase(snapshot2.yaml, name);
798
+ }
799
+ function validateDraft(draft, t, _snapshot) {
800
+ const errors = [];
801
+ const publicBaseUrls = {};
802
+ const names = /* @__PURE__ */ new Set([DIRECT_BASE]);
803
+ for (const row of draft.rows) {
804
+ const isDirect = row.id === DIRECT_BASE;
805
+ const name = isDirect ? DIRECT_BASE : row.name.trim();
806
+ if (!isDirect) {
807
+ if (name === "") {
808
+ errors.push(t("settings.error.nameEmpty"));
809
+ } else if (!NAME_PATTERN.test(name)) {
810
+ errors.push(t("settings.error.name", { name }));
811
+ } else if (name.length > BASE_NAME_MAX) {
812
+ errors.push(t("settings.error.nameLong", { max: BASE_NAME_MAX }));
813
+ } else if (names.has(name)) {
814
+ errors.push(t("settings.error.nameDuplicate", { name }));
815
+ } else {
816
+ names.add(name);
817
+ }
818
+ }
819
+ if (isDirect && row.url.trim() === "") continue;
820
+ const label = name === "" ? t("settings.bases.unnamed") : name;
821
+ if (row.url.trim() === "") {
822
+ errors.push(t("settings.error.urlRequired", { name: label }));
823
+ continue;
824
+ }
825
+ const normalized = normalizeBaseUrl(row.url);
826
+ if (normalized === null) {
827
+ errors.push(t("settings.error.url", { name: label }));
828
+ continue;
829
+ }
830
+ const include = isDirect ? row.origin !== "implicit" || row.edited : true;
831
+ if (include) publicBaseUrls[name] = normalized;
832
+ }
833
+ if (Object.keys(publicBaseUrls).length > BASE_COUNT_MAX) {
834
+ errors.push(t("settings.error.tooMany", { max: BASE_COUNT_MAX }));
835
+ }
836
+ if (!names.has(draft.defaultBase)) {
837
+ errors.push(t("settings.error.defaultMissing", {
838
+ name: draft.defaultBase === "" ? t("settings.bases.unnamed") : draft.defaultBase
839
+ }));
840
+ }
841
+ const parsedLimits = {};
842
+ for (const field of LIMIT_FIELDS) {
843
+ const raw = draft[field].trim();
844
+ const label = t(`settings.limits.${field}`);
845
+ if (!/^\d+$/.test(raw)) {
846
+ errors.push(t("settings.error.limitInteger", { field: label }));
847
+ continue;
848
+ }
849
+ const value = Number(raw);
850
+ const bounds = LIMIT_BOUNDS[field];
851
+ if (!Number.isSafeInteger(value) || value < bounds.min || value > bounds.max) {
852
+ errors.push(t("settings.error.limitRange", { field: label, min: bounds.min, max: bounds.max }));
853
+ continue;
854
+ }
855
+ parsedLimits[field] = value;
856
+ }
857
+ const { maxBodyBytes, maxTextBytes, ratePerMinute } = parsedLimits;
858
+ if (maxBodyBytes !== void 0 && maxTextBytes !== void 0 && maxTextBytes > maxBodyBytes) {
859
+ errors.push(t("settings.error.textOverBody"));
860
+ }
861
+ if (errors.length > 0) return { errors, payload: null };
862
+ return {
863
+ errors,
864
+ payload: {
865
+ publicBaseUrls,
866
+ defaultBase: draft.defaultBase,
867
+ limits: {
868
+ maxBodyBytes,
869
+ maxTextBytes,
870
+ ratePerMinute
871
+ }
872
+ }
873
+ };
874
+ }
875
+ function baseSourceHint(t, snapshot2, name) {
876
+ const settingsUrl = snapshot2.settings.publicBaseUrls?.[name];
877
+ const yamlUrl = snapshot2.yaml.publicBaseUrls?.[name];
878
+ if (settingsUrl !== void 0) {
879
+ return yamlUrl === void 0 ? t("settings.source.settingsOnly") : t("settings.source.settingsOverYaml", { yaml: yamlUrl });
880
+ }
881
+ if (yamlUrl !== void 0) return t("settings.source.yaml", { yaml: yamlUrl });
882
+ return "";
883
+ }
884
+ function limitSourceHint(t, snapshot2, field) {
885
+ const settingsValue = snapshot2.settings.limits?.[field];
886
+ const yamlValue = snapshot2.yaml.limits?.[field];
887
+ if (settingsValue !== void 0) {
888
+ return yamlValue === void 0 ? t("settings.source.settingsOnly") : t("settings.source.settingsOverYaml", { yaml: String(yamlValue) });
889
+ }
890
+ if (yamlValue !== void 0) return t("settings.source.yaml", { yaml: String(yamlValue) });
891
+ return t("settings.source.default", { value: String(DEFAULT_LIMITS[field]) });
892
+ }
893
+ function defaultBaseSourceHint(t, snapshot2) {
894
+ const settingsBase = snapshot2.settings.defaultBase;
895
+ const yamlBase = snapshot2.yaml.defaultBase;
896
+ if (settingsBase !== void 0) {
897
+ return yamlBase === void 0 ? t("settings.source.settingsOnly") : t("settings.source.settingsOverYaml", { yaml: yamlBase });
898
+ }
899
+ if (yamlBase !== void 0) return t("settings.source.yaml", { yaml: yamlBase });
900
+ return t("settings.source.default", { value: DIRECT_BASE });
901
+ }
902
+ function hasBasesOverride(snapshot2) {
903
+ return snapshot2.settings.publicBaseUrls !== void 0 || snapshot2.settings.defaultBase !== void 0;
904
+ }
905
+ function hasLimitsOverride(snapshot2) {
906
+ return snapshot2.settings.limits !== void 0;
907
+ }
908
+ function groupHead(t, title, reset) {
909
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-group-head-row", children: [
910
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "si-group-head", children: title }),
911
+ reset === null ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
912
+ "button",
913
+ {
914
+ type: "button",
915
+ className: "si-btn si-btn-sm",
916
+ title: t("settings.resetHint"),
917
+ disabled: reset.disabled,
918
+ onClick: () => reset.onReset(reset.keys),
919
+ children: t("settings.reset")
920
+ }
921
+ )
922
+ ] });
923
+ }
924
+ function limitField(props, field) {
925
+ const bounds = LIMIT_BOUNDS[field];
926
+ const label = props.t(`settings.limits.${field}`);
927
+ const source = limitSourceHint(props.t, props.snapshot, field);
928
+ const range = props.t("settings.limits.help", { min: bounds.min, max: bounds.max });
929
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-setting-row", children: [
930
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-setting-row-text", children: [
931
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "si-setting-row-title", htmlFor: `si-limit-${field}`, children: label }),
932
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-setting-row-desc", children: `${range} · ${source}` })
933
+ ] }),
934
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "si-setting-row-control", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
935
+ "input",
936
+ {
937
+ id: `si-limit-${field}`,
938
+ className: "si-num",
939
+ type: "number",
940
+ inputMode: "numeric",
941
+ min: bounds.min,
942
+ max: bounds.max,
943
+ step: 1,
944
+ value: props.draft[field],
945
+ "aria-label": label,
946
+ onChange: (event) => {
947
+ props.onChangeDraft(setLimitField(props.draft, field, event.target.value));
948
+ }
949
+ }
950
+ ) })
951
+ ] }, field);
952
+ }
953
+ function baseRow(props, row, nameRef) {
954
+ const { t, draft, snapshot: snapshot2 } = props;
955
+ const isDirect = row.id === DIRECT_BASE;
956
+ const directOrigin = snapshot2.directOrigin;
957
+ const directFallback = snapshot2.yaml.publicBaseUrls?.[DIRECT_BASE] ?? directOrigin ?? t("settings.bases.originUnavailable");
958
+ const sourceHint = baseSourceHint(t, snapshot2, row.name);
959
+ const hint = isDirect && sourceHint === "" ? t("settings.bases.directHint", { origin: directFallback }) : sourceHint;
960
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-base-item", children: [
961
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-base-row", children: [
962
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
963
+ "input",
964
+ {
965
+ className: "si-input si-base-name",
966
+ ref: nameRef,
967
+ value: isDirect ? DIRECT_BASE : row.name,
968
+ placeholder: t("settings.bases.namePlaceholder"),
969
+ readOnly: isDirect,
970
+ "aria-label": t("settings.bases.nameLabel"),
971
+ onChange: (event) => {
972
+ props.onChangeDraft(updateBaseRow(draft, row.id, { name: event.target.value }));
973
+ }
974
+ }
975
+ ),
976
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
977
+ "input",
978
+ {
979
+ className: "si-input si-base-url",
980
+ value: row.url,
981
+ placeholder: isDirect ? directFallback : "https://",
982
+ "aria-label": t("settings.bases.urlLabel"),
983
+ onChange: (event) => {
984
+ props.onChangeDraft(updateBaseRow(draft, row.id, { url: event.target.value }));
985
+ }
986
+ }
987
+ ),
988
+ isDirect ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
989
+ "button",
990
+ {
991
+ type: "button",
992
+ className: "si-btn si-btn-sm",
993
+ disabled: row.origin === "implicit" && !row.edited,
994
+ onClick: () => props.onChangeDraft(resetDirectRow(draft)),
995
+ children: t("settings.bases.resetDirect")
996
+ }
997
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
998
+ "button",
999
+ {
1000
+ type: "button",
1001
+ className: "si-btn si-btn-danger si-btn-sm",
1002
+ onClick: () => props.onChangeDraft(removeBaseRow(draft, row.id)),
1003
+ children: t("settings.bases.remove")
1004
+ }
1005
+ )
1006
+ ] }),
1007
+ hint === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-field-help", children: hint })
1008
+ ] }, row.id);
1009
+ }
1010
+ function SettingsPanel(props) {
1011
+ const { t, draft, snapshot: snapshot2 } = props;
1012
+ const basePath = snapshot2.basePath !== "" ? snapshot2.basePath : DEFAULT_BASE_PATH;
1013
+ const header = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1014
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { className: "si-page-title", children: t("settings.title") }),
1015
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-page-intro", children: t("settings.intro", { basePath }) }),
1016
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-page-intro", children: t("settings.layerNote") })
1017
+ ] });
1018
+ if (props.status === "loading") {
1019
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-page", children: [
1020
+ header,
1021
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-page-loading", children: t("settings.loading") })
1022
+ ] });
1023
+ }
1024
+ if (props.status === "failed") {
1025
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-page", children: [
1026
+ header,
1027
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-invalid", children: t("settings.error.load", { message: props.loadError ?? "" }) }),
1028
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "si-page-actions", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "si-btn si-btn-outline", onClick: props.onReload, children: t("settings.retry") }) })
1029
+ ] });
1030
+ }
1031
+ const optionNames = [DIRECT_BASE];
1032
+ for (const row of draft.rows) {
1033
+ const name = row.id === DIRECT_BASE ? DIRECT_BASE : row.name.trim();
1034
+ if (name !== "" && !optionNames.includes(name)) optionNames.push(name);
1035
+ }
1036
+ const defaultOptions = optionNames.includes(draft.defaultBase) ? optionNames : [draft.defaultBase, ...optionNames];
1037
+ const [pendingFocusId, setPendingFocusId] = React2.useState(null);
1038
+ const pendingFocusRef = React2.useRef(null);
1039
+ React2.useEffect(() => {
1040
+ if (pendingFocusId === null || pendingFocusRef.current === null) return;
1041
+ pendingFocusRef.current.focus();
1042
+ setPendingFocusId(null);
1043
+ }, [pendingFocusId, draft.rows.length]);
1044
+ const basesGroup = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "si-group", children: [
1045
+ groupHead(t, t("settings.bases.title"), hasBasesOverride(snapshot2) ? { keys: ["publicBaseUrls", "defaultBase"], disabled: props.busy, onReset: props.onReset } : null),
1046
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-group-desc", children: t("settings.bases.desc") }),
1047
+ snapshot2.directError === null ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-page-note", children: t("settings.bases.directError", { message: snapshot2.directError }) }),
1048
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-card", children: [
1049
+ draft.rows.map((row) => baseRow(
1050
+ props,
1051
+ row,
1052
+ row.id === pendingFocusId ? pendingFocusRef : void 0
1053
+ )),
1054
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1055
+ "button",
1056
+ {
1057
+ type: "button",
1058
+ className: "si-add",
1059
+ onClick: () => {
1060
+ const next = addBaseRow(draft);
1061
+ props.onChangeDraft(next);
1062
+ const id = lastRowId(next);
1063
+ if (id !== void 0) setPendingFocusId(id);
1064
+ },
1065
+ children: [
1066
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-hidden": "true", children: "+" }),
1067
+ t("settings.bases.add")
1068
+ ]
1069
+ }
1070
+ ),
1071
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-setting-row", children: [
1072
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-setting-row-text", children: [
1073
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "si-setting-row-title", htmlFor: "si-default-base", children: t("settings.defaultBase.label") }),
1074
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-setting-row-desc", children: `${t("settings.defaultBase.help")} · ${defaultBaseSourceHint(t, snapshot2)}` })
1075
+ ] }),
1076
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "si-setting-row-control", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1077
+ "select",
1078
+ {
1079
+ id: "si-default-base",
1080
+ className: "si-select",
1081
+ value: draft.defaultBase,
1082
+ onChange: (event) => {
1083
+ props.onChangeDraft(setDefaultBase(draft, event.target.value));
1084
+ },
1085
+ children: defaultOptions.map((name) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: name, children: optionNames.includes(name) ? name : t("settings.defaultBase.invalidOption", { name }) }, name))
1086
+ }
1087
+ ) })
1088
+ ] })
1089
+ ] })
1090
+ ] });
1091
+ const limitsGroup = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "si-group", children: [
1092
+ groupHead(t, t("settings.limits.title"), hasLimitsOverride(snapshot2) ? { keys: ["limits"], disabled: props.busy, onReset: props.onReset } : null),
1093
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "si-group-desc", children: t("settings.limits.desc") }),
1094
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "si-card", children: LIMIT_FIELDS.map((field) => limitField(props, field)) })
1095
+ ] });
1096
+ const dirty = isDraftDirty(draft, snapshot2);
1097
+ const errorsBlock = props.errors.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "si-page-errors", children: props.errors.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { className: "si-invalid", children: message }, `${index}-${message}`)) });
1098
+ const actions = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-page-actions", children: [
1099
+ props.notice === null ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1100
+ "p",
1101
+ {
1102
+ className: props.notice.kind === "saved" ? "si-saved" : props.notice.kind === "warn" ? "si-page-note" : "si-invalid",
1103
+ role: props.notice.kind === "error" ? "alert" : "status",
1104
+ children: props.notice.text
1105
+ }
1106
+ ),
1107
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1108
+ "button",
1109
+ {
1110
+ type: "button",
1111
+ className: "si-btn si-btn-primary",
1112
+ disabled: props.busy || !dirty,
1113
+ title: dirty ? void 0 : t("settings.saveNoChanges"),
1114
+ onClick: props.onSave,
1115
+ children: props.busy ? t("settings.saving") : t("settings.save")
1116
+ }
1117
+ )
1118
+ ] });
1119
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-page", children: [
1120
+ header,
1121
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "si-page-body", children: [
1122
+ basesGroup,
1123
+ limitsGroup,
1124
+ errorsBlock,
1125
+ actions
1126
+ ] })
1127
+ ] });
1128
+ }
1129
+ function isUrlFileWarning(failure) {
1130
+ return failure instanceof RpcError && failure.code === "urlfile-failed";
1131
+ }
1132
+ function emptySnapshot() {
1133
+ return {
1134
+ yaml: {},
1135
+ settings: {},
1136
+ effective: {
1137
+ publicBaseUrls: {},
1138
+ defaultBase: DIRECT_BASE,
1139
+ limits: { ...DEFAULT_LIMITS }
1140
+ },
1141
+ directOrigin: null,
1142
+ directError: null,
1143
+ basePath: DEFAULT_BASE_PATH
1144
+ };
1145
+ }
1146
+ function SettingsSection(props) {
1147
+ const { t, rpc } = props;
1148
+ const [snapshot2, setSnapshot] = React2.useState(emptySnapshot);
1149
+ const [draft, setDraft] = React2.useState(EMPTY_DRAFT);
1150
+ const [status, setStatus] = React2.useState("loading");
1151
+ const [loadError, setLoadError] = React2.useState(null);
1152
+ const [errors, setErrors] = React2.useState([]);
1153
+ const [notice, setNotice] = React2.useState(null);
1154
+ const [busy, setBusy] = React2.useState(false);
1155
+ const [attempt, setAttempt] = React2.useState(0);
1156
+ const load = React2.useCallback(async (showLoading) => {
1157
+ if (showLoading) setStatus("loading");
1158
+ setLoadError(null);
1159
+ try {
1160
+ const next = readConfig(await rpc("config/get", {}));
1161
+ setSnapshot(next);
1162
+ setDraft(draftFromConfig(next));
1163
+ setStatus("ready");
1164
+ } catch (failure) {
1165
+ setLoadError(messageOf(failure));
1166
+ setStatus("failed");
1167
+ }
1168
+ }, [rpc]);
1169
+ React2.useEffect(() => {
1170
+ void load(true);
1171
+ }, [load, attempt]);
1172
+ const reset = (keys) => {
1173
+ setNotice(null);
1174
+ setBusy(true);
1175
+ void (async () => {
1176
+ try {
1177
+ await rpc("config/reset", { keys: [...keys] });
1178
+ await load(false);
1179
+ setErrors([]);
1180
+ setNotice({ kind: "saved", text: t("settings.resetDone") });
1181
+ } catch (failure) {
1182
+ if (isUrlFileWarning(failure)) {
1183
+ await load(false);
1184
+ setNotice({ kind: "warn", text: t("settings.warning", { message: messageOf(failure) }) });
1185
+ } else {
1186
+ setNotice({ kind: "error", text: t("settings.error.reset", { message: messageOf(failure) }) });
1187
+ }
1188
+ } finally {
1189
+ setBusy(false);
1190
+ }
1191
+ })();
1192
+ };
1193
+ const save = () => {
1194
+ const outcome = validateDraft(draft, t, snapshot2);
1195
+ setErrors(outcome.errors);
1196
+ setNotice(null);
1197
+ if (outcome.payload === null) return;
1198
+ const payload = outcome.payload;
1199
+ setBusy(true);
1200
+ void (async () => {
1201
+ try {
1202
+ await rpc("config/set", payload);
1203
+ await load(false);
1204
+ setErrors([]);
1205
+ setNotice({ kind: "saved", text: t("settings.savedEffective") });
1206
+ } catch (failure) {
1207
+ if (isUrlFileWarning(failure)) {
1208
+ await load(false);
1209
+ setNotice({ kind: "warn", text: t("settings.warning", { message: messageOf(failure) }) });
1210
+ } else {
1211
+ setNotice({ kind: "error", text: t("settings.error.save", { message: messageOf(failure) }) });
1212
+ }
1213
+ } finally {
1214
+ setBusy(false);
1215
+ }
1216
+ })();
1217
+ };
1218
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1219
+ SettingsPanel,
1220
+ {
1221
+ t,
1222
+ status,
1223
+ loadError,
1224
+ snapshot: snapshot2,
1225
+ draft,
1226
+ errors,
1227
+ notice,
1228
+ busy,
1229
+ onChangeDraft: (next) => {
1230
+ setDraft(next);
1231
+ setNotice(null);
1232
+ },
1233
+ onSave: save,
1234
+ onReset: reset,
1235
+ onReload: () => setAttempt((current) => current + 1)
1236
+ }
1237
+ );
1238
+ }
1239
+ function registerSettingsSection(ctx, deps) {
1240
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
1241
+ name: "settings.section",
1242
+ id: "session-inject.settings",
1243
+ order: 30,
1244
+ label: () => deps.t("settings.nav"),
1245
+ locale: "session-inject",
1246
+ inject: () => ({ rpc: deps.rpc })
1247
+ }, SettingsSection));
1248
+ }
1249
+ var SETTINGS_LOCALE = {
1250
+ en: {
1251
+ "settings.nav": "Webhook endpoints",
1252
+ "settings.title": "Session webhook endpoints",
1253
+ "settings.intro": "External scripts, CI, and monitors deliver one message into a target session through the bases configured here. An endpoint URL is a base plus the mount prefix plus /hooks/<token>. Current mount prefix: {basePath}.",
1254
+ "settings.layerNote": "Saving writes settings.json; once that file exists it takes over the base list and the default base as a whole, and overrides limits field by field.",
1255
+ "settings.loading": "Loading configuration…",
1256
+ "settings.retry": "Retry",
1257
+ "settings.save": "Save",
1258
+ "settings.saveNoChanges": "Nothing to save — edit a field first",
1259
+ "settings.saving": "Saving…",
1260
+ "settings.savedEffective": "Saved and active: the new bases and limits take effect immediately, and URL files were rewritten.",
1261
+ "settings.reset": "Reset to YAML",
1262
+ "settings.resetHint": "Drop the UI override of this group and go back to the plugin YAML value.",
1263
+ "settings.resetDone": "Reset to YAML: this group follows the plugin configuration again.",
1264
+ "settings.error.reset": "Could not reset to YAML: {message}",
1265
+ "settings.warning": "Warning: {message}",
1266
+ "settings.bases.title": "Bases",
1267
+ "settings.bases.desc": "direct always exists: unless overridden it points at this host’s listening origin. Other bases are for reverse proxies or public domains.",
1268
+ "settings.bases.originUnavailable": "(listening origin unavailable)",
1269
+ "settings.bases.directHint": "direct is not configured explicitly; it follows the listening origin: {origin}",
1270
+ "settings.bases.directError": "The listening origin is unavailable right now: {message}",
1271
+ "settings.bases.nameLabel": "Base name",
1272
+ "settings.bases.namePlaceholder": "Name",
1273
+ "settings.bases.urlLabel": "Base URL",
1274
+ "settings.bases.resetDirect": "Use default",
1275
+ "settings.bases.remove": "Remove",
1276
+ "settings.bases.add": "Add base",
1277
+ "settings.bases.unnamed": "unnamed",
1278
+ "settings.defaultBase.label": "Default base",
1279
+ "settings.defaultBase.help": "New endpoints use this base by default; it must exist in the base list.",
1280
+ "settings.defaultBase.invalidOption": "{name} (invalid)",
1281
+ "settings.limits.title": "Limits",
1282
+ "settings.limits.desc": "Written to the plugin configuration; out-of-range or non-integer values are rejected locally.",
1283
+ "settings.limits.maxBodyBytes": "Request body cap (bytes)",
1284
+ "settings.limits.maxTextBytes": "Single text cap (bytes)",
1285
+ "settings.limits.ratePerMinute": "Deliveries per endpoint per minute",
1286
+ "settings.limits.help": "Range {min}–{max}",
1287
+ "settings.source.settingsOnly": "UI override (no YAML value)",
1288
+ "settings.source.settingsOverYaml": "UI override (YAML: {yaml})",
1289
+ "settings.source.yaml": "Inherited from YAML: {yaml}",
1290
+ "settings.source.default": "Default: {value}",
1291
+ "settings.error.load": "Could not read the configuration: {message}",
1292
+ "settings.error.save": "Could not save: {message}",
1293
+ "settings.error.nameEmpty": "A base name must not be empty.",
1294
+ "settings.error.name": "Base name “{name}” is invalid: start with a lowercase letter and use only lowercase letters, digits, and hyphens.",
1295
+ "settings.error.nameDuplicate": "Base name “{name}” is used twice.",
1296
+ "settings.error.nameLong": "A base name must be at most {max} characters.",
1297
+ "settings.error.tooMany": "At most {max} explicit bases are supported.",
1298
+ "settings.error.urlRequired": "The URL of base “{name}” must not be empty.",
1299
+ "settings.error.url": "The URL of base “{name}” is invalid: it must be an absolute http(s):// address without a query string or # fragment.",
1300
+ "settings.error.defaultMissing": "The default base “{name}” is not in the base list.",
1301
+ "settings.error.limitInteger": "{field} must be an integer.",
1302
+ "settings.error.limitRange": "{field} must be between {min} and {max}.",
1303
+ "settings.error.textOverBody": "The single text cap must not exceed the request body cap."
1304
+ },
1305
+ zh: {
1306
+ "settings.nav": "Webhook 端点",
1307
+ "settings.title": "会话 Webhook 端点",
1308
+ "settings.intro": "外部脚本、CI、监控通过这里配置的入口把一条消息投进指定会话;端点 URL = 入口地址 + 接入前缀 + /hooks/<令牌>。当前接入前缀:{basePath}。",
1309
+ "settings.layerNote": "界面保存写入 settings.json;该文件一旦存在就整表接管入口与默认入口,限额逐字段覆盖。",
1310
+ "settings.loading": "正在读取配置…",
1311
+ "settings.retry": "重试",
1312
+ "settings.save": "保存",
1313
+ "settings.saveNoChanges": "没有改动可保存——先改一处再保存",
1314
+ "settings.saving": "保存中…",
1315
+ "settings.savedEffective": "已保存并已生效:入口与限额立刻生效,URL 文件已按入口重写。",
1316
+ "settings.reset": "恢复继承 YAML",
1317
+ "settings.resetHint": "清除这一组在界面上的覆盖,回到插件 YAML 的值。",
1318
+ "settings.resetDone": "已恢复继承 YAML:这一组重新跟随插件配置。",
1319
+ "settings.error.reset": "恢复继承 YAML 失败:{message}",
1320
+ "settings.warning": "警告:{message}",
1321
+ "settings.bases.title": "入口(Base URL)",
1322
+ "settings.bases.desc": "direct 恒存在:未显式配置时指向本机监听地址;其它入口用于反向代理或公网域名。",
1323
+ "settings.bases.originUnavailable": "(当前取不到监听地址)",
1324
+ "settings.bases.directHint": "direct 未显式配置,跟随监听地址:{origin}",
1325
+ "settings.bases.directError": "当前取不到监听地址:{message}",
1326
+ "settings.bases.nameLabel": "入口名",
1327
+ "settings.bases.namePlaceholder": "名称",
1328
+ "settings.bases.urlLabel": "入口 URL",
1329
+ "settings.bases.resetDirect": "恢复默认",
1330
+ "settings.bases.remove": "移除",
1331
+ "settings.bases.add": "添加入口",
1332
+ "settings.bases.unnamed": "未命名",
1333
+ "settings.defaultBase.label": "默认入口",
1334
+ "settings.defaultBase.help": "新建端点默认使用这个入口;它必须在入口列表里。",
1335
+ "settings.defaultBase.invalidOption": "{name}(无效)",
1336
+ "settings.limits.title": "限额",
1337
+ "settings.limits.desc": "写入插件配置;超出范围或非整数的值会被拦在本地。",
1338
+ "settings.limits.maxBodyBytes": "单次请求体上限(字节)",
1339
+ "settings.limits.maxTextBytes": "单条文本上限(字节)",
1340
+ "settings.limits.ratePerMinute": "每端点每分钟投递上限",
1341
+ "settings.limits.help": "范围 {min}–{max}",
1342
+ // 与 limits.help 拼成一句:`范围 1024–67108864 · 继承自 YAML: 1048576`。
1343
+ // 统一用半角冒号与中点(英文 locale 本来就是半角,中文这边对齐它)。
1344
+ "settings.source.settingsOnly": "界面覆盖 · YAML 无此项",
1345
+ "settings.source.settingsOverYaml": "界面覆盖 · YAML: {yaml}",
1346
+ "settings.source.yaml": "继承自 YAML: {yaml}",
1347
+ "settings.source.default": "默认值: {value}",
1348
+ "settings.error.load": "读取配置失败:{message}",
1349
+ "settings.error.save": "保存失败:{message}",
1350
+ "settings.error.nameEmpty": "入口名不能为空。",
1351
+ "settings.error.name": "入口名「{name}」不合法:必须以小写字母开头,只含小写字母、数字和连字符。",
1352
+ "settings.error.nameDuplicate": "入口名「{name}」重复了。",
1353
+ "settings.error.nameLong": "入口名最多 {max} 个字符。",
1354
+ "settings.error.tooMany": "最多只能配置 {max} 个显式入口。",
1355
+ "settings.error.urlRequired": "入口「{name}」的 URL 不能为空。",
1356
+ "settings.error.url": "入口「{name}」的 URL 不合法:必须是 http(s):// 开头的绝对地址,且不含查询串或 # 片段。",
1357
+ "settings.error.defaultMissing": "默认入口「{name}」不在入口列表里。",
1358
+ "settings.error.limitInteger": "{field} 必须是整数。",
1359
+ "settings.error.limitRange": "{field} 必须在 {min} 到 {max} 之间。",
1360
+ "settings.error.textOverBody": "单条文本上限不能大于请求体上限。"
1361
+ }
1362
+ };
1363
+
1364
+ // src/client/styles.ts
1365
+ var STYLES = `
1366
+ /* ── 会话菜单里的入口行:抄宿主 MenuItemButton 的规格(34px 高、14/22 字号)── */
1367
+ .si-menu-row{display:flex;align-items:center;gap:6px;width:100%;min-height:34px;padding:6px 8px;
1368
+ border:none;border-radius:var(--dsw-radius-md);background:transparent;cursor:pointer;
1369
+ font-family:inherit;font-size:13px;line-height:20px;color:var(--dsw-alias-label-primary);text-align:left}
1370
+ .si-menu-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
1371
+ .si-menu-row:focus-visible:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);outline:none}
1372
+ .si-menu-row:disabled{opacity:.4;cursor:not-allowed}
1373
+ .si-menu-icon{display:inline-flex;flex:none;width:14px;height:14px;align-items:center;justify-content:center;
1374
+ color:var(--dsw-alias-menu-icon)}
1375
+ .si-menu-icon svg{width:14px;height:14px}
1376
+ .si-menu-label{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1377
+
1378
+ /* ── 端点弹层:抄宿主 Modal(无模糊遮罩、28px 圆角、layer-2 表面)── */
1379
+ .si-backdrop{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;
1380
+ padding:max(24px,var(--dsh-frame-overlay-top,24px)) 24px;background:var(--dsw-alias-bg-mask-1);
1381
+ pointer-events:auto;z-index:60}
1382
+ .si-panel{box-sizing:border-box;position:relative;width:min(720px,100%);max-height:82vh;overflow:auto;
1383
+ padding:0 0 24px;border:0;border-radius:var(--dsw-radius-panel);
1384
+ background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);
1385
+ color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}
1386
+ .si-head{display:flex;align-items:flex-start;gap:8px;padding:22px 14px 12px 24px}
1387
+ .si-title{font-size:16px;line-height:24px;font-weight:500;color:var(--dsw-alias-label-primary)}
1388
+ .si-sub{margin-top:2px;font-size:13px;line-height:20px;color:var(--dsw-alias-label-secondary)}
1389
+ .si-close{flex:none;display:inline-flex;align-items:center;justify-content:center;
1390
+ margin-left:auto;width:28px;height:28px;border:none;border-radius:var(--dsw-radius-sm);
1391
+ background:transparent;color:var(--dsw-alias-label-secondary);font-size:16px;line-height:1;cursor:pointer}
1392
+ .si-close:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
1393
+
1394
+ /* ── 控件:输入、下拉、按钮统一 36px 高、radius-md;字号跟随宿主输入框的 13px ── */
1395
+ .si-form{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:20px 24px 16px}
1396
+ /* 控件基线:逐属性对齐宿主设置页里的文本输入框,源头是
1397
+ dsh-client-ui-settings-plugin-inventory 的 .qSYn7G_search input:
1398
+ border .5px solid var(--dsw-alias-border-l4) / radius-md / bg-layer-1
1399
+ height 36px / font-size 13px / outline none
1400
+ 注意是 .5px 而不是 1px;背景是 layer-1(比面板的 layer-2 更凹陷)而不是 layer-3。
1401
+ 输入类与 select/数字框共用这套外观,只有宽度和内边距各自不同。 */
1402
+ .si-input,.si-select,.si-num{box-sizing:border-box;height:36px;
1403
+ border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);
1404
+ background:var(--dsw-alias-bg-layer-1);
1405
+ font-family:inherit;font-size:13px;line-height:normal;color:var(--dsw-alias-label-primary)}
1406
+ .si-input{padding:0 12px}
1407
+ .si-input::placeholder{color:var(--dsw-alias-label-tertiary)}
1408
+ /* 焦点环跟随宿主设置页的写法:边框变色 + 2px 柔光,而不是浏览器默认 outline
1409
+ (默认 outline 在这套 token 下几乎不可见)。
1410
+ 注意这里直接写 --dsw-alias-state-business-primary,不要再包一层
1411
+ var(--dsw-focus-ring-color, …):那个变量在宿主的这个层级是**已定义但值为空**,
1412
+ 而 CSS 里空值不会触发 var() 的 fallback,会导致 border-color 变成透明。 */
1413
+ .si-input:focus-visible,.si-select:focus-visible,.si-num:focus-visible{
1414
+ outline:none;
1415
+ border-color:var(--dsw-alias-state-business-primary);
1416
+ box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-state-business-primary) 18%,transparent)}
1417
+ .si-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
1418
+ /* 只读(direct 行的入口名):外观要能看出不可编辑,否则用户会去点它。 */
1419
+ .si-input[readonly]{color:var(--dsw-alias-label-secondary);
1420
+ background:transparent;border-color:var(--dsw-alias-border-l2);cursor:default}
1421
+ /* 三态选择器:与输入同高的槽,里面是一颗药丸。 */
1422
+ .si-modes{display:inline-flex;align-items:center;gap:2px;box-sizing:border-box;height:36px;padding:2px;
1423
+ border:1px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-3)}
1424
+ .si-mode{height:30px;padding:0 10px;border:none;border-radius:var(--dsw-radius-sm);background:transparent;
1425
+ color:var(--dsw-alias-label-secondary);font-family:inherit;font-size:13px;line-height:18px;cursor:pointer}
1426
+ .si-mode:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
1427
+ .si-mode:focus-visible{outline-offset:1px}
1428
+ .si-mode-active{background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);
1429
+ box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l2)}
1430
+ .si-mode-wrap{position:relative;display:inline-flex}
1431
+ /* 一行说明:悬停与键盘聚焦时出现。 */
1432
+ .si-tip{display:none;position:absolute;top:calc(100% + 8px);right:0;left:auto;z-index:10;box-sizing:border-box;
1433
+ width:min(264px,calc(100vw - 48px));
1434
+ padding:8px 10px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-md);
1435
+ background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);
1436
+ font-size:12px;line-height:18px;font-weight:400;text-align:left;white-space:normal;
1437
+ box-shadow:var(--dsw-elevation-prominent);pointer-events:none}
1438
+ .si-mode-wrap:hover .si-tip,.si-mode-wrap:focus-within .si-tip{display:block}
1439
+ /* 表单右侧的 chip 气泡向左开;行内左侧的徽标气泡向右开。 */
1440
+ .si-row .si-tip{left:0;right:auto}
1441
+ .si-name{flex:1 1 180px;min-width:140px}
1442
+ .si-tags{flex:1 1 140px;min-width:120px}
1443
+ .si-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;
1444
+ height:36px;padding:0 14px;border:none;border-radius:var(--dsw-radius-md);background:transparent;
1445
+ color:var(--dsw-alias-label-primary);font-family:inherit;font-size:14px;line-height:22px;
1446
+ cursor:pointer;white-space:nowrap}
1447
+ .si-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
1448
+ /* 按钮焦点环与输入类同一套:UA 默认 outline 在这套 token 下几乎不可见。
1449
+ 注意别包 var(--dsw-focus-ring-color, …)——该变量在宿主此层是空值,
1450
+ CSS 里空值不触发 fallback(见输入类的注释与断言)。 */
1451
+ .si-btn:focus-visible{outline:none;
1452
+ box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-state-business-primary) 30%,transparent)}
1453
+ .si-btn[disabled]{opacity:.4;cursor:not-allowed}
1454
+ .si-btn-outline{border:.5px solid var(--dsw-alias-border-l3)}
1455
+ .si-btn-outline:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
1456
+ .si-btn-primary{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-foreground)}
1457
+ .si-btn-primary:disabled{background:var(--dsw-alias-button-primary-fill);opacity:.4}
1458
+ /* 宿主主按钮 hover 是**变亮**(button-primary-hover),不是降透明度变暗。 */
1459
+ .si-btn-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover);opacity:1}
1460
+ .si-btn-danger{color:var(--dsw-alias-state-error-primary);border:none}
1461
+ .si-btn-danger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger)}
1462
+ /* 行内小按钮:28px 高、12/18 字号、radius-sm(与宿主设置页行内操作一致)。 */
1463
+ .si-btn-sm{height:28px;padding:0 10px;border-radius:var(--dsw-radius-sm);border:.5px solid var(--dsw-alias-border-l3);
1464
+ font-size:12px;line-height:18px}
1465
+
1466
+ /* ── 弹层里的端点列表与已创建区块 ── */
1467
+ .si-list{display:flex;flex-direction:column;gap:8px;margin:0 24px}
1468
+ .si-row{display:flex;align-items:center;gap:12px;flex-wrap:wrap;padding:12px;
1469
+ border:.5px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-lg)}
1470
+ .si-row-main{flex:1 1 260px;min-width:0}
1471
+ .si-row-actions{display:flex;flex:none;flex-wrap:wrap;gap:8px;justify-content:flex-end;margin-left:auto}
1472
+ .si-row-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
1473
+ .si-row-name{font-weight:500;color:var(--dsw-alias-label-primary)}
1474
+ .si-tag{font-size:11px;line-height:16px;padding:1px 8px;border-radius:999px;
1475
+ background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary)}
1476
+ .si-badge{font-size:11px;line-height:16px;padding:1px 8px;border-radius:999px;
1477
+ border:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary)}
1478
+ /* agent 建的端点:agent 工具可以自行撤销它们,所以用警示色标出来。 */
1479
+ .si-badge-agent{color:var(--dsw-alias-state-warn-label);border-color:var(--dsw-alias-border-l3)}
1480
+ .si-url{margin-top:8px;font-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace);
1481
+ font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);word-break:break-all}
1482
+ .si-row-actions .si-btn{height:28px;padding:0 10px;border-radius:var(--dsw-radius-sm);
1483
+ font-size:12px;line-height:18px;border:.5px solid var(--dsw-alias-border-l3)}
1484
+ .si-row-actions .si-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
1485
+ .si-meta{margin-top:8px;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
1486
+ .si-error{margin:12px 24px 0;color:var(--dsw-alias-state-error-primary);font-size:12px;line-height:18px}
1487
+ .si-note{margin:20px 24px 0;padding-top:12px;border-top:.5px solid var(--dsw-alias-separator-primary);
1488
+ color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
1489
+ .si-warn{margin:0 24px 12px;padding:8px 12px;border-radius:var(--dsw-radius-md);font-size:12px;line-height:18px;
1490
+ color:var(--dsw-alias-state-warn-primary);background:var(--dsw-alias-interactive-bg-hover)}
1491
+ .si-created{margin:0 24px 16px;padding:12px;border-radius:var(--dsw-radius-lg);
1492
+ border:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1)}
1493
+ .si-created-url{font-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace);
1494
+ font-size:12px;line-height:18px;word-break:break-all;margin:6px 0;color:var(--dsw-alias-label-primary)}
1495
+ .si-created-base{margin-top:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
1496
+ /* 多入口时按入口名列路径文件;完整 URL 仍然只在上面那一行出现。 */
1497
+ .si-created-files{display:flex;flex-direction:column;gap:4px;margin-top:8px}
1498
+ .si-created-file{display:flex;align-items:baseline;gap:8px;font-size:12px;line-height:18px}
1499
+ .si-created-file-name{flex:none;min-width:72px;color:var(--dsw-alias-label-secondary)}
1500
+ .si-created-file-path{font-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace);
1501
+ font-size:12px;line-height:18px;color:var(--dsw-alias-label-primary);word-break:break-all}
1502
+ .si-code{font-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace);
1503
+ font-size:11px;line-height:16px;white-space:pre-wrap;word-break:break-all;
1504
+ color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-markdown-code-block);
1505
+ padding:10px 12px;border-radius:var(--dsw-radius-md);margin-top:8px}
1506
+ .si-empty{margin:0 24px;color:var(--dsw-alias-label-tertiary)}
1507
+ .si-inline{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
1508
+
1509
+ /* ── 插件设置页:整体布局照宿主 Settings 页(ui-settings-models 的 section/card 参数)──
1510
+ 宿主 settings.section 的容器已经给了 0 24px 24px 的内边距与滚动,所以这里只排内容。 */
1511
+ .si-page{display:flex;flex-direction:column;gap:12px;max-width:720px;color:var(--dsw-alias-label-primary)}
1512
+ .si-page-title{margin:0;font-size:16px;font-weight:500;line-height:24px}
1513
+ .si-page-intro{margin:0;font-size:14px;line-height:22px;color:var(--dsw-alias-label-tertiary)}
1514
+ .si-page-body{display:flex;flex-direction:column;gap:12px}
1515
+ .si-group{display:flex;flex-direction:column;gap:10px}
1516
+ .si-group+.si-group{margin-top:12px}
1517
+ .si-group-head-row{display:flex;align-items:center;justify-content:space-between;gap:12px}
1518
+ .si-group-head{margin:0;font-size:12px;font-weight:600;line-height:18px;
1519
+ letter-spacing:.06em;color:var(--dsw-alias-label-tertiary)}
1520
+ .si-group-desc{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
1521
+ .si-card{display:flex;flex-direction:column;gap:0;box-sizing:border-box;
1522
+ border:.5px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-xl);
1523
+ background:var(--dsw-alias-settings-card-fill);padding:12px 14px}
1524
+ .si-field{display:flex;flex-direction:column;gap:6px;min-width:0}
1525
+ .si-field-label{font-size:12px;font-weight:500;line-height:18px;color:var(--dsw-alias-label-secondary)}
1526
+ .si-field-help{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
1527
+ /* 宿主 Settings 页的行:标题+说明在左,控件在右,行间一条 hairline。
1528
+ 数值同宿主:padding 16px 0、gap 8px、文本列 padding-right 48px(宿主给的留白)。
1529
+ 注意:类名刻意用 .si-setting-row 而不是 .si-row —— 后者是端点弹层列表行的类名
1530
+ (见上方「弹层里的端点列表」一节)。同名会让后定义的 padding 覆盖先定义的,
1531
+ 表现为弹层行内边距塌成 0、设置页行多出一圈框(QA 实测的 P0 回归)。 */
1532
+ .si-setting-row{display:flex;align-items:center;gap:8px;padding:16px 0;
1533
+ border-bottom:.5px solid var(--dsw-alias-border-l2)}
1534
+ .si-setting-row:last-child{border-bottom:none;padding-bottom:0}
1535
+ .si-setting-row:first-child{padding-top:0}
1536
+ .si-setting-row-text{display:flex;flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px}
1537
+ .si-setting-row-title{font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary)}
1538
+ .si-setting-row-desc{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
1539
+ .si-setting-row-control{display:inline-flex;align-items:center;gap:8px;flex:none}
1540
+ .si-base-item{display:flex;flex-direction:column;gap:4px;padding:12px 0;
1541
+ border-bottom:.5px solid var(--dsw-alias-border-l2)}
1542
+ .si-base-item:first-child{padding-top:0}
1543
+ .si-base-item:nth-last-child(2){border-bottom:none}
1544
+ .si-base-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
1545
+ .si-base-name{flex:0 0 160px;min-width:0}
1546
+ .si-base-url{flex:1 1 200px;min-width:160px}
1547
+ /* 下拉:宿主的「多选一」控件是填充式(bg-module-platform + 无描边 + 14/22 + padding 0 14),
1548
+ 与文本输入框(.5px 描边 + 13px)是两套配方,这里照宿主的来。 */
1549
+ .si-select{padding:0 14px;border:none;outline:none;
1550
+ background:var(--dsw-alias-bg-module-platform);
1551
+ font-size:14px;line-height:22px;border-radius:var(--dsw-radius-md)}
1552
+ .si-select:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
1553
+ .si-select:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
1554
+ /* 注意:这里必须用 width,不能用 flex-basis。
1555
+ 这些输入曾在 .si-field(column 容器)里,那时 flex: 0 0 160px 会被当成**高度**,
1556
+ 渲染出 160px 高的巨型输入框;改成固定 width 后与宿主控件的 36px 一致。 */
1557
+ /* 数字框:去掉浏览器原生的上下箭头(input[type=number] 的 spinner)。
1558
+ 宿主设置页的输入框没有这个元素,留着会让聚焦态看起来"不是同一个控件";
1559
+ 而且这三项都是大整数(1048576 这种),微调按钮没有实际用处——直接手输。
1560
+ 文字左对齐,与宿主输入框一致。 */
1561
+ .si-num{flex:none;width:132px;padding:0 12px;
1562
+ font-variant-numeric:tabular-nums;text-align:left;
1563
+ -moz-appearance:textfield;appearance:textfield}
1564
+ .si-num::-webkit-outer-spin-button,.si-num::-webkit-inner-spin-button{
1565
+ -webkit-appearance:none;appearance:none;margin:0}
1566
+ /* 「添加入口」:虚线占位条。高度取 36px 与同一组里的输入框/下拉对齐,
1567
+ 否则卡片里会出现 44 与 36 两种控件节奏。字号跟控件基线 13px。 */
1568
+ /* 「添加入口」:照宿主设置页的全宽虚线 add 按钮(44px / radius-lg / 14px / 带 + 号)。
1569
+ 不要做成 36px 小按钮——那样读起来像同组里的第 4 个输入框。 */
1570
+ .si-add{box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:6px;
1571
+ width:100%;height:44px;padding:0 14px;border:1px dashed var(--dsw-alias-border-l3);
1572
+ border-radius:var(--dsw-radius-lg);background:transparent;color:var(--dsw-alias-label-primary);
1573
+ font-family:inherit;font-size:14px;line-height:22px;cursor:pointer}
1574
+ .si-add:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
1575
+ .si-add:disabled{opacity:.4;cursor:not-allowed}
1576
+ /* 保存条吸底:页面在 1400×900 下内容高 823 / 可视 746,按老样子保存按钮要滚动才看得到。 */
1577
+ .si-page-actions{position:sticky;bottom:0;z-index:1;
1578
+ display:flex;align-items:center;justify-content:flex-end;gap:12px;flex-wrap:wrap;
1579
+ padding:12px 0;background:var(--dsw-alias-bg-layer-2)}
1580
+ .si-page-errors{margin:0;padding-left:18px;display:flex;flex-direction:column;gap:4px}
1581
+ .si-invalid{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary)}
1582
+ .si-saved{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-state-success-primary)}
1583
+ .si-page-loading{margin:0;font-size:13px;line-height:20px;color:var(--dsw-alias-label-tertiary)}
1584
+ .si-page-note{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-state-warn-label)}
1585
+ `;
1586
+ var STYLESHEET_ID = "dsh-session-webhook/styles.css";
1587
+ function installStyles(ctx) {
1588
+ ctx.effect(() => {
1589
+ if (typeof document === "undefined") return () => {
1590
+ };
1591
+ const tagId = STYLESHEET_ID;
1592
+ const existing = document.head.querySelector(
1593
+ `style[data-plugin-css=${JSON.stringify(tagId)}]`
1594
+ );
1595
+ if (existing !== null) return () => {
1596
+ };
1597
+ const tag = document.createElement("style");
1598
+ tag.dataset.plugin = "dsh-session-webhook";
1599
+ tag.dataset.pluginCss = tagId;
1600
+ tag.textContent = STYLES;
1601
+ document.head.appendChild(tag);
1602
+ return () => {
1603
+ tag.remove();
1604
+ };
1605
+ }, "session-inject: stylesheet");
1606
+ }
1607
+
1608
+ // src/client/main.ts
1609
+ var NS = "session-inject";
1610
+ var DIALOG_BASE = {
1611
+ en: {
1612
+ "menu.open": "Webhook endpoints…",
1613
+ "dialog.title": "Webhook endpoints of this session",
1614
+ "dialog.subtitle": "Each URL delivers one message into this session only.",
1615
+ "dialog.empty": "This session has no webhook endpoint yet.",
1616
+ "dialog.create": "Create",
1617
+ "dialog.namePlaceholder": "Name (e.g. github-notify)",
1618
+ "dialog.tagsPlaceholder": "Tags, comma separated",
1619
+ "dialog.modeLabel": "Default delivery mode",
1620
+ "mode.steer.label": "Steer",
1621
+ "mode.steer.hint": "Join at the nearest step boundary; an idle session starts a turn now. Use it when this must be handled immediately.",
1622
+ "mode.queue.label": "Queue",
1623
+ "mode.queue.hint": "Never interrupts: runs as its own next turn. Use it when it can wait until the current work finishes.",
1624
+ "mode.passive.label": "Passive",
1625
+ "mode.passive.hint": "Context only — never wakes the session, so an idle session leaves it pending. Use it to add information without asking for work.",
1626
+ "dialog.createdTitle": "Endpoint created — copy it now",
1627
+ "dialog.copy": "Copy",
1628
+ "dialog.copied": "Copied",
1629
+ "dialog.reveal": "Show",
1630
+ "dialog.revoke": "Delete",
1631
+ "dialog.disable": "Disable",
1632
+ "dialog.enable": "Enable",
1633
+ "dialog.rename": "Rename",
1634
+ "dialog.save": "Save",
1635
+ "dialog.cancel": "Cancel",
1636
+ "dialog.close": "Close",
1637
+ "dialog.lastUsed": "Last delivery {time}",
1638
+ "dialog.neverUsed": "Never used",
1639
+ "dialog.deliveryCount": "{count} deliveries",
1640
+ "dialog.statusDelivered": "delivered",
1641
+ "dialog.statusFailed": "failed",
1642
+ "dialog.disabled": "disabled",
1643
+ "dialog.archived": "This session is archived, so its endpoints accept deliveries that never run.",
1644
+ "dialog.securityNote": "Anyone holding a URL can deliver messages into this session, and the agent may run tools. Keep it private; delete an endpoint to revoke it.",
1645
+ "dialog.curlHint": "Call it like this:",
1646
+ "dialog.error": "Operation failed: {message}"
1647
+ },
1648
+ zh: {
1649
+ "menu.open": "Webhook 端点…",
1650
+ "dialog.title": "本会话的 Webhook 端点",
1651
+ "dialog.subtitle": "每条 URL 只能把消息投进这一个会话。",
1652
+ "dialog.empty": "这个会话还没有 webhook 端点。",
1653
+ "dialog.create": "创建",
1654
+ "dialog.namePlaceholder": "名称(例如 github-notify)",
1655
+ "dialog.tagsPlaceholder": "标签,用逗号分隔",
1656
+ "dialog.modeLabel": "默认投递方式",
1657
+ "mode.steer.label": "插话",
1658
+ "mode.steer.hint": "在会话当前这一步结束时插入;会话空闲就直接开始新一轮。适合「现在就得处理」。",
1659
+ "mode.queue.label": "排队",
1660
+ "mode.queue.hint": "不打断当前工作,排成下一整轮再处理。适合「可以等一等」。",
1661
+ "mode.passive.label": "静默",
1662
+ "mode.passive.hint": "只把消息放进上下文,不唤醒会话;会话空闲时会一直搁着。适合「只补充信息、不要它干活」。",
1663
+ "dialog.createdTitle": "端点已创建 —— 现在复制",
1664
+ "dialog.copy": "复制",
1665
+ "dialog.copied": "已复制",
1666
+ "dialog.reveal": "显示",
1667
+ "dialog.revoke": "删除",
1668
+ "dialog.disable": "停用",
1669
+ "dialog.enable": "启用",
1670
+ "dialog.rename": "改名",
1671
+ "dialog.save": "保存",
1672
+ "dialog.cancel": "取消",
1673
+ "dialog.close": "关闭",
1674
+ "dialog.lastUsed": "最近投递 {time}",
1675
+ "dialog.neverUsed": "从未使用",
1676
+ "dialog.deliveryCount": "已完成 {count} 次投递",
1677
+ "dialog.statusDelivered": "成功",
1678
+ "dialog.statusFailed": "失败",
1679
+ "dialog.disabled": "已停用",
1680
+ "dialog.archived": "该会话已归档:端点仍能接收投递,但会话永远不会执行。",
1681
+ "dialog.securityNote": "持有 URL 的人即可向本会话投递消息,agent 可能执行工具。请勿外传;删除端点即吊销。",
1682
+ "dialog.curlHint": "调用方式:",
1683
+ "dialog.error": "操作失败:{message}"
1684
+ }
1685
+ };
1686
+ var __test__ = {
1687
+ // 弹层 / 菜单行(原有 9 项断言依赖这四个名字)
1688
+ WebhookMenuItem,
1689
+ WebhookDialog,
1690
+ WebhookPanel,
1691
+ Row,
1692
+ CreatedBlock,
1693
+ openDialog,
1694
+ closeDialog,
1695
+ // 设置页:容器 + 纯展示树 + 校验/草稿纯函数
1696
+ SettingsSection,
1697
+ SettingsPanel,
1698
+ validateDraft,
1699
+ draftFromConfig,
1700
+ isDraftDirty,
1701
+ readConfig,
1702
+ rowIsFromYaml,
1703
+ baseSourceHint,
1704
+ limitSourceHint,
1705
+ defaultBaseSourceHint,
1706
+ addBaseRow,
1707
+ lastRowId,
1708
+ removeBaseRow,
1709
+ resetDirectRow,
1710
+ setDefaultBase,
1711
+ setLimitField,
1712
+ updateBaseRow,
1713
+ EMPTY_DRAFT,
1714
+ LIMIT_BOUNDS,
1715
+ DEFAULT_LIMITS,
1716
+ CONFIG_LAYER_KEYS,
1717
+ hasBasesOverride,
1718
+ hasLimitsOverride,
1719
+ // RPC 边界与样式表
1720
+ createRpc,
1721
+ RpcError,
1722
+ STYLES,
1723
+ // locale 分片(测试断言中英键集一致)
1724
+ DIALOG_LOCALE,
1725
+ SETTINGS_LOCALE
1726
+ };
1727
+ var inject = ["slots", "locale", "connection"];
1728
+ function apply(ctx) {
1729
+ installStyles(ctx);
1730
+ ctx.effect(() => ctx.locale.register(NS, {
1731
+ en: { ...DIALOG_BASE.en, ...DIALOG_LOCALE.en, ...SETTINGS_LOCALE.en },
1732
+ zh: { ...DIALOG_BASE.zh, ...DIALOG_LOCALE.zh, ...SETTINGS_LOCALE.zh }
1733
+ }), "session-inject: dictionaries");
1734
+ const t = ctx.locale.bind(NS);
1735
+ const rpc = createRpc(ctx);
1736
+ ctx.slots.inject("sidebar.workspaces.session.menu.item", () => ctx.slots.register({
1737
+ name: "sidebar.workspaces.session.menu.item",
1738
+ id: "session-inject.webhook",
1739
+ order: 460,
1740
+ locale: NS,
1741
+ inject: () => ({ openWebhooks: openDialog })
1742
+ }, WebhookMenuItem));
1743
+ ctx.slots.inject("shell.overlay", () => ctx.slots.register({
1744
+ name: "shell.overlay",
1745
+ id: "session-inject.dialog",
1746
+ order: 20,
1747
+ locale: NS,
1748
+ inject: () => ({ rpc })
1749
+ }, WebhookDialog));
1750
+ registerSettingsSection(ctx, { rpc, t });
1751
+ }
1752
+
1753
+ return module.exports;
1754
+ }
1755
+ });