Spaces:
Running
Running
Andrew
commited on
Commit
·
f21352e
1
Parent(s):
684165a
feat(ui): add conversation tree store for state management
Browse files
src/lib/stores/conversationTree.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { writable } from "svelte/store";
|
| 2 |
+
import type { Message } from "$lib/types/Message";
|
| 3 |
+
|
| 4 |
+
interface ConversationTreeState {
|
| 5 |
+
conversationId: string | null;
|
| 6 |
+
messages: Message[];
|
| 7 |
+
activeMessageId: string | null; // Currently displayed message
|
| 8 |
+
branchedFrom: { messageId: string; personaId: string } | null;
|
| 9 |
+
activePath: string[]; // Linear path of message IDs visible in chat
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
const initialState: ConversationTreeState = {
|
| 13 |
+
conversationId: null,
|
| 14 |
+
messages: [],
|
| 15 |
+
activeMessageId: null,
|
| 16 |
+
branchedFrom: null,
|
| 17 |
+
activePath: [],
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
export const conversationTree = writable<ConversationTreeState>(initialState);
|
| 21 |
+
|
| 22 |
+
export function setConversationTree(
|
| 23 |
+
conversationId: string,
|
| 24 |
+
messages: Message[],
|
| 25 |
+
activeMessageId?: string,
|
| 26 |
+
branchedFrom?: { messageId: string; personaId: string } | null,
|
| 27 |
+
activePath: string[] = []
|
| 28 |
+
) {
|
| 29 |
+
conversationTree.set({
|
| 30 |
+
conversationId,
|
| 31 |
+
messages,
|
| 32 |
+
activeMessageId: activeMessageId ?? null,
|
| 33 |
+
branchedFrom: branchedFrom ?? null,
|
| 34 |
+
activePath,
|
| 35 |
+
});
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export function clearConversationTree() {
|
| 39 |
+
conversationTree.set(initialState);
|
| 40 |
+
}
|