provider

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthConfigEnvironment

func AuthConfigEnvironment(authConfig map[string]any) []string

func ClaudeCodeAssistantSnapshotContinues

func ClaudeCodeAssistantSnapshotContinues(previous string, next string) bool

func ClaudeCodeEventSessionID

func ClaudeCodeEventSessionID(event ClaudeCodeEvent) string

func ClaudeCodeEventTurnID

func ClaudeCodeEventTurnID(event ClaudeCodeEvent) string

func ClaudeCodeEventUUID

func ClaudeCodeEventUUID(event ClaudeCodeEvent) string

func ClaudeCodeRawPayload

func ClaudeCodeRawPayload(event ClaudeCodeEvent) map[string]any

func ClaudeCodeTurnFailure

func ClaudeCodeTurnFailure(event ClaudeCodeEvent) (string, string)

func ExtractClaudeCodeToolResultText

func ExtractClaudeCodeToolResultText(content any) string

func LookupEnvironmentValue

func LookupEnvironmentValue(environment []string, key string) (string, bool)

func ResolveSpanStartOptions

func ResolveSpanStartOptions(opts ...SpanStartOption) (SpanKind, []SpanAttribute)

Types

type AbsolutePath

type AbsolutePath string

AbsolutePath is a validated absolute filesystem path.

func MustParseAbsolutePath

func MustParseAbsolutePath(raw string) AbsolutePath

MustParseAbsolutePath parses an absolute path and panics on invalid input.

func ParseAbsolutePath

func ParseAbsolutePath(raw string) (AbsolutePath, error)

ParseAbsolutePath validates and normalizes an absolute path.

func (AbsolutePath) String

func (p AbsolutePath) String() string

type AgentCLICommand

type AgentCLICommand string

func MustParseAgentCLICommand

func MustParseAgentCLICommand(raw string) AgentCLICommand

func ParseAgentCLICommand

func ParseAgentCLICommand(raw string) (AgentCLICommand, error)

func (AgentCLICommand) String

func (c AgentCLICommand) String() string

type AgentCLIProcess

type AgentCLIProcess interface {
	PID() int
	Stdin() io.WriteCloser
	Stdout() io.ReadCloser
	Stderr() io.ReadCloser
	Wait() error
	Stop(context.Context) error
}

type AgentCLIProcessManager

type AgentCLIProcessManager interface {
	Start(context.Context, AgentCLIProcessSpec) (AgentCLIProcess, error)
}

type AgentCLIProcessSpec

type AgentCLIProcessSpec struct {
	Command          AgentCLICommand
	Args             []string
	WorkingDirectory *AbsolutePath
	Environment      []string
}

func NewAgentCLIProcessSpec

func NewAgentCLIProcessSpec(
	command AgentCLICommand,
	args []string,
	workingDirectory *AbsolutePath,
	environment []string,
) (AgentCLIProcessSpec, error)

type CLIRateLimit

type CLIRateLimit struct {
	Provider   CLIRateLimitProvider `json:"provider"`
	ClaudeCode *ClaudeCodeRateLimit `json:"claude_code,omitempty"`
	Codex      *CodexRateLimit      `json:"codex,omitempty"`
	Gemini     *GeminiRateLimit     `json:"gemini,omitempty"`
	Raw        map[string]any       `json:"raw,omitempty"`
}

func ParseClaudeCodeRateLimit

func ParseClaudeCodeRateLimit(raw json.RawMessage) (*CLIRateLimit, error)

func ParseCodexRateLimit

func ParseCodexRateLimit(raw json.RawMessage) (*CLIRateLimit, error)

func ParseGeminiCLIRateLimit

func ParseGeminiCLIRateLimit(raw json.RawMessage) (*CLIRateLimit, error)

func ProbeGeminiCLIRateLimit

func ProbeGeminiCLIRateLimit(
	ctx context.Context,
	processManager AgentCLIProcessManager,
	geminiCommand AgentCLICommand,
	workingDirectory *AbsolutePath,
	environment []string,
	model string,
) (*CLIRateLimit, *time.Time, error)

type CLIRateLimitProvider

type CLIRateLimitProvider string
const (
	CLIRateLimitProviderClaudeCode CLIRateLimitProvider = "claude_code"
	CLIRateLimitProviderCodex      CLIRateLimitProvider = "codex"
	CLIRateLimitProviderGemini     CLIRateLimitProvider = "gemini"
)

type CLIUsage

type CLIUsage struct {
	Provider           CLIUsageProvider `json:"provider"`
	Source             CLIUsageSource   `json:"source"`
	Model              string           `json:"model,omitempty"`
	CostUSD            *float64         `json:"cost_usd,omitempty"`
	ModelContextWindow *int64           `json:"model_context_window,omitempty"`
	Total              CLIUsageTokens   `json:"total"`
	Delta              CLIUsageTokens   `json:"delta,omitempty"`
	Raw                json.RawMessage  `json:"raw,omitempty"`
	Claude             *ClaudeCodeUsage `json:"claude,omitempty"`
	Gemini             *GeminiCLIUsage  `json:"gemini,omitempty"`
}

func NewCodexCLIUsage

func NewCodexCLIUsage(total CLIUsageTokens, delta CLIUsageTokens, modelContextWindow *int64) *CLIUsage

func ParseClaudeCodeUsage

func ParseClaudeCodeUsage(raw json.RawMessage, model string, totalCostUSD *float64) (*CLIUsage, error)

func ParseGeminiCLIStreamUsage

func ParseGeminiCLIStreamUsage(raw json.RawMessage) (*CLIUsage, error)

func ParseGeminiCLIUsage

func ParseGeminiCLIUsage(raw json.RawMessage) (*CLIUsage, error)

func (*CLIUsage) HasTokenTotals

func (u *CLIUsage) HasTokenTotals() bool

type CLIUsageProvider

type CLIUsageProvider string
const (
	CLIUsageProviderCodex      CLIUsageProvider = "codex"
	CLIUsageProviderClaudeCode CLIUsageProvider = "claude_code"
	CLIUsageProviderGemini     CLIUsageProvider = "gemini"
)

type CLIUsageSource

type CLIUsageSource string
const (
	CLIUsageSourceCodexAppServerThreadUpdate CLIUsageSource = "codex_app_server_thread_update"
	CLIUsageSourceClaudeCodeResult           CLIUsageSource = "claude_code_result"
	CLIUsageSourceGeminiJSONStats            CLIUsageSource = "gemini_json_stats"
	CLIUsageSourceGeminiStreamJSONResult     CLIUsageSource = "gemini_stream_json_result"
)

type CLIUsageTokens

type CLIUsageTokens struct {
	InputTokens              int64 `json:"input_tokens,omitempty"`
	OutputTokens             int64 `json:"output_tokens,omitempty"`
	TotalTokens              int64 `json:"total_tokens,omitempty"`
	CachedInputTokens        int64 `json:"cached_input_tokens,omitempty"`
	CacheCreationInputTokens int64 `json:"cache_creation_input_tokens,omitempty"`
	ReasoningTokens          int64 `json:"reasoning_tokens,omitempty"`
	PromptTokens             int64 `json:"prompt_tokens,omitempty"`
	CandidateTokens          int64 `json:"candidate_tokens,omitempty"`
	ToolTokens               int64 `json:"tool_tokens,omitempty"`
}

type ClaudeCodeAdapter

type ClaudeCodeAdapter interface {
	Start(context.Context, ClaudeCodeSessionSpec) (ClaudeCodeSession, error)
}

ClaudeCodeAdapter starts Claude Code sessions behind a provider abstraction.

type ClaudeCodeContentBlock

type ClaudeCodeContentBlock struct {
	Kind      ClaudeCodeContentBlockKind
	ID        string
	Name      string
	Input     map[string]any
	Text      string
	ToolUseID string
	Content   any
	IsError   bool
}

func ParseClaudeCodeMessageBlocks

func ParseClaudeCodeMessageBlocks(raw json.RawMessage) ([]ClaudeCodeContentBlock, bool)

type ClaudeCodeContentBlockKind

type ClaudeCodeContentBlockKind string
const (
	ClaudeCodeContentBlockKindText          ClaudeCodeContentBlockKind = "text"
	ClaudeCodeContentBlockKindToolUse       ClaudeCodeContentBlockKind = "tool_use"
	ClaudeCodeContentBlockKindServerToolUse ClaudeCodeContentBlockKind = "server_tool_use"
	ClaudeCodeContentBlockKindMCPToolUse    ClaudeCodeContentBlockKind = "mcp_tool_use"
	ClaudeCodeContentBlockKindToolResult    ClaudeCodeContentBlockKind = "tool_result"
)

type ClaudeCodeEvent

type ClaudeCodeEvent struct {
	Kind            ClaudeCodeEventKind
	Raw             json.RawMessage
	UnknownType     string
	Subtype         string
	SessionID       string
	ParentToolUseID string
	Message         json.RawMessage
	Data            json.RawMessage
	Result          string
	Model           string
	Usage           json.RawMessage
	UsageInfo       *CLIUsage
	RateLimit       json.RawMessage
	RateLimitInfo   *CLIRateLimit
	Event           json.RawMessage
	UUID            string
	IsError         bool
	NumTurns        int
	DurationMS      int
	DurationAPIMS   int
	TotalCostUSD    *float64
}

ClaudeCodeEvent is the normalized event envelope emitted by the adapter.

type ClaudeCodeEventKind

type ClaudeCodeEventKind string

ClaudeCodeEventKind classifies one streamed Claude Code event frame.

const (
	// Claude Code event kinds mirror the upstream streaming protocol.
	ClaudeCodeEventKindUnknown      ClaudeCodeEventKind = "unknown"
	ClaudeCodeEventKindSystem       ClaudeCodeEventKind = "system"
	ClaudeCodeEventKindAssistant    ClaudeCodeEventKind = "assistant"
	ClaudeCodeEventKindUser         ClaudeCodeEventKind = "user"
	ClaudeCodeEventKindResult       ClaudeCodeEventKind = "result"
	ClaudeCodeEventKindRateLimit    ClaudeCodeEventKind = "rate_limit_event"
	ClaudeCodeEventKindStream       ClaudeCodeEventKind = "stream_event"
	ClaudeCodeEventKindTaskStart    ClaudeCodeEventKind = "task_started"
	ClaudeCodeEventKindTaskProgress ClaudeCodeEventKind = "task_progress"
	ClaudeCodeEventKindTaskNotice   ClaudeCodeEventKind = "task_notification"
)

type ClaudeCodeRateLimit

type ClaudeCodeRateLimit struct {
	Status                string     `json:"status,omitempty"`
	RateLimitType         string     `json:"rate_limit_type,omitempty"`
	ResetsAt              *time.Time `json:"resets_at,omitempty"`
	Utilization           *float64   `json:"utilization,omitempty"`
	SurpassedThreshold    *float64   `json:"surpassed_threshold,omitempty"`
	OverageStatus         string     `json:"overage_status,omitempty"`
	OverageDisabledReason string     `json:"overage_disabled_reason,omitempty"`
	IsUsingOverage        *bool      `json:"is_using_overage,omitempty"`
}

type ClaudeCodeSession

type ClaudeCodeSession interface {
	SessionID() (ClaudeCodeSessionID, bool)
	Events() <-chan ClaudeCodeEvent
	Errors() <-chan error
	Send(context.Context, ClaudeCodeTurnInput) error
	Close(context.Context) error
}

ClaudeCodeSession represents a live Claude Code session.

type ClaudeCodeSessionID

type ClaudeCodeSessionID string

ClaudeCodeSessionID identifies a Claude Code session.

func MustParseClaudeCodeSessionID

func MustParseClaudeCodeSessionID(raw string) ClaudeCodeSessionID

MustParseClaudeCodeSessionID parses a session ID and panics on invalid input.

func ParseClaudeCodeSessionID

func ParseClaudeCodeSessionID(raw string) (ClaudeCodeSessionID, error)

ParseClaudeCodeSessionID validates a raw Claude Code session identifier.

func (ClaudeCodeSessionID) String

func (s ClaudeCodeSessionID) String() string

type ClaudeCodeSessionSpec

type ClaudeCodeSessionSpec struct {
	Command                AgentCLICommand
	BaseArgs               []string
	WorkingDirectory       *AbsolutePath
	Environment            []string
	AllowedTools           []string
	AppendSystemPrompt     string
	MaxTurns               *int
	MaxBudgetUSD           *float64
	ResumeSessionID        *ClaudeCodeSessionID
	IncludePartialMessages bool
}

ClaudeCodeSessionSpec defines how to start or resume a Claude Code session.

func NewClaudeCodeSessionSpec

func NewClaudeCodeSessionSpec(
	command AgentCLICommand,
	baseArgs []string,
	workingDirectory *AbsolutePath,
	environment []string,
	allowedTools []string,
	appendSystemPrompt string,
	maxTurns *int,
	maxBudgetUSD *float64,
	resumeSessionID *ClaudeCodeSessionID,
	includePartialMessages bool,
) (ClaudeCodeSessionSpec, error)

NewClaudeCodeSessionSpec validates and constructs a Claude Code session spec.

type ClaudeCodeToolUseSemantics

type ClaudeCodeToolUseSemantics struct {
	Command string
}

func DeriveClaudeCodeToolUseSemantics

func DeriveClaudeCodeToolUseSemantics(toolName string, input map[string]any) ClaudeCodeToolUseSemantics

type ClaudeCodeTurnInput

type ClaudeCodeTurnInput struct {
	Prompt string
}

ClaudeCodeTurnInput is a single prompt turn sent to Claude Code.

func NewClaudeCodeTurnInput

func NewClaudeCodeTurnInput(prompt string) (ClaudeCodeTurnInput, error)

NewClaudeCodeTurnInput validates and constructs a Claude Code turn input.

type ClaudeCodeUsage

type ClaudeCodeUsage struct {
	ServiceTier  string `json:"service_tier,omitempty"`
	InferenceGeo string `json:"inference_geo,omitempty"`
}

type CodexRateLimit

type CodexRateLimit struct {
	LimitID   string                `json:"limit_id,omitempty"`
	LimitName string                `json:"limit_name,omitempty"`
	Primary   *CodexRateLimitWindow `json:"primary,omitempty"`
	Secondary *CodexRateLimitWindow `json:"secondary,omitempty"`
	PlanType  string                `json:"plan_type,omitempty"`
}

type CodexRateLimitWindow

type CodexRateLimitWindow struct {
	UsedPercent   *float64   `json:"used_percent,omitempty"`
	WindowMinutes int64      `json:"window_minutes,omitempty"`
	ResetsAt      *time.Time `json:"resets_at,omitempty"`
}

type Counter

type Counter interface {
	Add(float64)
}

Counter records additive totals.

type Event

type Event struct {
	Topic       Topic           `json:"topic"`
	Type        EventType       `json:"type"`
	Payload     json.RawMessage `json:"payload,omitempty"`
	PublishedAt time.Time       `json:"published_at"`
}

Event is the envelope published through the event provider abstraction.

func NewEvent

func NewEvent(topic Topic, eventType EventType, payload json.RawMessage, publishedAt time.Time) (Event, error)

NewEvent constructs a validated event envelope.

func NewJSONEvent

func NewJSONEvent(topic Topic, eventType EventType, payload any, publishedAt time.Time) (Event, error)

NewJSONEvent marshals a JSON payload and constructs a validated event envelope.

type EventProvider

type EventProvider interface {
	Publish(ctx context.Context, event Event) error
	Subscribe(ctx context.Context, topics ...Topic) (<-chan Event, error)
	Close() error
}

EventProvider publishes and subscribes runtime events.

type EventType

type EventType string

EventType names a specific event kind within a topic.

func MustParseEventType

func MustParseEventType(raw string) EventType

MustParseEventType parses an event type and panics on invalid input.

func ParseEventType

func ParseEventType(raw string) (EventType, error)

ParseEventType validates a raw event type token.

func (EventType) String

func (t EventType) String() string

type ExecutableResolver

type ExecutableResolver interface {
	LookPath(name string) (string, error)
}

ExecutableResolver resolves executable paths from the local environment.

type Gauge

type Gauge interface {
	Set(float64)
}

Gauge records the latest instantaneous floating point value.

type GeminiCLIAPIUsage

type GeminiCLIAPIUsage struct {
	TotalRequests  int64 `json:"total_requests,omitempty"`
	TotalErrors    int64 `json:"total_errors,omitempty"`
	TotalLatencyMS int64 `json:"total_latency_ms,omitempty"`
}

type GeminiCLIModelUsage

type GeminiCLIModelUsage struct {
	API    GeminiCLIAPIUsage             `json:"api"`
	Tokens CLIUsageTokens                `json:"tokens"`
	Roles  map[string]GeminiCLIRoleUsage `json:"roles,omitempty"`
}

type GeminiCLIRoleUsage

type GeminiCLIRoleUsage struct {
	API    GeminiCLIAPIUsage `json:"api"`
	Tokens CLIUsageTokens    `json:"tokens"`
}

type GeminiCLIUsage

type GeminiCLIUsage struct {
	DurationMS int64                          `json:"duration_ms,omitempty"`
	ToolCalls  int64                          `json:"tool_calls,omitempty"`
	Models     map[string]GeminiCLIModelUsage `json:"models,omitempty"`
}

type GeminiRateLimit

type GeminiRateLimit struct {
	AuthType  string                  `json:"auth_type,omitempty"`
	Remaining *int64                  `json:"remaining,omitempty"`
	Limit     *int64                  `json:"limit,omitempty"`
	ResetTime *time.Time              `json:"reset_time,omitempty"`
	Buckets   []GeminiRateLimitBucket `json:"buckets,omitempty"`
}

type GeminiRateLimitBucket

type GeminiRateLimitBucket struct {
	ModelID           string     `json:"model_id,omitempty"`
	TokenType         string     `json:"token_type,omitempty"`
	RemainingAmount   string     `json:"remaining_amount,omitempty"`
	RemainingFraction *float64   `json:"remaining_fraction,omitempty"`
	ResetTime         *time.Time `json:"reset_time,omitempty"`
}

type Histogram

type Histogram interface {
	Record(float64)
}

Histogram records sampled floating point values.

type MetricsProvider

type MetricsProvider interface {
	Counter(name string, tags Tags) Counter
	Histogram(name string, tags Tags) Histogram
	Gauge(name string, tags Tags) Gauge
}

MetricsProvider abstracts application metrics collection.

func NewNoopMetricsProvider

func NewNoopMetricsProvider() MetricsProvider

NewNoopMetricsProvider returns a provider that drops all measurements.

type ServiceName

type ServiceName string

ServiceName identifies a managed user service.

func MustParseServiceName

func MustParseServiceName(raw string) ServiceName

MustParseServiceName parses a service name and panics on invalid input.

func ParseServiceName

func ParseServiceName(raw string) (ServiceName, error)

ParseServiceName validates a raw service name token.

func (ServiceName) String

func (n ServiceName) String() string

type Span

type Span interface {
	End()
	RecordError(err error)
	SetAttributes(attrs ...SpanAttribute)
	SetStatus(code SpanStatusCode, description string)
	TraceID() string
	SpanID() string
}

Span is the provider-facing span abstraction used across application layers.

type SpanAttribute

type SpanAttribute struct {
	Key         string
	Type        SpanAttributeType
	StringValue string
	Int64Value  int64
	BoolValue   bool
}

func BoolAttribute

func BoolAttribute(key string, value bool) SpanAttribute

func Int64Attribute

func Int64Attribute(key string, value int64) SpanAttribute

func IntAttribute

func IntAttribute(key string, value int) SpanAttribute

func StringAttribute

func StringAttribute(key string, value string) SpanAttribute

type SpanAttributeType

type SpanAttributeType uint8
const (
	SpanAttributeTypeString SpanAttributeType = iota + 1
	SpanAttributeTypeInt64
	SpanAttributeTypeBool
)

type SpanKind

type SpanKind string
const (
	SpanKindInternal SpanKind = "internal"
	SpanKindServer   SpanKind = "server"
	SpanKindClient   SpanKind = "client"
	SpanKindProducer SpanKind = "producer"
	SpanKindConsumer SpanKind = "consumer"
)

type SpanStartOption

type SpanStartOption interface {
	// contains filtered or unexported methods
}

func WithSpanAttributes

func WithSpanAttributes(attrs ...SpanAttribute) SpanStartOption

func WithSpanKind

func WithSpanKind(kind SpanKind) SpanStartOption

type SpanStatusCode

type SpanStatusCode string
const (
	SpanStatusUnset SpanStatusCode = "unset"
	SpanStatusOK    SpanStatusCode = "ok"
	SpanStatusError SpanStatusCode = "error"
)

type Tags

type Tags map[string]string

Tags describe metric dimensions attached to a measurement.

type Topic

type Topic string

Topic names an event stream channel.

func MustParseTopic

func MustParseTopic(raw string) Topic

MustParseTopic parses a topic and panics on invalid input.

func ParseTopic

func ParseTopic(raw string) (Topic, error)

ParseTopic validates a raw event topic token.

func (Topic) String

func (t Topic) String() string

type TraceProvider

type TraceProvider interface {
	ExtractHTTPContext(ctx context.Context, header http.Header) context.Context
	InjectHTTPHeaders(ctx context.Context, header http.Header)
	StartSpan(ctx context.Context, name string, opts ...SpanStartOption) (context.Context, Span)
	Shutdown(ctx context.Context) error
}

TraceProvider manages request/context propagation and span lifecycle.

func NewNoopTraceProvider

func NewNoopTraceProvider() TraceProvider

type UserServiceInstallSpec

type UserServiceInstallSpec struct {
	Name             ServiceName
	Description      string
	ProgramPath      AbsolutePath
	Arguments        []string
	WorkingDirectory AbsolutePath
	EnvironmentFile  AbsolutePath
	StdoutPath       AbsolutePath
	StderrPath       AbsolutePath
}

UserServiceInstallSpec defines how to install a managed user service.

func NewUserServiceInstallSpec

func NewUserServiceInstallSpec(
	name ServiceName,
	description string,
	programPath AbsolutePath,
	arguments []string,
	workingDirectory AbsolutePath,
	environmentFile AbsolutePath,
	stdoutPath AbsolutePath,
	stderrPath AbsolutePath,
) (UserServiceInstallSpec, error)

NewUserServiceInstallSpec validates and constructs a managed service install spec.

type UserServiceLogsOptions

type UserServiceLogsOptions struct {
	Follow bool
	Lines  int
	Stdout io.Writer
	Stderr io.Writer
}

UserServiceLogsOptions controls service log streaming behavior.

func NewUserServiceLogsOptions

func NewUserServiceLogsOptions(lines int, follow bool, stdout io.Writer, stderr io.Writer) (UserServiceLogsOptions, error)

NewUserServiceLogsOptions validates and constructs log streaming options.

type UserServiceManager

UserServiceManager abstracts platform-specific user service control.

Jump to

Keyboard shortcuts

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