[PR #726] [MERGED] feat(chat): import JSONL into existing chat as a new branch #4748

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/726
Author: @LukaTheHero
Created: 5/12/2026
Status: ✅ Merged
Merged: 5/12/2026
Merged by: @LukaTheHero

Base: main ← Head: feat/import-chat-into-group


📝 Commits (1)

  • 03fa729 feat(chat): import JSONL into existing chat as a new branch

📊 Changes

3 files changed (+202 additions, -6 deletions)

View changed files

📝 packages/client/src/components/chat/ChatFilesDrawer.tsx (+92 -1)
📝 packages/server/src/routes/import.routes.ts (+91 -0)
📝 packages/server/src/services/import/st-chat.importer.ts (+19 -5)

📄 Description

Summary

Adds an Import Chat button to the Manage Chat Files drawer so a JSONL exported from one chat can be brought back as a sibling branch of another chat — instead of dropping into Settings → Import Chat, which spawns a brand-new character entry at the top of the chat list.

Why

Right now, the only "Import Chat" UI lives in Settings, and it always creates a new top-level chat (and, when no character match is found, it can effectively orphan the transcript away from the character you actually want it on). The drawer for an individual chat only offers Export Chat, which is asymmetric — there's no way to round-trip a JSONL back into the same conversation as a new chat file. This PR makes Manage Chat Files symmetric: you can export a branch and import a branch from the same place, and the imported one lands alongside the others as a chat file.

Changes

  • packages/server/src/services/import/st-chat.importer.ts — ImportSTChatOptions now accepts characterIds, personaId, connectionId, and promptPresetId so callers can fully inherit an existing chat's settings (previously these were always nulled).
  • packages/server/src/routes/import.routes.ts — new POST /api/import/st-chat-into-group endpoint. Looks up the target chat, auto-assigns a groupId if it doesn't have one (same trick the existing POST /chats/:id/branch endpoint uses at chats.routes.ts:1579), inherits the target chat's character roster / persona / connection / prompt preset, and for multi-character chats builds a name → characterId speaker map from the target roster so per-message attribution survives the import. No new character is created in any path.
  • packages/client/src/components/chat/ChatFilesDrawer.tsx — adds an Import Chat section under Export Chat in both the grouped and ungrouped drawer states. Posts the file + the current chat id to the new endpoint, invalidates list/detail/group caches (the target chat may have just been freshly assigned a groupId), refetches the branch list, and switches the active chat to the newly imported branch.

Notes for reviewer

  • The new endpoint never reads the JSONL header's character_name to match or create characters — it only uses the target chat's existing roster. Speakers in the JSONL whose name doesn't match anyone in that roster fall back to the first inherited character (existing importSTChat fallback behavior).
  • Same auto-groupId behavior as POST /chats/:id/branch, so importing into a chat that's never been branched will quietly give it a groupId and the imported file becomes its first branch.
  • UI lives in the existing drawer; styling reuses the same secondary/border/ring tokens as Export Chat and the existing branch list, so it inherits theming and mobile layout from the surrounding section.

🔄 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/726 **Author:** [@LukaTheHero](https://github.com/LukaTheHero) **Created:** 5/12/2026 **Status:** ✅ Merged **Merged:** 5/12/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `feat/import-chat-into-group` --- ### 📝 Commits (1) - [`03fa729`](https://github.com/Pasta-Devs/Marinara-Engine/commit/03fa729f80eef2fad2e10be9299988b80f4032a7) feat(chat): import JSONL into existing chat as a new branch ### 📊 Changes **3 files changed** (+202 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatFilesDrawer.tsx` (+92 -1) 📝 `packages/server/src/routes/import.routes.ts` (+91 -0) 📝 `packages/server/src/services/import/st-chat.importer.ts` (+19 -5) </details> ### 📄 Description ## Summary Adds an **Import Chat** button to the **Manage Chat Files** drawer so a JSONL exported from one chat can be brought back as a sibling branch of another chat — instead of dropping into Settings → Import Chat, which spawns a brand-new character entry at the top of the chat list. ## Why Right now, the only "Import Chat" UI lives in Settings, and it always creates a new top-level chat (and, when no character match is found, it can effectively orphan the transcript away from the character you actually want it on). The drawer for an individual chat only offers **Export Chat**, which is asymmetric — there's no way to round-trip a JSONL back into the same conversation as a new chat file. This PR makes Manage Chat Files symmetric: you can export a branch and import a branch from the same place, and the imported one lands alongside the others as a chat file. ## Changes - **`packages/server/src/services/import/st-chat.importer.ts`** — `ImportSTChatOptions` now accepts `characterIds`, `personaId`, `connectionId`, and `promptPresetId` so callers can fully inherit an existing chat's settings (previously these were always nulled). - **`packages/server/src/routes/import.routes.ts`** — new `POST /api/import/st-chat-into-group` endpoint. Looks up the target chat, auto-assigns a `groupId` if it doesn't have one (same trick the existing `POST /chats/:id/branch` endpoint uses at `chats.routes.ts:1579`), inherits the target chat's character roster / persona / connection / prompt preset, and for multi-character chats builds a `name → characterId` speaker map from the target roster so per-message attribution survives the import. **No new character is created in any path.** - **`packages/client/src/components/chat/ChatFilesDrawer.tsx`** — adds an **Import Chat** section under Export Chat in both the grouped and ungrouped drawer states. Posts the file + the current chat id to the new endpoint, invalidates list/detail/group caches (the target chat may have just been freshly assigned a groupId), refetches the branch list, and switches the active chat to the newly imported branch. ## Notes for reviewer - The new endpoint *never* reads the JSONL header's `character_name` to match or create characters — it only uses the target chat's existing roster. Speakers in the JSONL whose name doesn't match anyone in that roster fall back to the first inherited character (existing `importSTChat` fallback behavior). - Same auto-groupId behavior as `POST /chats/:id/branch`, so importing into a chat that's never been branched will quietly give it a `groupId` and the imported file becomes its first branch. - UI lives in the existing drawer; styling reuses the same secondary/border/ring tokens as Export Chat and the existing branch list, so it inherits theming and mobile layout from the surrounding section. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:19 +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#4748
No description provided.