httpclient

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCallbackListener added in v0.4.0

func NewCallbackListener(addr string) (net.Listener, string, error)

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

func WithLabel(key, value string) opt.Opt

WithLabel adds a label filter (key:value) for listing sessions. The key must be a valid identifier. Multiple calls accumulate filters.

func WithLimit

func WithLimit(limit *uint) opt.Opt

WithLimit sets the maximum number of results to return. If limit is nil, any existing limit is removed.

func WithName added in v0.3.0

func WithName(name string) opt.Opt

WithName filters results by name.

func WithOffset

func WithOffset(offset uint) opt.Opt

WithOffset sets the pagination offset. If offset is 0, any existing offset is removed.

func WithProvider

func WithProvider(provider string) opt.Opt

WithProvider filters results by provider name.

func WithVersion added in v0.3.0

func WithVersion(version uint) opt.Opt

WithVersion filters results by version number.

Types

type AskOpt

type AskOpt func(*askOptions)

AskOpt is a functional option for the Ask method.

func WithFile

func WithFile(filename string, r io.Reader) AskOpt

///////////////////////////////////////////////////////////////////////////// OPTIONS is the only attachment, it is sent via streaming multipart/form-data.

func WithURL

func WithURL(u string) AskOpt

WithURL adds a URL-referenced attachment to the request.

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

func WithChatFile(filename string, r io.Reader) ChatOpt

WithChatFile adds a file attachment to the chat request.

func WithChatStream

func WithChatStream(fn opt.StreamFn) ChatOpt

WithChatStream enables SSE streaming for the chat request. The callback receives streamed text chunks as they arrive (role and text).

func WithChatURL

func WithChatURL(u string) ChatOpt

WithChatURL adds a URL-referenced attachment to the chat request.

type Client

type Client struct {
	*client.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

func New(url string, opts ...client.ClientOpt) (*Client, error)

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

func (c *Client) CreateAgent(ctx context.Context, meta schema.AgentMeta) (*schema.Agent, error)

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

func (c *Client) DeleteAgent(ctx context.Context, id string) error

DeleteAgent deletes an agent by ID or name.

func (*Client) DeleteCredential added in v0.4.0

func (c *Client) DeleteCredential(ctx context.Context, url_ string) error

DeleteCredential removes the credential for the given server URL.

func (*Client) DeleteSession

func (c *Client) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session by ID.

func (*Client) Embedding

Embedding generates embedding vectors for the given text inputs.

func (*Client) GetAgent added in v0.3.0

func (c *Client) GetAgent(ctx context.Context, id string) (*schema.Agent, error)

GetAgent retrieves an agent by ID or name.

func (*Client) GetCredential added in v0.4.0

func (c *Client) GetCredential(ctx context.Context, url_ string) (*schema.OAuthCredentials, error)

GetCredential retrieves the credential stored for the given server URL.

func (*Client) GetModel

func (c *Client) GetModel(ctx context.Context, name string, opts ...opt.Opt) (*schema.Model, error)

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

func (c *Client) GetSession(ctx context.Context, id string) (*schema.Session, error)

GetSession retrieves a session by ID.

func (*Client) GetTool

func (c *Client) GetTool(ctx context.Context, name string) (*schema.ToolMeta, error)

GetTool retrieves a specific tool by name.

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

func (c *Client) ListTools(ctx context.Context, opts ...opt.Opt) (*schema.ListToolResponse, error)

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

func (c *Client) UpdateAgent(ctx context.Context, meta schema.AgentMeta) (*schema.Agent, error)

UpdateAgent updates an existing agent by name (sent as JSON). The agent name in the metadata is used to look up the existing agent.

func (*Client) UpdateSession

func (c *Client) UpdateSession(ctx context.Context, id string, meta schema.SessionMeta) (*schema.Session, error)

UpdateSession updates a session's metadata by ID.

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

func OptClientName(name string) LoginOpt

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.

Jump to

Keyboard shortcuts

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