@bridgebrew/plugin-manager 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/browser/browser.tsx +2173 -0
- package/browser/screen/harness-profiles.tsx +1348 -0
- package/browser/screen/marketplace-model.ts +356 -0
- package/browser/screen/marketplace.tsx +1173 -0
- package/browser/screen/plugin-dependencies.tsx +139 -0
- package/browser/screen/plugin-docs.tsx +142 -0
- package/browser/screen/plugin-logs.tsx +549 -0
- package/browser/screen/plugin-parts.tsx +257 -0
- package/browser/screen/plugin-readme.tsx +152 -0
- package/browser/screen/plugin-settings.tsx +169 -0
- package/browser/screen/plugins-model.ts +427 -0
- package/browser/screen/plugins.tsx +2593 -0
- package/browser/screen/settings-action.ts +42 -0
- package/browser/screen/settings-fields.ts +414 -0
- package/browser/screen/settings-form.tsx +1669 -0
- package/browser/screen/settings-kinds.tsx +918 -0
- package/browser/screen/settings-page.tsx +72 -0
- package/browser/screen/settings-row.tsx +558 -0
- package/browser/screen/update-all.tsx +175 -0
- package/browser/tsconfig.json +15 -0
- package/package.json +61 -4
- package/tsconfig.json +5 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1348 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
Dialog,
|
|
5
|
+
DialogBody,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogDescription,
|
|
8
|
+
DialogFooter,
|
|
9
|
+
DialogHeader,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
Field,
|
|
12
|
+
FieldLabel,
|
|
13
|
+
Icon,
|
|
14
|
+
Input,
|
|
15
|
+
isRecord,
|
|
16
|
+
readJson,
|
|
17
|
+
refusalOf,
|
|
18
|
+
Section,
|
|
19
|
+
Select,
|
|
20
|
+
SelectContent,
|
|
21
|
+
SelectItem,
|
|
22
|
+
SelectTrigger,
|
|
23
|
+
SelectValue,
|
|
24
|
+
cn,
|
|
25
|
+
useToast,
|
|
26
|
+
Toggle,
|
|
27
|
+
copyText,
|
|
28
|
+
isComposing,
|
|
29
|
+
} from '@bridge/ui';
|
|
30
|
+
import type { Context } from 'cordis';
|
|
31
|
+
import { describeError, validate } from '@bridge/kernel/schema';
|
|
32
|
+
import { Control, ObjectFields, type FormContext } from './settings-form.tsx';
|
|
33
|
+
import type { Schema } from './settings-fields.ts';
|
|
34
|
+
import { sentence } from './plugins-model.ts';
|
|
35
|
+
|
|
36
|
+
type Entry = Record<string, unknown> & {
|
|
37
|
+
driver?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
color?: string;
|
|
40
|
+
enabled?: boolean;
|
|
41
|
+
};
|
|
42
|
+
interface DriverInfo {
|
|
43
|
+
name: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
config?: Schema;
|
|
47
|
+
}
|
|
48
|
+
interface Status {
|
|
49
|
+
installed: boolean;
|
|
50
|
+
version?: string;
|
|
51
|
+
account?: string;
|
|
52
|
+
message?: string;
|
|
53
|
+
fix?: string;
|
|
54
|
+
checkedAt?: string;
|
|
55
|
+
}
|
|
56
|
+
interface ModelOption {
|
|
57
|
+
id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
current?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** The host list as `_host`'s root resolves it: entries, whether they are the manifest's defaults, and the entry schema. */
|
|
62
|
+
interface HostList {
|
|
63
|
+
entries: Record<string, Entry>;
|
|
64
|
+
local: Record<string, Entry>;
|
|
65
|
+
baselineEntries: Record<string, Entry>;
|
|
66
|
+
defaults: boolean;
|
|
67
|
+
materialize: boolean;
|
|
68
|
+
defaultsEntries: Record<string, Entry>;
|
|
69
|
+
item: Schema;
|
|
70
|
+
profiles: Profile[];
|
|
71
|
+
}
|
|
72
|
+
interface Profile {
|
|
73
|
+
id: string;
|
|
74
|
+
harness: string;
|
|
75
|
+
driver: string;
|
|
76
|
+
config: Entry;
|
|
77
|
+
origin: string | { node: string };
|
|
78
|
+
fields: Record<string, string | { node: string }>;
|
|
79
|
+
}
|
|
80
|
+
interface Failure {
|
|
81
|
+
message: string;
|
|
82
|
+
hint?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The fields every provider has, edited outside the driver's form. */
|
|
86
|
+
const COMMON = ['harness', 'driver', 'name', 'color', 'enabled', 'environment', 'models', 'mode'];
|
|
87
|
+
/** T3's id rule: a letter, then letters, digits, `_` or `-`; at most 64. */
|
|
88
|
+
const ID = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;
|
|
89
|
+
/** The id a name suggests: its words joined by `_`, lowercase, starting with a letter. */
|
|
90
|
+
const idFrom = (name: string) =>
|
|
91
|
+
name
|
|
92
|
+
.toLowerCase()
|
|
93
|
+
.normalize('NFKD')
|
|
94
|
+
.replace(/[^a-z0-9]+/g, '_')
|
|
95
|
+
.replace(/^[^a-z]+|_+$/g, '')
|
|
96
|
+
.slice(0, 64);
|
|
97
|
+
const originLabel = (origin: string | { node: string }) =>
|
|
98
|
+
typeof origin === 'object'
|
|
99
|
+
? origin.node === 'root'
|
|
100
|
+
? 'Workspace root'
|
|
101
|
+
: `Node ${origin.node}`
|
|
102
|
+
: ({ host: 'Bridge', workspace: 'Workspace installation', default: 'Default' }[origin] ??
|
|
103
|
+
origin);
|
|
104
|
+
const identity = (id: string, entry: Entry) =>
|
|
105
|
+
typeof entry.harness === 'string'
|
|
106
|
+
? entry.harness
|
|
107
|
+
: entry.driver === 'acp'
|
|
108
|
+
? typeof entry.command === 'string'
|
|
109
|
+
? (entry.command.split(/[\\/]/).at(-1) ?? id)
|
|
110
|
+
: id
|
|
111
|
+
: String(entry.driver);
|
|
112
|
+
const labelOf = (id: string, entry: Entry) =>
|
|
113
|
+
typeof entry.name === 'string' && entry.name.trim() ? entry.name.trim() : id;
|
|
114
|
+
/** Why `id` cannot name a new provider, else `undefined`. */
|
|
115
|
+
const idError = (id: string, taken: string[]) => {
|
|
116
|
+
if (!id) return 'Give it an id.';
|
|
117
|
+
if (!ID.test(id)) return 'An id starts with a letter, then letters, digits, _ or -, at most 64.';
|
|
118
|
+
if (taken.includes(id)) return `A profile ${id} already exists.`;
|
|
119
|
+
return undefined;
|
|
120
|
+
};
|
|
121
|
+
/** A status that needs attention: the agent missing, or a message. */
|
|
122
|
+
const attention = (status: Status | undefined) =>
|
|
123
|
+
!!status && (!status.installed || status.message !== undefined);
|
|
124
|
+
|
|
125
|
+
/** A refused answer as the screen shows it: the refusal's message and hint. */
|
|
126
|
+
async function failureOf(res: Response): Promise<Failure> {
|
|
127
|
+
const body: unknown = await res.json().catch(() => undefined);
|
|
128
|
+
const { message, hint } = refusalOf(body, res.status);
|
|
129
|
+
return { message, ...(hint !== undefined && { hint }) };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A command or fix with a Copy button. */
|
|
133
|
+
function Fix({ text }: { text: string }) {
|
|
134
|
+
const { toast } = useToast();
|
|
135
|
+
return (
|
|
136
|
+
<span className="flex items-start gap-2">
|
|
137
|
+
<code className="min-w-0 flex-1 whitespace-pre-wrap break-all rounded-sm bg-hover px-2 py-1 font-mono text-xs text-foreground">
|
|
138
|
+
{text}
|
|
139
|
+
</code>
|
|
140
|
+
<Button
|
|
141
|
+
size="sm"
|
|
142
|
+
variant="ghost"
|
|
143
|
+
onClick={() =>
|
|
144
|
+
void copyText(text).then(
|
|
145
|
+
() => toast({ variant: 'success', title: 'Copied' }),
|
|
146
|
+
() => toast({ variant: 'error', title: 'The clipboard is not available here' }),
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
>
|
|
150
|
+
<Icon name="copy" size={12} />
|
|
151
|
+
Copy
|
|
152
|
+
</Button>
|
|
153
|
+
</span>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** A status in words: the version and account, or what needs attention and its fix. */
|
|
158
|
+
function StatusLine({ status }: { status: Status | 'checking' | undefined }) {
|
|
159
|
+
if (status === 'checking')
|
|
160
|
+
return (
|
|
161
|
+
<p role="status" className="flex items-center gap-1.5 text-xs text-muted">
|
|
162
|
+
<Icon name="loader-circle" size={12} className="animate-spin motion-reduce:animate-none" />
|
|
163
|
+
Checking…
|
|
164
|
+
</p>
|
|
165
|
+
);
|
|
166
|
+
if (!status) return null;
|
|
167
|
+
const facts = [status.version, status.account].filter(Boolean).join(' · ');
|
|
168
|
+
return (
|
|
169
|
+
<div
|
|
170
|
+
data-status={attention(status) ? 'attention' : 'ready'}
|
|
171
|
+
className="flex flex-col gap-1.5 text-xs"
|
|
172
|
+
>
|
|
173
|
+
{status.message === undefined && status.installed ? (
|
|
174
|
+
<p className="flex items-center gap-1.5 text-success">
|
|
175
|
+
<Icon name="check" size={12} />
|
|
176
|
+
Ready{facts && <span className="text-secondary">· {facts}</span>}
|
|
177
|
+
</p>
|
|
178
|
+
) : (
|
|
179
|
+
<p className="text-warning-text">
|
|
180
|
+
{status.message ?? 'Not installed.'}
|
|
181
|
+
{facts && <span className="ml-1 text-secondary">({facts})</span>}
|
|
182
|
+
</p>
|
|
183
|
+
)}
|
|
184
|
+
{status.fix && <Fix text={status.fix} />}
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The editor's sections are divided by a rule, none above the first. */
|
|
190
|
+
const divided = 'border-t border-border-subtle pt-4 first:border-t-0 first:pt-0';
|
|
191
|
+
|
|
192
|
+
/** One provider's editor: a draft of its entry, saved whole. */
|
|
193
|
+
function Editor({
|
|
194
|
+
id,
|
|
195
|
+
entry,
|
|
196
|
+
item,
|
|
197
|
+
driver,
|
|
198
|
+
onSave,
|
|
199
|
+
onRemove,
|
|
200
|
+
onCancel,
|
|
201
|
+
onTest,
|
|
202
|
+
status,
|
|
203
|
+
modes,
|
|
204
|
+
models,
|
|
205
|
+
busy,
|
|
206
|
+
removeLabel,
|
|
207
|
+
}: {
|
|
208
|
+
removeLabel: string;
|
|
209
|
+
id: string;
|
|
210
|
+
entry: Entry;
|
|
211
|
+
item: Schema;
|
|
212
|
+
driver: DriverInfo | undefined;
|
|
213
|
+
busy: boolean;
|
|
214
|
+
status: Status | 'checking' | undefined;
|
|
215
|
+
modes: string[];
|
|
216
|
+
models: ModelOption[];
|
|
217
|
+
onSave: (next: Entry, previous: Entry) => Promise<Failure | undefined>;
|
|
218
|
+
onRemove: () => void;
|
|
219
|
+
onCancel: () => void;
|
|
220
|
+
onTest: () => void;
|
|
221
|
+
}) {
|
|
222
|
+
const dom = React.useId().replace(/:/g, '');
|
|
223
|
+
const [draft, setDraft] = React.useState<Entry>(entry);
|
|
224
|
+
const [failure, setFailure] = React.useState<Failure>();
|
|
225
|
+
// The entry the draft was last loaded from: a refresh adopts it only while the draft has no unsaved edits, so a
|
|
226
|
+
// dirty draft is never silently overwritten (the Reload configuration affordance below loads it deliberately).
|
|
227
|
+
const base = React.useRef(entry);
|
|
228
|
+
React.useEffect(() => {
|
|
229
|
+
if (JSON.stringify(draft) === JSON.stringify(base.current)) {
|
|
230
|
+
base.current = entry;
|
|
231
|
+
setDraft(entry);
|
|
232
|
+
setFailure(undefined);
|
|
233
|
+
}
|
|
234
|
+
}, [JSON.stringify(entry)]);
|
|
235
|
+
const set = (field: string, value: unknown) =>
|
|
236
|
+
setDraft((was) => {
|
|
237
|
+
const { [field]: _, ...rest } = was;
|
|
238
|
+
return value === undefined || value === '' ? (rest as Entry) : { ...rest, [field]: value };
|
|
239
|
+
});
|
|
240
|
+
const properties = isRecord(item.properties) ? (item.properties as Record<string, Schema>) : {};
|
|
241
|
+
const draftModels = isRecord(draft.models) ? draft.models : {};
|
|
242
|
+
const customModels = Array.isArray(draftModels.custom)
|
|
243
|
+
? draftModels.custom.filter((id): id is string => typeof id === 'string' && !!id)
|
|
244
|
+
: [];
|
|
245
|
+
const modelIds = [...new Set([...models.map((each) => each.id), ...customModels])];
|
|
246
|
+
const driverDefault = models.find((each) => each.current) ?? models[0];
|
|
247
|
+
const ctx = (name: string, options: (kind: string) => string[] = () => []): FormContext => ({
|
|
248
|
+
disabled: busy,
|
|
249
|
+
errorAt: () => undefined,
|
|
250
|
+
options,
|
|
251
|
+
needle: '',
|
|
252
|
+
id: `profile-${dom}-${id}-${name}`.replace(/[^\w-]/g, '_'),
|
|
253
|
+
});
|
|
254
|
+
/** The driver's own fields: its schema's, then any other field the entry has (kept, edited as JSON by the Settings screen). */
|
|
255
|
+
const config: Schema = driver?.config ?? { type: 'object', properties: {} };
|
|
256
|
+
const own = Object.fromEntries(Object.entries(draft).filter(([key]) => !COMMON.includes(key)));
|
|
257
|
+
const save = async () => {
|
|
258
|
+
const error = validate(item, draft);
|
|
259
|
+
if (error) return setFailure({ message: describeError(error, [id]) });
|
|
260
|
+
const refused = await onSave(draft, base.current);
|
|
261
|
+
setFailure(refused);
|
|
262
|
+
};
|
|
263
|
+
const changed = JSON.stringify(draft) !== JSON.stringify(base.current);
|
|
264
|
+
const stale =
|
|
265
|
+
JSON.stringify(draft) !== JSON.stringify(base.current) &&
|
|
266
|
+
JSON.stringify(base.current) !== JSON.stringify(entry);
|
|
267
|
+
const nameId = `profile-${dom}-${id}-name`;
|
|
268
|
+
const colorId = `profile-${dom}-${id}-color`;
|
|
269
|
+
const enabledId = `profile-${dom}-${id}-enabled`;
|
|
270
|
+
return (
|
|
271
|
+
<div
|
|
272
|
+
data-editor={id}
|
|
273
|
+
className="flex flex-col gap-4 border-t border-border-subtle px-4 pb-4 pt-4"
|
|
274
|
+
>
|
|
275
|
+
<p className="m-0 text-xs leading-5 text-muted">
|
|
276
|
+
An empty optional field inherits its value from the scope above.
|
|
277
|
+
</p>
|
|
278
|
+
<Section title="Display" className={divided}>
|
|
279
|
+
<div className="flex flex-wrap gap-4">
|
|
280
|
+
<Field className="flex min-w-[220px] flex-1 flex-col gap-1.5">
|
|
281
|
+
<FieldLabel htmlFor={nameId} className="text-[13px] font-medium text-foreground">
|
|
282
|
+
Name
|
|
283
|
+
</FieldLabel>
|
|
284
|
+
<Input
|
|
285
|
+
id={nameId}
|
|
286
|
+
placeholder={id}
|
|
287
|
+
value={typeof draft.name === 'string' ? draft.name : ''}
|
|
288
|
+
disabled={busy}
|
|
289
|
+
onChange={(event) => set('name', event.currentTarget.value)}
|
|
290
|
+
/>
|
|
291
|
+
</Field>
|
|
292
|
+
<Field className="flex w-[180px] flex-col gap-1.5">
|
|
293
|
+
<FieldLabel htmlFor={colorId} className="text-[13px] font-medium text-foreground">
|
|
294
|
+
Color
|
|
295
|
+
</FieldLabel>
|
|
296
|
+
<span className="flex items-center gap-2">
|
|
297
|
+
<span
|
|
298
|
+
aria-hidden="true"
|
|
299
|
+
className="size-5 shrink-0 rounded-full border border-border"
|
|
300
|
+
style={{
|
|
301
|
+
background: typeof draft.color === 'string' ? draft.color : 'transparent',
|
|
302
|
+
}}
|
|
303
|
+
/>
|
|
304
|
+
<Input
|
|
305
|
+
id={colorId}
|
|
306
|
+
placeholder="#d97757"
|
|
307
|
+
value={typeof draft.color === 'string' ? draft.color : ''}
|
|
308
|
+
disabled={busy}
|
|
309
|
+
onChange={(event) => set('color', event.currentTarget.value)}
|
|
310
|
+
/>
|
|
311
|
+
</span>
|
|
312
|
+
</Field>
|
|
313
|
+
</div>
|
|
314
|
+
<label htmlFor={enabledId} className="flex items-center gap-2 text-[13px] text-foreground">
|
|
315
|
+
<Toggle
|
|
316
|
+
id={enabledId}
|
|
317
|
+
checked={draft.enabled !== false}
|
|
318
|
+
disabled={busy}
|
|
319
|
+
onCheckedChange={(on) => set('enabled', on === true ? true : false)}
|
|
320
|
+
/>
|
|
321
|
+
Enabled
|
|
322
|
+
<span className="text-xs text-muted">
|
|
323
|
+
Off hides it in this scope and its descendants.
|
|
324
|
+
</span>
|
|
325
|
+
</label>
|
|
326
|
+
</Section>
|
|
327
|
+
<Section title={`Setup${driver?.title ? `: ${driver.title}` : ''}`} className={divided}>
|
|
328
|
+
{driver?.description && (
|
|
329
|
+
<p className="text-xs leading-5 text-secondary">{driver.description}</p>
|
|
330
|
+
)}
|
|
331
|
+
{!driver && (
|
|
332
|
+
<p className="text-xs text-warning-text">
|
|
333
|
+
Its driver {String(draft.driver)} is not installed in this workspace: its settings show
|
|
334
|
+
as they are.
|
|
335
|
+
</p>
|
|
336
|
+
)}
|
|
337
|
+
<ObjectFields
|
|
338
|
+
schema={config}
|
|
339
|
+
value={own}
|
|
340
|
+
ctx={ctx('setup')}
|
|
341
|
+
path={[]}
|
|
342
|
+
onChange={(next) =>
|
|
343
|
+
setDraft(
|
|
344
|
+
(was) =>
|
|
345
|
+
({
|
|
346
|
+
...Object.fromEntries(
|
|
347
|
+
Object.entries(was).filter(([key]) => COMMON.includes(key)),
|
|
348
|
+
),
|
|
349
|
+
...(isRecord(next) ? next : {}),
|
|
350
|
+
}) as Entry,
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
/>
|
|
354
|
+
</Section>
|
|
355
|
+
<Section title="Environment" className={divided}>
|
|
356
|
+
<p className="text-xs leading-5 text-secondary">
|
|
357
|
+
Variables set for the agent's process, over the host's.
|
|
358
|
+
</p>
|
|
359
|
+
<Control
|
|
360
|
+
schema={properties.environment ?? { type: 'array' }}
|
|
361
|
+
value={draft.environment}
|
|
362
|
+
ctx={ctx('environment')}
|
|
363
|
+
path={['environment']}
|
|
364
|
+
label="Environment"
|
|
365
|
+
labelledBy={`profile-${dom}-${id}-environment`}
|
|
366
|
+
onChange={(next) =>
|
|
367
|
+
set('environment', Array.isArray(next) && next.length ? next : undefined)
|
|
368
|
+
}
|
|
369
|
+
/>
|
|
370
|
+
</Section>
|
|
371
|
+
<Section title="Models" className={divided}>
|
|
372
|
+
{/* The `models` object's fields (default, custom) and `mode`, side by side. */}
|
|
373
|
+
<ObjectFields
|
|
374
|
+
schema={{
|
|
375
|
+
type: 'object',
|
|
376
|
+
properties: {
|
|
377
|
+
...(isRecord(properties.models?.properties) &&
|
|
378
|
+
(properties.models.properties as Record<string, Schema>)),
|
|
379
|
+
default: {
|
|
380
|
+
type: 'string',
|
|
381
|
+
title: 'Default model',
|
|
382
|
+
description: 'The model used for new sessions.',
|
|
383
|
+
enum: modelIds,
|
|
384
|
+
'x-bridge-labels': modelIds.map(
|
|
385
|
+
(id) => models.find((each) => each.id === id)?.name ?? id,
|
|
386
|
+
),
|
|
387
|
+
},
|
|
388
|
+
...(properties.mode && { mode: properties.mode }),
|
|
389
|
+
},
|
|
390
|
+
}}
|
|
391
|
+
value={{
|
|
392
|
+
...(isRecord(draft.models) && draft.models),
|
|
393
|
+
default: draftModels.default ?? driverDefault?.id,
|
|
394
|
+
...(draft.mode !== undefined && { mode: draft.mode }),
|
|
395
|
+
}}
|
|
396
|
+
ctx={ctx('models', (kind) => (kind === 'modes' ? modes : []))}
|
|
397
|
+
path={[]}
|
|
398
|
+
onChange={(next) =>
|
|
399
|
+
setDraft((was) => {
|
|
400
|
+
const { models: _, mode: __, ...rest } = was;
|
|
401
|
+
const { mode, default: preferred, ...modelSettings } = isRecord(next) ? next : {};
|
|
402
|
+
const previous = isRecord(was.models) ? was.models.default : undefined;
|
|
403
|
+
const selected = preferred === (previous ?? driverDefault?.id) ? previous : preferred;
|
|
404
|
+
const models = { ...modelSettings, ...(selected ? { default: selected } : {}) };
|
|
405
|
+
return {
|
|
406
|
+
...rest,
|
|
407
|
+
...((Object.keys(models).length || isRecord(was.models)) && { models }),
|
|
408
|
+
...(mode !== undefined && { mode }),
|
|
409
|
+
} as Entry;
|
|
410
|
+
})
|
|
411
|
+
}
|
|
412
|
+
/>
|
|
413
|
+
</Section>
|
|
414
|
+
<Section title="Test" className={divided}>
|
|
415
|
+
<div className="flex items-start gap-3">
|
|
416
|
+
<div className="min-w-0 flex-1">
|
|
417
|
+
<StatusLine status={status} />
|
|
418
|
+
{status === undefined && (
|
|
419
|
+
<p className="text-xs text-muted">
|
|
420
|
+
Checks that its agent is installed and logged in, without a model call.
|
|
421
|
+
</p>
|
|
422
|
+
)}
|
|
423
|
+
</div>
|
|
424
|
+
<Button
|
|
425
|
+
size="sm"
|
|
426
|
+
variant="outline"
|
|
427
|
+
disabled={busy || status === 'checking' || changed}
|
|
428
|
+
title={changed ? 'Save first' : undefined}
|
|
429
|
+
onClick={onTest}
|
|
430
|
+
>
|
|
431
|
+
<Icon name="activity" size={13} />
|
|
432
|
+
Test
|
|
433
|
+
</Button>
|
|
434
|
+
</div>
|
|
435
|
+
</Section>
|
|
436
|
+
{failure && (
|
|
437
|
+
<p role="alert" className="text-[13px] text-destructive">
|
|
438
|
+
{sentence(failure.message)}
|
|
439
|
+
{failure.hint && <span className="block text-xs text-secondary">{failure.hint}</span>}
|
|
440
|
+
</p>
|
|
441
|
+
)}
|
|
442
|
+
{stale && (
|
|
443
|
+
<p role="note" className="flex items-center gap-2 text-xs text-secondary">
|
|
444
|
+
<span className="min-w-0 flex-1">
|
|
445
|
+
This configuration changed elsewhere. Your edits are kept.
|
|
446
|
+
</span>
|
|
447
|
+
<Button
|
|
448
|
+
size="sm"
|
|
449
|
+
variant="outline"
|
|
450
|
+
disabled={busy}
|
|
451
|
+
onClick={() => {
|
|
452
|
+
base.current = entry;
|
|
453
|
+
setDraft(entry);
|
|
454
|
+
setFailure(undefined);
|
|
455
|
+
}}
|
|
456
|
+
>
|
|
457
|
+
Reload configuration
|
|
458
|
+
</Button>
|
|
459
|
+
</p>
|
|
460
|
+
)}
|
|
461
|
+
<div className="flex justify-end gap-2">
|
|
462
|
+
<Button variant="destructive" disabled={busy} onClick={onRemove}>
|
|
463
|
+
{removeLabel}
|
|
464
|
+
</Button>
|
|
465
|
+
<Button variant="outline" disabled={busy} onClick={onCancel}>
|
|
466
|
+
{changed ? 'Cancel' : 'Close'}
|
|
467
|
+
</Button>
|
|
468
|
+
<Button variant="primary" disabled={busy || !changed} onClick={() => void save()}>
|
|
469
|
+
{busy ? 'Saving…' : 'Save'}
|
|
470
|
+
</Button>
|
|
471
|
+
</div>
|
|
472
|
+
</div>
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** "Add profile": a driver, a name, and the id (derived from the name until typed), checked as typed. */
|
|
477
|
+
function AddDialog({
|
|
478
|
+
open,
|
|
479
|
+
onOpenChange,
|
|
480
|
+
drivers,
|
|
481
|
+
taken,
|
|
482
|
+
onAdd,
|
|
483
|
+
}: {
|
|
484
|
+
open: boolean;
|
|
485
|
+
onOpenChange: (open: boolean) => void;
|
|
486
|
+
drivers: DriverInfo[];
|
|
487
|
+
taken: string[];
|
|
488
|
+
onAdd: (id: string, entry: Entry) => Promise<Failure | undefined>;
|
|
489
|
+
}) {
|
|
490
|
+
const dom = React.useId().replace(/:/g, '');
|
|
491
|
+
const fieldId = (name: string) => `profile-${dom}-${name}`;
|
|
492
|
+
const [driver, setDriver] = React.useState('');
|
|
493
|
+
const [name, setName] = React.useState('');
|
|
494
|
+
const [harness, setHarness] = React.useState('');
|
|
495
|
+
const [id, setId] = React.useState<string>();
|
|
496
|
+
const [failure, setFailure] = React.useState<Failure>();
|
|
497
|
+
const [busy, setBusy] = React.useState(false);
|
|
498
|
+
const submitting = React.useRef(false);
|
|
499
|
+
// Claude and Codex are a Harness identity themselves; ACP defaults to `hermes`; any other driver to its own name.
|
|
500
|
+
const harnessDefault = (which: string) => (which === 'acp' ? 'hermes' : which);
|
|
501
|
+
const showHarness = driver !== '' && driver !== 'claude' && driver !== 'codex';
|
|
502
|
+
const harnessValue = showHarness ? harness.trim() : driver;
|
|
503
|
+
// Claude first when there: the common case.
|
|
504
|
+
React.useEffect(() => {
|
|
505
|
+
if (!open) return;
|
|
506
|
+
const first = (drivers.find((each) => each.name === 'claude') ?? drivers[0])?.name ?? '';
|
|
507
|
+
setDriver(first);
|
|
508
|
+
setHarness(harnessDefault(first));
|
|
509
|
+
setName('');
|
|
510
|
+
setId(undefined);
|
|
511
|
+
setFailure(undefined);
|
|
512
|
+
setBusy(false);
|
|
513
|
+
}, [open]);
|
|
514
|
+
React.useEffect(() => {
|
|
515
|
+
if (open && driver) setHarness(harnessDefault(driver));
|
|
516
|
+
}, [driver]);
|
|
517
|
+
const shown = id ?? (idFrom(name) || (driver ? `${driver}_work` : ''));
|
|
518
|
+
const error = idError(shown, taken);
|
|
519
|
+
const add = async () => {
|
|
520
|
+
// The handler validates for itself: both Enter and the button reach it, and both must refuse the same way.
|
|
521
|
+
if (submitting.current || busy || error || !driver || !harnessValue) return;
|
|
522
|
+
submitting.current = true;
|
|
523
|
+
setBusy(true);
|
|
524
|
+
const refused = await onAdd(shown, {
|
|
525
|
+
driver,
|
|
526
|
+
harness: harnessValue,
|
|
527
|
+
...(name.trim() && { name: name.trim() }),
|
|
528
|
+
});
|
|
529
|
+
submitting.current = false;
|
|
530
|
+
setBusy(false);
|
|
531
|
+
if (refused) setFailure(refused);
|
|
532
|
+
else onOpenChange(false);
|
|
533
|
+
};
|
|
534
|
+
const items = Object.fromEntries(drivers.map((each) => [each.name, each.title ?? each.name]));
|
|
535
|
+
return (
|
|
536
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
537
|
+
<DialogContent>
|
|
538
|
+
<DialogHeader>
|
|
539
|
+
<DialogTitle>Add profile</DialogTitle>
|
|
540
|
+
</DialogHeader>
|
|
541
|
+
<DialogBody className="flex flex-col gap-4 pb-3">
|
|
542
|
+
<DialogDescription>
|
|
543
|
+
A Profile configures a Harness through a Driver in this scope. Several profiles can
|
|
544
|
+
share one Harness and use different accounts.
|
|
545
|
+
</DialogDescription>
|
|
546
|
+
<Field className="flex flex-col gap-1.5">
|
|
547
|
+
<FieldLabel
|
|
548
|
+
htmlFor={fieldId('driver')}
|
|
549
|
+
className="text-[13px] font-medium text-foreground"
|
|
550
|
+
>
|
|
551
|
+
Driver
|
|
552
|
+
</FieldLabel>
|
|
553
|
+
<Select
|
|
554
|
+
items={items}
|
|
555
|
+
value={driver || null}
|
|
556
|
+
onValueChange={(next) => {
|
|
557
|
+
if (typeof next === 'string') setDriver(next);
|
|
558
|
+
}}
|
|
559
|
+
>
|
|
560
|
+
<SelectTrigger id={fieldId('driver')} aria-label="Driver" className="w-full">
|
|
561
|
+
<SelectValue placeholder="Choose…" />
|
|
562
|
+
</SelectTrigger>
|
|
563
|
+
<SelectContent>
|
|
564
|
+
{drivers.map((each) => (
|
|
565
|
+
<SelectItem key={each.name} value={each.name}>
|
|
566
|
+
{each.title ?? each.name}
|
|
567
|
+
</SelectItem>
|
|
568
|
+
))}
|
|
569
|
+
</SelectContent>
|
|
570
|
+
</Select>
|
|
571
|
+
</Field>
|
|
572
|
+
{showHarness && (
|
|
573
|
+
<Field className="flex flex-col gap-1.5">
|
|
574
|
+
<FieldLabel htmlFor={fieldId('harness')}>Harness</FieldLabel>
|
|
575
|
+
<Input
|
|
576
|
+
id={fieldId('harness')}
|
|
577
|
+
value={harness}
|
|
578
|
+
placeholder={harnessDefault(driver)}
|
|
579
|
+
onChange={(event) => setHarness(event.currentTarget.value)}
|
|
580
|
+
onKeyDown={(event) => {
|
|
581
|
+
if (event.key === 'Enter' && !isComposing(event)) void add();
|
|
582
|
+
}}
|
|
583
|
+
/>
|
|
584
|
+
</Field>
|
|
585
|
+
)}
|
|
586
|
+
<Field className="flex flex-col gap-1.5">
|
|
587
|
+
<FieldLabel
|
|
588
|
+
htmlFor={fieldId('name')}
|
|
589
|
+
className="text-[13px] font-medium text-foreground"
|
|
590
|
+
>
|
|
591
|
+
Name
|
|
592
|
+
</FieldLabel>
|
|
593
|
+
<Input
|
|
594
|
+
id={fieldId('name')}
|
|
595
|
+
placeholder="Claude pro"
|
|
596
|
+
value={name}
|
|
597
|
+
onChange={(event) => setName(event.currentTarget.value)}
|
|
598
|
+
onKeyDown={(event) => {
|
|
599
|
+
if (event.key === 'Enter' && !isComposing(event)) void add();
|
|
600
|
+
}}
|
|
601
|
+
/>
|
|
602
|
+
</Field>
|
|
603
|
+
<Field className="flex flex-col gap-1.5">
|
|
604
|
+
<FieldLabel htmlFor={fieldId('id')} className="text-[13px] font-medium text-foreground">
|
|
605
|
+
Id
|
|
606
|
+
</FieldLabel>
|
|
607
|
+
<Input
|
|
608
|
+
id={fieldId('id')}
|
|
609
|
+
className="font-mono"
|
|
610
|
+
value={shown}
|
|
611
|
+
aria-invalid={!!error || undefined}
|
|
612
|
+
aria-describedby={fieldId('id-note')}
|
|
613
|
+
onChange={(event) => setId(event.currentTarget.value)}
|
|
614
|
+
onKeyDown={(event) => {
|
|
615
|
+
if (event.key === 'Enter' && !isComposing(event)) void add();
|
|
616
|
+
}}
|
|
617
|
+
/>
|
|
618
|
+
<p
|
|
619
|
+
id={fieldId('id-note')}
|
|
620
|
+
role={error ? 'alert' : undefined}
|
|
621
|
+
className={cn('m-0 text-xs', error ? 'text-destructive' : 'text-muted')}
|
|
622
|
+
>
|
|
623
|
+
{error ?? 'Sessions keep it: it cannot change later.'}
|
|
624
|
+
</p>
|
|
625
|
+
</Field>
|
|
626
|
+
{failure && (
|
|
627
|
+
<p role="alert" className="m-0 text-[13px] text-destructive">
|
|
628
|
+
{sentence(failure.message)}
|
|
629
|
+
{failure.hint && <span className="block text-xs text-secondary">{failure.hint}</span>}
|
|
630
|
+
</p>
|
|
631
|
+
)}
|
|
632
|
+
</DialogBody>
|
|
633
|
+
<DialogFooter className="justify-end gap-2">
|
|
634
|
+
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
|
635
|
+
Cancel
|
|
636
|
+
</Button>
|
|
637
|
+
<Button
|
|
638
|
+
variant="primary"
|
|
639
|
+
disabled={!!error || !driver || !harnessValue || busy}
|
|
640
|
+
onClick={() => void add()}
|
|
641
|
+
>
|
|
642
|
+
{busy ? 'Adding…' : 'Add'}
|
|
643
|
+
</Button>
|
|
644
|
+
</DialogFooter>
|
|
645
|
+
</DialogContent>
|
|
646
|
+
</Dialog>
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
export function HarnessProfiles({
|
|
651
|
+
ctx,
|
|
652
|
+
root = ctx.workspace.slug,
|
|
653
|
+
node = 'root',
|
|
654
|
+
readOnly = false,
|
|
655
|
+
scopeLabel,
|
|
656
|
+
}: {
|
|
657
|
+
ctx: Context;
|
|
658
|
+
root?: string;
|
|
659
|
+
node?: string;
|
|
660
|
+
readOnly?: boolean;
|
|
661
|
+
scopeLabel?: string;
|
|
662
|
+
}) {
|
|
663
|
+
const { workspace } = ctx;
|
|
664
|
+
const { toast } = useToast();
|
|
665
|
+
const revision = React.useSyncExternalStore(ctx.nodes.subscribe, () => ctx.nodes.revision);
|
|
666
|
+
const generation = React.useRef(0);
|
|
667
|
+
const scopeGeneration = React.useRef(0);
|
|
668
|
+
const requestScope = React.useRef(`${root}/${node}`);
|
|
669
|
+
if (requestScope.current !== `${root}/${node}`) {
|
|
670
|
+
requestScope.current = `${root}/${node}`;
|
|
671
|
+
generation.current += 1;
|
|
672
|
+
scopeGeneration.current += 1;
|
|
673
|
+
}
|
|
674
|
+
const viewGeneration = scopeGeneration.current;
|
|
675
|
+
const api = `/${encodeURIComponent(root === '_host' ? workspace.slug : root)}/api/harness`;
|
|
676
|
+
const headers = { 'x-bridge-node': root === '_host' ? 'root' : node };
|
|
677
|
+
const scope =
|
|
678
|
+
scopeLabel ??
|
|
679
|
+
(root === '_host' ? 'Bridge' : node === 'root' ? `Workspace: ${root}` : `Project: ${node}`);
|
|
680
|
+
const [list, setList] = React.useState<HostList | 'missing'>();
|
|
681
|
+
const [drivers, setDrivers] = React.useState<DriverInfo[]>([]);
|
|
682
|
+
const [statuses, setStatuses] = React.useState<Record<string, Status | 'checking'>>({});
|
|
683
|
+
const [modes, setModes] = React.useState<Record<string, string[]>>({});
|
|
684
|
+
const [models, setModels] = React.useState<Record<string, ModelOption[]>>({});
|
|
685
|
+
const [open, setOpen] = React.useState<string>();
|
|
686
|
+
const [adding, setAdding] = React.useState(false);
|
|
687
|
+
const [busy, setBusy] = React.useState(false);
|
|
688
|
+
const [failure, setFailure] = React.useState<Failure>();
|
|
689
|
+
const [editorRevision, setEditorRevision] = React.useState(0);
|
|
690
|
+
const [harnessLink, setHarnessLink] = React.useState<string>();
|
|
691
|
+
|
|
692
|
+
const load = React.useCallback(async () => {
|
|
693
|
+
if (requestScope.current !== `${root}/${node}`) return;
|
|
694
|
+
const at = ++generation.current;
|
|
695
|
+
try {
|
|
696
|
+
const res = await workspace.fetch(`/_bridge/workspaces/${encodeURIComponent(root)}/nodes`, {
|
|
697
|
+
cache: 'no-store',
|
|
698
|
+
});
|
|
699
|
+
if (!res.ok) {
|
|
700
|
+
const error = await failureOf(res);
|
|
701
|
+
if (at === generation.current) setFailure(error);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const tree = (await readJson(res)) as {
|
|
705
|
+
nodes: { id: string; settings?: Record<string, Record<string, unknown>> }[];
|
|
706
|
+
resolved: Record<
|
|
707
|
+
string,
|
|
708
|
+
{
|
|
709
|
+
settings: Record<
|
|
710
|
+
string,
|
|
711
|
+
{ values: Record<string, { value: unknown; origin: unknown }> }
|
|
712
|
+
>;
|
|
713
|
+
}
|
|
714
|
+
>;
|
|
715
|
+
rootBaseline?: {
|
|
716
|
+
settings: Record<string, { values: Record<string, { value: unknown; origin: unknown }> }>;
|
|
717
|
+
};
|
|
718
|
+
schemas: Record<string, { properties?: Record<string, Schema> }>;
|
|
719
|
+
};
|
|
720
|
+
const resolved = tree.resolved[node]?.settings.harness?.values.harnesses;
|
|
721
|
+
const schema = tree.schemas.harness?.properties?.harnesses;
|
|
722
|
+
if (!schema) {
|
|
723
|
+
if (at === generation.current) setList('missing');
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const local = tree.nodes.find((each) => each.id === node)?.settings?.harness?.harnesses;
|
|
727
|
+
// The installation/default baseline: what `root` resolves to with its own overrides left out. A manifest
|
|
728
|
+
// default is never read directly, so a profile an installation map does not have is not resurrected.
|
|
729
|
+
const baseline = tree.rootBaseline?.settings.harness?.values.harnesses;
|
|
730
|
+
let baselineEntries = isRecord(baseline?.value)
|
|
731
|
+
? (baseline.value as Record<string, Entry>)
|
|
732
|
+
: {};
|
|
733
|
+
if (root !== '_host' && baseline?.origin === 'default') {
|
|
734
|
+
// Bridge fields override manifest defaults. They must remain inherited on first write and on Reset,
|
|
735
|
+
// even after local writes changed the effective fields' origins to this workspace.
|
|
736
|
+
const bridgeResponse = await workspace.fetch('/_bridge/workspaces/_host/nodes', {
|
|
737
|
+
cache: 'no-store',
|
|
738
|
+
});
|
|
739
|
+
if (!bridgeResponse.ok) throw new Error((await failureOf(bridgeResponse)).message);
|
|
740
|
+
const bridgeTree = (await readJson(bridgeResponse)) as {
|
|
741
|
+
resolved?: Record<
|
|
742
|
+
string,
|
|
743
|
+
{
|
|
744
|
+
settings?: Record<
|
|
745
|
+
string,
|
|
746
|
+
{ values?: Record<string, { value: unknown; origin: unknown }> }
|
|
747
|
+
>;
|
|
748
|
+
}
|
|
749
|
+
>;
|
|
750
|
+
};
|
|
751
|
+
const bridge = bridgeTree.resolved?.root?.settings?.harness?.values?.harnesses;
|
|
752
|
+
if (bridge && bridge.origin !== 'default' && isRecord(bridge.value)) {
|
|
753
|
+
const bridgeEntries = bridge.value;
|
|
754
|
+
baselineEntries = Object.fromEntries(
|
|
755
|
+
Object.entries(baselineEntries).flatMap(([id, config]) => {
|
|
756
|
+
const inherited = isRecord(bridgeEntries[id]) ? bridgeEntries[id] : {};
|
|
757
|
+
const fields = Object.fromEntries(
|
|
758
|
+
Object.entries(config).filter(([field]) => !Object.hasOwn(inherited, field)),
|
|
759
|
+
);
|
|
760
|
+
return Object.keys(fields).length ? [[id, fields]] : [];
|
|
761
|
+
}),
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
const response = await workspace.fetch(`${api}/profiles`, { headers, cache: 'no-store' });
|
|
766
|
+
if (!response.ok) {
|
|
767
|
+
const error = await failureOf(response);
|
|
768
|
+
if (at === generation.current) setFailure(error);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
let profiles = (await readJson(response)) as Profile[];
|
|
772
|
+
if (root === '_host') {
|
|
773
|
+
// Checks use workspace drivers; Bridge edits must show only Bridge configuration.
|
|
774
|
+
const effective = isRecord(resolved?.value)
|
|
775
|
+
? (resolved.value as Record<string, Entry>)
|
|
776
|
+
: {};
|
|
777
|
+
profiles = Object.entries(effective).map(([id, config]) => ({
|
|
778
|
+
id,
|
|
779
|
+
config,
|
|
780
|
+
driver: String(config.driver),
|
|
781
|
+
harness: identity(id, config),
|
|
782
|
+
origin: 'host',
|
|
783
|
+
fields: {},
|
|
784
|
+
}));
|
|
785
|
+
}
|
|
786
|
+
if (at !== generation.current) return;
|
|
787
|
+
setStatuses({});
|
|
788
|
+
setModes({});
|
|
789
|
+
setModels({});
|
|
790
|
+
setList({
|
|
791
|
+
entries: Object.fromEntries(profiles.map((profile) => [profile.id, profile.config])),
|
|
792
|
+
profiles,
|
|
793
|
+
baselineEntries: baselineEntries,
|
|
794
|
+
materialize: node === 'root' && !isRecord(local) && Object.keys(baselineEntries).length > 0,
|
|
795
|
+
defaultsEntries: baselineEntries,
|
|
796
|
+
local: isRecord(local) ? (local as Record<string, Entry>) : {},
|
|
797
|
+
defaults: baseline?.origin === 'default',
|
|
798
|
+
item: isRecord(schema.additionalProperties) ? (schema.additionalProperties as Schema) : {},
|
|
799
|
+
});
|
|
800
|
+
setFailure(undefined);
|
|
801
|
+
} catch (cause) {
|
|
802
|
+
if (at === generation.current) setFailure({ message: (cause as Error).message });
|
|
803
|
+
}
|
|
804
|
+
}, [root, node, api]);
|
|
805
|
+
/** Provider `id`'s status, checked now with `refresh`. */
|
|
806
|
+
const check = React.useCallback(
|
|
807
|
+
async (id: string, refresh = false) => {
|
|
808
|
+
const at = generation.current;
|
|
809
|
+
setStatuses((was) => ({ ...was, [id]: 'checking' }));
|
|
810
|
+
const res = await workspace
|
|
811
|
+
.fetch(
|
|
812
|
+
`${api}/status?${new URLSearchParams({ harness: id, ...(refresh && { refresh: '1' }), ...(root === '_host' && { scope: 'bridge' }) })}`,
|
|
813
|
+
{ headers, cache: 'no-store' },
|
|
814
|
+
)
|
|
815
|
+
.catch(() => undefined);
|
|
816
|
+
const status: Status = res?.ok
|
|
817
|
+
? ((await readJson(res)) as Status)
|
|
818
|
+
: {
|
|
819
|
+
installed: false,
|
|
820
|
+
message: res ? (await failureOf(res)).message : 'Bridge did not answer.',
|
|
821
|
+
};
|
|
822
|
+
if (at === generation.current) setStatuses((was) => ({ ...was, [id]: status }));
|
|
823
|
+
},
|
|
824
|
+
[api, node, root],
|
|
825
|
+
);
|
|
826
|
+
React.useEffect(() => {
|
|
827
|
+
const here = `${root}/${node}`;
|
|
828
|
+
const scopeAt = scopeGeneration.current;
|
|
829
|
+
// A scope switch clears a busy flag an in-flight write of the old scope would otherwise leave set.
|
|
830
|
+
setBusy(false);
|
|
831
|
+
setDrivers([]);
|
|
832
|
+
setHarnessLink(undefined);
|
|
833
|
+
setList(undefined);
|
|
834
|
+
setOpen(undefined);
|
|
835
|
+
setAdding(false);
|
|
836
|
+
setStatuses({});
|
|
837
|
+
setModes({});
|
|
838
|
+
setModels({});
|
|
839
|
+
setFailure(undefined);
|
|
840
|
+
void load();
|
|
841
|
+
void workspace
|
|
842
|
+
.fetch(`${api}/drivers`, { cache: 'no-store' })
|
|
843
|
+
.then((res) => (res.ok ? readJson(res) : []))
|
|
844
|
+
.then(
|
|
845
|
+
(body) => {
|
|
846
|
+
if (requestScope.current === here && scopeGeneration.current === scopeAt)
|
|
847
|
+
setDrivers(body as DriverInfo[]);
|
|
848
|
+
},
|
|
849
|
+
() => {},
|
|
850
|
+
);
|
|
851
|
+
// Where this workspace's harness comes from, to install it in `_host` when that lacks it (an older root).
|
|
852
|
+
void workspace
|
|
853
|
+
.fetch(`/_bridge/workspaces/${encodeURIComponent(workspace.slug)}/plugins`, {
|
|
854
|
+
cache: 'no-store',
|
|
855
|
+
})
|
|
856
|
+
.then((res) => (res.ok ? readJson(res) : undefined))
|
|
857
|
+
.then(
|
|
858
|
+
(body) => {
|
|
859
|
+
const plugins = body as
|
|
860
|
+
| { plugins?: { key: string; source?: { path?: string; spec?: string } }[] }
|
|
861
|
+
| undefined;
|
|
862
|
+
// By its key: the harness is `@bridgebrew/harness` from the registry, or a linked folder.
|
|
863
|
+
const source = plugins?.plugins?.find((each) => each.key === 'harness')?.source;
|
|
864
|
+
if (requestScope.current === here && scopeGeneration.current === scopeAt)
|
|
865
|
+
setHarnessLink(source?.path ?? source?.spec);
|
|
866
|
+
},
|
|
867
|
+
() => {},
|
|
868
|
+
);
|
|
869
|
+
}, [load]);
|
|
870
|
+
React.useEffect(() => {
|
|
871
|
+
void load();
|
|
872
|
+
}, [revision]);
|
|
873
|
+
React.useEffect(
|
|
874
|
+
() =>
|
|
875
|
+
ctx.hostStatus.subscribe((event) => {
|
|
876
|
+
if (
|
|
877
|
+
event.event === 'nodes' &&
|
|
878
|
+
(event.data.workspace === root || event.data.workspace === '_host')
|
|
879
|
+
)
|
|
880
|
+
void load();
|
|
881
|
+
}),
|
|
882
|
+
[root, load],
|
|
883
|
+
);
|
|
884
|
+
const entries = list && list !== 'missing' ? list.entries : {};
|
|
885
|
+
const ids = Object.keys(entries).sort((a, b) =>
|
|
886
|
+
identity(a, entries[a]!).localeCompare(identity(b, entries[b]!)),
|
|
887
|
+
);
|
|
888
|
+
const local = list && list !== 'missing' ? list.local : {};
|
|
889
|
+
// Each enabled provider's status (cached by the harness plugin: cheap after the first).
|
|
890
|
+
React.useEffect(() => {
|
|
891
|
+
for (const id of ids) if (entries[id]!.enabled !== false && !(id in statuses)) void check(id);
|
|
892
|
+
}, [list]);
|
|
893
|
+
React.useEffect(() => {
|
|
894
|
+
if (!open || open in modes || !(open in entries)) return;
|
|
895
|
+
const at = generation.current;
|
|
896
|
+
void workspace
|
|
897
|
+
.fetch(
|
|
898
|
+
`${api}/modes?harness=${encodeURIComponent(open)}${root === '_host' ? '&scope=bridge' : ''}`,
|
|
899
|
+
{ headers },
|
|
900
|
+
)
|
|
901
|
+
.then((res) => (res.ok ? readJson(res) : []))
|
|
902
|
+
.then(
|
|
903
|
+
(body) => {
|
|
904
|
+
const answer = body as { id: string }[];
|
|
905
|
+
if (at === generation.current)
|
|
906
|
+
setModes((was) => ({ ...was, [open]: answer.map((each) => each.id) }));
|
|
907
|
+
},
|
|
908
|
+
() => {},
|
|
909
|
+
);
|
|
910
|
+
}, [open, open !== undefined && open in modes, ids.join('\n'), list]);
|
|
911
|
+
React.useEffect(() => {
|
|
912
|
+
if (!open || open in models || !(open in entries)) return;
|
|
913
|
+
const at = generation.current;
|
|
914
|
+
void workspace
|
|
915
|
+
.fetch(
|
|
916
|
+
`${api}/model-options?harness=${encodeURIComponent(open)}${root === '_host' ? '&scope=bridge' : ''}`,
|
|
917
|
+
{ headers },
|
|
918
|
+
)
|
|
919
|
+
.then((res) => (res.ok ? readJson(res) : []))
|
|
920
|
+
.then(
|
|
921
|
+
(body) => {
|
|
922
|
+
const options = body as ModelOption[];
|
|
923
|
+
if (at === generation.current) setModels((was) => ({ ...was, [open]: options }));
|
|
924
|
+
},
|
|
925
|
+
() => {},
|
|
926
|
+
);
|
|
927
|
+
}, [open, open !== undefined && open in models, ids.join('\n'), list]);
|
|
928
|
+
|
|
929
|
+
/** Writes the host list `next` whole; the refusal, if any. */
|
|
930
|
+
const write = async (next: Record<string, Entry>): Promise<Failure | undefined> => {
|
|
931
|
+
if (readOnly) return { message: 'This scope is read-only.' };
|
|
932
|
+
const scopeAt = scopeGeneration.current;
|
|
933
|
+
setBusy(true);
|
|
934
|
+
try {
|
|
935
|
+
const res = await workspace.fetch(
|
|
936
|
+
`/_bridge/workspaces/${encodeURIComponent(root)}/nodes/${encodeURIComponent(node)}`,
|
|
937
|
+
{
|
|
938
|
+
method: 'PATCH',
|
|
939
|
+
headers: { 'content-type': 'application/json' },
|
|
940
|
+
body: JSON.stringify({
|
|
941
|
+
settings: {
|
|
942
|
+
plugin: 'harness',
|
|
943
|
+
field: 'harnesses',
|
|
944
|
+
value: Object.keys(next).length
|
|
945
|
+
? node === 'root' && list && list !== 'missing' && list.materialize
|
|
946
|
+
? Object.fromEntries(
|
|
947
|
+
Object.entries({ ...list.defaultsEntries, ...next }).map(([id, config]) => [
|
|
948
|
+
id,
|
|
949
|
+
{ ...list.defaultsEntries[id], ...config },
|
|
950
|
+
]),
|
|
951
|
+
)
|
|
952
|
+
: next
|
|
953
|
+
: undefined,
|
|
954
|
+
},
|
|
955
|
+
}),
|
|
956
|
+
},
|
|
957
|
+
);
|
|
958
|
+
if (!res.ok) {
|
|
959
|
+
const error = await failureOf(res);
|
|
960
|
+
return scopeGeneration.current === scopeAt ? error : undefined;
|
|
961
|
+
}
|
|
962
|
+
if (requestScope.current === `${root}/${node}` && scopeGeneration.current === scopeAt) {
|
|
963
|
+
setStatuses({});
|
|
964
|
+
setModes({});
|
|
965
|
+
setModels({});
|
|
966
|
+
await load();
|
|
967
|
+
}
|
|
968
|
+
return undefined;
|
|
969
|
+
} catch (cause) {
|
|
970
|
+
return scopeGeneration.current === scopeAt
|
|
971
|
+
? { message: (cause as Error).message }
|
|
972
|
+
: undefined;
|
|
973
|
+
} finally {
|
|
974
|
+
if (requestScope.current === `${root}/${node}` && scopeGeneration.current === scopeAt)
|
|
975
|
+
setBusy(false);
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
const save = async (id: string, entry: Entry, previous: Entry = entries[id] ?? {}) => {
|
|
979
|
+
const here = `${root}/${node}`;
|
|
980
|
+
const scopeAt = scopeGeneration.current;
|
|
981
|
+
const override = { ...local[id] };
|
|
982
|
+
if (previous.command !== entry.command) override.harness = identity(id, previous);
|
|
983
|
+
for (const field of new Set([...Object.keys(previous), ...Object.keys(entry)])) {
|
|
984
|
+
if (JSON.stringify(previous[field]) === JSON.stringify(entry[field])) continue;
|
|
985
|
+
if (entry[field] === undefined) {
|
|
986
|
+
const inherited =
|
|
987
|
+
node === 'root' && list && list !== 'missing'
|
|
988
|
+
? list.baselineEntries[id]?.[field]
|
|
989
|
+
: undefined;
|
|
990
|
+
if (inherited === undefined) delete override[field];
|
|
991
|
+
else override[field] = inherited;
|
|
992
|
+
} else override[field] = entry[field];
|
|
993
|
+
}
|
|
994
|
+
// Nothing local left: drop the entry rather than persist an empty map (an inherited field stays inherited).
|
|
995
|
+
const next = { ...local };
|
|
996
|
+
if (Object.keys(override).length) next[id] = override;
|
|
997
|
+
else delete next[id];
|
|
998
|
+
const refused = await write(next);
|
|
999
|
+
if (!refused && requestScope.current === here && scopeGeneration.current === scopeAt) {
|
|
1000
|
+
setEditorRevision((value) => value + 1);
|
|
1001
|
+
toast({ variant: 'success', title: 'Profile saved', description: scope });
|
|
1002
|
+
setModes(({ [id]: _, ...rest }) => rest);
|
|
1003
|
+
setModels(({ [id]: _, ...rest }) => rest);
|
|
1004
|
+
void check(id, true);
|
|
1005
|
+
}
|
|
1006
|
+
return refused;
|
|
1007
|
+
};
|
|
1008
|
+
const remove = async (id: string) => {
|
|
1009
|
+
const here = `${root}/${node}`;
|
|
1010
|
+
const scopeAt = scopeGeneration.current;
|
|
1011
|
+
const { [id]: _, ...rest } = local;
|
|
1012
|
+
const baseline =
|
|
1013
|
+
node === 'root' && list && list !== 'missing' ? list.baselineEntries[id] : undefined;
|
|
1014
|
+
const refused = await write(
|
|
1015
|
+
baseline && Object.keys(rest).length ? { ...rest, [id]: baseline } : rest,
|
|
1016
|
+
);
|
|
1017
|
+
if (refused) {
|
|
1018
|
+
if (requestScope.current === here && scopeGeneration.current === scopeAt) setFailure(refused);
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (requestScope.current !== here || scopeGeneration.current !== scopeAt) return;
|
|
1022
|
+
setOpen(undefined);
|
|
1023
|
+
toast({
|
|
1024
|
+
variant: 'success',
|
|
1025
|
+
title: `${labelOf(id, entries[id]!)}: local configuration removed`,
|
|
1026
|
+
description: 'Local overrides removed. Existing sessions keep their history.',
|
|
1027
|
+
});
|
|
1028
|
+
};
|
|
1029
|
+
const installHarness = async () => {
|
|
1030
|
+
if (!harnessLink) return;
|
|
1031
|
+
const here = `${root}/${node}`;
|
|
1032
|
+
const scopeAt = scopeGeneration.current;
|
|
1033
|
+
setBusy(true);
|
|
1034
|
+
const res = await workspace
|
|
1035
|
+
.fetch('/_bridge/workspaces/_host/plugins/install', {
|
|
1036
|
+
method: 'POST',
|
|
1037
|
+
headers: { 'content-type': 'application/json' },
|
|
1038
|
+
body: JSON.stringify({ source: harnessLink }),
|
|
1039
|
+
})
|
|
1040
|
+
.catch(() => undefined);
|
|
1041
|
+
if (requestScope.current !== here || scopeGeneration.current !== scopeAt) return;
|
|
1042
|
+
setBusy(false);
|
|
1043
|
+
if (!res?.ok)
|
|
1044
|
+
return setFailure(res ? await failureOf(res) : { message: 'Bridge did not answer.' });
|
|
1045
|
+
setFailure(undefined);
|
|
1046
|
+
await load();
|
|
1047
|
+
};
|
|
1048
|
+
const known = new Map(drivers.map((each) => [each.name, each]));
|
|
1049
|
+
|
|
1050
|
+
return (
|
|
1051
|
+
<section
|
|
1052
|
+
aria-label="Profiles"
|
|
1053
|
+
data-system="providers"
|
|
1054
|
+
data-field="harnesses"
|
|
1055
|
+
className="flex min-h-0 flex-1 flex-col [:where(&)_:is(p,ul,h1,h2,h3)]:m-0"
|
|
1056
|
+
>
|
|
1057
|
+
<div className="mx-auto flex min-h-0 w-full max-w-[968px] flex-1">
|
|
1058
|
+
<div className="min-h-0 min-w-0 flex-1">
|
|
1059
|
+
<div className="box-border flex w-full max-w-[760px] flex-col gap-5 px-4 pb-16 pt-5">
|
|
1060
|
+
<Section
|
|
1061
|
+
size="lg"
|
|
1062
|
+
title="Profiles"
|
|
1063
|
+
description={
|
|
1064
|
+
<>
|
|
1065
|
+
<span className="block text-xs text-muted">
|
|
1066
|
+
Scope: {scope}
|
|
1067
|
+
{readOnly ? ' · Read-only' : ''}
|
|
1068
|
+
</span>
|
|
1069
|
+
Profiles configure execution software (Harnesses), through Bridge adapters
|
|
1070
|
+
(Drivers).
|
|
1071
|
+
</>
|
|
1072
|
+
}
|
|
1073
|
+
actions={
|
|
1074
|
+
list &&
|
|
1075
|
+
list !== 'missing' && (
|
|
1076
|
+
<Button
|
|
1077
|
+
variant="primary"
|
|
1078
|
+
disabled={busy || readOnly || !drivers.length}
|
|
1079
|
+
onClick={() => setAdding(true)}
|
|
1080
|
+
>
|
|
1081
|
+
<Icon name="plus" size={13} />
|
|
1082
|
+
Add profile
|
|
1083
|
+
</Button>
|
|
1084
|
+
)
|
|
1085
|
+
}
|
|
1086
|
+
/>
|
|
1087
|
+
{list === 'missing' && (
|
|
1088
|
+
<div
|
|
1089
|
+
role="note"
|
|
1090
|
+
data-missing-harness
|
|
1091
|
+
className="flex flex-col gap-2 rounded-default bg-warning-subtle px-3 py-2.5 text-[13px] leading-5 text-warning-text"
|
|
1092
|
+
>
|
|
1093
|
+
<span className="flex items-start gap-3">
|
|
1094
|
+
<span className="min-w-0 flex-1">
|
|
1095
|
+
The shell (_host) has no harness plugin, so profiles cannot be shared by every
|
|
1096
|
+
workspace yet.
|
|
1097
|
+
</span>
|
|
1098
|
+
{harnessLink && (
|
|
1099
|
+
<Button
|
|
1100
|
+
size="sm"
|
|
1101
|
+
variant="primary"
|
|
1102
|
+
disabled={busy || readOnly}
|
|
1103
|
+
onClick={() => void installHarness()}
|
|
1104
|
+
>
|
|
1105
|
+
Install it
|
|
1106
|
+
</Button>
|
|
1107
|
+
)}
|
|
1108
|
+
</span>
|
|
1109
|
+
{harnessLink && <Fix text={`bridge install ${harnessLink} --workspace _host`} />}
|
|
1110
|
+
</div>
|
|
1111
|
+
)}
|
|
1112
|
+
{list && list !== 'missing' && list.defaults && (
|
|
1113
|
+
<p
|
|
1114
|
+
role="note"
|
|
1115
|
+
className="rounded-default bg-hover px-3 py-2 text-[13px] leading-5 text-secondary"
|
|
1116
|
+
>
|
|
1117
|
+
Inherited fields stay inherited. Saving writes only changed fields in this scope;
|
|
1118
|
+
Reset removes local overrides.
|
|
1119
|
+
</p>
|
|
1120
|
+
)}
|
|
1121
|
+
{failure && (
|
|
1122
|
+
<p role="alert" className="text-[13px] text-destructive">
|
|
1123
|
+
{sentence(failure.message)}
|
|
1124
|
+
{failure.hint && (
|
|
1125
|
+
<span className="block text-xs text-secondary">{failure.hint}</span>
|
|
1126
|
+
)}
|
|
1127
|
+
</p>
|
|
1128
|
+
)}
|
|
1129
|
+
{list && list !== 'missing' && (
|
|
1130
|
+
<ul aria-label="Profiles" className="m-0 flex list-none flex-col gap-2 p-0">
|
|
1131
|
+
{ids.length === 0 && (
|
|
1132
|
+
<li className="text-[13px] text-muted">No profiles in this scope.</li>
|
|
1133
|
+
)}
|
|
1134
|
+
{ids.map((id) => {
|
|
1135
|
+
const entry = entries[id]!;
|
|
1136
|
+
const profile = list.profiles.find((each) => each.id === id);
|
|
1137
|
+
const group = identity(id, entry);
|
|
1138
|
+
const firstInGroup =
|
|
1139
|
+
ids.find((each) => identity(each, entries[each]!) === group) === id;
|
|
1140
|
+
const driver =
|
|
1141
|
+
typeof entry.driver === 'string' ? known.get(entry.driver) : undefined;
|
|
1142
|
+
const status = statuses[id];
|
|
1143
|
+
const unavailable = !driver;
|
|
1144
|
+
const warn = unavailable || (status !== 'checking' && attention(status));
|
|
1145
|
+
return (
|
|
1146
|
+
<li
|
|
1147
|
+
key={id}
|
|
1148
|
+
data-provider={id}
|
|
1149
|
+
className={cn(
|
|
1150
|
+
'rounded-default border border-border bg-surface',
|
|
1151
|
+
entry.enabled === false && 'opacity-80',
|
|
1152
|
+
)}
|
|
1153
|
+
>
|
|
1154
|
+
<>
|
|
1155
|
+
{firstInGroup && (
|
|
1156
|
+
<h3 className="border-b border-border-subtle px-4 py-2 text-sm font-semibold">
|
|
1157
|
+
{group}
|
|
1158
|
+
</h3>
|
|
1159
|
+
)}
|
|
1160
|
+
</>
|
|
1161
|
+
<div className="flex items-center gap-3 px-4 py-3">
|
|
1162
|
+
<span
|
|
1163
|
+
aria-hidden="true"
|
|
1164
|
+
className="size-2.5 shrink-0 rounded-full"
|
|
1165
|
+
style={{
|
|
1166
|
+
background:
|
|
1167
|
+
typeof entry.color === 'string' && entry.color
|
|
1168
|
+
? entry.color
|
|
1169
|
+
: 'transparent',
|
|
1170
|
+
}}
|
|
1171
|
+
/>
|
|
1172
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
1173
|
+
<span className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
1174
|
+
<span className="truncate">{labelOf(id, entry)}</span>
|
|
1175
|
+
{warn && (
|
|
1176
|
+
<span
|
|
1177
|
+
data-attention
|
|
1178
|
+
title={
|
|
1179
|
+
unavailable
|
|
1180
|
+
? `Driver ${String(entry.driver)} is not installed`
|
|
1181
|
+
: status !== 'checking'
|
|
1182
|
+
? status?.message
|
|
1183
|
+
: undefined
|
|
1184
|
+
}
|
|
1185
|
+
className="size-2 shrink-0 rounded-full bg-warning"
|
|
1186
|
+
/>
|
|
1187
|
+
)}
|
|
1188
|
+
{entry.enabled === false && (
|
|
1189
|
+
<span className="text-xs font-normal text-muted">Off</span>
|
|
1190
|
+
)}
|
|
1191
|
+
{unavailable && (
|
|
1192
|
+
<span className="text-xs font-normal text-warning-text">
|
|
1193
|
+
Unavailable
|
|
1194
|
+
</span>
|
|
1195
|
+
)}
|
|
1196
|
+
</span>
|
|
1197
|
+
<span className="truncate text-xs text-secondary">
|
|
1198
|
+
<span className="font-mono">{id}</span> · Harness: {identity(id, entry)}{' '}
|
|
1199
|
+
· Driver: {driver?.title ?? String(entry.driver ?? 'no driver')}
|
|
1200
|
+
{status &&
|
|
1201
|
+
status !== 'checking' &&
|
|
1202
|
+
!attention(status) &&
|
|
1203
|
+
[status.account, status.version]
|
|
1204
|
+
.filter(Boolean)
|
|
1205
|
+
.map((fact) => ` · ${fact}`)
|
|
1206
|
+
.join('')}
|
|
1207
|
+
</span>
|
|
1208
|
+
</span>
|
|
1209
|
+
<Button
|
|
1210
|
+
size="sm"
|
|
1211
|
+
variant="outline"
|
|
1212
|
+
disabled={busy || readOnly}
|
|
1213
|
+
onClick={() =>
|
|
1214
|
+
void write({
|
|
1215
|
+
...local,
|
|
1216
|
+
[id]: { ...local[id], enabled: entry.enabled === false },
|
|
1217
|
+
}).then((error) => error && setFailure(error))
|
|
1218
|
+
}
|
|
1219
|
+
>
|
|
1220
|
+
{entry.enabled === false ? 'Show' : 'Hide'}
|
|
1221
|
+
</Button>
|
|
1222
|
+
{Object.hasOwn(local, id) && (
|
|
1223
|
+
<Button
|
|
1224
|
+
size="sm"
|
|
1225
|
+
variant="outline"
|
|
1226
|
+
disabled={busy || readOnly}
|
|
1227
|
+
onClick={() => void remove(id)}
|
|
1228
|
+
>
|
|
1229
|
+
{local[id]?.driver !== undefined && !list.baselineEntries[id]
|
|
1230
|
+
? 'Remove'
|
|
1231
|
+
: 'Reset'}
|
|
1232
|
+
</Button>
|
|
1233
|
+
)}
|
|
1234
|
+
<Button
|
|
1235
|
+
size="sm"
|
|
1236
|
+
variant="ghost"
|
|
1237
|
+
aria-expanded={open === id}
|
|
1238
|
+
aria-label={`${open === id ? 'Close' : 'Edit'} ${labelOf(id, entry)}`}
|
|
1239
|
+
onClick={() => setOpen(open === id ? undefined : id)}
|
|
1240
|
+
>
|
|
1241
|
+
<Icon name={open === id ? 'chevron-up' : 'pen-line'} size={13} />
|
|
1242
|
+
{open === id ? 'Close' : 'Edit'}
|
|
1243
|
+
</Button>
|
|
1244
|
+
</div>
|
|
1245
|
+
<p className="px-4 pb-2 text-xs text-muted">
|
|
1246
|
+
{Object.hasOwn(local, id) ? 'Local overrides' : 'Inherited'} ·{' '}
|
|
1247
|
+
{profile && originLabel(profile.origin)}
|
|
1248
|
+
{profile &&
|
|
1249
|
+
Object.entries(profile.fields)
|
|
1250
|
+
.map(([field, origin]) => ` · ${field}: ${originLabel(origin)}`)
|
|
1251
|
+
.join('')}
|
|
1252
|
+
</p>
|
|
1253
|
+
{open !== id && warn && (
|
|
1254
|
+
<div className="px-4 pb-3 pl-[34px]">
|
|
1255
|
+
{unavailable ? (
|
|
1256
|
+
<p className="text-xs text-warning-text">
|
|
1257
|
+
Its driver {String(entry.driver)} is not installed in this workspace:
|
|
1258
|
+
install the harness-{String(entry.driver)} plugin, or remove this
|
|
1259
|
+
profile.
|
|
1260
|
+
</p>
|
|
1261
|
+
) : (
|
|
1262
|
+
<StatusLine status={status} />
|
|
1263
|
+
)}
|
|
1264
|
+
</div>
|
|
1265
|
+
)}
|
|
1266
|
+
{open === id && Object.keys(local[id] ?? {}).length > 0 && (
|
|
1267
|
+
<div className="flex flex-wrap gap-2 px-4 pb-3">
|
|
1268
|
+
{Object.keys(local[id]!)
|
|
1269
|
+
.filter((field) => field !== 'driver' && field !== 'harness')
|
|
1270
|
+
.map((field) => (
|
|
1271
|
+
<Button
|
|
1272
|
+
key={field}
|
|
1273
|
+
size="sm"
|
|
1274
|
+
variant="outline"
|
|
1275
|
+
disabled={busy || readOnly}
|
|
1276
|
+
onClick={() => {
|
|
1277
|
+
const { [field]: _, ...rest } = local[id]!;
|
|
1278
|
+
const baseline =
|
|
1279
|
+
node === 'root' ? list.baselineEntries[id]?.[field] : undefined;
|
|
1280
|
+
const override =
|
|
1281
|
+
baseline === undefined ? rest : { ...rest, [field]: baseline };
|
|
1282
|
+
const next = { ...local };
|
|
1283
|
+
if (Object.keys(override).length) next[id] = override;
|
|
1284
|
+
else delete next[id];
|
|
1285
|
+
void write(next).then((error) => error && setFailure(error));
|
|
1286
|
+
}}
|
|
1287
|
+
>
|
|
1288
|
+
Reset {field}
|
|
1289
|
+
</Button>
|
|
1290
|
+
))}
|
|
1291
|
+
</div>
|
|
1292
|
+
)}
|
|
1293
|
+
{open === id && list.item && (
|
|
1294
|
+
<Editor
|
|
1295
|
+
key={`${id}/${editorRevision}`}
|
|
1296
|
+
id={id}
|
|
1297
|
+
removeLabel={
|
|
1298
|
+
local[id]?.driver !== undefined && !list.baselineEntries[id]
|
|
1299
|
+
? 'Remove profile'
|
|
1300
|
+
: 'Reset overrides'
|
|
1301
|
+
}
|
|
1302
|
+
entry={entry}
|
|
1303
|
+
item={list.item}
|
|
1304
|
+
driver={driver}
|
|
1305
|
+
busy={busy || readOnly}
|
|
1306
|
+
status={status}
|
|
1307
|
+
modes={modes[id] ?? []}
|
|
1308
|
+
models={models[id] ?? []}
|
|
1309
|
+
onSave={(next, previous) => save(id, next, previous)}
|
|
1310
|
+
onRemove={() => void remove(id)}
|
|
1311
|
+
onCancel={() => setOpen(undefined)}
|
|
1312
|
+
onTest={() => void check(id, true)}
|
|
1313
|
+
/>
|
|
1314
|
+
)}
|
|
1315
|
+
</li>
|
|
1316
|
+
);
|
|
1317
|
+
})}
|
|
1318
|
+
</ul>
|
|
1319
|
+
)}
|
|
1320
|
+
</div>
|
|
1321
|
+
</div>
|
|
1322
|
+
</div>
|
|
1323
|
+
<AddDialog
|
|
1324
|
+
key={`${root}/${node}`}
|
|
1325
|
+
open={adding}
|
|
1326
|
+
onOpenChange={(next) => {
|
|
1327
|
+
if (scopeGeneration.current === viewGeneration) setAdding(next);
|
|
1328
|
+
}}
|
|
1329
|
+
drivers={drivers}
|
|
1330
|
+
taken={ids}
|
|
1331
|
+
onAdd={async (id, entry) => {
|
|
1332
|
+
const here = `${root}/${node}`;
|
|
1333
|
+
const scopeAt = scopeGeneration.current;
|
|
1334
|
+
const refused = await write({ ...local, [id]: entry });
|
|
1335
|
+
if (!refused && requestScope.current === here && scopeGeneration.current === scopeAt) {
|
|
1336
|
+
setOpen(id);
|
|
1337
|
+
toast({
|
|
1338
|
+
variant: 'success',
|
|
1339
|
+
title: `${labelOf(id, entry)} added`,
|
|
1340
|
+
description: 'Finish its setup below.',
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
return refused;
|
|
1344
|
+
}}
|
|
1345
|
+
/>
|
|
1346
|
+
</section>
|
|
1347
|
+
);
|
|
1348
|
+
}
|