@ -165,6 +165,9 @@ details.dt>.dt-in{padding-left:var(--sp-4);margin-top:var(--sp-2)}
.tk-a :is(h2,h3,h4){font-size:var(--fs-ui);margin:.8em 0 .3em}
.tk-a :is(h2,h3,h4){font-size:var(--fs-ui);margin:.8em 0 .3em}
:is(.bub,.page,.tk-a) code{font-family:var(--mono);font-size:var(--fs-small);background:var(--hover);padding:1px 5px;border-radius:var(--r-s)}
:is(.bub,.page,.tk-a) code{font-family:var(--mono);font-size:var(--fs-small);background:var(--hover);padding:1px 5px;border-radius:var(--r-s)}
:is(.bub,.page,.tk-a) pre{margin:0 0 .75em;padding:var(--sp-3) var(--sp-4);border-radius:var(--r-m);background:var(--hover);overflow-x:auto;font:var(--fs-small)/1.55 var(--mono)}
:is(.bub,.page,.tk-a) pre{margin:0 0 .75em;padding:var(--sp-3) var(--sp-4);border-radius:var(--r-m);background:var(--hover);overflow-x:auto;font:var(--fs-small)/1.55 var(--mono)}
/* 複製程式碼: a small button on each code block (the whole message's 複製 is in its menu). */
pre.cb{position:relative}
pre.cb .cpy{position:absolute;top:4px;right:4px;width:30px;height:30px;border-radius:var(--r-s);display:grid;place-items:center;color:var(--text3);background:var(--elev);opacity:.85}
:is(.bub,.page,.tk-a) pre code{background:none;padding:0;border-radius:0;font:inherit}
:is(.bub,.page,.tk-a) pre code{background:none;padding:0;border-radius:0;font:inherit}
:is(.bub,.page,.tk-a) blockquote{margin:0 0 .75em;padding-left:var(--sp-3);border-left:2px solid var(--line);color:var(--text2)}
:is(.bub,.page,.tk-a) blockquote{margin:0 0 .75em;padding-left:var(--sp-3);border-left:2px solid var(--line);color:var(--text2)}
:is(.bub,.page,.tk-a) hr{border:0;border-top:1px solid var(--line);margin:var(--sp-5) 0}
:is(.bub,.page,.tk-a) hr{border:0;border-top:1px solid var(--line);margin:var(--sp-5) 0}
@ -577,6 +580,28 @@ textarea.field{min-height:96px;line-height:1.5}
.tools .btn.once{background:color-mix(in srgb,var(--accent) 18%,transparent);color:var(--accent-ink)}
.tools .btn.once{background:color-mix(in srgb,var(--accent) 18%,transparent);color:var(--accent-ink)}
.tools .btn.lock{background:var(--accent);color:var(--on-color)}
.tools .btn.lock{background:var(--accent);color:var(--on-color)}
.tools .btn.on{background:var(--primary);color:var(--on-primary)}
.tools .btn.on{background:var(--primary);color:var(--on-primary)}
/* 個人資料與用量: one strip of big numbers, the year's dots, a big number and bars. */
.me-figs{display:grid;grid-template-columns:repeat(4,1fr);gap:4px;margin:var(--sp-3) var(--sp-4) 0;padding:var(--sp-3) var(--sp-2);background:var(--elev);border-radius:var(--r-l)}
.me-figs div{display:flex;flex-direction:column;align-items:center;gap:2px;min-width:0}
.me-figs b{font-size:var(--fs-h3);font-weight:600;white-space:nowrap}
.me-figs span{font-size:var(--fs-caption);color:var(--text3);white-space:nowrap}
.me-card{margin:0 var(--sp-4);padding:var(--sp-3) var(--sp-4);background:var(--elev);border-radius:var(--r-l)}
.me-heat{width:100%;height:auto;display:block}
.me-note{font-size:var(--fs-caption);color:var(--text3);margin-top:var(--sp-2);line-height:1.5}
.me-seg{display:flex;gap:2px;padding:3px;background:var(--active);border-radius:999px;margin:var(--sp-1) 0 var(--sp-3)}
.me-seg button{flex:1;height:30px;border-radius:999px;font-size:var(--fs-small);color:var(--text2)}
.me-seg button.on{background:var(--elev);color:var(--text);font-weight:600}
.me-hero{font-size:var(--fs-small);color:var(--text3)}
.me-hero b{font-size:var(--fs-h1);font-weight:600;color:var(--text);margin-right:4px}
.me-bars{width:100%;height:84px;display:block;margin:var(--sp-3) 0 var(--sp-4);border-bottom:1px solid var(--grid)}
.me-split{display:flex;height:10px;border-radius:999px;overflow:hidden;background:var(--hover);margin-bottom:var(--sp-2)}
.me-split i{display:block;height:100%}
.me-row{display:flex;align-items:center;gap:10px;min-height:36px}
.me-dot{width:8px;height:8px;border-radius:50%;flex:none}
.me-av{width:22px;height:22px;flex:none;display:grid}.me-av svg{width:22px;height:22px}
.me-name{flex:1;min-width:0;font-size:var(--fs-small);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.me-bar{width:70px;height:6px;border-radius:999px;background:var(--hover);overflow:hidden;flex:none}.me-bar i{display:block;height:100%;background:var(--accent)}
.me-n{font-size:var(--fs-small);color:var(--text2);white-space:nowrap}
/* 虛擬觸控板 over this Mac's screen: a layer that takes the fingers, and the pointer drawn on it. */
/* 虛擬觸控板 over this Mac's screen: a layer that takes the fingers, and the pointer drawn on it. */
.stagewrap{flex:1;min-height:0;position:relative;display:flex}
.stagewrap{flex:1;min-height:0;position:relative;display:flex}
.pad{position:absolute;inset:0;display:none;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
.pad{position:absolute;inset:0;display:none;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
@ -1419,7 +1444,7 @@ function mergeState(prev, v) {
}
}
function apply(v) {
function apply(v) {
S.bots = v.bots || []; S.approvals = v.approvals || []; S.hostName = v.host || ""; S.mac = !!v.mac;
S.bots = v.bots || []; S.approvals = v.approvals || []; S.hostName = v.host || ""; S.mac = !!v.mac;
S.box = v.box || ""; S.boxOn = !!v.box_available; S.pages = v.pages || []; S.tasks = v.tasks || []; S.models = v.models || []; S.sections = v.sections || null; S.role = v.role || "owner";
S.box = v.box || ""; S.boxOn = !!v.box_available; S.pages = v.pages || []; S.tasks = v.tasks || []; S.models = v.models || []; S.sections = v.sections || null; S.pinOrder = v.pin_order || null; S. role = v.role || "owner";
S.voice = v.voice || {}; micShown(); appBadge();
S.voice = v.voice || {}; micShown(); appBadge();
// The computer's 外觀 (an older brain sends neither: the built-in look stays).
// The computer's 外觀 (an older brain sends neither: the built-in look stays).
if (v.palettes) applyPalette(v.palettes);
if (v.palettes) applyPalette(v.palettes);
@ -1467,8 +1492,43 @@ function apply(v) {
// ---------- home: the sidebar ----------
// ---------- home: the sidebar ----------
$("b-search").innerHTML = ic("search", 20); $("b-newbot").innerHTML = ic("plus", 22); $("search-ic").innerHTML = ic("search", 16); $("b-search-x").innerHTML = ic("x", 16);
$("b-search").innerHTML = ic("search", 20); $("b-newbot").innerHTML = ic("plus", 22); $("search-ic").innerHTML = ic("search", 16); $("b-search-x").innerHTML = ic("x", 16);
$("b-search").onclick = () => { $("searchbox").classList.add("on"); $("search").focus(); };
$("b-search").onclick = () => { $("searchbox").classList.add("on"); $("search").focus(); };
$("b-search-x").onclick = () => { $("search").value = ""; S.search = ""; $("searchbox").classList.remove("on"); renderHome(); };
$("b-search-x").onclick = () => { $("search").value = ""; S.search = ""; S.hits = null; $("searchbox").classList.remove("on"); renderHome(); };
$("search").oninput = () => { S.search = $("search").value.trim().toLowerCase(); renderHome(); };
// 搜尋 finds bots by name, and (the owner's) words in every chat — past conversations and file
// names too — as on the computer: a tap opens that chat at that message.
let searchTimer = 0, searchSeq = 0;
$("search").oninput = () => {
S.search = $("search").value.trim().toLowerCase();
S.hits = null; clearTimeout(searchTimer);
if (S.search & & owner()) searchTimer = setTimeout(searchChats, 300);
renderHome();
};
async function searchChats() {
const q = S.search, seq = ++searchSeq;
const v = await act("search", {q: $("search").value.trim()}, false);
if (seq !== searchSeq || q !== S.search) return;
S.hits = v || {hits: [], more: false};
renderHome();
}
function hitsHtml() {
if (!S.search || !S.hits) return "";
const hits = S.hits.hits || [];
if (!hits.length) return `< div class = "empty" style = "padding-top:12px" > 聊天裡也沒有找到< / div > `;
return `< div class = "sec" > ${ic("message", 13)}聊天裡 < span class = "n" > ${hits.length}${S.hits.more ? "+" : ""}< / span > < / div > < div class = "rows" > ${hits.map((h, i) => {
const b = bot(h.bot) || {};
const where = h.thread != null ? `< span class = "pill" > 過去的對話< / span > ` : "";
const what = (h.file ? "📎 " + h.file + " " : "") + (h.snippet || "");
return `< div class = "row" data-hit = "${i}" > < div class = "av" > ${avatarSvg(b.shape, b.color)}< / div > < div class = "mid" > < div class = "nm" > < span class = "t" > ${esc(h.bot_name || b.name || "")}< / span > ${where}< / div > < div class = "pv" > ${esc(what)}< / div > < / div > < div class = "tm" > ${ago(h.at)}< / div > < / div > `;
}).join("")}< / div > `;
}
async function openHit(i) {
const h = ((S.hits || {}).hits || [])[i];
if (!h) return;
if (h.thread != null) {
if (!await confirmSheet("回到這段對話?", `「${h.thread_title || "對話"}」會換回來,現在的對話留在「過去的對話」裡。`, "回到這段對話", false)) return;
try { await api(base() + `api/bots/${h.bot}/restore`, {json: {index: h.thread}}); } catch (e) { toast(e.message); return; }
}
go("chat", {bot: h.bot, at: h.at});
}
function botState(b) {
function botState(b) {
const waiting = S.approvals.find((a) => a.bot === b.id);
const waiting = S.approvals.find((a) => a.bot === b.id);
if (waiting) return {cls: "wait", dot: "wait", text: waiting.kind === "question" ? "等你回答:" + waiting.reason : "等你處理:" + (waiting.kind === "handoff" ? waiting.reason : waiting.title)};
if (waiting) return {cls: "wait", dot: "wait", text: waiting.kind === "question" ? "等你回答:" + waiting.reason : "等你處理:" + (waiting.kind === "handoff" ? waiting.reason : waiting.title)};
@ -1502,10 +1562,16 @@ function renderHome() {
$("b-newbot").style.display = isOwner() ? "" : "none";
$("b-newbot").style.display = isOwner() ? "" : "none";
$("quick").querySelectorAll("[data-q]").forEach((b) => b.onclick = () => go("list", {kind: b.dataset.q}));
$("quick").querySelectorAll("[data-q]").forEach((b) => b.onclick = () => go("list", {kind: b.dataset.q}));
if (!S.bots.length) { $("home").innerHTML = `< div class = "empty" > 還沒有 Bot。按右上角的 + 建立第一個。< / div > `; return; }
if (!S.bots.length) { $("home").innerHTML = `< div class = "empty" > 還沒有 Bot。按右上角的 + 建立第一個。< / div > `; return; }
if (!bots.length) { $("home").innerHTML = `< div class = "empty" > 沒有相符的 Bot< / div > `; return; }
if (!bots.length) {
$("home").innerHTML = (q & & S.hits & & (S.hits.hits || []).length ? "" : `< div class = "empty" > ${q & & owner() & & !S.hits ? "找找看聊天裡…" : "沒有相符的 Bot"}< / div > `) + hitsHtml();
$("home").querySelectorAll("[data-hit]").forEach((r) => r.onclick = () => openHit(+r.dataset.hit));
return;
}
// The sidebar's sections: 主要 Bot, 已釘選的 Bot, the person's own sections, then Bot.
// The sidebar's sections: 主要 Bot, 已釘選的 Bot, the person's own sections, then Bot.
const primary = bots.filter((b) => b.primary);
const primary = bots.filter((b) => b.primary);
const pinned = bots.filter((b) => !b.primary & & b.pinned);
// (In the desktop's order, which the owner can change from a bot's ⋯ › 更多.)
const pinAt = (b) => { const i = (S.pinOrder || []).indexOf(b.id); return i < 0 ? 1e9 : i ; } ;
const pinned = bots.filter((b) => !b.primary & & b.pinned).sort((a, b) => pinAt(a) - pinAt(b));
const rest = bots.filter((b) => !b.primary & & !b.pinned);
const rest = bots.filter((b) => !b.primary & & !b.pinned);
// The desktop's 分區 in its order (null = 未分區), empty ones too.
// The desktop's 分區 in its order (null = 未分區), empty ones too.
const order = S.sections || [...new Set(rest.map((b) => b.folder).filter(Boolean)), null];
const order = S.sections || [...new Set(rest.map((b) => b.folder).filter(Boolean)), null];
@ -1517,7 +1583,8 @@ function renderHome() {
if (f == null) h += sec(folders.length ? "未分區" : "Bot", "", rest.filter((b) => !folders.includes(b.folder)), folders.length ? "loose" : "");
if (f == null) h += sec(folders.length ? "未分區" : "Bot", "", rest.filter((b) => !folders.includes(b.folder)), folders.length ? "loose" : "");
else h += sec(f, "folder", rest.filter((b) => b.folder === f), "f:" + f, isOwner() ? `< button data-fmenu = "${esc(f)}" style = "margin-left:auto" > ${ic("ellipsis", 15)}< / button > ` : "", !q);
else h += sec(f, "folder", rest.filter((b) => b.folder === f), "f:" + f, isOwner() ? `< button data-fmenu = "${esc(f)}" style = "margin-left:auto" > ${ic("ellipsis", 15)}< / button > ` : "", !q);
}
}
$("home").innerHTML = h + `< div style = "height:calc(var(--safe-b) + 24px)" > < / div > `;
$("home").innerHTML = h + hitsHtml() + `< div style = "height:calc(var(--safe-b) + 24px)" > < / div > `;
$("home").querySelectorAll("[data-hit]").forEach((r) => r.onclick = () => openHit(+r.dataset.hit));
$("home").querySelectorAll(".row[data-bot]").forEach((r) => {
$("home").querySelectorAll(".row[data-bot]").forEach((r) => {
r.onclick = (e) => { if (e.target.closest("[data-botmenu]")) return; go("chat", {bot: +r.dataset.bot}); };
r.onclick = (e) => { if (e.target.closest("[data-botmenu]")) return; go("chat", {bot: +r.dataset.bot}); };
let t = null; r.addEventListener("touchstart", () => { t = setTimeout(() => { t = "long"; botMenu(+r.dataset.bot); }, 520); }, {passive: true});
let t = null; r.addEventListener("touchstart", () => { t = setTimeout(() => { t = "long"; botMenu(+r.dataset.bot); }, 520); }, {passive: true});
@ -1529,6 +1596,8 @@ function renderHome() {
e.stopPropagation();
e.stopPropagation();
const f = b.dataset.fmenu;
const f = b.dataset.fmenu;
sheet(f, [
sheet(f, [
{icon: "arrow-up", label: "往上移", on: () => act("section_move", {folder: f, by: -1}, false)},
{icon: "arrow-down", label: "往下移", on: () => act("section_move", {folder: f, by: 1}, false)},
{icon: "pen", label: "重新命名分區", on: async () => { const n = await ask("分區名稱", f); if (n & & n !== f) app("rename_group", {group: f, new_name: n}); }},
{icon: "pen", label: "重新命名分區", on: async () => { const n = await ask("分區名稱", f); if (n & & n !== f) app("rename_group", {group: f, new_name: n}); }},
{icon: "trash", label: "刪除分區", danger: true, on: async () => { if (await confirmSheet(`刪除分區「${f}」?`, "裡面的 Bot 會移到未分區,不會刪除任何 Bot。", "刪除分區")) app("delete_group", {group: f}); }},
{icon: "trash", label: "刪除分區", danger: true, on: async () => { if (await confirmSheet(`刪除分區「${f}」?`, "裡面的 Bot 會移到未分區,不會刪除任何 Bot。", "刪除分區")) app("delete_group", {group: f}); }},
]);
]);
@ -1546,6 +1615,13 @@ function botMenu(id) {
// 團隊: whether teammates may use this bot (they see its chat, pages and files).
// 團隊: whether teammates may use this bot (they see its chat, pages and files).
if (isOwner() & & !b.members) more.push({icon: "users", label: b.team ? "不再分享給團隊成員" : "分享給團隊成員", on: () => act("bot", {bot: id, key: "team", value: !b.team}, b.team ? "團隊成員看不到這個 Bot 了" : "團隊成員現在可以使用這個 Bot")});
if (isOwner() & & !b.members) more.push({icon: "users", label: b.team ? "不再分享給團隊成員" : "分享給團隊成員", on: () => act("bot", {bot: id, key: "team", value: !b.team}, b.team ? "團隊成員看不到這個 Bot 了" : "團隊成員現在可以使用這個 Bot")});
if (!b.primary & & isOwner()) more.push({icon: "star", label: "設為主要 Bot", on: () => act("bot", {bot: id, key: "primary", value: true}, "已設為主要 Bot")});
if (!b.primary & & isOwner()) more.push({icon: "star", label: "設為主要 Bot", on: () => act("bot", {bot: id, key: "primary", value: true}, "已設為主要 Bot")});
// 已釘選的 Bot in another order (the desktop drags them; here one step at a time).
const pins = (S.pinOrder || []).filter((x) => { const y = bot(x); return y & & y.pinned & & !y.primary; });
const at = pins.indexOf(id);
if (isOwner() & & b.pinned & & at > 0) more.push({icon: "arrow-up", label: "釘選裡往前移", on: () => act("bot", {bot: id, key: "pin_at", value: at - 1}, false)});
if (isOwner() & & b.pinned & & at >= 0 & & at < pins.length - 1 ) more . push ( { icon: " arrow-down " , label: " 釘選裡往後移 " , on: ( ) = > act("bot", {bot: id, key: "pin_at", value: at + 1}, false)});
// 分享: the bot as a file (another AnyBot imports it), or this chat as Markdown.
if (isOwner()) more.push({icon: "share", label: "匯出 Bot 檔案(.anybot) ", on: () => exportAs("export_bot", id)});
more.push({icon: "refresh", label: "重新啟動這個 Bot", on: () => act("restart_bot", {bot: id})});
more.push({icon: "refresh", label: "重新啟動這個 Bot", on: () => act("restart_bot", {bot: id})});
items.push({icon: "ellipsis", label: "更多…", on: () => sheet(b.name, more)});
items.push({icon: "ellipsis", label: "更多…", on: () => sheet(b.name, more)});
if (isOwner()) items.push({sep: true}, {icon: "trash", label: "刪除 Bot", danger: true, on: () => deleteBot(b)});
if (isOwner()) items.push({sep: true}, {icon: "trash", label: "刪除 Bot", danger: true, on: () => deleteBot(b)});
@ -1573,8 +1649,36 @@ $("b-newbot").onclick = async () => {
{icon: "sparkles", label: "從範本建立", on: templates},
{icon: "sparkles", label: "從範本建立", on: templates},
{icon: "users", label: "建立群組聊天", on: groupChat},
{icon: "users", label: "建立群組聊天", on: groupChat},
{icon: "folder", label: "新增分區", on: async () => { const n = await ask("新增分區", "", "例如:文宣組"); if (n) app("create_group", {name: n}); }},
{icon: "folder", label: "新增分區", on: async () => { const n = await ask("新增分區", "", "例如:文宣組"); if (n) app("create_group", {name: n}); }},
{icon: "download", label: "匯入 Bot 檔案(.anybot) ", on: importBot},
]);
]);
};
};
// A file the brain made (a bot, a transcript): saved on the phone — the share sheet where there
// is one (iPhone: 儲存到檔案, AirDrop…), else a download.
async function exportAs(what, id) {
const v = await act(what, {bot: id}, false);
if (!v || !v.content) return;
const file = new File([v.content], v.filename || "AnyBot.txt", {type: what === "export_bot" ? "application/json" : "text/markdown"});
try { if (navigator.canShare & & navigator.canShare({files: [file]})) { await navigator.share({files: [file]}); return; } } catch (e) { if (e.name === "AbortError") return; }
const a = document.createElement("a"); a.href = URL.createObjectURL(file); a.download = file.name; document.body.appendChild(a); a.click(); a.remove();
setTimeout(() => URL.revokeObjectURL(a.href), 4000);
toast("已存成「" + file.name + "」");
}
async function saveText(text, name) {
const file = new File([text], name, {type: "text/markdown"});
try { if (navigator.canShare & & navigator.canShare({files: [file]})) { await navigator.share({files: [file]}); return; } } catch (e) { if (e.name === "AbortError") return; }
const a = document.createElement("a"); a.href = URL.createObjectURL(file); a.download = name; document.body.appendChild(a); a.click(); a.remove();
setTimeout(() => URL.revokeObjectURL(a.href), 4000);
toast("已存成「" + name + "」");
}
function importBot() {
const pick = document.createElement("input"); pick.type = "file"; pick.accept = ".anybot,application/json";
pick.onchange = async () => {
const f = pick.files & & pick.files[0]; if (!f) return;
const v = await act("import_bot", {content: await f.text()}, false);
if (v & & v.ok !== false) { toast(v.text || "已匯入"); newBotDone(v); }
};
pick.click();
}
function newBotDone(v) { if (v & & v.bot) setTimeout(() => go("chat", {bot: v.bot}), 400); }
function newBotDone(v) { if (v & & v.bot) setTimeout(() => go("chat", {bot: v.bot}), 400); }
async function templates() {
async function templates() {
if (!S.settings) await loadSettings();
if (!S.settings) await loadSettings();
@ -1707,9 +1811,23 @@ function keepChat(id, msgs, sig) {
CHATS.delete(k); CHATS.set(k, was & & was.sig === sig & & Date.now() - (was.t || 0) < = 3600000 ? was : c);
CHATS.delete(k); CHATS.set(k, was & & was.sig === sig & & Date.now() - (was.t || 0) < = 3600000 ? was : c);
while (CHATS.size > 12) { const old = CHATS.keys().next().value; CHATS.delete(old); KEEP.del("chat:" + old); }
while (CHATS.size > 12) { const old = CHATS.keys().next().value; CHATS.delete(old); KEEP.del("chat:" + old); }
}
}
// What was typed and not sent stays with its bot, as on the computer: switching bots, or closing
// the page, does not lose it (kept on this phone, per AnyBot).
const draftKey = () => "anybot.drafts:" + (S.host || "lan");
function drafts() { try { return JSON.parse(localStorage.getItem(draftKey()) || "{}"); } catch (_) { return {}; } }
function keepDraft(id, text) {
if (!id) return;
const d = drafts();
if (text & & text.trim()) d[id] = text; else delete d[id];
try { localStorage.setItem(draftKey(), JSON.stringify(d)); } catch (_) {}
}
function openChat(id, at) {
function openChat(id, at) {
S.jumpAt = at || 0;
S.jumpAt = at || 0;
if (S.open !== id) {
if (S.open !== id) {
// (The box by id: this can run before the script below has named it.)
const box = $("input");
keepDraft(S.open, box.value);
box.value = drafts()[id] || ""; box.style.height = "auto"; setTimeout(() => box.dispatchEvent(new Event("input")), 0);
keepChat(S.open, S.msgs, S.chatSig);
keepChat(S.open, S.msgs, S.chatSig);
S.msgs = []; S.pending = []; S.quote = null; S.unfold = {}; S.openSteps = {}; S.chatSig = ""; S.prevShown = 0; S.prevFirst = ""; MODE_OPEN = ""; $("msgs").innerHTML = "";
S.msgs = []; S.pending = []; S.quote = null; S.unfold = {}; S.openSteps = {}; S.chatSig = ""; S.prevShown = 0; S.prevFirst = ""; MODE_OPEN = ""; $("msgs").innerHTML = "";
const kept = CHATS.get(chatKey(id));
const kept = CHATS.get(chatKey(id));
@ -1758,7 +1876,7 @@ async function loadChat(jump) {
loading = false;
loading = false;
if (again) { again = false; loadChat(); }
if (again) { again = false; loadChat(); }
// 任務 → a message older than what the phone keeps of the chat: the chat stays at its end.
// 任務 → a message older than what the phone keeps of the chat: the chat stays at its end.
else if (S.jumpAt & & S.chatLoaded & & S.open === id & & !jumpTo()) { S.jumpAt = 0; toast("那件事開頭的 訊息太早了,手機上只留最近的訊息"); }
else if (S.jumpAt & & S.chatLoaded & & S.open === id & & !jumpTo()) { S.jumpAt = 0; toast("那則 訊息太早了,手機上只留最近的訊息"); }
}
}
// 載入更早:開頁只拿最新 30 條,這裡一次往回補 60 條(序號去重,接在上方)——從大腦上整段聊天拿,
// 載入更早:開頁只拿最新 30 條,這裡一次往回補 60 條(序號去重,接在上方)——從大腦上整段聊天拿,
// 不只手機那份最新的。按了一定有回應:載入中、補上了、或「已是對話最開頭」(按鈕收起來)。
// 不只手機那份最新的。按了一定有回應:載入中、補上了、或「已是對話最開頭」(按鈕收起來)。
@ -2194,6 +2312,7 @@ function selectSheet(i, m) {
el.scrollTop = 0;
el.scrollTop = 0;
}
}
async function copyText(t) { try { await navigator.clipboard.writeText(t || ""); toast("已複製"); } catch (_) { toast("這支手機不讓網頁複製"); } }
async function copyText(t) { try { await navigator.clipboard.writeText(t || ""); toast("已複製"); } catch (_) { toast("這支手機不讓網頁複製"); } }
document.addEventListener("click", (e) => { const b = e.target.closest("[data-copycode]"); if (!b) return; e.stopPropagation(); copyText((b.parentElement.querySelector("code") || {}).textContent || ""); }, true);
const QUICK = ["👍", "❤️", "😂", "🎉", "👀", "🙏", "👌", "🔥"];
const QUICK = ["👍", "❤️", "😂", "🎉", "👀", "🙏", "👌", "🔥"];
function msgMenu(i) {
function msgMenu(i) {
const m = S.msgs[i]; if (!m) return;
const m = S.msgs[i]; if (!m) return;
@ -2349,6 +2468,7 @@ function renderQuote() {
if (q) $("q-x").onclick = () => { S.quote = null; renderQuote(); };
if (q) $("q-x").onclick = () => { S.quote = null; renderQuote(); };
}
}
const input = $("input");
const input = $("input");
input.addEventListener("input", () => { clearTimeout(S.draftTimer); S.draftTimer = setTimeout(() => keepDraft(S.open, input.value), 400); });
input.addEventListener("input", () => {
input.addEventListener("input", () => {
input.style.height = "auto"; input.style.height = Math.min(input.scrollHeight, 140) + "px";
input.style.height = "auto"; input.style.height = Math.min(input.scrollHeight, 140) + "px";
$("composer").classList.toggle("tall", input.scrollHeight > 40); renderSendBtn();
$("composer").classList.toggle("tall", input.scrollHeight > 40); renderSendBtn();
@ -2493,7 +2613,7 @@ async function send() {
memReset();
memReset();
// (A command takes no file that isn't up yet: those stay above the input for the next message.)
// (A command takes no file that isn't up yet: those stay above the input for the next message.)
const had = S.pending; S.pending = quiet ? S.pending.filter((p) => p.blob) : [];
const had = S.pending; S.pending = quiet ? S.pending.filter((p) => p.blob) : [];
input.value = ""; input.style.height = "auto"; $("composer").classList.remove("tall"); renderChips(); renderSlash();
input.value = ""; keepDraft(S.open, ""); input.style.height = "auto"; $("composer").classList.remove("tall"); renderChips(); renderSlash();
// A command (not words for the chat): sent now, or said that it couldn't be (its words and files back).
// A command (not words for the chat): sent now, or said that it couldn't be (its words and files back).
if (quiet) { try { await deliver(base() + `api/bots/${S.open}/send`, {text, attachments}); loadChat(); } catch (e) { toast(e.message); if (!input.value) { input.value = text; input.dispatchEvent(new Event("input")); } S.pending = [...had.filter((p) => !S.pending.includes(p)), ...S.pending]; renderChips(); } return; }
if (quiet) { try { await deliver(base() + `api/bots/${S.open}/send`, {text, attachments}); loadChat(); } catch (e) { toast(e.message); if (!input.value) { input.value = text; input.dispatchEvent(new Event("input")); } S.pending = [...had.filter((p) => !S.pending.includes(p)), ...S.pending]; renderChips(); } return; }
// 先顯示: in the chat at once, network or not; it goes when the line is there (kept on this
// 先顯示: in the chat at once, network or not; it goes when the line is there (kept on this
@ -2660,6 +2780,7 @@ $("b-chatmore").onclick = () => {
{icon: "info", label: "對話詳細資訊", on: () => go("details", {bot: b.id})},
{icon: "info", label: "對話詳細資訊", on: () => go("details", {bot: b.id})},
{icon: "history", label: "過去的對話", x: String((b.threads || []).length || ""), on: () => threads(b)},
{icon: "history", label: "過去的對話", x: String((b.threads || []).length || ""), on: () => threads(b)},
{icon: "copy", label: "複製整段對話", on: () => copyText(S.msgs.filter((m) => m.text & & !m.summary).map((m) => (m.role === "user" ? "我:" : b.name + ": ") + m.text).join("\n\n"))},
{icon: "copy", label: "複製整段對話", on: () => copyText(S.msgs.filter((m) => m.text & & !m.summary).map((m) => (m.role === "user" ? "我:" : b.name + ": ") + m.text).join("\n\n"))},
{icon: "download", label: "匯出文字記錄(.md) ", on: () => exportAs("export_transcript", b.id)},
];
];
if (owner()) items.splice(1, 0, {icon: "refresh", label: "重新產生上一個回答", on: regen});
if (owner()) items.splice(1, 0, {icon: "refresh", label: "重新產生上一個回答", on: regen});
if (isOwner()) items.push({icon: "settings", label: "Bot 設定", on: () => go("botset", {bot: b.id})});
if (isOwner()) items.push({icon: "settings", label: "Bot 設定", on: () => go("botset", {bot: b.id})});
@ -3063,7 +3184,11 @@ async function renderBotset(id) {
h += ticks("可以用的電腦", "may_use", (d.may_use || []).length > 1 ? d.may_use : [], "它自己的電腦一定可以用。");
h += ticks("可以用的電腦", "may_use", (d.may_use || []).length > 1 ? d.may_use : [], "它自己的電腦一定可以用。");
}
}
h += `< div class = "gt" > 頭像< / div > < div class = "group" > < div class = "shapes" > ${(st.shapes || []).map((s) => `< button data-shape = "${s}" class = "${s === d.shape ? " on " : " " } " > ${avatarSvg(s, b.color)}< / button > `).join("")}< / div > < div class = "colors" > ${(st.colors || []).map((c) => `< button data-color = "${c.key}" title = "${esc(c.name)}" class = "${c.key === d.color ? " on " : " " } " style = "background:${c.hex}" > < / button > `).join("")}< / div > < / div > `;
h += `< div class = "gt" > 頭像< / div > < div class = "group" > < div class = "shapes" > ${(st.shapes || []).map((s) => `< button data-shape = "${s}" class = "${s === d.shape ? " on " : " " } " > ${avatarSvg(s, b.color)}< / button > `).join("")}< / div > < div class = "colors" > ${(st.colors || []).map((c) => `< button data-color = "${c.key}" title = "${esc(c.name)}" class = "${c.key === d.color ? " on " : " " } " style = "background:${c.hex}" > < / button > `).join("")}< / div > < / div > `;
h += group("AI 與電腦", item({icon: "sparkles", k: "模型", v: b.via || b.model, r: b.runs || "", tap: 1, data: 'data-e="model"'}) + item({icon: "monitor", k: "做事的電腦", r: b.computer || "", tap: 1, data: 'data-e="comp"'}) + item({icon: "terminal", k: "電腦操作", v: S.settings & & S.settings.direct_mode ? "直接操作開著:照樣可以用電腦(關掉直接操作才照這裡)" : "關掉時,用電腦前會先問你", sw: d.tools_enabled !== false, swdata: 'data-sw="tools"', disabled: !isOwner()}) + item({icon: "brain", k: "模型可讀長度", r: (CTX.find((c) => c[0] === d.context_tokens) || [0, Math.round((d.context_tokens || 0) / 1000) + "K"])[1], tap: 1, data: 'data-e="ctx"'}));
// (As on the computer's Bot 設定: who carries out the planned steps, and how long it thinks.)
const EFFORTS = [["", "自動(模型自己決定)"], ["low", "快速(想得少,回得快)"], ["medium", "平衡"], ["high", "深入(想得久,較慢)"]];
const stepShown = !d.step_model ? "自動" : d.step_model === "off" ? "不分開" : d.step_model;
const extra = isOwner() ? item({icon: "zap", k: "執行步驟用的模型", v: "想計畫和確認用上面的模型;照計畫做的步驟交給這個比較快的", r: stepShown, tap: 1, data: 'data-e="step"'}) + item({icon: "lightbulb", k: "思考模式", r: (EFFORTS.find((e) => e[0] === (d.thinking || "")) || EFFORTS[0])[1].replace(/( .*) /, ""), tap: 1, data: 'data-e="think"'}) : "";
h += group("AI 與電腦", item({icon: "sparkles", k: "模型", v: b.via || b.model, r: b.runs || "", tap: 1, data: 'data-e="model"'}) + extra + item({icon: "monitor", k: "做事的電腦", r: b.computer || "", tap: 1, data: 'data-e="comp"'}) + item({icon: "terminal", k: "電腦操作", v: S.settings & & S.settings.direct_mode ? "直接操作開著:照樣可以用電腦(關掉直接操作才照這裡)" : "關掉時,用電腦前會先問你", sw: d.tools_enabled !== false, swdata: 'data-sw="tools"', disabled: !isOwner()}) + item({icon: "brain", k: "模型可讀長度", r: (CTX.find((c) => c[0] === d.context_tokens) || [0, Math.round((d.context_tokens || 0) / 1000) + "K"])[1], tap: 1, data: 'data-e="ctx"'}));
if (isOwner()) h += group("已設定「一律允許」", (d.allow_rules || []).map((r) => `< div class = "item" > ${ic("shield", 17)}< div class = "mid" > < div class = "v" style = "color:var(--text);font-size:var(--fs-ui)" > ${esc(r)}< / div > < / div > < button class = "btn sm no" data-rule = "${esc(r)}" > 移除< / button > < / div > `).join("") || `< div class = "note" style = "padding:12px 16px" > 還沒有。在核准時選「一律允許」就會記在這裡。< / div > `);
if (isOwner()) h += group("已設定「一律允許」", (d.allow_rules || []).map((r) => `< div class = "item" > ${ic("shield", 17)}< div class = "mid" > < div class = "v" style = "color:var(--text);font-size:var(--fs-ui)" > ${esc(r)}< / div > < / div > < button class = "btn sm no" data-rule = "${esc(r)}" > 移除< / button > < / div > `).join("") || `< div class = "note" style = "padding:12px 16px" > 還沒有。在核准時選「一律允許」就會記在這裡。< / div > `);
h += group("整理", item({icon: "pin", k: "釘選", sw: !!d.pinned, swdata: 'data-sw="pinned"'}) + item({icon: "star", k: "主要 Bot", v: d.primary ? "這是主要 Bot" : "", sw: !!d.primary, swdata: 'data-sw="primary"', disabled: !!d.primary}) + item({icon: "folder", k: "分區", r: d.folder || "未分區", tap: 1, data: 'data-e="folder"'}));
h += group("整理", item({icon: "pin", k: "釘選", sw: !!d.pinned, swdata: 'data-sw="pinned"'}) + item({icon: "star", k: "主要 Bot", v: d.primary ? "這是主要 Bot" : "", sw: !!d.primary, swdata: 'data-sw="primary"', disabled: !!d.primary}) + item({icon: "folder", k: "分區", r: d.folder || "未分區", tap: 1, data: 'data-e="folder"'}));
if ((d.demos || []).length) h += group("示範教學", d.demos.map((x) => item({icon: "eye", k: x.name, v: `${x.steps} 個步驟 · ${x.created}`})).join("") + `< div class = "note" style = "padding:8px 16px" > 示範要在那台電腦上錄; Bot 在對話裡會照著做。< / div > `);
if ((d.demos || []).length) h += group("示範教學", d.demos.map((x) => item({icon: "eye", k: x.name, v: `${x.steps} 個步驟 · ${x.created}`})).join("") + `< div class = "note" style = "padding:8px 16px" > 示範要在那台電腦上錄; Bot 在對話裡會照著做。< / div > `);
@ -3103,6 +3228,13 @@ async function renderBotset(id) {
else if (k === "not_for") { const n = await ask("不找它做的事", d.not_for || "", "例如:不寫程式、不碰帳務", true); if (n != null & & n !== (d.not_for || "") & & await act("bot", {bot: id, key: "not_for", value: n}, "已更新")) refresh(); }
else if (k === "not_for") { const n = await ask("不找它做的事", d.not_for || "", "例如:不寫程式、不碰帳務", true); if (n != null & & n !== (d.not_for || "") & & await act("bot", {bot: id, key: "not_for", value: n}, "已更新")) refresh(); }
else if (k === "model") modelSheet(b);
else if (k === "model") modelSheet(b);
else if (k === "comp") pickComputer(b, d);
else if (k === "comp") pickComputer(b, d);
else if (k === "think") sheet("思考模式", [{group: "想得越久越仔細,也越慢、越花額度"}].concat(EFFORTS.map(([v, l]) => ({label: l, check: v === (d.thinking || ""), on: async () => { if (await act("bot", {bot: id, key: "thinking", value: v}, "已更新")) refresh(); }}))));
else if (k === "step") {
const models = ((S.models || []).find((p) => p.provider === b.provider) || {}).models || [];
const pick = (v, ok) => async () => { if (await act("bot", {bot: id, key: "step_model", value: v}, ok)) refresh(); };
sheet("執行步驟用的模型", [{label: "自動", check: !d.step_model, on: pick("", "已改成自動")}, {label: "不分開(每一步都用上面的模型)", check: d.step_model === "off", on: pick("off", "已改成不分開")}]
.concat(models.filter((m) => m !== b.model).map((m) => ({label: m, check: d.step_model === m, on: pick(m, "步驟改用 " + m)}))));
}
else if (k === "ctx") sheet("模型可讀長度", CTX.map(([n, l]) => ({label: l + " 個 token", check: n === d.context_tokens, on: async () => { if (await act("bot", {bot: id, key: "context", value: n}, "已更新")) refresh(); }})));
else if (k === "ctx") sheet("模型可讀長度", CTX.map(([n, l]) => ({label: l + " 個 token", check: n === d.context_tokens, on: async () => { if (await act("bot", {bot: id, key: "context", value: n}, "已更新")) refresh(); }})));
else if (k === "folder") moveToFolder(b);
else if (k === "folder") moveToFolder(b);
else if (k === "restart") act("restart_bot", {bot: id});
else if (k === "restart") act("restart_bot", {bot: id});
@ -3139,7 +3271,7 @@ async function settingsChanged() {
}
}
let listTimer = null;
let listTimer = null;
function stopListTimer() { clearInterval(listTimer); listTimer = null; }
function stopListTimer() { clearInterval(listTimer); listTimer = null; }
const TITLES = {tasks: "任務", routines: "例行任務", pages: "頁面", computers: "電腦", settings: "設定", general: "一般", models: "模型", perms: "權限", integrations: "整合", vault: "保險庫", account: "手機與帳號", updates: "更新"};
const TITLES = {tasks: "任務", routines: "例行任務", pages: "頁面", computers: "電腦", settings: "設定", general: "一般", me: "個人資料與用量", m odels: "模型", perms: "權限", integrations: "整合", vault: "保險庫", account: "手機與帳號", updates: "更新"};
async function renderList(arg) {
async function renderList(arg) {
const kind = arg.kind;
const kind = arg.kind;
$("list-title").textContent = TITLES[kind] || "";
$("list-title").textContent = TITLES[kind] || "";
@ -3149,6 +3281,7 @@ async function renderList(arg) {
if (kind === "tasks") return listTasks(el);
if (kind === "tasks") return listTasks(el);
if (kind === "routines") return listRoutines(el);
if (kind === "routines") return listRoutines(el);
if (kind === "pages") return listPages(el);
if (kind === "pages") return listPages(el);
if (kind === "me") return listMe(el);
if (SETTINGS_PAGES.includes(kind)) {
if (SETTINGS_PAGES.includes(kind)) {
// (Drawn from what this phone has at once; read again behind it when it may be old.)
// (Drawn from what this phone has at once; read again behind it when it may be old.)
if (!S.settings) { el.innerHTML = `< div class = "empty" > 載入中…< / div > `; await loadSettings(); }
if (!S.settings) { el.innerHTML = `< div class = "empty" > 載入中…< / div > `; await loadSettings(); }
@ -3159,6 +3292,58 @@ async function renderList(arg) {
if (["computers", "integrations"].includes(kind)) listTimer = setInterval(async () => { await loadSettings(); if (cur().v === "list" & & cur().arg.kind === kind) drawSettings(kind, true); }, 4000);
if (["computers", "integrations"].includes(kind)) listTimer = setInterval(async () => { await loadSettings(); if (cur().v === "list" & & cur().arg.kind === kind) drawSettings(kind, true); }, 4000);
}
}
}
}
// ---------- 個人資料與用量(設定)----------
// The year in figures, a heat map of its days, and 用量 by period — as on the computer
// (設定 › 個人資料): big numbers and bars instead of lines of words; the fine print in a tap.
const ME = {span: "30", by: "model", data: null, at: 0};
const wan = (n) => { n = n || 0; return n < 1e4 ? n . toLocaleString ( " en-US " ) : n < 1e7 ? ( n / 1e4 ) . toFixed ( 1 ) . replace ( / \ . 0 $ / , " " ) + " 萬 " : n < 1e8 ? Math . round ( n / 1e4 ) . toLocaleString ( " en-US " ) + " 萬 " : ( n / 1e8 ) . toFixed ( 2 ) . replace ( / \ . 00 $ / , " " ) + " 億 " ; } ;
const costWords = (micros, unpriced, calls) => !micros ? "未定價" : "US$" + (micros / 1e6).toFixed(2) + (unpriced > 0 & & unpriced < calls ? ` ( 另有 $ { unpriced } 次呼叫未定價 ) ` : " " ) ;
const shortDate = (d) => { const [, m, dd] = (d || "").split("-"); return m ? `${+m}月${+dd}日` : d || ""; };
async function listMe(el) {
if (ME.data) drawMe(el); else el.innerHTML = `< div class = "empty" > 正在算過去一年的用量…< / div > `;
if (ME.data & & Date.now() - ME.at < 60000 ) return ;
try { ME.data = await api(base() + "api/stats"); ME.at = Date.now(); }
catch (e) { if (!ME.data) { el.innerHTML = `< div class = "empty" > 讀不到用量:${esc(e.message)}< / div > `; return; } }
if (cur().v === "list" & & cur().arg.kind === "me") drawMe(el);
}
function drawMe(el) {
const d = ME.data || {};
const figs = [[wan(d.tokens_year), "Token・一年"], [wan(d.messages_year), "訊息・一年"], [(d.streak_now || 0) + " 天", "連續使用"], [(d.streak_best || 0) + " 天", "最長連續"]];
let h = `< div class = "me-figs" > ${figs.map(([v, l]) => `< div > < b > ${esc(v)}< / b > < span > ${esc(l)}< / span > < / div > `).join("")}< / div > `;
// The year: a dot a day, a column a week (Sunday on top), deeper the busier.
const days = d.days || [], off = d.weekday_first || 0, weeks = Math.ceil((days.length + off) / 7) || 1;
const cell = 7, W = weeks * cell, H = 7 * cell;
const lv = ["var(--hover)", "color-mix(in srgb,var(--accent) 30%,transparent)", "color-mix(in srgb,var(--accent) 50%,transparent)", "color-mix(in srgb,var(--accent) 75%,transparent)", "var(--accent)"];
const dots = days.map((x, i) => { const k = i + off; return `< circle cx = "${Math.floor(k / 7) * cell + cell / 2}" cy = "${(k % 7) * cell + cell / 2}" r = "${cell * 0.38}" fill = "${lv[Math.min(4, x[3] || 0)]}" > < title > ${esc(shortDate(x[0]))}: ${wan(x[1])} token、${x[2]} 則訊息< / title > < / circle > `; }).join("");
const busy = d.busiest & & d.busiest.date ? `最活躍:${shortDate(d.busiest.date)}・${wan(d.busiest.tokens)} token` : "";
h += `< div class = "gt" > 活動< / div > < div class = "me-card" > < svg class = "me-heat" viewBox = "0 0 ${W} ${H}" preserveAspectRatio = "xMinYMid meet" > ${dots}< / svg > < div class = "me-note" > 過去一年有 ${d.active_days || 0} 個活躍日${busy ? "・" + esc(busy) : ""}< / div > < / div > `;
// 用量: the period's big number, a bar a day, then by model or by bot.
const u = (d.periods || {})[ME.span] || {};
const seg = (list, cur, key) => `< div class = "me-seg" > ${list.map(([v, l]) => `< button data- $ { key } = " $ { v } " class = "${v === cur ? " on " : " " } " > ${l}< / button > `).join("")}< / div > `;
h += `< div class = "gt" > 用量< / div > < div class = "me-card" > ${seg([["7", "7 天"], ["30", "30 天"], ["90", "90 天"], ["365", "一年"]], ME.span, "mespan")}`;
h += `< div class = "me-hero" > < b > ${wan(u.tokens)}< / b > token< / div > < div class = "me-note" title = "花費是模型服務自己回報的;沒回報的寫「未定價」,不是 0 元。" > ${wan(u.calls)} 次呼叫・花費 ${esc(costWords(u.cost_micros, u.unpriced, u.calls))}・新讀 ${wan((u.input || 0) + (u.cache_write || 0))}、寫 ${wan(u.output)}、快取 ${wan(u.cache_read)}< / div > `;
const daily = u.daily || [], max = Math.max(1, ...daily.map((x) => x[1] || 0)), bw = 100 / Math.max(1, daily.length);
h += `< svg class = "me-bars" viewBox = "0 0 100 40" preserveAspectRatio = "none" > ${daily.map((x, i) => x[1] ? `< rect x = "${i * bw + bw * 0.18}" y = "${40 - Math.max(1.2, x[1] / max * 38)}" width = "${bw * 0.64}" height = "${Math.max(1.2, x[1] / max * 38)}" rx = "0.6" fill = "var(--accent)" > < title > ${esc(shortDate(x[0]))}: ${wan(x[1])} token< / title > < / rect > ` : "").join("")}< / svg > `;
const rows = (u[ME.by === "bot" ? "by_bot" : "by_model"] || []).slice(0, 8);
const total = Math.max(1, rows.reduce((n, r) => n + (r.tokens || 0), 0));
const cat = (i) => `var(--cat${(i % 6) + 1})`;
h += seg([["model", "依模型"], ["bot", "依 Bot"]], ME.by, "meby");
if (!rows.length) h += `< div class = "me-note" > 這段時間沒有用量紀錄< / div > `;
else {
if (ME.by === "model") h += `< div class = "me-split" > ${rows.map((r, i) => `< i style = "width:${(r.tokens || 0) / total * 100}%;background:${cat(i)}" > < / i > `).join("")}< / div > `;
const top = Math.max(1, rows[0].tokens || 0);
h += rows.map((r, i) => {
const b = ME.by === "bot" ? S.bots.find((x) => x.name === r.name) : null;
const mark = ME.by === "bot" ? `< span class = "me-av" > ${b ? avatarSvg(b.shape, b.color) : ""}< / span > ` : `< span class = "me-dot" style = "background:${cat(i)}" > < / span > `;
const bar = ME.by === "bot" ? `< span class = "me-bar" > < i style = "width:${(r.tokens || 0) / top * 100}%" > < / i > < / span > ` : "";
return `< div class = "me-row" > ${mark}< span class = "me-name" > ${esc(r.name)}< / span > ${bar}< span class = "me-n" > ${wan(r.tokens)}・${Math.round((r.tokens || 0) / total * 100)}%< / span > < / div > `;
}).join("");
}
h += `< / div > < div style = "height:calc(var(--safe-b) + 24px)" > < / div > `;
el.innerHTML = h;
el.querySelectorAll("[data-mespan]").forEach((b) => b.onclick = () => { ME.span = b.dataset.mespan; drawMe(el); });
el.querySelectorAll("[data-meby]").forEach((b) => b.onclick = () => { ME.by = b.dataset.meby; drawMe(el); });
}
// ---------- 任務 ----------
// ---------- 任務 ----------
// Every bot's tasks as the brain works them out — from the steps, the turn's end, the follow-ups,
// Every bot's tasks as the brain works them out — from the steps, the turn's end, the follow-ups,
// the goal checks and whether a device showed the files, never from what a bot says. They come
// the goal checks and whether a device showed the files, never from what a bot says. They come
@ -3197,7 +3382,9 @@ function listTasks(el) {
// 任務 → 那則訊息: the chat at where the task began, lit a moment (once that message is here).
// 任務 → 那則訊息: the chat at where the task began, lit a moment (once that message is here).
function jumpTo() {
function jumpTo() {
if (!S.jumpAt || S.view !== "chat") return false;
if (!S.jumpAt || S.view !== "chat") return false;
const i = S.msgs.findIndex((m) => m.at === S.jumpAt & & m.role === "user");
// (A task opens at the person's opening message; a search hit may be any message.)
let i = S.msgs.findIndex((m) => m.at === S.jumpAt & & m.role === "user");
if (i < 0 ) i = S.msgs.findIndex((m) = > m.at === S.jumpAt);
const el = i < 0 ? null : document . querySelector ( ` # msgs [ data-msg = "${i}" ] ` ) ;
const el = i < 0 ? null : document . querySelector ( ` # msgs [ data-msg = "${i}" ] ` ) ;
if (!el) return false;
if (!el) return false;
S.jumpAt = 0;
S.jumpAt = 0;
@ -3246,7 +3433,7 @@ function drawSettings(kind, quiet) {
let h = "";
let h = "";
if (kind === "settings") {
if (kind === "settings") {
h += group("", [
h += group("", [
["general", "settings", "一般", "外觀、時區、通知總開關"], ["models", "sparkles", "模型", "可以用的 AI 服務"], ["perms", "shield", "權限", st.direct_mode ? "直接操作:開" : "Bot 做事前的規則"],
["general", "settings", "一般", "外觀、時區、通知總開關"], ...(isOwner() ? [["me", "activity", "個人資料與用量", ""]] : []), ["models", "sparkles", "模型", "可以用的 AI 服務"], ["perms", "shield", "權限", st.direct_mode ? "直接操作:開" : "Bot 做事前的規則"],
["integrations", "plug", "整合", "訊息管道、連接器、技能"], ["computers", "monitor", "電腦", "Bot 的電腦和你帳號裡的電腦"], ["vault", "lock", "保險庫", "密碼和卡號"],
["integrations", "plug", "整合", "訊息管道、連接器、技能"], ["computers", "monitor", "電腦", "Bot 的電腦和你帳號裡的電腦"], ["vault", "lock", "保險庫", "密碼和卡號"],
["account", "smartphone", "手機與帳號", "登入的手機、這支手機的通知"], ["updates", "download", "更新", st.version || ""],
["account", "smartphone", "手機與帳號", "登入的手機、這支手機的通知"], ["updates", "download", "更新", st.version || ""],
].map(([k, i, n, v]) => item({icon: i, k: n, r: k === "updates" ? v : "", tap: 1, data: `data-go="${k}"`})).join(""));
].map(([k, i, n, v]) => item({icon: i, k: n, r: k === "updates" ? v : "", tap: 1, data: `data-go="${k}"`})).join(""));
@ -3566,7 +3753,7 @@ function pageToc(root) {
}
}
$("b-pagemore").onclick = () => {
$("b-pagemore").onclick = () => {
const v = S.pageData; if (!v) return;
const v = S.pageData; if (!v) return;
const items = [{icon: "copy", label: "複製 Markdown", on: () => copyText(v.body)}];
const items = [{icon: "copy", label: "複製 Markdown", on: () => copyText(v.body)}, {icon: "download", label: "存成檔案(.md) ", on: () => saveText(v.body, (v.title || "頁面").replace(/[\\/:*?"< >|]/g, "_") + ".md")} ];
if ((v.versions || []).length) items.push({icon: "history", label: "其他版本", on: () => sheet("版本", [{label: `第 ${v.latest} 版(最新)`, check: v.revision === v.latest, on: () => openPage(v.id)}, ...v.versions.map((x) => ({label: `第 ${x.revision} 版`, x: x.at, check: v.revision === x.revision, on: () => openPage(v.id, x.revision)}))])});
if ((v.versions || []).length) items.push({icon: "history", label: "其他版本", on: () => sheet("版本", [{label: `第 ${v.latest} 版(最新)`, check: v.revision === v.latest, on: () => openPage(v.id)}, ...v.versions.map((x) => ({label: `第 ${x.revision} 版`, x: x.at, check: v.revision === x.revision, on: () => openPage(v.id, x.revision)}))])});
if (isOwner()) items.push({sep: true}, {icon: "trash", label: "刪除頁面", danger: true, on: async () => { if (await confirmSheet(`刪除「${v.title}」?`, "", "刪除") & & await act("delete_page", {id: v.id}, "已刪除頁面")) back(); }});
if (isOwner()) items.push({sep: true}, {icon: "trash", label: "刪除頁面", danger: true, on: async () => { if (await confirmSheet(`刪除「${v.title}」?`, "", "刪除") & & await act("delete_page", {id: v.id}, "已刪除頁面")) back(); }});
sheet(v.title, items);
sheet(v.title, items);
@ -4008,7 +4195,7 @@ function pageMd(text, id, rev) {
});
});
if (items.length) { out.push(`< ul class = "steps" > ${items.join("")}< / ul > `); continue; }
if (items.length) { out.push(`< ul class = "steps" > ${items.join("")}< / ul > `); continue; }
}
}
out.push(`< pre > < code > ${esc(body.join("\n"))}< / code > < / pre > `); continue;
out.push(`< pre class = "cb" > < button class = "cpy" data-copycode > ${ic("copy", 14)}< / button > < code > ${esc(body.join("\n"))}< / code > < / pre > `); continue;
}
}
const h = t.match(/^(#{1,6})\s+(.*)$/);
const h = t.match(/^(#{1,6})\s+(.*)$/);
if (h) { const n = Math.min(h[1].length + 1, 4); out.push(`< h $ { n } > ${inl(h[2])}< /h${n}>`); i++; continue; }
if (h) { const n = Math.min(h[1].length + 1, 4); out.push(`< h $ { n } > ${inl(h[2])}< /h${n}>`); i++; continue; }