JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix: 定时任务列表飞书/钉钉等非web渠道任务不显示,且无主动刷新机制等bug问题
cjh_jinduoxia74dcc23d3636
diff --git a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsx b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsxindex 2ffdef1e1d..afbbd447e3 100644--- a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsx@@ -89,12 +89,32 @@ interface CronTaskDrawerProps {const fieldClass = 'w-full rounded-md border border-border bg-card px-3 py-1.5 text-sm text-text outline-none focus:border-accent disabled:cursor-not-allowed disabled:opacity-50';+// 后端存在两条"默认项目"记录(project_id 分别为 'default'/'default_code',对应普通/代码工作模式),+// 二者 project_dir 均为空串,展示名也都被 getProjectDisplayName 统一成"默认项目"(见 workspaceStore.ts)。+// 项目下拉框按原始 projects 直接 map 会把这两条都列出来,造成"默认项目"重复出现两次(bug005)。+// 这里只保留第一条命中的默认类项目,其余同类项目过滤掉——跟 ConversationSidebar.tsx 里对默认项目的+// 收敛处理是同一思路,但收敛范围只限于这个下拉框的可选项,不改 CronPanel 里传入的 projects 原始列表+// (cronJobToUI 还要用完整列表按 project_id 精确匹配任务归属的项目名,见 index.tsx)。+function isDefaultLikeProject(p: ProjectInfo): boolean {+ return p.is_default || p.project_id === 'default' || p.project_id === 'default_code';+}++function dedupeDefaultProjects(projects: ProjectInfo[]): ProjectInfo[] {+ let seenDefault = false;+ return projects.filter((p) => {+ if (!isDefaultLikeProject(p)) return true;+ if (seenDefault) return false;+ seenDefault = true;+ return true;+ });+}+export default function CronTaskDrawer({ mode, initial, projects, targetOptions, proactiveLocked = false, onClose, onSubmit, onSwitchToManual, onSwitchToTemplate }: CronTaskDrawerProps) {const { t } = useTranslation();const [form, setForm] = useState<CronTaskFormValue>(initial ?? emptyForm());const title = mode === 'edit' ? t('cron.drawer.titleEdit') : mode === 'template' ? t('cron.drawer.titleTemplate') : t('cron.drawer.titleCreate');- const projectOptions = projects.map((p) => ({ value: p.project_dir, label: getProjectDisplayName(p) }));+ const projectOptions = dedupeDefaultProjects(projects).map((p) => ({ value: p.project_dir, label: getProjectDisplayName(p) }));const timezoneOptions = TIMEZONE_OPTIONS.map((tz) => ({ value: tz, label: tz }));// 必填项缺失时,收集清单用来在"确定"按钮旁给出具体提示(而不是只让按钮变灰、不说原因)const missingFieldLabels: string[] = [];@@ -249,21 +269,32 @@ export default function CronTaskDrawer({ mode, initial, projects, targetOptions,</div></div>- <div className="mt-8 flex justify-center gap-3">- <button- onClick={() => onSubmit(form)}- disabled={!canSubmit}- title={missingFieldsHint}- className="rounded-full bg-cron-action px-10 py-1.5 text-sm font-bold text-cron-action-foreground hover:bg-cron-action-hover disabled:opacity-50"- >- {t('cron.actions.confirm')}- </button>- <button- onClick={onClose}- className="rounded-full border border-border bg-card px-10 py-1.5 text-sm font-bold text-text hover:bg-bg-hover"- >- {t('common.cancel')}- </button>+ <div className="mt-8 flex flex-col items-center gap-2">+ <div className="flex justify-center gap-3">+ {/* title 挂在按钮外层这个非 disabled 的 span 上,而不是挂在 disabled 的 <button> 本身——+ 主流浏览器(Chromium/Firefox)对 disabled 的原生表单控件不派发 hover 事件,title+ tooltip 因此根本不会弹出,之前的实现导致"按钮置灰但怎么悬停都没有提示"+ (见 2026-07-23 bugfix,bug002)。这里额外在按钮下方常驻展示同一段文案作为主要+ 提示渠道,span 上的 title 只是锦上添花的 hover 备份。 */}+ <span title={missingFieldsHint}>+ <button+ onClick={() => onSubmit(form)}+ disabled={!canSubmit}+ className="rounded-full bg-cron-action px-10 py-1.5 text-sm font-bold text-cron-action-foreground hover:bg-cron-action-hover disabled:opacity-50"+ >+ {t('cron.actions.confirm')}+ </button>+ </span>+ <button+ onClick={onClose}+ className="rounded-full border border-border bg-card px-10 py-1.5 text-sm font-bold text-text hover:bg-bg-hover"+ >+ {t('common.cancel')}+ </button>+ </div>+ {missingFieldsHint && (+ <p className="text-xs text-danger">{missingFieldsHint}</p>+ )}</div></div></div>diff --git a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/ScheduleEditor.tsx b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/ScheduleEditor.tsxindex c0c57c7e60..24db92e4ef 100644--- a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/ScheduleEditor.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/ScheduleEditor.tsx@@ -52,6 +52,14 @@ function intervalNumberTextOf(schedule: CronSchedule): string {return n !== undefined ? String(n) : '';}+// 去掉纯数字字符串的前导零,只保留数值本身的字符串形式:""→"","0"→"0","00"→"0",+// "01"→"1","010"→"10"。用 Number(...) 往返一次即可,不用手写正则去处理"全 0"这种边界+// (见 2026-07-23 bugfix 追加需求,bug002:用户先敲 0 再敲其它数字时,输入框不应该停留在+// "01"这种带前导零的形式上)。+function normalizeIntegerDigits(digitsOnly: string): string {+ return digitsOnly === '' ? '' : String(Number(digitsOnly));+}+function WeekdayPicker({ selected, onToggle }: { selected: number[]; onToggle: (day: number) => void }) {const { t } = useTranslation();return (@@ -356,46 +364,84 @@ export default function ScheduleEditor({ value, onChange, timezone }: ScheduleEd)}{topMode === 'interval' && schedule.kind === 'interval' && (- <div className="flex flex-nowrap items-center gap-2">- <span className="shrink-0 text-sm text-text-muted">{t('cron.schedule.every')}</span>- <input- type="text"- inputMode="numeric"- value={intervalNumberText}- onChange={(e) => {- // 小时/分钟步长在 croniter 里都只支持正整数,从输入源头过滤掉非数字字符- // (而不是允许打小数、事后校验失败再把确定按钮悄悄置灰,见 2026-07-16 bugfix)- const raw = e.target.value.replace(/\D/g, '');- setIntervalNumberText(raw);- const isMinutes = schedule.intervalUnit === 'minutes';- if (raw === '') {- updateSchedule(isMinutes ? { ...schedule, everyMinutes: undefined } : { ...schedule, everyHours: undefined });- return;- }- const n = Number(raw);- updateSchedule(isMinutes ? { ...schedule, everyMinutes: n } : { ...schedule, everyHours: n });- }}- placeholder={t(schedule.intervalUnit === 'minutes' ? 'cron.schedule.everyMinutesPlaceholder' : 'cron.schedule.everyHoursPlaceholder') ?? undefined}- className="w-16 shrink-0 rounded-md border border-border bg-card px-2 py-1.5 text-sm text-text outline-none focus:border-accent"- />- <div className="inline-flex w-fit shrink-0 rounded-md bg-bg-muted p-0.5">- {(['hours', 'minutes'] as const).map((unit) => {- const active = (schedule.intervalUnit ?? 'hours') === unit;- return (- <button- key={unit}- type="button"- onClick={() => setIntervalUnit(unit)}- className={`rounded px-1.5 py-0.5 text-xs transition-colors ${- active ? 'bg-card font-bold text-text-strong shadow-sm' : 'text-text-muted hover:text-text'- }`}- >- {t(`cron.schedule.intervalUnit.${unit}`)}- </button>- );- })}+ <div className="flex flex-col gap-1">+ <div className="flex flex-nowrap items-center gap-2">+ <span className="shrink-0 text-sm text-text-muted">{t('cron.schedule.every')}</span>+ <input+ type="text"+ inputMode="numeric"+ value={intervalNumberText}+ title={t('cron.schedule.integerOnlyHint') ?? undefined}+ onKeyDown={(e) => {+ // 小时/分钟步长在 croniter 里都只支持正整数:在按键这一刻就挡掉非数字字符,+ // 而不是等 onChange 里再"事后清洗"——之前的实现允许小数点先短暂插入、再被+ // 静默过滤掉,用户敲"0.1"会在无任何提示的情况下被拼接成一个和输入无关的整数+ // (比如"0.1"变成"01"=1,"1.5"变成"15"),完全没有反馈,见 2026-07-23 bugfix(bug002)。+ // 放行:数字键、编辑/导航类控制键、以及 Ctrl/Cmd 组合的编辑快捷键(全选/复制/粘贴/剪切/撤销)。+ if (e.ctrlKey || e.metaKey || e.altKey) return;+ const allowedControlKeys = ['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Tab', 'Home', 'End', 'Enter', 'Escape'];+ if (allowedControlKeys.includes(e.key)) return;+ if (!/^\d$/.test(e.key)) e.preventDefault();+ }}+ onPaste={(e) => {+ // 粘贴走的是单独的剪贴板事件,不经过 onKeyDown;同样只保留数字字符,+ // 避免粘贴"0.1"这类字符串被 onChange 静默拼接成无关的整数(见上)。+ e.preventDefault();+ const digitsOnly = e.clipboardData.getData('text').replace(/\D/g, '');+ if (!digitsOnly) return;+ const pasted = normalizeIntegerDigits(digitsOnly);+ setIntervalNumberText(pasted);+ const isMinutes = schedule.intervalUnit === 'minutes';+ const n = Number(pasted);+ updateSchedule(isMinutes ? { ...schedule, everyMinutes: n } : { ...schedule, everyHours: n });+ }}+ onChange={(e) => {+ // onKeyDown/onPaste 已经在源头挡掉了非数字输入,这里的过滤是兜底+ // (比如浏览器自动填充、IME 等不经过 onKeyDown 的输入路径)。+ const digitsOnly = e.target.value.replace(/\D/g, '');+ // 去掉前导零,只保留数值本身的字符串形式("00"→"0","01"→"1","010"→"10"):+ // 用户先敲 "0" 再敲其它数字时(包括之前"敲 0 再敲被拦截的小数点再敲 1"这类路径),+ // 框里不应该一直停留在"01"这种带前导零的形式(见 2026-07-23 bugfix 追加需求,bug002)。+ const raw = normalizeIntegerDigits(digitsOnly);+ setIntervalNumberText(raw);+ const isMinutes = schedule.intervalUnit === 'minutes';+ if (raw === '') {+ updateSchedule(isMinutes ? { ...schedule, everyMinutes: undefined } : { ...schedule, everyHours: undefined });+ return;+ }+ const n = Number(raw);+ updateSchedule(isMinutes ? { ...schedule, everyMinutes: n } : { ...schedule, everyHours: n });+ }}+ placeholder={t(schedule.intervalUnit === 'minutes' ? 'cron.schedule.everyMinutesPlaceholder' : 'cron.schedule.everyHoursPlaceholder') ?? undefined}+ className="w-16 shrink-0 rounded-md border border-border bg-card px-2 py-1.5 text-sm text-text outline-none focus:border-accent"+ />+ <div className="inline-flex w-fit shrink-0 rounded-md bg-bg-muted p-0.5">+ {(['hours', 'minutes'] as const).map((unit) => {+ const active = (schedule.intervalUnit ?? 'hours') === unit;+ return (+ <button+ key={unit}+ type="button"+ onClick={() => setIntervalUnit(unit)}+ className={`rounded px-1.5 py-0.5 text-xs transition-colors ${+ active ? 'bg-card font-bold text-text-strong shadow-sm' : 'text-text-muted hover:text-text'+ }`}+ >+ {t(`cron.schedule.intervalUnit.${unit}`)}+ </button>+ );+ })}+ </div>+ <WeekdayPicker selected={schedule.weekdays ?? []} onToggle={toggleWeekday} /></div>- <WeekdayPicker selected={schedule.weekdays ?? []} onToggle={toggleWeekday} />+ {/* 间隔数字缺失或 < 1(含用户想输小数被约束成整数后落在 0 的情况)时,直接在输入框下面+ 给出常驻提示,不用等用户去悬停确定按钮才知道哪里有问题(见 2026-07-23 bugfix,bug002)。 */}+ {(() => {+ const n = schedule.intervalUnit === 'minutes' ? schedule.everyMinutes : schedule.everyHours;+ return n === undefined || n < 1;+ })() && (+ <p className="text-xs text-danger">{t('cron.schedule.integerOnlyHint')}</p>+ )}</div>)}diff --git a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsx b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsxindex 0f140e9ea8..ce91e2afa8 100644--- a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsx@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';import { ChevronDown, Search, TrendingUp, Newspaper, Briefcase } from 'lucide-react';import { webRequest, webClient } from '../../services/webClient';import { useSessionStore } from '../../stores/sessionStore';-import { useCronStore, isWebChannelJob } from '../../stores';+import { useCronStore } from '../../stores';import { projectRegistryClient } from '../../features/workspace/projectRegistryClient';import type { ProjectInfo } from '../../features/workspace/projectTypes';import type { Session } from '../../types';@@ -158,20 +158,33 @@ export default function CronPanel({ sessionId, onCreateViaChat, onSelectSession[t],);- const loadJobs = useCallback(async (projectList: ProjectInfo[]) => {- setLoading(true);- setError(null);+ // silent=true 用于轮询/可见性刷新等后台静默拉取:不切 loading 态、失败时不清空现有列表、+ // 不弹错误提示,避免偶发网络抖动打断用户正在看的内容(见 bug007/bug008/bug009 progress.md)+ const loadJobs = useCallback(async (projectList: ProjectInfo[], options?: { silent?: boolean }) => {+ const silent = options?.silent ?? false;+ if (!silent) {+ setLoading(true);+ setError(null);+ }try {const payload = await webRequest<{ jobs: CronJobDTO[] }>('cron.job.list');- // Web 端工作区只展示 targets 含 "web" 的定时任务(targets 为空按后端 normalize 默认 web)- const webJobs = (payload.jobs || []).filter((j) => isWebChannelJob(j.targets));- setJobs(webJobs.map((j) => cronJobToUI(j, projectList)));+ // 展示所有渠道的定时任务(含飞书/钉钉等非 web 渠道创建的),不再按 targets 过滤隐藏;+ // 来源渠道由列表"渠道"列的 channelLabel 用 badge 形式标明,让用户一眼区分任务归属哪个渠道+ // (见 bug007/bug008/bug009 progress.md:此前 isWebChannelJob 过滤把非 web 任务藏掉,+ // 导致飞书建的任务在 web 列表永不出现,轮询再勤也无济于事)+ const allJobs = payload.jobs || [];+ setJobs(allJobs.map((j) => cronJobToUI(j, projectList)));} catch (loadError) {+ if (silent) {+ return;+ }const message = loadError instanceof Error ? loadError.message : t('cron.errors.loadJobs');setError(message);setJobs([]);} finally {- setLoading(false);+ if (!silent) {+ setLoading(false);+ }}}, [t]);@@ -219,6 +232,35 @@ export default function CronPanel({ sessionId, onCreateViaChat, onSelectSession})();}, [loadChannels, loadJobs, loadProjects]);+ // 供轮询/可见性刷新的静默重拉使用:始终指向最新的 projects,避免定时器闭包拿到挂载时+ // 的旧值(projects 是异步加载的,轮询早于它变化时也不该被锁死在空数组上)+ const projectsRef = useRef<ProjectInfo[]>(projects);+ useEffect(() => {+ projectsRef.current = projects;+ }, [projects]);++ // 定时任务列表除了"挂载时拉一次"、"本页面自己发起的创建/编辑/启停/删除"、"同一 web 会话内+ // cron_ 前缀工具调用完成"这三种触发方式外,没有别的刷新入口——跨渠道(飞书/钉钉等)创建的+ // 任务,以及纯粹随时间推移产生的"过期"状态变化,都覆盖不到,只能等用户手动切页重新挂载+ // 才会看到最新数据(见 bug007/bug008/bug009 的根因分析,progress.md)。这里加一个 5 秒+ // 轮询兜底 + 页面重新可见时立即刷新一次,两者都走 silent 静默拉取,不影响 loading/error 展示。+ useEffect(() => {+ const silentReload = () => {+ void loadJobs(projectsRef.current, { silent: true });+ };+ const intervalId = window.setInterval(silentReload, 5000);+ const onVisibilityChange = () => {+ if (document.visibilityState === 'visible') {+ silentReload();+ }+ };+ document.addEventListener('visibilitychange', onVisibilityChange);+ return () => {+ window.clearInterval(intervalId);+ document.removeEventListener('visibilitychange', onVisibilityChange);+ };+ }, [loadJobs]);+// 监听 Agent 工具调用结果:cron_ 前缀的工具(比如通过聊天创建/改动定时任务)执行完后// 自动刷新任务列表,不用用户手动刷新页面(复用的是 upstream 同款监听逻辑,见 progress.md)useEffect(() => {diff --git a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/scheduleConvert.ts b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/scheduleConvert.tsindex c0ede630c3..9af1c44a45 100644--- a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/scheduleConvert.ts+++ b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/scheduleConvert.ts@@ -109,11 +109,14 @@ export function scheduleToCronExpr(schedule: CronSchedule): string {const days = schedule.weekdays && schedule.weekdays.length > 0? Array.from(new Set(schedule.weekdays)).sort((a, b) => a - b).join(','): '*';+ // 显式判断而不是 `!schedule.everyMinutes`/`!schedule.everyHours`:0 和 undefined 在语义上+ // 都是"无效间隔",但用显式的 `< 1` 表达出来,不依赖假值隐式转换,逻辑更清楚,也方便以后+ // 需要更精确的报错文案时复用同一个判断(见 2026-07-23 bugfix,bug002)。if (schedule.intervalUnit === 'minutes') {- if (!schedule.everyMinutes) return '';+ if (schedule.everyMinutes === undefined || schedule.everyMinutes < 1) return '';return `0 */${schedule.everyMinutes} * * * ${days} *`;}- if (!schedule.everyHours) return '';+ if (schedule.everyHours === undefined || schedule.everyHours < 1) return '';return `0 0 */${schedule.everyHours} * * ${days} *`;}case 'once': {diff --git a/jiuwenswarm/channels/web/frontend/src/components/InteractionSlot/InteractionPrompt.tsx b/jiuwenswarm/channels/web/frontend/src/components/InteractionSlot/InteractionPrompt.tsxindex 55a5bd228f..51f65dd433 100644--- a/jiuwenswarm/channels/web/frontend/src/components/InteractionSlot/InteractionPrompt.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/InteractionSlot/InteractionPrompt.tsx@@ -20,6 +20,19 @@ const CUSTOM_OPTION_LABEL = 'Other';/** 多轮上限(产品约定:多轮确认最多不超过 3 轮)。 */const MAX_PAGES = 3;+/**+ * 「跳过」/「取消」时回传给后端的标记文本。+ *+ * 协议里没有独立于 options 之外的「跳过」/「取消」信号——ask_user 的结构化问答+ * 唯一的输出通道就是 selected_options / custom_input 拼成的文本,最终由 LLM+ * 读文本自行判断语义(见 jiuwenswarm/agents/harness/common/rails/ask_user_rail.py+ * StructuredAskUserRail.resolve_interrupt)。这里比照后端既有的同类标记文本+ * (如 interface.py 里硬编码的「用户拒绝」「用户希望继续规划」)不做 i18n,+ * 因为它是喂给 LLM 的内部信号而非界面文案。+ */+const SKIPPED_ANSWER_TEXT = '用户已跳过此题,未选择任何选项。';+const CANCELLED_ANSWER_TEXT = '用户已取消本次问答,未作答。';+interface InteractionPromptProps {pending: AskUserQuestionPayload;onSubmit: (requestId: string, answers: UserAnswer[], source?: string) => void;@@ -30,6 +43,12 @@ interface PageState {custom: string;/** 单选场景下是否选中「自定义」项 */customActive: boolean;+ /**+ * 该页是否因「点击跳过按钮且当前无任何选择/输入」而被显式标记为跳过。+ * 仅用于 answerFor 判断是否要用 SKIPPED_ANSWER_TEXT 替代「默认选第一项」的兜底;+ * 一旦用户在该页重新做出任何选择/输入,会被清除。+ */+ skippedNoSelection?: boolean;}function emptyPage(): PageState {@@ -83,9 +102,10 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps)return {...prev,selected: has ? prev.selected.filter((v) => v !== label) : [...prev.selected, label],+ skippedNoSelection: false,};}- return { ...prev, selected: [label], customActive: false };+ return { ...prev, selected: [label], customActive: false, skippedNoSelection: false };});},[submitting, isMulti, patch],@@ -93,11 +113,11 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps)const selectCustom = useCallback(() => {if (submitting) return;- patch((prev) => ({ ...prev, selected: [], customActive: true }));+ patch((prev) => ({ ...prev, selected: [], customActive: true, skippedNoSelection: false }));}, [submitting, patch]);const setCustomText = useCallback(- (text: string) => patch((prev) => ({ ...prev, custom: text })),+ (text: string) => patch((prev) => ({ ...prev, custom: text, skippedNoSelection: false })),[patch],);@@ -107,9 +127,15 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps)const q = questions[idx];const s = overrides?.[idx] ?? states[idx] ?? emptyPage();const customText = s.custom.trim();+ // 该页是被「跳过」按钮显式标记为「无选择」的:如实告知后端「已跳过」,+ // 不再套用下面「默认选第一项」的兜底(否则会把跳过误传成某个具体选项)。+ if (s.skippedNoSelection && s.selected.length === 0 && !customText) {+ return { question: q?.question, selected_options: [], custom_input: SKIPPED_ANSWER_TEXT };+ }const answer: UserAnswer = { question: q?.question, selected_options: [...s.selected] };if (customText) answer.custom_input = customText;- // 兜底:既无选择也无输入时,默认第一个普通选项(避免后端拿到空答案)。+ // 兜底:既无选择也无输入、且不是显式跳过时,默认第一个普通选项(避免后端拿到空答案)。+ // 该分支对应「点确定/下一步但什么都没选」这种情况,维持原有行为,不在本次改动范围内。if (answer.selected_options.length === 0 && !customText) {const first = (q?.options ?? []).find((o) => o.label !== CUSTOM_OPTION_LABEL);if (first) answer.selected_options = [first.value || first.label];@@ -120,8 +146,14 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps));const buildAnswers = useCallback(- (overrides?: Record<number, PageState>): UserAnswer[] =>- questions.map((_, idx) => answerFor(idx, overrides)),+ (overrides?: Record<number, PageState>, forcedTextByIdx?: Record<number, string>): UserAnswer[] =>+ questions.map((q, idx) => {+ const forced = forcedTextByIdx?.[idx];+ if (forced !== undefined) {+ return { question: q.question, selected_options: [], custom_input: forced };+ }+ return answerFor(idx, overrides);+ }),[questions, answerFor],);@@ -129,8 +161,11 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps)const buildSummary = useCallback((overrides?: Record<number, PageState>): QaSummaryData => {const items: QaSummaryItem[] = questions.map((q, idx) => {const s = overrides?.[idx] ?? states[idx] ?? emptyPage();- const answers: string[] = [...s.selected];const customText = s.custom.trim();+ if (s.skippedNoSelection && s.selected.length === 0 && !customText) {+ return { header: q.header, question: q.question, answers: [t('interactionPrompt.skippedSummary')] };+ }+ const answers: string[] = [...s.selected];if (customText) answers.push(customText);return { header: q.header, question: q.question, answers };});@@ -143,7 +178,7 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps)}, [setPendingQuestion]);const submit = useCallback(- (withEcho: boolean, overrides?: Record<number, PageState>) => {+ (withEcho: boolean, overrides?: Record<number, PageState>, forcedTextByIdx?: Record<number, string>) => {if (submitting) return;setSubmitting(true);if (withEcho) {@@ -158,7 +193,7 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps)addMessage(sid, message);}}- onSubmit(pending.request_id, buildAnswers(overrides), pending.source);+ onSubmit(pending.request_id, buildAnswers(overrides, forcedTextByIdx), pending.source);clearPending();},[submitting, pending, buildSummary, buildAnswers, addMessage, onSubmit, clearPending],@@ -179,19 +214,34 @@ export function InteractionPrompt({ pending, onSubmit }: InteractionPromptProps)}, [isLast, submit, goNextPage]);const handleSkip = useCallback(() => {- // 跳过当前页:清空本页作答,前进;末页则直接提交。- // patch() 触发的 setStates 是异步的,若末页直接 submit 会读到清空前的旧值,+ // 若当前页已经有选择/自定义输入(哪怕选的就是"跳过"这个选项),跳过按钮+ // 等价于确定:原样提交/翻页,绝不能清空用户已经做出的选择(这正是本次要修的 bug)。+ const hasAnswer = st.selected.length > 0 || st.custom.trim().length > 0;+ if (hasAnswer) {+ if (isLast) submit(true);+ else goNextPage();+ return;+ }+ // 当前页确实什么都没选:显式标记为"已跳过",后续 answerFor/buildSummary 会用+ // SKIPPED_ANSWER_TEXT 如实告知后端,而不是套用"默认选第一项"的兜底逻辑。+ // patch() 触发的 setStates 是异步的,若末页直接 submit 会读到旧值,// 因此显式构造覆盖态传给 submit,避免依赖尚未生效的 state。- const cleared = { ...states, [page]: emptyPage() };- patch(() => emptyPage());- if (isLast) submit(true, cleared);+ const skippedState: PageState = { ...emptyPage(), skippedNoSelection: true };+ const overridden = { ...states, [page]: skippedState };+ patch(() => skippedState);+ if (isLast) submit(true, overridden);else goNextPage();- }, [states, page, patch, isLast, submit, goNextPage]);+ }, [st, states, page, patch, isLast, submit, goNextPage]);const handleCancel = useCallback(() => {- // 取消整轮:以默认值提交解除阻塞,不回显。- submit(false);- }, [submit]);+ // 取消整轮:不管当前页/其它页有没有选择、选了什么,统一对每道题回传明确的+ // "已取消"标记,避免后端/LLM 把取消误当成某个具体选项的选择;不回显到聊天记录。+ const forcedTextByIdx: Record<number, string> = {};+ questions.forEach((_, idx) => {+ forcedTextByIdx[idx] = CANCELLED_ANSWER_TEXT;+ });+ submit(false, undefined, forcedTextByIdx);+ }, [submit, questions]);if (!current) return null;diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.jsonindex 658bc539ed..9f50f9e8a7 100644--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json@@ -1121,6 +1121,7 @@"every": "Every","everyHoursPlaceholder": "Hours","everyMinutesPlaceholder": "Minutes",+ "integerOnlyHint": "Interval must be an integer of at least 1","hoursUnit": "hours","minutesUnit": "minutes","intervalUnit": {@@ -2173,7 +2174,8 @@"nextStep": "Next","confirm": "Confirm","customOption": "Custom",- "customPlaceholder": "No suitable option? Type your answer..."+ "customPlaceholder": "No suitable option? Type your answer...",+ "skippedSummary": "Skipped"},"qaSummary": {"title": "Clarifications"diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.jsonindex 652947ac9b..957c5a7882 100644--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json@@ -1122,6 +1122,7 @@"every": "每","everyHoursPlaceholder": "小时数","everyMinutesPlaceholder": "分钟数",+ "integerOnlyHint": "间隔必须为大于等于 1 的整数","hoursUnit": "小时","minutesUnit": "分钟","intervalUnit": {@@ -2177,7 +2178,8 @@"nextStep": "下一步","confirm": "确定","customOption": "自定义",- "customPlaceholder": "没有合适的选项?输入您的答案..."+ "customPlaceholder": "没有合适的选项?输入您的答案...",+ "skippedSummary": "已跳过"},"qaSummary": {"title": "问题澄清"