Skip to main content

Crate ed_agent_tauri

Crate ed_agent_tauri 

Source
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:

Structs§

ApprovalRequestedPayload
Payload for EVENT_CHAT_APPROVAL_REQUESTED when the approval handler is TauriApprovals. Answer it with chat_respond_approval { request_id, decision }.
ApprovalResolvedPayload
Payload for EVENT_CHAT_APPROVAL_RESOLVED.
ChatStatusPayload
Payload for EVENT_CHAT_STATUS_CHANGED.
EdSessions
Multi-session chat state: one Ed, many conversations.
EdSessionsBuilder
Configuration for EdSessions.
EdState
Managed state holding the agent.
SubmitReplyPayload
Payload for EVENT_CHAT_REPLY when the turn came through submit.
TauriApprovals
TauriSink
An EventSink that emits to the webview.
TextDeltaPayload
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 AgentReply when a full agent turn completes.
EVENT_CHAT_APPROVAL_REQUESTED
Emitted with an ApprovalRequest when a mutating tool is waiting on the user.
EVENT_CHAT_APPROVAL_RESOLVED
Emitted with an ApprovalResolvedPayload once 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 TextDeltaPayload for each piece of a reply as it is generated. Concatenate the deltas of one id to grow the assistant bubble; EVENT_CHAT_REPLY still arrives at the end with the whole text.
EVENT_CHAT_TOOL_FINISHED
Emitted with a ToolExecutionResult when a tool finishes, whether it succeeded or failed.
EVENT_CHAT_TOOL_REQUESTED
Emitted with a ToolCall when the model asks for a tool, before any approval or execution.
EVENT_CHAT_TOOL_STARTED
Emitted with a ToolCall once 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_requested event.
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 a chat_reply event carrying id.
chat_switch_session
Make session live and return its messages.