// Package ai implements the panel AI assistant: OpenAI-compatible chat, // streaming output, tool calling and approval for mutating operations. package ai // Risk classifies a tool call. type Risk string const ( // RiskRead executes immediately without asking the operator. RiskRead Risk = "read" // RiskWrite changes panel state and must be confirmed. RiskWrite Risk = "write" // RiskDanger executes host commands and must be confirmed. RiskDanger Risk = "danger" ) // ToolCall is the OpenAI function call shape. type ToolCall struct { ID string `json:"id"` Type string `json:"type"` Function FunctionCall `json:"function"` } // FunctionCall carries the tool name and raw JSON arguments. type FunctionCall struct { Name string `json:"name"` Arguments string `json:"arguments"` } // ChatMessage is one provider message. type ChatMessage struct { Role string `json:"role"` Content string `json:"content,omitempty"` ToolCalls []ToolCall `json:"tool_calls,omitempty"` ToolCallID string `json:"tool_call_id,omitempty"` Name string `json:"name,omitempty"` } // ToolDef is the function schema sent to the provider. type ToolDef struct { Type string `json:"type"` Function FunctionDef `json:"function"` } // FunctionDef describes one callable tool. type FunctionDef struct { Name string `json:"name"` Description string `json:"description"` Parameters map[string]any `json:"parameters"` } // ChatRequest is one completion request. type ChatRequest struct { Model string Messages []ChatMessage Tools []ToolDef Temperature float64 MaxTokens int } // Usage mirrors the provider token accounting. type Usage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` } // ChatResult is one completed assistant turn. type ChatResult struct { Message ChatMessage FinishReason string Usage *Usage } // EmitFunc writes one downstream SSE event. type EmitFunc func(event string, data any) error // TerminalCommand is one command suggested for the smart terminal. type TerminalCommand struct { Command string `json:"command"` Note string `json:"note"` Risk string `json:"risk"` } // TerminalSuggestion is the terminal assistant response. type TerminalSuggestion struct { Reply string `json:"reply"` Commands []TerminalCommand `json:"commands"` } // Meta identifies the conversation and model behind a stream. type Meta struct { SessionID string `json:"session_id"` Model string `json:"model"` } // TextDelta is one incremental assistant token. type TextDelta struct { Delta string `json:"delta"` } // ToolEvent reports a tool call progress update. type ToolEvent struct { ID string `json:"id"` Name string `json:"name"` Args string `json:"args,omitempty"` Status string `json:"status,omitempty"` Result string `json:"result,omitempty"` } // ActionEvent is a pending approval card. type ActionEvent struct { ID string `json:"id"` ToolCallID string `json:"tool_call_id"` Tool string `json:"tool"` Args string `json:"args"` Summary string `json:"summary"` Risk string `json:"risk"` } // DoneEvent ends one stream. type DoneEvent struct { Status string `json:"status"` } // ErrorEvent reports a failure to the client. type ErrorEvent struct { Message string `json:"message"` }