Skip to content

Conversation

@hellovai
Copy link
Contributor

@hellovai hellovai commented Oct 30, 2025

Summary

This PR fixes two critical issues affecting the VSCode playground:

  1. WASM Vertex AI authentication failures - GCP service account JWT encoding was not sufficiently resilient
  2. Environment variable deletion not persisting - Clicking trash icon didn't save changes

Changes

1. Fix JWT encoding for GCP service account keys in WASM

Problem: The base64 decoder was producing only 3 bytes instead of 1600+ bytes for RSA keys because literal \n characters in JSON strings weren't being removed.

Root cause: GCP service account JSON files contain the private key with escaped newlines like:

{
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIE...\n-----END PRIVATE KEY-----\n"
}

The code was only removing actual newline characters (\n) but not the two-character literal string \n.

Solution:

  • Added .replace("\\n", "") to handle escaped newlines in JSON strings
  • Added support for both PKCS#8 (BEGIN PRIVATE KEY) and PKCS#1 (BEGIN RSA PRIVATE KEY) formats
  • Added validation: keys < 100 bytes now fail early with clear error
  • Enhanced error messages with actionable troubleshooting steps

2. Fix environment variable deletion not persisting

Problem: When users clicked the trash icon to delete an env var, it disappeared from the UI but remained in memory after reload.

Root cause: The deleteApiKeyAtom only updated local state but didn't call save, unlike the auto-save behavior for edits.

Solution:

  • Modified deleteApiKeyAtom to auto-save deletions immediately
  • Now consistent with the debounced auto-save used for value edits
  • Centralized the fix at the atom level (not component level)

Testing

  • ✅ Tested with real GCP service account credentials
  • ✅ Verified env var deletion persists across reloads
  • ✅ Error messages provide clear guidance for common issues
  • ✅ WASM build compiles successfully

Files Changed

  • engine/baml-runtime/src/internal/wasm_jwt.rs - JWT encoding fixes
  • engine/baml-runtime/src/internal/llm_client/primitive/vertex/wasm_auth.rs - Early validation
  • typescript/packages/playground-common/src/components/api-keys-dialog/atoms.ts - Auto-save deletions

🤖 Generated with Claude Code

This commit fixes two critical issues:

1. **Fix JWT encoding for GCP service account keys in WASM**
   - Handle literal `\n` characters in JSON (common in GCP service account files)
   - Add support for both PKCS#8 and PKCS#1 format PEM headers
   - Validate key length before attempting import (must be >= 100 bytes)
   - Improve error messages with actionable troubleshooting steps
   - Add new `KeyTooShort` error variant with context

2. **Fix environment variable deletion not persisting**
   - `deleteApiKeyAtom` now auto-saves changes to storage
   - Deletion behavior now consistent with edit auto-save
   - Fixes bug where clicking trash icon only updated local state

Technical details:
- WASM JWT: Added `.replace("\\n", "")` to handle escaped newlines in JSON strings
- WASM JWT: Enhanced error messages for WebCrypto import failures
- WASM Auth: Add early validation for credentials string length
- TypeScript: Modified `deleteApiKeyAtom` to persist deletions immediately

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@vercel
Copy link

vercel bot commented Oct 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
promptfiddle Ready Ready Preview Comment Nov 3, 2025 6:31pm

@hellovai hellovai changed the title Fix WASM Vertex AI authentication and env var deletion bug: improve WASM Vertex AI authentication + VSCode env var deletion Oct 30, 2025
@github-actions
Copy link

@hellovai hellovai enabled auto-merge October 30, 2025 21:01
@hellovai hellovai temporarily deployed to boundary-tools-dev October 30, 2025 21:02 — with GitHub Actions Inactive
@hellovai hellovai temporarily deployed to boundary-tools-dev October 30, 2025 21:02 — with GitHub Actions Inactive
@hellovai hellovai temporarily deployed to boundary-tools-dev October 30, 2025 21:02 — with GitHub Actions Inactive
@github-actions
Copy link

@github-actions
Copy link

@hellovai hellovai temporarily deployed to boundary-tools-dev November 3, 2025 18:07 — with GitHub Actions Inactive
@hellovai hellovai temporarily deployed to boundary-tools-dev November 3, 2025 18:07 — with GitHub Actions Inactive
@hellovai hellovai temporarily deployed to boundary-tools-dev November 3, 2025 18:07 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

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