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
feat(aui): implement real queue adapter for core run queue
Steven Enamakeld936975d3998
diff --git a/app/src/features/conversations/aui/queueAdapter.ts b/app/src/features/conversations/aui/queueAdapter.tsindex 8dbfa60da2..5d55ce15ef 100644--- a/app/src/features/conversations/aui/queueAdapter.ts+++ b/app/src/features/conversations/aui/queueAdapter.ts@@ -1,19 +1,94 @@-import type { AppendMessage, ExternalThreadQueueAdapter } from '@assistant-ui/react';+/**+ * The external-store `queue` adapter over the core's run queue.+ *+ * assistant-ui's own `createMessageQueue` keeps the queue in the browser and+ * dispatches from it. OpenHuman's queue lives in the core (`RunQueue`), so this+ * adapter is hand-rolled over it instead:+ *+ * - `items` are the core's queue items (`queueSlice`, fed by the+ * `queue_item_*` socket events), which `ComposerPrimitive.Queue` and+ * `s.composer.queue` read.+ * - `enqueue` and `steer` both go to the host send path. Once a runtime has a+ * queue, assistant-ui routes every composer send through it (`steer` while+ * running, `enqueue` when idle), and the host decides the `queue_mode`+ * (`Conversations.handleComposerSend`: follow-up while streaming, a normal+ * send otherwise), exactly as it did for `onNew`.+ * - `remove` asks the core to drop the item and only then drops it locally; a+ * failed removal leaves the item showing, because the core will still send it.+ * - `move` and `edit` are no-ops: the core queue cannot reorder or rewrite.+ */+import type { AppendMessage, ExternalThreadQueueAdapter, QueueItemState } from '@assistant-ui/react';+import debug from 'debug';+import { useCallback, useMemo } from 'react';-import type { RunQueueItem } from '../../../store/queueSlice';+import { chatRemoveQueueItem } from '../../../services/chatService';+import { useAppDispatch, useAppSelector } from '../../../store/hooks';+import { queueItemRemoved, type RunQueueItem } from '../../../store/queueSlice';-export function buildOpenHumanQueueAdapter(_args: {+const log = debug('openhuman:aui-queue');++const EMPTY_ITEMS: readonly RunQueueItem[] = [];+const EMPTY_QUEUE_STATE: readonly QueueItemState[] = [];++export function buildOpenHumanQueueAdapter({+ items,+ send,+ remove,+}: {items: readonly RunQueueItem[];send: (message: AppendMessage) => Promise<void>;remove: (itemId: string) => void;}): ExternalThreadQueueAdapter {- const noop = () => {};- return { items: [], steerItems: [], enqueue: noop, steer: noop, move: noop, edit: noop, remove: noop };+ const forward = (lane: 'enqueue' | 'steer') => (message: AppendMessage) => {+ log('[aui-queue] %s → host send', lane);+ // The host send path reports its own failures (send-error banner); this+ // only keeps a rejection from going unhandled.+ send(message).catch((error: unknown) => {+ log('[aui-queue] %s send failed: %s', lane, error instanceof Error ? error.message : error);+ });+ };+ return {+ items:+ items.length === 0+ ? EMPTY_QUEUE_STATE+ : items.map(item => ({+ id: item.id,+ prompt: item.textPreview,+ parts: [{ type: 'text' as const, text: item.textPreview }],+ })),+ steerItems: EMPTY_QUEUE_STATE,+ enqueue: forward('enqueue'),+ steer: forward('steer'),+ move: queueItemId => log('[aui-queue] move ignored item=%s (core queue is fixed)', queueItemId),+ edit: queueItemId => log('[aui-queue] edit ignored item=%s (core queue is fixed)', queueItemId),+ remove,+ };}+/** The `queue` option for `threadId`'s external store. */export function useOpenHumanQueueAdapter(- _threadId: string | null,- _send: (message: AppendMessage) => Promise<void>+ threadId: string | null,+ send: (message: AppendMessage) => Promise<void>): ExternalThreadQueueAdapter {- return buildOpenHumanQueueAdapter({ items: [], send: _send, remove: () => {} });+ const dispatch = useAppDispatch();+ const items = useAppSelector(state =>+ threadId ? (state.queue?.itemsByThread[threadId] ?? EMPTY_ITEMS) : EMPTY_ITEMS+ );++ const remove = useCallback(+ (itemId: string) => {+ if (!threadId) return;+ log('[aui-queue] remove requested thread=%s item=%s', threadId, itemId);+ void chatRemoveQueueItem(threadId, itemId).then(removed => {+ if (removed) dispatch(queueItemRemoved({ threadId, itemId }));+ else log('[aui-queue] remove not confirmed thread=%s item=%s', threadId, itemId);+ });+ },+ [dispatch, threadId]+ );++ return useMemo(+ () => buildOpenHumanQueueAdapter({ items, send, remove }),+ [items, send, remove]+ );}