executor

package
v0.2.44 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestIDFromContext added in v0.2.6

func RequestIDFromContext(ctx context.Context) string

func WithAllowedProviders added in v0.2.21

func WithAllowedProviders(ctx context.Context, providers []string) context.Context

func WithRequestID added in v0.2.6

func WithRequestID(ctx context.Context, id string) context.Context

func WithSessionKey added in v0.2.42

func WithSessionKey(ctx context.Context, key string) context.Context

Types

type AttemptHook added in v0.2.6

type AttemptHook func(accounts.RequestAttempt)

type ChatExecutor

type ChatExecutor struct {
	Pool            *accounts.Pool
	WorkerKey       string
	HTTPClient      *http.Client
	Providers       *providerRegistry
	OnAttempt       AttemptHook
	MaxAttempts     int
	SessionAffinity *SessionAffinity
}

func NewChatExecutor

func NewChatExecutor(pool *accounts.Pool, workerKey string) ChatExecutor

func (ChatExecutor) ChatNonStream

func (e ChatExecutor) ChatNonStream(ctx context.Context, req translate.ChatRequest, prefer, providerFilter string) (result ChatResult, returnErr error)

func (ChatExecutor) ChatStreamProxy

func (e ChatExecutor) ChatStreamProxy(ctx context.Context, req translate.ChatRequest, prefer, providerFilter string) (result StreamResult, returnErr error)

func (ChatExecutor) CommitSession added in v0.2.42

func (e ChatExecutor) CommitSession(ctx context.Context, routing, accountID string)

CommitSession binds a successfully completed stream. The executor cannot know whether an SSE response reached [DONE], so the relay calls this only after it has finished without an upstream or client error.

func (ChatExecutor) ObserveStreamFailure added in v0.2.28

func (e ChatExecutor) ObserveStreamFailure(accountID string, err error, model string)

ObserveStreamFailure applies a post-headers streaming failure to the pool. Upstream can answer 200 and then fail inside the SSE body, which happens after the executor already returned a successful StreamResult; the relay error is the first place the failure is observable. Same-account retry is impossible at that point (bytes are on the wire), so this only records the classified state for the next request's scheduling.

type ChatResult

type ChatResult struct {
	Model            string
	Content          string
	Reasoning        string
	ToolCalls        json.RawMessage
	FinishReason     string
	PromptTokens     int
	CompletionTokens int
	CacheReadTokens  *int
	CacheWriteTokens *int
	CachedTokens     *int
	UsageSource      string
	Credits          *float64
	AccountID        string
	Provider         string
	AttemptCount     int
	RawNote          string
	Routing          string
}

type SessionAffinity added in v0.2.42

type SessionAffinity struct {
	// contains filtered or unexported fields
}

SessionAffinity is a bounded process-local LRU. Session bindings are a routing cache, not durable account state: process restarts intentionally clear them.

func NewSessionAffinity added in v0.2.42

func NewSessionAffinity(ttl time.Duration, capacity int) *SessionAffinity

func (*SessionAffinity) Bind added in v0.2.42

func (a *SessionAffinity) Bind(key, accountID string)

func (*SessionAffinity) Forget added in v0.2.42

func (a *SessionAffinity) Forget(key string)

func (*SessionAffinity) Get added in v0.2.42

func (a *SessionAffinity) Get(key string) (string, bool)

type StreamResult added in v0.2.6

type StreamResult struct {
	Response     *http.Response
	AccountID    string
	Provider     string
	AttemptCount int
	TTFBMs       int
	Routing      string
}

Jump to

Keyboard shortcuts

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