backendtypes

package
v1.0.24 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package backendtypes defines types for backend server configuration and API communication.

This package provides shared type definitions used by the backend package and applications built on ai-provider-kit. It separates type definitions from implementation to allow clean imports without circular dependencies.

Type Categories

The package defines several categories of types:

Configuration Types

BackendConfig and related types define how the backend server is configured:

  • ServerConfig: HTTP server settings (host, port, timeouts)
  • AuthConfig: Authentication configuration
  • LoggingConfig: Logging settings
  • CORSConfig: Cross-origin resource sharing settings
  • ExtensionConfig: Per-extension configuration

Request Types

Request types define the structure of incoming API requests:

  • ChatRequest: Chat completion requests
  • StreamRequest: Streaming requests

Response Types

Response types define the structure of API responses:

  • ChatResponse: Chat completion responses
  • ErrorResponse: Standard error format
  • HealthResponse: Health check responses

Usage

Import this package to use backend types without importing the full backend implementation:

import "github.com/cecil-the-coder/ai-provider-kit/pkg/backendtypes"

config := backendtypes.BackendConfig{
    Server: backendtypes.ServerConfig{Port: 8080},
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Details string `json:"details,omitempty"`
}

type APIResponse

type APIResponse struct {
	Success   bool        `json:"success"`
	Data      interface{} `json:"data,omitempty"`
	Error     *APIError   `json:"error,omitempty"`
	RequestID string      `json:"request_id,omitempty"`
	Timestamp time.Time   `json:"timestamp"`
}

APIResponse is the standard response wrapper

type AuthConfig

type AuthConfig struct {
	Enabled     bool     `yaml:"enabled"`
	APIPassword string   `yaml:"api_password"`
	APIKeyEnv   string   `yaml:"api_key_env"`
	PublicPaths []string `yaml:"public_paths"`
}

type BackendConfig

type BackendConfig struct {
	Server     ServerConfig                     `yaml:"server"`
	Auth       AuthConfig                       `yaml:"auth"`
	Logging    LoggingConfig                    `yaml:"logging"`
	CORS       CORSConfig                       `yaml:"cors"`
	Providers  map[string]*types.ProviderConfig `yaml:"providers"`
	Extensions map[string]ExtensionConfig       `yaml:"extensions"`
}

BackendConfig defines the configuration for the backend server

type CORSConfig

type CORSConfig struct {
	Enabled        bool     `yaml:"enabled"`
	AllowedOrigins []string `yaml:"allowed_origins"`
	AllowedMethods []string `yaml:"allowed_methods"`
	AllowedHeaders []string `yaml:"allowed_headers"`
}

type ExtensionConfig

type ExtensionConfig struct {
	Enabled bool                   `yaml:"enabled"`
	Config  map[string]interface{} `yaml:"config"`
}

type GenerateRequest

type GenerateRequest struct {
	Provider    string                 `json:"provider,omitempty"`
	Model       string                 `json:"model,omitempty"`
	Prompt      string                 `json:"prompt"`
	Messages    []types.ChatMessage    `json:"messages,omitempty"`
	MaxTokens   int                    `json:"max_tokens,omitempty"`
	Temperature float64                `json:"temperature,omitempty"`
	Stream      bool                   `json:"stream,omitempty"`
	Tools       []types.Tool           `json:"tools,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

GenerateRequest represents a code/chat generation request

type GenerateResponse

type GenerateResponse struct {
	Content  string                 `json:"content"`
	Model    string                 `json:"model"`
	Provider string                 `json:"provider"`
	Usage    *UsageInfo             `json:"usage,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

GenerateResponse for code/chat generation

type HealthResponse

type HealthResponse struct {
	Status    string                    `json:"status"`
	Version   string                    `json:"version"`
	Uptime    string                    `json:"uptime"`
	Providers map[string]ProviderHealth `json:"providers,omitempty"`
}

HealthResponse for health endpoints

type LoggingConfig

type LoggingConfig struct {
	Level  string `yaml:"level"`
	Format string `yaml:"format"` // "json" or "text"
}

type ProviderConfigRequest

type ProviderConfigRequest struct {
	Type         string   `json:"type"`
	APIKey       string   `json:"api_key,omitempty"`
	APIKeys      []string `json:"api_keys,omitempty"`
	DefaultModel string   `json:"default_model,omitempty"`
	BaseURL      string   `json:"base_url,omitempty"`
	Enabled      bool     `json:"enabled"`
}

ProviderConfigRequest for updating provider configuration

type ProviderHealth

type ProviderHealth struct {
	Status  string `json:"status"`
	Latency int64  `json:"latency_ms"`
	Message string `json:"message,omitempty"`
}

type ProviderInfo

type ProviderInfo struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Enabled     bool     `json:"enabled"`
	Healthy     bool     `json:"healthy"`
	Models      []string `json:"models,omitempty"`
	Description string   `json:"description,omitempty"`
}

ProviderInfo for provider listing

type ServerConfig

type ServerConfig struct {
	Host            string        `yaml:"host"`
	Port            int           `yaml:"port"`
	Version         string        `yaml:"version"`
	ReadTimeout     time.Duration `yaml:"read_timeout"`
	WriteTimeout    time.Duration `yaml:"write_timeout"`
	ShutdownTimeout time.Duration `yaml:"shutdown_timeout"`
}

type UsageInfo

type UsageInfo = types.Usage

UsageInfo is a type alias to types.Usage to avoid duplication

Jump to

Keyboard shortcuts

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