@kadaliao/dsh-bots 0.6.0 → 0.7.0

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);
@@ -1741,25 +1764,76 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1741
1764
  );
1742
1765
  }
1743
1766
 
1767
+ /**
1768
+ * Keep a scrolling thread at its bottom while the reader is there: when a message arrives, and when
1769
+ * something already shown grows later (a link card or picture loading, the "working" line appearing).
1770
+ * Scrolled up to read, the reader is left alone; `stick()` brings them back (after they send).
1771
+ */
1772
+ function useStickToBottom(lastKey) {
1773
+ const box = useRef(null);
1774
+ const content = useRef(null);
1775
+ const pinned = useRef(true);
1776
+ const toBottom = () => {
1777
+ const el = box.current;
1778
+ if (el) el.scrollTop = el.scrollHeight;
1779
+ };
1780
+ useEffect(() => {
1781
+ if (pinned.current) toBottom();
1782
+ }, [lastKey]);
1783
+ useEffect(() => {
1784
+ if (typeof ResizeObserver !== 'function' || !content.current) return undefined;
1785
+ const ro = new ResizeObserver(() => {
1786
+ if (pinned.current) toBottom();
1787
+ });
1788
+ ro.observe(content.current);
1789
+ return () => ro.disconnect();
1790
+ }, [content.current]);
1791
+ const onScroll = (e) => {
1792
+ const el = e.currentTarget;
1793
+ pinned.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
1794
+ };
1795
+ const stick = () => {
1796
+ pinned.current = true;
1797
+ toBottom();
1798
+ };
1799
+ return { box, content, onScroll, stick };
1800
+ }
1801
+
1744
1802
  function ChatTab({ t, bot, env, toast }) {
1745
1803
  const { items, failed, reload } = useMessages(bot.id);
1746
1804
  const [text, setText] = useState('');
1747
1805
  const [sending, setSending] = useState(false);
1806
+ const running = bot.status === 'running';
1807
+ const thread = useStickToBottom(`${items?.length ?? 0}:${items?.[items.length - 1]?.id ?? ''}:${running}`);
1808
+ const [topicBusy, setTopicBusy] = useState(false);
1809
+ const startTopic = () => {
1810
+ setTopicBusy(true);
1811
+ postJson('topic/new', { id: bot.id })
1812
+ .then((r) => {
1813
+ if (r?.ok) {
1814
+ toast(t('newTopicDone', { name: bot.name || `@${bot.handle}` }));
1815
+ void reload();
1816
+ void refreshState();
1817
+ } else toast(r?.reason || t('actionFailed'), 'error');
1818
+ })
1819
+ .finally(() => setTopicBusy(false));
1820
+ };
1748
1821
  const send = () => {
1749
1822
  const body = text.trim();
1750
1823
  if (!body || sending) return;
1751
1824
  setSending(true);
1825
+ thread.stick();
1752
1826
  postJson('send', { to: bot.id, text: body })
1753
1827
  .then((r) => {
1754
1828
  if (r?.ok) {
1755
1829
  setText('');
1830
+ thread.stick();
1756
1831
  void reload();
1757
1832
  void refreshState();
1758
1833
  } else toast(r?.reason || t('sendFailed'), 'error');
1759
1834
  })
1760
1835
  .finally(() => setSending(false));
1761
1836
  };
1762
- const running = bot.status === 'running';
1763
1837
  // A pasted link previews above the composer, as it will in the thread.
1764
1838
  const previewUrl = linksIn(useDebounced(text, 400))[0] ?? '';
1765
1839
  return h(
@@ -1767,7 +1841,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1767
1841
  { style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
1768
1842
  h(
1769
1843
  'div',
1770
- { className: 'dshb-scroll', 'data-dsh-bots-thread': bot.id, style: { flex: 1, padding: '6px 24px' } },
1844
+ { className: 'dshb-scroll', 'data-dsh-bots-thread': bot.id, ref: thread.box, onScroll: thread.onScroll, style: { flex: 1, padding: '6px 24px' } },
1845
+ h(
1846
+ 'div',
1847
+ { ref: thread.content },
1771
1848
  items === null
1772
1849
  ? h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('unavailable') : t('loading'))
1773
1850
  : h(MessageList, {
@@ -1785,6 +1862,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1785
1862
  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
1863
  )
1787
1864
  : null,
1865
+ ),
1788
1866
  ),
1789
1867
  h(
1790
1868
  'div',
@@ -1817,6 +1895,9 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1817
1895
  { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 7, fontSize: TINY, color: C.faint } },
1818
1896
  h('span', null, t('composerHint')),
1819
1897
  h('span', { style: { flex: 1 } }),
1898
+ 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,
1899
+ 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')),
1900
+ env.canOpen() ? h('span', { style: { color: C.faint } }, '·') : null,
1820
1901
  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
1902
  ),
1822
1903
  ),
@@ -1878,7 +1959,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
1878
1959
  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
1960
  h('span', { style: { marginLeft: 'auto', color: C.faint, fontSize: TINY }, title: fmtDate(toMs(m.at)) }, fmtAgo(t, m.at)),
1880
1961
  ),
1881
- h(Clamp, { t, text: m.text, lines: 3, style: { fontSize: SMALL, color: C.muted } }),
1962
+ 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
1963
  ),
1883
1964
  );
1884
1965
  }),
@@ -2038,7 +2119,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2038
2119
  bio: str(bot.bio),
2039
2120
  persona: str(bot.persona),
2040
2121
  avatar: avatarOf(bot.avatar),
2041
- model: bot.model && bot.model.model ? { provider: str(bot.model.provider), model: str(bot.model.model) } : null,
2122
+ 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
2123
  deny: Array.isArray(bot.tools?.deny) ? bot.tools.deny.slice().sort() : [],
2043
2124
  });
2044
2125
  /** A clean avatar value: an image keeps its url, anything else is initials (emoji rows from v0.1 too). */
@@ -2147,7 +2228,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2147
2228
  };
2148
2229
  const lang = langOf(t);
2149
2230
  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));
2231
+ const chosen = draft.model ? models.find((m) => modelKey(m) === modelKey(draft.model)) : null;
2232
+ const knownModel = !draft.model || Boolean(chosen);
2233
+ const efforts = Array.isArray(chosen?.efforts) ? chosen.efforts : [];
2234
+ const [sources, setSources] = useState(false);
2151
2235
  return h(
2152
2236
  'div',
2153
2237
  { style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
@@ -2190,24 +2274,38 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2190
2274
  ),
2191
2275
  h(
2192
2276
  Section,
2193
- { title: t('model'), hint: t('modelHint') },
2277
+ { 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
2278
  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('::') } });
2279
+ 'div',
2280
+ { style: { display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center' } },
2281
+ h(
2282
+ 'select',
2283
+ {
2284
+ className: 'dshb-input',
2285
+ 'data-dsh-bots-model': true,
2286
+ value: modelKey(draft.model),
2287
+ style: { maxWidth: 420, flex: '1 1 260px' },
2288
+ onChange: (e) => {
2289
+ const v = e.target.value;
2290
+ if (!v) return set({ model: null });
2291
+ const [provider, ...rest] = v.split('::');
2292
+ set({ model: { provider, model: rest.join('::') } });
2293
+ },
2205
2294
  },
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}`)),
2295
+ h('option', { value: '' }, catalog?.defaultModel ? t('modelDefaultIs', { model: catalog.defaultModel.model }) : t('modelDefault')),
2296
+ !knownModel ? h('option', { value: modelKey(draft.model) }, `${draft.model.provider} · ${draft.model.model}`) : null,
2297
+ 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)))),
2298
+ ),
2299
+ efforts.length
2300
+ ? h(
2301
+ 'select',
2302
+ { 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 } : {}) } }) },
2303
+ h('option', { value: '' }, `${t('reasoning')} · ${t('effortDefault')}${chosen?.defaultEffort ? ` (${chosen.defaultEffort})` : ''}`),
2304
+ efforts.map((e) => h('option', { key: e.id, value: e.id }, `${t('reasoning')} · ${e.name}`)),
2305
+ )
2306
+ : null,
2210
2307
  ),
2308
+ 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
2309
  ),
2212
2310
  h(
2213
2311
  Section,
@@ -2275,6 +2373,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2275
2373
  ),
2276
2374
  ),
2277
2375
  h(SaveBar, { t, dirty, busy, valid, onSave: save, onReset: () => setDraft(JSON.parse(base.current)) }),
2376
+ sources ? h(ModelSourcesModal, { t, toast, onClose: () => setSources(false) }) : null,
2278
2377
  );
2279
2378
  }
2280
2379
  function SaveBar({ t, dirty, busy, valid, onSave, onReset }) {
@@ -2311,6 +2410,9 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2311
2410
  }
2312
2411
 
2313
2412
  const skillSource = (s) => (s?.source === 'dsh' || s?.source === 'import' ? s.source : 'own');
2413
+ /** How many skills a bot keeps, and how many of them may be on at once (from the host; lib/store.mjs). */
2414
+ const skillLimits = () => ({ max: Number(store.state?.limits?.skills) || 200, on: Number(store.state?.limits?.skillsOn) || 50 });
2415
+ const onCount = (skills) => skills.filter((s) => s.enabled !== false).length;
2314
2416
  /** A skill linked to a folder on this machine (its origin is a path, not a URL): read live, never copied. */
2315
2417
  const isLocalSkill = (s) => s?.source === 'import' && typeof s.origin === 'string' && s.origin !== '' && !/^https?:\/\//i.test(s.origin);
2316
2418
  const SOURCE_COLOR = { dsh: '#2563eb', import: '#475569', own: '#16a34a' };
@@ -2332,7 +2434,18 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2332
2434
  /** One line for what an import did: added, updated, skipped. */
2333
2435
  function importSummary(t, r) {
2334
2436
  const n = (k) => (Array.isArray(r?.[k]) ? r[k].length : 0);
2335
- return [n('added') ? t('importedN', { n: n('added') }) : '', n('updated') ? t('updatedN', { n: n('updated') }) : '', n('skipped') ? t('skippedN', { n: n('skipped') }) : ''].filter(Boolean).join(' ');
2437
+ const skipped = Array.isArray(r?.skipped) ? r.skipped : [];
2438
+ const full = skipped.filter((x) => x?.reason === 'full').length;
2439
+ const lim = skillLimits();
2440
+ return [
2441
+ n('added') ? t('importedN', { n: n('added') }) : '',
2442
+ n('off') ? t('offN', { n: n('off'), max: lim.on }) : '',
2443
+ n('updated') ? t('updatedN', { n: n('updated') }) : '',
2444
+ skipped.length - full ? t('skippedN', { n: skipped.length - full }) : '',
2445
+ full ? t('fullN', { n: full, max: lim.max }) : '',
2446
+ ]
2447
+ .filter(Boolean)
2448
+ .join(' ');
2336
2449
  }
2337
2450
  /** Run an import and report it; resolves to the rows that failed, or null when nothing came back. */
2338
2451
  function runImport(t, toast, botId, items) {
@@ -2790,14 +2903,30 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2790
2903
  toast(t('skillNameTaken', { name: s.name.trim() }), 'error');
2791
2904
  return;
2792
2905
  }
2793
- const item = { ...(prev ?? {}), id: s.id || rid('skill'), name: s.name.trim(), source: prev ? skillSource(prev) : 'own', description: s.description.trim(), content: s.content, enabled: s.enabled !== false };
2906
+ const lim = skillLimits();
2907
+ if (!prev && skills.length >= lim.max) {
2908
+ toast(t('skillsFull', { max: lim.max }), 'error');
2909
+ return;
2910
+ }
2911
+ // A new skill past the limit of skills on is kept, switched off.
2912
+ const off = !prev && s.enabled !== false && onCount(skills) >= lim.on;
2913
+ const item = { ...(prev ?? {}), id: s.id || rid('skill'), name: s.name.trim(), source: prev ? skillSource(prev) : 'own', description: s.description.trim(), content: s.content, enabled: s.enabled !== false && !off };
2794
2914
  const next = s.id ? skills.map((x) => (x.id === s.id ? item : x)) : [...skills, item];
2795
- void commit(next, t('skillSaved')).then((ok) => ok && setEditing(null));
2915
+ void commit(next, off ? `${t('skillSaved')} ${t('offN', { n: 1, max: lim.on })}` : t('skillSaved')).then((ok) => ok && setEditing(null));
2796
2916
  };
2797
2917
  const addHarness = (list) => {
2798
2918
  const have = new Set(skills.map((x) => str(x.name).toLowerCase()));
2799
- const add = list.filter((x) => !have.has(str(x.name).toLowerCase())).map((x) => ({ name: x.name, source: 'dsh', enabled: true, description: str(x.description) }));
2800
- void commit([...skills, ...add], t('addedN', { n: add.length })).then((ok) => ok && setPicker(null));
2919
+ const lim = skillLimits();
2920
+ const fresh = list.filter((x) => !have.has(str(x.name).toLowerCase()));
2921
+ if (skills.length + fresh.length > lim.max) {
2922
+ toast(t('skillsRoom', { max: lim.max, n: Math.max(0, lim.max - skills.length) }), 'error');
2923
+ return;
2924
+ }
2925
+ // Past the limit of skills on, the rest come in switched off.
2926
+ const room = Math.max(0, lim.on - onCount(skills));
2927
+ const add = fresh.map((x, i) => ({ name: x.name, source: 'dsh', enabled: i < room, description: str(x.description) }));
2928
+ const off = add.length - Math.min(room, add.length);
2929
+ void commit([...skills, ...add], off ? `${t('addedN', { n: add.length })} ${t('offN', { n: off, max: lim.on })}` : t('addedN', { n: add.length })).then((ok) => ok && setPicker(null));
2801
2930
  };
2802
2931
  const counts = { dsh: 0, import: 0, local: 0, own: 0 };
2803
2932
  for (const s of skills) counts[isLocalSkill(s) ? 'local' : skillSource(s)] += 1;
@@ -2822,7 +2951,14 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2822
2951
  {
2823
2952
  title: t('botSkills', { n: skills.length }),
2824
2953
  hint: t('skillsHint2', { name: bot.name }),
2825
- right: skills.length ? h('span', { style: { fontSize: TINY, color: C.faint } }, t('skillMix', counts)) : null,
2954
+ right: skills.length
2955
+ ? h(
2956
+ 'span',
2957
+ { style: { fontSize: TINY, color: C.faint } },
2958
+ `${t('skillMix', counts)} · `,
2959
+ h('span', { 'data-dsh-bots-skills-on': onCount(skills), style: onCount(skills) >= skillLimits().on ? { color: C.warn, fontWeight: 600 } : null }, t('skillsOnOf', { n: onCount(skills), max: skillLimits().on })),
2960
+ )
2961
+ : null,
2826
2962
  },
2827
2963
  editing ? h(SkillEditor, { t, skill: editing, onChange: setEditing, onCancel: () => setEditing(null), onSave: saveSkill, busy }) : null,
2828
2964
  skills.length === 0 && !editing
@@ -2840,7 +2976,15 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
2840
2976
  { style: { display: 'flex', alignItems: 'center', gap: 8 } },
2841
2977
  h('span', { className: 'dshb-mono', style: { fontWeight: 650, flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: s.name }, s.name),
2842
2978
  h(SourceBadge, { t, source: src, local: isLocalSkill(s) }),
2843
- h(Switch, { on: s.enabled !== false, disabled: busy, title: s.enabled !== false ? t('disable') : t('enable'), onChange: (on) => void commit(skills.map((x) => (x === s ? { ...x, enabled: on } : x))) }),
2979
+ h(Switch, {
2980
+ on: s.enabled !== false,
2981
+ disabled: busy,
2982
+ title: s.enabled !== false ? t('disable') : t('enable'),
2983
+ onChange: (on) => {
2984
+ if (on && onCount(skills) >= skillLimits().on) return void toast(t('tooManyOn', { max: skillLimits().on }), 'error');
2985
+ void commit(skills.map((x) => (x === s ? { ...x, enabled: on } : x)));
2986
+ },
2987
+ }),
2844
2988
  ),
2845
2989
  h('div', { className: 'dshb-clamp2', style: { fontSize: SMALL, color: C.muted, minHeight: 37, lineHeight: 1.5 }, title: s.description }, s.description || h('i', { style: { color: C.faint } }, t('noDescription'))),
2846
2990
  h(
@@ -3867,8 +4011,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
3867
4011
 
3868
4012
  // --- detail: header + tabs ------------------------------------------------------------
3869
4013
 
3870
- const TABS = ['chat', 'profile', 'skills', 'schedules', 'apps'];
3871
- function BotDetail({ t, bot, primaryId, env, toast, catalog, tab, setTab, onDeleted }) {
4014
+ const TABS = ['chat', 'profile', 'memory', 'skills', 'schedules', 'apps'];
4015
+ function BotDetail({ t, bot, primaryId, env, toast, catalog, tab, setTab, onDeleted, onSettings }) {
3872
4016
  const [menu, setMenu] = useState(false);
3873
4017
  const [confirm, setConfirm] = useState(false);
3874
4018
  const [opening, setOpening] = useState(false);
@@ -3893,12 +4037,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
3893
4037
  void refreshState();
3894
4038
  } else toast(r?.reason || t('actionFailed'), 'error');
3895
4039
  });
3896
- const counts = { skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length };
4040
+ const counts = { skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length, memory: Number(bot.memoryNotes) || 0 };
3897
4041
  let body;
3898
4042
  if (tab === 'profile') body = h(ProfileTab, { key: bot.id, t, bot, toast, catalog });
3899
4043
  else if (tab === 'skills') body = h(SkillsTab, { key: bot.id, t, bot, toast, catalog, setTab, env });
3900
4044
  else if (tab === 'schedules') body = h(SchedulesTab, { key: bot.id, t, bot, toast, catalog });
3901
4045
  else if (tab === 'apps') body = h(AppsTab, { key: bot.id, t, bot, toast, catalog });
4046
+ else if (tab === 'memory') body = h(MemoryTab, { key: bot.id, t, bot, toast, onSettings });
3902
4047
  else body = h(ChatTab, { key: bot.id, t, bot, env, toast });
3903
4048
  return h(
3904
4049
  'div',
@@ -3924,7 +4069,9 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
3924
4069
  { style: { display: 'flex', alignItems: 'center', gap: 8, fontSize: SMALL, color: C.muted, minWidth: 0 } },
3925
4070
  h('span', { className: 'dshb-mono', style: { fontSize: 12 } }, `@${bot.handle}`),
3926
4071
  h('span', { style: { color: C.faint } }, '·'),
3927
- h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 5 } }, h(StatusDot, { status, size: 7 }), t(`status_${status}`)),
4072
+ h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 5, whiteSpace: 'nowrap', flex: 'none' } }, h(StatusDot, { status, size: 7 }), t(`status_${status}`)),
4073
+ Number(bot.usageToday) > 0 ? h('span', { style: { color: C.faint } }, '·') : null,
4074
+ Number(bot.usageToday) > 0 ? h('span', { 'data-dsh-bots-today': bot.id, style: { whiteSpace: 'nowrap', flex: 'none' } }, t('usageHint', { tokens: fmtNum(bot.usageToday) })) : null,
3928
4075
  bot.bio ? h('span', { style: { color: C.faint } }, '·') : null,
3929
4076
  bot.bio ? h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, bot.bio) : null,
3930
4077
  ),
@@ -3974,6 +4121,826 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
3974
4121
  );
3975
4122
  }
3976
4123
 
4124
+ // --- usage, memory, topics, settings, model sources ---------------------------------------
4125
+
4126
+ const fmtNum = (n) => {
4127
+ const x = Number(n) || 0;
4128
+ if (x >= 1e9) return `${(x / 1e9).toFixed(x >= 1e10 ? 0 : 1)}B`;
4129
+ if (x >= 1e6) return `${(x / 1e6).toFixed(x >= 1e7 ? 0 : 1)}M`;
4130
+ if (x >= 1e3) return `${(x / 1e3).toFixed(x >= 1e4 ? 0 : 1)}K`;
4131
+ return String(Math.round(x));
4132
+ };
4133
+ const CURRENCY = { USD: '$', CNY: '¥' };
4134
+ const fmtMoney = (amount, cur) => {
4135
+ const v = Number(amount) || 0;
4136
+ 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'}`;
4137
+ };
4138
+ const fmtCost = (cost) => {
4139
+ const parts = Object.entries(cost ?? {})
4140
+ .filter(([, v]) => Number(v) > 0)
4141
+ .map(([c, v]) => fmtMoney(v, c));
4142
+ return parts.length ? parts.join(' + ') : '—';
4143
+ };
4144
+ const tzNow = () => {
4145
+ try {
4146
+ return -new Date().getTimezoneOffset();
4147
+ } catch {
4148
+ return 0;
4149
+ }
4150
+ };
4151
+ const API_LABELS = {
4152
+ 'openai-completions': 'OpenAI-compatible · Chat Completions',
4153
+ 'openai-responses': 'OpenAI · Responses',
4154
+ 'anthropic-messages': 'Anthropic-compatible · Messages',
4155
+ 'google-generative-ai': 'Google Gemini',
4156
+ };
4157
+ /** A GET loaded now and every `ms` while shown (`ms` 0 = once). */
4158
+ function useJson(path, ms = 0) {
4159
+ const [data, setData] = useState(null);
4160
+ const [failed, setFailed] = useState(false);
4161
+ const alive = useRef(true);
4162
+ useEffect(() => {
4163
+ alive.current = true;
4164
+ return () => {
4165
+ alive.current = false;
4166
+ };
4167
+ }, []);
4168
+ const load = () =>
4169
+ Promise.resolve()
4170
+ .then(() => getJson(path))
4171
+ .then((r) => {
4172
+ if (!alive.current) return;
4173
+ if (r && r.ok !== false) {
4174
+ setData(r);
4175
+ setFailed(false);
4176
+ } else setFailed(true);
4177
+ })
4178
+ .catch(() => {
4179
+ if (alive.current) setFailed(true);
4180
+ });
4181
+ usePoll(load, ms || 3_600_000, [path]);
4182
+ return { data, failed, reload: load };
4183
+ }
4184
+ /** A bot's colour for charts: its avatar colour. */
4185
+ const botColor = (id) => botById(id)?.avatar?.color || C.faint;
4186
+ const botName = (t, id) => {
4187
+ const b = botById(id);
4188
+ return b ? b.name || `@${b.handle}` : id === 'team' ? t('teamMemoryTitle') : t('removedBot');
4189
+ };
4190
+ const Seg = ({ items, value, onChange, attr }) =>
4191
+ h(
4192
+ 'div',
4193
+ { role: 'tablist', style: { display: 'inline-flex', padding: 2, borderRadius: 9, background: C.layer2, gap: 2 } },
4194
+ items.map((it) =>
4195
+ h(
4196
+ 'button',
4197
+ {
4198
+ key: it.id,
4199
+ type: 'button',
4200
+ role: 'tab',
4201
+ 'aria-selected': value === it.id,
4202
+ [attr]: it.id,
4203
+ onClick: () => onChange(it.id),
4204
+ 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' },
4205
+ },
4206
+ it.label,
4207
+ ),
4208
+ ),
4209
+ );
4210
+ function Tile({ label, value, sub, delta, attr }) {
4211
+ return h(
4212
+ 'div',
4213
+ { className: 'dshb-card', 'data-dsh-bots-tile': attr, style: { display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0 } },
4214
+ h('span', { style: { fontSize: TINY, fontWeight: 600, color: C.muted, textTransform: 'uppercase', letterSpacing: '.03em' } }, label),
4215
+ h('span', { style: { fontSize: 22, fontWeight: 700, color: C.primary, fontVariantNumeric: 'tabular-nums', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, value),
4216
+ sub ? h('span', { style: { fontSize: TINY, color: C.faint } }, sub) : null,
4217
+ delta ? h('span', { style: { fontSize: TINY, color: C.muted } }, delta) : null,
4218
+ );
4219
+ }
4220
+ /** "+12%" / "−8%" of `now` against `before`, or ''. */
4221
+ const pctDelta = (now, before) => {
4222
+ if (!(before > 0)) return '';
4223
+ const p = Math.round(((now - before) / before) * 100);
4224
+ return `${p > 0 ? '+' : p < 0 ? '−' : '±'}${Math.abs(p)}%`;
4225
+ };
4226
+ const bucketLabel = (ms, bucket) => {
4227
+ try {
4228
+ const d = new Date(ms);
4229
+ return bucket < 86_400_000 ? `${pad(d.getHours())}:00` : `${d.getMonth() + 1}/${d.getDate()}`;
4230
+ } catch {
4231
+ return '';
4232
+ }
4233
+ };
4234
+ /** A top-rounded bar: flat on the baseline, 3px round at the data end. */
4235
+ const barPath = (x, y, w, hgt, r) => {
4236
+ const rr = Math.max(0, Math.min(r, w / 2, hgt));
4237
+ 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`;
4238
+ };
4239
+
4240
+ /** Tokens per bucket, stacked by bot (the top seven by tokens, the rest as "other"). */
4241
+ function UsageChart({ t, data }) {
4242
+ const [hover, setHover] = useState(-1);
4243
+ const series = Array.isArray(data?.series) ? data.series : [];
4244
+ const ranked = (data?.bots ?? []).map((b) => b.bot);
4245
+ const shown = ranked.slice(0, 7);
4246
+ const keys = ranked.length > 7 ? [...shown, '__other'] : shown;
4247
+ 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)));
4248
+ const max = Math.max(1, ...series.map((p) => p.tokens));
4249
+ const W = 720;
4250
+ const H = 190;
4251
+ const L = 44;
4252
+ const B = 22;
4253
+ const T = 8;
4254
+ const innerW = W - L - 6;
4255
+ const innerH = H - B - T;
4256
+ const n = Math.max(1, series.length);
4257
+ const slot = innerW / n;
4258
+ const bw = Math.max(2, Math.min(28, slot * 0.66));
4259
+ const y = (v) => T + innerH - (v / max) * innerH;
4260
+ const ticks = [0, 0.5, 1].map((f) => max * f);
4261
+ const every = Math.max(1, Math.ceil(n / 8));
4262
+ const colorOf = (k) => (k === '__other' ? C.faint : botColor(k));
4263
+ const nameOf = (k) => (k === '__other' ? t('other') : botName(t, k));
4264
+ const hp = hover >= 0 ? series[hover] : null;
4265
+ return h(
4266
+ 'div',
4267
+ { 'data-dsh-bots-usage-chart': true, style: { position: 'relative' } },
4268
+ keys.length > 1
4269
+ ? h(
4270
+ 'div',
4271
+ { style: { display: 'flex', flexWrap: 'wrap', gap: '4px 14px', marginBottom: 8, fontSize: TINY, color: C.muted } },
4272
+ 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))),
4273
+ )
4274
+ : null,
4275
+ h(
4276
+ 'svg',
4277
+ { viewBox: `0 0 ${W} ${H}`, width: '100%', role: 'img', 'aria-label': t('usageChart'), style: { display: 'block', overflow: 'visible' }, onMouseLeave: () => setHover(-1) },
4278
+ ticks.map((v, i) =>
4279
+ h(
4280
+ 'g',
4281
+ { key: `t${i}` },
4282
+ 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 } }),
4283
+ h('text', { x: L - 6, y: y(v) + 3.5, textAnchor: 'end', fontSize: 10.5, fill: 'currentColor', style: { color: C.faint } }, fmtNum(v)),
4284
+ ),
4285
+ ),
4286
+ series.map((p, i) => {
4287
+ const cx = L + slot * i + slot / 2;
4288
+ const stack = stackOf(p);
4289
+ let acc = 0;
4290
+ const top = stack.reduce((last, v, j) => (v > 0 ? j : last), -1);
4291
+ const segs = stack.map((v, j) => {
4292
+ if (!(v > 0)) return null;
4293
+ const y0 = y(acc);
4294
+ acc += v;
4295
+ const y1 = y(acc);
4296
+ // A 2px surface gap between stacked segments.
4297
+ const hgt = Math.max(1, y0 - y1 - (j === 0 ? 0 : 2));
4298
+ 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 });
4299
+ });
4300
+ return h(
4301
+ 'g',
4302
+ { key: p.t },
4303
+ segs,
4304
+ 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,
4305
+ // The hit target is the whole column, not just the bar.
4306
+ h('rect', { x: L + slot * i, y: T, width: slot, height: innerH, fill: 'transparent', onMouseEnter: () => setHover(i), 'data-dsh-bots-usage-col': i }),
4307
+ );
4308
+ }),
4309
+ ),
4310
+ hp
4311
+ ? h(
4312
+ 'div',
4313
+ {
4314
+ 'data-dsh-bots-usage-tip': true,
4315
+ 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 },
4316
+ },
4317
+ h('div', { style: { fontWeight: 700, color: C.primary, marginBottom: 4 } }, `${bucketLabel(hp.t, data.range?.bucket ?? 86_400_000)} · ${fmtNum(hp.tokens)}`),
4318
+ keys
4319
+ .map((k, j) => [k, stackOf(hp)[j]])
4320
+ .filter(([, v]) => v > 0)
4321
+ .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)))),
4322
+ fmtCost(hp.cost) !== '—' ? h('div', { style: { marginTop: 4, color: C.faint } }, fmtCost(hp.cost)) : null,
4323
+ )
4324
+ : null,
4325
+ );
4326
+ }
4327
+ 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);
4328
+ 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);
4329
+ 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));
4330
+ function BotCell({ t, id }) {
4331
+ const b = botById(id);
4332
+ 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)));
4333
+ }
4334
+ function triggerText(t, task) {
4335
+ if (task.trigger === 'schedule') return t('trigger_schedule');
4336
+ if (task.trigger === 'chat') return t('trigger_chat', { app: channelName(task.via, t) });
4337
+ if (task.trigger === 'dm') return task.from === 'user' ? t('trigger_user') : t('trigger_dm', { handle: botById(task.from)?.handle ?? '?' });
4338
+ return t('trigger_user');
4339
+ }
4340
+
4341
+ function UsageView({ t, bots }) {
4342
+ const [range, setRange] = useState('7d');
4343
+ const [bot, setBot] = useState('');
4344
+ const [prices, setPrices] = useState(false);
4345
+ const { data, failed, reload } = useJson(`usage?range=${range}&tz=${tzNow()}${bot ? `&bot=${encodeURIComponent(bot)}` : ''}`, 30_000);
4346
+ const tot = data?.totals;
4347
+ const prev = data?.prev;
4348
+ const empty = tot && tot.calls === 0;
4349
+ 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);
4350
+ return h(
4351
+ 'div',
4352
+ { 'data-dsh-bots-usage': true, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
4353
+ h(
4354
+ 'header',
4355
+ { style: { padding: '18px 24px 14px', borderBottom: `1px solid ${C.border1}`, display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' } },
4356
+ 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'))),
4357
+ h(Seg, { attr: 'data-dsh-bots-range', value: range, onChange: setRange, items: ['today', '7d', '30d', '90d', 'all'].map((id) => ({ id, label: t(`range_${id}`) })) }),
4358
+ 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}`))),
4359
+ h(Btn, { size: 'sm', icon: Icon.edit(12), onClick: () => setPrices(true), 'data-dsh-bots-prices': true }, t('prices')),
4360
+ ),
4361
+ h(
4362
+ 'div',
4363
+ { className: 'dshb-scroll', style: { flex: 1, padding: '18px 24px 28px' } },
4364
+ !data
4365
+ ? h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('unavailable') : t('loading'))
4366
+ : h(
4367
+ 'div',
4368
+ { style: { maxWidth: 1080, display: 'flex', flexDirection: 'column', gap: 16 } },
4369
+ h(
4370
+ 'div',
4371
+ { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 12 } },
4372
+ 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) }) : '' }),
4373
+ h(Tile, { attr: 'cost', label: t('tileCost'), value: fmtCost(tot.cost), sub: tot.unpriced > 0 ? t('tileUnpriced', { tokens: fmtNum(tot.unpriced) }) : '' }),
4374
+ 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) }) : '' }),
4375
+ 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) }) }),
4376
+ ),
4377
+ 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 })),
4378
+ empty
4379
+ ? null
4380
+ : h(
4381
+ 'div',
4382
+ { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(340px, 1fr))', gap: 16 } },
4383
+ section(
4384
+ t('byBot'),
4385
+ h(Table, {
4386
+ attr: 'data-dsh-bots-usage-bots',
4387
+ head: [th(t('colBot')), th(t('colTasks'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4388
+ 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))),
4389
+ }),
4390
+ ),
4391
+ section(
4392
+ t('byModel'),
4393
+ h(Table, {
4394
+ attr: 'data-dsh-bots-usage-models',
4395
+ head: [th(t('colModel')), th(t('colCalls'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4396
+ rows: data.models.map((r) =>
4397
+ h(
4398
+ 'tr',
4399
+ { key: `${r.provider}/${r.model}` },
4400
+ 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))),
4401
+ td(String(r.calls), true),
4402
+ td(fmtNum(r.tokens), true),
4403
+ td(r.priced ? fmtCost(r.cost) : h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY }, onClick: () => setPrices(r.model) }, t('setPrice')), true),
4404
+ ),
4405
+ ),
4406
+ }),
4407
+ ),
4408
+ section(
4409
+ t('byKind'),
4410
+ h(Table, {
4411
+ attr: 'data-dsh-bots-usage-kinds',
4412
+ head: [th(''), th(t('colCalls'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4413
+ 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))),
4414
+ }),
4415
+ ),
4416
+ data.schedules.length
4417
+ ? section(
4418
+ t('bySchedule'),
4419
+ h(Table, {
4420
+ attr: 'data-dsh-bots-usage-schedules',
4421
+ head: [th(t('colTask')), th(t('colRuns'), true), th(t('colTokens'), true), th(t('colCost'), true)],
4422
+ 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))),
4423
+ }),
4424
+ )
4425
+ : null,
4426
+ ),
4427
+ empty || data.tasks.length === 0
4428
+ ? null
4429
+ : section(
4430
+ t('recentTasks'),
4431
+ h(Table, {
4432
+ attr: 'data-dsh-bots-usage-tasks',
4433
+ head: [th(t('colTask')), th(t('colBot')), th(t('colWhen')), th(t('colTokens'), true), th(t('colCost'), true)],
4434
+ rows: data.tasks.map((r) =>
4435
+ h(
4436
+ 'tr',
4437
+ { key: r.id, 'data-dsh-bots-usage-task': r.id },
4438
+ td(
4439
+ h(
4440
+ 'span',
4441
+ { style: { display: 'flex', flexDirection: 'column', minWidth: 0, maxWidth: 380 } },
4442
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: r.title }, r.title),
4443
+ h(
4444
+ 'span',
4445
+ { style: { fontSize: TINY, color: C.faint, display: 'inline-flex', gap: 6, alignItems: 'center' } },
4446
+ triggerText(t, r),
4447
+ 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,
4448
+ ),
4449
+ ),
4450
+ ),
4451
+ td(h(BotCell, { t, id: r.bot })),
4452
+ td(h('span', { style: { color: C.muted, fontSize: TINY, whiteSpace: 'nowrap' } }, fmtDate(r.end ?? r.start))),
4453
+ td(fmtNum(r.tokens), true),
4454
+ td(fmtCost(r.cost), true),
4455
+ ),
4456
+ ),
4457
+ }),
4458
+ ),
4459
+ ),
4460
+ ),
4461
+ prices ? h(PricesModal, { t, focus: typeof prices === 'string' ? prices : '', onClose: () => (setPrices(false), void reload()) }) : null,
4462
+ );
4463
+ }
4464
+
4465
+ function PricesModal({ t, focus, onClose }) {
4466
+ const { data, reload } = useJson('prices');
4467
+ const [edit, setEdit] = useState(focus ? { model: focus, input: '', cacheRead: '', output: '', currency: 'USD' } : null);
4468
+ const [busy, setBusy] = useState(false);
4469
+ const [note, setNote] = useState('');
4470
+ const save = (price) => {
4471
+ setBusy(true);
4472
+ 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 } })
4473
+ .then((r) => {
4474
+ if (r?.ok) {
4475
+ setEdit(null);
4476
+ setNote(t('priceSaved'));
4477
+ void reload();
4478
+ } else setNote(r?.reason || t('saveFailed'));
4479
+ })
4480
+ .finally(() => setBusy(false));
4481
+ };
4482
+ const valid = edit && edit.input !== '' && edit.output !== '' && Number(edit.input) >= 0 && Number(edit.output) >= 0;
4483
+ const list = data?.list;
4484
+ return h(
4485
+ Modal,
4486
+ { title: t('pricesTitle'), onClose, width: 640, closeLabel: t('close') },
4487
+ h('div', { style: { fontSize: SMALL, color: C.muted, lineHeight: 1.6 } }, t('pricesHint', { count: list?.count ?? 0, when: list?.fetchedAt ? fmtDate(list.fetchedAt) : '—' })),
4488
+ note ? h('div', { style: { fontSize: SMALL, color: C.ok } }, note) : null,
4489
+ !data
4490
+ ? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('loading'))
4491
+ : data.models.length === 0
4492
+ ? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('noUsage'))
4493
+ : h(Table, {
4494
+ attr: 'data-dsh-bots-price-table',
4495
+ head: [th(t('colModel')), th(t('priceInput'), true), th(t('priceOutput'), true), th('')],
4496
+ rows: data.models.map((m) =>
4497
+ h(
4498
+ 'tr',
4499
+ { key: m.model },
4500
+ 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')))),
4501
+ td(m.price ? fmtMoney(m.price.input, m.price.currency) : '—', true),
4502
+ td(m.price ? fmtMoney(m.price.output, m.price.currency) : '—', true),
4503
+ td(
4504
+ h(
4505
+ 'span',
4506
+ { style: { display: 'inline-flex', gap: 8 } },
4507
+ 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')),
4508
+ 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,
4509
+ ),
4510
+ true,
4511
+ ),
4512
+ ),
4513
+ ),
4514
+ }),
4515
+ edit && edit.input !== undefined
4516
+ ? h(
4517
+ 'div',
4518
+ { className: 'dshb-card', 'data-dsh-bots-price-form': edit.model, style: { display: 'flex', flexDirection: 'column', gap: 10 } },
4519
+ h('span', { className: 'dshb-mono', style: { fontWeight: 600 } }, edit.model),
4520
+ h(
4521
+ 'div',
4522
+ { style: { display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 } },
4523
+ h(Field, { label: t('priceInput') }, h(Input, { type: 'number', min: 0, step: 'any', value: edit.input, onChange: (e) => setEdit({ ...edit, input: e.target.value }) })),
4524
+ 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 }) })),
4525
+ h(Field, { label: t('priceOutput') }, h(Input, { type: 'number', min: 0, step: 'any', value: edit.output, onChange: (e) => setEdit({ ...edit, output: e.target.value }) })),
4526
+ 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 ¥'))),
4527
+ ),
4528
+ 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'))),
4529
+ )
4530
+ : null,
4531
+ h('div', null, h(Btn, { size: 'sm', kind: 'ghost', icon: Icon.refresh(12), onClick: () => postJson('prices/refresh', {}).then(() => reload()) }, t('refreshPriceList'))),
4532
+ );
4533
+ }
4534
+
4535
+ const NOTE_KINDS = ['fact', 'preference', 'person', 'project', 'procedure', 'lesson'];
4536
+ /** A list of memory notes the user can add to, edit, pin and delete. */
4537
+ function NotesEditor({ t, scope, notes, reload, toast }) {
4538
+ const [text, setText] = useState('');
4539
+ const [kind, setKind] = useState('fact');
4540
+ const [q, setQ] = useState('');
4541
+ const [editing, setEditing] = useState(null);
4542
+ const put = (note, ok) =>
4543
+ postJson('memory/put', { scope, note }).then((r) => {
4544
+ if (r?.ok) {
4545
+ if (ok) toast(ok);
4546
+ setEditing(null);
4547
+ void reload();
4548
+ void refreshState();
4549
+ } else toast(r?.reason || t('saveFailed'), 'error');
4550
+ return r;
4551
+ });
4552
+ const add = () => {
4553
+ if (!text.trim()) return;
4554
+ void put({ text: text.trim(), kind }, t('noteSaved')).then((r) => r?.ok && setText(''));
4555
+ };
4556
+ const remove = (id) =>
4557
+ postJson('memory/delete', { scope, id }).then((r) => {
4558
+ if (r?.ok) {
4559
+ void reload();
4560
+ void refreshState();
4561
+ } else toast(r?.reason || t('actionFailed'), 'error');
4562
+ });
4563
+ const needle = q.trim().toLowerCase();
4564
+ const list = (notes ?? [])
4565
+ .filter((n) => !needle || n.text.toLowerCase().includes(needle))
4566
+ .slice()
4567
+ .sort((a, b) => Number(Boolean(b.pinned)) - Number(Boolean(a.pinned)) || b.updated - a.updated);
4568
+ return h(
4569
+ 'div',
4570
+ { 'data-dsh-bots-notes': scope, style: { display: 'flex', flexDirection: 'column', gap: 10 } },
4571
+ h(
4572
+ 'div',
4573
+ { style: { display: 'flex', gap: 8 } },
4574
+ 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 } }),
4575
+ 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}`)))),
4576
+ h(Btn, { kind: 'primary', icon: Icon.plus(13), disabled: !text.trim(), onClick: add, 'data-dsh-bots-note-add': true }, t('add')),
4577
+ ),
4578
+ (notes ?? []).length > 8 ? h(Input, { value: q, placeholder: t('filterNotes'), onChange: (e) => setQ(e.target.value), style: { height: 30, fontSize: SMALL, maxWidth: 280 } }) : null,
4579
+ list.length === 0
4580
+ ? h('div', { style: { fontSize: SMALL, color: C.faint, padding: '6px 2px' } }, t('noNotes'))
4581
+ : h(
4582
+ 'div',
4583
+ { style: { display: 'flex', flexDirection: 'column', border: `1px solid ${C.border1}`, borderRadius: 12, overflow: 'hidden', background: C.layer1 } },
4584
+ list.map((n, i) =>
4585
+ h(
4586
+ 'div',
4587
+ { 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' } },
4588
+ h(Badge, { color: C.muted }, t(`note_${n.kind}`)),
4589
+ editing?.id === n.id
4590
+ ? h(
4591
+ 'div',
4592
+ { style: { flex: 1, display: 'flex', gap: 6 } },
4593
+ 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 } }),
4594
+ h(Btn, { size: 'sm', kind: 'primary', onClick: () => put({ id: n.id, text: editing.text }) }, t('save')),
4595
+ h(Btn, { size: 'sm', kind: 'ghost', onClick: () => setEditing(null) }, t('cancel')),
4596
+ )
4597
+ : h(
4598
+ 'div',
4599
+ { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 2 } },
4600
+ 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),
4601
+ h('span', { style: { fontSize: TINY, color: C.faint } }, `${t(`src_${n.source}`)} · ${fmtAgo(t, n.updated)}`),
4602
+ ),
4603
+ 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)),
4604
+ 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)),
4605
+ ),
4606
+ ),
4607
+ ),
4608
+ );
4609
+ }
4610
+ function JournalList({ t, items, showBot }) {
4611
+ if (!items?.length) return h('div', { style: { fontSize: SMALL, color: C.faint } }, t('noJournal'));
4612
+ return h(
4613
+ 'div',
4614
+ { 'data-dsh-bots-journal': true, style: { display: 'flex', flexDirection: 'column', gap: 2 } },
4615
+ items.slice(0, 60).map((j) =>
4616
+ h(
4617
+ 'div',
4618
+ { key: j.id, style: { display: 'flex', gap: 10, alignItems: 'flex-start', padding: '6px 2px', fontSize: SMALL } },
4619
+ h('span', { style: { color: C.faint, fontSize: TINY, width: 132, flex: 'none', paddingTop: 2, whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' } }, fmtDate(j.at)),
4620
+ showBot ? h('span', { style: { flex: 'none', width: 130 } }, h(BotCell, { t, id: j.bot })) : null,
4621
+ h('span', { style: { flex: 1, color: C.primary, lineHeight: 1.5, wordBreak: 'break-word' } }, j.summary || j.title),
4622
+ ),
4623
+ ),
4624
+ );
4625
+ }
4626
+ const memModelText = (t, m) => (m ? `${m.provider} · ${m.model}` : t('botsOwnModel'));
4627
+
4628
+ function MemoryTab({ t, bot, toast, onSettings }) {
4629
+ const { data, reload } = useJson(`memory?bot=${encodeURIComponent(bot.id)}`, 15_000);
4630
+ const [busy, setBusy] = useState(false);
4631
+ const name = bot.name || `@${bot.handle}`;
4632
+ const topic = data?.topic;
4633
+ const startTopic = () => {
4634
+ setBusy(true);
4635
+ postJson('topic/new', { id: bot.id })
4636
+ .then((r) => {
4637
+ if (r?.ok) {
4638
+ toast(t('newTopicDone', { name }));
4639
+ void reload();
4640
+ void refreshState();
4641
+ } else toast(r?.reason || t('actionFailed'), 'error');
4642
+ })
4643
+ .finally(() => setBusy(false));
4644
+ };
4645
+ return h(
4646
+ 'div',
4647
+ { className: 'dshb-scroll', 'data-dsh-bots-memory': bot.id, style: { flex: 1, padding: '20px 24px 28px' } },
4648
+ h(
4649
+ 'div',
4650
+ { style: { maxWidth: 820, display: 'flex', flexDirection: 'column', gap: 26 } },
4651
+ h(
4652
+ Section,
4653
+ { 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) })) },
4654
+ data ? h(NotesEditor, { t, scope: bot.id, notes: data.notes, reload, toast }) : h('div', { style: { fontSize: SMALL, color: C.faint } }, t('loading')),
4655
+ ),
4656
+ h(Section, { title: t('recentWork'), hint: t('recentWorkHint') }, data ? h(JournalList, { t, items: data.journal }) : null),
4657
+ h(
4658
+ Section,
4659
+ { 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')) },
4660
+ topic ? h('div', { className: 'dshb-card', style: { fontSize: SMALL } }, t('topicNow', { when: fmtAgo(t, topic.startedAt), n: topic.tasks, ctx: fmtNum(topic.lastPrompt) })) : null,
4661
+ ...(data?.topics ?? []).map((p) =>
4662
+ h(
4663
+ 'div',
4664
+ { key: p.sessionId, 'data-dsh-bots-past-topic': p.sessionId, style: { display: 'flex', alignItems: 'center', gap: 10, padding: '4px 2px', fontSize: SMALL } },
4665
+ h('span', { style: { color: C.muted, whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' } }, t('pastTopic', { from: fmtDate(p.startedAt), to: fmtDate(p.endedAt), n: p.tasks })),
4666
+ h(Badge, { color: C.muted }, t(`topicReason_${p.reason}`)),
4667
+ h('span', { style: { flex: 1, minWidth: 0, color: C.faint, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, (p.titles ?? []).join(' · ')),
4668
+ ),
4669
+ ),
4670
+ ),
4671
+ ),
4672
+ );
4673
+ }
4674
+
4675
+ function TeamMemoryView({ t, toast, onSettings }) {
4676
+ const { data, reload } = useJson('memory?bot=team', 20_000);
4677
+ const [busy, setBusy] = useState(false);
4678
+ const dream = () => {
4679
+ setBusy(true);
4680
+ postJson('memory/dream', {})
4681
+ .then((r) => {
4682
+ if (r?.ok) {
4683
+ const errs = r.result?.errors ?? [];
4684
+ 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');
4685
+ void reload();
4686
+ void refreshState();
4687
+ } else toast(r?.reason || t('actionFailed'), 'error');
4688
+ })
4689
+ .finally(() => setBusy(false));
4690
+ };
4691
+ const st = data?.settings;
4692
+ const last = data?.dream?.lastAt;
4693
+ return h(
4694
+ 'div',
4695
+ { 'data-dsh-bots-team-memory': true, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
4696
+ h(
4697
+ 'header',
4698
+ { style: { padding: '18px 24px 14px', borderBottom: `1px solid ${C.border1}`, display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' } },
4699
+ h(
4700
+ 'div',
4701
+ { style: { display: 'flex', flexDirection: 'column', gap: 2, flex: 1, minWidth: 220 } },
4702
+ h('span', { style: { fontWeight: 700, fontSize: 19 } }, t('teamMemoryTitle')),
4703
+ 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 })),
4704
+ ),
4705
+ h(Btn, { kind: 'ghost', size: 'sm', icon: Icon.edit(12), onClick: onSettings }, t('settings')),
4706
+ 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')),
4707
+ ),
4708
+ h(
4709
+ 'div',
4710
+ { className: 'dshb-scroll', style: { flex: 1, padding: '20px 24px 28px' } },
4711
+ h(
4712
+ 'div',
4713
+ { style: { maxWidth: 860, display: 'flex', flexDirection: 'column', gap: 26 } },
4714
+ 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'))),
4715
+ h(
4716
+ Section,
4717
+ { title: t('digests'), hint: t('digestsHint') },
4718
+ !data?.digests?.length
4719
+ ? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('noDigests'))
4720
+ : 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 } }))),
4721
+ ),
4722
+ h(Section, { title: t('teamJournal'), hint: t('recentWorkHint') }, data ? h(JournalList, { t, items: data.journal, showBot: true }) : null),
4723
+ ),
4724
+ ),
4725
+ );
4726
+ }
4727
+
4728
+ function SettingsModal({ t, catalog, onClose, toast }) {
4729
+ const [form, setForm] = useState(null);
4730
+ const [busy, setBusy] = useState(false);
4731
+ useEffect(() => {
4732
+ void getJson('settings').then((r) => r?.settings && setForm(r.settings));
4733
+ }, []);
4734
+ const set = (part, patch) => setForm((f) => ({ ...f, [part]: { ...f[part], ...patch } }));
4735
+ const models = Array.isArray(catalog?.models) ? catalog.models : [];
4736
+ const save = () => {
4737
+ setBusy(true);
4738
+ postJson('settings', { patch: { topics: { idleHours: Number(form.topics.idleHours) || 0, maxContextK: Number(form.topics.maxContextK) || 0 }, memory: form.memory } })
4739
+ .then((r) => {
4740
+ if (r?.ok) {
4741
+ toast(t('settingsSaved'));
4742
+ onClose();
4743
+ } else toast(r?.reason || t('saveFailed'), 'error');
4744
+ })
4745
+ .finally(() => setBusy(false));
4746
+ };
4747
+ 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);
4748
+ return h(
4749
+ Modal,
4750
+ {
4751
+ title: t('settingsTitle'),
4752
+ onClose,
4753
+ width: 560,
4754
+ closeLabel: t('close'),
4755
+ 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'))],
4756
+ },
4757
+ !form
4758
+ ? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('loading'))
4759
+ : [
4760
+ h(
4761
+ Section,
4762
+ { key: 'topics', title: t('setTopics') },
4763
+ 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 } })),
4764
+ 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 } })),
4765
+ ),
4766
+ h(
4767
+ Section,
4768
+ { key: 'memory', title: t('setMemory') },
4769
+ 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' })),
4770
+ row(
4771
+ t('setMemoryModel'),
4772
+ t('setMemoryModelHint'),
4773
+ h(
4774
+ 'select',
4775
+ {
4776
+ className: 'dshb-input',
4777
+ value: modelKey(form.memory.model),
4778
+ style: { width: 230 },
4779
+ 'data-dsh-bots-setting': 'memoryModel',
4780
+ onChange: (e) => {
4781
+ const v = e.target.value;
4782
+ if (!v) return set('memory', { model: null });
4783
+ const [provider, ...rest] = v.split('::');
4784
+ set('memory', { model: { provider, model: rest.join('::') } });
4785
+ },
4786
+ },
4787
+ h('option', { value: '' }, t('botsOwnModel')),
4788
+ 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,
4789
+ 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)))),
4790
+ ),
4791
+ ),
4792
+ 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' }))),
4793
+ ),
4794
+ ],
4795
+ );
4796
+ }
4797
+
4798
+ /** Catalog models by provider, in catalog order. */
4799
+ function modelGroups(models) {
4800
+ const groups = [];
4801
+ for (const m of models) {
4802
+ const name = m.group || m.provider;
4803
+ let g = groups.find((x) => x.name === name);
4804
+ if (!g) groups.push((g = { name, source: m.source ?? '', models: [] }));
4805
+ g.models.push(m);
4806
+ }
4807
+ return groups;
4808
+ }
4809
+
4810
+ function EndpointForm({ t, value, apis, onCancel, onSaved, toast }) {
4811
+ const editing = Boolean(value?.route);
4812
+ 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') }));
4813
+ const [found, setFound] = useState(null);
4814
+ const [busy, setBusy] = useState('');
4815
+ const set = (p) => setF((x) => ({ ...x, ...p }));
4816
+ const ids = [...new Set(f.models.split(/[\n,]+/).map((s) => s.trim()).filter(Boolean))];
4817
+ const fetchModels = () => {
4818
+ setBusy('fetch');
4819
+ postJson('models/custom/test', { api: f.api, baseURL: f.baseURL, key: f.key, ...(editing ? { route: value.route } : {}) })
4820
+ .then((r) => {
4821
+ if (r?.ok) {
4822
+ setFound(r.models);
4823
+ toast(t('fetchedN', { n: r.models.length }));
4824
+ } else toast(r?.reason || t('actionFailed'), 'error');
4825
+ })
4826
+ .finally(() => setBusy(''));
4827
+ };
4828
+ const toggle = (id, on) => set({ models: (on ? [...ids, id] : ids.filter((x) => x !== id)).join('\n') });
4829
+ const save = () => {
4830
+ setBusy('save');
4831
+ postJson('models/custom/save', { ...(editing ? { route: value.route } : {}), name: f.name, api: f.api, baseURL: f.baseURL, key: f.key, models: ids })
4832
+ .then((r) => {
4833
+ if (r?.ok) {
4834
+ toast(t('epSaved'));
4835
+ onSaved();
4836
+ } else toast(r?.reason || t('saveFailed'), 'error');
4837
+ })
4838
+ .finally(() => setBusy(''));
4839
+ };
4840
+ const valid = f.name.trim() && /^https?:\/\/\S+/.test(f.baseURL.trim()) && ids.length > 0 && (editing || f.key.trim());
4841
+ return h(
4842
+ 'div',
4843
+ { className: 'dshb-card', 'data-dsh-bots-endpoint-form': value?.route ?? 'new', style: { display: 'flex', flexDirection: 'column', gap: 12 } },
4844
+ h('div', { style: { fontWeight: 700, fontSize: SMALL } }, editing ? t('editEndpoint') : t('addEndpoint')),
4845
+ h(
4846
+ 'div',
4847
+ { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 } },
4848
+ 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' })),
4849
+ 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)))),
4850
+ 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' })),
4851
+ 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' })),
4852
+ ),
4853
+ h(
4854
+ Field,
4855
+ { 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')) },
4856
+ found && found.length
4857
+ ? h(
4858
+ 'div',
4859
+ { 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 } },
4860
+ 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))),
4861
+ )
4862
+ : null,
4863
+ 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' }),
4864
+ ),
4865
+ 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'))),
4866
+ );
4867
+ }
4868
+
4869
+ function ModelSourcesModal({ t, onClose, toast }) {
4870
+ const { data, reload } = useJson('models/sources');
4871
+ const [form, setForm] = useState(null);
4872
+ const [busy, setBusy] = useState('');
4873
+ const [confirm, setConfirm] = useState(null);
4874
+ const act = (path, body, ok) => {
4875
+ setBusy(path);
4876
+ return postJson(path, body)
4877
+ .then((r) => {
4878
+ if (r?.ok) {
4879
+ if (ok) toast(ok);
4880
+ void reload();
4881
+ void loadCatalog(true);
4882
+ void refreshState();
4883
+ } else toast(r?.reason || t('actionFailed'), 'error');
4884
+ })
4885
+ .finally(() => setBusy(''));
4886
+ };
4887
+ return h(
4888
+ Modal,
4889
+ { title: t('sourcesTitle'), onClose, width: 680, closeLabel: t('close') },
4890
+ h('div', { style: { fontSize: SMALL, color: C.muted, lineHeight: 1.6 } }, t('sourcesIntro')),
4891
+ data && !data.writable ? h('div', { style: { fontSize: SMALL, color: C.warn } }, t('notWritable')) : null,
4892
+ h(
4893
+ Section,
4894
+ { 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')) },
4895
+ form ? h(EndpointForm, { t, value: form, apis: data?.apis, toast, onCancel: () => setForm(null), onSaved: () => (setForm(null), void reload(), void loadCatalog(true)) }) : null,
4896
+ !data
4897
+ ? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('loading'))
4898
+ : data.custom.length === 0 && !form
4899
+ ? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('noEndpoints'))
4900
+ : data.custom.map((e) =>
4901
+ h(
4902
+ 'div',
4903
+ { key: e.route, className: 'dshb-card', 'data-dsh-bots-endpoint': e.route, style: { display: 'flex', alignItems: 'center', gap: 12 } },
4904
+ h(
4905
+ 'div',
4906
+ { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 2 } },
4907
+ h('span', { style: { fontWeight: 600 } }, e.name),
4908
+ 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}`),
4909
+ h('span', { style: { fontSize: TINY, color: C.muted } }, `${t('nModels', { n: e.models.length })} · ${e.keyConfigured ? t('keySet') : t('keyMissing')}`),
4910
+ ),
4911
+ confirm === e.route
4912
+ ? 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')))
4913
+ : 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 })),
4914
+ ),
4915
+ ),
4916
+ ),
4917
+ h(
4918
+ Section,
4919
+ { title: t('logins'), hint: t('loginsHint') },
4920
+ !data
4921
+ ? null
4922
+ : data.logins.map((l) =>
4923
+ h(
4924
+ 'div',
4925
+ { 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 } },
4926
+ h(
4927
+ 'div',
4928
+ { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 3 } },
4929
+ h('span', { style: { fontWeight: 600 } }, `${l.name} · ${l.product}`),
4930
+ 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(' · ')),
4931
+ l.supported && l.found ? h('span', { style: { fontSize: TINY, color: C.faint, lineHeight: 1.5 } }, t(`loginHint_${l.id}`)) : null,
4932
+ ),
4933
+ l.supported && l.found
4934
+ ? l.connected
4935
+ ? 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'))
4936
+ : 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'))
4937
+ : null,
4938
+ ),
4939
+ ),
4940
+ ),
4941
+ );
4942
+ }
4943
+
3977
4944
  // --- new bot ----------------------------------------------------------------------------
3978
4945
 
3979
4946
  function NewBotModal({ t, onClose, onCreated, toast }) {
@@ -4516,6 +5483,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4516
5483
  const [detail, setDetail] = useState(null); // a team shown in the detail modal
4517
5484
  const [hire, setHire] = useState(null); // {team, phase: confirm|start|busy|done|error, primary, result?}
4518
5485
  const [primaryTick, setPrimaryTick] = useState(true);
5486
+ const [settings, setSettings] = useState(false);
4519
5487
  const [toast, showToast] = useToast();
4520
5488
  const seenNav = useRef(0);
4521
5489
  const bots = Array.isArray(s.state?.bots) ? s.state.bots : [];
@@ -4557,10 +5525,14 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4557
5525
  main = h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', color: C.faint, fontSize: SMALL } }, s.failed ? t('unavailable') : t('loading'));
4558
5526
  } else if (shownView === 'activity') {
4559
5527
  main = h(ActivityView, { t, bots });
5528
+ } else if (shownView === 'usage') {
5529
+ main = h(UsageView, { t, bots });
5530
+ } else if (shownView === 'memory') {
5531
+ main = h(TeamMemoryView, { t, toast: showToast, onSettings: () => setSettings(true) });
4560
5532
  } else if (shownView === 'hero' || shownView === 'teams' || !current) {
4561
5533
  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) });
4562
5534
  } else {
4563
- main = h(BotDetail, { t, bot: current, primaryId, env: env2, toast: showToast, catalog, tab, setTab, onDeleted: () => setSelected(null) });
5535
+ main = h(BotDetail, { t, bot: current, primaryId, env: env2, toast: showToast, catalog, tab, setTab, onDeleted: () => setSelected(null), onSettings: () => setSettings(true) });
4564
5536
  }
4565
5537
  return h(
4566
5538
  'div',
@@ -4580,6 +5552,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4580
5552
  onNew: () => setCreating(true),
4581
5553
  onTeams: () => setView('teams'),
4582
5554
  onActivity: () => setView('activity'),
5555
+ onUsage: () => setView('usage'),
5556
+ onMemory: () => setView('memory'),
5557
+ onSettings: () => setSettings(true),
5558
+ teamNotes: s.state?.teamNotes ?? 0,
4583
5559
  }),
4584
5560
  h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', minHeight: 0 } }, main),
4585
5561
  creating
@@ -4598,6 +5574,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
4598
5574
  ? 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 })
4599
5575
  : null,
4600
5576
  hire ? h(HireModal, { t, lang, hire, setHire, toast: showToast, catalog, onDone: openBotTab, onOpenBot: openBotTab }) : null,
5577
+ settings ? h(SettingsModal, { t, catalog, toast: showToast, onClose: () => setSettings(false) }) : null,
4601
5578
  h(Toast, { toast }),
4602
5579
  );
4603
5580
  }
@@ -5274,6 +6251,12 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
5274
6251
  importedN: "Imported {n} skills.",
5275
6252
  updatedN: "Updated {n}.",
5276
6253
  skippedN: "Skipped {n}: a skill of that name is already here.",
6254
+ fullN: "Skipped {n}: a bot keeps at most {max} skills.",
6255
+ offN: "{n} came in switched off: at most {max} skills can be on at once.",
6256
+ tooManyOn: "At most {max} skills can be on at once. Switch one off first.",
6257
+ skillsFull: "A bot keeps at most {max} skills. Remove one first.",
6258
+ skillsRoom: "A bot keeps at most {max} skills; there is room for {n} more.",
6259
+ skillsOnOf: "{n}/{max} on",
5277
6260
  nameTaken: "Name already used",
5278
6261
  reimport: "Imported · import again to update",
5279
6262
  skillNameTaken: "This bot already has a skill named “{name}”.",
@@ -5385,6 +6368,176 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
5385
6368
  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.',
5386
6369
  viaChannel: '{app} · {who}',
5387
6370
  sentToChannel: 'Also sent to {app}',
6371
+ // Usage, memory, topics, settings, model sources
6372
+ settings: 'Settings',
6373
+ usage: 'Usage',
6374
+ usageHint: '{tokens} tokens today',
6375
+ usageSub: 'Tokens and estimated cost of every bot, task and day: conversations, memory work and context compaction.',
6376
+ usageChart: 'Tokens by bot',
6377
+ other: 'Other',
6378
+ removedBot: 'Removed bot',
6379
+ range_today: 'Today',
6380
+ range_7d: '7 days',
6381
+ range_30d: '30 days',
6382
+ range_90d: '90 days',
6383
+ range_all: 'All',
6384
+ prices: 'Prices',
6385
+ tileTokens: 'Tokens',
6386
+ tileCacheRate: '{pct}% of input from cache',
6387
+ tileCost: 'Estimated cost',
6388
+ tileUnpriced: '{tokens} tokens have no price',
6389
+ tileTasks: 'Tasks',
6390
+ tileCalls: 'Model calls',
6391
+ tileInOut: '{input} in · {output} out',
6392
+ vsPrev: '{delta} vs the period before',
6393
+ noUsage: 'No model calls in this period yet.',
6394
+ byBot: 'By bot',
6395
+ byModel: 'By model',
6396
+ byKind: 'By kind of work',
6397
+ bySchedule: 'Scheduled tasks',
6398
+ recentTasks: 'Recent tasks',
6399
+ colBot: 'Bot',
6400
+ colTask: 'Task',
6401
+ colTasks: 'Tasks',
6402
+ colTokens: 'Tokens',
6403
+ colCost: 'Cost',
6404
+ colCalls: 'Calls',
6405
+ colModel: 'Model',
6406
+ colRuns: 'Runs',
6407
+ colWhen: 'When',
6408
+ work_chat: 'Conversations',
6409
+ work_memory: 'Memory summaries',
6410
+ work_compaction: 'Context compaction',
6411
+ work_dream: 'Daily consolidation',
6412
+ trigger_user: 'From you',
6413
+ trigger_chat: 'From {app}',
6414
+ trigger_schedule: 'Scheduled',
6415
+ trigger_dm: 'From @{handle}',
6416
+ taskRunning: 'Running',
6417
+ taskState_error: 'Failed',
6418
+ taskState_stopped: 'Stopped',
6419
+ setPrice: 'Set price',
6420
+ pricesTitle: 'Model prices',
6421
+ 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.',
6422
+ priceInput: 'Input / 1M',
6423
+ priceCached: 'Cached input / 1M',
6424
+ priceOutput: 'Output / 1M',
6425
+ priceCurrency: 'Currency',
6426
+ priceSource_user: 'Your price',
6427
+ priceNone: 'No price',
6428
+ usePriceList: 'Use the price list',
6429
+ refreshPriceList: 'Refresh the price list',
6430
+ priceSaved: 'Price saved',
6431
+ tab_memory: 'Memory',
6432
+ memoryOf: 'What {name} remembers',
6433
+ 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.',
6434
+ memoryModelIs: 'Memory work runs on {model}',
6435
+ botsOwnModel: 'each bot’s own model',
6436
+ addNote: 'Add a note…',
6437
+ noteSaved: 'Note saved',
6438
+ filterNotes: 'Filter notes',
6439
+ noNotes: 'Nothing remembered yet. Notes appear after tasks, or add one.',
6440
+ note_fact: 'Fact',
6441
+ note_preference: 'Preference',
6442
+ note_person: 'Person',
6443
+ note_project: 'Project',
6444
+ note_procedure: 'How-to',
6445
+ note_lesson: 'Lesson',
6446
+ src_auto: 'after a task',
6447
+ src_tool: 'saved by the bot',
6448
+ src_user: 'written by you',
6449
+ src_dream: 'consolidated',
6450
+ pin: 'Pin',
6451
+ unpin: 'Unpin',
6452
+ recentWork: 'Recent work',
6453
+ recentWorkHint: 'One line per finished task, written when it ends.',
6454
+ noJournal: 'No finished tasks yet.',
6455
+ topicsTitle: 'Topics',
6456
+ 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.',
6457
+ topicNow: 'Current topic: started {when} · tasks done: {n} · last prompt {ctx} tokens',
6458
+ topicShort: 'This topic: {ctx} context · tasks done: {n}',
6459
+ newTopic: 'New topic',
6460
+ newTopicHint: 'Start a fresh conversation; memory carries over. You can also send /new.',
6461
+ newTopicDone: '{name} starts a new topic',
6462
+ topicDivider: 'New topic · {reason}',
6463
+ topicReason_manual: 'started by you',
6464
+ topicReason_idle: 'after a quiet spell',
6465
+ topicReason_context: 'the conversation grew large',
6466
+ pastTopic: '{from} – {to} · tasks: {n}',
6467
+ kind_topic: 'New topic',
6468
+ teamMemoryTitle: 'Team memory',
6469
+ teamMemoryHint: '{n} shared notes · daily digest',
6470
+ teamNotes: 'Shared notes',
6471
+ teamNotesHint: 'Every bot reads these. They hold what all of them should know: about you, your business, shared conventions.',
6472
+ digests: 'Daily digests',
6473
+ digestsHint: 'Each day the team’s work is written up; every bot reads the latest one.',
6474
+ noDigests: 'No digest yet.',
6475
+ teamJournal: 'Team journal',
6476
+ dreamNow: 'Consolidate now',
6477
+ dreaming: 'Consolidating…',
6478
+ dreamDone: 'Consolidated {bots} bots{digest}',
6479
+ dreamDigest: ' and wrote the digest',
6480
+ dreamPartly: 'Consolidation finished with a problem: {reason}',
6481
+ lastDream: 'Last consolidated {when}',
6482
+ dreamDaily: 'every day at {time}',
6483
+ neverDreamed: 'Not consolidated yet; it runs every day at {time}.',
6484
+ dreamOff: 'Daily consolidation is off.',
6485
+ settingsTitle: 'Bots settings',
6486
+ settingsSaved: 'Settings saved',
6487
+ setTopics: 'Topics',
6488
+ setIdle: 'New topic after this many quiet hours',
6489
+ setIdleHint: 'Checked before the next task. 0 = never.',
6490
+ setContext: 'New topic at this context size (thousand tokens)',
6491
+ setContextHint: 'Harness also compacts a conversation near the model’s limit; a new topic keeps every call small and cheap. 0 = never.',
6492
+ setMemory: 'Memory',
6493
+ setAuto: 'Summarize every task into memory',
6494
+ setAutoHint: 'One short model call per finished task. Off: only a one-line journal entry.',
6495
+ setMemoryModel: 'Model for memory work',
6496
+ setMemoryModelHint: 'Summaries and consolidation; a small, cheap model is enough.',
6497
+ setDream: 'Consolidate every day',
6498
+ setDreamHint: 'Merges repeated notes, drops stale ones and writes the team’s daily digest.',
6499
+ modelSources: 'Model sources',
6500
+ modelDefaultIs: 'Harness default ({model})',
6501
+ modelContext: 'context window {k} tokens',
6502
+ reasoning: 'Thinking',
6503
+ effortDefault: 'default',
6504
+ msrc_custom: 'your endpoint',
6505
+ msrc_login: 'subscription',
6506
+ sourcesTitle: 'Model sources',
6507
+ 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.',
6508
+ notWritable: 'This Harness does not let plugins change its model settings.',
6509
+ endpoints: 'Your endpoints',
6510
+ noEndpoints: 'None yet.',
6511
+ addEndpoint: 'Add endpoint',
6512
+ editEndpoint: 'Edit endpoint',
6513
+ epName: 'Name',
6514
+ epApi: 'API',
6515
+ epBase: 'Base URL',
6516
+ epKey: 'API key',
6517
+ epKeyHint: 'Kept in the Harness credential store and never shown again. Any text for a local server that needs none.',
6518
+ epKeyKeep: 'Leave empty to keep the saved key',
6519
+ epModels: 'Models',
6520
+ epModelsHint: 'One model id per line, or fetch the list from the endpoint and tick the ones you want.',
6521
+ fetchModels: 'Fetch models',
6522
+ fetching: 'Fetching…',
6523
+ fetchedN: '{n} models found',
6524
+ epSaved: 'Endpoint saved',
6525
+ epRemoved: 'Endpoint removed',
6526
+ epRemoveConfirm: 'Remove it? Bots on it go back to the default.',
6527
+ nModels: '{n} models',
6528
+ keySet: 'key saved',
6529
+ keyMissing: 'no key',
6530
+ logins: 'Logins on this computer',
6531
+ loginsHint: 'Subscriptions other agents on this Mac are signed in to.',
6532
+ loginNotFound: 'Not signed in on this computer.',
6533
+ loginConnected: 'In use · kept in sync with {name}',
6534
+ 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.',
6535
+ 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.',
6536
+ loginReason_harness: 'This Harness cannot use it yet.',
6537
+ loginReason_signin: 'Sign in from Harness Settings → Models instead.',
6538
+ useLogin: 'Use it',
6539
+ loginReady: '{name} is ready: pick its models in a bot’s profile',
6540
+ disconnect: 'Stop using',
5388
6541
  },
5389
6542
  zh: {
5390
6543
  lang: 'zh',
@@ -5790,6 +6943,12 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
5790
6943
  importedN: "已导入 {n} 个技能。",
5791
6944
  updatedN: "已更新 {n} 个。",
5792
6945
  skippedN: "跳过 {n} 个:已有同名技能。",
6946
+ fullN: "跳过 {n} 个:一个 Bot 最多放 {max} 个技能。",
6947
+ offN: "其中 {n} 个先关着:最多同时开 {max} 个技能。",
6948
+ tooManyOn: "最多同时开 {max} 个技能,先关掉一个。",
6949
+ skillsFull: "一个 Bot 最多放 {max} 个技能,先删掉一个。",
6950
+ skillsRoom: "一个 Bot 最多放 {max} 个技能,还能加 {n} 个。",
6951
+ skillsOnOf: "开着 {n}/{max}",
5793
6952
  nameTaken: "已有同名技能",
5794
6953
  reimport: "已导入 · 再次导入可更新",
5795
6954
  skillNameTaken: "这个 Bot 已经有名为“{name}”的技能。",
@@ -5901,6 +7060,176 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
5901
7060
  channelPrivate: '只有配对过的人能找到团队,其他人一律忽略(每天最多回一句“这是私人 Bot”)。在群里,只有 @ 它或回复它时才会回答。',
5902
7061
  viaChannel: '{app} · {who}',
5903
7062
  sentToChannel: '也已发到 {app}',
7063
+ // 用量、记忆、话题、设置、模型来源
7064
+ settings: '设置',
7065
+ usage: '用量',
7066
+ usageHint: '今天 {tokens} tokens',
7067
+ usageSub: '每个 Bot、每个任务、每一天的 tokens 和估算费用:对话、记忆整理和上下文压缩都算在内。',
7068
+ usageChart: '各 Bot 的 tokens',
7069
+ other: '其他',
7070
+ removedBot: '已删除的 Bot',
7071
+ range_today: '今天',
7072
+ range_7d: '7 天',
7073
+ range_30d: '30 天',
7074
+ range_90d: '90 天',
7075
+ range_all: '全部',
7076
+ prices: '价格',
7077
+ tileTokens: 'Tokens',
7078
+ tileCacheRate: '{pct}% 的输入命中缓存',
7079
+ tileCost: '估算费用',
7080
+ tileUnpriced: '{tokens} tokens 没有价格',
7081
+ tileTasks: '任务',
7082
+ tileCalls: '模型调用',
7083
+ tileInOut: '输入 {input} · 输出 {output}',
7084
+ vsPrev: '比上一期 {delta}',
7085
+ noUsage: '这段时间还没有模型调用。',
7086
+ byBot: '按 Bot',
7087
+ byModel: '按模型',
7088
+ byKind: '按用途',
7089
+ bySchedule: '定时任务',
7090
+ recentTasks: '最近的任务',
7091
+ colBot: 'Bot',
7092
+ colTask: '任务',
7093
+ colTasks: '任务',
7094
+ colTokens: 'Tokens',
7095
+ colCost: '费用',
7096
+ colCalls: '调用',
7097
+ colModel: '模型',
7098
+ colRuns: '次数',
7099
+ colWhen: '时间',
7100
+ work_chat: '对话',
7101
+ work_memory: '记忆总结',
7102
+ work_compaction: '上下文压缩',
7103
+ work_dream: '每日整理',
7104
+ trigger_user: '你发起',
7105
+ trigger_chat: '来自 {app}',
7106
+ trigger_schedule: '定时',
7107
+ trigger_dm: '来自 @{handle}',
7108
+ taskRunning: '进行中',
7109
+ taskState_error: '出错',
7110
+ taskState_stopped: '已停止',
7111
+ setPrice: '设价格',
7112
+ pricesTitle: '模型价格',
7113
+ pricesHint: '费用是估算:tokens × 每百万 tokens 的价格。优先用你填的价格,其次是 LiteLLM 公开价格表({count} 个模型,{when} 获取)。网关和订阅的实际计费可能不同。',
7114
+ priceInput: '输入 / 百万',
7115
+ priceCached: '缓存输入 / 百万',
7116
+ priceOutput: '输出 / 百万',
7117
+ priceCurrency: '币种',
7118
+ priceSource_user: '你填的价格',
7119
+ priceNone: '没有价格',
7120
+ usePriceList: '改用价格表',
7121
+ refreshPriceList: '刷新价格表',
7122
+ priceSaved: '价格已保存',
7123
+ tab_memory: '记忆',
7124
+ memoryOf: '{name} 记得的事',
7125
+ memoryHint: '跨对话、跨话题保留的笔记。{name} 会自己记:每个任务结束后自动总结,你让它记住的也会存进来;可以在这里直接修改。置顶的笔记不会被自动整理改动。',
7126
+ memoryModelIs: '记忆工作使用 {model}',
7127
+ botsOwnModel: '各 Bot 自己的模型',
7128
+ addNote: '添加一条笔记…',
7129
+ noteSaved: '笔记已保存',
7130
+ filterNotes: '筛选笔记',
7131
+ noNotes: '还没有记忆。任务完成后会自动出现,也可以手动添加。',
7132
+ note_fact: '事实',
7133
+ note_preference: '偏好',
7134
+ note_person: '人物',
7135
+ note_project: '项目',
7136
+ note_procedure: '做法',
7137
+ note_lesson: '教训',
7138
+ src_auto: '任务后总结',
7139
+ src_tool: 'Bot 自己记的',
7140
+ src_user: '你写的',
7141
+ src_dream: '整理后',
7142
+ pin: '置顶',
7143
+ unpin: '取消置顶',
7144
+ recentWork: '最近做过的事',
7145
+ recentWorkHint: '每完成一个任务记一行,任务结束时写入。',
7146
+ noJournal: '还没有完成的任务。',
7147
+ topicsTitle: '话题',
7148
+ topicsHint: '每个话题是一段新对话,上下文不会无限变长。发送 /new、闲置较久,或对话变得很长时(见设置)会开始新话题;记忆会延续下去。',
7149
+ topicNow: '当前话题:开始于{when} · {n} 个任务 · 最近一次提示 {ctx} tokens',
7150
+ topicShort: '本话题:上下文 {ctx} · 已完成 {n} 个任务',
7151
+ newTopic: '新话题',
7152
+ newTopicHint: '开始一段新对话,记忆会保留。也可以直接发送 /new。',
7153
+ newTopicDone: '{name} 开始了新话题',
7154
+ topicDivider: '新话题 · {reason}',
7155
+ topicReason_manual: '你开启的',
7156
+ topicReason_idle: '闲置后自动开启',
7157
+ topicReason_context: '对话太长自动开启',
7158
+ pastTopic: '{from} – {to} · {n} 个任务',
7159
+ kind_topic: '新话题',
7160
+ teamMemoryTitle: '团队记忆',
7161
+ teamMemoryHint: '{n} 条共享笔记 · 每日摘要',
7162
+ teamNotes: '共享笔记',
7163
+ teamNotesHint: '每个 Bot 都会读。放所有 Bot 都该知道的事:关于你、你的业务、团队约定。',
7164
+ digests: '每日摘要',
7165
+ digestsHint: '每天把团队做过的事写成摘要,每个 Bot 都会读最新的一份。',
7166
+ noDigests: '还没有摘要。',
7167
+ teamJournal: '团队工作日志',
7168
+ dreamNow: '立即整理',
7169
+ dreaming: '整理中…',
7170
+ dreamDone: '已整理 {bots} 个 Bot{digest}',
7171
+ dreamDigest: ',并写好了每日摘要',
7172
+ dreamPartly: '整理完成,但有问题:{reason}',
7173
+ lastDream: '上次整理:{when}',
7174
+ dreamDaily: '每天 {time}',
7175
+ neverDreamed: '还没整理过,每天 {time} 自动进行。',
7176
+ dreamOff: '每日整理已关闭。',
7177
+ settingsTitle: 'Bots 设置',
7178
+ settingsSaved: '设置已保存',
7179
+ setTopics: '话题',
7180
+ setIdle: '闲置多少小时后开新话题',
7181
+ setIdleHint: '在下一个任务开始前检查。0 表示不自动开。',
7182
+ setContext: '上下文达到多少千 tokens 时开新话题',
7183
+ setContextHint: 'Harness 自己会在接近模型上限时压缩对话;开新话题让每次调用都保持小而便宜。0 表示不自动开。',
7184
+ setMemory: '记忆',
7185
+ setAuto: '每个任务结束后总结进记忆',
7186
+ setAutoHint: '每完成一个任务调用一次模型。关闭后只记一行工作日志。',
7187
+ setMemoryModel: '记忆工作用的模型',
7188
+ setMemoryModelHint: '用于总结和整理,小而便宜的模型就够了。',
7189
+ setDream: '每天整理一次',
7190
+ setDreamHint: '合并重复的笔记、删掉过时的,并写团队每日摘要。',
7191
+ modelSources: '模型来源',
7192
+ modelDefaultIs: 'Harness 默认({model})',
7193
+ modelContext: '上下文窗口 {k} tokens',
7194
+ reasoning: '思考强度',
7195
+ effortDefault: '默认',
7196
+ msrc_custom: '自定义端点',
7197
+ msrc_login: '订阅',
7198
+ sourcesTitle: '模型来源',
7199
+ sourcesIntro: 'Bot 可以用 Harness 里的任何模型。你可以添加自己的端点,或者用这台电脑上其他 Agent 已经登录的订阅。两者都会成为 Harness 的模型提供方,也会出现在 设置 → 模型 和每个会话的模型选择里。',
7200
+ notWritable: '当前 Harness 不允许插件修改模型设置。',
7201
+ endpoints: '自定义端点',
7202
+ noEndpoints: '还没有。',
7203
+ addEndpoint: '添加端点',
7204
+ editEndpoint: '编辑端点',
7205
+ epName: '名称',
7206
+ epApi: '接口类型',
7207
+ epBase: 'Base URL',
7208
+ epKey: 'API Key',
7209
+ epKeyHint: '保存在 Harness 凭据库里,之后不再显示。不需要 key 的本地服务随便填点文字即可。',
7210
+ epKeyKeep: '留空则保留已保存的 key',
7211
+ epModels: '模型',
7212
+ epModelsHint: '每行一个模型 id;也可以从端点获取列表后勾选。',
7213
+ fetchModels: '获取模型列表',
7214
+ fetching: '获取中…',
7215
+ fetchedN: '找到 {n} 个模型',
7216
+ epSaved: '端点已保存',
7217
+ epRemoved: '端点已删除',
7218
+ epRemoveConfirm: '确定删除?用它的 Bot 会改回默认模型。',
7219
+ nModels: '{n} 个模型',
7220
+ keySet: '已存 key',
7221
+ keyMissing: '没有 key',
7222
+ logins: '本机其他 Agent 的登录',
7223
+ loginsHint: '这台 Mac 上其他 Agent 已经登录的订阅。',
7224
+ loginNotFound: '本机没有登录。',
7225
+ loginConnected: '使用中 · 与 {name} 保持同步',
7226
+ loginHint_codex: '通过 Codex CLI 的登录使用你的 ChatGPT 订阅。无论哪一边刷新了登录,另一边都会拿到新令牌(会原地更新 ~/.codex/auth.json),两边不会互相踢下线。',
7227
+ loginReason_terms: '不提供:Anthropic 只允许在 Claude Code 和 claude.ai 里使用 Claude 订阅。可以用 API Key 把 Claude 添加为自定义端点。',
7228
+ loginReason_harness: '当前 Harness 还不能使用它。',
7229
+ loginReason_signin: '请改在 Harness 设置 → 模型里登录。',
7230
+ useLogin: '使用',
7231
+ loginReady: '{name} 已就绪:在 Bot 资料页里选它的模型',
7232
+ disconnect: '停用',
5904
7233
  },
5905
7234
  };
5906
7235