Documentation
¶
Index ¶
- func BuildSystemPrompt() string
- func FormatValidationIssues(issues []ValidationIssue) string
- func GetAvailableTaskNames() []string
- func SerializeValidationResult(result *ValidationResult) (json.RawMessage, error)
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type OpenRouterClient
- type Session
- func (s *Session) AppendResponse(chunk string)
- func (s *Session) CanFixWarnings() bool
- func (s *Session) CanRetryFix() bool
- func (s *Session) Complete()
- func (s *Session) GetSnapshot() *Session
- func (s *Session) IncrementFixAttempts() int
- func (s *Session) SetCancelFunc(cancel context.CancelFunc)
- func (s *Session) SetError(err string)
- func (s *Session) SetGeneratedYaml(yaml string)
- func (s *Session) SetResponse(response string)
- func (s *Session) SetUsage(prompt, completion, total int)
- func (s *Session) SetValidation(validation *ValidationResult)
- func (s *Session) SetWarningFixAttempted()
- func (s *Session) Subscribe() <-chan *Session
- func (s *Session) Unsubscribe(ch <-chan *Session)
- func (s *Session) UpdateStatus(status SessionStatus)
- type SessionManager
- type SessionStatus
- type StreamChunk
- type ValidationIssue
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildSystemPrompt ¶
func BuildSystemPrompt() string
BuildSystemPrompt creates the static system prompt for the AI assistant. This prompt is designed to be cachable - all static content is included here. Dynamic content (current YAML context) should be added as separate messages.
func FormatValidationIssues ¶
func FormatValidationIssues(issues []ValidationIssue) string
FormatValidationIssues formats validation issues as a human-readable string.
func GetAvailableTaskNames ¶
func GetAvailableTaskNames() []string
GetAvailableTaskNames returns all available task names for reference.
func SerializeValidationResult ¶
func SerializeValidationResult(result *ValidationResult) (json.RawMessage, error)
SerializeValidationResult converts a validation result to JSON.
Types ¶
type ChatMessage ¶
type ChatMessage struct {
Role string `json:"role"` // "system", "user", "assistant"
Content string `json:"content"`
}
ChatMessage represents a single message in the chat history.
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
Stream bool `json:"stream,omitempty"`
}
ChatRequest represents a request to the chat completions endpoint.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Model string `json:"model"`
Choices []struct {
Message ChatMessage `json:"message"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
ChatResponse represents a response from the chat completions endpoint.
type OpenRouterClient ¶
type OpenRouterClient struct {
// contains filtered or unexported fields
}
OpenRouterClient handles communication with the OpenRouter API.
func NewOpenRouterClient ¶
func NewOpenRouterClient(apiKey string) *OpenRouterClient
NewOpenRouterClient creates a new OpenRouter client.
func (*OpenRouterClient) Chat ¶
func (c *OpenRouterClient) Chat(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
Chat sends a chat completion request and returns the response.
func (*OpenRouterClient) ChatStream ¶
func (c *OpenRouterClient) ChatStream( ctx context.Context, req *ChatRequest, onChunk func(string), ) (*ChatResponse, error)
ChatStream sends a streaming chat completion request. The onChunk callback is called for each content chunk received. Returns the final response with usage statistics.
type Session ¶
type Session struct {
ID string `json:"id"`
Status SessionStatus `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// Response data
Response string `json:"response"`
GeneratedYaml string `json:"generatedYaml,omitempty"`
Validation *ValidationResult `json:"validation,omitempty"`
// Token usage
Usage struct {
PromptTokens int `json:"promptTokens"`
CompletionTokens int `json:"completionTokens"`
TotalTokens int `json:"totalTokens"`
} `json:"usage"`
// Error information
Error string `json:"error,omitempty"`
// Fix attempt tracking
FixAttempts int `json:"fixAttempts"`
MaxFixAttempts int `json:"-"`
WarningFixAttempted bool `json:"warningFixAttempted"`
// contains filtered or unexported fields
}
Session represents an AI chat session with streaming support.
func (*Session) AppendResponse ¶
AppendResponse appends to the response (for streaming).
func (*Session) CanFixWarnings ¶
CanFixWarnings checks if a warning fix attempt is allowed (only 1 allowed).
func (*Session) CanRetryFix ¶
CanRetryFix checks if another fix attempt is allowed.
func (*Session) GetSnapshot ¶
GetSnapshot returns a copy of the session for safe reading.
func (*Session) IncrementFixAttempts ¶
IncrementFixAttempts increments the fix attempt counter.
func (*Session) SetCancelFunc ¶
func (s *Session) SetCancelFunc(cancel context.CancelFunc)
SetCancelFunc sets the cancel function for the session.
func (*Session) SetGeneratedYaml ¶
SetGeneratedYaml sets the generated YAML.
func (*Session) SetResponse ¶
SetResponse sets the response content.
func (*Session) SetValidation ¶
func (s *Session) SetValidation(validation *ValidationResult)
SetValidation sets the validation result.
func (*Session) SetWarningFixAttempted ¶
func (s *Session) SetWarningFixAttempted()
SetWarningFixAttempted marks that a warning fix was attempted.
func (*Session) Unsubscribe ¶
Unsubscribe removes a subscriber channel.
func (*Session) UpdateStatus ¶
func (s *Session) UpdateStatus(status SessionStatus)
UpdateStatus updates the session status and notifies subscribers.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages AI chat sessions.
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates a new session manager.
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession(maxFixAttempts int) *Session
CreateSession creates a new session and returns it.
func (*SessionManager) DeleteSession ¶
func (sm *SessionManager) DeleteSession(id string)
DeleteSession removes a session.
func (*SessionManager) GetSession ¶
func (sm *SessionManager) GetSession(id string) *Session
GetSession retrieves a session by ID.
func (*SessionManager) Stop ¶
func (sm *SessionManager) Stop()
Stop stops the session manager cleanup loop.
type SessionStatus ¶
type SessionStatus string
SessionStatus represents the current state of an AI chat session.
const ( SessionStatusPending SessionStatus = "pending" SessionStatusStreaming SessionStatus = "streaming" SessionStatusValidating SessionStatus = "validating" SessionStatusFixing SessionStatus = "fixing" SessionStatusComplete SessionStatus = "complete" SessionStatusError SessionStatus = "error" )
type StreamChunk ¶
type StreamChunk struct {
ID string `json:"id"`
Model string `json:"model"`
Choices []struct {
Delta struct {
Content string `json:"content"`
} `json:"delta"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
}
StreamChunk represents a single chunk from a streaming response.
type ValidationIssue ¶
type ValidationIssue struct {
Type string `json:"type"` // "error" or "warning"
Path string `json:"path"` // Path to the issue (e.g., "tasks[0].name")
Message string `json:"message"` // Human-readable message
}
ValidationIssue represents a problem found in the generated YAML.
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
Issues []ValidationIssue `json:"issues,omitempty"`
}
ValidationResult contains the results of validating generated YAML.
func ValidateGeneratedYaml ¶
func ValidateGeneratedYaml(yamlContent string) *ValidationResult
ValidateGeneratedYaml validates the AI-generated YAML for correct task names and configs.