Skip to content

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

Blank chat Live call: a second Live press waits for the first start

AdityaUmale483eb1a7a63a
diff --git a/src/components/CallView.start-request.test.ts b/src/components/CallView.start-request.test.ts
index 46cd2b3ac5..2389636ae8 100644
--- a/src/components/CallView.start-request.test.ts
+++ b/src/components/CallView.start-request.test.ts
@@ -93,6 +93,27 @@ describe("a call started from the composer's + menu", () => {
expect(liveMedia()).toMatchObject({ phase: "starting", botId: "atlas", threadId: "made" });
});
+ it("waits for the blank chat's Live start when Live is pressed again before its settings are saved", () => {
+ render(newChatThreadId("atlas"));
+ flushSync(() => requestCallStart("atlas", "live"));
+ render("made");
+ flushSync(() => requestCallStart("atlas", "live"));
+ expect(liveMedia().phase).toBe("idle");
+ expect(fixture.dispatch).toHaveBeenCalledOnce();
+
+ flushSync(() => fixture.dispatch.mock.calls[0][0].onMade("made"));
+ expect(liveMedia()).toMatchObject({ phase: "starting", botId: "atlas", threadId: "made" });
+ });
+
+ it("lets Live be pressed again once making the blank chat's conversation failed", () => {
+ render(newChatThreadId("atlas"));
+ flushSync(() => requestCallStart("atlas", "live"));
+ flushSync(() => fixture.dispatch.mock.calls[0][0].onError());
+ render("made");
+ flushSync(() => requestCallStart("atlas", "live"));
+ expect(liveMedia()).toMatchObject({ phase: "starting", botId: "atlas", threadId: "made" });
+ });
+
it("never goes Live from a blank chat after a Turns call started and hung up while the conversation was being made", () => {
render(newChatThreadId("atlas"));
flushSync(() => requestCallStart("atlas", "live"));
diff --git a/src/components/CallView.tsx b/src/components/CallView.tsx
index 131445c385..6fc9e2a02f 100644
--- a/src/components/CallView.tsx
+++ b/src/components/CallView.tsx
@@ -178,20 +178,27 @@ export function CallTargetButton({
useEffect(() => () => dismissStartPrompt(targetId), [targetId]);
- // A Live call from a blank chat starts once its conversation is made; a later start or a Turns call cancels it.
+ // A Live call from a blank chat starts once its conversation is made and its held settings are saved; a later start
+ // or a Turns call cancels it, and pressing Live again meanwhile waits for that same start.
const liveRequest = useRef(0);
+ const waitingLive = useRef(0);
useEffect(() => { if (onCall) liveRequest.current++; }, [onCall]);
const start = (next: CallMode) => {
setHelpOpen(false);
setMenuOpen(false);
+ if (next === "live" && waitingLive.current && waitingLive.current === liveRequest.current) return;
const request = ++liveRequest.current;
if (next === "live" && liveThreadId !== undefined) {
onStart("live");
const live = (thread: string) => {
+ if (waitingLive.current === request) waitingLive.current = 0;
if (liveRequest.current === request) void startLiveCall({ botId: targetId, threadId: thread, provider: state.config?.live?.provider });
};
- if (isNewChatThread(liveThreadId)) dispatch({ type: "makeNewChat", botId: targetId, threadId: liveThreadId, onMade: live });
- else live(liveThreadId);
+ if (isNewChatThread(liveThreadId)) {
+ waitingLive.current = request;
+ const failed = () => { if (waitingLive.current === request) waitingLive.current = 0; };
+ dispatch({ type: "makeNewChat", botId: targetId, threadId: liveThreadId, onMade: live, onError: failed });
+ } else live(liveThreadId);
return;
}
if (!turnsReady) {
diff --git a/src/state/new-chat.test.ts b/src/state/new-chat.test.ts
index 971b445b34..94de0a0783 100644
--- a/src/state/new-chat.test.ts
+++ b/src/state/new-chat.test.ts
@@ -326,6 +326,15 @@ describe("a new conversation opens blank and is made by its first send", () => {
await vi.waitFor(() => expect(made).toHaveBeenCalledExactlyOnceWith("made"));
});
+ it("tells a Live call from a blank chat that is no longer open that no conversation is coming", () => {
+ const made = vi.fn();
+ const failed = vi.fn();
+ flushSync(() => dispatch({ type: "makeNewChat", botId: "bot", threadId: DRAFT, onMade: made, onError: failed }));
+ expect(failed).toHaveBeenCalledOnce();
+ expect(made).not.toHaveBeenCalled();
+ expect(creates).toEqual([]);
+ });
+
it("makes one conversation for a Live call and a send that start together", async () => {
const made = vi.fn();
openBlank();
diff --git a/src/state/new-chat.ts b/src/state/new-chat.ts
index 568fa835c8..31ca7f9e15 100644
--- a/src/state/new-chat.ts
+++ b/src/state/new-chat.ts
@@ -5,7 +5,7 @@ import type { Action, AppState, Bot } from "./store";
export type NewChat = { session: number; botId: string; projectId?: string; held: HeldAction[] };
type HeldAction = Extract<Action, { type: "setModel" } | { type: "updateTask" }>;
/** Makes the conversation a bot's blank chat stands for, as its first send would, and answers with its thread. */
-export type MakeNewChatAction = { type: "makeNewChat"; botId: string; threadId: string; onMade: (threadId: string) => void };
+export type MakeNewChatAction = { type: "makeNewChat"; botId: string; threadId: string; onMade: (threadId: string) => void; onError?: () => void };
const THREAD_PREFIX = "new-chat-";
export const newChatThreadId = (botId: string) => `${THREAD_PREFIX}${botId}`;
@@ -88,8 +88,13 @@ export function createNewChat(effects: Effects) {
if (!intoBlank && !("threadId" in action && isNewChatThread(action.threadId))) return false;
const conversationFor = (botId: string) => open?.botId === botId ? making.get(open.session) ?? make(open) : null;
if (action.type === "makeNewChat") {
- conversationFor(action.botId)?.then((threadId) => effects.settled(action.botId, threadId).then(() => action.onMade(threadId)))
- .catch(effects.showError);
+ const made = conversationFor(action.botId);
+ if (!made) action.onError?.();
+ else made.then((threadId) => effects.settled(action.botId, threadId).then(() => action.onMade(threadId)))
+ .catch((error: unknown) => {
+ action.onError?.();
+ effects.showError(error);
+ });
return true;
}
if (action.type !== "send") {