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 ¶
- Constants
- func BackoffDelay(attempt int, baseDelay, maxDelay time.Duration) time.Duration
- func ClassifyError(statusCode int, message string) error
- func CryptoRandDuration(max time.Duration) time.Duration
- func ExtractHTTPStatus(err error) (int, bool)
- func IsConnectorTextBlock(m map[string]interface{}) bool
- func IsTransient(err error) bool
- type APIConnectionError
- type APIConnectionTimeoutError
- type APIError
- type APIUserAbortError
- type AgentId
- type AssistantMessage
- type AuthenticationError
- type Base64ImageSource
- type BetaMessage
- type BetaMessageParam
- type BetaUsage
- type CacheCreation
- type ClientOptions
- type ConnectorTextBlock
- type ConnectorTextDelta
- type ContentBlock
- type ContentBlockParam
- type ErrorDetails
- type ImageBlockParam
- type Message
- type MessageCreateParams
- type MessageOrigin
- type MessageParam
- type MessageSource
- type MessageStreamEvent
- type NonNullableUsage
- type NotFoundError
- type RedactedThinkingBlock
- type RedactedThinkingBlockParam
- type RetryConfig
- type ServerToolUse
- type SessionId
- type SystemMessage
- type TextBlock
- type TextBlockParam
- type ThinkingBlock
- type ThinkingBlockParam
- type Tool
- type ToolChoice
- type ToolInputSchema
- type ToolResultBlockParam
- type ToolUseBlock
- type ToolUseBlockParam
- type TransientError
- type Usage
- type UserMessage
Examples ¶
Constants ¶
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
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
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
CryptoRandDuration returns a cryptographically random duration in [0, max).
func ExtractHTTPStatus ¶ added in v0.1.1
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 IsTransient ¶ added in v0.1.1
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 ¶
type APIUserAbortError ¶
type APIUserAbortError struct{ APIError }
func NewAPIUserAbortError ¶
func NewAPIUserAbortError(message string) *APIUserAbortError
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 BetaMessage ¶
type BetaMessageParam ¶
type BetaMessageParam struct {
Role string `json:"role"`
Content interface{} `json:"content"`
}
type CacheCreation ¶
type ClientOptions ¶
type ConnectorTextBlock ¶
type ConnectorTextDelta ¶
type ContentBlock ¶
type ContentBlock = interface{}
type ContentBlockParam ¶
type ContentBlockParam = interface{}
type ErrorDetails ¶
type ImageBlockParam ¶
type ImageBlockParam struct {
Type string `json:"type"`
Source Base64ImageSource `json:"source"`
}
func IsImageBlock ¶
func IsImageBlock(v interface{}) (ImageBlockParam, bool)
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 RetryConfig ¶ added in v0.1.1
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 SystemMessage ¶
type SystemMessage struct {
Message
}
func CreateSystemMessage ¶
func CreateSystemMessage(text string) SystemMessage
type TextBlock ¶
func IsTextBlock ¶
type TextBlockParam ¶
type ThinkingBlock ¶
type ThinkingBlockParam ¶
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema ToolInputSchema `json:"input_schema"`
}
type ToolChoice ¶
type ToolInputSchema ¶
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 TransientError ¶ added in v0.1.1
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 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?