ai

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPaths

func DefaultPaths() (user, project string, err error)

func HistoryPath

func HistoryPath() (string, error)

func ResolveValue

func ResolveValue(value string) (string, error)

Types

type API

type API string
const (
	APIOpenAI           API = "openai"
	APIAnthropic        API = "anthropic"
	APIGemini           API = "gemini"
	APIOpenAICompatible API = "openai-compatible"
)

type Agent

type Agent struct {
	Name         string `json:"name"`
	Provider     string `json:"provider"`
	Model        string `json:"model"`
	SystemPrompt string `json:"system_prompt"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) (*Client, error)

func (*Client) AgentForPrompt

func (c *Client) AgentForPrompt(prompt string) string

func (*Client) Chat

func (c *Client) Chat(ctx context.Context, request Request) (Response, error)

func (*Client) ChatStream

func (c *Client) ChatStream(ctx context.Context, request Request) (<-chan StreamEvent, error)

ChatStream sends a streaming chat request, returning a channel of StreamEvents. The channel is safe to read until closed.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, request Request) (Response, error)

Complete sends a non-streaming chat request with optional tool definitions and returns the parsed turn (text + tool calls). Provider-specific wire translation is handled per adapter.

func (*Client) GenerateTitle

func (c *Client) GenerateTitle(ctx context.Context, message string) (string, error)

GenerateTitle asks the cheap agent to summarize a first user message into a short conversation title.

func (*Client) SupportsTools

func (c *Client) SupportsTools(agentID string) bool

SupportsTools reports whether the given agent's provider supports function calling.

func (*Client) TitleAgentID

func (c *Client) TitleAgentID() string

TitleAgentID returns the cheap agent used for auxiliary calls such as conversation titles: spark when configured, otherwise assistant.

type Config

type Config struct {
	Providers map[string]Provider `json:"providers"`
	Agents    map[string]Agent    `json:"agents"`
}

func Load

func Load() (Config, error)

func LoadFiles

func LoadFiles(userPath, projectPath string) (Config, error)

func (Config) Validate

func (c Config) Validate() error

type Conversation

type Conversation struct {
	ID           string
	ConnectionID string
	Title        string
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type History

type History struct {
	// contains filtered or unexported fields
}

func OpenHistory

func OpenHistory(path string) (*History, error)

func (*History) AppendMessage

func (h *History) AppendMessage(ctx context.Context, connectionID, conversationID string, message Message) error

AppendMessage inserts only through a scope-checked parent conversation, so a wrong connection scope is a silent no-op instead of a cross-scope write.

func (*History) Clear

func (h *History) Clear(ctx context.Context, connectionID string) error

func (*History) Close

func (h *History) Close() error

func (*History) Conversations

func (h *History) Conversations(ctx context.Context, connectionID string) ([]Conversation, error)

func (*History) DeleteConversation

func (h *History) DeleteConversation(ctx context.Context, connectionID, conversationID string) error

func (*History) Messages

func (h *History) Messages(ctx context.Context, connectionID, conversationID string) ([]Message, error)

func (*History) NewConversation

func (h *History) NewConversation(ctx context.Context, connectionID, title string) (Conversation, error)

func (*History) RenameConversation

func (h *History) RenameConversation(ctx context.Context, connectionID, conversationID, title string) error

RenameConversation updates the title of a conversation, leaving timestamps untouched so renames never reorder the history list.

type Message

type Message struct {
	Role      Role
	Agent     string
	Content   string
	ToolCalls []ToolCall
	ToolID    string
	ToolName  string
	CreatedAt time.Time
}

type Provider

type Provider struct {
	Name    string   `json:"name"`
	API     API      `json:"api"`
	BaseURL string   `json:"base_url"`
	APIKey  string   `json:"api_key"`
	Models  []string `json:"models"`
}

type Request

type Request struct {
	AgentID  string
	Messages []Message
	Context  string
	Tools    []ToolDefinition
}

type Response

type Response struct {
	Agent     string
	Content   string
	ToolCalls []ToolCall
}

type Role

type Role string
const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type StreamEvent

type StreamEvent struct {
	Kind     StreamEventKind
	Delta    string    // incremental content token (empty for terminal events)
	Response *Response // non-nil on successful completion (carries Agent + full Content)
	Err      error     // non-nil on error
	ToolCall ToolCall  // populated when Kind is EventToolCall
}

StreamEvent is an event on the channel returned by ChatStream.

type StreamEventKind

type StreamEventKind string
const (
	EventDelta    StreamEventKind = "delta"
	EventDone     StreamEventKind = "done"
	EventToolCall StreamEventKind = "tool_call"
)

type ToolCall

type ToolCall struct {
	ID    string         `json:"id"`
	Name  string         `json:"name"`
	Input map[string]any `json:"input"`
}

ToolCall represents a tool invocation requested by the AI.

type ToolDefinition

type ToolDefinition struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"input_schema"`
}

ToolDefinition describes a tool the AI can call.

type ToolResult

type ToolResult struct {
	CallID  string `json:"call_id"`
	Name    string `json:"name"`
	Content string `json:"content"`
	Error   string `json:"error,omitempty"`
}

ToolResult is the outcome of executing a ToolCall.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL