File size: 1,057 Bytes
f21352e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { writable } from "svelte/store";
import type { Message } from "$lib/types/Message";

interface ConversationTreeState {
	conversationId: string | null;
	messages: Message[];
	activeMessageId: string | null; // Currently displayed message
	branchedFrom: { messageId: string; personaId: string } | null;
	activePath: string[]; // Linear path of message IDs visible in chat
}

const initialState: ConversationTreeState = {
	conversationId: null,
	messages: [],
	activeMessageId: null,
	branchedFrom: null,
	activePath: [],
};

export const conversationTree = writable<ConversationTreeState>(initialState);

export function setConversationTree(
	conversationId: string,
	messages: Message[],
	activeMessageId?: string,
	branchedFrom?: { messageId: string; personaId: string } | null,
	activePath: string[] = []
) {
	conversationTree.set({
		conversationId,
		messages,
		activeMessageId: activeMessageId ?? null,
		branchedFrom: branchedFrom ?? null,
		activePath,
	});
}

export function clearConversationTree() {
	conversationTree.set(initialState);
}