Skip to content

Commit 30efdcc

Browse files
committed
Merge branch 'master' into fs2
2 parents 45863ee + dfc6618 commit 30efdcc

File tree

7 files changed

+316
-134
lines changed

7 files changed

+316
-134
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,29 @@ export class ChatActions extends Actions<ChatState> {
574574
return true;
575575
};
576576

577-
markThreadRead = (threadKey: string, count: number): boolean => {
577+
setThreadPin = (threadKey: string, pinned: boolean): boolean => {
578+
if (this.syncdb == null) {
579+
return false;
580+
}
581+
const entry = this.getThreadRootDoc(threadKey);
582+
if (entry == null) {
583+
return false;
584+
}
585+
if (pinned) {
586+
entry.doc.pin = true;
587+
} else {
588+
entry.doc.pin = false;
589+
}
590+
this.syncdb.set(entry.doc);
591+
this.syncdb.commit();
592+
return true;
593+
};
594+
595+
markThreadRead = (
596+
threadKey: string,
597+
count: number,
598+
commit = true,
599+
): boolean => {
578600
if (this.syncdb == null) {
579601
return false;
580602
}
@@ -588,7 +610,9 @@ export class ChatActions extends Actions<ChatState> {
588610
}
589611
entry.doc[`read-${account_id}`] = count;
590612
this.syncdb.set(entry.doc);
591-
this.syncdb.commit();
613+
if (commit) {
614+
this.syncdb.commit();
615+
}
592616
return true;
593617
};
594618

@@ -752,30 +776,44 @@ export class ChatActions extends Actions<ChatState> {
752776
* This checks a thread of messages to see if it is a language model thread and if so, returns it.
753777
*/
754778
isLanguageModelThread = (date?: Date): false | LanguageModel => {
755-
if (date == null) {
779+
if (date == null || this.store == null) {
756780
return false;
757781
}
758-
const thread = this.getMessagesInThread(date.toISOString());
759-
if (thread == null) {
782+
const messages = this.store.get("messages");
783+
if (messages == null) {
784+
return false;
785+
}
786+
const rootMs =
787+
getThreadRootDate({ date: date.valueOf(), messages }) || date.valueOf();
788+
const entry = this.getThreadRootDoc(`${rootMs}`);
789+
const rootMessage = entry?.message;
790+
if (rootMessage == null) {
760791
return false;
761792
}
762793

763-
// We deliberately start at the last most recent message.
764-
// Why? If we use the LLM regenerate dropdown button to change the LLM, we want to keep it.
765-
for (const message of thread.reverse()) {
766-
const lastHistory = message.get("history")?.first();
767-
// this must be an invalid message, because there is no history
768-
if (lastHistory == null) continue;
769-
const sender_id = lastHistory.get("author_id");
770-
if (isLanguageModelService(sender_id)) {
771-
return service2model(sender_id);
772-
}
773-
const input = lastHistory.get("content")?.toLowerCase();
774-
if (mentionsLanguageModel(input)) {
775-
return getLanguageModel(input);
776-
}
794+
const thread = this.getMessagesInThread(
795+
rootMessage.get("date")?.toISOString?.() ?? `${rootMs}`,
796+
);
797+
if (thread == null) {
798+
return false;
777799
}
778800

801+
const firstMessage = thread.first();
802+
if (firstMessage == null) {
803+
return false;
804+
}
805+
const firstHistory = firstMessage.get("history")?.first();
806+
if (firstHistory == null) {
807+
return false;
808+
}
809+
const sender_id = firstHistory.get("author_id");
810+
if (isLanguageModelService(sender_id)) {
811+
return service2model(sender_id);
812+
}
813+
const input = firstHistory.get("content")?.toLowerCase();
814+
if (mentionsLanguageModel(input)) {
815+
return getLanguageModel(input);
816+
}
779817
return false;
780818
};
781819

@@ -1270,7 +1308,6 @@ export class ChatActions extends Actions<ChatState> {
12701308
};
12711309

12721310
setSelectedThread = (threadKey: string | null) => {
1273-
console.log("setSelectedThread", { threadKey });
12741311
this.frameTreeActions?.set_frame_data({
12751312
id: this.frameId,
12761313
selectedThreadKey: threadKey,

src/packages/frontend/chat/chat-log.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ export function MessageList({
546546
return (
547547
<Virtuoso
548548
ref={virtuosoRef}
549-
totalCount={sortedDates.length}
549+
totalCount={sortedDates.length + 1}
550550
itemSize={(el) => {
551551
// see comment in jupyter/cell-list.tsx
552552
const h = el.getBoundingClientRect().height;
@@ -558,6 +558,9 @@ export function MessageList({
558558
return h;
559559
}}
560560
itemContent={(index) => {
561+
if (sortedDates.length == index) {
562+
return <div style={{ height: "25vh" }} />;
563+
}
561564
const date = sortedDates[index];
562565
const message: ChatMessageTyped | undefined = messages.get(date);
563566
if (message == null) {

0 commit comments

Comments
 (0)