The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(chat): handle missing thread transcript gracefully
Steven Enamakel3dc15531f489
diff --git a/app/src/components/assistant-ui/elements/inline-citation.tsx b/app/src/components/assistant-ui/elements/inline-citation.tsxnew file mode 100644index 0000000000..099a82843b--- /dev/null+++ b/app/src/components/assistant-ui/elements/inline-citation.tsx@@ -0,0 +1,93 @@+'use client';++/**+ * Vendored from the assistant-ui `elements-inline-citation` registry item+ * (https://r.assistant-ui.com/styles/base-nova/elements-inline-citation.json).+ *+ * Upstream ships this as a specimen: one hard-coded paragraph with two+ * citation markers stitched into fixed sentence positions, purely to show the+ * hover-card interaction. That shape does not fit a real caller, which needs+ * to drop a `[n]` marker into arbitrary markdown-rendered text at the offset+ * where the model wrote it. Refactor from the specimen (minimal, allowed+ * change per the vendoring rules):+ * - The fixed `<p>` + two inline `<Citation>` calls is replaced by+ * `CitationMarker`, a single exported marker component keyed by `index`+ * into a `sources` array. A caller renders one per `[n]`/`[^n]` token it+ * finds in the message text (see `markdown-text.tsx`).+ * - `open`/`onOpenChange` become optional; omitted, the marker manages its+ * own hover-card state (`useState`) so callers with many independent+ * markers scattered through prose don't have to lift index-keyed state.+ * - `cn` import path (`@/components/assistant-ui/lib/utils`); `./surfaces` ->+ * sibling `surfaces.tsx` (unchanged import shape).+ * - The upstream `InlineCitationProps`/`InlineCitation` demo wrapper is+ * dropped; `Source` (renamed `CitationSource` to avoid a name clash with+ * `sources.aui.tsx`'s `Source`) and `CitationMarker` are the public API.+ */+import { PreviewCard } from '@base-ui/react/preview-card';+import type { ComponentProps } from 'react';++import { cn } from '@/components/assistant-ui/lib/utils';++import { floating, mono } from './surfaces';++export interface CitationSource {+ domain: string;+ title: string;+ snippet: string;+}++export interface CitationMarkerProps extends Omit<ComponentProps<'button'>, 'children' | 'onOpenChange'> {+ /** 0-based position, rendered as `index + 1`. */+ index: number;+ source: CitationSource;+ open?: boolean;+ onOpenChange?: (open: boolean) => void;+}++/** One `[n]` marker with a hover card showing the cited source. */+export function CitationMarker({+ index,+ source,+ open,+ onOpenChange,+ className,+ ...props+}: CitationMarkerProps) {+ return (+ <PreviewCard.Root open={open} onOpenChange={onOpenChange}>+ <PreviewCard.Trigger+ delay={0}+ render={<button type="button" {...props} />}+ className={cn(+ 'mx-0.5 inline-flex h-4 min-w-4 translate-y-[-2px] cursor-default items-center justify-center rounded-[5px] px-1 align-middle font-mono text-[10px] font-medium tabular-nums transition-colors',+ open+ ? 'bg-foreground text-background'+ : 'bg-foreground/[0.06] text-foreground/45 hover:text-foreground/90',+ className+ )}>+ {index + 1}+ </PreviewCard.Trigger>+ <PreviewCard.Portal>+ <PreviewCard.Positioner side="top" sideOffset={8}>+ <PreviewCard.Popup+ className={cn(+ floating,+ 'z-50 w-64 origin-(--transform-origin) rounded-2xl p-3.5 outline-none',+ 'transition-[opacity,scale] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none',+ 'data-[starting-style]:scale-[0.97] data-[starting-style]:opacity-0',+ 'data-[ending-style]:scale-[0.97] data-[ending-style]:opacity-0'+ )}>+ <div className="flex items-center gap-1.5">+ <span className="bg-foreground/[0.06] text-foreground/45 flex size-4 items-center justify-center rounded text-[9px] font-medium">+ {source.domain[0]?.toUpperCase()}+ </span>+ <span className={cn(mono, 'text-foreground/40')}>{source.domain}</span>+ </div>+ <p className="mt-2 text-[13px] leading-snug font-medium">{source.title}</p>+ <p className="text-foreground/50 mt-1 text-[13px] leading-relaxed">{source.snippet}</p>+ </PreviewCard.Popup>+ </PreviewCard.Positioner>+ </PreviewCard.Portal>+ </PreviewCard.Root>+ );+}diff --git a/app/src/components/assistant-ui/elements/todo-list.tsx b/app/src/components/assistant-ui/elements/todo-list.tsxnew file mode 100644index 0000000000..c1acc310f7--- /dev/null+++ b/app/src/components/assistant-ui/elements/todo-list.tsx@@ -0,0 +1,97 @@+'use client';++/**+ * A checklist of the agent's steps for the current thread, ticking off as it+ * works.+ *+ * Vendored from the assistant-ui `elements-todo-list` registry item+ * (https://r.assistant-ui.com/styles/base-nova/elements-todo-list.json).+ * Changes from upstream:+ * - `cn` import path (`@/components/assistant-ui/lib/utils`).+ * - The header text `"Todos"` is a prop (`title`) with that English default,+ * so the caller (`TodoListPart` in+ * `features/conversations/aui/TodoListPart.tsx`) supplies the translated+ * string via `useT()`.+ */+import { cn } from '@/components/assistant-ui/lib/utils';+import { CheckIcon, Loader2Icon, XIcon } from 'lucide-react';+import type { ComponentProps } from 'react';++import { mono } from './surfaces';++export type TodoStatus = 'pending' | 'active' | 'done' | 'failed';++export interface TodoItem {+ id: string;+ text: string;+ status: TodoStatus;+ reason?: string;+}++export function TodoList({+ items,+ revision,+ title = 'Todos',+ className,+ ...props+}: Omit<ComponentProps<'div'>, 'children' | 'items' | 'revision' | 'title'> & {+ items: readonly TodoItem[];+ revision?: number;+ title?: string;+}) {+ const done = items.filter(item => item.status === 'done').length;++ return (+ <div+ data-slot="todo-list"+ className={cn('flex w-full max-w-sm flex-col gap-3', className)}+ {...props}>+ <div className="flex items-baseline justify-between">+ <span className="text-[13.5px] font-medium">{title}</span>+ <span className={cn(mono, 'text-foreground/35 tabular-nums')}>+ {revision === undefined+ ? `${done}/${items.length}`+ : `${done}/${items.length} · rev ${revision}`}+ </span>+ </div>+ <ul className="flex flex-col gap-1">+ {items.map(item => (+ <li+ key={item.id}+ className="fade-in slide-in-from-bottom-1 animate-in fill-mode-both flex items-start gap-2.5 py-0.5 text-[13.5px] duration-300">+ <span aria-hidden className="flex size-4 h-5 shrink-0 items-center justify-center">+ {item.status === 'done' ? (+ <span className="border-foreground/20 bg-foreground/[0.06] flex size-3.5 items-center justify-center rounded-[5px] border">+ <CheckIcon className="text-foreground/45 size-2.5" />+ </span>+ ) : item.status === 'failed' ? (+ <span className="flex size-3.5 items-center justify-center rounded-[5px] border border-red-600/25 bg-red-600/[0.08] dark:border-red-400/25 dark:bg-red-400/[0.08]">+ <XIcon className="size-2.5 text-red-600 dark:text-red-400" />+ </span>+ ) : item.status === 'active' ? (+ <Loader2Icon className="size-3.5 animate-spin text-blue-500 motion-reduce:animate-none dark:text-blue-400" />+ ) : (+ <span className="border-foreground/15 size-3.5 rounded-[5px] border" />+ )}+ </span>+ <span className="sr-only">{item.status}</span>+ <div className="min-w-0 flex-1 leading-5 break-words">+ <span+ className={cn(+ item.status === 'done' && 'text-foreground/35 line-through decoration-[1.5px]',+ item.status === 'active' && 'text-foreground/90',+ item.status === 'pending' && 'text-foreground/50',+ item.status === 'failed' && 'text-red-600 dark:text-red-400'+ )}>+ {item.text}+ </span>+ {item.status === 'failed' && item.reason ? (+ <p className="text-foreground/45 text-xs leading-4 break-words">{item.reason}</p>+ ) : null}+ </div>+ </li>+ ))}+ </ul>+ </div>+ );+}diff --git a/app/src/services/chatService.ts b/app/src/services/chatService.tsindex 3039e3edfb..daf42fd615 100644--- a/app/src/services/chatService.ts+++ b/app/src/services/chatService.ts@@ -240,6 +240,48 @@ export interface ChatApprovalRequestEvent {* exact command/target from this so the user sees precisely what will run.*/args?: Record<string, unknown>;+ /**+ * The parked call's own tool-call id (wire contract: `DomainEvent::+ * ApprovalRequested.tool_call_id`, additive). Lets the approval attach to+ * the EXACT tool-call part it gates rather than the newest-unresolved-by-+ * name heuristic (`assistantUiMessages.ts`'s `withApproval`). May be absent+ * on a core that has not landed the C2 approvals workstream yet — every+ * reader must treat it as optional.+ */+ tool_call_id?: string;+ /**+ * RFC3339 timestamp the gate's TTL expires at (wire contract:+ * `DomainEvent::ApprovalRequested.expires_at`, additive). Drives the+ * expiry countdown on the approval card. Absent on an older core.+ */+ expires_at?: string;+}++/**+ * Emitted when a parked approval is resolved by any path — an interactive+ * decision routed through the RPC, the gate's TTL expiring with nobody+ * answering, or an external cancel (thread deleted, turn superseded). Bridged+ * from the Rust `DomainEvent::ApprovalDecided` (wire contract: additive+ * `thread_id`/`client_id`/`tool_call_id`). Distinct from the client's own+ * optimistic clear on a successful `openhuman.approval_decide` call: this is+ * the SERVER's record of the outcome, and is the only signal for a TTL+ * expiry or an approval decided by another connected client.+ */+export interface ChatApprovalDecidedEvent {+ thread_id?: string;+ client_id?: string;+ request_id: string;+ /** The gated call's tool-call id, when the core attached one (see above). */+ tool_call_id?: string;+ /** Human-readable summary of how the request was resolved. */+ message?: string;+ /**+ * The terminal outcome. `'expired'` / `'cancelled'` map onto assistant-ui's+ * own `ToolCallMessagePart.approval.resolution` union; any other value+ * (e.g. a plain decision echo) is treated as an ordinary resolved decision+ * with no special terminal state.+ */+ resolution?: 'expired' | 'cancelled' | string;}/**@@ -618,6 +660,7 @@ export interface ChatEventListeners {onToolArgsDelta?: (event: ChatToolArgsDeltaEvent) => void;onProactiveMessage?: (event: ProactiveMessageEvent) => void;onApprovalRequest?: (event: ChatApprovalRequestEvent) => void;+ onApprovalDecided?: (event: ChatApprovalDecidedEvent) => void;onPlanReviewRequest?: (event: ChatPlanReviewRequestEvent) => void;onArtifactPending?: (event: ArtifactPendingEvent) => void;onArtifactReady?: (event: ArtifactReadyEvent) => void;diff --git a/crates/openhuman-core/src/threads/transcript_view/project.rs b/crates/openhuman-core/src/threads/transcript_view/project.rsindex 0af53ab9e6..c1eb7236e4 100644--- a/crates/openhuman-core/src/threads/transcript_view/project.rs+++ b/crates/openhuman-core/src/threads/transcript_view/project.rs@@ -37,7 +37,12 @@ type NativeToolEnvelope = (String, Vec<NativeToolCall>);/// no root transcript yet (brand-new thread / first turn not persisted).pub fn project_thread(workspace_dir: &Path, thread_id: &str) -> Option<ProjectedTranscript> {let (root_paths, sub_paths) = resolve_files(workspace_dir, thread_id)?;- Some(project_from_files(thread_id, &root_paths, &sub_paths))+ Some(project_from_files(+ thread_id,+ &root_paths,+ &sub_paths,+ Some(workspace_dir),+ ))}/// Resolve the on-disk file set backing a thread's transcript view: the root