types

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package types holds eyrie's shared data types — message/content blocks and related request/response shapes — plus small cross-cutting helpers such as retry backoff (BackoffDelay, CryptoRandDuration).

Index

Examples

Constants

View Source
const (
	EndTurn      = "end_turn"
	MaxTokens    = "max_tokens"
	StopSequence = "stop_sequence"
	ToolUse      = "tool_use"
)

Variables

This section is empty.

Functions

func BackoffDelay added in v0.1.1

func BackoffDelay(attempt int, baseDelay, maxDelay time.Duration) time.Duration

BackoffDelay calculates an exponential backoff delay with full jitter. This is the shared backoff implementation used by both client and router retry logic.

Parameters:

  • attempt: the current retry attempt (0-based)
  • baseDelay: the base delay duration
  • maxDelay: the maximum delay duration cap

func ClassifyError added in v0.1.1

func ClassifyError(statusCode int, message string) error

ClassifyError creates a structured error from a status code and message. It returns the most specific error type for the given error condition. For retriable status codes (408, 429, 500, 502, 503, 504, 529), returns a TransientError.

Example
package main

import (
	"fmt"

	"github.com/GrayCodeAI/eyrie/types"
)

func main() {
	// Retriable status codes get TransientError
	err := types.ClassifyError(429, "rate limited")
	if te, ok := err.(*types.TransientError); ok {
		fmt.Printf("Transient: HTTP %d\n", te.StatusCode)
	}

	// Non-retriable codes get APIError
	err = types.ClassifyError(400, "bad request")
	if apiErr, ok := err.(*types.APIError); ok {
		fmt.Printf("API Error: HTTP %d\n", apiErr.Status)
	}
}
Output:
Transient: HTTP 429
API Error: HTTP 400

func CryptoRandDuration added in v0.1.1

func CryptoRandDuration(max time.Duration) time.Duration

CryptoRandDuration returns a cryptographically random duration in [0, max).

func ExtractHTTPStatus added in v0.1.1

func ExtractHTTPStatus(err error) (int, bool)

ExtractHTTPStatus attempts to extract an HTTP status code from err's message. Uses the same regex as IsTransient to find 3-digit codes in error text. Returns the status code and true if found, or 0 and false otherwise.

Example
package main

import (
	"fmt"

	"github.com/GrayCodeAI/eyrie/types"
)

func main() {
	err := &types.TransientError{StatusCode: 529, Message: "overloaded"}
	code, ok := types.ExtractHTTPStatus(err)
	fmt.Printf("Status: %d, Found: %v\n", code, ok)
}
Output:
Status: 529, Found: true

func IsConnectorTextBlock

func IsConnectorTextBlock(m map[string]interface{}) bool

func IsTransient added in v0.1.1

func IsTransient(err error) bool

IsTransient reports whether the error is likely temporary and worth retrying. This is the canonical retry classifier used by the retry middleware.

Conservative by default: unknown errors (those that match neither retriable nor non-retriable patterns) are treated as NOT retriable. This avoids unnecessary retries for unexpected error types (e.g., malformed responses, serialization failures). Callers like FallbackProvider that want optimistic fallback on unknown errors implement their own wrapper — see client.isRetriableError.

Example
package main

import (
	"fmt"

	"github.com/GrayCodeAI/eyrie/types"
)

func main() {
	// Transient errors are worth retrying
	err := &types.TransientError{StatusCode: 429, Message: "rate limited"}
	fmt.Printf("Is transient: %v\n", types.IsTransient(err))
}
Output:
Is transient: true

Types

type APIConnectionError

type APIConnectionError struct{ APIError }

func NewAPIConnectionError

func NewAPIConnectionError(message string) *APIConnectionError

type APIConnectionTimeoutError

type APIConnectionTimeoutError struct{ APIError }

func NewAPIConnectionTimeoutError

func NewAPIConnectionTimeoutError(message string) *APIConnectionTimeoutError

type APIError

type APIError struct {
	Status  int                    `json:"status"`
	Headers map[string]string      `json:"headers"`
	Err     map[string]interface{} `json:"error"`
	Message string                 `json:"message"`
}

func NewAPIError

func NewAPIError(status int, headers map[string]string, err map[string]interface{}, message string) *APIError

func (*APIError) Error

func (e *APIError) Error() string

type APIUserAbortError

type APIUserAbortError struct{ APIError }

func NewAPIUserAbortError

func NewAPIUserAbortError(message string) *APIUserAbortError

type AgentId

type AgentId string

func AsAgentId

func AsAgentId(s string) AgentId

func ToAgentId

func ToAgentId(s string) (*AgentId, error)

type AssistantMessage

type AssistantMessage struct {
	Message
	IsApiErrorMessage bool          `json:"is_api_error_message"`
	ErrorDetails      *ErrorDetails `json:"error_details,omitempty"`
}

func CreateAssistantMessage

func CreateAssistantMessage(text string) AssistantMessage
Example
package main

import (
	"fmt"

	"github.com/GrayCodeAI/eyrie/types"
)

func main() {
	msg := types.CreateAssistantMessage("I can help with that!")
	fmt.Printf("Role: %s\n", msg.Role)
}
Output:
Role: assistant

type AuthenticationError

type AuthenticationError struct{ APIError }

func NewAuthenticationError

func NewAuthenticationError(message string) *AuthenticationError

type Base64ImageSource

type Base64ImageSource struct {
	Type      string `json:"type"`
	MediaType string `json:"media_type"`
	Data      string `json:"data"`
}

type BetaMessage

type BetaMessage struct {
	ID           string         `json:"id"`
	Type_        string         `json:"type"`
	Role         string         `json:"role"`
	Content      []ContentBlock `json:"content"`
	Model        string         `json:"model"`
	StopReason   string         `json:"stop_reason"`
	StopSequence string         `json:"stop_sequence"`
	Usage        BetaUsage      `json:"usage"`
}

type BetaMessageParam

type BetaMessageParam struct {
	Role    string      `json:"role"`
	Content interface{} `json:"content"`
}

type BetaUsage

type BetaUsage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

type CacheCreation

type CacheCreation struct {
	Ephemeral1hInputTokens int `json:"ephemeral_1h_input_tokens"`
	Ephemeral5mInputTokens int `json:"ephemeral_5m_input_tokens"`
}

type ClientOptions

type ClientOptions struct {
	APIKey     string `json:"-"`
	BaseURL    string `json:"base_url"`
	Timeout    int    `json:"timeout"`
	MaxRetries int    `json:"max_retries"`
}

type ConnectorTextBlock

type ConnectorTextBlock struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type ConnectorTextDelta

type ConnectorTextDelta struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type ContentBlock

type ContentBlock = interface{}

type ContentBlockParam

type ContentBlockParam = interface{}

type ErrorDetails

type ErrorDetails struct {
	ActualTokens *int `json:"actual_tokens,omitempty"`
	LimitTokens  *int `json:"limit_tokens,omitempty"`
}

type ImageBlockParam

type ImageBlockParam struct {
	Type   string            `json:"type"`
	Source Base64ImageSource `json:"source"`
}

func IsImageBlock

func IsImageBlock(v interface{}) (ImageBlockParam, bool)

type Message

type Message struct {
	ID           string      `json:"id"`
	Type_        string      `json:"type"`
	Role         string      `json:"role"`
	Content      interface{} `json:"content"`
	Model        string      `json:"model"`
	StopReason   string      `json:"stop_reason"`
	StopSequence string      `json:"stop_sequence"`
	Usage        *Usage      `json:"usage"`
}

type MessageCreateParams

type MessageCreateParams struct {
	Model         string         `json:"model"`
	MaxTokens     int            `json:"max_tokens"`
	Messages      []MessageParam `json:"messages"`
	Tools         []Tool         `json:"tools,omitempty"`
	ToolChoice    *ToolChoice    `json:"tool_choice,omitempty"`
	System        *string        `json:"system,omitempty"`
	Temperature   *float64       `json:"temperature,omitempty"`
	TopP          *float64       `json:"top_p,omitempty"`
	TopK          *int           `json:"top_k,omitempty"`
	StopSequences []string       `json:"stop_sequences,omitempty"`
	Stream        bool           `json:"stream"`
}

type MessageOrigin

type MessageOrigin = string
const (
	User       MessageOrigin = "user"
	API        MessageOrigin = "api"
	ToolOrigin MessageOrigin = "tool"
	System     MessageOrigin = "system"
	Compact    MessageOrigin = "compact"
	Recovery   MessageOrigin = "recovery"
)

type MessageParam

type MessageParam struct {
	Role    string      `json:"role"`
	Content interface{} `json:"content"`
}

type MessageSource

type MessageSource = string
const (
	UserSource   MessageSource = "user"
	Teammate     MessageSource = "teammate"
	SystemSource MessageSource = "system"
	Tick         MessageSource = "tick"
	Task         MessageSource = "task"
)

type MessageStreamEvent

type MessageStreamEvent struct {
	Type string `json:"type"`
}

type NonNullableUsage

type NonNullableUsage struct {
	InputTokens              int           `json:"input_tokens"`
	CacheCreationInputTokens int           `json:"cache_creation_input_tokens"`
	CacheReadInputTokens     int           `json:"cache_read_input_tokens"`
	OutputTokens             int           `json:"output_tokens"`
	ServerToolUse            ServerToolUse `json:"server_tool_use"`
	ServiceTier              string        `json:"service_tier"`
	CacheCreation            CacheCreation `json:"cache_creation"`
	InferenceGeo             string        `json:"inference_geo"`
	Iterations               []interface{} `json:"iterations"`
	Speed                    string        `json:"speed"`
}

func EmptyUsage

func EmptyUsage() NonNullableUsage

type NotFoundError

type NotFoundError struct{ APIError }

func NewNotFoundError

func NewNotFoundError(message string) *NotFoundError

type RedactedThinkingBlock

type RedactedThinkingBlock struct {
	Type string `json:"type"`
	Data string `json:"data"`
}

type RedactedThinkingBlockParam

type RedactedThinkingBlockParam struct {
	Type string `json:"type"`
	Data string `json:"data"`
}

type RetryConfig added in v0.1.1

type RetryConfig struct {
	MaxRetries int
	BaseDelay  time.Duration
	MaxDelay   time.Duration
}

RetryConfig is the canonical retry configuration shared by HTTP clients and the router. Packages that need extra fields (e.g. RetryOn for status codes, OnRetry for callbacks) embed this type and add the extensions.

type ServerToolUse

type ServerToolUse struct {
	WebSearchRequests int `json:"web_search_requests"`
	WebFetchRequests  int `json:"web_fetch_requests"`
}

type SessionId

type SessionId string

func AsSessionId

func AsSessionId(s string) SessionId

type SystemMessage

type SystemMessage struct {
	Message
}

func CreateSystemMessage

func CreateSystemMessage(text string) SystemMessage

type TextBlock

type TextBlock struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

func IsTextBlock

func IsTextBlock(v interface{}) (TextBlock, bool)

type TextBlockParam

type TextBlockParam struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type ThinkingBlock

type ThinkingBlock struct {
	Type      string `json:"type"`
	Thinking  string `json:"thinking"`
	Signature string `json:"signature"`
}

type ThinkingBlockParam

type ThinkingBlockParam struct {
	Type      string `json:"type"`
	Thinking  string `json:"thinking"`
	Signature string `json:"signature"`
}

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	InputSchema ToolInputSchema `json:"input_schema"`
}

type ToolChoice

type ToolChoice struct {
	Type string `json:"type"`
	Name string `json:"name,omitempty"`
}

type ToolInputSchema

type ToolInputSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties"`
	Required   []string               `json:"required"`
}

type ToolResultBlockParam

type ToolResultBlockParam struct {
	Type      string      `json:"type"`
	ToolUseID string      `json:"tool_use_id"`
	Content   interface{} `json:"content"`
	IsError   bool        `json:"is_error"`
}

func IsToolResultBlock

func IsToolResultBlock(v interface{}) (ToolResultBlockParam, bool)

type ToolUseBlock

type ToolUseBlock struct {
	Type  string                 `json:"type"`
	ID    string                 `json:"id"`
	Name  string                 `json:"name"`
	Input map[string]interface{} `json:"input"`
}

func IsToolUseBlock

func IsToolUseBlock(v interface{}) (ToolUseBlock, bool)

type ToolUseBlockParam

type ToolUseBlockParam struct {
	Type  string                 `json:"type"`
	ID    string                 `json:"id"`
	Name  string                 `json:"name"`
	Input map[string]interface{} `json:"input"`
}

type TransientError added in v0.1.1

type TransientError struct {
	StatusCode int
	Message    string
}

TransientError wraps an HTTP status code and message to indicate a retriable error. Use errors.As to check for transient errors programmatically.

func (*TransientError) Error added in v0.1.1

func (e *TransientError) Error() string

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

type UserMessage

type UserMessage struct {
	Message
}

func CreateUserMessage

func CreateUserMessage(text string) UserMessage
Example
package main

import (
	"fmt"

	"github.com/GrayCodeAI/eyrie/types"
)

func main() {
	msg := types.CreateUserMessage("Hello, how can I help you?")
	fmt.Printf("Role: %s\n", msg.Role)
	fmt.Printf("Content: %s\n", msg.Content)
}
Output:
Role: user
Content: Hello, how can I help you?

Jump to

Keyboard shortcuts

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