Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(chat): add document source support and handle approval expiry

Steven Enamakel96a833c70c60
diff --git a/app/src/components/assistant-ui/elements/image-generation.tsx b/app/src/components/assistant-ui/elements/image-generation.tsx
new file mode 100644
index 0000000000..37188099c9
--- /dev/null
+++ b/app/src/components/assistant-ui/elements/image-generation.tsx
@@ -0,0 +1,105 @@
+'use client';
+
+/**
+ * assistant-ui's image-generation element: a placeholder canvas with a
+ * shimmering dot grid and gradient wash while an image generates, settling
+ * into the prompt text and a regenerate button once it's done.
+ *
+ * Vendored from the assistant-ui `elements-image-generation` registry item
+ * (https://r.assistant-ui.com/styles/base-nova/elements-image-generation.json).
+ * Changes from upstream:
+ * - `cn` import path and `./surfaces` resolved through this app's alias.
+ * - `generatingLabel` / `regenerateLabel` props (English defaults supplied
+ * by the caller via `useT()`) replace the hardcoded "Generating" /
+ * "Regenerate image" strings.
+ * - `onRegenerate` is optional; the button renders disabled/inert when
+ * absent instead of upstream's always-present no-op button.
+ * - `dimensions` prop (default `"1024 × 1024"`) replaces the hardcoded size
+ * label, since OpenHuman's image tool can return other sizes.
+ */
+import type { ComponentProps } from 'react';
+import { RefreshCwIcon } from 'lucide-react';
+import { cn } from '@/components/assistant-ui/lib/utils';
+import { ghostButton, mono, paper, ShimmerLabel } from '@/components/assistant-ui/elements/surfaces';
+
+const DOTS = Array.from({ length: 64 }, (_, i) => i);
+
+export interface ImageGenerationProps
+ extends Omit<ComponentProps<'div'>, 'children' | 'prompt' | 'generating'> {
+ prompt: string;
+ generating: boolean;
+ dimensions?: string;
+ generatingLabel?: string;
+ regenerateLabel?: string;
+ onRegenerate?: () => void;
+}
+
+export function ImageGeneration({
+ prompt,
+ generating,
+ dimensions = '1024 × 1024',
+ generatingLabel = 'Generating',
+ regenerateLabel = 'Regenerate image',
+ onRegenerate,
+ className,
+ ...props
+}: ImageGenerationProps) {
+ return (
+ <div data-slot="image-generation" className={cn('flex w-52 flex-col gap-2.5', className)} {...props}>
+ <div className={cn(paper, 'relative aspect-square w-full overflow-hidden rounded-2xl')}>
+ <div className="absolute inset-0 grid grid-cols-8 place-items-center p-6" aria-hidden>
+ {DOTS.map(dot => {
+ const row = Math.floor(dot / 8);
+ const col = dot % 8;
+ return (
+ <span
+ key={dot}
+ className={cn(
+ 'bg-foreground/20 size-1 rounded-full transition-opacity duration-500',
+ generating ? 'animate-pulse motion-reduce:animate-none' : 'opacity-0'
+ )}
+ style={{ animationDelay: `${(row + col) * 90}ms` }}
+ />
+ );
+ })}
+ </div>
+ <div
+ aria-hidden
+ className={cn(
+ 'absolute inset-0 transition-[opacity,filter] duration-1000 ease-out motion-reduce:transition-none',
+ generating ? 'opacity-0 blur-xl' : 'blur-0 opacity-100'
+ )}
+ style={{
+ background:
+ 'radial-gradient(120% 90% at 20% 100%, oklch(0.45 0.09 265) 0%, transparent 55%), radial-gradient(110% 80% at 85% 90%, oklch(0.62 0.1 300 / 0.8) 0%, transparent 60%), radial-gradient(130% 100% at 60% 0%, oklch(0.88 0.06 60) 0%, oklch(0.74 0.09 25 / 0.9) 45%, transparent 75%), linear-gradient(to top, oklch(0.35 0.06 275), oklch(0.82 0.07 50))',
+ }}
+ />
+ <span
+ className={cn(
+ mono,
+ 'absolute end-2.5 top-2.5 tabular-nums',
+ generating ? 'text-foreground/35' : 'text-white/70'
+ )}>
+ {dimensions}
+ </span>
+ </div>
+ <div className="flex items-center justify-between gap-2">
+ <p className="text-foreground/45 min-w-0 flex-1 truncate text-xs">
+ {generating ? (
+ <ShimmerLabel className="relative">{generatingLabel}</ShimmerLabel>
+ ) : (
+ prompt
+ )}
+ </p>
+ <button
+ type="button"
+ aria-label={regenerateLabel}
+ disabled={!onRegenerate}
+ onClick={onRegenerate}
+ className={cn(ghostButton, 'size-6 shrink-0', generating && 'pointer-events-none opacity-0')}>
+ <RefreshCwIcon className="size-3" />
+ </button>
+ </div>
+ </div>
+ );
+}
diff --git a/app/src/features/conversations/components/aui/ChatSources.tsx b/app/src/features/conversations/components/aui/ChatSources.tsx
index 3a6e190f76..8838501425 100644
--- a/app/src/features/conversations/components/aui/ChatSources.tsx
+++ b/app/src/features/conversations/components/aui/ChatSources.tsx
@@ -1,43 +1,44 @@
/**
- * The web sources a turn visited, as one collapsed disclosure under its answer.
+ * The sources a turn drew on, as one row of source badges under its answer:
+ * `url` sources (web fetch/search) and `document` sources (memory citations).
*
- * The sources arrive as assistant-ui `source` parts, emitted by `assistantParts`
- * (`providers/assistantUiMessages.ts`) through `extractAgentSources`, which is
- * the one place a model-supplied URL is admitted (http(s) only) — the `url` is a
- * raw tool-call argument and so prompt-injection-influenceable. `Thread` groups
+ * Sources arrive as assistant-ui `source` parts, emitted by `assistantParts`
+ * (`providers/assistantUiMessages.ts`) through `extractAgentSources` for
+ * `url` (the one place a model-supplied URL is admitted, http(s) only — a raw
+ * tool-call argument, so prompt-injection-influenceable) and directly from
+ * the turn's `citations` (memory retrieval) for `document`. `Thread` groups
* the run of source parts and hands them here through its `SourceGroup` slot.
*
- * Collapsed by default: the answer stays the top of the turn.
+ * Renders through the vendored `sources.aui` element's per-part `Sources`
+ * component (a `SourceMessagePartComponent`) rather than the old collapsible
+ * `components/ai-elements/Sources.tsx` disclosure — every source shows as a
+ * badge/link inline, nothing hidden behind a click.
*/
-import { Sources, SourcesContent, SourcesTrigger } from '../../../../components/ai-elements';
-import type { SourceUrlPart } from '../../../../components/assistant-ui/thread';
+import { Sources } from '../../../../components/assistant-ui/elements/sources.aui';
+import type { SourceItemPart } from '../../../../components/assistant-ui/thread';
import { useT } from '../../../../lib/i18n/I18nContext';
-import { AgentSourceRow } from '../AgentSourceRow';
-export function ChatSources({ sources }: { sources: readonly SourceUrlPart[] }) {
+export function ChatSources({ sources }: { sources: readonly SourceItemPart[] }) {
const { t } = useT();
if (sources.length === 0) return null;
return (
- <Sources asChild className="mb-0 text-content-muted">
- <section data-testid="turn-sources">
- <SourcesTrigger
- count={sources.length}
- className="text-content-muted hover:text-content-secondary text-xs transition-colors">
- {t('conversations.agentTaskInsights.sourcesHeading')} ({sources.length})
- </SourcesTrigger>
- <SourcesContent className="mt-1 w-full gap-0">
- <ul className="space-y-0.5">
- {sources.map(source => (
- <AgentSourceRow
- key={source.id}
- source={{ id: source.id, url: source.url, title: source.title ?? source.url }}
- />
- ))}
- </ul>
- </SourcesContent>
- </section>
- </Sources>
+ <section
+ data-testid="turn-sources"
+ aria-label={t('conversations.agentTaskInsights.sourcesHeading')}
+ className="mt-1 flex flex-wrap items-center gap-1.5">
+ {sources.map(source =>
+ source.sourceType === 'url' ? (
+ <Sources key={source.id} sourceType="url" url={source.url} title={source.title} />
+ ) : (
+ <Sources
+ key={source.id}
+ sourceType="document"
+ title={source.title ?? t('conversations.agentTaskInsights.memoryCitationFallbackTitle')}
+ />
+ )
+ )}
+ </section>
);
}
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsx
index 63e5f0c461..9829f97d7c 100644
--- a/app/src/providers/ChatRuntimeProvider.tsx
+++ b/app/src/providers/ChatRuntimeProvider.tsx
@@ -1306,10 +1306,39 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {
message: event.message,
command,
toolkit,
+ toolCallId: event.tool_call_id,
+ expiresAt: event.expires_at,
},
})
);
},
+ onApprovalDecided: (event: ChatApprovalDecidedEvent) => {
+ rtLog('approval_decided', {
+ thread: event.thread_id,
+ request: event.request_id,
+ resolution: event.resolution,
+ });
+ // Only a server-recorded TERMINAL non-decision (TTL expiry, an
+ // external cancel) needs handling here: an interactive decision made
+ // through THIS client already cleared the entry optimistically
+ // (`useOpenHumanExternalStore`'s `onRespondToToolApproval` /
+ // `ApprovalRequestCard`), and a decision made on another connected
+ // client is covered by the existing turn-end handlers once that
+ // client's turn settles. Clearing eagerly on every `approval_decided`
+ // would race the optimistic clear and, worse, drop a card whose
+ // decision the USER on this client is mid-click on when the event
+ // for a DIFFERENT thread's request arrives.
+ if (!event.thread_id || (event.resolution !== 'expired' && event.resolution !== 'cancelled')) {
+ return;
+ }
+ dispatch(
+ resolvePendingApprovalForThread({
+ threadId: event.thread_id,
+ requestId: event.request_id,
+ resolution: event.resolution,
+ })
+ );
+ },
onPlanReviewRequest: (event: ChatPlanReviewRequestEvent) => {
rtLog('plan_review_request', { thread: event.thread_id, request: event.request_id });
const steps = Array.isArray(event.args?.steps)