Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
605c74bb8c | ||
|
|
2880ef8276 |
No files matched your search
@@ -63,6 +63,19 @@ bun run dist:desktop:dmg
|
||||
npx t3
|
||||
```
|
||||
|
||||
## Remote usage (phone/tablet/laptop)
|
||||
|
||||
To run the server on one device and control it from another (for example over Tailscale), use:
|
||||
|
||||
- `docs/remote-access.md`
|
||||
|
||||
This includes:
|
||||
|
||||
- architecture and security model
|
||||
- production setup for remote control
|
||||
- remote dev setup with hot reload
|
||||
- troubleshooting for cross-device connectivity
|
||||
|
||||
## Scripts
|
||||
|
||||
- `bun run dev` — Starts contracts, server, and web in `turbo watch` mode.
|
||||
|
||||
@@ -182,7 +182,7 @@ export default function BranchToolbar({
|
||||
if (!activeThread || !activeProject) return null;
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-3xl items-center justify-between px-5 pb-3 pt-1">
|
||||
<div className="mx-auto flex w-full max-w-3xl items-center justify-between px-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] pt-1 sm:px-5 sm:pb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{envLocked || activeWorktreePath ? (
|
||||
<span className="border border-transparent px-[calc(--spacing(2)-1px)] text-sm font-medium text-muted-foreground/70 sm:text-xs">
|
||||
|
||||
@@ -119,6 +119,7 @@ import {
|
||||
setupProjectScript,
|
||||
} from "~/projectScripts";
|
||||
import { Toggle } from "./ui/toggle";
|
||||
import { SidebarTrigger } from "./ui/sidebar";
|
||||
|
||||
function formatMessageMeta(createdAt: string, duration: string | null): string {
|
||||
if (!duration) return formatTimestamp(createdAt);
|
||||
@@ -433,6 +434,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
);
|
||||
const phase = derivePhase(activeThread?.session ?? null);
|
||||
const isWorking = phase === "running" || isSending || isConnecting || isRevertingCheckpoint;
|
||||
const canSend =
|
||||
Boolean(api) &&
|
||||
Boolean(activeThread) &&
|
||||
!isSending &&
|
||||
!isConnecting &&
|
||||
(prompt.trim().length > 0 || composerImages.length > 0);
|
||||
const nowIso = new Date(nowTick).toISOString();
|
||||
const workLogEntries = useMemo(
|
||||
() => deriveWorkLogEntries(activeThread?.events ?? [], undefined),
|
||||
@@ -1583,7 +1590,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
);
|
||||
|
||||
const ensureSession = useCallback(
|
||||
async (cwdOverride?: string): Promise<EnsuredSessionInfo | null> => {
|
||||
async (
|
||||
cwdOverride?: string,
|
||||
options?: {
|
||||
silent?: boolean;
|
||||
},
|
||||
): Promise<EnsuredSessionInfo | null> => {
|
||||
if (!api || !activeThread || !activeProject) return null;
|
||||
if (activeThread.session && activeThread.session.status !== "closed") {
|
||||
const sessionThreadId = activeThread.session.threadId ?? null;
|
||||
@@ -1606,7 +1618,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
}
|
||||
|
||||
const priorCodexThreadId = activeThread.codexThreadId;
|
||||
setIsConnecting(true);
|
||||
const shouldShowConnectingState = !options?.silent;
|
||||
if (shouldShowConnectingState) {
|
||||
setIsConnecting(true);
|
||||
}
|
||||
try {
|
||||
const session = await api.providers.startSession({
|
||||
provider: "codex",
|
||||
@@ -1649,7 +1664,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setIsConnecting(false);
|
||||
if (shouldShowConnectingState) {
|
||||
setIsConnecting(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -1679,7 +1696,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
}
|
||||
checkpointHydrationSessionRequestRef.current.add(requestKey);
|
||||
setThreadError(activeThreadId, null);
|
||||
void ensureSession().then(
|
||||
void ensureSession(undefined, { silent: true }).then(
|
||||
() => {
|
||||
checkpointHydrationSessionRequestRef.current.delete(requestKey);
|
||||
},
|
||||
@@ -1904,6 +1921,24 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const triggerSend = () => {
|
||||
if (!canSend) return;
|
||||
const form = textareaRef.current?.form;
|
||||
if (form) {
|
||||
if (typeof form.requestSubmit === "function") {
|
||||
form.requestSubmit();
|
||||
} else {
|
||||
const submitEvent = new Event("submit", { bubbles: true, cancelable: true });
|
||||
const dispatched = form.dispatchEvent(submitEvent);
|
||||
if (!dispatched) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
void onSend({ preventDefault: () => undefined } as FormEvent);
|
||||
};
|
||||
|
||||
const onInterrupt = async () => {
|
||||
if (!api || !activeThread?.session) return;
|
||||
await api.providers.interruptTurn({
|
||||
@@ -2047,7 +2082,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
void onSend(e as unknown as FormEvent);
|
||||
triggerSend();
|
||||
}
|
||||
};
|
||||
const onToggleWorkGroup = useCallback((groupId: string) => {
|
||||
@@ -2117,7 +2152,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background">
|
||||
{/* Top bar */}
|
||||
<header
|
||||
className={`flex items-center justify-between border-b border-border px-5 ${isElectron ? "drag-region h-[52px]" : "py-3"}`}
|
||||
className={`flex items-center justify-between border-b border-border px-3 sm:px-5 ${isElectron ? "drag-region h-[52px]" : "py-3"}`}
|
||||
>
|
||||
<ChatHeader
|
||||
activeThreadId={activeThread.id}
|
||||
@@ -2151,7 +2186,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
{/* Messages */}
|
||||
<div
|
||||
ref={messagesScrollRef}
|
||||
className="min-h-0 flex-1 overflow-y-auto px-5 py-4"
|
||||
className="min-h-0 flex-1 overflow-y-auto px-3 py-3 sm:px-5 sm:py-4"
|
||||
onScroll={onMessagesScroll}
|
||||
>
|
||||
<MessagesTimeline
|
||||
@@ -2176,7 +2211,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
</div>
|
||||
|
||||
{/* Input bar */}
|
||||
<div className={cn("px-5 pt-2", isGitRepo ? "pb-1" : "pb-4")}>
|
||||
<div
|
||||
className={cn(
|
||||
"px-3 pt-2 sm:px-5 max-sm:pb-[calc(0.5rem+env(safe-area-inset-bottom))]",
|
||||
isGitRepo ? "pb-1" : "pb-4",
|
||||
)}
|
||||
>
|
||||
<form onSubmit={onSend} className="mx-auto max-w-3xl">
|
||||
<div
|
||||
className={`group rounded-[20px] border bg-card transition-colors duration-200 focus-within:border-ring ${
|
||||
@@ -2275,8 +2315,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
</div>
|
||||
|
||||
{/* Bottom toolbar */}
|
||||
<div className="flex items-center justify-between px-3 pb-3">
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="flex items-center justify-end px-3 pb-3 sm:justify-between">
|
||||
<div className="hidden items-center gap-1 sm:flex">
|
||||
{/* Model picker */}
|
||||
<ModelPicker model={selectedModel} onModelChange={onModelSelect} />
|
||||
|
||||
@@ -2317,7 +2357,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
{phase === "running" ? (
|
||||
<button
|
||||
type="button"
|
||||
className="flex h-8 w-8 items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 hover:scale-105"
|
||||
className="relative z-10 flex h-10 w-10 touch-manipulation items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 pointer-events-auto sm:h-8 sm:w-8 sm:hover:scale-105"
|
||||
onClick={() => void onInterrupt()}
|
||||
aria-label="Stop generation"
|
||||
>
|
||||
@@ -2333,11 +2373,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
type="submit"
|
||||
className="flex h-8 w-8 items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary hover:scale-105 disabled:opacity-30 disabled:hover:scale-100"
|
||||
disabled={
|
||||
isSending || isConnecting || (!prompt.trim() && composerImages.length === 0)
|
||||
}
|
||||
type="button"
|
||||
className="relative z-10 flex h-10 w-10 touch-manipulation items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary pointer-events-auto disabled:opacity-30 disabled:hover:scale-100 sm:h-8 sm:w-8 sm:hover:scale-105"
|
||||
disabled={!canSend}
|
||||
onClick={triggerSend}
|
||||
aria-label={
|
||||
isConnecting ? "Connecting" : isSending ? "Sending" : "Send message"
|
||||
}
|
||||
@@ -2387,13 +2426,15 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
</div>
|
||||
|
||||
{isGitRepo && (
|
||||
<BranchToolbar
|
||||
threadId={activeThread.id}
|
||||
envMode={envMode}
|
||||
onEnvModeChange={onEnvModeChange}
|
||||
envLocked={envLocked}
|
||||
onComposerFocusRequest={scheduleComposerFocus}
|
||||
/>
|
||||
<div className="hidden sm:block">
|
||||
<BranchToolbar
|
||||
threadId={activeThread.id}
|
||||
envMode={envMode}
|
||||
onEnvModeChange={onEnvModeChange}
|
||||
envLocked={envLocked}
|
||||
onComposerFocusRequest={scheduleComposerFocus}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeThread.terminalOpen && api && activeProject && (
|
||||
@@ -2497,28 +2538,43 @@ const ChatHeader = memo(function ChatHeader({
|
||||
}: ChatHeaderProps) {
|
||||
return (
|
||||
<>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<h2 className="truncate text-sm font-medium text-foreground" title={activeThreadTitle}>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-2 sm:gap-3">
|
||||
<SidebarTrigger className="size-8 md:hidden" />
|
||||
<Separator orientation="vertical" className="md:hidden data-[orientation=vertical]:h-4" />
|
||||
<h2
|
||||
className="truncate text-xs font-medium text-foreground sm:text-sm"
|
||||
title={activeThreadTitle}
|
||||
>
|
||||
{activeThreadTitle}
|
||||
</h2>
|
||||
{activeProjectName && <Badge variant="outline">{activeProjectName}</Badge>}
|
||||
{activeProjectName && (
|
||||
<Badge variant="outline" className="hidden sm:inline-flex">
|
||||
{activeProjectName}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className="shrink-0 flex items-center gap-3">
|
||||
<div className="shrink-0 flex items-center gap-1.5 sm:gap-3">
|
||||
{activeProjectScripts && (
|
||||
<ProjectScriptsControl
|
||||
scripts={activeProjectScripts}
|
||||
keybindings={keybindings}
|
||||
preferredScriptId={preferredScriptId}
|
||||
onRunScript={onRunProjectScript}
|
||||
onAddScript={onAddProjectScript}
|
||||
onUpdateScript={onUpdateProjectScript}
|
||||
/>
|
||||
<div className="hidden md:block">
|
||||
<ProjectScriptsControl
|
||||
scripts={activeProjectScripts}
|
||||
keybindings={keybindings}
|
||||
preferredScriptId={preferredScriptId}
|
||||
onRunScript={onRunProjectScript}
|
||||
onAddScript={onAddProjectScript}
|
||||
onUpdateScript={onUpdateProjectScript}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{activeProjectName && (
|
||||
<OpenInPicker keybindings={keybindings} activeThreadId={activeThreadId} />
|
||||
<div className="hidden md:block">
|
||||
<OpenInPicker keybindings={keybindings} activeThreadId={activeThreadId} />
|
||||
</div>
|
||||
)}
|
||||
{activeProjectName && (
|
||||
<GitActionsControl api={api} gitCwd={gitCwd} activeThreadId={activeThreadId} />
|
||||
<div className="hidden md:block">
|
||||
<GitActionsControl api={api} gitCwd={gitCwd} activeThreadId={activeThreadId} />
|
||||
</div>
|
||||
)}
|
||||
<Toggle
|
||||
pressed={diffOpen}
|
||||
|
||||
@@ -112,7 +112,11 @@ function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null
|
||||
};
|
||||
}
|
||||
|
||||
export default function Sidebar() {
|
||||
interface SidebarProps {
|
||||
embedded?: boolean;
|
||||
}
|
||||
|
||||
export default function Sidebar({ embedded = false }: SidebarProps = {}) {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useNativeApi();
|
||||
const navigate = useNavigate();
|
||||
@@ -497,8 +501,12 @@ export default function Sidebar() {
|
||||
};
|
||||
}, [handleNewThread, keybindings, routeThreadId, state.projects, state.threads]);
|
||||
|
||||
const rootClassName = embedded
|
||||
? "sidebar flex h-full min-h-0 flex-col bg-card"
|
||||
: "sidebar flex h-full w-[260px] shrink-0 flex-col border-r border-border bg-card max-sm:w-[36vw] max-sm:min-w-[140px] max-sm:max-w-[200px]";
|
||||
|
||||
return (
|
||||
<aside className="sidebar flex h-full w-[260px] shrink-0 flex-col border-r border-border bg-card">
|
||||
<aside className={rootClassName}>
|
||||
{/* Branding */}
|
||||
<div
|
||||
className={`flex items-center gap-2.5 px-4 ${isElectron ? "drag-region h-[52px] pl-[76px]" : "py-4"}`}
|
||||
@@ -507,7 +515,7 @@ export default function Sidebar() {
|
||||
<span className="truncate text-sm font-semibold tracking-tight text-foreground">
|
||||
T3 <span className="font-normal text-muted-foreground">Code</span>
|
||||
</span>
|
||||
<span className="rounded-full bg-muted/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-widest text-muted-foreground/60">
|
||||
<span className="hidden rounded-full bg-muted/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-widest text-muted-foreground/60 sm:inline-block">
|
||||
{APP_STAGE_LABEL}
|
||||
</span>
|
||||
</div>
|
||||
@@ -563,7 +571,9 @@ export default function Sidebar() {
|
||||
<span className="flex-1 truncate text-xs font-medium text-foreground/90">
|
||||
{project.name}
|
||||
</span>
|
||||
<span className="text-[10px] text-muted-foreground/60">{threads.length}</span>
|
||||
<span className="hidden text-[10px] text-muted-foreground/60 sm:inline">
|
||||
{threads.length}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
{/* Threads */}
|
||||
@@ -627,7 +637,7 @@ export default function Sidebar() {
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
<span className="text-[10px] text-muted-foreground/40">
|
||||
<span className="hidden text-[10px] text-muted-foreground/40 sm:inline">
|
||||
{formatRelativeTime(thread.createdAt)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,698 @@
|
||||
"use client";
|
||||
|
||||
import { mergeProps } from "@base-ui/react/merge-props";
|
||||
import { useRender } from "@base-ui/react/use-render";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { PanelLeftIcon } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { Input } from "~/components/ui/input";
|
||||
import { ScrollArea } from "~/components/ui/scroll-area";
|
||||
import { Separator } from "~/components/ui/separator";
|
||||
import {
|
||||
Sheet,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetPopup,
|
||||
SheetTitle,
|
||||
} from "~/components/ui/sheet";
|
||||
import { Skeleton } from "~/components/ui/skeleton";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
|
||||
import { useMediaQuery } from "~/hooks/useMediaQuery";
|
||||
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
||||
const SIDEBAR_WIDTH = "16rem";
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
||||
const SIDEBAR_WIDTH_ICON = "3rem";
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
|
||||
|
||||
type SidebarContextProps = {
|
||||
state: "expanded" | "collapsed";
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
openMobile: boolean;
|
||||
setOpenMobile: (open: boolean) => void;
|
||||
isMobile: boolean;
|
||||
toggleSidebar: () => void;
|
||||
};
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextProps | null>(null);
|
||||
|
||||
function useSidebar() {
|
||||
const context = React.useContext(SidebarContext);
|
||||
if (!context) {
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.");
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
function SidebarProvider({
|
||||
defaultOpen = true,
|
||||
open: openProp,
|
||||
onOpenChange: setOpenProp,
|
||||
className,
|
||||
style,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
defaultOpen?: boolean;
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}) {
|
||||
const isMobile = useMediaQuery("(max-width: 767px)");
|
||||
const [openMobile, setOpenMobile] = React.useState(false);
|
||||
|
||||
// This is the internal state of the sidebar.
|
||||
// We use openProp and setOpenProp for control from outside the component.
|
||||
const [_open, _setOpen] = React.useState(defaultOpen);
|
||||
const open = openProp ?? _open;
|
||||
const setOpen = React.useCallback(
|
||||
async (value: boolean | ((value: boolean) => boolean)) => {
|
||||
const openState = typeof value === "function" ? value(open) : value;
|
||||
if (setOpenProp) {
|
||||
setOpenProp(openState);
|
||||
} else {
|
||||
_setOpen(openState);
|
||||
}
|
||||
|
||||
// This sets the cookie to keep the sidebar state.
|
||||
await cookieStore.set({
|
||||
expires: Date.now() + SIDEBAR_COOKIE_MAX_AGE * 1000,
|
||||
name: SIDEBAR_COOKIE_NAME,
|
||||
path: "/",
|
||||
value: String(openState),
|
||||
});
|
||||
},
|
||||
[setOpenProp, open],
|
||||
);
|
||||
|
||||
// Helper to toggle the sidebar.
|
||||
const toggleSidebar = React.useCallback(() => {
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
|
||||
}, [isMobile, setOpen]);
|
||||
|
||||
// Adds a keyboard shortcut to toggle the sidebar.
|
||||
React.useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
|
||||
event.preventDefault();
|
||||
toggleSidebar();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
}, [toggleSidebar]);
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed";
|
||||
|
||||
const contextValue = React.useMemo<SidebarContextProps>(
|
||||
() => ({
|
||||
isMobile,
|
||||
open,
|
||||
openMobile,
|
||||
setOpen,
|
||||
setOpenMobile,
|
||||
state,
|
||||
toggleSidebar,
|
||||
}),
|
||||
[state, open, setOpen, isMobile, openMobile, toggleSidebar],
|
||||
);
|
||||
|
||||
return (
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
<div
|
||||
className={cn(
|
||||
"group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",
|
||||
className,
|
||||
)}
|
||||
data-slot="sidebar-wrapper"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH,
|
||||
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||
...style,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</SidebarContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function Sidebar({
|
||||
side = "left",
|
||||
variant = "sidebar",
|
||||
collapsible = "offcanvas",
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
side?: "left" | "right";
|
||||
variant?: "sidebar" | "floating" | "inset";
|
||||
collapsible?: "offcanvas" | "icon" | "none";
|
||||
}) {
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
||||
|
||||
if (collapsible === "none") {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",
|
||||
className,
|
||||
)}
|
||||
data-slot="sidebar"
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Sheet onOpenChange={setOpenMobile} open={openMobile} {...props}>
|
||||
<SheetPopup
|
||||
className="w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
|
||||
data-mobile="true"
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar"
|
||||
side={side}
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetTitle>Sidebar</SheetTitle>
|
||||
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
</SheetPopup>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="group peer hidden text-sidebar-foreground md:block"
|
||||
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||
data-side={side}
|
||||
data-slot="sidebar"
|
||||
data-state={state}
|
||||
data-variant={variant}
|
||||
>
|
||||
{/* This is what handles the sidebar gap on desktop */}
|
||||
<div
|
||||
className={cn(
|
||||
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
||||
"group-data-[collapsible=offcanvas]:w-0",
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
|
||||
)}
|
||||
data-slot="sidebar-gap"
|
||||
/>
|
||||
<div
|
||||
className={cn(
|
||||
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
|
||||
side === "left"
|
||||
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||
// Adjust the padding for floating and inset variants.
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
className,
|
||||
)}
|
||||
data-slot="sidebar-container"
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
className="flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm/5"
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar-inner"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<Button
|
||||
className={cn("size-7", className)}
|
||||
data-sidebar="trigger"
|
||||
data-slot="sidebar-trigger"
|
||||
onClick={(event) => {
|
||||
onClick?.(event);
|
||||
toggleSidebar();
|
||||
}}
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<button
|
||||
aria-label="Toggle Sidebar"
|
||||
className={cn(
|
||||
"-translate-x-1/2 group-data-[side=left]:-right-4 absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=right]:left-0 sm:flex",
|
||||
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
||||
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||
"group-data-[collapsible=offcanvas]:translate-x-0 hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:after:left-full",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
className,
|
||||
)}
|
||||
data-sidebar="rail"
|
||||
data-slot="sidebar-rail"
|
||||
onClick={toggleSidebar}
|
||||
tabIndex={-1}
|
||||
title="Toggle Sidebar"
|
||||
type="button"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
return (
|
||||
<main
|
||||
className={cn(
|
||||
"relative flex w-full flex-1 flex-col bg-background",
|
||||
"md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ms-2 md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ms-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm/5",
|
||||
className,
|
||||
)}
|
||||
data-slot="sidebar-inset"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarInput({ className, ...props }: React.ComponentProps<typeof Input>) {
|
||||
return (
|
||||
<Input
|
||||
className={cn("h-8 w-full bg-background shadow-none", className)}
|
||||
data-sidebar="input"
|
||||
data-slot="sidebar-input"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
data-sidebar="header"
|
||||
data-slot="sidebar-header"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
data-sidebar="footer"
|
||||
data-slot="sidebar-footer"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
className={cn("mx-2 w-auto bg-sidebar-border", className)}
|
||||
data-sidebar="separator"
|
||||
data-slot="sidebar-separator"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<ScrollArea className="**:data-[slot=scroll-area-scrollbar]:hidden" scrollFade>
|
||||
<div
|
||||
className={cn(
|
||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
className,
|
||||
)}
|
||||
data-sidebar="content"
|
||||
data-slot="sidebar-content"
|
||||
{...props}
|
||||
/>
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
data-sidebar="group"
|
||||
data-slot="sidebar-group"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroupLabel({ className, render, ...props }: useRender.ComponentProps<"div">) {
|
||||
const defaultProps = {
|
||||
className: cn(
|
||||
"flex h-8 shrink-0 items-center rounded-lg px-2 font-medium text-sidebar-foreground text-xs outline-hidden ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||
className,
|
||||
),
|
||||
"data-sidebar": "group-label",
|
||||
"data-slot": "sidebar-group-label",
|
||||
};
|
||||
|
||||
return useRender({
|
||||
defaultTagName: "div",
|
||||
props: mergeProps(defaultProps, props),
|
||||
render,
|
||||
});
|
||||
}
|
||||
|
||||
function SidebarGroupAction({ className, render, ...props }: useRender.ComponentProps<"button">) {
|
||||
const defaultProps = {
|
||||
className: cn(
|
||||
"absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-lg p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg:not([class*='size-'])]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:-inset-2 after:absolute md:after:hidden",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className,
|
||||
),
|
||||
"data-sidebar": "group-action",
|
||||
"data-slot": "sidebar-group-action",
|
||||
};
|
||||
|
||||
return useRender({
|
||||
defaultTagName: "button",
|
||||
props: mergeProps(defaultProps, props),
|
||||
render,
|
||||
});
|
||||
}
|
||||
|
||||
function SidebarGroupContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn("w-full text-sm", className)}
|
||||
data-sidebar="group-content"
|
||||
data-slot="sidebar-group-content"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||
data-sidebar="menu"
|
||||
data-slot="sidebar-menu"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
className={cn("group/menu-item relative", className)}
|
||||
data-sidebar="menu-item"
|
||||
data-slot="sidebar-menu-item"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-lg p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pe-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg:not([class*='size-'])]:size-4 [&>svg]:shrink-0",
|
||||
{
|
||||
defaultVariants: {
|
||||
size: "default",
|
||||
variant: "default",
|
||||
},
|
||||
variants: {
|
||||
size: {
|
||||
default: "h-8 text-sm",
|
||||
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
||||
sm: "h-7 text-xs",
|
||||
},
|
||||
variant: {
|
||||
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
outline:
|
||||
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function SidebarMenuButton({
|
||||
isActive = false,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
tooltip,
|
||||
className,
|
||||
render,
|
||||
...props
|
||||
}: useRender.ComponentProps<"button"> & {
|
||||
isActive?: boolean;
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipPopup>;
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||
const { isMobile, state } = useSidebar();
|
||||
|
||||
const defaultProps = {
|
||||
className: cn(sidebarMenuButtonVariants({ size, variant }), className),
|
||||
"data-active": isActive,
|
||||
"data-sidebar": "menu-button",
|
||||
"data-size": size,
|
||||
"data-slot": "sidebar-menu-button",
|
||||
};
|
||||
|
||||
const buttonProps = mergeProps<"button">(defaultProps, props);
|
||||
|
||||
const buttonElement = useRender({
|
||||
defaultTagName: "button",
|
||||
props: buttonProps,
|
||||
render,
|
||||
});
|
||||
|
||||
if (!tooltip) {
|
||||
return buttonElement;
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={buttonElement as React.ReactElement<Record<string, unknown>>} />
|
||||
<TooltipPopup
|
||||
align="center"
|
||||
hidden={state !== "collapsed" || isMobile}
|
||||
side="right"
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuAction({
|
||||
className,
|
||||
showOnHover = false,
|
||||
render,
|
||||
...props
|
||||
}: useRender.ComponentProps<"button"> & {
|
||||
showOnHover?: boolean;
|
||||
}) {
|
||||
const defaultProps = {
|
||||
className: cn(
|
||||
"absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-lg p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg:not([class*='size-'])]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:-inset-2 after:absolute md:after:hidden",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
showOnHover &&
|
||||
"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
|
||||
className,
|
||||
),
|
||||
"data-sidebar": "menu-action",
|
||||
"data-slot": "sidebar-menu-action",
|
||||
};
|
||||
|
||||
return useRender({
|
||||
defaultTagName: "button",
|
||||
props: mergeProps<"button">(defaultProps, props),
|
||||
render,
|
||||
});
|
||||
}
|
||||
|
||||
function SidebarMenuBadge({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-lg px-1 font-medium text-sidebar-foreground text-xs tabular-nums",
|
||||
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className,
|
||||
)}
|
||||
data-sidebar="menu-badge"
|
||||
data-slot="sidebar-menu-badge"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSkeleton({
|
||||
className,
|
||||
showIcon = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showIcon?: boolean;
|
||||
}) {
|
||||
// Random width between 50 to 90%.
|
||||
const width = React.useMemo(() => {
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn("flex h-8 items-center gap-2 rounded-lg px-2", className)}
|
||||
data-sidebar="menu-skeleton"
|
||||
data-slot="sidebar-menu-skeleton"
|
||||
{...props}
|
||||
>
|
||||
{showIcon && <Skeleton className="size-4 rounded-lg" data-sidebar="menu-skeleton-icon" />}
|
||||
<Skeleton
|
||||
className="h-4 max-w-(--skeleton-width) flex-1"
|
||||
data-sidebar="menu-skeleton-text"
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": width,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
className={cn(
|
||||
"mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-sidebar-border border-l px-2.5 py-0.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className,
|
||||
)}
|
||||
data-sidebar="menu-sub"
|
||||
data-slot="sidebar-menu-sub"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSubItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
className={cn("group/menu-sub-item relative", className)}
|
||||
data-sidebar="menu-sub-item"
|
||||
data-slot="sidebar-menu-sub-item"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSubButton({
|
||||
size = "md",
|
||||
isActive = false,
|
||||
className,
|
||||
render,
|
||||
...props
|
||||
}: useRender.ComponentProps<"a"> & {
|
||||
size?: "sm" | "md";
|
||||
isActive?: boolean;
|
||||
}) {
|
||||
const defaultProps = {
|
||||
className: cn(
|
||||
"-translate-x-px flex h-7 min-w-0 items-center gap-2 overflow-hidden rounded-lg px-2 text-sidebar-foreground outline-hidden ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg:not([class*='size-'])]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
||||
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||
size === "sm" && "text-xs",
|
||||
size === "md" && "text-sm",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className,
|
||||
),
|
||||
"data-active": isActive,
|
||||
"data-sidebar": "menu-sub-button",
|
||||
"data-size": size,
|
||||
"data-slot": "sidebar-menu-sub-button",
|
||||
};
|
||||
|
||||
return useRender({
|
||||
defaultTagName: "a",
|
||||
props: mergeProps<"a">(defaultProps, props),
|
||||
render,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupAction,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarInput,
|
||||
SidebarInset,
|
||||
SidebarMenu,
|
||||
SidebarMenuAction,
|
||||
SidebarMenuBadge,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarMenuSkeleton,
|
||||
SidebarMenuSub,
|
||||
SidebarMenuSubButton,
|
||||
SidebarMenuSubItem,
|
||||
SidebarProvider,
|
||||
SidebarRail,
|
||||
SidebarSeparator,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
"use client";
|
||||
|
||||
import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";
|
||||
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
const TooltipCreateHandle = TooltipPrimitive.createHandle;
|
||||
|
||||
const TooltipProvider = TooltipPrimitive.Provider;
|
||||
|
||||
const Tooltip = TooltipPrimitive.Root;
|
||||
|
||||
function TooltipTrigger(props: TooltipPrimitive.Trigger.Props) {
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function TooltipPopup({
|
||||
className,
|
||||
align = "center",
|
||||
sideOffset = 4,
|
||||
side = "top",
|
||||
anchor,
|
||||
children,
|
||||
...props
|
||||
}: TooltipPrimitive.Popup.Props & {
|
||||
align?: TooltipPrimitive.Positioner.Props["align"];
|
||||
side?: TooltipPrimitive.Positioner.Props["side"];
|
||||
sideOffset?: TooltipPrimitive.Positioner.Props["sideOffset"];
|
||||
anchor?: TooltipPrimitive.Positioner.Props["anchor"];
|
||||
}) {
|
||||
return (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Positioner
|
||||
align={align}
|
||||
anchor={anchor}
|
||||
className="z-50 h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-[top,left,right,bottom,transform] data-instant:transition-none"
|
||||
data-slot="tooltip-positioner"
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
>
|
||||
<TooltipPrimitive.Popup
|
||||
className={cn(
|
||||
"relative flex h-(--popup-height,auto) w-(--popup-width,auto) origin-(--transform-origin) text-balance rounded-md border bg-popover not-dark:bg-clip-padding text-popover-foreground text-xs shadow-md/5 transition-[width,height,scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 data-instant:duration-0 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
||||
className,
|
||||
)}
|
||||
data-slot="tooltip-popup"
|
||||
{...props}
|
||||
>
|
||||
<TooltipPrimitive.Viewport
|
||||
className="relative size-full overflow-clip px-(--viewport-inline-padding) py-1 [--viewport-inline-padding:--spacing(2)] data-instant:transition-none **:data-current:data-ending-style:opacity-0 **:data-current:data-starting-style:opacity-0 **:data-previous:data-ending-style:opacity-0 **:data-previous:data-starting-style:opacity-0 **:data-current:w-[calc(var(--popup-width)-2*var(--viewport-inline-padding)-2px)] **:data-previous:w-[calc(var(--popup-width)-2*var(--viewport-inline-padding)-2px)] **:data-previous:truncate **:data-current:opacity-100 **:data-previous:opacity-100 **:data-current:transition-opacity **:data-previous:transition-opacity"
|
||||
data-slot="tooltip-viewport"
|
||||
>
|
||||
{children}
|
||||
</TooltipPrimitive.Viewport>
|
||||
</TooltipPrimitive.Popup>
|
||||
</TooltipPrimitive.Positioner>
|
||||
</TooltipPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
TooltipCreateHandle,
|
||||
TooltipProvider,
|
||||
Tooltip,
|
||||
TooltipTrigger,
|
||||
TooltipPopup,
|
||||
TooltipPopup as TooltipContent,
|
||||
};
|
||||
@@ -13,6 +13,18 @@ import { APP_DISPLAY_NAME } from "./branding";
|
||||
import { isElectron } from "./env";
|
||||
import { routeTree } from "./routeTree.gen";
|
||||
|
||||
if (!globalThis.crypto.randomUUID) {
|
||||
// https://stackoverflow.com/a/2117523/2800218
|
||||
// LICENSE: https://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
// oxlint-disable-next-line unicorn/consistent-function-scoping
|
||||
crypto.randomUUID = function randomUUID() {
|
||||
// @ts-expect-error -- Some cryptic stuff that this polyfill uses
|
||||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
||||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0]! & (15 >> (c / 4)))).toString(16),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
const history = isElectron ? createHashHistory() : createBrowserHistory();
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
@@ -28,7 +28,7 @@ function RootRouteView() {
|
||||
|
||||
if (!api) {
|
||||
return (
|
||||
<div className="flex h-screen flex-col bg-background text-foreground">
|
||||
<div className="flex h-dvh flex-col bg-background text-foreground">
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Connecting to {APP_DISPLAY_NAME} server...
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { Suspense, lazy, type ReactNode, useCallback, useEffect } from "react";
|
||||
import { Suspense, lazy, type CSSProperties, type ReactNode, useCallback, useEffect } from "react";
|
||||
|
||||
import ChatView from "../components/ChatView";
|
||||
import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch";
|
||||
import { useMediaQuery } from "../hooks/useMediaQuery";
|
||||
import { useStore } from "../store";
|
||||
import { Sheet, SheetPopup } from "../components/ui/sheet";
|
||||
import { Sidebar, SidebarProvider } from "../components/ui/sidebar";
|
||||
|
||||
const DiffPanel = lazy(() => import("../components/DiffPanel"));
|
||||
const DIFF_INLINE_LAYOUT_MEDIA_QUERY = "(max-width: 1180px)";
|
||||
@@ -53,6 +54,20 @@ function ChatThreadRouteView() {
|
||||
const threadExists = threadId ? state.threads.some((thread) => thread.id === threadId) : false;
|
||||
const diffOpen = search.diff === "1";
|
||||
const shouldUseDiffSheet = useMediaQuery(DIFF_INLINE_LAYOUT_MEDIA_QUERY);
|
||||
const setDiffOpen = useCallback(
|
||||
(open: boolean) => {
|
||||
if (open === diffOpen) return;
|
||||
void navigate({
|
||||
to: "/$threadId",
|
||||
params: { threadId },
|
||||
search: (previous) => {
|
||||
const rest = stripDiffSearchParams(previous);
|
||||
return open ? { ...rest, diff: "1" } : rest;
|
||||
},
|
||||
});
|
||||
},
|
||||
[diffOpen, navigate, threadId],
|
||||
);
|
||||
const closeDiff = useCallback(() => {
|
||||
void navigate({
|
||||
to: "/$threadId",
|
||||
@@ -83,26 +98,45 @@ function ChatThreadRouteView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
const diffLoadingFallback =
|
||||
!diffOpen || shouldUseDiffSheet ? (
|
||||
<div className="flex h-full min-h-0 items-center justify-center px-4 text-center text-xs text-muted-foreground/70">
|
||||
Loading diff viewer...
|
||||
</div>
|
||||
) : (
|
||||
<aside className="flex h-full w-[560px] shrink-0 items-center justify-center border-l border-border bg-card px-4 text-center text-xs text-muted-foreground/70">
|
||||
Loading diff viewer...
|
||||
</aside>
|
||||
const diffLoadingFallback = (
|
||||
<div className="flex h-full min-h-0 items-center justify-center px-4 text-center text-xs text-muted-foreground/70">
|
||||
Loading diff viewer...
|
||||
</div>
|
||||
);
|
||||
|
||||
if (shouldUseDiffSheet) {
|
||||
return (
|
||||
<>
|
||||
<ChatView threadId={threadId} />
|
||||
<DiffPanelWrapper sheet diffOpen={diffOpen} onCloseDiff={closeDiff}>
|
||||
<Suspense fallback={diffLoadingFallback}>
|
||||
<DiffPanel mode="sheet" />
|
||||
</Suspense>
|
||||
</DiffPanelWrapper>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex min-h-0 min-w-0 flex-1">
|
||||
<ChatView threadId={threadId} />
|
||||
<DiffPanelWrapper sheet={shouldUseDiffSheet} diffOpen={diffOpen} onCloseDiff={closeDiff}>
|
||||
<Suspense fallback={diffLoadingFallback}>
|
||||
<DiffPanel mode={shouldUseDiffSheet ? "sheet" : "inline"} />
|
||||
</Suspense>
|
||||
</DiffPanelWrapper>
|
||||
</>
|
||||
<SidebarProvider
|
||||
open={diffOpen}
|
||||
onOpenChange={setDiffOpen}
|
||||
className="w-0 min-w-0 flex-none"
|
||||
style={{ "--sidebar-width": "34rem" } as CSSProperties}
|
||||
>
|
||||
<Sidebar
|
||||
side="right"
|
||||
collapsible="offcanvas"
|
||||
className="border-l border-border bg-card text-foreground"
|
||||
>
|
||||
<Suspense fallback={diffLoadingFallback}>
|
||||
<DiffPanel mode="sheet" />
|
||||
</Suspense>
|
||||
</Sidebar>
|
||||
</SidebarProvider>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
|
||||
import { isElectron } from "../env";
|
||||
import { Separator } from "../components/ui/separator";
|
||||
import { SidebarTrigger } from "../components/ui/sidebar";
|
||||
|
||||
function ChatIndexRouteView() {
|
||||
return (
|
||||
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background text-muted-foreground/40">
|
||||
{!isElectron && (
|
||||
<header className="sticky top-0 z-20 flex h-11 shrink-0 items-center gap-2 border-b border-border/70 bg-background/95 px-2 backdrop-blur md:hidden">
|
||||
<SidebarTrigger className="size-8" />
|
||||
<Separator orientation="vertical" className="data-[orientation=vertical]:h-4" />
|
||||
<span className="truncate text-xs text-muted-foreground/75">Threads</span>
|
||||
</header>
|
||||
)}
|
||||
{isElectron && (
|
||||
<div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5">
|
||||
<span className="text-xs text-muted-foreground/50">No active thread</span>
|
||||
|
||||
@@ -2,7 +2,8 @@ import { Outlet, createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { DiffWorkerPoolProvider } from "../components/DiffWorkerPoolProvider";
|
||||
import Sidebar from "../components/Sidebar";
|
||||
import ThreadSidebar from "../components/Sidebar";
|
||||
import { Sidebar, SidebarInset, SidebarProvider } from "../components/ui/sidebar";
|
||||
|
||||
function ChatRouteLayout() {
|
||||
const navigate = useNavigate();
|
||||
@@ -24,16 +25,23 @@ function ChatRouteLayout() {
|
||||
}, [navigate]);
|
||||
|
||||
return (
|
||||
<div className="flex h-screen overflow-hidden bg-background text-foreground isolate">
|
||||
<Sidebar />
|
||||
<DiffWorkerPoolProvider>
|
||||
<Outlet />
|
||||
</DiffWorkerPoolProvider>
|
||||
</div>
|
||||
<SidebarProvider defaultOpen>
|
||||
<Sidebar
|
||||
side="left"
|
||||
collapsible="offcanvas"
|
||||
className="border-r border-border bg-card text-foreground"
|
||||
>
|
||||
<ThreadSidebar embedded />
|
||||
</Sidebar>
|
||||
<SidebarInset className="h-dvh min-h-0 overflow-hidden bg-background text-foreground isolate">
|
||||
<DiffWorkerPoolProvider>
|
||||
<Outlet />
|
||||
</DiffWorkerPoolProvider>
|
||||
</SidebarInset>
|
||||
</SidebarProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export const Route = createFileRoute("/_chat")({
|
||||
component: ChatRouteLayout,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { appendTokenFromPageUrl, resolveWsUrl } from "./wsTransport";
|
||||
|
||||
describe("resolveWsUrl", () => {
|
||||
it("prefers explicit url when provided", () => {
|
||||
const resolved = resolveWsUrl({
|
||||
explicitUrl: "ws://explicit.example:3773/socket",
|
||||
bridgeUrl: "ws://bridge.example:3773",
|
||||
envUrl: "ws://env.example:3773",
|
||||
pageUrl: "http://device.local:3773/?token=abc",
|
||||
pageProtocol: "http:",
|
||||
pageHostname: "device.local",
|
||||
pagePort: "3773",
|
||||
});
|
||||
|
||||
expect(resolved).toBe("ws://explicit.example:3773/socket");
|
||||
});
|
||||
|
||||
it("prefers desktop bridge url over env url", () => {
|
||||
const resolved = resolveWsUrl({
|
||||
bridgeUrl: "ws://bridge.example:3773",
|
||||
envUrl: "ws://env.example:3773",
|
||||
pageUrl: "http://device.local:3773/",
|
||||
pageProtocol: "http:",
|
||||
pageHostname: "device.local",
|
||||
pagePort: "3773",
|
||||
});
|
||||
|
||||
expect(resolved).toBe("ws://bridge.example:3773");
|
||||
});
|
||||
|
||||
it("falls back to env url when bridge url is missing", () => {
|
||||
const resolved = resolveWsUrl({
|
||||
envUrl: "ws://env.example:3773/path",
|
||||
pageUrl: "http://device.local:3773/",
|
||||
pageProtocol: "http:",
|
||||
pageHostname: "device.local",
|
||||
pagePort: "3773",
|
||||
});
|
||||
|
||||
expect(resolved).toBe("ws://env.example:3773/path");
|
||||
});
|
||||
|
||||
it("derives wss url from https page when no explicit, bridge, or env url exists", () => {
|
||||
const resolved = resolveWsUrl({
|
||||
pageUrl: "https://tailnet-host.ts.net/",
|
||||
pageProtocol: "https:",
|
||||
pageHostname: "tailnet-host.ts.net",
|
||||
pagePort: "",
|
||||
});
|
||||
|
||||
expect(resolved).toBe("wss://tailnet-host.ts.net");
|
||||
});
|
||||
|
||||
it("adds token from page url when missing on websocket url", () => {
|
||||
const resolved = resolveWsUrl({
|
||||
envUrl: "ws://tailnet-host.ts.net:3773",
|
||||
pageUrl: "http://tailnet-host.ts.net:3773/?token=super-secret",
|
||||
pageProtocol: "http:",
|
||||
pageHostname: "tailnet-host.ts.net",
|
||||
pagePort: "3773",
|
||||
});
|
||||
|
||||
expect(resolved).toBe("ws://tailnet-host.ts.net:3773/?token=super-secret");
|
||||
});
|
||||
|
||||
it("does not overwrite existing websocket token", () => {
|
||||
const resolved = resolveWsUrl({
|
||||
envUrl: "ws://tailnet-host.ts.net:3773/?token=already-set",
|
||||
pageUrl: "http://tailnet-host.ts.net:3773/?token=super-secret",
|
||||
pageProtocol: "http:",
|
||||
pageHostname: "tailnet-host.ts.net",
|
||||
pagePort: "3773",
|
||||
});
|
||||
|
||||
expect(resolved).toBe("ws://tailnet-host.ts.net:3773/?token=already-set");
|
||||
});
|
||||
});
|
||||
|
||||
describe("appendTokenFromPageUrl", () => {
|
||||
it("returns original url for invalid page urls", () => {
|
||||
expect(appendTokenFromPageUrl("ws://localhost:3773", "not-a-url")).toBe("ws://localhost:3773");
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,56 @@ interface PendingRequest {
|
||||
const REQUEST_TIMEOUT_MS = 60_000;
|
||||
const RECONNECT_DELAYS_MS = [500, 1_000, 2_000, 4_000, 8_000];
|
||||
|
||||
interface WsUrlResolutionInput {
|
||||
explicitUrl?: string;
|
||||
bridgeUrl?: string | null;
|
||||
envUrl?: string;
|
||||
pageUrl: string;
|
||||
pageProtocol: string;
|
||||
pageHostname: string;
|
||||
pagePort: string;
|
||||
}
|
||||
|
||||
function normalizeUrl(value: string | null | undefined): string | undefined {
|
||||
if (!value) return undefined;
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
|
||||
function defaultWsUrlForPage(protocol: string, hostname: string, port: string): string {
|
||||
const wsProtocol = protocol === "https:" ? "wss" : "ws";
|
||||
const authority = port.length > 0 ? `${hostname}:${port}` : hostname;
|
||||
return `${wsProtocol}://${authority}`;
|
||||
}
|
||||
|
||||
export function appendTokenFromPageUrl(wsUrl: string, pageUrl: string): string {
|
||||
try {
|
||||
const page = new URL(pageUrl);
|
||||
const token = page.searchParams.get("token")?.trim();
|
||||
if (!token) return wsUrl;
|
||||
|
||||
const resolvedWsUrl = new URL(wsUrl, page.origin);
|
||||
if (!resolvedWsUrl.searchParams.has("token")) {
|
||||
resolvedWsUrl.searchParams.set("token", token);
|
||||
}
|
||||
return resolvedWsUrl.toString();
|
||||
} catch {
|
||||
return wsUrl;
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveWsUrl(input: WsUrlResolutionInput): string {
|
||||
const explicitUrl = normalizeUrl(input.explicitUrl);
|
||||
if (explicitUrl) return explicitUrl;
|
||||
|
||||
const baseUrl =
|
||||
normalizeUrl(input.bridgeUrl) ??
|
||||
normalizeUrl(input.envUrl) ??
|
||||
defaultWsUrlForPage(input.pageProtocol, input.pageHostname, input.pagePort);
|
||||
|
||||
return appendTokenFromPageUrl(baseUrl, input.pageUrl);
|
||||
}
|
||||
|
||||
export class WsTransport {
|
||||
private ws: WebSocket | null = null;
|
||||
private nextId = 1;
|
||||
@@ -26,13 +76,15 @@ export class WsTransport {
|
||||
// In dev mode, VITE_WS_URL points to the server's WebSocket endpoint.
|
||||
// In production, the page is served by the WS server on the same host:port.
|
||||
const envUrl = import.meta.env.VITE_WS_URL as string | undefined;
|
||||
this.url =
|
||||
url ??
|
||||
(bridgeUrl && bridgeUrl.length > 0
|
||||
? bridgeUrl
|
||||
: envUrl && envUrl.length > 0
|
||||
? envUrl
|
||||
: `ws://${window.location.hostname}:${window.location.port}`);
|
||||
this.url = resolveWsUrl({
|
||||
explicitUrl: url,
|
||||
bridgeUrl,
|
||||
envUrl,
|
||||
pageUrl: window.location.href,
|
||||
pageProtocol: window.location.protocol,
|
||||
pageHostname: window.location.hostname,
|
||||
pagePort: window.location.port,
|
||||
});
|
||||
this.connect();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import { tanstackRouter } from "@tanstack/router-plugin/vite";
|
||||
import { defineConfig } from "vite";
|
||||
|
||||
const port = Number(process.env.PORT ?? 5173);
|
||||
const devServerHost = process.env.VITE_DEV_SERVER_HOST ?? "localhost";
|
||||
const hmrHost = process.env.VITE_HMR_HOST ?? "localhost";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
@@ -29,6 +31,7 @@ export default defineConfig({
|
||||
tsconfigPaths: true,
|
||||
},
|
||||
server: {
|
||||
host: devServerHost,
|
||||
port,
|
||||
strictPort: true,
|
||||
hmr: {
|
||||
@@ -36,7 +39,7 @@ export default defineConfig({
|
||||
// inside Electron's BrowserWindow. Vite 8 uses console.debug for
|
||||
// connection logs — enable "Verbose" in DevTools to see them.
|
||||
protocol: "ws",
|
||||
host: "localhost",
|
||||
host: hmrHost,
|
||||
},
|
||||
},
|
||||
build: {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
# Remote Access Guide (Server on Computer, Client on Phone)
|
||||
|
||||
This guide explains how to run T3 Code on one machine and control it from another device (for example, your phone) over a private network like Tailscale.
|
||||
|
||||
## Goal
|
||||
|
||||
- Run the `apps/server` process on your computer.
|
||||
- Open the web client from another device.
|
||||
- Keep Codex running on the computer while controlling it remotely.
|
||||
|
||||
## Architecture
|
||||
|
||||
T3 Code is already split into backend and frontend roles:
|
||||
|
||||
- Backend (`apps/server`):
|
||||
- Runs on your computer.
|
||||
- Hosts HTTP pages + static assets.
|
||||
- Hosts the WebSocket API.
|
||||
- Spawns and manages Codex app-server sessions.
|
||||
- Reads/writes local state and your local workspace files.
|
||||
- Frontend (`apps/web`):
|
||||
- Runs in the browser on any device.
|
||||
- Connects to backend over WebSocket.
|
||||
- Renders thread state and sends commands.
|
||||
|
||||
Data path:
|
||||
|
||||
1. Phone browser opens `http://<computer-tailnet-host>:<port>`.
|
||||
2. Browser loads the T3 web app from that server.
|
||||
3. Web app opens a WebSocket to the same server.
|
||||
4. Server executes provider/terminal/git/file actions on the computer.
|
||||
5. Server streams updates back to the phone.
|
||||
|
||||
Important: your phone never runs Codex itself. The agent process stays on the computer.
|
||||
|
||||
## Security Model
|
||||
|
||||
- Recommended network boundary: Tailscale tailnet ACLs.
|
||||
- Optional app-layer auth: set `T3CODE_AUTH_TOKEN` on server start.
|
||||
- When `T3CODE_AUTH_TOKEN` is enabled, open the UI with `?token=<token>` in the URL so the browser can authenticate WebSocket requests.
|
||||
|
||||
Example:
|
||||
|
||||
`http://my-macbook.tailnet-name.ts.net:3773/?token=<your-token>`
|
||||
|
||||
## Recommended Setup (Production Build)
|
||||
|
||||
Use this for reliable "control from phone while away from home".
|
||||
|
||||
### 1. Prepare computer
|
||||
|
||||
- Ensure Codex CLI is installed and authenticated on the computer.
|
||||
- Ensure Tailscale is connected on the computer.
|
||||
- Build the app:
|
||||
|
||||
```bash
|
||||
bun run build
|
||||
```
|
||||
|
||||
### 2. Start server
|
||||
|
||||
- Choose a port (default is `3773`).
|
||||
- Create an auth token (recommended).
|
||||
|
||||
```bash
|
||||
export T3CODE_PORT=3773
|
||||
export T3CODE_NO_BROWSER=1
|
||||
export T3CODE_AUTH_TOKEN="$(openssl rand -hex 24)"
|
||||
bun run start
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- `T3CODE_NO_BROWSER=1` avoids auto-opening a local browser tab.
|
||||
- Without `T3CODE_AUTH_TOKEN`, anyone with network reachability to your server can open a session.
|
||||
|
||||
### 3. Find Tailscale address of computer
|
||||
|
||||
```bash
|
||||
tailscale ip -4
|
||||
```
|
||||
|
||||
Or use MagicDNS hostname (for example `my-macbook.tailnet-name.ts.net`).
|
||||
|
||||
### 4. Open from phone
|
||||
|
||||
- Ensure your phone is connected to the same Tailscale tailnet.
|
||||
- In phone browser, open:
|
||||
|
||||
```text
|
||||
http://<tailscale-host-or-ip>:3773/?token=<T3CODE_AUTH_TOKEN>
|
||||
```
|
||||
|
||||
You should now control the agent running on your computer.
|
||||
|
||||
## Remote Dev Setup (Hot Reload)
|
||||
|
||||
This repo now supports remote dev host wiring directly.
|
||||
|
||||
### 1. Pick the public host
|
||||
|
||||
Use the computer's Tailscale hostname or IP as `T3CODE_PUBLIC_HOST`.
|
||||
|
||||
### 2. Run dev mode
|
||||
|
||||
```bash
|
||||
T3CODE_PUBLIC_HOST=my-macbook.tailnet-name.ts.net bun run dev
|
||||
```
|
||||
|
||||
What this config does:
|
||||
|
||||
- Vite dev server is reachable off-machine (`0.0.0.0` bind).
|
||||
- Server redirects to the public dev URL instead of localhost.
|
||||
- WebSocket target uses the same public host instead of localhost.
|
||||
- HMR uses the public host for browser reconnects.
|
||||
|
||||
If you also use auth token in dev:
|
||||
|
||||
1. set `T3CODE_AUTH_TOKEN=...` before running `bun run dev`
|
||||
2. open `http://<host>:<web-port>/?token=<token>`
|
||||
|
||||
## Operational Tips
|
||||
|
||||
- Keep the server process running in `tmux`, `screen`, or a service manager.
|
||||
- Use a long, random auth token.
|
||||
- Restrict tailnet access using Tailscale ACLs to only your user/devices.
|
||||
- Prefer production build for lower moving parts when remote.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Page loads but no data:
|
||||
- Most likely missing/incorrect `?token=` when `T3CODE_AUTH_TOKEN` is set.
|
||||
- Phone cannot reach host:
|
||||
- Verify both devices are connected to Tailscale and can ping each other.
|
||||
- Dev mode opens localhost URL:
|
||||
- Ensure `T3CODE_PUBLIC_HOST` is set before `bun run dev`.
|
||||
- Live reload not working in remote dev:
|
||||
- Ensure `T3CODE_PUBLIC_HOST` resolves on the phone and no conflicting port overrides are set.
|
||||
+26
-3
@@ -58,6 +58,19 @@ function resolveOffset() {
|
||||
return { offset, source: `hashed T3CODE_DEV_INSTANCE=${seed}` };
|
||||
}
|
||||
|
||||
function resolvePublicHost() {
|
||||
const rawHost = process.env.T3CODE_PUBLIC_HOST?.trim();
|
||||
if (!rawHost) return undefined;
|
||||
|
||||
if (rawHost.includes("://") || rawHost.includes("/")) {
|
||||
throw new Error(
|
||||
`Invalid T3CODE_PUBLIC_HOST: ${rawHost}. Use only a host or IP (no protocol/path).`,
|
||||
);
|
||||
}
|
||||
|
||||
return rawHost;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const mode = process.argv[2];
|
||||
const isDryRun = process.argv.includes("--dry-run");
|
||||
@@ -69,6 +82,9 @@ function main() {
|
||||
const { offset, source } = resolveOffset();
|
||||
const serverPort = BASE_SERVER_PORT + offset;
|
||||
const webPort = BASE_WEB_PORT + offset;
|
||||
const publicHost = resolvePublicHost();
|
||||
const wsHost = publicHost ?? "localhost";
|
||||
const webHost = publicHost ?? "localhost";
|
||||
|
||||
if (serverPort > 65535 || webPort > 65535) {
|
||||
throw new Error(
|
||||
@@ -81,15 +97,22 @@ function main() {
|
||||
T3CODE_PORT: String(serverPort),
|
||||
PORT: String(webPort),
|
||||
ELECTRON_RENDERER_PORT: String(webPort),
|
||||
VITE_WS_URL: `ws://localhost:${serverPort}`,
|
||||
VITE_DEV_SERVER_URL: `http://localhost:${webPort}`,
|
||||
VITE_WS_URL: `ws://${wsHost}:${serverPort}`,
|
||||
VITE_DEV_SERVER_URL: `http://${webHost}:${webPort}`,
|
||||
};
|
||||
|
||||
if (publicHost) {
|
||||
env.VITE_DEV_SERVER_HOST = "0.0.0.0";
|
||||
env.VITE_HMR_HOST = publicHost;
|
||||
}
|
||||
|
||||
if (mode === "dev" && !env.T3CODE_LOG_WS_EVENTS) {
|
||||
env.T3CODE_LOG_WS_EVENTS = "1";
|
||||
}
|
||||
|
||||
console.info(
|
||||
`[dev-runner] mode=${mode} source=${source} serverPort=${serverPort} webPort=${webPort}`,
|
||||
`[dev-runner] mode=${mode} source=${source} serverPort=${serverPort} webPort=${webPort}` +
|
||||
`${publicHost ? ` publicHost=${publicHost}` : ""}`,
|
||||
);
|
||||
|
||||
if (isDryRun) {
|
||||
|
||||
Reference in new issue
Block a user