Documentation
¶
Overview ¶
TTYPrompter: the CLI's Prompter over stdin/stderr. Secrets are read with terminal echo disabled via stty against the controlling terminal — stdlib-only, unix-only, and honest when it cannot: the fallback prompts visibly and says so rather than silently echoing what the operator believed was hidden. The desktop app implements Prompter as a form and never comes through here.
Package setup implements the operator-experience flows: first-run machine setup with LLM-provider configuration, the guided MCP-profile setup that collects a QuickAgent's keys and identities, and the model catalog — one read of a provider's models listing with the operator's key, so a form can offer the models rather than ask for one to be typed, which is also the endpoint test the form gets for free (models.go). Everything works through the Prompter interface so the CLI (a TTY) and the desktop app (a form) drive the same logic — no parallel implementations; the provider table below is the one place that knows a provider's endpoints and how its key is sent.
Index ¶
- Constants
- func ConfigureModel(p Prompter, pol *policy.Policy, opts ModelOpts) error
- func GuidedProfile(p Prompter, opts GuidedProfileOpts) (*profile.Profile, error)
- func IsConnectProvider(provider string) bool
- func IsLoopbackHost(host string) bool
- func PlainHTTPWarning(endpoint string) string
- func Providers() []string
- type Catalog
- type ChatGPTOffer
- type ClaudeOffer
- type ConnectOffer
- type CopilotOffer
- type GuidedProfileOpts
- type Model
- type ModelOpts
- type Prompter
- type ProviderDefault
- type TTYPrompter
Constants ¶
const AnthropicKeyCredits = "" /* 143-byte string literal not displayed */
AnthropicKeyCredits is what the API-key choice for Anthropic says: the plans whose included API credits a key spends.
const ClaudeSignInLabel = "Use your Claude subscription (runs Claude Code)"
ClaudeSignInLabel is the Claude choice's wording everywhere: plain text that runs use Claude Code, no logo, no "Sign in with Claude".
const ConnectLabel = "Connect your account"
ConnectLabel is the connect choice's wording.
const CopilotAuto = "auto"
CopilotAuto is the Copilot model that lets Copilot choose, the only one a Copilot Free plan has; it is always offered.
const CopilotSignInLabel = "Sign in with GitHub"
CopilotSignInLabel is the Copilot choice's wording.
Variables ¶
This section is empty.
Functions ¶
func ConfigureModel ¶
ConfigureModel resolves the operator's LLM provider preference (req 5) into the policy's model block, prompting through p where opts leave gaps. Everything outside `model:` is untouched.
func GuidedProfile ¶
func GuidedProfile(p Prompter, opts GuidedProfileOpts) (*profile.Profile, error)
GuidedProfile runs the guided conversation and returns the new profile. Empty secret answers are recorded as absent (resolve from the environment at run time), not as empty strings.
func IsConnectProvider ¶
IsConnectProvider reports whether provider's account can be connected.
func IsLoopbackHost ¶
IsLoopbackHost is true for localhost, a *.localhost name, and a loopback address: a server on the operator's own machine.
func PlainHTTPWarning ¶
PlainHTTPWarning is the sentence a caller shows for a model endpoint the key would reach over plain http off this machine, and "" for https, for loopback http, and for anything that is not an http URL. It is the one wording the CLI's setup, doctor and the desktop share.
Types ¶
type Catalog ¶
Catalog is what a provider's models endpoint listed, in the provider's own order. Warning, when set, is PlainHTTPWarning's sentence for the endpoint the key was sent to: the caller shows it beside the listing.
func ListModels ¶
ListModels asks provider's models endpoint with key and returns what it listed. baseURL is required for custom and ignored for the table providers. A scheme other than http or https is refused before a request is made; plain http off loopback, which only a custom endpoint can be, is the operator's choice and is carried out with the warning on the Catalog; no redirect is followed; the key is scrubbed from any error, the provider's own message included. An empty listing is an error: a form offering nothing is worse than one saying so.
type ChatGPTOffer ¶
type ChatGPTOffer struct {
// Kept is the account of a kept ChatGPT sign-in that still works, ""
// when there is none.
Kept func() string
// SignIn signs in (fresh, or when none is kept) or refreshes the kept
// sign-in, and returns its account and the models its plan offers.
SignIn func(fresh bool) (account string, models []string, err error)
}
ChatGPTOffer is how setup reaches the ChatGPT sign-in, which the caller owns (the store, the browser, the network).
type ClaudeOffer ¶
type ClaudeOffer struct {
// Kept is the account of the Claude Code image's kept sign-in, ""
// when there is none.
Kept func() string
// SignIn runs Claude Code's own sign-in and returns its account.
SignIn func() (account string, err error)
}
ClaudeOffer is how setup reaches Claude Code's own sign-in, which the caller owns (the image, docker, the terminal).
type ConnectOffer ¶
type ConnectOffer struct {
// Kept is how a kept connect for provider is named ("Connected as …"),
// "" when none is kept.
Kept func(provider string) string
// Connect connects the person's account in their browser, keeps the
// key it minted in the OS keychain, and returns how the account is
// named.
Connect func(provider string) (account string, err error)
// Forget forgets the connect kept for provider once a pasted key has
// replaced its key in the keychain, and says what became of it (""
// when none was kept).
Forget func(provider string) (outcome string, err error)
}
ConnectOffer is how setup reaches a connect, which the caller owns (the browser, the network, the keychain). Each takes the policy's provider.
type CopilotOffer ¶
type CopilotOffer struct {
// Kept is the account of a kept Copilot sign-in that still works, ""
// when there is none.
Kept func() string
// SignIn signs in with GitHub and returns the account.
SignIn func() (account string, err error)
// Models lists the model ids the Copilot plan named offers the signed-in
// account, asked of Copilot CLI, in its order; nil lists none. Setup asks
// it only when it is about to ask for the model.
Models func(plan string) ([]string, error)
}
CopilotOffer is how setup reaches the Copilot sign-in, which the caller owns (the store, the browser, the network).
type GuidedProfileOpts ¶
type GuidedProfileOpts struct {
Ref string
Digest string
// CapabilityLines is the contract display (what the keys are FOR).
CapabilityLines []string
// Secrets are the manifest-declared env names to collect.
Secrets []string
// Optional are the ones a run may go without (the manifest's
// optionalSecrets): asked the same way, and said so.
Optional []string
// DefaultKeep seeds the keep question (policy default or flag).
DefaultKeep bool
// KeepDecided suppresses the keep question (the flag already chose).
KeepDecided bool
// Help is the release guide's connect help per secret name:
// where to create the key, which scopes it needs, in markdown that may
// span lines. Printed as text before the question for that
// key, beneath its name behind termtext's gutter when it spans lines.
Help map[string]string
}
GuidedProfileOpts parameterizes the guided profile flow.
type Model ¶
Model is one listed model: the id a policy names, and the name a person reads where the provider gives one.
type ModelOpts ¶
type ModelOpts struct {
Provider string
Model string
APIKeyEnv string
// APIKeySource is "" (keep what the policy has for the same provider, else
// env), "env" or "keyring": where the key comes from when the variable is
// unset. Interactive setup offers to store the key in the keychain and sets
// keyring itself.
APIKeySource string
// StoreKey puts a key into the OS keychain (nil: modelkey.Store). A
// seam: tests have no keychain, and a form-driven caller stores the
// key itself before calling.
StoreKey func(provider, key string) error
// APIKeyKind is what the credential is (policy apiKeyKind): "" (keep what
// the policy has for the same provider, else api), "api" or "subscription".
// A form-driven caller that stored the key itself passes
// policy.CredentialKindOf's answer; an interactive setup derives it from
// the key it stores; a variable-only setup takes --api-key-kind.
APIKeyKind string
BaseURL string
// ChatGPT offers Sign in with ChatGPT for provider openai: nil offers none.
// APIKeyKind chatgpt-plan asks for it without the question.
ChatGPT ChatGPTOffer
// Claude offers ClaudeSignInLabel for provider anthropic: nil offers none.
// APIKeyKind claude-signin asks for it without the question.
Claude ClaudeOffer
// Copilot offers Sign in with GitHub for provider copilot, its one way
// to pay.
Copilot CopilotOffer
// Connect offers Connect your account for OpenRouter, Poe and Hugging Face:
// nil offers none. ConnectAccount asks for it without the question.
Connect ConnectOffer
ConnectAccount bool
// CopilotPlan is the Copilot plan the account is on (policy.CopilotPlans:
// individual, business, enterprise), which names the Copilot API host
// runs reach; "" keeps the policy's, else asks, else individual.
CopilotPlan string
// Yes suppresses prompting entirely: table defaults fill the gaps, the
// same provider's policy fills what it customized, and a custom
// provider with no BaseURL left is an error rather than a question.
Yes bool
}
ModelOpts carries non-interactive answers (flags / desktop form); empty fields are asked for or defaulted.
type Prompter ¶
type Prompter interface {
// Ask shows a prompt with a default and returns the answer ("" keeps
// the default).
Ask(prompt, def string) (string, error)
// AskSecret reads a value without echoing it. An empty answer means
// "leave unset" and is not an error.
AskSecret(prompt string) (string, error)
// Confirm asks a yes/no question with a default.
Confirm(prompt string, def bool) (bool, error)
// Say emits informational text.
Say(text string)
}
Prompter is the interaction surface guided flows run through.
type ProviderDefault ¶
type ProviderDefault struct {
Provider string
Model string
APIKeyEnv string
ProxyAllow []string
// ModelsURL is the provider's models listing; KeyHeader the header
// its key rides in (keyHeaderBearer is "Authorization: Bearer").
ModelsURL string
KeyHeader string
}
ProviderDefault is one row of the provider table.
func DefaultsFor ¶
func DefaultsFor(provider string) *ProviderDefault
DefaultsFor returns the table row for a provider (nil for custom or unknown).
type TTYPrompter ¶
TTYPrompter prompts on Err (stderr, keeping stdout pipeline-clean) and reads answers from In.
func (*TTYPrompter) Ask ¶
func (t *TTYPrompter) Ask(prompt, def string) (string, error)
Ask implements Prompter.
func (*TTYPrompter) AskSecret ¶
func (t *TTYPrompter) AskSecret(prompt string) (string, error)
AskSecret implements Prompter with echo disabled where possible.