110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
package catalog
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// ReadinessState is the stable catalog-facing provider/profile state.
|
|
type ReadinessState string
|
|
|
|
const (
|
|
StateReady ReadinessState = "ready"
|
|
StateMissingBinary ReadinessState = "missing_binary"
|
|
StateUnauthenticated ReadinessState = "unauthenticated"
|
|
StateUnsupportedModel ReadinessState = "unsupported_model"
|
|
StateProbeError ReadinessState = "probe_error"
|
|
)
|
|
|
|
var (
|
|
ErrBinaryMissing = errors.New("agent provider binary is missing")
|
|
ErrAuthenticationRequired = errors.New("agent provider authentication is required")
|
|
ErrModelUnsupported = errors.New("agent provider model is unsupported")
|
|
ErrProbeFailed = errors.New("agent provider probe failed")
|
|
)
|
|
|
|
// ReadinessError carries official catalog identity without raw provider output.
|
|
type ReadinessError struct {
|
|
State ReadinessState
|
|
ProviderID string
|
|
ModelID string
|
|
ProfileID string
|
|
Message string
|
|
cause error
|
|
}
|
|
|
|
func (e *ReadinessError) Error() string {
|
|
if e == nil {
|
|
return ""
|
|
}
|
|
if e.Message != "" {
|
|
return e.Message
|
|
}
|
|
return fmt.Sprintf(
|
|
"agent provider readiness %s: provider=%s model=%s profile=%s",
|
|
e.State, e.ProviderID, e.ModelID, e.ProfileID,
|
|
)
|
|
}
|
|
|
|
func (e *ReadinessError) Unwrap() error {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
return e.cause
|
|
}
|
|
|
|
func (e *ReadinessError) Is(target error) bool {
|
|
switch e.State {
|
|
case StateMissingBinary:
|
|
return target == ErrBinaryMissing
|
|
case StateUnauthenticated:
|
|
return target == ErrAuthenticationRequired
|
|
case StateUnsupportedModel:
|
|
return target == ErrModelUnsupported
|
|
case StateProbeError:
|
|
return target == ErrProbeFailed
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Readiness is one deterministic provider/model/profile discovery result.
|
|
type Readiness struct {
|
|
ProviderID string
|
|
ModelID string
|
|
ProfileID string
|
|
Command string
|
|
Version string
|
|
State ReadinessState
|
|
Detail string
|
|
Capabilities []string
|
|
Error *ReadinessError
|
|
}
|
|
|
|
// Ready reports whether the profile may be passed to the common provider
|
|
// factory.
|
|
func (r Readiness) Ready() bool {
|
|
return r.State == StateReady && r.Error == nil
|
|
}
|
|
|
|
func readinessFailure(
|
|
state ReadinessState,
|
|
providerID, modelID, profileID, message string,
|
|
cause error,
|
|
) Readiness {
|
|
return Readiness{
|
|
ProviderID: providerID,
|
|
ModelID: modelID,
|
|
ProfileID: profileID,
|
|
State: state,
|
|
Detail: message,
|
|
Error: &ReadinessError{
|
|
State: state,
|
|
ProviderID: providerID,
|
|
ModelID: modelID,
|
|
ProfileID: profileID,
|
|
Message: message,
|
|
cause: cause,
|
|
},
|
|
}
|
|
}
|