Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ jobs:

- run: pnpm workbench:check

- run: pnpm headless:test
- id: host_tests
run: pnpm headless:test

- name: Verify settings and chat in real sandboxed Chrome
timeout-minutes: 4
Expand All @@ -58,6 +59,13 @@ jobs:
timeout-minutes: 5
run: node scripts/workbench/e2e-attachments.mjs

- name: Verify conversation preferences across two independent owner logins
# Independent UI fixture: record its own outcome even if a previous Chrome workflow failed.
# Other failed steps still fail the overall job.
if: ${{ !cancelled() && steps.host_tests.outcome == 'success' }}
timeout-minutes: 5
run: node scripts/workbench/e2e-sessions.mjs

- name: Select the same installed Chrome for UI and worker
run: bash scripts/workbench/ci-select-chromium.sh

Expand Down
22 changes: 15 additions & 7 deletions apps/desktop/src/renderer/src/redesign/ModelMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 每行只写模型名(悬停提示写完整 ID)。服务商名是灰色小字、滚动时吸顶;组间不画线、不放色点。
* 列表自己滚动;打开时把当前模型滚到可见范围中间。
*/
import { useLayoutEffect, useRef } from 'react'
import { useLayoutEffect, useRef, type ReactNode } from 'react'
import { Check, ChevronDown } from 'lucide-react'
import './model-panel.css'
import type { ModelDef, Provider } from '../mock/models'
Expand All @@ -19,8 +19,12 @@ export function ModelMenu({
groups,
activePid,
activeMid,
onPick
onPick,
leading,
menuId
}: {
leading?: ReactNode
menuId?: string
groups: ModelGroup[]
activePid: string | null
activeMid: string | null
Expand All @@ -39,7 +43,8 @@ export function ModelMenu({
}, [])

return (
<div className="model-pick__menu cf-mp__menu" role="menu" aria-label={t('chat.selectModel')}>
<div id={menuId} className="model-pick__menu cf-mp__menu" role="menu" aria-label={t('chat.selectModel')}>
{leading}
{groups.length === 0 ? (
<div className="model-pick__empty">{t('chat.noModel')}</div>
) : (
Expand Down Expand Up @@ -78,18 +83,21 @@ export function modelGroups(providers: Provider[]): ModelGroup[] {
.map((p) => ({ p, models: p.models.filter((m) => m.enabled) })).filter((g) => g.models.length > 0)
}

export function ModelSelectButton({ open, active, groups, onToggle, onPick }: {
export function ModelSelectButton({ open, active, groups, onToggle, onPick, label, leading, disabled, menuId }: {
label?: string; leading?: ReactNode; disabled?: boolean; menuId?: string
open: boolean; active: { provider: Provider; model: ModelDef } | null; groups: ModelGroup[]
onToggle: () => void; onPick: (pid: string, mid: string) => void
}): React.JSX.Element {
const { t } = useI18n()
const name = active?.model.name ?? t('chat.selectModel')
const name = label ?? active?.model.name ?? t('chat.selectModel')
return <>
<button className={`chip cf-mp__model${open ? ' is-open' : ''}`} type="button"
title={open ? undefined : name} aria-label={name} aria-haspopup="menu" aria-expanded={open} onClick={onToggle}>
title={open ? undefined : name} aria-label={name} aria-haspopup="menu" aria-expanded={open} aria-controls={open ? menuId : undefined}
disabled={disabled} onClick={onToggle}>
<span className="chip__label">{name}</span>
<ChevronDown size={13} className="chip__caret" />
</button>
{open && <ModelMenu groups={groups} activePid={active?.provider.id ?? null} activeMid={active?.model.id ?? null} onPick={onPick} />}
{open && <ModelMenu groups={groups} activePid={active?.provider.id ?? null} activeMid={active?.model.id ?? null}
onPick={onPick} leading={leading} menuId={menuId} />}
</>
}
4 changes: 4 additions & 0 deletions apps/desktop/src/workbench/chat-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export function chatCopy(locale: Locale) {
selectModel: 'Select an enabled model. Configure providers, keys and models in Model settings.',
turnFailure: 'Could not confirm the message. The draft was kept; sending the same draft retries the same request.',
busy: 'A reply is already in progress in this conversation.', modelFailure: 'Check the selected model and provider in Model settings.',
preferencesChanged: 'This conversation’s model changed. Your draft is still here. Check the refreshed selection before sending again.',
effortUnavailable: 'Workbench does not support the saved thinking level. Your draft is still here.',
listFailure: 'Could not load conversations.', createFailure: 'Could not confirm a new conversation. Try New conversation again.',
stopFailure: 'Could not confirm the stop request.', reloadList: 'Retry',
limits: '{turns} turns per conversation · 12 KiB input · 65,536 UTF-16 code units of output', input: 'Message the assistant…', inputLimit: 'Messages can contain up to 12 KiB of UTF-8 text.', previous: 'Show earlier messages'
Expand All @@ -39,6 +41,8 @@ export function chatCopy(locale: Locale) {
selectModel: '请选择已启用的模型。可在模型设置中配置服务商、密钥和模型。',
turnFailure: '消息发送结果尚未确认。已保留草稿,再次提交原草稿会使用同一个请求。',
busy: '这段对话已有一条回复正在进行。', modelFailure: '请在模型设置中检查所选模型和服务商。',
preferencesChanged: '对话模型已变更。草稿已保留,请核对同步后的模型再发送。',
effortUnavailable: '已保存的思考档位在工作台中尚未开放。草稿已保留。',
listFailure: '加载对话列表失败。', createFailure: '新建对话的结果尚未确认,可再次点击新建对话。',
stopFailure: '停止请求的结果尚未确认。', reloadList: '重试',
limits: '每段对话 {turns} 轮 · 输入 12 KiB · 输出 65,536 个 UTF-16 码元', input: '跟助手说点什么…', inputLimit: '单条消息最多 12 KiB UTF-8 文本。', previous: '显示更早的消息'
Expand Down
6 changes: 5 additions & 1 deletion apps/desktop/src/workbench/chat-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface ChatSummary {
updatedAt: number
model: string | null
personaId?: string
archived?: boolean
customTitle?: string
compatibility: 'text' | 'legacy_text' | 'unsupported'
writable: boolean
}
Expand All @@ -52,7 +54,7 @@ export interface ChatSnapshot { cursor: ChatCursor; state: ChatState }
export type ChatFrame = ({ t: 'snapshot' } & ChatSnapshot) | {
t: 'event'; cursor: ChatCursor; sessionId: string; turnId: string; type: 'chat'; event: { type: string; text?: string }
}
export interface TurnRequest { clientRequestId: string; text: string; model: string; attachments?: string[] }
export interface TurnRequest { clientRequestId: string; text: string; model: string | null; attachments?: string[] }

type TurnDraft = Omit<TurnRequest, 'clientRequestId'>
export function sameTurnDraft(a: TurnDraft | undefined, b: TurnDraft): boolean {
Expand All @@ -79,6 +81,8 @@ function message(value: unknown): value is ChatMessage {
function summary(value: unknown): value is Omit<ChatSummary, 'updatedAt'> {
return record(value) && id(value.id) && typeof value.title === 'string' && nullableString(value.model) &&
(value.personaId === undefined || isRoleId(value.personaId)) &&
(value.archived === undefined || typeof value.archived === 'boolean') &&
(value.customTitle === undefined || typeof value.customTitle === 'string') &&
(value.compatibility === 'text' || value.compatibility === 'legacy_text' || value.compatibility === 'unsupported') &&
typeof value.writable === 'boolean'
}
Expand Down
44 changes: 44 additions & 0 deletions apps/desktop/src/workbench/session-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { ChatSummary } from './chat-transport'

export function sessionAfterRefresh(sessions: ChatSummary[], selected: string | null, saved: string | null, grouped: boolean): string | null {
// A list invalidation is not a navigation action. In the owner workbench an archived (or now missing)
// selected conversation keeps its pane and drafts until the user chooses another conversation.
if (grouped && selected) return selected
const wanted = selected ?? saved
if (wanted && sessions.some((row) => row.id === wanted)) return wanted
return (grouped ? sessions.find((row) => !row.archived) : undefined)?.id ?? sessions[0]?.id ?? null
}

/** At most one GET in flight, plus one trailing GET for all invalidations received during it. */
export function createListRefresh<T>(read: () => Promise<T>, updated: (value: T) => void, failed: (error: unknown) => void) {
let active = true
let pending = false
let running = false
let revision = 0
async function run(): Promise<void> {
while (active && pending) {
pending = false
const expected = revision
try {
const next = await read()
if (active && revision === expected) updated(next)
} catch (error) {
if (active && revision === expected) failed(error)
}
}
running = false
}
function request(): void {
if (!active) return
pending = true
if (running) return
running = true
queueMicrotask(() => void run())
}
return {
request,
// A locally acknowledged mutation is newer than any outstanding read started before it.
afterWrite() { ++revision; request() },
close() { active = false }
}
}
110 changes: 110 additions & 0 deletions apps/desktop/src/workbench/session-preference-ui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { useEffect, useId, useRef } from 'react'
import { Archive, ArchiveRestore, Check, Pencil } from 'lucide-react'
import { Modal } from '../renderer/src/components/Modal'
import { useI18n } from '../renderer/src/i18n/i18n'
import { ModelSelectButton } from '../renderer/src/redesign/ModelMenu'
import { normalizeTitle, type PreferenceEntry, type PreferenceIssue, type SessionPreferenceController } from './session-preferences'

const labels = {
en: {
conflict: 'These preferences changed elsewhere. Your draft is still here. Reload the saved preferences before applying changes again.',
busy: 'This conversation has a reply in progress. Try again once it ends.',
readOnly: 'Preferences for this desktop history are read-only in Workbench.',
missing: 'This conversation is no longer available.',
storage: 'The save was not confirmed in storage. Reload the saved preferences to check the result.',
invalid: 'The server rejected this preference. Check the title or the model enabled in settings.',
readFailure: 'Could not load saved conversation preferences.',
writeFailure: 'Could not confirm the save. Reload the saved preferences to check the result.',
reload: 'Reload saved preferences', saving: 'Saving preferences…', loading: 'Loading preferences…',
follow: 'Follow default', actions: 'Conversation actions'
},
'zh-CN': {
conflict: '其他窗口已更改会话设置。草稿已保留;请重新读取已保存的设置,再提交修改。',
busy: '这段对话有一条回复正在进行,请在回复结束后重试。',
readOnly: '这段桌面历史的会话设置在工作台中为只读。',
missing: '这段对话已失效。',
storage: '保存结果尚未在存储中确认,请重新读取已保存的设置核对结果。',
invalid: '服务端未接受这项设置,请检查标题或模型设置中的启用状态。',
readFailure: '加载已保存的会话设置失败。',
writeFailure: '保存结果尚未确认,请重新读取已保存的设置核对结果。',
reload: '重读已保存的设置', saving: '正在保存会话设置…', loading: '正在读取会话设置…',
follow: '跟随默认', actions: '会话操作'
}
} satisfies Record<string, Record<PreferenceIssue | 'reload' | 'saving' | 'loading' | 'follow' | 'actions', string>>

export function SessionPreferenceStatus({ entry, reload, locked }: {
entry: PreferenceEntry; reload: () => void; locked?: boolean
}): React.JSX.Element | null {
const { locale } = useI18n()
const c = labels[locale]
if (entry.pending) return <p className="wb-session-prefs__notice" role="status">{c.saving}</p>
if (!entry.issue) return entry.reading && !entry.confirmed ? <p className="wb-session-prefs__notice" role="status">{c.loading}</p> : null
return <div className="wb-session-prefs__notice" data-testid="workbench-session-preferences-issue">
<span role="alert">{c[entry.issue]}</span>{' '}
{entry.needsRead && <button className="cf-empty__action" type="button" data-testid="workbench-session-preferences-reload"
disabled={locked || entry.reading} onClick={reload}>{c.reload}</button>}
</div>
}

export function SessionHeaderActions({ archived, blocked, disabled, rename, archive }: {
archived: boolean; blocked?: string; disabled: boolean; rename: () => void; archive: () => void
}): React.JSX.Element {
const { t, locale } = useI18n()
return <div className="wb-session-prefs__actions" role="group" data-testid="workbench-session-menu" aria-label={labels[locale].actions}>
{archived && <span className="cf-conv__tag" data-testid="workbench-session-archived"><Archive size={11} />{t('cf.archivedTag')}</span>}
<button className="cf-conv__headbtn" type="button" data-testid="workbench-session-rename" aria-haspopup="dialog"
aria-label={t('cf.renameChat')} title={blocked ?? t('cf.renameChat')} disabled={disabled} onClick={rename}><Pencil size={14} /></button>
<button className="cf-conv__headbtn" type="button" data-testid={archived ? 'workbench-session-restore' : 'workbench-session-archive'}
aria-label={archived ? t('cf.unarchive') : t('cf.archive')} title={blocked ?? (archived ? t('cf.unarchive') : t('cf.archive'))}
disabled={disabled} onClick={archive}>
{archived ? <><ArchiveRestore size={13} /><span>{t('cf.unarchive')}</span></> : <Archive size={14} />}
</button>
</div>
}

export function SessionRenameDialog({ sid, entry, store, disabled, close, reload }: {
sid: string; entry: PreferenceEntry; store: SessionPreferenceController; disabled: boolean; close: () => void; reload: () => void
}): React.JSX.Element | null {
const { t } = useI18n()
const field = useRef<HTMLInputElement>(null)
const id = useId()
useEffect(() => { field.current?.select() }, [])
const draft = entry.draft
if (!draft) return null
const title = normalizeTitle(draft.text)
const unchanged = title === draft.initial
const ready = !disabled && !entry.reading && !entry.pending && !entry.needsRead && !unchanged
const cancel = (): void => { if (!entry.pending) { store.discardRename(sid); close() } }
const save = (): void => { if (ready) void store.saveRename(sid).then((ok) => { if (ok) close() }) }
return <Modal open onClose={cancel} labelledBy={id}>
<h2 id={id} className="modal__title">{t('cf.renameChatTitle')}</h2>
<div className="modal__field">
<input ref={field} className="input" autoFocus aria-label={t('cf.renameChatTitle')} data-testid="workbench-rename-input"
value={draft.text} disabled={!!entry.pending} placeholder={t('cf.renamePlaceholder')} onChange={(event) => store.editRename(sid, event.target.value)}
onKeyDown={(event) => { if (event.key === 'Enter' && !event.nativeEvent.isComposing) save() }} />
</div>
<SessionPreferenceStatus entry={entry} reload={reload} />
<div className="modal__actions">
<button className="btn btn--ghost" type="button" disabled={!!entry.pending} onClick={cancel}>{t('common.cancel')}</button>
<button className="btn btn--primary" type="button" data-testid="workbench-rename-save" disabled={!ready} onClick={save}>{t('cf.renameChat')}</button>
</div>
</Modal>
}

type ModelButton = Parameters<typeof ModelSelectButton>[0]
export function SessionModelPicker({ open, active, groups, onToggle, onPick, follow, pinned, disabled }: ModelButton & {
follow: () => void; pinned: string | null | undefined; disabled: boolean
}): React.JSX.Element {
const { t, locale } = useI18n()
const c = labels[locale]
const name = pinned === null ? c.follow : active?.model.name ?? pinned ?? t('chat.selectModel')
const id = useId()
return <ModelSelectButton open={open && !disabled} active={active} groups={groups} onToggle={onToggle} onPick={onPick}
label={name} menuId={id} disabled={disabled} leading={
<button className={`model-pick__item${pinned === null ? ' is-active' : ''}`} type="button" role="menuitemradio"
aria-checked={pinned === null} data-testid="workbench-session-model-default" onClick={follow}>
<span className="model-pick__name">{c.follow}</span>
<span className="cf-mp__check">{pinned === null && <Check size={14} className="model-pick__check" />}</span>
</button>
} />
}
Loading
Loading