@jeffusion/bungee-core 6.17.0 → 6.18.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.
@@ -0,0 +1,674 @@
1
+ <script lang="ts">
2
+ import { onMount, tick } from 'svelte';
3
+ import { locale } from 'svelte-i18n';
4
+ import AlertCircle from 'lucide-svelte/icons/alert-circle';
5
+ import CheckCircle2 from 'lucide-svelte/icons/check-circle-2';
6
+ import Info from 'lucide-svelte/icons/info';
7
+ import RefreshCw from 'lucide-svelte/icons/refresh-cw';
8
+ import RouteIcon from 'lucide-svelte/icons/route';
9
+ import Save from 'lucide-svelte/icons/save';
10
+ import Search from 'lucide-svelte/icons/search';
11
+ import Shield from 'lucide-svelte/icons/shield';
12
+ import Unlink from 'lucide-svelte/icons/unlink';
13
+ import { BSelect, LoadingIndicator, PanelCard, SectionDivider, StatusBadge, StatusDot, SystemAlertBar } from '$components/industrial';
14
+ import { Button } from '$components/ui/button';
15
+ import { confirmAction } from '$stores/confirmation';
16
+ import { editorDirty } from '$stores/navigation-guard';
17
+ import RedactionRulesEditor from './RedactionRulesEditor.svelte';
18
+ import RequestBodyRedactionStats from './RequestBodyRedactionStats.svelte';
19
+ import { loadRedactionRoutes, RedactionRouteConflictError, redactionConfigurationWrite, saveRedactionRouteBinding, type RedactionRouteBinding } from './route-bindings';
20
+
21
+ let { pluginName = 'request-body-redaction' }: { pluginName?: string } = $props();
22
+ const uid = $props.id();
23
+ const pickerId = `${uid}-route`;
24
+
25
+ const copy = $derived($locale?.startsWith('zh') ? {
26
+ section: 'REQUEST BODY SANITIZATION',
27
+ title: '请求脱敏',
28
+ scopeBadge: '仅处理出站 JSON 字符串值',
29
+ intro: '在转发上游前按路由规则替换 JSON 请求正文中的敏感字符串值,不改写键名、非字符串值、请求头或响应。',
30
+ routesSection: '路由脱敏策略',
31
+ routeList: '路由列表',
32
+ route: '当前路由',
33
+ switchRoute: '切换路由',
34
+ choose: '选择路由',
35
+ rules: '脱敏规则管线',
36
+ ready: '已绑定',
37
+ off: '已停用',
38
+ unbound: '未绑定',
39
+ unsaved: '未保存',
40
+ synced: '配置已同步',
41
+ filterAll: '全部',
42
+ filterBound: '已绑定',
43
+ filterUnbound: '未绑定',
44
+ search: '搜索路由路径…',
45
+ noMatch: '没有匹配的路由',
46
+ resetFilter: '重置筛选',
47
+ ruleCount: (n: number) => `${n} 条规则`,
48
+ invalidRuleCount: '规则异常',
49
+ summaryBound: (n: number) => `${n} 生效中`,
50
+ summaryOff: (n: number) => `${n} 已停用`,
51
+ summaryUnbound: (n: number) => `${n} 未绑定`,
52
+ disabledNotice: '当前路由的脱敏绑定处于停用状态,保存规则后将自动重新启用。',
53
+ bind: '绑定并保存规则',
54
+ enable: '启用并保存规则',
55
+ save: '保存规则',
56
+ unbind: '解除绑定',
57
+ cancel: '取消',
58
+ keep: '继续编辑',
59
+ discard: '放弃草稿',
60
+ discardTitle: '放弃草稿?',
61
+ discardMessage: '未保存的修改将丢失。',
62
+ unbindTitle: '解除绑定?',
63
+ unbindMessage: (path: string) => `解绑将删除 ${path} 的脱敏规则。`,
64
+ loading: '正在加载路由配置…',
65
+ noRoutesTitle: '尚无可用路由',
66
+ noRoutes: '请先在路由管理中创建至少一条路由,再为其配置请求脱敏规则。',
67
+ goRoutes: '前往路由管理',
68
+ selectPromptTitle: '选择一条路由以配置规则',
69
+ selectPrompt: '从左侧路由列表中选择需要脱敏的路由,独立管理其字面文本或 RE2 正则替换管线。',
70
+ retry: '重试',
71
+ refreshRoutes: '重载路由',
72
+ saving: '保存中…',
73
+ saved: '规则已保存,工作进程生效可能有短暂延迟。',
74
+ removed: '解绑已保存,工作进程生效可能有短暂延迟。',
75
+ loadError: '无法加载路由列表,请检查控制面状态后重试。',
76
+ saveError: '保存结果未确认,请核对配置状态后再试。',
77
+ conflict: '路由配置已被其他操作变更,本次修改未保存。',
78
+ reload: '放弃草稿并重新加载',
79
+ reloadClean: '重新加载路由',
80
+ writeBlockedTitle: '上次配置写入结果未确认',
81
+ writeBlocked: '请先前往「全局设置」核对当前发布状态,确认无误后再提交脱敏变更。',
82
+ openSettings: '全局设置',
83
+ fixHint: '请先补全或修正标记为红色的规则项',
84
+ needRuleHint: '至少添加 1 条有效规则后可保存',
85
+ } : {
86
+ section: 'REQUEST BODY SANITIZATION',
87
+ title: 'Request Redaction',
88
+ scopeBadge: 'OUTBOUND JSON STRINGS ONLY',
89
+ intro: 'Sanitize sensitive string values in outbound JSON request bodies per route before forwarding. Keys, primitives, headers, and responses remain untouched.',
90
+ routesSection: 'Route Redaction Policies',
91
+ routeList: 'Route Inventory',
92
+ route: 'Active Route',
93
+ switchRoute: 'Switch Route',
94
+ choose: 'Select a route',
95
+ rules: 'Redaction Pipeline',
96
+ ready: 'Bound',
97
+ off: 'Disabled',
98
+ unbound: 'Unbound',
99
+ unsaved: 'Unsaved',
100
+ synced: 'Synced',
101
+ filterAll: 'All',
102
+ filterBound: 'Bound',
103
+ filterUnbound: 'Unbound',
104
+ search: 'Filter route path…',
105
+ noMatch: 'No matching routes',
106
+ resetFilter: 'Reset filter',
107
+ ruleCount: (n: number) => `${n} ${n === 1 ? 'rule' : 'rules'}`,
108
+ invalidRuleCount: 'Invalid',
109
+ summaryBound: (n: number) => `${n} active`,
110
+ summaryOff: (n: number) => `${n} disabled`,
111
+ summaryUnbound: (n: number) => `${n} unbound`,
112
+ disabledNotice: 'Redaction binding on this route is currently disabled. Saving rules will re-enable it.',
113
+ bind: 'Bind & save rules',
114
+ enable: 'Enable & save rules',
115
+ save: 'Save rules',
116
+ unbind: 'Unbind route',
117
+ cancel: 'Cancel',
118
+ keep: 'Keep editing',
119
+ discard: 'Discard draft',
120
+ discardTitle: 'Discard draft?',
121
+ discardMessage: 'Unsaved changes will be lost.',
122
+ unbindTitle: 'Unbind route?',
123
+ unbindMessage: (path: string) => `Unbinding deletes the redaction rules for ${path}.`,
124
+ loading: 'Loading route bindings…',
125
+ noRoutesTitle: 'No routes available',
126
+ noRoutes: 'Create a route in Route Management first, then return here to attach redaction rules.',
127
+ goRoutes: 'Open Route Management',
128
+ selectPromptTitle: 'Select a route to configure',
129
+ selectPrompt: 'Pick a route from the inventory on the left to edit its ordered literal and RE2 regex rules.',
130
+ retry: 'Retry',
131
+ refreshRoutes: 'Reload routes',
132
+ saving: 'Saving…',
133
+ saved: 'Rules saved. Workers may take a moment to converge.',
134
+ removed: 'Unbinding saved. Workers may take a moment to converge.',
135
+ loadError: 'Could not load routes. Check the control plane and retry.',
136
+ saveError: 'Save unconfirmed. Check configuration status before retrying.',
137
+ conflict: 'The route configuration changed elsewhere. Nothing was saved.',
138
+ reload: 'Discard draft & reload',
139
+ reloadClean: 'Reload routes',
140
+ writeBlockedTitle: 'Previous configuration write unconfirmed',
141
+ writeBlocked: 'Verify publication status in Global Settings before submitting further redaction changes.',
142
+ openSettings: 'Global Settings',
143
+ fixHint: 'Resolve highlighted rule errors before saving',
144
+ needRuleHint: 'Add at least 1 valid rule to save',
145
+ });
146
+
147
+ type RouteFilter = 'all' | 'bound' | 'unbound';
148
+
149
+ let routes = $state<RedactionRouteBinding[]>([]);
150
+ let selected = $state('');
151
+ let pickerValue = $state('');
152
+ let searchQuery = $state('');
153
+ let filterState = $state<RouteFilter>('all');
154
+ let draft = $state<unknown>(undefined);
155
+ let invalid = $state(false);
156
+ let revision = $state(0);
157
+ let loading = $state(true);
158
+ let saving = $state(false);
159
+ let loadFailed = $state(false);
160
+ let problem = $state<'conflict' | 'saveError' | null>(null);
161
+ let notice = $state<'saved' | 'removed' | null>(null);
162
+
163
+ const route = $derived(routes.find(item => item.id === selected));
164
+ const dirty = $derived(!!route && JSON.stringify(draft) !== JSON.stringify(route.binding?.rules));
165
+ const canSaveRules = $derived(Array.isArray(draft) && !!draft.length && !invalid && (dirty || route?.binding?.enabled === false));
166
+ const writeBlocked = $derived($redactionConfigurationWrite.corrupt || !!($redactionConfigurationWrite.pending && !$redactionConfigurationWrite.pending.accepted));
167
+
168
+ const activeBoundCount = $derived(routes.filter(r => r.binding?.enabled).length);
169
+ const disabledBoundCount = $derived(routes.filter(r => r.binding && !r.binding.enabled).length);
170
+ const boundTotalCount = $derived(activeBoundCount + disabledBoundCount);
171
+ const unboundCount = $derived(routes.length - boundTotalCount);
172
+
173
+ const filterOptions = $derived([
174
+ { value: 'all' as const, label: copy.filterAll, count: routes.length },
175
+ { value: 'bound' as const, label: copy.filterBound, count: boundTotalCount },
176
+ { value: 'unbound' as const, label: copy.filterUnbound, count: unboundCount },
177
+ ]);
178
+
179
+ function handleFilterKeydown(event: KeyboardEvent, index: number) {
180
+ let nextIndex: number;
181
+ switch (event.key) {
182
+ case 'ArrowRight':
183
+ case 'ArrowDown': nextIndex = (index + 1) % filterOptions.length; break;
184
+ case 'ArrowLeft':
185
+ case 'ArrowUp': nextIndex = (index - 1 + filterOptions.length) % filterOptions.length; break;
186
+ case 'Home': nextIndex = 0; break;
187
+ case 'End': nextIndex = filterOptions.length - 1; break;
188
+ default: return;
189
+ }
190
+ event.preventDefault();
191
+ filterState = filterOptions[nextIndex].value;
192
+ ((event.currentTarget as HTMLButtonElement).parentElement?.children.item(nextIndex) as HTMLElement | null)?.focus();
193
+ }
194
+
195
+ const filteredRoutes = $derived.by(() => {
196
+ const q = searchQuery.trim().toLowerCase();
197
+ return routes.filter(item => {
198
+ if (filterState === 'bound' && !item.binding) return false;
199
+ if (filterState === 'unbound' && item.binding) return false;
200
+ if (q && !item.path.toLowerCase().includes(q)) return false;
201
+ return true;
202
+ });
203
+ });
204
+
205
+ const mobileRouteOptions = $derived(routes.map(item => {
206
+ const statusText = item.binding
207
+ ? item.binding.enabled ? copy.ready : copy.off
208
+ : copy.unbound;
209
+ const countSuffix = item.binding && Array.isArray(item.binding.rules)
210
+ ? ` · ${item.binding.rules.length}`
211
+ : '';
212
+ return {
213
+ value: item.id,
214
+ label: `${item.path} [${statusText}${countSuffix}]`,
215
+ };
216
+ }));
217
+
218
+ let mounted = false;
219
+
220
+ onMount(() => {
221
+ mounted = true;
222
+ void refresh();
223
+ return () => {
224
+ mounted = false;
225
+ editorDirty.set(false);
226
+ };
227
+ });
228
+
229
+ $effect(() => { editorDirty.set(dirty || saving); });
230
+
231
+ function routeStatusDot(item: RedactionRouteBinding): 'ok' | 'warn' | 'idle' {
232
+ if (!item.binding) return 'idle';
233
+ return item.binding.enabled ? 'ok' : 'warn';
234
+ }
235
+
236
+ function routeRuleSummary(item: RedactionRouteBinding): string {
237
+ if (!item.binding) return copy.unbound;
238
+ if (!Array.isArray(item.binding.rules)) return copy.invalidRuleCount;
239
+ return copy.ruleCount(item.binding.rules.length);
240
+ }
241
+
242
+ function openRoute(id: string) {
243
+ selected = id;
244
+ pickerValue = id;
245
+ draft = routes.find(item => item.id === id)?.binding?.rules;
246
+ invalid = false;
247
+ problem = null;
248
+ notice = null;
249
+ revision++;
250
+ }
251
+
252
+ async function refresh() {
253
+ loading = true;
254
+ loadFailed = false;
255
+ try {
256
+ const result = await loadRedactionRoutes();
257
+ if (!mounted) return;
258
+ routes = result;
259
+ const fallback = result.find(item => item.binding?.enabled)?.id
260
+ ?? result.find(item => item.binding)?.id
261
+ ?? result[0]?.id
262
+ ?? '';
263
+ openRoute(result.some(item => item.id === selected) ? selected : fallback);
264
+ } catch {
265
+ if (mounted) loadFailed = true;
266
+ } finally {
267
+ if (mounted) loading = false;
268
+ }
269
+ }
270
+
271
+ function confirmDiscard() {
272
+ return confirmAction({
273
+ title: copy.discardTitle,
274
+ message: copy.discardMessage,
275
+ confirmText: copy.discard,
276
+ cancelText: copy.keep,
277
+ });
278
+ }
279
+
280
+ async function selectRoute(id: string | string[]) {
281
+ if (typeof id !== 'string' || id === selected || saving || loading) return;
282
+ if (dirty && !await confirmDiscard()) {
283
+ pickerValue = selected;
284
+ return;
285
+ }
286
+ if (mounted) openRoute(id);
287
+ }
288
+
289
+ async function reload() {
290
+ if (dirty && !await confirmDiscard()) return;
291
+ if (mounted) await refresh();
292
+ }
293
+
294
+ async function commit(unbind: boolean) {
295
+ const baseline = route;
296
+ if (!baseline || problem === 'conflict' || loading || saving || writeBlocked) return;
297
+ if (unbind) {
298
+ if (!baseline.binding || !await confirmAction({
299
+ title: copy.unbindTitle,
300
+ message: copy.unbindMessage(baseline.path),
301
+ confirmText: copy.unbind,
302
+ cancelText: copy.cancel,
303
+ })) return;
304
+ if (!mounted || route !== baseline || saving || loading || writeBlocked) return;
305
+ } else if (!canSaveRules) return;
306
+
307
+ saving = true;
308
+ problem = null;
309
+ notice = null;
310
+ try {
311
+ const result = await saveRedactionRouteBinding($state.snapshot(baseline), unbind ? null : $state.snapshot(draft) as unknown[]);
312
+ if (!mounted || selected !== baseline.id) return;
313
+ routes = routes.map(item => item.id === result.id ? result : item);
314
+ openRoute(result.id);
315
+ notice = unbind ? 'removed' : 'saved';
316
+ } catch (error) {
317
+ if (mounted && selected === baseline.id) {
318
+ problem = error instanceof RedactionRouteConflictError ? 'conflict' : 'saveError';
319
+ }
320
+ } finally {
321
+ if (mounted) {
322
+ saving = false;
323
+ if (notice === 'removed') {
324
+ await tick();
325
+ if (mounted) {
326
+ const activeRow = document.getElementById(`${uid}-row-${selected}`);
327
+ const mobilePicker = document.getElementById(pickerId);
328
+ if (activeRow && activeRow.offsetParent !== null) activeRow.focus();
329
+ else mobilePicker?.focus();
330
+ }
331
+ }
332
+ }
333
+ }
334
+ }
335
+ </script>
336
+
337
+ <div class="nx-page space-y-5 py-5" data-testid="request-body-redaction-page">
338
+ <!-- Standard §5.2 Page Header -->
339
+ <header class="flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between">
340
+ <div class="space-y-1.5">
341
+ <div class="flex items-center gap-3">
342
+ <span class="nx-stripe" aria-hidden="true"></span>
343
+ <div class="flex flex-col leading-tight">
344
+ <span class="nx-label">// {copy.section}</span>
345
+ <h1 class="nx-display text-xl tracking-[0.02em] text-zinc-50">{copy.title}</h1>
346
+ </div>
347
+ </div>
348
+ <p class="text-sm text-zinc-400">{copy.intro}</p>
349
+ </div>
350
+
351
+ <div class="flex flex-wrap items-center gap-2 self-start lg:self-center">
352
+ <span class="inline-flex items-center gap-1.5 border border-carbon-600 bg-carbon-900 px-2.5 py-1.5 font-mono text-[10px] uppercase tracking-command text-zinc-300">
353
+ <Shield class="h-3.5 w-3.5 text-nexus-400" aria-hidden="true" />
354
+ {copy.scopeBadge}
355
+ </span>
356
+ <Button variant="ghost" size="sm" disabled={loading || saving} onclick={reload}>
357
+ <RefreshCw class="mr-1.5 h-3.5 w-3.5 {loading ? 'motion-safe:animate-spin' : ''}" aria-hidden="true" />
358
+ {copy.refreshRoutes}
359
+ </Button>
360
+ </div>
361
+ </header>
362
+
363
+ <!-- Global Telemetry Strip -->
364
+ <RequestBodyRedactionStats {pluginName} />
365
+
366
+ <!-- Route Redaction Policies Section -->
367
+ <section class="space-y-3" data-testid="request-body-redaction-bindings">
368
+ <SectionDivider label={copy.routesSection}>
369
+ <div slot="actions" class="hidden flex-wrap items-center gap-2 sm:flex">
370
+ {#if routes.length > 0}
371
+ <span class="nx-badge-active">{copy.summaryBound(activeBoundCount)}</span>
372
+ {#if disabledBoundCount > 0}
373
+ <span class="nx-badge-standby">{copy.summaryOff(disabledBoundCount)}</span>
374
+ {/if}
375
+ <span class="nx-badge-muted">{copy.summaryUnbound(unboundCount)}</span>
376
+ {/if}
377
+ </div>
378
+ </SectionDivider>
379
+ {#if routes.length > 0}
380
+ <div class="flex flex-wrap items-center gap-2 sm:hidden">
381
+ <span class="nx-badge-active">{copy.summaryBound(activeBoundCount)}</span>
382
+ {#if disabledBoundCount > 0}
383
+ <span class="nx-badge-standby">{copy.summaryOff(disabledBoundCount)}</span>
384
+ {/if}
385
+ <span class="nx-badge-muted">{copy.summaryUnbound(unboundCount)}</span>
386
+ </div>
387
+ {/if}
388
+
389
+ {#if writeBlocked}
390
+ <SystemAlertBar tone="warn" title={copy.writeBlockedTitle} subtitle={copy.writeBlocked}>
391
+ <a slot="action" href="/#/config" class="nx-btn-ghost nx-btn-sm">{copy.openSettings}</a>
392
+ </SystemAlertBar>
393
+ {/if}
394
+
395
+ {#if loadFailed && !routes.length}
396
+ <PanelCard title={copy.routeList} tag="ERROR" stripe="red">
397
+ <div class="flex flex-wrap items-center justify-between gap-3">
398
+ <div class="flex items-center gap-2.5 text-sm text-red-300" role="alert">
399
+ <AlertCircle class="h-4 w-4 shrink-0" aria-hidden="true" />
400
+ <span>{copy.loadError}</span>
401
+ </div>
402
+ <Button variant="outline" size="sm" onclick={reload} disabled={loading}>{copy.retry}</Button>
403
+ </div>
404
+ </PanelCard>
405
+ {:else if loading && !routes.length}
406
+ <PanelCard title={copy.routeList} tag="LOADING">
407
+ <LoadingIndicator label={copy.loading} size="md" height="sm" />
408
+ </PanelCard>
409
+ {:else if !routes.length}
410
+ <PanelCard title={copy.noRoutesTitle} tag="EMPTY" stripe="zinc">
411
+ <div class="flex flex-col items-center justify-center gap-3 py-10 text-center">
412
+ <span class="flex h-12 w-12 items-center justify-center border border-carbon-500 bg-carbon-900 text-zinc-400">
413
+ <RouteIcon class="h-5 w-5" aria-hidden="true" />
414
+ </span>
415
+ <div class="max-w-md space-y-1">
416
+ <p class="font-mono text-xs font-bold uppercase tracking-command text-zinc-200">{copy.noRoutesTitle}</p>
417
+ <p class="text-sm text-zinc-400">{copy.noRoutes}</p>
418
+ </div>
419
+ <a href="/#/routes" class="nx-btn-primary mt-1">{copy.goRoutes}</a>
420
+ </div>
421
+ </PanelCard>
422
+ {:else}
423
+ {#if loadFailed}
424
+ <div role="alert" class="flex flex-wrap items-center justify-between gap-2 border-l-2 border-red-500 bg-red-500/10 px-3 py-2 text-sm text-red-300">
425
+ <span>{copy.loadError}</span>
426
+ <Button variant="ghost" size="sm" onclick={reload} disabled={loading}>{copy.retry}</Button>
427
+ </div>
428
+ {/if}
429
+
430
+ <!-- Mobile & Tablet Route Switcher (< lg) -->
431
+ <div class="lg:hidden">
432
+ <PanelCard title={copy.switchRoute} tag={`${boundTotalCount} / ${routes.length}`}>
433
+ <div>
434
+ <label for={pickerId} class="sr-only">{copy.switchRoute}</label>
435
+ <BSelect
436
+ id={pickerId}
437
+ searchable
438
+ ariaLabel={copy.switchRoute}
439
+ placeholder={copy.choose}
440
+ bind:value={pickerValue}
441
+ searchLabels={{ search: copy.search, empty: copy.noMatch }}
442
+ options={mobileRouteOptions}
443
+ disabled={loading || saving}
444
+ onchange={selectRoute}
445
+ />
446
+ </div>
447
+ </PanelCard>
448
+ </div>
449
+
450
+ <!-- Desktop Master-Detail Split Grid -->
451
+ <div class="workspace-grid">
452
+ <!-- Left Rail: Route Inventory (Desktop lg+) -->
453
+ <div class="hidden min-w-0 lg:block">
454
+ <PanelCard title={copy.routeList} tag={`${boundTotalCount} / ${routes.length}`} flush>
455
+ <div class="space-y-2.5 border-b border-carbon-600 bg-carbon-900/50 p-3">
456
+ <div class="relative">
457
+ <Search class="pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-zinc-500" aria-hidden="true" />
458
+ <input
459
+ type="text"
460
+ class="nx-input pl-9"
461
+ bind:value={searchQuery}
462
+ placeholder={copy.search}
463
+ aria-label={copy.search}
464
+ />
465
+ </div>
466
+ <div
467
+ role="radiogroup"
468
+ aria-label={copy.routeList}
469
+ class="grid grid-cols-3 border border-carbon-600 bg-carbon-900"
470
+ >
471
+ {#each filterOptions as opt, index (opt.value)}
472
+ {@const active = filterState === opt.value}
473
+ <button
474
+ type="button"
475
+ role="radio"
476
+ aria-checked={active}
477
+ tabindex={active ? 0 : -1}
478
+ class="flex items-center justify-center gap-1 whitespace-nowrap px-2 py-1.5 font-mono text-[10px] font-semibold uppercase tracking-command transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-nexus-500 {active ? 'bg-nexus-500 text-black' : 'text-zinc-400 hover:bg-carbon-700 hover:text-nexus-300'}"
479
+ onclick={() => { filterState = opt.value; }}
480
+ onkeydown={event => handleFilterKeydown(event, index)}
481
+ >
482
+ <span>{opt.label}</span>
483
+ <span class="tabular-nums {active ? 'text-black/75' : 'text-zinc-500'}">{opt.count}</span>
484
+ </button>
485
+ {/each}
486
+ </div>
487
+ </div>
488
+
489
+ {#if filteredRoutes.length === 0}
490
+ <div class="space-y-2.5 px-4 py-8 text-center">
491
+ <p class="text-xs text-zinc-400">{copy.noMatch}</p>
492
+ <Button
493
+ variant="ghost"
494
+ size="sm"
495
+ onclick={() => { searchQuery = ''; filterState = 'all'; }}
496
+ >
497
+ {copy.resetFilter}
498
+ </Button>
499
+ </div>
500
+ {:else}
501
+ <div class="max-h-[600px] overflow-y-auto" role="listbox" aria-label={copy.routeList}>
502
+ {#each filteredRoutes as item (item.id)}
503
+ {@const isSelected = item.id === selected}
504
+ <button
505
+ id={`${uid}-row-${item.id}`}
506
+ type="button"
507
+ role="option"
508
+ aria-selected={isSelected}
509
+ disabled={loading || saving}
510
+ onclick={() => selectRoute(item.id)}
511
+ class="nx-row w-full cursor-pointer gap-3 text-left disabled:cursor-not-allowed disabled:opacity-60 {isSelected ? 'nx-row-active' : ''}"
512
+ >
513
+ <div class="flex min-w-0 flex-1 items-center gap-2.5">
514
+ <StatusDot status={routeStatusDot(item)} />
515
+ <div class="min-w-0 flex-1">
516
+ <div class="truncate font-mono text-xs font-medium {isSelected ? 'text-nexus-300' : 'text-zinc-100'}" title={item.path}>
517
+ {item.path}
518
+ </div>
519
+ <div class="mt-0.5 font-mono text-[10px] text-zinc-500">
520
+ {routeRuleSummary(item)}
521
+ </div>
522
+ </div>
523
+ </div>
524
+
525
+ <div class="flex shrink-0 items-center gap-1.5">
526
+ {#if isSelected && dirty}
527
+ <span class="border border-nexus-500/60 bg-nexus-500/15 px-1.5 py-0.5 font-mono text-[9px] uppercase tracking-chiseled text-nexus-300">
528
+ {copy.unsaved}
529
+ </span>
530
+ {:else if item.binding?.enabled}
531
+ <span class="nx-feature-tag border-emerald-500/40 bg-emerald-500/10 text-emerald-300">{copy.ready}</span>
532
+ {:else if item.binding}
533
+ <span class="nx-feature-tag border-amber-500/40 bg-amber-500/10 text-amber-300">{copy.off}</span>
534
+ {/if}
535
+ </div>
536
+ </button>
537
+ {/each}
538
+ </div>
539
+ {/if}
540
+ </PanelCard>
541
+ </div>
542
+
543
+ <!-- Right Workbench: Selected Route Rule Pipeline -->
544
+ <div class="min-w-0">
545
+ {#if route}
546
+ <PanelCard title={copy.route}>
547
+ <code
548
+ slot="title-extra"
549
+ class="ml-1 truncate border border-carbon-600 bg-carbon-950 px-2 py-0.5 font-mono text-xs font-medium normal-case tracking-normal text-zinc-100"
550
+ title={route.path}
551
+ >{route.path}</code>
552
+ <div slot="actions" class="flex flex-wrap items-center gap-2">
553
+ {#if dirty}
554
+ <StatusBadge variant="online">{copy.unsaved}</StatusBadge>
555
+ {/if}
556
+ <StatusBadge
557
+ variant={route.binding?.enabled ? 'active' : route.binding ? 'standby' : 'muted'}
558
+ dot
559
+ >
560
+ {route.binding ? route.binding.enabled ? copy.ready : copy.off : copy.unbound}
561
+ </StatusBadge>
562
+ </div>
563
+
564
+ <div class="space-y-4">
565
+ {#if problem}
566
+ <div role="alert" class="flex items-start gap-2.5 border-l-2 border-red-500 bg-red-500/10 px-3.5 py-2.5 text-sm text-red-200">
567
+ <AlertCircle class="mt-0.5 h-4 w-4 shrink-0 text-red-400" aria-hidden="true" />
568
+ <span>{copy[problem]}</span>
569
+ </div>
570
+ {/if}
571
+
572
+ {#if notice}
573
+ <div role="status" class="flex items-start gap-2.5 border-l-2 border-emerald-500 bg-emerald-500/10 px-3.5 py-2.5 text-sm text-emerald-200">
574
+ <CheckCircle2 class="mt-0.5 h-4 w-4 shrink-0 text-emerald-400" aria-hidden="true" />
575
+ <span>{copy[notice]}</span>
576
+ </div>
577
+ {/if}
578
+
579
+ {#if route.binding && !route.binding.enabled && !problem}
580
+ <div role="status" class="flex items-start gap-2.5 border-l-2 border-amber-500 bg-amber-500/10 px-3.5 py-2.5 text-sm text-amber-200">
581
+ <Info class="mt-0.5 h-4 w-4 shrink-0 text-amber-400" aria-hidden="true" />
582
+ <span>{copy.disabledNotice}</span>
583
+ </div>
584
+ {/if}
585
+
586
+ <div inert={saving || loading}>
587
+ {#key revision}
588
+ <RedactionRulesEditor
589
+ value={draft}
590
+ label={copy.rules}
591
+ onchange={rules => { draft = rules; notice = null; }}
592
+ onvalidate={value => { invalid = value; }}
593
+ />
594
+ {/key}
595
+ </div>
596
+ </div>
597
+
598
+ <div slot="foot" class="flex flex-wrap items-center justify-between gap-3">
599
+ <div class="flex items-center gap-2">
600
+ {#if route.binding && problem !== 'conflict'}
601
+ <Button
602
+ variant="destructive"
603
+ size="sm"
604
+ disabled={saving || loading || writeBlocked}
605
+ onclick={() => commit(true)}
606
+ >
607
+ <Unlink class="mr-1.5 h-3.5 w-3.5" aria-hidden="true" />
608
+ {copy.unbind}
609
+ </Button>
610
+ {/if}
611
+ </div>
612
+
613
+ <div class="flex flex-wrap items-center gap-2.5">
614
+ {#if problem !== 'conflict' && !saving && !loading && !canSaveRules}
615
+ {#if Array.isArray(draft) && draft.length > 0 && invalid}
616
+ <span class="font-mono text-[11px] text-red-300">{copy.fixHint}</span>
617
+ {:else if dirty && (!Array.isArray(draft) || draft.length === 0)}
618
+ <span class="font-mono text-[11px] text-zinc-400">{copy.needRuleHint}</span>
619
+ {:else if !dirty && route.binding?.enabled}
620
+ <span class="font-mono text-[10px] uppercase tracking-command text-zinc-500">{copy.synced}</span>
621
+ {/if}
622
+ {/if}
623
+
624
+ {#if problem === 'conflict'}
625
+ <Button variant="outline" disabled={saving || loading} onclick={reload}>
626
+ <RefreshCw class="mr-1.5 h-3.5 w-3.5" aria-hidden="true" />
627
+ {dirty ? copy.reload : copy.reloadClean}
628
+ </Button>
629
+ {:else}
630
+ {#if dirty}
631
+ <Button variant="ghost" disabled={saving || loading} onclick={() => openRoute(selected)}>
632
+ {copy.discard}
633
+ </Button>
634
+ {/if}
635
+ <Button
636
+ disabled={!canSaveRules || saving || loading || writeBlocked}
637
+ onclick={() => commit(false)}
638
+ >
639
+ <Save class="mr-1.5 h-3.5 w-3.5" aria-hidden="true" />
640
+ {saving ? copy.saving : !route.binding ? copy.bind : route.binding.enabled ? copy.save : copy.enable}
641
+ </Button>
642
+ {/if}
643
+ </div>
644
+ </div>
645
+ </PanelCard>
646
+ {:else}
647
+ <PanelCard title={copy.rules} stripe="zinc">
648
+ <div class="flex flex-col items-center justify-center gap-2.5 py-12 text-center">
649
+ <RouteIcon class="h-6 w-6 text-zinc-500" aria-hidden="true" />
650
+ <p class="font-mono text-xs font-bold uppercase tracking-command text-zinc-200">{copy.selectPromptTitle}</p>
651
+ <p class="max-w-sm text-sm text-zinc-400">{copy.selectPrompt}</p>
652
+ </div>
653
+ </PanelCard>
654
+ {/if}
655
+ </div>
656
+ </div>
657
+ {/if}
658
+ </section>
659
+ </div>
660
+
661
+ <style>
662
+ .workspace-grid {
663
+ display: grid;
664
+ grid-template-columns: minmax(0, 1fr);
665
+ gap: 16px;
666
+ align-items: start;
667
+ }
668
+
669
+ @media (min-width: 1024px) {
670
+ .workspace-grid {
671
+ grid-template-columns: 320px minmax(0, 1fr);
672
+ }
673
+ }
674
+ </style>