-
Notifications
You must be signed in to change notification settings - Fork 64
feat: split playground API for Node.js-only LLM providers #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: split playground API for Node.js-only LLM providers #194
Conversation
Add definePlaygroundQueries and definePlaygroundActions to allow separation of V8-safe queries/mutations from Node.js-only actions. This is needed when using LLM providers that require Node.js modules (e.g., Vertex AI with google-auth-library, http, https) because: - Queries/mutations MUST run in V8 runtime (Convex restriction) - Actions CAN use Node.js runtime (with 'use node' directive) - The combined definePlaygroundAPI pulls all dependencies into V8 New exports: - definePlaygroundQueries: V8-safe queries and mutations - definePlaygroundActions: Node.js actions for text generation - AgentInfo type for static agent info in queries - PlaygroundQueriesAPI and PlaygroundActionsAPI types The original definePlaygroundAPI is preserved for backward compatibility with providers that work in V8 (e.g., OpenAI via fetch).
WalkthroughThe playground API has been refactored into modular components, introducing separate Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/client/definePlaygroundAPI.ts (1)
90-264: Well-implemented V8-safe API with comprehensive documentation.The function correctly provides V8-safe queries and mutations while accepting static
AgentInfo[]to avoid Node.js dependencies. The documentation with examples is excellent.Note on code duplication: The implementations of
validateApiKey,listUsers,listThreads,listMessages, andcreateThreadare duplicated betweendefinePlaygroundQueries,definePlaygroundActions, anddefinePlaygroundAPI. While this duplication may be intentional to keep the APIs independent, consider extracting common implementations into shared internal helpers to improve maintainability and reduce the risk of inconsistent bug fixes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/client/definePlaygroundAPI.ts(1 hunks)src/client/index.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/client/definePlaygroundAPI.ts (1)
src/client/types.ts (1)
AgentComponent(328-328)
🔇 Additional comments (6)
src/client/index.ts (1)
131-139: LGTM! Clean extension of the public API surface.The new exports properly expose the split playground API functions and their associated types, while maintaining backward compatibility with the existing
definePlaygroundAPIandPlaygroundAPIexports.src/client/definePlaygroundAPI.ts (5)
38-44: LGTM! Type exports follow established patterns.The new
PlaygroundQueriesAPIandPlaygroundActionsAPItypes correctly use theApiFromModulesutility to infer types from their respective builder functions, consistent with the existingPlaygroundAPItype.
51-62: LGTM! Well-designed type for V8-safe agent metadata.The
AgentInfotype appropriately captures static agent configuration without requiring Node.js-dependentAgentinstances. The structure aligns with the information extracted from actual agents indefinePlaygroundAPI(line 558-565).
292-456: LGTM! Node.js actions properly separated with clear documentation.The function correctly provides Node.js-only actions while requiring actual
Agentinstances. The implementation properly handles agent validation and provides comprehensive error messages. The documentation with examples clearly shows the "use node" directive requirement.
458-490: Excellent documentation for the combined API.The JSDoc clearly explains the limitations and when to use the split APIs instead. The prominent warning about Node.js-only dependencies and the cross-references to
definePlaygroundQueriesanddefinePlaygroundActionswill help users choose the right approach.
64-64: LGTM! Good abstraction for shared validation logic.The
RunQueryCtxtype appropriately abstracts the minimal context needed for API key validation, allowing thevalidateApiKeyhelper to work in both query and action contexts.
commit: |
|
High level:
|
Adds two new functions to allow separation of V8-safe queries/mutations from Node.js-only actions in the playground API:
definePlaygroundQueries- V8-safe queries and mutationsdefinePlaygroundActions- Node.js actions for text generationProblem
When using LLM providers that require Node.js modules (e.g., Vertex AI with
google-auth-library,http,https), the currentdefinePlaygroundAPIcauses bundler errors because:"use node"directive)definePlaygroundAPIpulls all dependencies (including Node.js-only ones) into the V8 bundle, causing errors like:Solution
Split the API into two separate functions that can be imported independently:
Usage Example
Changes
definePlaygroundQueries()- takes staticAgentInfo[]instead ofAgent[]to avoid importing Node.js dependenciesdefinePlaygroundActions()- takesAgent[]and exports only actionsAgentInfo,PlaygroundQueriesAPI,PlaygroundActionsAPIdefinePlaygroundAPIfor backward compatibility with providers that work in V8 (e.g., OpenAI via fetch)