feat: shared @bragdoc/ai provider package (BYOK 1/4)#406
Open
edspencer wants to merge 3 commits into
Open
Conversation
Introduce packages/ai (@bragdoc/ai), a shared multi-provider LLM
configuration and factory package consumed by both the CLI and (in
upcoming BYOK work) the web app. It contains the LLMProvider union,
per-provider config interfaces, LLMConfig, DEFAULT_MODELS,
PROVIDER_OPTIONS (names + signup URLs), createLLMFromConfig(),
getLLMDisplayName() and isLLMConfigured(), all moved from the CLI.
The public API is zod-free (CLI is on zod v4, web on zod v3), builds
to dist/ with declarations via tsc, and is published publicly so the
npm-published CLI can depend on it via workspace:*.
The Google provider path no longer mutates
process.env.GOOGLE_GENERATIVE_AI_API_KEY: it now uses
createGoogleGenerativeAI({ apiKey }), matching the explicit-instance
pattern already used for OpenAI, Anthropic and Ollama. This makes the
factory safe for concurrent server-side use while preserving the
config-or-environment-variable key fallback the CLI relies on.
New verifyLLMConfig(config) instantiates the configured model and runs
a tiny generateText probe (maxOutputTokens 8, 15s AbortSignal timeout),
returning { ok: true } or { ok: false, error } with a human-readable
provider error message. It never throws, so the upcoming settings
"verify & save" flow can surface failures directly.
The CLI now imports all of the above from @bragdoc/ai:
createLLMFromConfig/getLLMDisplayName take an LLMConfig (call sites
pass config.llm), config/types.ts re-exports the shared types, and the
duplicated provider/setup code is deleted. lib/extraction.ts no longer
hard-requires OPENAI_API_KEY when a different provider is configured;
missing credentials now fail at model creation with a provider-specific
message.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Braintrust eval reportNo experiments to report |
The cli-test job installed dependencies only inside packages/cli, so the new @bragdoc/ai workspace dependency was never built and its dist/ output was missing, failing every suite that imports it. Install at the workspace root and build the shared package first. The integration job similarly built only the CLI package; use pnpm's dependency-inclusive filter so workspace deps build in topological order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Keeps dist/ output fresh during turbo dev so the web app's compiled workspace dependency never goes stale while developing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 7, 2026
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.
Part 1 of 4 of the BYOK stack (#405). Base:
main.Extracts the CLI's multi-provider LLM factory into a new shared
packages/ai(@bragdoc/ai) package so the web app (PRs 2–3) can reuse it for per-user keys.What's here
packages/ai—LLMProviderunion, per-provider config interfaces,LLMConfig,DEFAULT_MODELS,PROVIDER_OPTIONS(names + signup URLs),createLLMFromConfig(),getLLMDisplayName(),isLLMConfigured(). Zod-free public surface (CLI is zod v4, web zod v3). tsc build todist/with declarations; published as public so the npm-published CLI can depend on it (workspace:*→^0.1.0at publish time).process.env.GOOGLE_GENERATIVE_AI_API_KEY(unsafe under server concurrency); now usescreateGoogleGenerativeAI({ apiKey }). All providers use explicit instances; env-key fallback semantics preserved for the CLI.verifyLLMConfig(config)— tinygenerateTextprobe with 15s timeout, returns{ ok } | { ok: false, error }; used by the settings "Verify & Save" flow in PR 2.@bragdoc/ai; duplicated code deleted.config/types.tsre-exports the shared types so external consumers are unchanged. Also fixeslib/extraction.tshard-requiringOPENAI_API_KEYeven when another provider is configured.Verification
pnpm build: 6/6 tasks pass (@bragdoc/aibuilds before@bragdoc/cli)pnpm test: green (web: 330 passed)Closes nothing on its own — see #405 for the full plan.
🤖 Generated with Claude Code