Documentation
¶
Index ¶
- func NewCallbackListener(addr string) (net.Listener, string, error)
- func WithLabel(key, value string) opt.Opt
- func WithLimit(limit *uint) opt.Opt
- func WithName(name string) opt.Opt
- func WithOffset(offset uint) opt.Opt
- func WithProvider(provider string) opt.Opt
- func WithVersion(version uint) opt.Opt
- type AskOpt
- type AuthURLCallback
- type ChatOpt
- type Client
- func (c *Client) Ask(ctx context.Context, req schema.AskRequest, opts ...AskOpt) (*schema.AskResponse, error)
- func (c *Client) Chat(ctx context.Context, req schema.ChatRequest, opts ...ChatOpt) (*schema.ChatResponse, error)
- func (c *Client) CreateAgent(ctx context.Context, meta schema.AgentMeta) (*schema.Agent, error)
- func (c *Client) CreateAgentSession(ctx context.Context, agentID string, request schema.CreateAgentSessionRequest) (*schema.CreateAgentSessionResponse, error)
- func (c *Client) CreateSession(ctx context.Context, meta schema.SessionMeta) (*schema.Session, error)
- func (c *Client) DeleteAgent(ctx context.Context, id string) error
- func (c *Client) DeleteCredential(ctx context.Context, url_ string) error
- func (c *Client) DeleteSession(ctx context.Context, id string) error
- func (c *Client) Embedding(ctx context.Context, req schema.EmbeddingRequest) (*schema.EmbeddingResponse, error)
- func (c *Client) GetAgent(ctx context.Context, id string) (*schema.Agent, error)
- func (c *Client) GetCredential(ctx context.Context, url_ string) (*schema.OAuthCredentials, error)
- func (c *Client) GetModel(ctx context.Context, name string, opts ...opt.Opt) (*schema.Model, error)
- func (c *Client) GetSession(ctx context.Context, id string) (*schema.Session, error)
- func (c *Client) GetTool(ctx context.Context, name string) (*schema.ToolMeta, error)
- func (c *Client) ListAgents(ctx context.Context, opts ...opt.Opt) (*schema.ListAgentResponse, error)
- func (c *Client) ListModels(ctx context.Context, opts ...opt.Opt) (*schema.ListModelsResponse, error)
- func (c *Client) ListSessions(ctx context.Context, opts ...opt.Opt) (*schema.ListSessionResponse, error)
- func (c *Client) ListTools(ctx context.Context, opts ...opt.Opt) (*schema.ListToolResponse, error)
- func (c *Client) Login(ctx context.Context, cfg *oauth2.Config, opts ...LoginOpt) (*schema.OAuthCredentials, error)
- func (c *Client) RefreshToken(ctx context.Context, creds *schema.OAuthCredentials, force bool) (*schema.OAuthCredentials, error)
- func (c *Client) SetCredential(ctx context.Context, url_ string, cred schema.OAuthCredentials) error
- func (c *Client) UpdateAgent(ctx context.Context, meta schema.AgentMeta) (*schema.Agent, error)
- func (c *Client) UpdateSession(ctx context.Context, id string, meta schema.SessionMeta) (*schema.Session, error)
- type DeviceAuthCallback
- type LoginOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCallbackListener ¶ added in v0.4.0
NewCallbackListener creates a TCP listener for OAuth callbacks and returns both the listener and the redirect URI to use. If addr is empty, a random available port on localhost is used. Only loopback addresses are allowed for security reasons.
func WithLabel ¶
WithLabel adds a label filter (key:value) for listing sessions. The key must be a valid identifier. Multiple calls accumulate filters.
func WithLimit ¶
WithLimit sets the maximum number of results to return. If limit is nil, any existing limit is removed.
func WithOffset ¶
WithOffset sets the pagination offset. If offset is 0, any existing offset is removed.
func WithProvider ¶
WithProvider filters results by provider name.
func WithVersion ¶ added in v0.3.0
WithVersion filters results by version number.
Types ¶
type AskOpt ¶
type AskOpt func(*askOptions)
AskOpt is a functional option for the Ask method.
type AuthURLCallback ¶ added in v0.4.0
type AuthURLCallback func(authURL string)
AuthURLCallback is called with the authorization URL for interactive login. The callback should present this URL to the user (e.g., open browser, display).
type ChatOpt ¶
type ChatOpt func(*chatOptions)
ChatOpt is a functional option for the Chat method.
func WithChatFile ¶
WithChatFile adds a file attachment to the chat request.
func WithChatStream ¶
WithChatStream enables SSE streaming for the chat request. The callback receives streamed text chunks as they arrive (role and text).
func WithChatURL ¶
WithChatURL adds a URL-referenced attachment to the chat request.
type Client ¶
Client is an LLM HTTP client that wraps the base HTTP client and provides typed methods for interacting with the LLM API.
func New ¶
New creates a new LLM HTTP client with the given base URL and options. The url parameter should point to the LLM API endpoint, e.g. "http://localhost:8084/api".
func (*Client) Ask ¶
func (c *Client) Ask(ctx context.Context, req schema.AskRequest, opts ...AskOpt) (*schema.AskResponse, error)
Ask sends a stateless text request with zero or more attachments. Use WithFile to attach file uploads and WithURL to attach URL references. A single file with no other attachments uses streaming multipart/form-data; all other cases use JSON with base64-encoded file data.
func (*Client) Chat ¶
func (c *Client) Chat(ctx context.Context, req schema.ChatRequest, opts ...ChatOpt) (*schema.ChatResponse, error)
Chat sends a message within a session with zero or more attachments. Use WithChatFile to attach file uploads and WithChatURL to attach URL references. A single file with no other attachments uses streaming multipart/form-data; all other cases use JSON with base64-encoded file data.
func (*Client) CreateAgent ¶ added in v0.3.0
CreateAgent creates a new agent with the given metadata (sent as JSON).
func (*Client) CreateAgentSession ¶ added in v0.3.0
func (c *Client) CreateAgentSession(ctx context.Context, agentID string, request schema.CreateAgentSessionRequest) (*schema.CreateAgentSessionResponse, error)
CreateAgentSession creates a new session from an agent definition. The agentID can be an agent ID or name.
func (*Client) CreateSession ¶
func (c *Client) CreateSession(ctx context.Context, meta schema.SessionMeta) (*schema.Session, error)
CreateSession creates a new session with the given metadata.
func (*Client) DeleteAgent ¶ added in v0.3.0
DeleteAgent deletes an agent by ID or name.
func (*Client) DeleteCredential ¶ added in v0.4.0
DeleteCredential removes the credential for the given server URL.
func (*Client) DeleteSession ¶
DeleteSession deletes a session by ID.
func (*Client) Embedding ¶
func (c *Client) Embedding(ctx context.Context, req schema.EmbeddingRequest) (*schema.EmbeddingResponse, error)
Embedding generates embedding vectors for the given text inputs.
func (*Client) GetCredential ¶ added in v0.4.0
GetCredential retrieves the credential stored for the given server URL.
func (*Client) GetModel ¶
GetModel retrieves a specific model by name, optionally scoped to a provider. If provider is empty, the model is looked up across all providers.
func (*Client) GetSession ¶
GetSession retrieves a session by ID.
func (*Client) ListAgents ¶ added in v0.3.0
func (c *Client) ListAgents(ctx context.Context, opts ...opt.Opt) (*schema.ListAgentResponse, error)
ListAgents returns a list of all agents. Use WithLimit, WithOffset and WithName to filter and paginate results.
func (*Client) ListModels ¶
func (c *Client) ListModels(ctx context.Context, opts ...opt.Opt) (*schema.ListModelsResponse, error)
ListModels returns a list of all available models. Use WithLimit, WithOffset and WithProvider to paginate and filter results.
func (*Client) ListSessions ¶
func (c *Client) ListSessions(ctx context.Context, opts ...opt.Opt) (*schema.ListSessionResponse, error)
ListSessions returns a list of all sessions. Use WithLimit and WithOffset to paginate results.
func (*Client) ListTools ¶
ListTools returns a list of all available tools. Use WithLimit and WithOffset to paginate results.
func (*Client) Login ¶ added in v0.4.0
func (c *Client) Login(ctx context.Context, cfg *oauth2.Config, opts ...LoginOpt) (*schema.OAuthCredentials, error)
Login performs an OAuth 2.0 login flow. It discovers OAuth metadata using cfg.Endpoint.AuthURL as the base server URL, then replaces cfg.Endpoint with the discovered authorization and token URLs.
Flow is selected by the provided options:
- OptInteractive: Authorization Code flow with PKCE (default for user-facing apps)
- OptDevice: Device Authorization flow (RFC 8628)
- OptClientCredentials: Client Credentials flow (machine-to-machine)
If cfg.ClientID is empty and OptClientName is set, dynamic client registration is attempted. cfg.ClientSecret is passed through for confidential clients.
func (*Client) RefreshToken ¶ added in v0.4.0
func (c *Client) RefreshToken(ctx context.Context, creds *schema.OAuthCredentials, force bool) (*schema.OAuthCredentials, error)
RefreshToken exchanges a refresh token for a new access token. If force is false and the token is still valid (with a 30-second buffer), the existing credentials are returned as-is. The provided token must contain a valid refresh token.
func (*Client) SetCredential ¶ added in v0.4.0
func (c *Client) SetCredential(ctx context.Context, url_ string, cred schema.OAuthCredentials) error
SetCredential stores (or updates) the credential for the given server URL.
func (*Client) UpdateAgent ¶ added in v0.3.0
UpdateAgent updates an existing agent by name (sent as JSON). The agent name in the metadata is used to look up the existing agent.
type DeviceAuthCallback ¶ added in v0.4.0
type DeviceAuthCallback func(verificationURI, userCode string)
DeviceAuthCallback is called with the device authorization details. The callback should present the verification URI and user code to the user.
type LoginOpt ¶ added in v0.4.0
type LoginOpt func(*loginOpts)
LoginOpt is a functional option for the Login method.
func OptClientCredentials ¶ added in v0.4.0
func OptClientCredentials() LoginOpt
OptClientCredentials selects the Client Credentials flow (RFC 6749 Section 4.4). The oauth2.Config must have ClientSecret set.
func OptClientName ¶ added in v0.4.0
OptClientName sets the client name for dynamic client registration (RFC 7591). If the oauth2.Config has an empty ClientID, registration is attempted using this name.
func OptDevice ¶ added in v0.4.0
func OptDevice(callback DeviceAuthCallback) LoginOpt
OptDevice selects the Device Authorization flow (RFC 8628). The callback is invoked with the verification URI and user code.
func OptInteractive ¶ added in v0.4.0
func OptInteractive(listener net.Listener, callback AuthURLCallback) LoginOpt
OptInteractive selects the Authorization Code flow with PKCE. The listener is used for the OAuth callback server, and the callback is invoked with the authorization URL for the user to visit.