@kadaliao/dsh-bots 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -504,6 +504,9 @@ window.__ModuleLoader__.load({
504
504
  github: (s = 14) => svg(s, ['M9 19c-4 1.5-4-2-6-2.5', 'M15 21v-3.5a3 3 0 0 0-.8-2.3c2.8-.3 5.8-1.4 5.8-6.2a4.8 4.8 0 0 0-1.3-3.3 4.5 4.5 0 0 0-.1-3.3s-1-.3-3.4 1.3a11.6 11.6 0 0 0-6 0C6.8 2.1 5.8 2.4 5.8 2.4a4.5 4.5 0 0 0-.1 3.3A4.8 4.8 0 0 0 4.4 9c0 4.8 3 5.9 5.8 6.2a3 3 0 0 0-.8 2.3V21']),
505
505
  wand: (s = 14) => svg(s, ['M4 20l11-11', 'M13 7l4 4', 'M18 3v4', 'M16 5h4', 'M8 3v2', 'M7 4h2']),
506
506
  chevron: (s = 12) => svg(s, ['M6 9l6 6 6-6']),
507
+ chart: (s = 14) => svg(s, ['M4 20V10', 'M10 20V4', 'M16 20v-7', 'M21 20H3']),
508
+ brain: (s = 14) => svg(s, ['M9 4a3 3 0 0 0-3 3v.2A3 3 0 0 0 4 10a3 3 0 0 0 1 2.2A3 3 0 0 0 6 17a3 3 0 0 0 3 3h0V4z', 'M15 4a3 3 0 0 1 3 3v.2A3 3 0 0 1 20 10a3 3 0 0 1-1 2.2A3 3 0 0 1 18 17a3 3 0 0 1-3 3h0V4z']),
509
+ gear: (s = 14) => svg(s, ['M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z', 'M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z']),
507
510
  };
508
511
  function BotsGlyph(props) {
509
512
  const size = Number(props?.size) > 0 ? Number(props.size) : 18;
@@ -967,7 +970,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
967
970
  return groups.sort((a, b) => (a.id === '' ? 1 : b.id === '' ? -1 : 0)).map((g) => ({ ...g, label: label(g.id) }));
968
971
  }
969
972
 
970
- function Rail({ t, bots, primaryId, selected, onSelect, onNew, onTeams, view, onActivity, messageCount }) {
973
+ function Rail({ t, bots, primaryId, selected, onSelect, onNew, onTeams, view, onActivity, messageCount, onUsage, onMemory, onSettings, teamNotes }) {
971
974
  const lang = langOf(t);
972
975
  const [q, setQ] = useState('');
973
976
  const [menu, setMenu] = useState(false);
@@ -1003,7 +1006,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1003
1006
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, fontWeight: 700, fontSize: 15 } }, h(BotsGlyph, { size: 18, active: true }), t('title')),
1004
1007
  h(
1005
1008
  'div',
1006
- { style: { position: 'relative' } },
1009
+ { style: { position: 'relative', display: 'flex', alignItems: 'center', gap: 4 } },
1010
+ onSettings ? h(Btn, { kind: 'ghost', size: 'sm', icon: Icon.gear(14), title: t('settings'), onClick: onSettings, 'data-dsh-bots-settings': true }) : null,
1007
1011
  h(Btn, { kind: 'primary', size: 'sm', icon: Icon.plus(13), onClick: () => setMenu((v) => !v), 'data-dsh-bots-new': true }, t('newBot'), Icon.chevron(11)),
1008
1012
  menu
1009
1013
  ? h(Menu, {
@@ -1047,6 +1051,22 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1047
1051
  h('span', { style: { width: 36, height: 36, borderRadius: '50%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.layer2, color: C.label, flex: 'none' } }, Icon.activity(16)),
1048
1052
  h('span', { style: { display: 'flex', flexDirection: 'column', flex: 1, minWidth: 0 } }, h('span', { style: { fontWeight: 600 } }, t('activity')), h('span', { style: { fontSize: TINY, color: C.muted } }, t('activityHint', { n: messageCount ?? 0 }))),
1049
1053
  ),
1054
+ onUsage
1055
+ ? h(
1056
+ 'button',
1057
+ { type: 'button', className: 'dshb-row', 'data-active': view === 'usage', 'data-dsh-bots-usage-entry': true, onClick: onUsage },
1058
+ h('span', { style: { width: 36, height: 36, borderRadius: '50%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.layer2, color: C.label, flex: 'none' } }, Icon.chart(16)),
1059
+ h('span', { style: { display: 'flex', flexDirection: 'column', flex: 1, minWidth: 0 } }, h('span', { style: { fontWeight: 600 } }, t('usage')), h('span', { style: { fontSize: TINY, color: C.muted } }, t('usageHint', { tokens: fmtNum(bots.reduce((n, b) => n + (Number(b.usageToday) || 0), 0)) }))),
1060
+ )
1061
+ : null,
1062
+ onMemory
1063
+ ? h(
1064
+ 'button',
1065
+ { type: 'button', className: 'dshb-row', 'data-active': view === 'memory', 'data-dsh-bots-memory-entry': true, onClick: onMemory },
1066
+ h('span', { style: { width: 36, height: 36, borderRadius: '50%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.layer2, color: C.label, flex: 'none' } }, Icon.brain(16)),
1067
+ h('span', { style: { display: 'flex', flexDirection: 'column', flex: 1, minWidth: 0 } }, h('span', { style: { fontWeight: 600 } }, t('teamMemoryTitle')), h('span', { style: { fontSize: TINY, color: C.muted } }, t('teamMemoryHint', { n: teamNotes ?? 0 }))),
1068
+ )
1069
+ : null,
1050
1070
  h(
1051
1071
  'button',
1052
1072
  { type: 'button', className: 'dshb-row', 'data-active': view === 'teams', 'data-dsh-bots-teams-entry': true, onClick: onTeams },
@@ -1063,6 +1083,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1063
1083
  function party(t, id) {
1064
1084
  if (id === 'user') return { kind: 'user', name: t('you') };
1065
1085
  if (id === 'schedule') return { kind: 'schedule', name: t('scheduler') };
1086
+ if (id === 'system') return { kind: 'system', name: t('title') };
1066
1087
  const b = botById(id);
1067
1088
  return b ? { kind: 'bot', bot: b, name: b.name || `@${b.handle}` } : { kind: 'unknown', name: str(id) || '?' };
1068
1089
  }
@@ -1074,15 +1095,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1074
1095
 
1075
1096
  /** A thread of one bot: the user's prompts right, the bot's replies left, DMs as cards. */
1076
1097
  function MessageList({ t, items, botId, empty }) {
1077
- const end = useRef(null);
1078
1098
  const count = items.length;
1079
- useEffect(() => {
1080
- try {
1081
- end.current?.scrollIntoView?.({ block: 'end' });
1082
- } catch {
1083
- // No layout.
1084
- }
1085
- }, [count]);
1086
1099
  if (count === 0) return empty;
1087
1100
  const rows = [];
1088
1101
  let lastDay = '';
@@ -1116,10 +1129,20 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1116
1129
  const grouped = prev && prev.from === m.from && prev.to === m.to && prev.kind === m.kind && prev.via === m.via && at - toMs(prev.at) < 5 * 60_000;
1117
1130
  rows.push(h(MessageRow, { key: m.id ?? i, t, m, botId, grouped }));
1118
1131
  });
1119
- return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4, padding: '8px 0', maxWidth: 880, margin: '0 auto' } }, rows, h('div', { ref: end }));
1132
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4, padding: '8px 0', maxWidth: 880, margin: '0 auto' } }, rows);
1120
1133
  }
1121
1134
 
1122
1135
  function MessageRow({ t, m, botId, grouped }) {
1136
+ if (m.kind === 'topic') {
1137
+ const at = toMs(m.at);
1138
+ return h(
1139
+ 'div',
1140
+ { 'data-dsh-bots-msg': 'topic', style: { display: 'flex', alignItems: 'center', gap: 10, margin: '14px 0 8px', color: C.label, fontSize: TINY, fontWeight: 600 } },
1141
+ h('span', { style: { flex: 1, height: 1, background: tint(C.label, 35) } }),
1142
+ h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 5 } }, Icon.plus(11), t('topicDivider', { reason: t(`topicReason_${m.text}`) }), Number.isFinite(at) ? h('span', { style: { color: C.faint, fontWeight: 500 } }, fmtClock(at)) : null),
1143
+ h('span', { style: { flex: 1, height: 1, background: tint(C.label, 35) } }),
1144
+ );
1145
+ }
1123
1146
  const from = party(t, m.from);
1124
1147
  const to = party(t, m.to);
1125
1148
  const at = toMs(m.at);
@@ -1236,10 +1259,20 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1236
1259
  }
1237
1260
 
1238
1261
  /** Markdown through the product's own renderer (the same as the main chat), else a small built-in one. */
1262
+ /**
1263
+ * Amounts stay amounts: the Harness renderer reads `$…$` as inline math, so "$9 monthly / $90 annual"
1264
+ * would turn into a formula. A `$` right before a digit is escaped, outside code.
1265
+ */
1266
+ function moneySafe(text) {
1267
+ return str(text)
1268
+ .split(/(```[\s\S]*?(?:```|$)|`[^`\n]*`)/g)
1269
+ .map((part, i) => (i % 2 ? part : part.replace(/(^|[^\\])\$(?=\d)/g, '$1\\$')))
1270
+ .join('');
1271
+ }
1239
1272
  function RichText({ t, text }) {
1240
1273
  const Md = primitives && primitives.MarkdownText;
1241
1274
  if (Md && (typeof Md === 'function' || typeof Md === 'object')) {
1242
- return h('div', { className: 'dshb-rich', 'data-dsh-bots-md': 'harness' }, h(Md, { text, labels: mdLabels(t), variant: 'compact' }));
1275
+ return h('div', { className: 'dshb-rich', 'data-dsh-bots-md': 'harness' }, h(Md, { text: moneySafe(text), labels: mdLabels(t), variant: 'compact' }));
1243
1276
  }
1244
1277
  return h('div', { className: 'dshb-rich dshb-mdf', 'data-dsh-bots-md': 'builtin' }, miniMarkdown(text));
1245
1278
  }
@@ -1741,25 +1774,76 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1741
1774
  );
1742
1775
  }
1743
1776
 
1777
+ /**
1778
+ * Keep a scrolling thread at its bottom while the reader is there: when a message arrives, and when
1779
+ * something already shown grows later (a link card or picture loading, the "working" line appearing).
1780
+ * Scrolled up to read, the reader is left alone; `stick()` brings them back (after they send).
1781
+ */
1782
+ function useStickToBottom(lastKey) {
1783
+ const box = useRef(null);
1784
+ const content = useRef(null);
1785
+ const pinned = useRef(true);
1786
+ const toBottom = () => {
1787
+ const el = box.current;
1788
+ if (el) el.scrollTop = el.scrollHeight;
1789
+ };
1790
+ useEffect(() => {
1791
+ if (pinned.current) toBottom();
1792
+ }, [lastKey]);
1793
+ useEffect(() => {
1794
+ if (typeof ResizeObserver !== 'function' || !content.current) return undefined;
1795
+ const ro = new ResizeObserver(() => {
1796
+ if (pinned.current) toBottom();
1797
+ });
1798
+ ro.observe(content.current);
1799
+ return () => ro.disconnect();
1800
+ }, [content.current]);
1801
+ const onScroll = (e) => {
1802
+ const el = e.currentTarget;
1803
+ pinned.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
1804
+ };
1805
+ const stick = () => {
1806
+ pinned.current = true;
1807
+ toBottom();
1808
+ };
1809
+ return { box, content, onScroll, stick };
1810
+ }
1811
+
1744
1812
  function ChatTab({ t, bot, env, toast }) {
1745
1813
  const { items, failed, reload } = useMessages(bot.id);
1746
1814
  const [text, setText] = useState('');
1747
1815
  const [sending, setSending] = useState(false);
1816
+ const running = bot.status === 'running';
1817
+ const thread = useStickToBottom(`${items?.length ?? 0}:${items?.[items.length - 1]?.id ?? ''}:${running}`);
1818
+ const [topicBusy, setTopicBusy] = useState(false);
1819
+ const startTopic = () => {
1820
+ setTopicBusy(true);
1821
+ postJson('topic/new', { id: bot.id })
1822
+ .then((r) => {
1823
+ if (r?.ok) {
1824
+ toast(t('newTopicDone', { name: bot.name || `@${bot.handle}` }));
1825
+ void reload();
1826
+ void refreshState();
1827
+ } else toast(r?.reason || t('actionFailed'), 'error');
1828
+ })
1829
+ .finally(() => setTopicBusy(false));
1830
+ };
1748
1831
  const send = () => {
1749
1832
  const body = text.trim();
1750
1833
  if (!body || sending) return;
1751
1834
  setSending(true);
1835
+ thread.stick();
1752
1836
  postJson('send', { to: bot.id, text: body })
1753
1837
  .then((r) => {
1754
1838
  if (r?.ok) {
1755
1839
  setText('');
1840
+ thread.stick();
1756
1841
  void reload();
1757
1842
  void refreshState();
1758
1843
  } else toast(r?.reason || t('sendFailed'), 'error');
1759
1844
  })
1760
1845
  .finally(() => setSending(false));
1761
1846
  };
1762
- const running = bot.status === 'running';
1763
1847
  // A pasted link previews above the composer, as it will in the thread.
1764
1848
  const previewUrl = linksIn(useDebounced(text, 400))[0] ?? '';
1765
1849
  return h(
@@ -1767,7 +1851,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1767
1851
  { style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
1768
1852
  h(
1769
1853
  'div',
1770
- { className: 'dshb-scroll', 'data-dsh-bots-thread': bot.id, style: { flex: 1, padding: '6px 24px' } },
1854
+ { className: 'dshb-scroll', 'data-dsh-bots-thread': bot.id, ref: thread.box, onScroll: thread.onScroll, style: { flex: 1, padding: '6px 24px' } },
1855
+ h(
1856
+ 'div',
1857
+ { ref: thread.content },
1771
1858
  items === null
1772
1859
  ? h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('unavailable') : t('loading'))
1773
1860
  : h(MessageList, {
@@ -1785,6 +1872,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1785
1872
  h('span', { style: { display: 'inline-flex', gap: 3 } }, [0, 1, 2].map((i) => h('span', { key: i, style: { width: 4, height: 4, borderRadius: '50%', background: C.muted, animation: `dshb-blink 1.2s ${i * 0.2}s infinite` } }))),
1786
1873
  )
1787
1874
  : null,
1875
+ ),
1788
1876
  ),
1789
1877
  h(
1790
1878
  'div',
@@ -1817,6 +1905,9 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1817
1905
  { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 7, fontSize: TINY, color: C.faint } },
1818
1906
  h('span', null, t('composerHint')),
1819
1907
  h('span', { style: { flex: 1 } }),
1908
+ bot.topic ? h('span', { 'data-dsh-bots-topic': true, title: t('topicNow', { when: fmtAgo(t, bot.topic.startedAt), n: bot.topic.tasks, ctx: fmtNum(bot.topic.context) }) }, t('topicShort', { n: bot.topic.tasks, ctx: fmtNum(bot.topic.context) })) : null,
1909
+ h('button', { type: 'button', className: 'dshb-link', title: t('newTopicHint'), disabled: running || topicBusy || !bot.sessionId, onClick: startTopic, 'data-dsh-bots-new-topic': 'chat', style: { fontSize: TINY, display: 'inline-flex', alignItems: 'center', gap: 4, opacity: running || !bot.sessionId ? 0.5 : 1 } }, Icon.plus(11), t('newTopic')),
1910
+ env.canOpen() ? h('span', { style: { color: C.faint } }, '·') : null,
1820
1911
  env.canOpen() ? h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY, display: 'inline-flex', alignItems: 'center', gap: 4 }, onClick: () => env.openBot(bot) }, Icon.open(11), t('fullTranscript')) : null,
1821
1912
  ),
1822
1913
  ),
@@ -1878,7 +1969,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1878
1969
  m.via ? h(Badge, { color: CHANNEL_COLORS[m.via] ?? C.muted, 'data-dsh-bots-via': m.via }, m.from === 'user' && m.who ? `${channelName(m.via, t)} · ${str(m.who)}` : channelName(m.via, t)) : null,
1879
1970
  h('span', { style: { marginLeft: 'auto', color: C.faint, fontSize: TINY }, title: fmtDate(toMs(m.at)) }, fmtAgo(t, m.at)),
1880
1971
  ),
1881
- h(Clamp, { t, text: m.text, lines: 3, style: { fontSize: SMALL, color: C.muted } }),
1972
+ h(Clamp, { t, text: m.kind === 'topic' ? t('topicDivider', { reason: t(`topicReason_${m.text}`) }) : m.text, lines: 3, style: { fontSize: SMALL, color: C.muted } }),
1882
1973
  ),
1883
1974
  );
1884
1975
  }),
@@ -2038,7 +2129,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2038
2129
  bio: str(bot.bio),
2039
2130
  persona: str(bot.persona),
2040
2131
  avatar: avatarOf(bot.avatar),
2041
- model: bot.model && bot.model.model ? { provider: str(bot.model.provider), model: str(bot.model.model) } : null,
2132
+ model: bot.model && bot.model.model ? { provider: str(bot.model.provider), model: str(bot.model.model), ...(bot.model.reasoningEffort ? { reasoningEffort: str(bot.model.reasoningEffort) } : {}) } : null,
2042
2133
  deny: Array.isArray(bot.tools?.deny) ? bot.tools.deny.slice().sort() : [],
2043
2134
  });
2044
2135
  /** A clean avatar value: an image keeps its url, anything else is initials (emoji rows from v0.1 too). */
@@ -2147,7 +2238,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2147
2238
  };
2148
2239
  const lang = langOf(t);
2149
2240
  const abilities = (Array.isArray(catalog?.abilities) ? catalog.abilities : []).filter((ab) => Array.isArray(ab.available) && ab.available.length > 0);
2150
- const knownModel = !draft.model || models.some((m) => modelKey(m) === modelKey(draft.model));
2241
+ const chosen = draft.model ? models.find((m) => modelKey(m) === modelKey(draft.model)) : null;
2242
+ const knownModel = !draft.model || Boolean(chosen);
2243
+ const efforts = Array.isArray(chosen?.efforts) ? chosen.efforts : [];
2244
+ const [sources, setSources] = useState(false);
2151
2245
  return h(
2152
2246
  'div',
2153
2247
  { style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
@@ -2190,24 +2284,38 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2190
2284
  ),
2191
2285
  h(
2192
2286
  Section,
2193
- { title: t('model'), hint: t('modelHint') },
2287
+ { title: t('model'), hint: t('modelHint'), right: h(Btn, { size: 'sm', kind: 'ghost', icon: Icon.layers(12), onClick: () => setSources(true), 'data-dsh-bots-model-sources': true }, t('modelSources')) },
2194
2288
  h(
2195
- 'select',
2196
- {
2197
- className: 'dshb-input',
2198
- value: modelKey(draft.model),
2199
- style: { maxWidth: 420 },
2200
- onChange: (e) => {
2201
- const v = e.target.value;
2202
- if (!v) return set({ model: null });
2203
- const [provider, ...rest] = v.split('::');
2204
- set({ model: { provider, model: rest.join('::') } });
2289
+ 'div',
2290
+ { style: { display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center' } },
2291
+ h(
2292
+ 'select',
2293
+ {
2294
+ className: 'dshb-input',
2295
+ 'data-dsh-bots-model': true,
2296
+ value: modelKey(draft.model),
2297
+ style: { maxWidth: 420, flex: '1 1 260px' },
2298
+ onChange: (e) => {
2299
+ const v = e.target.value;
2300
+ if (!v) return set({ model: null });
2301
+ const [provider, ...rest] = v.split('::');
2302
+ set({ model: { provider, model: rest.join('::') } });
2303
+ },
2205
2304
  },
2206
- },
2207
- h('option', { value: '' }, t('modelDefault')),
2208
- !knownModel ? h('option', { value: modelKey(draft.model) }, `${draft.model.provider} · ${draft.model.model}`) : null,
2209
- models.map((m) => h('option', { key: modelKey(m), value: modelKey(m) }, m.label || `${m.provider} · ${m.model}`)),
2305
+ h('option', { value: '' }, catalog?.defaultModel ? t('modelDefaultIs', { model: catalog.defaultModel.model }) : t('modelDefault')),
2306
+ !knownModel ? h('option', { value: modelKey(draft.model) }, `${draft.model.provider} · ${draft.model.model}`) : null,
2307
+ modelGroups(models).map((g) => h('optgroup', { key: g.name, label: g.source ? `${g.name} · ${t(`msrc_${g.source}`)}` : g.name }, g.models.map((m) => h('option', { key: modelKey(m), value: modelKey(m) }, m.name || m.model)))),
2308
+ ),
2309
+ efforts.length
2310
+ ? h(
2311
+ 'select',
2312
+ { className: 'dshb-input', 'data-dsh-bots-effort': true, title: t('reasoning'), value: draft.model?.reasoningEffort ?? '', style: { width: 150 }, onChange: (e) => set({ model: { provider: draft.model.provider, model: draft.model.model, ...(e.target.value ? { reasoningEffort: e.target.value } : {}) } }) },
2313
+ h('option', { value: '' }, `${t('reasoning')} · ${t('effortDefault')}${chosen?.defaultEffort ? ` (${chosen.defaultEffort})` : ''}`),
2314
+ efforts.map((e) => h('option', { key: e.id, value: e.id }, `${t('reasoning')} · ${e.name}`)),
2315
+ )
2316
+ : null,
2210
2317
  ),
2318
+ chosen ? h('div', { 'data-dsh-bots-model-info': true, style: { fontSize: TINY, color: C.faint } }, [chosen.group || chosen.provider, chosen.source ? t(`msrc_${chosen.source}`) : '', chosen.context ? t('modelContext', { k: fmtNum(chosen.context) }) : ''].filter(Boolean).join(' · ')) : null,
2211
2319
  ),
2212
2320
  h(
2213
2321
  Section,
@@ -2275,6 +2383,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2275
2383
  ),
2276
2384
  ),
2277
2385
  h(SaveBar, { t, dirty, busy, valid, onSave: save, onReset: () => setDraft(JSON.parse(base.current)) }),
2386
+ sources ? h(ModelSourcesModal, { t, toast, onClose: () => setSources(false) }) : null,
2278
2387
  );
2279
2388
  }
2280
2389
  function SaveBar({ t, dirty, busy, valid, onSave, onReset }) {
@@ -3912,8 +4021,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
3912
4021
 
3913
4022
  // --- detail: header + tabs ------------------------------------------------------------
3914
4023
 
3915
- const TABS = ['chat', 'profile', 'skills', 'schedules', 'apps'];
3916
- function BotDetail({ t, bot, primaryId, env, toast, catalog, tab, setTab, onDeleted }) {
4024
+ const TABS = ['chat', 'profile', 'memory', 'skills', 'schedules', 'apps'];
4025
+ function BotDetail({ t, bot, primaryId, env, toast, catalog, tab, setTab, onDeleted, onSettings }) {
3917
4026
  const [menu, setMenu] = useState(false);
3918
4027
  const [confirm, setConfirm] = useState(false);
3919
4028
  const [opening, setOpening] = useState(false);
@@ -3938,12 +4047,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
3938
4047
  void refreshState();
3939
4048
  } else toast(r?.reason || t('actionFailed'), 'error');
3940
4049
  });
3941
- const counts = { skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length };
4050
+ const counts = { skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length, memory: Number(bot.memoryNotes) || 0 };
3942
4051
  let body;
3943
4052
  if (tab === 'profile') body = h(ProfileTab, { key: bot.id, t, bot, toast, catalog });
3944
4053
  else if (tab === 'skills') body = h(SkillsTab, { key: bot.id, t, bot, toast, catalog, setTab, env });
3945
4054
  else if (tab === 'schedules') body = h(SchedulesTab, { key: bot.id, t, bot, toast, catalog });
3946
4055
  else if (tab === 'apps') body = h(AppsTab, { key: bot.id, t, bot, toast, catalog });
4056
+ else if (tab === 'memory') body = h(MemoryTab, { key: bot.id, t, bot, toast, onSettings });
3947
4057
  else body = h(ChatTab, { key: bot.id, t, bot, env, toast });
3948
4058
  return h(
3949
4059
  'div',
@@ -3969,7 +4079,9 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
3969
4079
  { style: { display: 'flex', alignItems: 'center', gap: 8, fontSize: SMALL, color: C.muted, minWidth: 0 } },
3970
4080
  h('span', { className: 'dshb-mono', style: { fontSize: 12 } }, `@${bot.handle}`),
3971
4081
  h('span', { style: { color: C.faint } }, '·'),
3972
- h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 5 } }, h(StatusDot, { status, size: 7 }), t(`status_${status}`)),
4082
+ h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 5, whiteSpace: 'nowrap', flex: 'none' } }, h(StatusDot, { status, size: 7 }), t(`status_${status}`)),
4083
+ Number(bot.usageToday) > 0 ? h('span', { style: { color: C.faint } }, '·') : null,
4084
+ Number(bot.usageToday) > 0 ? h('span', { 'data-dsh-bots-today': bot.id, style: { whiteSpace: 'nowrap', flex: 'none' } }, t('usageHint', { tokens: fmtNum(bot.usageToday) })) : null,
3973
4085
  bot.bio ? h('span', { style: { color: C.faint } }, '·') : null,
3974
4086
  bot.bio ? h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, bot.bio) : null,
3975
4087
  ),
@@ -4019,6 +4131,826 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4019
4131
  );
4020
4132
  }
4021
4133
 
4134
+ // --- usage, memory, topics, settings, model sources ---------------------------------------
4135
+
4136
+ const fmtNum = (n) => {
4137
+ const x = Number(n) || 0;
4138
+ if (x >= 1e9) return `${(x / 1e9).toFixed(x >= 1e10 ? 0 : 1)}B`;
4139
+ if (x >= 1e6) return `${(x / 1e6).toFixed(x >= 1e7 ? 0 : 1)}M`;
4140
+ if (x >= 1e3) return `${(x / 1e3).toFixed(x >= 1e4 ? 0 : 1)}K`;
4141
+ return String(Math.round(x));
4142
+ };
4143
+ const CURRENCY = { USD: '$', CNY: '¥' };
4144
+ const fmtMoney = (amount, cur) => {
4145
+ const v = Number(amount) || 0;
4146
+ return `${CURRENCY[cur] ?? `${cur} `}${v >= 100 ? v.toFixed(0) : v >= 1 ? v.toFixed(2) : v >= 0.01 ? v.toFixed(3) : v > 0 ? v.toFixed(4) : '0'}`;
4147
+ };
4148
+ const fmtCost = (cost) => {
4149
+ const parts = Object.entries(cost ?? {})
4150
+ .filter(([, v]) => Number(v) > 0)
4151
+ .map(([c, v]) => fmtMoney(v, c));
4152
+ return parts.length ? parts.join(' + ') : '—';
4153
+ };
4154
+ const tzNow = () => {
4155
+ try {
4156
+ return -new Date().getTimezoneOffset();
4157
+ } catch {
4158
+ return 0;
4159
+ }
4160
+ };
4161
+ const API_LABELS = {
4162
+ 'openai-completions': 'OpenAI-compatible · Chat Completions',
4163
+ 'openai-responses': 'OpenAI · Responses',
4164
+ 'anthropic-messages': 'Anthropic-compatible · Messages',
4165
+ 'google-generative-ai': 'Google Gemini',
4166
+ };
4167
+ /** A GET loaded now and every `ms` while shown (`ms` 0 = once). */
4168
+ function useJson(path, ms = 0) {
4169
+ const [data, setData] = useState(null);
4170
+ const [failed, setFailed] = useState(false);
4171
+ const alive = useRef(true);
4172
+ useEffect(() => {
4173
+ alive.current = true;
4174
+ return () => {
4175
+ alive.current = false;
4176
+ };
4177
+ }, []);
4178
+ const load = () =>
4179
+ Promise.resolve()
4180
+ .then(() => getJson(path))
4181
+ .then((r) => {
4182
+ if (!alive.current) return;
4183
+ if (r && r.ok !== false) {
4184
+ setData(r);
4185
+ setFailed(false);
4186
+ } else setFailed(true);
4187
+ })
4188
+ .catch(() => {
4189
+ if (alive.current) setFailed(true);
4190
+ });
4191
+ usePoll(load, ms || 3_600_000, [path]);
4192
+ return { data, failed, reload: load };
4193
+ }
4194
+ /** A bot's colour for charts: its avatar colour. */
4195
+ const botColor = (id) => botById(id)?.avatar?.color || C.faint;
4196
+ const botName = (t, id) => {
4197
+ const b = botById(id);
4198
+ return b ? b.name || `@${b.handle}` : id === 'team' ? t('teamMemoryTitle') : t('removedBot');
4199
+ };
4200
+ const Seg = ({ items, value, onChange, attr }) =>
4201
+ h(
4202
+ 'div',
4203
+ { role: 'tablist', style: { display: 'inline-flex', padding: 2, borderRadius: 9, background: C.layer2, gap: 2 } },
4204
+ items.map((it) =>
4205
+ h(
4206
+ 'button',
4207
+ {
4208
+ key: it.id,
4209
+ type: 'button',
4210
+ role: 'tab',
4211
+ 'aria-selected': value === it.id,
4212
+ [attr]: it.id,
4213
+ onClick: () => onChange(it.id),
4214
+ style: { height: 26, padding: '0 10px', border: 'none', borderRadius: 7, font: 'inherit', fontSize: SMALL, fontWeight: 600, cursor: 'pointer', color: value === it.id ? C.primary : C.muted, background: value === it.id ? C.layer1 : 'transparent', boxShadow: value === it.id ? '0 1px 2px rgba(0,0,0,.12)' : 'none' },
4215
+ },
4216
+ it.label,
4217
+ ),
4218
+ ),
4219
+ );
4220
+ function Tile({ label, value, sub, delta, attr }) {
4221
+ return h(
4222
+ 'div',
4223
+ { className: 'dshb-card', 'data-dsh-bots-tile': attr, style: { display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0 } },
4224
+ h('span', { style: { fontSize: TINY, fontWeight: 600, color: C.muted, textTransform: 'uppercase', letterSpacing: '.03em' } }, label),
4225
+ h('span', { style: { fontSize: 22, fontWeight: 700, color: C.primary, fontVariantNumeric: 'tabular-nums', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, value),
4226
+ sub ? h('span', { style: { fontSize: TINY, color: C.faint } }, sub) : null,
4227
+ delta ? h('span', { style: { fontSize: TINY, color: C.muted } }, delta) : null,
4228
+ );
4229
+ }
4230
+ /** "+12%" / "−8%" of `now` against `before`, or ''. */
4231
+ const pctDelta = (now, before) => {
4232
+ if (!(before > 0)) return '';
4233
+ const p = Math.round(((now - before) / before) * 100);
4234
+ return `${p > 0 ? '+' : p < 0 ? '−' : '±'}${Math.abs(p)}%`;
4235
+ };
4236
+ const bucketLabel = (ms, bucket) => {
4237
+ try {
4238
+ const d = new Date(ms);
4239
+ return bucket < 86_400_000 ? `${pad(d.getHours())}:00` : `${d.getMonth() + 1}/${d.getDate()}`;
4240
+ } catch {
4241
+ return '';
4242
+ }
4243
+ };
4244
+ /** A top-rounded bar: flat on the baseline, 3px round at the data end. */
4245
+ const barPath = (x, y, w, hgt, r) => {
4246
+ const rr = Math.max(0, Math.min(r, w / 2, hgt));
4247
+ return `M${x},${y + hgt}V${y + rr}Q${x},${y} ${x + rr},${y}H${x + w - rr}Q${x + w},${y} ${x + w},${y + rr}V${y + hgt}Z`;
4248
+ };
4249
+
4250
+ /** Tokens per bucket, stacked by bot (the top seven by tokens, the rest as "other"). */
4251
+ function UsageChart({ t, data }) {
4252
+ const [hover, setHover] = useState(-1);
4253
+ const series = Array.isArray(data?.series) ? data.series : [];
4254
+ const ranked = (data?.bots ?? []).map((b) => b.bot);
4255
+ const shown = ranked.slice(0, 7);
4256
+ const keys = ranked.length > 7 ? [...shown, '__other'] : shown;
4257
+ const stackOf = (p) => keys.map((k) => (k === '__other' ? Object.entries(p.byBot ?? {}).filter(([id]) => !shown.includes(id)).reduce((s, [, v]) => s + v, 0) : (p.byBot?.[k] ?? 0)));
4258
+ const max = Math.max(1, ...series.map((p) => p.tokens));
4259
+ const W = 720;
4260
+ const H = 190;
4261
+ const L = 44;
4262
+ const B = 22;
4263
+ const T = 8;
4264
+ const innerW = W - L - 6;
4265
+ const innerH = H - B - T;
4266
+ const n = Math.max(1, series.length);
4267
+ const slot = innerW / n;
4268
+ const bw = Math.max(2, Math.min(28, slot * 0.66));
4269
+ const y = (v) => T + innerH - (v / max) * innerH;
4270
+ const ticks = [0, 0.5, 1].map((f) => max * f);
4271
+ const every = Math.max(1, Math.ceil(n / 8));
4272
+ const colorOf = (k) => (k === '__other' ? C.faint : botColor(k));
4273
+ const nameOf = (k) => (k === '__other' ? t('other') : botName(t, k));
4274
+ const hp = hover >= 0 ? series[hover] : null;
4275
+ return h(
4276
+ 'div',
4277
+ { 'data-dsh-bots-usage-chart': true, style: { position: 'relative' } },
4278
+ keys.length > 1
4279
+ ? h(
4280
+ 'div',
4281
+ { style: { display: 'flex', flexWrap: 'wrap', gap: '4px 14px', marginBottom: 8, fontSize: TINY, color: C.muted } },
4282
+ keys.map((k) => h('span', { key: k, style: { display: 'inline-flex', alignItems: 'center', gap: 5 } }, h('span', { style: { width: 9, height: 9, borderRadius: 3, background: colorOf(k) } }), nameOf(k))),
4283
+ )
4284
+ : null,
4285
+ h(
4286
+ 'svg',
4287
+ { viewBox: `0 0 ${W} ${H}`, width: '100%', role: 'img', 'aria-label': t('usageChart'), style: { display: 'block', overflow: 'visible' }, onMouseLeave: () => setHover(-1) },
4288
+ ticks.map((v, i) =>
4289
+ h(
4290
+ 'g',
4291
+ { key: `t${i}` },
4292
+ h('line', { x1: L, x2: W, y1: y(v), y2: y(v), stroke: 'currentColor', strokeOpacity: i === 0 ? 0.25 : 0.1, strokeWidth: 1, style: { color: C.muted } }),
4293
+ h('text', { x: L - 6, y: y(v) + 3.5, textAnchor: 'end', fontSize: 10.5, fill: 'currentColor', style: { color: C.faint } }, fmtNum(v)),
4294
+ ),
4295
+ ),
4296
+ series.map((p, i) => {
4297
+ const cx = L + slot * i + slot / 2;
4298
+ const stack = stackOf(p);
4299
+ let acc = 0;
4300
+ const top = stack.reduce((last, v, j) => (v > 0 ? j : last), -1);
4301
+ const segs = stack.map((v, j) => {
4302
+ if (!(v > 0)) return null;
4303
+ const y0 = y(acc);
4304
+ acc += v;
4305
+ const y1 = y(acc);
4306
+ // A 2px surface gap between stacked segments.
4307
+ const hgt = Math.max(1, y0 - y1 - (j === 0 ? 0 : 2));
4308
+ return h('path', { key: j, d: j === top ? barPath(cx - bw / 2, y1, bw, hgt, 3) : `M${cx - bw / 2},${y1}h${bw}v${hgt}h${-bw}Z`, fill: colorOf(keys[j]), opacity: hover === -1 || hover === i ? 1 : 0.45 });
4309
+ });
4310
+ return h(
4311
+ 'g',
4312
+ { key: p.t },
4313
+ segs,
4314
+ i % every === 0 || i === n - 1 ? h('text', { x: cx, y: H - 6, textAnchor: 'middle', fontSize: 10.5, fill: 'currentColor', style: { color: C.faint } }, bucketLabel(p.t, data.range?.bucket ?? 86_400_000)) : null,
4315
+ // The hit target is the whole column, not just the bar.
4316
+ h('rect', { x: L + slot * i, y: T, width: slot, height: innerH, fill: 'transparent', onMouseEnter: () => setHover(i), 'data-dsh-bots-usage-col': i }),
4317
+ );
4318
+ }),
4319
+ ),
4320
+ hp
4321
+ ? h(
4322
+ 'div',
4323
+ {
4324
+ 'data-dsh-bots-usage-tip': true,
4325
+ style: { position: 'absolute', top: 0, left: `${Math.min(78, Math.max(2, ((L + slot * hover + slot / 2) / W) * 100))}%`, transform: 'translateX(-50%)', pointerEvents: 'none', padding: '8px 10px', borderRadius: 10, background: C.layer1, border: `1px solid ${C.border}`, boxShadow: '0 6px 20px rgba(0,0,0,.18)', fontSize: TINY, minWidth: 140, zIndex: 2 },
4326
+ },
4327
+ h('div', { style: { fontWeight: 700, color: C.primary, marginBottom: 4 } }, `${bucketLabel(hp.t, data.range?.bucket ?? 86_400_000)} · ${fmtNum(hp.tokens)}`),
4328
+ keys
4329
+ .map((k, j) => [k, stackOf(hp)[j]])
4330
+ .filter(([, v]) => v > 0)
4331
+ .map(([k, v]) => h('div', { key: k, style: { display: 'flex', alignItems: 'center', gap: 6, color: C.muted } }, h('span', { style: { width: 8, height: 8, borderRadius: 2, background: colorOf(k) } }), h('span', { style: { flex: 1 } }, nameOf(k)), h('span', { style: { color: C.primary, fontVariantNumeric: 'tabular-nums' } }, fmtNum(v)))),
4332
+ fmtCost(hp.cost) !== '—' ? h('div', { style: { marginTop: 4, color: C.faint } }, fmtCost(hp.cost)) : null,
4333
+ )
4334
+ : null,
4335
+ );
4336
+ }
4337
+ const th = (label, right) => h('th', { style: { textAlign: right ? 'right' : 'left', fontWeight: 600, fontSize: TINY, color: C.muted, padding: '6px 8px', borderBottom: `1px solid ${C.border1}` } }, label);
4338
+ const td = (content, right, extra = {}) => h('td', { style: { textAlign: right ? 'right' : 'left', padding: '7px 8px', borderBottom: `1px solid ${C.border1}`, fontVariantNumeric: 'tabular-nums', verticalAlign: 'middle', ...extra } }, content);
4339
+ const Table = ({ head, rows, attr }) => h('table', { [attr]: true, style: { width: '100%', borderCollapse: 'collapse', fontSize: SMALL } }, h('thead', null, h('tr', null, head)), h('tbody', null, rows));
4340
+ function BotCell({ t, id }) {
4341
+ const b = botById(id);
4342
+ return h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 7, minWidth: 0 } }, b ? h(Avatar, { avatar: b.avatar, name: b.name || b.handle, size: 20 }) : h('span', { style: { width: 20, height: 20, borderRadius: '50%', background: C.layer2 } }), h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, botName(t, id)));
4343
+ }
4344
+ function triggerText(t, task) {
4345
+ if (task.trigger === 'schedule') return t('trigger_schedule');
4346
+ if (task.trigger === 'chat') return t('trigger_chat', { app: channelName(task.via, t) });
4347
+ if (task.trigger === 'dm') return task.from === 'user' ? t('trigger_user') : t('trigger_dm', { handle: botById(task.from)?.handle ?? '?' });
4348
+ return t('trigger_user');
4349
+ }
4350
+
4351
+ function UsageView({ t, bots }) {
4352
+ const [range, setRange] = useState('7d');
4353
+ const [bot, setBot] = useState('');
4354
+ const [prices, setPrices] = useState(false);
4355
+ const { data, failed, reload } = useJson(`usage?range=${range}&tz=${tzNow()}${bot ? `&bot=${encodeURIComponent(bot)}` : ''}`, 30_000);
4356
+ const tot = data?.totals;
4357
+ const prev = data?.prev;
4358
+ const empty = tot && tot.calls === 0;
4359
+ const section = (title, body, right) => h('section', { className: 'dshb-card', style: { display: 'flex', flexDirection: 'column', gap: 10, minWidth: 0 } }, h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } }, h('span', { style: { fontWeight: 700, fontSize: SMALL } }, title), h('span', { style: { flex: 1 } }), right ?? null), body);
4360
+ return h(
4361
+ 'div',
4362
+ { 'data-dsh-bots-usage': true, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
4363
+ h(
4364
+ 'header',
4365
+ { style: { padding: '18px 24px 14px', borderBottom: `1px solid ${C.border1}`, display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' } },
4366
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2, flex: 1, minWidth: 200 } }, h('span', { style: { fontWeight: 700, fontSize: 19 } }, t('usage')), h('span', { style: { fontSize: SMALL, color: C.muted } }, t('usageSub'))),
4367
+ h(Seg, { attr: 'data-dsh-bots-range', value: range, onChange: setRange, items: ['today', '7d', '30d', '90d', 'all'].map((id) => ({ id, label: t(`range_${id}`) })) }),
4368
+ h('select', { className: 'dshb-input', 'data-dsh-bots-usage-bot': true, value: bot, onChange: (e) => setBot(e.target.value), style: { width: 160, height: 30, fontSize: SMALL } }, h('option', { value: '' }, t('allBots')), bots.map((b) => h('option', { key: b.id, value: b.id }, b.name || `@${b.handle}`))),
4369
+ h(Btn, { size: 'sm', icon: Icon.edit(12), onClick: () => setPrices(true), 'data-dsh-bots-prices': true }, t('prices')),
4370
+ ),
4371
+ h(
4372
+ 'div',
4373
+ { className: 'dshb-scroll', style: { flex: 1, padding: '18px 24px 28px' } },
4374
+ !data
4375
+ ? h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('unavailable') : t('loading'))
4376
+ : h(
4377
+ 'div',
4378
+ { style: { maxWidth: 1080, display: 'flex', flexDirection: 'column', gap: 16 } },
4379
+ h(
4380
+ 'div',
4381
+ { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 12 } },
4382
+ h(Tile, { attr: 'tokens', label: t('tileTokens'), value: fmtNum(tot.tokens), sub: t('tileCacheRate', { pct: Math.round((tot.cacheRate ?? 0) * 100) }), delta: pctDelta(tot.tokens, prev?.tokens) ? t('vsPrev', { delta: pctDelta(tot.tokens, prev.tokens) }) : '' }),
4383
+ h(Tile, { attr: 'cost', label: t('tileCost'), value: fmtCost(tot.cost), sub: tot.unpriced > 0 ? t('tileUnpriced', { tokens: fmtNum(tot.unpriced) }) : '' }),
4384
+ h(Tile, { attr: 'tasks', label: t('tileTasks'), value: String(tot.tasks ?? 0), delta: pctDelta(tot.tasks, prev?.tasks) ? t('vsPrev', { delta: pctDelta(tot.tasks, prev.tasks) }) : '' }),
4385
+ h(Tile, { attr: 'calls', label: t('tileCalls'), value: String(tot.calls ?? 0), sub: t('tileInOut', { input: fmtNum(tot.input + tot.cacheRead + tot.cacheWrite), output: fmtNum(tot.output) }) }),
4386
+ ),
4387
+ empty ? h('div', { className: 'dshb-card', style: { color: C.faint, fontSize: SMALL, textAlign: 'center', padding: 24 } }, t('noUsage')) : section(t('usageChart'), h(UsageChart, { t, data })),
4388
+ empty
4389
+ ? null
4390
+ : h(
4391
+ 'div',
4392
+ { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(340px, 1fr))', gap: 16 } },
4393
+ section(
4394
+ t('byBot'),
4395
+ h(Table, {
4396
+ attr: 'data-dsh-bots-usage-bots',
4397
+ head: [th(t('colBot')), th(t('colTasks'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4398
+ rows: data.bots.map((r) => h('tr', { key: r.bot, onClick: () => setBot(bot === r.bot ? '' : r.bot), style: { cursor: 'pointer' } }, td(h(BotCell, { t, id: r.bot })), td(String(r.tasks), true), td(fmtNum(r.tokens), true), td(fmtCost(r.cost), true))),
4399
+ }),
4400
+ ),
4401
+ section(
4402
+ t('byModel'),
4403
+ h(Table, {
4404
+ attr: 'data-dsh-bots-usage-models',
4405
+ head: [th(t('colModel')), th(t('colCalls'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4406
+ rows: data.models.map((r) =>
4407
+ h(
4408
+ 'tr',
4409
+ { key: `${r.provider}/${r.model}` },
4410
+ td(h('span', { style: { display: 'flex', flexDirection: 'column', minWidth: 0 } }, h('span', { className: 'dshb-mono', style: { fontSize: 12, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: 220 } }, r.model), h('span', { style: { fontSize: TINY, color: C.faint } }, r.provider))),
4411
+ td(String(r.calls), true),
4412
+ td(fmtNum(r.tokens), true),
4413
+ td(r.priced ? fmtCost(r.cost) : h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY }, onClick: () => setPrices(r.model) }, t('setPrice')), true),
4414
+ ),
4415
+ ),
4416
+ }),
4417
+ ),
4418
+ section(
4419
+ t('byKind'),
4420
+ h(Table, {
4421
+ attr: 'data-dsh-bots-usage-kinds',
4422
+ head: [th(''), th(t('colCalls'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4423
+ rows: data.kinds.map((r) => h('tr', { key: r.kind }, td(t(`work_${r.kind}`)), td(String(r.calls), true), td(fmtNum(r.tokens), true), td(fmtCost(r.cost), true))),
4424
+ }),
4425
+ ),
4426
+ data.schedules.length
4427
+ ? section(
4428
+ t('bySchedule'),
4429
+ h(Table, {
4430
+ attr: 'data-dsh-bots-usage-schedules',
4431
+ head: [th(t('colTask')), th(t('colRuns'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4432
+ rows: data.schedules.map((r) => h('tr', { key: r.id }, td(h('span', { style: { display: 'flex', flexDirection: 'column' } }, h('span', null, r.title), h('span', { style: { fontSize: TINY, color: C.faint } }, botName(t, r.bot)))), td(String(r.runs), true), td(fmtNum(r.tokens), true), td(fmtCost(r.cost), true))),
4433
+ }),
4434
+ )
4435
+ : null,
4436
+ ),
4437
+ empty || data.tasks.length === 0
4438
+ ? null
4439
+ : section(
4440
+ t('recentTasks'),
4441
+ h(Table, {
4442
+ attr: 'data-dsh-bots-usage-tasks',
4443
+ head: [th(t('colTask')), th(t('colBot')), th(t('colWhen')), th(t('colTokens'), true), th(t('colCost'), true)],
4444
+ rows: data.tasks.map((r) =>
4445
+ h(
4446
+ 'tr',
4447
+ { key: r.id, 'data-dsh-bots-usage-task': r.id },
4448
+ td(
4449
+ h(
4450
+ 'span',
4451
+ { style: { display: 'flex', flexDirection: 'column', minWidth: 0, maxWidth: 380 } },
4452
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: r.title }, r.title),
4453
+ h(
4454
+ 'span',
4455
+ { style: { fontSize: TINY, color: C.faint, display: 'inline-flex', gap: 6, alignItems: 'center' } },
4456
+ triggerText(t, r),
4457
+ r.status === 'running' ? h(Badge, { color: C.ok }, t('taskRunning')) : r.status === 'error' || r.status === 'stopped' ? h(Badge, { color: C.error }, t(`taskState_${r.status}`)) : null,
4458
+ ),
4459
+ ),
4460
+ ),
4461
+ td(h(BotCell, { t, id: r.bot })),
4462
+ td(h('span', { style: { color: C.muted, fontSize: TINY, whiteSpace: 'nowrap' } }, fmtDate(r.end ?? r.start))),
4463
+ td(fmtNum(r.tokens), true),
4464
+ td(fmtCost(r.cost), true),
4465
+ ),
4466
+ ),
4467
+ }),
4468
+ ),
4469
+ ),
4470
+ ),
4471
+ prices ? h(PricesModal, { t, focus: typeof prices === 'string' ? prices : '', onClose: () => (setPrices(false), void reload()) }) : null,
4472
+ );
4473
+ }
4474
+
4475
+ function PricesModal({ t, focus, onClose }) {
4476
+ const { data, reload } = useJson('prices');
4477
+ const [edit, setEdit] = useState(focus ? { model: focus, input: '', cacheRead: '', output: '', currency: 'USD' } : null);
4478
+ const [busy, setBusy] = useState(false);
4479
+ const [note, setNote] = useState('');
4480
+ const save = (price) => {
4481
+ setBusy(true);
4482
+ postJson('prices', { model: edit?.model ?? price?.model, price: price === null ? null : { input: Number(edit.input), output: Number(edit.output), ...(edit.cacheRead !== '' ? { cacheRead: Number(edit.cacheRead) } : {}), currency: edit.currency } })
4483
+ .then((r) => {
4484
+ if (r?.ok) {
4485
+ setEdit(null);
4486
+ setNote(t('priceSaved'));
4487
+ void reload();
4488
+ } else setNote(r?.reason || t('saveFailed'));
4489
+ })
4490
+ .finally(() => setBusy(false));
4491
+ };
4492
+ const valid = edit && edit.input !== '' && edit.output !== '' && Number(edit.input) >= 0 && Number(edit.output) >= 0;
4493
+ const list = data?.list;
4494
+ return h(
4495
+ Modal,
4496
+ { title: t('pricesTitle'), onClose, width: 640, closeLabel: t('close') },
4497
+ h('div', { style: { fontSize: SMALL, color: C.muted, lineHeight: 1.6 } }, t('pricesHint', { count: list?.count ?? 0, when: list?.fetchedAt ? fmtDate(list.fetchedAt) : '—' })),
4498
+ note ? h('div', { style: { fontSize: SMALL, color: C.ok } }, note) : null,
4499
+ !data
4500
+ ? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('loading'))
4501
+ : data.models.length === 0
4502
+ ? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('noUsage'))
4503
+ : h(Table, {
4504
+ attr: 'data-dsh-bots-price-table',
4505
+ head: [th(t('colModel')), th(t('priceInput'), true), th(t('priceOutput'), true), th('')],
4506
+ rows: data.models.map((m) =>
4507
+ h(
4508
+ 'tr',
4509
+ { key: m.model },
4510
+ td(h('span', { style: { display: 'flex', flexDirection: 'column' } }, h('span', { className: 'dshb-mono', style: { fontSize: 12 } }, m.model), h('span', { style: { fontSize: TINY, color: C.faint } }, m.price ? `${m.price.source === 'user' ? t('priceSource_user') : 'LiteLLM'}${m.price.approximate ? ' ≈' : ''}` : t('priceNone')))),
4511
+ td(m.price ? fmtMoney(m.price.input, m.price.currency) : '—', true),
4512
+ td(m.price ? fmtMoney(m.price.output, m.price.currency) : '—', true),
4513
+ td(
4514
+ h(
4515
+ 'span',
4516
+ { style: { display: 'inline-flex', gap: 8 } },
4517
+ h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY }, onClick: () => setEdit({ model: m.model, input: String(m.price?.input ?? ''), cacheRead: m.price?.cacheRead !== undefined ? String(m.price.cacheRead) : '', output: String(m.price?.output ?? ''), currency: m.price?.currency ?? 'USD' }) }, t('setPrice')),
4518
+ m.price?.source === 'user' ? h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY, color: C.muted }, onClick: () => (setEdit({ model: m.model }), save(null)) }, t('usePriceList')) : null,
4519
+ ),
4520
+ true,
4521
+ ),
4522
+ ),
4523
+ ),
4524
+ }),
4525
+ edit && edit.input !== undefined
4526
+ ? h(
4527
+ 'div',
4528
+ { className: 'dshb-card', 'data-dsh-bots-price-form': edit.model, style: { display: 'flex', flexDirection: 'column', gap: 10 } },
4529
+ h('span', { className: 'dshb-mono', style: { fontWeight: 600 } }, edit.model),
4530
+ h(
4531
+ 'div',
4532
+ { style: { display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 } },
4533
+ h(Field, { label: t('priceInput') }, h(Input, { type: 'number', min: 0, step: 'any', value: edit.input, onChange: (e) => setEdit({ ...edit, input: e.target.value }) })),
4534
+ h(Field, { label: t('priceCached') }, h(Input, { type: 'number', min: 0, step: 'any', value: edit.cacheRead, placeholder: edit.input, onChange: (e) => setEdit({ ...edit, cacheRead: e.target.value }) })),
4535
+ h(Field, { label: t('priceOutput') }, h(Input, { type: 'number', min: 0, step: 'any', value: edit.output, onChange: (e) => setEdit({ ...edit, output: e.target.value }) })),
4536
+ h(Field, { label: t('priceCurrency') }, h('select', { className: 'dshb-input', value: edit.currency, onChange: (e) => setEdit({ ...edit, currency: e.target.value }) }, h('option', { value: 'USD' }, 'USD $'), h('option', { value: 'CNY' }, 'CNY ¥'))),
4537
+ ),
4538
+ h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8 } }, h(Btn, { kind: 'ghost', onClick: () => setEdit(null) }, t('cancel')), h(Btn, { kind: 'primary', disabled: !valid || busy, onClick: () => save() }, t('save'))),
4539
+ )
4540
+ : null,
4541
+ h('div', null, h(Btn, { size: 'sm', kind: 'ghost', icon: Icon.refresh(12), onClick: () => postJson('prices/refresh', {}).then(() => reload()) }, t('refreshPriceList'))),
4542
+ );
4543
+ }
4544
+
4545
+ const NOTE_KINDS = ['fact', 'preference', 'person', 'project', 'procedure', 'lesson'];
4546
+ /** A list of memory notes the user can add to, edit, pin and delete. */
4547
+ function NotesEditor({ t, scope, notes, reload, toast }) {
4548
+ const [text, setText] = useState('');
4549
+ const [kind, setKind] = useState('fact');
4550
+ const [q, setQ] = useState('');
4551
+ const [editing, setEditing] = useState(null);
4552
+ const put = (note, ok) =>
4553
+ postJson('memory/put', { scope, note }).then((r) => {
4554
+ if (r?.ok) {
4555
+ if (ok) toast(ok);
4556
+ setEditing(null);
4557
+ void reload();
4558
+ void refreshState();
4559
+ } else toast(r?.reason || t('saveFailed'), 'error');
4560
+ return r;
4561
+ });
4562
+ const add = () => {
4563
+ if (!text.trim()) return;
4564
+ void put({ text: text.trim(), kind }, t('noteSaved')).then((r) => r?.ok && setText(''));
4565
+ };
4566
+ const remove = (id) =>
4567
+ postJson('memory/delete', { scope, id }).then((r) => {
4568
+ if (r?.ok) {
4569
+ void reload();
4570
+ void refreshState();
4571
+ } else toast(r?.reason || t('actionFailed'), 'error');
4572
+ });
4573
+ const needle = q.trim().toLowerCase();
4574
+ const list = (notes ?? [])
4575
+ .filter((n) => !needle || n.text.toLowerCase().includes(needle))
4576
+ .slice()
4577
+ .sort((a, b) => Number(Boolean(b.pinned)) - Number(Boolean(a.pinned)) || b.updated - a.updated);
4578
+ return h(
4579
+ 'div',
4580
+ { 'data-dsh-bots-notes': scope, style: { display: 'flex', flexDirection: 'column', gap: 10 } },
4581
+ h(
4582
+ 'div',
4583
+ { style: { display: 'flex', gap: 8 } },
4584
+ h(Input, { value: text, placeholder: t('addNote'), maxLength: 400, 'data-dsh-bots-note-input': true, onChange: (e) => setText(e.target.value), onKeyDown: (e) => e.key === 'Enter' && !e.isComposing && add(), style: { flex: 1 } }),
4585
+ h('select', { className: 'dshb-input', value: kind, onChange: (e) => setKind(e.target.value), style: { width: 110 } }, NOTE_KINDS.map((k) => h('option', { key: k, value: k }, t(`note_${k}`)))),
4586
+ h(Btn, { kind: 'primary', icon: Icon.plus(13), disabled: !text.trim(), onClick: add, 'data-dsh-bots-note-add': true }, t('add')),
4587
+ ),
4588
+ (notes ?? []).length > 8 ? h(Input, { value: q, placeholder: t('filterNotes'), onChange: (e) => setQ(e.target.value), style: { height: 30, fontSize: SMALL, maxWidth: 280 } }) : null,
4589
+ list.length === 0
4590
+ ? h('div', { style: { fontSize: SMALL, color: C.faint, padding: '6px 2px' } }, t('noNotes'))
4591
+ : h(
4592
+ 'div',
4593
+ { style: { display: 'flex', flexDirection: 'column', border: `1px solid ${C.border1}`, borderRadius: 12, overflow: 'hidden', background: C.layer1 } },
4594
+ list.map((n, i) =>
4595
+ h(
4596
+ 'div',
4597
+ { key: n.id, 'data-dsh-bots-note': n.id, style: { display: 'flex', alignItems: 'flex-start', gap: 10, padding: '9px 12px', borderTop: i ? `1px solid ${C.border1}` : 'none', background: n.pinned ? tint(C.label, 5) : 'transparent' } },
4598
+ h(Badge, { color: C.muted }, t(`note_${n.kind}`)),
4599
+ editing?.id === n.id
4600
+ ? h(
4601
+ 'div',
4602
+ { style: { flex: 1, display: 'flex', gap: 6 } },
4603
+ h(Input, { value: editing.text, maxLength: 400, onChange: (e) => setEditing({ ...editing, text: e.target.value }), onKeyDown: (e) => e.key === 'Enter' && !e.isComposing && put({ id: n.id, text: editing.text }), style: { flex: 1, height: 28 } }),
4604
+ h(Btn, { size: 'sm', kind: 'primary', onClick: () => put({ id: n.id, text: editing.text }) }, t('save')),
4605
+ h(Btn, { size: 'sm', kind: 'ghost', onClick: () => setEditing(null) }, t('cancel')),
4606
+ )
4607
+ : h(
4608
+ 'div',
4609
+ { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 2 } },
4610
+ h('span', { style: { fontSize: SMALL, color: C.primary, lineHeight: 1.5, wordBreak: 'break-word', cursor: 'text' }, onClick: () => setEditing({ id: n.id, text: n.text }) }, n.text),
4611
+ h('span', { style: { fontSize: TINY, color: C.faint } }, `${t(`src_${n.source}`)} · ${fmtAgo(t, n.updated)}`),
4612
+ ),
4613
+ h('button', { type: 'button', className: 'dshb-link', title: n.pinned ? t('unpin') : t('pin'), 'data-dsh-bots-note-pin': n.id, onClick: () => put({ id: n.id, pinned: !n.pinned }), style: { color: n.pinned ? '#d99a00' : C.faint, display: 'inline-flex', paddingTop: 2 } }, Icon.star(13)),
4614
+ h('button', { type: 'button', className: 'dshb-link', title: t('delete'), 'data-dsh-bots-note-delete': n.id, onClick: () => remove(n.id), style: { color: C.faint, display: 'inline-flex', paddingTop: 2 } }, Icon.trash(13)),
4615
+ ),
4616
+ ),
4617
+ ),
4618
+ );
4619
+ }
4620
+ function JournalList({ t, items, showBot }) {
4621
+ if (!items?.length) return h('div', { style: { fontSize: SMALL, color: C.faint } }, t('noJournal'));
4622
+ return h(
4623
+ 'div',
4624
+ { 'data-dsh-bots-journal': true, style: { display: 'flex', flexDirection: 'column', gap: 2 } },
4625
+ items.slice(0, 60).map((j) =>
4626
+ h(
4627
+ 'div',
4628
+ { key: j.id, style: { display: 'flex', gap: 10, alignItems: 'flex-start', padding: '6px 2px', fontSize: SMALL } },
4629
+ h('span', { style: { color: C.faint, fontSize: TINY, width: 132, flex: 'none', paddingTop: 2, whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' } }, fmtDate(j.at)),
4630
+ showBot ? h('span', { style: { flex: 'none', width: 130 } }, h(BotCell, { t, id: j.bot })) : null,
4631
+ h('span', { style: { flex: 1, color: C.primary, lineHeight: 1.5, wordBreak: 'break-word' } }, j.summary || j.title),
4632
+ ),
4633
+ ),
4634
+ );
4635
+ }
4636
+ const memModelText = (t, m) => (m ? `${m.provider} · ${m.model}` : t('botsOwnModel'));
4637
+
4638
+ function MemoryTab({ t, bot, toast, onSettings }) {
4639
+ const { data, reload } = useJson(`memory?bot=${encodeURIComponent(bot.id)}`, 15_000);
4640
+ const [busy, setBusy] = useState(false);
4641
+ const name = bot.name || `@${bot.handle}`;
4642
+ const topic = data?.topic;
4643
+ const startTopic = () => {
4644
+ setBusy(true);
4645
+ postJson('topic/new', { id: bot.id })
4646
+ .then((r) => {
4647
+ if (r?.ok) {
4648
+ toast(t('newTopicDone', { name }));
4649
+ void reload();
4650
+ void refreshState();
4651
+ } else toast(r?.reason || t('actionFailed'), 'error');
4652
+ })
4653
+ .finally(() => setBusy(false));
4654
+ };
4655
+ return h(
4656
+ 'div',
4657
+ { className: 'dshb-scroll', 'data-dsh-bots-memory': bot.id, style: { flex: 1, padding: '20px 24px 28px' } },
4658
+ h(
4659
+ 'div',
4660
+ { style: { maxWidth: 820, display: 'flex', flexDirection: 'column', gap: 26 } },
4661
+ h(
4662
+ Section,
4663
+ { title: t('memoryOf', { name }), hint: t('memoryHint', { name }), right: h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY, whiteSpace: 'nowrap' }, onClick: onSettings }, t('memoryModelIs', { model: memModelText(t, data?.settings?.model) })) },
4664
+ data ? h(NotesEditor, { t, scope: bot.id, notes: data.notes, reload, toast }) : h('div', { style: { fontSize: SMALL, color: C.faint } }, t('loading')),
4665
+ ),
4666
+ h(Section, { title: t('recentWork'), hint: t('recentWorkHint') }, data ? h(JournalList, { t, items: data.journal }) : null),
4667
+ h(
4668
+ Section,
4669
+ { title: t('topicsTitle'), hint: t('topicsHint'), right: h(Btn, { size: 'sm', icon: Icon.plus(12), disabled: busy || bot.status === 'running', onClick: startTopic, 'data-dsh-bots-new-topic': 'memory' }, t('newTopic')) },
4670
+ topic ? h('div', { className: 'dshb-card', style: { fontSize: SMALL } }, t('topicNow', { when: fmtAgo(t, topic.startedAt), n: topic.tasks, ctx: fmtNum(topic.lastPrompt) })) : null,
4671
+ ...(data?.topics ?? []).map((p) =>
4672
+ h(
4673
+ 'div',
4674
+ { key: p.sessionId, 'data-dsh-bots-past-topic': p.sessionId, style: { display: 'flex', alignItems: 'center', gap: 10, padding: '4px 2px', fontSize: SMALL } },
4675
+ h('span', { style: { color: C.muted, whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' } }, t('pastTopic', { from: fmtDate(p.startedAt), to: fmtDate(p.endedAt), n: p.tasks })),
4676
+ h(Badge, { color: C.muted }, t(`topicReason_${p.reason}`)),
4677
+ h('span', { style: { flex: 1, minWidth: 0, color: C.faint, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, (p.titles ?? []).join(' · ')),
4678
+ ),
4679
+ ),
4680
+ ),
4681
+ ),
4682
+ );
4683
+ }
4684
+
4685
+ function TeamMemoryView({ t, toast, onSettings }) {
4686
+ const { data, reload } = useJson('memory?bot=team', 20_000);
4687
+ const [busy, setBusy] = useState(false);
4688
+ const dream = () => {
4689
+ setBusy(true);
4690
+ postJson('memory/dream', {})
4691
+ .then((r) => {
4692
+ if (r?.ok) {
4693
+ const errs = r.result?.errors ?? [];
4694
+ toast(errs.length ? t('dreamPartly', { reason: errs[0].reason }) : t('dreamDone', { bots: (r.result?.bots ?? []).length, digest: r.result?.digest ? t('dreamDigest') : '' }), errs.length ? 'error' : 'ok');
4695
+ void reload();
4696
+ void refreshState();
4697
+ } else toast(r?.reason || t('actionFailed'), 'error');
4698
+ })
4699
+ .finally(() => setBusy(false));
4700
+ };
4701
+ const st = data?.settings;
4702
+ const last = data?.dream?.lastAt;
4703
+ return h(
4704
+ 'div',
4705
+ { 'data-dsh-bots-team-memory': true, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
4706
+ h(
4707
+ 'header',
4708
+ { style: { padding: '18px 24px 14px', borderBottom: `1px solid ${C.border1}`, display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' } },
4709
+ h(
4710
+ 'div',
4711
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, flex: 1, minWidth: 220 } },
4712
+ h('span', { style: { fontWeight: 700, fontSize: 19 } }, t('teamMemoryTitle')),
4713
+ h('span', { style: { fontSize: SMALL, color: C.muted } }, !st ? '' : !st.dream ? t('dreamOff') : last ? `${t('lastDream', { when: fmtAgo(t, last) })} · ${t('dreamDaily', { time: st.dreamTime })}` : t('neverDreamed', { time: st.dreamTime })),
4714
+ ),
4715
+ h(Btn, { kind: 'ghost', size: 'sm', icon: Icon.edit(12), onClick: onSettings }, t('settings')),
4716
+ h(Btn, { kind: 'primary', size: 'sm', icon: busy ? h('span', { className: 'dshb-spinner' }) : Icon.sparkle(13), disabled: busy, onClick: dream, 'data-dsh-bots-dream': true }, busy ? t('dreaming') : t('dreamNow')),
4717
+ ),
4718
+ h(
4719
+ 'div',
4720
+ { className: 'dshb-scroll', style: { flex: 1, padding: '20px 24px 28px' } },
4721
+ h(
4722
+ 'div',
4723
+ { style: { maxWidth: 860, display: 'flex', flexDirection: 'column', gap: 26 } },
4724
+ h(Section, { title: t('teamNotes'), hint: t('teamNotesHint') }, data ? h(NotesEditor, { t, scope: 'team', notes: data.notes, reload, toast }) : h('div', { style: { fontSize: SMALL, color: C.faint } }, t('loading'))),
4725
+ h(
4726
+ Section,
4727
+ { title: t('digests'), hint: t('digestsHint') },
4728
+ !data?.digests?.length
4729
+ ? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('noDigests'))
4730
+ : data.digests.slice(0, 14).map((d) => h('div', { key: d.date, className: 'dshb-card', 'data-dsh-bots-digest': d.date, style: { display: 'flex', flexDirection: 'column', gap: 6 } }, h('span', { style: { fontSize: TINY, fontWeight: 700, color: C.muted } }, d.date), h(Clamp, { t, text: d.text, lines: 10, style: { fontSize: SMALL } }))),
4731
+ ),
4732
+ h(Section, { title: t('teamJournal'), hint: t('recentWorkHint') }, data ? h(JournalList, { t, items: data.journal, showBot: true }) : null),
4733
+ ),
4734
+ ),
4735
+ );
4736
+ }
4737
+
4738
+ function SettingsModal({ t, catalog, onClose, toast }) {
4739
+ const [form, setForm] = useState(null);
4740
+ const [busy, setBusy] = useState(false);
4741
+ useEffect(() => {
4742
+ void getJson('settings').then((r) => r?.settings && setForm(r.settings));
4743
+ }, []);
4744
+ const set = (part, patch) => setForm((f) => ({ ...f, [part]: { ...f[part], ...patch } }));
4745
+ const models = Array.isArray(catalog?.models) ? catalog.models : [];
4746
+ const save = () => {
4747
+ setBusy(true);
4748
+ postJson('settings', { patch: { topics: { idleHours: Number(form.topics.idleHours) || 0, maxContextK: Number(form.topics.maxContextK) || 0 }, memory: form.memory } })
4749
+ .then((r) => {
4750
+ if (r?.ok) {
4751
+ toast(t('settingsSaved'));
4752
+ onClose();
4753
+ } else toast(r?.reason || t('saveFailed'), 'error');
4754
+ })
4755
+ .finally(() => setBusy(false));
4756
+ };
4757
+ const row = (label, hint, control) => h('div', { style: { display: 'flex', alignItems: 'center', gap: 14 } }, h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { style: { fontWeight: 600, fontSize: SMALL } }, label), hint ? h('div', { style: { fontSize: TINY, color: C.faint, lineHeight: 1.5, marginTop: 2 } }, hint) : null), control);
4758
+ return h(
4759
+ Modal,
4760
+ {
4761
+ title: t('settingsTitle'),
4762
+ onClose,
4763
+ width: 560,
4764
+ closeLabel: t('close'),
4765
+ footer: [h(Btn, { key: 'c', kind: 'ghost', onClick: onClose }, t('cancel')), h(Btn, { key: 's', kind: 'primary', disabled: !form || busy, onClick: save, 'data-dsh-bots-settings-save': true }, t('save'))],
4766
+ },
4767
+ !form
4768
+ ? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('loading'))
4769
+ : [
4770
+ h(
4771
+ Section,
4772
+ { key: 'topics', title: t('setTopics') },
4773
+ row(t('setIdle'), t('setIdleHint'), h(Input, { type: 'number', min: 0, max: 720, value: form.topics.idleHours, onChange: (e) => set('topics', { idleHours: e.target.value }), 'data-dsh-bots-setting': 'idleHours', style: { width: 90 } })),
4774
+ row(t('setContext'), t('setContextHint'), h(Input, { type: 'number', min: 0, max: 4096, value: form.topics.maxContextK, onChange: (e) => set('topics', { maxContextK: e.target.value }), 'data-dsh-bots-setting': 'maxContextK', style: { width: 90 } })),
4775
+ ),
4776
+ h(
4777
+ Section,
4778
+ { key: 'memory', title: t('setMemory') },
4779
+ row(t('setAuto'), t('setAutoHint'), h(Switch, { on: form.memory.auto, onChange: (v) => set('memory', { auto: v }), title: t('setAuto'), 'data-dsh-bots-setting': 'auto' })),
4780
+ row(
4781
+ t('setMemoryModel'),
4782
+ t('setMemoryModelHint'),
4783
+ h(
4784
+ 'select',
4785
+ {
4786
+ className: 'dshb-input',
4787
+ value: modelKey(form.memory.model),
4788
+ style: { width: 230 },
4789
+ 'data-dsh-bots-setting': 'memoryModel',
4790
+ onChange: (e) => {
4791
+ const v = e.target.value;
4792
+ if (!v) return set('memory', { model: null });
4793
+ const [provider, ...rest] = v.split('::');
4794
+ set('memory', { model: { provider, model: rest.join('::') } });
4795
+ },
4796
+ },
4797
+ h('option', { value: '' }, t('botsOwnModel')),
4798
+ form.memory.model && !models.some((m) => modelKey(m) === modelKey(form.memory.model)) ? h('option', { value: modelKey(form.memory.model) }, `${form.memory.model.provider} · ${form.memory.model.model}`) : null,
4799
+ modelGroups(models).map((g) => h('optgroup', { key: g.name, label: g.name }, g.models.map((m) => h('option', { key: modelKey(m), value: modelKey(m) }, m.name || m.model)))),
4800
+ ),
4801
+ ),
4802
+ row(t('setDream'), t('setDreamHint'), h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } }, h(Input, { type: 'time', value: form.memory.dreamTime, disabled: !form.memory.dream, onChange: (e) => set('memory', { dreamTime: e.target.value }), style: { width: 136 } }), h(Switch, { on: form.memory.dream, onChange: (v) => set('memory', { dream: v }), title: t('setDream'), 'data-dsh-bots-setting': 'dream' }))),
4803
+ ),
4804
+ ],
4805
+ );
4806
+ }
4807
+
4808
+ /** Catalog models by provider, in catalog order. */
4809
+ function modelGroups(models) {
4810
+ const groups = [];
4811
+ for (const m of models) {
4812
+ const name = m.group || m.provider;
4813
+ let g = groups.find((x) => x.name === name);
4814
+ if (!g) groups.push((g = { name, source: m.source ?? '', models: [] }));
4815
+ g.models.push(m);
4816
+ }
4817
+ return groups;
4818
+ }
4819
+
4820
+ function EndpointForm({ t, value, apis, onCancel, onSaved, toast }) {
4821
+ const editing = Boolean(value?.route);
4822
+ const [f, setF] = useState(() => ({ name: value?.name ?? '', api: value?.api ?? 'openai-completions', baseURL: value?.baseURL ?? '', key: '', models: (value?.models ?? []).map((m) => m.id).join('\n') }));
4823
+ const [found, setFound] = useState(null);
4824
+ const [busy, setBusy] = useState('');
4825
+ const set = (p) => setF((x) => ({ ...x, ...p }));
4826
+ const ids = [...new Set(f.models.split(/[\n,]+/).map((s) => s.trim()).filter(Boolean))];
4827
+ const fetchModels = () => {
4828
+ setBusy('fetch');
4829
+ postJson('models/custom/test', { api: f.api, baseURL: f.baseURL, key: f.key, ...(editing ? { route: value.route } : {}) })
4830
+ .then((r) => {
4831
+ if (r?.ok) {
4832
+ setFound(r.models);
4833
+ toast(t('fetchedN', { n: r.models.length }));
4834
+ } else toast(r?.reason || t('actionFailed'), 'error');
4835
+ })
4836
+ .finally(() => setBusy(''));
4837
+ };
4838
+ const toggle = (id, on) => set({ models: (on ? [...ids, id] : ids.filter((x) => x !== id)).join('\n') });
4839
+ const save = () => {
4840
+ setBusy('save');
4841
+ postJson('models/custom/save', { ...(editing ? { route: value.route } : {}), name: f.name, api: f.api, baseURL: f.baseURL, key: f.key, models: ids })
4842
+ .then((r) => {
4843
+ if (r?.ok) {
4844
+ toast(t('epSaved'));
4845
+ onSaved();
4846
+ } else toast(r?.reason || t('saveFailed'), 'error');
4847
+ })
4848
+ .finally(() => setBusy(''));
4849
+ };
4850
+ const valid = f.name.trim() && /^https?:\/\/\S+/.test(f.baseURL.trim()) && ids.length > 0 && (editing || f.key.trim());
4851
+ return h(
4852
+ 'div',
4853
+ { className: 'dshb-card', 'data-dsh-bots-endpoint-form': value?.route ?? 'new', style: { display: 'flex', flexDirection: 'column', gap: 12 } },
4854
+ h('div', { style: { fontWeight: 700, fontSize: SMALL } }, editing ? t('editEndpoint') : t('addEndpoint')),
4855
+ h(
4856
+ 'div',
4857
+ { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 } },
4858
+ h(Field, { label: t('epName'), hint: editing ? value.route : '' }, h(Input, { value: f.name, disabled: editing, maxLength: 40, placeholder: 'My gateway', onChange: (e) => set({ name: e.target.value }), 'data-dsh-bots-ep': 'name' })),
4859
+ h(Field, { label: t('epApi') }, h('select', { className: 'dshb-input', value: f.api, onChange: (e) => set({ api: e.target.value }), 'data-dsh-bots-ep': 'api' }, (apis ?? Object.keys(API_LABELS)).map((a) => h('option', { key: a, value: a }, API_LABELS[a] ?? a)))),
4860
+ h(Field, { label: t('epBase'), style: { gridColumn: '1 / -1' } }, h(Input, { value: f.baseURL, mono: true, placeholder: f.api === 'anthropic-messages' ? 'https://api.anthropic.com' : 'https://api.example.com/v1', onChange: (e) => set({ baseURL: e.target.value }), 'data-dsh-bots-ep': 'baseURL' })),
4861
+ h(Field, { label: t('epKey'), hint: t('epKeyHint'), style: { gridColumn: '1 / -1' } }, h(Input, { type: 'password', autoComplete: 'off', value: f.key, placeholder: editing ? t('epKeyKeep') : '', onChange: (e) => set({ key: e.target.value }), 'data-dsh-bots-ep': 'key' })),
4862
+ ),
4863
+ h(
4864
+ Field,
4865
+ { label: t('epModels'), hint: t('epModelsHint'), right: h(Btn, { size: 'sm', kind: 'ghost', icon: busy === 'fetch' ? h('span', { className: 'dshb-spinner' }) : Icon.download(12), disabled: busy !== '' || !/^https?:\/\//.test(f.baseURL.trim()), onClick: fetchModels, 'data-dsh-bots-ep-fetch': true }, busy === 'fetch' ? t('fetching') : t('fetchModels')) },
4866
+ found && found.length
4867
+ ? h(
4868
+ 'div',
4869
+ { className: 'dshb-scroll', style: { maxHeight: 180, display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(220px, 1fr))', gap: 4, padding: 6, border: `1px solid ${C.border1}`, borderRadius: 9 } },
4870
+ found.map((m) => h('label', { key: m.id, style: { display: 'flex', gap: 6, alignItems: 'center', fontSize: SMALL, cursor: 'pointer', minWidth: 0 } }, h('input', { type: 'checkbox', checked: ids.includes(m.id), onChange: (e) => toggle(m.id, e.target.checked), style: { accentColor: 'var(--dsw-alias-brand-primary)' } }), h('span', { className: 'dshb-mono', style: { fontSize: 12, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: m.name ?? m.id }, m.id))),
4871
+ )
4872
+ : null,
4873
+ h(TextArea, { rows: 3, mono: true, value: f.models, placeholder: 'gpt-5.1\ndeepseek-chat', onChange: (e) => set({ models: e.target.value }), 'data-dsh-bots-ep': 'models' }),
4874
+ ),
4875
+ h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8 } }, h(Btn, { kind: 'ghost', onClick: onCancel }, t('cancel')), h(Btn, { kind: 'primary', disabled: !valid || busy !== '', onClick: save, 'data-dsh-bots-ep-save': true }, busy === 'save' ? t('saving') : t('save'))),
4876
+ );
4877
+ }
4878
+
4879
+ function ModelSourcesModal({ t, onClose, toast }) {
4880
+ const { data, reload } = useJson('models/sources');
4881
+ const [form, setForm] = useState(null);
4882
+ const [busy, setBusy] = useState('');
4883
+ const [confirm, setConfirm] = useState(null);
4884
+ const act = (path, body, ok) => {
4885
+ setBusy(path);
4886
+ return postJson(path, body)
4887
+ .then((r) => {
4888
+ if (r?.ok) {
4889
+ if (ok) toast(ok);
4890
+ void reload();
4891
+ void loadCatalog(true);
4892
+ void refreshState();
4893
+ } else toast(r?.reason || t('actionFailed'), 'error');
4894
+ })
4895
+ .finally(() => setBusy(''));
4896
+ };
4897
+ return h(
4898
+ Modal,
4899
+ { title: t('sourcesTitle'), onClose, width: 680, closeLabel: t('close') },
4900
+ h('div', { style: { fontSize: SMALL, color: C.muted, lineHeight: 1.6 } }, t('sourcesIntro')),
4901
+ data && !data.writable ? h('div', { style: { fontSize: SMALL, color: C.warn } }, t('notWritable')) : null,
4902
+ h(
4903
+ Section,
4904
+ { title: t('endpoints'), right: form ? null : h(Btn, { size: 'sm', icon: Icon.plus(12), disabled: data && !data.writable, onClick: () => setForm({}), 'data-dsh-bots-add-endpoint': true }, t('addEndpoint')) },
4905
+ form ? h(EndpointForm, { t, value: form, apis: data?.apis, toast, onCancel: () => setForm(null), onSaved: () => (setForm(null), void reload(), void loadCatalog(true)) }) : null,
4906
+ !data
4907
+ ? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('loading'))
4908
+ : data.custom.length === 0 && !form
4909
+ ? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('noEndpoints'))
4910
+ : data.custom.map((e) =>
4911
+ h(
4912
+ 'div',
4913
+ { key: e.route, className: 'dshb-card', 'data-dsh-bots-endpoint': e.route, style: { display: 'flex', alignItems: 'center', gap: 12 } },
4914
+ h(
4915
+ 'div',
4916
+ { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 2 } },
4917
+ h('span', { style: { fontWeight: 600 } }, e.name),
4918
+ h('span', { className: 'dshb-mono', style: { fontSize: 11.5, color: C.faint, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, `${API_LABELS[e.api] ?? e.api} · ${e.baseURL}`),
4919
+ h('span', { style: { fontSize: TINY, color: C.muted } }, `${t('nModels', { n: e.models.length })} · ${e.keyConfigured ? t('keySet') : t('keyMissing')}`),
4920
+ ),
4921
+ confirm === e.route
4922
+ ? h('span', { style: { display: 'inline-flex', gap: 6, alignItems: 'center', fontSize: TINY, color: C.muted } }, t('epRemoveConfirm'), h(Btn, { size: 'sm', kind: 'danger', disabled: busy !== '', onClick: () => act('models/custom/delete', { route: e.route }, t('epRemoved')).then(() => setConfirm(null)) }, t('remove')), h(Btn, { size: 'sm', kind: 'ghost', onClick: () => setConfirm(null) }, t('cancel')))
4923
+ : h('span', { style: { display: 'inline-flex', gap: 6 } }, h(Btn, { size: 'sm', kind: 'ghost', icon: Icon.edit(12), onClick: () => setForm(e) }, t('edit')), h(Btn, { size: 'sm', kind: 'ghost', icon: Icon.trash(12), onClick: () => setConfirm(e.route), 'data-dsh-bots-endpoint-remove': e.route })),
4924
+ ),
4925
+ ),
4926
+ ),
4927
+ h(
4928
+ Section,
4929
+ { title: t('logins'), hint: t('loginsHint') },
4930
+ !data
4931
+ ? null
4932
+ : data.logins.map((l) =>
4933
+ h(
4934
+ 'div',
4935
+ { key: l.id, className: 'dshb-card', 'data-dsh-bots-login': l.id, style: { display: 'flex', alignItems: 'center', gap: 12, opacity: l.found ? 1 : 0.7 } },
4936
+ h(
4937
+ 'div',
4938
+ { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 3 } },
4939
+ h('span', { style: { fontWeight: 600 } }, `${l.name} · ${l.product}`),
4940
+ h('span', { style: { fontSize: TINY, color: C.muted, lineHeight: 1.5 } }, !l.found ? t('loginNotFound') : !l.supported ? t(`loginReason_${l.reason}`) : l.connected ? t('loginConnected', { name: l.name }) : [l.account, l.plan].filter(Boolean).join(' · ')),
4941
+ l.supported && l.found ? h('span', { style: { fontSize: TINY, color: C.faint, lineHeight: 1.5 } }, t(`loginHint_${l.id}`)) : null,
4942
+ ),
4943
+ l.supported && l.found
4944
+ ? l.connected
4945
+ ? h(Btn, { size: 'sm', kind: 'ghost', disabled: busy !== '', onClick: () => act('models/login/disconnect', { id: l.id }), 'data-dsh-bots-login-disconnect': l.id }, t('disconnect'))
4946
+ : h(Btn, { size: 'sm', kind: 'primary', disabled: busy !== '' || (data && !data.writable), onClick: () => act('models/login/connect', { id: l.id }, t('loginReady', { name: l.product })), 'data-dsh-bots-login-connect': l.id }, t('useLogin'))
4947
+ : null,
4948
+ ),
4949
+ ),
4950
+ ),
4951
+ );
4952
+ }
4953
+
4022
4954
  // --- new bot ----------------------------------------------------------------------------
4023
4955
 
4024
4956
  function NewBotModal({ t, onClose, onCreated, toast }) {
@@ -4561,6 +5493,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4561
5493
  const [detail, setDetail] = useState(null); // a team shown in the detail modal
4562
5494
  const [hire, setHire] = useState(null); // {team, phase: confirm|start|busy|done|error, primary, result?}
4563
5495
  const [primaryTick, setPrimaryTick] = useState(true);
5496
+ const [settings, setSettings] = useState(false);
4564
5497
  const [toast, showToast] = useToast();
4565
5498
  const seenNav = useRef(0);
4566
5499
  const bots = Array.isArray(s.state?.bots) ? s.state.bots : [];
@@ -4602,10 +5535,14 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4602
5535
  main = h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', color: C.faint, fontSize: SMALL } }, s.failed ? t('unavailable') : t('loading'));
4603
5536
  } else if (shownView === 'activity') {
4604
5537
  main = h(ActivityView, { t, bots });
5538
+ } else if (shownView === 'usage') {
5539
+ main = h(UsageView, { t, bots });
5540
+ } else if (shownView === 'memory') {
5541
+ main = h(TeamMemoryView, { t, toast: showToast, onSettings: () => setSettings(true) });
4605
5542
  } else if (shownView === 'hero' || shownView === 'teams' || !current) {
4606
5543
  main = h(TeamsGallery, { t, lang, teams, hero: shownView !== 'teams', onHire: (team) => startHire(team), onDetail: (team) => (setPrimaryTick(true), setDetail(team)), onBlank: () => setCreating(true), busy: Boolean(hire) });
4607
5544
  } else {
4608
- main = h(BotDetail, { t, bot: current, primaryId, env: env2, toast: showToast, catalog, tab, setTab, onDeleted: () => setSelected(null) });
5545
+ main = h(BotDetail, { t, bot: current, primaryId, env: env2, toast: showToast, catalog, tab, setTab, onDeleted: () => setSelected(null), onSettings: () => setSettings(true) });
4609
5546
  }
4610
5547
  return h(
4611
5548
  'div',
@@ -4625,6 +5562,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4625
5562
  onNew: () => setCreating(true),
4626
5563
  onTeams: () => setView('teams'),
4627
5564
  onActivity: () => setView('activity'),
5565
+ onUsage: () => setView('usage'),
5566
+ onMemory: () => setView('memory'),
5567
+ onSettings: () => setSettings(true),
5568
+ teamNotes: s.state?.teamNotes ?? 0,
4628
5569
  }),
4629
5570
  h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', minHeight: 0 } }, main),
4630
5571
  creating
@@ -4643,6 +5584,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4643
5584
  ? h(TeamDetailModal, { t, lang, team: detail, entries: catalog?.templates, onClose: () => setDetail(null), onHire: (team) => startHire(team, true), askPrimary: hasPrimary && bots.length > 1, primary: primaryTick, setPrimary: setPrimaryTick })
4644
5585
  : null,
4645
5586
  hire ? h(HireModal, { t, lang, hire, setHire, toast: showToast, catalog, onDone: openBotTab, onOpenBot: openBotTab }) : null,
5587
+ settings ? h(SettingsModal, { t, catalog, toast: showToast, onClose: () => setSettings(false) }) : null,
4646
5588
  h(Toast, { toast }),
4647
5589
  );
4648
5590
  }
@@ -5436,6 +6378,176 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
5436
6378
  channelPrivate: 'Only paired people reach the team. Anyone else is ignored (at most a one-line "this bot is private" a day). In a group the bot only answers when @mentioned or replied to.',
5437
6379
  viaChannel: '{app} · {who}',
5438
6380
  sentToChannel: 'Also sent to {app}',
6381
+ // Usage, memory, topics, settings, model sources
6382
+ settings: 'Settings',
6383
+ usage: 'Usage',
6384
+ usageHint: '{tokens} tokens today',
6385
+ usageSub: 'Tokens and estimated cost of every bot, task and day: conversations, memory work and context compaction.',
6386
+ usageChart: 'Tokens by bot',
6387
+ other: 'Other',
6388
+ removedBot: 'Removed bot',
6389
+ range_today: 'Today',
6390
+ range_7d: '7 days',
6391
+ range_30d: '30 days',
6392
+ range_90d: '90 days',
6393
+ range_all: 'All',
6394
+ prices: 'Prices',
6395
+ tileTokens: 'Tokens',
6396
+ tileCacheRate: '{pct}% of input from cache',
6397
+ tileCost: 'Estimated cost',
6398
+ tileUnpriced: '{tokens} tokens have no price',
6399
+ tileTasks: 'Tasks',
6400
+ tileCalls: 'Model calls',
6401
+ tileInOut: '{input} in · {output} out',
6402
+ vsPrev: '{delta} vs the period before',
6403
+ noUsage: 'No model calls in this period yet.',
6404
+ byBot: 'By bot',
6405
+ byModel: 'By model',
6406
+ byKind: 'By kind of work',
6407
+ bySchedule: 'Scheduled tasks',
6408
+ recentTasks: 'Recent tasks',
6409
+ colBot: 'Bot',
6410
+ colTask: 'Task',
6411
+ colTasks: 'Tasks',
6412
+ colTokens: 'Tokens',
6413
+ colCost: 'Cost',
6414
+ colCalls: 'Calls',
6415
+ colModel: 'Model',
6416
+ colRuns: 'Runs',
6417
+ colWhen: 'When',
6418
+ work_chat: 'Conversations',
6419
+ work_memory: 'Memory summaries',
6420
+ work_compaction: 'Context compaction',
6421
+ work_dream: 'Daily consolidation',
6422
+ trigger_user: 'From you',
6423
+ trigger_chat: 'From {app}',
6424
+ trigger_schedule: 'Scheduled',
6425
+ trigger_dm: 'From @{handle}',
6426
+ taskRunning: 'Running',
6427
+ taskState_error: 'Failed',
6428
+ taskState_stopped: 'Stopped',
6429
+ setPrice: 'Set price',
6430
+ pricesTitle: 'Model prices',
6431
+ pricesHint: 'Costs are estimates: tokens × the price per million tokens. Your own prices come first, then LiteLLM’s public price list ({count} models, fetched {when}). Gateways and subscriptions may bill differently.',
6432
+ priceInput: 'Input / 1M',
6433
+ priceCached: 'Cached input / 1M',
6434
+ priceOutput: 'Output / 1M',
6435
+ priceCurrency: 'Currency',
6436
+ priceSource_user: 'Your price',
6437
+ priceNone: 'No price',
6438
+ usePriceList: 'Use the price list',
6439
+ refreshPriceList: 'Refresh the price list',
6440
+ priceSaved: 'Price saved',
6441
+ tab_memory: 'Memory',
6442
+ memoryOf: 'What {name} remembers',
6443
+ memoryHint: 'Notes kept across conversations and topics. {name} writes them itself, after every task and whenever you ask it to remember something; edit them here. Pinned notes are never changed by the automatic passes.',
6444
+ memoryModelIs: 'Memory work runs on {model}',
6445
+ botsOwnModel: 'each bot’s own model',
6446
+ addNote: 'Add a note…',
6447
+ noteSaved: 'Note saved',
6448
+ filterNotes: 'Filter notes',
6449
+ noNotes: 'Nothing remembered yet. Notes appear after tasks, or add one.',
6450
+ note_fact: 'Fact',
6451
+ note_preference: 'Preference',
6452
+ note_person: 'Person',
6453
+ note_project: 'Project',
6454
+ note_procedure: 'How-to',
6455
+ note_lesson: 'Lesson',
6456
+ src_auto: 'after a task',
6457
+ src_tool: 'saved by the bot',
6458
+ src_user: 'written by you',
6459
+ src_dream: 'consolidated',
6460
+ pin: 'Pin',
6461
+ unpin: 'Unpin',
6462
+ recentWork: 'Recent work',
6463
+ recentWorkHint: 'One line per finished task, written when it ends.',
6464
+ noJournal: 'No finished tasks yet.',
6465
+ topicsTitle: 'Topics',
6466
+ topicsHint: 'Each topic is a fresh conversation, so the context never grows without end. A new one starts when you send /new, after a long quiet, or once the conversation grows large (see Settings). Memory carries over.',
6467
+ topicNow: 'Current topic: started {when} · tasks done: {n} · last prompt {ctx} tokens',
6468
+ topicShort: 'This topic: {ctx} context · tasks done: {n}',
6469
+ newTopic: 'New topic',
6470
+ newTopicHint: 'Start a fresh conversation; memory carries over. You can also send /new.',
6471
+ newTopicDone: '{name} starts a new topic',
6472
+ topicDivider: 'New topic · {reason}',
6473
+ topicReason_manual: 'started by you',
6474
+ topicReason_idle: 'after a quiet spell',
6475
+ topicReason_context: 'the conversation grew large',
6476
+ pastTopic: '{from} – {to} · tasks: {n}',
6477
+ kind_topic: 'New topic',
6478
+ teamMemoryTitle: 'Team memory',
6479
+ teamMemoryHint: '{n} shared notes · daily digest',
6480
+ teamNotes: 'Shared notes',
6481
+ teamNotesHint: 'Every bot reads these. They hold what all of them should know: about you, your business, shared conventions.',
6482
+ digests: 'Daily digests',
6483
+ digestsHint: 'Each day the team’s work is written up; every bot reads the latest one.',
6484
+ noDigests: 'No digest yet.',
6485
+ teamJournal: 'Team journal',
6486
+ dreamNow: 'Consolidate now',
6487
+ dreaming: 'Consolidating…',
6488
+ dreamDone: 'Consolidated {bots} bots{digest}',
6489
+ dreamDigest: ' and wrote the digest',
6490
+ dreamPartly: 'Consolidation finished with a problem: {reason}',
6491
+ lastDream: 'Last consolidated {when}',
6492
+ dreamDaily: 'every day at {time}',
6493
+ neverDreamed: 'Not consolidated yet; it runs every day at {time}.',
6494
+ dreamOff: 'Daily consolidation is off.',
6495
+ settingsTitle: 'Bots settings',
6496
+ settingsSaved: 'Settings saved',
6497
+ setTopics: 'Topics',
6498
+ setIdle: 'New topic after this many quiet hours',
6499
+ setIdleHint: 'Checked before the next task. 0 = never.',
6500
+ setContext: 'New topic at this context size (thousand tokens)',
6501
+ setContextHint: 'Harness also compacts a conversation near the model’s limit; a new topic keeps every call small and cheap. 0 = never.',
6502
+ setMemory: 'Memory',
6503
+ setAuto: 'Summarize every task into memory',
6504
+ setAutoHint: 'One short model call per finished task. Off: only a one-line journal entry.',
6505
+ setMemoryModel: 'Model for memory work',
6506
+ setMemoryModelHint: 'Summaries and consolidation; a small, cheap model is enough.',
6507
+ setDream: 'Consolidate every day',
6508
+ setDreamHint: 'Merges repeated notes, drops stale ones and writes the team’s daily digest.',
6509
+ modelSources: 'Model sources',
6510
+ modelDefaultIs: 'Harness default ({model})',
6511
+ modelContext: 'context window {k} tokens',
6512
+ reasoning: 'Thinking',
6513
+ effortDefault: 'default',
6514
+ msrc_custom: 'your endpoint',
6515
+ msrc_login: 'subscription',
6516
+ sourcesTitle: 'Model sources',
6517
+ sourcesIntro: 'A bot can run on any model Harness has. Add your own endpoint, or use a login another agent on this computer already has. Both become Harness providers, so they also appear in Settings → Models and in every conversation’s model picker.',
6518
+ notWritable: 'This Harness does not let plugins change its model settings.',
6519
+ endpoints: 'Your endpoints',
6520
+ noEndpoints: 'None yet.',
6521
+ addEndpoint: 'Add endpoint',
6522
+ editEndpoint: 'Edit endpoint',
6523
+ epName: 'Name',
6524
+ epApi: 'API',
6525
+ epBase: 'Base URL',
6526
+ epKey: 'API key',
6527
+ epKeyHint: 'Kept in the Harness credential store and never shown again. Any text for a local server that needs none.',
6528
+ epKeyKeep: 'Leave empty to keep the saved key',
6529
+ epModels: 'Models',
6530
+ epModelsHint: 'One model id per line, or fetch the list from the endpoint and tick the ones you want.',
6531
+ fetchModels: 'Fetch models',
6532
+ fetching: 'Fetching…',
6533
+ fetchedN: '{n} models found',
6534
+ epSaved: 'Endpoint saved',
6535
+ epRemoved: 'Endpoint removed',
6536
+ epRemoveConfirm: 'Remove it? Bots on it go back to the default.',
6537
+ nModels: '{n} models',
6538
+ keySet: 'key saved',
6539
+ keyMissing: 'no key',
6540
+ logins: 'Logins on this computer',
6541
+ loginsHint: 'Subscriptions other agents on this Mac are signed in to.',
6542
+ loginNotFound: 'Not signed in on this computer.',
6543
+ loginConnected: 'In use · kept in sync with {name}',
6544
+ loginHint_codex: 'Your ChatGPT plan, through the Codex CLI’s login. Whichever side refreshes the login, the other gets the new tokens (~/.codex/auth.json is updated in place), so neither signs the other out.',
6545
+ loginReason_terms: 'Not offered: Anthropic allows a Claude subscription only in Claude Code and claude.ai. Add Claude as an endpoint with an API key instead.',
6546
+ loginReason_harness: 'This Harness cannot use it yet.',
6547
+ loginReason_signin: 'Sign in from Harness Settings → Models instead.',
6548
+ useLogin: 'Use it',
6549
+ loginReady: '{name} is ready: pick its models in a bot’s profile',
6550
+ disconnect: 'Stop using',
5439
6551
  },
5440
6552
  zh: {
5441
6553
  lang: 'zh',
@@ -5958,6 +7070,176 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
5958
7070
  channelPrivate: '只有配对过的人能找到团队,其他人一律忽略(每天最多回一句“这是私人 Bot”)。在群里,只有 @ 它或回复它时才会回答。',
5959
7071
  viaChannel: '{app} · {who}',
5960
7072
  sentToChannel: '也已发到 {app}',
7073
+ // 用量、记忆、话题、设置、模型来源
7074
+ settings: '设置',
7075
+ usage: '用量',
7076
+ usageHint: '今天 {tokens} tokens',
7077
+ usageSub: '每个 Bot、每个任务、每一天的 tokens 和估算费用:对话、记忆整理和上下文压缩都算在内。',
7078
+ usageChart: '各 Bot 的 tokens',
7079
+ other: '其他',
7080
+ removedBot: '已删除的 Bot',
7081
+ range_today: '今天',
7082
+ range_7d: '7 天',
7083
+ range_30d: '30 天',
7084
+ range_90d: '90 天',
7085
+ range_all: '全部',
7086
+ prices: '价格',
7087
+ tileTokens: 'Tokens',
7088
+ tileCacheRate: '{pct}% 的输入命中缓存',
7089
+ tileCost: '估算费用',
7090
+ tileUnpriced: '{tokens} tokens 没有价格',
7091
+ tileTasks: '任务',
7092
+ tileCalls: '模型调用',
7093
+ tileInOut: '输入 {input} · 输出 {output}',
7094
+ vsPrev: '比上一期 {delta}',
7095
+ noUsage: '这段时间还没有模型调用。',
7096
+ byBot: '按 Bot',
7097
+ byModel: '按模型',
7098
+ byKind: '按用途',
7099
+ bySchedule: '定时任务',
7100
+ recentTasks: '最近的任务',
7101
+ colBot: 'Bot',
7102
+ colTask: '任务',
7103
+ colTasks: '任务',
7104
+ colTokens: 'Tokens',
7105
+ colCost: '费用',
7106
+ colCalls: '调用',
7107
+ colModel: '模型',
7108
+ colRuns: '次数',
7109
+ colWhen: '时间',
7110
+ work_chat: '对话',
7111
+ work_memory: '记忆总结',
7112
+ work_compaction: '上下文压缩',
7113
+ work_dream: '每日整理',
7114
+ trigger_user: '你发起',
7115
+ trigger_chat: '来自 {app}',
7116
+ trigger_schedule: '定时',
7117
+ trigger_dm: '来自 @{handle}',
7118
+ taskRunning: '进行中',
7119
+ taskState_error: '出错',
7120
+ taskState_stopped: '已停止',
7121
+ setPrice: '设价格',
7122
+ pricesTitle: '模型价格',
7123
+ pricesHint: '费用是估算:tokens × 每百万 tokens 的价格。优先用你填的价格,其次是 LiteLLM 公开价格表({count} 个模型,{when} 获取)。网关和订阅的实际计费可能不同。',
7124
+ priceInput: '输入 / 百万',
7125
+ priceCached: '缓存输入 / 百万',
7126
+ priceOutput: '输出 / 百万',
7127
+ priceCurrency: '币种',
7128
+ priceSource_user: '你填的价格',
7129
+ priceNone: '没有价格',
7130
+ usePriceList: '改用价格表',
7131
+ refreshPriceList: '刷新价格表',
7132
+ priceSaved: '价格已保存',
7133
+ tab_memory: '记忆',
7134
+ memoryOf: '{name} 记得的事',
7135
+ memoryHint: '跨对话、跨话题保留的笔记。{name} 会自己记:每个任务结束后自动总结,你让它记住的也会存进来;可以在这里直接修改。置顶的笔记不会被自动整理改动。',
7136
+ memoryModelIs: '记忆工作使用 {model}',
7137
+ botsOwnModel: '各 Bot 自己的模型',
7138
+ addNote: '添加一条笔记…',
7139
+ noteSaved: '笔记已保存',
7140
+ filterNotes: '筛选笔记',
7141
+ noNotes: '还没有记忆。任务完成后会自动出现,也可以手动添加。',
7142
+ note_fact: '事实',
7143
+ note_preference: '偏好',
7144
+ note_person: '人物',
7145
+ note_project: '项目',
7146
+ note_procedure: '做法',
7147
+ note_lesson: '教训',
7148
+ src_auto: '任务后总结',
7149
+ src_tool: 'Bot 自己记的',
7150
+ src_user: '你写的',
7151
+ src_dream: '整理后',
7152
+ pin: '置顶',
7153
+ unpin: '取消置顶',
7154
+ recentWork: '最近做过的事',
7155
+ recentWorkHint: '每完成一个任务记一行,任务结束时写入。',
7156
+ noJournal: '还没有完成的任务。',
7157
+ topicsTitle: '话题',
7158
+ topicsHint: '每个话题是一段新对话,上下文不会无限变长。发送 /new、闲置较久,或对话变得很长时(见设置)会开始新话题;记忆会延续下去。',
7159
+ topicNow: '当前话题:开始于{when} · {n} 个任务 · 最近一次提示 {ctx} tokens',
7160
+ topicShort: '本话题:上下文 {ctx} · 已完成 {n} 个任务',
7161
+ newTopic: '新话题',
7162
+ newTopicHint: '开始一段新对话,记忆会保留。也可以直接发送 /new。',
7163
+ newTopicDone: '{name} 开始了新话题',
7164
+ topicDivider: '新话题 · {reason}',
7165
+ topicReason_manual: '你开启的',
7166
+ topicReason_idle: '闲置后自动开启',
7167
+ topicReason_context: '对话太长自动开启',
7168
+ pastTopic: '{from} – {to} · {n} 个任务',
7169
+ kind_topic: '新话题',
7170
+ teamMemoryTitle: '团队记忆',
7171
+ teamMemoryHint: '{n} 条共享笔记 · 每日摘要',
7172
+ teamNotes: '共享笔记',
7173
+ teamNotesHint: '每个 Bot 都会读。放所有 Bot 都该知道的事:关于你、你的业务、团队约定。',
7174
+ digests: '每日摘要',
7175
+ digestsHint: '每天把团队做过的事写成摘要,每个 Bot 都会读最新的一份。',
7176
+ noDigests: '还没有摘要。',
7177
+ teamJournal: '团队工作日志',
7178
+ dreamNow: '立即整理',
7179
+ dreaming: '整理中…',
7180
+ dreamDone: '已整理 {bots} 个 Bot{digest}',
7181
+ dreamDigest: ',并写好了每日摘要',
7182
+ dreamPartly: '整理完成,但有问题:{reason}',
7183
+ lastDream: '上次整理:{when}',
7184
+ dreamDaily: '每天 {time}',
7185
+ neverDreamed: '还没整理过,每天 {time} 自动进行。',
7186
+ dreamOff: '每日整理已关闭。',
7187
+ settingsTitle: 'Bots 设置',
7188
+ settingsSaved: '设置已保存',
7189
+ setTopics: '话题',
7190
+ setIdle: '闲置多少小时后开新话题',
7191
+ setIdleHint: '在下一个任务开始前检查。0 表示不自动开。',
7192
+ setContext: '上下文达到多少千 tokens 时开新话题',
7193
+ setContextHint: 'Harness 自己会在接近模型上限时压缩对话;开新话题让每次调用都保持小而便宜。0 表示不自动开。',
7194
+ setMemory: '记忆',
7195
+ setAuto: '每个任务结束后总结进记忆',
7196
+ setAutoHint: '每完成一个任务调用一次模型。关闭后只记一行工作日志。',
7197
+ setMemoryModel: '记忆工作用的模型',
7198
+ setMemoryModelHint: '用于总结和整理,小而便宜的模型就够了。',
7199
+ setDream: '每天整理一次',
7200
+ setDreamHint: '合并重复的笔记、删掉过时的,并写团队每日摘要。',
7201
+ modelSources: '模型来源',
7202
+ modelDefaultIs: 'Harness 默认({model})',
7203
+ modelContext: '上下文窗口 {k} tokens',
7204
+ reasoning: '思考强度',
7205
+ effortDefault: '默认',
7206
+ msrc_custom: '自定义端点',
7207
+ msrc_login: '订阅',
7208
+ sourcesTitle: '模型来源',
7209
+ sourcesIntro: 'Bot 可以用 Harness 里的任何模型。你可以添加自己的端点,或者用这台电脑上其他 Agent 已经登录的订阅。两者都会成为 Harness 的模型提供方,也会出现在 设置 → 模型 和每个会话的模型选择里。',
7210
+ notWritable: '当前 Harness 不允许插件修改模型设置。',
7211
+ endpoints: '自定义端点',
7212
+ noEndpoints: '还没有。',
7213
+ addEndpoint: '添加端点',
7214
+ editEndpoint: '编辑端点',
7215
+ epName: '名称',
7216
+ epApi: '接口类型',
7217
+ epBase: 'Base URL',
7218
+ epKey: 'API Key',
7219
+ epKeyHint: '保存在 Harness 凭据库里,之后不再显示。不需要 key 的本地服务随便填点文字即可。',
7220
+ epKeyKeep: '留空则保留已保存的 key',
7221
+ epModels: '模型',
7222
+ epModelsHint: '每行一个模型 id;也可以从端点获取列表后勾选。',
7223
+ fetchModels: '获取模型列表',
7224
+ fetching: '获取中…',
7225
+ fetchedN: '找到 {n} 个模型',
7226
+ epSaved: '端点已保存',
7227
+ epRemoved: '端点已删除',
7228
+ epRemoveConfirm: '确定删除?用它的 Bot 会改回默认模型。',
7229
+ nModels: '{n} 个模型',
7230
+ keySet: '已存 key',
7231
+ keyMissing: '没有 key',
7232
+ logins: '本机其他 Agent 的登录',
7233
+ loginsHint: '这台 Mac 上其他 Agent 已经登录的订阅。',
7234
+ loginNotFound: '本机没有登录。',
7235
+ loginConnected: '使用中 · 与 {name} 保持同步',
7236
+ loginHint_codex: '通过 Codex CLI 的登录使用你的 ChatGPT 订阅。无论哪一边刷新了登录,另一边都会拿到新令牌(会原地更新 ~/.codex/auth.json),两边不会互相踢下线。',
7237
+ loginReason_terms: '不提供:Anthropic 只允许在 Claude Code 和 claude.ai 里使用 Claude 订阅。可以用 API Key 把 Claude 添加为自定义端点。',
7238
+ loginReason_harness: '当前 Harness 还不能使用它。',
7239
+ loginReason_signin: '请改在 Harness 设置 → 模型里登录。',
7240
+ useLogin: '使用',
7241
+ loginReady: '{name} 已就绪:在 Bot 资料页里选它的模型',
7242
+ disconnect: '停用',
5961
7243
  },
5962
7244
  };
5963
7245