Skip to content

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

fix(web-chat): correct approval card rendering for pending messages

Steven Enamakel79e6fe25848e
diff --git a/app/src/components/assistant-ui/elements/message-queue.tsx b/app/src/components/assistant-ui/elements/message-queue.tsx
new file mode 100644
index 0000000000..635118ee1f
--- /dev/null
+++ b/app/src/components/assistant-ui/elements/message-queue.tsx
@@ -0,0 +1,95 @@
+'use client';
+
+/**
+ * The running message and the messages queued behind it, each removable.
+ *
+ * Vendored from the assistant-ui `elements-message-queue` registry item
+ * (https://r.assistant-ui.com/styles/base-nova/elements-message-queue.json).
+ * Changes from upstream:
+ * - `cn` import path (`@/components/assistant-ui/lib/utils`).
+ * - The "running", "N queued" and "sends when this finishes" captions and the
+ * remove button's accessible name are props with English defaults, for
+ * `useT()` — see `ComposerMessageQueue` in
+ * `features/conversations/aui/ComposerMessageQueue.tsx`, the only caller.
+ */
+import { cn } from '@/components/assistant-ui/lib/utils';
+import { ArrowUpIcon, XIcon } from 'lucide-react';
+import type { ComponentProps } from 'react';
+
+import { field, ghostButton, mono, paper } from './surfaces';
+
+export interface QueuedMessage {
+ id: string;
+ text: string;
+}
+
+export function MessageQueue({
+ running,
+ queued,
+ onCancel,
+ runningLabel = 'running',
+ queuedLabel = (count: number) => `${count} queued`,
+ pendingHint = 'sends when this finishes',
+ removeLabel = (text: string) => `Remove "${text}" from the queue`,
+ className,
+ ...props
+}: Omit<ComponentProps<'div'>, 'children' | 'running' | 'queued' | 'onCancel'> & {
+ running: string;
+ queued: readonly QueuedMessage[];
+ onCancel?: (id: string) => void;
+ runningLabel?: string;
+ queuedLabel?: (count: number) => string;
+ pendingHint?: string;
+ removeLabel?: (text: string) => string;
+}) {
+ return (
+ <div
+ data-slot="message-queue"
+ className={cn('flex w-full max-w-sm flex-col gap-2', className)}
+ {...props}>
+ <div className={cn(paper, 'flex items-center gap-2.5 rounded-2xl p-3')}>
+ <span className="relative flex size-2 shrink-0">
+ <span className="absolute inline-flex size-full animate-ping rounded-full bg-blue-500/60 motion-reduce:hidden" />
+ <span className="relative inline-flex size-2 rounded-full bg-blue-500 dark:bg-blue-400" />
+ </span>
+ <span className="text-foreground/90 min-w-0 flex-1 truncate text-[13.5px]">{running}</span>
+ <span className={cn(mono, 'text-foreground/35 shrink-0')}>{runningLabel}</span>
+ </div>
+
+ {queued.length > 0 && (
+ <div className="flex items-baseline justify-between px-1">
+ <span className={cn(mono, 'text-foreground/35')}>{queuedLabel(queued.length)}</span>
+ <span className={cn(mono, 'text-foreground/35')}>{pendingHint}</span>
+ </div>
+ )}
+
+ <ul className="flex flex-col gap-1.5">
+ {queued.map((message, index) => (
+ <li
+ key={message.id}
+ className={cn(
+ field,
+ 'fade-in slide-in-from-bottom-1 animate-in fill-mode-both flex items-center gap-2.5 rounded-2xl py-2 pr-2 pl-3 duration-300'
+ )}>
+ <span className={cn(mono, 'text-foreground/30 w-3 shrink-0 tabular-nums')}>
+ {index + 1}
+ </span>
+ <span className="text-foreground/60 min-w-0 flex-1 truncate text-[13.5px]">
+ {message.text}
+ </span>
+ <ArrowUpIcon className="text-foreground/25 size-3 shrink-0" />
+ {onCancel && (
+ <button
+ type="button"
+ aria-label={removeLabel(message.text)}
+ onClick={() => onCancel(message.id)}
+ className={cn(ghostButton, 'size-6 shrink-0')}>
+ <XIcon className="size-3.5" />
+ </button>
+ )}
+ </li>
+ ))}
+ </ul>
+ </div>
+ );
+}
diff --git a/app/src/features/conversations/aui/ApprovalCardAdapter.tsx b/app/src/features/conversations/aui/ApprovalCardAdapter.tsx
new file mode 100644
index 0000000000..1f830e888e
--- /dev/null
+++ b/app/src/features/conversations/aui/ApprovalCardAdapter.tsx
@@ -0,0 +1,135 @@
+'use client';
+
+/**
+ * OpenHuman glue over the vendored `elements/approval-card.tsx`.
+ *
+ * Two call sites share this one adapter (per the assistant-ui-elements plan,
+ * WS-B row: "Build ONE adapter component for this out-of-thread case"):
+ *
+ * - In-thread: `ChatToolParts.tsx`'s `GatedToolCall`, for a `Prompt`-class
+ * tool call parked on the ApprovalGate and attached to its own tool-call
+ * part (`approval_request` socket event). Replaces the deleted
+ * `ApprovalRequestCard`.
+ * - Out-of-thread: the composer-header decks in `Conversations.tsx` (a
+ * paused `tinyflows` run's `flow_approval_request`, or a background park
+ * with no owning thread/run — `approval_list_pending`), and the flow-run
+ * inspector's `FlowRunPendingApprovalCard`. Replaces the deleted
+ * `FlowApprovalRequestCard` / `UnroutedApprovalCard` / `ApprovalDecisionCard`.
+ *
+ * Every decision still routes through the single shared
+ * `openhuman.approval_decide` RPC (`services/api/approvalApi.ts`'s
+ * `decideApproval`) — this component owns only the deciding/error UI state
+ * and the vendored element's props, never the RPC itself; callers pass
+ * `onDecide`.
+ */
+import { useState } from 'react';
+import debug from 'debug';
+
+import { ApprovalCard } from '../../../components/assistant-ui/elements/approval-card';
+import { useT } from '../../../lib/i18n/I18nContext';
+import type { ApprovalDecision } from '../../../services/api/approvalApi';
+import { formatCountdown, useApprovalExpirySeconds } from './approvalCountdown';
+
+const log = debug('openhuman:aui:approval-card-adapter');
+
+export interface ApprovalCardAdapterProps {
+ ariaLabel: string;
+ title: string;
+ subtitle: string;
+ /** The exact command/target rendered in the card's mono panel. */
+ command: string;
+ toolName: string;
+ /** RFC3339 timestamp, or `null`/absent when the request does not expire. */
+ expiresAt?: string | null;
+ /**
+ * Decision to send for "Always allow". Omit to hide that button entirely
+ * (e.g. the unrouted-approval surface, which deliberately offers only
+ * once/deny — see the deleted `UnroutedApprovalCard`'s doc comment).
+ */
+ alwaysDecision?: ApprovalDecision;
+ alwaysHint?: string;
+ onDecide: (decision: ApprovalDecision) => Promise<void>;
+ /** Prefix for each button's `data-analytics-id` / e2e `data-testid`. */
+ analyticsPrefix: string;
+ testId?: string;
+ className?: string;
+ /** External busy flag (the unrouted deck shares one busy state across rows). */
+ busy?: boolean;
+}
+
+export function ApprovalCardAdapter({
+ ariaLabel,
+ title,
+ subtitle,
+ command,
+ toolName,
+ expiresAt,
+ alwaysDecision,
+ alwaysHint,
+ onDecide,
+ analyticsPrefix,
+ testId,
+ className,
+ busy = false,
+}: ApprovalCardAdapterProps) {
+ const { t } = useT();
+ const [deciding, setDeciding] = useState<ApprovalDecision | null>(null);
+ const [errorMsg, setErrorMsg] = useState<string | null>(null);
+ const expirySeconds = useApprovalExpirySeconds(expiresAt);
+
+ const decide = async (decision: ApprovalDecision) => {
+ if (deciding || busy) return;
+ setDeciding(decision);
+ setErrorMsg(null);
+ try {
+ await onDecide(decision);
+ } catch (e) {
+ log('decide(%s) failed: %o', decision, e);
+ setErrorMsg(t('chat.approval.error'));
+ setDeciding(null);
+ }
+ };
+
+ const disabled = deciding !== null || busy;
+
+ return (
+ <div role="alertdialog" aria-label={ariaLabel} data-testid={testId} className={className}>
+ <ApprovalCard
+ state={deciding ? 'running' : 'request'}
+ title={title}
+ subtitle={subtitle}
+ command={command || toolName}
+ expiry={
+ expirySeconds !== null ? (
+ <span className="text-foreground/35 mt-0.5 text-[11px] tabular-nums">
+ {t('chat.approval.expiresIn').replace('{time}', formatCountdown(expirySeconds))}
+ </span>
+ ) : undefined
+ }
+ denyLabel={t('chat.approval.deny')}
+ alwaysAllowLabel={t('chat.approval.alwaysAllow')}
+ allowOnceLabel={t('chat.approval.approve')}
+ runningLabel={t('chat.approval.deciding')}
+ onDeny={() => void decide('deny')}
+ onAlwaysAllow={alwaysDecision ? () => void decide(alwaysDecision) : undefined}
+ onAllowOnce={() => void decide('approve_once')}
+ denyProps={{ 'data-analytics-id': `${analyticsPrefix}-deny`, disabled }}
+ alwaysAllowProps={
+ alwaysDecision
+ ? {
+ 'data-analytics-id': `${analyticsPrefix}-always`,
+ disabled,
+ title: alwaysHint,
+ }
+ : undefined
+ }
+ allowOnceProps={{ 'data-analytics-id': `${analyticsPrefix}-approve-once`, disabled }}
+ />
+ {errorMsg && (
+ <p role="alert" className="mt-2 text-xs text-coral-600 dark:text-coral-400">
+ ⚠ {errorMsg}
+ </p>
+ )}
+ </div>
+ );
+}
diff --git a/crates/openhuman-core/src/web_chat/schemas.rs b/crates/openhuman-core/src/web_chat/schemas.rs
index 0df9018f93..e85f0a54c0 100644
--- a/crates/openhuman-core/src/web_chat/schemas.rs
+++ b/crates/openhuman-core/src/web_chat/schemas.rs
@@ -9,9 +9,12 @@ use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
use crate::rpc::RpcOutcome;
use super::ops::{
- channel_web_cancel, channel_web_chat, channel_web_queue_clear, channel_web_queue_status,
+ channel_web_cancel, channel_web_chat, channel_web_queue_clear, channel_web_queue_remove,
+ channel_web_queue_status,
+};
+use super::types::{
+ ChatRequestMetadata, WebCancelParams, WebChatParams, WebQueueParams, WebQueueRemoveParams,
};
-use super::types::{ChatRequestMetadata, WebCancelParams, WebChatParams, WebQueueParams};
pub fn all_web_channel_controller_schemas() -> Vec<ControllerSchema> {
vec![
@@ -19,6 +22,7 @@ pub fn all_web_channel_controller_schemas() -> Vec<ControllerSchema> {
schemas("cancel"),
schemas("queue_status"),
schemas("queue_clear"),
+ schemas("queue_remove"),
]
}
@@ -40,6 +44,10 @@ pub fn all_web_channel_registered_controllers() -> Vec<RegisteredController> {
schema: schemas("queue_clear"),
handler: handle_queue_clear,
},
+ RegisteredController {
+ schema: schemas("queue_remove"),
+ handler: handle_queue_remove,
+ },
]
}
@@ -109,6 +117,20 @@ pub fn schemas(function: &str) -> ControllerSchema {
inputs: vec![required_string("thread_id", "Thread identifier.")],
outputs: vec![json_output("result", "Queue clear result.")],
},
+ "queue_remove" => ControllerSchema {
+ namespace: "channel",
+ function: "web_queue_remove",
+ description: "Remove one specific queued item from a thread's run queue by id.",
+ inputs: vec![
+ required_string("client_id", "Client stream identifier."),
+ required_string("thread_id", "Thread identifier."),
+ required_string("item_id", "Id of the queued item to remove."),
+ ],
+ outputs: vec![json_output(
+ "result",
+ "{ thread_id, item_id, removed }.",
+ )],
+ },
_ => ControllerSchema {
namespace: "channel",
function: "unknown",