Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/web/src/components/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ const lookup = <P extends ModelProvider>(providers: ReadonlyArray<P>, ref: Model
return provider === undefined || model === undefined ? undefined : { provider, model };
};

/** Display name of `value` (or the settings default when `value` is absent), once `models.list` has loaded. */
export function useModelName(hostDir: string | undefined, value: ModelRef | undefined): string | undefined {
const result = useAtomValue(modelsAtom(hostDir));
const list = AsyncResult.isSuccess(result) ? result.value : undefined;
const current = value ?? list?.default;
if (current === undefined) return undefined;
if (list !== undefined) {
const found = lookup(list.providers, current);
if (found !== undefined) return found.model.name;
if (
current.provider === list.default.provider &&
current.id === list.default.id &&
list.default.name !== undefined
) {
return list.default.name;
}
}
return current.id;
}

/**
* Picks the model a new session uses: providers down a rail on the left, their models on the
* right, and a search across all of them. `value` undefined means settings decide; the trigger
Expand Down
68 changes: 66 additions & 2 deletions apps/web/src/landing/empty.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,74 @@
import type { ReactNode } from "react";

const GRID_W = 16;

const TERMINAL = [
"..############..",
".##..........##.",
".#............#.",
".#..#.........#.",
".#...#...###..#.",
".#..#....###..#.",
".#............#.",
".#............#.",
".##..........##.",
"..############..",
"......####......",
"....########....",
] as const;

const GLOW = [
"#.#..........#.#",
"................",
"#..............#",
"................",
"................",
"................",
"................",
"#..............#",
"................",
"#.#..........#.#",
"................",
"..#..........#..",
] as const;

/** Merges each row's filled runs into one rect so the path stays short. */
function spritePath(rows: readonly string[]) {
let path = "";
rows.forEach((row, y) => {
let x = 0;
while (x < row.length) {
if (row[x] !== "#") {
x += 1;
continue;
}
let run = 1;
while (row[x + run] === "#") run += 1;
path += `M${x} ${y}h${run}v1h-${run}z`;
x += run;
}
});
return path;
}

const TERMINAL_PATH = spritePath(TERMINAL);
const GLOW_PATH = spritePath(GLOW);

/** The sidebar's message when it has nothing to list: a few quiet lines, centered, and what to do next. */
export function Empty({ children }: { children: ReactNode }) {
return (
<div className="flex w-full min-w-0 flex-col items-center gap-2 px-2 py-6 text-center text-xs text-ink-muted/70">
{children}
<div className="flex min-h-full w-full min-w-0 flex-col items-center justify-center gap-5 px-6 py-10 text-center text-body leading-relaxed text-ink-muted/70">
<div className="flex flex-col items-center gap-2">{children}</div>
<svg
aria-hidden
viewBox={`0 0 ${GRID_W} ${TERMINAL.length}`}
shapeRendering="crispEdges"
className="w-24 text-ink-muted/35"
fill="currentColor"
>
<path d={GLOW_PATH} opacity={0.4} />
<path d={TERMINAL_PATH} />
</svg>
</div>
);
}
Expand Down
35 changes: 28 additions & 7 deletions apps/web/src/landing/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useOpenElsewhere } from "../wm/open";
import { ago } from "../widgets/time";
import { Monogram } from "@/components/monogram";
import { OpenProviderSettings } from "@/components/offline";
import { ProviderIcon } from "@/components/provider";
import { problemAtom } from "../kernel/servers";
import { Empty, EmptyAction } from "./empty";
import { placeAtom, usePickFolder } from "./place";
Expand Down Expand Up @@ -145,16 +146,36 @@ export function SessionsSidebar() {
type="button"
title={`${session.project.path}\n${isMac ? "⌘" : "Ctrl"}-click opens it in a new frame\n⇧-click opens it in a new workspace`}
aria-current={sessionAddress(session.id) === current ? "true" : undefined}
className="block w-full rounded-md px-2.5 py-2 text-left outline-none hover:bg-selection-subtle focus-visible:ring-2 focus-visible:ring-ring aria-current:bg-selection"
className="group relative flex w-full flex-col rounded-md px-2 py-1.5 text-left text-ink/80 outline-none hover:bg-selection-subtle hover:text-ink focus-visible:ring-2 focus-visible:ring-ring aria-current:bg-selection aria-current:text-ink"
onClick={(event) => open(session, event)}
onAuxClick={(event) => open(session, event)}
>
<div className="flex h-4 min-w-0 items-center gap-1.5 text-2xs text-ink-muted">
<Monogram id={session.project.id} name={session.project.name} />
<span className="min-w-0 flex-1 truncate">{session.project.name}</span>
<span className="shrink-0 tabular-nums">{ago(session.updated)}</span>
</div>
<div className="mt-1 truncate text-ui text-ink">{session.title}</div>
<span className="flex min-w-0 items-center gap-1.5">
<span className="min-w-0 flex-1 truncate text-body font-semibold leading-snug text-ink">
{session.title}
</span>
<span className="ml-auto shrink-0 pl-2 text-2xs tabular-nums text-ink-muted">
{ago(session.updated)}
</span>
</span>
<span className="mt-1 flex min-w-0 items-center gap-2 text-2xs text-ink-muted">
<span className="flex min-w-0 flex-1 items-center gap-1.5">
<Monogram id={session.project.id} name={session.project.name} />
<span className="min-w-0 truncate">{session.project.name}</span>
</span>
{session.model !== undefined && (
<span className="flex shrink-0 items-center text-2xs text-ink-muted">
<span className="max-w-0 truncate pr-0 opacity-0 transition-[max-width,opacity,padding] duration-200 ease-out group-focus-within:max-w-32 group-focus-within:pr-1.5 group-focus-within:opacity-100 group-hover:max-w-32 group-hover:pr-1.5 group-hover:opacity-100">
{session.model.id}
</span>
<ProviderIcon
id={session.model.provider}
name={session.model.provider}
className="size-3.5 shrink-0"
/>
</span>
)}
</span>
</button>
</li>
))}
Expand Down
Loading
Loading