feat(ai-harness): providerKeys() plugin lets each user connect their own model provider key #1765
feat/harness-core fromrefs/pull/1765/head·merged by AlemTuzlak View on GitHubWith this PR, users of a harness that you ship can connect their own model provider key in the app, with no .env file. providerKeys({ providers }) from @tanstack/ai-harness/plugins adds /connect:<id>, /disconnect:<id>, and /keys. The key is saved for the user who runs the command, and a keyedAdapter(...) for that provider uses it on the next turn.
This PR targets the first-party plugins PR #1759 (feat/harness-plugins), which targets the core harness PR #1755 (feat/harness-core). It is split out of #1555.
🎯 Changes#
Source (packages/ai-harness):
src/first-party/provider-keys.ts: theproviderKeysplugin, ported from #1555./connect:<id>runs the provider'ssignInwhen it has one. Else it openskeyUrl(through aharness.auth_requiredevent) and asks for the key as asecretquestion./keysand the plugin state show where each key comes from: a saved key (masked), the env var, or no key.
src/first-party/index.tsexportsproviderKeysand the typesKeyProvider,ProviderKeyStatus, andProviderKeysState.
Changes from #1555:
- Tests: the "judges the goal with the saved key" case needs
goal(), which is in the sibling PRfeat/harness-goal. It is left out here. The session view case readssession.snapshot().pendingQuestionsinstead of a view. - Docs: the samples call
session.command('connect:openai')and answer the question withsession.answer. No CLI, client, or view. The Anthropic token section usescreateAnthropicChat, which picks the auth mode from the token. Theoauth: trueflag of #1555 is not onmain. - From the code review:
- A cancelled
/connect:<id>stops at once, and a late answer saves nothing (new unit test). - The key question and the key page go to the session of the user who runs the command, not the setup session.
- The plugin state types are exported.
- The E2E route fails fast when no question appears.
- A cancelled
Changes from the #1779 merge (feat/harness-core and feat/harness-plugins now take one object):
- Merged
feat/harness-plugins(with #1779) in. Onlydocs/config.jsonhad a conflict: it keeps both sides, with the newerupdatedAt.overview.mdmerged with no conflict: it has the #1779 step 3 and this branch's link. /connect:<id>saves the key withcredentials.set({ id, credential }). The tests and the E2E route use the object shapes of the credential store andsession.answer.- Keys are scrubbed from errors. The plugin reads and saves keys only through the session's credential access, so each key goes into the session's
secretsset. A new unit test checks that a key that/connectsaved shows as[redacted]in a published error. provider-keys.mdanswers the key question withsession.onEvent('CUSTOM', ...), not with a loop oversession.events().
Not changed (review findings left as they are in #1555):
- The plugin state shows the key status of the user who ran the last command. In a thread that several users share, other clients see that status. A state per user needs a design decision.
/disconnect:<id>says "Disconnected" also when a tenant key or the env var still gives a key./keysshows the real source.- The
/keyshint saysRun /connect <id>., the same text as the coreAuthRequiredError.
Docs. New page docs/harness/provider-keys.md ("Connect model providers"), a link from docs/harness/overview.md, and docs/config.json entries (addedAt 2026-10-13, updatedAt 2026-10-14 for the changed pages). Readers: agent builders who ship a harness to users. Tone: plain second person, short sentences.
Changeset. @tanstack/ai-harness minor.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm run test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
- Docs: I updated
docs/for this change, or this change is not user-facing. - Changeset: I added a changeset (
pnpm changeset), or this PR does not change a published package.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Testing#
Commands run. After the #1779 merge, all of these passed:
nx run-many --targets=test:types,test:oxlint,test:lib:@tanstack/ai-harness: 64 test files, 890 tests.nx run-many --targets=test:types --projects='examples/**,testing/**': 27 projects.pnpm test:docs,kiira check docs/harness(28 snippets),pnpm test:knip,pnpm test:sherif.
Not run: the full pnpm test:pr and the E2E suite. CI runs them.
Manual test.
- Run
pnpm --filter @tanstack/ai-e2e test:e2e --grep "providerKeys". - The route runs
/connect:openai, answers the secret question with a key, then sends a prompt. - The spec checks that the question was secret, that the result shows the key masked, and that the next turn built the OpenAI adapter with that key. (aimock's journal redacts the
authorizationheader, so the route records the key that the adapter factory got.)
How this PR makes testing easy.
packages/ai-harness/tests/provider-keys.test.tsruns the plugin, keyed adapters,ctx.keysin agents, and the key safety checks in a real harness host.- E2E: the
provider-keysscenario intesting/e2e/src/routes/api.harness-first-party.tsandtests/harness-first-party.spec.ts.
Risk / rollback#
Low. The plugin is opt-in. It writes keys only to the credential store of the host. Revert the PR to remove it.
Public API change#
Before: no plugin to connect a provider key.
After
import { keyedAdapter } from '@tanstack/ai'
import { createOpenaiChat } from '@tanstack/ai-openai'
import { openaiByok } from '@tanstack/ai-openai/byok'
import { providerKeys } from '@tanstack/ai-harness/plugins'
defineHarness({
name: 'acme/assistant',
adapter: keyedAdapter(openaiByok, (key) => createOpenaiChat('gpt-6.1-sol', key)),
plugins: () => [providerKeys({ providers: [openaiByok] })],
})
await session.command('connect:openai')
🤖 Generated with Claude Code
- 1
Important
Review skipped#
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
-
- Configuration used: Repository: TanStack/ai/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3ac014a9-cebf-4c97-92ae-c32931617e1b
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit 5fb4f24275fd6c4733bfc11a2dbb0a06cfabe877
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 3s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-15 16:51:18UTCCoverage#
✅ Coverage held across 29 compared package(s).
Each package is measured twice in this job — on this PR and on its merge-base with
main— and compared. A metric fails only when it is at or above 60% on the merge-base and under 60% on this PR. Other drops are listed but do not fail. Packages your PR doesn't affect are not measured and not listed.package statements branches functions lines ai-acp 82.32% (0.00) 71.27% (0.00) 77.08% (0.00) 83.97% (0.00) ok ai-claude-code 88.93% (0.00) 76.88% (0.00) 86.88% (0.00) 90.40% (0.00) ok ai-code-mode 92.71% (0.00) 85.66% (0.00) 89.06% (0.00) 93.51% (0.00) ok ai-code-mode-snippets 87.13% (0.00) 75.67% (0.00) 91.11% (0.00) 88.39% (0.00) ok ai-codex 94.55% (0.00) 85.10% (0.00) 89.28% (0.00) 95.56% (0.00) ok ai-durable-stream 86.70% (0.00) 82.25% (0.00) 92.30% (0.00) 88.72% (0.00) ok ai-grok-build 79.19% (0.00) 63.56% (0.00) 77.39% (0.00) 81.02% (0.00) ok ai-harness 92.96% (+0.10) 87.54% (+0.14) 93.36% (+0.06) 94.52% (+0.10) ok ai-isolate-cloudflare 94.11% (0.00) 70.66% (0.00) 100.00% (0.00) 93.96% (0.00) ok ai-isolate-daytona 90.25% (0.00) 80.59% (0.00) 100.00% (0.00) 90.15% (0.00) ok ai-isolate-e2b 92.11% (0.00) 82.22% (+0.74) 97.36% (0.00) 95.05% (0.00) ok ai-isolate-node 84.00% (0.00) 43.39% (0.00) 100.00% (0.00) 83.78% (0.00) ok ai-isolate-quickjs 89.07% (0.00) 76.41% (0.00) 90.90% (0.00) 90.30% (0.00) ok ai-isolate-quickjs-bun 7.76% (0.00) 8.08% (0.00) 5.00% (0.00) 8.33% (0.00) ok ai-mcp 96.71% (0.00) 91.77% (0.00) 96.86% (0.00) 98.66% (0.00) ok ai-opencode 68.77% (0.00) 60.82% (0.00) 64.04% (0.00) 70.78% (0.00) ok ai-sandbox 77.45% (0.00) 82.80% (0.00) 74.47% (0.00) 77.97% (0.00) ok ai-sandbox-blaxel 87.64% (0.00) 77.18% (0.00) 82.26% (0.00) 89.71% (0.00) ok ai-sandbox-boxd 95.86% (0.00) 87.12% (0.00) 95.31% (0.00) 98.17% (0.00) ok ai-sandbox-cloudflare 67.91% (0.00) 57.47% (0.00) 71.79% (0.00) 69.62% (0.00) ok ai-sandbox-daytona 82.70% (0.00) 81.89% (0.00) 67.14% (0.00) 85.18% (0.00) ok ai-sandbox-docker 80.15% (0.00) 71.49% (0.00) 77.38% (0.00) 82.13% (0.00) ok ai-sandbox-e2b 94.42% (0.00) 88.97% (0.00) 93.24% (0.00) 98.63% (0.00) ok ai-sandbox-local-process 68.00% (0.00) 53.59% (0.00) 75.86% (0.00) 68.88% (0.00) ok ai-sandbox-railway 94.75% (0.00) 92.68% (0.00) 90.90% (0.00) 97.59% (0.00) ok ai-sandbox-sprites 73.23% (0.00) 59.70% (0.00) 73.83% (0.00) 76.17% (0.00) ok ai-sandbox-upstash-box 94.82% (0.00) 91.52% (0.00) 91.04% (0.00) 97.76% (0.00) ok ai-sandbox-vercel 44.67% (0.00) 38.18% (0.00) 35.18% (0.00) 45.76% (0.00) ok ai-skills 83.39% (0.00) 68.53% (0.00) 87.36% (0.00) 85.48% (0.00) ok @tanstack/ai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@1765@tanstack/ai-acp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@1765@tanstack/ai-angular
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@1765@tanstack/ai-anthropic
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@1765@tanstack/ai-bedrock
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@1765@tanstack/ai-byteplus
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@1765@tanstack/ai-claude-code
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@1765@tanstack/ai-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@1765@tanstack/ai-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@1765@tanstack/ai-code-mode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@1765@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@1765@tanstack/ai-codex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@1765@tanstack/ai-cohere
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@1765@tanstack/ai-compaction
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@1765@tanstack/ai-devtools-core
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@1765@tanstack/ai-durable-stream
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@1765@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@1765@tanstack/ai-event-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@1765@tanstack/ai-fal
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@1765@tanstack/ai-gemini
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@1765@tanstack/ai-grok
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@1765@tanstack/ai-grok-build
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@1765@tanstack/ai-groq
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@1765@tanstack/ai-harness
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@1765@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@1765@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@1765@tanstack/ai-isolate-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-e2b@1765@tanstack/ai-isolate-node
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@1765@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@1765@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@1765@tanstack/ai-llmgateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@1765@tanstack/ai-lovable
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@1765@tanstack/ai-mcp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@1765@tanstack/ai-memory
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@1765@tanstack/ai-mistral
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@1765@tanstack/ai-octane
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@1765@tanstack/ai-ollama
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@1765@tanstack/ai-ollaya
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollaya@1765@tanstack/ai-openai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@1765@tanstack/ai-opencode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@1765@tanstack/ai-openrouter
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@1765@tanstack/ai-perplexity
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@1765@tanstack/ai-persistence
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@1765@tanstack/ai-preact
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@1765@tanstack/ai-react
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@1765@tanstack/ai-react-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@1765@tanstack/ai-reactor
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@1765@tanstack/ai-remix
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@1765@tanstack/ai-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@1765@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@1765@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@1765@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@1765@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@1765@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@1765@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@1765@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@1765@tanstack/ai-sandbox-railway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-railway@1765@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@1765@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@1765@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@1765@tanstack/ai-skills
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@1765@tanstack/ai-solid
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@1765@tanstack/ai-solid-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@1765@tanstack/ai-svelte
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@1765@tanstack/ai-typesafe
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@1765@tanstack/ai-utils
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@1765@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@1765@tanstack/ai-vertex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@1765@tanstack/ai-vue
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@1765@tanstack/ai-vue-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@1765@tanstack/ai-worldlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@1765@tanstack/openai-base
npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@1765@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@1765@tanstack/react-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@1765@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@1765@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@1765commit:
5fb4f24github-actions[bot](GitHub profile, opens in a new tab) assignedtombeckenham
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
jherr approved these changes
I love, love, love that this is a plugin.
github-actions[bot](GitHub profile, opens in a new tab) added labelsready-to-merge
@copilot please fix the merge conflicts in this pull request.
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
Diff Package Supply Chain
SecurityVulnerability Quality Maintenance License npm/@tanstack/solid-store@0.8.0 ⏵ 0.11.2 +3
+3
-1
npm/@cfworker/json-schema@4.1.1 AlemTuzlak merged thisea75cbb
AlemTuzlak closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: fb39ded9f2ed4af0792e9bc16db02b5b71608bf5
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 56 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR