modelcheck

package
v0.7.42-dev.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package modelcheck checks a saved model before it is saved: that its provider can be reached with the credential the provider names, and that the model id is one the provider offers. Each kind is asked the way its harness or its vendor answers:

  • a key or a connected account: the provider's models listing must list the id (setup.ListModels, which follows no redirect, takes http or https alone, bounds the time and the size, and scrubs the key from every error);
  • an endpoint of the person's own: the same listing, and its context window as the endpoint reports it;
  • a ChatGPT plan: the plan's own model list;
  • a Copilot plan: Copilot CLI's own model list, with auto, which it never lists, always taken;
  • a Claude subscription: one short message through Claude Code, since it has no list, which counts toward the plan's usage (ClaudeNotice);
  • Agentry credits: a credits session opens, since there is one model.

A check that cannot ask refuses the save with the reason. Plain http off this computer is said and never refused.

Index

Constants

View Source
const (
	// NotOffered: the provider answered, and does not offer the model id.
	NotOffered = "not-offered"
	// CannotCheck: the provider could not be asked, or its answer read; the
	// save may be tried again.
	CannotCheck = "cannot-check"
	// NeedsSignIn: the provider's sign-in is not kept, or no longer works.
	NeedsSignIn = "needs-sign-in"
	// KeyMissing: the provider's key is neither in its variable nor in the
	// keychain.
	KeyMissing = "key-missing"
	// NotEligible: the account's plan does not include this use.
	NotEligible = "not-eligible"
)

The kinds of refusal.

View Source
const ClaudeNotice = "" /* 128-byte string literal not displayed */

ClaudeNotice is said before a Claude subscription's model is checked.

View Source
const CopilotAuto = "auto"

CopilotAuto is the Copilot model that lets GitHub choose: never listed, and the only one Copilot Free has.

Variables

This section is empty.

Functions

func ClaudeArgs

func ClaudeArgs(model string) []string

ClaudeArgs are the check's arguments to Claude Code: a run's own flags, one turn, no tools, no settings and no session kept, and a one-line system prompt that keeps the message short.

Types

type Checkers

type Checkers struct {
	// Key is the key m names, from its variable or the keychain entry of its
	// provider; "" when neither holds one.
	Key func(m policy.Model) (string, error)
	// ListModels is setup.ListModelsToCheck; nil uses it.
	ListModels func(ctx context.Context, provider, baseURL, key string) (*setup.Catalog, error)
	// ProbeContextWindow is setup.ProbeContextWindow; nil asks nothing.
	ProbeContextWindow func(ctx context.Context, baseURL, model, key string) (setup.ContextWindow, error)
	// ChatGPTModels is the kept ChatGPT sign-in's plan models.
	ChatGPTModels func(ctx context.Context) ([]string, error)
	// CopilotModels is Copilot CLI's model list on plan.
	CopilotModels func(ctx context.Context, plan string) ([]string, error)
	// Claude sends Claude Code the check's one message on model.
	Claude func(ctx context.Context, model string) (ClaudeAnswer, error)
	// Credits opens a credits session for m and ends it.
	Credits func(ctx context.Context, m policy.Model) error
}

Checkers are how each kind is asked: the CLI wires the real ones, a test fakes them. A nil checker refuses its kind as one that cannot be checked.

type ClaudeAnswer

type ClaudeAnswer struct {
	// OK: the model answered.
	OK bool
	// Resolved is the model id the answer was made with.
	Resolved string
	// Status is the API's error status, 0 for none.
	Status int
	// NotSignedIn: Claude Code holds no sign-in.
	NotSignedIn bool
	// Message is Claude Code's own words for an error.
	Message string
}

ClaudeAnswer is Claude Code's answer to the check's one message.

func ParseClaudeResult

func ParseClaudeResult(stdout []byte) (ClaudeAnswer, error)

ParseClaudeResult reads Claude Code's JSON result of the check: is_error and api_error_status say what happened (subtype says success even on an error, and the stderr's model warning is not an answer).

type Refusal

type Refusal struct {
	Kind    string
	Reason  string
	Offered []string
}

Refusal is a save the check refused: Kind says why, Reason in words. Offered is what the provider does offer, where it said.

func (*Refusal) Error

func (r *Refusal) Error() string

type Result

type Result struct {
	// Resolved is the model id a Claude alias resolved to at the check: it
	// moves with Claude Code's version, so it is shown beside the alias and
	// never saved in its place.
	Resolved string
	// ContextWindow is the window an endpoint of the person's own reports
	// for the model, with Source where it said so; 0 when it said nothing.
	ContextWindow int64
	Source        string
	// Warning is the plain-http sentence for an endpoint the key reaches
	// unencrypted.
	Warning string
}

Result is a check that passed.

func Check

func Check(ctx context.Context, c Checkers, m policy.Model) (Result, error)

Check checks the model m reads as (policy.Policy.ModelView).

Jump to

Keyboard shortcuts

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