const icons = {
menu: '',
flower: Array.from(
{ length: 8 },
(_, index) =>
``,
).join(''),
'arrow-right': '',
'arrow-up': '',
back: '',
chevron: '',
right: '',
plus: '',
close: '',
chat: '',
edit: '',
search: '',
people:
'',
grid: '',
user: '',
more: '',
folder: '',
archive: '',
file: '',
clip: '',
check: '',
shield: '',
copy: '',
moon: '',
bell: '',
key: '',
eye: '',
logout: '',
link: '',
wallet: '',
trash: '',
download: '',
spark: '',
wifi: '',
signal: '',
battery:
'',
};
const icon = (name, className = '') =>
``;
const esc = (value) =>
String(value).replace(
/[&<>"']/g,
(character) =>
({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[character],
);
const ib = (name, label, action, extra = '') =>
``;
const agents = [
{
id: 'a1',
name: '小禾',
role: '研究与写作伙伴',
tone: '',
online: true,
cpu: '12%',
memory: '328 MB',
balance: '128.60',
task: '正在整理产品体验调研',
symbol: 'flower',
},
{
id: 'a2',
name: '阿澈',
role: '开发与技术伙伴',
tone: 'clay',
online: true,
cpu: '8%',
memory: '256 MB',
balance: '86.20',
task: '等待新的协作指令',
symbol: 'grid',
},
{
id: 'a3',
name: '知夏',
role: '设计与创意伙伴',
tone: 'lilac',
online: false,
cpu: '—',
memory: '—',
balance: '42.00',
task: '当前离线,连接恢复后继续协作',
symbol: 'spark',
},
];
const conversations = [
{
id: 'c1',
title: '把产品的第一印象做好',
agentId: 'a1',
preview: '我整理了三个可以落地的优化方向。',
time: '刚刚',
group: '今天',
workspace: 'w1',
unread: 2,
archived: false,
},
{
id: 'c2',
title: '官网首页的灵感与参考',
agentId: 'a3',
preview: '留白、秩序,以及一点点恰好的温度。',
time: '10:24',
group: '今天',
workspace: 'w1',
unread: 0,
archived: false,
},
{
id: 'c3',
title: '梳理一下这周的工作',
agentId: 'a1',
preview: '已按优先级整理好,随时可以继续。',
time: '昨天',
group: '昨天',
workspace: null,
unread: 0,
archived: false,
},
{
id: 'c4',
title: '登录接口联调记录',
agentId: 'a2',
preview: '接口参数和错误处理已经检查完毕。',
time: '昨天',
group: '昨天',
workspace: 'w2',
unread: 1,
archived: false,
},
{
id: 'c5',
title: '一些还没成形的小想法',
agentId: 'a1',
preview: '我们可以从一个最小的版本开始。',
time: '周五',
group: '更早',
workspace: null,
unread: 0,
archived: false,
},
{
id: 'c6',
title: '上一版品牌文案',
agentId: 'a1',
preview: '品牌文案讨论已归档。',
time: '11/08',
group: '更早',
workspace: 'w1',
unread: 0,
archived: true,
},
];
let workspaces = [
{ id: 'w1', name: '产品与灵感' },
{ id: 'w2', name: '研发协作' },
];
const messages = new Map();
const collaboration = new Map([
['c1', { kind: 'done', label: '体验优化建议已交付', elapsed: '刚刚完成' }],
['c2', { kind: 'attention', label: '连接中断,等待恢复', elapsed: '需要关注' }],
['c3', { kind: 'running', label: '正在整理本周的优先级', elapsed: '已进行 2 分钟' }],
['c4', { kind: 'running', label: '正在检查接口返回结果', elapsed: '已进行 45 秒' }],
['c5', { kind: 'idle', label: '等待新的想法', elapsed: '空闲' }],
]);
const activityNames = { running: '进行中', attention: '待关注', done: '已完成', idle: '空闲' };
const drafts = new Map();
const draftKey = () => (state.page === 'chat' ? state.currentId : 'home');
function saveDraft() {
if (['home', 'chat'].includes(state.page))
drafts.set(draftKey(), { text: state.draft, files: [...state.attachments] });
}
function restoreDraft() {
const draft = drafts.get(draftKey());
state.draft = draft?.text || '';
state.attachments = [...(draft?.files || [])];
}
let preferences = { dark: false, palette: 'forest', font: 14 };
try {
preferences = {
...preferences,
...JSON.parse(localStorage.getItem('fmode_mobile_proposal_v1') || '{}'),
};
} catch {}
const state = {
page: 'home',
currentId: 'c1',
agentId: null,
draft: '',
attachments: [],
filter: 'all',
contactFilter: 'agents',
agentFilter: 'all',
keyword: '',
expanded: new Set(),
drawerExpanded: new Set(),
pendingSend: false,
newWorkspace: null,
generating: false,
disconnected: false,
tokenVisible: false,
drawerView: 'recent',
activityFilter: 'all',
activityKeyword: '',
...preferences,
};
const main = document.querySelector('#main'),
header = document.querySelector('#app-header'),
composerArea = document.querySelector('#composer-area'),
tabbar = document.querySelector('#tabbar'),
overlay = document.querySelector('#overlay-root'),
app = document.querySelector('#app');
let returnFocus, toastTimer, generationTimer;
const getAgent = (agentId) => agents.find((agent) => agent.id === agentId) || agents[0];
const getConversation = (identifier = state.currentId) =>
conversations.find((conversation) => conversation.id === identifier);
const avatar = (agent) => `${icon(agent.symbol)}`;
const activeConversations = () => conversations.filter((conversation) => !conversation.archived);
const navItems = [
['messages', 'chat', '会话'],
['contacts', 'people', '通讯录'],
['workbench', 'grid', '工作台'],
['mine', 'user', '我的'],
];
const emptyState = (title, description = '', symbol = 'search') =>
`
${icon(symbol)}
${title}${description}
`;
const tabs = (items, active, action) =>
`${items.map(([value, label]) => ``).join('')}
`;
const searchField = (placeholder, action = 'search', value = '') =>
``;
const navigation = () =>
navItems
.map(
([page, symbol, label]) =>
``,
)
.join('');
function applyPreferences() {
const device = document.querySelector('#device');
device.classList.toggle('dark', state.dark);
const palettes = {
forest: ['#386b52', '#eaf1e8', '#a4c59a', '#303f30'],
blue: ['#496a96', '#eaf0f8', '#a5bde0', '#2e3c50'],
purple: ['#806495', '#f0eaf5', '#c9acdf', '#403349'],
amber: ['#9a7641', '#f4efdf', '#ddc195', '#443a27'],
};
const palette = palettes[state.palette] || palettes.forest;
device.style.setProperty('--accent', palette[state.dark ? 2 : 0]);
device.style.setProperty('--tint', palette[state.dark ? 3 : 1]);
device.style.setProperty('--chat-font', `${state.font}px`);
try {
localStorage.setItem(
'fmode_mobile_proposal_v1',
JSON.stringify({ dark: state.dark, palette: state.palette, font: state.font }),
);
} catch {}
}
function navigate(page, identifier) {
const destination =
page === 'chat'
? `#/chat/${identifier || state.currentId}`
: page === 'agent'
? `#/agent/${identifier}`
: `#/${page}`;
if (location.hash === destination) readRoute();
else location.hash = destination;
}
function readRoute() {
saveDraft();
const [page = 'home', identifier] = location.hash.replace(/^#\/?/, '').split('/');
state.page = ['home', 'chat', 'messages', 'contacts', 'workbench', 'mine', 'agent'].includes(page)
? page
: 'home';
if (state.page === 'chat') {
const conversation = getConversation(identifier);
if (conversation) {
state.currentId = identifier;
conversation.unread = 0;
} else state.page = 'messages';
}
if (state.page === 'agent') state.detailAgentId = identifier;
state.keyword = '';
restoreDraft();
closeOverlay();
render();
main.scrollTop = 0;
}
function render() {
const conversation = getConversation(),
agent = getAgent(conversation?.agentId);
if (state.page === 'chat')
header.innerHTML = `${ib('menu', '打开会话侧栏', 'drawer')}${ib('more', '会话详情', 'details')}`;
else if (state.page === 'home')
header.innerHTML = `${ib('menu', '打开会话侧栏', 'drawer')}${icon('flower')}fmode
`;
else if (state.page === 'agent')
header.innerHTML = `${ib('back', '返回通讯录', 'navigate', 'data-page="contacts"')}数字生命设置`;
else
header.innerHTML = `${ib('menu', '打开会话侧栏', 'drawer')}${navItems.find(([page]) => page === state.page)?.[2]}${state.page === 'messages' ? ib('edit', '新建对话', 'new-chat') : ''}`;
({
home: renderHome,
chat: renderChat,
messages: renderMessages,
contacts: renderContacts,
workbench: renderWorkbench,
mine: renderMine,
agent: renderAgent,
})[state.page]();
if (state.page === 'chat' && messages.get(state.currentId)?.length === 0) {
main.innerHTML = `${icon(agent.symbol)}
新的想法,直接说。
正在和 ${esc(agent.name)} 对话
${esc(workspaces.find((workspace) => workspace.id === conversation.workspace)?.name || '日常对话')} · 不影响之前的会话
`;
}
if (state.page === 'mine')
main
.querySelector('.version-text')
.insertAdjacentHTML(
'beforeend',
'
',
);
tabbar.innerHTML = ['messages', 'contacts', 'workbench', 'mine'].includes(state.page)
? navigation()
: '';
if (['home', 'chat'].includes(state.page)) renderComposer();
else composerArea.innerHTML = '';
document
.querySelectorAll('[data-scene]')
.forEach((button) => button.classList.toggle('active', button.dataset.scene === state.page));
applyPreferences();
}
function renderHome() {
main.innerHTML = `${icon('flower')}
每一个想法,都值得被认真对待
让想法,
再往前一步。
写下想做的事,和你的数字生命一起完成。
接着上次的想法
${activeConversations()
.slice(0, 2)
.map(
(conversation) =>
`
`,
)
.join('')}
`;
}
function renderComposer() {
const agentId = state.page === 'chat' ? getConversation()?.agentId : state.agentId,
agent = agentId ? getAgent(agentId) : null;
composerArea.innerHTML = `${state.attachments.map((file, index) => `${icon('clip')}${esc(file.name)}`).join('')}
${ib('plus', '添加附件', 'attach')}
`;
if (state.page === 'chat') {
const running = activeConversations().filter(
(conversation) => collaboration.get(conversation.id)?.kind === 'running',
).length;
const attention = activeConversations().filter(
(conversation) => collaboration.get(conversation.id)?.kind === 'attention',
).length;
composerArea.insertAdjacentHTML(
'afterbegin',
``,
);
}
const textarea = document.querySelector('#draft');
textarea.setAttribute('enterkeyhint', 'enter');
textarea.style.height = 'auto';
textarea.style.height = `${Math.min(textarea.scrollHeight, 116)}px`;
}
function conversationRow(conversation) {
const agent = getAgent(conversation.agentId);
return ``;
}
function renderMessages() {
main.innerHTML = `每一次对话,都是想法向前的一步。
${searchField('搜索会话或数字生命', 'search', state.keyword)}${tabs(
[
['all', '全部'],
['unread', '未读'],
['workspace', '工作区'],
],
state.filter,
'message-filter',
)}${conversationResults()}
`;
}
function conversationResults() {
const keyword = state.keyword.trim().toLowerCase(),
filtered = activeConversations().filter(
(conversation) =>
(state.filter !== 'unread' || conversation.unread > 0) &&
`${conversation.title} ${getAgent(conversation.agentId).name}`
.toLowerCase()
.includes(keyword),
);
if (state.filter === 'workspace')
return `${workspaces
.map((workspace) => {
const rows = filtered.filter((conversation) => conversation.workspace === workspace.id);
if (keyword && !rows.length && !workspace.name.includes(keyword)) return '';
return `${ib('plus', '在 ' + workspace.name + ' 中新建对话', 'workspace-chat', `data-id="${workspace.id}"`)}${ib('more', workspace.name + ' 更多操作', 'workspace-menu', `data-id="${workspace.id}"`)}${rows.length ? rows.map(conversationRow).join('') : emptyState('还没有对话', '在这里开始一个新的想法', 'chat')}
`;
})
.join('')}`;
if (!filtered.length)
return emptyState(
state.filter === 'unread' ? '未读已清空,安心专注' : '没有找到相关对话',
state.filter === 'unread' ? '新的消息会出现在这里。' : '换个关键词再试试。',
);
return ['今天', '昨天', '更早']
.map((group) => {
const rows = filtered.filter((conversation) => conversation.group === group);
return rows.length
? `${group}
${rows.map(conversationRow).join('')}`
: '';
})
.join('');
}
const sampleAnswer =
'好的。第一印象不一定要做得更满,
而是让用户更快地感到:这里懂我。
先把这三件事做好
- 让入口更清楚
一个明确的主操作,比同时展示很多功能更有效。 - 让阅读更轻松
减少卡片边框,拉开段落间距,让内容成为主角。 - 让操作有回应
无论是发送、等待还是完成,都给出清晰、克制的反馈。
好的体验,是不用思考下一步该点哪里。
我把具体建议整理成了一份文档,可以先从首页和对话页开始验证。
';
function sampleMessages(conversation) {
if (conversation.id === 'c1')
return [
{ role: 'user', text: '我们来想想,怎么把产品的第一印象做得更好?' },
{ role: 'assistant', html: sampleAnswer, file: true },
];
return [
{ role: 'user', text: conversation.title },
{
role: 'assistant',
html: `${esc(conversation.preview)}
这段对话保留在「${esc(workspaces.find((workspace) => workspace.id === conversation.workspace)?.name || '日常对话')}」中,你可以接着补充想法。
这是界面演示内容,不是真实的历史消息。
`,
},
];
}
function fileCard() {
return ``;
}
function renderChat() {
const conversation = getConversation(),
agent = getAgent(conversation.agentId);
if (!messages.has(conversation.id)) messages.set(conversation.id, sampleMessages(conversation));
const rows = messages.get(conversation.id);
main.innerHTML = `${state.disconnected ? `` : ''}今天 · 10:42
${rows.map((message, index) => (message.role === 'user' ? `${esc(message.text).replace(/\n/g, '
')}${message.files?.map((name) => `${icon('clip')} ${esc(name)}`).join('') || ''}
` : `${icon(agent.symbol)}${esc(agent.name)}
${icon('check')} 已完成 ${message.file ? '3' : '2'} 个步骤 · ${message.file ? '12' : '3'} 秒 ${icon('chevron', 'chevron')}
- 理解需求与对话上下文
- 整理可执行的建议
${message.file ? '- 生成文档并上传云盘
' : ''}
${message.html}
${message.file ? fileCard() : ''}${message.file ? `` : ''}AI 生成 · 请核实
`)).join('')}${state.generating && state.generatingId === conversation.id ? '' + icon(agent.symbol) + '正在整理你的想法
' : ''}`;
}
function renderContacts() {
main.innerHTML = `${tabs(
[
['agents', '数字生命'],
['coworkers', '同事'],
],
state.contactFilter,
'contact-filter',
)}${searchField('搜索联系人', 'contact-search', state.keyword)}${contactResults()}
`;
}
function contactResults() {
if (state.contactFilter === 'coworkers') {
const people = [
{ name: '林一', role: '产品设计 · 我', initial: '林' },
{ name: '陈序', role: '研发协作', initial: '陈' },
].filter((person) => person.name.includes(state.keyword));
return people.length
? `产品与研发 · ${people.length} 人
${people.map((person) => `${icon('right')}
`).join('')}`
: emptyState('没有找到联系人');
}
const filtered = agents.filter((agent) => `${agent.name} ${agent.role}`.includes(state.keyword));
return filtered.length
? `我的数字伙伴${filtered.length} 位
${filtered.map((agent) => `${icon('right')}
`).join('')}`
: emptyState('没有找到数字生命');
}
function renderWorkbench() {
main.innerHTML = `伙伴们的工作状态,一眼就知道。
${tabs(
[
['all', '全部'],
['online', '在线'],
['offline', '离线'],
],
state.agentFilter,
'agent-filter',
)}${searchField('搜索数字生命', 'agent-search', state.keyword)}${agentResults()}
`;
}
function agentResults() {
const filtered = agents.filter(
(agent) =>
agent.name.includes(state.keyword) &&
(state.agentFilter === 'all' || agent.online === (state.agentFilter === 'online')),
);
return filtered.length
? filtered
.map(
(agent) =>
`${avatar(agent)}
${esc(agent.name)}
${agent.role}${agent.online ? '在线' : '离线'}${agent.task}
CPU ${agent.cpu}内存 ${agent.memory}余额 ¥${agent.balance}
`,
)
.join('')
: emptyState('没有匹配的数字生命');
}
function renderMine() {
main.innerHTML = `外观与阅读
${[
['forest', '#386b52', '森林'],
['blue', '#496a96', '湖蓝'],
['purple', '#806495', '暮紫'],
['amber', '#9a7641', '暖砂'],
]
.map(
([value, color, label]) =>
``,
)
.join(
'',
)}
账号与通知
fmode · 人机共生中枢
Mobile experience / 01 · 独立体验提案
`;
}
function renderAgent() {
const agent = getAgent(state.detailAgentId);
main.innerHTML = `${avatar(agent)}
${esc(agent.name)}
${agent.role}
容器设置
连接状态${agent.online ? '在线' : '离线'}
沿用现有通讯录逻辑:数字生命详情只提供重命名。
`;
}
function openOverlay(html) {
if (!overlay.childElementCount) returnFocus = document.activeElement;
overlay.innerHTML = html;
app.inert = true;
requestAnimationFrame(() => {
const target = overlay.querySelector('[autofocus]') || overlay.querySelector('button,input,select,summary');
target?.focus({ preventScroll: true });
});
}
function closeOverlay() {
const wasOpen = overlay.childElementCount > 0;
overlay.innerHTML = '';
app.inert = false;
state.pendingSend = false;
if (wasOpen && returnFocus?.isConnected) returnFocus.focus({ preventScroll: true });
}
function sheet(title, content, extra = '') {
openOverlay(
``,
);
}
function drawerHistory(keyword = '') {
if (state.drawerView === 'recent') {
const recent = activeConversations().filter((conversation) =>
`${conversation.title} ${getAgent(conversation.agentId).name} ${workspaces.find((workspace) => workspace.id === conversation.workspace)?.name || ''}`.includes(
keyword,
),
);
return `最近的协作${recent.length} 段对话
${recent.map((conversation) => drawerConversation(conversation)).join('') || emptyState('没有找到对话', '换个关键词再试试。')}`;
}
if (state.drawerView === 'agents') {
return (
agents
.map((agent) => {
const rows = activeConversations().filter(
(conversation) =>
conversation.agentId === agent.id &&
`${conversation.title} ${agent.name}`.includes(keyword),
);
if (!rows.length) return '';
const running = rows.filter(
(conversation) => collaboration.get(conversation.id)?.kind === 'running',
).length;
return `${avatar(agent)}${esc(agent.name)}${agent.role}${running ? `${running} 进行中` : `${rows.length} 段对话`}
${rows.map((conversation) => drawerConversation(conversation)).join('')}`;
})
.join('') || emptyState('没有找到对话')
);
}
const matches = (conversation) =>
`${conversation.title} ${getAgent(conversation.agentId).name}`.includes(keyword),
row = (conversation) =>
``;
return `${workspaces
.map(
(workspace) =>
`${ib('more', workspace.name + ' 更多操作', 'workspace-menu', `data-id="${workspace.id}"`)}
${
state.drawerExpanded.has(workspace.id) || keyword
? activeConversations()
.filter(
(conversation) =>
conversation.workspace === workspace.id && matches(conversation),
)
.map(row)
.join('')
: ''
}`,
)
.join(
'',
)}日常对话
${
activeConversations()
.filter((conversation) => !conversation.workspace && matches(conversation))
.map(row)
.join('') || '暂无匹配对话
'
}`;
}
function openDrawer() {
openOverlay(
``,
);
overlay.querySelector('.search-field').insertAdjacentHTML(
'afterend',
tabs(
[
['recent', '最近'],
['agents', '数字生命'],
['workspace', '工作区'],
],
state.drawerView,
'drawer-view',
),
);
overlay
.querySelector('.drawer-scroll')
.insertAdjacentHTML(
'afterend',
'',
);
}
function pickAgent(pending = false) {
sheet(
'和谁一起开始?',
`选择数字生命,草稿和附件会一并保留。
${agents.map((agent) => ``).join('')}保留「先选择数字生命,再建立会话」的现有流程。
`,
);
state.pendingSend = pending;
}
function details(tab = 'task') {
const agent = getAgent(getConversation().agentId),
content = {
task: `当前会话中的任务,不新增全局任务入口。
已完成产品初体验优化建议分析首页与对话页的体验问题,整理可执行的改进方向。
3 / 3 步骤完成 · ${esc(agent.name)}
`,
file: `${fileCard()}演示文件内容为静态预览,不会上传或读取云盘。
`,
deliver: `v1.0产品初体验优化建议今天 10:42 · ${esc(agent.name)} 已交付
${fileCard()}
`,
state: `数字生命${esc(agent.name)} · ${agent.online ? '在线' : '离线'}
会话连接${state.disconnected ? '连接中断,等待重连' : '已连接 · 当前没有待发送消息'}
原型状态演示(不影响实际服务)
`,
};
if (state.currentId !== 'c1' && tab !== 'state')
content[tab] = emptyState(
tab === 'task' ? '还没有任务' : tab === 'file' ? '还没有文件' : '还没有成果',
'这段对话中的内容会显示在这里。',
tab === 'task' ? 'check' : 'file',
);
sheet(
'会话详情',
content[tab] || content.task,
tabs(
[
['task', '任务'],
['file', '文件'],
['deliver', '成果'],
['state', '状态'],
],
tab,
'detail-tab',
),
);
}
function previewFile() {
sheet(
'文档预览',
`产品初体验优化建议.docx · 演示内容
FMODE / EXPERIENCE NOTE
把第一印象做好
一份围绕移动端的体验优化建议
2026.11.16 / v1.0
01 · 让入口更清楚
保留熟悉的导航,用明确的主操作降低理解成本。
02 · 让内容回到中心
减少无效的视觉容器,用段落、留白与字重建立信息层级。
| 页面 | 体验方向 |
|---|
| 新建对话 | 一个输入框,开始协作 |
| 会话详情 | 正文优先,过程折叠 |
| 会话列表 | 搜索、分组与清晰状态 |
03 · 每次操作都有回应
发送、加载、离线和失败状态清晰可见,操作始终可恢复。
`,
);
}
function formSheet(title, label, value, submitAction, identifier = '') {
sheet(
title,
``,
);
}
function confirmation(title, description, action, identifier) {
sheet(
title,
`${description}
`,
);
}
function conversationMenu(identifier) {
const conversation = getConversation(identifier);
sheet(
'管理这段对话',
`${esc(conversation.title)}
`,
);
}
function drawerConversation(conversation) {
const status = collaboration.get(conversation.id)?.kind || 'idle';
const workspace =
workspaces.find((item) => item.id === conversation.workspace)?.name || '日常对话';
return ``;
}
function activityResults() {
const rows = activeConversations().filter((conversation) => {
const status = collaboration.get(conversation.id)?.kind;
return (
status &&
status !== 'idle' &&
(state.activityFilter === 'all' || status === state.activityFilter) &&
`${conversation.title} ${getAgent(conversation.agentId).name}`.includes(state.activityKeyword)
);
});
return (
['running', 'attention', 'done']
.map((kind) => {
const group = rows.filter(
(conversation) => collaboration.get(conversation.id)?.kind === kind,
);
if (!group.length) return '';
return `${activityNames[kind]}${group.length}
${group
.map((conversation) => {
const activity = collaboration.get(conversation.id);
const agent = getAgent(conversation.agentId);
const workspace =
workspaces.find((item) => item.id === conversation.workspace)?.name || '日常对话';
return ``;
})
.join('')}`;
})
.join('') || emptyState('这里暂时没有协作动态', '切换筛选,看看其他会话。', 'check')
);
}
function openActivity() {
const count = (kind) =>
activeConversations().filter(
(conversation) => collaboration.get(conversation.id)?.kind === kind,
).length;
sheet(
'切换协作',
`不用退出对话,也能知道每件事的进展。
${searchField('搜索正在协作的事', 'activity-search', state.activityKeyword)}${tabs(
[
['all', '全部'],
['running', '进行中 ' + count('running')],
['attention', '待关注 ' + count('attention')],
['done', '已完成 ' + count('done')],
],
state.activityFilter,
'activity-filter',
)}${activityResults()}
`,
);
overlay.querySelector('.sheet').classList.add('activity-sheet');
}
function quickCurrent() {
if (state.generating) {
toast('演示回复完成后即可新建');
return;
}
const previous = getConversation();
saveDraft();
const identifier = `c${Date.now()}`;
conversations.unshift({
id: identifier,
title: '新对话',
agentId: previous.agentId,
preview: '等待你的第一个想法',
time: '刚刚',
group: '今天',
workspace: previous.workspace,
unread: 0,
archived: false,
});
collaboration.set(identifier, { kind: 'idle', label: '等待新的想法', elapsed: '空闲' });
messages.set(identifier, []);
navigate('chat', identifier);
toast('已在 ' + getAgent(previous.agentId).name + ' 中新建,原对话草稿已保留');
}
function editCurrentTitle() {
const conversation = getConversation();
formSheet(
'给这段对话起个名字',
'会话标题',
conversation.title,
'rename-conversation',
conversation.id,
);
const form = overlay.querySelector('form');
form.insertAdjacentHTML(
'beforeend',
`${icon('shield')}只有点保存才会更新。手动标题不会被自动覆盖。
`,
);
}
function previewListState(mode) {
saveDraft();
state.page = 'messages';
state.keyword = '';
history.pushState(null, '', '#/messages');
closeOverlay();
render();
const results = document.querySelector('#conversation-results');
if (mode === 'loading') {
results.innerHTML = `${Array.from({ length: 5 }, () => '
').join('')}
`;
setTimeout(() => {
if (results.isConnected) results.innerHTML = conversationResults();
}, 1800);
} else if (mode === 'error') {
results.innerHTML =
emptyState('暂时没连上,不是消息丢了', '网络恢复后可以重试,草稿仍然保留。', 'wifi') +
'';
} else
results.innerHTML =
emptyState('还没有对话,从一个想法开始', '选择熟悉的数字生命,开始你的第一次协作。', 'chat') +
'';
}
function completeDemo() {
const conversation = getConversation('c4');
if (!conversation) {
toast('这条演示会话已删除,刷新可恢复');
return;
}
const activity = collaboration.get(conversation.id);
if (activity?.kind === 'done') {
toast('该协作已完成,可在「已完成」中查看');
return;
}
collaboration.set(conversation.id, {
kind: 'done',
label: '接口检查已完成,结果已整理',
elapsed: '刚刚完成',
});
conversation.unread = 1;
closeOverlay();
render();
document.querySelector('#completion-banner')?.remove();
document
.querySelector('#device')
.insertAdjacentHTML(
'beforeend',
`${icon('check')}
`,
);
}
function send() {
if (state.generating || (!state.draft.trim() && !state.attachments.length)) return;
if (state.disconnected && state.page === 'chat') {
toast('连接已断开,请先重连;草稿已保留');
return;
}
if (state.page === 'home' && !state.agentId) {
pickAgent(true);
return;
}
if (state.page === 'home') {
drafts.delete('home');
const identifier = `c${Date.now()}`;
conversations.unshift({
id: identifier,
title: state.draft.trim().slice(0, 18) || '附件对话',
agentId: state.agentId,
preview: '正在整理你的想法…',
time: '刚刚',
group: '今天',
workspace: state.newWorkspace,
unread: 0,
archived: false,
});
messages.set(identifier, []);
state.currentId = identifier;
state.newWorkspace = null;
state.page = 'chat';
history.pushState(null, '', `#/chat/${identifier}`);
}
const conversation = getConversation(),
rows = messages.get(conversation.id) || sampleMessages(conversation),
question = state.draft.trim(),
files = state.attachments.map((file) => file.name);
rows.push({ role: 'user', text: question || '请查看我添加的附件', files });
if (conversation.title === '新对话' && !conversation.manuallyNamed)
conversation.title = (question || '附件对话').slice(0, 18);
collaboration.set(conversation.id, {
kind: 'running',
label: '正在处理你的消息',
elapsed: '刚刚开始',
});
messages.set(conversation.id, rows);
state.draft = '';
state.attachments = [];
drafts.delete(conversation.id);
state.generating = true;
state.generatingId = conversation.id;
render();
main.scrollTop = main.scrollHeight;
clearTimeout(generationTimer);
generationTimer = setTimeout(() => {
rows.push({
role: 'assistant',
html: `收到,我们就从「${esc(question || '这份附件')}」开始。
我会先把目标、已有信息和下一步梳理清楚,再一起把它变成可执行的行动。
这是一条本地模拟回复,仅用于体验发送、等待和阅读的完整流程${files.length ? ';附件只展示文件名,未读取或上传' : ''}。
`,
});
conversation.preview = '已整理好思路,可以继续讨论。';
collaboration.set(conversation.id, {
kind: 'done',
label: '演示回复已完成',
elapsed: '刚刚完成',
});
state.generating = false;
if (state.page === 'chat' && state.currentId === conversation.id) {
render();
main.scrollTop = main.scrollHeight;
} else if (['home', 'messages'].includes(state.page)) render();
}, 1100);
}
function toast(message) {
const element = document.querySelector('#toast');
element.textContent = message;
element.classList.add('visible');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => element.classList.remove('visible'), 2700);
}
async function copyText(text) {
try {
await navigator.clipboard.writeText(text);
toast('已复制');
} catch {
toast('浏览器未开放剪贴板权限,请手动选择内容复制');
}
}
function downloadDemo() {
const content =
'产品初体验优化建议(演示文稿)\n\n01 让入口更清楚\n保留现有导航与功能,突出主操作。\n\n02 让阅读更轻松\n减少厚重卡片,扩大段落留白。\n\n03 让操作有回应\n清晰呈现加载、断线与错误状态。\n\n本文件为独立 HTML 原型的演示文稿,并非真实云盘文件。',
url = URL.createObjectURL(new Blob([content], { type: 'text/plain;charset=utf-8' })),
link = document.createElement('a');
link.href = url;
link.download = '产品初体验优化建议-演示.txt';
link.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
toast('演示文稿已下载,不是实际 DOCX 文件');
}
function showArchived() {
sheet(
'已归档对话',
conversations
.filter((conversation) => conversation.archived)
.map(conversationRow)
.join('') || emptyState('没有归档对话', '归档的对话会保留在这里。', 'archive'),
);
}
function newChat(workspace = null, agentId = null) {
if (state.generating) {
toast('演示回复完成后即可新建对话');
return;
}
state.agentId = agentId;
state.newWorkspace = workspace;
navigate('home');
}
const actions = {
'preview-states': () =>
sheet(
'加载与反馈状态',
'仅切换演示视图,不改变真实数据或权限。
',
),
'list-state': (button) => previewListState(button.dataset.value),
'retry-list': renderMessages,
activity: openActivity,
'activity-filter': (button) => {
state.activityFilter = button.dataset.value;
openActivity();
},
'activity-open': (button) => {
closeOverlay();
navigate('chat', button.dataset.id);
requestAnimationFrame(() => {
main.scrollTop = main.scrollHeight;
});
},
'drawer-view': (button) => {
state.drawerView = button.dataset.value;
openDrawer();
},
'quick-current': quickCurrent,
'agent-new': (button) => {
newChat(null, button.dataset.id);
toast('已选中 ' + getAgent(button.dataset.id).name + ',不用再次选择');
},
'edit-current-title': editCurrentTitle,
'regenerate-title': () => {
const conversation = getConversation();
const rows = messages.get(conversation.id) || [];
const question = [...rows].reverse().find((message) => message.role === 'user')?.text;
overlay.querySelector('#form-value').value =
conversation.id === 'c1'
? '移动端第一印象与体验优化'
: (question || conversation.title).slice(0, 22);
toast('候选标题已填入,保存后才会更新;未调用 AI');
},
'complete-demo': completeDemo,
'dismiss-completion': () => document.querySelector('#completion-banner')?.remove(),
'completion-open': (button) => {
document.querySelector('#completion-banner')?.remove();
navigate('chat', button.dataset.id);
requestAnimationFrame(() => {
main.scrollTop = main.scrollHeight;
});
},
navigate: (button) => navigate(button.dataset.page),
drawer: openDrawer,
close: closeOverlay,
'new-chat': () => newChat(),
'open-chat': (button) => navigate('chat', button.dataset.id),
'pick-agent': () => pickAgent(false),
'choose-agent': (button) => {
const pending = state.pendingSend;
state.agentId = button.dataset.id;
closeOverlay();
renderComposer();
if (pending) send();
},
'agent-info': () => {
const agent = getAgent(getConversation().agentId);
sheet(
'当前数字生命',
`${avatar(agent)}
${esc(agent.name)}
${agent.role} · ${agent.online ? '在线' : '离线'}
当前会话固定关联该数字生命。如需更换,请新建对话。
`,
);
},
prompt: (button) => {
state.draft = button.dataset.value;
renderComposer();
document.querySelector('#draft').focus();
},
send,
attach: () => {
if (state.generating) return;
document.querySelector('#file-input').click();
},
'remove-attachment': (button) => {
state.attachments.splice(Number(button.dataset.index), 1);
renderComposer();
},
'message-filter': (button) => {
state.filter = button.dataset.value;
renderMessages();
},
'contact-filter': (button) => {
state.contactFilter = button.dataset.value;
state.keyword = '';
renderContacts();
},
'agent-filter': (button) => {
state.agentFilter = button.dataset.value;
renderWorkbench();
},
'toggle-workspace': (button) => {
state.expanded.has(button.dataset.id)
? state.expanded.delete(button.dataset.id)
: state.expanded.add(button.dataset.id);
document.querySelector('#conversation-results').innerHTML = conversationResults();
},
'drawer-workspace': (button) => {
state.drawerExpanded.has(button.dataset.id)
? state.drawerExpanded.delete(button.dataset.id)
: state.drawerExpanded.add(button.dataset.id);
document.querySelector('#drawer-results').innerHTML = drawerHistory(
document.querySelector('[data-input="drawer-search"]').value,
);
},
'workspace-chat': (button) => newChat(button.dataset.id),
'create-workspace': () =>
formSheet('新建工作区', '工作区名称(最多 24 字)', '', 'create-workspace'),
'workspace-menu': (button) => {
const workspace = workspaces.find((item) => item.id === button.dataset.id);
sheet(
esc(workspace.name),
``,
);
},
'rename-workspace': (button) =>
formSheet(
'重命名工作区',
'工作区名称(最多 24 字)',
workspaces.find((workspace) => workspace.id === button.dataset.id).name,
'rename-workspace',
button.dataset.id,
),
'delete-workspace': (button) =>
confirmation(
'删除工作区?',
'其中的会话会移到「日常对话」,不会被删除。此操作只影响演示数据。',
'confirm-delete-workspace',
button.dataset.id,
),
'confirm-delete-workspace': (button) => {
conversations.forEach((conversation) => {
if (conversation.workspace === button.dataset.id) conversation.workspace = null;
});
workspaces = workspaces.filter((workspace) => workspace.id !== button.dataset.id);
if (state.newWorkspace === button.dataset.id) state.newWorkspace = null;
closeOverlay();
render();
toast('工作区已删除,会话已移到日常对话');
},
'conversation-menu': (button) => conversationMenu(button.dataset.id),
'rename-conversation': (button) =>
formSheet(
'重命名对话',
'对话名称',
getConversation(button.dataset.id).title,
'rename-conversation',
button.dataset.id,
),
'move-conversation': (button) =>
sheet(
'移动到工作区',
`${workspaces.map((workspace) => ``).join('')}`,
),
'choose-workspace': (button) => {
getConversation(button.dataset.id).workspace = button.dataset.workspace || null;
closeOverlay();
render();
toast('已移动,仅影响本地演示数据');
},
'archive-conversation': (button) => {
const conversation = getConversation(button.dataset.id);
conversation.archived = !conversation.archived;
closeOverlay();
if (state.page === 'chat' && conversation.archived) navigate('messages');
else render();
toast(conversation.archived ? '已归档,可在侧栏中找回' : '已取消归档');
},
'delete-conversation': (button) =>
confirmation(
'删除对话?',
'删除后这条演示对话将从当前预览中移除,刷新页面可恢复。',
'confirm-delete-conversation',
button.dataset.id,
),
'confirm-delete-conversation': (button) => {
const index = conversations.findIndex((conversation) => conversation.id === button.dataset.id);
if (index >= 0) conversations.splice(index, 1);
messages.delete(button.dataset.id);
closeOverlay();
if (state.page === 'chat') navigate('messages');
else render();
toast('演示对话已删除');
},
'show-archived': showArchived,
details: (button) => details(button?.dataset.tab || 'task'),
'detail-tab': (button) => details(button.dataset.value),
'preview-file': previewFile,
'download-demo': downloadDemo,
'copy-message': (button) => {
const message = messages.get(state.currentId)[Number(button.dataset.index)],
content = document.createElement('div');
content.innerHTML = message.html;
copyText(content.textContent);
},
disconnect: () => {
state.disconnected = true;
closeOverlay();
renderChat();
toast('已进入断线演示,草稿不会丢失');
},
reconnect: () => {
state.disconnected = false;
closeOverlay();
renderChat();
toast('演示连接已恢复');
},
'open-agent': (button) => navigate('agent', button.dataset.id),
'rename-agent': (button) =>
formSheet(
'重命名数字生命',
'显示名称',
getAgent(button.dataset.id).name,
'rename-agent',
button.dataset.id,
),
'agent-chat': (button) => {
const conversation = activeConversations().find((item) => item.agentId === button.dataset.id);
conversation ? navigate('chat', conversation.id) : newChat(null, button.dataset.id);
},
channels: (button) =>
sheet(
'消息通道',
`${esc(getAgent(button.dataset.id).name)} · 演示连接信息
${getAgent(button.dataset.id).online ? '已连接' : '离线'}Matrix沿用现有消息通道,不在原型中建立真实连接。
`,
),
recharge: (button) =>
sheet(
'数字生命充值',
`${esc(getAgent(button.dataset.id).name)} · 当前演示余额 ¥${getAgent(button.dataset.id).balance}
${icon('shield')}
这里只预览,不会产生支付正式迁移时继续使用现有充值页面与接口,金额、账单和支付流程均不改变。
`,
),
coworker: (button) =>
sheet(
esc(button.dataset.name),
`同事的数字生命 · 演示
${agents
.slice(0, 2)
.map(
(agent) =>
``,
)
.join('')}`,
),
theme: () => {
state.dark = !state.dark;
const scroll = main.scrollTop;
renderMine();
applyPreferences();
main.scrollTop = scroll;
},
palette: (button) => {
state.palette = button.dataset.value;
const scroll = main.scrollTop;
renderMine();
applyPreferences();
main.scrollTop = scroll;
},
font: () =>
sheet(
'舒适地阅读',
`仅调整对话正文,沿用现有字号偏好功能。
${[
[14, '标准'],
[16, '较大'],
[18, '大号'],
]
.map(
([value, label]) =>
``,
)
.join(
'',
)}
让每一个想法,都有舒展的空间。
好的阅读体验,从恰好的字号开始。
`,
),
'choose-font': (button) => {
state.font = Number(button.dataset.value);
applyPreferences();
renderMine();
actions.font();
},
token: () =>
sheet(
'访问 Token',
`演示占位,不读取或展示任何真实凭据。
${state.tokenVisible ? 'DEMO-NOT-A-REAL-TOKEN' : '•••• •••• •••• ••••'}
`,
),
'toggle-token': () => {
state.tokenVisible = !state.tokenVisible;
actions.token();
},
'copy-token': () => copyText('DEMO-NOT-A-REAL-TOKEN'),
notifications: () =>
sheet(
'消息与任务通知',
`继续保留现有通知权限状态和系统设置入口。
${icon('bell')}
原型不申请系统权限正式版本仍由现有通知服务检查权限,并引导到系统设置。
`,
),
logout: () =>
confirmation('退出登录?', '此处仅演示二次确认,不会退出真实项目账号。', 'confirm-logout'),
'confirm-logout': () => {
closeOverlay();
navigate('home');
toast('退出交互演示完成;未操作真实账号');
},
};
document.addEventListener('click', (event) => {
const experience = event.target.closest('[data-experience]');
if (experience) {
const type = experience.dataset.experience;
closeOverlay();
if (state.page !== 'chat') {
saveDraft();
state.page = 'chat';
state.currentId = 'c1';
restoreDraft();
history.pushState(null, '', '#/chat/c1');
render();
}
if (type === 'activity') openActivity();
if (type === 'title') editCurrentTitle();
if (type === 'complete') completeDemo();
return;
}
const scene = event.target.closest('[data-scene]');
if (scene) {
navigate(scene.dataset.scene, scene.dataset.scene === 'chat' ? 'c1' : undefined);
return;
}
const button = event.target.closest('[data-action]');
if (button && !button.disabled) actions[button.dataset.action]?.(button);
});
document.addEventListener('input', (event) => {
const element = event.target;
if (element.id === 'draft') {
state.draft = element.value;
element.style.height = 'auto';
element.style.height = `${Math.min(element.scrollHeight, 116)}px`;
document.querySelector('.send-button').disabled =
state.generating || (!state.draft.trim() && !state.attachments.length);
return;
}
const kind = element.dataset.input;
if (!kind) return;
if (kind === 'activity-search') {
state.activityKeyword = element.value;
document.querySelector('#activity-results').innerHTML = activityResults();
return;
}
if (kind === 'drawer-search') {
document.querySelector('#drawer-results').innerHTML = drawerHistory(element.value);
return;
}
state.keyword = element.value;
if (kind === 'search')
document.querySelector('#conversation-results').innerHTML = conversationResults();
if (kind === 'contact-search')
document.querySelector('#contact-results').innerHTML = contactResults();
if (kind === 'agent-search') document.querySelector('#agent-results').innerHTML = agentResults();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && overlay.childElementCount) {
event.preventDefault();
closeOverlay();
return;
}
if (event.key === 'Tab' && overlay.childElementCount) {
const focusable = [
...overlay.querySelectorAll('button:not(:disabled),input,select,a[href],summary'),
].filter((element) => element.getClientRects().length),
first = focusable[0],
last = focusable.at(-1);
if (event.shiftKey && document.activeElement === first) {
event.preventDefault();
last?.focus();
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault();
first?.focus();
}
}
});
let sheetDrag = null;
overlay.addEventListener('pointerdown', (event) => {
const handle = event.target.closest('.sheet-handle');
if (!handle) return;
sheetDrag = { start: event.clientY, distance: 0, element: handle.closest('.sheet'), handle };
handle.setPointerCapture(event.pointerId);
sheetDrag.element.style.transition = 'none';
sheetDrag.element.style.animation = 'none';
});
overlay.addEventListener('pointermove', (event) => {
if (!sheetDrag) return;
sheetDrag.distance = Math.max(0, event.clientY - sheetDrag.start);
sheetDrag.element.style.transform = `translateY(${sheetDrag.distance}px)`;
});
overlay.addEventListener('pointerup', () => {
if (!sheetDrag) return;
if (sheetDrag.distance > 85) closeOverlay();
else {
sheetDrag.element.style.transition = 'transform .2s ease';
sheetDrag.element.style.transform = '';
}
sheetDrag = null;
});
overlay.addEventListener('pointercancel', () => {
if (sheetDrag) sheetDrag.element.style.transform = '';
sheetDrag = null;
});
document.addEventListener('submit', (event) => {
const form = event.target.closest('[data-form]');
if (!form) return;
event.preventDefault();
const value = new FormData(form).get('value').trim(),
kind = form.dataset.form,
identifier = form.dataset.id,
error = form.querySelector('.form-error');
if (!value) {
error.textContent = '名称不能为空';
return;
}
if (kind.includes('workspace')) {
if (value.length > 24) {
error.textContent = '工作区名称最多 24 字';
return;
}
if (workspaces.some((workspace) => workspace.name === value && workspace.id !== identifier)) {
error.textContent = '已有同名工作区,请换一个名称';
return;
}
}
if (kind === 'create-workspace') workspaces.push({ id: `w${Date.now()}`, name: value });
if (kind === 'rename-workspace')
workspaces.find((workspace) => workspace.id === identifier).name = value;
if (kind === 'rename-conversation') {
getConversation(identifier).title = value;
getConversation(identifier).manuallyNamed = true;
}
if (kind === 'rename-agent') getAgent(identifier).name = value;
closeOverlay();
render();
toast('已保存,仅影响本地演示数据');
});
document.querySelector('#file-input').addEventListener('change', (event) => {
state.attachments.push(...Array.from(event.target.files));
event.target.value = '';
renderComposer();
toast('附件仅暂存在本页,不会读取或上传');
});
window.addEventListener('hashchange', readRoute);
function syncVisualViewport() {
if (window.innerWidth <= 520 && window.visualViewport?.scale === 1) {
document
.querySelector('#device')
.style.setProperty('--visual-height', `${window.visualViewport.height}px`);
} else document.querySelector('#device').style.removeProperty('--visual-height');
}
window.visualViewport?.addEventListener('resize', syncVisualViewport);
window.addEventListener('resize', syncVisualViewport);
syncVisualViewport();
document
.querySelectorAll('[data-icon]')
.forEach((element) => (element.innerHTML = icon(element.dataset.icon)));
readRoute();