From 4df9aad18bbe1789bb2fa0bd89feee374cb6994a Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sun, 4 Oct 2026 20:46:19 +0800 Subject: [PATCH] design(webui): preview explicit automation chat selection --- .../automation-chat/BindingControls.tsx | 133 ++++++++++++++ webui/proposals/automation-chat/README.md | 172 ++++++++++++++++++ webui/proposals/automation-chat/detail.jpg | Bin 0 -> 23321 bytes webui/proposals/automation-chat/index.html | 12 ++ webui/proposals/automation-chat/main.tsx | 115 ++++++++++++ webui/proposals/automation-chat/review.jpg | Bin 0 -> 35350 bytes webui/proposals/automation-chat/tsconfig.json | 5 + .../proposals/automation-chat/vite.config.ts | 69 +++++++ 8 files changed, 506 insertions(+) create mode 100644 webui/proposals/automation-chat/BindingControls.tsx create mode 100644 webui/proposals/automation-chat/README.md create mode 100644 webui/proposals/automation-chat/detail.jpg create mode 100644 webui/proposals/automation-chat/index.html create mode 100644 webui/proposals/automation-chat/main.tsx create mode 100644 webui/proposals/automation-chat/review.jpg create mode 100644 webui/proposals/automation-chat/tsconfig.json create mode 100644 webui/proposals/automation-chat/vite.config.ts diff --git a/webui/proposals/automation-chat/BindingControls.tsx b/webui/proposals/automation-chat/BindingControls.tsx new file mode 100644 index 000000000..1a119fffd --- /dev/null +++ b/webui/proposals/automation-chat/BindingControls.tsx @@ -0,0 +1,133 @@ +import { createContext, useContext, useEffect, useRef, useState, type ReactNode } from 'react'; +import { ArrowLeft, Check, Users } from 'lucide-react'; +import { ChannelLogo } from '@/components/settings/channels/ChannelIdentity'; +import { Button } from '@/components/ui/button'; +import { DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'; +import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select'; +import { Textarea } from '@/components/ui/textarea'; +import type { NanobotFeatureInfo, SessionAutomationJob } from '@/lib/types'; + +export const targets = { + weixin: { name: '我的私聊', platform: '微信', channel: 'weixin', group: false }, + feishu: { name: '产品讨论群', platform: '飞书', channel: 'feishu', group: true }, + telegram: { name: '工作群 / 日报', platform: 'Telegram', channel: 'telegram', group: true }, + webui: { name: '天气助手', platform: '网页聊天', channel: 'websocket', group: false }, +}; +export type Target = keyof typeof targets; +export const legacy = '\n\n投递方式:调用 message 发送到微信。\nchannel="weixin"\nchat_id="demo-person"\ncontent=整理好的天气推送文本'; +export const PreviewContext = createContext<{ + mode: string; scenario: string; + save: (job: SessionAutomationJob, target: Target, message: string) => Promise; +} | null>(null); +const BindingContext = createContext<{ + saved: Target; notice: string; locked: boolean; + select: (target: Target) => void; +} | null>(null); + +export function ConversationIdentity({ target }: { target: Target }) { + const item = targets[target]; + const feature: NanobotFeatureInfo = { + name: item.channel, display_name: item.platform, type: 'channel', + enabled: true, installed: true, ready: true, status: 'ready', + install_supported: false, requires_restart: false, + }; + return + + {target === 'webui' ? + : } + + + {item.name}{item.platform} + + ; +} + +// One original dialog owns the complete interaction. The page never unmounts. +export function BindingDialogFrame({ job, children }: { job: SessionAutomationJob; children: ReactNode }) { + const preview = useContext(PreviewContext)!; + const saved = (Object.keys(targets) as Target[]).find(key => targets[key].channel === job.origin?.channel) ?? 'webui'; + const [draft, setDraft] = useState(saved); + const [reviewing, setReviewing] = useState(false); + const [message, setMessage] = useState(job.payload.message); + const [ack, setAck] = useState(false); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(''); + const [notice, setNotice] = useState(''); + const heading = useRef(null); + const returning = useRef(false); + const locked = Boolean(job.state.pending || preview.scenario === 'oldhost'); + useEffect(() => { + if (reviewing) heading.current?.focus(); + else if (returning.current) { + document.querySelector('[data-binding-select]')?.focus(); + returning.current = false; + } + }, [reviewing]); + const back = () => { returning.current = true; setReviewing(false); }; + const save = async () => { + if (!ack || !message.trim() || saving || locked) return; + setSaving(true); setError(''); + try { + await preview.save(job, draft, message); + setNotice('已更换,下次执行时使用这个聊天。'); back(); + } catch { setError('没有保存:任务已被其他操作修改。原设置没变,你填写的内容也还在。'); } + finally { setSaving(false); } + }; + if (preview.mode === 'current') return children; + return { + if (target === saved || locked) return; + setDraft(target); setNotice(''); setAck(false); setError(''); setReviewing(true); + }, + }}> + {!reviewing ? children : <> + + 确认更换聊天 + +
+
+
现在
+
改为
+
+

下次执行时,nanobot 会参考新聊天的记录,并默认把结果发到那里。

+

原来的聊天记录不会带过去。执行时间不变,也不会马上运行。

+ {targets[draft].group ?

这是群聊,群里的人可能看到任务涉及的内容和结果。

: null} +