aiassist

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package aiassist is an optional, bring-your-own-key bridge to an LLM that explains requests, suggests payloads, and summarizes findings. It is off until the user supplies an API key, and it only ever talks to the configured provider — captured traffic is sent only when the user explicitly asks.

Two providers are supported: Anthropic (native Messages API) and OpenRouter (OpenAI-compatible chat completions, which fronts many models).

Index

Constants

View Source
const (
	ProviderAnthropic  = "anthropic"
	ProviderOpenRouter = "openrouter"
)

Providers.

Variables

This section is empty.

Functions

func ValidateOpenRouter added in v0.8.0

func ValidateOpenRouter(ctx context.Context, key, model string) error

ValidateOpenRouter checks key and model before saving OpenRouter settings.

func ValidateOpenRouterKey added in v0.8.0

func ValidateOpenRouterKey(ctx context.Context, key string) error

ValidateOpenRouterKey checks the API key against OpenRouter's auth endpoint. The public /models endpoint returns 200 even for invalid keys, so /auth/key is required.

func ValidateOpenRouterModel added in v0.8.0

func ValidateOpenRouterModel(ctx context.Context, model string) error

ValidateOpenRouterModel ensures model is non-empty and present in the catalog.

Types

type AgentMessage added in v0.12.0

type AgentMessage struct {
	Role    string
	Content any // string or []ContentBlock
}

AgentMessage is one turn in an agent conversation (user or assistant).

type AgentTurn added in v0.12.0

type AgentTurn struct {
	StopReason string
	Blocks     []ContentBlock
	ToolCalls  []ToolCall
	Text       string
}

AgentTurn is one non-streaming model reply that may include tool calls.

type Client

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

Client calls a chosen LLM provider with a user-provided key.

func New

func New(provider, key, model string) *Client

New returns a client for the given provider (defaults to Anthropic for an unknown/empty value). An empty model uses that provider's default.

func (*Client) Complete

func (c *Client) Complete(system, user string) (string, error)

Complete sends a system + user prompt and returns the model's text reply.

func (*Client) CompleteAgentTurn added in v0.12.0

func (c *Client) CompleteAgentTurn(ctx context.Context, system string, messages []AgentMessage, tools []Tool) (*AgentTurn, error)

CompleteAgentTurn sends one agent turn with tools and returns the model reply.

func (*Client) CompleteMessages added in v0.12.0

func (c *Client) CompleteMessages(system string, messages []Message) (string, error)

CompleteMessages sends a system prompt and an ordered message history.

func (*Client) CompleteStream added in v0.7.0

func (c *Client) CompleteStream(ctx context.Context, system, user string, onDelta func(string)) error

CompleteStream sends the prompt and invokes onDelta for each incremental text chunk as the model generates it (Server-Sent Events). It returns when the stream ends, the provider reports an error, or ctx is cancelled. onDelta is always called from the calling goroutine.

func (*Client) CompleteStreamAgentMessages added in v0.12.0

func (c *Client) CompleteStreamAgentMessages(ctx context.Context, system string, messages []AgentMessage, onDelta func(string)) error

CompleteStreamAgentMessages streams a final agent reply (no tools) token by token.

func (*Client) CompleteStreamMessages added in v0.12.0

func (c *Client) CompleteStreamMessages(ctx context.Context, system string, messages []Message, onDelta func(string)) error

CompleteStreamMessages is the multi-turn streaming variant of CompleteMessages.

func (*Client) SupportsAgentTools added in v0.12.0

func (c *Client) SupportsAgentTools() bool

SupportsAgentTools reports whether this client can run tool-use agent loops.

type ContentBlock added in v0.12.0

type ContentBlock struct {
	Type      string         `json:"type"`
	Text      string         `json:"text,omitempty"`
	ID        string         `json:"id,omitempty"`
	Name      string         `json:"name,omitempty"`
	Input     map[string]any `json:"input,omitempty"`
	ToolUseID string         `json:"tool_use_id,omitempty"`
	Content   string         `json:"content,omitempty"`
	IsError   bool           `json:"is_error,omitempty"`
}

ContentBlock is one piece of an agent message (text, tool_use, or tool_result).

type Message added in v0.12.0

type Message struct {
	Role    string
	Content string
}

Message is one turn in a multi-message completion (user or assistant).

type OpenRouterModel added in v0.8.0

type OpenRouterModel struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

OpenRouterModel is one entry from the OpenRouter model catalog.

func ListOpenRouterModels added in v0.8.0

func ListOpenRouterModels(ctx context.Context) ([]OpenRouterModel, error)

ListOpenRouterModels returns chat models from the OpenRouter catalog.

type Tool added in v0.12.0

type Tool struct {
	Name        string
	Description string
	InputSchema map[string]any
}

Tool is one callable function exposed to the model during agent mode.

type ToolCall added in v0.12.0

type ToolCall struct {
	ID    string
	Name  string
	Input map[string]any
}

ToolCall is a tool invocation the model requested.

Jump to

Keyboard shortcuts

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