Documentation
¶
Overview ¶
Package event defines the event system for Techne Code. Events are used to communicate state changes, tool executions, and other occurrences throughout the agent's lifecycle.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiffData ¶
type DiffData struct {
FilePath string `json:"file_path"`
OldContent string `json:"old_content,omitempty"`
NewContent string `json:"new_content,omitempty"`
IsNewFile bool `json:"is_new_file"`
}
DiffData carries file diff information through the event bus.
type ErrorData ¶
type ErrorData struct {
// Message describes the error.
Message string `json:"message"`
// Fatal indicates whether the error is unrecoverable.
Fatal bool `json:"fatal"`
}
ErrorData contains data for EventError events.
type Event ¶
type Event struct {
// Type identifies the kind of event.
Type EventType `json:"type"`
// SessionID identifies which session this event belongs to.
SessionID string `json:"session_id"`
// Data contains the event-specific payload.
Data interface{} `json:"data"`
// Timestamp records when the event occurred.
Timestamp time.Time `json:"timestamp"`
}
Event represents an occurrence in the system.
type EventBus ¶
type EventBus interface {
// Publish sends an event to all subscribers.
Publish(event Event)
// Subscribe registers a handler and returns an unsubscribe function.
Subscribe(handler EventHandler) func()
// Close shuts down the event bus and releases resources.
Close()
}
EventBus defines the interface for a publish/subscribe event system.
type EventHandler ¶
type EventHandler func(Event)
EventHandler is a callback function for handling events.
type EventType ¶
type EventType string
EventType represents the type of an event in the system.
const ( // EventMessageDelta is emitted for each chunk of text from the LLM. EventMessageDelta EventType = "message_delta" // EventToolStart is emitted when a tool begins execution. EventToolStart EventType = "tool_start" // EventToolResult is emitted when a tool completes execution. EventToolResult EventType = "tool_result" // EventError is emitted when an error occurs. EventError EventType = "error" // EventDone is emitted when the agent completes its response. EventDone EventType = "done" // EventSummarize is emitted when context summarization is needed. EventSummarize EventType = "summarize" // EventSessionUpdate is emitted when session metadata changes. EventSessionUpdate EventType = "session_update" // EventPermissionReq is emitted when user permission is required for an action. EventPermissionReq EventType = "permission_request" // EventPermissionRes is emitted when the user responds to a permission request. EventPermissionRes EventType = "permission_response" // EventTokenUsage is emitted when token usage stats are updated. EventTokenUsage EventType = "token_usage" )
Event types for different kinds of system occurrences.
type MessageDeltaData ¶
type MessageDeltaData struct {
// Text is the chunk of text from the LLM.
Text string `json:"text"`
}
MessageDeltaData contains data for EventMessageDelta events.
type PermissionRequestData ¶
type PermissionRequestData struct {
// ToolName is the name of the tool requiring permission.
ToolName string
// Action describes the action being requested.
Action string
// Description provides details about the action for user review.
Description string
// Params contains the parameters for the action as raw JSON.
Params json.RawMessage
// Response is the channel where the user's response is sent back.
Response chan<- PermissionResponseData
}
PermissionRequestData contains data for EventPermissionReq events.
type PermissionResponseData ¶
type PermissionResponseData struct {
// Allowed indicates whether the user granted permission.
Allowed bool
// Remember indicates whether to remember this permission for the session.
Remember bool
}
PermissionResponseData contains the user's response to a permission request.
type SessionUpdateData ¶
type SessionUpdateData struct {
// SessionID is the ID of the updated session.
SessionID string `json:"session_id"`
// Title is the new title of the session.
Title string `json:"title"`
}
SessionUpdateData contains data for EventSessionUpdate events.
type ThinkingDeltaData ¶
type ThinkingDeltaData struct {
// Text is the chunk of thinking content from the LLM.
Text string `json:"text"`
}
ThinkingDeltaData contains data for thinking/reasoning chunks.
type TokenUsageData ¶
type TokenUsageData struct {
// InputTokens is the cumulative input tokens used.
InputTokens int `json:"input_tokens"`
// OutputTokens is the cumulative output tokens used.
OutputTokens int `json:"output_tokens"`
// TotalTokens is the sum of input and output tokens.
TotalTokens int `json:"total_tokens"`
// CachedTokens is the cumulative tokens read from cache.
CachedTokens int `json:"cached_tokens,omitempty"`
// EstimatedContextUsage is the estimated current context window usage in tokens.
EstimatedContextUsage int `json:"estimated_context_usage,omitempty"`
// ContextWindow is the model's maximum context window size.
ContextWindow int `json:"context_window,omitempty"`
}
TokenUsageData contains cumulative token usage statistics for a session.
type ToolResultData ¶
type ToolResultData struct {
// ToolName is the name of the tool that was executed.
ToolName string `json:"tool_name"`
// Content contains the output from the tool execution.
Content string `json:"content"`
// IsError indicates whether the tool execution failed.
IsError bool `json:"is_error"`
// Diff contains file diff information when available.
Diff *DiffData `json:"diff,omitempty"`
}
ToolResultData contains data for EventToolResult events.
type ToolStartData ¶
type ToolStartData struct {
// ToolName is the name of the tool being executed.
ToolName string `json:"tool_name"`
// Input contains the tool parameters as raw JSON.
Input json.RawMessage `json:"input"`
}
ToolStartData contains data for EventToolStart events.