[GH-ISSUE #1457] [Feature]: Migrate remaining raw invokeTauri callers to focused shared API wrappers #725

Closed
opened 2026-10-20 17:32:24 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Xelvanis on GitHub (May 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1457

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

Some feature-facing code still calls src/shared/api/tauri-client directly instead of going through focused src/shared/api wrappers. That spreads command names, payload shapes, response validation, error behavior, remote-runtime allowlisting expectations, and test seams across UI-facing code.

This makes future command changes harder to review because a command contract can be duplicated across hooks, components, and broad utility modules instead of being owned by one small API wrapper.

Proposed behavior

Continue migrating raw invokeTauri callers behind focused shared API wrappers, one bounded owner slice at a time.

Suggested shape:

  • Add or reuse a focused wrapper under src/shared/api for each command family.
  • Move command payload shaping, response validation, cancellation/abort handling, and binary conversion into that wrapper when applicable.
  • Update feature/hooks/lib callers to depend on the focused wrapper instead of importing invokeTauri directly.
  • Add targeted wrapper tests for command names, payloads, response validation, and negative/failure-path behavior.
  • Add remote-runtime routing coverage for commands that are expected to work through the hostable runtime.
  • Avoid expanding broad mixed utility modules unless keeping a compatibility re-export is needed during migration.

Migration status

Completed / in progress:

  • First slice: haptics API wrapper, merged in PR #1456.
  • Second slice: TTS and translation wrappers, merged in PR #1458.
    • Adds tts-api.ts and translation-api.ts.
    • Moves TTS/translation hooks and helper callers off direct invokeTauri.
    • Covers payloads, malformed response handling, abort handling for stale TTS audio, and remote routing tests.
  • Current slice: URL binary wrapper in PR #1460.
    • Adds url-binary-api.ts for load_url_binary.
    • Moves src/shared/lib/url-blob.ts off direct invokeTauri.
    • Covers payload shape, malformed responses, invalid base64 data, data URL passthrough, non-GET rejection, caller error copy, array-buffer conversion, and remote routing tests.

Scan note: the remaining-work list below is based on a direct-caller scan of current origin/refactor after PR #1458, with the TTS/translation paths covered by PR #1458 and the URL-binary path covered by PR #1460 removed from the future-work set.

Remaining work after PR #1460 lands

The remaining work is not one giant mechanical rename. It should be split by owner/command family so each PR can prove behavior and failure paths.

Catalog resource command wrappers

Create or extend focused wrappers for catalog-owned command families, then update catalog hooks/components to use them:

  • Chats: src/features/catalog/chats/hooks/use-chats.ts
    • Commands include chat memory list/delete/clear/refresh/export/import, notes list/delete/clear, group delete, autonomous unread mark/clear, bulk message delete, branch, swipes, connect/disconnect.
  • Characters/personas: src/features/catalog/characters/hooks/use-characters.ts, src/features/catalog/personas/hooks/use-personas.ts, src/features/catalog/characters/components/CharacterEditor.tsx, src/features/catalog/characters/components/CharactersPanel.tsx
    • Commands include restore version, avatar upload, persona activate, storage duplicate, and chat swipe additions.
  • Chat presets, lorebooks, connections, agents: use-chat-presets.ts, use-lorebooks.ts, LorebookEditor.tsx, use-connections.ts, use-agents.ts, use-custom-tools.ts
    • Commands include storage duplicate, lorebook image upload/vectorize, connection test/message/defaults, agent patch/toggle, and custom tool capabilities.

Likely outcome: either extend existing wrappers such as storage-api.ts / storage-commands-api.ts, or add focused wrappers such as chat-memory/chat-notes/chat-swipes, catalog-character/persona, lorebook-assets, connection-test, and agent-admin APIs.

Shared chat UI and mode command wrappers

Move direct command calls out of shared mode UI and roleplay/conversation components:

  • Shared chat UI: ChatSettingsDrawer.tsx, ChatSetupWizard.tsx, EchoChamberPanel.tsx
    • Commands include chat swipe add, agent memory get/clear, and echo message clear.
  • Conversation/roleplay: use-background-autonomous.ts, ContextInjectionPanel.tsx, SecretPlotPanel.tsx
    • Commands include autonomous unread mark, agent cadence status, and agent memory get/patch.

Likely outcome: reuse catalog/chat wrappers where the command is already chat-owned, and add focused agent-memory / agent-cadence wrappers for agent-owned commands.

Shell and admin wrappers

Move shell-level direct command calls behind focused shared API wrappers:

  • Bot Browser: src/features/shell/bot-browser/api/bot-browser-api.ts
    • Commands: bot_browser_get, bot_browser_post.
    • Needs explicit error/result behavior so provider failures do not collapse into ambiguous empty states.
  • Admin data reset: src/features/shell/settings/hooks/use-admin-data-reset.ts
    • Commands: admin_expunge_command, admin_clear_all_command.
    • Treat as high-risk/destructive: add payload tests and negative/failure-path handling before changing UI behavior.

Expected owner or impact area

  • App shell, navigation, startup, or providers
  • Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Refactor branch considerations

  • Keep product behavior out of the shared API layer; wrappers should own transport contracts, not product decisions.
  • Do not add new feature-level raw invokeTauri imports while migrating old ones.
  • Keep remote-capable commands explicit in remote-runtime.ts and the corresponding Rust HTTP dispatch path.
  • Prefer small PR slices by command family or owning feature area so review stays focused.
  • Include failure-path tests where the wrapper validates malformed responses, cancellation, binary decoding, destructive commands, or command errors.
  • Skip Graphify output churn unless maintainers specifically request a map refresh.

Alternatives considered

Leaving direct invokeTauri calls in feature code keeps each small call site simple, but it makes command contract drift harder to audit and test. Keeping everything in one broad integration utility file also reduces file count, but it preserves mixed ownership and makes unrelated integrations change together.

Focused wrappers add a little indirection, but they make each command family easier to test, review, and route through embedded or remote runtime paths.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (May 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1457 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? Some feature-facing code still calls `src/shared/api/tauri-client` directly instead of going through focused `src/shared/api` wrappers. That spreads command names, payload shapes, response validation, error behavior, remote-runtime allowlisting expectations, and test seams across UI-facing code. This makes future command changes harder to review because a command contract can be duplicated across hooks, components, and broad utility modules instead of being owned by one small API wrapper. ## Proposed behavior Continue migrating raw `invokeTauri` callers behind focused shared API wrappers, one bounded owner slice at a time. Suggested shape: - Add or reuse a focused wrapper under `src/shared/api` for each command family. - Move command payload shaping, response validation, cancellation/abort handling, and binary conversion into that wrapper when applicable. - Update feature/hooks/lib callers to depend on the focused wrapper instead of importing `invokeTauri` directly. - Add targeted wrapper tests for command names, payloads, response validation, and negative/failure-path behavior. - Add remote-runtime routing coverage for commands that are expected to work through the hostable runtime. - Avoid expanding broad mixed utility modules unless keeping a compatibility re-export is needed during migration. ## Migration status Completed / in progress: - First slice: haptics API wrapper, merged in PR #1456. - Second slice: TTS and translation wrappers, merged in PR #1458. - Adds `tts-api.ts` and `translation-api.ts`. - Moves TTS/translation hooks and helper callers off direct `invokeTauri`. - Covers payloads, malformed response handling, abort handling for stale TTS audio, and remote routing tests. - Current slice: URL binary wrapper in PR #1460. - Adds `url-binary-api.ts` for `load_url_binary`. - Moves `src/shared/lib/url-blob.ts` off direct `invokeTauri`. - Covers payload shape, malformed responses, invalid base64 data, data URL passthrough, non-GET rejection, caller error copy, array-buffer conversion, and remote routing tests. Scan note: the remaining-work list below is based on a direct-caller scan of current `origin/refactor` after PR #1458, with the TTS/translation paths covered by PR #1458 and the URL-binary path covered by PR #1460 removed from the future-work set. ## Remaining work after PR #1460 lands The remaining work is not one giant mechanical rename. It should be split by owner/command family so each PR can prove behavior and failure paths. ### Catalog resource command wrappers Create or extend focused wrappers for catalog-owned command families, then update catalog hooks/components to use them: - Chats: `src/features/catalog/chats/hooks/use-chats.ts` - Commands include chat memory list/delete/clear/refresh/export/import, notes list/delete/clear, group delete, autonomous unread mark/clear, bulk message delete, branch, swipes, connect/disconnect. - Characters/personas: `src/features/catalog/characters/hooks/use-characters.ts`, `src/features/catalog/personas/hooks/use-personas.ts`, `src/features/catalog/characters/components/CharacterEditor.tsx`, `src/features/catalog/characters/components/CharactersPanel.tsx` - Commands include restore version, avatar upload, persona activate, storage duplicate, and chat swipe additions. - Chat presets, lorebooks, connections, agents: `use-chat-presets.ts`, `use-lorebooks.ts`, `LorebookEditor.tsx`, `use-connections.ts`, `use-agents.ts`, `use-custom-tools.ts` - Commands include storage duplicate, lorebook image upload/vectorize, connection test/message/defaults, agent patch/toggle, and custom tool capabilities. Likely outcome: either extend existing wrappers such as `storage-api.ts` / `storage-commands-api.ts`, or add focused wrappers such as chat-memory/chat-notes/chat-swipes, catalog-character/persona, lorebook-assets, connection-test, and agent-admin APIs. ### Shared chat UI and mode command wrappers Move direct command calls out of shared mode UI and roleplay/conversation components: - Shared chat UI: `ChatSettingsDrawer.tsx`, `ChatSetupWizard.tsx`, `EchoChamberPanel.tsx` - Commands include chat swipe add, agent memory get/clear, and echo message clear. - Conversation/roleplay: `use-background-autonomous.ts`, `ContextInjectionPanel.tsx`, `SecretPlotPanel.tsx` - Commands include autonomous unread mark, agent cadence status, and agent memory get/patch. Likely outcome: reuse catalog/chat wrappers where the command is already chat-owned, and add focused agent-memory / agent-cadence wrappers for agent-owned commands. ### Shell and admin wrappers Move shell-level direct command calls behind focused shared API wrappers: - Bot Browser: `src/features/shell/bot-browser/api/bot-browser-api.ts` - Commands: `bot_browser_get`, `bot_browser_post`. - Needs explicit error/result behavior so provider failures do not collapse into ambiguous empty states. - Admin data reset: `src/features/shell/settings/hooks/use-admin-data-reset.ts` - Commands: `admin_expunge_command`, `admin_clear_all_command`. - Treat as high-risk/destructive: add payload tests and negative/failure-path handling before changing UI behavior. ## Expected owner or impact area <!-- Check the areas you think are relevant. Leave uncertain items unchecked. --> - [ ] App shell, navigation, startup, or providers - [ ] Catalog resources: chats, characters, personas, lorebooks, presets, connections, agents, gallery, or knowledge - [ ] Chat mode - [ ] Roleplay mode - [ ] Game mode - [ ] Shared mode UI - [ ] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [ ] React-free engine behavior, contracts, agents, or capability ports - [x] Shared API wrapper or remote runtime routing - [ ] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Refactor branch considerations - Keep product behavior out of the shared API layer; wrappers should own transport contracts, not product decisions. - Do not add new feature-level raw `invokeTauri` imports while migrating old ones. - Keep remote-capable commands explicit in `remote-runtime.ts` and the corresponding Rust HTTP dispatch path. - Prefer small PR slices by command family or owning feature area so review stays focused. - Include failure-path tests where the wrapper validates malformed responses, cancellation, binary decoding, destructive commands, or command errors. - Skip Graphify output churn unless maintainers specifically request a map refresh. ## Alternatives considered Leaving direct `invokeTauri` calls in feature code keeps each small call site simple, but it makes command contract drift harder to audit and test. Keeping everything in one broad integration utility file also reduces file count, but it preserves mixed ownership and makes unrelated integrations change together. Focused wrappers add a little indirection, but they make each command family easier to test, review, and route through embedded or remote runtime paths. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:32:24 +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#725
No description provided.