diff --git a/apps/web/tests/schedule-after.e2e.ts b/apps/web/tests/schedule-after.e2e.ts index 64c8fe274e..34cbaf4155 100644 --- a/apps/web/tests/schedule-after.e2e.ts +++ b/apps/web/tests/schedule-after.e2e.ts @@ -672,7 +672,6 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => { } expect(await detail.getByRole('tab', { name: 'Records', exact: true }).getAttribute('aria-selected')).toBe('true') await detail.getByRole('tab', { name: 'Rules', exact: true }).click() - await detail.getByRole('button', { name: 'Edit', exact: true }).click() await detail.getByRole('button', { name: /^Repeat / }).click() await page.getByRole('menuitem', { name: 'Every N hours', exact: true }).click() const interval = detail.getByLabel('Interval', { exact: true }) @@ -1251,9 +1250,8 @@ describe.skipIf(MODE === 'record')('web e2e: active Schedule catalog', () => { expect(await row.textContent()).toContain(frequency) await row.click() const detail = manager.getByRole('complementary', { name: 'Task details' }) - expect(await detail.getByText(frequency, { exact: true }).count()).toBe(1) + expect(await detail.getByRole('button', { name: /^Repeat / }).textContent()).toContain('Every day') expect(await detail.getByText('Once', { exact: true }).count()).toBe(0) - await detail.getByRole('button', { name: 'Edit', exact: true }).click() const runTime = detail.getByRole('region', { name: 'Run time', exact: true }) const timeField = runTime.getByRole('button', { name: 'Time', exact: true }) // The Time zone row is a menu trigger button; the zone is chosen, never typed. @@ -1281,7 +1279,7 @@ describe.skipIf(MODE === 'record')('web e2e: active Schedule catalog', () => { }) expect(rruleOf(saved)).toContain('BYHOUR=12;BYMINUTE=34') // A stored zone equal to the browser zone is omitted from the frequency line. - await expect.poll(() => detail.getByText('Daily at 12:34', { exact: true }).count(), { timeout: 15_000 }).toBe(1) + await expect.poll(() => row.textContent(), { timeout: 15_000 }).toContain('Daily at 12:34') expect(await scaffold.ctx.schedule.history({ id: created.id, limit: 20 })) .toEqual({ id: created.id, records: [], earlierRecordsUnavailable: false, earlierRecordsPruned: false, retention: { days: 30, records: 200 } }) @@ -1296,6 +1294,39 @@ describe.skipIf(MODE === 'record')('web e2e: active Schedule catalog', () => { } }, 60_000) + it('restores the latest linked Session after reviewing a concurrent destination change', async () => { + const before = SessionId('schedule-destination-before') + const after = SessionId('schedule-destination-after') + const fixture = await readFile(CATALOG_FIXTURE, 'utf8') + for (const id of [before, after]) await seedSession(scaffold, fixture, id, 'standard') + const created = await scaffold.ctx.schedule.create({ title: 'Destination recovery', prompt: 'Review the destination', + timing: { kind: 'at', at: '2099-09-01T12:00:00.000Z' }, target: { kind: 'session', sessionId: before } }) + try { + await page.getByRole('button', { name: 'Automation tasks', exact: true }).click() + const manager = page.getByTestId('task-manager-page') + await manager.getByRole('searchbox', { name: 'Search tasks' }).fill('') + await manager.getByRole('button', { name: 'All', exact: true }).click() + await manager.getByRole('button', { name: 'Destination recovery', exact: true }).click() + const detail = manager.getByRole('complementary') + await detail.getByRole('textbox', { name: 'Automation task name', exact: true }).fill('Recovered destination') + await detail.getByRole('button', { name: /^Run in / }).click() + await page.getByRole('menuitem', { name: /^Create a session and reuse it/ }).click() + const remote = await scaffold.ctx.schedule.edit({ id: created.id, action: 'update', expectedUpdatedAt: created.updatedAt ?? null, + patch: { target: { kind: 'session', sessionId: after } } }) + expect(remote).toMatchObject({ target: { kind: 'session', sessionId: after } }) + await detail.getByRole('button', { name: 'Review with my edits', exact: true }).click() + await detail.getByRole('button', { name: /^Run in / }).click() + await page.getByRole('menuitem', { name: 'Current linked session', exact: true }).click() + await detail.getByRole('button', { name: 'Save changes', exact: true }).click() + await detail.getByRole('heading', { name: 'Recovered destination', exact: true }).waitFor() + expect(await scaffold.ctx.schedule.view({ id: created.id })) + .toMatchObject({ title: 'Recovered destination', target: { kind: 'session', sessionId: after } }) + expect(tripwire.pageErrors).toEqual([]) + } finally { + await scaffold.ctx.schedule.edit({ id: created.id, action: 'delete' }) + } + }) + it('removes every ended task from the page and keeps the active ones', async () => { onTestFailed(() => saveFailureShot(page, 'web-e2e-schedule-clear-ended')) const endedSession = SessionId('schedule-manager-ended-clear') diff --git a/apps/web/tests/schedule-manual.e2e.ts b/apps/web/tests/schedule-manual.e2e.ts index c4525cbebe..60ca701a4d 100644 --- a/apps/web/tests/schedule-manual.e2e.ts +++ b/apps/web/tests/schedule-manual.e2e.ts @@ -30,8 +30,10 @@ it('creates from a paused empty state, selects the task, and saves an inline edi await page.getByRole('menuitem', { name: '手动创建', exact: true }).waitFor() await page.keyboard.press('Escape') await manager.getByRole('button', { name: '新建自动化任务', exact: true }).click() - const dialog = page.getByRole('dialog', { name: '手动创建', exact: true }) + const dialog = manager.getByRole('complementary', { name: '手动创建', exact: true }) await dialog.getByRole('textbox', { name: '自动化任务名称', exact: true }).fill('AI 新闻简报') + expect(await dialog.getByRole('status').count()).toBe(0) + expect(await dialog.getByRole('textbox', { name: '自动化任务名称', exact: true }).getAttribute('aria-required')).toBe('true') await dialog.getByRole('textbox', { name: '自动化任务内容', exact: true }).fill('整理过去 24 小时的 AI 新闻,附原文链接。') await dialog.getByRole('button', { name: /^重复 / }).click() await page.getByRole('menuitem', { name: '周一至周五', exact: true }).click() @@ -62,14 +64,60 @@ it('creates from a paused empty state, selects the task, and saves an inline edi const task = (await scaffold.ctx.schedule.catalog()).find(task => task.title === 'AI 新闻简报') if (task === undefined || task.target.kind !== 'new_once') throw new Error('manual task was not created with the reusable target') expect(task.target.create.cwd).toBe(defaultPath) - await detail.getByRole('button', { name: '编辑', exact: true }).click() + expect(await detail.getByRole('button', { name: '保存修改', exact: true }).isDisabled()).toBe(true) await detail.getByRole('textbox', { name: '自动化任务内容', exact: true }).fill('整理过去 24 小时的 AI 新闻,附原文链接,按重要性排序。') + expect(await detail.getByRole('button', { name: '暂停任务', exact: true }).isDisabled()).toBe(true) + await manager.getByRole('button', { name: '关闭详情', exact: true }).click() + await manager.getByRole('list', { name: '任务列表', exact: true }).getByRole('button', { name: task.title, exact: true }).click() + expect(await detail.getByRole('textbox', { name: '自动化任务内容', exact: true }).inputValue()) + .toBe('整理过去 24 小时的 AI 新闻,附原文链接,按重要性排序。') await detail.getByRole('button', { name: '保存修改', exact: true }).click() - await detail.getByRole('textbox', { name: '自动化任务内容', exact: true }).waitFor({ state: 'detached' }) - await detail.getByText('整理过去 24 小时的 AI 新闻,附原文链接,按重要性排序。', { exact: true }).waitFor() + await expect.poll(() => detail.getByRole('button', { name: '保存修改', exact: true }).isDisabled()).toBe(true) + expect(await detail.getByRole('textbox', { name: '自动化任务内容', exact: true }).inputValue()) + .toBe('整理过去 24 小时的 AI 新闻,附原文链接,按重要性排序。') const saved = await scaffold.ctx.schedule.view({ id: task.id }) if ('code' in saved) throw new Error('edited task was not retained') expect(saved.prompt).toBe('整理过去 24 小时的 AI 新闻,附原文链接,按重要性排序。') + await detail.getByRole('textbox', { name: '自动化任务名称', exact: true }).fill('本地简报草稿') + const remote = await scaffold.ctx.schedule.edit({ id: task.id, action: 'update', + expectedUpdatedAt: saved.updatedAt ?? null, patch: { prompt: '来自其他窗口的新指令' } }) + expect(remote).toMatchObject({ prompt: '来自其他窗口的新指令' }) + const recovery = detail.getByRole('button', { name: '保留修改并复核', exact: true }) + await recovery.waitFor() + const notice = detail.getByRole('alert').locator('..') + const palettes = [] + for (const dark of [false, true]) { + await page.evaluate(dark => document.body.toggleAttribute('data-ds-dark-theme', dark), dark) + const [box, field, message, action] = await Promise.all([ + notice.boundingBox(), detail.getByRole('textbox', { name: '自动化任务名称', exact: true }).locator('..').boundingBox(), + detail.getByRole('alert').boundingBox(), recovery.boundingBox(), + ]) + expect(box).not.toBeNull() + expect(field).not.toBeNull() + expect(message).not.toBeNull() + expect(action).not.toBeNull() + expect(Math.abs(box!.x - field!.x)).toBeLessThanOrEqual(1) + expect(Math.abs(box!.x + box!.width - field!.x - field!.width)).toBeLessThanOrEqual(1) + expect(action!.y).toBeLessThan(message!.y + message!.height) + expect(action!.y + action!.height).toBeGreaterThan(message!.y) + expect(box!.y + box!.height).toBeLessThan(field!.y) + palettes.push(await notice.evaluate((element) => { + const style = getComputedStyle(element) + return { color: style.color, background: style.backgroundColor } + })) + } + expect(palettes[0]).not.toEqual(palettes[1]) + await page.evaluate(() => { document.body.removeAttribute('data-ds-dark-theme') }) + expect(await detail.getByRole('button', { name: '保存修改', exact: true }).isDisabled()).toBe(true) + expect(await detail.getByRole('textbox', { name: '自动化任务内容', exact: true }).inputValue()).toBe(saved.prompt) + await detail.getByRole('button', { name: '保留修改并复核', exact: true }).click() + expect(await detail.getByRole('textbox', { name: '自动化任务名称', exact: true }).inputValue()).toBe('本地简报草稿') + expect(await detail.getByRole('textbox', { name: '自动化任务内容', exact: true }).inputValue()).toBe('来自其他窗口的新指令') + expect(await scaffold.ctx.schedule.view({ id: task.id })).toMatchObject({ title: task.title }) + await detail.getByRole('button', { name: '保存修改', exact: true }).click() + await detail.getByRole('heading', { name: '本地简报草稿', exact: true }).waitFor() + expect(await scaffold.ctx.schedule.view({ id: task.id })).toMatchObject({ title: '本地简报草稿', prompt: '来自其他窗口的新指令' }) + expect(await detail.evaluate(element => element === document.activeElement)).toBe(true) await manager.getByRole('button', { name: '选择创建方式', exact: true }).click() await page.getByRole('menuitem', { name: '手动创建', exact: true }).click() await dialog.getByRole('textbox', { name: '自动化任务名称', exact: true }).fill('检查最新进展') @@ -92,7 +140,7 @@ it('creates from a paused empty state, selects the task, and saves an inline edi await detail.getByRole('button', { name: '恢复任务', exact: true }).waitFor() expect(await detail.getByText('待创建', { exact: true }).count()).toBe(0) expect(await detail.getByText('最近运行会话', { exact: true }).count()).toBe(0) - expect(await detail.getByText('运行间隔至少', { exact: false }).count()).toBe(0) + expect(await detail.getByText('运行间隔至少', { exact: false }).count()).toBe(1) expect(tripwire.pageErrors).toEqual([]) expect(scaffold.ctx.agents.get(task.target.sessionId)).toBeUndefined() } finally { @@ -113,7 +161,7 @@ it('creates and edits Custom Cron through the built UI while retaining its expli const manager = page.getByTestId('task-manager-page') await manager.getByRole('button', { name: '选择创建方式', exact: true }).click() await page.getByRole('menuitem', { name: '手动创建', exact: true }).click() - const dialog = page.getByRole('dialog', { name: '手动创建', exact: true }) + const dialog = manager.getByRole('complementary', { name: '手动创建', exact: true }) await dialog.getByRole('textbox', { name: '自动化任务名称', exact: true }).fill('Cron deployment check') await dialog.getByRole('textbox', { name: '自动化任务内容', exact: true }).fill('Check the deployment status.') await dialog.getByRole('button', { name: /^重复 / }).click() @@ -128,15 +176,14 @@ it('creates and edits Custom Cron through the built UI while retaining its expli expect(created).toMatchObject({ kind: 'cron', expression: '0 9 * * 1-5', timeZone: 'Asia/Shanghai' }) expect(created).not.toHaveProperty('rrule') - await detail.getByRole('button', { name: '编辑', exact: true }).click() await detail.getByRole('textbox', { name: '自定义', exact: true }).fill(' ') - await detail.getByRole('button', { name: '保存修改', exact: true }).click() - await detail.getByRole('alert').getByText('请检查规则内容和时区', { exact: true }).waitFor() + expect(await detail.getByRole('button', { name: '保存修改', exact: true }).isDisabled()).toBe(true) + await detail.getByRole('status').getByText('请检查必填项和运行规则', { exact: true }).waitFor() expect(await scaffold.ctx.schedule.view({ id: created.id })).toEqual(created) await detail.getByRole('textbox', { name: '自定义', exact: true }).fill('0 10 * * 1-5') await detail.getByRole('button', { name: /^时区 / }).waitFor() await detail.getByRole('button', { name: '保存修改', exact: true }).click() - await detail.getByRole('textbox', { name: '自定义', exact: true }).waitFor({ state: 'detached' }) + await expect.poll(() => detail.getByRole('button', { name: '保存修改', exact: true }).isDisabled()).toBe(true) const edited = await scaffold.ctx.schedule.view({ id: created.id }) expect(edited).toMatchObject({ id: created.id, kind: 'cron', expression: '0 10 * * 1-5', timeZone: 'Asia/Shanghai' }) expect(edited).not.toHaveProperty('rrule') diff --git a/apps/web/tests/schedule-phone.e2e.ts b/apps/web/tests/schedule-phone.e2e.ts index 46e1bb1bfd..6fdd275553 100644 --- a/apps/web/tests/schedule-phone.e2e.ts +++ b/apps/web/tests/schedule-phone.e2e.ts @@ -53,6 +53,26 @@ async function viewFacts(page: Page): Promise { }) } +/** Header, form, notices, and footer share the pane's visible content edges. */ +async function expectEditorAlignment(title: Locator): Promise { + await expect.poll(() => title.evaluate((field) => { + const pane = field.closest('aside')! + const bounds = pane.getBoundingClientRect() + const name = field.parentElement!.getBoundingClientRect() + const action = pane.querySelector('footer:last-of-type > button:last-of-type')!.getBoundingClientRect() + const content = Array.from(pane.querySelectorAll('h2, textarea, [class*="_ruleRows"], [class*="_saveNotice"], [class*="_detailNotice"], [class*="_saveFailure"]')) + .filter(node => node.getClientRects().length > 0) + const offsets = { + gutters: Math.abs(name.left - bounds.left - bounds.right + name.right), + action: Math.abs(action.right - name.right), + left: Math.max(...content.map(node => Math.abs(node.getBoundingClientRect().left - name.left))), + right: Math.max(...Array.from(pane.querySelectorAll('textarea, [class*="_ruleRows"]')) + .map(node => Math.abs(node.getBoundingClientRect().right - name.right))), + } + return Object.fromEntries(Object.entries(offsets).filter(([, offset]) => offset > 1)) + })).toEqual({}) +} + it('keeps the automation page on screen with its text fields at the touch step', async () => { const scaffold = await launchWebScaffold() const url = scaffold.authenticatedUrl @@ -82,7 +102,6 @@ it('keeps the automation page on screen with its text fields at the touch step', // The editor keeps the touch floor for its name and instruction fields. await phonePanel.getByRole('button', { name: PHONE_TASK_TITLE, exact: true }).click() await phonePanel.locator('[class*="_detailScroll"]').waitFor({ timeout: 10_000 }) - await phonePanel.getByRole('button', { name: '编辑', exact: true }).click() await expect.poll(() => viewFacts(phonePage)).toEqual({ width: PHONE_PAGE_WIDTH, documentWidth: PHONE_PAGE_WIDTH, @@ -91,6 +110,66 @@ it('keeps the automation page on screen with its text fields at the touch step', search: '16px', instruction: '16px', }) + const detail = phonePanel.getByRole('complementary', { name: '任务详情', exact: true }) + await expectEditorAlignment(detail.getByRole('textbox', { name: '自动化任务名称', exact: true })) + await detail.getByRole('textbox', { name: '自动化任务名称', exact: true }).fill('未保存的手机草稿') + const task = (await scaffold.ctx.schedule.catalog()).find(item => item.title === PHONE_TASK_TITLE) + if (task === undefined) throw new Error('phone task was not retained') + await scaffold.ctx.schedule.edit({ id: task.id, action: 'update', expectedUpdatedAt: task.updatedAt ?? null, + patch: { prompt: '其他窗口的最新内容' } }) + const recovery = detail.getByRole('button', { name: '保留修改并复核', exact: true }) + await recovery.waitFor() + await recovery.scrollIntoViewIfNeeded() + const recoveryBox = await recovery.boundingBox() + expect(recoveryBox).not.toBeNull() + expect(recoveryBox!.x).toBeGreaterThanOrEqual(0) + expect(recoveryBox!.x + recoveryBox!.width).toBeLessThanOrEqual(PHONE_PAGE_WIDTH) + expect(recoveryBox!.y).toBeGreaterThanOrEqual(0) + expect(recoveryBox!.y + recoveryBox!.height).toBeLessThanOrEqual(844) + const [noticeBox, messageBox, nameBox] = await Promise.all([ + detail.getByRole('alert').locator('..').boundingBox(), detail.getByRole('alert').boundingBox(), + detail.getByRole('textbox', { name: '自动化任务名称', exact: true }).locator('..').boundingBox(), + ]) + expect(noticeBox).not.toBeNull() + expect(messageBox).not.toBeNull() + expect(nameBox).not.toBeNull() + expect(Math.abs(noticeBox!.x - nameBox!.x)).toBeLessThanOrEqual(1) + expect(Math.abs(noticeBox!.x + noticeBox!.width - nameBox!.x - nameBox!.width)).toBeLessThanOrEqual(1) + expect(recoveryBox!.y).toBeGreaterThanOrEqual(messageBox!.y + messageBox!.height) + expect(recoveryBox!.x + recoveryBox!.width).toBeLessThanOrEqual(noticeBox!.x + noticeBox!.width) + expect(await detail.getByRole('button', { name: '保存修改', exact: true }).isDisabled()).toBe(true) + await recovery.click() + expect(await detail.getByRole('textbox', { name: '自动化任务名称', exact: true }).inputValue()).toBe('未保存的手机草稿') + expect(await detail.getByRole('textbox', { name: '自动化任务内容', exact: true }).inputValue()).toBe('其他窗口的最新内容') + expect((await viewFacts(phonePage)).documentWidth).toBe(PHONE_PAGE_WIDTH) + expect(await scaffold.ctx.schedule.view({ id: task.id })).toMatchObject({ title: PHONE_TASK_TITLE }) + await detail.getByRole('button', { name: '放弃', exact: true }).click() + await phonePanel.getByRole('button', { name: '关闭详情', exact: true }).click() + await phonePanel.getByRole('button', { name: '选择创建方式', exact: true }).click() + await phonePage.getByRole('menuitem', { name: '手动创建', exact: true }).click() + const creation = phonePanel.getByRole('complementary', { name: '手动创建', exact: true }) + await creation.waitFor() + await expectEditorAlignment(creation.getByRole('textbox', { name: '自动化任务名称', exact: true })) + await expect.poll(() => viewFacts(phonePage)).toEqual({ + width: PHONE_PAGE_WIDTH, + documentWidth: PHONE_PAGE_WIDTH, + smallestField: 16, + name: '16px', + search: '16px', + instruction: '16px', + }) + for (const name of ['放弃', '创建']) { + const button = creation.getByRole('button', { name, exact: true }) + await button.scrollIntoViewIfNeeded() + const box = await button.boundingBox() + expect(box).not.toBeNull() + expect(box!.x).toBeGreaterThanOrEqual(0) + expect(box!.x + box!.width).toBeLessThanOrEqual(PHONE_PAGE_WIDTH) + expect(box!.y).toBeGreaterThanOrEqual(0) + expect(box!.y + box!.height).toBeLessThanOrEqual(844) + } + await creation.getByRole('button', { name: '放弃', exact: true }).click() + expect(await phonePanel.getByRole('complementary').count()).toBe(0) await phone.close() // A fine pointer keeps the compact steps: the floor is pointer-scoped. @@ -108,7 +187,6 @@ it('keeps the automation page on screen with its text fields at the touch step', }) await desktopPanel.getByRole('button', { name: PHONE_TASK_TITLE, exact: true }).click() await desktopPanel.locator('[class*="_detailScroll"]').waitFor({ timeout: 10_000 }) - await desktopPanel.getByRole('button', { name: '编辑', exact: true }).click() await expect.poll(() => viewFacts(desktopPage)).toEqual({ width: 1024, documentWidth: 1024, @@ -130,3 +208,83 @@ it('keeps the automation page on screen with its text fields at the touch step', await scaffold.close() } }, 180_000) + +it.each([ + { locale: 'en-US', tasks: 'Automation tasks', sidebar: 'Collapse sidebar', openSidebar: 'Open sidebar', close: 'Close details', + methods: 'Choose a creation method', manual: 'Create manually', title: 'Automation task name', discard: 'Discard', + instruction: 'Automation task instruction', create: 'Create', + repeat: /^Repeat /, frequencies: ['Every month', 'Weekly', 'Once'] }, + { locale: 'zh-CN', tasks: '自动化任务', sidebar: '收起侧边栏', openSidebar: '打开侧边栏', close: '关闭详情', + methods: '选择创建方式', manual: '手动创建', title: '自动化任务名称', discard: '放弃', + instruction: '自动化任务内容', create: '创建', + repeat: /^重复 /, frequencies: ['每月', '每周', '仅一次'] }, + { locale: 'fr-FR', tasks: "Tâches d'automatisation", sidebar: 'Réduire la barre latérale', openSidebar: 'Ouvrir la barre latérale', close: 'Fermer les détails', + methods: 'Choisir le mode de création', manual: 'Créer manuellement', title: "Nom de la tâche d'automatisation", discard: 'Abandonner', + instruction: "Instruction de tâche d'automatisation", create: 'Créer', + repeat: /^Répéter /, frequencies: ['Tous les mois', 'Hebdomadaire', 'Une fois'] }, +] as const)('keeps both editor modes inside a narrow pane with the sidebar open ($locale)', async (copy) => { + const scaffold = await launchWebScaffold() + let browser: Browser | undefined + try { + browser = await chromium.launch() + await scaffold.ctx.schedule.create({ + title: PHONE_TASK_TITLE, prompt: 'Check the deployment log', + timing: { kind: 'at', at: '2099-08-25T12:08:00.000Z' }, target: { kind: 'new_once' }, + }) + const context = await browser.newContext({ viewport: { width: 1100, height: 844 }, locale: copy.locale, timezoneId: 'Asia/Shanghai' }) + const page = await context.newPage() + const consoleWatch = watchConsole(page) + await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) + await page.getByRole('button', { name: copy.sidebar, exact: true }).waitFor() + await page.getByRole('button', { name: copy.tasks, exact: true }).click() + const panel = page.getByTestId('task-manager-page') + await panel.getByRole('button', { name: PHONE_TASK_TITLE, exact: true }).click() + await page.evaluate(() => document.fonts.ready) + for (const mode of ['edit', 'create']) { + if (mode === 'create') { + await panel.getByRole('button', { name: copy.close, exact: true }).click() + await panel.getByRole('button', { name: copy.methods, exact: true }).click() + await page.getByRole('menuitem', { name: copy.manual, exact: true }).click() + } + const editor = panel.getByRole('complementary') + const title = editor.getByRole('textbox', { name: copy.title, exact: true }) + if (mode === 'create') { + for (const name of [copy.title, copy.instruction]) { + const field = editor.getByRole('textbox', { name, exact: true }) + expect(await field.getAttribute('required')).toBeNull() + expect(await field.getAttribute('aria-required')).toBe('true') + expect(await field.evaluate(node => (node as HTMLInputElement | HTMLTextAreaElement).validationMessage)).toBe('') + } + expect(await editor.getByRole('button', { name: copy.create, exact: true }).isDisabled()).toBe(true) + } + await title.fill('Retained draft through resizing') + await editor.getByRole('button', { name: copy.discard, exact: true }).waitFor() + for (const width of [1280, 1100, 1024, 900, 800]) { + await title.focus() + await page.setViewportSize({ width, height: 844 }) + expect(await title.evaluate(node => document.activeElement === node)).toBe(true) + // Entering the shell's narrow range publishes the reopen action after its resize observer runs. + if (width === 900) { await page.getByRole('button', { name: copy.openSidebar, exact: true }).click(); await title.focus() } + await page.getByRole('button', { name: copy.sidebar, exact: true }).waitFor() + expect(await panel.getByRole('button', { name: PHONE_TASK_TITLE, exact: true }).isVisible()).toBe(true) + for (const frequency of copy.frequencies) { + await editor.getByRole('button', { name: copy.repeat }).click() + await page.getByRole('menuitem', { name: frequency, exact: true }).click() + await expectEditorAlignment(title) + await expect.poll(() => editor.locator('[class*="_detailScroll"]').evaluate(node => node.scrollWidth - node.clientWidth)).toBe(0) + expect(await editor.locator('input, textarea, button').evaluateAll(nodes => nodes.every((node) => { + const box = node.getBoundingClientRect() + const pane = node.closest('aside')!.getBoundingClientRect() + return box.left >= pane.left && box.right <= pane.right + }))).toBe(true) + } + expect(await title.inputValue()).toBe('Retained draft through resizing') + } + await page.setViewportSize({ width: 1100, height: 844 }) + } + expect(consoleWatch.pageErrors).toEqual([]) + expect(consoleWatch.warnings).toEqual([]) + } finally { + try { await browser?.close() } finally { await scaffold.close() } + } +}, 180_000) diff --git a/apps/web/tests/schedule-pickers.e2e.ts b/apps/web/tests/schedule-pickers.e2e.ts index 057ec0879c..2548f71777 100644 --- a/apps/web/tests/schedule-pickers.e2e.ts +++ b/apps/web/tests/schedule-pickers.e2e.ts @@ -50,8 +50,8 @@ async function expectEllipsizedText(labels: Locator): Promise { } describe.each([ - { locale: 'en-US', tasks: 'Automation tasks', edit: 'Edit', time: 'Time', second: 'Second', zone: 'Time zone' }, - { locale: 'zh-CN', tasks: '自动化任务', edit: '编辑', time: '时间', second: '秒', zone: '时区' }, + { locale: 'en-US', tasks: 'Automation tasks', time: 'Time', second: 'Second', zone: 'Time zone' }, + { locale: 'zh-CN', tasks: '自动化任务', time: '时间', second: '秒', zone: '时区' }, ])('automation pickers ($locale)', (copy) => { it.each(['clock', 'zone'] as const)('ellipsizes the %s labels and keeps vertical choices reachable at 500% zoom', async (kind) => { const context = await browser.newContext({ @@ -66,7 +66,6 @@ describe.each([ await page.getByRole('button', { name: copy.tasks, exact: true }).click() const detail = page.getByTestId('task-manager-page') await detail.getByRole('button', { name: TITLE, exact: true }).click() - await detail.getByRole('button', { name: copy.edit, exact: true }).click() await page.evaluate(() => document.fonts.ready) const trigger = kind === 'clock' ? detail.getByRole('button', { name: copy.time, exact: true }) diff --git a/docs/user/guide/schedule.i18n.yaml b/docs/user/guide/schedule.i18n.yaml index 73c5f4dae9..31fba2c702 100644 --- a/docs/user/guide/schedule.i18n.yaml +++ b/docs/user/guide/schedule.i18n.yaml @@ -12,14 +12,14 @@ en: c1d163bf7d366e24 zh: 34dccfbb0bf3701d /schedule-reminders/create-reminders: - en: 9bd962e3653a8a72 - zh: 6b0887ed1477420c + en: 762ecb7a7743cd2d + zh: 1b163ae679601767 /schedule-reminders/inspect-run-and-delete-tasks: - en: 9407dca2b849be4a - zh: 9e158a42f4d95305 + en: 9f1e9d732597aa28 + zh: 66feec44adf24332 /schedule-reminders/edit-a-task: - en: 45f9dac1f9d86696 - zh: 3193f010cc6168da + en: fe8c59251f0b4620 + zh: a422e44f758adae1 /schedule-reminders/timing-and-delivery-reference: en: acb84b04d567d15c zh: c658a81d8c6875f4 diff --git a/docs/user/guide/schedule.md b/docs/user/guide/schedule.md index 37ed142182..bdee6c86b3 100644 --- a/docs/user/guide/schedule.md +++ b/docs/user/guide/schedule.md @@ -27,7 +27,7 @@ A conversation that a delivery creates joins the Workspace registered at its wor For example, ask: “Remind me every day at 23:00 in Asia/Shanghai to check the weather.” Below the reply, a card shows the created reminder's name and frequency; Open shows its details in the right sidebar. Check that the frequency repeats every day at 23:00, not Once. A one-time reminder does not become recurring after delivery. After the reminder is deleted, the card shows Deleted and no longer opens it. -To create a reminder without the model, open Automation tasks from the sidebar, open Choose a creation method beside New, and choose Create manually; when no task exists, New automation task opens the same dialog. The Create manually dialog asks for an Automation task name, an Automation task instruction, Run in, Linked workspace, and Run time. It starts with Once at one hour from now in the browser's time zone and with Create a conversation and reuse it. Run in offers Create a conversation and reuse it, which creates one conversation at the first run and keeps using it, and New conversation for every run, which creates a separate conversation at each run and shows the Host's minimum run interval. Linked workspace lists each registered Workspace with its directory and selects the Workspace whose directory the new conversation uses; it starts at Default workspace, or at the first Workspace when the default Workspace is not registered. When no Workspace exists, Linked workspace shows Ungrouped and the Host project directory is used. The new conversation uses the default preset. Create creates the task and selects it in the list, and Cancel closes the dialog without creating one. If the Host refuses the task, the dialog keeps your input and states the problem, for example that the date and time must be in the future. +To create a reminder without the model, open Automation tasks from the sidebar, open Choose a creation method beside New, and choose Create manually; when no task exists, New automation task opens the same editor. This editor also opens existing tasks and asks for an Automation task name, an Automation task instruction, Run in, Linked workspace, and Run time. It starts with Once at one hour from now in the browser's time zone and with Create a conversation and reuse it. Run in offers Create a conversation and reuse it, which creates one conversation at the first run and keeps using it, and New conversation for every run, which creates a separate conversation at each run and shows the Host's minimum run interval. Linked workspace lists each registered Workspace with its directory and selects the Workspace whose directory the new conversation uses; it starts at Default workspace, or at the first Workspace when the default Workspace is not registered. When no Workspace exists, Linked workspace shows Ungrouped and the Host project directory is used. The new conversation uses the default preset. Create creates the task and selects it in the list, and Discard closes the editor without creating one. If the Host refuses the task, the editor keeps your input and states the problem, for example that the date and time must be in the future. New, and Create in a conversation in the same menu, open a new conversation in the current or most recent Workspace; ask the model there to create the task. @@ -50,7 +50,7 @@ When retention removed earlier records, the last page states that earlier delive Active tasks participate in scheduling. Paused and ended tasks do not schedule another delivery. A one-time task ends after its reminder is durably written to the conversation inbox, and a repeating task ends after the last occurrence of its rule; choose All or Ended in Task status to find an ended task. The Session header clock, the row mark, and the hover card show only active tasks, so disappearance from those views does not mean that the task was deleted. -Pause in the details stops the future deliveries of an active task, and Resume restarts a paused task. Run now, in the Automation task actions menu, asks the Host to deliver the instruction once now and keeps the next scheduled run, also for a paused or ended task. While a delivery of a task that delivers to an existing conversation or to one new conversation is queued or running, Edit, Pause, Resume, Run now, and Delete task are disabled, and the details state that the task is queued or running and that you manage it in its conversation, which the button at the bottom of the details opens. A task that creates a new conversation for every run is not disabled this way; its runs continue beside one another. After a delivery, Run now stays disabled until the task's minimum delivery interval ends; while only the interval holds it, hold the pointer on Run now or move the keyboard to it to see when it becomes available. If the Host refuses a run for one of these reasons, the details state that the task is queued, running, or was just delivered. Run now is also disabled while the conversation that the task delivers to is archived. If you stop the conversation while the task's instruction waits there, the instruction stays queued until your next message, the task's next scheduled run, or Run now starts it. +Pause in the details stops the future deliveries of an active task, and Resume restarts a paused task. Run now, in the Automation task actions menu, asks the Host to deliver the instruction once now and keeps the next scheduled run, also for a paused or ended task. While a delivery of a task that delivers to an existing conversation or to one new conversation is queued or running, the fields, Save changes, Pause, Resume, Run now, and Delete task are disabled, and the details state that the task is queued or running and that you manage it in its conversation, which the button at the bottom of the details opens. A task that creates a new conversation for every run is not disabled this way; its runs continue beside one another. After a delivery, Run now stays disabled until the task's minimum delivery interval ends; while only the interval holds it, hold the pointer on Run now or move the keyboard to it to see when it becomes available. If the Host refuses a run for one of these reasons, the details state that the task is queued, running, or was just delivered. Run now is also disabled while the conversation that the task delivers to is archived. If you stop the conversation while the task's instruction waits there, the instruction stays queued until your next message, the task's next scheduled run, or Run now starts it. Choose Delete task from the Automation task actions menu and confirm to stop future delivery and remove the task from the list, including for a paused or ended task. Deletion removes the task together with its saved delivery records, so the task's saved history is gone. Confirming the deletion reports the outcome in one app-wide notice — deleted, which also closes the details, or a failure that leaves the task in place to retry; it does not remove the conversations or retract a message already queued there. The row stays visible until a successful query confirms the remaining tasks. If a query fails, Retry reloads the catalog; the error is not an empty successful result. @@ -59,7 +59,7 @@ Choose Delete task from the Automation task actions menu and confirm to stop fut Ask the model to change a reminder's name, instruction, repeat rule, or delivery target, or to pause or resume it; the change keeps the reminder id and saved delivery records. -In Automation tasks, select a task and choose Edit to change its Automation task name, Automation task instruction, Run in, Linked workspace, and Run time, including for a paused or ended task. Edits stay in a local draft until you choose Save changes. Editing keeps the task id, latest delivery receipt, and all saved delivery records. A changed rule makes an ended task active again and keeps a paused task paused. For a task that delivers to an existing conversation, Run in shows Current linked conversation; choosing another option makes later runs create their conversations and sets Linked workspace to its starting value, as in Create manually. A task keeps its stored preset while its Workspace stays the same; a changed Workspace uses the default preset. +In Automation tasks, select a task to change its Automation task name, Automation task instruction, Run in, Linked workspace, and Run time, including for a paused or ended task. Edits stay in a local draft until you choose Save changes. Editing keeps the task id, latest delivery receipt, and all saved delivery records. A changed rule makes an ended task active again and keeps a paused task paused. For a task that delivers to an existing conversation, Run in shows Current linked conversation; choosing another option makes later runs create their conversations and sets Linked workspace to its starting value, as in Create manually. A task keeps its stored preset while its Workspace stays the same; a changed Workspace uses the default preset. - Once: Date opens a month calendar, Time opens Hour, Minute, and Second columns, and Time zone interprets them. The task runs once and then ends. - Every N minutes and Every N hours: Interval sets the number of minutes or hours, at least 1. The interval counts from the minute at which you save the task. @@ -70,9 +70,9 @@ In Automation tasks, select a task and choose Edit to change its Automation task Time zone lists recently selected zones first, marks the system zone, and searches by UTC offset, IANA ID, or city. It appears for guided choices and Custom expressions that use a separate zone; otherwise the Custom rule text supplies its zone. -The fields change only a local draft. While you edit, the bottom of the details shows Unsaved changes with Cancel and Save changes; Save changes sends only the changed fields in one update, and Cancel restores the stored values. A save sends a new rule only when the timing changed. Save changes stays disabled while the name or instruction is empty or a guided choice is incomplete. The Host validates a supplied Custom rule on save; invalid text keeps the draft and shows an error. The fields are disabled while a save is in flight. Leaving the details does not roll back a Host write already begun. +The fields change only a local draft. If the task targets an existing conversation, Current linked session remains available so you can undo a destination change without discarding other edits. While you edit, the bottom of the details shows Unsaved changes with Discard and Save changes; Save changes sends only the changed fields in one update, and Discard restores the stored values. A save sends a new rule only when the timing changed. Save changes stays disabled until a meaningful change has valid fields and timing. Invalid Custom text keeps the draft and shows a correction message; the Host also validates the rule on save. Pause, resume, Run now, and deletion wait until you save or discard unsaved changes. The fields are disabled while a save is in flight. Leaving the details does not roll back a Host write already begun. -A catalog refresh does not change the draft. If delivery or another edit changed the task before the save arrives, the Host refuses the save and changes nothing; the details state that the task changed elsewhere, Load latest version replaces the draft with the latest version, and Save changes stays disabled until then. If another save fails, the draft stays and the details ask you to try again; check the task before retrying an update whose outcome is unknown. An accepted update refreshes the catalog. Late responses after closing details or switching tasks do not replace the current view. +Switching tasks or leaving the page keeps unsaved drafts. A catalog refresh updates a pristine form; an edited form keeps all fields and its original version. If delivery or another edit changes the task, the details state that the task changed elsewhere and disable Save changes when the newer version arrives. The Host also checks the version on save. Review with my edits keeps the title, prompt, timing, and target groups you changed and loads the latest values for the other groups. Review the whole form before saving; this action alone does not save. If the same group changed elsewhere, your edits take precedence in the form. Discard replaces the whole draft with the latest stored values. If another save fails, the draft stays and the details ask you to try again; check the task before retrying an update whose outcome is unknown. An accepted update refreshes the catalog. Late responses after closing details or switching tasks do not replace the current view. ## Timing and delivery reference diff --git a/docs/user/guide/schedule.zh.md b/docs/user/guide/schedule.zh.md index 1e52ae1f60..ebf7b24946 100644 --- a/docs/user/guide/schedule.zh.md +++ b/docs/user/guide/schedule.zh.md @@ -27,7 +27,7 @@ 例如,请求:“每天 Asia/Shanghai 时区 23:00 提醒我查看天气。”回复下方的卡片显示刚创建的提醒的名称和频率;“打开”在右侧栏显示其详情。检查频率是每天 23:00 重复,而非“仅一次”。一次性提醒不会在投递后变成重复任务。提醒删除后,卡片显示“已删除”,且不再打开该提醒。 -不经模型创建提醒时,从侧栏打开自动化任务页面,打开“新建”旁的“选择创建方式”,再选择“手动创建”;尚无任务时,“新建自动化任务”打开同一对话框。“手动创建”对话框要求填写“自动化任务名称”“自动化任务内容”“执行位置”“关联工作区”和“运行时间”。初始运行时间为“仅一次”,时间为浏览器时区下的一小时后,初始执行位置为“新建对话并复用”。“执行位置”提供“新建对话并复用”和“每次新建对话”:前者在首次运行时创建一个对话并在之后沿用,后者在每次运行时创建独立对话,并显示宿主的最小运行间隔。“关联工作区”列出每个已注册的 Workspace 及其目录,并选择新对话使用其目录的 Workspace;初始值为“默认工作区”,未注册默认 Workspace 时为第一个 Workspace。尚无任何 Workspace 时,“关联工作区”显示“未分组”,并使用宿主项目目录。新对话使用默认 preset。“创建”创建该任务并在列表中选中它,“取消”关闭对话框而不创建任务。若宿主拒绝该任务,对话框保留你的输入并说明问题,例如日期和时间必须在未来。 +不经模型创建提醒时,从侧栏打开自动化任务页面,打开“新建”旁的“选择创建方式”,再选择“手动创建”;尚无任务时,“新建自动化任务”打开同一编辑页。已有任务也使用此页面,填写“自动化任务名称”“自动化任务内容”“执行位置”“关联工作区”和“运行时间”。初始运行时间为“仅一次”,时间为浏览器时区下的一小时后,初始执行位置为“新建对话并复用”。“执行位置”提供“新建对话并复用”和“每次新建对话”:前者在首次运行时创建一个对话并在之后沿用,后者在每次运行时创建独立对话,并显示宿主的最小运行间隔。“关联工作区”列出每个已注册的 Workspace 及其目录,并选择新对话使用其目录的 Workspace;初始值为“默认工作区”,未注册默认 Workspace 时为第一个 Workspace。尚无任何 Workspace 时,“关联工作区”显示“未分组”,并使用宿主项目目录。新对话使用默认 preset。“创建”创建该任务并在列表中选中它,“放弃”关闭编辑页而不创建任务。若宿主拒绝该任务,编辑页保留你的输入并说明问题,例如日期和时间必须在未来。 “新建”以及同一菜单中的“在对话中创建”会在当前或最近使用的 Workspace 中打开一个新对话;在其中请模型创建该任务。 @@ -50,7 +50,7 @@ 活动任务参与调度;已暂停和已结束的任务不会再次安排投递。一次性任务在提醒持久写入对话收件箱后结束,重复任务在其规则的最后一个发生时点后结束;在“任务状态”中选择“全部”或“已结束”即可找到已结束的任务。Session 顶部的提醒时钟、Session 行的时钟标识和悬浮卡片只显示活动任务,因此从这些视图消失并不表示任务已被删除。 -详情中的“暂停任务”停止活动任务之后的投递,“恢复任务”重新启动已暂停的任务。“自动化任务操作”菜单中的“立即执行”请宿主现在投递一次指令,并保留下次计划运行;已暂停或已结束的任务也可以这样运行。投递到现有对话或一个新对话的任务的一次投递已排队或正在运行时,“编辑”“暂停任务”“恢复任务”“立即执行”和“删除任务”均禁用,详情说明此任务已排队或执行中,请在会话中管理任务;详情底部的按钮打开该会话。每次运行都创建新对话的任务不会这样禁用;它的各次运行并行继续。一次投递之后,“立即执行”保持禁用,直到该任务的最小投递间隔结束;仅因间隔禁用时,将指针停在“立即执行”上或用键盘移到该项,即可查看它恢复可用的时间。若宿主因上述原因之一拒绝运行,详情会说明该任务已排队、执行中或刚执行过。任务投递到的对话已归档时,“立即执行”同样禁用。若在任务指令仍在对话中等待时停止该对话,指令会保持排队,直到你的下一条消息、该任务的下一次计划运行或“立即执行”使其开始。 +详情中的“暂停任务”停止活动任务之后的投递,“恢复任务”重新启动已暂停的任务。“自动化任务操作”菜单中的“立即执行”请宿主现在投递一次指令,并保留下次计划运行;已暂停或已结束的任务也可以这样运行。投递到现有对话或一个新对话的任务的一次投递已排队或正在运行时,字段、“保存修改”“暂停任务”“恢复任务”“立即执行”和“删除任务”均禁用,详情说明此任务已排队或执行中,请在会话中管理任务;详情底部的按钮打开该会话。每次运行都创建新对话的任务不会这样禁用;它的各次运行并行继续。一次投递之后,“立即执行”保持禁用,直到该任务的最小投递间隔结束;仅因间隔禁用时,将指针停在“立即执行”上或用键盘移到该项,即可查看它恢复可用的时间。若宿主因上述原因之一拒绝运行,详情会说明该任务已排队、执行中或刚执行过。任务投递到的对话已归档时,“立即执行”同样禁用。若在任务指令仍在对话中等待时停止该对话,指令会保持排队,直到你的下一条消息、该任务的下一次计划运行或“立即执行”使其开始。 从“自动化任务操作”菜单选择“删除任务”并确认,可停止未来投递并将该任务从列表中移除,包括已暂停或已结束的任务。删除会移除该任务及其已保存的发送记录,因此该任务的已保存历史随之消失。确认删除会在同一个应用级提示里报告结果——已删除(同时关闭详情),或失败(失败时任务保留、可重试);删除不会删除相关对话,也不会撤回已进入其队列的消息。该行会保留到成功查询确认剩余任务为止。查询失败时,“重试”重新加载目录;错误不会被视为查询成功的空结果。 @@ -59,7 +59,7 @@ 请模型修改提醒的名称、指令、重复规则或投递目标,或暂停、恢复提醒;修改保留提醒 id 与已保存的投递记录。 -在自动化任务页面选择任务并选择“编辑”,即可修改其“自动化任务名称”“自动化任务内容”“执行位置”“关联工作区”和“运行时间”,包括已暂停或已结束的任务。修改先保存在本地草稿中,直到选择“保存修改”。编辑保留任务 id、最近一次投递回执以及全部已保存的发送记录。规则改变后,已结束的任务重新变为活动,已暂停的任务保持暂停。对于投递到现有对话的任务,“执行位置”显示“当前关联对话”;选择其他选项后,之后的运行会创建各自的对话,“关联工作区”也设为其初始值,与“手动创建”相同。Workspace 保持不变时,任务保留已存储的 preset;改换 Workspace 后使用默认 preset。 +在自动化任务页面选择任务,即可直接修改其“自动化任务名称”“自动化任务内容”“执行位置”“关联工作区”和“运行时间”,包括已暂停或已结束的任务。修改先保存在本地草稿中,直到选择“保存修改”。编辑保留任务 id、最近一次投递回执以及全部已保存的发送记录。规则改变后,已结束的任务重新变为活动,已暂停的任务保持暂停。对于投递到现有对话的任务,“执行位置”显示“当前关联对话”;选择其他选项后,之后的运行会创建各自的对话,“关联工作区”也设为其初始值,与“手动创建”相同。Workspace 保持不变时,任务保留已存储的 preset;改换 Workspace 后使用默认 preset。 - “仅一次”:“日期”打开月历,“时间”打开“时”“分”“秒”三列,“时区”决定如何解释它们。任务运行一次后结束。 - “每 N 分钟”和“每 N 小时”:“重复间隔”设置分钟数或小时数,至少为 1。间隔从你保存任务时所在的分钟起算。 @@ -70,9 +70,9 @@ “时区”先列出最近选择的时区,标出系统时区,并可按 UTC 偏移、IANA 标识或城市搜索。引导式选项和使用独立时区的“自定义”表达式显示此字段;其他“自定义”规则由文本指定时区。 -各字段只修改本地草稿。编辑期间,详情底部显示“有未保存的修改”以及“取消”和“保存修改”;“保存修改”以一次更新只提交已修改的字段,“取消”恢复已存储的值。只有时间规则改变时,保存才会提交新规则。名称或指令为空,或引导式选择不完整时,“保存修改”保持禁用。宿主在保存时验证所填的“自定义”规则;文本无效时保留草稿并显示错误。保存进行期间,各字段禁用。离开详情不会回滚宿主已开始的写入。 +各字段只修改本地草稿。若任务指向已有会话,执行位置仍提供“当前关联会话”,可撤销目标变更而保留其他修改。编辑期间,详情底部显示“有未保存的修改”以及“放弃”和“保存修改”;“保存修改”以一次更新只提交已修改的字段,“放弃”恢复已存储的值。只有时间规则改变时,保存才会提交新规则。只有实际修改且字段和时间规则有效时,才能“保存修改”。无效的自定义文本保留在草稿中,并显示纠正提示;宿主也会在保存时校验规则。有未保存修改时,先保存或放弃更改,才能暂停、恢复、立即执行或删除。保存进行期间,各字段禁用。离开详情不会回滚宿主已开始的写入。 -刷新目录不会改变草稿。若投递或其他编辑在保存到达前改变了任务,宿主拒绝保存且不做任何修改;详情会说明此任务已在其他位置更新,“载入最新版本”用最新版本替换草稿,在此之前“保存修改”保持禁用。保存因其他原因失败时,草稿保留,详情提示你重试;对于结果未知的更新,请在重试前检查任务。更新被接受后刷新目录。关闭详情或切换任务后才到达的响应不会替换当前视图。 +切换任务或离开页面时保留未保存的草稿。刷新目录会更新未修改的表单;已修改的表单保留全部字段和原版本。若投递或其他编辑改变了任务,详情会在收到新版本后说明任务已在其他位置更新,并禁用“保存修改”。宿主也会在保存时检查版本。“保留修改并复核”保留你改过的名称、内容、时间和目标字段组,其余字段组载入最新值。保存前请复核整份表单;此操作本身不保存。若同一字段组在其他位置也有更改,表单优先保留你的修改。“放弃”用最新存储值替换整份草稿。保存因其他原因失败时,草稿保留,详情提示你重试;对于结果未知的更新,请在重试前检查任务。更新被接受后刷新目录。关闭详情或切换任务后才到达的响应不会替换当前视图。 ## 时间与投递参考 diff --git a/packages/client/ui-schedule/README.i18n.yaml b/packages/client/ui-schedule/README.i18n.yaml index 0595c06496..bd2c8e8209 100644 --- a/packages/client/ui-schedule/README.i18n.yaml +++ b/packages/client/ui-schedule/README.i18n.yaml @@ -9,20 +9,20 @@ en: 862120984d5392eb zh: eb3e5d5a802da592 /deepseek-ai-dsh-client-ui-schedule/summary: - en: 0ccbbf29836a8fca - zh: d2de9b43e89ab05e + en: 9a690c99b0562de5 + zh: 77a7464316afb3ed /deepseek-ai-dsh-client-ui-schedule/table-of-contents: en: d152484eb41ac6b4 zh: 405b30feaf48c087 /deepseek-ai-dsh-client-ui-schedule/use-this-package: - en: 43cae3c92503c742 - zh: 41c64476fd9f2375 + en: 928ae699661089c5 + zh: 9895b75c5a30771b /deepseek-ai-dsh-client-ui-schedule/use-this-package/time-zone-data-source: en: 4005b800e930f581 zh: ccb9318dad7f7e8f /deepseek-ai-dsh-client-ui-schedule/understand-the-implementation: - en: 2ff0c2b6a93cd6b5 - zh: 388305ea48a79734 + en: f9895e84de5f5eb7 + zh: 844cba2fc3f424bc /deepseek-ai-dsh-client-ui-schedule/further-exploration: en: 2fd968202916b197 zh: f1ab66194846562b diff --git a/packages/client/ui-schedule/README.md b/packages/client/ui-schedule/README.md index ab2c248044..2bb348ba16 100644 --- a/packages/client/ui-schedule/README.md +++ b/packages/client/ui-schedule/README.md @@ -9,7 +9,7 @@ English | [中文](README.zh.md) ## Summary -The Automation tasks page and right Sidebar task tab share task rules, local edits, saved delivery records, deletion, and conversation navigation. Manual creation and target selection use the Host Schedule service; conversation cards, header clocks, and Session row marks retain their existing locations. +The Automation tasks page and right Sidebar task tab use the same editor for task rules, saved delivery records, deletion, and conversation navigation. Manual creation and target selection use the Host Schedule service; conversation cards, header clocks, and Session row marks retain their existing locations. ## Table of Contents @@ -27,17 +27,17 @@ The Automation tasks page and right Sidebar task tab share task rules, local edi Below 768px, the task list uses 20px horizontal insets, matching the Plugins page. -The shipped Web composition mounts `ui-schedule` with Host Schedule. The Automation tasks sidebar entry opens the task list without selecting or activating a Session. New retains its existing behavior: open a new conversation and let the user enter an instruction. Its adjacent menu offers Create in conversation and Create manually. Manual creation opens the shared Modal, validates required fields, and saves a task without starting an Agent or sending the instruction. A failed request leaves the form and its values visible. The empty state shows a decorative document-and-clock illustration whose colors follow the theme. +The shipped Web composition mounts `ui-schedule` with Host Schedule. The Automation tasks sidebar entry opens the task list without selecting or activating a Session. New retains its existing behavior: open a new conversation and let the user enter an instruction. Its adjacent menu offers Create in conversation and Create manually. Manual creation opens the same editor as an existing task, validates required fields, and saves a task without starting an Agent or sending the instruction. A failed request leaves the form and its values visible. The empty state shows a decorative document-and-clock illustration whose colors follow the theme. -Enabled, Paused, Ended, and All filters combine with text search over the title, prompt, and linked Session id; the page starts on Enabled. The search-row menu clears all ended tasks after confirmation, preserving active and paused tasks. Selecting a task opens Rules / Records. Edit stages a draft; Save sends changed fields with `expectedUpdatedAt`, or `null` when no stored revision exists. An unchanged Save still asks the Host to store the current row shape. A successful save returns to the read-only view and focuses Edit. Conflict retains the draft and offers Reload; Cancel discards it. Late responses cannot change another task's detail. Coarse-pointer search, instruction, and timing fields use 16px text to prevent focus zoom on iOS Safari. +Enabled, Paused, Ended, and All filters combine with text search over the title, prompt, and linked Session id; the page starts on Enabled. The search-row menu clears all ended tasks after confirmation, preserving active and paused tasks. Selecting a task opens its editable Rules / Records page. Save is enabled only for valid, meaningful changes and sends only changed fields with `expectedUpdatedAt`, or `null` when no stored revision exists. The fields stay editable after saving. Unsaved drafts survive navigation between tasks and away from the page. A conflict retains the whole draft and disables Save. Review with my edits reapplies the changed field groups to the latest values for review before saving; Discard replaces the draft with the latest stored values. For a new task, Discard closes the editor. Late responses cannot change another task's detail. Coarse-pointer search, instruction, and timing fields use 16px text to prevent focus zoom on iOS Safari. The destination menu offers a new conversation that the first delivery creates and later deliveries reuse, or a new conversation at every delivery. Manual creation defaults to reuse. A task already bound to a Session shows Current linked conversation as its destination, and editing it preserves that destination unless the user explicitly chooses a new one. The Linked workspace selector lists the framework Workspace catalog, shows each Workspace's directory under its name, and labels the first-use Workspace with its localized default name. A new destination starts in that Workspace, else in the first listed one. A stored task without a directory shows Ungrouped, because the Sessions it creates join no Workspace. For a reusable destination, the bottom conversation entry shows Pending creation until the first Session exists. A per-run destination instead shows Latest run conversation after its first delivery and hides the entry before that delivery; earlier conversations remain accessible from delivery records. Available links recheck membership and archive state before opening; missing or archived Sessions remain disabled. -The repeat editor offers once, minute, hour, day, week, month, and custom rules. Date and clock controls reuse existing pickers. Guided presets produce RRULE; minute and hour intervals start from the current minute in the selected zone. The Custom choice and Customize input do not name either syntax; the input accepts a two-line RRULE or a five-field Cron expression with an explicit zone. RRULE retains the zone in `DTSTART`; Cron retains its expression and selected zone as Cron timing. Complex RRULE values remain verbatim. Save validates Custom text through the Host; invalid or empty input keeps the draft open and shows the existing correction message. Existing After, At, Every, Daily, and Weekly records show their description in Custom and keep their typed timing until a replacement is entered. Editing other fields preserves the committed occurrence. +The repeat editor offers once, minute, hour, day, week, month, and custom rules. Date and clock controls reuse existing pickers. Guided presets produce RRULE; minute and hour intervals start from the current minute in the selected zone. The Custom choice and Customize input do not name either syntax; the input accepts a two-line RRULE or a five-field Cron expression with an explicit zone. RRULE retains the zone in `DTSTART`; Cron retains its expression and selected zone as Cron timing. Complex RRULE values remain verbatim. The shared time parser checks new or changed Custom text before enabling Save; invalid or empty input keeps the draft and shows the correction message. The Host performs the final validation on save. Existing After, At, Every, Daily, and Weekly records show their description in Custom and keep their typed timing until a replacement is entered. Editing other fields preserves the committed occurrence. -Pause and resume update lifecycle state. The detail menu offers Run now and Delete. It offers no queued-message cancellation: one inbox message may contain deliveries from several tasks. While a delivery to a reused conversation is queued or running, the detail disables Edit, pause and resume, Run now, and Delete, and states that the task is queued or running and is managed in its conversation, which the bottom conversation entry opens. The minimum delivery interval disables another immediate run until the interval ends, while pause and deletion remain available once execution is idle. When the interval is the only cause, the Run now row stays focusable, and its tooltip states that the minimum run interval has not passed and when Run now becomes available. An archived linked conversation of a task already bound to a Session also disables Run now, because the Host refuses that delivery. A run that the Host refuses with `schedule_execution_pending` shows a status notice instead of an error. Deletion requires confirmation, removes the task and its saved records, retains Sessions and already-delivered messages, and reports the result through the existing app-wide toast. The confirmation focuses Cancel first; when it closes, focus returns to the detail menu button. The detail keeps the task until the Host answers. An applied deletion closes the detail or its task tab; a failed deletion keeps the task open for another attempt. +Pause and resume update lifecycle state. Unsaved changes hold pause, resume, Run now, and Delete until you save or discard them. The detail menu offers Run now and Delete. It offers no queued-message cancellation: one inbox message may contain deliveries from several tasks. While a delivery to a reused conversation is queued or running, the detail disables its fields, Save, pause and resume, Run now, and Delete, and states that the task is queued or running and is managed in its conversation, which the bottom conversation entry opens. The minimum delivery interval disables another immediate run until the interval ends, while pause and deletion remain available once execution is idle. When the interval is the only cause, the Run now row stays focusable, and its tooltip states that the minimum run interval has not passed and when Run now becomes available. An archived linked conversation of a task already bound to a Session also disables Run now, because the Host refuses that delivery. A run that the Host refuses with `schedule_execution_pending` shows a status notice instead of an error. Deletion requires confirmation, removes the task and its saved records, retains Sessions and already-delivered messages, and reports the result through the existing app-wide toast. The confirmation focuses Cancel first; when it closes, focus returns to the detail menu button. The detail keeps the task until the Host answers. An applied deletion closes the detail or its task tab; a failed deletion keeps the task open for another attempt. -The list, detail, header, and Session hover show the later of the scheduled occurrence and the Host delivery floor as the next run. Creation and editing show one short minimum-interval hint for per-run conversation targets, read from `schedule.deliveryLimits`; a failed read offers Retry. The read-only detail keeps the next-run time without repeating that hint. Scheduled and immediate runs share this limit. +The list, detail, header, and Session hover show the later of the scheduled occurrence and the Host delivery floor as the next run. Creation and editing show one short minimum-interval hint for per-run conversation targets, read from `schedule.deliveryLimits`; a failed read offers Retry. Scheduled and immediate runs share this limit. Records lazily requests 20 saved deliveries, supports newest-first pagination, retains loaded records after failure, and ignores superseded or unmounted requests. Each record shows its occurrence and saved prompt, with Expand / Collapse for long prompts; legacy records without prompt text never substitute the current instruction. A receipt's actual destination has a conversation link when the Session is available. Confirmed pruning is stated only after the final saved page and offers the current retention explanation. These records acknowledge inbox delivery, not model execution success. @@ -55,7 +55,7 @@ Task menus use the [standard menu geometry](../../../docs/ui-radius.md#nested-ho
Implementation details — click to expand -While the Peer may read `schedule/catalog`, the plugin registers the existing `schedules` main panel, Session header utility, Turn tail card, Session row mark and hover entries, and `scheduleTask` right Sidebar tab. Slot injection supplies framework readers and action callbacks; components own disposable selection, search, form, and paging state. The Host owns task storage and execution. Browsing catalogs does not activate a Session. +While the Peer may read `schedule/catalog`, the plugin registers the existing `schedules` main panel, Session header utility, Turn tail card, Session row mark and hover entries, and `scheduleTask` right Sidebar tab. Slot injection supplies framework readers and action callbacks; components own selection, search, and paging state. Entry-declared stores retain each task draft and its CAS baseline across navigation within their root or Session scope; the main panel and Session tabs have independent drafts. Pristine forms follow the catalog. A dirty form retains all fields and its original revision. A newer catalog revision prevents saving until the user discards the draft or explicitly reapplies changed title, prompt, timing, and target groups to that revision. Reapplying does not write; the user reviews the resulting form and saves with the new CAS baseline. Untouched groups follow the newer record. Missing tasks retain editable local drafts while Host mutations stay disabled. Drafts are not persisted; a Client reload or disposal of the owning entry or Session scope drops them. The Host owns task storage and execution. Browsing catalogs does not activate a Session. Conflict feedback reuses the catalog notice style; its outlined review action wraps below the message in narrow panes. The manager, task tabs, row marks, and conversation-header projections share one observable `schedule.catalog` source. Header and row views filter active records by involvement and delivery target. Mutations use task-id-based `schedule.create`, `schedule.edit`, and `schedule.run`; history uses task identity and cursor without a Session ownership parameter. A mutation acknowledgment triggers a fresh authoritative read; a failed read remains a catalog error rather than changing the acknowledged write into a failure. diff --git a/packages/client/ui-schedule/README.zh.md b/packages/client/ui-schedule/README.zh.md index ad42208b4f..f7f4ff4d9e 100644 --- a/packages/client/ui-schedule/README.zh.md +++ b/packages/client/ui-schedule/README.zh.md @@ -9,7 +9,7 @@ kind: "package-reference" ## 概述 -自动化任务页和右侧栏任务页签共用任务规则、本地编辑、已保存的投递记录、删除及会话导航。手动创建和执行目标选择使用宿主的 Schedule 服务;会话卡片、页头时钟和会话行标记保留现有位置。 +自动化任务页和右侧栏任务页签使用同一编辑器处理任务规则、已保存的投递记录、删除及会话导航。手动创建和执行目标选择使用宿主的 Schedule 服务;会话卡片、页头时钟和会话行标记保留现有位置。 ## 目录 @@ -27,17 +27,17 @@ kind: "package-reference" 宽度小于 768px 时,任务列表使用 20px 的左右内边距,与插件页一致。 -发布的 Web 组合将 `ui-schedule` 与宿主 Schedule 一起挂载。自动化任务侧栏入口打开任务列表,不选择或激活会话。“新建”保留现有行为:进入新会话,由用户输入指令。相邻下拉提供“在对话中创建”和“手动创建”。手动创建打开共用 Modal,校验必填项并保存任务,不启动 Agent 或发送指令。请求失败时保留表单和已填内容。空态显示装饰性的文档与时钟插图,其颜色随主题变化。 +发布的 Web 组合将 `ui-schedule` 与宿主 Schedule 一起挂载。自动化任务侧栏入口打开任务列表,不选择或激活会话。“新建”保留现有行为:进入新会话,由用户输入指令。相邻下拉提供“在对话中创建”和“手动创建”。手动创建与已有任务打开同一编辑页,校验必填项并保存任务,不启动 Agent 或发送指令。请求失败时保留表单和已填内容。空态显示装饰性的文档与时钟插图,其颜色随主题变化。 -“已开启”“已暂停”“已结束”“全部”筛选结合标题、指令和关联会话 id 搜索,默认显示已开启任务。搜索行菜单在确认后清除全部已结束任务,保留已开启和已暂停任务。选择任务打开“规则 / 任务运行记录”。编辑暂存草稿;保存发送变更字段及 `expectedUpdatedAt`,存储版本缺失时发送 `null`。未改动的保存仍要求宿主写入当前行格式。成功后返回只读视图并聚焦“编辑”。冲突保留草稿并提供“重新加载”;取消丢弃草稿。迟到响应不会改变其他任务详情。粗指针设备的搜索、指令和时间字段使用 16px 字号,避免 iOS Safari 聚焦时缩放。 +“已开启”“已暂停”“已结束”“全部”筛选结合标题、指令和关联会话 id 搜索,默认显示已开启任务。搜索行菜单在确认后清除全部已结束任务,保留已开启和已暂停任务。选择任务直接打开可编辑的“规则 / 任务运行记录”页面。只有字段有效且有实际修改时才能保存;保存只发送变更字段及 `expectedUpdatedAt`,存储版本缺失时发送 `null`。保存后字段保持可编辑。切换任务或离开页面时保留未保存的草稿。冲突保留整份草稿并禁用保存。“保留修改并复核”将改过的字段组应用到最新值,供保存前复核;“放弃”用最新存储值替换草稿。对于新任务,“放弃”关闭编辑页。迟到响应不会改变其他任务详情。粗指针设备的搜索、指令和时间字段使用 16px 字号,避免 iOS Safari 聚焦时缩放。 执行位置下拉提供“新建对话并复用”和“每次新建对话”,手动创建默认前者。已经关联会话的任务,执行位置显示“当前关联对话”;编辑时保留原目标,只有用户主动选择新方式才会切换。“关联工作区”选择器列出框架工作区目录,在每个工作区名称下显示其路径,并以本地化默认名称标注首次使用时创建的工作区。新的执行位置默认使用该工作区;没有该工作区时使用列表中的第一个。没有目录的已有任务显示“未分组”,因为它创建的会话不加入任何工作区。复用目标的首次会话尚未存在时,详情底部入口显示“待创建”。每次新建的目标在首次投递后显示“最近运行对话”,首次投递前隐藏该入口;更早的对话仍可从任务运行记录进入。可用链接在打开前再次检查会话是否仍存在、是否归档;缺失或归档会话保持禁用。 -重复编辑提供仅一次、每分钟、每小时、每天、每周、每月和自定义规则。日期和时间控件复用已有选择器。引导选项生成 RRULE;分钟和小时间隔从所选时区的当前分钟开始。自定义选项和自定义输入框不提示任何语法名称;输入框接受两行 RRULE 或带显式时区的五字段 Cron。RRULE 在 `DTSTART` 中保留时区;Cron 将表达式和所选时区保留为 Cron 时间类型。复杂 RRULE 保持原文。保存通过 Host 校验自定义文本;无效或空输入保持草稿打开,并显示已有纠正提示。已有 After、At、Every、Daily、Weekly 记录在自定义中显示描述,并在输入替代规则前保留原类型。编辑其他字段保留已提交发生时点。 +重复编辑提供仅一次、每分钟、每小时、每天、每周、每月和自定义规则。日期和时间控件复用已有选择器。引导选项生成 RRULE;分钟和小时间隔从所选时区的当前分钟开始。自定义选项和自定义输入框不提示任何语法名称;输入框接受两行 RRULE 或带显式时区的五字段 Cron。RRULE 在 `DTSTART` 中保留时区;Cron 将表达式和所选时区保留为 Cron 时间类型。复杂 RRULE 保持原文。新的或已修改的自定义文本由共享时间解析器校验,校验通过后才能保存;无效或空输入保留草稿并显示纠正提示。宿主在保存时执行最终校验。已有 After、At、Every、Daily、Weekly 记录在自定义中显示描述,并在输入替代规则前保留原类型。编辑其他字段保留已提交发生时点。 -暂停和恢复修改生命周期状态。详情菜单提供立即执行和删除,不提供取消排队消息:同一条收件箱消息可能包含多个任务的投递。投递到复用对话的投递排队或执行期间,详情禁用编辑、暂停与恢复、立即执行和删除,并说明此任务已排队或执行中,请在会话中管理任务;详情底部的会话入口打开该会话。最小投递间隔结束前禁用再次立即执行,执行空闲后仍可暂停或删除。仅因间隔禁用时,立即执行项仍可聚焦,其提示说明未满最小运行间隔,并给出可以立即执行的时间。已经关联会话的任务,其关联对话已归档时,同样禁用立即执行,因为宿主拒绝这次投递。宿主以 `schedule_execution_pending` 拒绝的立即执行显示为状态提示,而非错误。删除需要确认,移除任务及其已保存记录,保留会话和已经投递的消息,并通过现有应用级提示报告结果。确认对话框首先聚焦“取消”;对话框关闭后,焦点回到详情菜单按钮。宿主答复之前,详情保持显示该任务。删除生效后关闭详情或其任务页签;删除失败时保留任务,以便再次尝试。 +暂停和恢复修改生命周期状态。有未保存修改时,先保存或放弃更改,才能暂停、恢复、立即执行或删除。详情菜单提供立即执行和删除,不提供取消排队消息:同一条收件箱消息可能包含多个任务的投递。投递到复用对话的投递排队或执行期间,详情禁用字段、保存、暂停与恢复、立即执行和删除,并说明此任务已排队或执行中,请在会话中管理任务;详情底部的会话入口打开该会话。最小投递间隔结束前禁用再次立即执行,执行空闲后仍可暂停或删除。仅因间隔禁用时,立即执行项仍可聚焦,其提示说明未满最小运行间隔,并给出可以立即执行的时间。已经关联会话的任务,其关联对话已归档时,同样禁用立即执行,因为宿主拒绝这次投递。宿主以 `schedule_execution_pending` 拒绝的立即执行显示为状态提示,而非错误。删除需要确认,移除任务及其已保存记录,保留会话和已经投递的消息,并通过现有应用级提示报告结果。确认对话框首先聚焦“取消”;对话框关闭后,焦点回到详情菜单按钮。宿主答复之前,详情保持显示该任务。删除生效后关闭详情或其任务页签;删除失败时保留任务,以便再次尝试。 -列表、详情、页头和会话悬浮内容的下次运行时间,取计划发生时间和宿主最早允许投递时间中较晚的一项。创建和编辑“每次新建对话”时,通过 `schedule.deliveryLimits` 读取宿主配置,以一句短提示显示最小间隔;读取失败可重试。只读详情保留下次运行时间,不重复该提示。定时与立即执行共用此限制。 +列表、详情、页头和会话悬浮内容的下次运行时间,取计划发生时间和宿主最早允许投递时间中较晚的一项。创建和编辑“每次新建对话”时,通过 `schedule.deliveryLimits` 读取宿主配置,以一句短提示显示最小间隔;读取失败可重试。定时与立即执行共用此限制。 “任务运行记录”按需请求 20 条已保存投递,支持从新到旧分页,失败时保留已加载记录,并忽略被刷新替代或卸载后的请求。每条记录显示投递发生时间与已保存指令,长指令可展开、收起;缺少指令的旧记录不使用当前指令替代。回执的实际执行会话可用时提供入口。仅在最后一页且确认裁剪后显示清理提示,并提供当前保留规则说明。这些记录确认收件箱投递,不表示模型执行成功。 @@ -55,7 +55,7 @@ kind: "package-reference"
实现内部细节 — 点击展开 -Peer 可读取 `schedule/catalog` 时,插件注册现有 `schedules` 主面板、会话页头功能位、轮次尾部卡片、会话行标记与悬浮内容,以及 `scheduleTask` 右侧栏页签。槽位注入提供框架读取器与操作回调;组件拥有可丢弃的选择、搜索、表单和分页状态。宿主拥有任务存储与执行。浏览目录不会激活会话。 +Peer 可读取 `schedule/catalog` 时,插件注册现有 `schedules` 主面板、会话页头功能位、轮次尾部卡片、会话行标记与悬浮内容,以及 `scheduleTask` 右侧栏页签。槽位注入提供框架读取器与操作回调;组件拥有选择、搜索和分页状态。入口声明的存储在根或会话作用域中按任务保留草稿和 CAS 基线,支持导航后恢复;主面板与会话页签的草稿相互独立。未修改的表单跟随目录更新。已修改的表单保留全部字段及原版本。目录出现新版本后,须放弃草稿,或由用户明确将改过的名称、内容、时间和目标字段组重新应用到该版本,才能保存。此操作不写入任务;用户复核结果后,以新版本作为 CAS 基线保存。未修改的字段组采用新记录的值。任务缺失时保留可编辑的本地草稿,宿主修改操作仍禁用。草稿不持久化;客户端重新加载,或所属入口、会话作用域销毁时,草稿随之释放。宿主拥有任务存储与执行。浏览目录不会激活会话。冲突反馈沿用目录提示样式;复核按钮采用描边样式,在窄面板中换到提示下方。 管理页、任务页签、行标记和会话页头投影共享一个可观察的 `schedule.catalog` 数据源。页头与会话行根据关联关系和执行目标筛选活动记录。修改使用基于任务 id 的 `schedule.create`、`schedule.edit` 和 `schedule.run`;历史使用任务标识和游标,不携带会话所有权参数。修改确认后发起新的权威读取;回读失败仍是目录错误,不将已经确认的写入改判为失败。 diff --git a/packages/client/ui-schedule/package.json b/packages/client/ui-schedule/package.json index bd9ccb6b07..b11b3a2331 100644 --- a/packages/client/ui-schedule/package.json +++ b/packages/client/ui-schedule/package.json @@ -60,6 +60,7 @@ "@deepseek-ai/dsh-api-workspace-controller": "workspace:*", "@deepseek-ai/dsh-client-connection": "workspace:*", "@deepseek-ai/dsh-client-locale": "workspace:*", + "@deepseek-ai/dsh-client-store": "workspace:*", "@deepseek-ai/dsh-client-test-runtime": "workspace:*", "@deepseek-ai/dsh-client-ui-conversation": "workspace:*", "@deepseek-ai/dsh-client-ui-layout": "workspace:*", diff --git a/packages/client/ui-schedule/src/client/ScheduleTaskTab.tsx b/packages/client/ui-schedule/src/client/ScheduleTaskTab.tsx index fe5ae47615..1b3df3b5b5 100644 --- a/packages/client/ui-schedule/src/client/ScheduleTaskTab.tsx +++ b/packages/client/ui-schedule/src/client/ScheduleTaskTab.tsx @@ -7,7 +7,7 @@ * offer identical fields, Host edits and runs, saved deliveries, confirmed * deletion, and the linked Session entry. A record restored by a reload carries * no parameters, so the body falls back to the provider-owned binding that the - * navigation wrote; a task that an open edit or a confirmed deletion retained + * navigation wrote; a task that an unsaved draft or a confirmed deletion retained * keeps the detail on screen after the catalog row disappears, and an applied * deletion closes this tab once the catalog refresh after it settles; without a * retained task, the body reports that the task is gone. @@ -23,6 +23,7 @@ import type { CatalogSnapshot } from './catalog-source.ts' import { CatalogFeedback } from './CatalogFeedback.tsx' import { TaskDetail, useTaskDetail, type TaskDetailInjected } from './TaskDetail.tsx' import type { TaskTabBindings } from './task-tab-bindings.ts' +import type { TaskEditorStoreProps } from './editor-store.ts' import { useTaskTabTarget } from './task-tab-target.ts' import css from './TaskManagerPage.module.css' @@ -43,6 +44,7 @@ export interface ScheduleTaskTabInjected extends TaskDetailInjected, ScheduleTas /** Props of the task tab's body: the tab it draws, localized copy, and its catalog face. */ export type ScheduleTaskTabProps = PropsRuntime<'sidebar.right.pane.tab'> + & TaskEditorStoreProps & PropsLocale<'schedule.manager'> & InjectFace diff --git a/packages/client/ui-schedule/src/client/TaskCreateDialog.tsx b/packages/client/ui-schedule/src/client/TaskCreateDialog.tsx deleted file mode 100644 index 2467eed403..0000000000 --- a/packages/client/ui-schedule/src/client/TaskCreateDialog.tsx +++ /dev/null @@ -1,53 +0,0 @@ -/** Manual creation reuses the existing Modal and Rules editor controls. */ -import { useState } from 'react' -import type { ReactNode } from 'react' -import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots' -import type { ScheduleCatalogEntry, ScheduleCreateRequest } from '@deepseek-ai/dsh-schedule/client' -import { Button, Modal } from '@deepseek-ai/dsh-client-ui-primitives' -import { TaskEditorFields, draftTarget, newTaskDraft, taskDraftValid } from './TaskEditorFields.tsx' -import type { ProjectChoices } from './TaskEditorFields.tsx' -import { timingFromDraft } from './editor-timing.ts' -import type { HostTaskActions } from './TaskDetail.tsx' -import { NewSessionLimit } from './NewSessionLimit.tsx' -import css from './TaskManagerPage.module.css' - -/** Creation outcome retains Host validation and never closes a failed draft. */ -export type TaskCreateOutcome = { readonly created: ScheduleCatalogEntry } - | { readonly failed: 'host.createError' | 'host.notFuture' | 'host.invalidRule' } - -/** Create one task without starting an Agent or sending its instruction. */ -export function TaskCreateDialog({ projects, onCreate, onClose, onCreated, loadNewSessionInterval, t }: PropsLocale<'schedule.manager'> & { - readonly projects: ProjectChoices - readonly loadNewSessionInterval: HostTaskActions['loadNewSessionInterval'] - readonly onCreate: (request: ScheduleCreateRequest) => Promise - readonly onClose: () => void - readonly onCreated: (task: ScheduleCatalogEntry) => void -}): ReactNode { - const [input, setDraft] = useState(newTaskDraft) - // An unchosen directory follows the starting Workspace, which can arrive after the dialog opens. - const draft = input.cwd === '' ? { ...input, cwd: projects.defaultCwd } : input - const [pending, setPending] = useState(false) - const [failure, setFailure] = useState['failed'] | null>(null) - const save = async (): Promise => { - setPending(true) - setFailure(null) - const outcome = await onCreate({ - title: draft.title, prompt: draft.prompt, timing: timingFromDraft(draft, true), target: draftTarget(draft), - }) - setPending(false) - if ('created' in outcome) onCreated(outcome.created) - else setFailure(outcome.failed) - } - return { if (!pending) onClose() }} - footer={
- - -
}> - - {draft.target === 'new' && } - {failure !== null &&

{t(failure)}

} -
-} diff --git a/packages/client/ui-schedule/src/client/TaskDetail.tsx b/packages/client/ui-schedule/src/client/TaskDetail.tsx index 2f6b853337..9bd279997d 100644 --- a/packages/client/ui-schedule/src/client/TaskDetail.tsx +++ b/packages/client/ui-schedule/src/client/TaskDetail.tsx @@ -1,10 +1,9 @@ /** One task's rule, saved deliveries, edits, runs, and linked Session. */ -import { useEffect, useId, useRef, useState } from 'react' +import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react' import type { ReactNode } from 'react' -import { flushSync } from 'react-dom' import clsx from 'clsx' import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' -import type { ScheduleCatalogEntry, ScheduleEditRequest, ScheduleId } from '@deepseek-ai/dsh-schedule/client' +import type { ScheduleCatalogEntry, ScheduleCreateRequest, ScheduleEditRequest, ScheduleId } from '@deepseek-ai/dsh-schedule/client' import type { SessionId } from '@deepseek-ai/dsh-session/types' import type { SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client' import { @@ -14,9 +13,11 @@ import { import { CatalogFeedback } from './CatalogFeedback.tsx' import { DeliveryHistory, type DeliveryHistoryInjected } from './DeliveryHistory.tsx' import type { CatalogDeleteOutcome, CatalogSnapshot } from './catalog-source.ts' -import { TaskEditorFields, draftTarget, projectChoices, targetLabelKey, taskDraft, taskDraftValid } from './TaskEditorFields.tsx' +import { TaskEditorFields, draftTarget, newTaskDraft, projectChoices, reapplyTaskDraft, taskDraft, taskDraftPatch, taskDraftValid } from './TaskEditorFields.tsx' +import type { TaskEditorDraft } from './TaskEditorFields.tsx' +import type { TaskEditorStoreProps } from './editor-store.ts' import { timingFromDraft } from './editor-timing.ts' -import { formatAvailableAt, formatScheduleFrequency, nextRunParts, recordTimeZone, zoneLabel } from './schedule-format.ts' +import { formatAvailableAt, nextRunParts, recordTimeZone } from './schedule-format.ts' import { sessionLinkState } from './session-link.ts' import { taskNextRunAt, taskSessionId } from './task-record.ts' import { NewSessionLimit } from './NewSessionLimit.tsx' @@ -29,6 +30,10 @@ export type HostEditFailure = 'host.saveError' | 'host.conflict' | 'host.notFutu /** Localized reason the Host refused a run, or reason the wiring could not confirm it. */ export type HostRunFailure = 'host.runError' | 'host.executionPending' | 'detail.missing' +/** Creation keeps a failed draft and never creates or activates its destination Session. */ +export type TaskCreateOutcome = { readonly created: ScheduleCatalogEntry } + | { readonly failed: 'host.createError' | 'host.notFuture' | 'host.invalidRule' } + /** Target-based mutations supplied by the owning plugin's Remote wiring. */ export interface HostTaskActions { /** @@ -76,28 +81,21 @@ export interface TaskDetailInjected extends DeliveryHistoryInjected { } /** One task's detail, as the Tasks page and the task tab both compose it. */ -export type TaskDetailProps = TaskDetailInjected +type TaskDetailCommonProps = TaskDetailInjected + & TaskEditorStoreProps & PropsLocale<'schedule.manager'> & Pick, 'useSessions' | 'useWorkspaces'> & { - /** Task shown; an authoritative catalog row refreshes on its own outside an open edit. */ - readonly task: ScheduleCatalogEntry - /** - * Whether an authoritative catalog row backs the shown task; a retained task alone disables its edit, pause, - * run, and delete entries. - */ - readonly authoritative: boolean /** Element id shared by the detail panels and any control that points at them. */ readonly id: string - /** Catalog query state; loading keeps every action visible and disabled. */ + /** Catalog query state; loading disables saved-task actions. */ readonly status: 'loading' | 'ready' | 'error' /** Tasks with a deletion in flight. */ readonly deleting: readonly ScheduleId[] /** - * Report the task that an open edit started from or that a confirmed deletion is removing, so its owner - * retains it outside the catalog, or null when that edit closes or the Host does not apply that deletion. + * Retain a task while a confirmed deletion and its catalog refresh settle. */ - readonly onEditState: (task: ScheduleCatalogEntry | null) => void + readonly onRetainTask: (task: ScheduleCatalogEntry | null) => void /** Active detail view; the owner resets it to Rules when it selects another task. */ readonly tab: TaskDetailTab /** Select the active detail view. */ @@ -115,44 +113,60 @@ export type TaskDetailProps = TaskDetailInjected readonly onClose?: () => void } -/** One task detail's editing state, as its Tasks page or task tab owns it. */ +/** New and existing tasks use the same editable page; only submission and saved-task actions differ. */ +export type TaskDetailProps = TaskDetailCommonProps & ({ + readonly task: ScheduleCatalogEntry + readonly authoritative: boolean + readonly onCreateTask?: never + readonly onCreated?: never +} | { + readonly task?: undefined + readonly authoritative?: never + readonly onCreateTask: (request: ScheduleCreateRequest) => Promise + readonly onCreated: (task: ScheduleCatalogEntry) => void +}) + +/** One task detail's selected tab, confirmation, and retained catalog row. */ export interface TaskDetailController { /** Catalog row the shown id resolves to, or undefined when the read has no such row. */ readonly record: ScheduleCatalogEntry | undefined - /** Task to show: the catalog row, or the task that an open edit or a confirmed deletion retained. */ + /** Task to show: the catalog row, an unsaved draft's baseline, or a confirmed deletion's retained row. */ readonly task: ScheduleCatalogEntry | undefined /** Props the shared detail element takes, without the task it shows. */ - readonly props: Omit + readonly props: Omit } /** - * Own the editing state one task detail shares across both of its owners. + * Own selected-task state shared by the Tasks page and task tabs. * - * The shown task is the catalog row for `taskId`, or the task that an open edit - * or a confirmed deletion of that row retained after the row left the catalog. - * The view, the confirmation, and the retained task all reset when `taskId` - * changes, so one task's edit never carries into another. + * The shown task comes from the catalog, an unsaved form's CAS baseline, or a + * confirmed deletion. The view and confirmation reset when selection changes; + * the entry's store retains unsaved fields by task identity. * @param injected - detail actions, localized copy, and framework readers. * @param catalog - the owner's authoritative task catalog snapshot. * @param taskId - task the owner selected, or undefined when it selected none. * @returns the shown task and catalog row, its element id, its confirmation, and the detail props. */ export function useTaskDetail( - injected: TaskDetailInjected & PropsLocale<'schedule.manager'> & Pick, 'useSessions' | 'useWorkspaces'>, + injected: TaskDetailInjected & TaskEditorStoreProps & PropsLocale<'schedule.manager'> & Pick, 'useSessions' | 'useWorkspaces'>, catalog: CatalogSnapshot, taskId: ScheduleId | undefined, ): TaskDetailController { - const [draft, setDraft] = useState(null) + const [retained, setRetained] = useState(null) const [tab, setTab] = useState('rule') const [confirmId, setConfirmId] = useState(null) const id = useId() + const savedDraft = injected.useStore(state => taskId === undefined ? undefined : state.drafts[`task:${taskId}`]) useEffect(() => { - setDraft(null) + setRetained(null) setTab('rule') setConfirmId(null) }, [taskId]) const record = taskId === undefined ? undefined : catalog.records.find(item => item.id === taskId) - const task = record ?? (draft !== null && draft.id === taskId ? draft : undefined) + const edited = record === undefined && savedDraft?.base !== undefined + && Object.keys(taskDraftPatch(savedDraft.draft, savedDraft.base)).length > 0 + ? savedDraft.base : undefined + const task = record ?? edited ?? (retained !== null && retained.id === taskId ? retained : undefined) return { record, task, props: { @@ -160,7 +174,7 @@ export function useTaskDetail( status: catalog.status, deleting: catalog.deleting, id, - onEditState: setDraft, + onRetainTask: setRetained, tab, onTabChange: setTab, confirmId, @@ -170,12 +184,12 @@ export function useTaskDetail( } /** - * Render one task's rule or saved deliveries; changing its id resets the edit. + * Render one new or existing task's editable rule or saved deliveries. * @param props - Task, catalog state, detail view, confirmation, locale, and actions. * @returns The detail region and its deletion confirmation dialog. */ export function TaskDetail(props: TaskDetailProps): ReactNode { - return + return } function TaskDetailView(props: TaskDetailProps): ReactNode { @@ -183,111 +197,131 @@ function TaskDetailView(props: TaskDetailProps): ReactNode { onRetry, onOpenSession, loadHistory, status, deleting, useSessions, useWorkspaces, t, hostActions } = props const sessions = useSessions(snapshot => snapshot) const workspaces = useWorkspaces(snapshot => snapshot) - const [editing, setEditing] = useState(false) - const [draft, setDraft] = useState(() => taskDraft(task)) - const [base, setBase] = useState(task) - const [pending, setPending] = useState(false) - const [failure, setFailure] = useState(null) + const key = task === undefined ? 'new' : `task:${task.id}` + const stored = props.useStore(state => state.drafts[key]) + const [seed] = useState(newTaskDraft) + const initial = stored?.initial ?? seed + const changes = useMemo(() => stored?.base === undefined ? undefined : taskDraftPatch(stored.draft, stored.base), + [stored?.draft, stored?.base]) + const storedDirty = changes !== undefined && Object.keys(changes).length > 0 + const cached = stored?.base !== undefined && !storedDirty && !stored.pending && stored.failure === undefined + && stored.base.updatedAt !== task?.updatedAt ? undefined : stored + const base = cached?.base ?? task + const input = cached?.draft ?? (task === undefined ? initial : taskDraft(task)) + const projects = projectChoices(workspaces.items, t('host.defaultProject')) + // Until a directory is chosen, a new form follows the Workspace list as it arrives. + const draft = task === undefined && input.cwd === '' ? { ...input, cwd: projects.defaultCwd } : input + const dirty = base === undefined + ? JSON.stringify(draft) !== JSON.stringify({ ...initial, cwd: initial.cwd || projects.defaultCwd }) : storedDirty + const valid = !dirty || taskDraftValid(draft, changes) + const [actionPending, setPending] = useState(false) + const [actionFailure, setFailure] = useState(null) + const saving = cached?.pending === true + const pending = actionPending || saving + const failure = !pending && dirty && base !== undefined && task !== undefined && base.updatedAt !== task.updatedAt + ? 'host.conflict' : actionFailure ?? cached?.failure ?? null const [menuOpen, setMenuOpen] = useState(false) - const editRef = useRef(null) const moreRef = useRef(null) const panelRef = useRef(null) + const scrollRef = useRef(null) const mounted = useRef(true) + useLayoutEffect(() => { + const scroll = scrollRef.current as HTMLDivElement + const measure = (): void => { + scroll.style.setProperty('--detail-scrollbar-space', `${scroll.offsetWidth - scroll.clientWidth}px`) + } + measure() + const observer = new ResizeObserver(measure) + observer.observe(scroll) + return () => { observer.disconnect() } + }, [tab]) useEffect(() => { mounted.current = true panelRef.current?.focus({ preventScroll: true }) return () => { mounted.current = false } }, []) - const floorEndsAt = task.deliveryFloorEndsAt === undefined ? undefined : Date.parse(task.deliveryFloorEndsAt) + const floorEndsAt = task?.deliveryFloorEndsAt === undefined ? undefined : Date.parse(task.deliveryFloorEndsAt) // A sample at the floor's end enables Run now when the interval passes, not up to one period later. const now = useRelativeClock(RELATIVE_CLOCK_PERIOD_MS, floorEndsAt) - const busy = pending || status === 'loading' || deleting.includes(task.id) - const executionActive = task.executionActive === true + const deletingTask = task !== undefined && deleting.includes(task.id) + const busy = pending || deletingTask || task !== undefined && status === 'loading' + const executionActive = task?.executionActive === true const deliveryFloor = floorEndsAt !== undefined && floorEndsAt > now - const linkedId = taskSessionId(task) + const linkedId = task === undefined ? undefined : taskSessionId(task) const linkedText = linkedId === undefined ? '' : sessions.byId[linkedId]?.displayTitle ?? linkedId const linkedState = linkedId === undefined ? 'unavailable' : sessionLinkState(linkedId, sessions, workspaces) // The Host refuses to deliver to an archived target Session. - const targetArchived = task.target.kind !== 'new' && linkedState === 'archived' + const targetArchived = task?.target.kind !== 'new' && linkedState === 'archived' // Only the interval needs the row to explain itself: each other cause shows in the detail or is transient. - const runHeld = busy || editing || executionActive || targetArchived || !props.authoritative - const nextRunAt = taskNextRunAt(task) - const next = nextRunParts(nextRunAt, t('time.locale'), now, t) + const runHeld = busy || dirty || executionActive || targetArchived || !props.authoritative + const nextRunAt = task === undefined ? '' : taskNextRunAt(task) + const next = task === undefined ? undefined : nextRunParts(nextRunAt, t('time.locale'), now, t) // SessionListState gives every listed id a byId row. const choices = sessions.ids.map(value => ({ value, label: (sessions.byId[value] as SessionSummary).displayTitle })) - const projects = projectChoices(workspaces.items, t('host.defaultProject')) - - const beginEdit = (): void => { - setBase(task) - setDraft(taskDraft(task)) + const setDraft = (value: TaskEditorDraft): void => { + props.actions.setDraft(key, { base, draft: value, ...(task === undefined ? { initial } : {}), + ...(cached?.failure === 'host.conflict' ? { failure: cached.failure } : {}) }) setFailure(null) - props.onEditState(task) - setEditing(true) - onTabChange('rule') } + const reset = (): void => { props.actions.clearDraft(key); setFailure(null) } const save = async (): Promise => { - setPending(true) + props.actions.setDraft(key, { base, draft, pending: true, ...(task === undefined ? { initial } : {}) }) setFailure(null) - const target = draftTarget(draft, base) - const seeded = taskDraft(base) - const timingChanged = JSON.stringify(timingFromDraft(draft)) !== JSON.stringify(timingFromDraft(seeded)) - const targetChanged = draft.target !== seeded.target || draft.sessionId !== seeded.sessionId || draft.cwd !== seeded.cwd - const patch = { - ...(draft.title === base.title ? {} : { title: draft.title }), - ...(draft.prompt === base.prompt ? {} : { prompt: draft.prompt }), - ...(timingChanged ? { timing: timingFromDraft(draft, true) } : {}), - ...(targetChanged ? { target } : {}), - } - if (Object.keys(patch).length === 0) Object.assign(patch, { title: draft.title }) - const outcome = await hostActions.edit({ id: task.id, action: 'update', patch, expectedUpdatedAt: base.updatedAt ?? null }) - if (!mounted.current) return - // The read-only view returns at once, so its Edit button can take back the focus of the removed Save button. - flushSync(() => { - setPending(false) - if (outcome === 'saved') { setEditing(false); props.onEditState(null) } - else setFailure(outcome.failed) - }) - if (outcome === 'saved') editRef.current?.focus() + const existingBase = base as ScheduleCatalogEntry + const outcome = task === undefined + ? await props.onCreateTask({ title: draft.title.trim(), prompt: draft.prompt.trim(), + timing: timingFromDraft(draft, true), target: draftTarget(draft) }) + : await hostActions.edit({ id: task.id, action: 'update', patch: taskDraftPatch(draft, existingBase, true), + expectedUpdatedAt: existingBase.updatedAt ?? null }) + if (outcome === 'saved' || 'created' in outcome) { + props.actions.clearDraft(key) + if (mounted.current && outcome !== 'saved') props.onCreated?.(outcome.created) + if (mounted.current && outcome === 'saved') panelRef.current?.focus({ preventScroll: true }) + } else props.actions.setDraft(key, { base, draft, failure: outcome.failed, ...(task === undefined ? { initial } : {}) }) } - const setActive = async (): Promise => { + const setActive = async (task: ScheduleCatalogEntry): Promise => { setPending(true) const outcome = await hostActions.edit({ id: task.id, action: 'update', patch: { active: task.status !== 'active' }, expectedUpdatedAt: task.updatedAt ?? null }) if (!mounted.current) return setPending(false) setFailure(outcome === 'saved' ? null : outcome.failed) } - const run = async (): Promise => { + const run = async (id: ScheduleId): Promise => { setMenuOpen(false) setPending(true) - const outcome = await hostActions.run(task.id) + const outcome = await hostActions.run(id) if (!mounted.current) return setPending(false) setFailure(outcome === 'queued' ? null : outcome.failed) } return <> -