From c3e641c3c01fcb9b462d96b5a277783b0ba3b1b5 Mon Sep 17 00:00:00 2001 From: lvbaiqing Date: Wed, 18 Nov 2026 23:32:17 +0800 Subject: [PATCH 01/56] fix(ui): share the searchable desktop language picker --- .../app/e2e/desktop-onboarding.spec.ts | 25 +++++++++ .../e2e/settings-appearance-layout.spec.ts | 22 ++++++++ .../features/onboarding/DesktopOnboarding.tsx | 43 ++++++---------- .../onboarding/desktop-onboarding.css | 20 +++++--- .../settings/sections/LanguageSection.tsx | 26 ++-------- .../ui/controls/InterfaceLanguagePicker.tsx | 51 +++++++++++++++++++ openless-all/app/src/ui/styles/select.css | 4 +- 7 files changed, 133 insertions(+), 58 deletions(-) create mode 100644 openless-all/app/src/ui/controls/InterfaceLanguagePicker.tsx diff --git a/openless-all/app/e2e/desktop-onboarding.spec.ts b/openless-all/app/e2e/desktop-onboarding.spec.ts index 48650561e..12e814e62 100644 --- a/openless-all/app/e2e/desktop-onboarding.spec.ts +++ b/openless-all/app/e2e/desktop-onboarding.spec.ts @@ -230,6 +230,8 @@ test('text reveals progressively without shifting layout and input focus uses an const input = page.getByRole('textbox', { name: '怎么称呼你?(选填)' }); await input.click(); await expect(input).toHaveCSS('outline-style', 'none'); + await expect(input).toHaveCSS('padding-inline-start', '12px'); + await expect(input).toHaveCSS('padding-inline-end', '12px'); const before = (await input.boundingBox())!; const reveal = await page.locator('.ol-reveal-glyph').evaluateAll((elements) => elements @@ -253,6 +255,29 @@ test('text reveals progressively without shifting layout and input focus uses an expect(Math.abs(before.y - after.y)).toBeLessThan(1); }); +test('onboarding uses the shared searchable language popup above the footer', async ({ page }) => { + await page.setViewportSize({ width: 390, height: 700 }); + await page.goto('/?onboarding=1&os=mac'); + const footer = page.locator('.ol-guide-footer'); + const trigger = footer.locator('.ol-select-trigger'); + await expect(footer.getByText('Language:', { exact: true })).toBeVisible(); + await expect(trigger).toHaveAccessibleName('Language'); + await expect(trigger).toContainText('简体中文'); + await trigger.click(); + const popup = page.locator('.ol-select-positioner[data-side="top"] .ol-select-popup'); + const search = popup.getByPlaceholder('搜索语言…'); + await expect(popup).toBeInViewport({ ratio: 1 }); + await expect(search).toBeFocused(); + await expect(search).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)'); + await search.fill('English'); + await expect(popup.getByRole('option')).toHaveCount(1); + await popup.getByRole('option', { name: 'English' }).click(); + await expect(page.getByRole('heading', { name: 'Hi, this is OpenLess' })).toBeVisible(); + await expect(trigger).toContainText('English'); + await page.reload(); + await expect(trigger).toContainText('English'); +}); + test('model setup stays in its own dialog and returns to the unchanged centered step', async ({ page, }) => { diff --git a/openless-all/app/e2e/settings-appearance-layout.spec.ts b/openless-all/app/e2e/settings-appearance-layout.spec.ts index 615d2ee79..d189d8b19 100644 --- a/openless-all/app/e2e/settings-appearance-layout.spec.ts +++ b/openless-all/app/e2e/settings-appearance-layout.spec.ts @@ -91,3 +91,25 @@ for (const profile of [ } }); } + + +test('the settings language popup paints one search field and filters languages', async ({ page }) => { + await page.goto('/?os=mac'); + await page.getByRole('button', { name: '设置', exact: true }).click(); + const dialog = page.getByRole('dialog', { name: '设置', exact: true }); + await dialog.getByRole('button', { name: '外观与语言', exact: true }).click(); + await settleNavigation(dialog); + const language = dialog.locator('.ol-select-trigger[aria-label="语言"]'); + await language.click(); + const popup = page.locator('.ol-select-positioner[data-open] .ol-select-popup'); + const search = popup.getByPlaceholder('搜索语言…'); + await expect(search).toBeFocused(); + await expect(search).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)'); + await expect(search).toHaveCSS('border-top-width', '0px'); + await search.fill('Deutsch'); + await expect(popup.getByRole('option')).toHaveCount(1); + await expect(popup.getByRole('option', { name: 'Deutsch' })).toBeVisible(); + await page.keyboard.press('Escape'); + await expect(popup).toHaveCount(0); + await expect(dialog).toBeVisible(); +}); diff --git a/openless-all/app/src/features/onboarding/DesktopOnboarding.tsx b/openless-all/app/src/features/onboarding/DesktopOnboarding.tsx index 5ffe90de4..be41abbc7 100644 --- a/openless-all/app/src/features/onboarding/DesktopOnboarding.tsx +++ b/openless-all/app/src/features/onboarding/DesktopOnboarding.tsx @@ -15,21 +15,12 @@ import { ModelSetupDialog } from './ModelSetupDialog'; import { ShortcutRecorder } from '../../components/ShortcutRecorder'; import { RevealText } from '../../components/ui/RevealText'; import { TransitionViewport } from '../../components/ui/TransitionViewport'; -import { setLocalePreference, SUPPORTED_LOCALES, type SupportedLocale } from '../../i18n'; +import { setLocalePreference } from '../../i18n'; +import { InterfaceLanguagePicker } from '../../ui/controls/InterfaceLanguagePicker'; import { ProviderLeaveContext } from '../providers/ProviderForm'; import './desktop-onboarding.css'; import { granted, useDesktopGuide } from './useDesktopGuide'; -const localeLabels = [ - '简体中文', - '繁體中文', - 'English', - '日本語', - '한국어', - 'Español', - 'Français', - 'Deutsch', -]; export function DesktopOnboarding({ onComplete }: { onComplete: () => void | Promise }) { const { t, @@ -378,24 +369,20 @@ export function DesktopOnboarding({ onComplete }: { onComplete: () => void | Pro />
{preview ? t('desktopGuide.preview') : ''} - + includeSystem={false} + side="top" + /> +
diff --git a/openless-all/app/src/features/onboarding/desktop-onboarding.css b/openless-all/app/src/features/onboarding/desktop-onboarding.css index 1cdf2bd93..103a1dcdf 100644 --- a/openless-all/app/src/features/onboarding/desktop-onboarding.css +++ b/openless-all/app/src/features/onboarding/desktop-onboarding.css @@ -85,9 +85,10 @@ background: transparent; color: inherit; border-radius: 0; - padding: 11px 0; + padding: 11px 12px; font: inherit; font-size: 14px; + line-height: 1.5; } .ol-guide button, .ol-guide select { @@ -254,13 +255,18 @@ font-size: 11px; flex-shrink: 0; } -.ol-guide-footer select { +.ol-guide-language { + display: flex; + align-items: center; + gap: 8px; + min-width: 0; + margin-inline-start: auto; color: var(--ol-ink-2); - background: var(--ol-surface); - border: 1px solid var(--ol-line); - border-radius: var(--ol-surface-radius); - padding: 6px 10px; - max-width: 160px; + font-size: 12.5px; +} +.ol-guide-language .ol-select-trigger { + width: 160px; + min-width: 0; } .ol-onboarding-layer { diff --git a/openless-all/app/src/features/settings/sections/LanguageSection.tsx b/openless-all/app/src/features/settings/sections/LanguageSection.tsx index 275d18d4a..15d9e2d96 100644 --- a/openless-all/app/src/features/settings/sections/LanguageSection.tsx +++ b/openless-all/app/src/features/settings/sections/LanguageSection.tsx @@ -1,6 +1,6 @@ // UI language is persisted separately; it never overwrites working languages or the translation target. -import { useEffect, useMemo, useState } from 'react'; +import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FOLLOW_SYSTEM, @@ -8,7 +8,7 @@ import { setLocalePreference, type SupportedLocale, } from '../../../i18n/index'; -import { SelectLite } from '../../../ui/controls/SelectLite'; +import { InterfaceLanguagePicker } from '../../../ui/controls/InterfaceLanguagePicker'; import { Card } from '../../../ui/layout/Card'; import { SectionTitle } from '../../../ui/layout/SectionTitle'; import { SettingRow } from '../../../ui/controls/SettingRow'; @@ -19,21 +19,6 @@ export function LanguageSection() { useEffect(() => setPref(getLocalePreference()), [i18n.resolvedLanguage]); - const options = useMemo( - () => [ - { value: FOLLOW_SYSTEM, label: t('settings.language.followSystem') }, - { value: 'zh-CN', label: t('settings.language.zh') }, - { value: 'zh-TW', label: t('settings.language.zhTW') }, - { value: 'en', label: t('settings.language.en') }, - { value: 'ja', label: t('settings.language.ja') }, - { value: 'ko', label: t('settings.language.ko') }, - { value: 'es', label: t('settings.language.es') }, - { value: 'fr', label: t('settings.language.fr') }, - { value: 'de', label: t('settings.language.de') }, - ], - [t], - ); - const apply = async (next: SupportedLocale | typeof FOLLOW_SYSTEM) => { setPref(next); // Interface language is independent from speech recognition and translation targets. @@ -44,13 +29,10 @@ export function LanguageSection() { {t('settings.language.title')} - apply(next as SupportedLocale | typeof FOLLOW_SYSTEM)} - options={options} + onChange={apply} ariaLabel={t('settings.language.label')} - searchable - searchPlaceholder={t('modal.searchPlaceholder')} /> diff --git a/openless-all/app/src/ui/controls/InterfaceLanguagePicker.tsx b/openless-all/app/src/ui/controls/InterfaceLanguagePicker.tsx new file mode 100644 index 000000000..49cb7ddf9 --- /dev/null +++ b/openless-all/app/src/ui/controls/InterfaceLanguagePicker.tsx @@ -0,0 +1,51 @@ +import { useTranslation } from 'react-i18next'; +import { FOLLOW_SYSTEM, SUPPORTED_LOCALES, type SupportedLocale } from '../../i18n'; +import { SelectLite } from './SelectLite'; + +type LocalePreference = SupportedLocale | typeof FOLLOW_SYSTEM; + +const labelKeys: Record = { + 'zh-CN': 'zh', + 'zh-TW': 'zhTW', + en: 'en', + ja: 'ja', + ko: 'ko', + es: 'es', + fr: 'fr', + de: 'de', +}; + +export function InterfaceLanguagePicker({ + value, + onChange, + ariaLabel, + side, + includeSystem = true, +}: { + value: string; + onChange: (next: LocalePreference) => void; + ariaLabel: string; + side?: 'top' | 'bottom'; + includeSystem?: boolean; +}) { + const { t } = useTranslation(); + const options = SUPPORTED_LOCALES.map((locale) => ({ + value: locale as LocalePreference, + label: t(`settings.language.${labelKeys[locale]}`), + })); + if (includeSystem) + options.unshift({ value: FOLLOW_SYSTEM, label: t('settings.language.followSystem') }); + + return ( + onChange(next as LocalePreference)} + ariaLabel={ariaLabel} + side={side} + searchable + searchPlaceholder={t('translation.searchLanguages')} + emptyMessage={t('translation.noMatchingLanguages')} + /> + ); +} diff --git a/openless-all/app/src/ui/styles/select.css b/openless-all/app/src/ui/styles/select.css index abd2a2da7..93a7b7027 100644 --- a/openless-all/app/src/ui/styles/select.css +++ b/openless-all/app/src/ui/styles/select.css @@ -155,9 +155,11 @@ html[data-ol-input='pointer'] .ol-select-trigger:focus-visible { .ol-select-search input { flex: 1; min-width: 0; + padding: 0; border: 0; outline: 0; - background: transparent; + /* The search wrapper is the only field surface. */ + background-color: transparent !important; color: inherit; font: inherit; } From 18abcd795751e95a7e1c16134889fc1105c3c968 Mon Sep 17 00:00:00 2001 From: lvbaiqing Date: Wed, 18 Nov 2026 23:50:47 +0800 Subject: [PATCH 02/56] Redesign Ask Anything around a modular prompt box --- openless-all/app/e2e/ask-anything.spec.ts | 114 ++++- .../app/e2e/aux-window-geometry.spec.ts | 7 +- .../app/e2e/capsule-reference-motion.spec.ts | 8 +- .../app/e2e/fixtures/capsule-motion.tsx | 9 +- openless-all/app/src-tauri/src/lib.rs | 65 ++- .../app/src/features/qa/QaComposer.tsx | 122 ++++++ openless-all/app/src/features/qa/QaPanel.tsx | 327 +++----------- .../app/src/features/qa/QaPromptBox.tsx | 109 +++++ .../src/features/qa/QaStreamingResponse.tsx | 63 +++ openless-all/app/src/features/qa/qa-panel.css | 411 +++--------------- .../app/src/features/qa/qa-prompt-box.css | 204 +++++++++ .../app/src/features/qa/useQaWindowLayout.ts | 3 +- openless-all/app/src/i18n/de.ts | 1 + openless-all/app/src/i18n/en.ts | 1 + openless-all/app/src/i18n/es.ts | 1 + openless-all/app/src/i18n/fr.ts | 1 + openless-all/app/src/i18n/ja.ts | 1 + openless-all/app/src/i18n/ko.ts | 1 + openless-all/app/src/i18n/zh-CN.ts | 1 + openless-all/app/src/i18n/zh-TW.ts | 1 + openless-all/app/src/lib/messageFollow.ts | 5 +- .../app/src/styles/continuous-corners.css | 12 +- 22 files changed, 814 insertions(+), 653 deletions(-) create mode 100644 openless-all/app/src/features/qa/QaComposer.tsx create mode 100644 openless-all/app/src/features/qa/QaPromptBox.tsx create mode 100644 openless-all/app/src/features/qa/QaStreamingResponse.tsx create mode 100644 openless-all/app/src/features/qa/qa-prompt-box.css diff --git a/openless-all/app/e2e/ask-anything.spec.ts b/openless-all/app/e2e/ask-anything.spec.ts index d9bcd6d7f..e83be779b 100644 --- a/openless-all/app/e2e/ask-anything.spec.ts +++ b/openless-all/app/e2e/ask-anything.spec.ts @@ -83,7 +83,7 @@ test('Ask opens a conversation on record, streams activity, and keeps a composer }); await expect(page.locator('.qa-answer-panel')).toBeVisible(); await expect(page.locator('.qa-recording-selection')).toContainText('selected source'); - await expect(page.locator('#native-host')).toHaveCSS('width', '720px'); + await expect(page.locator('#native-host')).toHaveCSS('width', '975px'); await emit(page, 'qa:state', { kind: 'thinking', sessionId: 'ask-a', messages: [] }); await emit(page, 'qa:state', { kind: 'activity', @@ -112,7 +112,7 @@ test('Ask opens a conversation on record, streams activity, and keeps a composer await expect(page.locator('.qa-assistant-message')).toContainText('最终回答'); await expect(page.locator('.qa-thought')).toContainText('已思考'); await expect(page.locator('.qa-follow-up')).toHaveCount(0); - await expect(page.locator('.qa-prompt input')).toBeVisible(); + await expect(page.locator('.qa-prompt textarea')).toBeVisible(); await expect(page.locator('.qa-prompt .qa-close')).toHaveCount(0); await page.screenshot({ path: info.outputPath('ask-result.png') }); }); @@ -148,7 +148,7 @@ test('Stop cancels the current turn and retains the open conversation for a foll await expect(page.locator('.qa-answer-panel')).toBeVisible(); await expect(page.locator('.qa-assistant-message')).toContainText('first answer'); await expect(page.getByText('draft answer')).toHaveCount(0); - await expect(page.locator('.qa-prompt input')).toBeEnabled(); + await expect(page.locator('.qa-prompt textarea')).toBeEnabled(); await expect(stop).toHaveCount(0); }); @@ -166,3 +166,111 @@ test('overview is restored and the Ask page remains without the added three-row await expect(page.locator('.ol-recording-key-guide')).toHaveCount(0); await expect(page.getByText('保存历史', { exact: true })).toBeVisible(); }); + +test('the macOS prompt box preserves the draft through the voice chord and allows multiline text', async ({ + page, +}) => { + await page.addInitScript(() => + Object.defineProperty(navigator, 'platform', { value: 'MacIntel' }), + ); + await page.goto(fixture + '?qa'); + await expect(page.locator('.ol-default-capsule')).toBeVisible(); + const firstTurn = [ + { role: 'user', content: 'First question' }, + { role: 'assistant', content: 'First answer' }, + ]; + await emit(page, 'qa:state', { kind: 'answer', sessionId: 'first', messages: firstTurn }); + const panel = page.locator('.qa-conversation'); + await expect(panel).toHaveCSS('border-radius', '0px'); + const close = panel.locator('.qa-close'); + await expect(close).toHaveCSS('border-radius', '50%'); + await expect(panel.locator('.qa-window-actions')).toHaveCSS('left', '10px'); + const draft = panel.locator('textarea'); + await draft.fill('typed'); + await draft.press('Space'); + await draft.press('Shift+Enter'); + await draft.press('a'); + const typed = 'typed \na'; + await expect(draft).toHaveValue(typed); + expect((await draft.boundingBox())!.height).toBeGreaterThan(24); + + // WKWebView does not always expose Fn; the native hook consumes the chord first. + // When a browser reports it, the editor must also not insert a space. + const leakedChordPrevented = await draft.evaluate((editor) => { + const key = new KeyboardEvent('keydown', { key: ' ', bubbles: true, cancelable: true }); + Object.defineProperty(key, 'getModifierState', { value: (name: string) => name === 'Fn' }); + return !editor.dispatchEvent(key); + }); + expect(leakedChordPrevented).toBe(true); + await emit(page, 'qa:state', { kind: 'recording', sessionId: 'voice', messages: firstTurn }); + await expect(draft).toHaveAttribute('readonly', ''); + await expect(draft).toHaveAttribute('placeholder', '你正在进行语音输入'); + await expect(panel.locator('.voice-waveform-label')).toHaveText('你正在进行语音输入'); + await expect(draft).toHaveValue(typed); + await emit(page, 'qa:state', { kind: 'cancelled', sessionId: 'voice', messages: firstTurn }); + await expect(draft).toBeEditable(); + await expect(draft).toHaveValue(typed); + await draft.press('Enter'); + await expect + .poll(() => page.evaluate(() => (window as any).fixture.qaActions.at(-1))) + .toMatchObject({ + command: 'qa_submit_text', + args: { text: typed, expectedSessionId: 'voice' }, + }); +}); + +test('the Windows conversation clips and scrolls streamed text, and opens live and final source links', async ({ + page, +}) => { + await page.addInitScript(() => { + localStorage.setItem('ol.locale', 'en'); + Object.defineProperty(navigator, 'platform', { value: 'Win32' }); + }); + await page.goto(fixture + '?qa'); + await expect(page.locator('.ol-default-capsule')).toBeVisible(); + await emit(page, 'qa:state', { kind: 'recording', sessionId: 'search', messages: [] }); + const panel = page.locator('.qa-conversation'); + const close = panel.locator('.qa-close'); + await expect(panel).toHaveAttribute('data-platform', 'win'); + await expect(panel.locator('.qa-window-actions')).toHaveCSS('right', '10px'); + await expect(close).toHaveCSS('border-radius', '50%'); + await expect(panel.locator('textarea')).toHaveAttribute( + 'placeholder', + 'You are using voice input', + ); + await expect(panel).toHaveCSS('overflow', 'hidden'); + await expect(panel).toHaveCSS('width', '975px'); + await expect(panel).toHaveCSS('height', '415px'); + const question = { role: 'user', content: 'What are the sources?' }; + await emit(page, 'qa:state', { kind: 'thinking', sessionId: 'search', messages: [question] }); + const response = panel.locator('.qa-assistant-message'); + await response.evaluate((element) => element.setAttribute('data-retained', 'yes')); + const body = 'Some streaming text.\n\n'.repeat(28) + '[An inline source](https://example.org/a)'; + await emit(page, 'qa:state', { kind: 'answer_delta', sessionId: 'search', chunk: body }); + const viewport = panel.locator('[data-slot=message-scroller-viewport]'); + await expect + .poll(() => viewport.evaluate((el) => el.scrollHeight - el.clientHeight - el.scrollTop)) + .toBeLessThan(2); + await expect(panel.locator('textarea')).toBeInViewport(); + await response.getByRole('link', { name: 'An inline source' }).click(); + await expect + .poll(() => page.evaluate(() => (window as any).fixture.externalLinks)) + .toEqual(['https://example.org/a']); + await emit(page, 'qa:state', { + kind: 'answer', + sessionId: 'search', + messages: [ + question, + { + role: 'assistant', + content: `${body}\n\n[1]() [2]()`, + }, + ], + }); + await expect(response).toHaveAttribute('data-retained', 'yes'); + const source = response.getByRole('link', { name: '2. example.com (example.com)' }); + await source.click(); + await expect + .poll(() => page.evaluate(() => (window as any).fixture.externalLinks)) + .toEqual(['https://example.org/a', 'https://example.com/b']); +}); diff --git a/openless-all/app/e2e/aux-window-geometry.spec.ts b/openless-all/app/e2e/aux-window-geometry.spec.ts index 11573df70..cf51ec120 100644 --- a/openless-all/app/e2e/aux-window-geometry.spec.ts +++ b/openless-all/app/e2e/aux-window-geometry.spec.ts @@ -27,12 +27,13 @@ test('QA waits for observed geometry and reopens without the closed transcript', await expect(host).toHaveCSS('height', '80px'); await expect(page.locator('.qa-answer-panel')).toBeHidden(); - await page.evaluate(() => (window as any).fixture.applyQaGeometry(true, 320, 220)); + await page.evaluate(() => (window as any).fixture.applyQaGeometry(true, 420, 179)); const answer = page.locator('.qa-answer-panel'); await expect(answer).toBeVisible(); await expect(answer.getByText('Old result', { exact: true })).toBeVisible(); - await expect(host).toHaveCSS('width', '320px'); - await expect(host).toHaveCSS('height', '220px'); + await expect(host).toHaveCSS('width', '420px'); + await expect(host).toHaveCSS('height', '179px'); + await expect(answer.locator('textarea')).toBeInViewport(); await page.evaluate(() => { const bridge = (window as any).fixture; diff --git a/openless-all/app/e2e/capsule-reference-motion.spec.ts b/openless-all/app/e2e/capsule-reference-motion.spec.ts index 20fabb604..cd57eb8ee 100644 --- a/openless-all/app/e2e/capsule-reference-motion.spec.ts +++ b/openless-all/app/e2e/capsule-reference-motion.spec.ts @@ -147,14 +147,14 @@ test('QA opens the conversation while recording and starts fresh after close', a await expect(page.locator('.qa-answer-panel')).toBeVisible(); await expect(page.locator('.qa-prompt')).toBeVisible(); const host = page.locator('#native-host'); - await expect(host).toHaveCSS('width', '720px'); - await expect(host).toHaveCSS('height', '380px'); + await expect(host).toHaveCSS('width', '975px'); + await expect(host).toHaveCSS('height', '415px'); await emit(page, 'qa:state', { kind: 'thinking', sessionId: 'a', messages: [messages[0]] }); await expect(page.locator('.qa-thought')).toBeVisible(); await expect(page.locator('.ol-default-capsule')).toHaveCount(0); await emit(page, 'qa:state', { kind: 'answer', sessionId: 'a', messages }); await expect(page.locator('.qa-assistant-message')).toContainText('我会尽力为你解答'); - await expect(host).toHaveCSS('width', '720px'); + await expect(host).toHaveCSS('width', '975px'); await expect(page.locator('.qa-capsule-shell')).toHaveCSS('opacity', '1'); await page.screenshot({ path: info.outputPath('qa-result.png') }); await emit(page, 'chat-panel:closing', {}); @@ -174,7 +174,7 @@ test('QA opens the conversation while recording and starts fresh after close', a await expect(page.locator('.qa-capsule-shell')).not.toHaveClass(/is-closing/); await expect(page.locator('.qa-answer-panel')).toBeVisible(); await expect(page.locator('.qa-assistant-message')).toHaveCount(0); - await expect(host).toHaveCSS('height', '380px'); + await expect(host).toHaveCSS('height', '415px'); expect(errors).toEqual([]); }); diff --git a/openless-all/app/e2e/fixtures/capsule-motion.tsx b/openless-all/app/e2e/fixtures/capsule-motion.tsx index 534348717..25e9a2800 100644 --- a/openless-all/app/e2e/fixtures/capsule-motion.tsx +++ b/openless-all/app/e2e/fixtures/capsule-motion.tsx @@ -45,6 +45,7 @@ const bridge = { regionWrites: [] as any[], dictationActions: [] as string[], qaActions: [] as { command: string; args: unknown }[], + externalLinks: [] as string[], pipelineMode: params.get('pipelineMode') === 'deepseek' ? 'deepseek' : 'traditional', hasListener: (event: string) => Boolean(listeners.get(event)?.size), setCapsule: (_: Record) => {}, @@ -65,8 +66,8 @@ const bridge = { const host = document.querySelector('#native-host'); if (!host) return; // Match the native window's nominal dimensions; tests can deliver a work-area clamp. - host.style.width = `${width ?? (expanded ? 720 : 480)}px`; - host.style.height = `${height ?? (expanded ? 380 : 80)}px`; + host.style.width = `${width ?? (expanded ? 975 : 480)}px`; + host.style.height = `${height ?? (expanded ? 415 : 80)}px`; host.style.bottom = expanded ? '48px' : '8px'; }, target: { @@ -96,6 +97,10 @@ window.__TAURI_INTERNALS__ = { callbacks.delete(id); }, async invoke(command: string, args: any) { + if (command === 'plugin:shell|open') { + bridge.externalLinks.push(args.path); + return; + } if (['qa_cancel_turn', 'qa_stop_recording', 'qa_submit_text'].includes(command)) { bridge.qaActions.push({ command, args }); } diff --git a/openless-all/app/src-tauri/src/lib.rs b/openless-all/app/src-tauri/src/lib.rs index 52e621c03..dd382bae9 100644 --- a/openless-all/app/src-tauri/src/lib.rs +++ b/openless-all/app/src-tauri/src/lib.rs @@ -2319,8 +2319,10 @@ fn wait_for_app_activation(_app: &AppHandle) {} /// QA records through the shared capsule and keeps its separate answer card open. const QA_WINDOW_WIDTH: f64 = 480.0; const QA_WINDOW_HEIGHT: f64 = 80.0; -const QA_WINDOW_EXPANDED_WIDTH: f64 = 720.0; -const QA_WINDOW_EXPANDED_HEIGHT: f64 = 380.0; +// 1950 × 830 at 2× display scale. Keep a shared scale when fitting smaller work areas. +const QA_WINDOW_EXPANDED_WIDTH: f64 = 975.0; +const QA_WINDOW_EXPANDED_HEIGHT: f64 = 415.0; +const QA_WINDOW_MIN_EXPANDED_HEIGHT: f64 = 144.0; /// Reserve room for the independent recording capsule and its context badge. const QA_WINDOW_BOTTOM_INSET: f64 = 96.0; /// Expanded answers sit higher so the lower composer does not crowd the recording capsule. @@ -2893,6 +2895,17 @@ fn qa_resize_origin( ) } +fn qa_expanded_size(area: Option) -> (f64, f64) { + let fit = area.map_or(1.0, |frame| { + let available_width = (frame.width - 32.0).max(1.0); + let available_height = (frame.height - 32.0 - QA_WINDOW_EXPANDED_BOTTOM_INSET).max(1.0); + (available_width / QA_WINDOW_EXPANDED_WIDTH) + .min(available_height / QA_WINDOW_EXPANDED_HEIGHT) + .min(1.0) + }); + (QA_WINDOW_EXPANDED_WIDTH * fit, QA_WINDOW_EXPANDED_HEIGHT * fit) +} + /// Called on the native main thread by the restricted QA command. The compact /// state has a genuinely small native frame, so hidden content cannot eat clicks. pub(crate) fn set_qa_window_expanded( @@ -2917,19 +2930,18 @@ pub(crate) fn set_qa_window_expanded( .map_err(|_| "qa_geometry_unavailable")? .to_logical::(scale); let was_expanded = current_size.height > QA_WINDOW_HEIGHT + 1.0; - let mut width = if expanded { - QA_WINDOW_EXPANDED_WIDTH - } else { - QA_WINDOW_WIDTH - }; - let mut height = if expanded { - QA_WINDOW_EXPANDED_HEIGHT + let (width, height) = if expanded { + qa_expanded_size(area.map(|(frame, _)| frame)) + } else if let Some((frame, _)) = area { + ( + QA_WINDOW_WIDTH.min((frame.width - 32.0).max(240.0)), + QA_WINDOW_HEIGHT, + ) } else { - QA_WINDOW_HEIGHT + (QA_WINDOW_WIDTH, QA_WINDOW_HEIGHT) }; - if let Some((frame, _)) = area { - width = width.min((frame.width - 32.0).max(240.0)); - height = height.min((frame.height - 64.0).max(QA_WINDOW_HEIGHT)); + if expanded && height < QA_WINDOW_MIN_EXPANDED_HEIGHT { + return Err("qa_work_area_too_small".into()); } let (mut x, mut y) = qa_resize_origin( position.x, @@ -4286,17 +4298,36 @@ mod tests { assert_eq!(capsule_visual_height(true), 140.0); } + #[test] + fn expanded_qa_fits_the_work_area_with_a_single_scale() { + let fit = |width, height| { + super::qa_expanded_size(Some(LogicalMonitorFrame { + x: -1600.0, + y: 20.0, + width, + height, + })) + }; + assert_eq!(fit(1440.0, 900.0), (975.0, 415.0)); + for (width, height) in [(800.0, 700.0), (1280.0, 480.0)] { + let (w, h) = fit(width, height); + assert!(w <= width - 32.0 + 1e-6); + assert!(h <= height - 164.0 + 1e-6); + assert!((w / h - 1950.0 / 830.0).abs() < 1e-6); + } + } + #[test] fn qa_resize_preserves_centre_baseline_and_user_position() { let expanded = - super::qa_resize_origin(-700.0, 700.0, 480.0, 80.0, 720.0, 380.0, false, true); - assert_eq!(expanded, (-820.0, 360.0)); + super::qa_resize_origin(-700.0, 700.0, 480.0, 80.0, 975.0, 415.0, false, true); + assert_eq!(expanded, (-947.5, 325.0)); assert_eq!( - super::qa_resize_origin(expanded.0, expanded.1, 720.0, 380.0, 720.0, 380.0, true, true), + super::qa_resize_origin(expanded.0, expanded.1, 975.0, 415.0, 975.0, 415.0, true, true), expanded ); assert_eq!( - super::qa_resize_origin(expanded.0, expanded.1, 720.0, 380.0, 480.0, 80.0, true, false), + super::qa_resize_origin(expanded.0, expanded.1, 975.0, 415.0, 480.0, 80.0, true, false), (-700.0, 700.0) ); } diff --git a/openless-all/app/src/features/qa/QaComposer.tsx b/openless-all/app/src/features/qa/QaComposer.tsx new file mode 100644 index 000000000..93fc246cd --- /dev/null +++ b/openless-all/app/src/features/qa/QaComposer.tsx @@ -0,0 +1,122 @@ +import { MicIcon, PencilLineIcon, QuoteIcon, SquareIcon } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; +import { chatPanelFocusKeyboard } from '../../api/qa'; +import { QaPromptBox } from './QaPromptBox'; +import { VoiceWaveform } from './chat/VoiceWaveform'; + +export type QaStatus = 'idle' | 'recording' | 'thinking' | 'error'; + +interface QaComposerProps { + value: string; + status: QaStatus; + level: number; + voiceActive: boolean; + selectionPreview: string; + busy: boolean; + micBusy: boolean; + embedded: boolean; + available: boolean; + editInstructionMode: boolean; + onEditInstructionModeChange: (enabled: boolean) => void; + onChange: (value: string) => void; + onSubmit: () => void; + onToggleRecording: () => void; + onCancelTurn: () => void; + cancelBusy: boolean; +} + +export function QaComposer({ + value, + status, + level, + voiceActive, + selectionPreview, + busy, + micBusy, + embedded, + available, + editInstructionMode, + onEditInstructionModeChange, + onChange, + onSubmit, + onToggleRecording, + onCancelTurn, + cancelBusy, +}: QaComposerProps) { + const { t } = useTranslation(); + const recording = status === 'recording'; + const generating = status === 'thinking'; + const voiceLabel = recording + ? t('qa.voiceInputPlaceholder') + : micBusy + ? t('common.loading') + : t('overview.inAppDictation.processing'); + const inputLabel = t('qa.composerPlaceholder'); + + return ( + { + if (available && !embedded) void chatPanelFocusKeyboard().catch(() => undefined); + }} + actions={ + <> + + + + } + feedback={ + voiceActive ? ( +
+ + {selectionPreview && ( + + + {selectionPreview} + + )} +
+ ) : !available ? ( + {t('qa.compact.browserUnavailable')} + ) : undefined + } + /> + ); +} diff --git a/openless-all/app/src/features/qa/QaPanel.tsx b/openless-all/app/src/features/qa/QaPanel.tsx index bd4f40961..524fcfb2a 100644 --- a/openless-all/app/src/features/qa/QaPanel.tsx +++ b/openless-all/app/src/features/qa/QaPanel.tsx @@ -1,24 +1,9 @@ // Fn+Space opens this conversation immediately. Closing dismisses the native // session, so the next press starts a new one; an open panel keeps it and can // take the next voice turn or a typed message. -import { - useEffect, - useRef, - useState, - type ReactNode, - type KeyboardEvent as ReactKeyboardEvent, -} from 'react'; +import { useEffect, useRef, useState, type ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; -import { - ArrowUpIcon, - CheckIcon, - CopyIcon, - MicIcon, - PencilLineIcon, - QuoteIcon, - SquareIcon, - XIcon, -} from 'lucide-react'; +import { CheckIcon, CopyIcon, XIcon } from 'lucide-react'; import { MessageScroller, MessageScrollerButton, @@ -29,11 +14,10 @@ import { } from './chat/ui/message-scroller'; import { OpenLessPill } from '../capsule/OpenLessCapsule'; import { QaSurface } from './QaSurface'; -import { VoiceWaveform } from './chat/VoiceWaveform'; -import { AssistantMarkdown } from './chat/markdown'; +import { QaComposer, type QaStatus } from './QaComposer'; +import { QaStreamingResponse } from './QaStreamingResponse'; import { useChatPanelLifecycle } from './chat/lifecycle'; import { - chatPanelFocusKeyboard, listenQaDismissed, listenQaLevelChanges, listenQaStateChanges, @@ -61,14 +45,11 @@ import { useQaWindowLayout } from './useQaWindowLayout'; import { acceptQaSessionEvent, splitQaUserMessage } from '../../lib/qaMessage'; import { installMessageFollow } from '../../lib/messageFollow'; import type { QaChatMessage, QaStatePayload } from '../../api/contracts'; -import { QaAnswerFooter } from './QaAnswerFooter'; -import { qaSources } from './qaSources'; import { useQaPipeline } from './useQaPipeline'; import { stopDeepSeekReading } from './DeepSeekReadAloud'; import { copyTextToClipboard } from '../../api/files'; import './qa-panel.css'; -type Status = 'idle' | 'recording' | 'thinking' | 'error'; type Translate = ReturnType['t']; export interface QaPanelProps { embedded?: boolean; @@ -82,7 +63,7 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: const pipelineMode = useQaPipeline(); const isTauri = isTauriHost(); const [messages, setMessages] = useState([]); - const [status, setStatus] = useState('idle'); + const [status, setStatus] = useState('idle'); const [errorMsg, setErrorMsg] = useState(''); const [selectionPreview, setSelectionPreview] = useState(''); const [composerText, setComposerText] = useState(''); @@ -126,7 +107,7 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: }; const loadPolishResultRef = useRef(loadPolishResult); loadPolishResultRef.current = loadPolishResult; - const statusRef = useRef('idle'); + const statusRef = useRef('idle'); const panelEpoch = useRef(0); const nativeStateEpoch = useRef(0); const submissionRef = useRef(null); @@ -146,7 +127,7 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: const delegatedDismiss = useRef(onRequestDismiss); delegatedDismiss.current = onRequestDismiss; - const changeStatus = (next: Status) => { + const changeStatus = (next: QaStatus) => { statusRef.current = next; setStatus(next); }; @@ -495,7 +476,8 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: } }; const onSubmitText = async () => { - const text = composerText.trim(); + const draft = composerText; + const text = draft.trim(); if ( !isTauri || !text || @@ -530,7 +512,7 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: submissionRef.current === request && activeSessionIdRef.current === originSession ) { - setComposerText((current) => current || text); + setComposerText((current) => current || draft); setErrorMsg(t('qa.compact.sendError')); changeStatus('error'); } @@ -759,14 +741,6 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: const heading = firstQuestion ? truncate(splitQaUserMessage(firstQuestion).question, 42) : t('qa.title'); - const thoughtByIndex = new Map(); - let assistantCount = 0; - messages.forEach((message, index) => { - if (message.role !== 'assistant') return; - const seconds = thoughts[assistantCount]; - if (seconds) thoughtByIndex.set(index, seconds); - assistantCount += 1; - }); const liveActivity = status === 'thinking' && activity && !streamingAnswer ? activityLabel : undefined; const voiceActive = @@ -781,6 +755,42 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: modeBusy || editApplyBusy; + let assistantCount = 0; + const turns = messages.map((message, index) => { + const id = `m${index}`; + if (message.role === 'user') { + return ( + + + + ); + } + const elapsed = thoughts[assistantCount++]; + return ( + + + + ); + }); + if (status === 'thinking') { + // Use the final answer's slot so finishing the stream doesn't replace the response element. + const id = `m${messages.length}`; + turns.push( + + + , + ); + } + if (layout.failed && !presentationClosing) { return ( - {messages.map((message, index) => ( - - ))} - {status === 'thinking' && ( - -
- - {streamingAnswer && ( - - )} -
-
- )} + {turns} {status === 'error' && ( @@ -1010,7 +996,7 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: )}
- void cancelTurnForSession(currentSession)} cancelBusy={cancelBusy} - t={t} + available={isTauri} />
@@ -1035,219 +1021,16 @@ export function QaPanel({ embedded = false, onRequestClose, onRequestDismiss }: ); } -function Composer({ - value, - status, - level, - voiceActive, - selectionPreview, - busy, - micBusy, - embedded, - editInstructionMode, - onEditInstructionModeChange, - onChange, - onSubmit, - onToggleRecording, - onCancelTurn, - cancelBusy, - t, -}: { - value: string; - status: Status; - level: number; - voiceActive: boolean; - selectionPreview: string; - busy: boolean; - micBusy: boolean; - embedded: boolean; - editInstructionMode: boolean; - onEditInstructionModeChange: (enabled: boolean) => void; - onChange: (value: string) => void; - onSubmit: () => void; - onToggleRecording: () => void; - onCancelTurn: () => void; - cancelBusy: boolean; - t: Translate; -}) { - const isTauri = isTauriHost(); - const composingRef = useRef(false); - const recording = status === 'recording'; - const generating = status === 'thinking'; - const onKeyDown = (event: ReactKeyboardEvent) => { - if (event.key !== 'Enter') return; - event.preventDefault(); - if (composingRef.current || event.nativeEvent.isComposing || event.keyCode === 229) return; - if (!busy && isTauri) onSubmit(); - }; - const label = recording - ? t('overview.inAppDictation.recording') - : micBusy - ? t('common.loading') - : t('overview.inAppDictation.processing'); +function QaUserMessage({ message }: { message: QaChatMessage }) { + const { selection, question } = splitQaUserMessage(message); return ( -
{ - event.preventDefault(); - if (!composingRef.current && !busy && isTauri) onSubmit(); - }} - > -
- onChange(event.currentTarget.value)} - onKeyDown={onKeyDown} - onCompositionStart={() => { - composingRef.current = true; - }} - onCompositionEnd={() => { - composingRef.current = false; - }} - onFocus={() => { - if (isTauri && !embedded) void chatPanelFocusKeyboard().catch(() => undefined); - }} - onPointerDown={() => { - if (isTauri && !embedded) void chatPanelFocusKeyboard().catch(() => undefined); - }} - /> - {!isTauri && {t('qa.compact.browserUnavailable')}} -
-
-
-
- {voiceActive && ( - <> - - {selectionPreview && ( - - - {truncate(selectionPreview, 32)} - - )} - - )} -
- -
- - {generating ? ( - - ) : ( - - )} -
-
- ); -} - -function ThoughtStatus({ - live, - seconds, - activityLabel, - t, -}: { - live: boolean; - seconds: number; - activityLabel?: string; - t: Translate; -}) { - const elapsed = live ? t('qa.thoughtLive', { seconds }) : t('qa.thoughtDone', { seconds }); - const label = live && activityLabel ? `${elapsed} · ${activityLabel}` : elapsed; - return ( -
- {live && } - {label} +
+ {selection &&
{truncate(selection, 120)}
} +

{question}

+
); } - -function MessageRow({ - index, - message, - thoughtSeconds, - t, - canReadAloud = false, -}: { - canReadAloud?: boolean; - index: number; - message: QaChatMessage; - thoughtSeconds?: number; - t: Translate; -}) { - const answer = qaSources(message.content); - if (message.role === 'user') { - const { selection, question } = splitQaUserMessage(message); - return ( - -
- {selection &&
{truncate(selection, 120)}
} -

{question}

- -
-
- ); - } - return ( - -
- {thoughtSeconds ? : null} - - -
-
- ); -} function CopyMessage({ text }: { text: string }) { const { t } = useTranslation(); const [copied, setCopied] = useState(false); diff --git a/openless-all/app/src/features/qa/QaPromptBox.tsx b/openless-all/app/src/features/qa/QaPromptBox.tsx new file mode 100644 index 000000000..73f1ef9bd --- /dev/null +++ b/openless-all/app/src/features/qa/QaPromptBox.tsx @@ -0,0 +1,109 @@ +import { useRef, type ReactNode } from 'react'; +import { ArrowUpIcon, SquareIcon } from 'lucide-react'; +import './qa-prompt-box.css'; + +interface QaPromptBoxProps { + value: string; + label: string; + placeholder: string; + actions: ReactNode; + feedback?: ReactNode; + disabled?: boolean; + readOnly?: boolean; + sendDisabled: boolean; + sendLabel: string; + stop?: { label: string; disabled: boolean; onClick: () => void }; + onChange: (value: string) => void; + onSubmit: () => void; + onRequestKeyboard: () => void; +} + +export function QaPromptBox({ + value, + label, + placeholder, + actions, + feedback, + disabled, + readOnly, + sendDisabled, + sendLabel, + stop, + onChange, + onSubmit, + onRequestKeyboard, +}: QaPromptBoxProps) { + const composing = useRef(false); + const canSend = !disabled && !readOnly && !sendDisabled && !stop && !!value.trim(); + return ( +
{ + event.preventDefault(); + if (canSend && !composing.current) onSubmit(); + }} + > +
+