[PR #3780] [MERGED] refactor(client): centralize API transport policy #6098

Closed
opened 2026-10-23 04:07:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3780
Author: @Xelvanis
Created: 7/18/2026
Status: ✅ Merged
Merged: 7/18/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/internal-api-transport


📝 Commits (3)

  • 7367874 refactor(client): centralize API transport policy
  • d26a0ea fix(client): tolerate unavailable local storage
  • 17374e3 Merge branch 'staging' into fix/internal-api-transport

📊 Changes

6 files changed (+34 additions, -53 deletions)

View changed files

📝 packages/client/src/components/chat/ChatBranchSelector.tsx (+10 -4)
📝 packages/client/src/components/layout/ChatSidebar.tsx (+5 -5)
📝 packages/client/src/components/modals/STBulkImportModal.tsx (+5 -18)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+1 -3)
📝 packages/client/src/hooks/use-knowledge-sources.ts (+1 -9)
📝 packages/client/src/lib/api-client.ts (+12 -14)

📄 Description

Linked issue

Follow-up to #3603.

Why this change

  • #3603 identified a wider inventory of direct internal /api fetches that bypass shared admin-secret, CSRF, cache, and error-handling policy. This applies the recommended incremental migration to the privileged and straightforward multipart paths reviewed here.

What changed

  • Route API-client POST downloads, SSE streams, and multipart uploads through the existing apiFetch transport boundary.
  • Migrate SillyTavern bulk import and backup download raw-response calls to api.raw while preserving JSON, SSE, header, and binary response access.
  • Migrate knowledge-source, standalone chat, and branch chat multipart imports to api.upload.
  • Keep the global CSRF fetch shim as defense-in-depth and make the admin-header helper private now that no external callers remain.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • pnpm check passed on the rebased commit, including project-context checks, workspace lint/type checks, and production builds.
  • A disposable Chromium Playwright pass exercised the real browser API client with forced admin authentication: missing/correct secret behavior, bulk scan and SSE completion, accepted/rejected knowledge uploads, standalone and branch chat imports, and ZIP backup headers/signature all passed. The temporary test and isolated data were removed afterward.
  • Actual UI controls, native save-dialog interaction, container builds, mobile, and theme-specific behavior were not manually verified.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

No documentation or release metadata changes are required for this internal transport refactor.

UI evidence (if applicable)

Not applicable; there is no visual UI change.

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat and bulk chat imports with more consistent success and error handling.
    • Improved SillyTavern folder scanning, browsing, and bulk import requests.
    • Improved knowledge source upload reliability and error handling.
    • Improved backup downloads, including filename handling and download fallbacks.
  • Refactor
    • Standardized several upload, download, and streaming operations for more consistent behavior across the app.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3780 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 7/18/2026 **Status:** ✅ Merged **Merged:** 7/18/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/internal-api-transport` --- ### 📝 Commits (3) - [`7367874`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7367874cad9dbd9564c61fd439d39eaf91f10310) refactor(client): centralize API transport policy - [`d26a0ea`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d26a0eac95505604e23c4ce8cd5330de3104e0f7) fix(client): tolerate unavailable local storage - [`17374e3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/17374e3c77c84f1be9290f3d53b68485ede74346) Merge branch 'staging' into fix/internal-api-transport ### 📊 Changes **6 files changed** (+34 additions, -53 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatBranchSelector.tsx` (+10 -4) 📝 `packages/client/src/components/layout/ChatSidebar.tsx` (+5 -5) 📝 `packages/client/src/components/modals/STBulkImportModal.tsx` (+5 -18) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+1 -3) 📝 `packages/client/src/hooks/use-knowledge-sources.ts` (+1 -9) 📝 `packages/client/src/lib/api-client.ts` (+12 -14) </details> ### 📄 Description ## Linked issue Follow-up to #3603. ## Why this change - #3603 identified a wider inventory of direct internal `/api` fetches that bypass shared admin-secret, CSRF, cache, and error-handling policy. This applies the recommended incremental migration to the privileged and straightforward multipart paths reviewed here. ## What changed - Route API-client POST downloads, SSE streams, and multipart uploads through the existing `apiFetch` transport boundary. - Migrate SillyTavern bulk import and backup download raw-response calls to `api.raw` while preserving JSON, SSE, header, and binary response access. - Migrate knowledge-source, standalone chat, and branch chat multipart imports to `api.upload`. - Keep the global CSRF fetch shim as defense-in-depth and make the admin-header helper private now that no external callers remain. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check` passed on the rebased commit, including project-context checks, workspace lint/type checks, and production builds. - A disposable Chromium Playwright pass exercised the real browser API client with forced admin authentication: missing/correct secret behavior, bulk scan and SSE completion, accepted/rejected knowledge uploads, standalone and branch chat imports, and ZIP backup headers/signature all passed. The temporary test and isolated data were removed afterward. - Actual UI controls, native save-dialog interaction, container builds, mobile, and theme-specific behavior were not manually verified. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) No documentation or release metadata changes are required for this internal transport refactor. ## UI evidence (if applicable) Not applicable; there is no visual UI change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved chat and bulk chat imports with more consistent success and error handling. * Improved SillyTavern folder scanning, browsing, and bulk import requests. * Improved knowledge source upload reliability and error handling. * Improved backup downloads, including filename handling and download fallbacks. * **Refactor** * Standardized several upload, download, and streaming operations for more consistent behavior across the app. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:07:03 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6098
No description provided.