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(chat): add wire format helpers for chat messages
Steven Enamakel531da76d7f2d
diff --git a/app/src/services/chatService.ts b/app/src/services/chatService.tsindex 942d4d3248..36ec615a51 100644--- a/app/src/services/chatService.ts+++ b/app/src/services/chatService.ts@@ -8,864 +8,102 @@*/import debug from 'debug';-import type { ChatErrorCopyParams } from '../lib/chatErrorCopy';+import type {+ ArtifactFailedEvent,+ ArtifactKind,+ ArtifactPendingEvent,+ ArtifactReadyEvent,+ ChatApprovalDecidedEvent,+ ChatApprovalRequestEvent,+ ChatCancelledEvent,+ ChatDoneEvent,+ ChatErrorEvent,+ ChatInferenceHeartbeatEvent,+ ChatInferenceStartEvent,+ ChatInterimEvent,+ ChatIterationStartEvent,+ ChatPlanReviewRequestEvent,+ ChatRunModeChangedEvent,+ ChatSegmentEvent,+ ChatSubagentDoneEvent,+ ChatSubagentIterationStartEvent,+ ChatSubagentSpawnedEvent,+ ChatSubagentSpawnedEventV2,+ ChatSubagentTextDeltaEvent,+ ChatSubagentThinkingDeltaEvent,+ ChatSubagentToolCallEvent,+ ChatSubagentToolResultEvent,+ ChatSuggestionsEvent,+ ChatTextDeltaEvent,+ ChatThinkingDeltaEvent,+ ChatThreadGoalClearedEvent,+ ChatThreadGoalUpdatedEvent,+ ChatThreadTodosChangedEvent,+ ChatToolArgsDeltaEvent,+ ChatToolCallEvent,+ ChatToolResultEvent,+ ExternalTransferPendingEvent,+ ProactiveMessageEvent,+ QueueItemEvent,+ QueueItemPayload,+} from './chatWire';import { callCoreRpc } from './coreRpcClient';import { socketService } from './socketService';const chatLog = debug('realtime:chat');-export interface ChatToolCallEvent {- thread_id: string;- request_id?: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- tool_name: string;- skill_id: string;- args: Record<string, unknown>;- round: number;- /**- * Stable call id (matches the `call_id` on preceding- * {@link ChatToolArgsDeltaEvent}s and the eventual- * {@link ChatToolResultEvent}). Reducers key tool-timeline rows by- * this id for end-to-end reconciliation.- */- tool_call_id?: string;- /**- * Server-computed human label for this call (e.g. "Reading messages"),- * set by the Rust `Tool::display_label`. Present for dynamic- * Composio/MCP/integration tools the client can't label itself; absent- * for built-ins the client formatter already handles.- */- tool_display_label?: string;- /** Server-computed contextual detail (e.g. "[email protected]"). */- tool_display_detail?: string;-}--export interface ChatToolResultEvent {- thread_id: string;- request_id?: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- tool_name: string;- skill_id: string;- output: string;- success: boolean;- round: number;- /** Matches the id on the corresponding {@link ChatToolCallEvent}. */- tool_call_id?: string;- /**- * Optional structured failure explanation, present only when `success` is- * false (#4254). Raw snake_case wire object (`class`, `category`,- * `recoverable`, `cause_plain`, `next_action`); parsed defensively via- * `parseToolFailure` before it reaches the store.- */- failure?: unknown;- /** The call's arguments. The start event may carry none; this is the fallback. */- args?: unknown;- /** Wall time the call took. */- elapsed_ms?: number;- /**- * Machine-readable result, when the tool produced one (the tool's- * `ToolResult.metadata`), e.g. `{ kind: "web_search", results: [...] }`.- */- structured?: unknown;- /** Label / detail recomputed by the core with the call's real arguments. */- tool_display_label?: string;- tool_display_detail?: string;-}--/** One sub-agent's token/cost contribution within a turn (hover breakdown). */-export interface SubagentUsageWire {- task_id: string;- agent_id: string;- input_tokens: number;- output_tokens: number;- /** `null` when the child's cost is not known. */- cost_usd: number | null;-}--/**- * Where a reported cost came from: every call billed by the provider, some- * call priced from published list rates, or not known at all.- */-export type CostSource = 'charged' | 'estimated' | 'unknown';--/**- * Holistic token/cost/context totals for a completed turn, carried on- * `chat_done`. Every numeric is a turn total (parent agent + any sub-agents);- * `subagents` breaks the same spend down per child. `context_window` is `0` when- * the core couldn't resolve the model's window.- */-export interface TurnUsageWire {- input_tokens: number;- output_tokens: number;- cached_input_tokens: number;- /**- * The turn's cost, or `null` when the core does not know it (no reported- * charge and no catalogued price). Never a guessed rate.- */- cost_usd: number | null;- /** Absent from an older core, whose `cost_usd` is always a number. */- cost_source?: CostSource;- context_window: number;- /**- * Tokens the parent's context held after the turn's final model call: the- * context gauge's numerator. The totals above sum every call of the turn.- * Absent from an older core.- */- context_tokens?: number;- subagents?: SubagentUsageWire[];-}--export interface ChatDoneEvent {- thread_id: string;- request_id?: string;- /**- * Socket.IO client that owns the turn. `"system"` marks a turn the core ran- * on its own behalf (background sub-agent result delivery, cron/flow- * agents); such turns are broadcast to every client.- * Always on the wire (`WebChannelEvent.client_id`); declared here for the- * consumers that key off it.- */- client_id?: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- full_response: string;- rounds_used: number;- /**- * @deprecated Superseded by {@link ChatDoneEvent.usage}. The core no longer- * populates these flat fields; read token totals from `usage` instead.- */- total_input_tokens?: number;- /** @deprecated See {@link ChatDoneEvent.total_input_tokens}. */- total_output_tokens?: number;- /**- * Holistic token/cost/context usage for the turn (parent + sub-agents).- * Absent on synthetic done events that never ran a real turn.- */- usage?: TurnUsageWire | null;- /** Total segments when the response was split into bubbles by Rust. */- segment_total?: number | null;- /** Memory citations captured during retrieval for this response. */- citations?: ChatCitation[] | null;- /**- * Turn latency snapshot from the core progress bridge (wire-contract.md;- * mirrors the Rust `TurnTimingPayload`). Absent on a core that predates- * timing instrumentation, or on a synthetic done event.- */- timing?: TurnTimingWire | null;-}--/** Mirrors the Rust `TurnTimingPayload` (`crates/openhuman-rpc/src/server/socketio.rs`). */-export interface TurnTimingWire {- first_token_ms?: number;- first_tool_ms?: number;- total_ms?: number;-}--export interface ChatCitation {- id: string;- key: string;- namespace?: string;- score?: number;- timestamp: string;- snippet: string;-}--/** A single segment of a multi-bubble response, emitted before `chat_done`. */-export interface ChatSegmentEvent {- thread_id: string;- /**- * Wire name is `full_response` for compatibility with {@link WebChannelEvent},- * but this field contains only the **segment text**, not the full response.- * Use {@link segmentText} for clarity in consuming code.- */- full_response: string;- request_id: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- segment_index: number;- segment_total: number;- citations?: ChatCitation[] | null;-}+export type {+ ChatToolCallEvent,+ ChatToolResultEvent,+ SubagentUsageWire,+ CostSource,+ TurnUsageWire,+ ChatDoneEvent,+ TurnTimingWire,+ ChatCitation,+ ChatSegmentEvent,+ ChatInterimEvent,+ ChatErrorEvent,+ GuardrailReason,+ GuardrailPayload,+ ExternalTransferPendingEvent,+ ChatCancelledEvent,+ ProactiveMessageEvent,+ ChatApprovalRequestEvent,+ ChatApprovalDecidedEvent,+ ChatPlanReviewRequestEvent,+ ChatThreadTodoItem,+ ChatThreadTodosChangedEvent,+ ThreadGoal,+ ChatThreadGoalUpdatedEvent,+ ChatThreadGoalClearedEvent,+ ChatRunModeChangedEvent,+ ArtifactKind,+ ArtifactReadyEvent,+ ArtifactFailedEvent,+ ArtifactPendingEvent,+ ChatInferenceStartEvent,+ ChatInferenceHeartbeatEvent,+ ChatIterationStartEvent,+ ChatSubagentSpawnedEvent,+ ChatSubagentDoneEvent,+ SubagentProgressDetail,+ ChatSubagentSpawnedEventV2,+ ChatSubagentIterationStartEvent,+ ChatSubagentToolCallEvent,+ ChatSubagentToolResultEvent,+ ChatSubagentTextDeltaEvent,+ ChatSubagentThinkingDeltaEvent,+ ChatTextDeltaEvent,+ ChatThinkingDeltaEvent,+ ChatToolArgsDeltaEvent,+} from './chatWire';/** Return the segment text from a {@link ChatSegmentEvent} (avoids the misleading wire name). */export function segmentText(event: ChatSegmentEvent): string {return event.full_response;}-/**- * The parent agent's leading narration for one round, flushed mid-turn when a- * tool/subagent call closes that round. Emitted (`chat_interim`) so the- * narration persists as its own interleaved chat bubble instead of vanishing- * when the turn settles. `round` is the 1-based iteration it belongs to and- * makes a stable per-turn dedup key (one interim per round).- */-export interface ChatInterimEvent {- thread_id: string;- request_id: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- /** Wire name is `full_response`; carries only this round's narration text. */- full_response: string;- round: number;-}--export interface ChatErrorEvent {- thread_id: string;- request_id?: string;- /**- * Socket.IO client that owns the turn. `"system"` marks a turn the core ran- * on its own behalf (background sub-agent result delivery, cron/flow- * agents); such turns are broadcast to every client.- * Always on the wire (`WebChannelEvent.client_id`); declared here for the- * consumers that key off it.- */- client_id?: string;- message: string;- /**- * Stable i18n key of the core's failure-copy table row behind `message`- * (`chat_error.<class>`). Absent on error types without a table row.- * Render with `chatErrorCopyText`, which falls back to `message`.- */- copy_key?: string;- /** Values the translated copy needs (retry-after seconds, provider, detail). */- copy_params?: ChatErrorCopyParams;- error_type:- | 'network'- | 'timeout'- | 'tool_error'- | 'inference'- | 'cancelled'- | 'rate_limited'- | 'auth_error'- | 'session_expired'- | 'provider_error'- | 'context_overflow'- | 'model_unavailable'- | 'payload_too_large'- | 'provider_request_rejected'- | 'chat_template_rejected'- | 'budget_exhausted'- | 'max_iterations'- | 'turn_timeout'- | 'empty_response'- | 'action_budget_exceeded'- | 'capability_unsupported'- | 'guardrail';- round: number | null;- /**- * Present only when `error_type === 'guardrail'`. Mirrors the Rust- * `GuardrailPayload` (`crates/openhuman-rpc/src/server/socketio.rs`) carried- * on `chat_error` — the policy verdict that blocked the turn, with the- * reasons the guardrail cited.- */- guardrail?: GuardrailPayload;-}--/** One reason a guardrail policy cited for its verdict. */-export interface GuardrailReason {- code: string;- message: string;-}--/**- * The guardrail verdict carried on a `chat_error` whose `error_type` is- * `"guardrail"`. Mirrors the Rust `GuardrailPayload`- * (`crates/openhuman-rpc/src/server/socketio.rs`).- */-export interface GuardrailPayload {- verdict: string;- score: number;- reasons: GuardrailReason[];-}--/**- * Emitted when the core's egress guard parks an outbound action (e.g. an- * integration call reaching outside the workspace) pending an explicit- * decision — a softer sibling of `chat_error{error_type:"guardrail"}` that- * does not fail the turn. Bridged from `DomainEvent::ExternalTransferPending`- * by `web_chat::event_bus` (`external_transfer_pending`).- */-export interface ExternalTransferPendingEvent {- thread_id: string;- request_id?: string;- client_id?: string;- /** Destination provider (e.g. `"gmail"`, `"slack"`). */- provider?: string;- /** Destination service/endpoint within the provider. */- service?: string;- /** Human-readable reason the transfer was flagged. */- reason?: string;-}--/**- * Emitted when the core cancels an in-flight turn (`chat_cancel` RPC, a- * superseding send, or a queue interrupt) — see wire-contract.md. Carries the- * `cancel_reason` and, for a superseded turn, the id of the turn that- * replaced it. The core keeps emitting `chat_error{error_type:"cancelled"}`- * alongside this for one release; consumers must dedupe on `request_id`.- */-export interface ChatCancelledEvent {- thread_id: string;- request_id?: string;- client_id?: string;- cancel_reason?: 'user_stop' | 'superseded';- superseded_by?: string;-}--/** Proactive assistant message pushed by the Rust event bus (not a chat turn). */-export interface ProactiveMessageEvent {- thread_id: string;- request_id?: string;- full_response: string;- /** Id of the thread row the core already stored for this message, if any. */- persisted_message_id?: string;-}--/**- * Emitted when the agent turn parks on the ApprovalGate — a `Prompt`-class- * (external-effect) tool call is awaiting the user's decision (only when the- * core runs with `OPENHUMAN_APPROVAL_GATE=1`). The frontend surfaces a- * pending-approval prompt; answering routes to the `openhuman.approval_decide`- * RPC. A typed `yes`/`no` chat reply is also honoured server-side; any other- * text cancels the parked turn and is taken as a fresh message.- */-export interface ChatApprovalRequestEvent {- thread_id: string;- client_id?: string;- request_id: string;- tool_name: string;- /** Human-readable summary of the action awaiting approval. */- message: string;- /**- * Redacted args of the gated call — e.g. `{ command }` for shell,- * `{ path }` for file writes, `{ url }` for network. The card renders the- * 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;- /**- * `true` when the park can outlive the chat turn it is shown on — an- * async-delegated sub-agent (wire contract: `DomainEvent::ApprovalRequested.- * detached`, additive). The card is kept across that turn's `chat_done` and- * cleared by `approval_decided` instead. Absent for an in-turn park.- */- detached?: boolean;-}--/**- * 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;-}--/**- * Interactive plan-review request: the orchestrator parked the live turn on a- * thread-scoped plan the user must review before execution (Codex/Claude plan- * mode). Resolved via the `openhuman.plan_review_decide` RPC. Bridged from the- * Rust `DomainEvent::PlanReviewRequested` by the web channel.- */-export interface ChatPlanReviewRequestEvent {- thread_id: string;- client_id?: string;- request_id: string;- /** One-line summary of the plan. */- message: string;- /** `{ steps: string[] }` — the ordered plan items shown in the review card. */- args?: { steps?: string[] };- /**- * The `request_plan_review` tool call this parked review binds to (wire- * contract: `DomainEvent::PlanReviewRequested.tool_call_id`, additive —- * lands with core workstream C2). Lets the toolkit's `request_plan_review`- * entry attach the review to the EXACT tool-call part it gates, matching- * {@link ChatApprovalRequestEvent.tool_call_id}. Absent on a core that has- * not landed C2 yet; every reader must treat it as optional and fall back- * to "any pending review for this thread".- */- tool_call_id?: string;- /**- * RFC3339 timestamp the parked review expires at (wire contract:- * `DomainEvent::PlanReviewRequested.expires_at`, additive, lands with C2).- * Absent on an older core.- */- expires_at?: string;-}--/**- * One item of a thread's live todo list, as the core writes it via the- * `todo` tool. Bridged from `DomainEvent::ThreadTodosChanged` by the web- * channel (socket event `thread_todos_changed`).- */-export interface ChatThreadTodoItem {- content: string;- status: 'pending' | 'in_progress' | 'completed' | 'cancelled';- /** Why the step was cancelled; only on a `cancelled` item. */- reason?: string;-}--/**- * Emitted whenever the agent (re)writes the thread's todo list. Bridged from- * the Rust `DomainEvent::ThreadTodosChanged { thread_id, todos }`.- */-export interface ChatThreadTodosChangedEvent {- thread_id: string;- todos: ChatThreadTodoItem[];-}--/**- * The durable objective the agent set for a thread via `goal_set`, kept- * across turns. Wire shape of `ThreadGoal` on the `thread_goal_updated`- * socket event.- */-export interface ThreadGoal {- goal_id: string;- objective: string;- status: 'active' | 'paused' | 'budget_limited' | 'complete';- token_budget?: number;- tokens_used: number;- time_used_seconds: number;-}--/**- * Emitted when the thread's goal is set or updated. Bridged from the Rust- * `DomainEvent::ThreadGoalUpdated { thread_id, goal }`.- */-export interface ChatThreadGoalUpdatedEvent {- thread_id: string;- goal: ThreadGoal;-}--/**- * Emitted when the thread's goal is cleared (`goal_complete`, or the- * orchestrator dropping it). Bridged from the `thread_goal_cleared` socket- * event.- */-export interface ChatThreadGoalClearedEvent {- thread_id: string;-}--/**- * Emitted when a thread's plan/build run mode changes — via the- * `openhuman.agent_set_run_mode` RPC from this client or another, or a- * server-side transition. Bridged from the `run_mode_changed` socket event.- */-export interface ChatRunModeChangedEvent {- thread_id: string;- mode: 'plan' | 'build';-}--/**- * Lowercase variant of the Rust `ArtifactKind` enum surfaced on- * artifact lifecycle socket events. Mirrors the slugs produced by- * `ArtifactKind::as_str()` in `crates/openhuman-core/src/agent/artifacts/types.rs`.- */-export type ArtifactKind = 'presentation' | 'document' | 'image' | 'video' | 'other';--/**- * Emitted when the core `artifacts::store::finalize_artifact` flips an- * artifact's status to `Ready`. The chat runtime upserts the snapshot- * keyed on `artifact_id` so the `ArtifactCard` can render in the- * message timeline with a download button (#2779).- */-export interface ArtifactReadyEvent {- thread_id: string;- client_id?: string;- /** UUID of the artifact record. Use with `ai_get_artifact`. */- artifact_id: string;- kind: ArtifactKind;- /** Human-readable title; also the on-disk filename stem. */- title: string;- /**- * Absolute workspace root the artifact belongs to. Subscribers must compare- * this to their own workspace binding and silently drop events that don't- * match — `path` is workspace-relative and would otherwise resolve into the- * wrong `<workspace>/artifacts/` tree after a workspace switch.- */- workspace_dir: string;- /** File name relative to its root: `deck.pptx` in the visible files folder, or `<uuid>/deck.pptx` for a legacy record. */- path: string;- /** Final on-disk size in bytes. */- size_bytes: number;- /**- * The producing tool call's id, when the core sends one (additive wire- * field). Lets the frontend route an artifact with an owning tool call to- * that call's own inline rendering instead of the header's live-artifact- * deck — see `ArtifactSnapshot.toolCallId`.- */- tool_call_id?: string;- /**- * The turn that made the artifact (`turn_request_id` on the wire). Places- * the card in that turn's reply while the turn runs.- */- request_id?: string;-}--/**- * Emitted when `artifacts::store::fail_artifact` flips an artifact to- * `Failed` after the producer surfaced a reason. The frontend swaps- * the in-flight card for a retry-hint view.- */-export interface ArtifactFailedEvent {- thread_id: string;- client_id?: string;- artifact_id: string;- kind: ArtifactKind;- title: string;- /** Absolute workspace root — see {@link ArtifactReadyEvent.workspace_dir}. */- workspace_dir: string;- /** Producer-supplied failure reason, already truncated. */- error: string;- /** See {@link ArtifactReadyEvent.tool_call_id}. */- tool_call_id?: string;- /** See {@link ArtifactReadyEvent.request_id}. */- request_id?: string;-}--/**- * Emitted when `artifacts::store::create_artifact` reserves an artifact- * row (status `Pending`), before the producer has written any bytes- * (#3162). The chat runtime upserts an `in_progress` snapshot keyed on- * `artifact_id` so the `ArtifactCard` shows a spinner the moment the- * tool starts, then swaps in place when the matching `artifact_ready`- * / `artifact_failed` arrives. Backend half shipped in #3277.- */-export interface ArtifactPendingEvent {- thread_id: string;- client_id?: string;- artifact_id: string;- kind: ArtifactKind;- title: string;- /** Absolute workspace root — see {@link ArtifactReadyEvent.workspace_dir}. */- workspace_dir: string;- /** File name relative to its root: `deck.pptx` in the visible files folder, or `<uuid>/deck.pptx` for a legacy record. */- path: string;- /** See {@link ArtifactReadyEvent.tool_call_id}. */- tool_call_id?: string;- /** See {@link ArtifactReadyEvent.request_id}. */- request_id?: string;-}--/** Emitted when the agent turn begins (before the first LLM call). */-export interface ChatInferenceStartEvent {- thread_id: string;- request_id: string;-}--/**- * Periodic liveness beat emitted by the core progress bridge for the whole- * duration of an in-flight turn (issue #4270). Carries no payload beyond the- * ids — its sole purpose is to rearm the frontend silence timer so a long- * prefill or a buffered-reasoning phase that streams no other progress event- * does not trip a false "no response after 2 minutes" timeout.- */-export interface ChatInferenceHeartbeatEvent {- thread_id: string;- request_id: string;-}--/** Emitted at the start of each LLM iteration in the tool loop. */-export interface ChatIterationStartEvent {- thread_id: string;- request_id: string;- /** 1-based iteration index. */- round: number;- message: string;-}--/** Emitted when a sub-agent is spawned during tool execution. */-export interface ChatSubagentSpawnedEvent {- thread_id: string;- request_id: string;- /** Agent definition id (e.g. "code_executor"). */- tool_name: string;- /** Per-spawn task id. */- skill_id: string;- message: string;- round: number;- /**- * Per-request monotonic ordering key stamped by the core's progress bridge- * (`publish_seq_stamped`). `(request_id, seq)` is the event's identity: a- * Socket.IO redelivery carries the same pair, a genuinely new emission never- * does. Absent on cores that predate the stamping bridge.- */- seq?: number;-}--/** Emitted when a sub-agent completes or fails. */-export interface ChatSubagentDoneEvent {- thread_id: string;- request_id: string;- tool_name: string;- skill_id: string;- message: string;- success: boolean;- round: number;- /** Event identity with `request_id`; see {@link ChatSubagentSpawnedEvent.seq}. */- seq?: number;- /** Per-event subagent detail. Mirrors `SubagentProgressDetail` in core. */- subagent?: SubagentProgressDetail;-}--/**- * Per-event subagent detail attached to live subagent activity events- * (`subagent_spawned`, `subagent_completed`, `subagent_iteration_start`,- * `subagent_tool_call`, `subagent_tool_result`).- *- * Matches the Rust `SubagentProgressDetail` struct in- * `crates/openhuman-rpc/src/server/socketio.rs` — every field is optional so older cores that- * don't emit it stay parseable.- */-export interface SubagentProgressDetail {- mode?: string;- dedicated_thread?: boolean;- prompt_chars?: number;- child_iteration?: number;- child_max_iterations?: number;- agent_id?: string;- task_id?: string;- elapsed_ms?: number;- iterations?: number;- output_chars?: number;- /** Persistent worker sub-thread id backing the delegation (on `subagent_spawned`). */- worker_thread_id?: string;- /** Human-readable display name from the agent registry. */- display_name?: string;- /**- * Absolute path to the worker's isolated `git worktree` checkout (on- * `subagent_completed`, when the worker ran with `isolation = "worktree"`).- * Drives the inline worktree row's open/diff/remove actions (#3376).- */- worktree_path?: string;- /** Files (relative to the worktree root) the worker changed (on `subagent_completed`). */- changed_files?: string[];- /** Whether the worker's worktree had uncommitted changes (on `subagent_completed`). */- dirty_status?: boolean;- /**- * This child's own spend (on `subagent_completed`) — present **only when it- * is not already inside the parent turn's totals**.- *- * A blocking spawn records into the parent's ledger and `chat_done` already- * carries the child's tokens AND cost; a detached spawn does not, and the- * core populates these instead. So the consumer adds whatever arrives- * unconditionally: absent means "already counted, or this emit site does not- * know", and both resolve to "add nothing".- */- input_tokens?: number;- output_tokens?: number;- cached_input_tokens?: number;- /** `null` when the child's cost is not known. */- cost_usd?: number | null;- /**- * Provider-assigned id of the `spawn_subagent`/`spawn_async_subagent`/- * `delegate_*` tool call that started this delegation- * (`AgentProgress::SubagentSpawned::parent_call_id`, threaded onto every- * event in the `subagent_*` family — see `crates/openhuman-rpc/src/server/socketio.rs`).- * Lets the frontend attach the delegation's live activity to the EXACT- * spawn tool-call part instead of guessing which running row started it.- * Absent on cores that predate this field.- */- parent_call_id?: string;- /**- * The sub-agent's final assistant text (on `subagent_completed`), capped by- * the core (`cap_wire_output`). Rendered as the delegation's nested- * transcript result.- */- output?: string;-}--/** Extended payload for `subagent_spawned`. */-export interface ChatSubagentSpawnedEventV2 extends ChatSubagentSpawnedEvent {- subagent?: SubagentProgressDetail;-}--/**- * Emitted at the start of each LLM iteration *inside* a running- * sub-agent. Lets the parent thread surface child progress (which round- * the subagent is on, its iteration cap) without flattening it into the- * parent's own iteration counter.- */-export interface ChatSubagentIterationStartEvent {- thread_id: string;- request_id: string;- /** Parent's iteration index (inherited from the parent context). */- round: number;- /** Subagent's agent id. Mirrored on the flat `tool_name` field. */- tool_name: string;- /** Subagent's task id (the spawn id). */- skill_id: string;- message: string;- subagent?: SubagentProgressDetail;-}--/** Emitted when a sub-agent starts executing one of its own tools. */-export interface ChatSubagentToolCallEvent {- thread_id: string;- request_id: string;- round: number;- /** Child's tool name (e.g. `composio_execute`, `web_search`). */- tool_name: string;- /** Subagent's task id. */- skill_id: string;- /** Provider-assigned tool call id. */- tool_call_id: string;- /**- * Full arguments the sub-agent invoked the tool with, so the processing- * drawer can show *what exactly* the child did. Absent for tools called- * with no/`null` arguments.- */- args?: unknown;- /** Server-computed human label for this child call (from `Tool::display_label`). */- tool_display_label?: string;- /** Server-computed contextual detail (path / recipient / query). */- tool_display_detail?: string;- subagent?: SubagentProgressDetail;-}--/** Emitted when a sub-agent's tool execution finishes. */-export interface ChatSubagentToolResultEvent {- thread_id: string;- request_id: string;- round: number;- tool_name: string;- skill_id: string;- tool_call_id: string;- success: boolean;- /**- * The child tool's actual output text, so the drawer can show what came- * back. Size/timing still arrive via `subagent.output_chars` /- * `subagent.elapsed_ms`.- */- output?: string;- /**- * Optional structured failure explanation for a FAILED child tool call- * (#4459), present only when `success` is false. Parsed via- * `parseToolFailure` and stored on the child row so the "why / next" copy- * survives live (previously it was dropped until a snapshot reload).- */- failure?: unknown;- subagent?: SubagentProgressDetail;-}--/**- * Emitted for each chunk of a sub-agent's streamed assistant text while- * the child iteration is in flight. Distinct from `text_delta` (which is- * the parent's own output) so the UI attributes the token to the running- * subagent row via `subagent.task_id` / `subagent.agent_id` and renders- * it in that row's live transcript. Concatenating `delta`s in order- * yields the child's visible text for the iteration.- */-export interface ChatSubagentTextDeltaEvent {- thread_id: string;- request_id: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- /** Parent iteration index (inherited from the parent context). */- round: number;- /** Text fragment from the sub-agent. */- delta: string;- subagent?: SubagentProgressDetail;-}--/**- * Emitted for each chunk of a sub-agent's streamed reasoning / thinking- * output. Counterpart to `thinking_delta` scoped to a child run — only- * sent by models that expose `reasoning_content`.- */-export interface ChatSubagentThinkingDeltaEvent {- thread_id: string;- request_id: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- round: number;- delta: string;- subagent?: SubagentProgressDetail;-}--/**- * Emitted for each chunk of streamed assistant text that arrives from the- * provider during an iteration. Concatenating `delta` values in order yields- * the visible assistant text for that iteration.- */-export interface ChatTextDeltaEvent {- thread_id: string;- request_id: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- /** 1-based iteration index the chunk belongs to. */- round: number;- /** Text fragment; may be a single token or a few characters. */- delta: string;-}--/**- * Emitted for each chunk of streamed model reasoning / thinking output.- * Only sent by models that expose `reasoning_content` (see the- * `supportsThinking` flag on the model registry entry). Concatenating- * `delta`s in order yields the full reasoning transcript.- */-export interface ChatThinkingDeltaEvent {- thread_id: string;- request_id: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- round: number;- delta: string;-}--/**- * Emitted for each chunk of a native tool call's arguments JSON while the- * model is still composing the call. `tool_call_id` groups fragments for- * the same call, and `tool_name` is populated once the provider sends it- * (may be empty on the very first chunk).- */-export interface ChatToolArgsDeltaEvent {- thread_id: string;- request_id: string;- /** Per-request monotonic ordering key stamped by the core progress bridge. */- seq?: number;- round: number;- tool_call_id: string;- tool_name: string;- /** JSON fragment; only valid JSON once concatenated across all chunks. */- delta: string;-}-export interface ChatEventListeners {onInferenceStart?: (event: ChatInferenceStartEvent) => void;onInferenceHeartbeat?: (event: ChatInferenceHeartbeatEvent) => void;@@ -1784,21 +1022,8 @@ export async function chatClearQueue(threadId: string): Promise<number | null> {}}-/** One run-queue item (`QueueItemPayload` in `openhuman-rpc/src/server/socketio.rs`). */-export interface QueueItemPayload {- id: string;- /** `steer` / `followup` / `collect`; absent when the core does not say. */- lane?: string | null;- /** The message text, clipped by the core to 80 characters plus `…`. */- text_preview?: string | null;-}-/** `queue_item_queued` / `queue_item_delivered` / `queue_item_removed`. */-export interface QueueItemEvent {- thread_id: string;- client_id?: string;- queue_item?: QueueItemPayload;-}+export type { QueueItemEvent, QueueItemPayload } from './chatWire';export interface QueueEventListeners {/** A message joined a running turn's queue. */@@ -1836,28 +1061,7 @@ export function subscribeQueueEvents(listeners: QueueEventListeners): () => void};}-/** One follow-up suggestion (`ChatSuggestion` in `openhuman-rpc/src/server/socketio.rs`). */-export interface ChatSuggestionWire {- /** The message sent when the chip is picked. */- prompt: string;- /** A short 2-4 word button label for the chip (`web_chat/suggestions.rs`). */- label?: string | null;-}--/**- * `chat_suggestions`: follow-up prompts for the turn that just finished,- * emitted by the core after `chat_done` (`web_chat/suggestions.rs`). Best- * effort — a disabled, slow or malformed suggestions call means the event- * simply never arrives for that turn.- */-export interface ChatSuggestionsEvent {- thread_id: string;- client_id?: string;- request_id?: string;- /** The turn the suggestions follow; the event fires outside its request. */- turn_request_id?: string;- suggestions: ChatSuggestionWire[];-}+export type { ChatSuggestionWire, ChatSuggestionsEvent } from './chatWire';export interface SuggestionEventListeners {onSuggestions?: (event: ChatSuggestionsEvent) => void;diff --git a/app/src/services/chatWire.ts b/app/src/services/chatWire.tsindex 77d13b436e..c567636b47 100644--- a/app/src/services/chatWire.ts+++ b/app/src/services/chatWire.ts@@ -89,9 +89,9 @@ export type ChatDoneEvent = Omit<WireEvent<'chat_done', 'full_response'>, 'citatcitations?: ChatCitation[] | null;};-export type ChatSegmentEvent = Omit<- WireEvent<'chat_segment', 'full_response' | 'segment_index' | 'segment_total'>,- never+export type ChatSegmentEvent = WireEvent<+ 'chat_segment',+ 'full_response' | 'segment_index' | 'segment_total'> & { citations?: ChatCitation[] | null };export type ChatInterimEvent = WireEvent<'chat_interim', 'full_response' | 'round'>;