Skip to content

WIP Replace raw fetch() calls with typed openapi-fetch client#1188

Open
scosman wants to merge 1 commit intomainfrom
scosman/typed_client_updates
Open

WIP Replace raw fetch() calls with typed openapi-fetch client#1188
scosman wants to merge 1 commit intomainfrom
scosman/typed_client_updates

Conversation

@scosman
Copy link
Copy Markdown
Collaborator

@scosman scosman commented Mar 31, 2026

Convert three remaining fetch() calls in connect_providers.svelte and connect_kiln_copilot_steps.svelte to use the typed openapi-fetch client, gaining compile-time path checking and consistent error handling. Remove now-unused base_url imports. Mark Phase 1 of typed-client-migration as complete.

retarget to main once improve-api-docs is merged

Summary by CodeRabbit

  • Refactor

    • Updated API request handling in provider connection workflows.
  • Chores

    • Added documentation for typed client migration project, architecture, and implementation guidelines.

Convert three remaining fetch() calls in connect_providers.svelte and
connect_kiln_copilot_steps.svelte to use the typed openapi-fetch client,
gaining compile-time path checking and consistent error handling. Remove
now-unused base_url imports. Mark Phase 1 of typed-client-migration as
complete.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 31, 2026

Walkthrough

This PR migrates raw fetch() calls to a typed openapi-fetch client in two Svelte components (connect_providers.svelte and connect_kiln_copilot_steps.svelte), replacing manual URL construction and JSON serialization with typed client calls that return { data, error }. Accompanying documentation outlines the migration approach and specifies the completed Phase 1 conversion targets.

Changes

Cohort / File(s) Summary
Typed Client Migration - Components
app/web_ui/src/routes/(fullscreen)/setup/(setup)/connect_providers/connect_providers.svelte, app/web_ui/src/lib/ui/kiln_copilot/connect_kiln_copilot_steps.svelte
Replaced raw fetch(base_url + "/api/provider/connect_api_key", ...) with client.POST() call; error handling shifted from HTTP status checks to { error } object inspection. In connect_providers.svelte, additionally replaced fetch(base_url + "/api/settings") with client.GET(), added TypeScript casting for API response values, and refined provider handling with typed variable for compatibility check. Removed unused base_url imports.
Migration Documentation
specs/projects/typed-client-migration/project_overview.md, specs/projects/typed-client-migration/functional_spec.md, specs/projects/typed-client-migration/architecture.md, specs/projects/typed-client-migration/implementation_plan.md, specs/projects/typed-client-migration/phase_plans/phase_1.md
Added comprehensive specification and planning documentation detailing the migration strategy, observable call-site differences (serialization/header handling by client, error object inspection), functional requirements, and Phase 1 completion status for converting three fetch calls to typed client calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • chore: move UI config to centralized file #930: Centralizes base_url into KilnApiBaseUrl and updates imports across the codebase—directly related since this PR removes base_url usage in favor of typed client calls at the same call sites.
  • gepa: copilot gate and warning fix #1013: Adds Kiln Copilot UI and utilities that invoke the same backend endpoints (/api/provider/connect_api_key and /api/settings)—related through shared endpoint usage and Copilot workflow integration.

Suggested reviewers

  • leonardmq
  • sfierro

Poem

🐰 A rabbit hops through typed pathways bright,
No more raw fetch in fading light,
With client.POST and client.GET,
Compile-time checks we won't forget!
Migrations done, the schema's tight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is clear and concise, explaining the main objective of converting fetch() calls to the typed client and marking Phase 1 complete. Add sections for 'Related Issues' and 'Contributor License Agreement' confirmation, and complete the checklist items as specified in the repository template.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: replacing raw fetch() calls with a typed openapi-fetch client across the specified components.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch scosman/typed_client_updates

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request migrates raw fetch calls in the Svelte frontend to a typed openapi-fetch client, specifically for provider connection and settings endpoints. This change improves type safety and centralizes API configuration. The PR also includes detailed documentation covering the architecture, functional specifications, and implementation plan for this migration. My feedback focuses on improving the robustness of the new implementation: first, by ensuring that the detail field in error responses is properly validated as a string before UI display to avoid showing [object Object]; and second, by adding a guard clause to verify that the data object is defined before accessing its properties to prevent runtime errors.

Comment on lines +114 to +115
(err.message as string) ||
(err.detail as string) ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The detail field in FastAPI error responses (such as 422 Validation Errors) is frequently an array of objects rather than a string. Casting it directly to string and assigning it to apiKeyMessage may result in [object Object] being displayed in the UI. It is safer to verify that detail is a string before assignment.

          (err.message as string) ||
          (typeof err.detail === "string" ? err.detail : null) ||

if (error) {
throw error
}
if (data["open_ai_api_key"]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The data object returned by the typed client is optional and could be undefined if the response body is empty. Accessing data["open_ai_api_key"] without a guard clause may lead to a runtime error. Adding a check for data after the error handling ensures the function exits gracefully if no data is returned.

      if (!data) return
      if (data["open_ai_api_key"]) {

@scosman scosman changed the title Replace raw fetch() calls with typed openapi-fetch client WIP Replace raw fetch() calls with typed openapi-fetch client Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

📊 Coverage Report

Overall Coverage: 91%

Diff: origin/scosman/improve-api-docs...HEAD

No lines with coverage information in this diff.


Base automatically changed from scosman/improve-api-docs to main April 1, 2026 16:09
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.

1 participant