/*
 Generated by typeshare 1.13.4
*/

/**
 * All agent event kinds.
 * Typeshare-annotated: generated for TypeScript and Swift.
 * Uses adjacently tagged serde (`tag = "type", content = "data"`) for typeshare compatibility.
 */
export type AgentEventKind = 
	| { type: "session_created", data?: undefined }
	| { type: "prompt_received", data: {
	content: string;
	message_id?: string;
}}
	| { type: "user_message_stored", data: {
	content: string;
}}
	/**
	 * Emitted after the user message is stored and before the execution
	 * state machine begins. Signals the UI that preparation is underway
	 * (loading history, snapshotting, building tools, running middleware).
	 */
	| { type: "turn_started", data?: undefined }
	| { type: "assistant_message_stored", data: {
	content: string;
	thinking?: string;
	message_id?: string;
}}
	/**
	 * Streaming text delta emitted per token/chunk during streaming.
	 * Ephemeral — must not be persisted to the event store.
	 */
	| { type: "assistant_content_delta", data: {
	content: string;
	message_id: string;
}}
	/**
	 * Streaming thinking/reasoning delta emitted during streaming.
	 * Ephemeral — must not be persisted to the event store.
	 */
	| { type: "assistant_thinking_delta", data: {
	content: string;
	message_id: string;
}}
	/** Ephemeral transport signal for remote streaming over mesh. */
	| { type: "remote_stream_disconnected", data: {
	message: string;
	message_id?: string;
}}
	/** Ephemeral signal emitted when a remote stream resumes after reconnect. */
	| { type: "remote_stream_reconnected", data: {
	message: string;
	message_id?: string;
}}
	/** Ephemeral signal emitted when an attached remote session disconnects. */
	| { type: "remote_session_disconnected", data: {
	message: string;
	node_id?: string;
}}
	/** Ephemeral signal emitted when a remote provider host reports liveness while waiting. */
	| { type: "remote_provider_heartbeat", data: {
	phase: string;
	elapsed_ms: number;
	idle_ms: number;
	chunk_count: number;
	message_id?: string;
}}
	/**
	 * Ephemeral signal emitted when mid-stream transport error is detected.
	 * Accumulated text is discarded and a new stream is being created.
	 */
	| { type: "stream_recovering", data: {
	/** Human-readable error message that triggered the retry */
	message: string;
	/** Current attempt (1-indexed) */
	attempt: number;
	/** Maximum attempts */
	max_attempts: number;
	message_id?: string;
}}
	| { type: "llm_request_start", data: {
	message_count: number;
}}
	| { type: "llm_request_end", data: {
	usage?: UsageInfo;
	tool_calls: number;
	finish_reason?: string;
	/** Cost information for this request in USD */
	cost_usd?: number;
	/** Cumulative cost for the session in USD */
	cumulative_cost_usd?: number;
	/** Current context size (input + output tokens) */
	context_tokens: number;
	/** Execution progress metrics (steps/turns) */
	metrics: ExecutionMetrics;
}}
	| { type: "provider_changed", data: {
	provider: string;
	model: string;
	config_id: number;
	context_limit?: number;
	/**
	 * Mesh node that owns this provider. `None` = local node.
	 * Included so the UI can display a node badge next to the model label.
	 */
	provider_node_id?: string;
}}
	| { type: "tool_call_start", data: {
	tool_call_id: string;
	tool_name: string;
	arguments: string;
}}
	| { type: "tool_call_end", data: {
	tool_call_id: string;
	tool_name: string;
	is_error: boolean;
	result: string;
}}
	| { type: "hook_notice", data: {
	event_name: string;
	message: string;
	is_error: boolean;
}}
	| { type: "snapshot_start", data: {
	policy: string;
}}
	| { type: "snapshot_end", data: {
	summary?: string;
}}
	| { type: "compaction_start", data: {
	token_estimate: number;
}}
	| { type: "compaction_end", data: {
	summary: string;
	summary_len: number;
}}
	| { type: "middleware_injected", data: {
	message: string;
}}
	| { type: "middleware_stopped", data: {
	/** Type of stop (for UI to handle differently) */
	stop_type: StopType;
	/** Human-readable reason message */
	reason: string;
	/** Execution metrics at time of stop */
	metrics: ExecutionMetrics;
}}
	/** Emitted when a prompt is queued because another operation is executing */
	| { type: "session_queued", data: {
	/** Reason for queueing (e.g., "waiting for previous operation to complete") */
	reason: string;
}}
	| { type: "session_stop_requested", data?: undefined }
	| { type: "session_force_stopped", data: {
	escalated_after_ms: number;
	reason: string;
}}
	| { type: "cancelled", data?: undefined }
	| { type: "error", data: {
	message: string;
}}
	| { type: "intent_updated", data: {
	intent_snapshot: IntentSnapshot;
}}
	| { type: "task_created", data: {
	task: Task;
}}
	| { type: "task_updated", data: {
	task: Task;
}}
	| { type: "task_status_changed", data: {
	task: Task;
}}
	| { type: "decision_recorded", data: {
	decision: Decision;
}}
	| { type: "alternative_recorded", data: {
	alternative: Alternative;
}}
	| { type: "alternative_discarded", data: {
	alternative_id: number;
	task_id?: number;
}}
	| { type: "progress_recorded", data: {
	progress_entry: ProgressEntry;
}}
	| { type: "artifact_recorded", data: {
	artifact: Artifact;
}}
	| { type: "delegation_requested", data: {
	delegation: Delegation;
}}
	| { type: "delegation_completed", data: {
	delegation_id: string;
	result?: string;
}}
	| { type: "delegation_failed", data: {
	delegation_id: string;
	error: string;
}}
	| { type: "delegation_cancelled", data: {
	delegation_id: string;
}}
	| { type: "delegation_cancel_requested", data: {
	delegation_id: string;
}}
	| { type: "uncertainty_escalated", data: {
	task_id?: string;
	description: string;
	options: string[];
}}
	| { type: "permission_requested", data: {
	permission_id: string;
	task_id?: string;
	tool_name: string;
	reason: string;
}}
	| { type: "permission_granted", data: {
	permission_id: string;
	granted: boolean;
}}
	| { type: "elicitation_requested", data: {
	elicitation_id: string;
	session_id: string;
	message: string;
	requested_schema: any;
	source: string;
}}
	| { type: "session_forked", data: {
	parent_session_id: string;
	child_session_id: string;
	target_agent_id: string;
	origin: string;
	fork_point_type: string;
	fork_point_ref: string;
	instructions?: string;
}}
	/** Emitted once at session creation with environment configuration */
	| { type: "session_configured", data: {
	cwd?: string;
	mcp_servers: McpServerInfo[];
	/** Session limits configuration (if any) */
	limits?: SessionLimits;
}}
	/** Emitted at session start and whenever available tools change */
	| { type: "tools_available", data: {
	tools: ToolInfo[];
	tools_hash: string;
}}
	/** Emitted when duplicate/similar code is detected in newly written code */
	| { type: "duplicate_code_detected", data: {
	/** Compacted list of duplicate code warnings (body_text stripped, matches capped) */
	warnings: DuplicateWarning[];
	/** Path to the full overflow report file (if written), readable via read_file */
	overflow_path?: string;
}}
	/** Emitted when the agent's operating mode changes at runtime */
	| { type: "mode_changed", data: {
	mode: string;
	previous_mode: string;
}}
	/** Emitted when a session's mode changes (per-session mode in actor model) */
	| { type: "session_mode_changed", data: {
	mode: string;
}}
	/** LLM request was rate limited, execution is paused and waiting */
	| { type: "rate_limited", data: {
	/** Human-readable message from the provider */
	message: string;
	/** Seconds until retry will be attempted */
	wait_secs: number;
	/** When the wait started (Unix timestamp in seconds) */
	started_at: number;
	/** Current retry attempt (1-indexed) */
	attempt: number;
	/** Maximum retry attempts configured */
	max_attempts: number;
}}
	/** Rate limit wait completed, resuming execution */
	| { type: "rate_limit_resume", data: {
	/** Which attempt is now being made */
	attempt: number;
}}
	/**
	 * Emitted on the remote node once its workspace index has finished
	 * building and is available via `GetFileIndex`.  Flows through the
	 * EventForwarder → EventRelayActor → local EventSink chain so the
	 * local UI server can react without polling.
	 */
	| { type: "workspace_index_ready", data: {
	workspace_root: string;
}}
	/** A new schedule was created and armed. */
	| { type: "schedule_created", data: {
	schedule_public_id: string;
	session_public_id: string;
	task_public_id: string;
}}
	/** A schedule cycle was fired (ScheduledPrompt sent to SessionActor). */
	| { type: "schedule_fired", data: {
	schedule_public_id: string;
	session_public_id: string;
}}
	/** A scheduled cycle completed successfully. */
	| { type: "schedule_cycle_completed", data: {
	schedule_public_id: string;
	turn_id: string;
	run_count: number;
}}
	/** A scheduled cycle failed. */
	| { type: "schedule_cycle_failed", data: {
	schedule_public_id: string;
	turn_id?: string;
	error: string;
}}
	/** A schedule was paused by user/API. */
	| { type: "schedule_paused", data: {
	schedule_public_id: string;
}}
	/** A schedule was resumed by user/API. */
	| { type: "schedule_resumed", data: {
	schedule_public_id: string;
}}
	/** A schedule reached max_runs and is now exhausted. */
	| { type: "schedule_exhausted", data: {
	schedule_public_id: string;
}}
	/** A schedule exceeded its failure threshold. */
	| { type: "schedule_failed", data: {
	schedule_public_id: string;
	consecutive_failures: number;
}}
	/** SessionActor finished a scheduled execution cycle successfully. */
	| { type: "scheduled_execution_completed", data: {
	schedule_public_id: string;
	turn_id: string;
}}
	/** SessionActor's scheduled execution cycle failed. */
	| { type: "scheduled_execution_failed", data: {
	schedule_public_id: string;
	turn_id?: string;
	error: string;
}}
	/**
	 * Debounce window completed for an event-driven schedule.
	 * Internal event used by the scheduler to trigger after debounce.
	 */
	| { type: "schedule_debounce_completed", data: {
	schedule_public_id: string;
}}
	/** A new knowledge entry was ingested. */
	| { type: "knowledge_ingested", data: {
	scope: string;
	entry_public_id: string;
	source: string;
}}
	/** Knowledge entries were consolidated into an insight. */
	| { type: "knowledge_consolidated", data: {
	scope: string;
	consolidation_public_id: string;
	source_count: number;
}};

/**
 * A single agent event with metadata.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export interface AgentEvent {
	seq: number;
	timestamp: number;
	session_id: string;
	origin?: string;
	source_node?: string;
	kind: AgentEventKind;
}

/** Alternative status */
export enum AlternativeStatus {
	Active = "active",
	Discarded = "discarded",
}

/** Alternative approach considered (internal only) */
export interface Alternative {
	description: string;
	status: AlternativeStatus;
	created_at: string;
}

/** Artifact produced during task execution (internal only) */
export interface Artifact {
	kind: string;
	uri?: string;
	path?: string;
	summary?: string;
	created_at: string;
}

/** An audio-capable model entry returned in [`UiServerMessage::AudioCapabilities`]. */
export interface AudioModelInfo {
	/** Provider name (e.g. "izwi") */
	provider: string;
	/** Model name (e.g. "Qwen3-ASR-0.6B") */
	model: string;
}

/** Task kind determines lifecycle and completion semantics */
export enum TaskKind {
	/** One-time task with clear completion */
	Finite = "finite",
	/** Repeated or periodic task */
	Recurring = "recurring",
	/** Open-ended, continuously evolving task */
	Evolving = "evolving",
}

/** Task status tracks current state */
export enum TaskStatus {
	Active = "active",
	Paused = "paused",
	Done = "done",
	Cancelled = "cancelled",
}

/** A unit of work within a session */
export interface Task {
	public_id: string;
	kind: TaskKind;
	status: TaskStatus;
	expected_deliverable?: string;
	acceptance_criteria?: string;
	created_at: string;
	updated_at: string;
}

/** Snapshot of current user intent at a point in time (internal only) */
export interface IntentSnapshot {
	/** Authoritative summary of what the user wants */
	summary: string;
	/** Constraints or boundaries */
	constraints?: string;
	/** Hint for next action */
	next_step_hint?: string;
	created_at: string;
}

/** Decision status */
export enum DecisionStatus {
	Accepted = "accepted",
	Rejected = "rejected",
}

/** Records a decision made during task execution (internal only) */
export interface Decision {
	description: string;
	rationale?: string;
	status: DecisionStatus;
	created_at: string;
}

/** Progress entry kind */
export enum ProgressKind {
	ToolCall = "tool_call",
	Artifact = "artifact",
	Note = "note",
	Checkpoint = "checkpoint",
}

/** Records a step of progress during task execution (internal only) */
export interface ProgressEntry {
	kind: ProgressKind;
	content: string;
	/** JSON metadata for extensibility */
	metadata?: string;
	created_at: string;
}

/** Delegation status */
export enum DelegationStatus {
	Requested = "requested",
	Running = "running",
	Complete = "complete",
	Failed = "failed",
	Cancelled = "cancelled",
}

/** Agent-to-agent delegation record */
export interface Delegation {
	public_id: string;
	target_agent_id: string;
	objective: string;
	/** Rapidhash of objective for deduplication tracking */
	objective_hash: number;
	context?: string;
	constraints?: string;
	expected_output?: string;
	/** Optional structured verification specification (preferred over parsing expected_output) */
	verification_spec?: any;
	/** AI-generated summary of parent planning conversation for coder context */
	planning_summary?: string;
	status: DelegationStatus;
	/** Number of retry attempts for this objective */
	retry_count: number;
	created_at: string;
	completed_at?: string;
}

/** Full audit view with all details for internal/compliance use */
export interface AuditView {
	session_id: string;
	events: AgentEvent[];
	tasks: Task[];
	intent_snapshots: IntentSnapshot[];
	decisions: Decision[];
	progress_entries: ProgressEntry[];
	artifacts: Artifact[];
	delegations: Delegation[];
	generated_at: string;
}

/** OAuth authentication status for a provider. */
export enum OAuthStatus {
	NotAuthenticated = "not_authenticated",
	Expired = "expired",
	Connected = "connected",
}

/**
 * Preferred authentication method for a provider.
 * 
 * Stored in the system keyring under `auth_method_{provider}` and used by
 * the credential resolution logic to determine the order in which OAuth,
 * stored API key, and environment variable sources are tried.
 */
export enum AuthMethod {
	OAuth = "oauth",
	ApiKey = "api_key",
	EnvVar = "env_var",
}

/** Provider entry for dashboard auth UI (supports both OAuth and API token auth). */
export interface AuthProviderEntry {
	provider: string;
	display_name: string;
	/** OAuth status (`None` if provider has no OAuth support) */
	oauth_status?: OAuthStatus;
	/** Whether a manually-entered API key is stored in the keyring */
	has_stored_api_key: boolean;
	/** Whether the environment variable for this provider is set */
	has_env_api_key: boolean;
	/** The environment variable name for this provider (e.g. "OPENAI_API_KEY") */
	env_var_name?: string;
	/** Whether this provider supports OAuth flows */
	supports_oauth: boolean;
	/** User's preferred auth method (`None` = auto/default) */
	preferred_method?: AuthMethod;
}

/** Knowledge consolidation DTO for the UI (read-only). */
export interface ConsolidationInfo {
	public_id: string;
	scope: string;
	summary: string;
	insight: string;
	source_count: number;
	created_at: string;
}

/** Location of a function in source code */
export interface FunctionLocation {
	file_path: string;
	function_name: string;
	start_line: number;
	end_line: number;
}

/** A match found in the existing codebase */
export interface SimilarMatch {
	file_path: string;
	function_name: string;
	start_line: number;
	end_line: number;
	similarity: number;
	body_text: string;
}

/** A warning about duplicate code */
export interface DuplicateWarning {
	/** The newly written function that is similar to existing code */
	new_function: FunctionLocation;
	/** Matching functions from the codebase, ordered by similarity (highest first) */
	matches: SimilarMatch[];
}

/**
 * A durable event that has been persisted to the journal.
 * 
 * Contains a DB-assigned `event_id` and monotonic `stream_seq`.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export interface DurableEvent {
	event_id: string;
	stream_seq: number;
	session_id: string;
	timestamp: number;
	origin: string;
	source_node?: string;
	kind: AgentEventKind;
}

/**
 * An ephemeral event — live delivery only, no persistence, no sequence.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export interface EphemeralEvent {
	session_id: string;
	timestamp: number;
	origin: string;
	source_node?: string;
	kind: AgentEventKind;
}

/**
 * Execution progress metrics.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export interface ExecutionMetrics {
	/** Number of LLM calls made */
	steps: number;
	/** Number of user/assistant turns */
	turns: number;
}

/** A single entry in the file index. */
export interface FileIndexEntry {
	/** Relative path from the index root */
	path: string;
	/** Whether this entry is a directory */
	is_dir: boolean;
}

/**
 * Mirror of `querymt::chat::FunctionTool` for typeshare generation.
 * Note: kept for typeshare output; may be unused in Rust code paths.
 */
export interface FunctionToolInfo {
	name: string;
	description: string;
	/** JSON Schema for the function parameters */
	parameters: any;
}

/** Knowledge entry DTO for the UI (read-only). */
export interface KnowledgeEntryInfo {
	public_id: string;
	scope: string;
	source: string;
	summary: string;
	entities: string[];
	topics: string[];
	importance: number;
	consolidated_at?: string;
	created_at: string;
}

/** Metadata about a session available on a remote node. */
export interface RemoteSessionInfo {
	/** Session public ID (same format as local sessions) */
	session_id: string;
	/** kameo ActorId of the SessionActor on the remote node (raw u64) */
	actor_id: number;
	/** Working directory on the remote machine (if set) */
	cwd?: string;
	/** Unix timestamp when the session was created */
	created_at: number;
	/** Session title/name, if set */
	title?: string;
	/** Human-readable label of the peer that owns this session */
	peer_label: string;
	/** High-level runtime lifecycle state for UI summaries. */
	runtime_state?: string;
}

/** Paginated response for listing sessions on a remote node. */
export interface ListRemoteSessionsResponse {
	/** Sessions in the requested page. */
	sessions: RemoteSessionInfo[];
	/** Offset for the next page; `None` when there are no more pages. */
	next_offset?: number;
	/** Total sessions across all pages. */
	total_count: number;
}

/**
 * Mirror of `querymt::mcp::config::McpServerConfig` for typeshare generation.
 * Note: kept for typeshare output; may be unused in Rust code paths.
 */
export interface McpServerInfo {
	name: string;
	/** Transport protocol: "http" or "stdio" */
	protocol: string;
	/** URL for HTTP transport, command for stdio transport */
	endpoint: string;
}

/** Mesh invite DTO for the UI. */
export interface MeshInviteInfo {
	invite_id: string;
	mesh_name?: string;
	expires_at: number;
	max_uses: number;
	uses_remaining: number;
	/** pending | consumed | revoked */
	status: string;
	used_by: string[];
	created_at: number;
}

/** Cached model list entry with canonical identity. */
export interface ModelEntry {
	/** Canonical internal identifier (e.g., "hf:repo:file.gguf", "file:/path/to/model.gguf", or provider-specific ID) */
	id: string;
	/** Human-readable display label */
	label: string;
	/** Model source: "preset", "cached", "custom", "catalog" */
	source: string;
	/** Provider name */
	provider: string;
	/** Original model identifier (for backwards compatibility) */
	model: string;
	/** Stable node id where this provider lives. `None` = local node. */
	node_id?: string;
	/** Human-readable node label for display purposes. */
	node_label?: string;
	/** Model family/repo for grouping (e.g., "Qwen2.5-Coder-32B-Instruct") */
	family?: string;
	/** Quantization level (e.g., "Q8_0", "Q6_K", "unknown") */
	quant?: string;
}

/** Result of updating a single OCI plugin, reported in `PluginUpdateComplete`. */
export interface PluginUpdateResult {
	plugin_name: string;
	success: boolean;
	message?: string;
}

export interface ProviderCapabilityEntry {
	provider: string;
	supports_custom_models: boolean;
}

/** Recent model usage entry from event history. */
export interface RecentModelEntry {
	provider: string;
	model: string;
	last_used: string;
	use_count: number;
}

/** Information about a remote node discovered in the kameo mesh. */
export interface RemoteNodeInfo {
	/** Stable mesh node id (PeerId string). */
	id: string;
	/** Human-readable label / hostname */
	label: string;
	/** Node capabilities */
	capabilities: string[];
	/** Number of active sessions on the node */
	active_sessions: number;
}

/** Schedule information DTO for the UI. */
export interface ScheduleInfo {
	public_id: string;
	task_public_id: string;
	session_public_id: string;
	node_id?: string;
	/** Serialized trigger config */
	trigger: any;
	/** Current state: armed, running, paused, exhausted, failed */
	state: string;
	last_run_at?: string;
	next_run_at?: string;
	run_count: number;
	consecutive_failures: number;
	max_runs?: number;
	max_runtime_seconds: number;
	created_at: string;
	updated_at: string;
}

export interface SessionSummary {
	session_id: string;
	name?: string;
	cwd?: string;
	title?: string;
	created_at?: string;
	updated_at?: string;
	parent_session_id?: string;
	fork_origin?: string;
	session_kind?: string;
	has_children: boolean;
	fork_count: number;
	node?: string;
	node_id?: string;
	attached?: boolean;
	runtime_state?: string;
}

export interface SessionGroup {
	cwd?: string;
	sessions: SessionSummary[];
	latest_activity?: string;
	total_count: number;
	next_cursor?: string;
}

/**
 * Session limits configuration (exposed to UI)
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export interface SessionLimits {
	/** Maximum number of LLM calls */
	max_steps?: number;
	/** Maximum number of user/assistant turns */
	max_turns?: number;
	/** Maximum cost in USD */
	max_cost_usd?: number;
}

export interface StreamCursor {
	local_seq: number;
	remote_seq_by_source: Record<string, number>;
}

export interface SessionLoadSnapshot {
	audit: AuditView;
	cursor: StreamCursor;
}

/**
 * Mirror of `querymt::chat::Tool` for typeshare generation.
 * Note: kept for typeshare output; may be unused in Rust code paths.
 */
export interface ToolInfo {
	/** The type of tool (e.g. "function") */
	type: string;
	/** The function definition */
	function: FunctionToolInfo;
}

/** Information about an available agent for the UI. */
export interface UiAgentInfo {
	id: string;
	name: string;
	description: string;
	capabilities: string[];
}

export interface UiProfileInfo {
	id: string;
	name: string;
	description?: string;
	tags: string[];
	config_kind?: string;
	source: string;
	fingerprint?: string;
}

export interface UndoStackFrame {
	message_id: string;
}

/**
 * Mirror of `querymt::Usage` for typeshare generation.
 * Fields match the serialized JSON shape of the upstream type.
 * 
 * Note: kept for typeshare output; may be unused in Rust code paths.
 */
export interface UsageInfo {
	input_tokens?: number;
	output_tokens?: number;
	reasoning_tokens?: number;
	cache_read?: number;
	cache_write?: number;
}

/**
 * Whether an event must be persisted to the journal (durable) or is
 * live-only (ephemeral).
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export enum Durability {
	/** Must be persisted; replayable via journal. */
	Durable = "durable",
	/** Live-only; never written to journal, never replayed. */
	Ephemeral = "ephemeral",
}

/**
 * A tagged union of durable and ephemeral events for the fanout layer.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export type EventEnvelope = 
	| { type: "durable", data: DurableEvent }
	| { type: "ephemeral", data: EphemeralEvent };

/**
 * Known values for `EventOrigin`, exposed for TypeScript/Swift type safety.
 * 
 * The real `EventOrigin` has a custom Serialize/Deserialize impl that
 * serializes to plain strings (`"local"`, `"remote"`, or any other string
 * for the `Unknown` variant). The `Unknown(String)` catch-all prevents
 * standard serde enum derivation, so `#[typeshare]` can't be applied to
 * the original type. The `origin` fields on events use
 * `serialized_as = "string"` because any string value is valid at runtime.
 * 
 * This enum provides the known discriminants for TS/Swift code to compare against.
 * Note: kept for typeshare output; may be unused in Rust code paths.
 */
export enum EventOriginKind {
	Local = "local",
	Remote = "remote",
}

/** Fork origin (why the fork happened) */
export enum ForkOrigin {
	User = "user",
	Delegation = "delegation",
}

/** Fork point type */
export enum ForkPointType {
	MessageIndex = "message_index",
	ProgressEntry = "progress_entry",
}

/**
 * Mirror of `querymt_utils::OAuthFlowKind` for typeshare generation.
 * Matches the serialized JSON values of the upstream enum.
 * Note: kept for typeshare output; may be unused in Rust code paths.
 */
export enum OAuthFlowKindTs {
	/** Redirect/callback flow where the user pastes the callback URL or code. */
	RedirectCode = "redirect_code",
	/** Device flow where the backend polls the provider's token endpoint. */
	DevicePoll = "device_poll",
}

export enum RoutingMode {
	Single = "single",
	Broadcast = "broadcast",
}

export enum SessionScope {
	All = "all",
	Root = "root",
	Forks = "forks",
	Delegates = "delegates",
	Children = "children",
}

/**
 * Why execution was stopped.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export enum StopType {
	/** Step limit reached (max LLM calls) */
	StepLimit = "step_limit",
	/** Turn limit reached (max user/assistant exchanges) */
	TurnLimit = "turn_limit",
	/** Price/cost limit exceeded */
	PriceLimit = "price_limit",
	/** Context token threshold reached (compaction needed) */
	ContextThreshold = "context_threshold",
	/** Model hit its token limit */
	ModelTokenLimit = "model_token_limit",
	/** Content filter blocked the response */
	ContentFilter = "content_filter",
	/** Delegation was blocked */
	DelegationBlocked = "delegation_blocked",
	/** Generic/unknown stop reason */
	Other = "other",
}

/**
 * Messages from UI client to server.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export type UiClientMessage = 
	| { type: "init", data?: undefined }
	| { type: "set_active_agent", data: {
	agent_id: string;
}}
	| { type: "set_active_profile", data: {
	profile_id: string;
}}
	| { type: "list_profiles", data?: undefined }
	| { type: "set_routing_mode", data: {
	mode: RoutingMode;
}}
	| { type: "new_session", data: {
	cwd?: string;
	request_id?: string;
	profile_id?: string;
}}
	| { type: "prompt", data: {
	prompt: UiPromptBlock[];
}}
	| { type: "list_sessions", data: {
	/** Query mode: browse (default), group, or search. */
	mode?: string;
	/** Opaque pagination cursor (offset as string for now). */
	cursor?: string;
	/** Max number of sessions to return. */
	limit?: number;
	/** Group key for mode=group (cwd path or null-group marker). */
	cwd?: string;
	/** Search query for mode=search. */
	query?: string;
	/** Session scope filter: all (default), root, forks, delegates, or children. */
	session_scope?: SessionScope;
	/**
	 * When true, merge remote mesh sessions into the response.
	 * Defaults to false so local session opening is never blocked on
	 * remote discovery. The frontend sets this explicitly when the
	 * session picker needs remote sessions.
	 */
	include_remote?: boolean;
}}
	| { type: "list_session_children", data: {
	parent_session_id: string;
	/** Opaque pagination cursor (offset as string for now). */
	cursor?: string;
	/** Max number of child sessions to return. */
	limit?: number;
	/** Child scope filter. Defaults to forks; delegates are never returned here. */
	session_scope?: SessionScope;
}}
	| { type: "load_session", data: {
	session_id: string;
}}
	| { type: "delete_session", data: {
	session_id: string;
}}
	| { type: "list_all_models", data: {
	refresh?: boolean;
}}
	| { type: "set_session_model", data: {
	session_id: string;
	model_id: string;
	/** Optional mesh node id (PeerId string) that owns the provider. `None` = local. */
	node_id?: string;
}}
	/** Get recent models from event history */
	| { type: "get_recent_models", data: {
	limit_per_workspace?: number;
}}
	/** Request file index for @ mentions */
	| { type: "get_file_index", data?: undefined }
	/** Request LLM config details by config_id */
	| { type: "get_llm_config", data: {
	config_id: number;
}}
	/** Cancel the active session for the current agent */
	| { type: "cancel_session", data?: undefined }
	/** Undo filesystem changes to a specific message point */
	| { type: "undo", data: {
	message_id: string;
}}
	/** Redo: restore filesystem to pre-undo state */
	| { type: "redo", data?: undefined }
	/** Fork the active session at a specific message boundary. */
	| { type: "fork_session", data: {
	message_id: string;
}}
	/** Subscribe to a session's event stream */
	| { type: "subscribe_session", data: {
	session_id: string;
	agent_id?: string;
}}
	/** Unsubscribe from a session's event stream */
	| { type: "unsubscribe_session", data: {
	session_id: string;
}}
	/** Respond to an elicitation request */
	| { type: "elicitation_response", data: {
	elicitation_id: string;
	session_id?: string;
	action: string;
	content: any;
}}
	/** List configured OAuth-capable providers and their auth status */
	| { type: "list_auth_providers", data?: undefined }
	/** Start OAuth login flow for provider */
	| { type: "start_oauth_login", data: {
	provider: string;
}}
	/** Complete OAuth login flow using pasted callback URL/code */
	| { type: "complete_oauth_login", data: {
	flow_id: string;
	response: string;
}}
	/** Disconnect OAuth credentials for provider */
	| { type: "disconnect_oauth", data: {
	provider: string;
}}
	/** Set the agent's operating mode (build/plan/review) */
	| { type: "set_agent_mode", data: {
	mode: string;
}}
	/** Get the current agent mode */
	| { type: "get_agent_mode", data?: undefined }
	/** Set the reasoning effort level for the current session */
	| { type: "set_reasoning_effort", data: {
	reasoning_effort: string;
}}
	/** Get the current reasoning effort level */
	| { type: "get_reasoning_effort", data?: undefined }
	/** List remote nodes discovered in the kameo mesh */
	| { type: "list_remote_nodes", data?: undefined }
	/** List sessions on a specific remote node */
	| { type: "list_remote_sessions", data: {
	/** Stable node id (PeerId string) identifying the target node */
	node_id: string;
	/** Number of sessions to skip (default 0) */
	offset?: number;
	/** Maximum sessions to return (default 20, clamped to 1..100) */
	limit?: number;
}}
	/** Create a new session on a specific remote node */
	| { type: "create_remote_session", data: {
	/** Stable node id (PeerId string) identifying the target node */
	node_id: string;
	/** Working directory on the remote machine (optional) */
	cwd?: string;
	/** Client-generated request ID for correlating the response */
	request_id?: string;
}}
	/** Attach an existing remote session to the local dashboard */
	| { type: "attach_remote_session", data: {
	/** Stable node id (PeerId string) identifying the target node */
	node_id: string;
	/** Session ID to attach */
	session_id: string;
}}
	/** Remove a persisted remote session bookmark and detach if currently attached */
	| { type: "dismiss_remote_session", data: {
	session_id: string;
}}
	| { type: "add_custom_model_from_hf", data: {
	provider: string;
	repo: string;
	filename: string;
	display_name?: string;
}}
	| { type: "add_custom_model_from_file", data: {
	provider: string;
	file_path: string;
	display_name?: string;
}}
	| { type: "delete_custom_model", data: {
	provider: string;
	model_id: string;
}}
	/** Set an API token for a provider (stored in SecretStore) */
	| { type: "set_api_token", data: {
	provider: string;
	api_key: string;
}}
	/** Clear a stored API token for a provider */
	| { type: "clear_api_token", data: {
	provider: string;
}}
	/** Set the preferred auth method for a provider */
	| { type: "set_auth_method", data: {
	provider: string;
	method: AuthMethod;
}}
	/** Trigger an update of all OCI provider plugins. */
	| { type: "update_plugins", data?: undefined }
	/** Create a new schedule (recurring task + schedule trigger) */
	| { type: "create_schedule", data: {
	session_id: string;
	/** Optional remote node that owns the session/schedule. */
	node_id?: string;
	/** Prompt text for each cycle (becomes the task's expected_deliverable) */
	prompt: string;
	/** Trigger configuration as JSON (ScheduleTrigger) */
	trigger: any;
	/** Optional execution limits */
	max_steps?: number;
	max_cost_usd?: number;
	/** Optional max runs before exhaustion */
	max_runs?: number;
}}
	/** List schedules for a session (or all if session_id is None) */
	| { type: "list_schedules", data: {
	session_id?: string;
	node_id?: string;
}}
	/** Pause a schedule */
	| { type: "pause_schedule", data: {
	schedule_public_id: string;
	session_id?: string;
	node_id?: string;
}}
	/** Resume a paused schedule */
	| { type: "resume_schedule", data: {
	schedule_public_id: string;
	session_id?: string;
	node_id?: string;
}}
	/** Trigger a schedule to fire immediately */
	| { type: "trigger_schedule", data: {
	schedule_public_id: string;
	session_id?: string;
	node_id?: string;
}}
	/** Delete a schedule */
	| { type: "delete_schedule", data: {
	schedule_public_id: string;
	session_id?: string;
	node_id?: string;
}}
	/** Create a new mesh invite token */
	| { type: "create_mesh_invite", data: {
	/** Optional human-readable mesh name */
	mesh_name?: string;
	/** TTL as human string: "24h", "7d", "none". Default: "24h". */
	ttl?: string;
	/** Max uses (0 = unlimited, default 1) */
	max_uses?: number;
}}
	/** List active (pending) mesh invites */
	| { type: "list_mesh_invites", data?: undefined }
	/** Revoke a mesh invite by ID */
	| { type: "revoke_mesh_invite", data: {
	invite_id: string;
}}
	/** Query the knowledge store */
	| { type: "query_knowledge", data: {
	scope: string;
	question: string;
	limit?: number;
}}
	/** List knowledge entries for a scope */
	| { type: "list_knowledge", data: {
	scope: string;
	/** Optional filter as JSON (topics, entities, since, consolidated, limit) */
	filter?: any;
}}
	/** Get knowledge stats for a scope */
	| { type: "knowledge_stats", data: {
	scope: string;
}}
	/**
	 * Transcribe audio to text (STT).
	 * 
	 * Sent as a **binary WebSocket frame** with a length-prefixed JSON header
	 * (this struct) followed by raw audio bytes. The JSON header is parsed
	 * separately by `parse_binary_frame`; the audio payload is passed directly
	 * to the handler.
	 */
	| { type: "transcribe", data: {
	/** Provider name (e.g. "izwi") */
	provider: string;
	/** Model name (e.g. "Qwen3-ASR-0.6B") */
	model: string;
	/** MIME type of the audio payload (e.g. "audio/wav", "audio/webm"). */
	mime_type?: string;
}}
	/**
	 * Synthesize speech from text (TTS).
	 * 
	 * Sent as a normal JSON text frame. The response (`speech_result`) is a
	 * binary frame containing a JSON header + raw audio bytes.
	 */
	| { type: "speech", data: {
	/** Provider name (e.g. "izwi") */
	provider: string;
	/** Model name (e.g. "Kokoro-82M") */
	model: string;
	/** Text to synthesize */
	text: string;
	/** Optional voice/speaker preset name */
	voice?: string;
	/** Target audio format: "wav" (default) */
	format?: string;
}};

/**
 * A block of content in a UI prompt (text or resource reference).
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export type UiPromptBlock = 
	| { type: "text", data: {
	text: string;
}}
	| { type: "resource_link", data: {
	name: string;
	uri: string;
	description?: string;
}};

/**
 * Messages from server to UI client.
 * Typeshare-annotated: generated for TypeScript and Swift.
 */
export type UiServerMessage = 
	| { type: "state", data: {
	routing_mode: RoutingMode;
	active_agent_id: string;
	active_session_id?: string;
	default_cwd?: string;
	agents: UiAgentInfo[];
	profiles: UiProfileInfo[];
	active_profile_id?: string;
	sessions_by_agent: Record<string, string>;
	agent_mode: string;
	reasoning_effort?: string;
}}
	| { type: "session_created", data: {
	agent_id: string;
	profile_id?: string;
	session_id: string;
	request_id?: string;
}}
	| { type: "event", data: {
	agent_id: string;
	profile_id?: string;
	session_id: string;
	event: EventEnvelope;
}}
	| { type: "session_events", data: {
	session_id: string;
	agent_id: string;
	profile_id?: string;
	events: EventEnvelope[];
	cursor: StreamCursor;
}}
	| { type: "error", data: {
	message: string;
}}
	| { type: "session_list", data: {
	groups: SessionGroup[];
	next_cursor?: string;
	total_count: number;
}}
	| { type: "session_children", data: {
	parent_session_id: string;
	sessions: SessionSummary[];
	next_cursor?: string;
	total_count: number;
}}
	| { type: "session_loaded", data: {
	session_id: string;
	agent_id: string;
	profile_id?: string;
	node_id?: string;
	audit: AuditView;
	undo_stack: UndoStackFrame[];
	cursor: StreamCursor;
}}
	| { type: "workspace_index_status", data: {
	session_id: string;
	status: string;
	message?: string;
}}
	| { type: "all_models_list", data: {
	models: ModelEntry[];
}}
	/** Recent models from event history, grouped by workspace */
	| { type: "recent_models", data: {
	by_workspace: Record<string, RecentModelEntry[]>;
}}
	| { type: "provider_capabilities", data: {
	providers: ProviderCapabilityEntry[];
}}
	/** File index for autocomplete */
	| { type: "file_index", data: {
	files: FileIndexEntry[];
	generated_at: number;
}}
	/** LLM config details response */
	| { type: "llm_config", data: {
	config_id: number;
	provider: string;
	model: string;
	params: any;
}}
	/** Result of an undo operation */
	| { type: "undo_result", data: {
	success: boolean;
	message?: string;
	reverted_files: string[];
	message_id?: string;
	undo_stack: UndoStackFrame[];
}}
	/** Result of a redo operation */
	| { type: "redo_result", data: {
	success: boolean;
	message?: string;
	undo_stack: UndoStackFrame[];
}}
	/** Result of a fork operation. */
	| { type: "fork_result", data: {
	success: boolean;
	source_session_id?: string;
	forked_session_id?: string;
	message?: string;
}}
	/** Current agent mode notification */
	| { type: "agent_mode", data: {
	mode: string;
}}
	/** Current reasoning effort notification */
	| { type: "reasoning_effort", data: {
	reasoning_effort?: string;
}}
	/** OAuth-capable providers and current authentication status */
	| { type: "auth_providers", data: {
	providers: AuthProviderEntry[];
}}
	/** OAuth flow started; frontend should open authorization_url */
	| { type: "oauth_flow_started", data: {
	flow_id: string;
	provider: string;
	authorization_url: string;
	flow_kind: OAuthFlowKindTs;
}}
	/** OAuth flow completion result */
	| { type: "oauth_result", data: {
	provider: string;
	success: boolean;
	message: string;
}}
	/** List of remote nodes discovered in the kameo mesh */
	| { type: "remote_nodes", data: {
	nodes: RemoteNodeInfo[];
}}
	/** Sessions available on a specific remote node */
	| { type: "remote_sessions", data: {
	/** Stable node id (PeerId string) */
	node_id: string;
	/** Sessions on that node */
	sessions: RemoteSessionInfo[];
	/** Offset for the next page; omitted when there are no more pages */
	next_offset?: number;
	/** Total sessions across all pages */
	total_count?: number;
}}
	/** Newly created mesh invite */
	| { type: "mesh_invite_created", data: {
	invite_id: string;
	url: string;
	qr_code?: string;
	expires_at: number;
	max_uses: number;
	mesh_name?: string;
}}
	/** List of mesh invites */
	| { type: "mesh_invite_list", data: {
	invites: MeshInviteInfo[];
}}
	/** Invite revocation result */
	| { type: "mesh_invite_revoked", data: {
	invite_id: string;
	success: boolean;
	message?: string;
}}
	| { type: "model_download_status", data: {
	provider: string;
	model_id: string;
	status: string;
	bytes_downloaded: number;
	bytes_total?: number;
	percent?: number;
	speed_bps?: number;
	eta_seconds?: number;
	message?: string;
}}
	/** Progress update for an OCI plugin update operation. */
	| { type: "plugin_update_status", data: {
	plugin_name: string;
	image_reference: string;
	phase: string;
	bytes_downloaded: number;
	bytes_total?: number;
	percent?: number;
	message?: string;
}}
	/** All OCI plugin updates have completed. */
	| { type: "plugin_update_complete", data: {
	results: PluginUpdateResult[];
}}
	/** Result of setting/clearing an API token */
	| { type: "api_token_result", data: {
	provider: string;
	success: boolean;
	message: string;
}}
	/** Schedule list response */
	| { type: "schedule_list", data: {
	schedules: ScheduleInfo[];
	session_id?: string;
	node_id?: string;
}}
	/** Schedule created successfully */
	| { type: "schedule_created_result", data: {
	success: boolean;
	schedule_public_id?: string;
	node_id?: string;
	message?: string;
}}
	/** Schedule action result (pause/resume/trigger/delete) */
	| { type: "schedule_action_result", data: {
	success: boolean;
	schedule_public_id: string;
	action: string;
	node_id?: string;
	message?: string;
}}
	/** Knowledge query result (entries + consolidations) */
	| { type: "knowledge_query_result", data: {
	entries: KnowledgeEntryInfo[];
	consolidations: ConsolidationInfo[];
}}
	/** Knowledge list result */
	| { type: "knowledge_list_result", data: {
	entries: KnowledgeEntryInfo[];
}}
	/** Knowledge stats result */
	| { type: "knowledge_stats_result", data: {
	total_entries: number;
	unconsolidated_entries: number;
	total_consolidations: number;
	latest_entry_at?: string;
	latest_consolidation_at?: string;
}}
	/** STT transcription result (text frame) */
	| { type: "transcribe_result", data: {
	text: string;
}}
	/** Audio provider capabilities (sent during init) */
	| { type: "audio_capabilities", data: {
	stt_models: AudioModelInfo[];
	tts_models: AudioModelInfo[];
}};

