provider

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedactedCommandEnvValue     = "<redacted>"
	MetadataOnlyCommandEnvValue = "<metadata-only>"
)

Variables

This section is empty.

Functions

func ClassifyProviderFailure

func ClassifyProviderFailure(err *ProviderError) interfaces.WorkFailureDecision

func ContainsStopToken

func ContainsStopToken(output, stopToken string) bool

ContainsStopToken checks whether the output text contains the given stop token. The check is case-sensitive and looks for the token as a substring. This is extracted as a pure function for independent unit testing.

func ProviderFailureDecisionFromMetadata

func ProviderFailureDecisionFromMetadata(metadata *interfaces.ProviderFailureMetadata) interfaces.WorkFailureDecision

ProviderFailureDecisionFromMetadata resolves retry behavior from the durable normalized provider-failure metadata carried across runtime boundaries. The normalized type is canonical when present; family remains a fallback for older or partial metadata that omitted type.

func WorkFailureDecisionFromMetadata

func WorkFailureDecisionFromMetadata(metadata *interfaces.WorkFailureMetadata) interfaces.WorkFailureDecision

WorkFailureDecisionFromMetadata resolves retry behavior from durable generalized failure metadata carried across runtime boundaries.

func WorkFailureMetadataFromError

func WorkFailureMetadataFromError(err *ProviderError) *interfaces.WorkFailureMetadata

WorkFailureMetadataFromError projects a provider-shaped execution error onto the generalized runtime failure contract.

Types

type CommandEnvClassification

type CommandEnvClassification string
const (
	CommandEnvClassificationSafe         CommandEnvClassification = "safe"
	CommandEnvClassificationRedacted     CommandEnvClassification = "redacted"
	CommandEnvClassificationMetadataOnly CommandEnvClassification = "metadata_only"
)

func ClassifyCommandEnvKey

func ClassifyCommandEnvKey(name string) CommandEnvClassification

type CommandEnvDiagnosticProjection

type CommandEnvDiagnosticProjection struct {
	Count  int               `json:"count"`
	Keys   []string          `json:"keys,omitempty"`
	Values map[string]string `json:"values,omitempty"`
}

func ProjectCommandEnvForDiagnostics

func ProjectCommandEnvForDiagnostics(env []string) CommandEnvDiagnosticProjection

type CommandRequest

type CommandRequest = workerprocess.CommandRequest

type CommandResult

type CommandResult = workerprocess.CommandResult

type CommandRunner

type CommandRunner = workerprocess.CommandRunner

type DispatcherType

type DispatcherType string

DispatcherType selects which CLI tool the ScriptWrapProvider invokes.

const (
	// DispatcherClaude runs the Claude Code CLI ("claude").
	DispatcherClaude DispatcherType = "claude"
	// DispatcherCodex runs the OpenAI Codex CLI ("codex").
	DispatcherCodex DispatcherType = "codex"
)

type ExecCommandRunner

type ExecCommandRunner = workerprocess.ExecCommandRunner

type InferenceEventRecorder

type InferenceEventRecorder func(factoryapi.FactoryEvent)

InferenceEventRecorder receives generated provider-boundary inference events.

type LoggingCommandRunner

type LoggingCommandRunner = workerprocess.LoggingCommandRunner

type Provider

type Provider interface {
	// Infer sends a prompt to the model and returns the raw text response.
	// The request carries system prompt, user message, output schema,
	// and execution-level settings (model, working directory, env vars).
	Infer(ctx context.Context, req interfaces.ProviderInferenceRequest) (interfaces.InferenceResponse, error)
}

Provider abstracts LLM inference calls. Implementations handle the specifics of communicating with a particular model provider.

type ProviderBuildContext

type ProviderBuildContext struct {
	ContentCache    *materialize.DispatchCache
	MaterializeOpts *materialize.Options
}

ProviderBuildContext carries dispatch-scoped resources for provider argument building.

type ProviderError

type ProviderError struct {
	Family          interfaces.ProviderErrorFamily
	Type            interfaces.ProviderErrorType
	Message         string
	ProviderSession *interfaces.ProviderSessionMetadata
	Diagnostics     *interfaces.WorkDiagnostics
	Cause           error
}

ProviderError is the shared normalized provider failure contract. Provider implementations should return this typed error so executor, pause, and customer-messaging logic can make deterministic decisions without parsing raw provider output at every call site.

func NewProviderError

func NewProviderError(errorType interfaces.ProviderErrorType, message string, cause error) *ProviderError

func NewProviderErrorWithSession

func NewProviderErrorWithSession(errorType interfaces.ProviderErrorType, message string, cause error, session *interfaces.ProviderSessionMetadata) *ProviderError

func NormalizeProviderExecutionError

func NormalizeProviderExecutionError(err error) *ProviderError

NormalizeProviderExecutionError projects raw execution failures that affect retry policy onto the shared provider failure contract before retry decisions are made.

func NormalizeProviderExitFailure

func NormalizeProviderExitFailure(provider string, result CommandResult, session *interfaces.ProviderSessionMetadata, diagnostics *interfaces.WorkDiagnostics) *ProviderError

NormalizeProviderExitFailure exposes the canonical provider exit-failure normalization path for compatibility shims and behavior-focused tests.

func (*ProviderError) Error

func (e *ProviderError) Error() string

func (*ProviderError) Unwrap

func (e *ProviderError) Unwrap() error

type ProviderErrorCorpus

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

ProviderErrorCorpus is the cached shared provider-failure fixture set.

func LoadProviderErrorCorpus

func LoadProviderErrorCorpus() (ProviderErrorCorpus, error)

LoadProviderErrorCorpus returns the shared provider-failure fixture corpus.

func (ProviderErrorCorpus) Entry

Entry returns the named shared fixture.

func (ProviderErrorCorpus) SupportedEntriesForCategory

func (c ProviderErrorCorpus) SupportedEntriesForCategory(category string) []ProviderErrorCorpusEntry

SupportedEntriesForCategory returns the currently supported fixtures for one normalized provider-failure category.

type ProviderErrorCorpusEntry

type ProviderErrorCorpusEntry struct {
	Name                  string                         `json:"name"`
	Provider              interfaces.ModelProvider       `json:"provider"`
	RawProviderFamily     string                         `json:"raw_provider_family"`
	Category              string                         `json:"category"`
	UpstreamSourceCase    string                         `json:"upstream_source_case"`
	ExitCode              int                            `json:"exit_code"`
	Stdout                string                         `json:"stdout"`
	Stderr                string                         `json:"stderr"`
	ExpectedType          interfaces.ProviderErrorType   `json:"expected_type"`
	ExpectedFamily        interfaces.ProviderErrorFamily `json:"expected_family"`
	Retryable             bool                           `json:"retryable"`
	TriggersThrottlePause bool                           `json:"triggers_throttle_pause"`
	Supported             bool                           `json:"supported"`
	RejectMessageContains []string                       `json:"reject_message_contains,omitempty"`
	Notes                 string                         `json:"notes,omitempty"`
}

ProviderErrorCorpusEntry is one shared raw provider-failure fixture used by worker unit tests and functional smoke coverage.

func (ProviderErrorCorpusEntry) CommandResult

func (e ProviderErrorCorpusEntry) CommandResult() CommandResult

CommandResult renders the raw shared fixture into the provider subprocess contract used by normalization tests and smoke harnesses.

func (ProviderErrorCorpusEntry) RepeatedCommandResults

func (e ProviderErrorCorpusEntry) RepeatedCommandResults(count int) []CommandResult

RepeatedCommandResults expands one shared failure shape into a fixed number of repeated provider command results for bounded retry and throttle tests.

type RecordingProvider

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

RecordingProvider wraps a Provider and emits inference request/response events around each delegated provider call.

func NewRecordingProvider

func NewRecordingProvider(inner Provider, recorder InferenceEventRecorder, opts ...RecordingProviderOption) *RecordingProvider

NewRecordingProvider creates a Provider wrapper that records generated inference events before and after calls to inner.

func (*RecordingProvider) Infer

Infer records a request event, delegates to the wrapped provider, then records the matching response event with success or failure details.

type RecordingProviderOption

type RecordingProviderOption func(*RecordingProvider)

RecordingProviderOption configures a RecordingProvider.

func WithRecordingProviderClock

func WithRecordingProviderClock(now func() time.Time) RecordingProviderOption

WithRecordingProviderClock sets the clock used for event occurrence times and provider-call duration measurement.

type ScriptWrapProvider

type ScriptWrapProvider struct {
	// SkipPermissions enables --dangerously-skip-permissions (claude) or
	// --full-auto (codex).
	SkipPermissions bool
	// MaterializeOptions configures dispatch-time content URL materialization for Codex image args.
	MaterializeOptions *materialize.Options
	// Logger is the structured logger for inference diagnostics. Nil disables logging.
	Logger logging.Logger
	// contains filtered or unexported fields
}

ScriptWrapProvider implements Provider by shelling out to a CLI tool (Claude Code or Codex) as a subprocess. It supports configurable dispatchers and skip-permissions.

func NewScriptWrapProvider

func NewScriptWrapProvider(opts ...ScriptWrapProviderOption) *ScriptWrapProvider

NewScriptWrapProvider creates a ScriptWrapProvider with functional options.

func (*ScriptWrapProvider) Execute

Execute implements the shared runner contract while preserving the current provider-backed subprocess execution path.

func (*ScriptWrapProvider) Infer

Infer shells out to the configured CLI dispatcher with the user message. It merges req.EnvVars into the subprocess environment.

type ScriptWrapProviderOption

type ScriptWrapProviderOption func(*ScriptWrapProvider)

ScriptWrapProviderOption configures a ScriptWrapProvider.

func WithMaterializeOptions

func WithMaterializeOptions(opts *materialize.Options) ScriptWrapProviderOption

WithMaterializeOptions configures dispatch-time content URL materialization (used by Codex image args).

func WithProviderCommandRunner

func WithProviderCommandRunner(runner CommandRunner) ScriptWrapProviderOption

func WithProviderLogger

func WithProviderLogger(l logging.Logger) ScriptWrapProviderOption

WithProviderLogger sets the structured logger for inference diagnostics.

func WithSkipPermissions

func WithSkipPermissions(skip bool) ScriptWrapProviderOption

WithSkipPermissions enables the dangerously-skip-permissions flag.

Jump to

Keyboard shortcuts

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