Expand description
Tauri bindings for Ed.
Ed’s core is framework-agnostic and reports through a
StatusSink. This crate is the Tauri implementation
of that sink plus the commands a webview calls.
§Wiring it up
Build an Ed around a TauriSink and manage it during
setup:
use ed_agent::Ed;
use ed_agent_tauri::{EdState, TauriSink};
use tauri::Manager;
fn setup(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
let ed = Ed::with_sink(TauriSink::new(app.handle().clone()));
app.manage(EdState::new(ed));
Ok(())
}Then register the commands on the builder. This can’t be a doc test — a
library has no tauri.conf.json for generate_context! to read:
tauri::Builder::default()
.setup(|app| setup(app))
.invoke_handler(tauri::generate_handler![
ed_agent_tauri::chat_get_status,
ed_agent_tauri::chat_get_history,
ed_agent_tauri::chat_clear_history,
ed_agent_tauri::chat_send_message,
ed_agent_tauri::chat_run,
ed_agent_tauri::chat_cancel,
])
.run(tauri::generate_context!())
.expect("run");Loading a model is deliberately not a command here: which model, and from
where, is an application decision. Call Ed::load
from your own command or during setup.
§Several conversations
For an app with a session list, build an EdSessions instead of an
EdState. You supply a SessionStore; it owns
the live session, the cache, the logout fence and approvals:
let sessions = EdSessions::builder(app.handle().clone(), MyStore::new())
.executor(my_executor)
.build();
app.manage(sessions);Register chat_list_sessions, chat_new_session, chat_switch_session,
chat_delete_session, chat_get_session_history, chat_submit and
chat_respond_approval. chat_submit returns at once and the answer comes
as a chat_reply event {id, session, reply, duration, error}, with
chat_text_delta {session, id, delta} events while it generates.
A host that has to rewrite the message first (to add context) or recover
from an engine failure wraps EdSessions::submit_with in a command of its
own. Call EdSessions::reset on logout or account switch.
§Tools
Tool calling works through this crate, but the host supplies the executor.
With EdSessions approvals are handled for you: TauriApprovals emits
chat_approval_requested {request_id, session, call, risk}, waits (120 s by
default) for chat_respond_approval {request_id, decision}, then emits
chat_approval_resolved {request_id}. A timeout or a reset denies.
With EdState, build the agent with
Ed::with_agent and your own
ApprovalHandler; the default Ed::with_sink
rejects every tool and denies every approval.
§Events
The first two are named exactly as the existing applications already emit them, so a frontend needs no change:
EVENT_CHAT_STATUS_CHANGEDwith aChatStatusPayloadEVENT_CHAT_REPLYwith aChatReplyEVENT_CHAT_TOOL_REQUESTEDwith aToolCallEVENT_CHAT_APPROVAL_REQUESTEDwith anApprovalRequestEVENT_CHAT_TOOL_STARTEDwith aToolCallEVENT_CHAT_TOOL_FINISHEDwith aToolExecutionResultEVENT_CHAT_AGENT_REPLYwith anAgentReplyEVENT_CHAT_WARNINGwith a stringEVENT_CHAT_TEXT_DELTAwith aTextDeltaPayloadEVENT_CHAT_APPROVAL_RESOLVEDwith anApprovalResolvedPayload
Structs§
- Approval
Requested Payload - Payload for
EVENT_CHAT_APPROVAL_REQUESTEDwhen the approval handler isTauriApprovals. Answer it withchat_respond_approval { request_id, decision }. - Approval
Resolved Payload - Payload for
EVENT_CHAT_APPROVAL_RESOLVED. - Chat
Status Payload - Payload for
EVENT_CHAT_STATUS_CHANGED. - EdSessions
- Multi-session chat state: one
Ed, many conversations. - EdSessions
Builder - Configuration for
EdSessions. - EdState
- Managed state holding the agent.
- Submit
Reply Payload - Payload for
EVENT_CHAT_REPLYwhen the turn came throughsubmit. - Tauri
Approvals - Tauri
Sink - An
EventSinkthat emits to the webview. - Text
Delta Payload - Payload for
EVENT_CHAT_TEXT_DELTA.
Constants§
- DEFAULT_
APPROVAL_ TIMEOUT - How long to wait for the user before denying.
- EVENT_
CHAT_ AGENT_ REPLY - Emitted with an
AgentReplywhen a full agent turn completes. - EVENT_
CHAT_ APPROVAL_ REQUESTED - Emitted with an
ApprovalRequestwhen a mutating tool is waiting on the user. - EVENT_
CHAT_ APPROVAL_ RESOLVED - Emitted with an
ApprovalResolvedPayloadonce an approval request has been answered, timed out, or cancelled, so the webview can close its sheet. - EVENT_
CHAT_ REPLY - Emitted once an inference turn completes, successfully or not.
- EVENT_
CHAT_ STATUS_ CHANGED - Emitted whenever the engine’s lifecycle status changes.
- EVENT_
CHAT_ TEXT_ DELTA - Emitted with a
TextDeltaPayloadfor each piece of a reply as it is generated. Concatenate the deltas of oneidto grow the assistant bubble;EVENT_CHAT_REPLYstill arrives at the end with the whole text. - EVENT_
CHAT_ TOOL_ FINISHED - Emitted with a
ToolExecutionResultwhen a tool finishes, whether it succeeded or failed. - EVENT_
CHAT_ TOOL_ REQUESTED - Emitted with a
ToolCallwhen the model asks for a tool, before any approval or execution. - EVENT_
CHAT_ TOOL_ STARTED - Emitted with a
ToolCallonce a tool is approved and about to run. - EVENT_
CHAT_ WARNING - Emitted with a string when Ed has something the user should see but the turn is still viable, such as an unverified model or a spent tool-round budget.
Functions§
- chat_
cancel - Cancel the agent turn in progress, if there is one.
- chat_
clear_ history - Clear the conversation, returning how many messages were dropped. The model stays loaded.
- chat_
delete_ session - chat_
get_ history - The conversation so far.
- chat_
get_ session_ history - The messages of
session, without switching to it. - chat_
get_ status - Current status, loaded model, footprint, and history length.
- chat_
list_ sessions - Stored sessions, most recently updated first.
- chat_
new_ session - Start an empty session and make it live. Returns its id.
- chat_
respond_ approval - Answer a
chat_approval_requestedevent. - chat_
run - Run a full agent turn, including any tools the host registered.
- chat_
send_ message - Run one inference turn.
- chat_
submit - Run a turn in
session. Returns at once; the result is achat_replyevent carryingid. - chat_
switch_ session - Make
sessionlive and return its messages.