Skip to content

feature: add compile_prompt function to the client#24

Merged
drorIvry merged 1 commit into
mainfrom
feature/FIRE-1028/add-compile-prompt-function
Jan 18, 2026
Merged

feature: add compile_prompt function to the client#24
drorIvry merged 1 commit into
mainfrom
feature/FIRE-1028/add-compile-prompt-function

Conversation

@amos-qualifire

@amos-qualifire amos-qualifire commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

Description of change

Pull-Request Checklist

  • Code is up-to-date with the main branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions outlined in the conventional commit spec

Summary by CodeRabbit

  • New Features
    • Added ability to compile prompts in Qualifire Studio with optional revision selection and parameter support.
    • Expanded public API types to include compiled prompt responses and associated tool definitions.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 15, 2026

Copy link
Copy Markdown

Walkthrough

This PR adds support for compiling prompts via Qualifire Studio. It introduces a new compilePrompt() method to the Qualifire class that sends a POST request to the compilation endpoint and returns a structured response. Additionally, it exports two new types: CompilePromptResponse and ToolResponse.

Changes

Cohort / File(s) Summary
Prompt Compilation Feature
src/index.ts
Adds public compilePrompt() method to Qualifire class that accepts promptId, optional revisionId, and optional params, making a POST request to /api/v1/studio/prompts/{promptId}/compile. Exports new public types CompilePromptResponse and ToolResponse.
Type Definitions
src/types.ts
Introduces ToolResponseSchema with type and function fields, and CompilePromptResponseSchema with id, name, revision, messages (LLMMessageSchema array), tools (ToolResponseSchema array), and parameters. Exports inferred types ToolResponse and CompilePromptResponse.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A prompt compilation so fine,
New schemas and methods align,
With Tools and Responses in tow,
The Studio API's aglow!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'feature: add compile_prompt function to the client' clearly and specifically describes the main change—adding a new compile_prompt function to the client API.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/FIRE-1028/add-compile-prompt-function

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 making tools and parameters fields 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}/compile endpoint always returns tools and parameters fields, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 527b82a and ccd49d9.

📒 Files selected for processing (2)
  • src/index.ts
  • src/types.ts
🧰 Additional context used
📓 Path-based instructions (2)
src/types.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Use Zod schemas in src/types.ts to define type validation including EvaluationRequestV2Schema, 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 via X-Qualifire-API-Key header in requests to Qualifire API
Qualifire API endpoint should be {baseUrl}/api/evaluation/evaluate with default baseUrl of https://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.ts
  • 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/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 ToolResponseSchema follows the existing pattern in this file, reusing LLMToolDefinitionSchema for the function field. The structure aligns with typical tool definitions in LLM APIs.


288-289: LGTM!

Type exports using z.infer are consistent with the existing pattern in this file (e.g., EvaluationResponse, LLMToolDefinition).

src/index.ts (4)

7-15: LGTM!

Import additions for CompilePromptResponse are 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}/compile while 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.

Comment thread src/index.ts
Comment on lines +459 to +462
let url = `${this.baseUrl}/api/v1/studio/prompts/${promptId}/compile`;
if (revisionId) {
url = `${url}?revision=${revisionId}`;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

@amos-qualifire amos-qualifire changed the title [FIRE-1020] feature: add compile_prompt function to the client feature: add compile_prompt function to the client Jan 18, 2026
@drorIvry drorIvry merged commit 5e39d54 into main Jan 18, 2026
3 checks passed
@drorIvry drorIvry deleted the feature/FIRE-1028/add-compile-prompt-function branch January 18, 2026 07:55
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