refactor(llm): colocate per-type factories on their namespaces#26799
Merged
Conversation
Drop the LLM.user / LLM.assistant / LLM.toolMessage / LLM.toolCall / LLM.toolResult / LLM.toolDefinition / LLM.toolChoice / LLM.toolChoiceName / LLM.generation / LLM.system / LLM.message / LLM.text aliases from the top-level LLM namespace and route every caller through the Schema-class-colocated forms (Message.user, ToolDefinition.make, ToolChoice.make, ...). The colocated form is already the codebase convention; two ways to construct the same thing is one too many. The top-level LLM namespace stays focused on the request-shaped call API (LLM.request, LLM.generate, LLM.stream, LLM.model, LLM.updateRequest, LLM.generateObject). Adds a Conventions section to packages/llm/AGENTS.md capturing the rule.
00ae041 to
874332f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
packages/llmalready follows a clean pattern everywhere else: per-type factories live on the type's own namespace (Message.user,Message.assistant,Message.tool,Message.make,Message.text,SystemPart.make,ToolDefinition.make,ToolCallPart.make,ToolResultPart.make,ToolChoice.make,ToolChoice.named,GenerationOptions.make,HttpOptions.make,ModelRef.update,LLMRequest.update).src/llm.tswas also re-exporting those same factories at the top level asLLM.user,LLM.assistant,LLM.toolMessage,LLM.toolCall,LLM.toolResult,LLM.toolDefinition,LLM.toolChoice,LLM.toolChoiceName,LLM.generation,LLM.system,LLM.message,LLM.text. Two construction paths to the same value is one too many — this isn't matching the AI SDK (which has no factories at all), it's matching ourselves.The top-level
LLMnamespace stays focused on the request-shaped call API:LLM.request,LLM.generate,LLM.stream,LLM.model,LLM.limits,LLM.stepCountIs,LLM.requestInput,LLM.updateRequest,LLM.generateObject.What changed
packages/llm/src/llm.ts:text,system,message,user,assistant,toolDefinition,toolCall,toolResult,toolMessage,toolChoiceName,toolChoice,generation.LLM.request's internal use of those aliases to call the canonical forms directly (Message.make,Message.user,ToolDefinition.make,ToolChoice.make,GenerationOptions.make).packages/llm/test/**to the colocated form (one provider test file plus the sharedrecorded-scenarios.tsand the unit tests).packages/llm/AGENTS.mdto match.packages/llm/AGENTS.mddocumenting the rule.No call sites existed outside
packages/llm/.Migration
LLM.user(x)Message.user(x)LLM.assistant(x)Message.assistant(x)LLM.toolMessage(x)Message.tool(x)LLM.message(x)Message.make(x)LLM.text(x)Message.text(x)LLM.system(x)SystemPart.make(x)LLM.toolDefinition(x)ToolDefinition.make(x)LLM.toolCall(x)ToolCallPart.make(x)LLM.toolResult(x)ToolResultPart.make(x)LLM.toolChoice(x)ToolChoice.make(x)LLM.toolChoiceName(x)ToolChoice.named(x)LLM.generation(x)GenerationOptions.make(x)All types are re-exported from
@opencode-ai/llm's barrel viaexport * from "./schema".Test plan
bun run --cwd packages/llm typecheck— cleanbun run --cwd packages/llm test— 174 pass / 31 skip / 0 failbun run --cwd packages/opencode typecheck— cleanbun run --cwd packages/opencode test— only pre-existing unrelated failures (Worktree > list > uses parent folder name...andsession.created event...); neither test referencesLLM.*