feature: add compile_prompt function to the client#24
Conversation
WalkthroughThis PR adds support for compiling prompts via Qualifire Studio. It introduces a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/index.ts`:
- Around line 459-462: The URL construction using this.baseUrl and the variables
promptId/revisionId is vulnerable to malformed URLs when those values contain
special characters; update the code that builds the compile endpoint (the lines
that set url = `${this.baseUrl}/api/v1/studio/prompts/${promptId}/compile` and
the conditional that appends `?revision=${revisionId}`) to use
encodeURIComponent(promptId) and encodeURIComponent(revisionId) when
interpolating those values so both segments and query parameters are safely
encoded.
🧹 Nitpick comments (2)
src/types.ts (1)
279-286: Consider makingtoolsandparametersfields optional for API response flexibility.If the API may return prompts without tools or parameters, these fields should be optional to avoid runtime mismatches. Additionally, since the schema is not exported, runtime validation won't occur—the response is cast directly in
compilePrompt.🔧 Suggested schema adjustment
const CompilePromptResponseSchema = z.object({ id: z.string(), name: z.string(), revision: z.number(), messages: z.array(LLMMessageSchema), - tools: z.array(ToolResponseSchema), - parameters: z.record(z.string(), z.any()), + tools: z.array(ToolResponseSchema).optional(), + parameters: z.record(z.string(), z.any()).optional(), });Please verify whether the
/api/v1/studio/prompts/{id}/compileendpoint always returnstoolsandparametersfields, or if they can be omitted/null in responses.src/index.ts (1)
479-484: Consider including response body in error messages for debugging.The current error only includes
response.statusText, which may be empty or generic. Including the response body (when available) would help with debugging API errors, consistent with how other SDKs typically handle this.🔧 Enhanced error handling
if (!response.ok) { - throw new Error(`Qualifire API error: ${response.statusText}`); + const errorBody = await response.text().catch(() => ''); + throw new Error( + `Qualifire API error: ${response.statusText}${errorBody ? ` - ${errorBody}` : ''}` + ); }Note: This same pattern could be applied to the other methods (
evaluate,invokeEvaluation) for consistency, but that's outside the scope of this PR.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/index.tssrc/types.ts
🧰 Additional context used
📓 Path-based instructions (2)
src/types.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Use Zod schemas in
src/types.tsto define type validation includingEvaluationRequestV2Schema,EvaluationProxyAPIRequestSchema, and supported frameworks (openai, vercelai, gemini, claude)
Files:
src/types.ts
src/index.ts
📄 CodeRabbit inference engine (CLAUDE.md)
src/index.ts: API key should be passed viaX-Qualifire-API-Keyheader in requests to Qualifire API
Qualifire API endpoint should be{baseUrl}/api/evaluation/evaluatewith default baseUrl ofhttps://proxy.qualifire.ai
Files:
src/index.ts
🧠 Learnings (4)
📚 Learning: 2026-01-08T09:57:56.537Z
Learnt from: CR
Repo: qualifire-dev/qualifire-typescript-sdk PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-08T09:57:56.537Z
Learning: Applies to src/types.ts : Use Zod schemas in `src/types.ts` to define type validation including `EvaluationRequestV2Schema`, `EvaluationProxyAPIRequestSchema`, and supported frameworks (openai, vercelai, gemini, claude)
Applied to files:
src/types.tssrc/index.ts
📚 Learning: 2026-01-08T09:57:56.537Z
Learnt from: CR
Repo: qualifire-dev/qualifire-typescript-sdk PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-08T09:57:56.537Z
Learning: Applies to src/index.ts : Qualifire API endpoint should be `{baseUrl}/api/evaluation/evaluate` with default baseUrl of `https://proxy.qualifire.ai`
Applied to files:
src/index.ts
📚 Learning: 2026-01-08T09:57:56.537Z
Learnt from: CR
Repo: qualifire-dev/qualifire-typescript-sdk PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-08T09:57:56.537Z
Learning: Main entry point should be the `Qualifire` class in `src/index.ts` providing `evaluate()`, `invokeEvaluation()`, and `init()` methods
Applied to files:
src/index.ts
📚 Learning: 2026-01-08T09:57:56.537Z
Learnt from: CR
Repo: qualifire-dev/qualifire-typescript-sdk PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-08T09:57:56.537Z
Learning: Applies to src/frameworks/**/*.ts : Framework converters in `src/frameworks/` must implement the `CanonicalEvaluationStrategy` interface from `canonical.ts`
Applied to files:
src/index.ts
🧬 Code graph analysis (2)
src/types.ts (1)
src/index.ts (2)
ToolResponse(26-26)CompilePromptResponse(18-18)
src/index.ts (1)
src/types.ts (1)
CompilePromptResponse(289-289)
🔇 Additional comments (6)
src/types.ts (2)
274-277: LGTM!The
ToolResponseSchemafollows the existing pattern in this file, reusingLLMToolDefinitionSchemafor thefunctionfield. The structure aligns with typical tool definitions in LLM APIs.
288-289: LGTM!Type exports using
z.inferare consistent with the existing pattern in this file (e.g.,EvaluationResponse,LLMToolDefinition).src/index.ts (4)
7-15: LGTM!Import additions for
CompilePromptResponseare correctly placed and follow the existing import pattern.
17-27: LGTM!The new type exports (
CompilePromptResponse,ToolResponse) are correctly added to the public API surface alongside existing types.
425-449: LGTM!The JSDoc documentation is comprehensive, includes proper parameter descriptions, and provides a clear usage example consistent with other methods in this class.
450-485: Verify the API endpoint path convention.The new endpoint uses
/api/v1/studio/prompts/{id}/compilewhile existing endpoints use/api/evaluation/.... Based on learnings, the evaluation endpoint should be{baseUrl}/api/evaluation/evaluate. Please confirm the/api/v1/studio/path is correct for the compile prompt feature.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| let url = `${this.baseUrl}/api/v1/studio/prompts/${promptId}/compile`; | ||
| if (revisionId) { | ||
| url = `${url}?revision=${revisionId}`; | ||
| } |
There was a problem hiding this comment.
URL-encode promptId and revisionId to prevent injection and malformed URLs.
If promptId or revisionId contain special characters (e.g., /, ?, &, #), the URL construction will break or behave unexpectedly. Use encodeURIComponent for safety.
🔧 Proposed fix
- let url = `${this.baseUrl}/api/v1/studio/prompts/${promptId}/compile`;
+ let url = `${this.baseUrl}/api/v1/studio/prompts/${encodeURIComponent(promptId)}/compile`;
if (revisionId) {
- url = `${url}?revision=${revisionId}`;
+ url = `${url}?revision=${encodeURIComponent(revisionId)}`;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let url = `${this.baseUrl}/api/v1/studio/prompts/${promptId}/compile`; | |
| if (revisionId) { | |
| url = `${url}?revision=${revisionId}`; | |
| } | |
| let url = `${this.baseUrl}/api/v1/studio/prompts/${encodeURIComponent(promptId)}/compile`; | |
| if (revisionId) { | |
| url = `${url}?revision=${encodeURIComponent(revisionId)}`; | |
| } |
🤖 Prompt for AI Agents
In `@src/index.ts` around lines 459 - 462, The URL construction using this.baseUrl
and the variables promptId/revisionId is vulnerable to malformed URLs when those
values contain special characters; update the code that builds the compile
endpoint (the lines that set url =
`${this.baseUrl}/api/v1/studio/prompts/${promptId}/compile` and the conditional
that appends `?revision=${revisionId}`) to use encodeURIComponent(promptId) and
encodeURIComponent(revisionId) when interpolating those values so both segments
and query parameters are safely encoded.
Description of change
Pull-Request Checklist
mainbranchnpm run lintpasses with this changenpm run testpasses with this changeFixes #0000Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.