Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

merge: 同步上游会话和已读更新

Zhehui Bi894f59ee21ab
diff --cc server/store.ts
index a3b1ab56e8,478ee93708..ce936858a9
--- a/server/store.ts
+++ b/server/store.ts
@@@ -38,14 -38,10 +38,14 @@@ import { movesThreadToTop, nextOpenThre
import { parseConnectorTools } from "./connector-tools.ts";
import { sameModelSelection } from "../shared/thread-model.ts";
import { initialGreetingMessage } from "./initial-greeting.ts"; import { createDefaultBot, defaultBotRefusal, type DefaultBotIntro } from "./default-bot.ts";
- import { appsFromCreator } from "./inherited-apps.ts";
+ import { appsFromCreator } from "./inherited-apps.ts"; import { newBotOwner, sharedAsMaker, sharedUnlessRestricted, type NewBotSharingRule } from "./new-bot-sharing.ts";
import { ThreadCache, type ThreadState } from "./thread-cache.ts";
import { titleFromMessage, UNTITLED_TASK } from "./thread-title.ts";
+import { buildTask, threadTitleFrom, UNTITLED_THREAD } from "./task-record.ts";
+import { createBotFork, createGroupFork } from "./store-forks.ts";
+import { activeGroupTask, groupTaskByThread, groupTasks, migrateGroupTaskRead, mirrorActiveGroupTask, refreshGroupUnread, setGroupTaskRead, syncGroupReadPatch } from "./group-task-state.ts";
export { titleFromMessage, UNTITLED_TASK } from "./thread-title.ts";
+export { threadTitleFrom, UNTITLED_THREAD } from "./task-record.ts";
export type {
BotActivity, GroupDefaultResponder, OptionCardData,
SecretRequestCardData, Surface, TaskClosedBy, TaskOpenedBy, TaskUsage,
diff --cc src/App.tsx
index bcd220383f,64fd708794..d76748e9d4
--- a/src/App.tsx
+++ b/src/App.tsx
@@@ -432,11 -429,11 +433,12 @@@ function Shell({ viewer }: { viewer: We
/>
)
)}
+ <AppPreviewPanel />
- {roomPanelOpen && group && (
+ {state.forkPanel && sidebarInline && <ForkPanel />}
+ {!state.forkPanel && roomPanelOpen && group && (
<RoomPanel key={`room:${group.id}`} group={group} overlay={notificationFeed && state.notificationsOpen && !twoSidePanelsFit} />
)}
- {!remoteClient && state.inspectorOpen && bot && <InspectorPanel key={bot.threadId} bot={bot} />}
+ {!remoteClient && !state.forkPanel && state.inspectorOpen && bot && <InspectorPanel key={bot.threadId} bot={bot} />}
{!remoteClient && state.activityOpen && bot && <ActivityPanel key={`activity:${bot.id}`} bot={bot} />}
{inboxShown && <InboxPanel />}
{notificationTray && state.notificationsOpen && <NotificationsPanel />}
diff --cc src/components/ChatView.tsx
index 7808107f36,8d8712cc09..3d4d24e80d
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@@ -3,12 -3,12 +3,13 @@@ import { useAdvancedMode } from "@/lib/
import { PHONE_LAYOUT, useMediaQuery } from "@/lib/use-media-query";
import { ThreadLinkContext } from "@/components/ThreadLinkMenu";
import { useShowThreads } from "@/lib/thread-preferences";
-import { AlertTriangle, ChevronLeft, ChevronRight, Copy, Monitor, RefreshCw, Reply, Square, Webhook } from "lucide-react";
+import { AlertTriangle, ChevronLeft, ChevronRight, Monitor, RefreshCw, Square, Webhook } from "lucide-react";
import { WorkingDots } from "@/components/WorkingIndicator";
-import { ACTION_ICON, ChatBusyContext, CopyButton, MESSAGE_ROW, MessageActions, messageActionClass, ReplyAction, type MessageMenuItem } from "@/components/MessageActions";
-import { copyText } from "@/lib/copy-text";
+import { ChatBusyContext, CopyButton, MESSAGE_ROW, MessageActions, messageActionClass, ReplyAction } from "@/components/MessageActions";
import { ReactAction, ReactionChips } from "@/components/Reactions";
-import { useBotMessageMenu, userMessageMenu } from "@/components/message-menu"; import { savesToTeamMemory, TEAM_MEMORY_ITEM, TeamMemorySavesContext } from "@/components/conversation-share/conversation-share";
+import { replyAndCopy, useBotMessageMenu, userMessageMenu } from "@/components/message-menu";
+import { forkMessageItem, ForkLinks } from "@/components/ForkMessage";
++import { savesToTeamMemory, TEAM_MEMORY_ITEM, TeamMemorySavesContext } from "@/components/conversation-share/conversation-share";
import { useSpeech } from "@/lib/tts/useSpeech";
import { localSystemVoiceActive } from "@/lib/local-voice";
import { computerStartLine, useScreensWhile } from "@/lib/computer-start";
@@@ -807,9 -800,9 +798,9 @@@ const MessagesList = memo(function Mess
const CHATHEAD_PILL = `flex min-w-0 items-center gap-2 rounded-full py-0.5 pl-1.5 text-ink ${ELEVATED_FLOAT}`;
- export function ChatView({ bot: profile, inForkPanel = false }: { bot: Bot; inForkPanel?: boolean }) {
-export const ChatView = memo(function ChatView({ bot: profile }: { bot: Bot }) {
++export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = false }: { bot: Bot; inForkPanel?: boolean }) {
const bot = useMemo(() => currentTaskBot(profile), [profile]);
- const { state, dispatch } = useStore();
- const state = useStoreSelector((s) => ({ computerStart: s.computerStarts[profile.id], mascotMotion: s.mascotMotion?.botId === profile.id ? s.mascotMotion : null, instances: s.instances, config: s.config, focusMessage: s.focusMessage, settingsOpen: s.settingsOpen, computerOpen: s.computerOpen, error: s.error, notice: s.notice }), sameFields), dispatch = useStoreDispatch(), store = useStoreRef();
++ const state = useStoreSelector((s) => ({ computerStart: s.computerStarts[profile.id], mascotMotion: s.mascotMotion?.botId === profile.id ? s.mascotMotion : null, instances: s.instances, config: s.config, focusMessage: s.focusMessage, forkPanelOpen: s.forkPanel !== null, settingsOpen: s.settingsOpen, computerOpen: s.computerOpen, error: s.error, notice: s.notice }), sameFields), dispatch = useStoreDispatch(), store = useStoreRef();
const showThreads = useShowThreads();
const remoteClient = window.ogb?.remoteClient?.active === true;
const { dragProps: headerDragProps, noDragStyle: headerNoDragStyle } = useCaptionChrome();
@@@ -833,7 -826,16 +824,7 @@@
);
useEffect(() => setFindOpen(false), [bot.threadId]);
useChatFindRequests(bot.threadId, findOpen, setFindOpen);
- useChatFindShortcut(inForkPanel, Boolean(state.forkPanel), setFindOpen);
- useEffect(() => {
- const onFind = (event: KeyboardEvent) => {
- if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "f") {
- event.preventDefault();
- setFindOpen(true);
- }
- };
- window.addEventListener("keydown", onFind);
- return () => window.removeEventListener("keydown", onFind);
- }, []);
++ useChatFindShortcut(inForkPanel, state.forkPanelOpen, setFindOpen);
const { messages: allMessages, activeLeafId } = bot;
const messages = useMemo(() => visibleMessages({ messages: allMessages, activeLeafId }), [allMessages, activeLeafId]);
@@@ -898,10 -900,10 +889,10 @@@
const reactor = useReactor();
const speakerViewer = state.config?.team && reactor !== "user" ? reactor : null;
const rows = useMemo<ChatRows>(
- () => ({ botId: bot.id, threadId: bot.threadId, botName: bot.name, botColor: bot.color, voiceId: bot.voice, tts, localVoice, hasMore, bots, mentionPeers, mentionPerson: { profileName: state.config?.profile?.name }, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, conversational: isConversational(bot.replyStyle), simple: !advanced, canReact: canWrite !== false, openedAt, speakerViewer }),
- [bot.id, bot.threadId, bot.name, bot.color, bot.voice, tts, localVoice, hasMore, bots, mentionPeers, state.config?.profile?.name, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, bot.replyStyle, advanced, canWrite, openedAt, speakerViewer],
+ () => ({ botId: bot.id, threadId: bot.threadId, botName: bot.name, botColor: bot.color, voiceId: bot.voice, tts, localVoice, hasMore, bots, mentionPeers, mentionPerson: { profileName: state.config?.profile?.name }, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, conversational: isConversational(bot.replyStyle), simple: !advanced, canReact: canWrite !== false, openedAt, speakerViewer, phone }),
+ [bot.id, bot.threadId, bot.name, bot.color, bot.voice, tts, localVoice, hasMore, bots, mentionPeers, state.config?.profile?.name, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, bot.replyStyle, advanced, canWrite, openedAt, speakerViewer, phone],
);
- const currentTask = bot.tasks?.find((task) => task.threadId === bot.threadId), place = effectivePlace(bot, currentTask), team = state.config?.team, privateChat = Boolean(team) && (currentTask?.private === true || ownChatStarted(bot.threadId)), ownHelper = Boolean(team) && !privateChat && Boolean(bot.defaultBot?.person), sharedChat = Boolean(team) && !privateChat && !ownHelper;
+ const currentTask = bot.tasks?.find((task) => task.threadId === bot.threadId), place = effectivePlace(bot, currentTask), team = state.config?.team, privateChat = Boolean(team) && (currentTask?.private === true || (ownChatStarted(bot.threadId) && !currentTask?.shared)), ownHelper = Boolean(team) && !privateChat && Boolean(bot.defaultBot?.person), sharedChat = Boolean(team) && !privateChat && !ownHelper;
const [editingId, setEditingId] = useState<string | null>(null);
useEffect(() => setEditingId(null), [bot.id, bot.threadId]);
@@@ -1122,10 -1124,10 +1113,10 @@@
{(advanced || remoteClient) && <BotActivityPicker bot={bot} />}{privateChat && team && <TeamPrivateFirstLine key={team.id} team={team} />}
{routineExecution && <div className="mx-5 mb-2 flex flex-wrap items-center gap-2 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[12px] text-ink-secondary">
<span className="min-w-0 flex-1 truncate">{t("routines.executionDetails", { name: routineExecution.routineName })}</span>
- {canOpenResults && resultsThreadId && <button type="button" onClick={() => openThread(dispatch, { botId: bot.id, threadId: resultsThreadId }, state, showThreads)} className="rounded px-2 py-1 text-accent hover:bg-raised">{t("routines.results.back")}</button>}
+ {canOpenResults && resultsThreadId && <button type="button" onClick={() => openThread(dispatch, { botId: bot.id, threadId: resultsThreadId }, store.state(), showThreads)} className="rounded px-2 py-1 text-accent hover:bg-raised">{t("routines.results.back")}</button>}
<button type="button" onClick={() => dispatch({ type: "showRoutines", section: "logs", routineId: routineExecution.routineId, botId: bot.id })} className="rounded px-2 py-1 hover:bg-raised hover:text-ink">{t("routines.logs")}</button>
</div>}
- {findOpen && <ChatFindBar threadId={bot.threadId} onClose={() => setFindOpen(false)} />}
+ {findOpen && <ChatFindBar threadId={bot.threadId} inForkPanel={inForkPanel} onClose={() => setFindOpen(false)} />}
<ChatErrorBanner message={state.error} onDismiss={() => dispatch({ type: "error", message: null })} />
<ChatNotice notice={state.notice} />
diff --cc src/components/message-menu.tsx
index f68a8ad029,f5308aa48a..8f7bf07304
--- a/src/components/message-menu.tsx
+++ b/src/components/message-menu.tsx
@@@ -1,6 -1,7 +1,7 @@@
- import { Code, Copy, Eye, Pencil, Pin, PinOff, RefreshCw, Reply, Square, Volume2 } from "lucide-react";
-import { BookmarkPlus, Code, Copy, Eye, Pencil, Pin, PinOff, RefreshCw, Square, Volume2 } from "lucide-react";
++import { BookmarkPlus, Code, Copy, Eye, Pencil, Pin, PinOff, RefreshCw, Reply, Square, Volume2 } from "lucide-react";
import { copyText } from "@/lib/copy-text";
import { t } from "@/lib/i18n";
+ import { useContext } from "react";
import type { ConfigStatus, Group, Message, useStore } from "@/state/store";
import { ACTION_ICON, type MessageMenuItem } from "@/components/MessageActions";
import { useSpeakAction } from "@/components/SpeakButton";
diff --cc src/hooks/use-transcript-viewport.ts
index 017e6c095b,8096bf8ce1..d3fb70dc0a
--- a/src/hooks/use-transcript-viewport.ts
+++ b/src/hooks/use-transcript-viewport.ts
@@@ -100,17 -199,19 +199,19 @@@ export function useTranscriptViewport<
if (targetIndex < 0) return;
appliedFocus.current = focus.nonce;
const range = focusWindowRange(messages.length, targetIndex);
- setBottomFollow(false);
+ followEvent({ type: "navigated" });
+ followEvent({ type: "leftEnd" });
setTranscriptWindow({ key: transcriptKey, start: range.start, end: range.end });
- }, [threadId, messages, setBottomFollow, state.focusMessage, transcriptKey]);
+ }, [threadId, messages, followEvent, focusMessage, transcriptKey]);
- useFocusMessage(threadId, messages.length > 0);
+ useFocusMessage(threadId, messages.length > 0, scrollRef);
- // `follow` is omitted on purpose: re-arming only arms future content and never scrolls.
- useEffect(() => {
+ // Before paint, so a conversation opens at its end with no frame elsewhere. `follow` is omitted on purpose: re-arming
+ // only arms future content and never scrolls.
+ useLayoutEffect(() => {
const el = scrollRef.current;
- if (!el || !followRef.current) return;
+ if (!el) return;
+ if (!followRef.current) return noteLeftEnd();
el.scrollTo({ top: el.scrollHeight });
- previousScrollTop.current = el.scrollTop;
// eslint-disable-next-line react-hooks/exhaustive-deps -- pinOn is the caller's dependency list
}, [transcriptKey, messages.length, ...pinOn]);
diff --cc src/lib/focus-message.ts
index 1cb6cfe050,58d35a029b..78eb20f3fb
--- a/src/lib/focus-message.ts
+++ b/src/lib/focus-message.ts
@@@ -1,6 -1,7 +1,7 @@@
// Rows are `display: contents` wrappers with no box, so their last child is what gets scrolled and highlighted.
-import { useEffect } from "react";
+import { useEffect, type RefObject } from "react";
- import { api, MESSAGE_PAGE_SIZE, useStore, type Action, type AppState, type Message } from "@/state/store";
+ import { api, MESSAGE_PAGE_SIZE, type Action, type AppState, type Message } from "@/state/store";
+ import { useStoreDispatch, useStoreSelector } from "@/state/store-select";
import type { SearchHit } from "@/lib/search-hit";
import { t } from "@/lib/i18n";
@@@ -99,9 -100,8 +100,8 @@@ function matchRange(root: HTMLElement,
return null;
}
-export function useFocusMessage(threadId: string, ready: boolean) {
+export function useFocusMessage(threadId: string, ready: boolean, rootRef?: RefObject<HTMLElement | null>) {
- const { state, dispatch } = useStore();
- const focus = state.focusMessage;
+ const focus = useStoreSelector((state) => state.focusMessage), dispatch = useStoreDispatch();
useEffect(() => {
if (!focus || focus.consumed || focus.threadId !== threadId || !ready) return;
let tries = 0;
diff --cc src/state/read-visible.test.ts
index 7156a49e5b,0000000000..40526d1a5b
mode 100644,000000..100644
--- a/src/state/read-visible.test.ts
+++ b/src/state/read-visible.test.ts
@@@ -1,29 -1,0 +1,29 @@@
+import { expect, it } from "vitest";
+import { markVisibleBotThreadsRead, markVisibleGroupThreadsRead } from "./read-visible";
+import type { AppState, BotAnnouncement, Group } from "./store";
+
+it("marks both visible bot threads read while leaving a hidden task unread", () => {
+ const bot = { id: "bot", unread: true, tasks: [
- { threadId: "main", unread: true }, { threadId: "fork", unread: true }, { threadId: "hidden", unread: true },
++ { threadId: "main", unread: true, updatedAt: 10 }, { threadId: "fork", unread: true, updatedAt: 20 }, { threadId: "hidden", unread: true },
+ ] } as unknown as BotAnnouncement;
+ const state = { selectedId: "bot", activeView: "chat", bots: [{ id: "bot", threadId: "main" }],
+ forkPanel: { kind: "bot", ownerId: "bot", threadId: "fork" } } as unknown as AppState;
- const read: string[] = [];
- markVisibleBotThreadsRead(state, bot, true, (_path, threadId) => read.push(threadId));
- expect(read).toEqual(["main", "fork"]);
++ const read: Array<[string, number]> = [];
++ markVisibleBotThreadsRead(state, bot, true, (_path, threadId, updatedAt) => read.push([threadId, updatedAt]));
++ expect(read).toEqual([["main", 10], ["fork", 20]]);
+ expect(bot.tasks?.map((task) => task.unread)).toEqual([false, false, true]);
+ expect(bot.unread).toBe(true);
+});
+
+it("marks the main room and its open fork read", () => {
+ const group = { id: "room", unread: true, tasks: [
+ { threadId: "main", unread: true }, { threadId: "fork", unread: true }, { threadId: "hidden", unread: true },
+ ] } as Partial<Group> & { id: string };
+ const state = { selectedId: "room", activeView: "chat", groups: [{ id: "room", threadId: "main" }],
+ forkPanel: { kind: "group", ownerId: "room", threadId: "fork" } } as unknown as AppState;
+ const read: string[] = [];
+ markVisibleGroupThreadsRead(state, group, true, (_path, threadId) => read.push(threadId));
+ expect(read).toEqual(["main", "fork"]);
+ expect(group.tasks?.map((task) => task.unread)).toEqual([false, false, true]);
+ expect(group.unread).toBe(true);
+});
diff --cc src/state/read-visible.ts
index 60aab07f50,0000000000..35025b59b4
mode 100644,000000..100644
--- a/src/state/read-visible.ts
+++ b/src/state/read-visible.ts
@@@ -1,41 -1,0 +1,41 @@@
+import { botShowsUnread } from "@/lib/bot-unread";
+import type { AppState, BotAnnouncement, Group } from "./store";
+
- type SendRead = (path: string, threadId: string) => void;
++type SendRead = (path: string, threadId: string, updatedAt: number) => void;
+const sendRead: SendRead = (path, threadId) => {
+ void fetch(path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ threadId }) }).catch(() => {});
+};
+
+function visibleThreadIds(state: AppState, kind: "bot" | "group", ownerId: string, shown?: string): string[] {
+ const panel = state.forkPanel;
+ return [...new Set([shown, panel?.kind === kind && panel.ownerId === ownerId ? panel.threadId : undefined])]
+ .filter((threadId): threadId is string => Boolean(threadId));
+}
+
+export function markVisibleBotThreadsRead(state: AppState, bot: BotAnnouncement, focused: boolean, post: SendRead = sendRead): void {
+ if (bot.id !== state.selectedId || state.activeView !== "chat" || !focused) return;
+ const selected = state.bots.find((candidate) => candidate.id === bot.id);
+ const shown = selected?.switchingTo ?? selected?.threadId;
+ const visibleThreads = visibleThreadIds(state, "bot", bot.id, shown);
+ for (const threadId of visibleThreads) {
+ const task = bot.tasks?.find((candidate) => candidate.threadId === threadId);
+ if (!task?.unread && (bot.tasks || !bot.unread)) continue;
+ if (task) task.unread = false;
- post(`/api/bots/${bot.id}/read`, threadId);
++ post(`/api/bots/${bot.id}/read`, threadId, task?.updatedAt ?? 0);
+ }
+ bot.unread = bot.tasks ? botShowsUnread(bot) : false;
+}
+
+export function markVisibleGroupThreadsRead(state: AppState, group: Partial<Group> & { id: string }, focused: boolean,
+ post: SendRead = sendRead): void {
+ if (group.id !== state.selectedId || state.activeView !== "chat" || !focused) return;
+ const shown = state.groups.find((candidate) => candidate.id === group.id)?.threadId;
+ const visibleThreads = visibleThreadIds(state, "group", group.id, shown);
+ for (const threadId of visibleThreads) {
+ const task = group.tasks?.find((candidate) => candidate.threadId === threadId);
+ if (!task?.unread && (group.tasks || !group.unread)) continue;
+ if (task) task.unread = false;
- post(`/api/groups/${group.id}/read`, threadId);
++ post(`/api/groups/${group.id}/read`, threadId, task?.updatedAt ?? 0);
+ }
+ group.unread = group.tasks ? group.tasks.some((task) => task.unread) : false;
+}
diff --cc src/state/store.tsx
index 3569597792,a66fbbb808..b10009906f
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@@ -1,18 -1,7 +1,10 @@@
import { cloudAsleep, onCloudPower } from "../lib/cloud-power";
import { api, ApiError, retryRequest, snapshotArrays } from "./api";
+import { loadOlderPage, MESSAGE_PAGE_SIZE, reduceOlderMessages } from "./message-history";
+export { MESSAGE_PAGE_SIZE } from "./message-history";
+import { addForkOptimistic, reduceForkPanel, removeForkOptimistic, runForkEffect, type ForkPanelAction, type ForkPanelState } from "./fork-panel";
- import {
- createContext,
- useCallback,
- useContext,
- useEffect,
- useMemo,
- useReducer,
- useRef,
- type ReactNode,
- } from "react";
+ import { use, useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
+ import { createAppStore } from "./app-store"; import { readOneBot } from "./bot-read"; import { StoreContext, StoreSourceContext } from "./store-context";
import { flushSync } from "react-dom";
import type { BotMovedTo, BotVisibility, CardAnswerer, CloudBackend, ConnectorToolGrant, EffortLevel, InstalledPackageMetadata, LiveCallState, ServerFrame, GroupThreadUsage, ResolvedSender, SteerQueueReason, WireBot, WireGroup, WireTask, OptionCardData as WireOptionCard } from "../../shared/wire"; import type { InstanceEndpointInfo } from "../../shared/claude-endpoint";
import { movesThreadToTop } from "../../shared/wire"; import type { DefaultBotFields } from "../../shared/default-bot";
@@@ -221,10 -207,9 +213,10 @@@ export interface ModelSelection
variant?: string;
}
- export interface Task extends Pick<WireTask, "private" | "setupRequest" | "inbox" | "openAsks" | "askedBy"> {
+ export interface Task extends Pick<WireTask, "private" | "shared" | "sharedWith" | "setupRequest" | "inbox" | "openAsks" | "askedBy"> {
waitingForTeammates?: boolean; sharedChat?: true;
threadId: string;
+ origin?: import("../../shared/wire").ForkOrigin;
routineRunId?: string;
projectId?: string;
title: string;
@@@ -1004,14 -969,11 +983,14 @@@ export function reducer(state: AppState
};
case "showChat":
return state.activeView === "chat" ? state : { ...state, activeView: "chat" };
+ case "forkMessage": case "openForkPanel": case "forkPanelLoaded": case "forkPanelLoadFailed":
+ case "forkPanelMessage": case "forkPanelActive": case "closeForkPanel":
+ return reduceForkPanel(state, action);
case "showTeamMap":
- case "showFiles": case "showWebPanel":
+ case "showFiles": case "showWebPanel": case "showPublishedApps":
return {
...state,
- activeView: action.type === "showFiles" ? "files" : action.type === "showWebPanel" ? "web-panel" : "team-map",
+ activeView: action.type === "showFiles" ? "files" : action.type === "showWebPanel" ? "web-panel" : action.type === "showPublishedApps" ? "published-apps" : "team-map",
filesSuggest: action.type === "showFiles" && action.suggest?.length ? action.suggest : null, webPanelId: action.type === "showWebPanel" ? action.id : state.webPanelId,
settingsOpen: false, computerOpen: false, inspectorOpen: false, activityOpen: false, appSettingsOpen: false, pluginsOpen: false,
};
@@@ -3151,7 -3130,17 +3134,11 @@@ export function StoreProvider({ childre
break;
case "bot": {
const bot = frame.bot as BotAnnouncement;
- markVisibleBotThreadsRead(stateRef.current, bot, document.hasFocus());
- const selected = stateRef.current.bots.find((candidate) => candidate.id === bot.id);
- const shown = selected?.switchingTo ?? selected?.threadId;
- const selectedTask = bot.tasks?.find((task) => task.threadId === shown);
- if (bot.id === stateRef.current.selectedId && stateRef.current.activeView === "chat" && document.hasFocus() &&
- (selectedTask?.unread || (!bot.tasks && bot.unread))) {
- if (selectedTask) selectedTask.unread = false;
- bot.unread = botShowsUnread(bot);
- const read = `${bot.id}:${shown}`, newest = selectedTask?.updatedAt ?? 0, open = readsInFlight.get(read);
- if (!open) sendRead(bot.id, shown, read, newest);
++ markVisibleBotThreadsRead(stateRef.current, bot, document.hasFocus(), (_path, threadId, newest) => {
++ const read = `${bot.id}:${threadId}`, open = readsInFlight.get(read);
++ if (!open) sendRead(bot.id, threadId, read, newest);
+ else if (newest > open.covers) readsInFlight.set(read, { covers: newest, again: true });
- }
++ });
rawDispatch({
type: "botPatched",
bot: withTaskWrites({ ...bot, ...botPatchQueue.overlayFor(bot.id) }),