/**
* SystemEvent - Base interface for all events in the system
*
* Unified Event Structure:
* ```
* SystemEvent
* │
* │  All events have: type, timestamp, data, source, category, intent
* │
* ├── source: "command"       ← API operations (request/response)
* │   ├── category: "request"   → container_create_request, agent_run_request...
* │   └── category: "response"  → container_create_response, agent_run_response...
* │
* ├── source: "environment"   ← External world (Claude API, Network)
* │   ├── category: "stream"    → message_start, text_delta, message_stop, tool_call...
* │   └── category: "connection"→ connected, disconnected, reconnecting
* │
* ├── source: "container"     ← Container operations
* │   └── category: "lifecycle" → container_created, container_destroyed, agent_registered...
* │
* ├── source: "session"       ← Session operations
* │   ├── category: "lifecycle" → session_created, session_destroyed
* │   ├── category: "persist"   → session_saved, message_persisted
* │   └── category: "action"    → session_resumed, session_forked
* │
* ├── source: "sandbox"       ← Sandbox resources
* │   ├── category: "workdir"   → file_read, file_written
* │   └── category: "mcp"       → tool_execute, mcp_server_connected
* │
* └── source: "agent"         ← Agent internal
*     ├── category: "stream"    → (forwarded from environment)
*     ├── category: "state"     → state transitions
*     ├── category: "message"   → complete messages
*     └── category: "turn"      → conversation turns
* ```
*
* Design Principles:
* - Unified: All events share the same base structure
* - Self-describing: source/category/intent tell you everything
* - Filterable: Easy to subscribe by source, category, or type
*/
/**
* Event source - where the event originated
*/
type EventSource = "environment" | "agent" | "session" | "container" | "sandbox" | "command";
/**
* Event intent - what the event represents
*/
type EventIntent = "request" | "result" | "notification";
/**
* Event category - fine-grained classification within source
*/
type EventCategory = "stream" | "connection" | "state" | "message" | "turn" | "error" | "lifecycle" | "persist" | "action" | "workdir" | "mcp" | "request" | "response";
/**
* UserContext - User-defined request context passed from client
*
* This context is passed through the entire request lifecycle:
* Client → WebSocket → Runtime → Agent → Model Service
*
* Purely user-customizable - define any fields you need for your application:
* - Authentication (userId, token, apiKey)
* - Multi-tenancy (tenantId, orgId)
* - Audit logging (clientIp, userAgent)
* - Business logic (permissions, roles, preferences)
*
* @example
* ```typescript
* const userContext: UserContext = {
*   userId: "user-123",
*   tenantId: "tenant-456",
*   token: "jwt-token",
*   roles: ["admin", "editor"],
*   preferences: { theme: "dark" }
* };
* ```
*/
type UserContext = Record<string, unknown>;
/**
* EventContext - Scope information attached to events
*/
interface EventContext {
	/**
	* Container ID (isolation boundary)
	*/
	containerId?: string;
	/**
	* Image ID (persistent conversation identity)
	*/
	imageId?: string;
	/**
	* Agent ID (if event is agent-scoped)
	*/
	agentId?: string;
	/**
	* Session ID (if event is session-scoped)
	*/
	sessionId?: string;
	/**
	* Turn ID (for correlating events within a single turn)
	* A turn = one user message + assistant response cycle
	*/
	turnId?: string;
	/**
	* Correlation ID (for request-response tracking)
	*/
	correlationId?: string;
	/**
	* User request context (passed from client)
	*
	* Contains user identity, authentication, and custom metadata
	* that flows through the entire request lifecycle.
	*/
	userContext?: UserContext;
}
/**
* SystemEvent - Base interface for ALL events in the system
*
* Every event has:
* - type: What happened (e.g., "text_delta", "session_saved")
* - timestamp: When it happened
* - data: Event payload
* - source: Where it came from
* - category: What kind of event
* - intent: What it means (notification/request/result)
* - context: Optional scope information
* - broadcastable: Whether to broadcast to external clients (default: true)
*/
interface SystemEvent<
	T extends string = string,
	D = unknown,
	S extends EventSource = EventSource,
	C extends EventCategory = EventCategory,
	I extends EventIntent = EventIntent
> {
	/**
	* Event type identifier (e.g., "text_delta", "session_saved")
	*/
	readonly type: T;
	/**
	* Event timestamp (Unix milliseconds)
	*/
	readonly timestamp: number;
	/**
	* Event payload data
	*/
	readonly data: D;
	/**
	* Event source - where the event originated
	*/
	readonly source: S;
	/**
	* Event category - fine-grained classification
	*/
	readonly category: C;
	/**
	* Event intent - what the event represents
	*/
	readonly intent: I;
	/**
	* Event context - scope information (optional)
	*/
	readonly context?: EventContext;
	/**
	* Whether to broadcast this event to external clients (SSE/WebSocket)
	*
	* - true or undefined: Broadcast to all external clients
	* - false: Only consumed internally, not broadcast
	*
	* Used for internal events like DriveableEvent that should be
	* processed by the engine but not sent directly to clients.
	* @default true
	*/
	readonly broadcastable?: boolean;
}
/**
* Check if event is from a specific source
*/
declare function isFromSource<S extends EventSource>(event: SystemEvent, source: S): event is SystemEvent<string, unknown, S>;
/**
* Check if event has a specific intent
*/
declare function hasIntent<I extends EventIntent>(event: SystemEvent, intent: I): event is SystemEvent<string, unknown, EventSource, EventCategory, I>;
/**
* Check if event is a request
*/
declare function isRequest(event: SystemEvent): boolean;
/**
* Check if event is a result
*/
declare function isResult(event: SystemEvent): boolean;
/**
* Check if event is a notification
*/
declare function isNotification(event: SystemEvent): boolean;
/**
* Reason why the LLM stopped generating
*
* Based on common stop reasons across multiple LLM providers:
* - Anthropic Claude: end_turn, max_tokens, tool_use, stop_sequence
* - OpenAI: stop, length, tool_calls, content_filter
* - Vercel AI SDK: stop, length, tool-calls, content-filter, error, other
*/
type StopReason = "end_turn" | "max_tokens" | "tool_use" | "stop_sequence" | "content_filter" | "error" | "other";
/**
* Base interface for all LLM stream events
*
* All DriveableEvents have:
* - source: "environment" (from external LLM)
* - category: "stream" (streaming output)
* - intent: "notification" (informational, no action needed)
* - requestId: correlation with the original request
* - context: agent/image/session scope (inherited from SystemEvent)
*/
interface BaseStreamEvent<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "environment", "stream", "notification"> {
	/**
	* Content block index (for multi-block responses)
	*/
	index?: number;
	/**
	* Request ID for correlating events with the original message_send_request
	*/
	requestId?: string;
}
/**
* MessageStartEvent - Emitted when streaming message begins
*/
interface MessageStartEvent extends BaseStreamEvent<"message_start", {
	message: {
		id: string
		model: string
	}
}> {}
/**
* MessageDeltaEvent - Emitted with message-level updates
*/
interface MessageDeltaEvent extends BaseStreamEvent<"message_delta", {
	usage?: {
		inputTokens: number
		outputTokens: number
	}
}> {}
/**
* MessageStopEvent - Emitted when streaming message completes
*/
interface MessageStopEvent extends BaseStreamEvent<"message_stop", {
	stopReason?: StopReason
	stopSequence?: string
}> {}
/**
* TextContentBlockStartEvent - Text block started
*/
interface TextContentBlockStartEvent extends BaseStreamEvent<"text_content_block_start", Record<string, never>> {
	index: number;
}
/**
* TextDeltaEvent - Incremental text output
*/
interface TextDeltaEvent extends BaseStreamEvent<"text_delta", {
	text: string
}> {}
/**
* TextContentBlockStopEvent - Text block completed
*/
interface TextContentBlockStopEvent extends BaseStreamEvent<"text_content_block_stop", Record<string, never>> {
	index: number;
}
/**
* ToolUseContentBlockStartEvent - Tool use block started
*/
interface ToolUseContentBlockStartEvent extends BaseStreamEvent<"tool_use_content_block_start", {
	id: string
	name: string
}> {
	index: number;
}
/**
* InputJsonDeltaEvent - Incremental tool input JSON
*/
interface InputJsonDeltaEvent extends BaseStreamEvent<"input_json_delta", {
	partialJson: string
}> {
	index: number;
}
/**
* ToolUseContentBlockStopEvent - Tool use block completed
*/
interface ToolUseContentBlockStopEvent extends BaseStreamEvent<"tool_use_content_block_stop", Record<string, never>> {
	index: number;
}
/**
* ToolCallEvent - Tool call ready for execution
*/
interface ToolCallEvent extends BaseStreamEvent<"tool_call", {
	id: string
	name: string
	input: Record<string, unknown>
}> {}
/**
* ToolResultEvent - Tool execution result
*/
interface ToolResultEvent extends BaseStreamEvent<"tool_result", {
	toolUseId: string
	result: unknown
	isError?: boolean
}> {}
/**
* InterruptedEvent - Stream interrupted
*/
interface InterruptedEvent extends BaseStreamEvent<"interrupted", {
	reason: "user_interrupt" | "timeout" | "error" | "system"
}> {}
/**
* ErrorReceivedEvent - Error received from environment (e.g., Claude API error)
*
* This event drives the MealyMachine to produce:
* - error_occurred (StateEvent) → state transitions to "error"
* - error_message (MessageEvent) → displayed in chat
*/
interface ErrorReceivedEvent extends BaseStreamEvent<"error_received", {
	/** Error message (human-readable) */
	message: string
	/** Error code (e.g., "rate_limit_error", "api_error", "overloaded_error") */
	errorCode?: string
}> {}
/**
* DriveableEvent - All events that can drive Agent
*/
type DriveableEvent2 = MessageStartEvent | MessageDeltaEvent | MessageStopEvent | TextContentBlockStartEvent | TextDeltaEvent | TextContentBlockStopEvent | ToolUseContentBlockStartEvent | InputJsonDeltaEvent | ToolUseContentBlockStopEvent | ToolCallEvent | ToolResultEvent | InterruptedEvent | ErrorReceivedEvent;
/**
* DriveableEventType - String literal union of all driveable event types
*/
type DriveableEventType = DriveableEvent2["type"];
/**
* Type guard: is this a DriveableEvent?
*/
declare function isDriveableEvent(event: SystemEvent): event is DriveableEvent2;
/**
* Base interface for all connection events
*/
interface BaseConnectionEvent<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "environment", "connection", "notification"> {}
/**
* ConnectedEvent - Connection established
*/
interface ConnectedEvent extends BaseConnectionEvent<"connected", {
	url?: string
	reconnectAttempt?: number
}> {}
/**
* DisconnectedEvent - Connection lost
*/
interface DisconnectedEvent extends BaseConnectionEvent<"disconnected", {
	reason?: string
	code?: number
	willReconnect?: boolean
}> {}
/**
* ReconnectingEvent - Attempting to reconnect
*/
interface ReconnectingEvent extends BaseConnectionEvent<"reconnecting", {
	attempt: number
	maxAttempts?: number
	delayMs: number
}> {}
/**
* ConnectionEvent - All network status events
*/
type ConnectionEvent2 = ConnectedEvent | DisconnectedEvent | ReconnectingEvent;
/**
* ConnectionEventType - String literal union
*/
type ConnectionEventType = ConnectionEvent2["type"];
/**
* Type guard: is this a ConnectionEvent?
*/
declare function isConnectionEvent(event: SystemEvent): event is ConnectionEvent2;
type EnvironmentEvent = import("./DriveableEvent").DriveableEvent | import("./ConnectionEvent").ConnectionEvent;
/**
* Base ContainerLifecycleEvent
*/
interface BaseContainerLifecycleEvent<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "container", "lifecycle", "notification"> {}
/**
* ContainerCreatedEvent - Container was created
*/
interface ContainerCreatedEvent extends BaseContainerLifecycleEvent<"container_created", {
	containerId: string
	name?: string
	createdAt: number
}> {}
/**
* ContainerDestroyedEvent - Container was destroyed
*/
interface ContainerDestroyedEvent extends BaseContainerLifecycleEvent<"container_destroyed", {
	containerId: string
	reason?: string
	agentCount: number
}> {}
/**
* AgentRegisteredEvent - Agent was registered to container
*/
interface AgentRegisteredEvent extends BaseContainerLifecycleEvent<"agent_registered", {
	containerId: string
	agentId: string
	definitionName: string
	registeredAt: number
}> {}
/**
* AgentUnregisteredEvent - Agent was unregistered from container
*/
interface AgentUnregisteredEvent extends BaseContainerLifecycleEvent<"agent_unregistered", {
	containerId: string
	agentId: string
	reason?: string
}> {}
/**
* ContainerLifecycleEvent - All container lifecycle events
*/
type ContainerLifecycleEvent = ContainerCreatedEvent | ContainerDestroyedEvent | AgentRegisteredEvent | AgentUnregisteredEvent;
/**
* Type guard: is this a ContainerLifecycleEvent?
*/
declare function isContainerLifecycleEvent(event: SystemEvent): event is ContainerLifecycleEvent;
/**
* Base WorkdirRequest
*/
interface BaseWorkdirRequest<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "sandbox", "workdir", "request"> {}
/**
* Base WorkdirResult
*/
interface BaseWorkdirResult<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "sandbox", "workdir", "result"> {}
/**
* Base WorkdirNotification
*/
interface BaseWorkdirNotification<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "sandbox", "workdir", "notification"> {}
/**
* FileReadRequest - Request to read a file
*/
interface FileReadRequest extends BaseWorkdirRequest<"file_read_request", {
	path: string
	encoding?: string
}> {}
/**
* FileReadResult - File read result
*/
interface FileReadResult extends BaseWorkdirResult<"file_read_result", {
	path: string
	content: string
	size: number
	encoding: string
}> {}
/**
* FileWriteRequest - Request to write a file
*/
interface FileWriteRequest extends BaseWorkdirRequest<"file_write_request", {
	path: string
	content: string
	encoding?: string
	createDirectories?: boolean
}> {}
/**
* FileWrittenEvent - File was written
*/
interface FileWrittenEvent extends BaseWorkdirResult<"file_written", {
	path: string
	size: number
	timestamp: number
}> {}
/**
* FileDeleteRequest - Request to delete a file
*/
interface FileDeleteRequest extends BaseWorkdirRequest<"file_delete_request", {
	path: string
	recursive?: boolean
}> {}
/**
* FileDeletedEvent - File was deleted
*/
interface FileDeletedEvent extends BaseWorkdirResult<"file_deleted", {
	path: string
	timestamp: number
}> {}
/**
* DirectoryListRequest - Request to list directory
*/
interface DirectoryListRequest extends BaseWorkdirRequest<"directory_list_request", {
	path: string
	recursive?: boolean
	pattern?: string
}> {}
/**
* DirectoryListResult - Directory listing result
*/
interface DirectoryListResult extends BaseWorkdirResult<"directory_list_result", {
	path: string
	entries: Array<{
		name: string
		type: "file" | "directory"
		size?: number
		modifiedAt?: number
	}>
}> {}
/**
* WorkdirErrorEvent - Workdir operation error
*/
interface WorkdirErrorEvent extends BaseWorkdirNotification<"workdir_error", {
	operation: string
	path: string
	code: string
	message: string
}> {}
/**
* WorkdirEvent - All workdir events
*/
type WorkdirEvent = FileReadRequest | FileReadResult | FileWriteRequest | FileWrittenEvent | FileDeleteRequest | FileDeletedEvent | DirectoryListRequest | DirectoryListResult | WorkdirErrorEvent;
/**
* Workdir request events
*/
type WorkdirRequestEvent = FileReadRequest | FileWriteRequest | FileDeleteRequest | DirectoryListRequest;
/**
* Workdir result events
*/
type WorkdirResultEvent = FileReadResult | FileWrittenEvent | FileDeletedEvent | DirectoryListResult;
/**
* Type guard: is this a WorkdirEvent?
*/
declare function isWorkdirEvent(event: SystemEvent): event is WorkdirEvent;
/**
* Base MCPRequest
*/
interface BaseMCPRequest<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "sandbox", "mcp", "request"> {}
/**
* Base MCPResult
*/
interface BaseMCPResult<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "sandbox", "mcp", "result"> {}
/**
* Base MCPNotification
*/
interface BaseMCPNotification<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "sandbox", "mcp", "notification"> {}
/**
* ToolExecuteRequest - Request to execute a tool
*/
interface ToolExecuteRequest extends BaseMCPRequest<"tool_execute_request", {
	toolId: string
	toolName: string
	serverName: string
	input: Record<string, unknown>
	timestamp: number
}> {}
/**
* ToolExecutedEvent - Tool execution completed
*/
interface ToolExecutedEvent extends BaseMCPResult<"tool_executed", {
	toolId: string
	toolName: string
	result: unknown
	duration: number
	timestamp: number
}> {}
/**
* ToolExecutionErrorEvent - Tool execution failed
*/
interface ToolExecutionErrorEvent extends BaseMCPNotification<"tool_execution_error", {
	toolId: string
	toolName: string
	code: string
	message: string
	timestamp: number
}> {}
/**
* MCPServerConnectedEvent - MCP server connected
*/
interface MCPServerConnectedEvent extends BaseMCPNotification<"mcp_server_connected", {
	serverName: string
	version?: string
	toolCount: number
	resourceCount: number
	timestamp: number
}> {}
/**
* MCPServerDisconnectedEvent - MCP server disconnected
*/
interface MCPServerDisconnectedEvent extends BaseMCPNotification<"mcp_server_disconnected", {
	serverName: string
	reason?: string
	timestamp: number
}> {}
/**
* ResourceReadRequest - Request to read an MCP resource
*/
interface ResourceReadRequest extends BaseMCPRequest<"resource_read_request", {
	serverName: string
	uri: string
}> {}
/**
* ResourceReadResult - Resource read result
*/
interface ResourceReadResult extends BaseMCPResult<"resource_read_result", {
	serverName: string
	uri: string
	content: unknown
	mimeType?: string
}> {}
/**
* MCPEvent - All MCP events
*/
type MCPEvent = ToolExecuteRequest | ToolExecutedEvent | ToolExecutionErrorEvent | MCPServerConnectedEvent | MCPServerDisconnectedEvent | ResourceReadRequest | ResourceReadResult;
/**
* MCP request events
*/
type MCPRequestEvent = ToolExecuteRequest | ResourceReadRequest;
/**
* MCP result events
*/
type MCPResultEvent = ToolExecutedEvent | ResourceReadResult;
/**
* Type guard: is this a MCPEvent?
*/
declare function isMCPEvent(event: SystemEvent): event is MCPEvent;
/**
* SandboxEvent - All sandbox events
*/
type SandboxEvent = WorkdirEvent | MCPEvent;
/**
* Type guard: is this a sandbox event?
*/
declare function isSandboxEvent(event: {
	source?: string
}): event is SandboxEvent;
/**
* ContainerEvent - All container events
*/
type ContainerEvent = ContainerLifecycleEvent | SandboxEvent;
/**
* Type guard: is this a container event?
*/
declare function isContainerEvent(event: {
	source?: string
}): event is ContainerEvent;
/**
* Base SessionLifecycleEvent
*/
interface BaseSessionLifecycleEvent<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "session", "lifecycle", "notification"> {}
/**
* SessionCreatedEvent - Session was created
*/
interface SessionCreatedEvent extends BaseSessionLifecycleEvent<"session_created", {
	sessionId: string
	imageId: string
	containerId: string
	title?: string
	createdAt: number
}> {}
/**
* SessionDestroyedEvent - Session was destroyed
*/
interface SessionDestroyedEvent extends BaseSessionLifecycleEvent<"session_destroyed", {
	sessionId: string
	reason?: string
}> {}
/**
* SessionLifecycleEvent - All session lifecycle events
*/
type SessionLifecycleEvent = SessionCreatedEvent | SessionDestroyedEvent;
/**
* Type guard: is this a SessionLifecycleEvent?
*/
declare function isSessionLifecycleEvent(event: SystemEvent): event is SessionLifecycleEvent;
/**
* Base SessionPersistRequest
*/
interface BaseSessionPersistRequest<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "session", "persist", "request"> {}
/**
* Base SessionPersistResult
*/
interface BaseSessionPersistResult<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "session", "persist", "result"> {}
/**
* SessionSaveRequest - Request to save session
*/
interface SessionSaveRequest extends BaseSessionPersistRequest<"session_save_request", {
	sessionId: string
	title?: string
	metadata?: Record<string, unknown>
}> {}
/**
* SessionSavedEvent - Session was saved
*/
interface SessionSavedEvent extends BaseSessionPersistResult<"session_saved", {
	sessionId: string
	savedAt: number
}> {}
/**
* MessagePersistRequest - Request to persist a message
*/
interface MessagePersistRequest extends BaseSessionPersistRequest<"message_persist_request", {
	sessionId: string
	messageId: string
	role: "user" | "assistant" | "tool_call" | "tool_result"
	content: unknown
}> {}
/**
* MessagePersistedEvent - Message was persisted
*/
interface MessagePersistedEvent extends BaseSessionPersistResult<"message_persisted", {
	sessionId: string
	messageId: string
	savedAt: number
}> {}
/**
* SessionPersistEvent - All session persist events
*/
type SessionPersistEvent = SessionSaveRequest | SessionSavedEvent | MessagePersistRequest | MessagePersistedEvent;
/**
* Session persist request events
*/
type SessionPersistRequestEvent = SessionSaveRequest | MessagePersistRequest;
/**
* Session persist result events
*/
type SessionPersistResultEvent = SessionSavedEvent | MessagePersistedEvent;
/**
* Type guard: is this a SessionPersistEvent?
*/
declare function isSessionPersistEvent(event: SystemEvent): event is SessionPersistEvent;
/**
* Base SessionActionRequest
*/
interface BaseSessionActionRequest<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "session", "action", "request"> {}
/**
* Base SessionActionResult
*/
interface BaseSessionActionResult<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "session", "action", "result"> {}
/**
* SessionResumeRequest - Request to resume a session
*/
interface SessionResumeRequest extends BaseSessionActionRequest<"session_resume_request", {
	sessionId: string
	containerId?: string
}> {}
/**
* SessionResumedEvent - Session was resumed
*/
interface SessionResumedEvent extends BaseSessionActionResult<"session_resumed", {
	sessionId: string
	agentId: string
	resumedAt: number
}> {}
/**
* SessionForkRequest - Request to fork a session
*/
interface SessionForkRequest extends BaseSessionActionRequest<"session_fork_request", {
	sessionId: string
	newTitle?: string
}> {}
/**
* SessionForkedEvent - Session was forked
*/
interface SessionForkedEvent extends BaseSessionActionResult<"session_forked", {
	originalSessionId: string
	newSessionId: string
	newImageId: string
	forkedAt: number
}> {}
/**
* SessionTitleUpdateRequest - Request to update session title
*/
interface SessionTitleUpdateRequest extends BaseSessionActionRequest<"session_title_update_request", {
	sessionId: string
	title: string
}> {}
/**
* SessionTitleUpdatedEvent - Session title was updated
*/
interface SessionTitleUpdatedEvent extends BaseSessionActionResult<"session_title_updated", {
	sessionId: string
	title: string
	updatedAt: number
}> {}
/**
* SessionActionEvent - All session action events
*/
type SessionActionEvent = SessionResumeRequest | SessionResumedEvent | SessionForkRequest | SessionForkedEvent | SessionTitleUpdateRequest | SessionTitleUpdatedEvent;
/**
* Session action request events
*/
type SessionActionRequestEvent = SessionResumeRequest | SessionForkRequest | SessionTitleUpdateRequest;
/**
* Session action result events
*/
type SessionActionResultEvent = SessionResumedEvent | SessionForkedEvent | SessionTitleUpdatedEvent;
/**
* Type guard: is this a SessionActionEvent?
*/
declare function isSessionActionEvent(event: SystemEvent): event is SessionActionEvent;
/**
* SessionEvent - All session events
*/
type SessionEvent = SessionLifecycleEvent | SessionPersistEvent | SessionActionEvent;
/**
* Type guard: is this a session event?
*/
declare function isSessionEvent(event: {
	source?: string
}): event is SessionEvent;
/**
* MCP Server Config (SDK Compatible)
*
* Configuration for MCP servers, compatible with Claude Agent SDK.
* Used in AgentConfig.mcpServers.
*
* Note: For stdio type, the 'type' field is optional (defaults to stdio).
*/
type McpServerConfig = McpStdioServerConfig | McpSseServerConfig | McpHttpServerConfig | McpSdkServerConfig;
/**
* Stdio Server Config (SDK Compatible)
* Type is optional, defaults to stdio when omitted.
*/
interface McpStdioServerConfig {
	type?: "stdio";
	command: string;
	args?: string[];
	env?: Record<string, string>;
}
/**
* SSE Server Config (SDK Compatible)
*/
interface McpSseServerConfig {
	type: "sse";
	url: string;
	headers?: Record<string, string>;
}
/**
* HTTP Server Config (SDK Compatible)
*/
interface McpHttpServerConfig {
	type: "http";
	url: string;
	headers?: Record<string, string>;
}
/**
* SDK Server Config (SDK Compatible)
* For in-process MCP servers.
*/
interface McpSdkServerConfig {
	type: "sdk";
	name: string;
	instance: unknown;
}
/**
* Image metadata for storing provider-specific data
*/
interface ImageMetadata {
	/** Claude SDK session ID for conversation resume */
	claudeSdkSessionId?: string;
	/** User context - serialized JSON string for passing to LLM Proxy via URL */
	userContext?: string;
}
/**
* Image storage record
*
* Represents a conversation that persists across server restarts.
*/
interface ImageRecord {
	/**
	* Unique image identifier
	* Pattern: `img_${nanoid()}`
	*/
	imageId: string;
	/**
	* Container ID (user isolation boundary)
	*/
	containerId: string;
	/**
	* Session ID for message storage
	* Messages are stored in Session, not duplicated here
	*/
	sessionId: string;
	/**
	* Conversation name (displayed to user)
	*/
	name: string;
	/**
	* Conversation description (optional)
	*/
	description?: string;
	/**
	* System prompt - controls agent behavior
	*/
	systemPrompt?: string;
	/**
	* Parent image ID (for fork/branch feature)
	*/
	parentImageId?: string;
	/**
	* MCP servers configuration
	*/
	mcpServers?: Record<string, McpServerConfig>;
	/**
	* Blacklist of disallowed tools (tool names)
	* When set, these tools will be disabled for the agent
	*/
	disallowedTools?: string[];
	/**
	* Restrict available tools - can be array of tool names or preset
	* More granular control over which built-in tools are available
	*/
	tools?: string[] | {
		type: "preset"
		preset: "claude_code"
	};
	/**
	* Claude Code 风格的 Skills
	* 每个 skill 会被写入 .claude/skills/{name}/SKILL.md
	* SDK 自动发现并注入到 Claude 的 context 中
	*/
	skills?: import("~/agentx").SkillDefinition[];
	/**
	* Per-image LLM configuration (optional)
	*
	* When set, this image's agent will use this LLM config instead of the global Runtime-level config.
	* Enables different conversations/roles to use different LLM providers or models.
	* Fields are merged with global config: only non-empty fields override the global defaults.
	*/
	llmConfig?: {
		apiKey?: string
		baseUrl?: string
		model?: string
	};
	/**
	* Provider-specific metadata (e.g., Claude SDK session ID)
	*/
	metadata?: ImageMetadata;
	/**
	* Creation timestamp (Unix milliseconds)
	*/
	createdAt: number;
	/**
	* Last update timestamp (Unix milliseconds)
	*/
	updatedAt: number;
}
/**
* Text Part
*
* Plain text content in a message.
*/
interface TextPart {
	/** Content type discriminator */
	type: "text";
	/** The text content (supports Markdown) */
	text: string;
}
/**
* Image Part
*
* Image content in a message.
*/
interface ImagePart {
	/** Content type discriminator */
	type: "image";
	/** Image data (base64-encoded string or URL) */
	data: string;
	/** Image MIME type */
	mediaType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
	/** Optional image name/filename */
	name?: string;
}
/**
* File Part
*
* File attachment in a message (PDF, documents, etc.).
*/
interface FilePart {
	/** Content type discriminator */
	type: "file";
	/** File data (base64-encoded string or URL) */
	data: string;
	/** File MIME type (IANA media type) */
	mediaType: string;
	/** Optional filename */
	filename?: string;
}
/**
* User Content Part
*
* Subset of ContentPart types that users can send in messages.
* - TextPart: Plain text content
* - ImagePart: Image attachments (JPEG, PNG, GIF, WebP)
* - FilePart: File attachments (PDF, documents, etc.)
*/
type UserContentPart = TextPart | ImagePart | FilePart;
/**
* User Message
*
* Message sent by the user.
* Can contain simple text or rich content (text, images, files).
*/
interface UserMessage {
	/** Unique identifier */
	id: string;
	/** Message role */
	role: "user";
	/** Message subtype for serialization */
	subtype: "user";
	/** Message content - can be simple string or array of parts */
	content: string | UserContentPart[];
	/** When this message was created (Unix timestamp in milliseconds) */
	timestamp: number;
	/** Parent message ID for threading (optional) */
	parentId?: string;
}
/**
* Thinking Part
*
* AI's reasoning/thinking process (extended thinking).
*/
interface ThinkingPart {
	/** Content type discriminator */
	type: "thinking";
	/** The reasoning text */
	reasoning: string;
	/** Tokens used for thinking (optional) */
	tokenCount?: number;
}
/**
* Agent event categories
*/
type AgentEventCategory = "stream" | "state" | "message" | "turn";
/**
* BaseAgentEvent - Base interface for all Agent events
*
* Extends SystemEvent with fixed source and intent.
*/
interface BaseAgentEvent<
	T extends string,
	D,
	C extends AgentEventCategory
> extends SystemEvent<T, D, "agent", C, "notification"> {
	/**
	* Runtime context (optional, added by Presenter)
	*/
	readonly context?: EventContext;
}
/**
* Base type for turn events
*/
interface AgentTurnEventBase<
	T extends string,
	D
> extends BaseAgentEvent<T, D, "turn"> {}
/**
* Token usage information
*/
interface TokenUsage {
	inputTokens: number;
	outputTokens: number;
	totalTokens?: number;
}
/**
* TurnRequestEvent - Turn started (user message received)
*/
interface TurnRequestEvent extends AgentTurnEventBase<"turn_request", {
	turnId: string
	messageId: string
	content: string
	timestamp: number
}> {}
/**
* TurnResponseEvent - Turn completed (assistant response finished)
*/
interface TurnResponseEvent extends AgentTurnEventBase<"turn_response", {
	turnId: string
	messageId: string
	duration: number
	usage?: TokenUsage
	model?: string
	stopReason?: string
	timestamp: number
}> {}
/**
* AgentTurnEvent - All turn events
*/
type AgentTurnEvent = TurnRequestEvent | TurnResponseEvent;
/**
* AgentTurnEventType - String literal union
*/
type AgentTurnEventType = AgentTurnEvent["type"];
/**
* Type guard: is this a turn event?
*/
declare function isAgentTurnEvent(event: {
	source?: string
	category?: string
}): event is AgentTurnEvent;
/**
* Assistant Message
*
* Message generated by the AI assistant.
* Contains text, thinking process, or files.
*
* Note: Tool calls are separate - use ToolCallMessage for tool invocations.
*/
interface AssistantMessage {
	/** Unique identifier */
	id: string;
	/** Message role */
	role: "assistant";
	/** Message subtype for serialization */
	subtype: "assistant";
	/** Message content - can be simple string or array of parts */
	content: string | Array<TextPart | ThinkingPart | FilePart>;
	/** When this message was created (Unix timestamp in milliseconds) */
	timestamp: number;
	/** Parent message ID for threading (optional) */
	parentId?: string;
	/** Token usage for this AI response (optional) */
	usage?: TokenUsage;
}
/**
* Tool Call Part
*
* AI's request to invoke a tool.
*/
interface ToolCallPart {
	/** Content type discriminator */
	type: "tool-call";
	/** Unique identifier for this tool call */
	id: string;
	/** Tool name */
	name: string;
	/** Tool input parameters */
	input: Record<string, unknown>;
}
/**
* Tool Call Message
*/
interface ToolCallMessage {
	/** Unique message identifier */
	id: string;
	/** Message role - assistant initiates tool calls */
	role: "assistant";
	/** Message subtype for serialization */
	subtype: "tool-call";
	/** Tool call details */
	toolCall: ToolCallPart;
	/** When this message was created (Unix timestamp in milliseconds) */
	timestamp: number;
	/** Parent message ID (the assistant message that triggered this) */
	parentId?: string;
}
/**
* Tool Result Output
*
* Enhanced tool result format supporting multiple output types.
* Based on Vercel AI SDK and industry best practices.
*/
type ToolResultOutput = {
	type: "text"
	value: string
} | {
	type: "json"
	value: unknown
} | {
	type: "error-text"
	value: string
} | {
	type: "error-json"
	value: unknown
} | {
	type: "execution-denied"
	reason?: string
} | {
	type: "content"
	value: Array<TextPart | ImagePart | FilePart>
};
/**
* Tool Result Part
*
* Result of tool execution.
*/
interface ToolResultPart {
	/** Content type discriminator */
	type: "tool-result";
	/** Tool call ID this result corresponds to */
	id: string;
	/** Tool name */
	name: string;
	/** Tool execution output */
	output: ToolResultOutput;
}
/**
* Tool Result Message
*/
interface ToolResultMessage {
	/** Unique message identifier */
	id: string;
	/** Message role - tool returns results */
	role: "tool";
	/** Message subtype for serialization */
	subtype: "tool-result";
	/** Tool result details */
	toolResult: ToolResultPart;
	/** ID of the corresponding tool call */
	toolCallId: string;
	/** When this message was created (Unix timestamp in milliseconds) */
	timestamp: number;
}
/**
* Error Message
*
* Message representing an error that occurred during conversation.
* Displayed in the chat history so users can see what went wrong.
*/
interface ErrorMessage {
	/** Unique identifier */
	id: string;
	/** Message role */
	role: "error";
	/** Message subtype for serialization */
	subtype: "error";
	/** Error message content (human-readable) */
	content: string;
	/** Error code (e.g., "rate_limit_error", "api_error") */
	errorCode?: string;
	/** When this error occurred (Unix timestamp in milliseconds) */
	timestamp: number;
	/** Parent message ID for threading (optional) */
	parentId?: string;
}
/**
* Base interface for Command request events
*/
interface BaseCommandRequest<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "command", "request", "request"> {}
/**
* Base interface for Command response events
*/
interface BaseCommandResponse<
	T extends string,
	D = unknown
> extends SystemEvent<T, D, "command", "response", "result"> {}
/**
* Request to create a container
*/
interface ContainerCreateRequest extends BaseCommandRequest<"container_create_request", {
	requestId: string
	containerId: string
}> {}
/**
* Response to container creation
*/
interface ContainerCreateResponse extends BaseCommandResponse<"container_create_response", {
	requestId: string
	containerId: string
	error?: string
}> {}
/**
* Request to get a container
*/
interface ContainerGetRequest extends BaseCommandRequest<"container_get_request", {
	requestId: string
	containerId: string
}> {}
/**
* Response to container get
*/
interface ContainerGetResponse extends BaseCommandResponse<"container_get_response", {
	requestId: string
	containerId?: string
	exists: boolean
	error?: string
}> {}
/**
* Request to list containers
*/
interface ContainerListRequest extends BaseCommandRequest<"container_list_request", {
	requestId: string
}> {}
/**
* Response to container list
*/
interface ContainerListResponse extends BaseCommandResponse<"container_list_response", {
	requestId: string
	containerIds: string[]
	error?: string
}> {}
/**
* Request to get an agent
*/
interface AgentGetRequest extends BaseCommandRequest<"agent_get_request", {
	requestId: string
	agentId: string
}> {}
/**
* Response to agent get
*/
interface AgentGetResponse extends BaseCommandResponse<"agent_get_response", {
	requestId: string
	agentId?: string
	containerId?: string
	exists: boolean
	error?: string
}> {}
/**
* Request to list agents
*/
interface AgentListRequest extends BaseCommandRequest<"agent_list_request", {
	requestId: string
	containerId: string
}> {}
/**
* Response to agent list
*/
interface AgentListResponse extends BaseCommandResponse<"agent_list_response", {
	requestId: string
	agents: Array<{
		agentId: string
		containerId: string
		imageId: string
	}>
	error?: string
}> {}
/**
* Request to destroy an agent
*/
interface AgentDestroyRequest extends BaseCommandRequest<"agent_destroy_request", {
	requestId: string
	agentId: string
}> {}
/**
* Response to agent destroy
*/
interface AgentDestroyResponse extends BaseCommandResponse<"agent_destroy_response", {
	requestId: string
	agentId: string
	success: boolean
	error?: string
}> {}
/**
* Request to destroy all agents in a container
*/
interface AgentDestroyAllRequest extends BaseCommandRequest<"agent_destroy_all_request", {
	requestId: string
	containerId: string
}> {}
/**
* Response to destroy all agents
*/
interface AgentDestroyAllResponse extends BaseCommandResponse<"agent_destroy_all_response", {
	requestId: string
	containerId: string
	error?: string
}> {}
/**
* Request to send a message
* Can use either imageId (preferred) or agentId
* If using imageId and agent is not running, it will be auto-activated
*/
interface MessageSendRequest extends BaseCommandRequest<"message_send_request", {
	requestId: string
	/** Image ID (preferred) - will auto-activate if offline */
	imageId?: string
	/** Agent ID (legacy) - must be already running */
	agentId?: string
	/** Message content (text-only or multimodal) */
	content: string | UserContentPart[]
	/**
	* User request context (passed from client)
	*
	* Contains user identity, authentication, and custom metadata.
	* This context flows through the entire request lifecycle:
	* Client → Runtime → Agent → Model Service
	*/
	userContext?: UserContext
}> {}
/**
* Response to message send (acknowledges message received, not completion)
*/
interface MessageSendResponse extends BaseCommandResponse<"message_send_response", {
	requestId: string
	imageId?: string
	agentId: string
	error?: string
}> {}
/**
* Request to interrupt an agent
* Can use either imageId or agentId
*/
interface AgentInterruptRequest extends BaseCommandRequest<"agent_interrupt_request", {
	requestId: string
	/** Image ID (preferred) */
	imageId?: string
	/** Agent ID (legacy) */
	agentId?: string
	/** User request context (for audit logging) */
	userContext?: UserContext
}> {}
/**
* Response to agent interrupt
*/
interface AgentInterruptResponse extends BaseCommandResponse<"agent_interrupt_response", {
	requestId: string
	imageId?: string
	agentId?: string
	error?: string
}> {}
/**
* Request to create a new image (conversation)
*/
interface ImageCreateRequest extends BaseCommandRequest<"image_create_request", {
	requestId: string
	containerId: string
	config: {
		name?: string
		description?: string
		systemPrompt?: string
		/** Blacklist of disallowed tools (tool names) */
		disallowedTools?: string[]
		/** Restrict available tools - can be array of tool names or preset */
		tools?: string[] | {
			type: "preset"
			preset: "claude_code"
		}
		/** Claude Code 风格的 Skills */
		skills?: import("~/agentx").SkillDefinition[]
		/** Per-image LLM configuration - overrides Runtime-level config */
		llmConfig?: {
			apiKey?: string
			baseUrl?: string
			model?: string
		}
	}
	/** User request context (for audit logging and access control) */
	userContext?: UserContext
}> {}
/**
* Response to image creation
*/
interface ImageCreateResponse extends BaseCommandResponse<"image_create_response", {
	requestId: string
	record: ImageRecord
	error?: string
}> {}
/**
* Request to run an image (create or reuse agent)
*/
interface ImageRunRequest extends BaseCommandRequest<"image_run_request", {
	requestId: string
	imageId: string
}> {}
/**
* Response to image run
*/
interface ImageRunResponse extends BaseCommandResponse<"image_run_response", {
	requestId: string
	imageId: string
	agentId: string
	/** true if reusing existing agent, false if newly created */
	reused: boolean
	error?: string
}> {}
/**
* Request to stop an image (destroy agent, keep image)
*/
interface ImageStopRequest extends BaseCommandRequest<"image_stop_request", {
	requestId: string
	imageId: string
}> {}
/**
* Response to image stop
*/
interface ImageStopResponse extends BaseCommandResponse<"image_stop_response", {
	requestId: string
	imageId: string
	error?: string
}> {}
/**
* Request to update an image (name, description, etc.)
*/
interface ImageUpdateRequest extends BaseCommandRequest<"image_update_request", {
	requestId: string
	imageId: string
	updates: {
		name?: string
		description?: string
	}
}> {}
/**
* Response to image update
*/
interface ImageUpdateResponse extends BaseCommandResponse<"image_update_response", {
	requestId: string
	record: ImageRecord
	error?: string
}> {}
/**
* Request to list all images
*/
interface ImageListRequest extends BaseCommandRequest<"image_list_request", {
	requestId: string
	containerId?: string
}> {}
/**
* Image list item with online status
*/
interface ImageListItem extends ImageRecord {
	/** Whether an agent is currently running for this image */
	online: boolean;
	/** Current agent ID if online */
	agentId?: string;
}
/**
* Response to image list
*/
interface ImageListResponse extends BaseCommandResponse<"image_list_response", {
	requestId: string
	records: ImageListItem[]
	error?: string
}> {}
/**
* Request to get an image by ID
*/
interface ImageGetRequest extends BaseCommandRequest<"image_get_request", {
	requestId: string
	imageId: string
}> {}
/**
* Response to image get
*/
interface ImageGetResponse extends BaseCommandResponse<"image_get_response", {
	requestId: string
	record?: ImageListItem | null
	error?: string
}> {}
/**
* Request to delete an image
*/
interface ImageDeleteRequest extends BaseCommandRequest<"image_delete_request", {
	requestId: string
	imageId: string
}> {}
/**
* Response to image delete
*/
interface ImageDeleteResponse extends BaseCommandResponse<"image_delete_response", {
	requestId: string
	imageId: string
	error?: string
}> {}
/**
* Request to get messages for an image
*/
interface ImageMessagesRequest extends BaseCommandRequest<"image_messages_request", {
	requestId: string
	imageId: string
}> {}
/**
* Response to image messages request
*/
interface ImageMessagesResponse extends BaseCommandResponse<"image_messages_response", {
	requestId: string
	imageId: string
	messages: Array<{
		id: string
		role: "user" | "assistant" | "tool_call" | "tool_result"
		content: unknown
		timestamp: number
	}>
	error?: string
}> {}
/**
* All Command request events
*/
type CommandRequest = ContainerCreateRequest | ContainerGetRequest | ContainerListRequest | AgentGetRequest | AgentListRequest | AgentDestroyRequest | AgentDestroyAllRequest | MessageSendRequest | AgentInterruptRequest | ImageCreateRequest | ImageRunRequest | ImageStopRequest | ImageUpdateRequest | ImageListRequest | ImageGetRequest | ImageDeleteRequest | ImageMessagesRequest;
/**
* All Command response events
*/
type CommandResponse = ContainerCreateResponse | ContainerGetResponse | ContainerListResponse | AgentGetResponse | AgentListResponse | AgentDestroyResponse | AgentDestroyAllResponse | MessageSendResponse | AgentInterruptResponse | ImageCreateResponse | ImageRunResponse | ImageStopResponse | ImageUpdateResponse | ImageListResponse | ImageGetResponse | ImageDeleteResponse | ImageMessagesResponse;
/**
* All Command events (requests + responses)
*/
type CommandEvent = CommandRequest | CommandResponse;
/**
* Command event type strings
*/
type CommandEventType = CommandEvent["type"];
/**
* Type guard: is this a CommandEvent?
*/
declare function isCommandEvent(event: {
	source?: string
}): event is CommandEvent;
/**
* Type guard: is this a Command request event?
*/
declare function isCommandRequest(event: {
	source?: string
	category?: string
}): event is CommandRequest;
/**
* Type guard: is this a Command response event?
*/
declare function isCommandResponse(event: {
	source?: string
	category?: string
}): event is CommandResponse;
/**
* CommandEventMap - Maps event type string to event interface
*
* Enables type-safe event handling:
* ```typescript
* bus.onCommand("container_create_request", (event) => {
*   event.data.requestId;    // ✓ string
*   event.data.containerId;  // ✓ string
* });
* ```
*/
interface CommandEventMap {
	container_create_request: ContainerCreateRequest;
	container_create_response: ContainerCreateResponse;
	container_get_request: ContainerGetRequest;
	container_get_response: ContainerGetResponse;
	container_list_request: ContainerListRequest;
	container_list_response: ContainerListResponse;
	agent_get_request: AgentGetRequest;
	agent_get_response: AgentGetResponse;
	agent_list_request: AgentListRequest;
	agent_list_response: AgentListResponse;
	agent_destroy_request: AgentDestroyRequest;
	agent_destroy_response: AgentDestroyResponse;
	agent_destroy_all_request: AgentDestroyAllRequest;
	agent_destroy_all_response: AgentDestroyAllResponse;
	message_send_request: MessageSendRequest;
	message_send_response: MessageSendResponse;
	agent_interrupt_request: AgentInterruptRequest;
	agent_interrupt_response: AgentInterruptResponse;
	image_create_request: ImageCreateRequest;
	image_create_response: ImageCreateResponse;
	image_run_request: ImageRunRequest;
	image_run_response: ImageRunResponse;
	image_stop_request: ImageStopRequest;
	image_stop_response: ImageStopResponse;
	image_update_request: ImageUpdateRequest;
	image_update_response: ImageUpdateResponse;
	image_list_request: ImageListRequest;
	image_list_response: ImageListResponse;
	image_get_request: ImageGetRequest;
	image_get_response: ImageGetResponse;
	image_delete_request: ImageDeleteRequest;
	image_delete_response: ImageDeleteResponse;
	image_messages_request: ImageMessagesRequest;
	image_messages_response: ImageMessagesResponse;
}
/**
* Maps request event type to its corresponding response event type
*/
interface CommandRequestResponseMap {
	container_create_request: "container_create_response";
	container_get_request: "container_get_response";
	container_list_request: "container_list_response";
	agent_get_request: "agent_get_response";
	agent_list_request: "agent_list_response";
	agent_destroy_request: "agent_destroy_response";
	agent_destroy_all_request: "agent_destroy_all_response";
	message_send_request: "message_send_response";
	agent_interrupt_request: "agent_interrupt_response";
	image_create_request: "image_create_response";
	image_run_request: "image_run_response";
	image_stop_request: "image_stop_response";
	image_update_request: "image_update_response";
	image_list_request: "image_list_response";
	image_get_request: "image_get_response";
	image_delete_request: "image_delete_response";
	image_messages_request: "image_messages_response";
}
/**
* All command request types
*/
type CommandRequestType = keyof CommandRequestResponseMap;
/**
* Get response type for a request type
*/
type ResponseTypeFor<T extends CommandRequestType> = CommandRequestResponseMap[T];
/**
* Get response event for a request type
*/
type ResponseEventFor<T extends CommandRequestType> = CommandEventMap[ResponseTypeFor<T>];
/**
* Get request data type (without requestId, as it's auto-generated)
*/
type RequestDataFor<T extends CommandRequestType> = Omit<CommandEventMap[T]["data"], "requestId">;
/**
* Base type for stream events
*/
interface AgentStreamEventBase<
	T extends string,
	D
> extends BaseAgentEvent<T, D, "stream"> {}
/**
* Stop reason for message completion
*/
type StopReason2 = "end_turn" | "max_tokens" | "stop_sequence" | "tool_use";
/**
* AgentMessageStartEvent - Streaming message begins
*/
interface AgentMessageStartEvent extends AgentStreamEventBase<"message_start", {
	messageId: string
	model: string
}> {}
/**
* AgentMessageDeltaEvent - Message-level updates (usage info)
*/
interface AgentMessageDeltaEvent extends AgentStreamEventBase<"message_delta", {
	usage?: {
		inputTokens: number
		outputTokens: number
	}
}> {}
/**
* AgentMessageStopEvent - Streaming message completes
*/
interface AgentMessageStopEvent extends AgentStreamEventBase<"message_stop", {
	stopReason?: StopReason2
}> {}
/**
* AgentTextDeltaEvent - Incremental text output
*/
interface AgentTextDeltaEvent extends AgentStreamEventBase<"text_delta", {
	text: string
}> {}
/**
* AgentToolUseStartEvent - Tool use block started
*/
interface AgentToolUseStartEvent extends AgentStreamEventBase<"tool_use_start", {
	toolCallId: string
	toolName: string
}> {}
/**
* AgentInputJsonDeltaEvent - Incremental tool input JSON
*/
interface AgentInputJsonDeltaEvent extends AgentStreamEventBase<"input_json_delta", {
	partialJson: string
}> {}
/**
* AgentToolUseStopEvent - Tool use block completed
*/
interface AgentToolUseStopEvent extends AgentStreamEventBase<"tool_use_stop", {
	toolCallId: string
	toolName: string
	input: Record<string, unknown>
}> {}
/**
* AgentToolResultEvent - Tool execution result
*/
interface AgentToolResultEvent extends AgentStreamEventBase<"tool_result", {
	toolCallId: string
	result: unknown
	isError?: boolean
}> {}
/**
* AgentErrorReceivedEvent - Error received from environment
*
* Processed by MealyMachine to produce:
* - error_occurred (StateEvent)
* - error_message (MessageEvent)
*/
interface AgentErrorReceivedEvent extends AgentStreamEventBase<"error_received", {
	/** Error message (human-readable) */
	message: string
	/** Error code (e.g., "rate_limit_error", "api_error") */
	errorCode?: string
}> {}
/**
* AgentStreamEvent - All stream events
*/
type AgentStreamEvent = AgentMessageStartEvent | AgentMessageDeltaEvent | AgentMessageStopEvent | AgentTextDeltaEvent | AgentToolUseStartEvent | AgentInputJsonDeltaEvent | AgentToolUseStopEvent | AgentToolResultEvent | AgentErrorReceivedEvent;
/**
* AgentStreamEventType - String literal union
*/
type AgentStreamEventType = AgentStreamEvent["type"];
/**
* Type guard: is this a stream event?
*/
declare function isAgentStreamEvent(event: {
	source?: string
	category?: string
}): event is AgentStreamEvent;
/**
* Base type for state events
*/
interface AgentStateEventBase<
	T extends string,
	D
> extends BaseAgentEvent<T, D, "state"> {}
/**
* ConversationQueuedEvent - Message queued for processing
*/
interface ConversationQueuedEvent extends AgentStateEventBase<"conversation_queued", {
	messageId: string
}> {}
/**
* ConversationStartEvent - Conversation started
*/
interface ConversationStartEvent extends AgentStateEventBase<"conversation_start", {
	messageId: string
}> {}
/**
* ConversationThinkingEvent - Agent is thinking
*/
interface ConversationThinkingEvent extends AgentStateEventBase<"conversation_thinking", Record<string, never>> {}
/**
* ConversationRespondingEvent - Agent is responding
*/
interface ConversationRespondingEvent extends AgentStateEventBase<"conversation_responding", Record<string, never>> {}
/**
* ConversationEndEvent - Conversation ended
*/
interface ConversationEndEvent extends AgentStateEventBase<"conversation_end", {
	reason: "completed" | "interrupted" | "error"
}> {}
/**
* ConversationInterruptedEvent - Conversation interrupted
*/
interface ConversationInterruptedEvent extends AgentStateEventBase<"conversation_interrupted", {
	reason: string
}> {}
/**
* ToolPlannedEvent - Tool use planned
*/
interface ToolPlannedEvent extends AgentStateEventBase<"tool_planned", {
	toolId: string
	toolName: string
}> {}
/**
* ToolExecutingEvent - Tool is executing
*/
interface ToolExecutingEvent extends AgentStateEventBase<"tool_executing", {
	toolId: string
	toolName: string
	input: Record<string, unknown>
}> {}
/**
* ToolCompletedEvent - Tool execution completed
*/
interface ToolCompletedEvent extends AgentStateEventBase<"tool_completed", {
	toolId: string
	toolName: string
	result: unknown
}> {}
/**
* ToolFailedEvent - Tool execution failed
*/
interface ToolFailedEvent extends AgentStateEventBase<"tool_failed", {
	toolId: string
	toolName: string
	error: string
}> {}
/**
* ErrorOccurredEvent - Error occurred during processing
*/
interface ErrorOccurredEvent extends AgentStateEventBase<"error_occurred", {
	code: string
	message: string
	recoverable: boolean
	category?: string
}> {}
/**
* AgentStateEvent - All state events
*/
type AgentStateEvent = ConversationQueuedEvent | ConversationStartEvent | ConversationThinkingEvent | ConversationRespondingEvent | ConversationEndEvent | ConversationInterruptedEvent | ToolPlannedEvent | ToolExecutingEvent | ToolCompletedEvent | ToolFailedEvent | ErrorOccurredEvent;
/**
* AgentStateEventType - String literal union
*/
type AgentStateEventType = AgentStateEvent["type"];
/**
* Type guard: is this a state event?
*/
declare function isAgentStateEvent(event: {
	source?: string
	category?: string
}): event is AgentStateEvent;
/**
* Base type for message events
*/
interface AgentMessageEventBase<
	T extends string,
	D
> extends BaseAgentEvent<T, D, "message"> {}
/**
* UserMessageEvent - User sent a message
* Data: Complete UserMessage object
*/
interface UserMessageEvent extends AgentMessageEventBase<"user_message", UserMessage> {}
/**
* AssistantMessageEvent - Assistant response message
* Data: Complete AssistantMessage object
*/
interface AssistantMessageEvent extends AgentMessageEventBase<"assistant_message", AssistantMessage> {}
/**
* ToolCallMessageEvent - Tool call message (part of assistant turn)
* Data: Complete ToolCallMessage object
*/
interface ToolCallMessageEvent extends AgentMessageEventBase<"tool_call_message", ToolCallMessage> {}
/**
* ToolResultMessageEvent - Tool result message
* Data: Complete ToolResultMessage object
*/
interface ToolResultMessageEvent extends AgentMessageEventBase<"tool_result_message", ToolResultMessage> {}
/**
* ErrorMessageEvent - Error message displayed in chat
* Data: Complete ErrorMessage object
*
* Generated when error_received StreamEvent is processed by MealyMachine.
* Displayed in the chat history so users can see what went wrong.
*/
interface ErrorMessageEvent extends AgentMessageEventBase<"error_message", ErrorMessage> {}
/**
* AgentMessageEvent - All message events
*/
type AgentMessageEvent = UserMessageEvent | AssistantMessageEvent | ToolCallMessageEvent | ToolResultMessageEvent | ErrorMessageEvent;
/**
* AgentMessageEventType - String literal union
*/
type AgentMessageEventType = AgentMessageEvent["type"];
/**
* Type guard: is this a message event?
*/
declare function isAgentMessageEvent(event: {
	source?: string
	category?: string
}): event is AgentMessageEvent;
/**
* AgentEvent - All events from Agent domain
*/
type AgentEvent = AgentStreamEvent | AgentStateEvent | AgentMessageEvent | AgentTurnEvent;
/**
* Type guard: is this an agent event?
*/
declare function isAgentEvent(event: {
	source?: string
}): event is AgentEvent;
/**
* SystemError - Generic error event
*
* Used for all errors until we create specific error types.
* Can originate from any source (runtime, agent, container, etc.)
*
* @example
* ```typescript
* const error: SystemError = {
*   type: "system_error",
*   timestamp: Date.now(),
*   source: "container",
*   category: "error",
*   intent: "notification",
*   data: {
*     message: "Container not found: default",
*     requestId: "req_123",
*     severity: "error",
*   },
*   context: { containerId: "default" }
* };
* ```
*/
interface SystemError extends SystemEvent<"system_error", {
	/**
	* Error message (human-readable)
	*/
	message: string
	/**
	* Associated request ID (if error is related to a request)
	*/
	requestId?: string
	/**
	* Error severity
	* - info: Informational, no action needed
	* - warn: Warning, operation succeeded but with issues
	* - error: Error, operation failed
	* - fatal: Fatal error, system unstable
	*/
	severity?: "info" | "warn" | "error" | "fatal"
	/**
	* Additional error details (stack trace, error code, etc.)
	*/
	details?: unknown
}, "agent" | "container" | "environment" | "session" | "sandbox" | "command", "error", "notification"> {}
/**
* Error event map - will grow as we add specific error types
*/
interface ErrorEventMap {
	system_error: SystemError;
}
/**
* Error event types
*/
type ErrorEventType = keyof ErrorEventMap;
/**
* Union of all error events
*/
type ErrorEvent = ErrorEventMap[ErrorEventType];
export { isWorkdirEvent, isSessionPersistEvent, isSessionLifecycleEvent, isSessionEvent, isSessionActionEvent, isSandboxEvent, isResult, isRequest, isNotification, isMCPEvent, isFromSource, isDriveableEvent, isContainerLifecycleEvent, isContainerEvent, isConnectionEvent, isCommandResponse, isCommandRequest, isCommandEvent, isAgentTurnEvent, isAgentStreamEvent, isAgentStateEvent, isAgentMessageEvent, isAgentEvent, hasIntent, WorkdirResultEvent, WorkdirRequestEvent, WorkdirEvent, WorkdirErrorEvent, UserMessageEvent, UserContext, TurnResponseEvent, TurnRequestEvent, ToolUseContentBlockStopEvent, ToolUseContentBlockStartEvent, ToolResultMessageEvent, ToolResultEvent, ToolPlannedEvent, ToolFailedEvent, ToolExecutionErrorEvent, ToolExecutingEvent, ToolExecutedEvent, ToolExecuteRequest, ToolCompletedEvent, ToolCallMessageEvent, ToolCallEvent, TokenUsage, TextDeltaEvent, TextContentBlockStopEvent, TextContentBlockStartEvent, SystemEvent, SystemError, StopReason2 as StopReason, SessionTitleUpdatedEvent, SessionTitleUpdateRequest, SessionSavedEvent, SessionSaveRequest, SessionResumedEvent, SessionResumeRequest, SessionPersistResultEvent, SessionPersistRequestEvent, SessionPersistEvent, SessionLifecycleEvent, SessionForkedEvent, SessionForkRequest, SessionEvent, SessionDestroyedEvent, SessionCreatedEvent, SessionActionResultEvent, SessionActionRequestEvent, SessionActionEvent, SandboxEvent, ResponseTypeFor, ResponseEventFor, ResourceReadResult, ResourceReadRequest, RequestDataFor, ReconnectingEvent, MessageStopEvent, MessageStartEvent, MessageSendResponse, MessageSendRequest, MessagePersistedEvent, MessagePersistRequest, MessageDeltaEvent, MCPServerDisconnectedEvent, MCPServerConnectedEvent, MCPResultEvent, MCPRequestEvent, MCPEvent, InterruptedEvent, InputJsonDeltaEvent, ImageUpdateResponse, ImageUpdateRequest, ImageStopResponse, ImageStopRequest, ImageRunResponse, ImageRunRequest, ImageListResponse, ImageListRequest, ImageListItem, ImageGetResponse, ImageGetRequest, ImageDeleteResponse, ImageDeleteRequest, ImageCreateResponse, ImageCreateRequest, FileWrittenEvent, FileWriteRequest, FileReadResult, FileReadRequest, FileDeletedEvent, FileDeleteRequest, EventSource, EventIntent, EventContext, EventCategory, ErrorReceivedEvent, ErrorOccurredEvent, ErrorMessageEvent, ErrorEventType, ErrorEventMap, ErrorEvent, EnvironmentEvent, DriveableEventType, DriveableEvent2 as DriveableEvent, DisconnectedEvent, DirectoryListResult, DirectoryListRequest, ConversationThinkingEvent, ConversationStartEvent, ConversationRespondingEvent, ConversationQueuedEvent, ConversationInterruptedEvent, ConversationEndEvent, ContainerListResponse, ContainerListRequest, ContainerLifecycleEvent, ContainerGetResponse, ContainerGetRequest, ContainerEvent, ContainerDestroyedEvent, ContainerCreatedEvent, ContainerCreateResponse, ContainerCreateRequest, ConnectionEventType, ConnectionEvent2 as ConnectionEvent, ConnectedEvent, CommandResponse, CommandRequestType, CommandRequestResponseMap, CommandRequest, CommandEventType, CommandEventMap, CommandEvent, BaseAgentEvent, AssistantMessageEvent, AgentUnregisteredEvent, AgentTurnEventType, AgentTurnEventBase, AgentTurnEvent, AgentToolUseStopEvent, AgentToolUseStartEvent, AgentToolResultEvent, AgentTextDeltaEvent, AgentStreamEventType, AgentStreamEventBase, AgentStreamEvent, AgentStateEventType, AgentStateEventBase, AgentStateEvent, AgentRegisteredEvent, AgentMessageStopEvent, AgentMessageStartEvent, AgentMessageEventType, AgentMessageEventBase, AgentMessageEvent, AgentMessageDeltaEvent, AgentListResponse, AgentListRequest, AgentInterruptResponse, AgentInterruptRequest, AgentInputJsonDeltaEvent, AgentGetResponse, AgentGetRequest, AgentEventCategory, AgentEvent, AgentErrorReceivedEvent, AgentDestroyResponse, AgentDestroyRequest, AgentDestroyAllResponse, AgentDestroyAllRequest };
