ai

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderAnthropic    = "anthropic"
	ProviderGoogle       = "google"
	ProviderOpenAI       = "openai"
	ProviderOpenAICompat = "openai-compat"
	ProviderOpenRouter   = "openrouter"
)

Variables

View Source
var (
	// ErrUnsupportedProvider - Returned when an AI provider is unknown.
	ErrUnsupportedProvider = errors.New("unsupported AI provider")
)

Functions

func ConfiguredProviders

func ConfiguredProviders() []*clientpb.AIProviderConfig

ConfiguredProviders - Return provider availability without exposing configured secrets.

func ConfiguredProvidersFromConfig

func ConfiguredProvidersFromConfig(cfg *configs.ServerConfig) []*clientpb.AIProviderConfig

ConfiguredProvidersFromConfig - Return provider availability for a specific config.

func IsSupportedProvider

func IsSupportedProvider(name string) bool

IsSupportedProvider - Indicates whether the provider is supported by the server scaffolding.

func NormalizeProviderName

func NormalizeProviderName(name string) string

NormalizeProviderName - Convert user supplied provider names to canonical identifiers.

func NormalizeThinkingLevelValue

func NormalizeThinkingLevelValue(value string) string

func SafeConfigSummary

func SafeConfigSummary() *clientpb.AIConfigSummary

SafeConfigSummary - Return the client-safe AI configuration summary.

func SafeConfigSummaryFromConfig

func SafeConfigSummaryFromConfig(cfg *configs.ServerConfig) *clientpb.AIConfigSummary

SafeConfigSummaryFromConfig - Return the client-safe AI configuration summary for a specific config.

func SetHTTPClientForTests

func SetHTTPClientForTests(client *http.Client) func()

SetHTTPClientForTests swaps the provider HTTP client and returns a restore function.

func SupportedProviders

func SupportedProviders() []string

SupportedProviders - Returns the currently supported server-side AI providers.

func SupportsAgenticConversation

func SupportsAgenticConversation(runtime *RuntimeConfig) bool

SupportsAgenticConversation reports whether the configured runtime can run the Responses API tool loop used by the Sliver AI chat.

Types

type AgenticChatMessage

type AgenticChatMessage struct {
	ItemID           string
	Role             string
	Content          string
	Status           string
	UIOnly           bool
	IncludeInContext bool
}

AgenticChatMessage is a provider-emitted assistant or system chat block.

type AgenticEventSink

type AgenticEventSink interface {
	ChatMessage(context.Context, AgenticChatMessage) error
	ReasoningItem(context.Context, AgenticReasoningItem) error
	ToolCallStarted(context.Context, AgenticToolCall) error
	ToolCallCompleted(context.Context, AgenticToolCallResult) error
}

AgenticEventSink persists and publishes non-context-window UI items.

type AgenticReasoningItem

type AgenticReasoningItem struct {
	ItemID           string
	Summary          string
	Content          string
	EncryptedContent string
	Status           string
}

AgenticReasoningItem is a completed reasoning item emitted by the provider.

type AgenticToolCall

type AgenticToolCall struct {
	ItemID    string
	CallID    string
	Name      string
	Arguments string
	Status    string
}

AgenticToolCall is a provider-emitted function tool call.

type AgenticToolCallResult

type AgenticToolCallResult struct {
	AgenticToolCall
	Output string
	Error  error
}

AgenticToolCallResult is the resolved tool call state after local execution.

type AgenticToolDefinition

type AgenticToolDefinition struct {
	Name        string
	Description string
	Parameters  map[string]any
}

AgenticToolDefinition describes a custom function tool exposed to the model.

type AgenticToolExecutor

type AgenticToolExecutor interface {
	ToolDefinitions() []AgenticToolDefinition
	CallTool(context.Context, string, string) (string, error)
}

AgenticToolExecutor executes model-requested tools for a conversation turn.

type Completion

type Completion struct {
	Provider           string
	Model              string
	Content            string
	ProviderMessageID  string
	FinishReason       string
	ContextWindowUsage *ContextWindowUsage
}

Completion contains the persisted assistant response details.

func CompleteConversation

func CompleteConversation(ctx context.Context, runtime *RuntimeConfig, conversation *clientpb.AIConversation) (*Completion, error)

CompleteConversation sends the stored conversation history to the provider and returns the assistant reply.

func CompleteConversationAgentic

func CompleteConversationAgentic(
	ctx context.Context,
	runtime *RuntimeConfig,
	conversation *clientpb.AIConversation,
	tools AgenticToolExecutor,
	sink AgenticEventSink,
) (*Completion, error)

CompleteConversationAgentic runs a Codex-style Responses API loop that emits reasoning and tool-call items between the user prompt and the final assistant reply. The returned completion is the assistant message that should be stored in the conversation context window.

type ContextWindowUsage

type ContextWindowUsage struct {
	InputTokens                  int64
	OutputTokens                 int64
	TotalTokens                  int64
	ContextWindowTokens          int64
	ContextWindowTokensEstimated bool
}

ContextWindowUsage captures the provider-reported token usage for a turn and, when available, the model context window used to render the client-side meter.

type Provider

type Provider struct {
	Name   string
	Config *configs.AIProviderConfig
}

Provider - Provider metadata derived from server configuration.

func ProviderFromConfig

func ProviderFromConfig(name string) (*Provider, error)

ProviderFromConfig - Resolve a configured provider by name.

type RuntimeConfig

type RuntimeConfig struct {
	Provider         string
	Model            string
	ThinkingLevel    string
	MaxOutputTokens  int64
	Temperature      *float64
	TopP             *float64
	TopK             *int64
	PresencePenalty  *float64
	FrequencyPenalty *float64

	APIKey          string
	BaseURL         string
	Headers         map[string]string
	UserAgent       string
	Organization    string
	Project         string
	Location        string
	SkipAuth        bool
	UseResponsesAPI bool
	UseBedrock      bool
}

RuntimeConfig captures the provider settings used for a single completion run.

func ResolveRuntimeConfig

func ResolveRuntimeConfig(cfg *configs.ServerConfig, conversation *clientpb.AIConversation) (*RuntimeConfig, error)

ResolveRuntimeConfig derives the provider settings for a stored conversation.

Jump to

Keyboard shortcuts

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