feat(v2): add Parse() function and extensible Registry for model string resolution
CI / Root Module (pull_request) Failing after 3s
CI / Lint (pull_request) Failing after 3s
CI / V2 Module (pull_request) Successful in 1m25s

Introduces llm.Parse(spec) backed by an extensible Registry that resolves
model strings like "openai/gpt-4o", aliases like "fast", and named targets
like "m5/qwen3:30b" (via LLM_M5 env var DSNs) into ready-to-use *Model
objects. Extension points: RegisterProvider, RegisterAlias, RegisterResolver.
Adds Foreman constructor and sentinel errors ErrAliasLoop, ErrUnknownProvider,
ErrInvalidDSN.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 22:58:14 -04:00
parent 5d4c4f91af
commit 4522310f5a
6 changed files with 1084 additions and 11 deletions
+12
View File
@@ -17,4 +17,16 @@ var (
// ErrNoStructuredOutput is returned when the model did not return a structured output tool call.
ErrNoStructuredOutput = errors.New("model did not return structured output")
// ErrAliasLoop is returned when alias resolution exceeds the maximum depth (10),
// indicating a cycle such as "a" → "b" → "a".
ErrAliasLoop = errors.New("alias resolution loop detected (depth > 10)")
// ErrUnknownProvider is returned when a spec references a provider name that
// is not registered and has no corresponding LLM_X environment variable.
ErrUnknownProvider = errors.New("unknown provider")
// ErrInvalidDSN is returned when a DSN string (from an LLM_X env var) cannot
// be parsed. Expected format: scheme://[token@]host[/path].
ErrInvalidDSN = errors.New("invalid DSN")
)