import { Button, FileIcon, Icon, IconButton, Logo, Tooltip } from "@/ui" import { Tabs } from "@/ui/tabs" import { Select } from "@/components/select" import FileTree from "@/components/file-tree" import { For, Match, onCleanup, onMount, Show, Switch } from "solid-js" import { SelectDialog } from "@/components/select-dialog" import { useLocal, useSDK } from "@/context" import { Code } from "@/components/code" import { DragDropProvider, DragDropSensors, DragOverlay, SortableProvider, createSortable, closestCenter, useDragDropContext, } from "@thisbeyond/solid-dnd" import type { DragEvent, Transformer } from "@thisbeyond/solid-dnd" import type { LocalFile } from "@/context/local" import SessionList from "@/components/session-list" import SessionTimeline from "@/components/session-timeline" import { createStore } from "solid-js/store" import { getDirectory, getFilename } from "@/utils" export default function Page() { const sdk = useSDK() const local = useLocal() const [store, setStore] = createStore({ clickTimer: undefined as number | undefined, activeItem: undefined as string | undefined, prompt: "", dragging: undefined as "left" | "right" | undefined, modelSelectOpen: false, fileSelectOpen: false, }) let inputRef: HTMLInputElement | undefined = undefined const MOD = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform) ? "Meta" : "Control" onMount(() => { document.addEventListener("keydown", handleKeyDown) }) onCleanup(() => { document.removeEventListener("keydown", handleKeyDown) }) const handleKeyDown = (e: KeyboardEvent) => { if (e.getModifierState(MOD) && e.shiftKey && e.key.toLowerCase() === "p") { e.preventDefault() // TODO: command palette return } if (e.getModifierState(MOD) && e.key.toLowerCase() === "p") { e.preventDefault() setStore("fileSelectOpen", true) return } const inputFocused = document.activeElement === inputRef if (inputFocused) { if (e.key === "Escape") { inputRef?.blur() } return } if (document.activeElement?.id === "select-filter") { return } if (local.file.active()) { if (e.getModifierState(MOD)) { if (e.key.toLowerCase() === "a") { return } if (e.key.toLowerCase() === "c") { return } } } if (e.key.length === 1 && e.key !== "Unidentified") { inputRef?.focus() } } const navigateChange = (dir: 1 | -1) => { const active = local.file.active() if (!active) return const current = local.file.changeIndex(active.path) const next = current == undefined ? (dir === 1 ? 0 : -1) : current + dir local.file.setChangeIndex(active.path, next) } const resetClickTimer = () => { if (!store.clickTimer) return clearTimeout(store.clickTimer) setStore("clickTimer", undefined) } const startClickTimer = () => { const newClickTimer = setTimeout(() => { setStore("clickTimer", undefined) }, 300) setStore("clickTimer", newClickTimer as unknown as number) } const handleFileClick = async (file: LocalFile) => { if (store.clickTimer) { resetClickTimer() local.file.update(file.path, { ...file, pinned: true }) } else { local.file.open(file.path) startClickTimer() } } const handleTabChange = (path: string) => { local.file.open(path) } const handleTabClose = (file: LocalFile) => { local.file.close(file.path) } const onDragStart = (event: any) => { setStore("activeItem", event.draggable.id as string) } const onDragOver = (event: DragEvent) => { const { draggable, droppable } = event if (draggable && droppable) { const currentFiles = local.file.opened().map((f) => f.path) const fromIndex = currentFiles.indexOf(draggable.id.toString()) const toIndex = currentFiles.indexOf(droppable.id.toString()) if (fromIndex !== toIndex) { local.file.move(draggable.id.toString(), toIndex) } } } const onDragEnd = () => { setStore("activeItem", undefined) } const handleLeftDragStart = (e: MouseEvent) => { e.preventDefault() setStore("dragging", "left") const startX = e.clientX const startWidth = local.layout.leftWidth() const handleMouseMove = (e: MouseEvent) => { const deltaX = e.clientX - startX const newWidth = startWidth + deltaX local.layout.setLeftWidth(newWidth) } const handleMouseUp = () => { setStore("dragging", undefined) document.removeEventListener("mousemove", handleMouseMove) document.removeEventListener("mouseup", handleMouseUp) } document.addEventListener("mousemove", handleMouseMove) document.addEventListener("mouseup", handleMouseUp) } const handleRightDragStart = (e: MouseEvent) => { e.preventDefault() setStore("dragging", "right") const startX = e.clientX const startWidth = local.layout.rightWidth() const handleMouseMove = (e: MouseEvent) => { const deltaX = startX - e.clientX const newWidth = startWidth + deltaX local.layout.setRightWidth(newWidth) } const handleMouseUp = () => { setStore("dragging", undefined) document.removeEventListener("mousemove", handleMouseMove) document.removeEventListener("mouseup", handleMouseUp) } document.addEventListener("mousemove", handleMouseMove) document.addEventListener("mouseup", handleMouseUp) } const handleSubmit = async (e: SubmitEvent) => { e.preventDefault() const prompt = store.prompt setStore("prompt", "") inputRef?.blur() const session = (local.layout.rightPane() ? local.session.active() : undefined) ?? (await sdk.session.create().then((x) => x.data!)) local.session.setActive(session!.id) local.layout.openRightPane() const response = await sdk.session.prompt({ path: { id: session!.id }, body: { agent: local.agent.current()!.name, model: { modelID: local.model.current()!.id, providerID: local.model.current()!.provider.id }, parts: [ { type: "text", text: prompt, }, ...local.file .opened() .filter((f) => f.selection || local.file.active()?.path === f.path) .flatMap((f) => [ { type: "file" as const, mime: "text/plain", url: `file://${f.absolute}${f.selection ? `?start=${f.selection.startLine}&end=${f.selection.endLine}` : ""}`, filename: f.name, source: { type: "file" as const, text: { value: "@" + f.name, start: 0, // f.start, end: 0, // f.end, }, path: f.absolute, }, }, ]), ], }, }) console.log("response", response) } return (
Files Changes
    {(path) => (
  • )}
handleLeftDragStart(e)} >
}> {(activeSession) => (
local.session.clearActive()} class="text-text-muted hover:text-text" >

{activeSession().title || "Untitled Session"}

)}
handleRightDragStart(e)} >
f.path)}> {(file) => }
{(() => { const f = local.file.active()! const view = local.file.view(f.path) return (
navigateChange(-1)}> navigateChange(1)}>
local.file.setView(f.path, "raw")} > local.file.setView(f.path, "diff-unified")} > local.file.setView(f.path, "diff-split")} >
) })()}
local.layout.toggleRightPane()}>
{(file) => ( {(() => { const view = local.file.view(file.path) const showRaw = view === "raw" || !file.content?.diff const code = showRaw ? (file.content?.content ?? "") : (file.content?.diff ?? "") return })()} )}
{store.activeItem && (() => { const draggedFile = local.file.node(store.activeItem!) return (
) })()}
local.file.close(local.file.active()?.path ?? "")} /> x.selection)}> {(file) => local.file.select(file.path, undefined)} />}
(inputRef = el)} type="text" value={store.prompt} onInput={(e) => setStore("prompt", e.currentTarget.value)} placeholder="Placeholder text..." class="w-full p-1 pb-4 text-text font-light placeholder-text-muted/70 text-sm focus:outline-none" />