1import { For, Show } from "solid-js";
2import { Checkbox } from "../components/Checkbox.tsx";
3import { TabBar } from "../components/TabBar.tsx";
4import { datetime, until } from "../format.ts";
5import type { Access, Catalog, Resources } from "../types/mcp.ts";
6
7const PLATFORMS: Record<string, string> = { linux: "Linux", windows: "Windows", macos: "macOS" };
8
9function facts(resource: Resources[number]) {
10 const platform = resource.platform && (PLATFORMS[resource.platform] ?? resource.platform);
11 return [platform && !resource.os?.toLowerCase().includes(platform.toLowerCase()) ? platform : null, resource.os, resource.arch].filter(Boolean);
12}
13
14export function MCPAccess(props: {
15 catalog: Catalog;
16 resources: Resources;
17 value: Access;
18 onChange: (value: Access) => void;
19 disabled: boolean;
20 create: boolean;
21}) {
22 return <fieldset class="mcp-access" disabled={props.disabled}>
23 <legend>{props.catalog === "computer" ? "Virtual machines" : props.catalog === "shale" ? "Repositories" : "Services"}</legend>
24 <Show when={props.catalog === "shale"}>
25 <TabBar label="Repository access">
26 <button type="button" aria-pressed={props.value === "all"} onClick={() => props.onChange("all")}>All repositories</button>
27 <button type="button" aria-pressed={props.value !== "all"} onClick={() => props.value === "all" && props.onChange([])}>Selected repositories</button>
28 </TabBar>
29 <p class="hint">{props.value === "all" ? "Includes repositories you can access later" : "Only the repositories you choose"}</p>
30 </Show>
31 <Show when={props.value !== "all"}>
32 <Show when={props.resources.length} fallback={<p class={props.catalog === "computer" && !props.create ? "mcp-none" : "hint"}>
33 {props.catalog === "computer" ? props.create ? "No VMs yet. This client can create its own test VMs." : "No VMs with computer use belong to your account."
34 : props.catalog === "shale" ? "No repositories available to select." : "No services available to your account."}
35 </p>}>
36 <div class="mcp-resources"><For each={props.resources}>{(resource) =>
37 <Checkbox checked={props.value !== "all" && props.value.includes(resource.id)} disabled={props.disabled} onChange={(checked) => {
38 const selected = props.value === "all" ? [] : props.value;
39 props.onChange(checked ? [...selected, resource.id] : selected.filter((id) => id !== resource.id));
40 }}><span>{resource.name}
41 <Show when={props.catalog === "computer"} fallback={<Show when={resource.description}><small class="muted">{resource.description}</small></Show>}>
42 <span class="chips">
43 <For each={facts(resource)}>{(fact) => <span class="chip fact">{fact}</span>}</For>
44 <Show when={resource.state}><span class="chip fact">{resource.state}</span></Show>
45 <Show when={resource.aiOwned}><span class="chip fact">Test VM</span></Show>
46 <Show when={resource.expiresAt}>{(t) => <span class="chip fact" data-tip={datetime(t())}>Expires {until(t())}</span>}</Show>
47 </span>
48 </Show>
49 </span></Checkbox>
50 }</For></div>
51 </Show>
52 </Show>
53 </fieldset>;
54}