@kadaliao/dsh-bots 0.7.1 → 0.9.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/README.md +255 -45
- package/README.zh-CN.md +182 -31
- package/client.js +2622 -246
- package/index.js +2472 -133
- package/lib/activity.mjs +221 -0
- package/lib/cards.mjs +582 -0
- package/lib/channels/discord.mjs +91 -11
- package/lib/channels/feishu.mjs +37 -9
- package/lib/channels/slack.mjs +26 -8
- package/lib/channels/telegram.mjs +37 -6
- package/lib/channels.mjs +399 -89
- package/lib/memory.mjs +37 -0
- package/lib/prompt.mjs +221 -20
- package/lib/settings.mjs +41 -2
- package/lib/store.mjs +60 -6
- package/lib/threads.mjs +460 -0
- package/lib/tickets.mjs +726 -0
- package/lib/usage.mjs +53 -7
- package/lib/watchdog.mjs +216 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -22,6 +22,8 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
const PANEL_ID = 'bots';
|
|
23
23
|
const R = '/__dsh_bots/';
|
|
24
24
|
const STATE_POLL_MS = 5000;
|
|
25
|
+
/** While a bot works (or a picture is being drawn), its live status is polled this often (`activity`, a small answer). */
|
|
26
|
+
const LIVE_POLL_MS = 1500;
|
|
25
27
|
const CHAT_POLL_MS = 3000;
|
|
26
28
|
const SCHEDULE_POLL_MS = 10000;
|
|
27
29
|
const TOOL_NAMES = ['bot_send_message', 'bot_create', 'bot_update', 'bot_delete', 'bot_list', 'bot_schedule'];
|
|
@@ -34,6 +36,8 @@ window.__ModuleLoader__.load({
|
|
|
34
36
|
border: 'var(--dsw-alias-border-l2, rgba(127,127,127,.25))',
|
|
35
37
|
border1: 'var(--dsw-alias-border-l1, rgba(127,127,127,.15))',
|
|
36
38
|
label: 'var(--dsw-alias-brand-primary)',
|
|
39
|
+
// Text on a brand fill (a primary button, your own message): white on a colour, dark on the white of a dark theme.
|
|
40
|
+
onLabel: 'var(--dsw-alias-label-primary-foreground, #fff)',
|
|
37
41
|
primary: 'var(--dsw-alias-label-primary)',
|
|
38
42
|
muted: 'var(--dsw-alias-label-secondary)',
|
|
39
43
|
faint: 'var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary))',
|
|
@@ -140,8 +144,16 @@ window.__ModuleLoader__.load({
|
|
|
140
144
|
teams: null,
|
|
141
145
|
library: null,
|
|
142
146
|
external: null,
|
|
143
|
-
|
|
147
|
+
settings: null,
|
|
148
|
+
nav: { botId: null, view: null, ticket: null, tick: 0 },
|
|
144
149
|
focusBound: false,
|
|
150
|
+
tickets: new Map(),
|
|
151
|
+
// The quick poll of what runs now (`activity`), and when it and the state last arrived.
|
|
152
|
+
live: null,
|
|
153
|
+
liveAt: 0,
|
|
154
|
+
stateAt: 0,
|
|
155
|
+
liveTimer: null,
|
|
156
|
+
liveInflight: null,
|
|
145
157
|
};
|
|
146
158
|
const notify = () => {
|
|
147
159
|
for (const fn of [...store.subs]) {
|
|
@@ -164,6 +176,8 @@ window.__ModuleLoader__.load({
|
|
|
164
176
|
.then((s) => {
|
|
165
177
|
if (s && Array.isArray(s.bots)) {
|
|
166
178
|
store.state = s;
|
|
179
|
+
store.stateAt = Date.now();
|
|
180
|
+
if (Number.isFinite(s.at)) store.skew = s.at - Date.now();
|
|
167
181
|
store.failed = false;
|
|
168
182
|
} else if (!store.state) store.failed = true;
|
|
169
183
|
})
|
|
@@ -185,6 +199,38 @@ window.__ModuleLoader__.load({
|
|
|
185
199
|
}
|
|
186
200
|
};
|
|
187
201
|
const onFocus = () => void refreshState();
|
|
202
|
+
/** Whether anything runs now: a bot at work, a task's conversation, a picture being drawn. */
|
|
203
|
+
function busyNow() {
|
|
204
|
+
const fresh = store.live && store.liveAt > store.stateAt;
|
|
205
|
+
if (fresh) return Object.values(store.live.bots ?? {}).some((b) => b?.status === 'running' || b?.activity || b?.avatarPending) || Object.keys(store.live.taskActivity ?? {}).length > 0;
|
|
206
|
+
return botsOf().some((b) => b.status === 'running' || b.activity || b.avatarPending) || Object.keys(store.state?.taskActivity ?? {}).length > 0;
|
|
207
|
+
}
|
|
208
|
+
/** What runs now, polled quickly while something does; a bot that stopped or a task that finished brings the whole state. */
|
|
209
|
+
function refreshLive() {
|
|
210
|
+
if (store.liveInflight) return store.liveInflight;
|
|
211
|
+
let p;
|
|
212
|
+
try {
|
|
213
|
+
p = Promise.resolve(getJson('activity'));
|
|
214
|
+
} catch {
|
|
215
|
+
p = Promise.resolve(null);
|
|
216
|
+
}
|
|
217
|
+
store.liveInflight = p
|
|
218
|
+
.then((r) => {
|
|
219
|
+
if (!r || typeof r.bots !== 'object' || !r.bots) return;
|
|
220
|
+
const before = { bots: Object.fromEntries(botsOf().map((b) => [b.id, liveBot(b)])), tasks: Object.keys(liveTasks()) };
|
|
221
|
+
store.live = r;
|
|
222
|
+
store.liveAt = Date.now();
|
|
223
|
+
if (Number.isFinite(r.at)) store.skew = r.at - Date.now();
|
|
224
|
+
const ended = Object.entries(r.bots).some(([id, x]) => before.bots[id] && (before.bots[id].status === 'running') !== (x?.status === 'running')) || before.tasks.some((id) => !r.taskActivity?.[id]) || Object.entries(r.bots).some(([id, x]) => before.bots[id]?.avatarPending && !x?.avatarPending);
|
|
225
|
+
notify();
|
|
226
|
+
if (ended) void refreshState();
|
|
227
|
+
})
|
|
228
|
+
.catch(() => {})
|
|
229
|
+
.then(() => {
|
|
230
|
+
store.liveInflight = null;
|
|
231
|
+
});
|
|
232
|
+
return store.liveInflight;
|
|
233
|
+
}
|
|
188
234
|
function subscribe(fn) {
|
|
189
235
|
store.subs.add(fn);
|
|
190
236
|
if (store.subs.size === 1) {
|
|
@@ -197,6 +243,14 @@ window.__ModuleLoader__.load({
|
|
|
197
243
|
} catch {
|
|
198
244
|
store.timer = null;
|
|
199
245
|
}
|
|
246
|
+
try {
|
|
247
|
+
store.liveTimer = setInterval(() => {
|
|
248
|
+
if (visible() && busyNow()) void refreshLive();
|
|
249
|
+
}, LIVE_POLL_MS);
|
|
250
|
+
store.liveTimer?.unref?.();
|
|
251
|
+
} catch {
|
|
252
|
+
store.liveTimer = null;
|
|
253
|
+
}
|
|
200
254
|
try {
|
|
201
255
|
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
202
256
|
window.addEventListener('focus', onFocus);
|
|
@@ -211,10 +265,12 @@ window.__ModuleLoader__.load({
|
|
|
211
265
|
if (store.subs.size === 0) {
|
|
212
266
|
try {
|
|
213
267
|
if (store.timer) clearInterval(store.timer);
|
|
268
|
+
if (store.liveTimer) clearInterval(store.liveTimer);
|
|
214
269
|
} catch {
|
|
215
270
|
// Gone already.
|
|
216
271
|
}
|
|
217
272
|
store.timer = null;
|
|
273
|
+
store.liveTimer = null;
|
|
218
274
|
try {
|
|
219
275
|
if (store.focusBound) window.removeEventListener('focus', onFocus);
|
|
220
276
|
} catch {
|
|
@@ -280,17 +336,91 @@ window.__ModuleLoader__.load({
|
|
|
280
336
|
const teamsOf = () => (Array.isArray(store.teams) ? store.teams : []);
|
|
281
337
|
const botsOf = () => (Array.isArray(store.state?.bots) ? store.state.bots : []);
|
|
282
338
|
const botById = (id) => botsOf().find((b) => b.id === id) ?? null;
|
|
339
|
+
/** Whether the quick poll is newer than the state. */
|
|
340
|
+
const liveFresh = () => Boolean(store.live) && store.liveAt > store.stateAt;
|
|
341
|
+
/** A bot's live fields: `{status, activity, avatarPending}` from whichever of the state and the quick poll is newer. */
|
|
342
|
+
function liveBot(bot) {
|
|
343
|
+
const x = liveFresh() ? store.live.bots?.[bot?.id] : null;
|
|
344
|
+
if (x) return { status: x.status ?? bot.status, activity: x.activity ?? null, avatarPending: x.avatarPending === true };
|
|
345
|
+
return { status: bot?.status, activity: bot?.activity ?? null, avatarPending: bot?.avatarPending === true };
|
|
346
|
+
}
|
|
347
|
+
/** Task id → what its conversation does now (with `botId`, `title`), from the newer of the state and the quick poll. */
|
|
348
|
+
function liveTasks() {
|
|
349
|
+
const map = liveFresh() ? store.live.taskActivity : store.state?.taskActivity;
|
|
350
|
+
return map && typeof map === 'object' ? map : {};
|
|
351
|
+
}
|
|
352
|
+
/** What one task's conversation does now, or null. */
|
|
353
|
+
const liveTask = (id) => (id ? liveTasks()[id] ?? null : null);
|
|
283
354
|
/** A bot by id, @handle or name, as a model writes it. */
|
|
284
355
|
function findBot(ref) {
|
|
285
356
|
if (!ref || typeof ref !== 'string') return null;
|
|
286
357
|
const key = ref.trim().replace(/^@/, '').toLowerCase();
|
|
287
358
|
return botsOf().find((b) => b.id === ref || String(b.handle).toLowerCase() === key || String(b.name).toLowerCase() === key) ?? null;
|
|
288
359
|
}
|
|
289
|
-
/** Ask the panel to show `botId` (or a view) once it renders. */
|
|
290
|
-
function navigate(botId, view = null) {
|
|
291
|
-
store.nav = { botId: botId ?? null, view, tick: store.nav.tick + 1 };
|
|
360
|
+
/** Ask the panel to show `botId` (or a view, or one task) once it renders. */
|
|
361
|
+
function navigate(botId, view = null, ticket = null) {
|
|
362
|
+
store.nav = { botId: botId ?? null, view, ticket: ticket ?? null, tick: store.nav.tick + 1 };
|
|
292
363
|
notify();
|
|
293
364
|
}
|
|
365
|
+
/** Show one task's detail in the panel. */
|
|
366
|
+
const openTicket = (id) => navigate(null, 'tasks', id);
|
|
367
|
+
|
|
368
|
+
// --- tasks (tickets in the Host; "tasks" on screen) ----------------------------------
|
|
369
|
+
|
|
370
|
+
/** How the dispatcher works ('router' | 'hands-on'), a team setting: the polled state's, else the settings'; router unless either says otherwise. */
|
|
371
|
+
const dispatcherOf = () => {
|
|
372
|
+
const v = store.state?.dispatcher ?? store.settings?.settings?.dispatcher;
|
|
373
|
+
return v === 'hands-on' ? 'hands-on' : 'router';
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Whether the dispatcher routes now: router mode, and a teammate to hand work to (the Host's
|
|
377
|
+
* `routerActive`). The only bot of a team works hands-on whatever the setting says.
|
|
378
|
+
*/
|
|
379
|
+
const routerActiveOf = (state = store.state) => dispatcherOf() === 'router' && state?.routerActive !== false;
|
|
380
|
+
/** Keep the shared copies of the settings after a save, so the page shows them before the next poll. */
|
|
381
|
+
function tookSettings(next) {
|
|
382
|
+
if (next && typeof next === 'object') {
|
|
383
|
+
store.settings = { ...(store.settings ?? {}), settings: next };
|
|
384
|
+
// Until the next poll says, router mode is in effect when the dispatcher has a teammate.
|
|
385
|
+
if (store.state && typeof next.dispatcher === 'string') store.state = { ...store.state, dispatcher: next.dispatcher, routerActive: next.dispatcher === 'router' && (store.state.bots?.length ?? 0) > 1 };
|
|
386
|
+
// Chats show the new level of bot-to-bot detail at once.
|
|
387
|
+
if (store.state && next.display && typeof next.display === 'object') store.state = { ...store.state, display: next.display };
|
|
388
|
+
notify();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
/** The one-time notice after an upgrade moved the dispatcher to router mode; its Host names live here only. */
|
|
392
|
+
// It waits while the dispatcher is the only bot: there is nothing to hand out yet.
|
|
393
|
+
const routerNotice = {
|
|
394
|
+
pending: (state) => state?.routerNoticePending === true && routerActiveOf(state),
|
|
395
|
+
dismiss: () => postJson('router-notice/dismiss', {}),
|
|
396
|
+
};
|
|
397
|
+
/** One task as the Host shows it, shared by every card on the page and refreshed when older than `maxAge`. */
|
|
398
|
+
function loadTicket(id, maxAge = 10_000) {
|
|
399
|
+
if (!id) return Promise.resolve(null);
|
|
400
|
+
const hit = store.tickets.get(id);
|
|
401
|
+
if (hit?.p) return hit.p;
|
|
402
|
+
if (hit && Date.now() - hit.at < maxAge) return Promise.resolve(hit.view);
|
|
403
|
+
const p = Promise.resolve()
|
|
404
|
+
.then(() => getJson(`tickets/${encodeURIComponent(id)}`))
|
|
405
|
+
.then((r) => {
|
|
406
|
+
const view = ticketViewOf(r);
|
|
407
|
+
store.tickets.set(id, { view: view ?? hit?.view ?? null, at: Date.now() });
|
|
408
|
+
notify();
|
|
409
|
+
return view;
|
|
410
|
+
})
|
|
411
|
+
.catch(() => {
|
|
412
|
+
store.tickets.set(id, { view: hit?.view ?? null, at: Date.now() });
|
|
413
|
+
return null;
|
|
414
|
+
});
|
|
415
|
+
store.tickets.set(id, { ...(hit ?? { view: null }), at: hit?.at ?? 0, p });
|
|
416
|
+
return p;
|
|
417
|
+
}
|
|
418
|
+
/** A TicketView from a route's answer: the view itself, or `{ticket: view}`. */
|
|
419
|
+
function ticketViewOf(r) {
|
|
420
|
+
if (!r || typeof r !== 'object' || r.ok === false) return null;
|
|
421
|
+
if (r.ticket && typeof r.ticket === 'object') return r.ticket;
|
|
422
|
+
return typeof r.id === 'string' ? r : null;
|
|
423
|
+
}
|
|
294
424
|
|
|
295
425
|
// --- small utilities -------------------------------------------------------------
|
|
296
426
|
|
|
@@ -495,6 +625,7 @@ window.__ModuleLoader__.load({
|
|
|
495
625
|
user: (s = 14) => svg(s, ['M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8z', 'M4 20a8 8 0 0 1 16 0']),
|
|
496
626
|
refresh: (s = 14) => svg(s, ['M20 11a8 8 0 1 0-2.3 5.7', 'M20 4v7h-7']),
|
|
497
627
|
alert: (s = 14) => svg(s, ['M12 4l9 16H3l9-16z', 'M12 10v4', 'M12 17h.01']),
|
|
628
|
+
question: (s = 14) => svg(s, ['M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18z', 'M9.6 9.4a2.5 2.5 0 1 1 3.4 2.4c-.6.3-1 .8-1 1.5v.4', 'M12 17h.01']),
|
|
498
629
|
download: (s = 14) => svg(s, ['M12 4v12', 'M7 11l5 5 5-5', 'M4 20h16']),
|
|
499
630
|
eye: (s = 14) => svg(s, ['M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z', 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z']),
|
|
500
631
|
eyeOff: (s = 14) => svg(s, ['M3 3l18 18', 'M10.6 5.1A10.7 10.7 0 0 1 12 5c6.5 0 10 7 10 7a17 17 0 0 1-3.2 4.1', 'M6.6 6.6A17 17 0 0 0 2 12s3.5 7 10 7a10 10 0 0 0 5.4-1.6', 'M9.9 9.9a3 3 0 0 0 4.2 4.2']),
|
|
@@ -504,6 +635,9 @@ window.__ModuleLoader__.load({
|
|
|
504
635
|
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
636
|
wand: (s = 14) => svg(s, ['M4 20l11-11', 'M13 7l4 4', 'M18 3v4', 'M16 5h4', 'M8 3v2', 'M7 4h2']),
|
|
506
637
|
chevron: (s = 12) => svg(s, ['M6 9l6 6 6-6']),
|
|
638
|
+
back: (s = 12) => svg(s, ['M19 12H5', 'M11 6l-6 6 6 6']),
|
|
639
|
+
tasks: (s = 14) => svg(s, ['M10 6h10', 'M10 12h10', 'M10 18h10', 'M3.5 6l1.5 1.5L7.5 5', 'M3.5 12l1.5 1.5 2.5-2.5', 'M3.5 18l1.5 1.5 2.5-2.5']),
|
|
640
|
+
stop: (s = 13) => svg(s, ['M7 7h10v10H7z']),
|
|
507
641
|
chart: (s = 14) => svg(s, ['M4 20V10', 'M10 20V4', 'M16 20v-7', 'M21 20H3']),
|
|
508
642
|
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
643
|
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']),
|
|
@@ -534,7 +668,7 @@ window.__ModuleLoader__.load({
|
|
|
534
668
|
.dshb-btn:hover{background:${C.hover}}
|
|
535
669
|
.dshb-btn:focus-visible{outline:2px solid ${C.label};outline-offset:1px}
|
|
536
670
|
.dshb-btn:disabled{opacity:.45;cursor:default}
|
|
537
|
-
.dshb-btn-primary{background:${C.label};border-color:transparent;color
|
|
671
|
+
.dshb-btn-primary{background:${C.label};border-color:transparent;color:${C.onLabel}}
|
|
538
672
|
.dshb-btn-primary:hover{background:${C.label};filter:brightness(1.1)}
|
|
539
673
|
.dshb-btn-ghost{background:transparent;border-color:transparent;color:${C.muted}}
|
|
540
674
|
.dshb-btn-ghost:hover{color:${C.primary}}
|
|
@@ -562,7 +696,7 @@ select.dshb-input{padding-right:6px}
|
|
|
562
696
|
.dshb-chip:hover{color:${C.primary};background:${C.hover}}
|
|
563
697
|
.dshb-chip[data-active=true]{color:${C.label};border-color:${C.label};background:${tint(C.label, 10)}}
|
|
564
698
|
.dshb-scroll{overflow:auto;scrollbar-width:thin;min-height:0}
|
|
565
|
-
.dshb-spinner{display:inline-block;flex:none;width:14px;height:14px;border-radius:50%;border:2px solid ${tint(C.label, 25)};border-top-color:${C.label};animation:dshb-spin .8s linear infinite}
|
|
699
|
+
.dshb-spinner{display:inline-block;flex:none;width:14px;height:14px;border-radius:50%;corner-shape:round;border:2px solid ${tint(C.label, 25)};border-top-color:${C.label};animation:dshb-spin .8s linear infinite}
|
|
566
700
|
.dshb-appcard{display:flex;flex-direction:column;gap:8px;padding:12px;border:1px solid ${C.border1};border-radius:12px;background:${C.layer1};transition:border-color .12s,box-shadow .12s;min-width:0}
|
|
567
701
|
.dshb-appcard:hover{border-color:${C.border};box-shadow:0 2px 10px rgba(0,0,0,.06)}
|
|
568
702
|
.dshb-clamp2{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
@@ -582,7 +716,7 @@ select.dshb-input{padding-right:6px}
|
|
|
582
716
|
.dshb-fade{animation:dshb-in .18s ease-out}
|
|
583
717
|
.dshb-md{white-space:pre-wrap;word-break:break-word;user-select:text}
|
|
584
718
|
.dshb-md a{color:inherit;text-decoration:underline;text-underline-offset:2px;word-break:break-all}
|
|
585
|
-
.dshb-md-light a{color
|
|
719
|
+
.dshb-md-light a{color:inherit}
|
|
586
720
|
.dshb-rich{min-width:0;word-break:break-word;user-select:text;overflow-wrap:anywhere}
|
|
587
721
|
.dshb-rich table{border-collapse:collapse;font-size:${SMALL};margin:6px 0}
|
|
588
722
|
.dshb-rich th,.dshb-rich td{border:1px solid ${C.border};padding:5px 9px;vertical-align:top;text-align:left}
|
|
@@ -617,6 +751,72 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
617
751
|
.dshb-play{position:absolute;inset:0;border:none;padding:0;margin:0;cursor:pointer;background:#000;display:block;width:100%;height:100%}
|
|
618
752
|
.dshb-play-btn{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);display:inline-flex;filter:drop-shadow(0 2px 6px rgba(0,0,0,.45));transition:transform .15s}
|
|
619
753
|
.dshb-play:hover .dshb-play-btn{transform:translate(-50%,-50%) scale(1.08)}
|
|
754
|
+
.dshb-act-code{font-family:var(--dsh-code-font, ui-monospace, SFMono-Regular, Menlo, monospace);font-size:.9em;padding:1px 5px;border-radius:5px;background:${C.layer3}}
|
|
755
|
+
.dshb-act-detail{font-weight:600}
|
|
756
|
+
.dshb-live{min-width:0}
|
|
757
|
+
.dshb-liveline{display:inline-flex;align-items:baseline;gap:4px;max-width:100%;min-width:0;vertical-align:bottom}
|
|
758
|
+
.dshb-liveline-words{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
759
|
+
.dshb-liveline .dshb-act-code{background:none;padding:0}
|
|
760
|
+
.dshb-live-time{color:${C.faint};font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
761
|
+
.dshb-dots{display:inline-flex;gap:3px;align-items:center;flex:none;align-self:center}
|
|
762
|
+
.dshb-dots i{width:4px;height:4px;border-radius:50%;background:${C.faint};animation:dshb-blink 1.2s infinite}
|
|
763
|
+
.dshb-dots i:nth-child(2){animation-delay:.2s}
|
|
764
|
+
.dshb-dots i:nth-child(3){animation-delay:.4s}
|
|
765
|
+
.dshb-livechip{display:inline-flex;align-items:center;gap:5px;height:20px;padding:0 8px;border-radius:999px;font-size:${TINY};font-weight:600;color:${C.ok};background:${tint(C.ok, 12)};max-width:300px;min-width:0;flex:0 0 auto;white-space:nowrap}
|
|
766
|
+
.dshb-livechip .dshb-act-code{background:none;padding:0;font-size:1em}
|
|
767
|
+
.dshb-livechip .dshb-live-time{color:inherit;opacity:.75}
|
|
768
|
+
.dshb-avring{position:absolute;inset:-3px;border-radius:50%;pointer-events:none}
|
|
769
|
+
.dshb-avring-pending{inset:-4px;corner-shape:round;border:2px solid ${tint(C.label, 14)};border-top-color:${C.label};border-right-color:${C.label};animation:dshb-spin 1.2s linear infinite}
|
|
770
|
+
.dshb-avring-working{box-shadow:0 0 0 0 ${tint(C.ok, 50)};animation:dshb-breathe 1.8s ease-out infinite}
|
|
771
|
+
.dshb-traffic{display:flex;flex-direction:column;gap:1px;margin:4px 0 6px 40px;padding:1px 0 1px 6px;border-left:2px solid ${C.border1};min-width:0}
|
|
772
|
+
.dshb-traffic[data-level=short]{gap:4px}
|
|
773
|
+
.dshb-traffic[data-level=full]{gap:10px;padding:2px 0 2px 8px}
|
|
774
|
+
.dshb-titem{display:flex;flex-direction:column;min-width:0;border-radius:8px}
|
|
775
|
+
.dshb-tline{display:flex;align-items:center;gap:6px;width:100%;min-width:0;min-height:28px;padding:3px 8px;border:none;border-radius:7px;background:transparent;color:${C.muted};font:inherit;font-size:${SMALL};line-height:1.35;text-align:left;cursor:pointer;transition:background .1s}
|
|
776
|
+
button.dshb-tline:hover{background:${C.hover}}
|
|
777
|
+
.dshb-tline:focus-visible{outline:2px solid ${C.label};outline-offset:-2px}
|
|
778
|
+
.dshb-tname{font-weight:600;color:${C.primary};white-space:nowrap;flex:none}
|
|
779
|
+
.dshb-tsubject{flex:1 1 0;min-width:40px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
780
|
+
.dshb-ttime{flex:none;min-width:58px;text-align:right;color:${C.faint};font-size:${TINY};font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
781
|
+
.dshb-tbody{padding:0 8px 4px 30px;font-size:${SMALL};color:${C.muted};line-height:1.5;min-width:0}
|
|
782
|
+
.dshb-titem[data-level=full] .dshb-tbody{padding:2px 8px 4px 30px;display:flex;flex-direction:column;gap:6px}
|
|
783
|
+
.dshb-reply{font-size:${FONT};line-height:1.65;color:${C.primary};min-width:0}
|
|
784
|
+
.dshb-reply [data-dsh-bots-md] > div{font:inherit;color:inherit}
|
|
785
|
+
.dshb-reply [data-dsh-bots-md] p{margin:0 0 9px}
|
|
786
|
+
.dshb-reply [data-dsh-bots-md] :is(ul,ol){margin:0 0 9px}
|
|
787
|
+
.dshb-reply [data-dsh-bots-md] li{margin:3px 0}
|
|
788
|
+
.dshb-seg{display:inline-flex;padding:2px;border-radius:9px;background:${C.layer2};border:1px solid ${C.border1};flex:none}
|
|
789
|
+
.dshb-seg button{height:26px;padding:0 11px;border:none;border-radius:7px;background:transparent;color:${C.muted};font:inherit;font-size:${SMALL};font-weight:550;cursor:pointer;white-space:nowrap}
|
|
790
|
+
.dshb-seg button:hover{color:${C.primary}}
|
|
791
|
+
.dshb-seg button[data-active=true]{background:${C.layer1};color:${C.primary};box-shadow:0 1px 2px rgba(0,0,0,.12),0 0 0 1px ${C.border1}}
|
|
792
|
+
.dshb-chatwrap{display:flex;flex:1;min-height:0;min-width:0;position:relative;container-type:inline-size}
|
|
793
|
+
.dshb-chatmain{display:flex;flex-direction:column;flex:1;min-width:0;min-height:0}
|
|
794
|
+
.dshb-composer{display:flex;flex-direction:column;gap:6px;padding:6px;border-radius:14px;border:1px solid ${C.border};background:${C.layer1};min-width:0}
|
|
795
|
+
.dshb-quote{display:flex;align-items:center;gap:6px;min-width:0;padding:5px 8px;border-radius:9px;background:${tint(C.label, 9)};border-left:3px solid ${C.label};font-size:${TINY}}
|
|
796
|
+
.dshb-msg{position:relative;min-width:0}
|
|
797
|
+
.dshb-msg-act{display:inline-flex;align-items:center;gap:4px;height:22px;padding:0 8px;border-radius:7px;border:1px solid ${C.border1};background:${C.base};color:${C.muted};font:inherit;font-size:${TINY};cursor:pointer;opacity:0;transition:opacity .12s;flex:none;white-space:nowrap}
|
|
798
|
+
.dshb-msg:hover .dshb-msg-act,.dshb-msg:focus-within .dshb-msg-act,.dshb-msg-act:focus-visible{opacity:1}
|
|
799
|
+
.dshb-msg-act:hover{color:${C.primary};background:${C.hover}}
|
|
800
|
+
.dshb-msg-actbox{position:absolute;top:0;right:0;z-index:1}
|
|
801
|
+
@media (hover:none){.dshb-msg-act{opacity:.65}}
|
|
802
|
+
.dshb-topicbar{display:flex;flex-direction:column;gap:5px;width:min(520px,100%);min-width:0;padding:8px 11px;border:1px solid ${C.border1};border-radius:11px;background:${C.layer1};font-size:${SMALL};cursor:pointer;text-align:left;transition:border-color .12s,background .12s}
|
|
803
|
+
.dshb-topicbar:hover{border-color:${C.border};background:${C.layer2}}
|
|
804
|
+
.dshb-topicbar:focus-visible{outline:2px solid ${C.label};outline-offset:1px}
|
|
805
|
+
.dshb-topicbar[data-unread=true]{border-color:${tint(C.label, 45)}}
|
|
806
|
+
.dshb-topicbar[data-flash=true]{animation:dshb-flash 1.8s ease-out}
|
|
807
|
+
.dshb-topictask{display:flex;align-items:center;gap:6px;width:100%;min-width:0;min-height:26px;padding:2px 6px;border:none;border-radius:7px;background:${C.base};color:${C.primary};font:inherit;font-size:${TINY};text-align:left;cursor:pointer}
|
|
808
|
+
.dshb-topictask:hover{background:${C.hover}}
|
|
809
|
+
.dshb-moved{display:inline-flex;align-items:center;gap:6px;max-width:min(520px,100%);min-width:0;font-size:${TINY};color:${C.muted}}
|
|
810
|
+
.dshb-moved:hover{color:${C.label}}
|
|
811
|
+
.dshb-pillrow{position:absolute;left:0;right:0;top:-42px;display:flex;justify-content:center;pointer-events:none;z-index:2}
|
|
812
|
+
.dshb-pill{pointer-events:auto;display:inline-flex;align-items:center;gap:7px;height:30px;padding:0 13px;border-radius:999px;border:1px solid ${C.border};background:${C.base};color:${C.primary};font:inherit;font-size:${SMALL};font-weight:600;cursor:pointer;box-shadow:0 4px 14px rgba(0,0,0,.14);max-width:calc(100% - 32px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
813
|
+
.dshb-pill:hover{background:${C.layer2}}
|
|
814
|
+
.dshb-threadpane{width:420px;flex:none;display:flex;flex-direction:column;min-height:0;min-width:0;border-left:1px solid ${C.border1};background:${C.base}}
|
|
815
|
+
.dshb-threadhead{display:flex;align-items:center;gap:10px;padding:12px 12px 10px 16px;border-bottom:1px solid ${C.border1};min-width:0}
|
|
816
|
+
@container (max-width: 860px){.dshb-threadpane{position:absolute;inset:0;width:auto;z-index:6;border-left:none}}
|
|
817
|
+
@media (max-width: 760px){.dshb-threadpane{position:absolute;inset:0;width:auto;z-index:6;border-left:none}}
|
|
818
|
+
@keyframes dshb-flash{0%{box-shadow:0 0 0 3px ${tint(C.label, 50)}}100%{box-shadow:0 0 0 0 ${tint(C.label, 0)}}}
|
|
819
|
+
@keyframes dshb-breathe{0%{box-shadow:0 0 0 0 ${tint(C.ok, 45)}}70%{box-shadow:0 0 0 5px ${tint(C.ok, 0)}}100%{box-shadow:0 0 0 0 ${tint(C.ok, 0)}}}
|
|
620
820
|
@keyframes dshb-pulse{0%{box-shadow:0 0 0 0 rgba(34,197,94,.6)}70%{box-shadow:0 0 0 5px rgba(34,197,94,0)}100%{box-shadow:0 0 0 0 rgba(34,197,94,0)}}
|
|
621
821
|
@keyframes dshb-in{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
|
|
622
822
|
@keyframes dshb-blink{0%,100%{opacity:.25}50%{opacity:1}}
|
|
@@ -700,7 +900,11 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
700
900
|
);
|
|
701
901
|
|
|
702
902
|
/** A circle: initials on a colour, or the uploaded / generated picture. */
|
|
703
|
-
|
|
903
|
+
/**
|
|
904
|
+
* A circle: initials on a colour, or the uploaded / generated picture. `pending`: a new picture is
|
|
905
|
+
* being drawn (a turning arc); `working`: it works right now (a soft pulse).
|
|
906
|
+
*/
|
|
907
|
+
function Avatar({ avatar, name, size = 32, status, title, ring, pending, working }) {
|
|
704
908
|
const a = avatar && typeof avatar === 'object' ? avatar : { kind: 'initials', color: COLORS[0] };
|
|
705
909
|
const color = str(a.color) || COLORS[0];
|
|
706
910
|
const letters = avatarLetters(a, name);
|
|
@@ -748,6 +952,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
748
952
|
},
|
|
749
953
|
},
|
|
750
954
|
face,
|
|
955
|
+
pending ? h('span', { className: 'dshb-avring dshb-avring-pending', 'data-dsh-bots-avatar-pending': true, title: undefined }) : working ? h('span', { className: 'dshb-avring dshb-avring-working' }) : null,
|
|
751
956
|
status ? h(StatusDot, { status, size: dot, style: { position: 'absolute', right: -1, bottom: -1, boxShadow: `0 0 0 2px ${C.base}` } }) : null,
|
|
752
957
|
);
|
|
753
958
|
}
|
|
@@ -970,7 +1175,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
970
1175
|
return groups.sort((a, b) => (a.id === '' ? 1 : b.id === '' ? -1 : 0)).map((g) => ({ ...g, label: label(g.id) }));
|
|
971
1176
|
}
|
|
972
1177
|
|
|
973
|
-
|
|
1178
|
+
/** A red count of what needs you (tasks, or a bot's questions). */
|
|
1179
|
+
const NeedsBadge = ({ n, label, attr }) =>
|
|
1180
|
+
h('span', { [attr]: n, 'aria-label': label, title: label, style: { minWidth: 20, height: 20, padding: '0 6px', borderRadius: 999, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.error, color: '#fff', fontSize: TINY, fontWeight: 700, fontVariantNumeric: 'tabular-nums', flex: 'none' } }, n > 99 ? '99+' : String(n));
|
|
1181
|
+
function Rail({ t, bots, primaryId, selected, onSelect, onNew, onTeams, view, onActivity, messageCount, onUsage, onMemory, onSettings, teamNotes, onTasks, attention = 0, openTasks = 0 }) {
|
|
974
1182
|
const lang = langOf(t);
|
|
975
1183
|
const [q, setQ] = useState('');
|
|
976
1184
|
const [menu, setMenu] = useState(false);
|
|
@@ -979,11 +1187,15 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
979
1187
|
.filter((b) => !needle || [b.name, b.handle, b.bio].some((s) => str(s).toLowerCase().includes(needle)))
|
|
980
1188
|
.sort((a, b) => (a.id === primaryId ? -1 : b.id === primaryId ? 1 : 0));
|
|
981
1189
|
const groups = needle ? null : groupByTeam(t, lang, shown);
|
|
982
|
-
const row = (b) =>
|
|
983
|
-
|
|
1190
|
+
const row = (b) => {
|
|
1191
|
+
// At work: its own conversation, else the freshest of its tasks; the line under its name says what it does.
|
|
1192
|
+
const live = liveBot(b);
|
|
1193
|
+
const work = live.activity ? live.activity : botTaskActivity(b.id);
|
|
1194
|
+
const status = live.status === 'running' || work ? 'running' : (live.status ?? 'offline');
|
|
1195
|
+
return h(
|
|
984
1196
|
'button',
|
|
985
1197
|
{ key: b.id, type: 'button', className: 'dshb-row', 'data-active': view === 'bot' && b.id === selected, 'data-dsh-bots-row': b.id, onClick: () => onSelect(b.id) },
|
|
986
|
-
h(Avatar, { avatar: b.avatar, name: b.name || b.handle, size: 36, status:
|
|
1198
|
+
h(Avatar, { avatar: b.avatar, name: b.name || b.handle, size: 36, status, pending: live.avatarPending, title: live.avatarPending ? t('avatarDrawing') : t(`status_${status}`) }),
|
|
987
1199
|
h(
|
|
988
1200
|
'span',
|
|
989
1201
|
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0, flex: 1 } },
|
|
@@ -994,9 +1206,19 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
994
1206
|
b.id === primaryId ? h('span', { title: t('dispatcher'), style: { color: '#f5b301', display: 'inline-flex' } }, Icon.crown(12)) : null,
|
|
995
1207
|
h('span', { style: { color: C.faint, fontSize: TINY, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, `@${b.handle}`),
|
|
996
1208
|
),
|
|
997
|
-
|
|
1209
|
+
work
|
|
1210
|
+
? h(
|
|
1211
|
+
'span',
|
|
1212
|
+
{ 'data-dsh-bots-row-live': work.ticket ? 'task' : 'home', title: work.ticket ? str(work.title) : undefined, style: { fontSize: TINY, color: C.muted, marginTop: 1, display: 'flex', alignItems: 'center', gap: 4, minWidth: 0, whiteSpace: 'nowrap' } },
|
|
1213
|
+
work.ticket ? h('span', { style: { color: C.faint, display: 'inline-flex', flex: 'none' } }, Icon.tasks(11)) : null,
|
|
1214
|
+
h(LiveLine, { t, a: work, attr: b.id }),
|
|
1215
|
+
)
|
|
1216
|
+
: h('span', { style: { fontSize: TINY, color: C.muted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', marginTop: 1 } }, b.bio || t('noBio')),
|
|
998
1217
|
),
|
|
1218
|
+
// Questions its own conversation waits to have answered (a task's show on Tasks).
|
|
1219
|
+
Number(b.asking) > 0 ? h(NeedsBadge, { n: Number(b.asking), label: t('askingBadge', { n: Number(b.asking) }), attr: 'data-dsh-bots-row-asking' }) : null,
|
|
999
1220
|
);
|
|
1221
|
+
};
|
|
1000
1222
|
return h(
|
|
1001
1223
|
'aside',
|
|
1002
1224
|
{ 'data-dsh-bots-rail': true, style: { width: 264, flex: 'none', display: 'flex', flexDirection: 'column', borderRight: `1px solid ${C.border1}`, background: C.base, minHeight: 0 } },
|
|
@@ -1045,6 +1267,20 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1045
1267
|
h(
|
|
1046
1268
|
'div',
|
|
1047
1269
|
{ style: { padding: 8, borderTop: `1px solid ${C.border1}` } },
|
|
1270
|
+
onTasks
|
|
1271
|
+
? h(
|
|
1272
|
+
'button',
|
|
1273
|
+
{ type: 'button', className: 'dshb-row', 'data-active': view === 'tasks', 'data-dsh-bots-tasks-entry': true, onClick: onTasks },
|
|
1274
|
+
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.tasks(16)),
|
|
1275
|
+
h(
|
|
1276
|
+
'span',
|
|
1277
|
+
{ style: { display: 'flex', flexDirection: 'column', flex: 1, minWidth: 0 } },
|
|
1278
|
+
h('span', { style: { fontWeight: 600 } }, t('tasks')),
|
|
1279
|
+
h('span', { style: { fontSize: TINY, color: attention > 0 ? C.warn : C.muted } }, attention > 0 ? t('tasksNeedYou', { n: attention }) : openTasks > 0 ? t('tasksInProgress', { n: openTasks }) : t('tasksHint')),
|
|
1280
|
+
),
|
|
1281
|
+
attention > 0 ? h(NeedsBadge, { n: attention, label: t('tasksNeedYou', { n: attention }), attr: 'data-dsh-bots-tasks-badge' }) : null,
|
|
1282
|
+
)
|
|
1283
|
+
: null,
|
|
1048
1284
|
h(
|
|
1049
1285
|
'button',
|
|
1050
1286
|
{ type: 'button', className: 'dshb-row', 'data-active': view === 'activity', 'data-dsh-bots-activity': true, onClick: onActivity },
|
|
@@ -1079,6 +1315,23 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1079
1315
|
|
|
1080
1316
|
// --- the panel: messages ---------------------------------------------------------------
|
|
1081
1317
|
|
|
1318
|
+
/** A chat thread's key (`kind:app:chat[:root]`, lib/threads.mjs), not the panel's own. */
|
|
1319
|
+
const isChatThread = (key) => typeof key === 'string' && /^[a-z][a-z0-9-]*:/.test(key) && !key.startsWith('panel:') && key.split(':').length >= 3;
|
|
1320
|
+
/** Who wrote in each chat thread of a timeline, so a thread reads by a name rather than its chat id. */
|
|
1321
|
+
function threadNamesOf(items) {
|
|
1322
|
+
const names = new Map();
|
|
1323
|
+
for (const m of items ?? []) if (isChatThread(m?.thread) && str(m.who).trim()) names.set(m.thread, str(m.who).trim());
|
|
1324
|
+
return names;
|
|
1325
|
+
}
|
|
1326
|
+
/** A chat thread as people read it (the Host's `threadLabel`): `Telegram · Kada`, `Slack · C042 · thread`. */
|
|
1327
|
+
function threadName(t, key, names) {
|
|
1328
|
+
const [kind, , chat, root] = str(key).split(':');
|
|
1329
|
+
const unescape = (s) => str(s).replace(/%(25|3A)/gi, (_, c) => (c === '25' ? '%' : ':'));
|
|
1330
|
+
const parts = [channelName(kind, t), names?.get(key) || unescape(chat)];
|
|
1331
|
+
if (root) parts.push(kind === 'telegram' ? t('threadTopic') : t('threadPart'));
|
|
1332
|
+
return parts.join(' · ');
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1082
1335
|
/** Who a message end is: a bot face, the user, or the scheduler. */
|
|
1083
1336
|
function party(t, id) {
|
|
1084
1337
|
if (id === 'user') return { kind: 'user', name: t('you') };
|
|
@@ -1093,13 +1346,19 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1093
1346
|
return h('span', { style: { width: size, height: size, borderRadius: '50%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.layer3, color: C.muted, flex: 'none' } }, glyph);
|
|
1094
1347
|
}
|
|
1095
1348
|
|
|
1096
|
-
/**
|
|
1097
|
-
|
|
1349
|
+
/**
|
|
1350
|
+
* A thread of one bot: the user's prompts right, the bot's replies left, DMs as cards. With `fold`
|
|
1351
|
+
* (the main timeline of a chat with topics), replies inside a topic are not listed: each root gets its
|
|
1352
|
+
* topic bar instead (`topic` props: `{index, topics, onOpen, unread, flash}`).
|
|
1353
|
+
*/
|
|
1354
|
+
function MessageList({ t, items, botId, empty, fold = null, onReply, onRetry, movedIn }) {
|
|
1098
1355
|
const count = items.length;
|
|
1099
1356
|
if (count === 0) return empty;
|
|
1357
|
+
const names = threadNamesOf(items);
|
|
1100
1358
|
const rows = [];
|
|
1101
1359
|
let lastDay = '';
|
|
1102
|
-
|
|
1360
|
+
const shown = fold ? fold.index.main : items;
|
|
1361
|
+
shown.forEach((m, i) => {
|
|
1103
1362
|
const at = toMs(m.at);
|
|
1104
1363
|
let day = '';
|
|
1105
1364
|
try {
|
|
@@ -1125,14 +1384,300 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1125
1384
|
),
|
|
1126
1385
|
);
|
|
1127
1386
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1387
|
+
// What bots say to each other runs together in one compact group, under the main thread.
|
|
1388
|
+
if (isTraffic(m)) {
|
|
1389
|
+
const last = rows[rows.length - 1];
|
|
1390
|
+
if (last && last.traffic) last.items.push(m);
|
|
1391
|
+
else rows.push({ traffic: true, key: `g${m.id ?? i}`, items: [m] });
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
const prev = shown[i - 1];
|
|
1395
|
+
// A root with its topic bar under it ends a run: the next message starts with its own header.
|
|
1396
|
+
const prevBar = fold && prev && fold.index.roots.has(prev.id) && topicBarShows(fold, prev.id);
|
|
1397
|
+
// Answers to two chats of one turn keep their own headers (where each went), and so do two tasks.
|
|
1398
|
+
const grouped = !prevBar && prev && !isTraffic(prev) && prev.from === m.from && prev.to === m.to && prev.kind === m.kind && prev.via === m.via && prev.thread === m.thread && messageTicket(prev) === messageTicket(m) && at - toMs(prev.at) < 5 * 60_000;
|
|
1399
|
+
rows.push(h(MessageRow, { key: m.id ?? i, t, m, botId, grouped, names, onReply, onRetry, moved: movedIn ? movedIn(m) : false }));
|
|
1400
|
+
if (fold && fold.index.roots.has(m.id)) {
|
|
1401
|
+
const bar = m.movedTo ? h(MovedBar, { key: `mv${m.id}`, t, m, fold }) : topicBarShows(fold, m.id) ? h(TopicBar, { key: `tb${m.id}`, t, m, fold }) : null;
|
|
1402
|
+
if (bar) rows.push(bar);
|
|
1403
|
+
}
|
|
1131
1404
|
});
|
|
1132
|
-
|
|
1405
|
+
const level = botMessagesLevel();
|
|
1406
|
+
return h(
|
|
1407
|
+
'div',
|
|
1408
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4, padding: '8px 0', maxWidth: 880, margin: '0 auto' } },
|
|
1409
|
+
rows.map((r) => (r && r.traffic ? h(BotTraffic, { key: r.key, t, items: r.items, level }) : r)),
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
/** The tasks of a topic (the Host's TicketRows for it). */
|
|
1413
|
+
const topicTasks = (fold, rootId) => {
|
|
1414
|
+
const list = fold?.topics?.[rootId]?.tickets;
|
|
1415
|
+
return Array.isArray(list) ? list.filter((r) => r && typeof r.id === 'string') : [];
|
|
1416
|
+
};
|
|
1417
|
+
/** Whether a root shows a bar: it was moved, or its topic has replies or tasks. */
|
|
1418
|
+
function topicBarShows(fold, rootId) {
|
|
1419
|
+
const r = fold?.index?.roots.get(rootId);
|
|
1420
|
+
if (!r) return false;
|
|
1421
|
+
if (r.root?.movedTo) return true;
|
|
1422
|
+
return r.replies.length > 0 || topicTasks(fold, rootId).length > 0;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
/**
|
|
1426
|
+
* The bar under a topic's root in the main timeline: how many replies, who said the latest and what,
|
|
1427
|
+
* the topic's tasks (alive while they work), and a dot when there is something new. It opens the topic.
|
|
1428
|
+
*/
|
|
1429
|
+
function TopicBar({ t, m, fold }) {
|
|
1430
|
+
const r = fold.index.roots.get(m.id);
|
|
1431
|
+
const n = r.replies.length;
|
|
1432
|
+
const last = r.last;
|
|
1433
|
+
const who = last ? party(t, last.from) : null;
|
|
1434
|
+
const tasks = topicTasks(fold, m.id).slice(0, 3);
|
|
1435
|
+
const unread = fold.unread?.has(m.id) === true;
|
|
1436
|
+
const mine = m.from === 'user';
|
|
1437
|
+
return h(
|
|
1438
|
+
'div',
|
|
1439
|
+
{ style: { display: 'flex', justifyContent: mine ? 'flex-end' : 'flex-start', paddingLeft: mine ? 0 : 40, margin: '3px 0 6px' } },
|
|
1440
|
+
h(
|
|
1441
|
+
'div',
|
|
1442
|
+
{
|
|
1443
|
+
role: 'button',
|
|
1444
|
+
tabIndex: 0,
|
|
1445
|
+
className: 'dshb-topicbar dshb-fade',
|
|
1446
|
+
'data-dsh-bots-topic-bar': m.id,
|
|
1447
|
+
'data-unread': unread ? 'true' : undefined,
|
|
1448
|
+
'data-flash': fold.flash === m.id ? 'true' : undefined,
|
|
1449
|
+
title: t('openTopic'),
|
|
1450
|
+
onClick: () => fold.onOpen(m.id),
|
|
1451
|
+
onKeyDown: (e) => {
|
|
1452
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
1453
|
+
e.preventDefault?.();
|
|
1454
|
+
fold.onOpen(m.id);
|
|
1455
|
+
}
|
|
1456
|
+
},
|
|
1457
|
+
},
|
|
1458
|
+
h(
|
|
1459
|
+
'div',
|
|
1460
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 } },
|
|
1461
|
+
h('span', { style: { color: C.label, display: 'inline-flex', flex: 'none' } }, Icon.chat(13)),
|
|
1462
|
+
h('span', { 'data-dsh-bots-topic-count': n, style: { fontWeight: 650, color: C.label, flex: 'none' } }, n === 0 ? t('topicLabel') : t(n === 1 ? 'topicReplyOne' : 'topicReplies', { n })),
|
|
1463
|
+
last && who ? h('span', { style: { color: C.faint, flex: 'none' } }, '·') : null,
|
|
1464
|
+
last && who ? h(PartyAvatar, { p: who, size: 16 }) : null,
|
|
1465
|
+
last && who ? h('span', { style: { fontWeight: 600, color: C.primary, flex: 'none', maxWidth: 140, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, who.name) : null,
|
|
1466
|
+
last ? h('span', { style: { color: C.faint, flex: 'none', fontSize: TINY } }, fmtClock(toMs(last.at))) : null,
|
|
1467
|
+
h('span', { style: { flex: 1 } }),
|
|
1468
|
+
unread ? h('span', { 'data-dsh-bots-topic-unread': m.id, title: t('topicUnread'), style: { width: 8, height: 8, borderRadius: '50%', background: C.error, flex: 'none' } }) : null,
|
|
1469
|
+
h('span', { style: { color: C.faint, display: 'inline-flex', flex: 'none' } }, Icon.arrow(11)),
|
|
1470
|
+
),
|
|
1471
|
+
last ? h('div', { className: 'dshb-clamp2', 'data-dsh-bots-topic-last': last.id ?? true, style: { color: C.muted, fontSize: SMALL, lineHeight: 1.45, wordBreak: 'break-word' } }, plainPreview(last.text)) : null,
|
|
1472
|
+
tasks.length
|
|
1473
|
+
? h(
|
|
1474
|
+
'div',
|
|
1475
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
1476
|
+
tasks.map((row) => {
|
|
1477
|
+
const live = row.stage === 'working' ? liveTask(row.id) ?? (row.activity && typeof row.activity === 'object' ? row.activity : null) : null;
|
|
1478
|
+
return h(
|
|
1479
|
+
'button',
|
|
1480
|
+
{
|
|
1481
|
+
key: row.id,
|
|
1482
|
+
type: 'button',
|
|
1483
|
+
className: 'dshb-topictask',
|
|
1484
|
+
'data-dsh-bots-topic-task': row.id,
|
|
1485
|
+
'data-stage': row.stage,
|
|
1486
|
+
title: t('openTask'),
|
|
1487
|
+
onClick: (e) => {
|
|
1488
|
+
e?.stopPropagation?.();
|
|
1489
|
+
openTicket(row.id);
|
|
1490
|
+
},
|
|
1491
|
+
},
|
|
1492
|
+
h('span', { style: { color: C.muted, display: 'inline-flex', flex: 'none' } }, Icon.tasks(12)),
|
|
1493
|
+
h(BotFace, { id: row.botId, size: 14 }),
|
|
1494
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, taskTitle(t, row)),
|
|
1495
|
+
live ? h(LiveChip, { t, a: live }) : h(TaskChip, { t, row }),
|
|
1496
|
+
);
|
|
1497
|
+
}),
|
|
1498
|
+
)
|
|
1499
|
+
: null,
|
|
1500
|
+
),
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
/** Where a top-level message went when the dispatcher placed it in another topic: a link to that topic. */
|
|
1504
|
+
function MovedBar({ t, m, fold }) {
|
|
1505
|
+
const target = fold.index.byId.get(m.movedTo);
|
|
1506
|
+
const title = target ? excerpt(target.text, 40) : '';
|
|
1507
|
+
const mine = m.from === 'user';
|
|
1508
|
+
return h(
|
|
1509
|
+
'div',
|
|
1510
|
+
{ style: { display: 'flex', justifyContent: mine ? 'flex-end' : 'flex-start', paddingLeft: mine ? 0 : 40, margin: '2px 0 6px' } },
|
|
1511
|
+
h(
|
|
1512
|
+
'button',
|
|
1513
|
+
{ type: 'button', className: 'dshb-link dshb-moved', 'data-dsh-bots-moved': m.movedTo, title: t('openTopic'), onClick: () => fold.onOpen(m.movedTo) },
|
|
1514
|
+
h('span', { style: { display: 'inline-flex', flex: 'none' } }, Icon.layers(12)),
|
|
1515
|
+
h('span', { style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, title ? t('movedTo', { title }) : t('movedToTopic')),
|
|
1516
|
+
h('span', { style: { display: 'inline-flex', flex: 'none' } }, Icon.arrow(11)),
|
|
1517
|
+
),
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
/** A message between two bots (a delegation, a report, a DM), or a scheduled prompt: secondary traffic. */
|
|
1522
|
+
const isTraffic = (m) => m?.kind === 'system' || ((m?.kind === 'dm' || m?.kind === 'report') && m.from !== 'user' && m.to !== 'user');
|
|
1523
|
+
/** How much of what bots say to each other a chat shows (a team setting): 'line' | 'short' | 'full'. */
|
|
1524
|
+
function botMessagesLevel() {
|
|
1525
|
+
const v = store.state?.display?.botMessages ?? store.settings?.settings?.display?.botMessages;
|
|
1526
|
+
return v === 'short' || v === 'full' ? v : 'line';
|
|
1527
|
+
}
|
|
1528
|
+
/** The first sentence of a message (or its first line), for a one-line row. */
|
|
1529
|
+
function firstSentence(text) {
|
|
1530
|
+
const line = (str(text).split('\n').find((l) => l.trim() !== '') ?? '').trim();
|
|
1531
|
+
const m = /^(.{12,}?[.!?。!?])(\s|$)/u.exec(line);
|
|
1532
|
+
const s = (m ? m[1] : line).trim();
|
|
1533
|
+
// A very long one is cut, and says so (the short view goes on from there).
|
|
1534
|
+
return [...s].length > 160 ? `${[...s].slice(0, 159).join('').trimEnd()}…` : s;
|
|
1535
|
+
}
|
|
1536
|
+
/** Consecutive messages between bots, as one quiet group at the chosen level of detail. */
|
|
1537
|
+
function BotTraffic({ t, items, level }) {
|
|
1538
|
+
let lastTime = '';
|
|
1539
|
+
return h(
|
|
1540
|
+
'div',
|
|
1541
|
+
{ className: 'dshb-traffic', 'data-dsh-bots-traffic': items.length, 'data-level': level },
|
|
1542
|
+
items.map((m, i) => {
|
|
1543
|
+
const at = toMs(m.at);
|
|
1544
|
+
const time = Number.isFinite(at) ? fmtClock(at) : '';
|
|
1545
|
+
// A time shows once for a run of messages in the same minute.
|
|
1546
|
+
const showTime = time !== lastTime;
|
|
1547
|
+
lastTime = time;
|
|
1548
|
+
return h(TrafficItem, { key: m.id ?? i, t, m, level, time: showTime ? time : '' });
|
|
1549
|
+
}),
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
/**
|
|
1554
|
+
* One message between bots. `line`: who to whom, the task's title (or the first sentence), its stage
|
|
1555
|
+
* (alive while it works) and the time; a click opens the task, or unfolds a message without one.
|
|
1556
|
+
* `short`: that and two lines of the text. `full`: the whole text, and a delegation's task card.
|
|
1557
|
+
*/
|
|
1558
|
+
function TrafficItem({ t, m, level, time }) {
|
|
1559
|
+
const [open, setOpen] = useState(false);
|
|
1560
|
+
const from = party(t, m.from);
|
|
1561
|
+
const to = party(t, m.to);
|
|
1562
|
+
const ticketId = messageTicket(m);
|
|
1563
|
+
const report = messageReport(m);
|
|
1564
|
+
const notice = messageNotice(m);
|
|
1565
|
+
const delegation = Boolean(ticketId) && !report && !notice;
|
|
1566
|
+
usePoll(() => (delegation ? loadTicket(ticketId) : undefined), 10_000, [ticketId, delegation]);
|
|
1567
|
+
const view = delegation ? store.tickets.get(ticketId)?.view ?? null : null;
|
|
1568
|
+
const live = delegation ? liveTask(ticketId) : null;
|
|
1569
|
+
const stage = str(view?.stage) || (live ? 'working' : '');
|
|
1570
|
+
const subject = delegation ? str(view?.title).trim() || firstLine(m.text) : firstSentence(m.text);
|
|
1571
|
+
const full = level === 'full' || open;
|
|
1572
|
+
const chip = notice
|
|
1573
|
+
? h(StageChip, { t, stage: notice })
|
|
1574
|
+
: report
|
|
1575
|
+
? h(ReportChip, { t, status: report })
|
|
1576
|
+
: m.kind === 'system'
|
|
1577
|
+
? h(Badge, { color: C.warn }, t('scheduled'))
|
|
1578
|
+
: delegation
|
|
1579
|
+
? live && (!stage || stage === 'working')
|
|
1580
|
+
? h(LiveChip, { t, a: live })
|
|
1581
|
+
: view?.asking
|
|
1582
|
+
? h(TaskChip, { t, row: view })
|
|
1583
|
+
: h(StageChip, { t, stage })
|
|
1584
|
+
: null;
|
|
1585
|
+
const who = [
|
|
1586
|
+
h(PartyAvatar, { key: 'fa', p: from, size: 16 }),
|
|
1587
|
+
h('span', { key: 'fn', className: 'dshb-tname' }, from.name),
|
|
1588
|
+
h('span', { key: 'ar', style: { color: C.faint, display: 'inline-flex', flex: 'none' } }, Icon.arrow(10)),
|
|
1589
|
+
h(PartyAvatar, { key: 'ta', p: to, size: 16 }),
|
|
1590
|
+
h('span', { key: 'tn', className: 'dshb-tname' }, to.name),
|
|
1591
|
+
];
|
|
1592
|
+
const timeEl = h('span', { className: 'dshb-ttime' }, time);
|
|
1593
|
+
if (full) {
|
|
1594
|
+
// The whole message: a header (who, its stage, a link to its task), the task card, the text.
|
|
1595
|
+
return h(
|
|
1596
|
+
'div',
|
|
1597
|
+
{ className: 'dshb-titem dshb-fade', 'data-dsh-bots-msg': m.kind, 'data-level': 'full' },
|
|
1598
|
+
h(
|
|
1599
|
+
'div',
|
|
1600
|
+
{ className: 'dshb-tline', style: { cursor: 'default' } },
|
|
1601
|
+
who,
|
|
1602
|
+
h('span', { style: { flex: 1 } }),
|
|
1603
|
+
delegation ? (live ? h(LiveChip, { t, a: live }) : null) : chip,
|
|
1604
|
+
ticketId && !delegation ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-report-task': ticketId, onClick: () => openTicket(ticketId), style: { fontSize: TINY, flex: 'none' } }, t('openTask')) : null,
|
|
1605
|
+
open && level !== 'full' ? h('button', { type: 'button', className: 'dshb-link', onClick: () => setOpen(false), style: { fontSize: TINY, flex: 'none' } }, t('showLess')) : null,
|
|
1606
|
+
timeEl,
|
|
1607
|
+
),
|
|
1608
|
+
h(
|
|
1609
|
+
'div',
|
|
1610
|
+
{ className: 'dshb-tbody' },
|
|
1611
|
+
delegation ? h(TaskCard, { t, id: ticketId, botId: m.to, title: firstLine(m.text) }) : null,
|
|
1612
|
+
h(Clamp, { t, text: m.text, lines: 6, style: { fontSize: SMALL } }),
|
|
1613
|
+
h(LinkCards, { t, text: m.text }),
|
|
1614
|
+
),
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
// Short: the text's first two lines under the row, which then names only a task title the text does not start with.
|
|
1618
|
+
const short = level === 'short' && str(m.text).trim() !== '';
|
|
1619
|
+
const ownTitle = delegation && str(view?.title).trim() !== '' && !str(m.text).trim().startsWith(str(view.title).trim().replace(/…$/, '').trimEnd());
|
|
1620
|
+
const lineSubject = short && !ownTitle ? '' : subject;
|
|
1621
|
+
return h(
|
|
1622
|
+
'div',
|
|
1623
|
+
{ className: 'dshb-titem dshb-fade', 'data-dsh-bots-msg': m.kind, 'data-level': level },
|
|
1624
|
+
h(
|
|
1625
|
+
'button',
|
|
1626
|
+
{
|
|
1627
|
+
type: 'button',
|
|
1628
|
+
className: 'dshb-tline',
|
|
1629
|
+
title: ticketId ? `${t('openTask')}: ${subject}` : t('showMore'),
|
|
1630
|
+
...(delegation ? { 'data-dsh-bots-task-card': ticketId } : ticketId ? { 'data-dsh-bots-report-task': ticketId } : { 'data-dsh-bots-expand': m.id ?? true }),
|
|
1631
|
+
onClick: (e) => {
|
|
1632
|
+
e?.stopPropagation?.();
|
|
1633
|
+
if (ticketId) openTicket(ticketId);
|
|
1634
|
+
else setOpen(true);
|
|
1635
|
+
},
|
|
1636
|
+
},
|
|
1637
|
+
who,
|
|
1638
|
+
h('span', { className: 'dshb-tsubject', 'data-dsh-bots-subject': true }, lineSubject),
|
|
1639
|
+
chip,
|
|
1640
|
+
timeEl,
|
|
1641
|
+
),
|
|
1642
|
+
short ? h('div', { className: 'dshb-tbody dshb-clamp2', 'data-dsh-bots-short': true }, str(m.text).trim()) : null,
|
|
1643
|
+
);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
/** "Reply" on a message, shown while the pointer is on it (always, faintly, without a pointer). */
|
|
1647
|
+
const ReplyAction = ({ t, m, onReply }) =>
|
|
1648
|
+
onReply && m?.id != null && !m.local
|
|
1649
|
+
? h(
|
|
1650
|
+
'button',
|
|
1651
|
+
{
|
|
1652
|
+
type: 'button',
|
|
1653
|
+
className: 'dshb-msg-act',
|
|
1654
|
+
'data-dsh-bots-reply-to': m.id,
|
|
1655
|
+
title: t('replyAction'),
|
|
1656
|
+
onClick: (e) => {
|
|
1657
|
+
e?.stopPropagation?.();
|
|
1658
|
+
onReply(m);
|
|
1659
|
+
},
|
|
1660
|
+
},
|
|
1661
|
+
Icon.back(11),
|
|
1662
|
+
t('replyAction'),
|
|
1663
|
+
)
|
|
1664
|
+
: null;
|
|
1665
|
+
/** Under one of your messages: still waiting for the bot to take it, or not sent (with a way to send it again). */
|
|
1666
|
+
function SendState({ t, m, onRetry }) {
|
|
1667
|
+
if (m.failed) {
|
|
1668
|
+
return h(
|
|
1669
|
+
'span',
|
|
1670
|
+
{ 'data-dsh-bots-send-failed': m.id, style: { display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.error } },
|
|
1671
|
+
Icon.alert(11),
|
|
1672
|
+
t('msgFailed'),
|
|
1673
|
+
onRetry ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-resend': m.id, onClick: () => onRetry(m), style: { fontSize: TINY, color: C.error, fontWeight: 600 } }, t('resend')) : null,
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
if (m.pending) return h('span', { 'data-dsh-bots-pending': m.id, title: t('msgPendingHint'), style: { fontSize: TINY, color: C.faint } }, t('msgPending'));
|
|
1677
|
+
return null;
|
|
1133
1678
|
}
|
|
1134
1679
|
|
|
1135
|
-
function MessageRow({ t, m, botId, grouped }) {
|
|
1680
|
+
function MessageRow({ t, m, botId, grouped, names, onReply, onRetry, moved = false }) {
|
|
1136
1681
|
if (m.kind === 'topic') {
|
|
1137
1682
|
const at = toMs(m.at);
|
|
1138
1683
|
return h(
|
|
@@ -1149,71 +1694,86 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1149
1694
|
const time = Number.isFinite(at) ? fmtClock(at) : '';
|
|
1150
1695
|
const mine = m.from === 'user';
|
|
1151
1696
|
// A DM between two bots, or something addressed to another bot: an "A → B" card.
|
|
1152
|
-
const between = m.kind === 'dm' && m.from !== 'user' && m.to !== 'user';
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
{ style: { width: 'min(600px, 100%)', borderLeft: `3px solid ${m.kind === 'system' ? C.warn : tint(C.label, 60)}`, border: `1px solid ${C.border1}`, borderRadius: 12, background: C.layer2, padding: '8px 12px', display: 'flex', flexDirection: 'column', gap: 5 } },
|
|
1160
|
-
h(
|
|
1161
|
-
'div',
|
|
1162
|
-
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.muted, minWidth: 0 } },
|
|
1163
|
-
h(PartyAvatar, { p: from, size: 18 }),
|
|
1164
|
-
h('span', { style: { fontWeight: 600, color: C.primary } }, from.name),
|
|
1165
|
-
h('span', { style: { color: C.faint, display: 'inline-flex' } }, Icon.arrow(11)),
|
|
1166
|
-
h(PartyAvatar, { p: to, size: 18 }),
|
|
1167
|
-
h('span', { style: { fontWeight: 600, color: C.primary } }, to.name),
|
|
1168
|
-
h('span', { style: { marginLeft: 'auto', color: C.faint } }, m.kind === 'system' ? `${t('scheduled')} · ${time}` : time),
|
|
1169
|
-
),
|
|
1170
|
-
h(Clamp, { t, text: m.text, lines: 6, style: { fontSize: SMALL, color: C.primary } }),
|
|
1171
|
-
h(LinkCards, { t, text: m.text }),
|
|
1172
|
-
),
|
|
1173
|
-
);
|
|
1174
|
-
}
|
|
1697
|
+
const between = (m.kind === 'dm' || m.kind === 'report') && m.from !== 'user' && m.to !== 'user';
|
|
1698
|
+
// A delegation that opened a task shows the task; a worker's report shows its status, and a
|
|
1699
|
+
// notice that the task is stuck or failed its stage.
|
|
1700
|
+
const ticketId = messageTicket(m);
|
|
1701
|
+
const report = messageReport(m);
|
|
1702
|
+
const notice = messageNotice(m);
|
|
1703
|
+
if (between || m.kind === 'system') return h(BotTraffic, { t, items: [m], level: botMessagesLevel() });
|
|
1175
1704
|
if (mine) {
|
|
1705
|
+
const state = m.pending || m.failed ? h(SendState, { t, m, onRetry }) : null;
|
|
1176
1706
|
return h(
|
|
1177
1707
|
'div',
|
|
1178
|
-
{ 'data-dsh-bots-msg': 'user', className: 'dshb-fade', style: { display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 3, marginTop: grouped ? 0 : 6 } },
|
|
1179
|
-
grouped
|
|
1708
|
+
{ 'data-dsh-bots-msg': 'user', 'data-dsh-bots-msg-id': m.id, 'data-local': m.local ? 'true' : undefined, className: 'dshb-msg dshb-fade', style: { display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 3, marginTop: grouped ? 0 : 6 } },
|
|
1709
|
+
grouped && !moved
|
|
1180
1710
|
? null
|
|
1181
1711
|
: h(
|
|
1182
1712
|
'span',
|
|
1183
|
-
{ style: { fontSize: TINY, color: C.faint, display: 'inline-flex', alignItems: 'center', gap: 6 } },
|
|
1713
|
+
{ style: { fontSize: TINY, color: C.faint, display: 'inline-flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', justifyContent: 'flex-end' } },
|
|
1714
|
+
moved ? h(Badge, { color: C.muted, 'data-dsh-bots-moved-in': m.id }, Icon.layers(10), t('movedIn')) : null,
|
|
1184
1715
|
m.via ? h(Badge, { color: CHANNEL_COLORS[m.via] ?? C.muted, 'data-dsh-bots-via': m.via }, t('viaChannel', { app: channelName(m.via, t), who: str(m.who) || t('you') })) : null,
|
|
1185
1716
|
m.to !== botId && to.kind === 'bot' ? `${t('toName', { name: to.name })} · ${time}` : time,
|
|
1717
|
+
// A message from a chat that went straight to the task it follows up on.
|
|
1718
|
+
ticketId ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-report-task': ticketId, title: m.via ? t('followUpHint') : undefined, onClick: () => openTicket(ticketId), style: { fontSize: TINY } }, t(m.via ? 'followUpTask' : 'openTask')) : null,
|
|
1186
1719
|
),
|
|
1187
|
-
h(
|
|
1720
|
+
h(
|
|
1721
|
+
'div',
|
|
1722
|
+
{ style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: 6, width: '100%', minWidth: 0 } },
|
|
1723
|
+
h(ReplyAction, { t, m, onReply }),
|
|
1724
|
+
h('div', { style: { maxWidth: '78%', minWidth: 0, padding: '8px 12px', borderRadius: '14px 14px 4px 14px', background: C.label, color: C.onLabel, fontSize: FONT, opacity: m.local && !m.failed ? 0.8 : 1, boxShadow: m.failed ? `0 0 0 2px ${C.error}` : undefined } }, h(Clamp, { t, text: m.text, lines: 14, light: true })),
|
|
1725
|
+
),
|
|
1726
|
+
state,
|
|
1188
1727
|
h('div', { style: { width: 'min(480px, 78%)', display: 'flex', justifyContent: 'flex-end' } }, h(LinkCards, { t, text: m.text, align: 'flex-end' })),
|
|
1189
1728
|
);
|
|
1190
1729
|
}
|
|
1730
|
+
// Where a reply went: its chat by name when the Host says which (`→ Telegram · Kada`), else the app.
|
|
1731
|
+
const place = m.via ? (isChatThread(m.thread) ? threadName(t, m.thread, names) : channelName(m.via, t)) : '';
|
|
1732
|
+
// With several chats in the turn, plain text reached none of them (bot_reply says where each answer goes).
|
|
1733
|
+
const choices = m.notSent === true && Array.isArray(m.choices) ? m.choices.filter(isChatThread) : [];
|
|
1734
|
+
// A teammate answering you itself, in this chat (the bot that did a task): its own face and name, the task.
|
|
1735
|
+
const worker = m.kind === 'reply' && m.from !== botId && from.kind === 'bot' && Boolean(ticketId);
|
|
1736
|
+
// A bot speaking to you reads like the main conversation: no box, full-strength text.
|
|
1191
1737
|
return h(
|
|
1192
1738
|
'div',
|
|
1193
|
-
{ 'data-dsh-bots-msg': m.kind || 'reply', className: 'dshb-fade', style: { display: 'flex', gap: 10, alignItems: 'flex-start', marginTop: grouped ?
|
|
1739
|
+
{ 'data-dsh-bots-msg': m.kind || 'reply', 'data-dsh-bots-msg-id': m.id, 'data-dsh-bots-worker': worker ? m.from : undefined, className: 'dshb-msg dshb-fade', style: { display: 'flex', gap: 10, alignItems: 'flex-start', marginTop: grouped ? 4 : 12 } },
|
|
1194
1740
|
h('div', { style: { width: 30, flex: 'none' } }, grouped ? null : h(PartyAvatar, { p: from, size: 30 })),
|
|
1195
1741
|
h(
|
|
1196
1742
|
'div',
|
|
1197
|
-
{ style: { display: 'flex', flexDirection: 'column', gap:
|
|
1743
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0, flex: 1, maxWidth: 760 } },
|
|
1744
|
+
onReply ? h('div', { className: 'dshb-msg-actbox' }, h(ReplyAction, { t, m, onReply })) : null,
|
|
1198
1745
|
grouped
|
|
1199
1746
|
? null
|
|
1200
1747
|
: h(
|
|
1201
1748
|
'div',
|
|
1202
|
-
{ style: { display: 'flex', alignItems: 'baseline', gap: 6, fontSize: TINY } },
|
|
1749
|
+
{ style: { display: 'flex', alignItems: 'baseline', gap: 6, fontSize: TINY, flexWrap: 'wrap' } },
|
|
1750
|
+
moved ? h(Badge, { color: C.muted, 'data-dsh-bots-moved-in': m.id }, Icon.layers(10), t('movedIn')) : null,
|
|
1203
1751
|
h('span', { style: { fontWeight: 700, fontSize: SMALL, color: C.primary } }, from.name),
|
|
1204
1752
|
from.kind === 'bot' ? h('span', { style: { color: C.faint } }, `@${from.bot.handle}`) : null,
|
|
1205
1753
|
m.to !== 'user' && to.kind === 'bot' && m.to !== botId ? h('span', { style: { color: C.faint } }, `→ ${to.name}`) : null,
|
|
1206
1754
|
h('span', { style: { color: C.faint } }, time),
|
|
1207
|
-
m.via ? h(Badge, { color: CHANNEL_COLORS[m.via] ?? C.muted, title: t('sentToChannel', { app:
|
|
1755
|
+
m.via ? h(Badge, { color: CHANNEL_COLORS[m.via] ?? C.muted, title: t('sentToChannel', { app: place }), 'data-dsh-bots-via': m.via }, `→ ${place}`) : null,
|
|
1756
|
+
report ? h(ReportChip, { t, status: report }) : null,
|
|
1757
|
+
notice ? h(StageChip, { t, stage: notice }) : null,
|
|
1758
|
+
ticketId ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-report-task': ticketId, onClick: () => openTicket(ticketId), style: { fontSize: TINY } }, t('openTask')) : null,
|
|
1208
1759
|
),
|
|
1209
|
-
h('div', {
|
|
1760
|
+
h('div', { className: 'dshb-reply', 'data-dsh-bots-reply-text': true }, h(Clamp, { t, text: m.text, lines: 24, variant: 'body' })),
|
|
1761
|
+
choices.length
|
|
1762
|
+
? h(
|
|
1763
|
+
'div',
|
|
1764
|
+
{ 'data-dsh-bots-not-sent': choices.length, style: { display: 'flex', alignItems: 'flex-start', gap: 5, fontSize: TINY, color: C.muted, lineHeight: 1.5 } },
|
|
1765
|
+
h('span', { style: { color: C.warn, display: 'inline-flex', paddingTop: 2 } }, Icon.alert(11)),
|
|
1766
|
+
t('notSentChats', { chats: choices.map((k) => threadName(t, k, names)).join(t('listSep')) }),
|
|
1767
|
+
)
|
|
1768
|
+
: null,
|
|
1210
1769
|
h(LinkCards, { t, text: m.text }),
|
|
1770
|
+
worker && !grouped ? h('div', { 'data-dsh-bots-worker-task': ticketId }, h(TaskCard, { t, id: ticketId, botId: m.from })) : null,
|
|
1211
1771
|
),
|
|
1212
1772
|
);
|
|
1213
1773
|
}
|
|
1214
1774
|
|
|
1215
1775
|
/** Long text folded to about `lines` lines, with a toggle. Bot text renders as Markdown; the user's own bubble stays plain with live links. */
|
|
1216
|
-
function Clamp({ t, text, lines = 6, style, light }) {
|
|
1776
|
+
function Clamp({ t, text, lines = 6, style, light, variant }) {
|
|
1217
1777
|
const [open, setOpen] = useState(false);
|
|
1218
1778
|
const s = str(text);
|
|
1219
1779
|
const long = s.length > lines * 90 || s.split('\n').length > lines;
|
|
@@ -1232,17 +1792,33 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1232
1792
|
...(folded ? { maxHeight: `${lines * 1.55}em`, overflow: 'hidden', WebkitMaskImage: 'linear-gradient(180deg,#000 70%,transparent)', maskImage: 'linear-gradient(180deg,#000 70%,transparent)' } : {}),
|
|
1233
1793
|
},
|
|
1234
1794
|
},
|
|
1235
|
-
light ? h('div', { className: 'dshb-md dshb-md-light' }, linkify(s, 'l')) : h(RichText, { t, text: s }),
|
|
1795
|
+
light ? h('div', { className: 'dshb-md dshb-md-light' }, linkify(s, 'l')) : h(RichText, { t, text: s, variant }),
|
|
1236
1796
|
),
|
|
1237
|
-
long ? h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY, alignSelf: 'flex-start', color: light ? '
|
|
1797
|
+
long ? h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY, alignSelf: 'flex-start', color: light ? 'inherit' : C.label, opacity: light ? 0.85 : 1 }, onClick: () => setOpen((v) => !v) }, open ? t('showLess') : t('showMore')) : null,
|
|
1238
1798
|
);
|
|
1239
1799
|
}
|
|
1240
1800
|
|
|
1241
|
-
/**
|
|
1801
|
+
/**
|
|
1802
|
+
* Preview cards for the links in `text`: none when it lists more than MAX_CARDS links
|
|
1803
|
+
* (a list of sources reads better as the links it already is), one large card for a
|
|
1804
|
+
* single link, compact ones for two or three. Links that resolve to the same preview
|
|
1805
|
+
* (two pages of one site sharing a title and picture) show it once.
|
|
1806
|
+
*/
|
|
1242
1807
|
function LinkCards({ t, text, align = 'flex-start' }) {
|
|
1243
|
-
const
|
|
1808
|
+
const all = linksIn(text);
|
|
1809
|
+
const links = all.length > MAX_CARDS ? [] : all;
|
|
1810
|
+
const cards = [useUnfurl(links[0] ?? ''), useUnfurl(links[1] ?? ''), useUnfurl(links[2] ?? '')];
|
|
1244
1811
|
if (!links.length) return null;
|
|
1245
|
-
|
|
1812
|
+
const seen = new Set();
|
|
1813
|
+
const shown = links.filter((u, i) => {
|
|
1814
|
+
const c = cards[i];
|
|
1815
|
+
if (!c || !c.ok) return true;
|
|
1816
|
+
const key = [c.kind, c.site || c.host || hostOf(u), c.title || '', c.image || ''].join('|');
|
|
1817
|
+
if (seen.has(key)) return false;
|
|
1818
|
+
seen.add(key);
|
|
1819
|
+
return true;
|
|
1820
|
+
});
|
|
1821
|
+
return h('div', { 'data-dsh-bots-cards': shown.length, style: { display: 'flex', flexDirection: 'column', gap: 8, alignItems: align, width: '100%', minWidth: 0 } }, shown.map((u) => h(LinkCard, { key: u, t, url: u, compact: links.length > 1 })));
|
|
1246
1822
|
}
|
|
1247
1823
|
|
|
1248
1824
|
// --- Markdown -------------------------------------------------------------------------
|
|
@@ -1269,10 +1845,11 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1269
1845
|
.map((part, i) => (i % 2 ? part : part.replace(/(^|[^\\])\$(?=\d)/g, '$1\\$')))
|
|
1270
1846
|
.join('');
|
|
1271
1847
|
}
|
|
1272
|
-
|
|
1848
|
+
/** `variant`: 'compact' (secondary text: muted and small, the default) or 'body' (the main conversation's). */
|
|
1849
|
+
function RichText({ t, text, variant = 'compact' }) {
|
|
1273
1850
|
const Md = primitives && primitives.MarkdownText;
|
|
1274
1851
|
if (Md && (typeof Md === 'function' || typeof Md === 'object')) {
|
|
1275
|
-
return h('div', { className: 'dshb-rich', 'data-dsh-bots-md': 'harness' }, h(Md, { text: moneySafe(text), labels: mdLabels(t), variant: 'compact' }));
|
|
1852
|
+
return h('div', { className: 'dshb-rich', 'data-dsh-bots-md': 'harness' }, h(Md, { text: moneySafe(text), labels: mdLabels(t), variant: variant === 'body' ? 'body' : 'compact' }));
|
|
1276
1853
|
}
|
|
1277
1854
|
return h('div', { className: 'dshb-rich dshb-mdf', 'data-dsh-bots-md': 'builtin' }, miniMarkdown(text));
|
|
1278
1855
|
}
|
|
@@ -1538,7 +2115,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1538
2115
|
}
|
|
1539
2116
|
|
|
1540
2117
|
/** One rich preview: a playable YouTube video, an X post or profile, or a page's OpenGraph card. */
|
|
1541
|
-
function LinkCard({ t, url }) {
|
|
2118
|
+
function LinkCard({ t, url, compact = false }) {
|
|
1542
2119
|
const card = useUnfurl(url);
|
|
1543
2120
|
const host = hostOf(url);
|
|
1544
2121
|
if (!card) {
|
|
@@ -1555,7 +2132,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1555
2132
|
if (card.kind === 'image' && card.ok) {
|
|
1556
2133
|
return h('a', { className: 'dshb-lc dshb-lc-image', href: card.url, target: '_blank', rel: 'noreferrer noopener', 'data-dsh-bots-card': 'image' }, h(Img, { src: card.image, alt: card.title, style: { display: 'block', maxWidth: '100%', maxHeight: 360 } }));
|
|
1557
2134
|
}
|
|
1558
|
-
if (card.ok && card.kind === 'page') return h(PageCard, { card });
|
|
2135
|
+
if (card.ok && card.kind === 'page') return h(PageCard, { card, compact });
|
|
1559
2136
|
// No preview: a slim link row still says where it goes.
|
|
1560
2137
|
return h(
|
|
1561
2138
|
'a',
|
|
@@ -1567,8 +2144,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1567
2144
|
);
|
|
1568
2145
|
}
|
|
1569
2146
|
|
|
1570
|
-
function PageCard({ card }) {
|
|
1571
|
-
const large = card.large && card.image;
|
|
2147
|
+
function PageCard({ card, compact = false }) {
|
|
2148
|
+
const large = !compact && card.large && card.image;
|
|
1572
2149
|
const site = h(
|
|
1573
2150
|
'div',
|
|
1574
2151
|
{ className: 'dshb-lc-site' },
|
|
@@ -1721,32 +2298,137 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1721
2298
|
return v;
|
|
1722
2299
|
}
|
|
1723
2300
|
|
|
1724
|
-
|
|
1725
|
-
|
|
2301
|
+
/**
|
|
2302
|
+
* A bot's chat (or every message, without `botId`), polled: `items` oldest first and, per panel topic,
|
|
2303
|
+
* `topics[rootId] = {key, tickets}` (PLAN-0.9 §7.3). With `topic`, only that topic's messages.
|
|
2304
|
+
*/
|
|
2305
|
+
function useMessages(botId, active = true, topic = '') {
|
|
2306
|
+
const [data, setData] = useState(null);
|
|
1726
2307
|
const [failed, setFailed] = useState(false);
|
|
1727
2308
|
const alive = useRef(true);
|
|
1728
2309
|
useEffect(() => {
|
|
1729
2310
|
alive.current = true;
|
|
1730
|
-
|
|
2311
|
+
setData(null);
|
|
1731
2312
|
return () => {
|
|
1732
2313
|
alive.current = false;
|
|
1733
2314
|
};
|
|
1734
|
-
}, [botId]);
|
|
2315
|
+
}, [botId, topic]);
|
|
1735
2316
|
const load = () =>
|
|
1736
2317
|
Promise.resolve()
|
|
1737
|
-
.then(() => getJson(`messages?limit
|
|
2318
|
+
.then(() => getJson(`messages?limit=${topic ? 500 : 200}${botId ? `&bot=${encodeURIComponent(botId)}` : ''}${topic ? `&topic=${encodeURIComponent(topic)}` : ''}`))
|
|
1738
2319
|
.then((r) => {
|
|
1739
2320
|
if (!alive.current) return;
|
|
1740
2321
|
if (r && Array.isArray(r.items)) {
|
|
1741
2322
|
setFailed(false);
|
|
1742
|
-
|
|
2323
|
+
const topics = r.topics && typeof r.topics === 'object' ? r.topics : {};
|
|
2324
|
+
// Same messages in the same states and the same tasks: keep what is shown (no re-render).
|
|
2325
|
+
const sig = `${r.items.map((m) => `${m?.id}${m?.pending ? '~' : ''}${m?.movedTo ? `>${m.movedTo}` : ''}`).join(',')}|${JSON.stringify(topics)}`;
|
|
2326
|
+
setData((prev) => (prev && prev.sig === sig ? prev : { items: r.items, topics, sig }));
|
|
1743
2327
|
} else setFailed(true);
|
|
1744
2328
|
})
|
|
1745
2329
|
.catch(() => {
|
|
1746
2330
|
if (alive.current) setFailed(true);
|
|
1747
2331
|
});
|
|
1748
|
-
usePoll(() => (active ? load() : undefined), CHAT_POLL_MS, [botId, active]);
|
|
1749
|
-
return { items, failed, reload: load };
|
|
2332
|
+
usePoll(() => (active ? load() : undefined), CHAT_POLL_MS, [botId, active, topic]);
|
|
2333
|
+
return { items: data ? data.items : null, topics: data ? data.topics : {}, failed, reload: load };
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// --- panel topics (PLAN-0.9): every top-level message is a topic's root ---------------------
|
|
2337
|
+
|
|
2338
|
+
/** The topic a message's thread is: the one it was moved into, else its own (a root's is its id), else ''. */
|
|
2339
|
+
const topicOfMsg = (m) => str(m?.movedTo) || str(m?.topic);
|
|
2340
|
+
/** A message is a reply inside topic `root` (moved in, or written there), not the root itself. */
|
|
2341
|
+
const inTopic = (m, root) => Boolean(root) && m?.id !== root && (m?.topic === root || m?.movedTo === root);
|
|
2342
|
+
/** A short excerpt of a message for a quote or a label. */
|
|
2343
|
+
/** Markdown as a line of plain text, for a preview: no emphasis marks, headings, list markers or link targets. */
|
|
2344
|
+
const plainPreview = (text) =>
|
|
2345
|
+
str(text)
|
|
2346
|
+
.replace(/```[\s\S]*?```/g, ' ')
|
|
2347
|
+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
2348
|
+
.replace(/^\s{0,3}(?:#{1,6}\s+|>\s?|[-*+]\s+|\d+[.)]\s+)/gm, '')
|
|
2349
|
+
.replace(/(\*\*|__|~~|`)/g, '')
|
|
2350
|
+
.replace(/(^|[\s(])[*_](\S[^*_]*?)[*_](?=[\s).,!?:;,。!?:;]|$)/g, '$1$2')
|
|
2351
|
+
.replace(/\s+/g, ' ')
|
|
2352
|
+
.trim();
|
|
2353
|
+
const excerpt = (text, n = 48) => {
|
|
2354
|
+
const line = plainPreview(str(text).split('\n').find((l) => plainPreview(l) !== '') ?? '');
|
|
2355
|
+
return [...line].length > n ? `${[...line].slice(0, n - 1).join('').trimEnd()}…` : line;
|
|
2356
|
+
};
|
|
2357
|
+
/**
|
|
2358
|
+
* A chat's messages folded into topics: `main` (what the main timeline shows: messages outside any
|
|
2359
|
+
* topic, and the roots), and per root its replies (oldest first) and its latest activity. A reply whose
|
|
2360
|
+
* root is not among the messages stays in the main timeline, so nothing goes missing.
|
|
2361
|
+
*/
|
|
2362
|
+
function topicIndex(items) {
|
|
2363
|
+
const byId = new Map();
|
|
2364
|
+
for (const m of items) if (m && m.id != null) byId.set(m.id, m);
|
|
2365
|
+
const roots = new Map();
|
|
2366
|
+
const rootOf = (id) => {
|
|
2367
|
+
let r = roots.get(id);
|
|
2368
|
+
if (!r) {
|
|
2369
|
+
r = { root: byId.get(id), replies: [], lastAt: toMs(byId.get(id)?.at) || 0, last: null, botAt: 0 };
|
|
2370
|
+
roots.set(id, r);
|
|
2371
|
+
}
|
|
2372
|
+
return r;
|
|
2373
|
+
};
|
|
2374
|
+
const main = [];
|
|
2375
|
+
for (const m of items) {
|
|
2376
|
+
if (!m) continue;
|
|
2377
|
+
const own = str(m.topic);
|
|
2378
|
+
if (own && own === m.id) {
|
|
2379
|
+
rootOf(m.id);
|
|
2380
|
+
main.push(m);
|
|
2381
|
+
}
|
|
2382
|
+
// A moved root stays where it was and is listed in the topic it went to; a reply only there.
|
|
2383
|
+
const home = str(m.movedTo) || (own && own !== m.id ? own : '');
|
|
2384
|
+
if (home && byId.has(home) && home !== m.id) {
|
|
2385
|
+
const r = rootOf(home);
|
|
2386
|
+
// What bots said to each other about the topic's tasks is shown in the topic, not counted as a reply.
|
|
2387
|
+
if (isTraffic(m)) continue;
|
|
2388
|
+
r.replies.push(m);
|
|
2389
|
+
const at = toMs(m.at) || 0;
|
|
2390
|
+
if (at >= r.lastAt) r.lastAt = at;
|
|
2391
|
+
if (!r.last || at >= (toMs(r.last.at) || 0)) r.last = m;
|
|
2392
|
+
// When a bot (or anyone not you) last said something here: what can be unread.
|
|
2393
|
+
if (m.from !== 'user' && at > r.botAt) r.botAt = at;
|
|
2394
|
+
} else if (!(own && own === m.id)) main.push(m);
|
|
2395
|
+
}
|
|
2396
|
+
for (const r of roots.values()) r.replies.sort((a, b) => (toMs(a.at) || 0) - (toMs(b.at) || 0));
|
|
2397
|
+
return { byId, roots, main };
|
|
2398
|
+
}
|
|
2399
|
+
/** Where the "seen" marks of topics live: the browser's storage, or null when there is none (then nothing is unread). */
|
|
2400
|
+
function seenStorage() {
|
|
2401
|
+
try {
|
|
2402
|
+
const s = typeof window !== 'undefined' ? window.localStorage : undefined;
|
|
2403
|
+
return s && typeof s.getItem === 'function' && typeof s.setItem === 'function' ? s : null;
|
|
2404
|
+
} catch {
|
|
2405
|
+
return null;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
const seenKey = (botId) => `dshb:topics-seen:${botId}`;
|
|
2409
|
+
/** The seen marks of a bot's topics (`{rootId: ms}`), `{}` when none were kept yet (`fresh`), or null without storage. */
|
|
2410
|
+
function readSeen(botId) {
|
|
2411
|
+
const s = seenStorage();
|
|
2412
|
+
if (!s) return null;
|
|
2413
|
+
try {
|
|
2414
|
+
const raw = s.getItem(seenKey(botId));
|
|
2415
|
+
if (raw === null || raw === undefined) return { marks: {}, fresh: true };
|
|
2416
|
+
const v = JSON.parse(raw);
|
|
2417
|
+
return { marks: v && typeof v === 'object' && !Array.isArray(v) ? v : {}, fresh: false };
|
|
2418
|
+
} catch {
|
|
2419
|
+
return null;
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
function writeSeen(botId, marks) {
|
|
2423
|
+
const s = seenStorage();
|
|
2424
|
+
if (!s) return;
|
|
2425
|
+
try {
|
|
2426
|
+
// Only the newest topics are worth keeping.
|
|
2427
|
+
const keep = Object.entries(marks).sort((a, b) => b[1] - a[1]).slice(0, 400);
|
|
2428
|
+
s.setItem(seenKey(botId), JSON.stringify(Object.fromEntries(keep)));
|
|
2429
|
+
} catch {
|
|
2430
|
+
// A full or blocked storage: unread marks are a convenience.
|
|
2431
|
+
}
|
|
1750
2432
|
}
|
|
1751
2433
|
|
|
1752
2434
|
/** A first chat: the bot's bio and three opening messages to start from. */
|
|
@@ -1783,9 +2465,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1783
2465
|
const box = useRef(null);
|
|
1784
2466
|
const content = useRef(null);
|
|
1785
2467
|
const pinned = useRef(true);
|
|
2468
|
+
const lastTop = useRef(0);
|
|
1786
2469
|
const toBottom = () => {
|
|
1787
2470
|
const el = box.current;
|
|
1788
|
-
if (el)
|
|
2471
|
+
if (el) {
|
|
2472
|
+
el.scrollTop = el.scrollHeight;
|
|
2473
|
+
lastTop.current = el.scrollTop;
|
|
2474
|
+
}
|
|
1789
2475
|
};
|
|
1790
2476
|
useEffect(() => {
|
|
1791
2477
|
if (pinned.current) toBottom();
|
|
@@ -1798,9 +2484,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1798
2484
|
ro.observe(content.current);
|
|
1799
2485
|
return () => ro.disconnect();
|
|
1800
2486
|
}, [content.current]);
|
|
2487
|
+
// Only the reader scrolling up lets go of the bottom: the browser nudging the view as content grows
|
|
2488
|
+
// (scroll anchoring) can land before the resize is seen, and must not.
|
|
1801
2489
|
const onScroll = (e) => {
|
|
1802
2490
|
const el = e.currentTarget;
|
|
1803
|
-
|
|
2491
|
+
if (el.scrollHeight - el.scrollTop - el.clientHeight < 80) pinned.current = true;
|
|
2492
|
+
else if (el.scrollTop < lastTop.current) pinned.current = false;
|
|
2493
|
+
lastTop.current = el.scrollTop;
|
|
1804
2494
|
};
|
|
1805
2495
|
const stick = () => {
|
|
1806
2496
|
pinned.current = true;
|
|
@@ -1809,172 +2499,1210 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1809
2499
|
return { box, content, onScroll, stick };
|
|
1810
2500
|
}
|
|
1811
2501
|
|
|
1812
|
-
|
|
1813
|
-
|
|
2502
|
+
// --- a bot's question (Harness's ask_user_question), answered here --------------------------
|
|
2503
|
+
|
|
2504
|
+
/** The questions waiting in one conversation (state `asks`), oldest first. */
|
|
2505
|
+
const asksIn = (sessionId) => (sessionId && Array.isArray(store.state?.asks) ? store.state.asks.filter((a) => a && typeof a.id === 'string' && a.sessionId === sessionId && Array.isArray(a.questions)) : []);
|
|
2506
|
+
const NO_PICK = { selected: [], custom: '' };
|
|
2507
|
+
|
|
2508
|
+
/**
|
|
2509
|
+
* A bot's question at the bottom of its chat or task. One single-choice question is answered by a
|
|
2510
|
+
* click on an option; several questions, or a multiple choice, are ticked and submitted. "Other"
|
|
2511
|
+
* takes your own words. An approval or a plan review is answered in the conversation.
|
|
2512
|
+
*/
|
|
2513
|
+
function AskCard({ t, ask, env, onAnswered }) {
|
|
2514
|
+
const [picks, setPicks] = useState({});
|
|
2515
|
+
const [busy, setBusy] = useState(false);
|
|
2516
|
+
const [error, setError] = useState('');
|
|
2517
|
+
const name = botName(t, ask.botId);
|
|
2518
|
+
const questions = ask.questions.filter((q) => q && typeof q.id === 'string');
|
|
2519
|
+
const quick = !ask.native && questions.length === 1 && !questions[0].multiSelect;
|
|
2520
|
+
const pickOf = (q) => picks[q.id] ?? NO_PICK;
|
|
2521
|
+
const change = (q, fn) => setPicks((all) => ({ ...all, [q.id]: { ...(all[q.id] ?? NO_PICK), ...fn(all[q.id] ?? NO_PICK) } }));
|
|
2522
|
+
const item = (q, p) => ({ id: q.id, selected: p.selected, ...(p.custom.trim() ? { custom: p.custom.trim() } : {}) });
|
|
2523
|
+
const complete = questions.every((q) => pickOf(q).selected.length > 0 || pickOf(q).custom.trim() !== '');
|
|
2524
|
+
const post = (answers) => {
|
|
2525
|
+
if (busy) return;
|
|
2526
|
+
setBusy(true);
|
|
2527
|
+
setError('');
|
|
2528
|
+
postJson(`asks/${encodeURIComponent(ask.id)}/answer`, { answers })
|
|
2529
|
+
.then((r) => {
|
|
2530
|
+
if (r?.ok) {
|
|
2531
|
+
onAnswered?.();
|
|
2532
|
+
void refreshState();
|
|
2533
|
+
} else setError(str(r?.reason) || t('askFailed'));
|
|
2534
|
+
})
|
|
2535
|
+
.finally(() => setBusy(false));
|
|
2536
|
+
};
|
|
2537
|
+
const submit = () => (complete ? post(questions.map((q) => item(q, pickOf(q)))) : undefined);
|
|
2538
|
+
const choose = (q, label) => {
|
|
2539
|
+
if (quick) return post([{ id: q.id, selected: [label] }]);
|
|
2540
|
+
change(q, (p) => (q.multiSelect ? { selected: p.selected.includes(label) ? p.selected.filter((x) => x !== label) : [...p.selected, label] } : { selected: [label], custom: '' }));
|
|
2541
|
+
};
|
|
2542
|
+
const option = (q, o) => {
|
|
2543
|
+
const on = !quick && pickOf(q).selected.includes(o.label);
|
|
2544
|
+
return h(
|
|
2545
|
+
'button',
|
|
2546
|
+
{
|
|
2547
|
+
key: o.label,
|
|
2548
|
+
type: 'button',
|
|
2549
|
+
className: 'dshb-row',
|
|
2550
|
+
disabled: busy,
|
|
2551
|
+
onClick: () => choose(q, o.label),
|
|
2552
|
+
'data-dsh-bots-ask-option': o.label,
|
|
2553
|
+
...(quick ? {} : { role: q.multiSelect ? 'checkbox' : 'radio', 'aria-checked': on }),
|
|
2554
|
+
style: { alignItems: 'flex-start', gap: 9, padding: '7px 10px', border: `1px solid ${on ? C.label : C.border1}`, background: on ? tint(C.label, 8) : C.layer1, opacity: busy ? 0.6 : 1 },
|
|
2555
|
+
},
|
|
2556
|
+
quick ? null : h('span', { style: { width: 14, height: 14, marginTop: 2, flex: 'none', borderRadius: q.multiSelect ? 4 : '50%', border: `1.5px solid ${on ? C.label : C.border}`, background: on ? C.label : 'transparent', color: C.onLabel, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' } }, on && q.multiSelect ? Icon.check(10) : null),
|
|
2557
|
+
h('span', { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } }, h('span', { style: { fontWeight: 600, fontSize: SMALL } }, str(o.label)), o.description ? h('span', { style: { fontSize: TINY, color: C.muted } }, str(o.description)) : null),
|
|
2558
|
+
);
|
|
2559
|
+
};
|
|
2560
|
+
const other = (q) => {
|
|
2561
|
+
const p = pickOf(q);
|
|
2562
|
+
const hasOptions = Array.isArray(q.options) && q.options.length > 0;
|
|
2563
|
+
const send = () => (p.custom.trim() ? post([item(q, { selected: [], custom: p.custom })]) : undefined);
|
|
2564
|
+
return h(
|
|
2565
|
+
'div',
|
|
2566
|
+
{ style: { display: 'flex', gap: 6, alignItems: 'center' } },
|
|
2567
|
+
h(Input, {
|
|
2568
|
+
value: p.custom,
|
|
2569
|
+
disabled: busy,
|
|
2570
|
+
placeholder: hasOptions ? t('askOtherPlaceholder') : t('askFreePlaceholder'),
|
|
2571
|
+
'aria-label': hasOptions ? t('askOtherPlaceholder') : t('askFreePlaceholder'),
|
|
2572
|
+
'data-dsh-bots-ask-other': q.id,
|
|
2573
|
+
onChange: (e) => change(q, () => ({ custom: e.target.value, ...(q.multiSelect ? {} : { selected: [] }) })),
|
|
2574
|
+
onKeyDown: (e) => {
|
|
2575
|
+
if (e.key === 'Enter' && !e.isComposing && !e.nativeEvent?.isComposing) {
|
|
2576
|
+
e.preventDefault();
|
|
2577
|
+
if (quick) send();
|
|
2578
|
+
else submit();
|
|
2579
|
+
}
|
|
2580
|
+
},
|
|
2581
|
+
style: { height: 30, fontSize: SMALL },
|
|
2582
|
+
}),
|
|
2583
|
+
quick ? h(Btn, { kind: 'primary', size: 'sm', icon: Icon.send(13), title: t('send'), disabled: busy || !p.custom.trim(), onClick: send, 'data-dsh-bots-ask-send': q.id }) : null,
|
|
2584
|
+
);
|
|
2585
|
+
};
|
|
2586
|
+
return h(
|
|
2587
|
+
'div',
|
|
2588
|
+
{ className: 'dshb-card dshb-fade', 'data-dsh-bots-ask': ask.id, 'data-native': ask.native ? true : undefined, style: { borderColor: tint(C.warn, 55), display: 'flex', flexDirection: 'column', gap: 10, marginBottom: 8 } },
|
|
2589
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, fontWeight: 600, color: C.warn } }, Icon.question(13), t(ask.native ? 'askNativeTitle' : 'askTitle', { name })),
|
|
2590
|
+
questions.map((q) =>
|
|
2591
|
+
h(
|
|
2592
|
+
'div',
|
|
2593
|
+
{ key: q.id, 'data-dsh-bots-ask-question': q.id, style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
2594
|
+
q.header ? h('div', null, h(Badge, { color: C.label }, str(q.header))) : null,
|
|
2595
|
+
h('div', { style: { fontWeight: 600, fontSize: FONT, wordBreak: 'break-word' } }, str(q.question)),
|
|
2596
|
+
q.detail ? h(Clamp, { t, text: q.detail, lines: 6, style: { fontSize: SMALL, color: C.muted } }) : null,
|
|
2597
|
+
ask.native ? null : q.multiSelect ? h('div', { style: { fontSize: TINY, color: C.faint } }, t('askMulti')) : null,
|
|
2598
|
+
ask.native || !Array.isArray(q.options) || q.options.length === 0 ? null : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 } }, q.options.filter((o) => o && typeof o.label === 'string').map((o) => option(q, o))),
|
|
2599
|
+
ask.native ? null : other(q),
|
|
2600
|
+
),
|
|
2601
|
+
),
|
|
2602
|
+
ask.continued ? h('div', { style: { fontSize: TINY, color: C.muted } }, t('askContinued', { name })) : null,
|
|
2603
|
+
ask.native
|
|
2604
|
+
? h(
|
|
2605
|
+
'div',
|
|
2606
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
|
|
2607
|
+
h('span', { style: { fontSize: SMALL, color: C.muted, flex: 1, minWidth: 160 } }, t('askNativeHint')),
|
|
2608
|
+
env?.canOpen?.()
|
|
2609
|
+
? h(Btn, { icon: Icon.chat(14), size: 'sm', 'data-dsh-bots-ask-open': ask.sessionId, onClick: () => (env.openSession?.(ask.sessionId) === true ? undefined : setError(t('openFailed'))) }, t('openConversation'))
|
|
2610
|
+
: null,
|
|
2611
|
+
)
|
|
2612
|
+
: null,
|
|
2613
|
+
!quick && !ask.native ? h('div', { style: { display: 'flex', justifyContent: 'flex-end' } }, h(Btn, { kind: 'primary', size: 'sm', disabled: busy || !complete, onClick: submit, 'data-dsh-bots-ask-submit': ask.id }, t('askSubmit'))) : null,
|
|
2614
|
+
error ? h('div', { 'data-dsh-bots-ask-error': true, style: { fontSize: TINY, color: C.error } }, error) : null,
|
|
2615
|
+
);
|
|
2616
|
+
}
|
|
2617
|
+
/** The waiting questions of one conversation, above its composer. */
|
|
2618
|
+
const AskCards = ({ t, sessionId, env, onAnswered }) => {
|
|
2619
|
+
const list = asksIn(sessionId);
|
|
2620
|
+
return list.length ? h('div', { 'data-dsh-bots-asks': list.length, className: 'dshb-scroll', style: { maxHeight: '45vh' } }, list.map((a) => h(AskCard, { key: a.id, t, ask: a, env, onAnswered }))) : null;
|
|
2621
|
+
};
|
|
2622
|
+
|
|
2623
|
+
/** A chat's messages with the ones being sent from here (`local`) that the Host has not listed yet. */
|
|
2624
|
+
function mergeLocal(items, local) {
|
|
2625
|
+
if (!Array.isArray(items)) return items;
|
|
2626
|
+
if (!local.length) return items;
|
|
2627
|
+
const ids = new Set(items.map((m) => m?.id));
|
|
2628
|
+
const extra = local.filter((m) => !ids.has(m.id));
|
|
2629
|
+
return extra.length ? [...items, ...extra] : items;
|
|
2630
|
+
}
|
|
2631
|
+
/** Whether a topic's bar is on screen in the scrolling `box` (no box, no DOM: not on screen). */
|
|
2632
|
+
function barOnScreen(box, id) {
|
|
2633
|
+
if (!box || typeof box.querySelector !== 'function' || typeof box.getBoundingClientRect !== 'function') return false;
|
|
2634
|
+
let el = null;
|
|
2635
|
+
try {
|
|
2636
|
+
el = box.querySelector(`[data-dsh-bots-topic-bar="${String(id).replace(/["\\]/g, '\\$&')}"]`);
|
|
2637
|
+
} catch {
|
|
2638
|
+
el = null;
|
|
2639
|
+
}
|
|
2640
|
+
if (!el || typeof el.getBoundingClientRect !== 'function') return false;
|
|
2641
|
+
const a = el.getBoundingClientRect();
|
|
2642
|
+
const b = box.getBoundingClientRect();
|
|
2643
|
+
return a.bottom > b.top + 8 && a.top < b.bottom - 8;
|
|
2644
|
+
}
|
|
2645
|
+
/** The line above a composer naming the message a reply answers, with a way to drop it. */
|
|
2646
|
+
function QuoteBar({ t, m, onCancel, attr = 'data-dsh-bots-quote' }) {
|
|
2647
|
+
const who = party(t, m.from);
|
|
2648
|
+
return h(
|
|
2649
|
+
'div',
|
|
2650
|
+
{ [attr]: m.id, className: 'dshb-quote' },
|
|
2651
|
+
h('span', { style: { color: C.label, display: 'inline-flex', flex: 'none' } }, Icon.back(12)),
|
|
2652
|
+
h('span', { style: { fontWeight: 600, flex: 'none' } }, t('replyingTo', { name: who.name })),
|
|
2653
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', color: C.muted } }, excerpt(m.text, 80)),
|
|
2654
|
+
h('button', { type: 'button', className: 'dshb-link', [`${attr}-cancel`]: m.id, title: t('cancelReply'), 'aria-label': t('cancelReply'), onClick: onCancel, style: { display: 'inline-flex', color: C.muted, flex: 'none' } }, Icon.close(12)),
|
|
2655
|
+
);
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
function ChatTab({ t, bot, env, toast }) {
|
|
2659
|
+
const { items: listed, topics, failed, reload } = useMessages(bot.id);
|
|
2660
|
+
const [text, setText] = useState('');
|
|
2661
|
+
// Messages sent from here: shown at once (queued), then the Host's own copy; a failed one stays to be sent again.
|
|
2662
|
+
const [local, setLocal] = useState([]);
|
|
2663
|
+
// The message the main composer replies to, the topic open beside the chat, the bar to point out.
|
|
2664
|
+
const [quote, setQuote] = useState(null);
|
|
2665
|
+
const [open, setOpen] = useState('');
|
|
2666
|
+
const [flash, setFlash] = useState('');
|
|
2667
|
+
// Which topics were read up to when (null: no storage, so nothing is unread).
|
|
2668
|
+
const [seen, setSeen] = useState(() => readSeen(bot.id));
|
|
2669
|
+
const [offscreen, setOffscreen] = useState('');
|
|
2670
|
+
const offscreenRef = useRef('');
|
|
2671
|
+
const measuring = useRef(false);
|
|
2672
|
+
// The quick poll may know before the state does that it started or stopped.
|
|
2673
|
+
const live = liveBot(bot);
|
|
2674
|
+
const running = live.status === 'running' || Boolean(live.activity);
|
|
2675
|
+
const items = mergeLocal(listed, local);
|
|
2676
|
+
const index = topicIndex(items ?? []);
|
|
2677
|
+
const lastMain = index.main[index.main.length - 1];
|
|
2678
|
+
const thread = useStickToBottom(`${index.main.length}:${lastMain?.id ?? ''}:${running}`);
|
|
2679
|
+
const [topicBusy, setTopicBusy] = useState(false);
|
|
2680
|
+
|
|
2681
|
+
// The Host listed what was sent from here: its copies take over.
|
|
2682
|
+
useEffect(() => {
|
|
2683
|
+
if (!Array.isArray(listed) || !local.some((m) => !m.failed)) return;
|
|
2684
|
+
const ids = new Set(listed.map((m) => m?.id));
|
|
2685
|
+
if (local.some((m) => ids.has(m.id))) setLocal((list) => list.filter((m) => !ids.has(m.id)));
|
|
2686
|
+
}, [listed]);
|
|
2687
|
+
// First time here: what is already there counts as read; only replies from now on are new.
|
|
2688
|
+
useEffect(() => {
|
|
2689
|
+
if (!seen || !seen.fresh || !Array.isArray(listed)) return;
|
|
2690
|
+
const marks = {};
|
|
2691
|
+
for (const [id, r] of index.roots) marks[id] = r.lastAt;
|
|
2692
|
+
writeSeen(bot.id, marks);
|
|
2693
|
+
setSeen({ marks, fresh: false });
|
|
2694
|
+
}, [listed === null, seen?.fresh]);
|
|
2695
|
+
const markSeen = (id, at) => {
|
|
2696
|
+
if (!id || !at) return;
|
|
2697
|
+
setSeen((prev) => {
|
|
2698
|
+
if (!prev || (Number(prev.marks[id]) || 0) >= at) return prev;
|
|
2699
|
+
const marks = { ...prev.marks, [id]: at };
|
|
2700
|
+
writeSeen(bot.id, marks);
|
|
2701
|
+
return { marks, fresh: false };
|
|
2702
|
+
});
|
|
2703
|
+
};
|
|
2704
|
+
// A topic with a reply you have not seen: the latest reply is a bot's, newer than when you last looked.
|
|
2705
|
+
const unread = new Set();
|
|
2706
|
+
if (seen && !seen.fresh) {
|
|
2707
|
+
for (const [id, r] of index.roots) {
|
|
2708
|
+
if (id === open || !r.botAt || r.root?.movedTo) continue;
|
|
2709
|
+
const mark = Number(seen.marks[id]) || toMs(r.root?.at) || 0;
|
|
2710
|
+
if (r.botAt > mark) unread.add(id);
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
const unreadIds = [...unread].sort((a, b) => index.roots.get(b).botAt - index.roots.get(a).botAt);
|
|
2714
|
+
const unreadKey = unreadIds.join(',');
|
|
2715
|
+
const measure = () => {
|
|
2716
|
+
const box = thread.box.current;
|
|
2717
|
+
const key = unreadIds.filter((id) => !barOnScreen(box, id)).join(',');
|
|
2718
|
+
if (key !== offscreenRef.current) {
|
|
2719
|
+
offscreenRef.current = key;
|
|
2720
|
+
setOffscreen(key);
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
useEffect(() => {
|
|
2724
|
+
measure();
|
|
2725
|
+
}, [unreadKey]);
|
|
2726
|
+
const measureSoon = () => {
|
|
2727
|
+
if (measuring.current) return;
|
|
2728
|
+
measuring.current = true;
|
|
2729
|
+
const run = () => {
|
|
2730
|
+
measuring.current = false;
|
|
2731
|
+
measure();
|
|
2732
|
+
};
|
|
2733
|
+
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(run);
|
|
2734
|
+
else setTimeout(run, 60);
|
|
2735
|
+
};
|
|
2736
|
+
const hidden = offscreen ? offscreen.split(',').filter((id) => unread.has(id)) : [];
|
|
2737
|
+
const pointAt = (id) => {
|
|
2738
|
+
try {
|
|
2739
|
+
const el = thread.box.current?.querySelector?.(`[data-dsh-bots-topic-bar="${String(id).replace(/["\\]/g, '\\$&')}"]`);
|
|
2740
|
+
el?.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
|
|
2741
|
+
} catch {
|
|
2742
|
+
// Scrolling is a nicety.
|
|
2743
|
+
}
|
|
2744
|
+
setFlash(id);
|
|
2745
|
+
setTimeout(() => setFlash((f) => (f === id ? '' : f)), 1800);
|
|
2746
|
+
measureSoon();
|
|
2747
|
+
};
|
|
2748
|
+
const openTopic = (id) => {
|
|
2749
|
+
if (!id) return;
|
|
2750
|
+
setOpen(id);
|
|
2751
|
+
markSeen(id, index.roots.get(id)?.lastAt ?? Date.now());
|
|
2752
|
+
};
|
|
2753
|
+
|
|
2754
|
+
const startTopic = () => {
|
|
2755
|
+
setTopicBusy(true);
|
|
2756
|
+
postJson('topic/new', { id: bot.id })
|
|
2757
|
+
.then((r) => {
|
|
2758
|
+
if (r?.ok) {
|
|
2759
|
+
toast(t('newTopicDone', { name: bot.name || `@${bot.handle}` }));
|
|
2760
|
+
void reload();
|
|
2761
|
+
void refreshState();
|
|
2762
|
+
} else toast(r?.reason || t('actionFailed'), 'error');
|
|
2763
|
+
})
|
|
2764
|
+
.finally(() => setTopicBusy(false));
|
|
2765
|
+
};
|
|
2766
|
+
/**
|
|
2767
|
+
* Send `body` (a reply in a topic with `replyTo`): it shows at once as queued, the Host's copy
|
|
2768
|
+
* replaces it, and a failure stays with a way to send again. Resolves `{ok, topic}`.
|
|
2769
|
+
*/
|
|
2770
|
+
const sendText = (body, replyTo = '', again = '', topicHint = '') => {
|
|
2771
|
+
const id = again || `local-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
2772
|
+
const target = replyTo ? index.byId.get(replyTo) : null;
|
|
2773
|
+
// The topic it goes into (the Host says for sure): the pane's own, else the one of the message it answers.
|
|
2774
|
+
const topic = replyTo ? topicHint || (target ? topicOfMsg(target) || target.id : replyTo) : id;
|
|
2775
|
+
const row = { id, local: true, pending: true, from: 'user', to: bot.id, chat: bot.id, kind: 'user', text: body, at: Date.now(), topic, ...(replyTo ? { replyTo } : {}) };
|
|
2776
|
+
setLocal((list) => [...list.filter((m) => m.id !== id), row]);
|
|
2777
|
+
return postJson('send', { to: bot.id, text: body, ...(replyTo ? { replyTo } : {}) }).then((r) => {
|
|
2778
|
+
if (r?.ok) {
|
|
2779
|
+
const msg = r.message && typeof r.message === 'object' && r.message.id != null ? r.message : null;
|
|
2780
|
+
setLocal((list) => list.flatMap((m) => (m.id !== id ? [m] : msg ? [{ ...msg, pending: msg.pending ?? true, chat: msg.chat ?? bot.id }] : [])));
|
|
2781
|
+
void reload();
|
|
2782
|
+
void refreshState();
|
|
2783
|
+
return { ok: true, topic: msg ? topicOfMsg(msg) || topic : topic };
|
|
2784
|
+
}
|
|
2785
|
+
setLocal((list) => list.map((m) => (m.id === id ? { ...m, pending: false, failed: true } : m)));
|
|
2786
|
+
toast(r?.reason || t('sendFailed'), 'error');
|
|
2787
|
+
return { ok: false, topic };
|
|
2788
|
+
});
|
|
2789
|
+
};
|
|
2790
|
+
const retry = (m) => {
|
|
2791
|
+
if (!m?.local) return;
|
|
2792
|
+
void sendText(str(m.text), str(m.replyTo), m.id, m.replyTo ? str(m.topic) : '');
|
|
2793
|
+
};
|
|
2794
|
+
const send = () => {
|
|
2795
|
+
const body = text.trim();
|
|
2796
|
+
if (!body) return;
|
|
2797
|
+
const replyTo = quote?.id ?? '';
|
|
2798
|
+
setText('');
|
|
2799
|
+
setQuote(null);
|
|
2800
|
+
if (!replyTo) thread.stick();
|
|
2801
|
+
void sendText(body, replyTo).then((r) => {
|
|
2802
|
+
// A reply went into its topic: open it there, where the answer will come.
|
|
2803
|
+
if (r.ok && replyTo) openTopic(r.topic);
|
|
2804
|
+
else if (!replyTo) thread.stick();
|
|
2805
|
+
});
|
|
2806
|
+
};
|
|
2807
|
+
// A pasted link previews above the composer, as it will in the thread.
|
|
2808
|
+
const previewUrl = linksIn(useDebounced(text, 400))[0] ?? '';
|
|
2809
|
+
const fold = { index, topics, onOpen: openTopic, unread, flash };
|
|
2810
|
+
return h(
|
|
2811
|
+
'div',
|
|
2812
|
+
{ className: 'dshb-chatwrap', 'data-dsh-bots-chat': bot.id, 'data-topic-open': open || undefined },
|
|
2813
|
+
h(
|
|
2814
|
+
'div',
|
|
2815
|
+
{ className: 'dshb-chatmain' },
|
|
2816
|
+
h(
|
|
2817
|
+
'div',
|
|
2818
|
+
{
|
|
2819
|
+
className: 'dshb-scroll',
|
|
2820
|
+
'data-dsh-bots-thread': bot.id,
|
|
2821
|
+
ref: thread.box,
|
|
2822
|
+
onScroll: (e) => {
|
|
2823
|
+
thread.onScroll(e);
|
|
2824
|
+
if (unreadIds.length) measureSoon();
|
|
2825
|
+
},
|
|
2826
|
+
style: { flex: 1, padding: '6px 24px' },
|
|
2827
|
+
},
|
|
2828
|
+
h(
|
|
2829
|
+
'div',
|
|
2830
|
+
{ ref: thread.content },
|
|
2831
|
+
items === null
|
|
2832
|
+
? h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('unavailable') : t('loading'))
|
|
2833
|
+
: h(MessageList, {
|
|
2834
|
+
t,
|
|
2835
|
+
items,
|
|
2836
|
+
botId: bot.id,
|
|
2837
|
+
fold,
|
|
2838
|
+
onReply: (m) => setQuote(m),
|
|
2839
|
+
onRetry: retry,
|
|
2840
|
+
empty: h(ChatEmpty, { t, bot, onPick: setText }),
|
|
2841
|
+
}),
|
|
2842
|
+
running ? h('div', { style: { maxWidth: 880, margin: '0 auto' } }, h(WorkingRow, { t, bot, a: live.activity, attr: bot.id })) : null,
|
|
2843
|
+
),
|
|
2844
|
+
),
|
|
2845
|
+
h(
|
|
2846
|
+
'div',
|
|
2847
|
+
{ style: { padding: '10px 24px 16px', borderTop: `1px solid ${C.border1}`, background: C.base, position: 'relative' } },
|
|
2848
|
+
hidden.length
|
|
2849
|
+
? h(
|
|
2850
|
+
'div',
|
|
2851
|
+
{ className: 'dshb-pillrow' },
|
|
2852
|
+
h(
|
|
2853
|
+
'button',
|
|
2854
|
+
{ type: 'button', className: 'dshb-pill', 'data-dsh-bots-new-replies': hidden.length, onClick: () => pointAt(hidden[0]) },
|
|
2855
|
+
h('span', { style: { width: 7, height: 7, borderRadius: '50%', background: C.error, flex: 'none' } }),
|
|
2856
|
+
hidden.length === 1 ? t('newReplyOne') : t('newReplies', { n: hidden.length }),
|
|
2857
|
+
h('span', { style: { display: 'inline-flex' } }, Icon.chevron(11)),
|
|
2858
|
+
),
|
|
2859
|
+
)
|
|
2860
|
+
: null,
|
|
2861
|
+
h(
|
|
2862
|
+
'div',
|
|
2863
|
+
{ style: { maxWidth: 880, margin: '0 auto' } },
|
|
2864
|
+
// Questions of its own conversation; a task's wait in the task.
|
|
2865
|
+
h(AskCards, { t, sessionId: bot.sessionId, env, onAnswered: () => void reload() }),
|
|
2866
|
+
previewUrl ? h('div', { 'data-dsh-bots-composer-preview': previewUrl, style: { marginBottom: 8, maxHeight: 260, overflow: 'auto' } }, h(LinkCard, { t, url: previewUrl })) : null,
|
|
2867
|
+
h(
|
|
2868
|
+
'div',
|
|
2869
|
+
{ className: 'dshb-composer' },
|
|
2870
|
+
quote ? h(QuoteBar, { t, m: quote, onCancel: () => setQuote(null) }) : null,
|
|
2871
|
+
h(
|
|
2872
|
+
'div',
|
|
2873
|
+
{ style: { display: 'flex', alignItems: 'flex-end', gap: 8 } },
|
|
2874
|
+
h('textarea', {
|
|
2875
|
+
'data-dsh-bots-composer': true,
|
|
2876
|
+
value: text,
|
|
2877
|
+
rows: Math.min(8, Math.max(1, text.split('\n').length)),
|
|
2878
|
+
placeholder: quote ? t('topicComposer') : t('composer', { handle: bot.handle }),
|
|
2879
|
+
onChange: (e) => setText(e.target.value),
|
|
2880
|
+
onKeyDown: (e) => {
|
|
2881
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !e.nativeEvent?.isComposing) {
|
|
2882
|
+
e.preventDefault();
|
|
2883
|
+
send();
|
|
2884
|
+
} else if (e.key === 'Escape' && quote) setQuote(null);
|
|
2885
|
+
},
|
|
2886
|
+
style: { flex: 1, minWidth: 0, minHeight: 32, maxHeight: 200, resize: 'none', border: 'none', outline: 'none', background: 'transparent', color: C.primary, font: 'inherit', fontSize: FONT, lineHeight: 1.5, padding: '6px 8px' },
|
|
2887
|
+
}),
|
|
2888
|
+
h(Btn, { kind: 'primary', icon: Icon.send(15), title: t('send'), disabled: !text.trim(), onClick: send, style: { borderRadius: 10, width: 34, height: 34 } }),
|
|
2889
|
+
),
|
|
2890
|
+
),
|
|
2891
|
+
h(
|
|
2892
|
+
'div',
|
|
2893
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 7, fontSize: TINY, color: C.faint, flexWrap: 'wrap' } },
|
|
2894
|
+
h('span', null, t('composerHint')),
|
|
2895
|
+
h('span', { style: { flex: 1 } }),
|
|
2896
|
+
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,
|
|
2897
|
+
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')),
|
|
2898
|
+
env.canOpen() ? h('span', { style: { color: C.faint } }, '·') : null,
|
|
2899
|
+
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,
|
|
2900
|
+
),
|
|
2901
|
+
),
|
|
2902
|
+
),
|
|
2903
|
+
),
|
|
2904
|
+
// Last in the tree: the topic beside the chat (over it when the panel is narrow).
|
|
2905
|
+
open ? h(ThreadPane, { key: open, t, bot, rootId: open, base: index, baseTopics: topics, local, onClose: () => setOpen(''), onSend: sendText, onRetry: retry, onSeen: markSeen }) : null,
|
|
2906
|
+
);
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
/**
|
|
2910
|
+
* One topic beside the chat: its root, every reply (and the messages the dispatcher moved into it),
|
|
2911
|
+
* its tasks while they run, and a composer whose messages go into this topic (or answer one of its
|
|
2912
|
+
* messages). It polls the topic on its own, starting from what the chat already shows.
|
|
2913
|
+
*/
|
|
2914
|
+
function ThreadPane({ t, bot, rootId, base, baseTopics, local, onClose, onSend, onRetry, onSeen }) {
|
|
2915
|
+
const { items, topics } = useMessages(bot.id, true, rootId);
|
|
2916
|
+
const [text, setText] = useState('');
|
|
2917
|
+
const [quote, setQuote] = useState(null);
|
|
2918
|
+
const fromBase = [base.byId.get(rootId), ...(base.roots.get(rootId)?.replies ?? [])].filter(Boolean);
|
|
2919
|
+
const list = mergeLocal(Array.isArray(items) && items.length ? items : fromBase, local) ?? [];
|
|
2920
|
+
const root = list.find((m) => m?.id === rootId) ?? base.byId.get(rootId) ?? null;
|
|
2921
|
+
const seenIds = new Set();
|
|
2922
|
+
const replies = list
|
|
2923
|
+
.filter((m) => inTopic(m, rootId) && !seenIds.has(m.id) && seenIds.add(m.id))
|
|
2924
|
+
.sort((a, b) => (toMs(a.at) || 0) - (toMs(b.at) || 0));
|
|
2925
|
+
const shown = root ? [root, ...replies] : replies;
|
|
2926
|
+
const lastAt = Math.max(toMs(root?.at) || 0, ...replies.map((m) => toMs(m.at) || 0));
|
|
2927
|
+
const tasks = topicTasks({ topics: Array.isArray(items) ? topics : baseTopics }, rootId);
|
|
2928
|
+
const stick = useStickToBottom(`${replies.length}:${replies[replies.length - 1]?.id ?? ''}`);
|
|
2929
|
+
// Open means read: what arrives while it is open is read too.
|
|
2930
|
+
useEffect(() => {
|
|
2931
|
+
onSeen?.(rootId, lastAt);
|
|
2932
|
+
}, [rootId, lastAt]);
|
|
2933
|
+
const send = () => {
|
|
2934
|
+
const body = text.trim();
|
|
2935
|
+
if (!body) return;
|
|
2936
|
+
const replyTo = quote?.id ?? rootId;
|
|
2937
|
+
setText('');
|
|
2938
|
+
setQuote(null);
|
|
2939
|
+
stick.stick();
|
|
2940
|
+
void onSend(body, replyTo, '', rootId).then(() => stick.stick());
|
|
2941
|
+
};
|
|
2942
|
+
const count = replies.filter((m) => !isTraffic(m)).length;
|
|
2943
|
+
return h(
|
|
2944
|
+
'aside',
|
|
2945
|
+
{
|
|
2946
|
+
className: 'dshb-threadpane dshb-fade',
|
|
2947
|
+
'data-dsh-bots-thread-pane': rootId,
|
|
2948
|
+
onKeyDown: (e) => {
|
|
2949
|
+
if (e.key === 'Escape' && !quote) onClose();
|
|
2950
|
+
},
|
|
2951
|
+
},
|
|
2952
|
+
h(
|
|
2953
|
+
'div',
|
|
2954
|
+
{ className: 'dshb-threadhead' },
|
|
2955
|
+
h('span', { style: { color: C.label, display: 'inline-flex', flex: 'none' } }, Icon.chat(15)),
|
|
2956
|
+
h(
|
|
2957
|
+
'div',
|
|
2958
|
+
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0, flex: 1 } },
|
|
2959
|
+
h('span', { style: { fontWeight: 700, fontSize: SMALL } }, t('topicTitle')),
|
|
2960
|
+
h('span', { 'data-dsh-bots-thread-title': true, style: { fontSize: TINY, color: C.muted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, root ? excerpt(root.text, 80) : ''),
|
|
2961
|
+
),
|
|
2962
|
+
h('button', { type: 'button', className: 'dshb-btn dshb-btn-ghost dshb-btn-sm dshb-btn-icon', 'data-dsh-bots-thread-close': rootId, title: t('closeTopic'), 'aria-label': t('closeTopic'), onClick: onClose }, Icon.close(14)),
|
|
2963
|
+
),
|
|
2964
|
+
tasks.length ? h('div', { 'data-dsh-bots-thread-tasks': tasks.length, style: { padding: '6px 10px', borderBottom: `1px solid ${C.border1}`, display: 'flex', flexDirection: 'column', gap: 2, maxHeight: '32%', overflow: 'auto' } }, tasks.map((row) => h(TaskRow, { key: row.id, t, row }))) : null,
|
|
2965
|
+
h(
|
|
2966
|
+
'div',
|
|
2967
|
+
{ className: 'dshb-scroll', 'data-dsh-bots-thread-body': rootId, ref: stick.box, onScroll: stick.onScroll, style: { flex: 1, padding: '4px 16px 12px' } },
|
|
2968
|
+
h(
|
|
2969
|
+
'div',
|
|
2970
|
+
{ ref: stick.content },
|
|
2971
|
+
shown.length
|
|
2972
|
+
? h(MessageList, {
|
|
2973
|
+
t,
|
|
2974
|
+
items: shown,
|
|
2975
|
+
botId: bot.id,
|
|
2976
|
+
onReply: (m) => setQuote(m.id === rootId ? null : m),
|
|
2977
|
+
onRetry,
|
|
2978
|
+
movedIn: (m) => m.movedTo === rootId && m.id !== rootId,
|
|
2979
|
+
empty: null,
|
|
2980
|
+
})
|
|
2981
|
+
: null,
|
|
2982
|
+
h('div', { 'data-dsh-bots-thread-count': count, style: { fontSize: TINY, color: C.faint, textAlign: 'center', padding: '10px 0 0' } }, count ? t(count === 1 ? 'topicReplyOne' : 'topicReplies', { n: count }) : t('topicEmpty')),
|
|
2983
|
+
),
|
|
2984
|
+
),
|
|
2985
|
+
h(
|
|
2986
|
+
'div',
|
|
2987
|
+
{ style: { padding: '8px 12px 12px', borderTop: `1px solid ${C.border1}` } },
|
|
2988
|
+
h(
|
|
2989
|
+
'div',
|
|
2990
|
+
{ className: 'dshb-composer' },
|
|
2991
|
+
quote ? h(QuoteBar, { t, m: quote, onCancel: () => setQuote(null), attr: 'data-dsh-bots-thread-quote' }) : null,
|
|
2992
|
+
h(
|
|
2993
|
+
'div',
|
|
2994
|
+
{ style: { display: 'flex', alignItems: 'flex-end', gap: 8 } },
|
|
2995
|
+
h('textarea', {
|
|
2996
|
+
'data-dsh-bots-thread-composer': rootId,
|
|
2997
|
+
value: text,
|
|
2998
|
+
rows: Math.min(6, Math.max(1, text.split('\n').length)),
|
|
2999
|
+
placeholder: t('topicComposer'),
|
|
3000
|
+
onChange: (e) => setText(e.target.value),
|
|
3001
|
+
onKeyDown: (e) => {
|
|
3002
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !e.nativeEvent?.isComposing) {
|
|
3003
|
+
e.preventDefault();
|
|
3004
|
+
send();
|
|
3005
|
+
} else if (e.key === 'Escape' && quote) {
|
|
3006
|
+
e.stopPropagation?.();
|
|
3007
|
+
setQuote(null);
|
|
3008
|
+
}
|
|
3009
|
+
},
|
|
3010
|
+
style: { flex: 1, minWidth: 0, minHeight: 30, maxHeight: 160, resize: 'none', border: 'none', outline: 'none', background: 'transparent', color: C.primary, font: 'inherit', fontSize: FONT, lineHeight: 1.5, padding: '5px 8px' },
|
|
3011
|
+
}),
|
|
3012
|
+
h(Btn, { kind: 'primary', icon: Icon.send(14), title: t('send'), disabled: !text.trim(), onClick: send, 'data-dsh-bots-thread-send': rootId, style: { borderRadius: 9, width: 32, height: 32 } }),
|
|
3013
|
+
),
|
|
3014
|
+
),
|
|
3015
|
+
),
|
|
3016
|
+
);
|
|
3017
|
+
}
|
|
3018
|
+
|
|
3019
|
+
function ActivityView({ t, bots }) {
|
|
3020
|
+
const { items, failed } = useMessages(null);
|
|
3021
|
+
const [filter, setFilter] = useState('');
|
|
3022
|
+
const shown = (items ?? []).filter((m) => !filter || m.from === filter || m.to === filter).slice().reverse();
|
|
3023
|
+
const names = threadNamesOf(items);
|
|
3024
|
+
return h(
|
|
3025
|
+
'div',
|
|
3026
|
+
{ style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
3027
|
+
h(
|
|
3028
|
+
'div',
|
|
3029
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 12, padding: '18px 24px 12px', borderBottom: `1px solid ${C.border1}` } },
|
|
3030
|
+
h('span', { style: { width: 44, height: 44, borderRadius: '50%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.layer2, color: C.label } }, Icon.activity(20)),
|
|
3031
|
+
h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { style: { fontWeight: 700, fontSize: 17 } }, t('activity')), h('div', { style: { fontSize: SMALL, color: C.muted } }, t('activitySub'))),
|
|
3032
|
+
h(
|
|
3033
|
+
'select',
|
|
3034
|
+
{ className: 'dshb-input', value: filter, onChange: (e) => setFilter(e.target.value), style: { width: 200, height: 30, fontSize: SMALL }, 'aria-label': t('filterBot') },
|
|
3035
|
+
h('option', { value: '' }, t('allBots')),
|
|
3036
|
+
bots.map((b) => h('option', { key: b.id, value: b.id }, `${b.name} (@${b.handle})`)),
|
|
3037
|
+
),
|
|
3038
|
+
),
|
|
3039
|
+
h(
|
|
3040
|
+
'div',
|
|
3041
|
+
{ className: 'dshb-scroll', 'data-dsh-bots-timeline': true, style: { flex: 1, padding: '8px 24px 24px' } },
|
|
3042
|
+
h(
|
|
3043
|
+
'div',
|
|
3044
|
+
{ style: { maxWidth: 960, margin: '0 auto' } },
|
|
3045
|
+
items === null
|
|
3046
|
+
? h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('unavailable') : t('loading'))
|
|
3047
|
+
: shown.length === 0
|
|
3048
|
+
? h(Empty, { icon: Icon.activity(28), title: t('activityEmptyTitle'), body: t('activityEmptyBody') })
|
|
3049
|
+
: shown.map((m, i) => {
|
|
3050
|
+
const from = party(t, m.from);
|
|
3051
|
+
const to = party(t, m.to);
|
|
3052
|
+
return h(
|
|
3053
|
+
'div',
|
|
3054
|
+
{ key: m.id ?? i, 'data-dsh-bots-event': m.kind, style: { display: 'flex', gap: 12, padding: '12px 0', borderBottom: `1px solid ${C.border1}` } },
|
|
3055
|
+
h(
|
|
3056
|
+
'div',
|
|
3057
|
+
{ style: { position: 'relative', width: 40, height: 34, flex: 'none' } },
|
|
3058
|
+
h('span', { style: { position: 'absolute', left: 0, top: 0 } }, h(PartyAvatar, { p: from, size: 30 })),
|
|
3059
|
+
h('span', { style: { position: 'absolute', left: 21, top: 19, display: 'inline-flex', borderRadius: '50%', boxShadow: `0 0 0 2px ${C.base}` } }, h(PartyAvatar, { p: to, size: 17 })),
|
|
3060
|
+
),
|
|
3061
|
+
h(
|
|
3062
|
+
'div',
|
|
3063
|
+
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
3064
|
+
h(
|
|
3065
|
+
'div',
|
|
3066
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: SMALL, flexWrap: 'wrap' } },
|
|
3067
|
+
h('span', { style: { fontWeight: 600 } }, from.name),
|
|
3068
|
+
h('span', { style: { color: C.faint, display: 'inline-flex' } }, Icon.arrow(11)),
|
|
3069
|
+
h('span', { style: { fontWeight: 600 } }, to.name),
|
|
3070
|
+
h(Badge, { color: m.kind === 'dm' ? C.label : m.kind === 'system' ? C.warn : C.muted }, t(`kind_${m.kind}`) || m.kind),
|
|
3071
|
+
messageReport(m) ? h(ReportChip, { t, status: messageReport(m) }) : null,
|
|
3072
|
+
messageNotice(m) ? h(StageChip, { t, stage: messageNotice(m) }) : null,
|
|
3073
|
+
messageTicket(m) ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-event-task': messageTicket(m), onClick: () => openTicket(messageTicket(m)), style: { fontSize: TINY } }, t('openTask')) : null,
|
|
3074
|
+
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)}` : isChatThread(m.thread) ? threadName(t, m.thread, names) : channelName(m.via, t)) : null,
|
|
3075
|
+
m.notSent === true ? h(Badge, { color: C.warn, 'data-dsh-bots-not-sent': true, title: (Array.isArray(m.choices) ? m.choices.filter(isChatThread) : []).map((k) => threadName(t, k, names)).join(t('listSep')) }, t('notSent')) : null,
|
|
3076
|
+
h('span', { style: { marginLeft: 'auto', color: C.faint, fontSize: TINY }, title: fmtDate(toMs(m.at)) }, fmtAgo(t, m.at)),
|
|
3077
|
+
),
|
|
3078
|
+
h(Clamp, { t, text: m.kind === 'topic' ? t('topicDivider', { reason: t(`topicReason_${m.text}`) }) : m.text, lines: 3, style: { fontSize: SMALL, color: C.muted } }),
|
|
3079
|
+
),
|
|
3080
|
+
);
|
|
3081
|
+
}),
|
|
3082
|
+
),
|
|
3083
|
+
),
|
|
3084
|
+
);
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
// --- tasks: the list, one task, a bot's open tasks, cards in the timeline ---------------
|
|
3088
|
+
|
|
3089
|
+
const NEEDS_YOU = ['question', 'failed', 'stalled'];
|
|
3090
|
+
const FINISHED = ['done', 'stopped'];
|
|
3091
|
+
const STAGE_COLOR = { question: C.warn, failed: C.error, stalled: C.warn, queued: C.muted, working: C.ok, done: C.label, stopped: C.muted };
|
|
3092
|
+
const REPORT_STATUSES = ['progress', 'done', 'blocked', 'question'];
|
|
3093
|
+
const REPORT_COLOR = { progress: C.muted, done: C.ok, blocked: C.error, question: C.warn };
|
|
3094
|
+
/** Open tasks of a bot, from the polled counts. */
|
|
3095
|
+
const openTaskCount = (bot) => ['working', 'question', 'stalled', 'queued'].reduce((n, k) => n + (Number(bot?.tickets?.[k]) || 0), 0);
|
|
3096
|
+
const DONE_PAGE = 20;
|
|
3097
|
+
// A task whose conversation waits for your answer to its question (`asking`) needs you too.
|
|
3098
|
+
const groupOf = (row) => (row?.asking || NEEDS_YOU.includes(row?.stage) ? 'needs' : FINISHED.includes(row?.stage) ? 'done' : 'progress');
|
|
3099
|
+
const newestFirst = (a, b) => (toMs(b.updatedAt ?? b.createdAt) || 0) - (toMs(a.updatedAt ?? a.createdAt) || 0);
|
|
3100
|
+
const taskTitle = (t, row) => str(row?.title).trim() || t('untitledTask');
|
|
3101
|
+
const firstLine = (text) => (str(text).split('\n').find((l) => l.trim() !== '') ?? '').trim().slice(0, 120);
|
|
3102
|
+
/** The task a timeline message belongs to (a delegation, or a report on it), or ''. */
|
|
3103
|
+
function messageTicket(m) {
|
|
3104
|
+
const v = m?.ticket && typeof m.ticket === 'object' ? m.ticket.id : (m?.ticket ?? m?.ticketId);
|
|
3105
|
+
return typeof v === 'string' ? v : '';
|
|
3106
|
+
}
|
|
3107
|
+
/** The status of a worker's report on a timeline message, or ''. */
|
|
3108
|
+
function messageReport(m) {
|
|
3109
|
+
const v = m?.report && typeof m.report === 'object' ? m.report.status : (m?.report ?? m?.status);
|
|
3110
|
+
return REPORT_STATUSES.includes(v) ? v : '';
|
|
3111
|
+
}
|
|
3112
|
+
/** The stage a watchdog notice on a timeline message tells of (a task stuck, or failed for good), or ''. */
|
|
3113
|
+
const messageNotice = (m) => (m?.kind === 'dm' && messageTicket(m) && (m.status === 'stalled' || m.status === 'failed') ? m.status : '');
|
|
3114
|
+
function StageChip({ t, stage }) {
|
|
3115
|
+
if (!STAGE_COLOR[stage]) return null;
|
|
3116
|
+
return h(Badge, { color: STAGE_COLOR[stage], 'data-dsh-bots-stage': stage }, stage === 'working' ? h(StatusDot, { status: 'running', size: 6 }) : null, t(`stage_${stage}`));
|
|
3117
|
+
}
|
|
3118
|
+
/** A task's stage, or that it waits for your answer to its question. */
|
|
3119
|
+
const TaskChip = ({ t, row }) => (row?.asking ? h(Badge, { color: C.warn, 'data-dsh-bots-task-asking': row.id }, Icon.question(11), t('askingChip')) : h(StageChip, { t, stage: row?.stage }));
|
|
3120
|
+
const ReportChip = ({ t, status }) => (REPORT_COLOR[status] ? h(Badge, { color: REPORT_COLOR[status], 'data-dsh-bots-report': status }, t(`report_${status}`)) : null);
|
|
3121
|
+
/** Who asked for a task: you, or a bot (the dispatcher, or the bot of a parent task). */
|
|
3122
|
+
const requesterBot = (row) => {
|
|
3123
|
+
const r = row?.requester ?? {};
|
|
3124
|
+
return r.kind === 'user' || typeof r.botId !== 'string' || !r.botId ? null : r.botId;
|
|
3125
|
+
};
|
|
3126
|
+
const requesterText = (t, row) => (requesterBot(row) ? t('askedBy', { name: botName(t, requesterBot(row)) }) : t('askedByYou'));
|
|
3127
|
+
const requesterName = (t, row) => (requesterBot(row) ? botName(t, requesterBot(row)) : t('you'));
|
|
3128
|
+
/** The chat a task came in from, as a badge (a scheduled run's task says so). */
|
|
3129
|
+
function viaBadge(t, via, who) {
|
|
3130
|
+
if (!via || typeof via !== 'string') return null;
|
|
3131
|
+
if (via === 'schedule') return h(Badge, { color: C.warn, 'data-dsh-bots-task-via': via }, t('trigger_schedule'));
|
|
3132
|
+
const label = via === 'panel' ? t('viaPanel') : channelName(via, t);
|
|
3133
|
+
return h(Badge, { color: CHANNEL_COLORS[via] ?? C.muted, 'data-dsh-bots-task-via': via }, who ? `${label} · ${str(who)}` : label);
|
|
3134
|
+
}
|
|
3135
|
+
const BotFace = ({ id, size }) => {
|
|
3136
|
+
const b = botById(id);
|
|
3137
|
+
return b ? h(Avatar, { avatar: b.avatar, name: b.name || b.handle, size }) : h(PartyAvatar, { p: { kind: 'unknown' }, size });
|
|
3138
|
+
};
|
|
3139
|
+
const dotSep = () => h('span', { style: { color: C.faint } }, '·');
|
|
3140
|
+
|
|
3141
|
+
// --- live status: what a bot's conversation or a task's does right now ------------------------
|
|
3142
|
+
|
|
3143
|
+
/** Tool names (an MCP tool by its last part) by what the panel says they do; the Host sends the name and a short `detail`. */
|
|
3144
|
+
const ACT_TOOLS = [
|
|
3145
|
+
[/^(bash|pwsh|shell|sh|terminal|exec|run_command|execute_command)$/, 'run'],
|
|
3146
|
+
[/^(read|read_file|read_image|view|open_file|cat)$/, 'read'],
|
|
3147
|
+
[/^(edit|str_replace|str_replace_editor|str_replace_based_edit_tool|multi_edit|multiedit|apply_patch|patch|notebook_edit)$/, 'edit'],
|
|
3148
|
+
[/^(write|write_file|create_file)$/, 'write'],
|
|
3149
|
+
[/^(grep|glob|ls|find|search_files|list_files|list_directory|ripgrep)$/, 'find'],
|
|
3150
|
+
[/^bot_send_message$/, 'send'],
|
|
3151
|
+
[/^memory_search$/, 'memory'],
|
|
3152
|
+
[/^memory_(save|forget)$/, 'remember'],
|
|
3153
|
+
[/(^|_)search$|^websearch$/, 'search'],
|
|
3154
|
+
[/^(web_fetch|fetch|webfetch|browse|open_url)$/, 'fetch'],
|
|
3155
|
+
[/^ask_user_question$/, 'ask'],
|
|
3156
|
+
[/^generate_image$/, 'draw'],
|
|
3157
|
+
[/^(subagent|task|agent|wait_agent)$/, 'helper'],
|
|
3158
|
+
[/^(skill|load_skill)$/, 'skill'],
|
|
3159
|
+
[/^bot_reply$/, 'reply'],
|
|
3160
|
+
[/^bot_recall$/, 'recall'],
|
|
3161
|
+
[/^bot_(create|update|delete|list|ticket)$/, 'team'],
|
|
3162
|
+
[/^bot_schedule$/, 'schedule'],
|
|
3163
|
+
[/^(todo|todo_write|todowrite|plan)$/, 'plan'],
|
|
3164
|
+
[/^job_/, 'job'],
|
|
3165
|
+
[/^office_/, 'office'],
|
|
3166
|
+
];
|
|
3167
|
+
/** Kinds of tool whose words name what they work on, when the Host sent it. */
|
|
3168
|
+
const ACT_DETAIL = new Set(['run', 'read', 'edit', 'write', 'find', 'search', 'fetch', 'helper', 'skill', 'memory', 'recall']);
|
|
3169
|
+
/** An activity as words: its dictionary key, the detail set off in it, and whether that detail is code. */
|
|
3170
|
+
function activityWords(a) {
|
|
3171
|
+
if (!a || typeof a !== 'object') return null;
|
|
3172
|
+
if (a.kind === 'writing') return { key: 'act_writing', detail: '' };
|
|
3173
|
+
if (a.kind !== 'tool') return { key: 'act_thinking', detail: '' };
|
|
3174
|
+
const tool = str(a.tool);
|
|
3175
|
+
const short = tool.toLowerCase().split('__').pop();
|
|
3176
|
+
const detail = str(a.detail).trim();
|
|
3177
|
+
const act = (ACT_TOOLS.find(([re]) => re.test(short)) ?? [null, 'tool'])[1];
|
|
3178
|
+
if (act === 'send') return detail.startsWith('@') ? { key: 'act_delegate', detail } : detail.startsWith('#') ? { key: 'act_followup', detail: detail.slice(1) } : { key: 'act_report', detail: '' };
|
|
3179
|
+
if (act === 'tool') return { key: 'act_tool', detail: tool.split('__').pop() || tool || '?', code: true };
|
|
3180
|
+
if (ACT_DETAIL.has(act)) return detail ? { key: `act_${act}`, detail, code: act === 'run' } : { key: `act_${act}_bare`, detail: '' };
|
|
3181
|
+
return { key: `act_${act}`, detail: '' };
|
|
3182
|
+
}
|
|
3183
|
+
/** The activity in plain words (a title, a row of text). */
|
|
3184
|
+
function activityLine(t, a) {
|
|
3185
|
+
const w = activityWords(a);
|
|
3186
|
+
return w ? t(w.key, { detail: w.detail }) : '';
|
|
3187
|
+
}
|
|
3188
|
+
/** The activity in words, its detail set off (a command in code type). */
|
|
3189
|
+
function ActivityWords({ t, a }) {
|
|
3190
|
+
const w = activityWords(a);
|
|
3191
|
+
if (!w) return null;
|
|
3192
|
+
if (!w.detail) return h('span', { 'data-dsh-bots-act': w.key }, t(w.key));
|
|
3193
|
+
const [before, after = ''] = t(w.key, { detail: '\u0000' }).split('\u0000');
|
|
3194
|
+
return h('span', { 'data-dsh-bots-act': w.key }, before, h('span', { className: w.code ? 'dshb-act-code' : 'dshb-act-detail' }, w.detail), after);
|
|
3195
|
+
}
|
|
3196
|
+
/** The Host's clock now, as far as this page can tell (its answers carry their time). */
|
|
3197
|
+
const hostNow = () => Date.now() + (Number.isFinite(store.skew) ? store.skew : 0);
|
|
3198
|
+
/** A running time as a timer reads: 42s, 1m 05s, 1h 02m. */
|
|
3199
|
+
function fmtElapsed(t, ms) {
|
|
3200
|
+
const sec = Math.max(0, Math.floor((Number(ms) || 0) / 1000));
|
|
3201
|
+
if (sec < 60) return t('elapsedS', { s: sec });
|
|
3202
|
+
if (sec < 3600) return t('elapsedM', { m: Math.floor(sec / 60), s: pad(sec % 60) });
|
|
3203
|
+
return t('elapsedH', { h: Math.floor(sec / 3600), m: pad(Math.floor(sec / 60) % 60) });
|
|
3204
|
+
}
|
|
3205
|
+
/** Re-render every second while `on`, so running times tick between polls. */
|
|
3206
|
+
function useTick(on) {
|
|
3207
|
+
const [, force] = useState(0);
|
|
3208
|
+
useEffect(() => {
|
|
3209
|
+
if (!on) return undefined;
|
|
3210
|
+
let id = null;
|
|
3211
|
+
try {
|
|
3212
|
+
id = setInterval(() => force((n) => n + 1), 1000);
|
|
3213
|
+
id?.unref?.();
|
|
3214
|
+
} catch {
|
|
3215
|
+
id = null;
|
|
3216
|
+
}
|
|
3217
|
+
return () => {
|
|
3218
|
+
if (id) clearInterval(id);
|
|
3219
|
+
};
|
|
3220
|
+
}, [on]);
|
|
3221
|
+
}
|
|
3222
|
+
/** The freshest activity of a bot's task conversations (with `ticket`), or null. */
|
|
3223
|
+
function botTaskActivity(botId) {
|
|
3224
|
+
let best = null;
|
|
3225
|
+
for (const [id, a] of Object.entries(liveTasks())) if (a && a.botId === botId && (!best || (Number(a.stepAt) || 0) > (Number(best.stepAt) || 0))) best = { ...a, ticket: id };
|
|
3226
|
+
return best;
|
|
3227
|
+
}
|
|
3228
|
+
/** The one-line live status: what it does now and for how long (`compact`: muted, for a row). */
|
|
3229
|
+
function LiveLine({ t, a, attr, style }) {
|
|
3230
|
+
useTick(Boolean(a));
|
|
3231
|
+
if (!a) return null;
|
|
3232
|
+
const now = hostNow();
|
|
3233
|
+
const time = fmtElapsed(t, now - (Number(a.stepAt) || now));
|
|
3234
|
+
// The words give way (an ellipsis); the time stays.
|
|
3235
|
+
return h(
|
|
3236
|
+
'span',
|
|
3237
|
+
{ 'data-dsh-bots-live': attr ?? true, title: `${activityLine(t, a)} · ${time}`, className: 'dshb-live dshb-liveline', style },
|
|
3238
|
+
h('span', { className: 'dshb-liveline-words' }, h(ActivityWords, { t, a })),
|
|
3239
|
+
h('span', { className: 'dshb-live-time' }, `· ${time}`),
|
|
3240
|
+
);
|
|
3241
|
+
}
|
|
3242
|
+
/**
|
|
3243
|
+
* The working row of a chat or a task: the bot, what it does now (ticking), then the step and
|
|
3244
|
+
* the turn's time so far. Without an activity yet (an older Host, the first poll) it says the bot works.
|
|
3245
|
+
*/
|
|
3246
|
+
function WorkingRow({ t, bot, a, attr }) {
|
|
3247
|
+
useTick(true);
|
|
3248
|
+
const now = hostNow();
|
|
3249
|
+
const name = bot ? bot.name || `@${bot.handle}` : '';
|
|
3250
|
+
return h(
|
|
3251
|
+
'div',
|
|
3252
|
+
{ 'data-dsh-bots-working': attr ?? true, className: 'dshb-fade', style: { display: 'flex', alignItems: 'center', gap: 10, padding: '10px 0 2px', minWidth: 0 } },
|
|
3253
|
+
h('div', { style: { width: 30, flex: 'none', display: 'flex', justifyContent: 'center' } }, bot ? h(Avatar, { avatar: bot.avatar, name, size: 24, working: true }) : null),
|
|
3254
|
+
h(
|
|
3255
|
+
'div',
|
|
3256
|
+
{ style: { display: 'flex', alignItems: 'baseline', gap: 8, minWidth: 0, flex: 1, fontSize: SMALL } },
|
|
3257
|
+
name ? h('span', { style: { fontWeight: 650, color: C.primary, flex: 'none' } }, name) : null,
|
|
3258
|
+
a
|
|
3259
|
+
? h(
|
|
3260
|
+
'span',
|
|
3261
|
+
{ className: 'dshb-live', 'data-dsh-bots-live': 'working', style: { color: C.primary, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
3262
|
+
h(ActivityWords, { t, a }),
|
|
3263
|
+
h('span', { className: 'dshb-live-time' }, ` · ${fmtElapsed(t, now - (Number(a.stepAt) || now))}`),
|
|
3264
|
+
)
|
|
3265
|
+
: h('span', { style: { color: C.muted } }, t('workingPlain')),
|
|
3266
|
+
h('span', { className: 'dshb-dots', 'aria-hidden': 'true' }, h('i'), h('i'), h('i')),
|
|
3267
|
+
// The step and the turn's time, once they say more than the current activity's time does.
|
|
3268
|
+
a && (Number(a.steps) > 1 || (Number(a.stepAt) || 0) - (Number(a.startedAt) || 0) > 2000)
|
|
3269
|
+
? h('span', { 'data-dsh-bots-live-total': true, style: { marginLeft: 'auto', paddingLeft: 12, flex: 'none', color: C.faint, fontSize: TINY, fontVariantNumeric: 'tabular-nums' } }, t('liveTotal', { n: Math.max(1, Number(a.steps) || 1), time: fmtElapsed(t, now - (Number(a.startedAt) || now)) }))
|
|
3270
|
+
: null,
|
|
3271
|
+
),
|
|
3272
|
+
);
|
|
3273
|
+
}
|
|
3274
|
+
/** A working task's stage chip, alive: what its conversation does now and for how long. */
|
|
3275
|
+
function LiveChip({ t, a }) {
|
|
3276
|
+
useTick(Boolean(a));
|
|
3277
|
+
const now = hostNow();
|
|
3278
|
+
return h(
|
|
3279
|
+
'span',
|
|
3280
|
+
{ 'data-dsh-bots-stage': 'working', 'data-dsh-bots-live': 'chip', title: `${t('stage_working')}: ${activityLine(t, a)}`, className: 'dshb-livechip' },
|
|
3281
|
+
h(StatusDot, { status: 'running', size: 6 }),
|
|
3282
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 } }, h(ActivityWords, { t, a })),
|
|
3283
|
+
h('span', { className: 'dshb-live-time', style: { flex: 'none' } }, fmtElapsed(t, now - (Number(a.stepAt) || now))),
|
|
3284
|
+
);
|
|
3285
|
+
}
|
|
3286
|
+
|
|
3287
|
+
/** One task in a list: title and stage, then bot, who asked, where from and when, then the last report. */
|
|
3288
|
+
function TaskRow({ t, row, onOpen = openTicket, showBot = true }) {
|
|
3289
|
+
const at = row.updatedAt ?? row.createdAt;
|
|
3290
|
+
const last = row.lastReport && typeof row.lastReport === 'object' ? row.lastReport : null;
|
|
3291
|
+
// While its conversation runs, the last line says what it does now.
|
|
3292
|
+
const live = row.stage === 'working' ? liveTask(row.id) ?? (row.activity && typeof row.activity === 'object' ? row.activity : null) : null;
|
|
3293
|
+
return h(
|
|
3294
|
+
'button',
|
|
3295
|
+
{ type: 'button', className: 'dshb-row', 'data-dsh-bots-task': row.id, 'data-stage': row.stage, onClick: () => onOpen(row.id), style: { alignItems: 'flex-start', padding: '9px 10px' } },
|
|
3296
|
+
showBot ? h('span', { style: { paddingTop: 1, display: 'inline-flex' } }, h(BotFace, { id: row.botId, size: 30 })) : null,
|
|
3297
|
+
h(
|
|
3298
|
+
'span',
|
|
3299
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3, flex: 1, minWidth: 0 } },
|
|
3300
|
+
h(
|
|
3301
|
+
'span',
|
|
3302
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 } },
|
|
3303
|
+
h('span', { style: { fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0, flex: 1 } }, taskTitle(t, row)),
|
|
3304
|
+
h(TaskChip, { t, row }),
|
|
3305
|
+
),
|
|
3306
|
+
h(
|
|
3307
|
+
'span',
|
|
3308
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.muted, minWidth: 0, flexWrap: 'wrap' } },
|
|
3309
|
+
showBot ? h('span', { style: { fontWeight: 600, color: C.primary } }, botName(t, row.botId)) : null,
|
|
3310
|
+
showBot ? dotSep() : null,
|
|
3311
|
+
h('span', null, requesterText(t, row)),
|
|
3312
|
+
viaBadge(t, row.via),
|
|
3313
|
+
h('span', { style: { color: C.faint }, title: fmtDate(toMs(at)) }, fmtAgo(t, at)),
|
|
3314
|
+
),
|
|
3315
|
+
live
|
|
3316
|
+
? h(
|
|
3317
|
+
'span',
|
|
3318
|
+
{ 'data-dsh-bots-task-live': row.id, style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.muted, minWidth: 0 } },
|
|
3319
|
+
h(StatusDot, { status: 'running', size: 6 }),
|
|
3320
|
+
h(LiveLine, { t, a: live, attr: row.id, style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }),
|
|
3321
|
+
)
|
|
3322
|
+
: last && str(last.preview).trim()
|
|
3323
|
+
? h(
|
|
3324
|
+
'span',
|
|
3325
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.muted, minWidth: 0 } },
|
|
3326
|
+
h(ReportChip, { t, status: last.status }),
|
|
3327
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 } }, str(last.preview)),
|
|
3328
|
+
)
|
|
3329
|
+
: null,
|
|
3330
|
+
),
|
|
3331
|
+
);
|
|
3332
|
+
}
|
|
3333
|
+
const TaskList = ({ rows, children, attr }) =>
|
|
3334
|
+
h('div', { [attr ?? 'data-dsh-bots-task-list']: true, className: 'dshb-card', style: { padding: 4, display: 'flex', flexDirection: 'column', gap: 2 } }, rows, children ?? null);
|
|
3335
|
+
|
|
3336
|
+
/** A task in a timeline or a tool card: title, the bot doing it and its stage; it opens the detail. */
|
|
3337
|
+
// Its seat (the panel, or a tool view) is subscribed to the store and re-renders it when the task loads.
|
|
3338
|
+
function TaskCard({ t, id, botId, title, stage, face, onOpen = openTicket }) {
|
|
3339
|
+
usePoll(() => loadTicket(id), 10_000, [id]);
|
|
3340
|
+
const v = store.tickets.get(id)?.view ?? null;
|
|
3341
|
+
const bot = botById(v?.botId ?? botId) ?? (face && typeof face === 'object' && (face.name || face.handle) ? face : null);
|
|
3342
|
+
return h(
|
|
3343
|
+
'button',
|
|
3344
|
+
{
|
|
3345
|
+
type: 'button',
|
|
3346
|
+
className: 'dshb-row',
|
|
3347
|
+
'data-dsh-bots-task-card': id,
|
|
3348
|
+
title: t('openTask'),
|
|
3349
|
+
onClick: (e) => {
|
|
3350
|
+
e?.stopPropagation?.();
|
|
3351
|
+
onOpen(id);
|
|
3352
|
+
},
|
|
3353
|
+
style: { border: `1px solid ${C.border1}`, background: C.layer1, padding: '7px 10px', gap: 9, maxWidth: 560 },
|
|
3354
|
+
},
|
|
3355
|
+
h('span', { style: { width: 26, height: 26, borderRadius: 8, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: tint(C.label, 14), color: C.label, flex: 'none' } }, Icon.tasks(14)),
|
|
3356
|
+
h(
|
|
3357
|
+
'span',
|
|
3358
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0, flex: 1 } },
|
|
3359
|
+
h('span', { style: { fontWeight: 600, fontSize: SMALL, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, str(v?.title).trim() || str(title).trim() || t('untitledTask')),
|
|
3360
|
+
h(
|
|
3361
|
+
'span',
|
|
3362
|
+
{ style: { display: 'inline-flex', alignItems: 'center', gap: 5, fontSize: TINY, color: C.muted, minWidth: 0 } },
|
|
3363
|
+
bot ? h(Avatar, { avatar: bot.avatar, name: bot.name || bot.handle, size: 14 }) : null,
|
|
3364
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, t('taskOf', { name: bot ? bot.name || `@${bot.handle}` : t('removedBot') })),
|
|
3365
|
+
),
|
|
3366
|
+
),
|
|
3367
|
+
h(StageChip, { t, stage: v?.stage ?? stage }),
|
|
3368
|
+
h('span', { style: { color: C.faint, display: 'inline-flex' } }, Icon.arrow(11)),
|
|
3369
|
+
);
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
/** Every task: what needs you, what is moving, what finished lately. */
|
|
3373
|
+
function TasksView({ t, bots, focusBot = '', onOpen = openTicket }) {
|
|
3374
|
+
const [bot, setBot] = useState(focusBot);
|
|
3375
|
+
const [doneShown, setDoneShown] = useState(DONE_PAGE);
|
|
3376
|
+
useEffect(() => {
|
|
3377
|
+
setBot(focusBot);
|
|
3378
|
+
}, [focusBot]);
|
|
3379
|
+
// The newest 200 (the Host's page limit): open tasks are touched often, so they are near the top.
|
|
3380
|
+
const { data, failed } = useJson(`tickets?limit=200${bot ? `&bot=${encodeURIComponent(bot)}` : ''}`, STATE_POLL_MS);
|
|
3381
|
+
const items = (Array.isArray(data?.items) ? data.items : []).filter((r) => r && typeof r.id === 'string' && (!bot || r.botId === bot));
|
|
3382
|
+
// The polled list of what needs you fills in when the page is not loaded yet, or is longer than a page.
|
|
3383
|
+
const attention = (Array.isArray(store.state?.attention) ? store.state.attention : []).filter((r) => r && typeof r.id === 'string' && (!bot || r.botId === bot) && !items.some((x) => x.id === r.id));
|
|
3384
|
+
const all = [...items, ...attention];
|
|
3385
|
+
const groups = [
|
|
3386
|
+
{ id: 'needs', title: t('tasksNeeds'), empty: t('tasksNeedsEmpty') },
|
|
3387
|
+
{ id: 'progress', title: t('tasksProgress'), empty: t('tasksProgressEmpty') },
|
|
3388
|
+
{ id: 'done', title: t('tasksDone'), empty: t('tasksDoneEmpty') },
|
|
3389
|
+
].map((g) => ({ ...g, rows: all.filter((r) => groupOf(r) === g.id).sort(newestFirst) }));
|
|
3390
|
+
const doneCount = groups[2].rows.length;
|
|
3391
|
+
groups[2].rows = groups[2].rows.slice(0, doneShown);
|
|
3392
|
+
let body;
|
|
3393
|
+
if (!data && all.length === 0) body = h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('tasksUnavailable') : t('loading'));
|
|
3394
|
+
else if (all.length === 0) body = h(Empty, { icon: Icon.tasks(28), title: bot ? t('tasksEmptyBotTitle', { name: botName(t, bot) }) : t('tasksEmptyTitle'), body: t('tasksEmptyBody') });
|
|
3395
|
+
else {
|
|
3396
|
+
body = h(
|
|
3397
|
+
'div',
|
|
3398
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 24 } },
|
|
3399
|
+
groups.map((g) =>
|
|
3400
|
+
h(
|
|
3401
|
+
'div',
|
|
3402
|
+
{ key: g.id, 'data-dsh-bots-task-group': g.id, 'data-count': g.rows.length },
|
|
3403
|
+
h(
|
|
3404
|
+
Section,
|
|
3405
|
+
{ title: [g.title, h('span', { key: 'n', style: { marginLeft: 6, fontWeight: 500, color: C.faint } }, g.id === 'done' ? doneCount : g.rows.length)] },
|
|
3406
|
+
g.rows.length === 0 ? h('div', { style: { fontSize: SMALL, color: C.faint, padding: '2px 2px 4px' } }, g.empty) : h(TaskList, { rows: g.rows.map((r) => h(TaskRow, { key: r.id, t, row: r, onOpen })) }),
|
|
3407
|
+
g.id === 'done' && doneCount > doneShown ? h('div', null, h(Btn, { size: 'sm', kind: 'ghost', onClick: () => setDoneShown((n) => n + DONE_PAGE), 'data-dsh-bots-tasks-more': true }, t('showMore'))) : null,
|
|
3408
|
+
),
|
|
3409
|
+
),
|
|
3410
|
+
),
|
|
3411
|
+
);
|
|
3412
|
+
}
|
|
3413
|
+
return h(
|
|
3414
|
+
'div',
|
|
3415
|
+
{ 'data-dsh-bots-tasks': true, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
3416
|
+
h(
|
|
3417
|
+
'div',
|
|
3418
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 12, padding: '18px 24px 12px', borderBottom: `1px solid ${C.border1}` } },
|
|
3419
|
+
h('span', { style: { width: 44, height: 44, borderRadius: '50%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.layer2, color: C.label } }, Icon.tasks(20)),
|
|
3420
|
+
h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { style: { fontWeight: 700, fontSize: 17 } }, t('tasks')), h('div', { style: { fontSize: SMALL, color: C.muted } }, t('tasksSub'))),
|
|
3421
|
+
h(
|
|
3422
|
+
'select',
|
|
3423
|
+
{ className: 'dshb-input', value: bot, onChange: (e) => setBot(e.target.value), style: { width: 200, height: 30, fontSize: SMALL }, 'aria-label': t('filterBot'), 'data-dsh-bots-tasks-bot': true },
|
|
3424
|
+
h('option', { value: '' }, t('allBots')),
|
|
3425
|
+
bots.map((b) => h('option', { key: b.id, value: b.id }, `${b.name} (@${b.handle})`)),
|
|
3426
|
+
),
|
|
3427
|
+
),
|
|
3428
|
+
h('div', { className: 'dshb-scroll', style: { flex: 1, padding: '18px 24px 28px' } }, h('div', { style: { maxWidth: 900, margin: '0 auto' } }, body)),
|
|
3429
|
+
);
|
|
3430
|
+
}
|
|
3431
|
+
|
|
3432
|
+
/** One task: who does it and for whom, where it came from, the reports, its usage, and what you can do with it. */
|
|
3433
|
+
function TicketDetail({ t, id, env, toast, onBack }) {
|
|
3434
|
+
const { data, failed, reload } = useJson(`tickets/${encodeURIComponent(id)}`, STATE_POLL_MS);
|
|
3435
|
+
const [confirm, setConfirm] = useState(null);
|
|
3436
|
+
const [busy, setBusy] = useState('');
|
|
1814
3437
|
const [text, setText] = useState('');
|
|
1815
3438
|
const [sending, setSending] = useState(false);
|
|
1816
|
-
const
|
|
1817
|
-
const
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
3439
|
+
const v = ticketViewOf(data);
|
|
3440
|
+
const back = h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-tasks-back': true, onClick: onBack, style: { display: 'inline-flex', alignItems: 'center', gap: 5, fontSize: SMALL } }, Icon.back(12), t('allTasks'));
|
|
3441
|
+
if (!v) {
|
|
3442
|
+
return h(
|
|
3443
|
+
'div',
|
|
3444
|
+
{ 'data-dsh-bots-ticket': id, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0, padding: '18px 24px' } },
|
|
3445
|
+
back,
|
|
3446
|
+
h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('taskMissing') : t('loading')),
|
|
3447
|
+
);
|
|
3448
|
+
}
|
|
3449
|
+
const name = botName(t, v.botId);
|
|
3450
|
+
const stage = v.stage;
|
|
3451
|
+
const open = !FINISHED.includes(stage) && !v.ended;
|
|
3452
|
+
// What its conversation does right now (the quick poll, else the view's).
|
|
3453
|
+
const live = open ? liveTask(id) ?? (v.activity && typeof v.activity === 'object' ? v.activity : null) : null;
|
|
3454
|
+
const archived = Boolean(v.archivedAt || v.archived);
|
|
3455
|
+
const after = (r, okText) => {
|
|
3456
|
+
if (r && r.ok !== false) {
|
|
3457
|
+
const next = ticketViewOf(r);
|
|
3458
|
+
if (next) store.tickets.set(id, { view: next, at: Date.now() });
|
|
3459
|
+
if (okText) toast(okText);
|
|
3460
|
+
void reload();
|
|
3461
|
+
void refreshState();
|
|
3462
|
+
return true;
|
|
3463
|
+
}
|
|
3464
|
+
toast(r?.reason || t('actionFailed'), 'error');
|
|
3465
|
+
return false;
|
|
3466
|
+
};
|
|
3467
|
+
const act = (action) => {
|
|
3468
|
+
setBusy(action);
|
|
3469
|
+
return postJson(`tickets/${encodeURIComponent(id)}/${action}`, {})
|
|
3470
|
+
.then((r) => void after(r, t(`taskDid_${action}`)))
|
|
3471
|
+
.finally(() => setBusy(''));
|
|
1830
3472
|
};
|
|
1831
3473
|
const send = () => {
|
|
1832
3474
|
const body = text.trim();
|
|
1833
3475
|
if (!body || sending) return;
|
|
1834
3476
|
setSending(true);
|
|
1835
|
-
|
|
1836
|
-
postJson('send', { to: bot.id, text: body })
|
|
3477
|
+
postJson(`tickets/${encodeURIComponent(id)}/message`, { text: body })
|
|
1837
3478
|
.then((r) => {
|
|
1838
|
-
if (r
|
|
1839
|
-
setText('');
|
|
1840
|
-
thread.stick();
|
|
1841
|
-
void reload();
|
|
1842
|
-
void refreshState();
|
|
1843
|
-
} else toast(r?.reason || t('sendFailed'), 'error');
|
|
3479
|
+
if (after(r, t('taskMessageSent', { name }))) setText('');
|
|
1844
3480
|
})
|
|
1845
3481
|
.finally(() => setSending(false));
|
|
1846
3482
|
};
|
|
1847
|
-
|
|
1848
|
-
|
|
3483
|
+
const openConversation = () => {
|
|
3484
|
+
const ok = Boolean(v.sessionId) && env?.openSession?.(v.sessionId) === true;
|
|
3485
|
+
if (!ok) toast(t('openFailed'), 'error');
|
|
3486
|
+
};
|
|
3487
|
+
const origin = v.origin && typeof v.origin === 'object' ? v.origin : {};
|
|
3488
|
+
const threads = Array.isArray(v.threads) ? v.threads : [];
|
|
3489
|
+
const originThread = threads.find((x) => (x?.key ?? x) === origin.threadKey) ?? threads[0];
|
|
3490
|
+
const originKind = str(originThread?.kind) || str(origin.threadKey).split(':')[0];
|
|
3491
|
+
const fromPanelThread = originKind === 'panel';
|
|
3492
|
+
const where = fromPanelThread ? '' : str(origin.label) || str(originThread?.label);
|
|
3493
|
+
const via = v.via ?? origin.via ?? (fromPanelThread ? '' : originThread?.kind);
|
|
3494
|
+
const parentId = typeof v.parentId === 'string' ? v.parentId : typeof v.parent === 'string' ? v.parent : v.parent?.id;
|
|
3495
|
+
const children = (Array.isArray(v.children) ? v.children : []).map((c) => (typeof c === 'string' ? c : c?.id)).filter((c) => typeof c === 'string');
|
|
3496
|
+
const reports = (Array.isArray(v.reports) ? v.reports : []).filter((r) => r && typeof r === 'object').slice().sort((a, b) => (toMs(a.at) || 0) - (toMs(b.at) || 0));
|
|
3497
|
+
const runs = (Array.isArray(v.runs) ? v.runs : []).filter((r) => r && typeof r === 'object');
|
|
3498
|
+
// The Host's totals also count calls outside a run (the task's memory summary); else the runs' sum.
|
|
3499
|
+
const total = v.usage && typeof v.usage === 'object' ? v.usage : null;
|
|
3500
|
+
const tokens = total ? Number(total.tokens) || 0 : runs.reduce((n, r) => n + (Number(r.tokens) || 0), 0);
|
|
3501
|
+
const cost = {};
|
|
3502
|
+
if (total) Object.assign(cost, total.cost ?? {});
|
|
3503
|
+
else for (const r of runs) for (const [c, x] of Object.entries(r.cost ?? {})) cost[c] = (cost[c] ?? 0) + (Number(x) || 0);
|
|
3504
|
+
const fact = (label, value, attr) => (value ? h('div', { key: label, 'data-dsh-bots-ticket-fact': attr, style: { display: 'flex', gap: 12, alignItems: 'baseline', minWidth: 0 } }, h('span', { style: { width: 96, flex: 'none', fontSize: TINY, color: C.muted } }, label), h('span', { style: { flex: 1, minWidth: 0, fontSize: SMALL } }, value)) : null);
|
|
3505
|
+
// The Host writes "the user" for you; the page says it in your language or not at all.
|
|
3506
|
+
const who = /^the user$/i.test(str(origin.who).trim()) ? '' : str(origin.who).trim();
|
|
3507
|
+
const fromValue = where
|
|
3508
|
+
? h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } }, h('span', null, where), who && !where.includes(who) ? dotSep() : null, who && !where.includes(who) ? h('span', { style: { color: C.muted } }, who) : null)
|
|
3509
|
+
: via && via !== 'panel'
|
|
3510
|
+
? viaBadge(t, via, via === 'schedule' ? '' : who)
|
|
3511
|
+
: t('fromPanel');
|
|
1849
3512
|
return h(
|
|
1850
3513
|
'div',
|
|
1851
|
-
{ style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
3514
|
+
{ 'data-dsh-bots-ticket': id, 'data-stage': stage, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
1852
3515
|
h(
|
|
1853
|
-
'
|
|
1854
|
-
{
|
|
3516
|
+
'header',
|
|
3517
|
+
{ style: { padding: '14px 24px 14px', borderBottom: `1px solid ${C.border1}`, display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
3518
|
+
h('div', null, back),
|
|
1855
3519
|
h(
|
|
1856
3520
|
'div',
|
|
1857
|
-
{
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
botId: bot.id,
|
|
1864
|
-
empty: h(ChatEmpty, { t, bot, onPick: setText }),
|
|
1865
|
-
}),
|
|
1866
|
-
running
|
|
1867
|
-
? h(
|
|
3521
|
+
{ style: { display: 'flex', alignItems: 'flex-start', gap: 12, flexWrap: 'wrap' } },
|
|
3522
|
+
h(
|
|
3523
|
+
'div',
|
|
3524
|
+
{ style: { flex: 1, minWidth: 240, display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
3525
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 } }, h('span', { style: { fontWeight: 700, fontSize: 19, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: taskTitle(t, v) }, taskTitle(t, v)), h(TaskChip, { t, row: v })),
|
|
3526
|
+
h(
|
|
1868
3527
|
'div',
|
|
1869
|
-
{ style: { display: 'flex', alignItems: 'center', gap:
|
|
1870
|
-
h(
|
|
1871
|
-
h('span',
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
3528
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: SMALL, color: C.muted, flexWrap: 'wrap' } },
|
|
3529
|
+
h(BotFace, { id: v.botId, size: 18 }),
|
|
3530
|
+
h('span', { style: { color: C.primary, fontWeight: 600 } }, name),
|
|
3531
|
+
dotSep(),
|
|
3532
|
+
h('span', null, requesterText(t, v)),
|
|
3533
|
+
dotSep(),
|
|
3534
|
+
h('span', { title: fmtDate(toMs(v.createdAt)) }, t('taskStarted', { when: fmtAgo(t, v.createdAt) })),
|
|
3535
|
+
),
|
|
3536
|
+
),
|
|
3537
|
+
h(
|
|
3538
|
+
'div',
|
|
3539
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } },
|
|
3540
|
+
env?.canOpen?.() ? h(Btn, { icon: Icon.chat(14), disabled: !v.sessionId, title: v.sessionId ? undefined : t('taskNoConversation'), onClick: openConversation, 'data-dsh-bots-ticket-open': id }, t('openConversation')) : null,
|
|
3541
|
+
['failed', 'stalled', 'stopped'].includes(stage) ? h(Btn, { icon: Icon.refresh(13), disabled: Boolean(busy), onClick: () => void act('retry'), 'data-dsh-bots-ticket-retry': id }, t('taskRetry')) : null,
|
|
3542
|
+
open ? h(Btn, { icon: Icon.check(13), disabled: Boolean(busy), onClick: () => setConfirm('close'), 'data-dsh-bots-ticket-close': id }, t('taskClose')) : null,
|
|
3543
|
+
open ? h(Btn, { kind: 'danger', icon: Icon.stop(12), disabled: Boolean(busy), onClick: () => setConfirm('stop'), 'data-dsh-bots-ticket-stop': id }, t('taskStop')) : null,
|
|
3544
|
+
),
|
|
1875
3545
|
),
|
|
1876
3546
|
),
|
|
1877
3547
|
h(
|
|
1878
3548
|
'div',
|
|
1879
|
-
{ style: { padding: '
|
|
1880
|
-
h(
|
|
1881
|
-
'div',
|
|
1882
|
-
{ style: { maxWidth: 880, margin: '0 auto' } },
|
|
1883
|
-
previewUrl ? h('div', { 'data-dsh-bots-composer-preview': previewUrl, style: { marginBottom: 8, maxHeight: 260, overflow: 'auto' } }, h(LinkCard, { t, url: previewUrl })) : null,
|
|
1884
|
-
h(
|
|
1885
|
-
'div',
|
|
1886
|
-
{ style: { display: 'flex', alignItems: 'flex-end', gap: 8, padding: 6, borderRadius: 14, border: `1px solid ${C.border}`, background: C.layer1 } },
|
|
1887
|
-
h('textarea', {
|
|
1888
|
-
'data-dsh-bots-composer': true,
|
|
1889
|
-
value: text,
|
|
1890
|
-
rows: Math.min(8, Math.max(1, text.split('\n').length)),
|
|
1891
|
-
placeholder: t('composer', { handle: bot.handle }),
|
|
1892
|
-
onChange: (e) => setText(e.target.value),
|
|
1893
|
-
onKeyDown: (e) => {
|
|
1894
|
-
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !e.nativeEvent?.isComposing) {
|
|
1895
|
-
e.preventDefault();
|
|
1896
|
-
send();
|
|
1897
|
-
}
|
|
1898
|
-
},
|
|
1899
|
-
style: { flex: 1, minHeight: 32, maxHeight: 200, resize: 'none', border: 'none', outline: 'none', background: 'transparent', color: C.primary, font: 'inherit', fontSize: FONT, lineHeight: 1.5, padding: '6px 8px' },
|
|
1900
|
-
}),
|
|
1901
|
-
h(Btn, { kind: 'primary', icon: Icon.send(15), title: t('send'), disabled: !text.trim() || sending, onClick: send, style: { borderRadius: 10, width: 34, height: 34 } }),
|
|
1902
|
-
),
|
|
3549
|
+
{ className: 'dshb-scroll', style: { flex: 1, padding: '18px 24px 24px' } },
|
|
1903
3550
|
h(
|
|
1904
3551
|
'div',
|
|
1905
|
-
{ style: { display: 'flex',
|
|
1906
|
-
h('
|
|
1907
|
-
h('span', { style: { flex:
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
3552
|
+
{ style: { maxWidth: 820, display: 'flex', flexDirection: 'column', gap: 22 } },
|
|
3553
|
+
live ? h('div', { className: 'dshb-card', 'data-dsh-bots-ticket-live': id, style: { padding: '4px 12px 8px', borderColor: tint(C.ok, 35) } }, h(WorkingRow, { t, bot: botById(v.botId), a: live, attr: id })) : null,
|
|
3554
|
+
stage === 'failed' && v.error ? h('div', { 'data-dsh-bots-ticket-error': true, style: { display: 'flex', gap: 8, padding: '10px 12px', borderRadius: 10, border: `1px solid ${tint(C.error, 40)}`, background: tint(C.error, 8), fontSize: SMALL, color: C.primary } }, h('span', { style: { color: C.error, display: 'inline-flex', paddingTop: 2 } }, Icon.alert(14)), h('span', { style: { minWidth: 0, wordBreak: 'break-word' } }, str(v.error))) : null,
|
|
3555
|
+
h(
|
|
3556
|
+
'div',
|
|
3557
|
+
{ className: 'dshb-card', style: { display: 'flex', flexDirection: 'column', gap: 7 } },
|
|
3558
|
+
fact(t('taskFactBot'), h('button', { type: 'button', className: 'dshb-link', onClick: () => navigate(v.botId), style: { display: 'inline-flex', alignItems: 'center', gap: 6 } }, h(BotFace, { id: v.botId, size: 16 }), name), 'bot'),
|
|
3559
|
+
fact(t('taskFactAsked'), requesterBot(v) ? h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 6 } }, h(BotFace, { id: requesterBot(v), size: 16 }), requesterName(t, v)) : requesterName(t, v), 'requester'),
|
|
3560
|
+
fact(t('taskFactFrom'), fromValue, 'from'),
|
|
3561
|
+
fact(t('taskFactUpdated'), h('span', { title: fmtDate(toMs(v.updatedAt)) }, fmtAgo(t, v.updatedAt)), 'updated'),
|
|
3562
|
+
),
|
|
3563
|
+
str(v.text).trim() ? h(Section, { title: t('taskAsked') }, h('div', { className: 'dshb-card', 'data-dsh-bots-ticket-text': true }, h(Clamp, { t, text: v.text, lines: 8, style: { fontSize: SMALL } }))) : null,
|
|
3564
|
+
h(
|
|
3565
|
+
Section,
|
|
3566
|
+
{ title: t('taskReports') },
|
|
3567
|
+
reports.length === 0
|
|
3568
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('taskNoReports', { name }))
|
|
3569
|
+
: h(
|
|
3570
|
+
'div',
|
|
3571
|
+
{ 'data-dsh-bots-reports': reports.length, style: { display: 'flex', flexDirection: 'column' } },
|
|
3572
|
+
reports.map((r, i) =>
|
|
3573
|
+
h(
|
|
3574
|
+
'div',
|
|
3575
|
+
{ key: `${r.at}-${i}`, 'data-dsh-bots-report-item': r.status, style: { display: 'flex', gap: 10 } },
|
|
3576
|
+
h(
|
|
3577
|
+
'div',
|
|
3578
|
+
{ style: { display: 'flex', flexDirection: 'column', alignItems: 'center', width: 12, flex: 'none', paddingTop: 6 } },
|
|
3579
|
+
h('span', { style: { width: 9, height: 9, borderRadius: '50%', background: REPORT_COLOR[r.status] ?? C.faint, flex: 'none' } }),
|
|
3580
|
+
i < reports.length - 1 ? h('span', { style: { flex: 1, width: 2, marginTop: 3, background: C.border1 } }) : null,
|
|
3581
|
+
),
|
|
3582
|
+
h(
|
|
3583
|
+
'div',
|
|
3584
|
+
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 5, paddingBottom: i < reports.length - 1 ? 14 : 0 } },
|
|
3585
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.faint } }, h(ReportChip, { t, status: r.status }), h('span', { title: fmtDate(toMs(r.at)) }, fmtClock(toMs(r.at)))),
|
|
3586
|
+
h('div', { style: { padding: '8px 12px', borderRadius: '4px 14px 14px 14px', background: C.layer2, border: `1px solid ${C.border1}`, fontSize: FONT, minWidth: 0 } }, h(Clamp, { t, text: r.text, lines: 14 })),
|
|
3587
|
+
),
|
|
3588
|
+
),
|
|
3589
|
+
),
|
|
3590
|
+
),
|
|
3591
|
+
),
|
|
3592
|
+
parentId || children.length
|
|
3593
|
+
? h(
|
|
3594
|
+
Section,
|
|
3595
|
+
{ title: t('taskRelated') },
|
|
3596
|
+
parentId ? h('div', { 'data-dsh-bots-ticket-parent': parentId, style: { display: 'flex', flexDirection: 'column', gap: 6 } }, h('span', { style: { fontSize: TINY, color: C.muted } }, t('taskParent')), h(TaskCard, { t, id: parentId })) : null,
|
|
3597
|
+
children.length ? h('div', { 'data-dsh-bots-ticket-children': children.length, style: { display: 'flex', flexDirection: 'column', gap: 6 } }, h('span', { style: { fontSize: TINY, color: C.muted } }, t('taskChildren', { n: children.length })), children.map((c) => h(TaskCard, { key: c, t, id: c }))) : null,
|
|
3598
|
+
)
|
|
3599
|
+
: null,
|
|
3600
|
+
h(
|
|
3601
|
+
Section,
|
|
3602
|
+
{ title: t('taskUsage') },
|
|
3603
|
+
runs.length === 0 && tokens === 0
|
|
3604
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('taskNoUsage'))
|
|
3605
|
+
: h(
|
|
3606
|
+
'div',
|
|
3607
|
+
{ 'data-dsh-bots-ticket-usage': true, style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: 12 } },
|
|
3608
|
+
h(Tile, { attr: 'ticket-tokens', label: t('tileTokens'), value: fmtNum(tokens) }),
|
|
3609
|
+
h(Tile, { attr: 'ticket-cost', label: t('tileCost'), value: fmtCost(cost) }),
|
|
3610
|
+
h(Tile, { attr: 'ticket-runs', label: t('tileRuns'), value: String(runs.length) }),
|
|
3611
|
+
),
|
|
3612
|
+
),
|
|
1913
3613
|
),
|
|
1914
3614
|
),
|
|
3615
|
+
archived
|
|
3616
|
+
? h('div', { style: { padding: '10px 24px 14px', borderTop: `1px solid ${C.border1}`, background: C.base, fontSize: SMALL, color: C.faint } }, t('taskArchived'))
|
|
3617
|
+
: h(
|
|
3618
|
+
'div',
|
|
3619
|
+
{ style: { padding: '10px 24px 16px', borderTop: `1px solid ${C.border1}`, background: C.base } },
|
|
3620
|
+
h(
|
|
3621
|
+
'div',
|
|
3622
|
+
{ style: { maxWidth: 820 } },
|
|
3623
|
+
h(AskCards, { t, sessionId: v.sessionId, env, onAnswered: () => void reload() }),
|
|
3624
|
+
h(
|
|
3625
|
+
'div',
|
|
3626
|
+
{ style: { display: 'flex', alignItems: 'flex-end', gap: 8, padding: 6, borderRadius: 14, border: `1px solid ${C.border}`, background: C.layer1 } },
|
|
3627
|
+
h('textarea', {
|
|
3628
|
+
'data-dsh-bots-ticket-composer': id,
|
|
3629
|
+
value: text,
|
|
3630
|
+
rows: Math.min(6, Math.max(1, text.split('\n').length)),
|
|
3631
|
+
'aria-label': t('taskMessageLabel'),
|
|
3632
|
+
placeholder: stage === 'question' ? t('taskAnswerPlaceholder', { name }) : t('taskMessagePlaceholder'),
|
|
3633
|
+
onChange: (e) => setText(e.target.value),
|
|
3634
|
+
onKeyDown: (e) => {
|
|
3635
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !e.nativeEvent?.isComposing) {
|
|
3636
|
+
e.preventDefault();
|
|
3637
|
+
send();
|
|
3638
|
+
}
|
|
3639
|
+
},
|
|
3640
|
+
style: { flex: 1, minHeight: 32, maxHeight: 160, resize: 'none', border: 'none', outline: 'none', background: 'transparent', color: C.primary, font: 'inherit', fontSize: FONT, lineHeight: 1.5, padding: '6px 8px' },
|
|
3641
|
+
}),
|
|
3642
|
+
h(Btn, { kind: 'primary', icon: Icon.send(15), title: t('send'), disabled: !text.trim() || sending, onClick: send, 'data-dsh-bots-ticket-send': id, style: { borderRadius: 10, width: 34, height: 34 } }),
|
|
3643
|
+
),
|
|
3644
|
+
h('div', { style: { marginTop: 7, fontSize: TINY, color: C.faint } }, t('taskMessageHint', { name })),
|
|
3645
|
+
),
|
|
3646
|
+
),
|
|
3647
|
+
confirm
|
|
3648
|
+
? h(Confirm, {
|
|
3649
|
+
t,
|
|
3650
|
+
title: t(confirm === 'stop' ? 'taskStopTitle' : 'taskCloseTitle', { title: taskTitle(t, v) }),
|
|
3651
|
+
body: t(confirm === 'stop' ? 'taskStopBody' : 'taskCloseBody', { name }),
|
|
3652
|
+
confirmLabel: t(confirm === 'stop' ? 'taskStop' : 'taskClose'),
|
|
3653
|
+
onClose: () => setConfirm(null),
|
|
3654
|
+
onConfirm: () => act(confirm),
|
|
3655
|
+
})
|
|
3656
|
+
: null,
|
|
1915
3657
|
);
|
|
1916
3658
|
}
|
|
1917
3659
|
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
const
|
|
1921
|
-
const
|
|
3660
|
+
/** A bot's open tasks (and the last few it finished), on its page. */
|
|
3661
|
+
function BotTasksTab({ t, bot, onOpen = openTicket }) {
|
|
3662
|
+
const { data, failed } = useJson(`tickets?bot=${encodeURIComponent(bot.id)}&limit=50`, STATE_POLL_MS);
|
|
3663
|
+
const name = bot.name || `@${bot.handle}`;
|
|
3664
|
+
const items = (Array.isArray(data?.items) ? data.items : []).filter((r) => r && typeof r.id === 'string' && r.botId === bot.id);
|
|
3665
|
+
const open = items.filter((r) => groupOf(r) !== 'done').sort(newestFirst);
|
|
3666
|
+
const done = items.filter((r) => groupOf(r) === 'done').sort(newestFirst).slice(0, 5);
|
|
1922
3667
|
return h(
|
|
1923
3668
|
'div',
|
|
1924
|
-
{
|
|
3669
|
+
{ className: 'dshb-scroll', 'data-dsh-bots-bot-tasks': bot.id, style: { flex: 1, padding: '20px 24px 28px' } },
|
|
1925
3670
|
h(
|
|
1926
3671
|
'div',
|
|
1927
|
-
{ style: {
|
|
1928
|
-
h('span', { style: { width: 44, height: 44, borderRadius: '50%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: C.layer2, color: C.label } }, Icon.activity(20)),
|
|
1929
|
-
h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { style: { fontWeight: 700, fontSize: 17 } }, t('activity')), h('div', { style: { fontSize: SMALL, color: C.muted } }, t('activitySub'))),
|
|
3672
|
+
{ style: { maxWidth: 820, display: 'flex', flexDirection: 'column', gap: 26 } },
|
|
1930
3673
|
h(
|
|
1931
|
-
|
|
1932
|
-
{ className: 'dshb-
|
|
1933
|
-
|
|
1934
|
-
|
|
3674
|
+
Section,
|
|
3675
|
+
{ title: t('botOpenTasks'), hint: t('botOpenTasksHint', { name }), right: h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-bot-tasks-all': bot.id, onClick: () => navigate(bot.id, 'tasks'), style: { fontSize: TINY, whiteSpace: 'nowrap' } }, t('allTasksOf', { name })) },
|
|
3676
|
+
!data
|
|
3677
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, failed ? t('tasksUnavailable') : t('loading'))
|
|
3678
|
+
: open.length === 0
|
|
3679
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('botNoOpenTasks', { name }))
|
|
3680
|
+
: h(TaskList, { rows: open.map((r) => h(TaskRow, { key: r.id, t, row: r, onOpen, showBot: false })) }),
|
|
1935
3681
|
),
|
|
3682
|
+
done.length ? h(Section, { title: t('tasksDone') }, h(TaskList, { rows: done.map((r) => h(TaskRow, { key: r.id, t, row: r, onOpen, showBot: false })) })) : null,
|
|
1936
3683
|
),
|
|
3684
|
+
);
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3687
|
+
/** Once, after an upgrade moved an existing team to router mode: what changed and where to switch back. */
|
|
3688
|
+
function RouterNoticeBanner({ t, onOpenDispatcher, onDismiss }) {
|
|
3689
|
+
return h(
|
|
3690
|
+
'div',
|
|
3691
|
+
{ role: 'region', 'aria-label': t('routerNoticeTitle'), 'data-dsh-bots-router-notice': true, className: 'dshb-fade', style: { display: 'flex', alignItems: 'flex-start', gap: 12, margin: '12px 24px 0', padding: '12px 14px', borderRadius: 12, border: `1px solid ${tint(C.label, 35)}`, background: tint(C.label, 8) } },
|
|
3692
|
+
h('span', { style: { color: C.label, display: 'inline-flex', paddingTop: 2 } }, Icon.sparkle(16)),
|
|
1937
3693
|
h(
|
|
1938
3694
|
'div',
|
|
1939
|
-
{
|
|
3695
|
+
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
3696
|
+
h('div', { style: { fontWeight: 700, fontSize: SMALL } }, t('routerNoticeTitle')),
|
|
3697
|
+
h('div', { style: { fontSize: SMALL, color: C.muted, lineHeight: 1.6 } }, t('routerNoticeBody')),
|
|
1940
3698
|
h(
|
|
1941
3699
|
'div',
|
|
1942
|
-
{ style: {
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
: shown.length === 0
|
|
1946
|
-
? h(Empty, { icon: Icon.activity(28), title: t('activityEmptyTitle'), body: t('activityEmptyBody') })
|
|
1947
|
-
: shown.map((m, i) => {
|
|
1948
|
-
const from = party(t, m.from);
|
|
1949
|
-
const to = party(t, m.to);
|
|
1950
|
-
return h(
|
|
1951
|
-
'div',
|
|
1952
|
-
{ key: m.id ?? i, 'data-dsh-bots-event': m.kind, style: { display: 'flex', gap: 12, padding: '12px 0', borderBottom: `1px solid ${C.border1}` } },
|
|
1953
|
-
h(
|
|
1954
|
-
'div',
|
|
1955
|
-
{ style: { position: 'relative', width: 40, height: 34, flex: 'none' } },
|
|
1956
|
-
h('span', { style: { position: 'absolute', left: 0, top: 0 } }, h(PartyAvatar, { p: from, size: 30 })),
|
|
1957
|
-
h('span', { style: { position: 'absolute', left: 21, top: 19, display: 'inline-flex', borderRadius: '50%', boxShadow: `0 0 0 2px ${C.base}` } }, h(PartyAvatar, { p: to, size: 17 })),
|
|
1958
|
-
),
|
|
1959
|
-
h(
|
|
1960
|
-
'div',
|
|
1961
|
-
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
1962
|
-
h(
|
|
1963
|
-
'div',
|
|
1964
|
-
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: SMALL, flexWrap: 'wrap' } },
|
|
1965
|
-
h('span', { style: { fontWeight: 600 } }, from.name),
|
|
1966
|
-
h('span', { style: { color: C.faint, display: 'inline-flex' } }, Icon.arrow(11)),
|
|
1967
|
-
h('span', { style: { fontWeight: 600 } }, to.name),
|
|
1968
|
-
h(Badge, { color: m.kind === 'dm' ? C.label : m.kind === 'system' ? C.warn : C.muted }, t(`kind_${m.kind}`) || m.kind),
|
|
1969
|
-
m.via ? h(Badge, { color: CHANNEL_COLORS[m.via] ?? C.muted, 'data-dsh-bots-via': m.via }, m.from === 'user' && m.who ? `${channelName(m.via, t)} · ${str(m.who)}` : channelName(m.via, t)) : null,
|
|
1970
|
-
h('span', { style: { marginLeft: 'auto', color: C.faint, fontSize: TINY }, title: fmtDate(toMs(m.at)) }, fmtAgo(t, m.at)),
|
|
1971
|
-
),
|
|
1972
|
-
h(Clamp, { t, text: m.kind === 'topic' ? t('topicDivider', { reason: t(`topicReason_${m.text}`) }) : m.text, lines: 3, style: { fontSize: SMALL, color: C.muted } }),
|
|
1973
|
-
),
|
|
1974
|
-
);
|
|
1975
|
-
}),
|
|
3700
|
+
{ style: { display: 'flex', gap: 8, marginTop: 6, flexWrap: 'wrap' } },
|
|
3701
|
+
onOpenDispatcher ? h(Btn, { size: 'sm', onClick: onOpenDispatcher, 'data-dsh-bots-router-notice-open': true }, t('routerNoticeOpen')) : null,
|
|
3702
|
+
h(Btn, { size: 'sm', kind: 'primary', onClick: onDismiss, 'data-dsh-bots-router-notice-dismiss': true }, t('routerNoticeOk')),
|
|
1976
3703
|
),
|
|
1977
3704
|
),
|
|
3705
|
+
h(Btn, { kind: 'ghost', size: 'sm', icon: Icon.close(13), title: t('close'), onClick: onDismiss }),
|
|
1978
3706
|
);
|
|
1979
3707
|
}
|
|
1980
3708
|
|
|
@@ -2131,6 +3859,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2131
3859
|
avatar: avatarOf(bot.avatar),
|
|
2132
3860
|
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,
|
|
2133
3861
|
deny: Array.isArray(bot.tools?.deny) ? bot.tools.deny.slice().sort() : [],
|
|
3862
|
+
routerAllow: Array.isArray(bot.tools?.routerAllow) ? bot.tools.routerAllow.map(String).sort() : [],
|
|
2134
3863
|
});
|
|
2135
3864
|
/** A clean avatar value: an image keeps its url, anything else is initials (emoji rows from v0.1 too). */
|
|
2136
3865
|
function avatarOf(a) {
|
|
@@ -2155,6 +3884,86 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2155
3884
|
if (!on) for (const x of ab.available ?? []) next.add(x);
|
|
2156
3885
|
return [...next].sort();
|
|
2157
3886
|
}
|
|
3887
|
+
/**
|
|
3888
|
+
* Tools a router dispatcher goes without unless allowed back: the Host's list when the catalog has one,
|
|
3889
|
+
* else the rule of lib/prompt.mjs (commands, writing and editing files, sub-agents, images, Office).
|
|
3890
|
+
*/
|
|
3891
|
+
function routerDenyOf(catalog) {
|
|
3892
|
+
if (Array.isArray(catalog?.routerDeny)) return catalog.routerDeny.map(String);
|
|
3893
|
+
const abilities = Array.isArray(catalog?.abilities) ? catalog.abilities : [];
|
|
3894
|
+
const of = (id) => abilities.find((a) => a.id === id)?.tools ?? [];
|
|
3895
|
+
return [...new Set([...of('code'), 'write', 'edit', ...of('delegate'), ...of('images'), ...of('office')])];
|
|
3896
|
+
}
|
|
3897
|
+
const sorted = (set) => [...set].sort();
|
|
3898
|
+
/**
|
|
3899
|
+
* The tool lists after switching one ability of a router dispatcher. An ability made only of tools a
|
|
3900
|
+
* router goes without (commands, sub-agents, images, Office) is switched through `routerAllow`, so it
|
|
3901
|
+
* keeps its own setting for hands-on mode. One with other tools too (files) switches as before and
|
|
3902
|
+
* comes back with the router's default; its writing tools are allowed back on their own.
|
|
3903
|
+
*/
|
|
3904
|
+
function toggleRouterAbility(draft, ab, on, routerDeny) {
|
|
3905
|
+
const gated = (ab.available ?? []).filter((x) => routerDeny.has(x));
|
|
3906
|
+
const whole = gated.length > 0 && gated.length === (ab.available ?? []).length;
|
|
3907
|
+
const allow = new Set(draft.routerAllow);
|
|
3908
|
+
if (on) {
|
|
3909
|
+
if (whole) for (const x of gated) allow.add(x);
|
|
3910
|
+
return { deny: toggleAbility(draft.deny, ab, true), routerAllow: sorted(allow) };
|
|
3911
|
+
}
|
|
3912
|
+
for (const x of [...(ab.tools ?? []), ...gated]) allow.delete(x);
|
|
3913
|
+
return { deny: whole ? draft.deny : toggleAbility(draft.deny, ab, false), routerAllow: sorted(allow) };
|
|
3914
|
+
}
|
|
3915
|
+
/** How the dispatcher works: only hand out (router) or also do small things itself (hands-on). A team setting. */
|
|
3916
|
+
function DispatcherMode({ t, name, toast }) {
|
|
3917
|
+
const mode = dispatcherOf();
|
|
3918
|
+
const [busy, setBusy] = useState(false);
|
|
3919
|
+
const choose = (next) => {
|
|
3920
|
+
if (busy || next === mode) return;
|
|
3921
|
+
setBusy(true);
|
|
3922
|
+
postJson('settings', { patch: { dispatcher: next } })
|
|
3923
|
+
.then((r) => {
|
|
3924
|
+
if (r?.ok) {
|
|
3925
|
+
tookSettings(r.settings && typeof r.settings === 'object' ? r.settings : { ...(store.settings?.settings ?? {}), dispatcher: next });
|
|
3926
|
+
toast(t(next === 'hands-on' ? 'modeSavedHandsOn' : 'modeSavedRouter', { name }));
|
|
3927
|
+
void refreshState();
|
|
3928
|
+
} else toast(r?.reason || t('saveFailed'), 'error');
|
|
3929
|
+
})
|
|
3930
|
+
.finally(() => setBusy(false));
|
|
3931
|
+
};
|
|
3932
|
+
const option = (id, title, body) => {
|
|
3933
|
+
const on = mode === id;
|
|
3934
|
+
return h(
|
|
3935
|
+
'button',
|
|
3936
|
+
{
|
|
3937
|
+
key: id,
|
|
3938
|
+
type: 'button',
|
|
3939
|
+
role: 'radio',
|
|
3940
|
+
'aria-checked': on,
|
|
3941
|
+
className: 'dshb-row',
|
|
3942
|
+
'data-active': on,
|
|
3943
|
+
'data-dsh-bots-dispatcher-mode': id,
|
|
3944
|
+
disabled: busy,
|
|
3945
|
+
onClick: () => choose(id),
|
|
3946
|
+
style: { alignItems: 'flex-start', gap: 10, padding: '10px 12px', border: `1px solid ${on ? C.label : C.border1}`, background: on ? tint(C.label, 8) : C.layer1 },
|
|
3947
|
+
},
|
|
3948
|
+
h('span', { style: { width: 16, height: 16, marginTop: 1, borderRadius: '50%', border: `2px solid ${on ? C.label : C.border}`, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flex: 'none' } }, on ? h('span', { style: { width: 7, height: 7, borderRadius: '50%', background: C.label } }) : null),
|
|
3949
|
+
h('span', { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } }, h('span', { style: { fontWeight: 600 } }, title), h('span', { style: { fontSize: TINY, color: C.muted, lineHeight: 1.5 } }, body)),
|
|
3950
|
+
);
|
|
3951
|
+
};
|
|
3952
|
+
return h(
|
|
3953
|
+
'div',
|
|
3954
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
3955
|
+
h(
|
|
3956
|
+
'div',
|
|
3957
|
+
{ role: 'radiogroup', 'aria-label': t('dispatcherMode'), 'data-dsh-bots-dispatcher-modes': mode, style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 10 } },
|
|
3958
|
+
option('router', t('modeRouter'), t('modeRouterBody')),
|
|
3959
|
+
option('hands-on', t('modeHandsOn'), t('modeHandsOnBody')),
|
|
3960
|
+
),
|
|
3961
|
+
// Router mode asked for, but nobody to hand work to yet.
|
|
3962
|
+
mode === 'router' && !routerActiveOf()
|
|
3963
|
+
? h('div', { 'data-dsh-bots-router-waiting': true, style: { display: 'flex', alignItems: 'flex-start', gap: 6, fontSize: TINY, color: C.muted, lineHeight: 1.5 } }, h('span', { style: { color: C.warn, display: 'inline-flex', paddingTop: 1 } }, Icon.alert(12)), t('routerWaiting', { name }))
|
|
3964
|
+
: null,
|
|
3965
|
+
);
|
|
3966
|
+
}
|
|
2158
3967
|
const ABILITY_ICON = {
|
|
2159
3968
|
web: () => Icon.search(15),
|
|
2160
3969
|
files: () => Icon.edit(15),
|
|
@@ -2168,6 +3977,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2168
3977
|
plugins: () => Icon.puzzle(15),
|
|
2169
3978
|
};
|
|
2170
3979
|
function ProfileTab({ t, bot, toast, catalog }) {
|
|
3980
|
+
// The dispatcher's mode is a team setting; the panel re-renders this tab once it loads.
|
|
3981
|
+
useEffect(() => {
|
|
3982
|
+
void loadOnce('settings', 'settings');
|
|
3983
|
+
}, []);
|
|
2171
3984
|
const [draft, setDraft] = useState(() => profileOf(bot));
|
|
2172
3985
|
const [busy, setBusy] = useState(false);
|
|
2173
3986
|
const [toolQ, setToolQ] = useState('');
|
|
@@ -2187,7 +4000,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2187
4000
|
const save = () => {
|
|
2188
4001
|
if (!valid || busy) return;
|
|
2189
4002
|
setBusy(true);
|
|
2190
|
-
const payload = { id: bot.id, name: draft.name.trim(), handle: draft.handle, bio: draft.bio.trim(), persona: draft.persona, model: draft.model, tools: { deny: draft.deny } };
|
|
4003
|
+
const payload = { id: bot.id, name: draft.name.trim(), handle: draft.handle, bio: draft.bio.trim(), persona: draft.persona, model: draft.model, tools: { deny: draft.deny, routerAllow: draft.routerAllow } };
|
|
2191
4004
|
if (draft.avatar) payload.avatar = avatarOf(draft.avatar);
|
|
2192
4005
|
postJson('save', { bot: payload })
|
|
2193
4006
|
.then((r) => {
|
|
@@ -2242,6 +4055,15 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2242
4055
|
const knownModel = !draft.model || Boolean(chosen);
|
|
2243
4056
|
const efforts = Array.isArray(chosen?.efforts) ? chosen.efforts : [];
|
|
2244
4057
|
const [sources, setSources] = useState(false);
|
|
4058
|
+
// A router dispatcher goes without some tools unless they are allowed back one ability at a time
|
|
4059
|
+
// (only while it routes: the only bot of a team keeps them all).
|
|
4060
|
+
const isPrimary = bot.role === 'primary' || bot.id === store.state?.primaryId;
|
|
4061
|
+
const routing = isPrimary && routerActiveOf();
|
|
4062
|
+
const routerDeny = new Set(routing ? routerDenyOf(catalog) : []);
|
|
4063
|
+
const routerAllow = new Set(draft.routerAllow);
|
|
4064
|
+
const routerBlocked = (names) => names.filter((x) => routerDeny.has(x) && !routerAllow.has(x));
|
|
4065
|
+
const inEffect = routing ? new Set([...draft.deny, ...routerBlocked([...routerDeny])]) : denied;
|
|
4066
|
+
const botLabel = draft.name || bot.name;
|
|
2245
4067
|
return h(
|
|
2246
4068
|
'div',
|
|
2247
4069
|
{ style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
@@ -2254,7 +4076,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2254
4076
|
h(
|
|
2255
4077
|
Section,
|
|
2256
4078
|
{ title: t('secAvatar') },
|
|
2257
|
-
h(AvatarEditor, { t, avatar: draft.avatar, name: draft.name || bot.name, onChange: (avatar) => set({ avatar }), onUpload: upload, onGenerate: generate, onClear: clearAvatar, imageGen: catalog?.imageGen === true, generating }),
|
|
4079
|
+
h(AvatarEditor, { t, avatar: draft.avatar, name: draft.name || bot.name, onChange: (avatar) => set({ avatar }), onUpload: upload, onGenerate: generate, onClear: clearAvatar, imageGen: catalog?.imageGen === true, generating: generating || liveBot(bot).avatarPending }),
|
|
2258
4080
|
),
|
|
2259
4081
|
h(
|
|
2260
4082
|
Section,
|
|
@@ -2276,6 +4098,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2276
4098
|
h(Field, { label: t('bio'), hint: t('bioHint'), style: { gridColumn: '1 / -1' } }, h(Input, { value: draft.bio, maxLength: 160, placeholder: t('bioPlaceholder'), onChange: (e) => set({ bio: e.target.value }) })),
|
|
2277
4099
|
),
|
|
2278
4100
|
),
|
|
4101
|
+
isPrimary ? h(Section, { title: t('dispatcherMode'), hint: t('dispatcherModeHint') }, h(DispatcherMode, { t, name: botLabel, toast })) : null,
|
|
2279
4102
|
h(
|
|
2280
4103
|
Section,
|
|
2281
4104
|
{ title: t('persona'), hint: t('personaHint') },
|
|
@@ -2316,18 +4139,22 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2316
4139
|
: null,
|
|
2317
4140
|
),
|
|
2318
4141
|
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,
|
|
4142
|
+
routing ? h('div', { 'data-dsh-bots-router-model-hint': true, style: { display: 'flex', alignItems: 'flex-start', gap: 6, fontSize: TINY, color: C.muted, lineHeight: 1.5 } }, h('span', { style: { color: C.label, display: 'inline-flex', paddingTop: 1 } }, Icon.sparkle(12)), t('routerModelHint')) : null,
|
|
2319
4143
|
),
|
|
2320
4144
|
h(
|
|
2321
4145
|
Section,
|
|
2322
|
-
{ title: t('abilities'), hint: t('
|
|
4146
|
+
{ title: t('abilities'), hint: routing ? t('abilitiesRouterHint', { name: botLabel }) : t('abilitiesHint', { name: botLabel }) },
|
|
2323
4147
|
abilities.length === 0
|
|
2324
4148
|
? h('div', { style: { fontSize: SMALL, color: C.faint } }, catalog ? t('noTools') : t('loading'))
|
|
2325
4149
|
: h(
|
|
2326
4150
|
'div',
|
|
2327
4151
|
{ 'data-dsh-bots-abilities': true, style: { display: 'flex', flexDirection: 'column', border: `1px solid ${C.border1}`, borderRadius: 12, overflow: 'hidden', background: C.layer1 } },
|
|
2328
4152
|
abilities.map((ab, i) => {
|
|
2329
|
-
const on = abilityOn(ab,
|
|
4153
|
+
const on = abilityOn(ab, inEffect);
|
|
2330
4154
|
const warn = ab.risky && on;
|
|
4155
|
+
const gated = ab.available.filter((x) => routerDeny.has(x));
|
|
4156
|
+
const blocked = routerBlocked(gated);
|
|
4157
|
+
const whole = gated.length > 0 && gated.length === ab.available.length;
|
|
2331
4158
|
return h(
|
|
2332
4159
|
'div',
|
|
2333
4160
|
{ key: ab.id, 'data-dsh-bots-ability': ab.id, 'data-on': on, style: { display: 'flex', alignItems: 'center', gap: 12, padding: '10px 14px', borderTop: i ? `1px solid ${C.border1}` : 'none', background: warn ? tint(C.warn, 8) : 'transparent' } },
|
|
@@ -2335,11 +4162,24 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2335
4162
|
h(
|
|
2336
4163
|
'div',
|
|
2337
4164
|
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 1 } },
|
|
2338
|
-
h(
|
|
4165
|
+
h(
|
|
4166
|
+
'span',
|
|
4167
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } },
|
|
4168
|
+
h('span', { style: { fontWeight: 600, color: on ? C.primary : C.muted } }, pick(ab.name, lang)),
|
|
4169
|
+
ab.risky ? h(Badge, { color: '#d97706' }, Icon.alert(10), t('risky')) : null,
|
|
4170
|
+
gated.length
|
|
4171
|
+
? blocked.length
|
|
4172
|
+
? h(Badge, { color: C.muted, title: blocked.join(', '), 'data-dsh-bots-router-off': ab.id }, t(whole ? 'routerOff' : 'routerPartOff'))
|
|
4173
|
+
: h(Badge, { color: C.label, title: gated.join(', '), 'data-dsh-bots-router-allowed': ab.id }, t('routerAllowed'))
|
|
4174
|
+
: null,
|
|
4175
|
+
gated.length && blocked.length && !whole && on
|
|
4176
|
+
? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-router-allow': ab.id, title: blocked.join(', '), onClick: () => set({ routerAllow: sorted(new Set([...draft.routerAllow, ...blocked])) }), style: { fontSize: TINY } }, t('routerAllowBack'))
|
|
4177
|
+
: null,
|
|
4178
|
+
),
|
|
2339
4179
|
h('span', { style: { fontSize: TINY, color: C.muted } }, pick(ab.description, lang)),
|
|
2340
4180
|
),
|
|
2341
4181
|
h('span', { className: 'dshb-mono', title: ab.available.join(', '), style: { fontSize: 11, color: C.faint, flex: 'none' } }, t('nTools', { n: ab.available.length })),
|
|
2342
|
-
h(Switch, { on, title: pick(ab.name, lang), onChange: (v) => set({ deny: toggleAbility(draft.deny, ab, v) }), 'data-dsh-bots-ability-switch': ab.id }),
|
|
4182
|
+
h(Switch, { on, title: pick(ab.name, lang), onChange: (v) => set(gated.length ? toggleRouterAbility(draft, ab, v, routerDeny) : { deny: toggleAbility(draft.deny, ab, v) }), 'data-dsh-bots-ability-switch': ab.id }),
|
|
2343
4183
|
);
|
|
2344
4184
|
}),
|
|
2345
4185
|
),
|
|
@@ -2371,7 +4211,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2371
4211
|
h(
|
|
2372
4212
|
'span',
|
|
2373
4213
|
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0 } },
|
|
2374
|
-
h('span', { className: 'dshb-mono', style: { fontSize: 12, fontWeight: 600, color: C.primary } }, x.name),
|
|
4214
|
+
h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 6, minWidth: 0 } }, h('span', { className: 'dshb-mono', style: { fontSize: 12, fontWeight: 600, color: C.primary } }, x.name), routerBlocked([x.name]).length ? h('span', { 'data-dsh-bots-router-tool': x.name, style: { fontSize: 10.5, color: C.faint, whiteSpace: 'nowrap' } }, t('routerOffShort')) : null),
|
|
2375
4215
|
x.description ? h('span', { style: { fontSize: TINY, color: C.faint, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, x.description) : null,
|
|
2376
4216
|
),
|
|
2377
4217
|
),
|
|
@@ -4021,13 +5861,15 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4021
5861
|
|
|
4022
5862
|
// --- detail: header + tabs ------------------------------------------------------------
|
|
4023
5863
|
|
|
4024
|
-
const TABS = ['chat', 'profile', 'memory', 'skills', 'schedules', 'apps'];
|
|
5864
|
+
const TABS = ['chat', 'tasks', 'profile', 'memory', 'skills', 'schedules', 'apps'];
|
|
4025
5865
|
function BotDetail({ t, bot, primaryId, env, toast, catalog, tab, setTab, onDeleted, onSettings }) {
|
|
4026
5866
|
const [menu, setMenu] = useState(false);
|
|
4027
5867
|
const [confirm, setConfirm] = useState(false);
|
|
4028
5868
|
const [opening, setOpening] = useState(false);
|
|
4029
5869
|
const isPrimary = bot.id === primaryId || bot.role === 'primary';
|
|
4030
|
-
|
|
5870
|
+
// Working on a task counts as working, as in the list.
|
|
5871
|
+
const live = liveBot(bot);
|
|
5872
|
+
const status = live.status === 'running' || live.activity || botTaskActivity(bot.id) ? 'running' : (live.status ?? 'offline');
|
|
4031
5873
|
const open = () => {
|
|
4032
5874
|
setOpening(true);
|
|
4033
5875
|
Promise.resolve(env.openBot(bot)).finally(() => setOpening(false));
|
|
@@ -4047,9 +5889,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4047
5889
|
void refreshState();
|
|
4048
5890
|
} else toast(r?.reason || t('actionFailed'), 'error');
|
|
4049
5891
|
});
|
|
4050
|
-
const counts = { skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length, memory: Number(bot.memoryNotes) || 0 };
|
|
5892
|
+
const counts = { tasks: openTaskCount(bot), skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length, memory: Number(bot.memoryNotes) || 0 };
|
|
4051
5893
|
let body;
|
|
4052
|
-
if (tab === '
|
|
5894
|
+
if (tab === 'tasks') body = h(BotTasksTab, { key: bot.id, t, bot });
|
|
5895
|
+
else if (tab === 'profile') body = h(ProfileTab, { key: bot.id, t, bot, toast, catalog });
|
|
4053
5896
|
else if (tab === 'skills') body = h(SkillsTab, { key: bot.id, t, bot, toast, catalog, setTab, env });
|
|
4054
5897
|
else if (tab === 'schedules') body = h(SchedulesTab, { key: bot.id, t, bot, toast, catalog });
|
|
4055
5898
|
else if (tab === 'apps') body = h(AppsTab, { key: bot.id, t, bot, toast, catalog });
|
|
@@ -4064,7 +5907,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4064
5907
|
h(
|
|
4065
5908
|
'div',
|
|
4066
5909
|
{ style: { display: 'flex', alignItems: 'center', gap: 14 } },
|
|
4067
|
-
h(Avatar, { avatar: bot.avatar, name: bot.name || bot.handle, size: 56, status, ring: isPrimary, title: t(`status_${status}`) }),
|
|
5910
|
+
h(Avatar, { avatar: bot.avatar, name: bot.name || bot.handle, size: 56, status, ring: isPrimary, pending: liveBot(bot).avatarPending, title: liveBot(bot).avatarPending ? t('avatarDrawing') : t(`status_${status}`) }),
|
|
4068
5911
|
h(
|
|
4069
5912
|
'div',
|
|
4070
5913
|
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
@@ -4334,12 +6177,22 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4334
6177
|
: null,
|
|
4335
6178
|
);
|
|
4336
6179
|
}
|
|
4337
|
-
const th = (label, right) => h('th', { style: { textAlign: right ? 'right' : 'left', fontWeight: 600, fontSize: TINY, color: C.muted, padding: '6px 8px', borderBottom: `1px solid ${C.border1}
|
|
4338
|
-
|
|
4339
|
-
const
|
|
6180
|
+
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}`, whiteSpace: 'nowrap' } }, label);
|
|
6181
|
+
// Text cells give way (and cut with an ellipsis); numbers never wrap or leave their card.
|
|
6182
|
+
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', overflow: 'hidden', ...(right ? { whiteSpace: 'nowrap' } : {}), ...extra } }, content);
|
|
6183
|
+
/** A table that stays inside its card: the first column takes what is left, the others have fixed widths (`cols`, px; null for the flexible one). */
|
|
6184
|
+
const NUM_COLS = [null, 56, 72, 84];
|
|
6185
|
+
const Table = ({ head, rows, attr, cols = NUM_COLS }) =>
|
|
6186
|
+
h(
|
|
6187
|
+
'table',
|
|
6188
|
+
{ [attr]: true, style: { width: '100%', tableLayout: 'fixed', borderCollapse: 'collapse', fontSize: SMALL } },
|
|
6189
|
+
h('colgroup', null, cols.map((w, i) => h('col', { key: i, style: w ? { width: w } : undefined }))),
|
|
6190
|
+
h('thead', null, h('tr', null, head)),
|
|
6191
|
+
h('tbody', null, rows),
|
|
6192
|
+
);
|
|
4340
6193
|
function BotCell({ t, id }) {
|
|
4341
6194
|
const b = botById(id);
|
|
4342
|
-
return h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 7, minWidth: 0 } }, b ? h(Avatar, { avatar: b.avatar, name: b.name || b.handle, size: 20 }) : h('span', { style: { width: 20, height: 20, borderRadius: '50%', background: C.layer2 } }), h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, botName(t, id)));
|
|
6195
|
+
return h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 7, minWidth: 0, maxWidth: '100%' } }, b ? h(Avatar, { avatar: b.avatar, name: b.name || b.handle, size: 20 }) : h('span', { style: { width: 20, height: 20, borderRadius: '50%', background: C.layer2 } }), h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, botName(t, id)));
|
|
4343
6196
|
}
|
|
4344
6197
|
function triggerText(t, task) {
|
|
4345
6198
|
if (task.trigger === 'schedule') return t('trigger_schedule');
|
|
@@ -4348,6 +6201,18 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4348
6201
|
return t('trigger_user');
|
|
4349
6202
|
}
|
|
4350
6203
|
|
|
6204
|
+
/** The usage report's rows by task (ticket), read loosely: `{id, title, bot, stage?, runs, tokens, cost}`. */
|
|
6205
|
+
function usageTickets(data) {
|
|
6206
|
+
const rows = Array.isArray(data?.tickets) ? data.tickets : Array.isArray(data?.byTicket) ? data.byTicket : [];
|
|
6207
|
+
return rows
|
|
6208
|
+
.map((r) => (r && typeof r === 'object' ? { ...r, id: str(r.id ?? r.ticket), bot: r.bot ?? r.botId } : null))
|
|
6209
|
+
.filter((r) => r && r.id);
|
|
6210
|
+
}
|
|
6211
|
+
/** The task a run belongs to, when the report says. */
|
|
6212
|
+
const runTicket = (r) => {
|
|
6213
|
+
const v = r?.ticket ?? r?.t;
|
|
6214
|
+
return typeof v === 'string' && v ? v : '';
|
|
6215
|
+
};
|
|
4351
6216
|
function UsageView({ t, bots }) {
|
|
4352
6217
|
const [range, setRange] = useState('7d');
|
|
4353
6218
|
const [bot, setBot] = useState('');
|
|
@@ -4356,6 +6221,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4356
6221
|
const tot = data?.totals;
|
|
4357
6222
|
const prev = data?.prev;
|
|
4358
6223
|
const empty = tot && tot.calls === 0;
|
|
6224
|
+
const allTickets = usageTickets(data);
|
|
6225
|
+
const [moreTasks, setMoreTasks] = useState(false);
|
|
6226
|
+
const TASK_ROWS = 8;
|
|
6227
|
+
const tickets = moreTasks ? allTickets : allTickets.slice(0, TASK_ROWS);
|
|
4359
6228
|
const section = (title, body, right) => h('section', { className: 'dshb-card', style: { display: 'flex', flexDirection: 'column', gap: 10, minWidth: 0 } }, h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } }, h('span', { style: { fontWeight: 700, fontSize: SMALL } }, title), h('span', { style: { flex: 1 } }), right ?? null), body);
|
|
4360
6229
|
return h(
|
|
4361
6230
|
'div',
|
|
@@ -4381,7 +6250,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4381
6250
|
{ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 12 } },
|
|
4382
6251
|
h(Tile, { attr: 'tokens', label: t('tileTokens'), value: fmtNum(tot.tokens), sub: t('tileCacheRate', { pct: Math.round((tot.cacheRate ?? 0) * 100) }), delta: pctDelta(tot.tokens, prev?.tokens) ? t('vsPrev', { delta: pctDelta(tot.tokens, prev.tokens) }) : '' }),
|
|
4383
6252
|
h(Tile, { attr: 'cost', label: t('tileCost'), value: fmtCost(tot.cost), sub: tot.unpriced > 0 ? t('tileUnpriced', { tokens: fmtNum(tot.unpriced) }) : '' }),
|
|
4384
|
-
h(Tile, { attr: '
|
|
6253
|
+
h(Tile, { attr: 'runs', label: t('tileRuns'), value: String(tot.tasks ?? 0), delta: pctDelta(tot.tasks, prev?.tasks) ? t('vsPrev', { delta: pctDelta(tot.tasks, prev.tasks) }) : '' }),
|
|
4385
6254
|
h(Tile, { attr: 'calls', label: t('tileCalls'), value: String(tot.calls ?? 0), sub: t('tileInOut', { input: fmtNum(tot.input + tot.cacheRead + tot.cacheWrite), output: fmtNum(tot.output) }) }),
|
|
4386
6255
|
),
|
|
4387
6256
|
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 })),
|
|
@@ -4394,7 +6263,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4394
6263
|
t('byBot'),
|
|
4395
6264
|
h(Table, {
|
|
4396
6265
|
attr: 'data-dsh-bots-usage-bots',
|
|
4397
|
-
head: [th(t('colBot')), th(t('
|
|
6266
|
+
head: [th(t('colBot')), th(t('colRunCount'), true), th(t('colTokens'), true), th(t('colCost'), true)],
|
|
4398
6267
|
rows: data.bots.map((r) => h('tr', { key: r.bot, onClick: () => setBot(bot === r.bot ? '' : r.bot), style: { cursor: 'pointer' } }, td(h(BotCell, { t, id: r.bot })), td(String(r.tasks), true), td(fmtNum(r.tokens), true), td(fmtCost(r.cost), true))),
|
|
4399
6268
|
}),
|
|
4400
6269
|
),
|
|
@@ -4407,7 +6276,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4407
6276
|
h(
|
|
4408
6277
|
'tr',
|
|
4409
6278
|
{ key: `${r.provider}/${r.model}` },
|
|
4410
|
-
td(h('span', { style: { display: 'flex', flexDirection: 'column', minWidth: 0 } }, h('span', { className: 'dshb-mono', style: { fontSize: 12, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
6279
|
+
td(h('span', { style: { display: 'flex', flexDirection: 'column', minWidth: 0 } }, h('span', { className: 'dshb-mono', style: { fontSize: 12, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: r.model }, r.model), h('span', { style: { fontSize: TINY, color: C.faint } }, r.provider))),
|
|
4411
6280
|
td(String(r.calls), true),
|
|
4412
6281
|
td(fmtNum(r.tokens), true),
|
|
4413
6282
|
td(r.priced ? fmtCost(r.cost) : h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY }, onClick: () => setPrices(r.model) }, t('setPrice')), true),
|
|
@@ -4423,13 +6292,44 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4423
6292
|
rows: data.kinds.map((r) => h('tr', { key: r.kind }, td(t(`work_${r.kind}`)), td(String(r.calls), true), td(fmtNum(r.tokens), true), td(fmtCost(r.cost), true))),
|
|
4424
6293
|
}),
|
|
4425
6294
|
),
|
|
6295
|
+
tickets.length
|
|
6296
|
+
? section(
|
|
6297
|
+
t('byTask'),
|
|
6298
|
+
h(
|
|
6299
|
+
'div',
|
|
6300
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0 } },
|
|
6301
|
+
h(Table, {
|
|
6302
|
+
attr: 'data-dsh-bots-usage-tickets',
|
|
6303
|
+
head: [th(t('colTask')), th(t('colRunCount'), true), th(t('colTokens'), true), th(t('colCost'), true)],
|
|
6304
|
+
rows: tickets.map((r) =>
|
|
6305
|
+
h(
|
|
6306
|
+
'tr',
|
|
6307
|
+
{ key: r.id, 'data-dsh-bots-usage-ticket': r.id, onClick: () => openTicket(r.id), style: { cursor: 'pointer' } },
|
|
6308
|
+
td(
|
|
6309
|
+
h(
|
|
6310
|
+
'span',
|
|
6311
|
+
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0 } },
|
|
6312
|
+
h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 6, minWidth: 0 } }, h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: taskTitle(t, r) }, taskTitle(t, r)), h(StageChip, { t, stage: r.stage })),
|
|
6313
|
+
h('span', { style: { fontSize: TINY, color: C.faint } }, botName(t, r.bot)),
|
|
6314
|
+
),
|
|
6315
|
+
),
|
|
6316
|
+
td(String(r.runs ?? 0), true),
|
|
6317
|
+
td(fmtNum(r.tokens), true),
|
|
6318
|
+
td(fmtCost(r.cost), true),
|
|
6319
|
+
),
|
|
6320
|
+
),
|
|
6321
|
+
}),
|
|
6322
|
+
allTickets.length > TASK_ROWS ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-usage-more-tasks': true, style: { fontSize: TINY, alignSelf: 'flex-start' }, onClick: () => setMoreTasks((v) => !v) }, moreTasks ? t('showLess') : t('usageAllTasks', { n: allTickets.length })) : null,
|
|
6323
|
+
),
|
|
6324
|
+
)
|
|
6325
|
+
: null,
|
|
4426
6326
|
data.schedules.length
|
|
4427
6327
|
? section(
|
|
4428
6328
|
t('bySchedule'),
|
|
4429
6329
|
h(Table, {
|
|
4430
6330
|
attr: 'data-dsh-bots-usage-schedules',
|
|
4431
6331
|
head: [th(t('colTask')), th(t('colRuns'), true), th(t('colTokens'), true), th(t('colCost'), true)],
|
|
4432
|
-
rows: data.schedules.map((r) => h('tr', { key: r.id }, td(h('span', { style: { display: 'flex', flexDirection: 'column' } }, h('span',
|
|
6332
|
+
rows: data.schedules.map((r) => h('tr', { key: r.id }, td(h('span', { style: { display: 'flex', flexDirection: 'column', minWidth: 0 } }, h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: r.title }, r.title), h('span', { style: { fontSize: TINY, color: C.faint } }, botName(t, r.bot)))), td(String(r.runs), true), td(fmtNum(r.tokens), true), td(fmtCost(r.cost), true))),
|
|
4433
6333
|
}),
|
|
4434
6334
|
)
|
|
4435
6335
|
: null,
|
|
@@ -4437,10 +6337,11 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4437
6337
|
empty || data.tasks.length === 0
|
|
4438
6338
|
? null
|
|
4439
6339
|
: section(
|
|
4440
|
-
t('
|
|
6340
|
+
t('recentRuns'),
|
|
4441
6341
|
h(Table, {
|
|
4442
6342
|
attr: 'data-dsh-bots-usage-tasks',
|
|
4443
|
-
|
|
6343
|
+
cols: [null, 150, 110, 72, 84],
|
|
6344
|
+
head: [th(t('colRun')), th(t('colBot')), th(t('colWhen')), th(t('colTokens'), true), th(t('colCost'), true)],
|
|
4444
6345
|
rows: data.tasks.map((r) =>
|
|
4445
6346
|
h(
|
|
4446
6347
|
'tr',
|
|
@@ -4448,13 +6349,14 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4448
6349
|
td(
|
|
4449
6350
|
h(
|
|
4450
6351
|
'span',
|
|
4451
|
-
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0
|
|
6352
|
+
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0 } },
|
|
4452
6353
|
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: r.title }, r.title),
|
|
4453
6354
|
h(
|
|
4454
6355
|
'span',
|
|
4455
6356
|
{ style: { fontSize: TINY, color: C.faint, display: 'inline-flex', gap: 6, alignItems: 'center' } },
|
|
4456
6357
|
triggerText(t, r),
|
|
4457
6358
|
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,
|
|
6359
|
+
runTicket(r) ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-usage-run-task': runTicket(r), onClick: () => openTicket(runTicket(r)), style: { fontSize: TINY } }, t('openTask')) : null,
|
|
4458
6360
|
),
|
|
4459
6361
|
),
|
|
4460
6362
|
),
|
|
@@ -4502,6 +6404,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4502
6404
|
? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('noUsage'))
|
|
4503
6405
|
: h(Table, {
|
|
4504
6406
|
attr: 'data-dsh-bots-price-table',
|
|
6407
|
+
cols: [null, 96, 96, 72],
|
|
4505
6408
|
head: [th(t('colModel')), th(t('priceInput'), true), th(t('priceOutput'), true), th('')],
|
|
4506
6409
|
rows: data.models.map((m) =>
|
|
4507
6410
|
h(
|
|
@@ -4735,19 +6638,28 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4735
6638
|
);
|
|
4736
6639
|
}
|
|
4737
6640
|
|
|
6641
|
+
/** Task limits the Host uses when its settings do not say (lib/tickets.mjs, lib/watchdog.mjs). */
|
|
6642
|
+
const TICKET_DEFAULTS = { maxWorking: 4, stallMinutes: 20, archiveHours: 24 };
|
|
6643
|
+
const numberOr = (v, d, min) => {
|
|
6644
|
+
const n = Number(v);
|
|
6645
|
+
return str(v).trim() !== '' && Number.isFinite(n) ? Math.max(min, n) : d;
|
|
6646
|
+
};
|
|
4738
6647
|
function SettingsModal({ t, catalog, onClose, toast }) {
|
|
4739
6648
|
const [form, setForm] = useState(null);
|
|
4740
6649
|
const [busy, setBusy] = useState(false);
|
|
4741
6650
|
useEffect(() => {
|
|
4742
|
-
void getJson('settings').then((r) => r?.settings && setForm(r.settings));
|
|
6651
|
+
void getJson('settings').then((r) => r?.settings && setForm({ ...r.settings, tickets: { ...TICKET_DEFAULTS, ...(r.settings.tickets ?? {}) }, display: { botMessages: 'line', ...(r.settings.display ?? {}) } }));
|
|
4743
6652
|
}, []);
|
|
4744
6653
|
const set = (part, patch) => setForm((f) => ({ ...f, [part]: { ...f[part], ...patch } }));
|
|
4745
6654
|
const models = Array.isArray(catalog?.models) ? catalog.models : [];
|
|
4746
6655
|
const save = () => {
|
|
4747
6656
|
setBusy(true);
|
|
4748
|
-
|
|
6657
|
+
const tk = form.tickets;
|
|
6658
|
+
const tickets = { maxWorking: Math.round(numberOr(tk.maxWorking, TICKET_DEFAULTS.maxWorking, 1)), stallMinutes: numberOr(tk.stallMinutes, TICKET_DEFAULTS.stallMinutes, 1), archiveHours: numberOr(tk.archiveHours, TICKET_DEFAULTS.archiveHours, 0) };
|
|
6659
|
+
postJson('settings', { patch: { display: { botMessages: form.display.botMessages }, tickets, topics: { idleHours: Number(form.topics.idleHours) || 0, maxContextK: Number(form.topics.maxContextK) || 0 }, memory: form.memory } })
|
|
4749
6660
|
.then((r) => {
|
|
4750
6661
|
if (r?.ok) {
|
|
6662
|
+
tookSettings(r.settings);
|
|
4751
6663
|
toast(t('settingsSaved'));
|
|
4752
6664
|
onClose();
|
|
4753
6665
|
} else toast(r?.reason || t('saveFailed'), 'error');
|
|
@@ -4767,6 +6679,28 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4767
6679
|
!form
|
|
4768
6680
|
? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('loading'))
|
|
4769
6681
|
: [
|
|
6682
|
+
h(
|
|
6683
|
+
Section,
|
|
6684
|
+
{ key: 'chat', title: t('setChat') },
|
|
6685
|
+
row(
|
|
6686
|
+
t('setBotMessages'),
|
|
6687
|
+
t(`setBotMessagesHint_${form.display.botMessages}`),
|
|
6688
|
+
h(
|
|
6689
|
+
'div',
|
|
6690
|
+
{ className: 'dshb-seg', role: 'radiogroup', 'aria-label': t('setBotMessages'), 'data-dsh-bots-setting': 'botMessages' },
|
|
6691
|
+
['line', 'short', 'full'].map((v) =>
|
|
6692
|
+
h('button', { key: v, type: 'button', role: 'radio', 'aria-checked': form.display.botMessages === v, 'data-active': form.display.botMessages === v, 'data-dsh-bots-bot-messages': v, onClick: () => set('display', { botMessages: v }) }, t(`botMessages_${v}`)),
|
|
6693
|
+
),
|
|
6694
|
+
),
|
|
6695
|
+
),
|
|
6696
|
+
),
|
|
6697
|
+
h(
|
|
6698
|
+
Section,
|
|
6699
|
+
{ key: 'tasks', title: t('setTasks') },
|
|
6700
|
+
row(t('setMaxWorking'), t('setMaxWorkingHint'), h(Input, { type: 'number', min: 1, max: 32, value: form.tickets.maxWorking, onChange: (e) => set('tickets', { maxWorking: e.target.value }), 'data-dsh-bots-setting': 'maxWorking', style: { width: 90 } })),
|
|
6701
|
+
row(t('setStall'), t('setStallHint'), h(Input, { type: 'number', min: 1, max: 1440, value: form.tickets.stallMinutes, onChange: (e) => set('tickets', { stallMinutes: e.target.value }), 'data-dsh-bots-setting': 'stallMinutes', style: { width: 90 } })),
|
|
6702
|
+
row(t('setArchive'), t('setArchiveHint'), h(Input, { type: 'number', min: 0, max: 720, value: form.tickets.archiveHours, onChange: (e) => set('tickets', { archiveHours: e.target.value }), 'data-dsh-bots-setting': 'archiveHours', style: { width: 90 } })),
|
|
6703
|
+
),
|
|
4770
6704
|
h(
|
|
4771
6705
|
Section,
|
|
4772
6706
|
{ key: 'topics', title: t('setTopics') },
|
|
@@ -5494,15 +7428,22 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5494
7428
|
const [hire, setHire] = useState(null); // {team, phase: confirm|start|busy|done|error, primary, result?}
|
|
5495
7429
|
const [primaryTick, setPrimaryTick] = useState(true);
|
|
5496
7430
|
const [settings, setSettings] = useState(false);
|
|
7431
|
+
const [ticketId, setTicketId] = useState(null); // the task shown in the Tasks view
|
|
7432
|
+
const [tasksBot, setTasksBot] = useState(''); // the Tasks view's bot filter when another view asked for it
|
|
7433
|
+
const [noticeGone, setNoticeGone] = useState(false);
|
|
5497
7434
|
const [toast, showToast] = useToast();
|
|
5498
7435
|
const seenNav = useRef(0);
|
|
5499
7436
|
const bots = Array.isArray(s.state?.bots) ? s.state.bots : [];
|
|
5500
7437
|
const primaryId = s.state?.primaryId ?? bots.find((b) => b.role === 'primary')?.id ?? null;
|
|
5501
|
-
// Another seat (a badge, a tool card) asked for a bot.
|
|
7438
|
+
// Another seat (a badge, a tool card, a task card) asked for a bot, a view or a task.
|
|
5502
7439
|
useEffect(() => {
|
|
5503
7440
|
if (s.nav.tick === seenNav.current) return;
|
|
5504
7441
|
seenNav.current = s.nav.tick;
|
|
5505
|
-
if (s.nav.view === '
|
|
7442
|
+
if (s.nav.view === 'tasks') {
|
|
7443
|
+
setView('tasks');
|
|
7444
|
+
setTicketId(s.nav.ticket ?? null);
|
|
7445
|
+
setTasksBot(s.nav.ticket ? '' : (s.nav.botId ?? ''));
|
|
7446
|
+
} else if (s.nav.view === 'activity') setView('activity');
|
|
5506
7447
|
else if (s.nav.botId) {
|
|
5507
7448
|
setSelected(s.nav.botId);
|
|
5508
7449
|
setView('bot');
|
|
@@ -5533,6 +7474,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5533
7474
|
let main;
|
|
5534
7475
|
if (!s.state) {
|
|
5535
7476
|
main = h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', color: C.faint, fontSize: SMALL } }, s.failed ? t('unavailable') : t('loading'));
|
|
7477
|
+
} else if (shownView === 'tasks') {
|
|
7478
|
+
main = ticketId ? h(TicketDetail, { key: ticketId, t, id: ticketId, env: env2, toast: showToast, onBack: () => setTicketId(null) }) : h(TasksView, { t, bots, focusBot: tasksBot, onOpen: setTicketId });
|
|
5536
7479
|
} else if (shownView === 'activity') {
|
|
5537
7480
|
main = h(ActivityView, { t, bots });
|
|
5538
7481
|
} else if (shownView === 'usage') {
|
|
@@ -5566,8 +7509,29 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5566
7509
|
onMemory: () => setView('memory'),
|
|
5567
7510
|
onSettings: () => setSettings(true),
|
|
5568
7511
|
teamNotes: s.state?.teamNotes ?? 0,
|
|
7512
|
+
onTasks: () => {
|
|
7513
|
+
setView('tasks');
|
|
7514
|
+
setTicketId(null);
|
|
7515
|
+
setTasksBot('');
|
|
7516
|
+
},
|
|
7517
|
+
attention: Array.isArray(s.state?.attention) ? s.state.attention.length : 0,
|
|
7518
|
+
openTasks: bots.reduce((n, b) => n + openTaskCount(b), 0),
|
|
5569
7519
|
}),
|
|
5570
|
-
h(
|
|
7520
|
+
h(
|
|
7521
|
+
'div',
|
|
7522
|
+
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', minHeight: 0 } },
|
|
7523
|
+
!noticeGone && routerNotice.pending(s.state)
|
|
7524
|
+
? h(RouterNoticeBanner, {
|
|
7525
|
+
t,
|
|
7526
|
+
onOpenDispatcher: primaryId ? () => openBotTab(primaryId, 'profile') : null,
|
|
7527
|
+
onDismiss: () => {
|
|
7528
|
+
setNoticeGone(true);
|
|
7529
|
+
void Promise.resolve(routerNotice.dismiss()).then(() => refreshState());
|
|
7530
|
+
},
|
|
7531
|
+
})
|
|
7532
|
+
: null,
|
|
7533
|
+
main,
|
|
7534
|
+
),
|
|
5571
7535
|
creating
|
|
5572
7536
|
? h(NewBotModal, {
|
|
5573
7537
|
t,
|
|
@@ -5588,7 +7552,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5588
7552
|
h(Toast, { toast }),
|
|
5589
7553
|
);
|
|
5590
7554
|
}
|
|
5591
|
-
const nullEnv = { canOpen: () => false, openBot: () => false, openPanel: () => false };
|
|
7555
|
+
const nullEnv = { canOpen: () => false, openBot: () => false, openSession: () => false, openPanel: () => false };
|
|
5592
7556
|
|
|
5593
7557
|
// --- tool views in the conversation -----------------------------------------------------
|
|
5594
7558
|
|
|
@@ -5680,9 +7644,14 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5680
7644
|
const to = faceOf(meta.to, args.to);
|
|
5681
7645
|
const from = meta.from ? faceOf(meta.from) : null;
|
|
5682
7646
|
const delivered = phase === 'result' && !block?.isError;
|
|
7647
|
+
// A delegation opens (or adds to) a task; a worker's message to whoever asked is a report with a status.
|
|
7648
|
+
const ref = meta.ticket && typeof meta.ticket === 'object' ? meta.ticket : null;
|
|
7649
|
+
const ticketId = typeof meta.ticket === 'string' ? meta.ticket : typeof ref?.id === 'string' ? ref.id : typeof args.ticket === 'string' ? args.ticket : '';
|
|
7650
|
+
const report = REPORT_STATUSES.includes(args.status) ? args.status : '';
|
|
7651
|
+
const showTicket = (id) => (typeof props.env?.showTicket === 'function' ? props.env.showTicket(id) : openTicket(id));
|
|
5683
7652
|
return h(
|
|
5684
7653
|
ToolShell,
|
|
5685
|
-
{ t, phase, block, title: t('toolSend'), env: props.env, face: to },
|
|
7654
|
+
{ t, phase, block, title: report ? t('toolReport') : t('toolSend'), env: props.env, face: to },
|
|
5686
7655
|
h(
|
|
5687
7656
|
'div',
|
|
5688
7657
|
{ 'data-dsh-bots-dm': true, style: { border: `1px solid ${C.border1}`, borderRadius: 12, background: C.layer1, padding: '8px 12px', display: 'flex', flexDirection: 'column', gap: 6, maxWidth: 640 } },
|
|
@@ -5691,10 +7660,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5691
7660
|
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: SMALL, minWidth: 0, flexWrap: 'wrap' } },
|
|
5692
7661
|
from ? h(FaceLine, { face: from, size: 18 }) : null,
|
|
5693
7662
|
h('span', { style: { color: C.faint, display: 'inline-flex' } }, Icon.arrow(12)),
|
|
5694
|
-
to ? h(FaceLine, { face: to, size: 18 }) : h('span', { style: { color: C.faint } }, '…'),
|
|
7663
|
+
to ? h(FaceLine, { face: to, size: 18 }) : h('span', { style: { color: C.faint } }, report ? t('requesterShort') : '…'),
|
|
7664
|
+
report ? h(ReportChip, { t, status: report }) : null,
|
|
5695
7665
|
delivered ? h('span', { style: { marginLeft: 'auto', display: 'inline-flex', alignItems: 'center', gap: 4, color: C.ok, fontSize: TINY } }, Icon.check(11), t('delivered')) : null,
|
|
5696
7666
|
),
|
|
7667
|
+
ticketId && !report ? h(TaskCard, { t, id: ticketId, botId: to?.id, face: to, title: str(ref?.title) || firstLine(args.text), stage: typeof meta.stage === 'string' ? meta.stage : ref?.stage, onOpen: showTicket }) : null,
|
|
5697
7668
|
args.text ? h(Clamp, { t, text: args.text, lines: 5, style: { fontSize: SMALL, color: C.primary } }) : null,
|
|
7669
|
+
ticketId && report ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-report-task': ticketId, onClick: () => showTicket(ticketId), style: { fontSize: TINY, alignSelf: 'flex-start' } }, t('openTask')) : null,
|
|
5698
7670
|
),
|
|
5699
7671
|
);
|
|
5700
7672
|
}
|
|
@@ -5815,7 +7787,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5815
7787
|
const t = typeof props.t === 'function' ? props.t : fallbackT;
|
|
5816
7788
|
const s = useStore();
|
|
5817
7789
|
const id = props.sessionId;
|
|
5818
|
-
|
|
7790
|
+
// A task's own conversation (`ticket-<id>`): the badge names its bot and opens the task.
|
|
7791
|
+
const ticketId = /^ticket-(t[a-z0-9]{8})$/.exec(str(id))?.[1] ?? '';
|
|
7792
|
+
useEffect(() => {
|
|
7793
|
+
if (ticketId) void loadTicket(ticketId);
|
|
7794
|
+
}, [ticketId]);
|
|
7795
|
+
const view = ticketId ? (s.tickets.get(ticketId)?.view ?? null) : null;
|
|
7796
|
+
const botId = (id ? s.state?.sessionMap?.[id] : undefined) ?? view?.botId;
|
|
5819
7797
|
const bot = botId ? botById(botId) : null;
|
|
5820
7798
|
if (!bot) return null;
|
|
5821
7799
|
return h(
|
|
@@ -5824,8 +7802,9 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5824
7802
|
type: 'button',
|
|
5825
7803
|
className: 'dshb',
|
|
5826
7804
|
'data-dsh-bots-badge': bot.id,
|
|
5827
|
-
|
|
5828
|
-
|
|
7805
|
+
'data-dsh-bots-badge-task': ticketId || undefined,
|
|
7806
|
+
title: ticketId ? t('taskBadgeTitle', { name: bot.name, title: str(view?.title) || ticketId }) : t('badgeTitle', { name: bot.name }),
|
|
7807
|
+
onClick: () => (ticketId && props.env?.showTicket ? props.env.showTicket(ticketId) : props.env?.showBot?.(bot.id)),
|
|
5829
7808
|
style: { display: 'inline-flex', alignItems: 'center', gap: 6, height: 26, padding: '0 9px 0 3px', borderRadius: 999, border: `1px solid ${C.border}`, background: C.layer1, color: C.primary, font: 'inherit', fontSize: SMALL, cursor: 'pointer', maxWidth: 220 },
|
|
5830
7809
|
},
|
|
5831
7810
|
h(Style),
|
|
@@ -5892,8 +7871,72 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5892
7871
|
chatEmptyTitle: 'Say hi to {name}',
|
|
5893
7872
|
chatEmptyBody: 'Messages you send land in this bot’s own conversation, where it works on them with its persona, skills and apps.',
|
|
5894
7873
|
working: '{name} is working…',
|
|
7874
|
+
workingPlain: 'Working…',
|
|
7875
|
+
liveTotal: 'step {n} · {time} so far',
|
|
7876
|
+
elapsedS: '{s}s',
|
|
7877
|
+
elapsedM: '{m}m {s}s',
|
|
7878
|
+
elapsedH: '{h}h {m}m',
|
|
7879
|
+
avatarDrawing: 'Drawing a new avatar…',
|
|
7880
|
+
act_thinking: 'Thinking',
|
|
7881
|
+
act_writing: 'Writing the reply',
|
|
7882
|
+
act_run: 'Running {detail}',
|
|
7883
|
+
act_run_bare: 'Running a command',
|
|
7884
|
+
act_read: 'Reading {detail}',
|
|
7885
|
+
act_read_bare: 'Reading a file',
|
|
7886
|
+
act_edit: 'Editing {detail}',
|
|
7887
|
+
act_edit_bare: 'Editing a file',
|
|
7888
|
+
act_write: 'Writing {detail}',
|
|
7889
|
+
act_write_bare: 'Writing a file',
|
|
7890
|
+
act_find: 'Looking for {detail}',
|
|
7891
|
+
act_find_bare: 'Looking through files',
|
|
7892
|
+
act_search: 'Searching for “{detail}”',
|
|
7893
|
+
act_search_bare: 'Searching the web',
|
|
7894
|
+
act_fetch: 'Reading {detail}',
|
|
7895
|
+
act_fetch_bare: 'Reading a web page',
|
|
7896
|
+
act_delegate: 'Handing work to {detail}',
|
|
7897
|
+
act_followup: 'Writing to task {detail}',
|
|
7898
|
+
act_report: 'Reporting back',
|
|
7899
|
+
act_ask: 'Asking you',
|
|
7900
|
+
act_draw: 'Drawing a picture',
|
|
7901
|
+
act_helper: 'Helper: {detail}',
|
|
7902
|
+
act_helper_bare: 'Working with a helper',
|
|
7903
|
+
act_skill: 'Using the skill {detail}',
|
|
7904
|
+
act_skill_bare: 'Loading a skill',
|
|
7905
|
+
act_memory: 'Searching memory for “{detail}”',
|
|
7906
|
+
act_memory_bare: 'Searching memory',
|
|
7907
|
+
act_remember: 'Updating memory',
|
|
7908
|
+
act_reply: 'Replying in a chat',
|
|
7909
|
+
act_recall: 'Looking up {detail}',
|
|
7910
|
+
act_recall_bare: 'Looking something up',
|
|
7911
|
+
act_team: 'Updating the team',
|
|
7912
|
+
act_schedule: 'Scheduling',
|
|
7913
|
+
act_plan: 'Updating its plan',
|
|
7914
|
+
act_job: 'Checking a background job',
|
|
7915
|
+
act_office: 'Working on a document',
|
|
7916
|
+
act_tool: 'Using {detail}',
|
|
5895
7917
|
composer: 'Message @{handle}',
|
|
5896
7918
|
composerHint: 'Enter to send · Shift+Enter for a new line',
|
|
7919
|
+
replyAction: 'Reply',
|
|
7920
|
+
replyingTo: 'Replying to {name}',
|
|
7921
|
+
cancelReply: 'Cancel the reply',
|
|
7922
|
+
topicLabel: 'Topic',
|
|
7923
|
+
topicTitle: 'Topic',
|
|
7924
|
+
topicReplyOne: '1 reply',
|
|
7925
|
+
topicReplies: '{n} replies',
|
|
7926
|
+
topicEmpty: 'No replies yet.',
|
|
7927
|
+
topicComposer: 'Reply in this topic',
|
|
7928
|
+
topicUnread: 'New replies',
|
|
7929
|
+
openTopic: 'Open the topic',
|
|
7930
|
+
closeTopic: 'Close the topic',
|
|
7931
|
+
movedTo: 'Put into “{title}”',
|
|
7932
|
+
movedToTopic: 'Put into another topic',
|
|
7933
|
+
movedIn: 'Moved into this topic',
|
|
7934
|
+
newReplyOne: 'A topic has a new reply',
|
|
7935
|
+
newReplies: '{n} topics have new replies',
|
|
7936
|
+
msgPending: 'Queued',
|
|
7937
|
+
msgPendingHint: 'Delivered; the bot takes it as soon as it finishes its current step.',
|
|
7938
|
+
msgFailed: 'Not sent',
|
|
7939
|
+
resend: 'Send again',
|
|
5897
7940
|
fullTranscript: 'Full transcript in its conversation',
|
|
5898
7941
|
send: 'Send',
|
|
5899
7942
|
sendFailed: 'Could not send the message.',
|
|
@@ -6378,6 +8421,135 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6378
8421
|
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.',
|
|
6379
8422
|
viaChannel: '{app} · {who}',
|
|
6380
8423
|
sentToChannel: 'Also sent to {app}',
|
|
8424
|
+
threadPart: 'thread',
|
|
8425
|
+
threadTopic: 'topic',
|
|
8426
|
+
notSent: 'Not sent',
|
|
8427
|
+
notSentChats: 'Not sent to any chat: this turn involved several ({chats}).',
|
|
8428
|
+
// tasks
|
|
8429
|
+
tasks: 'Tasks',
|
|
8430
|
+
tasksHint: 'Work handed to your bots',
|
|
8431
|
+
tasksNeedYou: '{n} need you',
|
|
8432
|
+
askTitle: '{name} is asking you',
|
|
8433
|
+
askNativeTitle: '{name} is waiting for you in the conversation',
|
|
8434
|
+
askNativeHint: 'Answer this one in the conversation.',
|
|
8435
|
+
askContinued: '{name} went on with other work; your answer still reaches it.',
|
|
8436
|
+
askMulti: 'Choose all that apply',
|
|
8437
|
+
askOtherPlaceholder: 'Or type your own answer',
|
|
8438
|
+
askFreePlaceholder: 'Type your answer',
|
|
8439
|
+
askSubmit: 'Submit',
|
|
8440
|
+
askFailed: 'The answer could not be sent.',
|
|
8441
|
+
askingBadge: '{n} waiting for your answer',
|
|
8442
|
+
askingChip: 'Asks you',
|
|
8443
|
+
tasksInProgress: '{n} in progress',
|
|
8444
|
+
tasksSub: 'Work your bots have taken on. Each task runs in its own conversation, so several move at once.',
|
|
8445
|
+
tasksNeeds: 'Needs you',
|
|
8446
|
+
tasksNeedsEmpty: 'Nothing needs you right now.',
|
|
8447
|
+
tasksProgress: 'In progress',
|
|
8448
|
+
tasksProgressEmpty: 'Nothing is in progress.',
|
|
8449
|
+
tasksDone: 'Recently done',
|
|
8450
|
+
tasksDoneEmpty: 'Nothing finished yet.',
|
|
8451
|
+
tasksUnavailable: 'Could not load the tasks.',
|
|
8452
|
+
tasksEmptyTitle: 'No tasks yet',
|
|
8453
|
+
tasksEmptyBotTitle: 'No tasks for {name} yet',
|
|
8454
|
+
tasksEmptyBody: 'When the dispatcher hands work to a teammate, it shows up here as a task you can follow, answer and stop.',
|
|
8455
|
+
untitledTask: 'Untitled task',
|
|
8456
|
+
openTask: 'Open task',
|
|
8457
|
+
followUpTask: 'Went to its task',
|
|
8458
|
+
followUpHint: 'A follow-up in the chat a task came from goes straight to that task.',
|
|
8459
|
+
taskOf: 'Task · {name}',
|
|
8460
|
+
stage_question: 'Needs your answer',
|
|
8461
|
+
stage_failed: 'Failed',
|
|
8462
|
+
stage_stalled: 'Stuck',
|
|
8463
|
+
stage_queued: 'Queued',
|
|
8464
|
+
stage_working: 'Working',
|
|
8465
|
+
stage_done: 'Done',
|
|
8466
|
+
stage_stopped: 'Stopped',
|
|
8467
|
+
report_progress: 'Progress',
|
|
8468
|
+
report_done: 'Done',
|
|
8469
|
+
report_blocked: 'Blocked',
|
|
8470
|
+
report_question: 'Question',
|
|
8471
|
+
askedByYou: 'asked by you',
|
|
8472
|
+
askedBy: 'asked by {name}',
|
|
8473
|
+
viaPanel: 'Panel',
|
|
8474
|
+
kind_report: 'Report',
|
|
8475
|
+
allTasks: 'All tasks',
|
|
8476
|
+
taskMissing: 'This task is not available. It may have been archived.',
|
|
8477
|
+
taskStarted: 'started {when}',
|
|
8478
|
+
taskNoConversation: 'It has not started yet.',
|
|
8479
|
+
taskRetry: 'Retry',
|
|
8480
|
+
taskClose: 'Mark done',
|
|
8481
|
+
taskStop: 'Stop',
|
|
8482
|
+
taskDid_stop: 'Task stopped.',
|
|
8483
|
+
taskDid_retry: 'Task started again.',
|
|
8484
|
+
taskDid_close: 'Task marked done.',
|
|
8485
|
+
taskStopTitle: 'Stop “{title}”?',
|
|
8486
|
+
taskStopBody: '{name} stops working on it now. You can retry it later.',
|
|
8487
|
+
taskCloseTitle: 'Mark “{title}” done?',
|
|
8488
|
+
taskCloseBody: '{name} stops working on it, and the task counts as done.',
|
|
8489
|
+
taskFactBot: 'Bot',
|
|
8490
|
+
taskFactAsked: 'Asked by',
|
|
8491
|
+
taskFactFrom: 'From',
|
|
8492
|
+
fromPanel: 'The Bots panel',
|
|
8493
|
+
taskFactUpdated: 'Last update',
|
|
8494
|
+
taskAsked: 'What was asked',
|
|
8495
|
+
taskReports: 'Reports',
|
|
8496
|
+
taskNoReports: 'No report yet. {name} reports when it is done, stuck, or has a question.',
|
|
8497
|
+
taskRelated: 'Related tasks',
|
|
8498
|
+
taskParent: 'Part of',
|
|
8499
|
+
taskChildren: 'Sub-tasks ({n})',
|
|
8500
|
+
taskUsage: 'Usage',
|
|
8501
|
+
taskNoUsage: 'No model calls yet.',
|
|
8502
|
+
taskArchived: 'This task is archived. A new message in its chat goes to the dispatcher.',
|
|
8503
|
+
taskMessageLabel: 'Message to this task',
|
|
8504
|
+
taskMessagePlaceholder: 'Add to this task…',
|
|
8505
|
+
taskAnswerPlaceholder: 'Answer {name}…',
|
|
8506
|
+
taskMessageHint: '{name} reads it in the task’s own conversation · Enter to send',
|
|
8507
|
+
taskMessageSent: 'Sent to {name}.',
|
|
8508
|
+
taskBadgeTitle: 'A task of {name}: {title} — open it in Bots',
|
|
8509
|
+
tab_tasks: 'Tasks',
|
|
8510
|
+
botOpenTasks: 'Open tasks',
|
|
8511
|
+
botOpenTasksHint: 'What {name} is working on, each in its own conversation.',
|
|
8512
|
+
allTasksOf: 'All tasks',
|
|
8513
|
+
botNoOpenTasks: '{name} has no open tasks.',
|
|
8514
|
+
toolReport: 'Report',
|
|
8515
|
+
requesterShort: 'whoever asked',
|
|
8516
|
+
// the dispatcher's mode
|
|
8517
|
+
dispatcherMode: 'How it works',
|
|
8518
|
+
dispatcherModeHint: 'For the whole team. Each piece of work the dispatcher hands out becomes a task with its own conversation.',
|
|
8519
|
+
modeRouter: 'Router',
|
|
8520
|
+
modeRouterBody: 'Understands, hands out, reports. Teammates do the work.',
|
|
8521
|
+
modeHandsOn: 'Hands-on',
|
|
8522
|
+
modeHandsOnBody: 'Also does small things itself, as before.',
|
|
8523
|
+
modeSavedRouter: '{name} now only hands out the work.',
|
|
8524
|
+
modeSavedHandsOn: '{name} does small things itself again.',
|
|
8525
|
+
routerModelHint: 'In Router mode it only understands, hands out and reports, so a light, fast model is enough, and every request stays quick and cheap.',
|
|
8526
|
+
routerWaiting: 'Router mode starts once the team has another bot; until then {name} does the work itself.',
|
|
8527
|
+
abilitiesRouterHint: 'What {name} can do with the Harness’s built-in tools. In Router mode it does not run commands, write files, use sub-agents, draw or make Office files; turn one back on below if it needs it.',
|
|
8528
|
+
routerOff: 'Off in Router mode',
|
|
8529
|
+
routerPartOff: 'Partly off in Router mode',
|
|
8530
|
+
routerAllowed: 'On in Router mode',
|
|
8531
|
+
routerAllowBack: 'Turn back on',
|
|
8532
|
+
routerOffShort: 'off in Router mode',
|
|
8533
|
+
routerNoticeTitle: 'Your dispatcher now hands out the work',
|
|
8534
|
+
routerNoticeBody: 'It listens, hands each request to a teammate as a task and reports back; every task runs in its own conversation, so several can move at once. To let it do small jobs itself again, open its profile and set How it works to Hands-on.',
|
|
8535
|
+
routerNoticeOpen: 'Open its profile',
|
|
8536
|
+
routerNoticeOk: 'Got it',
|
|
8537
|
+
setTasks: 'Tasks',
|
|
8538
|
+
setChat: 'Chat',
|
|
8539
|
+
setBotMessages: 'Messages between bots',
|
|
8540
|
+
setBotMessagesHint_line: 'One line each: who hands what to whom, its stage and time. A click opens the task.',
|
|
8541
|
+
setBotMessagesHint_short: 'The one line and the first two lines of the message.',
|
|
8542
|
+
setBotMessagesHint_full: 'The whole message, with the task card of a delegation.',
|
|
8543
|
+
botMessages_line: 'One line',
|
|
8544
|
+
botMessages_short: 'Short',
|
|
8545
|
+
botMessages_full: 'Full',
|
|
8546
|
+
setMaxWorking: 'Tasks worked on at once',
|
|
8547
|
+
setMaxWorkingHint: 'More wait in line. A follow-up from you can use one extra.',
|
|
8548
|
+
setStall: 'Minutes before a quiet task counts as stuck',
|
|
8549
|
+
setStallHint: 'A working task quiet this long is asked for a report; still quiet after that, it is marked stuck.',
|
|
8550
|
+
setArchive: 'Hours before a finished task’s conversation is archived',
|
|
8551
|
+
usageAllTasks: 'Show all {n} tasks',
|
|
8552
|
+
setArchiveHint: 'Until then, a new message in its chat thread picks the task up again.',
|
|
6381
8553
|
// Usage, memory, topics, settings, model sources
|
|
6382
8554
|
settings: 'Settings',
|
|
6383
8555
|
usage: 'Usage',
|
|
@@ -6396,7 +8568,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6396
8568
|
tileCacheRate: '{pct}% of input from cache',
|
|
6397
8569
|
tileCost: 'Estimated cost',
|
|
6398
8570
|
tileUnpriced: '{tokens} tokens have no price',
|
|
6399
|
-
|
|
8571
|
+
tileRuns: 'Runs',
|
|
6400
8572
|
tileCalls: 'Model calls',
|
|
6401
8573
|
tileInOut: '{input} in · {output} out',
|
|
6402
8574
|
vsPrev: '{delta} vs the period before',
|
|
@@ -6405,10 +8577,12 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6405
8577
|
byModel: 'By model',
|
|
6406
8578
|
byKind: 'By kind of work',
|
|
6407
8579
|
bySchedule: 'Scheduled tasks',
|
|
6408
|
-
|
|
8580
|
+
recentRuns: 'Recent runs',
|
|
8581
|
+
byTask: 'By task',
|
|
6409
8582
|
colBot: 'Bot',
|
|
6410
8583
|
colTask: 'Task',
|
|
6411
|
-
|
|
8584
|
+
colRunCount: 'Runs',
|
|
8585
|
+
colRun: 'Run',
|
|
6412
8586
|
colTokens: 'Tokens',
|
|
6413
8587
|
colCost: 'Cost',
|
|
6414
8588
|
colCalls: 'Calls',
|
|
@@ -6464,8 +8638,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6464
8638
|
noJournal: 'No finished tasks yet.',
|
|
6465
8639
|
topicsTitle: 'Topics',
|
|
6466
8640
|
topicsHint: 'Each topic is a fresh conversation, so the context never grows without end. A new one starts when you send /new, after a long quiet, or once the conversation grows large (see Settings). Memory carries over.',
|
|
6467
|
-
topicNow: 'Current topic: started {when} ·
|
|
6468
|
-
topicShort: 'This topic: {ctx} context ·
|
|
8641
|
+
topicNow: 'Current topic: started {when} · runs: {n} · last prompt {ctx} tokens',
|
|
8642
|
+
topicShort: 'This topic: {ctx} context · runs: {n}',
|
|
6469
8643
|
newTopic: 'New topic',
|
|
6470
8644
|
newTopicHint: 'Start a fresh conversation; memory carries over. You can also send /new.',
|
|
6471
8645
|
newTopicDone: '{name} starts a new topic',
|
|
@@ -6473,7 +8647,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6473
8647
|
topicReason_manual: 'started by you',
|
|
6474
8648
|
topicReason_idle: 'after a quiet spell',
|
|
6475
8649
|
topicReason_context: 'the conversation grew large',
|
|
6476
|
-
pastTopic: '{from} – {to} ·
|
|
8650
|
+
pastTopic: '{from} – {to} · runs: {n}',
|
|
6477
8651
|
kind_topic: 'New topic',
|
|
6478
8652
|
teamMemoryTitle: 'Team memory',
|
|
6479
8653
|
teamMemoryHint: '{n} shared notes · daily digest',
|
|
@@ -6595,8 +8769,72 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6595
8769
|
chatEmptyTitle: '和 {name} 打个招呼',
|
|
6596
8770
|
chatEmptyBody: '你发的消息会进入这个 Bot 自己的会话,它会用自己的人设、技能和应用来处理。',
|
|
6597
8771
|
working: '{name} 正在工作…',
|
|
8772
|
+
workingPlain: '工作中…',
|
|
8773
|
+
liveTotal: '第 {n} 步 · 已用 {time}',
|
|
8774
|
+
elapsedS: '{s} 秒',
|
|
8775
|
+
elapsedM: '{m} 分 {s} 秒',
|
|
8776
|
+
elapsedH: '{h} 小时 {m} 分',
|
|
8777
|
+
avatarDrawing: '正在画新头像…',
|
|
8778
|
+
act_thinking: '思考中',
|
|
8779
|
+
act_writing: '正在写回复',
|
|
8780
|
+
act_run: '运行 {detail}',
|
|
8781
|
+
act_run_bare: '运行命令',
|
|
8782
|
+
act_read: '读取 {detail}',
|
|
8783
|
+
act_read_bare: '读取文件',
|
|
8784
|
+
act_edit: '修改 {detail}',
|
|
8785
|
+
act_edit_bare: '修改文件',
|
|
8786
|
+
act_write: '写入 {detail}',
|
|
8787
|
+
act_write_bare: '写文件',
|
|
8788
|
+
act_find: '查找 {detail}',
|
|
8789
|
+
act_find_bare: '查找文件',
|
|
8790
|
+
act_search: '搜索“{detail}”',
|
|
8791
|
+
act_search_bare: '联网搜索',
|
|
8792
|
+
act_fetch: '阅读 {detail}',
|
|
8793
|
+
act_fetch_bare: '阅读网页',
|
|
8794
|
+
act_delegate: '把工作交给 {detail}',
|
|
8795
|
+
act_followup: '给任务 {detail} 发消息',
|
|
8796
|
+
act_report: '汇报进展',
|
|
8797
|
+
act_ask: '在问你',
|
|
8798
|
+
act_draw: '画图中',
|
|
8799
|
+
act_helper: '助手:{detail}',
|
|
8800
|
+
act_helper_bare: '让助手帮忙',
|
|
8801
|
+
act_skill: '使用技能 {detail}',
|
|
8802
|
+
act_skill_bare: '加载技能',
|
|
8803
|
+
act_memory: '搜索记忆“{detail}”',
|
|
8804
|
+
act_memory_bare: '搜索记忆',
|
|
8805
|
+
act_remember: '更新记忆',
|
|
8806
|
+
act_reply: '回复聊天',
|
|
8807
|
+
act_recall: '查阅 {detail}',
|
|
8808
|
+
act_recall_bare: '查阅记录',
|
|
8809
|
+
act_team: '调整团队',
|
|
8810
|
+
act_schedule: '安排定时任务',
|
|
8811
|
+
act_plan: '更新计划',
|
|
8812
|
+
act_job: '查看后台任务',
|
|
8813
|
+
act_office: '处理文档',
|
|
8814
|
+
act_tool: '使用 {detail}',
|
|
6598
8815
|
composer: '给 @{handle} 发消息',
|
|
6599
8816
|
composerHint: 'Enter 发送 · Shift+Enter 换行',
|
|
8817
|
+
replyAction: '回复',
|
|
8818
|
+
replyingTo: '回复 {name}',
|
|
8819
|
+
cancelReply: '取消回复',
|
|
8820
|
+
topicLabel: '话题',
|
|
8821
|
+
topicTitle: '话题',
|
|
8822
|
+
topicReplyOne: '1 条回复',
|
|
8823
|
+
topicReplies: '{n} 条回复',
|
|
8824
|
+
topicEmpty: '还没有回复。',
|
|
8825
|
+
topicComposer: '在话题里回复',
|
|
8826
|
+
topicUnread: '有新回复',
|
|
8827
|
+
openTopic: '打开话题',
|
|
8828
|
+
closeTopic: '关闭话题',
|
|
8829
|
+
movedTo: '已归入「{title}」',
|
|
8830
|
+
movedToTopic: '已归入另一个话题',
|
|
8831
|
+
movedIn: '归入此话题',
|
|
8832
|
+
newReplyOne: '1 个话题有新回复',
|
|
8833
|
+
newReplies: '{n} 个话题有新回复',
|
|
8834
|
+
msgPending: '排队中',
|
|
8835
|
+
msgPendingHint: '已送达,bot 做完手头这一步就会看到。',
|
|
8836
|
+
msgFailed: '发送失败',
|
|
8837
|
+
resend: '重发',
|
|
6600
8838
|
fullTranscript: '完整记录在它的会话里',
|
|
6601
8839
|
send: '发送',
|
|
6602
8840
|
sendFailed: '消息没有发出去。',
|
|
@@ -7070,6 +9308,135 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7070
9308
|
channelPrivate: '只有配对过的人能找到团队,其他人一律忽略(每天最多回一句“这是私人 Bot”)。在群里,只有 @ 它或回复它时才会回答。',
|
|
7071
9309
|
viaChannel: '{app} · {who}',
|
|
7072
9310
|
sentToChannel: '也已发到 {app}',
|
|
9311
|
+
threadPart: '话题',
|
|
9312
|
+
threadTopic: '话题',
|
|
9313
|
+
notSent: '未发出',
|
|
9314
|
+
notSentChats: '没有发到任何聊天:这一轮涉及多个聊天({chats})。',
|
|
9315
|
+
// tasks
|
|
9316
|
+
tasks: '任务',
|
|
9317
|
+
tasksHint: '交给 Bot 们的工作',
|
|
9318
|
+
tasksNeedYou: '{n} 个等你处理',
|
|
9319
|
+
askTitle: '{name} 在问你',
|
|
9320
|
+
askNativeTitle: '{name} 在对话里等你决定',
|
|
9321
|
+
askNativeHint: '这一项请在对话里回答。',
|
|
9322
|
+
askContinued: '{name} 先去做别的了,你的回答仍会送到。',
|
|
9323
|
+
askMulti: '可多选',
|
|
9324
|
+
askOtherPlaceholder: '或者输入你自己的回答',
|
|
9325
|
+
askFreePlaceholder: '输入你的回答',
|
|
9326
|
+
askSubmit: '提交',
|
|
9327
|
+
askFailed: '回答没有发出去。',
|
|
9328
|
+
askingBadge: '{n} 个问题等你回答',
|
|
9329
|
+
askingChip: '在问你',
|
|
9330
|
+
tasksInProgress: '{n} 个进行中',
|
|
9331
|
+
tasksSub: 'Bot 们接手的工作。每个任务在自己的会话里进行,几件事可以同时推进。',
|
|
9332
|
+
tasksNeeds: '需要你处理',
|
|
9333
|
+
tasksNeedsEmpty: '现在没有需要你处理的。',
|
|
9334
|
+
tasksProgress: '进行中',
|
|
9335
|
+
tasksProgressEmpty: '没有进行中的任务。',
|
|
9336
|
+
tasksDone: '最近完成',
|
|
9337
|
+
tasksDoneEmpty: '还没有完成的任务。',
|
|
9338
|
+
tasksUnavailable: '没能加载任务。',
|
|
9339
|
+
tasksEmptyTitle: '还没有任务',
|
|
9340
|
+
tasksEmptyBotTitle: '{name} 还没有任务',
|
|
9341
|
+
tasksEmptyBody: '调度者把工作交给队友时,这里会出现一个任务,你可以跟进、回答或叫停。',
|
|
9342
|
+
untitledTask: '未命名任务',
|
|
9343
|
+
openTask: '打开任务',
|
|
9344
|
+
followUpTask: '已交给所属任务',
|
|
9345
|
+
followUpHint: '在任务来源的聊天里跟进,消息会直接交给那个任务。',
|
|
9346
|
+
taskOf: '任务 · {name}',
|
|
9347
|
+
stage_question: '等你回答',
|
|
9348
|
+
stage_failed: '失败',
|
|
9349
|
+
stage_stalled: '卡住了',
|
|
9350
|
+
stage_queued: '排队中',
|
|
9351
|
+
stage_working: '进行中',
|
|
9352
|
+
stage_done: '已完成',
|
|
9353
|
+
stage_stopped: '已停止',
|
|
9354
|
+
report_progress: '进展',
|
|
9355
|
+
report_done: '完成',
|
|
9356
|
+
report_blocked: '受阻',
|
|
9357
|
+
report_question: '提问',
|
|
9358
|
+
askedByYou: '你发起',
|
|
9359
|
+
askedBy: '{name} 发起',
|
|
9360
|
+
viaPanel: '面板',
|
|
9361
|
+
kind_report: '汇报',
|
|
9362
|
+
allTasks: '全部任务',
|
|
9363
|
+
taskMissing: '这个任务不可用,可能已经归档。',
|
|
9364
|
+
taskStarted: '开始于{when}',
|
|
9365
|
+
taskNoConversation: '还没开始。',
|
|
9366
|
+
taskRetry: '重试',
|
|
9367
|
+
taskClose: '标为完成',
|
|
9368
|
+
taskStop: '停止',
|
|
9369
|
+
taskDid_stop: '任务已停止。',
|
|
9370
|
+
taskDid_retry: '任务已重新开始。',
|
|
9371
|
+
taskDid_close: '任务已标为完成。',
|
|
9372
|
+
taskStopTitle: '停止“{title}”?',
|
|
9373
|
+
taskStopBody: '{name} 会马上停下这件事,之后可以重试。',
|
|
9374
|
+
taskCloseTitle: '把“{title}”标为完成?',
|
|
9375
|
+
taskCloseBody: '{name} 会停下这件事,任务算作完成。',
|
|
9376
|
+
taskFactBot: '执行的 Bot',
|
|
9377
|
+
taskFactAsked: '发起方',
|
|
9378
|
+
taskFactFrom: '来源',
|
|
9379
|
+
fromPanel: 'Bots 面板',
|
|
9380
|
+
taskFactUpdated: '最近更新',
|
|
9381
|
+
taskAsked: '交代的内容',
|
|
9382
|
+
taskReports: '汇报',
|
|
9383
|
+
taskNoReports: '还没有汇报。{name} 完成、卡住或有问题时会汇报。',
|
|
9384
|
+
taskRelated: '相关任务',
|
|
9385
|
+
taskParent: '所属任务',
|
|
9386
|
+
taskChildren: '子任务({n})',
|
|
9387
|
+
taskUsage: '用量',
|
|
9388
|
+
taskNoUsage: '还没有模型调用。',
|
|
9389
|
+
taskArchived: '这个任务已归档。它所在聊天里的新消息会交给调度者。',
|
|
9390
|
+
taskMessageLabel: '给这个任务发消息',
|
|
9391
|
+
taskMessagePlaceholder: '补充点什么…',
|
|
9392
|
+
taskAnswerPlaceholder: '回答 {name}…',
|
|
9393
|
+
taskMessageHint: '{name} 会在这个任务自己的会话里看到 · Enter 发送',
|
|
9394
|
+
taskMessageSent: '已发给 {name}。',
|
|
9395
|
+
taskBadgeTitle: '{name} 的任务:{title}——在 Bots 中打开',
|
|
9396
|
+
tab_tasks: '任务',
|
|
9397
|
+
botOpenTasks: '进行中的任务',
|
|
9398
|
+
botOpenTasksHint: '{name} 手上的工作,每件在自己的会话里进行。',
|
|
9399
|
+
allTasksOf: '全部任务',
|
|
9400
|
+
botNoOpenTasks: '{name} 手上没有进行中的任务。',
|
|
9401
|
+
toolReport: '汇报',
|
|
9402
|
+
requesterShort: '发起方',
|
|
9403
|
+
// the dispatcher's mode
|
|
9404
|
+
dispatcherMode: '调度方式',
|
|
9405
|
+
dispatcherModeHint: '对整个团队生效。调度者分出去的每件工作都是一个任务,有自己的会话。',
|
|
9406
|
+
modeRouter: '只调度',
|
|
9407
|
+
modeRouterBody: '听懂、分派、汇报,具体工作交给队友。',
|
|
9408
|
+
modeHandsOn: '亲自动手',
|
|
9409
|
+
modeHandsOnBody: '小事自己顺手做掉,和以前一样。',
|
|
9410
|
+
modeSavedRouter: '{name} 现在只负责分派。',
|
|
9411
|
+
modeSavedHandsOn: '{name} 又会自己做小事了。',
|
|
9412
|
+
routerModelHint: '只调度时它只负责听懂、分派、汇报,用轻量、快速的模型就够了,每次请求都更快、更省。',
|
|
9413
|
+
routerWaiting: '团队里再有一个 Bot 后才开始只调度,在此之前 {name} 自己动手。',
|
|
9414
|
+
abilitiesRouterHint: '{name} 能用 Harness 内置工具做哪些事。只调度时它不执行命令、不写文件、不用子代理、不作图也不做 Office 文档;确实需要时可以在下面逐项打开。',
|
|
9415
|
+
routerOff: '只调度时关闭',
|
|
9416
|
+
routerPartOff: '只调度时部分关闭',
|
|
9417
|
+
routerAllowed: '只调度时也可用',
|
|
9418
|
+
routerAllowBack: '重新打开',
|
|
9419
|
+
routerOffShort: '只调度时关闭',
|
|
9420
|
+
routerNoticeTitle: '调度者现在只负责分派',
|
|
9421
|
+
routerNoticeBody: '它会听懂请求、把每件事作为任务交给队友并汇报结果;每个任务在自己的会话里进行,几件事可以同时推进。想让它像以前一样顺手做小事,打开它的资料页,把「调度方式」改成「亲自动手」。',
|
|
9422
|
+
routerNoticeOpen: '打开它的资料页',
|
|
9423
|
+
routerNoticeOk: '知道了',
|
|
9424
|
+
setTasks: '任务',
|
|
9425
|
+
setChat: '聊天',
|
|
9426
|
+
setBotMessages: 'Bot 之间的消息',
|
|
9427
|
+
setBotMessagesHint_line: '每条一行:谁把什么交给谁、进度和时间。点一下打开任务。',
|
|
9428
|
+
setBotMessagesHint_short: '一行摘要,再加消息的前两行。',
|
|
9429
|
+
setBotMessagesHint_full: '完整消息,委派附任务卡片。',
|
|
9430
|
+
botMessages_line: '一行',
|
|
9431
|
+
botMessages_short: '简短',
|
|
9432
|
+
botMessages_full: '完整',
|
|
9433
|
+
setMaxWorking: '同时进行的任务数',
|
|
9434
|
+
setMaxWorkingHint: '多出来的排队等候。你的跟进消息可以多占一个名额。',
|
|
9435
|
+
setStall: '多少分钟没动静算卡住',
|
|
9436
|
+
setStallHint: '进行中的任务这么久没动静,先请它汇报;之后仍没动静就标为卡住。',
|
|
9437
|
+
setArchive: '任务完成多少小时后归档会话',
|
|
9438
|
+
usageAllTasks: '显示全部 {n} 个任务',
|
|
9439
|
+
setArchiveHint: '在此之前,它所在话题或回复串里的新消息会让这个任务继续。',
|
|
7073
9440
|
// 用量、记忆、话题、设置、模型来源
|
|
7074
9441
|
settings: '设置',
|
|
7075
9442
|
usage: '用量',
|
|
@@ -7088,7 +9455,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7088
9455
|
tileCacheRate: '{pct}% 的输入命中缓存',
|
|
7089
9456
|
tileCost: '估算费用',
|
|
7090
9457
|
tileUnpriced: '{tokens} tokens 没有价格',
|
|
7091
|
-
|
|
9458
|
+
tileRuns: '回合',
|
|
7092
9459
|
tileCalls: '模型调用',
|
|
7093
9460
|
tileInOut: '输入 {input} · 输出 {output}',
|
|
7094
9461
|
vsPrev: '比上一期 {delta}',
|
|
@@ -7097,10 +9464,12 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7097
9464
|
byModel: '按模型',
|
|
7098
9465
|
byKind: '按用途',
|
|
7099
9466
|
bySchedule: '定时任务',
|
|
7100
|
-
|
|
9467
|
+
recentRuns: '最近的回合',
|
|
9468
|
+
byTask: '按任务',
|
|
7101
9469
|
colBot: 'Bot',
|
|
7102
9470
|
colTask: '任务',
|
|
7103
|
-
|
|
9471
|
+
colRunCount: '回合',
|
|
9472
|
+
colRun: '回合',
|
|
7104
9473
|
colTokens: 'Tokens',
|
|
7105
9474
|
colCost: '费用',
|
|
7106
9475
|
colCalls: '调用',
|
|
@@ -7156,8 +9525,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7156
9525
|
noJournal: '还没有完成的任务。',
|
|
7157
9526
|
topicsTitle: '话题',
|
|
7158
9527
|
topicsHint: '每个话题是一段新对话,上下文不会无限变长。发送 /new、闲置较久,或对话变得很长时(见设置)会开始新话题;记忆会延续下去。',
|
|
7159
|
-
topicNow: '当前话题:开始于{when} · {n}
|
|
7160
|
-
topicShort: '本话题:上下文 {ctx} ·
|
|
9528
|
+
topicNow: '当前话题:开始于{when} · {n} 个回合 · 最近一次提示 {ctx} tokens',
|
|
9529
|
+
topicShort: '本话题:上下文 {ctx} · 已进行 {n} 个回合',
|
|
7161
9530
|
newTopic: '新话题',
|
|
7162
9531
|
newTopicHint: '开始一段新对话,记忆会保留。也可以直接发送 /new。',
|
|
7163
9532
|
newTopicDone: '{name} 开始了新话题',
|
|
@@ -7165,7 +9534,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7165
9534
|
topicReason_manual: '你开启的',
|
|
7166
9535
|
topicReason_idle: '闲置后自动开启',
|
|
7167
9536
|
topicReason_context: '对话太长自动开启',
|
|
7168
|
-
pastTopic: '{from} – {to} · {n}
|
|
9537
|
+
pastTopic: '{from} – {to} · {n} 个回合',
|
|
7169
9538
|
kind_topic: '新话题',
|
|
7170
9539
|
teamMemoryTitle: '团队记忆',
|
|
7171
9540
|
teamMemoryHint: '{n} 条共享笔记 · 每日摘要',
|
|
@@ -7319,6 +9688,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7319
9688
|
navigate(botId);
|
|
7320
9689
|
return openPanel();
|
|
7321
9690
|
},
|
|
9691
|
+
/** Show a Harness conversation (a task's own one); false when it cannot. */
|
|
9692
|
+
openSession: (id) => openSession(id),
|
|
9693
|
+
/** One task's detail in the panel. */
|
|
9694
|
+
showTicket: (id) => {
|
|
9695
|
+
openTicket(id);
|
|
9696
|
+
return openPanel();
|
|
9697
|
+
},
|
|
7322
9698
|
openPanel,
|
|
7323
9699
|
sessionTitle: (id) => {
|
|
7324
9700
|
try {
|