Skip to content

Commit cf84051

Browse files
committed
chore: update CHANGELOG.md
1 parent 53bcb2a commit cf84051

File tree

4 files changed

+60
-22
lines changed

4 files changed

+60
-22
lines changed

packages/ragbits-chat/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## Unreleased
4+
- Decoupling of components from ragbits specific logic. Introduction of slot based plugin architecture. Minimal history store implementation (#917)
45
- Add timezone field to ChatContext, automatically populated from browser (#916)
56
- Fix PostgreSQL conversation persistence by ensuring session flush after creating new conversation in SQL storage (#903)
67
- Change auth backend from jwt to http-only cookie based authentication, add support for OAuth2 authentication (#867)

typescript/ui/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ function App() {
119119
<MinimalHistoryStoreProvider
120120
onSendMessage={async (text, client) => {
121121
// Call your API
122-
const response = await fetch('/api/chat', {
123-
method: 'POST',
122+
const response = await fetch("/api/chat", {
123+
method: "POST",
124124
body: JSON.stringify({ message: text }),
125125
});
126126
// Handle response...

typescript/ui/src/core/components/Slot.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ export function Slot<S extends SlotName>({
4949
const Component = filler.component;
5050
return (
5151
<Suspense key={index} fallback={skeleton}>
52-
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
53-
<Component {...(props as any)} />
52+
<Component {...(props || {})} />
5453
</Suspense>
5554
);
5655
})}

typescript/ui/src/core/stores/HistoryStore/HistoryStoreContextProvider.tsx

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ const createMinimalHistoryStore = immer<HistoryStore>((set, get) => {
2020
// TODO: We might want to unify primitives with the RagbitsHistoryStore later
2121
primitives: {
2222
getCurrentConversation: () => {
23-
const state = get();
24-
return (
25-
state.conversations[state.currentConversation] ??
26-
initialConversationValues()
27-
);
23+
const { currentConversation, conversations } = get();
24+
const conversation = conversations[currentConversation];
25+
26+
if (!conversation) {
27+
throw new Error("Tried to get conversation that doesn't exist.");
28+
}
29+
30+
return conversation;
2831
},
2932
addMessage: (conversationId, message) => {
3033
const id = uuidv4();
@@ -39,22 +42,36 @@ const createMinimalHistoryStore = immer<HistoryStore>((set, get) => {
3942
return id;
4043
},
4144
deleteMessage: (conversationId, messageId) => {
42-
set((draft) => {
43-
const conv = draft.conversations[conversationId];
44-
if (!conv) return;
45-
delete conv.history[messageId];
46-
});
45+
set(
46+
updateConversation(conversationId, (draft) => {
47+
const { history } = draft;
48+
const messageIds = Object.keys(history);
49+
50+
if (messageIds.at(-1) === messageId) {
51+
draft.lastMessageId = messageIds.at(-2) ?? null;
52+
}
53+
54+
delete draft.history[messageId];
55+
}),
56+
);
4757
},
4858
restore: () => {}, // No-op for minimal implementation
4959
stopAnswering: (conversationId) => {
50-
const conv = get().conversations[conversationId];
51-
conv?.abortController?.abort();
52-
set((draft) => {
53-
const c = draft.conversations[conversationId];
54-
if (!c) return;
55-
c.isLoading = false;
56-
c.abortController = null;
57-
});
60+
const conversation = get().conversations[conversationId];
61+
62+
if (!conversation) {
63+
throw new Error(
64+
"Tried to stop answering for conversation that doesn't exist",
65+
);
66+
}
67+
68+
conversation.abortController?.abort();
69+
set(
70+
updateConversation(conversationId, (draft) => {
71+
draft.abortController = null;
72+
draft.isLoading = false;
73+
}),
74+
);
5875
},
5976
},
6077

@@ -119,14 +136,35 @@ const createMinimalHistoryStore = immer<HistoryStore>((set, get) => {
119136

120137
selectConversation: (conversationId: string) => {
121138
set((draft) => {
139+
if (draft.currentConversation === conversationId) {
140+
return;
141+
}
142+
const conversation = draft.conversations[conversationId];
143+
if (!conversation) {
144+
throw new Error(
145+
`Tried to select conversation that doesn't exist, id: ${conversationId}`,
146+
);
147+
}
148+
122149
draft.currentConversation = conversationId;
123150
});
124151
},
125152

126153
deleteConversation: (conversationId: string) => {
154+
const {
155+
actions: { newConversation },
156+
primitives: { stopAnswering },
157+
currentConversation,
158+
} = get();
159+
stopAnswering(conversationId);
160+
127161
set((draft) => {
128162
delete draft.conversations[conversationId];
129163
});
164+
165+
if (conversationId === currentConversation) {
166+
return newConversation();
167+
}
130168
},
131169

132170
// These are no-ops for minimal implementation

0 commit comments

Comments
 (0)