| 1 | import { parseResponse } from "hono/client"; |
| 2 | import Download from "lucide-solid/icons/download"; |
| 3 | import EyeOff from "lucide-solid/icons/eye-off"; |
| 4 | import KeyRound from "lucide-solid/icons/key-round"; |
| 5 | import { createResource, createSignal, For, Show } from "solid-js"; |
| 6 | import { api, reason } from "../api.ts"; |
| 7 | import { CopyField } from "../components/Copy.tsx"; |
| 8 | import { Loaded } from "../components/Loaded.tsx"; |
| 9 | import claude from "../../src/claude.svg?raw"; |
| 10 | import openai from "../../src/openai.svg?raw"; |
| 11 | |
| 12 | export function ClientMark(props: { name: string }) { |
| 13 | const logo = () => /claude/i.test(props.name) ? claude : /codex|openai|chatgpt/i.test(props.name) ? openai : ""; |
| 14 | return <span class="mcp-client-mark" aria-hidden="true"> |
| 15 | <Show when={logo()} fallback={<span class="monogram">{props.name.trim()[0]?.toUpperCase()}</span>}>{(svg) => <span class="logo" innerHTML={svg()} />}</Show> |
| 16 | </span>; |
| 17 | } |
| 18 | |
| 19 | const WRAPPERS = [["claude", "Claude Code"], ["codex", "Codex"]] as const; |
| 20 | |
| 21 | export function AI(props: { viewing: boolean }) { |
| 22 | const [info, { refetch }] = createResource(() => parseResponse(api.ai.$get())); |
| 23 | const [key, setKey] = createSignal(""); |
| 24 | const [busy, setBusy] = createSignal(false); |
| 25 | const [error, setError] = createSignal(""); |
| 26 | let show!: HTMLButtonElement; |
| 27 | let hide!: HTMLButtonElement; |
| 28 | return <Loaded data={info} what="Local AI" retry={refetch}>{(data) => <> |
| 29 | <section class="mcp-section"> |
| 30 | <div class="stats"><span class="stat"><b>{data().model}</b></span><span class="stat"><b>{Math.round(data().context / 1024)}K</b> context</span></div> |
| 31 | <h2 class="mcp-label">API endpoint</h2> |
| 32 | <CopyField value={data().endpoint} label="API endpoint" /> |
| 33 | <p class="hint">OpenAI Responses and Chat Completions use /v1. Anthropic Messages uses this base URL</p> |
| 34 | <h2 class="mcp-label">API key</h2> |
| 35 | <div class="mcp-key"> |
| 36 | <Show when={key()} fallback={<> |
| 37 | <span class="copy-field masked" aria-hidden="true"><span class="value">••••••••••••••••••••••••••••••••</span></span> |
| 38 | <button ref={show} class="button" disabled={busy() || props.viewing} aria-busy={busy()} |
| 39 | data-tip={props.viewing ? "Switch back to your account to see the key" : undefined} onClick={async () => { |
| 40 | setBusy(true); setError(""); |
| 41 | try { setKey((await parseResponse(api.ai.key.$post())).key); hide.focus(); } |
| 42 | catch (failure) { setError(reason(failure)); } |
| 43 | finally { setBusy(false); } |
| 44 | }}><KeyRound size={14} />Show key</button> |
| 45 | </>}> |
| 46 | <CopyField value={key()} label="API key" /> |
| 47 | <button ref={hide} class="button" onClick={() => { setKey(""); show.focus(); }}><EyeOff size={14} />Hide</button> |
| 48 | </Show> |
| 49 | </div> |
| 50 | <Show when={error()}><p class="error" role="alert">Couldn't show the key. {error()}</p></Show> |
| 51 | <p class="hint">Use it with the endpoint, or enter it when a wrapper first starts</p> |
| 52 | </section> |
| 53 | <section class="mcp-section"> |
| 54 | <h2>Coding clients</h2> |
| 55 | <p>Bash wrappers for macOS and Linux that run your installed Claude Code or Codex on the local model. Both start with automatic approval.</p> |
| 56 | <div class="mcp-wrappers"><For each={WRAPPERS}>{([id, name]) => <div class="mcp-wrapper"> |
| 57 | <ClientMark name={name} /> |
| 58 | <div class="mcp-wrapper-main"> |
| 59 | <div class="mcp-wrapper-head"><b>{name}</b> |
| 60 | <a class="button small" href={`/api/ai/snow-${id}`} download={`snow-${id}`}><Download size={14} />Download snow-{id}</a></div> |
| 61 | <span class="mcp-label">Install from a macOS or Linux terminal</span> |
| 62 | <CopyField value={`mkdir -p ~/.local/bin && install -m 755 ~/Downloads/snow-${id} ~/.local/bin/snow-${id}`} label={`macOS and Linux install command for snow-${id}`} /> |
| 63 | </div> |
| 64 | </div>}</For></div> |
| 65 | <p class="hint">Keep ~/.local/bin on your PATH, then run snow-claude or snow-codex from a project. The first run asks for your API key</p> |
| 66 | <p class="hint">API waits allow eight hours. Stock Codex approval reviews keep their 90-second deadline</p> |
| 67 | </section> |
| 68 | </>}</Loaded>; |
| 69 | } |