setup

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package setup wires catalog-backed deployment routing for hawk and graycode-router CLIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneStringMap

func CloneStringMap(in map[string]string) map[string]string

CloneStringMap returns a shallow copy of m.

func ConfiguredDeploymentAdapters

func ConfiguredDeploymentAdapters(cfg *config.ProviderConfig) map[string]router.DeploymentAdapter

ConfiguredDeploymentAdapters maps deployment IDs to live provider clients.

func ConfiguredDeployments

func ConfiguredDeployments(cfg *config.ProviderConfig) map[string]config.DeploymentConfig

ConfiguredDeployments merges explicit deployments with flat provider.json config.

func DefaultDeploymentForProvider

func DefaultDeploymentForProvider(provider string) string

DefaultDeploymentForProvider resolves the default deployment for a logical provider name from the provider registry. New providers need no setup-side mapping.

func DeploymentConfigFromProviderState

func DeploymentConfigFromProviderState(cfg *config.ProviderConfig, provider string) config.DeploymentConfig

DeploymentConfigFromProviderState reads API keys and base URLs from flat provider.json fields via the provider registry.

func DeploymentProvider

func DeploymentProvider(ctx context.Context, cfg *config.ProviderConfig) (client.Provider, error)

DeploymentProvider builds a catalog-aware router over configured deployments.

func DeploymentProviderFromCatalog

func DeploymentProviderFromCatalog(cfg *config.ProviderConfig, compiled *catalog.CompiledCatalog) (client.Provider, error)

DeploymentProviderFromCatalog is the ambient compatibility constructor. It may consult the default store, process environment, and flat-config detection. Host integrations must use DeploymentProviderFromState instead.

func DeploymentProviderFromState

func DeploymentProviderFromState(cfg *config.ProviderConfig, compiled *catalog.CompiledCatalog) (client.Provider, error)

DeploymentProviderFromState builds a router exclusively from the supplied provider state. It never reads the default credential store, process environment, process-default provider path, or flat-config detection. Host-facing Engine code must use this strict constructor.

func DeploymentRoutingFromState

func DeploymentRoutingFromState(cfg *config.ProviderConfig) bool

DeploymentRoutingFromState reports routing state without consulting process environment. Host-facing Engine code must use this pure form.

func DiscoverModelCatalog

func DiscoverModelCatalog(ctx context.Context, creds catalog.Credentials) (*catalog.RefreshResult, error)

DiscoverModelCatalog refreshes the remote graycode-router catalog and enriches it using the supplied API keys. Pass config.DiscoveryCredentials(ctx) or explicit keys; graycode-router owns all model metadata.

func DiscoverModelCatalogWithOptions

func DiscoverModelCatalogWithOptions(ctx context.Context, creds catalog.Credentials, opts DiscoverModelCatalogOptions) (*catalog.RefreshResult, error)

DiscoverModelCatalogWithOptions runs discover with optional force refresh (manual hawk models refresh).

func DiscoverProviderCatalog

func DiscoverProviderCatalog(ctx context.Context, providerID string, creds catalog.Credentials) (*catalog.RefreshResult, error)

DiscoverProviderCatalog fetches live models for one provider after API key setup.

func FirstNonEmpty

func FirstNonEmpty(values ...string) string

FirstNonEmpty returns the first non-empty trimmed string.

func FormatStatus

func FormatStatus(report StatusReport) string

FormatStatus renders StatusReport for terminal output.

func LoadCompiledCatalog

func LoadCompiledCatalog(ctx context.Context) (*catalog.CompiledCatalog, error)

LoadCompiledCatalog returns the compiled catalog from cache/embedded data without network refresh.

func ProviderForDeployment

func ProviderForDeployment(id string, deployment config.DeploymentConfig) (client.Provider, bool)

ProviderForDeployment constructs one adapter with ambient compatibility fallbacks. Host integrations must use ProviderForDeploymentFromState.

func ProviderForDeploymentFromState

func ProviderForDeploymentFromState(id string, deployment config.DeploymentConfig, cfg *config.ProviderConfig) (client.Provider, bool)

ProviderForDeploymentFromState constructs exactly one adapter without any process-global credential, environment, OIDC, or provider-config fallback.

func ProviderIDForDeployment

func ProviderIDForDeployment(compiled *catalog.CompiledCatalog, deploymentID string) string

ProviderIDForDeployment resolves catalog provider id for a deployment id.

func RouterRoutingPolicy

func RouterRoutingPolicy(policy *config.RoutingPolicy) router.RoutingPolicy

RouterRoutingPolicy converts config routing JSON into router policy.

func RouterRoutingStageMap

func RouterRoutingStageMap(in map[string][]config.RoutingStage) map[string][]router.RoutingStage

RouterRoutingStageMap converts per-key routing stages.

func RouterRoutingStages

func RouterRoutingStages(stages []config.RoutingStage) []router.RoutingStage

RouterRoutingStages converts config stages to router stages.

func RoutingPreview

func RoutingPreview(ctx context.Context, model string) (string, error)

RoutingPreview returns JSON describing effective routing for a model ID.

func RoutingPreviewFromPaths

func RoutingPreviewFromPaths(ctx context.Context, model, providerConfigPath, catalogCachePath string) (string, error)

RoutingPreviewFromPaths resolves routing from host-owned state paths. Empty paths retain the process defaults for backwards compatibility.

func SaveProviderConfigV2

func SaveProviderConfigV2(cfg *config.ProviderConfig) error

SaveProviderConfigV2 writes migrated provider config when upgraded in memory.

func UseDeploymentRouting

func UseDeploymentRouting(cfg *config.ProviderConfig) bool

UseDeploymentRouting mirrors graycode-router CLI behavior: env override, then provider.json shape.

Types

type ApplyCredentialsResult

type ApplyCredentialsResult struct {
	Catalog            *catalog.RefreshResult
	ProviderConfig     *config.ProviderConfig
	ProviderConfigPath string
	RoutingJSON        string
	Setup              *SetupUI
}

ApplyCredentialsResult is the full graycode-router response after API keys are applied: refreshed catalog, provider.json (deployments + routing), and paths.

func ApplyCredentials

func ApplyCredentials(ctx context.Context, creds catalog.Credentials) (*ApplyCredentialsResult, error)

ApplyCredentials discovers the model catalog from env API keys, then writes ~/.hawk/provider.json deployments and routing derived from the catalog.

func ApplyCredentialsForProvider

func ApplyCredentialsForProvider(ctx context.Context, providerID string, creds catalog.Credentials) (*ApplyCredentialsResult, error)

ApplyCredentialsForProvider discovers models for one provider after key setup, then updates routing.

type DiscoverModelCatalogOptions

type DiscoverModelCatalogOptions struct {
	// ForceRefresh re-fetches the published remote catalog and all live provider APIs.
	ForceRefresh bool
}

DiscoverModelCatalogOptions controls catalog discovery behavior.

type ModelUI

type ModelUI struct {
	CanonicalID string `json:"canonical_id"`
	DisplayName string `json:"display_name"`
	Source      string `json:"source,omitempty"` // "remote", "live", or "remote+live"
}

ModelUI is one selectable model for host /config UIs.

type ProviderUI

type ProviderUI struct {
	ID          string    `json:"id"`
	DisplayName string    `json:"display_name"`
	Models      []ModelUI `json:"models"`
}

ProviderUI is a provider and its models after credential apply.

type SetupUI

type SetupUI struct {
	Providers []ProviderUI `json:"providers"`
}

SetupUI is JSON-safe metadata returned to hawk (no secrets).

func BuildSetupUI

func BuildSetupUI(compiled *catalog.CompiledCatalog, providerFilter string) *SetupUI

BuildSetupUI lists models per provider from the compiled catalog. If providerFilter is non-empty, only that provider is included.

type StatusReport

type StatusReport struct {
	DeploymentRouting  bool
	ProviderConfig     string
	ConfigVersion      int
	Configured         []string
	CatalogCache       string
	CatalogExists      bool
	CatalogModified    time.Time
	CatalogStale       bool
	CatalogModels      int
	CatalogDeployments int
	CatalogOfferings   int
	ActiveModel        string
	RoutingSource      string
	RoutingStages      int
}

StatusReport summarizes deployment routing readiness (graycode-router provider status).

func DeploymentStatus

func DeploymentStatus(ctx context.Context, activeModel string) (StatusReport, error)

DeploymentStatus builds a status report for CLI and agent diagnostics.

func DeploymentStatusFromPaths

func DeploymentStatusFromPaths(ctx context.Context, activeModel, providerConfigPath, catalogCachePath string) (StatusReport, error)

DeploymentStatusFromPaths builds a status report from host-owned state. Empty paths retain the process defaults for backwards compatibility.

Jump to

Keyboard shortcuts

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