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): restore detached composer runtime in agent chat panel
Steven Enamakel0cc8c7def4e6
diff --git a/app/src/components/chat/composer/DetachedComposerRuntime.tsx b/app/src/components/chat/composer/DetachedComposerRuntime.tsxnew file mode 100644index 0000000000..f1f0585f0e--- /dev/null+++ b/app/src/components/chat/composer/DetachedComposerRuntime.tsx@@ -0,0 +1,54 @@+import {+ AssistantRuntimeProvider,+ type ThreadMessageLike,+ useExternalStoreRuntime,+} from '@assistant-ui/react';+import type { ReactNode } from 'react';++const NO_MESSAGES: ThreadMessageLike[] = [];++/**+ * An assistant-ui runtime for a composer surface that owns **no chat thread**.+ *+ * `ChatComposer` is built on `ComposerPrimitive`, which resolves its runtime+ * from React context. A surface that renders inside the app shell and mounts no+ * runtime of its own therefore inherits the app-wide one from+ * `ChatRuntimeProvider` — which is bound to `state.thread.selectedThreadId`,+ * the HOME chat's thread. For a surface whose conversation is not a chat thread+ * at all (the orchestration agent chat talks to sessions over+ * `orchestrationClient`), that inheritance points its composer at an unrelated+ * conversation. That is a data-loss-shaped mistake, not a cosmetic one.+ *+ * The obvious fix — `AssistantUiRuntimeProvider threadId={null}` — is the right+ * shape but the wrong dependency: that provider reads Redux unconditionally+ * (`useAppSelector` for the selected thread, and again inside+ * `useOpenHumanExternalStore`), so it requires a store even when the thread is+ * explicitly `null` and there is nothing to select. A surface with no thread has+ * nothing to project from the store either, so this mounts a genuinely inert+ * runtime instead: no messages, never running, and a `onNew` that fails loudly+ * because nothing should reach it.+ *+ * Nothing routes a send through this runtime. `ChatComposer` intercepts+ * `ComposerPrimitive.Root`'s submit and calls its own `onSend` prop (see that+ * component's doc comment for why the primitive's send path cannot be used).+ * What the runtime actually supplies here is the composer's text store, which+ * `useComposerTextBridge` mirrors the host's `inputValue` into.+ */+export function DetachedComposerRuntime({ children }: { children: ReactNode }) {+ const runtime = useExternalStoreRuntime<ThreadMessageLike>({+ messages: NO_MESSAGES,+ isRunning: false,+ convertMessage: m => m,+ onNew: async () => {+ // Unreachable by construction. Loud rather than silent: a silent no-op+ // here would look exactly like a dropped message.+ throw new Error(+ 'DetachedComposerRuntime: this surface owns no chat thread, so sends must go through ' ++ "the composer's own onSend prop, not the assistant-ui runtime."+ );+ },+ });+ return <AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>;+}++export default DetachedComposerRuntime;diff --git a/app/src/components/orchestration/AgentChatPanel.tsx b/app/src/components/orchestration/AgentChatPanel.tsxindex 86121c0421..8d35ea267a 100644--- a/app/src/components/orchestration/AgentChatPanel.tsx+++ b/app/src/components/orchestration/AgentChatPanel.tsx@@ -41,10 +41,10 @@ import {useContactSessions,useSessionTranscript,} from '../../lib/orchestration/useOrchestrationSessions';-import { AssistantUiRuntimeProvider } from '../../providers/AssistantUiRuntimeProvider';import { subconsciousTrigger } from '../../utils/tauriCommands/subconscious';import ChatComposer from '../chat/ChatComposer';import ChatNewWindowHero from '../chat/ChatNewWindowHero';+import { DetachedComposerRuntime } from '../chat/composer/DetachedComposerRuntime';import Button from '../ui/Button';import SessionTranscript from './SessionTranscript';@@ -183,19 +183,15 @@ function AgentComposer({return (/* This panel's chats are orchestration sessions, not chat threads — there is- no thread id to scope a runtime to. `ChatComposer` is built on- `ComposerPrimitive`, which resolves its runtime from React context, and- this panel renders inside the app shell: without a provider of its own it- would silently inherit the app-wide runtime from `ChatRuntimeProvider`,- which is bound to `selectedThreadId` — the HOME chat's thread. That is a- data-loss-shaped mistake, not a cosmetic one, so the surface mounts its- own runtime with an explicit `threadId={null}`: "this surface owns no- thread". `null` is not a fallback request — `AssistantUiRuntimeProvider`- treats an omitted prop as "follow the selection" and an explicit `null`- as "no thread", which is precisely the distinction needed here. The- resulting runtime has no messages and is never running; sending stays on- this panel's own `onSend`, which goes through `orchestrationClient`. */- <AssistantUiRuntimeProvider threadId={null}>+ no thread id to scope a runtime to, and no Redux projection to build. But+ `ChatComposer` is built on `ComposerPrimitive`, which resolves its runtime+ from React context, and this panel renders inside the app shell: without a+ runtime of its own the composer would silently inherit the app-wide one+ from `ChatRuntimeProvider`, which is bound to `selectedThreadId` — the+ HOME chat's thread. Sending stays on this panel's own `onSend`, which goes+ through `orchestrationClient`. See `DetachedComposerRuntime` for why that+ rather than `AssistantUiRuntimeProvider threadId={null}`. */+ <DetachedComposerRuntime><ChatComposerinputValue={value}setInputValue={setValue}@@ -220,7 +216,7 @@ function AgentComposer({micEnabled={false}placeholder={placeholder}/>- </AssistantUiRuntimeProvider>+ </DetachedComposerRuntime>);}