ai

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCallOptions

func DefaultCallOptions() domain.CallOptions

DefaultCallOptions returns sensible defaults for AI provider calls.

func EnsureTimeout

func EnsureTimeout(t time.Duration) time.Duration

EnsureTimeout returns t if positive, otherwise the default 60s.

func NewProvider

func NewProvider(cfg *config.Config, store credential.CredentialStore, warnW io.Writer) (domain.AIProvider, error)

NewProvider creates an AIProvider based on configuration. Returns (nil, nil) when no provider is configured (zero-API mode). store may be nil (keychain unavailable). warnW receives plaintext warnings.

func ResolveAPIKey

func ResolveAPIKey(provider, configKey string, store credential.CredentialStore, warnW io.Writer) (string, error)

ResolveAPIKey resolves an API key using the priority chain: 1. LORE_AI_API_KEY env var (no warning) 2. keychain via store.Get() if key is "" or "@keychain" 3. plaintext config value (emits warning) 4. empty string (caller decides if error)

func ResolveOptions

func ResolveOptions(defaults domain.CallOptions, opts ...domain.Option) domain.CallOptions

ResolveOptions applies variadic options over defaults, returning final options.

func SafeHTTPClient

func SafeHTTPClient() *http.Client

SafeHTTPClient returns an http.Client with connection limits, a global timeout, and redirect-following disabled (prevents SSRF via open redirects).

func TruncateForError

func TruncateForError(s string, maxLen int) string

TruncateForError returns s truncated to maxLen bytes for safe inclusion in error messages. Prevents multi-MB response bodies from being propagated in error chains.

func ValidateEndpoint

func ValidateEndpoint(endpoint string) error

ValidateEndpoint checks that an endpoint URL uses http or https scheme only. Rejects file://, gopher://, javascript:, and other dangerous schemes. Also rejects plain http for non-localhost endpoints to prevent credential leakage.

Types

This section is empty.

Jump to

Keyboard shortcuts

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