@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,2593 @@
|
|
|
1
|
+
// The plugin manager (this folder, which the Plugin manager plugin's Plugins section and the Bridge
|
|
2
|
+
// settings plugin's Extensions each bundle), in the style of VS Code's Extensions view: a header with a
|
|
3
|
+
// search ("Search installed plugins"), filter chips (All, Enabled, Disabled, Failed, System, each with its count) and
|
|
4
|
+
// "Install plugin"; then the installed plugins (failing ones first) beside the chosen one's details: its state, error
|
|
5
|
+
// and way out, source, nodes, settings, and its actions (enable or disable, reload, remove after a confirmation listing
|
|
6
|
+
// what references it). Below a width the details replace the list, with a way back. Data from
|
|
7
|
+
// `GET /_bridge/workspaces/<slug>/plugins`, refetched on the host's status events for this workspace; each action is the
|
|
8
|
+
// CLI's (`POST …/install`, `…/<plugin>/enable|disable|reload`, `DELETE …/<plugin>`), answered once done: one at a time,
|
|
9
|
+
// its buttons busy meanwhile, its outcome a toast (the shell already toasts a disable and a removal).
|
|
10
|
+
// With `slug="_host"` it is System › Plugins, every plugin of Bridge's own workspace (research-016 W2): no
|
|
11
|
+
// install, no nodes, Bridge's storage and the shell locked (the CLI only).
|
|
12
|
+
import * as React from 'react';
|
|
13
|
+
import {
|
|
14
|
+
Badge,
|
|
15
|
+
Button,
|
|
16
|
+
Dialog,
|
|
17
|
+
DialogBody,
|
|
18
|
+
DialogClose,
|
|
19
|
+
DialogContent,
|
|
20
|
+
DialogDescription,
|
|
21
|
+
DialogFooter,
|
|
22
|
+
DialogHeader,
|
|
23
|
+
DialogTitle,
|
|
24
|
+
DropdownMenu,
|
|
25
|
+
DropdownMenuContent,
|
|
26
|
+
DropdownMenuItem,
|
|
27
|
+
DropdownMenuTrigger,
|
|
28
|
+
EmptyState,
|
|
29
|
+
Field,
|
|
30
|
+
FieldDescription,
|
|
31
|
+
FieldLabel,
|
|
32
|
+
HttpError,
|
|
33
|
+
Icon,
|
|
34
|
+
Input,
|
|
35
|
+
List,
|
|
36
|
+
ListGroup,
|
|
37
|
+
ScrollArea,
|
|
38
|
+
SegmentGroup,
|
|
39
|
+
Select,
|
|
40
|
+
SelectContent,
|
|
41
|
+
SelectItem,
|
|
42
|
+
SelectTrigger,
|
|
43
|
+
SelectValue,
|
|
44
|
+
Section,
|
|
45
|
+
SidebarResizeHandle,
|
|
46
|
+
SidebarTree,
|
|
47
|
+
SidebarTreeItem,
|
|
48
|
+
Tabs,
|
|
49
|
+
TabsContent,
|
|
50
|
+
TabsList,
|
|
51
|
+
TabsTrigger,
|
|
52
|
+
Toggle,
|
|
53
|
+
Tooltip,
|
|
54
|
+
TooltipContent,
|
|
55
|
+
TooltipTrigger,
|
|
56
|
+
cn,
|
|
57
|
+
useToast,
|
|
58
|
+
copyText,
|
|
59
|
+
readJson,
|
|
60
|
+
gestureOf,
|
|
61
|
+
useFollow,
|
|
62
|
+
} from '@bridge/ui';
|
|
63
|
+
import type { Context } from 'cordis';
|
|
64
|
+
import { Marketplace, useApproval, useCatalog } from './marketplace.tsx';
|
|
65
|
+
import { Readme, Versions, useEntryDetail } from './plugin-readme.tsx';
|
|
66
|
+
import {
|
|
67
|
+
actionOf,
|
|
68
|
+
entryOfPlugin,
|
|
69
|
+
unresolvedFixes,
|
|
70
|
+
pageTabs,
|
|
71
|
+
type CatalogEntry,
|
|
72
|
+
type PageTab,
|
|
73
|
+
} from './marketplace-model.ts';
|
|
74
|
+
import {
|
|
75
|
+
Fact,
|
|
76
|
+
OfficialBadge,
|
|
77
|
+
PluginGlyph,
|
|
78
|
+
PluginHeader,
|
|
79
|
+
PluginListRow,
|
|
80
|
+
kindIcon,
|
|
81
|
+
useListWidth,
|
|
82
|
+
} from './plugin-parts.tsx';
|
|
83
|
+
import { PluginDependencies } from './plugin-dependencies.tsx';
|
|
84
|
+
import { PluginDocs } from './plugin-docs.tsx';
|
|
85
|
+
import { UpdateAllDialog, updateOne } from './update-all.tsx';
|
|
86
|
+
import { PluginLogs } from './plugin-logs.tsx';
|
|
87
|
+
import { PluginSettings } from './plugin-settings.tsx';
|
|
88
|
+
// By its shared name, never its file: the page has one copy of the settings pages' context (research-115).
|
|
89
|
+
import { SettingsPageOutlet } from './settings-page.tsx';
|
|
90
|
+
import {
|
|
91
|
+
counts,
|
|
92
|
+
deliveries,
|
|
93
|
+
dependencyTree,
|
|
94
|
+
domainOf,
|
|
95
|
+
domains,
|
|
96
|
+
entryKey,
|
|
97
|
+
pluginOpening,
|
|
98
|
+
failing,
|
|
99
|
+
filterLabels,
|
|
100
|
+
filters,
|
|
101
|
+
groups,
|
|
102
|
+
modes,
|
|
103
|
+
nameOf,
|
|
104
|
+
needsSetup,
|
|
105
|
+
notUpdatedText,
|
|
106
|
+
pruneTree,
|
|
107
|
+
sentence,
|
|
108
|
+
sourceText,
|
|
109
|
+
stateLabel,
|
|
110
|
+
type DependencyNode,
|
|
111
|
+
type Filter,
|
|
112
|
+
type Mode,
|
|
113
|
+
type NodeRef,
|
|
114
|
+
type PluginItem,
|
|
115
|
+
type PluginsList,
|
|
116
|
+
type Root,
|
|
117
|
+
updateQuestion,
|
|
118
|
+
} from './plugins-model.ts';
|
|
119
|
+
|
|
120
|
+
/** "List by"'s segments, one array for every render. */
|
|
121
|
+
const modeItems = [...modes];
|
|
122
|
+
|
|
123
|
+
type Failure = { message: string; hint?: string; code?: string };
|
|
124
|
+
type Op = 'enable' | 'disable' | 'reload' | 'remove' | 'install' | 'back' | 'unhold' | 'update';
|
|
125
|
+
const doing: Record<Op, string> = {
|
|
126
|
+
enable: 'Enabling…',
|
|
127
|
+
disable: 'Disabling…',
|
|
128
|
+
reload: 'Reloading…',
|
|
129
|
+
remove: 'Removing…',
|
|
130
|
+
install: 'Installing…',
|
|
131
|
+
back: 'Going back…',
|
|
132
|
+
unhold: 'Lifting the hold…',
|
|
133
|
+
update: 'Updating…',
|
|
134
|
+
};
|
|
135
|
+
/** What a failed `act` could not do, after the plugin's name. */
|
|
136
|
+
const undone: Record<Op, string> = {
|
|
137
|
+
enable: 'could not be enabled',
|
|
138
|
+
disable: 'could not be disabled',
|
|
139
|
+
reload: 'could not be reloaded',
|
|
140
|
+
back: 'could not go back',
|
|
141
|
+
unhold: 'is still held',
|
|
142
|
+
update: 'could not be updated',
|
|
143
|
+
remove: 'could not be removed',
|
|
144
|
+
install: 'could not be installed',
|
|
145
|
+
};
|
|
146
|
+
/** This screen's own plugin: disabling or removing it here would take the screen away mid-action. */
|
|
147
|
+
const self = 'plugin-manager';
|
|
148
|
+
/** Why `plugin` cannot be disabled or removed here, if it cannot: this screen's own, or Bridge's storage (`_host`). */
|
|
149
|
+
const lockOf = (plugin: PluginItem) =>
|
|
150
|
+
plugin.key === self
|
|
151
|
+
? 'This screen belongs to it: disable or remove it with the CLI.'
|
|
152
|
+
: plugin.key === 'bridge-settings'
|
|
153
|
+
? "Bridge's System screens: disable or remove it with the CLI."
|
|
154
|
+
: plugin.role === 'storage'
|
|
155
|
+
? "Bridge stores the shell's settings through it: disable or remove it with the CLI."
|
|
156
|
+
: plugin.role === 'shell'
|
|
157
|
+
? 'The whole interface runs on it: disable or remove it with the CLI.'
|
|
158
|
+
: undefined;
|
|
159
|
+
|
|
160
|
+
/** A refused answer's failure: its message, `code` and `hint`; `HTTP <status>` when its body says nothing. */
|
|
161
|
+
const failureOf = async (res: Response): Promise<Failure> => {
|
|
162
|
+
try {
|
|
163
|
+
await readJson(res);
|
|
164
|
+
} catch (cause) {
|
|
165
|
+
if (!(cause instanceof HttpError)) throw cause;
|
|
166
|
+
return {
|
|
167
|
+
message: cause.message,
|
|
168
|
+
...(cause.hint !== undefined && { hint: cause.hint }),
|
|
169
|
+
...(cause.code !== undefined && { code: cause.code }),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return { message: `HTTP ${res.status}` };
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** The plugin's screen icon, else its kind's, in a tile. */
|
|
176
|
+
function PluginIcon({ plugin, size = 'md' }: { plugin: PluginItem; size?: 'md' | 'lg' }) {
|
|
177
|
+
return (
|
|
178
|
+
<PluginGlyph
|
|
179
|
+
icon={plugin.icon}
|
|
180
|
+
kind={plugin.kind}
|
|
181
|
+
size={size}
|
|
182
|
+
className={cn(
|
|
183
|
+
plugin.official && 'border-accent/25 bg-accent-subtle text-accent',
|
|
184
|
+
failing(plugin) && 'border-destructive/30 bg-destructive-subtle text-destructive',
|
|
185
|
+
plugin.state === 'disabled' && 'opacity-60',
|
|
186
|
+
)}
|
|
187
|
+
/>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A dot and a word: enabled green, disabled muted, failed red, an error or a wait amber. */
|
|
192
|
+
function StateMark({ plugin, busy }: { plugin: PluginItem; busy?: Op | undefined }) {
|
|
193
|
+
if (busy) {
|
|
194
|
+
return (
|
|
195
|
+
<span data-state="busy" className="flex items-center gap-1.5 text-xs text-secondary">
|
|
196
|
+
<Icon name="loader-circle" size={12} className="animate-spin motion-reduce:animate-none" />
|
|
197
|
+
{doing[busy]}
|
|
198
|
+
</span>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
const label = stateLabel(plugin);
|
|
202
|
+
const tone =
|
|
203
|
+
plugin.state === 'failed'
|
|
204
|
+
? 'text-destructive'
|
|
205
|
+
: failing(plugin) || needsSetup(plugin)
|
|
206
|
+
? 'text-warning-text'
|
|
207
|
+
: plugin.state === 'disabled'
|
|
208
|
+
? 'text-muted'
|
|
209
|
+
: 'text-secondary';
|
|
210
|
+
const dot =
|
|
211
|
+
plugin.state === 'failed'
|
|
212
|
+
? 'bg-destructive'
|
|
213
|
+
: failing(plugin) || needsSetup(plugin)
|
|
214
|
+
? 'bg-warning'
|
|
215
|
+
: plugin.state === 'disabled'
|
|
216
|
+
? 'border border-muted bg-transparent'
|
|
217
|
+
: 'bg-success';
|
|
218
|
+
return (
|
|
219
|
+
<span
|
|
220
|
+
data-state={plugin.replacedBy ? 'replaced' : plugin.state}
|
|
221
|
+
className={cn('flex items-center gap-1.5 text-xs font-medium', tone)}
|
|
222
|
+
>
|
|
223
|
+
<span aria-hidden="true" className={cn('size-2 shrink-0 rounded-full', dot)} />
|
|
224
|
+
{label}
|
|
225
|
+
</span>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** How the plugin arrives and updates (research-066); what that means for its updates in the tooltip. */
|
|
230
|
+
function DeliveryBadge({ plugin }: { plugin: PluginItem }) {
|
|
231
|
+
const { label, updates } = deliveries[plugin.delivery];
|
|
232
|
+
return (
|
|
233
|
+
<Tooltip>
|
|
234
|
+
<TooltipTrigger
|
|
235
|
+
render={
|
|
236
|
+
<Badge
|
|
237
|
+
data-delivery={plugin.delivery}
|
|
238
|
+
className={cn(
|
|
239
|
+
'h-4 px-1.5 text-[11px]',
|
|
240
|
+
plugin.delivery === 'built-in' && 'bg-accent-subtle text-accent',
|
|
241
|
+
)}
|
|
242
|
+
/>
|
|
243
|
+
}
|
|
244
|
+
>
|
|
245
|
+
{label}
|
|
246
|
+
</TooltipTrigger>
|
|
247
|
+
<TooltipContent>{updates}</TooltipContent>
|
|
248
|
+
</Tooltip>
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The user went back on it (#472): no update is offered until they lift the hold. */
|
|
253
|
+
function HeldBadge({ plugin }: { plugin: PluginItem }) {
|
|
254
|
+
return (
|
|
255
|
+
<Badge
|
|
256
|
+
data-held
|
|
257
|
+
title={`You went back to ${plugin.version}: no update until you lift the hold`}
|
|
258
|
+
className="h-4 px-1.5 text-[11px] bg-warning-subtle text-warning-text"
|
|
259
|
+
>
|
|
260
|
+
Held
|
|
261
|
+
</Badge>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Its manifest's `experimental`: a trial, which may change or go away. */
|
|
266
|
+
function ExperimentalBadge() {
|
|
267
|
+
return (
|
|
268
|
+
<Badge
|
|
269
|
+
data-experimental
|
|
270
|
+
title="A trial: it may change or go away"
|
|
271
|
+
className="h-4 px-1.5 text-[11px] bg-warning-subtle text-warning-text"
|
|
272
|
+
>
|
|
273
|
+
Experimental
|
|
274
|
+
</Badge>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** A small icon button with a tooltip. */
|
|
279
|
+
function IconAction({
|
|
280
|
+
label,
|
|
281
|
+
icon,
|
|
282
|
+
onClick,
|
|
283
|
+
disabled,
|
|
284
|
+
className,
|
|
285
|
+
}: {
|
|
286
|
+
label: string;
|
|
287
|
+
icon: string;
|
|
288
|
+
onClick: () => void;
|
|
289
|
+
disabled?: boolean;
|
|
290
|
+
className?: string;
|
|
291
|
+
}) {
|
|
292
|
+
return (
|
|
293
|
+
<Tooltip>
|
|
294
|
+
<TooltipTrigger
|
|
295
|
+
render={
|
|
296
|
+
<Button
|
|
297
|
+
size="icon-sm"
|
|
298
|
+
aria-label={label}
|
|
299
|
+
disabled={disabled}
|
|
300
|
+
className={className}
|
|
301
|
+
onClick={(event) => {
|
|
302
|
+
event.stopPropagation();
|
|
303
|
+
onClick();
|
|
304
|
+
}}
|
|
305
|
+
/>
|
|
306
|
+
}
|
|
307
|
+
>
|
|
308
|
+
<Icon name={icon} size={14} />
|
|
309
|
+
</TooltipTrigger>
|
|
310
|
+
<TooltipContent>{label}</TooltipContent>
|
|
311
|
+
</Tooltip>
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** One row of the list: icon, name, version, key and source; its state, or its quick actions on hover. */
|
|
316
|
+
function Row({
|
|
317
|
+
value,
|
|
318
|
+
plugin,
|
|
319
|
+
busy,
|
|
320
|
+
locked,
|
|
321
|
+
act,
|
|
322
|
+
}: {
|
|
323
|
+
value: string;
|
|
324
|
+
plugin: PluginItem;
|
|
325
|
+
busy: Op | undefined;
|
|
326
|
+
locked: boolean;
|
|
327
|
+
act: (op: Op, plugin: PluginItem) => void;
|
|
328
|
+
}) {
|
|
329
|
+
const name = nameOf(plugin);
|
|
330
|
+
const lock = lockOf(plugin);
|
|
331
|
+
const own = lock !== undefined;
|
|
332
|
+
const follow = useFollow();
|
|
333
|
+
// ⌘ (Ctrl), ⌥ or a middle click: the plugin in a window beside, on a new desk (research-048); the selection here
|
|
334
|
+
// stays. A plain click selects it here, as before.
|
|
335
|
+
const elsewhere = (event: React.MouseEvent) => {
|
|
336
|
+
const gesture = gestureOf(event);
|
|
337
|
+
if (!follow || (gesture !== 'beside' && gesture !== 'desk')) return;
|
|
338
|
+
event.preventDefault();
|
|
339
|
+
event.stopPropagation();
|
|
340
|
+
follow.follow({ item: value }, event);
|
|
341
|
+
};
|
|
342
|
+
return (
|
|
343
|
+
<PluginListRow
|
|
344
|
+
value={value}
|
|
345
|
+
onClickCapture={elsewhere}
|
|
346
|
+
onAuxClick={(event) => event.button === 1 && elsewhere(event)}
|
|
347
|
+
textValue={`${name}, ${stateLabel(plugin)}`}
|
|
348
|
+
data-plugin-row={plugin.key}
|
|
349
|
+
icon={plugin.icon}
|
|
350
|
+
kind={plugin.kind}
|
|
351
|
+
title={name}
|
|
352
|
+
official={plugin.official}
|
|
353
|
+
tone={failing(plugin) ? 'failing' : plugin.state === 'disabled' ? 'disabled' : undefined}
|
|
354
|
+
description={
|
|
355
|
+
// Bridge's update left it behind (research-102 rule 6b): said in the list, its Update on its page.
|
|
356
|
+
plugin.notUpdated && !plugin.stoppedAfterUpdate ? (
|
|
357
|
+
<span
|
|
358
|
+
data-row-not-updated={plugin.notUpdated.why}
|
|
359
|
+
className="min-w-0 truncate text-xs leading-4 text-warning-text"
|
|
360
|
+
title={`Not updated: ${notUpdatedText(plugin, plugin.notUpdated)}`}
|
|
361
|
+
>
|
|
362
|
+
Not updated: {notUpdatedText(plugin, plugin.notUpdated)}
|
|
363
|
+
</span>
|
|
364
|
+
) : plugin.description !== undefined ? (
|
|
365
|
+
<span
|
|
366
|
+
data-description
|
|
367
|
+
className="line-clamp-2 min-h-4 text-xs leading-4 text-secondary"
|
|
368
|
+
title={plugin.description}
|
|
369
|
+
>
|
|
370
|
+
{plugin.description}
|
|
371
|
+
</span>
|
|
372
|
+
) : (
|
|
373
|
+
<span className="min-w-0 truncate font-mono text-[11px] text-muted">{plugin.id}</span>
|
|
374
|
+
)
|
|
375
|
+
}
|
|
376
|
+
version={plugin.version}
|
|
377
|
+
action={
|
|
378
|
+
// The state, Enable or Disable and Reload on hover; removing is on the plugin's page.
|
|
379
|
+
<span className="flex items-center">
|
|
380
|
+
<span
|
|
381
|
+
className={cn(
|
|
382
|
+
'flex shrink-0 items-center',
|
|
383
|
+
!busy && !plugin.replacedBy && 'group-hover/row:hidden group-focus-within/row:hidden',
|
|
384
|
+
)}
|
|
385
|
+
>
|
|
386
|
+
<StateMark plugin={plugin} busy={busy} />
|
|
387
|
+
</span>
|
|
388
|
+
{!busy && !plugin.replacedBy && (
|
|
389
|
+
<span
|
|
390
|
+
className="hidden shrink-0 items-center gap-0.5 group-hover/row:flex group-focus-within/row:flex"
|
|
391
|
+
onClick={(event) => event.stopPropagation()}
|
|
392
|
+
>
|
|
393
|
+
<Tooltip>
|
|
394
|
+
<TooltipTrigger
|
|
395
|
+
render={
|
|
396
|
+
<span className="flex items-center px-1">
|
|
397
|
+
<Toggle
|
|
398
|
+
aria-label={
|
|
399
|
+
plugin.state === 'disabled' ? `Enable ${name}` : `Disable ${name}`
|
|
400
|
+
}
|
|
401
|
+
checked={plugin.state !== 'disabled'}
|
|
402
|
+
disabled={locked || own}
|
|
403
|
+
onCheckedChange={(on) => act(on ? 'enable' : 'disable', plugin)}
|
|
404
|
+
/>
|
|
405
|
+
</span>
|
|
406
|
+
}
|
|
407
|
+
/>
|
|
408
|
+
<TooltipContent>
|
|
409
|
+
{own ? 'Use the CLI' : plugin.state === 'disabled' ? 'Enable' : 'Disable'}
|
|
410
|
+
</TooltipContent>
|
|
411
|
+
</Tooltip>
|
|
412
|
+
<IconAction
|
|
413
|
+
label={`Reload ${name}`}
|
|
414
|
+
icon="rotate-cw"
|
|
415
|
+
disabled={locked || plugin.state === 'disabled'}
|
|
416
|
+
onClick={() => act('reload', plugin)}
|
|
417
|
+
/>
|
|
418
|
+
</span>
|
|
419
|
+
)}
|
|
420
|
+
</span>
|
|
421
|
+
}
|
|
422
|
+
>
|
|
423
|
+
{failing(plugin) && (
|
|
424
|
+
<span
|
|
425
|
+
aria-hidden="true"
|
|
426
|
+
className="absolute inset-y-2 left-0.5 w-[3px] rounded-full bg-destructive"
|
|
427
|
+
/>
|
|
428
|
+
)}
|
|
429
|
+
</PluginListRow>
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** A running plugin waiting for the user (bridge#449, `needsSetup`): amber, its message, and its fix on the right. */
|
|
434
|
+
function SetupNotice({
|
|
435
|
+
name,
|
|
436
|
+
attention,
|
|
437
|
+
openSetting,
|
|
438
|
+
runAction,
|
|
439
|
+
retry,
|
|
440
|
+
}: {
|
|
441
|
+
name: string;
|
|
442
|
+
attention: NonNullable<PluginItem['attention']>;
|
|
443
|
+
openSetting: (setting: string, event: React.MouseEvent) => void;
|
|
444
|
+
runAction: (fix: { action: string; label: string; confirm?: string }) => void;
|
|
445
|
+
/** Restarts its workspace: a `retry` fix. */
|
|
446
|
+
retry: () => void;
|
|
447
|
+
}) {
|
|
448
|
+
const { fix } = attention;
|
|
449
|
+
return (
|
|
450
|
+
<section
|
|
451
|
+
role="status"
|
|
452
|
+
data-needs-setup
|
|
453
|
+
className="flex items-start gap-3 rounded-default border border-warning/30 bg-warning-subtle px-4 py-3"
|
|
454
|
+
>
|
|
455
|
+
<Icon name="triangle-alert" size={16} className="mt-0.5 shrink-0 text-warning-text" />
|
|
456
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
457
|
+
<p className="text-sm font-semibold text-warning-text">{name} needs setup</p>
|
|
458
|
+
<p className="text-xs leading-5 text-foreground">{attention.message}</p>
|
|
459
|
+
</div>
|
|
460
|
+
{fix && 'setting' in fix && (
|
|
461
|
+
<Button size="sm" variant="outline" onClick={(event) => openSetting(fix.setting, event)}>
|
|
462
|
+
{fix.setting === '' ? 'Open its settings' : 'Open the setting'}
|
|
463
|
+
</Button>
|
|
464
|
+
)}
|
|
465
|
+
{fix && 'retry' in fix && (
|
|
466
|
+
<Button size="sm" variant="outline" onClick={retry}>
|
|
467
|
+
{fix.retry}
|
|
468
|
+
</Button>
|
|
469
|
+
)}
|
|
470
|
+
{fix && 'action' in fix && (
|
|
471
|
+
<Button
|
|
472
|
+
size="sm"
|
|
473
|
+
variant="outline"
|
|
474
|
+
onClick={() =>
|
|
475
|
+
runAction({
|
|
476
|
+
action: fix.action,
|
|
477
|
+
label: fix.label,
|
|
478
|
+
...(fix.confirm !== undefined && { confirm: fix.confirm }),
|
|
479
|
+
})
|
|
480
|
+
}
|
|
481
|
+
>
|
|
482
|
+
{fix.label}
|
|
483
|
+
</Button>
|
|
484
|
+
)}
|
|
485
|
+
</section>
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Bridge's last update left it behind (research-102 rule 6b): why, on one line, with its Update. */
|
|
490
|
+
function NotUpdatedNotice({
|
|
491
|
+
plugin,
|
|
492
|
+
disabled,
|
|
493
|
+
update,
|
|
494
|
+
}: {
|
|
495
|
+
plugin: PluginItem & { notUpdated: NonNullable<PluginItem['notUpdated']> };
|
|
496
|
+
disabled: boolean;
|
|
497
|
+
update: () => void;
|
|
498
|
+
}) {
|
|
499
|
+
const { to, error } = plugin.notUpdated;
|
|
500
|
+
return (
|
|
501
|
+
<section
|
|
502
|
+
role="status"
|
|
503
|
+
data-not-updated={plugin.notUpdated.why}
|
|
504
|
+
className="flex items-center gap-3 rounded-default border border-warning/30 bg-warning-subtle px-4 py-2"
|
|
505
|
+
>
|
|
506
|
+
<Icon name="circle-alert" size={16} className="shrink-0 text-warning-text" />
|
|
507
|
+
<p className="min-w-0 flex-1 truncate text-sm text-foreground" title={error}>
|
|
508
|
+
<span className="font-semibold text-warning-text">Not updated with Bridge: </span>
|
|
509
|
+
{notUpdatedText(plugin, plugin.notUpdated)}
|
|
510
|
+
</p>
|
|
511
|
+
<Button
|
|
512
|
+
size="sm"
|
|
513
|
+
variant="outline"
|
|
514
|
+
data-plugin-catch-up={to}
|
|
515
|
+
disabled={disabled}
|
|
516
|
+
onClick={update}
|
|
517
|
+
>
|
|
518
|
+
<Icon name="arrow-up" size={13} />
|
|
519
|
+
Update to {to}
|
|
520
|
+
</Button>
|
|
521
|
+
</section>
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function NodeLinks({ nodes, open }: { nodes: NodeRef[]; open: (id: string) => void }) {
|
|
526
|
+
if (!nodes.length) return <span className="text-muted">None</span>;
|
|
527
|
+
return (
|
|
528
|
+
<span className="flex flex-wrap gap-1.5">
|
|
529
|
+
{nodes.map((node) => (
|
|
530
|
+
<Button
|
|
531
|
+
key={node.id}
|
|
532
|
+
type="button"
|
|
533
|
+
variant="property"
|
|
534
|
+
size="sm"
|
|
535
|
+
data-node-link={node.id}
|
|
536
|
+
onClick={() => open(node.id)}
|
|
537
|
+
className="max-w-full"
|
|
538
|
+
>
|
|
539
|
+
<Icon name={node.id === 'root' ? 'home' : 'folder'} size={12} />
|
|
540
|
+
<span className="truncate">{node.title}</span>
|
|
541
|
+
</Button>
|
|
542
|
+
))}
|
|
543
|
+
</span>
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** A contract or a tool, in mono. */
|
|
548
|
+
function Chip({ children, tone }: { children: React.ReactNode; tone?: 'missing' | undefined }) {
|
|
549
|
+
return (
|
|
550
|
+
<code
|
|
551
|
+
className={cn(
|
|
552
|
+
'w-fit rounded-sm px-1.5 py-px font-mono text-[11px]',
|
|
553
|
+
tone === 'missing' ? 'bg-destructive-subtle text-destructive' : 'bg-hover text-secondary',
|
|
554
|
+
)}
|
|
555
|
+
>
|
|
556
|
+
{children}
|
|
557
|
+
</code>
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** Info (P4): what it is for, what it adds, where it runs, where it comes from; its contracts are the Dependencies tab's. */
|
|
562
|
+
function Info({
|
|
563
|
+
plugin,
|
|
564
|
+
openNode,
|
|
565
|
+
openScreen,
|
|
566
|
+
copy,
|
|
567
|
+
}: {
|
|
568
|
+
plugin: PluginItem;
|
|
569
|
+
/** None for `_host`: its plugins run on no node of this workspace. */
|
|
570
|
+
openNode: ((id: string) => void) | undefined;
|
|
571
|
+
openScreen: ((id: string) => void) | undefined;
|
|
572
|
+
copy: (text: string, what: string) => void;
|
|
573
|
+
}) {
|
|
574
|
+
const adds = plugin.screens.length > 0 || plugin.tools.length > 0;
|
|
575
|
+
const [allTools, setAllTools] = React.useState(false);
|
|
576
|
+
return (
|
|
577
|
+
<div className="flex flex-col gap-6">
|
|
578
|
+
{plugin.description !== undefined && (
|
|
579
|
+
<p className="max-w-[560px] text-sm leading-6 text-secondary">{plugin.description}</p>
|
|
580
|
+
)}
|
|
581
|
+
<Section title="What it adds" data-adds>
|
|
582
|
+
{!adds && (
|
|
583
|
+
<p className="text-[13px] text-secondary">
|
|
584
|
+
No screen, no service for other plugins, no tool for agents.
|
|
585
|
+
</p>
|
|
586
|
+
)}
|
|
587
|
+
{plugin.screens.length > 0 && (
|
|
588
|
+
<dl className="m-0 flex flex-col">
|
|
589
|
+
<Fact label="Screens">
|
|
590
|
+
<span className="flex flex-wrap gap-1.5">
|
|
591
|
+
{plugin.screens.map((screen) => (
|
|
592
|
+
<Button
|
|
593
|
+
key={screen.id}
|
|
594
|
+
type="button"
|
|
595
|
+
variant="property"
|
|
596
|
+
size="sm"
|
|
597
|
+
data-screen-link={screen.id}
|
|
598
|
+
disabled={!openScreen || plugin.state !== 'enabled'}
|
|
599
|
+
onClick={() => openScreen?.(screen.id)}
|
|
600
|
+
>
|
|
601
|
+
{screen.icon && <Icon name={screen.icon} size={12} />}
|
|
602
|
+
{screen.title}
|
|
603
|
+
</Button>
|
|
604
|
+
))}
|
|
605
|
+
</span>
|
|
606
|
+
</Fact>
|
|
607
|
+
</dl>
|
|
608
|
+
)}
|
|
609
|
+
{plugin.tools.length > 0 && (
|
|
610
|
+
<dl className="m-0">
|
|
611
|
+
<Fact label="Agent tools">
|
|
612
|
+
<ul className="m-0 flex list-none flex-col gap-1.5 p-0">
|
|
613
|
+
{(allTools ? plugin.tools : plugin.tools.slice(0, toolsShown)).map((tool) => (
|
|
614
|
+
<li key={tool.name} data-tool={tool.name} className="flex flex-col gap-0.5">
|
|
615
|
+
<Chip>{tool.name}</Chip>
|
|
616
|
+
<span
|
|
617
|
+
className="line-clamp-2 text-xs leading-5 text-secondary"
|
|
618
|
+
title={tool.description}
|
|
619
|
+
>
|
|
620
|
+
{tool.description}
|
|
621
|
+
</span>
|
|
622
|
+
</li>
|
|
623
|
+
))}
|
|
624
|
+
{!allTools && plugin.tools.length > toolsShown && (
|
|
625
|
+
<li>
|
|
626
|
+
<button
|
|
627
|
+
type="button"
|
|
628
|
+
onClick={() => setAllTools(true)}
|
|
629
|
+
className="cursor-pointer border-0 bg-transparent p-0 font-[inherit] text-xs font-medium text-accent hover:underline"
|
|
630
|
+
>
|
|
631
|
+
Show {plugin.tools.length - toolsShown} more
|
|
632
|
+
</button>
|
|
633
|
+
</li>
|
|
634
|
+
)}
|
|
635
|
+
</ul>
|
|
636
|
+
</Fact>
|
|
637
|
+
</dl>
|
|
638
|
+
)}
|
|
639
|
+
</Section>
|
|
640
|
+
<Section title="About">
|
|
641
|
+
<dl className="m-0 flex flex-col">
|
|
642
|
+
<Fact label="Domain">{domains.find(({ id }) => id === domainOf(plugin))!.title}</Fact>
|
|
643
|
+
<Fact label="Source">
|
|
644
|
+
<span className="flex min-w-0 items-center gap-1">
|
|
645
|
+
<span
|
|
646
|
+
className="min-w-0 truncate font-mono text-xs"
|
|
647
|
+
title={sourceText(plugin.source)}
|
|
648
|
+
>
|
|
649
|
+
{sourceText(plugin.source)}
|
|
650
|
+
</span>
|
|
651
|
+
<IconAction
|
|
652
|
+
label={'path' in plugin.source ? 'Copy path' : 'Copy spec'}
|
|
653
|
+
icon="copy"
|
|
654
|
+
className="size-5 shrink-0"
|
|
655
|
+
onClick={() =>
|
|
656
|
+
copy(sourceText(plugin.source), 'path' in plugin.source ? 'Path' : 'Spec')
|
|
657
|
+
}
|
|
658
|
+
/>
|
|
659
|
+
</span>
|
|
660
|
+
</Fact>
|
|
661
|
+
<Fact label="Delivery">
|
|
662
|
+
<span data-delivery-fact={plugin.delivery}>
|
|
663
|
+
{deliveries[plugin.delivery].label}
|
|
664
|
+
<span className="text-muted"> · {deliveries[plugin.delivery].updates}</span>
|
|
665
|
+
</span>
|
|
666
|
+
</Fact>
|
|
667
|
+
<Fact label="Kind">
|
|
668
|
+
<span className="capitalize">{plugin.kind ?? 'Unknown'}</span>
|
|
669
|
+
</Fact>
|
|
670
|
+
{plugin.generation !== undefined && (
|
|
671
|
+
<Fact label="Generation">
|
|
672
|
+
<span className="tabular-nums">{plugin.generation}</span>
|
|
673
|
+
</Fact>
|
|
674
|
+
)}
|
|
675
|
+
{openNode && (
|
|
676
|
+
<Fact label="Active on">
|
|
677
|
+
<NodeLinks nodes={plugin.active} open={openNode} />
|
|
678
|
+
</Fact>
|
|
679
|
+
)}
|
|
680
|
+
{openNode && (
|
|
681
|
+
<Fact label="Shown on">
|
|
682
|
+
<NodeLinks nodes={plugin.shown} open={openNode} />
|
|
683
|
+
</Fact>
|
|
684
|
+
)}
|
|
685
|
+
{plugin.manifestError !== undefined && (
|
|
686
|
+
<Fact label="Manifest">
|
|
687
|
+
<span className="text-destructive">{plugin.manifestError}</span>
|
|
688
|
+
</Fact>
|
|
689
|
+
)}
|
|
690
|
+
</dl>
|
|
691
|
+
</Section>
|
|
692
|
+
</div>
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** Agent tools shown before "Show more". */
|
|
697
|
+
const toolsShown = 4;
|
|
698
|
+
type Tab = PageTab;
|
|
699
|
+
/** The Plugins screen's item showing plugin `id` of `slug`'s settings page on its item `item` (by id, as `entryKey`). */
|
|
700
|
+
const pageItem = (slug: string, id: string, item?: string) =>
|
|
701
|
+
`${slug}/${id}/settings${item ? `/${item}` : ''}`;
|
|
702
|
+
/** A plain click: Bridge's rule follows it here, in this window. */
|
|
703
|
+
const plainClick = { metaKey: false, ctrlKey: false, altKey: false, shiftKey: false };
|
|
704
|
+
const tabLabels: Record<Tab, string> = {
|
|
705
|
+
details: 'Details',
|
|
706
|
+
versions: 'Versions',
|
|
707
|
+
info: 'Info',
|
|
708
|
+
dependencies: 'Dependencies',
|
|
709
|
+
docs: 'Docs',
|
|
710
|
+
settings: 'Settings',
|
|
711
|
+
logs: 'Logs',
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
/** The chosen plugin: header with its actions, its failure and the way out, then its tabs (P4). */
|
|
715
|
+
function Detail({
|
|
716
|
+
ctx,
|
|
717
|
+
root,
|
|
718
|
+
plugin,
|
|
719
|
+
usedBy,
|
|
720
|
+
entry,
|
|
721
|
+
catalog,
|
|
722
|
+
read,
|
|
723
|
+
update,
|
|
724
|
+
updating,
|
|
725
|
+
tab: chosen,
|
|
726
|
+
setTab,
|
|
727
|
+
busy,
|
|
728
|
+
locked,
|
|
729
|
+
act,
|
|
730
|
+
catchUp,
|
|
731
|
+
askRemove,
|
|
732
|
+
openPlugin,
|
|
733
|
+
openSettings,
|
|
734
|
+
copy,
|
|
735
|
+
back,
|
|
736
|
+
backLabel = 'All plugins',
|
|
737
|
+
until,
|
|
738
|
+
onLive,
|
|
739
|
+
page,
|
|
740
|
+
openPage,
|
|
741
|
+
}: {
|
|
742
|
+
ctx: Context;
|
|
743
|
+
root: Root;
|
|
744
|
+
plugin: PluginItem;
|
|
745
|
+
until?: string | undefined;
|
|
746
|
+
onLive?: () => void;
|
|
747
|
+
/** Its settings page's own item (`settingsPage`), from the navigation. */
|
|
748
|
+
page?: string | undefined;
|
|
749
|
+
/** Shows its settings page's item `item` in the Settings tab, a navigation entry where the shell is. */
|
|
750
|
+
openPage: (item?: string) => void;
|
|
751
|
+
usedBy: PluginItem[];
|
|
752
|
+
/** Its entry in the marketplace catalog, when it has one: the Details and Versions tabs, and its update. */
|
|
753
|
+
entry: CatalogEntry | undefined;
|
|
754
|
+
/** The marketplace's entries: what could provide a contract that nothing installed does. */
|
|
755
|
+
catalog: CatalogEntry[];
|
|
756
|
+
/** When the catalog was read. */
|
|
757
|
+
read: string | undefined;
|
|
758
|
+
/** Asks to update it to the entry's newer version (the marketplace's approval). */
|
|
759
|
+
update: (entry: CatalogEntry) => void;
|
|
760
|
+
updating: boolean;
|
|
761
|
+
/** The tab the user chose; none yet shows the first of the page. */
|
|
762
|
+
tab: Tab | undefined;
|
|
763
|
+
setTab: (tab: Tab) => void;
|
|
764
|
+
busy: Op | undefined;
|
|
765
|
+
locked: boolean;
|
|
766
|
+
act: (op: Op, plugin: PluginItem) => void;
|
|
767
|
+
/** Updates it to `to`, the version Bridge's update left it behind (its hold lifted, asked first when it must be). */
|
|
768
|
+
catchUp: (plugin: PluginItem, to: string) => void;
|
|
769
|
+
askRemove: (plugin: PluginItem) => void;
|
|
770
|
+
openPlugin: (plugin: PluginItem) => void;
|
|
771
|
+
openSettings: ((key: string, slug: string) => void) | undefined;
|
|
772
|
+
copy: (text: string, what: string) => void;
|
|
773
|
+
back: () => void;
|
|
774
|
+
backLabel?: string;
|
|
775
|
+
}) {
|
|
776
|
+
const name = nameOf(plugin);
|
|
777
|
+
// A replaced one is not installed: its docs, settings and logs (by key) would be the other one's.
|
|
778
|
+
const { tabs, initial } = plugin.replacedBy
|
|
779
|
+
? { tabs: ['info', 'dependencies'] as Tab[], initial: 'info' as const }
|
|
780
|
+
: pageTabs({ installed: true, inCatalog: entry !== undefined });
|
|
781
|
+
// The first tab it showed stays when the catalog lands later (adding Details): the page does not switch under the reader.
|
|
782
|
+
const [first] = React.useState(initial);
|
|
783
|
+
const tab =
|
|
784
|
+
chosen !== undefined && tabs.includes(chosen) ? chosen : tabs.includes(first) ? first : initial;
|
|
785
|
+
const { detail, error: detailError } = useEntryDetail(ctx, root.slug, entry, read);
|
|
786
|
+
const updateTo = entry !== undefined && actionOf(entry) === 'update' ? entry : undefined;
|
|
787
|
+
const { toast } = useToast();
|
|
788
|
+
/** An attention's Retry (`sessions_fallback`'s): its workspace restarted, as the Errors modal does; a refusal says so. */
|
|
789
|
+
const retry = () => {
|
|
790
|
+
const failed = (description: string) =>
|
|
791
|
+
toast({
|
|
792
|
+
variant: 'error',
|
|
793
|
+
title: `${root.label} could not restart`,
|
|
794
|
+
description,
|
|
795
|
+
duration: 8000,
|
|
796
|
+
});
|
|
797
|
+
void ctx.workspace
|
|
798
|
+
.fetch(`/_bridge/workspaces/${encodeURIComponent(root.slug)}/restart`, { method: 'POST' })
|
|
799
|
+
.then(async (res) => {
|
|
800
|
+
if (res.ok) return;
|
|
801
|
+
const failure = await failureOf(res);
|
|
802
|
+
failed([failure.message, failure.hint].filter(Boolean).join(' '));
|
|
803
|
+
})
|
|
804
|
+
.catch((cause: unknown) => failed(cause instanceof Error ? cause.message : String(cause)));
|
|
805
|
+
};
|
|
806
|
+
const lock = lockOf(plugin);
|
|
807
|
+
const own = lock !== undefined;
|
|
808
|
+
const host = root.slug === '_host';
|
|
809
|
+
const problem =
|
|
810
|
+
plugin.state === 'failed' || plugin.state === 'unresolved'
|
|
811
|
+
? (plugin.error ?? plugin.reloadError)
|
|
812
|
+
: (plugin.reloadError ?? plugin.browserError);
|
|
813
|
+
return (
|
|
814
|
+
<article
|
|
815
|
+
aria-label={`${name} details`}
|
|
816
|
+
data-detail={plugin.key}
|
|
817
|
+
data-root={root.slug}
|
|
818
|
+
className="flex flex-col gap-5 px-6 pb-12 pt-4"
|
|
819
|
+
>
|
|
820
|
+
<Button type="button" size="sm" onClick={back} className="-ml-1 w-fit @2xl/pm:hidden">
|
|
821
|
+
<Icon name="arrow-left" size={13} />
|
|
822
|
+
{backLabel}
|
|
823
|
+
</Button>
|
|
824
|
+
<PluginHeader
|
|
825
|
+
icon={<PluginIcon plugin={plugin} size="lg" />}
|
|
826
|
+
title={name}
|
|
827
|
+
titleMark={plugin.official && <OfficialBadge />}
|
|
828
|
+
name={plugin.id}
|
|
829
|
+
version={plugin.version}
|
|
830
|
+
badges={
|
|
831
|
+
<>
|
|
832
|
+
<DeliveryBadge plugin={plugin} />
|
|
833
|
+
{host && (
|
|
834
|
+
<Badge
|
|
835
|
+
data-root-badge
|
|
836
|
+
className="h-4 px-1.5 text-[11px]"
|
|
837
|
+
title="It runs for all of Bridge, every workspace"
|
|
838
|
+
>
|
|
839
|
+
Bridge-wide
|
|
840
|
+
</Badge>
|
|
841
|
+
)}
|
|
842
|
+
{plugin.experimental && <ExperimentalBadge />}
|
|
843
|
+
{plugin.held && <HeldBadge plugin={plugin} />}
|
|
844
|
+
<span aria-hidden="true">·</span>
|
|
845
|
+
<StateMark plugin={plugin} busy={busy} />
|
|
846
|
+
</>
|
|
847
|
+
}
|
|
848
|
+
actions={
|
|
849
|
+
plugin.replacedBy ? (
|
|
850
|
+
<div className="flex flex-wrap items-center justify-end gap-1.5">
|
|
851
|
+
<Button
|
|
852
|
+
size="sm"
|
|
853
|
+
variant="primary"
|
|
854
|
+
data-use-replaced
|
|
855
|
+
disabled={locked}
|
|
856
|
+
onClick={() => {
|
|
857
|
+
// Removing the one in its place brings it back (the host links it again, data kept).
|
|
858
|
+
const other = root.plugins.find(({ id }) => id === plugin.replacedBy!.id);
|
|
859
|
+
if (other) askRemove(other);
|
|
860
|
+
}}
|
|
861
|
+
>
|
|
862
|
+
<Icon name="rotate-ccw" size={13} />
|
|
863
|
+
Use {name}
|
|
864
|
+
</Button>
|
|
865
|
+
</div>
|
|
866
|
+
) : (
|
|
867
|
+
<div className="flex flex-wrap items-center justify-end gap-1.5">
|
|
868
|
+
{updateTo && (
|
|
869
|
+
<Button
|
|
870
|
+
size="sm"
|
|
871
|
+
variant="primary"
|
|
872
|
+
data-plugin-update={updateTo.update}
|
|
873
|
+
disabled={locked || updating}
|
|
874
|
+
onClick={() => update(updateTo)}
|
|
875
|
+
>
|
|
876
|
+
<Icon name="arrow-up" size={13} />
|
|
877
|
+
Update to {updateTo.update}
|
|
878
|
+
</Button>
|
|
879
|
+
)}
|
|
880
|
+
{plugin.held ? (
|
|
881
|
+
<Button
|
|
882
|
+
size="sm"
|
|
883
|
+
variant="outline"
|
|
884
|
+
data-plugin-unhold
|
|
885
|
+
disabled={locked}
|
|
886
|
+
onClick={() => act('unhold', plugin)}
|
|
887
|
+
>
|
|
888
|
+
<Icon name="lock-open" size={13} />
|
|
889
|
+
Lift hold
|
|
890
|
+
</Button>
|
|
891
|
+
) : (
|
|
892
|
+
plugin.previous !== undefined && (
|
|
893
|
+
<Button
|
|
894
|
+
size="sm"
|
|
895
|
+
variant="outline"
|
|
896
|
+
data-plugin-back={plugin.previous}
|
|
897
|
+
title={`Reinstall ${plugin.previous} from its registry, and hold it there`}
|
|
898
|
+
disabled={locked || updating}
|
|
899
|
+
onClick={() => act('back', plugin)}
|
|
900
|
+
>
|
|
901
|
+
<Icon name="undo-2" size={13} />
|
|
902
|
+
Back to {plugin.previous}
|
|
903
|
+
</Button>
|
|
904
|
+
)
|
|
905
|
+
)}
|
|
906
|
+
{plugin.state === 'disabled' ? (
|
|
907
|
+
<Button
|
|
908
|
+
size="sm"
|
|
909
|
+
variant="primary"
|
|
910
|
+
disabled={locked}
|
|
911
|
+
onClick={() => act('enable', plugin)}
|
|
912
|
+
>
|
|
913
|
+
<Icon name="power" size={13} />
|
|
914
|
+
Enable
|
|
915
|
+
</Button>
|
|
916
|
+
) : (
|
|
917
|
+
<Button
|
|
918
|
+
size="sm"
|
|
919
|
+
variant="outline"
|
|
920
|
+
disabled={locked || own}
|
|
921
|
+
onClick={() => act('disable', plugin)}
|
|
922
|
+
>
|
|
923
|
+
<Icon name="power" size={13} />
|
|
924
|
+
Disable
|
|
925
|
+
</Button>
|
|
926
|
+
)}
|
|
927
|
+
<Button
|
|
928
|
+
size="sm"
|
|
929
|
+
variant="outline"
|
|
930
|
+
disabled={locked || plugin.state === 'disabled'}
|
|
931
|
+
onClick={() => act('reload', plugin)}
|
|
932
|
+
>
|
|
933
|
+
<Icon name="rotate-cw" size={13} />
|
|
934
|
+
Reload
|
|
935
|
+
</Button>
|
|
936
|
+
<Button
|
|
937
|
+
size="sm"
|
|
938
|
+
variant="outline"
|
|
939
|
+
disabled={locked || own}
|
|
940
|
+
onClick={() => askRemove(plugin)}
|
|
941
|
+
className="text-destructive hover:bg-destructive-subtle"
|
|
942
|
+
>
|
|
943
|
+
<Icon name="trash" size={13} />
|
|
944
|
+
Uninstall
|
|
945
|
+
</Button>
|
|
946
|
+
</div>
|
|
947
|
+
)
|
|
948
|
+
}
|
|
949
|
+
>
|
|
950
|
+
{own && (
|
|
951
|
+
<p data-own className="mt-1 text-xs text-muted">
|
|
952
|
+
{lock}
|
|
953
|
+
</p>
|
|
954
|
+
)}
|
|
955
|
+
</PluginHeader>
|
|
956
|
+
|
|
957
|
+
{failing(plugin) && (
|
|
958
|
+
<section
|
|
959
|
+
role="alert"
|
|
960
|
+
data-failure
|
|
961
|
+
className="flex gap-3 rounded-default border border-destructive/30 bg-destructive-subtle px-4 py-3"
|
|
962
|
+
>
|
|
963
|
+
<Icon name="triangle-alert" size={16} className="mt-0.5 shrink-0 text-destructive" />
|
|
964
|
+
<div className="flex min-w-0 flex-col gap-1.5">
|
|
965
|
+
<p className="text-sm font-semibold text-destructive">
|
|
966
|
+
{plugin.state === 'unresolved'
|
|
967
|
+
? `${name} is waiting for a service`
|
|
968
|
+
: plugin.stoppedAfterUpdate
|
|
969
|
+
? `${name} stopped working after Bridge's update`
|
|
970
|
+
: plugin.state === 'failed'
|
|
971
|
+
? `${name} failed`
|
|
972
|
+
: `${name} has an error`}
|
|
973
|
+
</p>
|
|
974
|
+
{problem !== undefined && (
|
|
975
|
+
<pre
|
|
976
|
+
data-error
|
|
977
|
+
className="m-0 whitespace-pre-wrap break-words font-mono text-xs leading-5 text-foreground"
|
|
978
|
+
>
|
|
979
|
+
{problem}
|
|
980
|
+
</pre>
|
|
981
|
+
)}
|
|
982
|
+
{plugin.unresolved?.length ? (
|
|
983
|
+
<p className="text-xs text-secondary">
|
|
984
|
+
Waiting for {plugin.unresolved.join(', ')}
|
|
985
|
+
{plugin.blockedBy?.length
|
|
986
|
+
? `, which ${plugin.blockedBy.join(', ')} should provide (failed)`
|
|
987
|
+
: ''}
|
|
988
|
+
.
|
|
989
|
+
</p>
|
|
990
|
+
) : null}
|
|
991
|
+
{plugin.state === 'unresolved' && plugin.unresolved?.length ? (
|
|
992
|
+
<span data-unresolved-fixes className="flex flex-wrap gap-2 pt-1">
|
|
993
|
+
{unresolvedFixes(
|
|
994
|
+
plugin.unresolved,
|
|
995
|
+
root.plugins.map((each) => ({
|
|
996
|
+
id: each.id,
|
|
997
|
+
title: nameOf(each),
|
|
998
|
+
state: each.state,
|
|
999
|
+
implements: each.implements,
|
|
1000
|
+
})),
|
|
1001
|
+
// Nothing is installed into _host from a browser: its repairs only enable (Codex review).
|
|
1002
|
+
host ? [] : catalog,
|
|
1003
|
+
).map((fix) =>
|
|
1004
|
+
fix.kind === 'enable' ? (
|
|
1005
|
+
<Button
|
|
1006
|
+
key={fix.contract}
|
|
1007
|
+
size="sm"
|
|
1008
|
+
variant="primary"
|
|
1009
|
+
data-fix="enable"
|
|
1010
|
+
disabled={locked}
|
|
1011
|
+
onClick={() => {
|
|
1012
|
+
const provider = root.plugins.find((each) => each.id === fix.id);
|
|
1013
|
+
if (provider) act('enable', provider);
|
|
1014
|
+
}}
|
|
1015
|
+
>
|
|
1016
|
+
<Icon name="power" size={12} />
|
|
1017
|
+
Enable {fix.title}
|
|
1018
|
+
</Button>
|
|
1019
|
+
) : fix.kind === 'install' ? (
|
|
1020
|
+
<Button
|
|
1021
|
+
key={fix.contract}
|
|
1022
|
+
size="sm"
|
|
1023
|
+
variant="primary"
|
|
1024
|
+
data-fix="install"
|
|
1025
|
+
disabled={locked || updating}
|
|
1026
|
+
onClick={() => update(fix.entry)}
|
|
1027
|
+
>
|
|
1028
|
+
<Icon name="download" size={12} />
|
|
1029
|
+
Install {fix.entry.title}
|
|
1030
|
+
</Button>
|
|
1031
|
+
) : fix.kind === 'open' ? (
|
|
1032
|
+
<Button
|
|
1033
|
+
key={fix.contract}
|
|
1034
|
+
size="sm"
|
|
1035
|
+
variant="outline"
|
|
1036
|
+
data-fix="open"
|
|
1037
|
+
onClick={() => {
|
|
1038
|
+
const provider = root.plugins.find((each) => each.id === fix.id);
|
|
1039
|
+
if (provider) openPlugin(provider);
|
|
1040
|
+
}}
|
|
1041
|
+
>
|
|
1042
|
+
Open {fix.title}
|
|
1043
|
+
</Button>
|
|
1044
|
+
) : fix.asks !== undefined ? (
|
|
1045
|
+
<span key={fix.contract} data-fix="asks" className="text-xs text-secondary">
|
|
1046
|
+
{fix.asks}
|
|
1047
|
+
</span>
|
|
1048
|
+
) : null,
|
|
1049
|
+
)}
|
|
1050
|
+
</span>
|
|
1051
|
+
) : null}
|
|
1052
|
+
{plugin.hint !== undefined && (
|
|
1053
|
+
<p data-hint className="flex items-center gap-1.5 text-xs font-medium text-secondary">
|
|
1054
|
+
<Icon name="wrench" size={12} />
|
|
1055
|
+
{plugin.hint}
|
|
1056
|
+
</p>
|
|
1057
|
+
)}
|
|
1058
|
+
{plugin.state === 'failed' && (
|
|
1059
|
+
<button
|
|
1060
|
+
type="button"
|
|
1061
|
+
onClick={() => setTab('logs')}
|
|
1062
|
+
className="flex w-fit cursor-pointer items-center gap-1 border-0 bg-transparent p-0 font-[inherit] text-xs font-medium text-accent hover:underline"
|
|
1063
|
+
>
|
|
1064
|
+
<Icon name="scroll-text" size={12} />
|
|
1065
|
+
See its logs
|
|
1066
|
+
</button>
|
|
1067
|
+
)}
|
|
1068
|
+
</div>
|
|
1069
|
+
{/* Research-102 §7.10: one way out, its newer version (a hold lifted). */}
|
|
1070
|
+
{plugin.stoppedAfterUpdate?.update !== undefined && (
|
|
1071
|
+
<Button
|
|
1072
|
+
size="sm"
|
|
1073
|
+
variant="primary"
|
|
1074
|
+
data-plugin-catch-up={plugin.stoppedAfterUpdate.update}
|
|
1075
|
+
disabled={locked || updating}
|
|
1076
|
+
onClick={() => catchUp(plugin, plugin.stoppedAfterUpdate!.update!)}
|
|
1077
|
+
className="ml-auto shrink-0 self-start"
|
|
1078
|
+
>
|
|
1079
|
+
<Icon name="arrow-up" size={13} />
|
|
1080
|
+
Update to {plugin.stoppedAfterUpdate.update}
|
|
1081
|
+
</Button>
|
|
1082
|
+
)}
|
|
1083
|
+
</section>
|
|
1084
|
+
)}
|
|
1085
|
+
|
|
1086
|
+
{plugin.notUpdated && !plugin.stoppedAfterUpdate && (
|
|
1087
|
+
<NotUpdatedNotice
|
|
1088
|
+
plugin={{ ...plugin, notUpdated: plugin.notUpdated }}
|
|
1089
|
+
disabled={locked || updating}
|
|
1090
|
+
update={() => catchUp(plugin, plugin.notUpdated!.to)}
|
|
1091
|
+
/>
|
|
1092
|
+
)}
|
|
1093
|
+
|
|
1094
|
+
{needsSetup(plugin) && plugin.attention && (
|
|
1095
|
+
<SetupNotice
|
|
1096
|
+
name={name}
|
|
1097
|
+
attention={plugin.attention}
|
|
1098
|
+
openSetting={(setting, event) =>
|
|
1099
|
+
ctx.shell.openSetting(root.slug, plugin.key, setting, event)
|
|
1100
|
+
}
|
|
1101
|
+
runAction={(fix) => ctx.shell.runAction(root.slug, plugin.key, fix)}
|
|
1102
|
+
retry={retry}
|
|
1103
|
+
/>
|
|
1104
|
+
)}
|
|
1105
|
+
|
|
1106
|
+
{/* The space between the tabs and their panel is the kit's (its rendering's: a Windows 98 look joins them). */}
|
|
1107
|
+
<Tabs value={tab} onValueChange={(value) => setTab(value as Tab)}>
|
|
1108
|
+
<TabsList aria-label={`${name} details`}>
|
|
1109
|
+
{tabs.map((each) => (
|
|
1110
|
+
<TabsTrigger key={each} value={each} data-tab={each}>
|
|
1111
|
+
{tabLabels[each]}
|
|
1112
|
+
</TabsTrigger>
|
|
1113
|
+
))}
|
|
1114
|
+
</TabsList>
|
|
1115
|
+
<TabsContent value="details">
|
|
1116
|
+
<Readme detail={detail} error={detailError} />
|
|
1117
|
+
</TabsContent>
|
|
1118
|
+
<TabsContent value="info">
|
|
1119
|
+
<Info
|
|
1120
|
+
plugin={plugin}
|
|
1121
|
+
openNode={host ? undefined : (id) => ctx.shell.setNode(id)}
|
|
1122
|
+
openScreen={
|
|
1123
|
+
host ? undefined : (id) => ctx.shell.setScreen({ plugin: plugin.key, id }, 'root')
|
|
1124
|
+
}
|
|
1125
|
+
copy={copy}
|
|
1126
|
+
/>
|
|
1127
|
+
</TabsContent>
|
|
1128
|
+
<TabsContent value="dependencies">
|
|
1129
|
+
<PluginDependencies
|
|
1130
|
+
requires={plugin.requires}
|
|
1131
|
+
implemented={plugin.implements}
|
|
1132
|
+
installed={root.plugins.map((each) => ({
|
|
1133
|
+
id: each.id,
|
|
1134
|
+
title: nameOf(each),
|
|
1135
|
+
implements: each.implements,
|
|
1136
|
+
}))}
|
|
1137
|
+
catalog={catalog}
|
|
1138
|
+
openInstalled={(id) => {
|
|
1139
|
+
const other = root.plugins.find((each) => each.id === id);
|
|
1140
|
+
if (other) openPlugin(other);
|
|
1141
|
+
}}
|
|
1142
|
+
usedBy={usedBy.map((each) => ({
|
|
1143
|
+
id: each.id,
|
|
1144
|
+
key: each.key,
|
|
1145
|
+
title: nameOf(each),
|
|
1146
|
+
icon: each.icon,
|
|
1147
|
+
}))}
|
|
1148
|
+
/>
|
|
1149
|
+
</TabsContent>
|
|
1150
|
+
<TabsContent value="docs">
|
|
1151
|
+
<PluginDocs ctx={ctx} slug={root.slug} plugin={plugin.key} title={name} />
|
|
1152
|
+
</TabsContent>
|
|
1153
|
+
<TabsContent value="settings" className="flex flex-col gap-6">
|
|
1154
|
+
{plugin.settings && (
|
|
1155
|
+
<PluginSettings
|
|
1156
|
+
ctx={ctx}
|
|
1157
|
+
slug={root.slug}
|
|
1158
|
+
plugin={plugin.key}
|
|
1159
|
+
title={name}
|
|
1160
|
+
openSettings={openSettings && (() => openSettings(plugin.key, root.slug))}
|
|
1161
|
+
/>
|
|
1162
|
+
)}
|
|
1163
|
+
{/* Its own page, under its fields (a page made for a pane: a height of its own). */}
|
|
1164
|
+
{plugin.settingsPage && (
|
|
1165
|
+
<div data-settings-page={plugin.key} className="flex h-[70vh] min-h-[420px] flex-col">
|
|
1166
|
+
<SettingsPageOutlet
|
|
1167
|
+
plugin={plugin.key}
|
|
1168
|
+
slug={root.slug}
|
|
1169
|
+
fetch={ctx.workspace.fetch}
|
|
1170
|
+
node="root"
|
|
1171
|
+
item={page}
|
|
1172
|
+
open={openPage}
|
|
1173
|
+
linkTo={(each) => ({ item: pageItem(root.slug, plugin.id, each) })}
|
|
1174
|
+
readOnly={false}
|
|
1175
|
+
/>
|
|
1176
|
+
</div>
|
|
1177
|
+
)}
|
|
1178
|
+
{!plugin.settings && !plugin.settingsPage && (
|
|
1179
|
+
<p role="note" className="text-[13px] text-secondary">
|
|
1180
|
+
{name} has no settings.
|
|
1181
|
+
</p>
|
|
1182
|
+
)}
|
|
1183
|
+
</TabsContent>
|
|
1184
|
+
<TabsContent value="logs">
|
|
1185
|
+
<PluginLogs
|
|
1186
|
+
stream={ctx.workspace.stream}
|
|
1187
|
+
fetch={(path) => ctx.workspace.fetch(path, { cache: 'no-store' })}
|
|
1188
|
+
slug={root.slug}
|
|
1189
|
+
plugin={plugin.key}
|
|
1190
|
+
title={name}
|
|
1191
|
+
until={until}
|
|
1192
|
+
onLive={onLive}
|
|
1193
|
+
onOpenAll={(event) =>
|
|
1194
|
+
ctx.shell.openBridgeLogs(
|
|
1195
|
+
`${encodeURIComponent(root.slug)}/${encodeURIComponent(plugin.key)}`,
|
|
1196
|
+
event,
|
|
1197
|
+
)
|
|
1198
|
+
}
|
|
1199
|
+
/>
|
|
1200
|
+
</TabsContent>
|
|
1201
|
+
<TabsContent value="versions">
|
|
1202
|
+
{entry && (
|
|
1203
|
+
<Versions
|
|
1204
|
+
versions={detail?.versions ?? [entry.version]}
|
|
1205
|
+
latest={entry.version}
|
|
1206
|
+
installed={entry.installed?.version}
|
|
1207
|
+
/>
|
|
1208
|
+
)}
|
|
1209
|
+
</TabsContent>
|
|
1210
|
+
</Tabs>
|
|
1211
|
+
</article>
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/** Install: a folder, a registry spec or a `.tgz`, activated on a node (the workspace by default). */
|
|
1216
|
+
function InstallDialog({
|
|
1217
|
+
open,
|
|
1218
|
+
onOpenChange,
|
|
1219
|
+
nodes,
|
|
1220
|
+
install,
|
|
1221
|
+
}: {
|
|
1222
|
+
open: boolean;
|
|
1223
|
+
onOpenChange: (open: boolean) => void;
|
|
1224
|
+
nodes: { id: string; title: string; depth: number }[];
|
|
1225
|
+
install: (source: string, node: string) => Promise<Failure | undefined>;
|
|
1226
|
+
}) {
|
|
1227
|
+
const [source, setSource] = React.useState('');
|
|
1228
|
+
const [node, setNode] = React.useState('root');
|
|
1229
|
+
const [busy, setBusy] = React.useState(false);
|
|
1230
|
+
const [failure, setFailure] = React.useState<Failure>();
|
|
1231
|
+
React.useEffect(() => {
|
|
1232
|
+
if (open) {
|
|
1233
|
+
setSource('');
|
|
1234
|
+
setNode('root');
|
|
1235
|
+
setFailure(undefined);
|
|
1236
|
+
}
|
|
1237
|
+
}, [open]);
|
|
1238
|
+
const submit = async (event: React.FormEvent) => {
|
|
1239
|
+
event.preventDefault();
|
|
1240
|
+
if (!source.trim() || busy) return;
|
|
1241
|
+
setBusy(true);
|
|
1242
|
+
setFailure(undefined);
|
|
1243
|
+
const failed = await install(source.trim(), node);
|
|
1244
|
+
setBusy(false);
|
|
1245
|
+
if (failed) setFailure(failed);
|
|
1246
|
+
};
|
|
1247
|
+
const items = Object.fromEntries(nodes.map(({ id, title }) => [id, title]));
|
|
1248
|
+
return (
|
|
1249
|
+
<Dialog
|
|
1250
|
+
open={open}
|
|
1251
|
+
onOpenChange={(next) => {
|
|
1252
|
+
if (!busy) onOpenChange(next);
|
|
1253
|
+
}}
|
|
1254
|
+
>
|
|
1255
|
+
<DialogContent aria-label="Install plugin" className="w-[520px]">
|
|
1256
|
+
<form onSubmit={(event) => void submit(event)} className="flex flex-col">
|
|
1257
|
+
<DialogHeader className="px-5 pt-4">
|
|
1258
|
+
<DialogTitle>Install plugin</DialogTitle>
|
|
1259
|
+
</DialogHeader>
|
|
1260
|
+
<DialogBody className="flex flex-col gap-4 pb-5">
|
|
1261
|
+
<DialogDescription className="m-0">
|
|
1262
|
+
Link a plugin folder, or install a package from the registry or a .tgz file.
|
|
1263
|
+
</DialogDescription>
|
|
1264
|
+
<Field invalid={!!failure} className="gap-1.5">
|
|
1265
|
+
<FieldLabel className="text-[13px] font-medium">Source</FieldLabel>
|
|
1266
|
+
<Input
|
|
1267
|
+
variant="outline"
|
|
1268
|
+
autoFocus
|
|
1269
|
+
spellCheck={false}
|
|
1270
|
+
aria-label="Source"
|
|
1271
|
+
placeholder="/path/to/plugin, name@1.0.0 or /path/to/plugin.tgz"
|
|
1272
|
+
className="font-mono text-[13px]"
|
|
1273
|
+
icon={<Icon name="package" size={14} />}
|
|
1274
|
+
disabled={busy}
|
|
1275
|
+
value={source}
|
|
1276
|
+
onChange={(event) => {
|
|
1277
|
+
setSource(event.currentTarget.value);
|
|
1278
|
+
setFailure(undefined);
|
|
1279
|
+
}}
|
|
1280
|
+
/>
|
|
1281
|
+
<FieldDescription className="flex flex-col gap-1 text-xs">
|
|
1282
|
+
<span>
|
|
1283
|
+
A folder is linked: after an edit, reload it. A package is installed with its
|
|
1284
|
+
dependencies.
|
|
1285
|
+
</span>
|
|
1286
|
+
<span className="flex flex-wrap items-center gap-1.5">
|
|
1287
|
+
<span className="text-muted">Examples</span>
|
|
1288
|
+
{['~/code/my-plugin', 'invoices@2.1.0', '~/notes-1.0.0.tgz'].map((example) => (
|
|
1289
|
+
<code
|
|
1290
|
+
key={example}
|
|
1291
|
+
className="rounded-sm bg-hover px-1.5 py-px font-mono text-[11px] text-secondary"
|
|
1292
|
+
>
|
|
1293
|
+
{example}
|
|
1294
|
+
</code>
|
|
1295
|
+
))}
|
|
1296
|
+
</span>
|
|
1297
|
+
</FieldDescription>
|
|
1298
|
+
</Field>
|
|
1299
|
+
<Field className="gap-1.5">
|
|
1300
|
+
<FieldLabel className="text-[13px] font-medium">Activate on</FieldLabel>
|
|
1301
|
+
<Select
|
|
1302
|
+
items={items}
|
|
1303
|
+
value={node}
|
|
1304
|
+
disabled={busy}
|
|
1305
|
+
onValueChange={(value) => {
|
|
1306
|
+
if (typeof value === 'string') setNode(value);
|
|
1307
|
+
}}
|
|
1308
|
+
>
|
|
1309
|
+
<SelectTrigger aria-label="Activate on" className="w-full">
|
|
1310
|
+
<SelectValue />
|
|
1311
|
+
</SelectTrigger>
|
|
1312
|
+
<SelectContent>
|
|
1313
|
+
{nodes.map(({ id, title, depth }) => (
|
|
1314
|
+
<SelectItem key={id} value={id}>
|
|
1315
|
+
<span
|
|
1316
|
+
style={{ paddingLeft: depth * 12 }}
|
|
1317
|
+
className="flex items-center gap-1.5"
|
|
1318
|
+
>
|
|
1319
|
+
<Icon name={id === 'root' ? 'home' : 'folder'} size={13} />
|
|
1320
|
+
{title}
|
|
1321
|
+
</span>
|
|
1322
|
+
</SelectItem>
|
|
1323
|
+
))}
|
|
1324
|
+
</SelectContent>
|
|
1325
|
+
</Select>
|
|
1326
|
+
<FieldDescription className="text-xs">
|
|
1327
|
+
It runs there and below; its view is shown there.
|
|
1328
|
+
</FieldDescription>
|
|
1329
|
+
</Field>
|
|
1330
|
+
{failure && (
|
|
1331
|
+
<div
|
|
1332
|
+
role="alert"
|
|
1333
|
+
data-install-error
|
|
1334
|
+
className="flex gap-2.5 rounded-default border border-destructive/30 bg-destructive-subtle px-3 py-2.5"
|
|
1335
|
+
>
|
|
1336
|
+
<Icon
|
|
1337
|
+
name="triangle-alert"
|
|
1338
|
+
size={15}
|
|
1339
|
+
className="mt-0.5 shrink-0 text-destructive"
|
|
1340
|
+
/>
|
|
1341
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
1342
|
+
<p className="m-0 break-words text-[13px] leading-5 text-destructive">
|
|
1343
|
+
{sentence(failure.message)}
|
|
1344
|
+
</p>
|
|
1345
|
+
{failure.hint && (
|
|
1346
|
+
<p data-hint className="m-0 text-xs leading-5 text-secondary">
|
|
1347
|
+
{failure.hint}
|
|
1348
|
+
</p>
|
|
1349
|
+
)}
|
|
1350
|
+
</div>
|
|
1351
|
+
</div>
|
|
1352
|
+
)}
|
|
1353
|
+
</DialogBody>
|
|
1354
|
+
<DialogFooter className="justify-between gap-2 px-5 py-3">
|
|
1355
|
+
<span role="status" className="flex items-center gap-1.5 text-xs text-secondary">
|
|
1356
|
+
{busy && (
|
|
1357
|
+
<>
|
|
1358
|
+
<Icon
|
|
1359
|
+
name="loader-circle"
|
|
1360
|
+
size={13}
|
|
1361
|
+
className="animate-spin motion-reduce:animate-none"
|
|
1362
|
+
/>
|
|
1363
|
+
Installing and restarting the workspace…
|
|
1364
|
+
</>
|
|
1365
|
+
)}
|
|
1366
|
+
</span>
|
|
1367
|
+
<span className="flex gap-2">
|
|
1368
|
+
<DialogClose render={<Button type="button" variant="outline" disabled={busy} />}>
|
|
1369
|
+
Cancel
|
|
1370
|
+
</DialogClose>
|
|
1371
|
+
<Button type="submit" variant="primary" disabled={busy || !source.trim()}>
|
|
1372
|
+
{busy ? 'Installing…' : 'Install'}
|
|
1373
|
+
</Button>
|
|
1374
|
+
</span>
|
|
1375
|
+
</DialogFooter>
|
|
1376
|
+
</form>
|
|
1377
|
+
</DialogContent>
|
|
1378
|
+
</Dialog>
|
|
1379
|
+
);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
/** Remove: what references its objects (asked first), a warning for Bridge's own plugins; a refusal for the last
|
|
1383
|
+
* implementation of a contract offers to remove it anyway. */
|
|
1384
|
+
function RemoveDialog({
|
|
1385
|
+
plugin,
|
|
1386
|
+
successor,
|
|
1387
|
+
onClose,
|
|
1388
|
+
removal,
|
|
1389
|
+
remove,
|
|
1390
|
+
}: {
|
|
1391
|
+
plugin: PluginItem | undefined;
|
|
1392
|
+
/** The plugin of Bridge's that takes its place (its `replaced` row): Sessions Lite for Sessions. */
|
|
1393
|
+
successor?: PluginItem | undefined;
|
|
1394
|
+
onClose: () => void;
|
|
1395
|
+
removal: (plugin: PluginItem) => Promise<{ warnings: string[]; unchecked?: string }>;
|
|
1396
|
+
remove: (
|
|
1397
|
+
plugin: PluginItem,
|
|
1398
|
+
again: 'force' | 'confirm' | undefined,
|
|
1399
|
+
) => Promise<Failure | undefined>;
|
|
1400
|
+
}) {
|
|
1401
|
+
const [check, setCheck] = React.useState<{ warnings: string[]; unchecked?: string } | 'loading'>(
|
|
1402
|
+
'loading',
|
|
1403
|
+
);
|
|
1404
|
+
const [busy, setBusy] = React.useState(false);
|
|
1405
|
+
const [failure, setFailure] = React.useState<Failure>();
|
|
1406
|
+
React.useEffect(() => {
|
|
1407
|
+
if (!plugin) return;
|
|
1408
|
+
setCheck('loading');
|
|
1409
|
+
setFailure(undefined);
|
|
1410
|
+
let live = true;
|
|
1411
|
+
void removal(plugin).then((result) => {
|
|
1412
|
+
if (live) setCheck(result);
|
|
1413
|
+
});
|
|
1414
|
+
return () => {
|
|
1415
|
+
live = false;
|
|
1416
|
+
};
|
|
1417
|
+
}, [plugin?.id]);
|
|
1418
|
+
if (!plugin) return null;
|
|
1419
|
+
const name = nameOf(plugin);
|
|
1420
|
+
const again =
|
|
1421
|
+
failure?.code === 'needs_force'
|
|
1422
|
+
? 'force'
|
|
1423
|
+
: failure?.code === 'needs_confirm'
|
|
1424
|
+
? 'confirm'
|
|
1425
|
+
: undefined;
|
|
1426
|
+
const confirm = async () => {
|
|
1427
|
+
setBusy(true);
|
|
1428
|
+
const failed = await remove(plugin, again);
|
|
1429
|
+
setBusy(false);
|
|
1430
|
+
if (failed) setFailure(failed);
|
|
1431
|
+
};
|
|
1432
|
+
return (
|
|
1433
|
+
<Dialog
|
|
1434
|
+
open
|
|
1435
|
+
onOpenChange={(open) => {
|
|
1436
|
+
if (!open && !busy) onClose();
|
|
1437
|
+
}}
|
|
1438
|
+
>
|
|
1439
|
+
<DialogContent aria-label={`Remove ${name}`} className="w-[480px]">
|
|
1440
|
+
<DialogHeader className="px-5 pt-4">
|
|
1441
|
+
<DialogTitle>Remove {name}?</DialogTitle>
|
|
1442
|
+
</DialogHeader>
|
|
1443
|
+
<DialogBody className="flex flex-col gap-3 pb-5">
|
|
1444
|
+
<DialogDescription className="m-0 leading-5">
|
|
1445
|
+
{name} is removed from{' '}
|
|
1446
|
+
{plugin.role ? "Bridge's shell, which restarts" : 'this workspace, which restarts'}. Its
|
|
1447
|
+
data stays where it is: installing it again brings it back.
|
|
1448
|
+
{successor && ` ${nameOf(successor)} takes its place, with the same data.`}
|
|
1449
|
+
</DialogDescription>
|
|
1450
|
+
{plugin.system && (
|
|
1451
|
+
<p
|
|
1452
|
+
data-system-warning
|
|
1453
|
+
className="m-0 flex gap-2 rounded-default border border-warning/30 bg-warning-subtle px-3 py-2 text-[13px] leading-5 text-warning-text"
|
|
1454
|
+
>
|
|
1455
|
+
<Icon name="triangle-alert" size={15} className="mt-0.5 shrink-0" />
|
|
1456
|
+
{name} comes with Bridge. Features that rely on it stop working until you install it
|
|
1457
|
+
again.
|
|
1458
|
+
</p>
|
|
1459
|
+
)}
|
|
1460
|
+
{check === 'loading' ? (
|
|
1461
|
+
<p className="m-0 flex items-center gap-2 text-[13px] text-secondary">
|
|
1462
|
+
<Icon
|
|
1463
|
+
name="loader-circle"
|
|
1464
|
+
size={13}
|
|
1465
|
+
className="animate-spin motion-reduce:animate-none"
|
|
1466
|
+
/>
|
|
1467
|
+
Checking what references it…
|
|
1468
|
+
</p>
|
|
1469
|
+
) : check.warnings.length > 0 ? (
|
|
1470
|
+
<div data-referrers className="flex flex-col gap-1.5">
|
|
1471
|
+
<p className="m-0 text-[13px] font-medium text-foreground">
|
|
1472
|
+
Other data references it ({check.warnings.length}):
|
|
1473
|
+
</p>
|
|
1474
|
+
<ul className="m-0 flex max-h-40 list-none flex-col gap-1 overflow-y-auto rounded-default border border-border bg-background p-2 font-mono text-[11px] leading-4 text-secondary">
|
|
1475
|
+
{check.warnings.map((warning) => (
|
|
1476
|
+
<li key={warning} className="break-all">
|
|
1477
|
+
{warning}
|
|
1478
|
+
</li>
|
|
1479
|
+
))}
|
|
1480
|
+
</ul>
|
|
1481
|
+
<p className="m-0 text-xs text-muted">
|
|
1482
|
+
Those references show the owner as missing until it is back.
|
|
1483
|
+
</p>
|
|
1484
|
+
</div>
|
|
1485
|
+
) : check.unchecked !== undefined ? (
|
|
1486
|
+
<p data-referrers className="m-0 flex items-start gap-2 text-[13px] text-warning-text">
|
|
1487
|
+
<Icon name="triangle-alert" size={13} className="mt-1 shrink-0" />
|
|
1488
|
+
What references its data could not be checked: {check.unchecked}. Other data may still
|
|
1489
|
+
point to it.
|
|
1490
|
+
</p>
|
|
1491
|
+
) : (
|
|
1492
|
+
<p data-referrers className="m-0 flex items-center gap-2 text-[13px] text-secondary">
|
|
1493
|
+
<Icon name="check" size={13} className="text-success" />
|
|
1494
|
+
Nothing else references its data.
|
|
1495
|
+
</p>
|
|
1496
|
+
)}
|
|
1497
|
+
{failure && (
|
|
1498
|
+
<div
|
|
1499
|
+
role="alert"
|
|
1500
|
+
className="flex gap-2.5 rounded-default border border-destructive/30 bg-destructive-subtle px-3 py-2.5"
|
|
1501
|
+
>
|
|
1502
|
+
<Icon name="triangle-alert" size={15} className="mt-0.5 shrink-0 text-destructive" />
|
|
1503
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
1504
|
+
<p className="m-0 break-words text-[13px] leading-5 text-destructive">
|
|
1505
|
+
{sentence(failure.message)}
|
|
1506
|
+
</p>
|
|
1507
|
+
{failure.hint && (
|
|
1508
|
+
<p data-hint className="m-0 text-xs leading-5 text-secondary">
|
|
1509
|
+
{failure.hint}
|
|
1510
|
+
</p>
|
|
1511
|
+
)}
|
|
1512
|
+
</div>
|
|
1513
|
+
</div>
|
|
1514
|
+
)}
|
|
1515
|
+
</DialogBody>
|
|
1516
|
+
<DialogFooter className="justify-end gap-2 px-5 py-3">
|
|
1517
|
+
<DialogClose render={<Button variant="outline" disabled={busy} />}>Cancel</DialogClose>
|
|
1518
|
+
<Button
|
|
1519
|
+
variant="primary"
|
|
1520
|
+
disabled={busy || check === 'loading'}
|
|
1521
|
+
onClick={() => void confirm()}
|
|
1522
|
+
className="bg-destructive text-destructive-foreground hover:bg-destructive/90 focus-visible:bg-destructive/90"
|
|
1523
|
+
>
|
|
1524
|
+
{busy && (
|
|
1525
|
+
<Icon
|
|
1526
|
+
name="loader-circle"
|
|
1527
|
+
size={13}
|
|
1528
|
+
className="animate-spin motion-reduce:animate-none"
|
|
1529
|
+
/>
|
|
1530
|
+
)}
|
|
1531
|
+
{busy ? 'Removing…' : again ? 'Remove anyway' : 'Remove'}
|
|
1532
|
+
</Button>
|
|
1533
|
+
</DialogFooter>
|
|
1534
|
+
</DialogContent>
|
|
1535
|
+
</Dialog>
|
|
1536
|
+
);
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/** What the host asked to confirm (its message), with its way back (its hint). */
|
|
1540
|
+
function ConfirmDialog({
|
|
1541
|
+
title,
|
|
1542
|
+
failure,
|
|
1543
|
+
action,
|
|
1544
|
+
onClose,
|
|
1545
|
+
confirm,
|
|
1546
|
+
}: {
|
|
1547
|
+
title: string;
|
|
1548
|
+
failure: Failure;
|
|
1549
|
+
action: string;
|
|
1550
|
+
onClose: () => void;
|
|
1551
|
+
confirm: () => void;
|
|
1552
|
+
}) {
|
|
1553
|
+
return (
|
|
1554
|
+
<Dialog
|
|
1555
|
+
open
|
|
1556
|
+
onOpenChange={(open) => {
|
|
1557
|
+
if (!open) onClose();
|
|
1558
|
+
}}
|
|
1559
|
+
>
|
|
1560
|
+
<DialogContent aria-label={title} className="w-[440px]">
|
|
1561
|
+
<DialogHeader className="px-5 pt-4">
|
|
1562
|
+
<DialogTitle>{title}</DialogTitle>
|
|
1563
|
+
</DialogHeader>
|
|
1564
|
+
<DialogBody className="flex flex-col gap-2 pb-5">
|
|
1565
|
+
<DialogDescription className="m-0 leading-5">
|
|
1566
|
+
{sentence(failure.message)}.
|
|
1567
|
+
</DialogDescription>
|
|
1568
|
+
{failure.hint && (
|
|
1569
|
+
<p data-hint className="m-0 text-xs leading-5 text-secondary">
|
|
1570
|
+
{failure.hint}
|
|
1571
|
+
</p>
|
|
1572
|
+
)}
|
|
1573
|
+
</DialogBody>
|
|
1574
|
+
<DialogFooter className="justify-end gap-2 px-5 py-3">
|
|
1575
|
+
<DialogClose render={<Button variant="outline" />}>Cancel</DialogClose>
|
|
1576
|
+
<Button
|
|
1577
|
+
variant="primary"
|
|
1578
|
+
onClick={confirm}
|
|
1579
|
+
className="bg-destructive text-destructive-foreground hover:bg-destructive/90 focus-visible:bg-destructive/90"
|
|
1580
|
+
>
|
|
1581
|
+
{action}
|
|
1582
|
+
</Button>
|
|
1583
|
+
</DialogFooter>
|
|
1584
|
+
</DialogContent>
|
|
1585
|
+
</Dialog>
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
/** The tree's rows, each plugin selectable; a repeat dimmed, a missing contract red. */
|
|
1590
|
+
function DependencyRows({
|
|
1591
|
+
nodes,
|
|
1592
|
+
depth,
|
|
1593
|
+
selected,
|
|
1594
|
+
select,
|
|
1595
|
+
expanded,
|
|
1596
|
+
toggle,
|
|
1597
|
+
}: {
|
|
1598
|
+
nodes: DependencyNode[];
|
|
1599
|
+
depth: number;
|
|
1600
|
+
selected: string | undefined;
|
|
1601
|
+
select: (root: Root, plugin: PluginItem) => void;
|
|
1602
|
+
expanded: (key: string, depth: number) => boolean;
|
|
1603
|
+
toggle: (key: string, open: boolean) => void;
|
|
1604
|
+
}) {
|
|
1605
|
+
return nodes.map((node) => {
|
|
1606
|
+
if (!node.plugin) {
|
|
1607
|
+
return (
|
|
1608
|
+
<SidebarTreeItem
|
|
1609
|
+
key={node.key}
|
|
1610
|
+
data-missing={node.contract}
|
|
1611
|
+
label={node.contract!}
|
|
1612
|
+
depth={depth}
|
|
1613
|
+
icon={<Icon name="triangle-alert" size={14} className="text-destructive" />}
|
|
1614
|
+
trailing={<span className="text-destructive">Missing</span>}
|
|
1615
|
+
className="font-mono text-xs text-destructive"
|
|
1616
|
+
/>
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
const plugin = node.plugin;
|
|
1620
|
+
const open = node.children.length > 0 ? expanded(node.key, depth) : undefined;
|
|
1621
|
+
return (
|
|
1622
|
+
<SidebarTreeItem
|
|
1623
|
+
key={node.key}
|
|
1624
|
+
data-dependency={plugin.key}
|
|
1625
|
+
data-repeat={node.repeat || undefined}
|
|
1626
|
+
label={nameOf(plugin)}
|
|
1627
|
+
depth={depth}
|
|
1628
|
+
active={!node.repeat && selected === entryKey(node.root.slug, plugin)}
|
|
1629
|
+
icon={<Icon name={plugin.icon ?? kindIcon[plugin.kind ?? ''] ?? 'package'} size={14} />}
|
|
1630
|
+
className={cn(node.repeat && 'opacity-60')}
|
|
1631
|
+
trailing={
|
|
1632
|
+
<span className="flex items-center gap-1.5">
|
|
1633
|
+
{node.via && <span className="font-mono text-[10px] text-muted">{node.via}</span>}
|
|
1634
|
+
<span
|
|
1635
|
+
aria-label={stateLabel(plugin)}
|
|
1636
|
+
className={cn(
|
|
1637
|
+
'size-1.5 shrink-0 rounded-full',
|
|
1638
|
+
plugin.state === 'failed'
|
|
1639
|
+
? 'bg-destructive'
|
|
1640
|
+
: failing(plugin) || needsSetup(plugin)
|
|
1641
|
+
? 'bg-warning'
|
|
1642
|
+
: plugin.state === 'disabled'
|
|
1643
|
+
? 'border border-muted'
|
|
1644
|
+
: 'bg-success',
|
|
1645
|
+
)}
|
|
1646
|
+
/>
|
|
1647
|
+
</span>
|
|
1648
|
+
}
|
|
1649
|
+
{...(open !== undefined && {
|
|
1650
|
+
expanded: open,
|
|
1651
|
+
onExpandedChange: (next: boolean) => toggle(node.key, next),
|
|
1652
|
+
})}
|
|
1653
|
+
onSelect={() => select(node.root, plugin)}
|
|
1654
|
+
>
|
|
1655
|
+
{open && (
|
|
1656
|
+
<DependencyRows
|
|
1657
|
+
nodes={node.children}
|
|
1658
|
+
depth={depth + 1}
|
|
1659
|
+
selected={selected}
|
|
1660
|
+
select={select}
|
|
1661
|
+
expanded={expanded}
|
|
1662
|
+
toggle={toggle}
|
|
1663
|
+
/>
|
|
1664
|
+
)}
|
|
1665
|
+
</SidebarTreeItem>
|
|
1666
|
+
);
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
/** The Plugins screen (research-027 P1 to P4, P10): a sidebar listing the plugins by name, by domain or as their
|
|
1671
|
+
* dependency tree, one search over the three, beside the chosen plugin's details and tabs. In Admin it shows Bridge's
|
|
1672
|
+
* own plugins (`_host`, "System") above the workspace's: for the user the two are one place, the difference shown.
|
|
1673
|
+
* `openSettings`: the Settings screen on a plugin of a root (`_host` in Admin). */
|
|
1674
|
+
export function PluginsScreen({
|
|
1675
|
+
ctx,
|
|
1676
|
+
item,
|
|
1677
|
+
openSettings,
|
|
1678
|
+
}: {
|
|
1679
|
+
ctx: Context;
|
|
1680
|
+
/** Its window's item (research-048: a window beside has its own), not the focused window's. */
|
|
1681
|
+
item?: string | undefined;
|
|
1682
|
+
openSettings?: (key: string, slug: string) => void;
|
|
1683
|
+
}) {
|
|
1684
|
+
const { workspace, nodes } = ctx;
|
|
1685
|
+
const { toast } = useToast();
|
|
1686
|
+
const own = workspace.slug;
|
|
1687
|
+
/** The roots shown: Admin's Bridge (`_host`) and Workspace, else this workspace alone. */
|
|
1688
|
+
const slugs = React.useMemo(() => (own === 'admin' ? ['_host', own] : [own]), [own]);
|
|
1689
|
+
const labels: Record<string, string> = { _host: 'Bridge', [own]: 'Workspace' };
|
|
1690
|
+
const [lists, setLists] = React.useState<Record<string, PluginsList>>({});
|
|
1691
|
+
const [loadError, setLoadError] = React.useState('');
|
|
1692
|
+
const [query, setQuery] = React.useState('');
|
|
1693
|
+
const [filter, setFilter] = React.useState<Filter>('all');
|
|
1694
|
+
const remembered = (key: string) => {
|
|
1695
|
+
try {
|
|
1696
|
+
return sessionStorage.getItem(key) ?? undefined;
|
|
1697
|
+
} catch {
|
|
1698
|
+
return undefined;
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
const remember = (key: string, value: string | undefined) => {
|
|
1702
|
+
try {
|
|
1703
|
+
if (value === undefined) sessionStorage.removeItem(key);
|
|
1704
|
+
else sessionStorage.setItem(key, value);
|
|
1705
|
+
} catch {
|
|
1706
|
+
/* this view only */
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
const modeKey = `bridge.plugins.mode.${own}`;
|
|
1710
|
+
const [mode, setModeState] = React.useState<Mode>(
|
|
1711
|
+
() => modes.find(({ value }) => value === remembered(modeKey))?.value ?? 'name',
|
|
1712
|
+
);
|
|
1713
|
+
const setMode = (next: Mode) => {
|
|
1714
|
+
setModeState(next);
|
|
1715
|
+
remember(modeKey, next);
|
|
1716
|
+
};
|
|
1717
|
+
/** Installed plugins, or the Marketplace (research-043): `_host` has no marketplace, nothing installs there. */
|
|
1718
|
+
const viewKey = `bridge.plugins.view.${own}`;
|
|
1719
|
+
const [view, setViewState] = React.useState<'installed' | 'marketplace'>(() =>
|
|
1720
|
+
own !== '_host' && remembered(viewKey) === 'marketplace' ? 'marketplace' : 'installed',
|
|
1721
|
+
);
|
|
1722
|
+
const setView = (next: 'installed' | 'marketplace') => {
|
|
1723
|
+
setViewState(next);
|
|
1724
|
+
remember(viewKey, next);
|
|
1725
|
+
};
|
|
1726
|
+
/** The plugin shown, by root and id (`storage` is in both of Admin's roots); kept across a remount for this page. */
|
|
1727
|
+
const selectedKey = `bridge.plugins.selected.${own}`;
|
|
1728
|
+
const [selected, setSelectedState] = React.useState<string | undefined>(() =>
|
|
1729
|
+
remembered(selectedKey),
|
|
1730
|
+
);
|
|
1731
|
+
const setSelected = (key: string | undefined) => {
|
|
1732
|
+
setSelectedState(key);
|
|
1733
|
+
remember(selectedKey, key);
|
|
1734
|
+
};
|
|
1735
|
+
const [tab, setTab] = React.useState<Tab>();
|
|
1736
|
+
/** The Logs tab's end (an ISO time), when the navigation opened it on a Health episode's last sighting. */
|
|
1737
|
+
const [until, setUntil] = React.useState<string>();
|
|
1738
|
+
/** The settings page's own item (`…/settings/<item>`), when the navigation opened its Settings tab on one. */
|
|
1739
|
+
const [settingsItem, setSettingsItem] = React.useState<string>();
|
|
1740
|
+
const follow = useFollow();
|
|
1741
|
+
// A navigation item `<root>/<plugin>` (a row's ⌘-click, research-048): that plugin; `…/logs[/<time>]` (Health's
|
|
1742
|
+
// Logs, research-047): its Logs tab.
|
|
1743
|
+
React.useEffect(() => {
|
|
1744
|
+
const opening = pluginOpening(item);
|
|
1745
|
+
if (!opening) return;
|
|
1746
|
+
setSelected(opening.key);
|
|
1747
|
+
setTab(opening.tab);
|
|
1748
|
+
setUntil(opening.until);
|
|
1749
|
+
setSettingsItem(opening.page);
|
|
1750
|
+
}, [item]);
|
|
1751
|
+
const [opened, setOpened] = React.useState<Record<string, boolean>>({});
|
|
1752
|
+
const [running, setRunning] = React.useState<{ op: Op; key?: string }>();
|
|
1753
|
+
const [installing, setInstalling] = React.useState(false);
|
|
1754
|
+
const [updatingAll, setUpdatingAll] = React.useState(false);
|
|
1755
|
+
const [removing, setRemoving] = React.useState<{ root: Root; plugin: PluginItem }>();
|
|
1756
|
+
const [confirming, setConfirming] = React.useState<{
|
|
1757
|
+
root: Root;
|
|
1758
|
+
plugin: PluginItem;
|
|
1759
|
+
failure: Failure;
|
|
1760
|
+
}>();
|
|
1761
|
+
/** An update Bridge's update left that asks first (`updateQuestion`). */
|
|
1762
|
+
const [askingUpdate, setAskingUpdate] = React.useState<{
|
|
1763
|
+
root: Root;
|
|
1764
|
+
plugin: PluginItem;
|
|
1765
|
+
to: string;
|
|
1766
|
+
failure: Failure;
|
|
1767
|
+
}>();
|
|
1768
|
+
const search = React.useRef<HTMLInputElement>(null);
|
|
1769
|
+
const baseOf = (slug: string) => `/_bridge/workspaces/${encodeURIComponent(slug)}/plugins`;
|
|
1770
|
+
|
|
1771
|
+
const loadOne = React.useCallback(
|
|
1772
|
+
(slug: string) =>
|
|
1773
|
+
workspace
|
|
1774
|
+
.fetch(baseOf(slug), { cache: 'no-store' })
|
|
1775
|
+
.then(readJson)
|
|
1776
|
+
.then((body) => body as PluginsList)
|
|
1777
|
+
.then(
|
|
1778
|
+
(body: PluginsList) => {
|
|
1779
|
+
setLists((was) => ({ ...was, [slug]: body }));
|
|
1780
|
+
setLoadError('');
|
|
1781
|
+
return body;
|
|
1782
|
+
},
|
|
1783
|
+
(cause: Error) => {
|
|
1784
|
+
if (cause.name !== 'AbortError') setLoadError(cause.message);
|
|
1785
|
+
return undefined;
|
|
1786
|
+
},
|
|
1787
|
+
),
|
|
1788
|
+
[],
|
|
1789
|
+
);
|
|
1790
|
+
const load = React.useCallback(() => Promise.all(slugs.map(loadOne)), [slugs, loadOne]);
|
|
1791
|
+
React.useEffect(() => {
|
|
1792
|
+
void load();
|
|
1793
|
+
}, [load]);
|
|
1794
|
+
// Live: the host's status events for these workspaces (a plugin's state, a restart), coalesced per workspace.
|
|
1795
|
+
React.useEffect(() => {
|
|
1796
|
+
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
1797
|
+
const unsubscribe = ctx.hostStatus.subscribe((event) => {
|
|
1798
|
+
if (event.event === 'snapshot') return void load();
|
|
1799
|
+
if (event.event === 'code' || event.event === 'page') return;
|
|
1800
|
+
const of = event.event === 'nodes' ? event.data.workspace : event.data.slug;
|
|
1801
|
+
if (!slugs.includes(of)) return;
|
|
1802
|
+
clearTimeout(timers.get(of));
|
|
1803
|
+
timers.set(
|
|
1804
|
+
of,
|
|
1805
|
+
setTimeout(() => void loadOne(of), 150),
|
|
1806
|
+
);
|
|
1807
|
+
});
|
|
1808
|
+
return () => {
|
|
1809
|
+
for (const timer of timers.values()) clearTimeout(timer);
|
|
1810
|
+
unsubscribe();
|
|
1811
|
+
};
|
|
1812
|
+
}, [load, loadOne, slugs]);
|
|
1813
|
+
|
|
1814
|
+
// The marketplace's catalog and its approval serve both tabs: a plugin's page reads its README, versions and update there.
|
|
1815
|
+
const [listWidth, setListWidth] = useListWidth();
|
|
1816
|
+
const market = useCatalog(ctx, own, lists[own], own !== '_host');
|
|
1817
|
+
const approval = useApproval(
|
|
1818
|
+
ctx,
|
|
1819
|
+
own,
|
|
1820
|
+
market,
|
|
1821
|
+
() => void loadOne(own),
|
|
1822
|
+
() =>
|
|
1823
|
+
(lists[own]?.plugins ?? []).map((each) => ({
|
|
1824
|
+
id: each.id,
|
|
1825
|
+
key: each.key,
|
|
1826
|
+
title: nameOf(each),
|
|
1827
|
+
state: each.state,
|
|
1828
|
+
implements: each.implements,
|
|
1829
|
+
})),
|
|
1830
|
+
);
|
|
1831
|
+
|
|
1832
|
+
// Update all (#491): the workspace's updates in its catalog, and those a hold keeps back (`_host` has no catalog).
|
|
1833
|
+
const updates = (market.catalog?.entries ?? []).filter(
|
|
1834
|
+
(entry) => entry.update !== undefined || entry.held,
|
|
1835
|
+
);
|
|
1836
|
+
const offered = updates.filter((entry) => entry.update !== undefined).length;
|
|
1837
|
+
const roots: Root[] = slugs.flatMap((slug) =>
|
|
1838
|
+
lists[slug] ? [{ slug, label: labels[slug]!, plugins: lists[slug]!.plugins }] : [],
|
|
1839
|
+
);
|
|
1840
|
+
// Each root's rows: its plugins, then the plugins of Bridge's they replace (greyed, `replacedBy`).
|
|
1841
|
+
const rowsIn = (root: Root) => [...root.plugins, ...(lists[root.slug]?.replaced ?? [])];
|
|
1842
|
+
const everything = roots.flatMap((root) => rowsIn(root).map((plugin) => ({ root, plugin })));
|
|
1843
|
+
const successorOf = (removing: { root: Root; plugin: PluginItem } | undefined) =>
|
|
1844
|
+
removing &&
|
|
1845
|
+
lists[removing.root.slug]?.replaced?.find(
|
|
1846
|
+
({ replacedBy }) => replacedBy?.id === removing.plugin.id,
|
|
1847
|
+
);
|
|
1848
|
+
const current = everything.find(({ root, plugin }) => entryKey(root.slug, plugin) === selected);
|
|
1849
|
+
const count = counts(everything.map(({ plugin }) => plugin));
|
|
1850
|
+
// What is installed: a replaced plugin of Bridge's is listed, not installed.
|
|
1851
|
+
const installed = roots.reduce((sum, root) => sum + root.plugins.length, 0);
|
|
1852
|
+
const safe = Object.values(lists).some((list) => list.safe);
|
|
1853
|
+
const locked = running !== undefined || safe;
|
|
1854
|
+
const listed =
|
|
1855
|
+
mode === 'dependencies'
|
|
1856
|
+
? []
|
|
1857
|
+
: groups(
|
|
1858
|
+
roots.map((root) => ({ ...root, plugins: rowsIn(root) })),
|
|
1859
|
+
mode,
|
|
1860
|
+
query,
|
|
1861
|
+
filter,
|
|
1862
|
+
);
|
|
1863
|
+
const trees =
|
|
1864
|
+
mode === 'dependencies'
|
|
1865
|
+
? roots
|
|
1866
|
+
.map((root) => ({ root, nodes: pruneTree(dependencyTree(root, roots), query, filter) }))
|
|
1867
|
+
.filter(({ nodes: shown }) => shown.length > 0)
|
|
1868
|
+
: [];
|
|
1869
|
+
const found =
|
|
1870
|
+
mode === 'dependencies'
|
|
1871
|
+
? trees.length
|
|
1872
|
+
: listed.reduce((sum, group) => sum + group.entries.length, 0);
|
|
1873
|
+
const searching = query.trim() !== '' || filter !== 'all';
|
|
1874
|
+
const select = (root: Root, plugin: PluginItem) => {
|
|
1875
|
+
setUntil(undefined);
|
|
1876
|
+
setSelected(entryKey(root.slug, plugin));
|
|
1877
|
+
};
|
|
1878
|
+
/** The plugins of `root` requiring a contract `plugin` implements: Used by. */
|
|
1879
|
+
const usedBy = (root: Root, plugin: PluginItem) =>
|
|
1880
|
+
root.plugins.filter((each) =>
|
|
1881
|
+
each.requires.some((contract) => plugin.implements.includes(contract)),
|
|
1882
|
+
);
|
|
1883
|
+
|
|
1884
|
+
const rootOf = (plugin: PluginItem) => everything.find((each) => each.plugin === plugin)?.root;
|
|
1885
|
+
const act = async (op: Op, plugin: PluginItem, confirmed = false, confirmedRoot?: Root) => {
|
|
1886
|
+
// A list refresh replaces plugin objects while the confirmation is open. Keep its workspace.
|
|
1887
|
+
const root = confirmedRoot ?? rootOf(plugin);
|
|
1888
|
+
if (running || !root) return;
|
|
1889
|
+
const key = entryKey(root.slug, plugin);
|
|
1890
|
+
setRunning({ op, key });
|
|
1891
|
+
try {
|
|
1892
|
+
const res = await workspace.fetch(
|
|
1893
|
+
`${baseOf(root.slug)}/${encodeURIComponent(plugin.key)}/${op}${confirmed ? '?confirm=true' : ''}`,
|
|
1894
|
+
{ method: 'POST' },
|
|
1895
|
+
);
|
|
1896
|
+
if (!res.ok) {
|
|
1897
|
+
const failed = await failureOf(res);
|
|
1898
|
+
if (failed.code === 'needs_confirm')
|
|
1899
|
+
return setConfirming({ root, plugin, failure: failed });
|
|
1900
|
+
toast({
|
|
1901
|
+
variant: 'error',
|
|
1902
|
+
title: `${nameOf(plugin)} ${undone[op]}`,
|
|
1903
|
+
description: [failed.message, failed.hint].filter(Boolean).join(' '),
|
|
1904
|
+
duration: 8000,
|
|
1905
|
+
});
|
|
1906
|
+
} else if (op === 'reload') {
|
|
1907
|
+
const { restarted, warning } = (await readJson(res)) as {
|
|
1908
|
+
restarted?: boolean;
|
|
1909
|
+
warning?: string;
|
|
1910
|
+
};
|
|
1911
|
+
// Reloaded all the same; the previous version's failed cleanup is said, it may have left a timer or a file open.
|
|
1912
|
+
toast({
|
|
1913
|
+
variant: warning ? 'warning' : 'success',
|
|
1914
|
+
title: `${nameOf(plugin)} reloaded`,
|
|
1915
|
+
...(restarted && { description: 'The workspace restarted to start it again.' }),
|
|
1916
|
+
...(warning && {
|
|
1917
|
+
description: `${warning[0]!.toUpperCase()}${warning.slice(1)}.`,
|
|
1918
|
+
duration: 8000,
|
|
1919
|
+
}),
|
|
1920
|
+
});
|
|
1921
|
+
} else if (op === 'enable') toast({ variant: 'success', title: `${nameOf(plugin)} enabled` });
|
|
1922
|
+
else if (op === 'back') {
|
|
1923
|
+
const { waiting } = (await readJson(res)) as { waiting?: true };
|
|
1924
|
+
toast(
|
|
1925
|
+
waiting
|
|
1926
|
+
? {
|
|
1927
|
+
variant: 'info',
|
|
1928
|
+
title: `${nameOf(plugin)} ${plugin.previous} is reinstalled from its registry once the running turns end`,
|
|
1929
|
+
}
|
|
1930
|
+
: {
|
|
1931
|
+
variant: 'success',
|
|
1932
|
+
title: `${nameOf(plugin)} ${plugin.previous} reinstalled from its registry`,
|
|
1933
|
+
description: 'Held there: no update until you lift the hold.',
|
|
1934
|
+
},
|
|
1935
|
+
);
|
|
1936
|
+
} else if (op === 'unhold')
|
|
1937
|
+
toast({ variant: 'success', title: `${nameOf(plugin)}'s updates are offered again` });
|
|
1938
|
+
} catch (cause) {
|
|
1939
|
+
toast({
|
|
1940
|
+
variant: 'error',
|
|
1941
|
+
title: `${nameOf(plugin)}: ${op} failed`,
|
|
1942
|
+
description: (cause as Error).message,
|
|
1943
|
+
});
|
|
1944
|
+
} finally {
|
|
1945
|
+
setRunning(undefined);
|
|
1946
|
+
void loadOne(root.slug);
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
/** Updates `plugin` to `to`, the version Bridge's update left it behind (research-102 rule 6b, §7.10): an external
|
|
1950
|
+
* plugin or a change of data asked first (`updateQuestion`), its hold lifted, then installed as an update is. */
|
|
1951
|
+
const catchUp = async (
|
|
1952
|
+
plugin: PluginItem,
|
|
1953
|
+
to: string,
|
|
1954
|
+
confirmed = false,
|
|
1955
|
+
confirmedRoot?: Root,
|
|
1956
|
+
) => {
|
|
1957
|
+
const root = confirmedRoot ?? rootOf(plugin);
|
|
1958
|
+
if (running || !root) return;
|
|
1959
|
+
const question = updateQuestion(plugin, to);
|
|
1960
|
+
if (question && !confirmed) return setAskingUpdate({ root, plugin, to, failure: question });
|
|
1961
|
+
setRunning({ op: 'update', key: entryKey(root.slug, plugin) });
|
|
1962
|
+
const failed = (failure: Failure) =>
|
|
1963
|
+
toast({
|
|
1964
|
+
variant: 'error',
|
|
1965
|
+
title: `${nameOf(plugin)} ${undone.update}`,
|
|
1966
|
+
description: [failure.message, failure.hint].filter(Boolean).join(' '),
|
|
1967
|
+
duration: 8000,
|
|
1968
|
+
});
|
|
1969
|
+
try {
|
|
1970
|
+
if (plugin.held) {
|
|
1971
|
+
const lifted = await workspace.fetch(
|
|
1972
|
+
`${baseOf(root.slug)}/${encodeURIComponent(plugin.key)}/unhold`,
|
|
1973
|
+
{ method: 'POST' },
|
|
1974
|
+
);
|
|
1975
|
+
if (!lifted.ok) return failed(await failureOf(lifted));
|
|
1976
|
+
}
|
|
1977
|
+
const res = await workspace.fetch(`${baseOf(root.slug)}/install`, {
|
|
1978
|
+
method: 'POST',
|
|
1979
|
+
headers: { 'content-type': 'application/json' },
|
|
1980
|
+
body: JSON.stringify({ source: `${plugin.id}@${to}`, update: true }),
|
|
1981
|
+
});
|
|
1982
|
+
if (!res.ok) return failed(await failureOf(res));
|
|
1983
|
+
const { waiting, warning } = (await readJson(res)) as { waiting?: true; warning?: string };
|
|
1984
|
+
toast({
|
|
1985
|
+
variant: waiting ? 'info' : 'success',
|
|
1986
|
+
title: waiting
|
|
1987
|
+
? `${nameOf(plugin)} updates once the running sessions finish`
|
|
1988
|
+
: `${nameOf(plugin)} updated to ${to}`,
|
|
1989
|
+
...(warning !== undefined && { description: warning }),
|
|
1990
|
+
});
|
|
1991
|
+
} catch (cause) {
|
|
1992
|
+
failed({ message: (cause as Error).message });
|
|
1993
|
+
} finally {
|
|
1994
|
+
setRunning(undefined);
|
|
1995
|
+
void loadOne(root.slug);
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
const install = async (source: string, node: string): Promise<Failure | undefined> => {
|
|
1999
|
+
setRunning({ op: 'install' });
|
|
2000
|
+
try {
|
|
2001
|
+
const res = await workspace.fetch(`${baseOf(own)}/install`, {
|
|
2002
|
+
method: 'POST',
|
|
2003
|
+
headers: { 'content-type': 'application/json' },
|
|
2004
|
+
body: JSON.stringify({ source, ...(node !== 'root' && { node }) }),
|
|
2005
|
+
});
|
|
2006
|
+
if (!res.ok) return await failureOf(res);
|
|
2007
|
+
const { plugin, warning, pendingRestart } = (await readJson(res)) as {
|
|
2008
|
+
plugin: string;
|
|
2009
|
+
warning?: string;
|
|
2010
|
+
pendingRestart?: string;
|
|
2011
|
+
};
|
|
2012
|
+
const listedNow = (await loadOne(own))?.plugins.find(({ id }) => id === plugin);
|
|
2013
|
+
setInstalling(false);
|
|
2014
|
+
setQuery('');
|
|
2015
|
+
setFilter('all');
|
|
2016
|
+
if (!pendingRestart) {
|
|
2017
|
+
setSelected(`${own}/${plugin}`);
|
|
2018
|
+
setTab(undefined);
|
|
2019
|
+
}
|
|
2020
|
+
toast({
|
|
2021
|
+
variant: pendingRestart ? 'info' : 'success',
|
|
2022
|
+
title: pendingRestart
|
|
2023
|
+
? `${nameOf(listedNow ?? { id: plugin })} prepared, awaiting approval`
|
|
2024
|
+
: `${nameOf(listedNow ?? { id: plugin })} installed`,
|
|
2025
|
+
...(warning !== undefined && { description: warning }),
|
|
2026
|
+
});
|
|
2027
|
+
return undefined;
|
|
2028
|
+
} catch (cause) {
|
|
2029
|
+
return { message: (cause as Error).message };
|
|
2030
|
+
} finally {
|
|
2031
|
+
setRunning(undefined);
|
|
2032
|
+
}
|
|
2033
|
+
};
|
|
2034
|
+
const removal = async (plugin: PluginItem) => {
|
|
2035
|
+
const root = removing?.root ?? rootOf(plugin);
|
|
2036
|
+
try {
|
|
2037
|
+
const res = await workspace.fetch(
|
|
2038
|
+
`${baseOf(root?.slug ?? own)}/${encodeURIComponent(plugin.key)}/removal`,
|
|
2039
|
+
{ cache: 'no-store' },
|
|
2040
|
+
);
|
|
2041
|
+
if (res.ok) return (await readJson(res)) as { warnings: string[]; unchecked?: string };
|
|
2042
|
+
return { warnings: [], unchecked: (await failureOf(res)).message };
|
|
2043
|
+
} catch (cause) {
|
|
2044
|
+
return { warnings: [], unchecked: (cause as Error).message };
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
const remove = async (
|
|
2048
|
+
plugin: PluginItem,
|
|
2049
|
+
again: 'force' | 'confirm' | undefined,
|
|
2050
|
+
): Promise<Failure | undefined> => {
|
|
2051
|
+
const root = removing?.root ?? rootOf(plugin);
|
|
2052
|
+
if (!root) return { message: 'This plugin is no longer listed' };
|
|
2053
|
+
const key = entryKey(root.slug, plugin);
|
|
2054
|
+
setRunning({ op: 'remove', key });
|
|
2055
|
+
try {
|
|
2056
|
+
const res = await workspace.fetch(
|
|
2057
|
+
`${baseOf(root.slug)}/${encodeURIComponent(plugin.key)}${again ? `?${again}=true` : ''}`,
|
|
2058
|
+
{ method: 'DELETE' },
|
|
2059
|
+
);
|
|
2060
|
+
if (!res.ok) return await failureOf(res);
|
|
2061
|
+
setRemoving(undefined);
|
|
2062
|
+
if (selected === key) setSelected(undefined);
|
|
2063
|
+
await loadOne(root.slug);
|
|
2064
|
+
return undefined;
|
|
2065
|
+
} catch (cause) {
|
|
2066
|
+
return { message: (cause as Error).message };
|
|
2067
|
+
} finally {
|
|
2068
|
+
setRunning(undefined);
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
const askRemove = (plugin: PluginItem) => {
|
|
2072
|
+
const root = rootOf(plugin);
|
|
2073
|
+
if (root) setRemoving({ root, plugin });
|
|
2074
|
+
};
|
|
2075
|
+
const copy = (text: string, what: string) => {
|
|
2076
|
+
void copyText(text).then(
|
|
2077
|
+
() => toast({ variant: 'success', title: `${what} copied` }),
|
|
2078
|
+
() => toast({ variant: 'error', title: 'The clipboard is not available here' }),
|
|
2079
|
+
);
|
|
2080
|
+
};
|
|
2081
|
+
// The tree, workspace first, each node under its parent (archived ones left out), for "Activate on".
|
|
2082
|
+
const tree = React.useSyncExternalStore(nodes.subscribe, () => nodes.revision);
|
|
2083
|
+
const targets = React.useMemo(() => {
|
|
2084
|
+
const all = nodes.list();
|
|
2085
|
+
const out: { id: string; title: string; depth: number }[] = [];
|
|
2086
|
+
const walk = (parent: string, depth: number) => {
|
|
2087
|
+
for (const node of all.filter((each) => each.parent === parent && !each.archived)) {
|
|
2088
|
+
out.push({ id: node.id, title: node.title, depth });
|
|
2089
|
+
walk(node.id, depth + 1);
|
|
2090
|
+
}
|
|
2091
|
+
};
|
|
2092
|
+
out.push({ id: 'root', title: 'Workspace', depth: 0 });
|
|
2093
|
+
walk('root', 1);
|
|
2094
|
+
return out;
|
|
2095
|
+
}, [tree]);
|
|
2096
|
+
|
|
2097
|
+
const mine = lists[own];
|
|
2098
|
+
const banner = safe
|
|
2099
|
+
? {
|
|
2100
|
+
tone: 'warning',
|
|
2101
|
+
text: 'Bridge runs in safe mode: plugins cannot change until it restarts normally.',
|
|
2102
|
+
}
|
|
2103
|
+
: mine && (mine.workspace.state === 'starting' || mine.workspace.state === 'stopping')
|
|
2104
|
+
? { tone: 'info', text: 'The workspace is restarting…' }
|
|
2105
|
+
: mine && (mine.workspace.state === 'failed' || mine.workspace.state === 'stopped')
|
|
2106
|
+
? {
|
|
2107
|
+
tone: 'error',
|
|
2108
|
+
text: `The workspace is ${mine.workspace.state}${mine.workspace.reason ? `: ${mine.workspace.reason}` : ''}`,
|
|
2109
|
+
}
|
|
2110
|
+
: undefined;
|
|
2111
|
+
const clear = () => {
|
|
2112
|
+
setQuery('');
|
|
2113
|
+
setFilter('all');
|
|
2114
|
+
search.current?.focus();
|
|
2115
|
+
};
|
|
2116
|
+
|
|
2117
|
+
/** A plugin's page, the same from the Installed and the Marketplace tab; only its Back differs. */
|
|
2118
|
+
const page = (root: Root, plugin: PluginItem, back: () => void, backLabel?: string) => {
|
|
2119
|
+
const key = entryKey(root.slug, plugin);
|
|
2120
|
+
const entry =
|
|
2121
|
+
root.slug === own && own !== '_host' ? entryOfPlugin(market.catalog, plugin.id) : undefined;
|
|
2122
|
+
return (
|
|
2123
|
+
<Detail
|
|
2124
|
+
key={key}
|
|
2125
|
+
ctx={ctx}
|
|
2126
|
+
root={root}
|
|
2127
|
+
plugin={plugin}
|
|
2128
|
+
usedBy={usedBy(root, plugin)}
|
|
2129
|
+
entry={entry}
|
|
2130
|
+
catalog={market.catalog?.entries ?? []}
|
|
2131
|
+
read={market.catalog?.read}
|
|
2132
|
+
update={approval.ask}
|
|
2133
|
+
updating={approval.running !== undefined}
|
|
2134
|
+
tab={tab}
|
|
2135
|
+
setTab={setTab}
|
|
2136
|
+
busy={running?.key === key ? running.op : undefined}
|
|
2137
|
+
locked={locked}
|
|
2138
|
+
act={(op, each) => void act(op, each)}
|
|
2139
|
+
catchUp={(each, to) => void catchUp(each, to)}
|
|
2140
|
+
askRemove={askRemove}
|
|
2141
|
+
openPlugin={(other) => {
|
|
2142
|
+
// From a page the marketplace shows, the plugin opens in Installed, where it is listed (Codex review).
|
|
2143
|
+
select(root, other);
|
|
2144
|
+
setTab(undefined);
|
|
2145
|
+
setView('installed');
|
|
2146
|
+
}}
|
|
2147
|
+
openSettings={openSettings}
|
|
2148
|
+
copy={copy}
|
|
2149
|
+
back={back}
|
|
2150
|
+
{...(backLabel !== undefined && { backLabel })}
|
|
2151
|
+
until={until}
|
|
2152
|
+
onLive={() => setUntil(undefined)}
|
|
2153
|
+
page={settingsItem}
|
|
2154
|
+
// In the shell, a navigation entry this screen reads back (`pluginOpening`); elsewhere, here.
|
|
2155
|
+
openPage={(each) =>
|
|
2156
|
+
follow
|
|
2157
|
+
? follow.follow({ item: pageItem(root.slug, plugin.id, each) }, plainClick)
|
|
2158
|
+
: setSettingsItem(each)
|
|
2159
|
+
}
|
|
2160
|
+
/>
|
|
2161
|
+
);
|
|
2162
|
+
};
|
|
2163
|
+
|
|
2164
|
+
const switcher =
|
|
2165
|
+
own === '_host' ? null : (
|
|
2166
|
+
<Tabs value={view} onValueChange={(value) => setView(value as 'installed' | 'marketplace')}>
|
|
2167
|
+
<TabsList aria-label="Plugins view" className="-mx-3 -mt-1 mb-0.5 px-1">
|
|
2168
|
+
<TabsTrigger value="installed" data-view="installed" count={installed}>
|
|
2169
|
+
Installed
|
|
2170
|
+
</TabsTrigger>
|
|
2171
|
+
<TabsTrigger value="marketplace" data-view="marketplace">
|
|
2172
|
+
<Icon name="package" size={13} />
|
|
2173
|
+
Marketplace
|
|
2174
|
+
</TabsTrigger>
|
|
2175
|
+
</TabsList>
|
|
2176
|
+
</Tabs>
|
|
2177
|
+
);
|
|
2178
|
+
if (view === 'marketplace')
|
|
2179
|
+
return (
|
|
2180
|
+
<section
|
|
2181
|
+
aria-label="Screen"
|
|
2182
|
+
data-plugins-screen
|
|
2183
|
+
data-marketplace
|
|
2184
|
+
className="@container/pm relative flex min-h-0 flex-1 overflow-hidden [:where(&)_:is(p,ul,ol,h1,h2,h3,pre)]:m-0"
|
|
2185
|
+
style={{ '--pm-list': `${listWidth}px` } as React.CSSProperties}
|
|
2186
|
+
>
|
|
2187
|
+
<h1 className="sr-only">Marketplace</h1>
|
|
2188
|
+
<Marketplace
|
|
2189
|
+
ctx={ctx}
|
|
2190
|
+
slug={own}
|
|
2191
|
+
market={market}
|
|
2192
|
+
approval={approval}
|
|
2193
|
+
locked={locked}
|
|
2194
|
+
switcher={switcher}
|
|
2195
|
+
installed={(lists[own]?.plugins ?? []).map((each) => ({
|
|
2196
|
+
id: each.id,
|
|
2197
|
+
title: nameOf(each),
|
|
2198
|
+
implements: each.implements,
|
|
2199
|
+
}))}
|
|
2200
|
+
renderInstalled={(id, back) => {
|
|
2201
|
+
const list = lists[own];
|
|
2202
|
+
const plugin = list?.plugins.find((each) => each.id === id);
|
|
2203
|
+
return list && plugin
|
|
2204
|
+
? page(
|
|
2205
|
+
{ slug: own, label: labels[own]!, plugins: list.plugins },
|
|
2206
|
+
plugin,
|
|
2207
|
+
back,
|
|
2208
|
+
'Marketplace',
|
|
2209
|
+
)
|
|
2210
|
+
: undefined;
|
|
2211
|
+
}}
|
|
2212
|
+
uninstall={(id) => {
|
|
2213
|
+
const list = lists[own];
|
|
2214
|
+
const plugin = list?.plugins.find((each) => each.id === id);
|
|
2215
|
+
if (list && plugin)
|
|
2216
|
+
setRemoving({
|
|
2217
|
+
root: { slug: own, label: labels[own]!, plugins: list.plugins },
|
|
2218
|
+
plugin,
|
|
2219
|
+
});
|
|
2220
|
+
}}
|
|
2221
|
+
removable={(id) => {
|
|
2222
|
+
const plugin = lists[own]?.plugins.find((each) => each.id === id);
|
|
2223
|
+
return plugin !== undefined && lockOf(plugin) === undefined;
|
|
2224
|
+
}}
|
|
2225
|
+
openInstalled={(id) => {
|
|
2226
|
+
setSelected(`${own}/${id}`);
|
|
2227
|
+
setTab(undefined);
|
|
2228
|
+
setView('installed');
|
|
2229
|
+
}}
|
|
2230
|
+
/>
|
|
2231
|
+
{approval.dialog}
|
|
2232
|
+
<RemoveDialog
|
|
2233
|
+
plugin={removing?.plugin}
|
|
2234
|
+
successor={successorOf(removing)}
|
|
2235
|
+
onClose={() => setRemoving(undefined)}
|
|
2236
|
+
removal={removal}
|
|
2237
|
+
remove={remove}
|
|
2238
|
+
/>
|
|
2239
|
+
<SidebarResizeHandle
|
|
2240
|
+
width={listWidth}
|
|
2241
|
+
onWidthChange={setListWidth}
|
|
2242
|
+
className="hidden @2xl/pm:block"
|
|
2243
|
+
/>
|
|
2244
|
+
</section>
|
|
2245
|
+
);
|
|
2246
|
+
|
|
2247
|
+
return (
|
|
2248
|
+
<section
|
|
2249
|
+
aria-label="Screen"
|
|
2250
|
+
data-plugins-screen
|
|
2251
|
+
// Whether the marketplace's catalog is known yet: a page opened before keeps the tab it opened on (#48).
|
|
2252
|
+
data-catalog={market.catalog ? 'read' : 'reading'}
|
|
2253
|
+
className="@container/pm relative flex min-h-0 flex-1 overflow-hidden [:where(&)_:is(p,ul,ol,h1,h2,h3,pre)]:m-0"
|
|
2254
|
+
style={{ '--pm-list': `${listWidth}px` } as React.CSSProperties}
|
|
2255
|
+
>
|
|
2256
|
+
<h1 className="sr-only">Plugins</h1>
|
|
2257
|
+
<aside
|
|
2258
|
+
aria-label="Plugins"
|
|
2259
|
+
className={cn(
|
|
2260
|
+
'min-h-0 w-full shrink-0 flex-col border-border @2xl/pm:flex @2xl/pm:w-(--pm-list) @2xl/pm:border-r',
|
|
2261
|
+
current ? 'hidden' : 'flex',
|
|
2262
|
+
)}
|
|
2263
|
+
>
|
|
2264
|
+
<div className="flex shrink-0 flex-col gap-2 border-b border-border-subtle px-3 pb-2.5 pt-3">
|
|
2265
|
+
{switcher}
|
|
2266
|
+
<div className="flex items-center gap-1.5">
|
|
2267
|
+
<Input
|
|
2268
|
+
ref={search}
|
|
2269
|
+
variant="outline"
|
|
2270
|
+
type="search"
|
|
2271
|
+
aria-label="Search plugins"
|
|
2272
|
+
placeholder="Search plugins"
|
|
2273
|
+
icon={<Icon name="search" size={14} />}
|
|
2274
|
+
className="min-w-0 flex-1 [&::-webkit-search-cancel-button]:hidden"
|
|
2275
|
+
value={query}
|
|
2276
|
+
onChange={(event) => setQuery(event.currentTarget.value)}
|
|
2277
|
+
onKeyDown={(event) => {
|
|
2278
|
+
if (event.key === 'Escape') setQuery('');
|
|
2279
|
+
}}
|
|
2280
|
+
/>
|
|
2281
|
+
<DropdownMenu>
|
|
2282
|
+
<Tooltip>
|
|
2283
|
+
<TooltipTrigger
|
|
2284
|
+
render={
|
|
2285
|
+
<DropdownMenuTrigger
|
|
2286
|
+
render={
|
|
2287
|
+
<Button
|
|
2288
|
+
type="button"
|
|
2289
|
+
variant="outline"
|
|
2290
|
+
size="icon"
|
|
2291
|
+
aria-label={`Filter plugins: ${filterLabels[filter]}`}
|
|
2292
|
+
data-filter-menu={filter}
|
|
2293
|
+
className={cn(
|
|
2294
|
+
'relative',
|
|
2295
|
+
filter !== 'all' && 'border-accent/40 bg-accent-subtle text-accent',
|
|
2296
|
+
)}
|
|
2297
|
+
/>
|
|
2298
|
+
}
|
|
2299
|
+
/>
|
|
2300
|
+
}
|
|
2301
|
+
>
|
|
2302
|
+
<Icon name="filter" size={14} />
|
|
2303
|
+
{count.failed > 0 && filter !== 'failed' && (
|
|
2304
|
+
<span
|
|
2305
|
+
aria-hidden="true"
|
|
2306
|
+
className="absolute right-1 top-1 size-1.5 rounded-full bg-destructive"
|
|
2307
|
+
/>
|
|
2308
|
+
)}
|
|
2309
|
+
</TooltipTrigger>
|
|
2310
|
+
<TooltipContent>Filter</TooltipContent>
|
|
2311
|
+
</Tooltip>
|
|
2312
|
+
<DropdownMenuContent align="end" aria-label="Filter plugins">
|
|
2313
|
+
{filters.map((each) => (
|
|
2314
|
+
<DropdownMenuItem
|
|
2315
|
+
key={each}
|
|
2316
|
+
data-filter={each}
|
|
2317
|
+
onSelect={() => setFilter(each)}
|
|
2318
|
+
className={cn(each === 'failed' && count.failed > 0 && 'text-destructive')}
|
|
2319
|
+
>
|
|
2320
|
+
<Icon name="check" size={14} className={cn(filter !== each && 'invisible')} />
|
|
2321
|
+
<span className="flex-1">{filterLabels[each]}</span>
|
|
2322
|
+
<span className="tabular-nums text-muted">{count[each]}</span>
|
|
2323
|
+
</DropdownMenuItem>
|
|
2324
|
+
))}
|
|
2325
|
+
</DropdownMenuContent>
|
|
2326
|
+
</DropdownMenu>
|
|
2327
|
+
<IconAction
|
|
2328
|
+
label="Install plugin"
|
|
2329
|
+
icon="plus"
|
|
2330
|
+
disabled={locked}
|
|
2331
|
+
className="size-(--height-md) shrink-0 border border-border"
|
|
2332
|
+
onClick={() => setInstalling(true)}
|
|
2333
|
+
/>
|
|
2334
|
+
</div>
|
|
2335
|
+
{offered > 0 && (
|
|
2336
|
+
<div
|
|
2337
|
+
role="region"
|
|
2338
|
+
aria-label="Updates"
|
|
2339
|
+
className="flex items-center gap-2 rounded-md border border-accent/40 bg-accent-subtle py-1.5 pl-3 pr-1.5 text-sm text-accent"
|
|
2340
|
+
>
|
|
2341
|
+
<Icon name="arrow-up" size={14} className="shrink-0" />
|
|
2342
|
+
<span className="min-w-0 flex-1 truncate font-medium">
|
|
2343
|
+
{offered} {offered === 1 ? 'update' : 'updates'} available
|
|
2344
|
+
</span>
|
|
2345
|
+
<Button
|
|
2346
|
+
size="sm"
|
|
2347
|
+
variant="primary"
|
|
2348
|
+
disabled={locked}
|
|
2349
|
+
onClick={() => setUpdatingAll(true)}
|
|
2350
|
+
className="shrink-0"
|
|
2351
|
+
>
|
|
2352
|
+
Update all
|
|
2353
|
+
</Button>
|
|
2354
|
+
</div>
|
|
2355
|
+
)}
|
|
2356
|
+
<SegmentGroup
|
|
2357
|
+
fullWidth
|
|
2358
|
+
aria-label="List by"
|
|
2359
|
+
items={modeItems}
|
|
2360
|
+
value={mode}
|
|
2361
|
+
onValueChange={(value) => setMode(value as Mode)}
|
|
2362
|
+
/>
|
|
2363
|
+
{searching && (
|
|
2364
|
+
<p className="flex items-center gap-2 text-xs text-muted">
|
|
2365
|
+
<span role="status" className="flex-1">
|
|
2366
|
+
{filter !== 'all' && `${filterLabels[filter]} · `}
|
|
2367
|
+
{found === 0
|
|
2368
|
+
? 'No plugins found'
|
|
2369
|
+
: mode === 'dependencies'
|
|
2370
|
+
? 'Matches and the plugins that lead to them'
|
|
2371
|
+
: `${found} ${found === 1 ? 'plugin' : 'plugins'} found`}
|
|
2372
|
+
</span>
|
|
2373
|
+
<button
|
|
2374
|
+
type="button"
|
|
2375
|
+
onClick={clear}
|
|
2376
|
+
className="cursor-pointer border-0 bg-transparent p-0 font-[inherit] text-xs text-accent hover:underline"
|
|
2377
|
+
>
|
|
2378
|
+
Clear
|
|
2379
|
+
</button>
|
|
2380
|
+
</p>
|
|
2381
|
+
)}
|
|
2382
|
+
</div>
|
|
2383
|
+
{banner && (
|
|
2384
|
+
<p
|
|
2385
|
+
role="status"
|
|
2386
|
+
data-banner={banner.tone}
|
|
2387
|
+
className={cn(
|
|
2388
|
+
'mx-3 mt-2 flex items-center gap-2 rounded-default px-3 py-2 text-[13px]',
|
|
2389
|
+
banner.tone === 'error'
|
|
2390
|
+
? 'bg-destructive-subtle text-destructive'
|
|
2391
|
+
: banner.tone === 'warning'
|
|
2392
|
+
? 'bg-warning-subtle text-warning-text'
|
|
2393
|
+
: 'bg-hover text-secondary',
|
|
2394
|
+
)}
|
|
2395
|
+
>
|
|
2396
|
+
<Icon
|
|
2397
|
+
name={banner.tone === 'info' ? 'loader-circle' : 'triangle-alert'}
|
|
2398
|
+
size={14}
|
|
2399
|
+
className={cn(
|
|
2400
|
+
'shrink-0',
|
|
2401
|
+
banner.tone === 'info' && 'animate-spin motion-reduce:animate-none',
|
|
2402
|
+
)}
|
|
2403
|
+
/>
|
|
2404
|
+
{banner.text}
|
|
2405
|
+
</p>
|
|
2406
|
+
)}
|
|
2407
|
+
{loadError && (
|
|
2408
|
+
<p role="alert" className="mx-3 mt-2 text-sm text-destructive">
|
|
2409
|
+
Plugins could not be loaded: {loadError}
|
|
2410
|
+
</p>
|
|
2411
|
+
)}
|
|
2412
|
+
<ScrollArea
|
|
2413
|
+
className="min-h-0 flex-1"
|
|
2414
|
+
viewportClassName="[&>[data-slot=scroll-area-content]]:min-w-0!"
|
|
2415
|
+
>
|
|
2416
|
+
{mode !== 'dependencies' && listed.length > 0 && (
|
|
2417
|
+
<List
|
|
2418
|
+
aria-label="Installed plugins"
|
|
2419
|
+
selectionMode="single"
|
|
2420
|
+
selectedKey={selected}
|
|
2421
|
+
onSelectionChange={([key]) => {
|
|
2422
|
+
if (key !== undefined) setSelected(key);
|
|
2423
|
+
}}
|
|
2424
|
+
className="pb-6 outline-hidden"
|
|
2425
|
+
>
|
|
2426
|
+
{listed.map((group, index) => {
|
|
2427
|
+
const rows = group.entries.map(({ root, plugin }) => {
|
|
2428
|
+
const key = entryKey(root.slug, plugin);
|
|
2429
|
+
return (
|
|
2430
|
+
<Row
|
|
2431
|
+
key={key}
|
|
2432
|
+
value={key}
|
|
2433
|
+
plugin={plugin}
|
|
2434
|
+
busy={running?.key === key ? running.op : undefined}
|
|
2435
|
+
locked={locked}
|
|
2436
|
+
act={(op, each) => void act(op, each)}
|
|
2437
|
+
/>
|
|
2438
|
+
);
|
|
2439
|
+
});
|
|
2440
|
+
return group.label ? (
|
|
2441
|
+
<ListGroup
|
|
2442
|
+
key={group.label}
|
|
2443
|
+
label={group.label}
|
|
2444
|
+
variant="section"
|
|
2445
|
+
data-group={group.label}
|
|
2446
|
+
className="flex flex-col gap-px px-2 [&>[data-slot=list-group-header]]:-mx-2"
|
|
2447
|
+
>
|
|
2448
|
+
{rows}
|
|
2449
|
+
</ListGroup>
|
|
2450
|
+
) : (
|
|
2451
|
+
<div key={index} className="flex flex-col gap-px px-2 pt-1">
|
|
2452
|
+
{rows}
|
|
2453
|
+
</div>
|
|
2454
|
+
);
|
|
2455
|
+
})}
|
|
2456
|
+
</List>
|
|
2457
|
+
)}
|
|
2458
|
+
{mode === 'dependencies' && trees.length > 0 && (
|
|
2459
|
+
<SidebarTree aria-label="Plugin dependencies" className="px-2 pb-6 pt-1">
|
|
2460
|
+
{trees.map(({ root, nodes: rows }) => {
|
|
2461
|
+
const body = (
|
|
2462
|
+
<DependencyRows
|
|
2463
|
+
nodes={rows}
|
|
2464
|
+
depth={roots.length > 1 ? 1 : 0}
|
|
2465
|
+
selected={selected}
|
|
2466
|
+
select={select}
|
|
2467
|
+
expanded={(key, depth) =>
|
|
2468
|
+
opened[key] ?? (searching || depth < (roots.length > 1 ? 2 : 1))
|
|
2469
|
+
}
|
|
2470
|
+
toggle={(key, open) => setOpened((was) => ({ ...was, [key]: open }))}
|
|
2471
|
+
/>
|
|
2472
|
+
);
|
|
2473
|
+
if (roots.length === 1)
|
|
2474
|
+
return <React.Fragment key={root.slug}>{body}</React.Fragment>;
|
|
2475
|
+
const open = opened[root.slug] ?? true;
|
|
2476
|
+
return (
|
|
2477
|
+
<SidebarTreeItem
|
|
2478
|
+
key={root.slug}
|
|
2479
|
+
data-root={root.slug}
|
|
2480
|
+
label={root.label}
|
|
2481
|
+
icon={<Icon name={root.slug === '_host' ? 'settings' : 'home'} size={14} />}
|
|
2482
|
+
expanded={open}
|
|
2483
|
+
onExpandedChange={(next) => setOpened((was) => ({ ...was, [root.slug]: next }))}
|
|
2484
|
+
className="font-medium"
|
|
2485
|
+
>
|
|
2486
|
+
{open && body}
|
|
2487
|
+
</SidebarTreeItem>
|
|
2488
|
+
);
|
|
2489
|
+
})}
|
|
2490
|
+
</SidebarTree>
|
|
2491
|
+
)}
|
|
2492
|
+
{roots.length > 0 && found === 0 && (
|
|
2493
|
+
<EmptyState
|
|
2494
|
+
data-no-results
|
|
2495
|
+
icon={<Icon name={everything.length ? 'search' : 'package'} size={20} />}
|
|
2496
|
+
title={
|
|
2497
|
+
everything.length
|
|
2498
|
+
? 'No plugins match.'
|
|
2499
|
+
: 'No plugin is installed in this workspace.'
|
|
2500
|
+
}
|
|
2501
|
+
>
|
|
2502
|
+
{everything.length > 0 && (
|
|
2503
|
+
<Button variant="outline" size="sm" onClick={clear}>
|
|
2504
|
+
Clear search and filter
|
|
2505
|
+
</Button>
|
|
2506
|
+
)}
|
|
2507
|
+
</EmptyState>
|
|
2508
|
+
)}
|
|
2509
|
+
</ScrollArea>
|
|
2510
|
+
</aside>
|
|
2511
|
+
<ScrollArea
|
|
2512
|
+
className={cn('min-h-0 min-w-0 flex-1 @2xl/pm:block', current ? 'block' : 'hidden')}
|
|
2513
|
+
viewportClassName="[&>[data-slot=scroll-area-content]]:min-w-0!"
|
|
2514
|
+
>
|
|
2515
|
+
{current ? (
|
|
2516
|
+
<div className="mx-auto w-full max-w-[860px]">
|
|
2517
|
+
{page(current.root, current.plugin, () => setSelected(undefined))}
|
|
2518
|
+
</div>
|
|
2519
|
+
) : (
|
|
2520
|
+
roots.length > 0 &&
|
|
2521
|
+
everything.length > 0 && (
|
|
2522
|
+
<EmptyState
|
|
2523
|
+
fill
|
|
2524
|
+
className="py-24"
|
|
2525
|
+
icon={<Icon name="puzzle" size={22} />}
|
|
2526
|
+
title={`${installed} ${installed === 1 ? 'plugin' : 'plugins'} installed`}
|
|
2527
|
+
>
|
|
2528
|
+
<p className="max-w-[300px]">
|
|
2529
|
+
Select one to see what it adds, its documentation, its settings and its logs.
|
|
2530
|
+
</p>
|
|
2531
|
+
</EmptyState>
|
|
2532
|
+
)
|
|
2533
|
+
)}
|
|
2534
|
+
</ScrollArea>
|
|
2535
|
+
{confirming && (
|
|
2536
|
+
<ConfirmDialog
|
|
2537
|
+
title={`Disable ${nameOf(confirming.plugin)}?`}
|
|
2538
|
+
failure={confirming.failure}
|
|
2539
|
+
action="Disable"
|
|
2540
|
+
onClose={() => setConfirming(undefined)}
|
|
2541
|
+
confirm={() => {
|
|
2542
|
+
const { root, plugin } = confirming;
|
|
2543
|
+
setConfirming(undefined);
|
|
2544
|
+
void act('disable', plugin, true, root);
|
|
2545
|
+
}}
|
|
2546
|
+
/>
|
|
2547
|
+
)}
|
|
2548
|
+
{askingUpdate && (
|
|
2549
|
+
<ConfirmDialog
|
|
2550
|
+
title={`Update ${nameOf(askingUpdate.plugin)} to ${askingUpdate.to}?`}
|
|
2551
|
+
failure={askingUpdate.failure}
|
|
2552
|
+
action={`Update to ${askingUpdate.to}`}
|
|
2553
|
+
onClose={() => setAskingUpdate(undefined)}
|
|
2554
|
+
confirm={() => {
|
|
2555
|
+
const { root, plugin, to } = askingUpdate;
|
|
2556
|
+
setAskingUpdate(undefined);
|
|
2557
|
+
void catchUp(plugin, to, true, root);
|
|
2558
|
+
}}
|
|
2559
|
+
/>
|
|
2560
|
+
)}
|
|
2561
|
+
<InstallDialog
|
|
2562
|
+
open={installing}
|
|
2563
|
+
onOpenChange={setInstalling}
|
|
2564
|
+
nodes={targets}
|
|
2565
|
+
install={install}
|
|
2566
|
+
/>
|
|
2567
|
+
{approval.dialog}
|
|
2568
|
+
{updatingAll && (
|
|
2569
|
+
<UpdateAllDialog
|
|
2570
|
+
entries={updates}
|
|
2571
|
+
update={(entry) => updateOne(workspace.fetch, own, entry)}
|
|
2572
|
+
onClose={() => {
|
|
2573
|
+
setUpdatingAll(false);
|
|
2574
|
+
void loadOne(own);
|
|
2575
|
+
void market.load();
|
|
2576
|
+
}}
|
|
2577
|
+
/>
|
|
2578
|
+
)}
|
|
2579
|
+
<RemoveDialog
|
|
2580
|
+
plugin={removing?.plugin}
|
|
2581
|
+
successor={successorOf(removing)}
|
|
2582
|
+
onClose={() => setRemoving(undefined)}
|
|
2583
|
+
removal={removal}
|
|
2584
|
+
remove={remove}
|
|
2585
|
+
/>
|
|
2586
|
+
<SidebarResizeHandle
|
|
2587
|
+
width={listWidth}
|
|
2588
|
+
onWidthChange={setListWidth}
|
|
2589
|
+
className="hidden @2xl/pm:block"
|
|
2590
|
+
/>
|
|
2591
|
+
</section>
|
|
2592
|
+
);
|
|
2593
|
+
}
|