Skip to content

feat(runtime-core): export getAgentApiKeyEnvVar for agent provider API keys - #569

Merged
tkislan merged 4 commits into
mainfrom
feat/runtime-core-agent-api-key-env-var
Oct 12, 2026
Merged

tkislan merged 4 commits into
mainfrom
feat/runtime-core-agent-api-key-env-var

Conversation

@tkislan

@tkislan tkislan commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

resolveAgentModel falls back to a provider-specific environment variable (OPENAI_API_KEY, ANTHROPIC_API_KEY, DEEPNOTE_AGENT_API_KEY) when apiKey is omitted. Those names lived only in the private PROVIDER_ENV table, so callers that supply apiKey themselves couldn't apply the same fallback or name the variable in their own messages without copying the strings.

This exports getAgentApiKeyEnvVar(providerId) from the @deepnote/runtime-core package root. It reads PROVIDER_ENV[providerId].apiKeyVar, so each name is still defined in one place.

  • resolveAgentModel / executeAgentBlock behavior and error messages are unchanged.
  • Base URL / model variable names, default models, and the provider ID list are intentionally not exported.
  • No CLI, .deepnote format, docs/, or skills/ changes: library API addition only.

Test plan

  • New test: for each provider, a key set under the variable getAgentApiKeyEnvVar names is accepted by resolveAgentModel. Confirmed it fails if the getter returns the wrong field or if resolveAgentModel reads a different variable
  • pnpm exec vitest run packages/runtime-core — 361 passed
  • pnpm typecheck
  • pnpm biome:check — no new warnings (8 pre-existing on main)
  • pnpm test has one failure, packages/cli/src/commands/run.test.ts › creates ExecutionEngine with correct config, which also fails on clean main

🤖 Generated with Claude Code

https://claude.ai/code/session_01K3EZUwBoLd7dWhp6Y5QwAr

Summary by CodeRabbit

  • New Features
    • Added a way to look up the environment variable associated with an agent provider’s API key.
    • Updated the agent provider documentation with guidance for callers supplying API keys directly.
  • Tests
    • Added coverage confirming each provider can be resolved using its configured API key and base URL.

…I keys

Callers that pass `apiKey` to the agent block themselves cannot apply the
same environment-variable fallback as `resolveAgentModel` without copying
the variable names. Expose the name from the existing PROVIDER_ENV table so
it stays defined in one place.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3EZUwBoLd7dWhp6Y5QwAr
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.44%. Comparing base (fa4c492) to head (189a3c0).

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #569    +/-   ##
========================================
  Coverage   90.44%   90.44%            
========================================
  Files         216      216            
  Lines       12584    12586     +2     
  Branches     3636     3529   -107     
========================================
+ Hits        11382    11384     +2     
  Misses       1199     1199            
  Partials        3        3            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

tkislan and others added 2 commits October 8, 2026 13:13
…entModel reads

The literal-mapping test restated PROVIDER_ENV and would stay green if
resolveAgentModel stopped reading the variable the getter names. Assert
that the named variable is the one resolveAgentModel falls back to.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3EZUwBoLd7dWhp6Y5QwAr
…he list

Export the constant from the module (not the package root) so a newly added
provider is covered by the getAgentApiKeyEnvVar fallback test automatically.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3EZUwBoLd7dWhp6Y5QwAr
@tkislan

tkislan commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 4ddffba9-0fe2-4983-b9be-555aa6187198

📥 Commits

Reviewing files that changed from the base of the PR and between 20f70e7 and 189a3c0.


You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 65234522-0341-4e88-8b41-b54ac035b623

📥 Commits

Reviewing files that changed from the base of the PR and between aa891df and 20f70e7.


📒 Files selected for processing (4)
  • packages/runtime-core/README.md
  • packages/runtime-core/src/agent-provider.test.ts
  • packages/runtime-core/src/agent-provider.ts
  • packages/runtime-core/src/index.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.



📝 Walkthrough

Walkthrough

The runtime core now exports AGENT_PROVIDER_IDS and getAgentApiKeyEnvVar. The function returns the configured API-key environment-variable name for a provider ID. Tests check resolution for each provider when its API-key variable and DEEPNOTE_AGENT_BASE_URL are set. The README explains how callers can use parseAgentModel and getAgentApiKeyEnvVar when supplying an API key.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: jamesbhobbs


Merge Risk: ⚪ Minimal · up to 20f70

The change adds a documented provider environment-variable lookup with per-provider coverage. No actionable merge risk is identified; normal checks remain appropriate.

🚥 Pre-merge checks | ✅ 4 | ❌ 1 | ❓ 1

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Updates Docs ❓ Inconclusive The OSS documentation was updated in packages/runtime-core/README.md with guidance for getAgentApiKeyEnvVar(parseAgentModel(spec).providerId). The linked deepnote/deepnote-internal repository an… Please verify or add the feature entry in the deepnote/deepnote-internal landing-page roadmap.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: exporting getAgentApiKeyEnvVar for agent provider API keys.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)


Full details: Updates Docs

Explanation

The OSS documentation was updated in packages/runtime-core/README.md with guidance for getAgentApiKeyEnvVar(parseAgentModel(spec).providerId). The linked deepnote/deepnote-internal repository and its landing-page roadmap are not available in this review, so the roadmap update cannot be verified.


  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@tkislan
tkislan marked this pull request as ready for review October 8, 2026 13:31
@tkislan
tkislan requested a review from a team as a code owner October 8, 2026 13:31
@tkislan
tkislan enabled auto-merge (squash) October 12, 2026 12:17
@tkislan
tkislan merged commit 4186248 into main Oct 12, 2026
22 checks passed
@tkislan
tkislan deleted the feat/runtime-core-agent-api-key-env-var branch October 12, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants