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.
Three providers are supported: Anthropic (native Messages API), OpenRouter (OpenAI-compatible chat completions, which fronts many models), and GLM — the Zhipu "GLM Coding Plan", which exposes an Anthropic-compatible Messages endpoint (so it reuses the Anthropic request/response path, just a different base URL and a Bearer token).
Index ¶
- Constants
- func ValidateOpenRouter(ctx context.Context, key, model string) error
- func ValidateOpenRouterKey(ctx context.Context, key string) error
- func ValidateOpenRouterModel(ctx context.Context, model string) error
- type AgentMessage
- type AgentTurn
- type Client
- func (c *Client) Complete(system, user string) (string, error)
- func (c *Client) CompleteAgentTurn(ctx context.Context, system string, messages []AgentMessage, tools []Tool) (*AgentTurn, error)
- func (c *Client) CompleteMessages(system string, messages []Message) (string, error)
- func (c *Client) CompleteStream(ctx context.Context, system, user string, onDelta func(string)) error
- func (c *Client) CompleteStreamAgentMessages(ctx context.Context, system string, messages []AgentMessage, ...) error
- func (c *Client) CompleteStreamMessages(ctx context.Context, system string, messages []Message, onDelta func(string)) error
- func (c *Client) SupportsAgentTools() bool
- type ContentBlock
- type Message
- type OpenRouterModel
- type Tool
- type ToolCall
Constants ¶
const ( ProviderAnthropic = "anthropic" ProviderOpenRouter = "openrouter" ProviderGLM = "glm" )
Providers.
Variables ¶
This section is empty.
Functions ¶
func ValidateOpenRouter ¶ added in v0.8.0
ValidateOpenRouter checks key and model before saving OpenRouter settings.
func ValidateOpenRouterKey ¶ added in v0.8.0
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.
Types ¶
type AgentMessage ¶ added in v0.12.0
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 ¶
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) 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
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
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
Message is one turn in a multi-message completion (user or assistant).
type OpenRouterModel ¶ added in v0.8.0
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.