@ran-sh/dsh-crew 0.3.5 → 0.3.7

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.
Files changed (78) hide show
  1. package/.claude-plugin/plugin.json +8 -8
  2. package/.mcp.json +8 -8
  3. package/LICENSE +21 -21
  4. package/README.de.md +359 -359
  5. package/README.es.md +359 -359
  6. package/README.fr.md +359 -359
  7. package/README.hi.md +359 -359
  8. package/README.id.md +359 -359
  9. package/README.ja.md +359 -359
  10. package/README.ko.md +359 -359
  11. package/README.md +125 -180
  12. package/README.pt.md +359 -359
  13. package/README.ru.md +359 -359
  14. package/README.th.md +359 -359
  15. package/README.tr.md +359 -359
  16. package/README.vi.md +359 -359
  17. package/README.zh-TW.md +359 -359
  18. package/README.zh.md +125 -180
  19. package/agents/ds-flash.md +26 -26
  20. package/agents/ds-pro.md +32 -32
  21. package/agents/ds-reviewer.md +23 -23
  22. package/agents/ds-worker.md +22 -22
  23. package/codex/agents/ds-flash.toml +30 -30
  24. package/codex/agents/ds-pro.toml +31 -31
  25. package/codex/agents/ds-reviewer.toml +28 -28
  26. package/codex/agents/ds-worker.toml +28 -28
  27. package/codex/prompts/dsh-config.md +3 -3
  28. package/codex/prompts/dsh-status.md +1 -1
  29. package/commands/config.md +11 -11
  30. package/commands/off.md +5 -5
  31. package/commands/on.md +5 -5
  32. package/commands/status.md +5 -5
  33. package/cordis.patch.yml +4 -4
  34. package/lib/client.js +3446 -2765
  35. package/package.json +131 -131
  36. package/scripts/build-client.mjs +28 -28
  37. package/scripts/live-crew-smoke.mjs +39 -39
  38. package/scripts/live-policy-matrix.mjs +177 -177
  39. package/scripts/policy-probe.mjs +101 -101
  40. package/scripts/setup.mjs +284 -284
  41. package/scripts/smoke-real.mjs +110 -110
  42. package/scripts/smoke.mjs +78 -78
  43. package/scripts/verify-installer-fix.mjs +26 -26
  44. package/src/adaptive-routing.mjs +260 -260
  45. package/src/client/activation-summary.tsx +64 -64
  46. package/src/client/collapsible-sections.mjs +55 -0
  47. package/src/client/entry.tsx +236 -236
  48. package/src/client/index.tsx +1213 -1120
  49. package/src/config-readiness.mjs +59 -59
  50. package/src/delivery.mjs +205 -205
  51. package/src/dsh-cli-runtime.mjs +239 -239
  52. package/src/failure-classification.mjs +172 -172
  53. package/src/hub/entry.mjs +98 -98
  54. package/src/hub-client.mjs +132 -132
  55. package/src/hub-compatibility.mjs +49 -49
  56. package/src/i18n.mjs +19 -19
  57. package/src/install/cli.mjs +28 -28
  58. package/src/install/install-legacy.mjs +462 -462
  59. package/src/install/install.mjs +451 -451
  60. package/src/install/npx-lifecycle.mjs +1055 -1019
  61. package/src/mcp-runtime.mjs +257 -257
  62. package/src/model-catalog.mjs +173 -173
  63. package/src/model-routing.mjs +391 -391
  64. package/src/policy.mjs +197 -197
  65. package/src/readiness-matrix.mjs +169 -169
  66. package/src/runtime-controls.mjs +90 -90
  67. package/src/runtime-identity.mjs +108 -108
  68. package/src/server.mjs +477 -477
  69. package/src/status-shard.mjs +52 -52
  70. package/src/structured-error-code.mjs +38 -38
  71. package/src/vision-route.mjs +138 -138
  72. package/src/workflow-runtime.mjs +573 -573
  73. package/src/workflow.mjs +160 -160
  74. package/src/workspace-audit.mjs +231 -231
  75. package/src/workspace-isolation.mjs +365 -365
  76. package/statusline/statusline.sh +14 -14
  77. package/statusline/worker-segment.sh +35 -35
  78. package/worker.cordis.yml +77 -77
@@ -0,0 +1,55 @@
1
+ export const SETTINGS_SECTION_STORAGE_KEY = 'dsh-crew.settings-sections.v1';
2
+
3
+ export const SETTINGS_SECTION_IDS = Object.freeze([
4
+ 'integrations',
5
+ 'workflow',
6
+ 'flash',
7
+ 'pro',
8
+ 'dispatch',
9
+ 'runtime',
10
+ 'multimodal',
11
+ 'providers',
12
+ 'jobs',
13
+ ]);
14
+
15
+ export function createDefaultSectionState() {
16
+ return Object.fromEntries(SETTINGS_SECTION_IDS.map((id) => [id, id === 'workflow']));
17
+ }
18
+
19
+ export function readSectionState(storage, key = SETTINGS_SECTION_STORAGE_KEY) {
20
+ const defaults = createDefaultSectionState();
21
+ if (!storage?.getItem) return defaults;
22
+ try {
23
+ const parsed = JSON.parse(storage.getItem(key) ?? 'null');
24
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return defaults;
25
+ for (const id of SETTINGS_SECTION_IDS) {
26
+ if (typeof parsed[id] === 'boolean') defaults[id] = parsed[id];
27
+ }
28
+ } catch {
29
+ return defaults;
30
+ }
31
+ return defaults;
32
+ }
33
+
34
+ export function writeSectionState(storage, state, key = SETTINGS_SECTION_STORAGE_KEY) {
35
+ if (!storage?.setItem) return;
36
+ try {
37
+ storage.setItem(key, JSON.stringify(
38
+ Object.fromEntries(SETTINGS_SECTION_IDS.map((id) => [id, state[id] === true])),
39
+ ));
40
+ } catch {
41
+ // Storage can be unavailable in private/locked-down browser contexts.
42
+ }
43
+ }
44
+
45
+ export function setEverySection(expanded) {
46
+ return Object.fromEntries(SETTINGS_SECTION_IDS.map((id) => [id, expanded === true]));
47
+ }
48
+
49
+ export function openSections(state, ids) {
50
+ const next = { ...state };
51
+ for (const id of ids) {
52
+ if (SETTINGS_SECTION_IDS.includes(id)) next[id] = true;
53
+ }
54
+ return next;
55
+ }
@@ -1,236 +1,236 @@
1
- import React, { useEffect, useState, useSyncExternalStore } from 'react';
2
- import { apply as applyCrew, inject as crewInject } from './index';
3
- import { ActivationSummary } from './activation-summary';
4
-
5
- export const inject = crewInject;
6
- const API = '/_dsh/dsh-crew';
7
-
8
- type AdaptiveConfig = {
9
- enabled: boolean;
10
- window_size: number;
11
- min_samples: number;
12
- };
13
-
14
- const DEFAULT_ADAPTIVE: AdaptiveConfig = { enabled: false, window_size: 8, min_samples: 2 };
15
-
16
- function clampInt(value: unknown, fallback: number, min: number, max: number) {
17
- const parsed = Number(value);
18
- if (!Number.isInteger(parsed)) return fallback;
19
- return Math.max(min, Math.min(max, parsed));
20
- }
21
-
22
- function normalizeAdaptive(value: any): AdaptiveConfig {
23
- const windowSize = clampInt(value?.window_size, DEFAULT_ADAPTIVE.window_size, 1, 32);
24
- return {
25
- enabled: value?.enabled === true,
26
- window_size: windowSize,
27
- min_samples: clampInt(value?.min_samples, DEFAULT_ADAPTIVE.min_samples, 1, windowSize),
28
- };
29
- }
30
-
31
- function useLocale(ctx: any) {
32
- return useSyncExternalStore(
33
- (notify: () => void) => ctx.on('locale/change', notify),
34
- () => ctx.locale.getLocale().active,
35
- () => ctx.locale.getLocale().active,
36
- );
37
- }
38
-
39
- function AdaptiveRoutingPanel({ ctx }: { ctx: any }) {
40
- const locale = useLocale(ctx);
41
- const zh = locale === 'zh';
42
- const [adaptive, setAdaptive] = useState<AdaptiveConfig>(DEFAULT_ADAPTIVE);
43
- const [loaded, setLoaded] = useState(false);
44
- const [saving, setSaving] = useState(false);
45
- const [message, setMessage] = useState('');
46
-
47
- const copy = zh ? {
48
- title: '自适应模型路由(实验)',
49
- hint: '默认关闭。仅对系统自动产生的候选做健康排序;显式 Provider / Model 优先级永远保持原序。信号只来自本进程内 Crew 已观察到的成功、失败、超时与粗粒度延迟,不读取额度、价格或凭据。重启 Hub 会清空健康历史。',
50
- enabled: '启用自适应路由',
51
- window: '健康窗口',
52
- minSamples: '最少样本',
53
- windowHint: '每个 role/provider/model 最多参考最近 1–32 次结果。',
54
- minHint: '达到该样本数后才允许健康分数影响自动候选顺序。',
55
- boundary: '生效边界:下一工作流',
56
- saved: '已保存',
57
- loading: '加载中…',
58
- } : {
59
- title: 'Adaptive Model Routing (experimental)',
60
- hint: 'Off by default. Health ordering applies only to automatically derived candidates; explicit Provider / Model priorities always keep their order. Signals are limited to Crew-observed success, failure, timeout, and coarse latency in this process—never quota, pricing, or credentials. Restarting the Hub clears the history.',
61
- enabled: 'Enable adaptive routing',
62
- window: 'Health window',
63
- minSamples: 'Minimum samples',
64
- windowHint: 'Use at most the most recent 1–32 outcomes per role/provider/model.',
65
- minHint: 'Health may affect automatic candidate order only after this many samples.',
66
- boundary: 'Activation boundary: next workflow',
67
- saved: 'Saved',
68
- loading: 'Loading…',
69
- };
70
-
71
- useEffect(() => {
72
- let cancelled = false;
73
- const load = async () => {
74
- try {
75
- const lang = zh ? 'zh' : 'en';
76
- const res = await fetch(`${API}/config?lang=${lang}`, { cache: 'no-store' });
77
- const body = await res.json();
78
- if (!res.ok || body?.ok === false) throw new Error(body?.error ?? `HTTP ${res.status}`);
79
- if (!cancelled) {
80
- setAdaptive(normalizeAdaptive(body?.config?.worker?.model_policy?.adaptive));
81
- setMessage('');
82
- setLoaded(true);
83
- }
84
- } catch (err: any) {
85
- if (!cancelled) {
86
- setMessage(err?.message ?? String(err));
87
- setLoaded(true);
88
- }
89
- }
90
- };
91
- void load();
92
- return () => { cancelled = true; };
93
- }, [zh]);
94
-
95
- const save = async (candidate: AdaptiveConfig) => {
96
- const next = normalizeAdaptive(candidate);
97
- setAdaptive(next);
98
- setSaving(true);
99
- try {
100
- const lang = zh ? 'zh' : 'en';
101
- const res = await fetch(`${API}/config?lang=${lang}`, {
102
- method: 'POST',
103
- headers: { 'content-type': 'application/json' },
104
- body: JSON.stringify({ worker: { model_policy: { adaptive: next } } }),
105
- });
106
- const body = await res.json();
107
- if (!res.ok || body?.ok === false) throw new Error(body?.error ?? `HTTP ${res.status}`);
108
- setAdaptive(normalizeAdaptive(body?.config?.worker?.model_policy?.adaptive));
109
- setMessage(copy.saved);
110
- setTimeout(() => setMessage(''), 1500);
111
- } catch (err: any) {
112
- setMessage(err?.message ?? String(err));
113
- } finally {
114
- setSaving(false);
115
- }
116
- };
117
-
118
- if (!loaded) return <div style={{ fontSize: 12, opacity: 0.6 }}>{copy.loading}</div>;
119
-
120
- return (
121
- <div style={{ display: 'flex', flexDirection: 'column', gap: 10, fontSize: 13, lineHeight: 1.55 }}>
122
- <div>
123
- <div style={{ fontWeight: 600, fontSize: 14 }}>{copy.title}</div>
124
- <div style={{ opacity: 0.68, fontSize: 12, marginTop: 2 }}>{copy.hint}</div>
125
- </div>
126
- <label style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
127
- <input
128
- type="checkbox"
129
- checked={adaptive.enabled}
130
- disabled={saving}
131
- onChange={(event) => { void save({ ...adaptive, enabled: event.target.checked }); }}
132
- />
133
- <span>{copy.enabled}</span>
134
- </label>
135
- <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 10 }}>
136
- <label style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
137
- <span style={{ fontSize: 12, fontWeight: 500 }}>{copy.window}</span>
138
- <input
139
- type="number"
140
- min={1}
141
- max={32}
142
- value={adaptive.window_size}
143
- disabled={saving}
144
- onChange={(event) => {
145
- const windowSize = clampInt(event.target.value, adaptive.window_size, 1, 32);
146
- setAdaptive((current) => ({
147
- ...current,
148
- window_size: windowSize,
149
- min_samples: Math.min(current.min_samples, windowSize),
150
- }));
151
- }}
152
- onBlur={() => { void save(adaptive); }}
153
- style={{ padding: '5px 7px', borderRadius: 5, border: '1px solid rgba(128,128,128,0.35)', background: 'transparent', color: 'inherit' }}
154
- />
155
- <span style={{ fontSize: 10.5, opacity: 0.55 }}>{copy.windowHint}</span>
156
- </label>
157
- <label style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
158
- <span style={{ fontSize: 12, fontWeight: 500 }}>{copy.minSamples}</span>
159
- <input
160
- type="number"
161
- min={1}
162
- max={adaptive.window_size}
163
- value={adaptive.min_samples}
164
- disabled={saving}
165
- onChange={(event) => setAdaptive((current) => ({
166
- ...current,
167
- min_samples: clampInt(event.target.value, current.min_samples, 1, current.window_size),
168
- }))}
169
- onBlur={() => { void save(adaptive); }}
170
- style={{ padding: '5px 7px', borderRadius: 5, border: '1px solid rgba(128,128,128,0.35)', background: 'transparent', color: 'inherit' }}
171
- />
172
- <span style={{ fontSize: 10.5, opacity: 0.55 }}>{copy.minHint}</span>
173
- </label>
174
- </div>
175
- <div style={{ display: 'flex', gap: 8, alignItems: 'center', fontSize: 11.5, opacity: 0.62 }}>
176
- <span>{copy.boundary}</span>
177
- {message && <span>· {message}</span>}
178
- </div>
179
- </div>
180
- );
181
- }
182
-
183
- function ActivationBoundaryPanel({ ctx }: { ctx: any }) {
184
- const locale = useLocale(ctx);
185
- const [activation, setActivation] = useState<any>(null);
186
- const [error, setError] = useState('');
187
-
188
- useEffect(() => {
189
- let cancelled = false;
190
- const load = async () => {
191
- try {
192
- const lang = locale === 'zh' ? 'zh' : 'en';
193
- const res = await fetch(`${API}/config?lang=${lang}`, { cache: 'no-store' });
194
- const body = await res.json();
195
- if (!cancelled) {
196
- if (!res.ok || body?.ok === false) throw new Error(body?.error ?? `HTTP ${res.status}`);
197
- setActivation(body?.config?.config_activation ?? null);
198
- setError('');
199
- }
200
- } catch (err: any) {
201
- if (!cancelled) setError(err?.message ?? String(err));
202
- }
203
- };
204
- void load();
205
- return () => { cancelled = true; };
206
- }, [locale]);
207
-
208
- return (
209
- <div style={{ display: 'flex', flexDirection: 'column', gap: 8, fontSize: 13, lineHeight: 1.55 }}>
210
- {error && <div style={{ fontSize: 11.5, opacity: 0.6 }}>{error}</div>}
211
- <ActivationSummary activation={activation ?? undefined} locale={locale} />
212
- </div>
213
- );
214
- }
215
-
216
- export function apply(ctx: any): void {
217
- applyCrew(ctx);
218
- ctx.slots.inject('settings.section', () => ctx.slots.register(
219
- {
220
- name: 'settings.section',
221
- id: 'dsh-crew-adaptive-routing',
222
- order: 65,
223
- label: () => ctx.locale.getLocale().active === 'zh' ? 'DSH Crew · 自适应路由' : 'DSH Crew · Adaptive Routing',
224
- },
225
- () => <AdaptiveRoutingPanel ctx={ctx} />,
226
- ));
227
- ctx.slots.inject('settings.section', () => ctx.slots.register(
228
- {
229
- name: 'settings.section',
230
- id: 'dsh-crew-runtime-controls',
231
- order: 66,
232
- label: () => ctx.locale.getLocale().active === 'zh' ? 'DSH Crew · 生效边界' : 'DSH Crew · Activation',
233
- },
234
- () => <ActivationBoundaryPanel ctx={ctx} />,
235
- ));
236
- }
1
+ import React, { useEffect, useState, useSyncExternalStore } from 'react';
2
+ import { apply as applyCrew, inject as crewInject } from './index';
3
+ import { ActivationSummary } from './activation-summary';
4
+
5
+ export const inject = crewInject;
6
+ const API = '/_dsh/dsh-crew';
7
+
8
+ type AdaptiveConfig = {
9
+ enabled: boolean;
10
+ window_size: number;
11
+ min_samples: number;
12
+ };
13
+
14
+ const DEFAULT_ADAPTIVE: AdaptiveConfig = { enabled: false, window_size: 8, min_samples: 2 };
15
+
16
+ function clampInt(value: unknown, fallback: number, min: number, max: number) {
17
+ const parsed = Number(value);
18
+ if (!Number.isInteger(parsed)) return fallback;
19
+ return Math.max(min, Math.min(max, parsed));
20
+ }
21
+
22
+ function normalizeAdaptive(value: any): AdaptiveConfig {
23
+ const windowSize = clampInt(value?.window_size, DEFAULT_ADAPTIVE.window_size, 1, 32);
24
+ return {
25
+ enabled: value?.enabled === true,
26
+ window_size: windowSize,
27
+ min_samples: clampInt(value?.min_samples, DEFAULT_ADAPTIVE.min_samples, 1, windowSize),
28
+ };
29
+ }
30
+
31
+ function useLocale(ctx: any) {
32
+ return useSyncExternalStore(
33
+ (notify: () => void) => ctx.on('locale/change', notify),
34
+ () => ctx.locale.getLocale().active,
35
+ () => ctx.locale.getLocale().active,
36
+ );
37
+ }
38
+
39
+ function AdaptiveRoutingPanel({ ctx }: { ctx: any }) {
40
+ const locale = useLocale(ctx);
41
+ const zh = locale === 'zh';
42
+ const [adaptive, setAdaptive] = useState<AdaptiveConfig>(DEFAULT_ADAPTIVE);
43
+ const [loaded, setLoaded] = useState(false);
44
+ const [saving, setSaving] = useState(false);
45
+ const [message, setMessage] = useState('');
46
+
47
+ const copy = zh ? {
48
+ title: '自适应模型路由(实验)',
49
+ hint: '默认关闭。仅对系统自动产生的候选做健康排序;显式 Provider / Model 优先级永远保持原序。信号只来自本进程内 Crew 已观察到的成功、失败、超时与粗粒度延迟,不读取额度、价格或凭据。重启 Hub 会清空健康历史。',
50
+ enabled: '启用自适应路由',
51
+ window: '健康窗口',
52
+ minSamples: '最少样本',
53
+ windowHint: '每个 role/provider/model 最多参考最近 1–32 次结果。',
54
+ minHint: '达到该样本数后才允许健康分数影响自动候选顺序。',
55
+ boundary: '生效边界:下一工作流',
56
+ saved: '已保存',
57
+ loading: '加载中…',
58
+ } : {
59
+ title: 'Adaptive Model Routing (experimental)',
60
+ hint: 'Off by default. Health ordering applies only to automatically derived candidates; explicit Provider / Model priorities always keep their order. Signals are limited to Crew-observed success, failure, timeout, and coarse latency in this process—never quota, pricing, or credentials. Restarting the Hub clears the history.',
61
+ enabled: 'Enable adaptive routing',
62
+ window: 'Health window',
63
+ minSamples: 'Minimum samples',
64
+ windowHint: 'Use at most the most recent 1–32 outcomes per role/provider/model.',
65
+ minHint: 'Health may affect automatic candidate order only after this many samples.',
66
+ boundary: 'Activation boundary: next workflow',
67
+ saved: 'Saved',
68
+ loading: 'Loading…',
69
+ };
70
+
71
+ useEffect(() => {
72
+ let cancelled = false;
73
+ const load = async () => {
74
+ try {
75
+ const lang = zh ? 'zh' : 'en';
76
+ const res = await fetch(`${API}/config?lang=${lang}`, { cache: 'no-store' });
77
+ const body = await res.json();
78
+ if (!res.ok || body?.ok === false) throw new Error(body?.error ?? `HTTP ${res.status}`);
79
+ if (!cancelled) {
80
+ setAdaptive(normalizeAdaptive(body?.config?.worker?.model_policy?.adaptive));
81
+ setMessage('');
82
+ setLoaded(true);
83
+ }
84
+ } catch (err: any) {
85
+ if (!cancelled) {
86
+ setMessage(err?.message ?? String(err));
87
+ setLoaded(true);
88
+ }
89
+ }
90
+ };
91
+ void load();
92
+ return () => { cancelled = true; };
93
+ }, [zh]);
94
+
95
+ const save = async (candidate: AdaptiveConfig) => {
96
+ const next = normalizeAdaptive(candidate);
97
+ setAdaptive(next);
98
+ setSaving(true);
99
+ try {
100
+ const lang = zh ? 'zh' : 'en';
101
+ const res = await fetch(`${API}/config?lang=${lang}`, {
102
+ method: 'POST',
103
+ headers: { 'content-type': 'application/json' },
104
+ body: JSON.stringify({ worker: { model_policy: { adaptive: next } } }),
105
+ });
106
+ const body = await res.json();
107
+ if (!res.ok || body?.ok === false) throw new Error(body?.error ?? `HTTP ${res.status}`);
108
+ setAdaptive(normalizeAdaptive(body?.config?.worker?.model_policy?.adaptive));
109
+ setMessage(copy.saved);
110
+ setTimeout(() => setMessage(''), 1500);
111
+ } catch (err: any) {
112
+ setMessage(err?.message ?? String(err));
113
+ } finally {
114
+ setSaving(false);
115
+ }
116
+ };
117
+
118
+ if (!loaded) return <div style={{ fontSize: 12, opacity: 0.6 }}>{copy.loading}</div>;
119
+
120
+ return (
121
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 10, fontSize: 13, lineHeight: 1.55 }}>
122
+ <div>
123
+ <div style={{ fontWeight: 600, fontSize: 14 }}>{copy.title}</div>
124
+ <div style={{ opacity: 0.68, fontSize: 12, marginTop: 2 }}>{copy.hint}</div>
125
+ </div>
126
+ <label style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
127
+ <input
128
+ type="checkbox"
129
+ checked={adaptive.enabled}
130
+ disabled={saving}
131
+ onChange={(event) => { void save({ ...adaptive, enabled: event.target.checked }); }}
132
+ />
133
+ <span>{copy.enabled}</span>
134
+ </label>
135
+ <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 10 }}>
136
+ <label style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
137
+ <span style={{ fontSize: 12, fontWeight: 500 }}>{copy.window}</span>
138
+ <input
139
+ type="number"
140
+ min={1}
141
+ max={32}
142
+ value={adaptive.window_size}
143
+ disabled={saving}
144
+ onChange={(event) => {
145
+ const windowSize = clampInt(event.target.value, adaptive.window_size, 1, 32);
146
+ setAdaptive((current) => ({
147
+ ...current,
148
+ window_size: windowSize,
149
+ min_samples: Math.min(current.min_samples, windowSize),
150
+ }));
151
+ }}
152
+ onBlur={() => { void save(adaptive); }}
153
+ style={{ padding: '5px 7px', borderRadius: 5, border: '1px solid rgba(128,128,128,0.35)', background: 'transparent', color: 'inherit' }}
154
+ />
155
+ <span style={{ fontSize: 10.5, opacity: 0.55 }}>{copy.windowHint}</span>
156
+ </label>
157
+ <label style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
158
+ <span style={{ fontSize: 12, fontWeight: 500 }}>{copy.minSamples}</span>
159
+ <input
160
+ type="number"
161
+ min={1}
162
+ max={adaptive.window_size}
163
+ value={adaptive.min_samples}
164
+ disabled={saving}
165
+ onChange={(event) => setAdaptive((current) => ({
166
+ ...current,
167
+ min_samples: clampInt(event.target.value, current.min_samples, 1, current.window_size),
168
+ }))}
169
+ onBlur={() => { void save(adaptive); }}
170
+ style={{ padding: '5px 7px', borderRadius: 5, border: '1px solid rgba(128,128,128,0.35)', background: 'transparent', color: 'inherit' }}
171
+ />
172
+ <span style={{ fontSize: 10.5, opacity: 0.55 }}>{copy.minHint}</span>
173
+ </label>
174
+ </div>
175
+ <div style={{ display: 'flex', gap: 8, alignItems: 'center', fontSize: 11.5, opacity: 0.62 }}>
176
+ <span>{copy.boundary}</span>
177
+ {message && <span>· {message}</span>}
178
+ </div>
179
+ </div>
180
+ );
181
+ }
182
+
183
+ function ActivationBoundaryPanel({ ctx }: { ctx: any }) {
184
+ const locale = useLocale(ctx);
185
+ const [activation, setActivation] = useState<any>(null);
186
+ const [error, setError] = useState('');
187
+
188
+ useEffect(() => {
189
+ let cancelled = false;
190
+ const load = async () => {
191
+ try {
192
+ const lang = locale === 'zh' ? 'zh' : 'en';
193
+ const res = await fetch(`${API}/config?lang=${lang}`, { cache: 'no-store' });
194
+ const body = await res.json();
195
+ if (!cancelled) {
196
+ if (!res.ok || body?.ok === false) throw new Error(body?.error ?? `HTTP ${res.status}`);
197
+ setActivation(body?.config?.config_activation ?? null);
198
+ setError('');
199
+ }
200
+ } catch (err: any) {
201
+ if (!cancelled) setError(err?.message ?? String(err));
202
+ }
203
+ };
204
+ void load();
205
+ return () => { cancelled = true; };
206
+ }, [locale]);
207
+
208
+ return (
209
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 8, fontSize: 13, lineHeight: 1.55 }}>
210
+ {error && <div style={{ fontSize: 11.5, opacity: 0.6 }}>{error}</div>}
211
+ <ActivationSummary activation={activation ?? undefined} locale={locale} />
212
+ </div>
213
+ );
214
+ }
215
+
216
+ export function apply(ctx: any): void {
217
+ applyCrew(ctx);
218
+ ctx.slots.inject('settings.section', () => ctx.slots.register(
219
+ {
220
+ name: 'settings.section',
221
+ id: 'dsh-crew-adaptive-routing',
222
+ order: 65,
223
+ label: () => ctx.locale.getLocale().active === 'zh' ? 'DSH Crew · 自适应路由' : 'DSH Crew · Adaptive Routing',
224
+ },
225
+ () => <AdaptiveRoutingPanel ctx={ctx} />,
226
+ ));
227
+ ctx.slots.inject('settings.section', () => ctx.slots.register(
228
+ {
229
+ name: 'settings.section',
230
+ id: 'dsh-crew-runtime-controls',
231
+ order: 66,
232
+ label: () => ctx.locale.getLocale().active === 'zh' ? 'DSH Crew · 生效边界' : 'DSH Crew · Activation',
233
+ },
234
+ () => <ActivationBoundaryPanel ctx={ctx} />,
235
+ ));
236
+ }