{"modulePath":"github.com/Agent-Field/codeaf","version":"v0.8.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package modelsource\n\nPackage modelsource describes the places models come from without reading the machine or opening the network. Runtime facts are handed in by config.\n\n## Constants\n\n```go\nconst ChatCompletionsPath = \"/chat/\" + \"completions\"\n```\nChatCompletionsPath is composed so the repository's model-send-path law continues to reserve the literal endpoint for internal/provider. This package only describes the path; internal/config performs the probe.\n\n```go\nconst CodexName = \"Codex\"\n```\nCodexName is the Codex service's display name — its [Source.Name](#Source.Name), the one every surface calls it by. It is named once because it is ALSO the endpoint a Codex call row names ([Source.ServedAs](#Source.ServedAs)): the ChatGPT backend names no server of its own, and the row reads \\`\"endpoint\":\"Codex\"\\` the way an OpenRouter row reads the upstream that served it (#1391).\n\n```go\nconst CustomID = \"custom\"\n```\nCustomID is the identity of the vendored custom service row. The FIRST custom connection a profile persists keeps this id, so profiles and tests written before custom connections could multiply stay byte-identical; later instances mint CustomID-\\\u003cslug\u003e ids and are told apart by IsCustomID.\n\n```go\nconst DefaultID = \"openrouter\"\n```\nDefaultID is the stable identity of the service an unqualified model uses. It is named once because persisted rows, qualification, and every surface must agree on which member of a Set is the compatibility default.\n\n```go\nconst ProbeTimeout = 10 * time.Second\n```\nProbeTimeout is the watching-person ceiling shared by every vendored probe.\n\n## Functions\n\n```go\nfunc AddressHost(address string) string\n```\nAddressHost is the host a base URL is at, and the one step every caller takes before [SourceSlug](#SourceSlug): the name a connection defaults to is the slug of its address's host. It lives beside SourceSlug because the two halves of that one rule were spelled three times — in the chat surface's draft, in config's mint, and inline in the surface's address step — and three copies of a defaulting rule drift into three different names for one host.\n\nAN ADDRESS THE SURFACE ALREADY VALIDATED IS THE NORMAL CASE; an unparseable one, or one with no host at all, falls back to the raw trimmed text, which is what lets a bare host typed with no scheme still answer a usable name (url.Parse reads mybox.local:9001 as a scheme and an opaque path, and its Hostname is empty).\n\n```go\nfunc Collides(written string, taken []string, authors []string) (suggestion string, collides bool)\n```\nCollision says why a proposed Written may not be used, and what to use instead. Author segments arrive as an argument because this package may not reach internal/catalog.\n\n```go\nfunc IDWord(written string) string\n```\nIDWord turns a written connection name into the plain word a minted custom id carries: lowercase, every run of characters outside a-z and 0-9 one dash, edge dashes trimmed, and connection when nothing remains. Routing keys on the written name, so this is persistence vocabulary only.\n\n```go\nfunc IsCustomID(id string) bool\n```\nIsCustomID reports whether a persisted row id names a custom connection: the vendored row itself, or one of the instances minted after it. One predicate because every surface that used to compare against the literal must treat the instances as the same KIND of service, never as a second vendor. It is case-insensitive the way Set.ByID is, because both read ids a person's profile holds.\n\n```go\nfunc LooksLikeAPIKey(key string) bool\n```\nLooksLikeAPIKey is the shared OpenAI-shaped key rule. Config delegates its first-run check here so the DeepSeek row and the default service cannot drift.\n\n```go\nfunc SourceSlug(host string) string\n```\nSourceSlug turns a base URL's host into the short word a person reads for the connection: api.deepseek.com answers deepseek, mybox.local answers mybox. It moved here from the chat surface so config and both surfaces derive one name from one host. AN ADDRESS THAT IS AN IP LITERAL IS TAKEN WHOLE: 127.0.0.1 answers 127-0-0-1, not the 0 the old derivation read off its last dot-separated label, and an IPv6 literal keeps its groups in order (::1 answers ipv6-1, fe80::1 answers fe80-1) — brackets are stripped defensively, a zone id is cut first (fe80::1%eth0 answers fe80-1, because the zone names the interface and not the host), :: and runs of mapped dashes collapse to one, and a colon-host that reduces to digits alone carries the ipv6- prefix so ::1 does not read as \"1\"; a hex group like fe80 keeps no prefix, because hex digits a-f are letters. A host that yields nothing answers CustomID, which is what the surface it moved from answered and keeps that path byte-identical.\n\n```go\nfunc Split(model string, written []string) (segment, bare string)\n```\nSplit applies the service-prefix grammar to an already level-less model id. A first segment that is not a connected Written remains part of the default service's model id.\n\n## Types\n\n```go\ntype Connected struct {\n\tSource  Source\n\tKey     string\n\tAddress string\n\t// Home is the profile directory whose rotating credentials belong to this\n\t// connection. Empty keeps the ordinary codeaf state root.\n\tHome string\n\t// Door is the bound billing road. It is zero for a one-door service, so all\n\t// older status and runtime behaviour remains byte-identical.\n\tDoor Door\n\t// Overflow is the metered road a bound plan may use only when the person has\n\t// explicitly chosen it. Nil means there is no such road.\n\tOverflow   *Door\n\tPlanPaused string\n}\n```\nConnected is one service with the two facts only a caller that may read the machine can fill in: the key that reaches it and the address it is at.\n\n```go\nfunc (c Connected) HasCredentials() bool\n```\nHasCredentials reports whether the connection can authenticate, or explicitly accepts anonymous requests. A public catalog alone never connects an account.\n\n```go\nfunc (c Connected) Qualify(bare string) string\n```\nQualify spells a model the way a person selects it. Default-service and unnamed rows remain unqualified for compatibility.\n\n```go\ntype Door struct {\n\tID      string\n\tName    string\n\tAddress string\n\t// Metered marks the road whose use can create a charge outside a fixed\n\t// plan. The fact lives on the door because an ID is persistence vocabulary,\n\t// not a billing policy for callers to reinterpret.\n\tMetered bool\n\t// KeyPrefix is a shortcut hint for ordering, never a claim. Every door is\n\t// still tried because a vendor may change its key convention.\n\tKeyPrefix string\n\t// Models is the catalog to trust when this door's own listing is wider than\n\t// the models the billing product actually serves. Empty believes the listing.\n\tModels []string\n\t// Observed says somebody has watched this door answer. It never gates use.\n\tObserved bool\n}\n```\nDoor is one way of paying for the same vendor's models: a base URL, and the word a person reads for it. ORDER IS THE POLICY — the subsidised door is first, because a person who has paid a subscription meant to use it.\n\n```go\ntype Listing int\n```\nListing is the vendored expectation for whether \\\u003cbase\u003e/models exists on this service. It is a hint, never proof: connect always asks the service first, because silence in a documentation survey does not prove an endpoint absent.\n\n```go\nconst (\n\t// ListingNone is the first-try hint for a service no listing has been\n\t// observed on. It does NOT foreclose one: connect asks anyway, and a\n\t// service that answers is treated as a listing service from that moment.\n\tListingNone Listing = iota\n\t// ListingModels is the first-try hint for a service whose model list is\n\t// documented or has been seen to answer.\n\tListingModels\n)\n```\n\n```go\ntype Outcome struct {\n\tKind       OutcomeKind\n\tVendorSaid string\n\tModels     int\n\t// ModelIDs are the non-empty ids carried by an answered listing. Keeping\n\t// them lets the surface retain the list it already paid for instead of\n\t// making a second catalog-shaped response the only road to the picker.\n\tModelIDs []string\n\tListed   bool\n\t// Refreshed distinguishes an answered live list from the vendored fallback.\n\t// It is meaningful only when Listed is true.\n\tRefreshed bool\n\tDoor      Door\n\t// PlanPaused records that the selected door proved the plan exists but its\n\t// current usage window is spent. PlanReset is the vendor's readable reset\n\t// time when it supplied one, and Overflow is the separately billed road the\n\t// person may explicitly choose later.\n\tPlanPaused bool\n\tPlanReset  string\n\tOverflow   *Door\n}\n```\nOutcome is what a connect attempt learned, in facts rather than a sentence: the surface owns the words and this package owns the truth.\n\n```go\ntype OutcomeKind int\n```\nOutcomeKind distinguishes the facts learned by a connect attempt.\n\n```go\nconst (\n\tOutcomeConnected OutcomeKind = iota\n\tOutcomeRefused\n\tOutcomeAccountCannotPay\n\tOutcomeUnanswered\n\tOutcomeWrongShape\n)\n```\n\n```go\ntype Probe struct {\n\tAddress string\n\tMethod  string\n\tBody    string\n\tAccepts []int\n\tTimeout time.Duration\n}\n```\nProbe is the cheap read that proves a key works. It is a description only; internal/config performs the request beside the key it needs.\n\n```go\ntype Region struct {\n\tID      string\n\tName    string\n\tAddress string\n}\n```\nRegion is one of a vendor's separate hosts, which are separate accounts with separate keys.\n\n```go\ntype Set struct {\n\t// contains filtered or unexported fields\n}\n```\nSet is the services this profile talks to, in the person's own order, the default service first and always present.\n\n```go\nfunc NewSet(services ...Connected) Set\n```\nNewSet keeps services in the order given. The first service is the default.\n\n```go\nfunc (s Set) All() []Connected\n```\nAll returns a copy in the person's order, with the default first.\n\n```go\nfunc (s Set) ByID(id string) (Connected, bool)\n```\nByID finds a service by its stable persisted identity.\n\n```go\nfunc (s Set) Default() Connected\n```\nDefault returns the first service, or the zero value for an empty set.\n\n```go\nfunc (s Set) Empty() bool\n```\nEmpty reports whether the set names no service at all.\n\n```go\nfunc (s Set) For(model string) (Connected, string)\n```\nFor answers the service that serves model and the bare model id to send. Thinking levels are removed by internal/config before this pure package is called because internal/roles reaches process state through os.\n\n```go\nfunc (s Set) OrDefault(key, address string) Set\n```\nOrDefault makes a scalar account one default service. It preserves a set already supplied by a source-aware caller.\n\n```go\nfunc (s Set) WithDefaultKey(key string) Set\n```\nWithDefaultKey returns the same ordered set with its default member's key replaced. It is the live first-run handoff: callers may update the account without constructing a Connected value and duplicating source resolution.\n\n```go\nfunc (s Set) Written() []string\n```\nWritten returns every segment a connected service claims.\n\n```go\ntype Source struct {\n\tID      string\n\tWritten string\n\tName    string\n\tAddress string\n\tDoors   []Door\n\tRegions []Region\n\tKeyEnv  string\n\t// KeyShape validates a supplied key. Nil accepts any non-blank value;\n\t// KeyOptional is the only way a service accepts blank.\n\tKeyShape func(string) bool\n\t// KeyOptional is true only when this service explicitly accepts no key.\n\t// It is a fact about the service, never inferred from a validation function.\n\tKeyOptional bool\n\tProbe       Probe\n\tListing     Listing\n\tProbeModel  string\n\t// A ROW'S PREFERRED MUST BE ANSWERABLE ON EVERY DOOR IT CAN BIND. The door\n\t// is chosen by what the key proves, so this is the vendor's best model both\n\t// its subscription and metered roads serve, not simply its flagship.\n\tPreferred string\n\t// ServedAs is the endpoint a transcript's call row names for this service's\n\t// answers when an answer names no machine of its own; empty for every\n\t// service that has not declared one, whose silent answers name nothing.\n\t//\n\t// IT IS ATTRIBUTION FOR THE RECORD AND NOTHING ELSE. A name that arrived on\n\t// an ANSWER is evidence internal/provider learns from — a lane to rate, a\n\t// machine to pin, a router account to clear — and it is drawn beside the\n\t// model on the live screen. A service whose backend IS its one machine has\n\t// no lane to learn and no second machine to draw, so its name is declared\n\t// here and written only into the call row (internal/session's\n\t// [Agent.attributedEndpoint]), never put on the answer (#1391).\n\tServedAs string\n}\n```\nSource is one place models come from: an address, a key description, and the facts about what lives there. IT IS CONFIGURATION AND NEVER A GUESS — nothing here reads a hostname to decide anything, because a router is recognised by what it answers.\n\n```go\nfunc DefaultSource(address string) Source\n```\nDefaultSource is the synthesised OpenRouter row. The address is handed in because this package may not read the machine.\n\n```go\nfunc Vendored() []Source\n```\nVendored returns the service descriptions shipped by this phase.\n\n```go\nfunc (s Source) DoorProbe() Probe\n```\nDoorProbe is the one-token request that proves which billing road this key can use. A multi-door row must name a current model rather than guess at the call site.\n\n```go\nfunc (s Source) FallbackProbe() Probe\n```\nFallbackProbe describes the one-token check used only after /models proves absent. An empty ProbeModel deliberately means believe the key until its first real call; guessing a current billable model is worse than deferring proof.\n\n```go\nfunc (s Source) MeteredDoor() (Door, bool)\n```\nMeteredDoor returns the one separately billed road described by this service. A missing answer means the service has no honest overflow road.\n\n```go\nfunc (s Source) OrderedDoors(key string) []Door\n```\nOrderedDoors returns every billing road exactly once. A matching prefix moves its likely door to the front and never removes any alternative.\n\n```go\nfunc (s Source) PreferredModel(door Door, listed []string) string\n```\nPreferredModel answers the model a newly connected service should put the conversation on. THE ORDER IS THE POLICY: a door's documented catalog is narrower than the vendor row, then a row preference is trusted only when the service did not list models or listed that id, and only then may the first listed id stand in. Empty means there is no honest move to make.\n\n","path":"github.com/Agent-Field/codeaf/internal/modelsource","name":"modelsource","synopsis":"Package modelsource describes the places models come from without reading the machine or opening the network.","isRedistributable":true}
