loushoAgent() for Svelte is the React hook as a store: the same
sources, the same state and the same actions, over the same
typed event stream. Read React for what each
field means, the two kinds of source, how approvals work and the server side;
this page covers what differs.
It lives in the @lousho/build-ai-agent/svelte subpath. The store implements
Svelte’s store contract (subscribe(run) => unsubscribe) by hand, so it works
with $agent in Svelte 4 and 5 and needs no svelte import: there is no peer
dependency to install.
What differs from React
- State is the store value.
$agentis the React hook’s state object:messages,status,pendingApproval,error,usageandlastEvent. The commands (send,stop,approve,reject,answer) sit on the store itself with the React hook’s signatures; they do not need a subscriber. reset()aborts the run in flight, forgets the in-process session ({ agent, sessionId }starts a new conversation) and clears the state.- The source and options are plain values, read when a turn starts. To use
another agent or
url, create another store. - Cleanup is unsubscribing.
stop()aborts the request in flight, and so does the last subscriber going away (the component using$agentis destroyed). There is nodestroy(): this is how Svelte stores stop their work. A store nobody subscribes to still runs a turn you started withsend(); callstop()yourself if you drop it.
reduceAgentEvents, initialAgentUIState, parseEventStream), the same
ones as in @lousho/build-ai-agent/react.