Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

Ask: a question sent while the chat is still loading goes out once, when it loads

Eric Brownrout4870878b6d86
diff --git a/app/src/renderer/src/components/AskConversation.tsx b/app/src/renderer/src/components/AskConversation.tsx
index c58d491b..13fd4785 100644
--- a/app/src/renderer/src/components/AskConversation.tsx
+++ b/app/src/renderer/src/components/AskConversation.tsx
@@ -27,14 +27,15 @@ const starters = (chips: ContextTarget[], recording: boolean) => chips.length ==
: [t('What are my next steps this week?'), t('What did we decide last week?'), t('Catch me up on yesterday')]
/** One composer and thread for both the page and the note panel. Draft writes never wait for the model. */
-export function AskConversation({ id, pendingDraftKey, initial, home = false, panel = false, recording = false, onSelect, onSource, onDeleted, onClose, onExpand }: {
- id: string; pendingDraftKey?: string; initial?: ConversationView; home?: boolean; panel?: boolean; recording?: boolean; onDeleted: () => void; onClose?: () => void; onExpand?: () => void; onSelect: (id: string) => void; onSource: (source: LibrarySource, match?: string) => void
+export function AskConversation({ id, pendingDraftKey, initial, loadError = false, home = false, panel = false, recording = false, onSelect, onSource, onDeleted, onClose, onExpand }: {
+ id: string; pendingDraftKey?: string; initial?: ConversationView; loadError?: boolean; home?: boolean; panel?: boolean; recording?: boolean; onDeleted: () => void; onClose?: () => void; onExpand?: () => void; onSelect: (id: string) => void; onSource: (source: LibrarySource, match?: string) => void
}) {
const [chat, setChat] = useState(initial)
const [text, setText] = useState((pendingDraftKey ? drafts.get(pendingDraftKey) : undefined) ?? drafts.get(id) ?? initial?.draft ?? '')
const edited = useRef(false)
const [error, setError] = useState(false)
const [sending, setSending] = useState(false)
+ const pendingQuestion = useRef<string>(undefined)
const [changing, setChanging] = useState(false)
const [mention, setMention] = useState<{ start: number; end: number; query: string }>()
const [targetResults, setTargetResults] = useState<{ query: string; items: ContextTarget[] }>()
@@ -70,7 +71,12 @@ export function AskConversation({ id, pendingDraftKey, initial, home = false, pa
if (first) {
if (!initial && !edited.current) setText(drafts.get(id) ?? v.draft)
}
- }).catch(() => { if (active && request === revision) setError(true) })
+ }).catch(() => {
+ if (active && request === revision) {
+ setError(true)
+ if (pendingQuestion.current !== undefined) { pendingQuestion.current = undefined; setSending(false) }
+ }
+ })
}
const offMeetings = window.yogurt.meetings.onChange(() => load())
const offFolders = window.yogurt.folders.onChange(() => load())
@@ -137,16 +143,28 @@ export function AskConversation({ id, pendingDraftKey, initial, home = false, pa
}
// Sending from the box (Enter, the send button or a starter) keeps the person in it; the button turns into Stop and starters go. A disabled field would drop focus, so it is read-only while saving.
const keepTyping = () => { const from = document.activeElement; if (from === document.body || from?.closest('.ask-box, .ask-starters')) input.current?.focus({ preventScroll: true }) }
- const send = (q: string) => {
- if (!q.trim() || busy) return
- keepTyping()
- follow.resume(); setSending(true); setError(false); setMention(undefined)
+ const submit = (q: string) => {
void window.yogurt.conversations.ask(id, q).then(made => {
if (!made) throw new Error('Question was not saved')
setText(''); drafts.delete(id)
if (home) onSelect(made)
}).catch(() => { saveText(q); setError(true) }).finally(() => setSending(false))
}
+ const send = (q: string) => {
+ if (!q.trim() || sending || changing || answering || loadError || (!chat && (!panel || error))) return
+ keepTyping()
+ follow.resume(); setSending(true); setError(false); setMention(undefined)
+ // Typing is available before the conversation loads; Enter must survive that handoff too.
+ if (!chat) { pendingQuestion.current = q; return }
+ submit(q)
+ }
+ useEffect(() => {
+ if (loadError) { pendingQuestion.current = undefined; setSending(false); return }
+ if (!chat || pendingQuestion.current === undefined) return
+ const question = pendingQuestion.current
+ pendingQuestion.current = undefined
+ submit(question)
+ }, [chat, loadError])
const key = (e: KeyboardEvent<HTMLTextAreaElement>) => {
if (e.nativeEvent.isComposing) return
if (mention && ['ArrowDown', 'ArrowUp', 'Enter', 'Escape'].includes(e.key)) {
diff --git a/app/src/renderer/src/components/Chat.tsx b/app/src/renderer/src/components/Chat.tsx
index afb855ce..5ef4bccd 100644
--- a/app/src/renderer/src/components/Chat.tsx
+++ b/app/src/renderer/src/components/Chat.tsx
@@ -119,7 +119,7 @@ export function Ask({ id, recording, anchor, onSource }: { id: string; recording
<div ref={surface} className="chat-morph-surface" aria-hidden="true" />
<div ref={contents} className="chat-panel-contents">
{error && <p role="alert">{t("Yogurt couldn't answer that.")}</p>}
- <AskConversation key={`${id}/${conversationVersion}`} id={conversationId ?? ''} pendingDraftKey={`meeting/${id}`} panel recording={recording} onSelect={next => { setConversationId(next); setConversationVersion(version => version + 1) }} onClose={() => close()}
+ <AskConversation key={`${id}/${conversationVersion}`} id={conversationId ?? ''} pendingDraftKey={`meeting/${id}`} loadError={error} panel recording={recording} onSelect={next => { setConversationId(next); setConversationVersion(version => version + 1) }} onClose={() => close()}
onExpand={conversationId ? () => { rememberScrollPositions(); close(false); window.yogurt.nav.go(`/chat/${conversationId}`) } : undefined}
onDeleted={() => { close(false); setConversationId(undefined); window.yogurt.nav.go('/chat') }}
onSource={(source, match) => { close(false); onSource(source, match) }} />
diff --git a/app/test/motionInteractions.test.ts b/app/test/motionInteractions.test.ts
index 4f52b5d9..4dc0dd23 100644
--- a/app/test/motionInteractions.test.ts
+++ b/app/test/motionInteractions.test.ts
@@ -2,6 +2,8 @@ import { afterEach, expect, it, vi } from 'vitest'
import { useEffect, useLayoutEffect, useRef, useState, type ReactElement, type ReactNode } from 'react'
import { Search } from '../src/renderer/src/components/Search'
import { Ask } from '../src/renderer/src/components/Chat'
+import { AskConversation } from '../src/renderer/src/components/AskConversation'
+import type { ConversationView } from '../src/shared/types'
import { Workspace } from '../src/renderer/src/components/Workspace'
import { FoldersNav } from '../src/renderer/src/components/FoldersNav'
@@ -218,3 +220,59 @@ it.each([false, true])('keeps the composer clip inside the growing shape through
find(tree, 'chat-open').props.onClick()
check(false)
})
+
+
+it.each(['send', 'load', 'resolve'] as const)('keeps an early Enter through loading, without duplicate requests or a lost draft (%s failure)', async failure => {
+ let id = '', loadError = false
+ let loaded!: (view: ConversationView) => void, loadFailed!: (error: Error) => void, rejected!: (error: Error) => void
+ const get = vi.fn(() => new Promise<ConversationView>((resolve, reject) => { loaded = resolve; loadFailed = reject }))
+ const ask = vi.fn(() => new Promise<string>((_resolve, reject) => { rejected = reject }))
+ const draft = vi.fn().mockResolvedValue(undefined)
+ const body = {}
+ vi.stubGlobal('document', { body, activeElement: body })
+ vi.stubGlobal('window', { yogurt: {
+ conversations: { get, ask, draft, onChange: () => () => {} },
+ meetings: { onChange: () => () => {} }, folders: { onChange: () => () => {} },
+ } })
+ const render = renderer(() => AskConversation({ id, loadError, pendingDraftKey: `meeting/early-${failure}`, panel: true, onSelect() {}, onDeleted() {}, onSource() {} }))
+ const flush = async () => { for (let i = 0; i < 5; i++) await Promise.resolve() }
+ const drain = () => vi.mocked(useEffect).mock.calls.find(([, deps]) => deps?.length === 2 && deps[1] === loadError)![0]()
+ const enter = (tree: ReactNode) => find(tree, 'chat-input').props.onKeyDown({ key: 'Enter', nativeEvent: {}, preventDefault() {} })
+ let tree = render()
+ const focus = vi.fn()
+ find(tree, 'chat-input').props.ref.current = { focus }
+ find(tree, 'chat-input').props.onChange({ target: { value: 'Who owns the next step?', selectionStart: 23 } })
+ tree = render()
+ enter(tree)
+ tree = render()
+ expect(find(tree, 'chat-input').props.readOnly).toBe(true)
+ expect(focus).toHaveBeenCalledWith({ preventScroll: true })
+ enter(tree)
+ expect(ask).not.toHaveBeenCalled()
+ if (failure === 'resolve') {
+ loadError = true
+ tree = render(); drain(); tree = render()
+ } else {
+ id = `early-${failure}`
+ tree = render()
+ vi.mocked(useEffect).mock.calls.find(([, deps]) => deps?.length === 1 && deps[0] === id)![0]()
+ if (failure === 'load') loadFailed(new Error('read failed'))
+ else loaded({ id, title: '', draft: '', chips: [], draftChips: [], firstChips: null, turns: [], waitsForMeeting: false, waitsForModel: false })
+ await flush()
+ tree = render(); drain(); tree = render(); drain()
+ if (failure === 'send') {
+ enter(tree)
+ expect(ask).toHaveBeenCalledExactlyOnceWith(id, 'Who owns the next step?')
+ rejected(new Error('request failed'))
+ await flush()
+ } else expect(ask).not.toHaveBeenCalled()
+ tree = render()
+ }
+ expect(find(tree, 'chat-input').props.readOnly).toBe(false)
+ expect(find(tree, 'chat-input').props.value).toBe('Who owns the next step?')
+ if (failure === 'send') {
+ expect(find(tree, 'chat-send').props.disabled).toBe(false)
+ enter(tree)
+ expect(ask).toHaveBeenCalledTimes(2)
+ }
+})