@kadaliao/dsh-bots 0.7.1 → 0.8.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 +213 -45
- package/README.zh-CN.md +151 -31
- package/client.js +1857 -116
- package/index.js +2154 -110
- package/lib/activity.mjs +221 -0
- package/lib/cards.mjs +539 -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 +364 -89
- package/lib/memory.mjs +37 -0
- package/lib/prompt.mjs +196 -20
- package/lib/settings.mjs +41 -2
- package/lib/store.mjs +5 -1
- package/lib/threads.mjs +407 -0
- package/lib/tickets.mjs +722 -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,45 @@ 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
|
+
@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
793
|
@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
794
|
@keyframes dshb-in{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
|
|
622
795
|
@keyframes dshb-blink{0%,100%{opacity:.25}50%{opacity:1}}
|
|
@@ -700,7 +873,11 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
700
873
|
);
|
|
701
874
|
|
|
702
875
|
/** A circle: initials on a colour, or the uploaded / generated picture. */
|
|
703
|
-
|
|
876
|
+
/**
|
|
877
|
+
* A circle: initials on a colour, or the uploaded / generated picture. `pending`: a new picture is
|
|
878
|
+
* being drawn (a turning arc); `working`: it works right now (a soft pulse).
|
|
879
|
+
*/
|
|
880
|
+
function Avatar({ avatar, name, size = 32, status, title, ring, pending, working }) {
|
|
704
881
|
const a = avatar && typeof avatar === 'object' ? avatar : { kind: 'initials', color: COLORS[0] };
|
|
705
882
|
const color = str(a.color) || COLORS[0];
|
|
706
883
|
const letters = avatarLetters(a, name);
|
|
@@ -748,6 +925,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
748
925
|
},
|
|
749
926
|
},
|
|
750
927
|
face,
|
|
928
|
+
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
929
|
status ? h(StatusDot, { status, size: dot, style: { position: 'absolute', right: -1, bottom: -1, boxShadow: `0 0 0 2px ${C.base}` } }) : null,
|
|
752
930
|
);
|
|
753
931
|
}
|
|
@@ -970,7 +1148,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
970
1148
|
return groups.sort((a, b) => (a.id === '' ? 1 : b.id === '' ? -1 : 0)).map((g) => ({ ...g, label: label(g.id) }));
|
|
971
1149
|
}
|
|
972
1150
|
|
|
973
|
-
|
|
1151
|
+
/** A red count of what needs you (tasks, or a bot's questions). */
|
|
1152
|
+
const NeedsBadge = ({ n, label, attr }) =>
|
|
1153
|
+
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));
|
|
1154
|
+
function Rail({ t, bots, primaryId, selected, onSelect, onNew, onTeams, view, onActivity, messageCount, onUsage, onMemory, onSettings, teamNotes, onTasks, attention = 0, openTasks = 0 }) {
|
|
974
1155
|
const lang = langOf(t);
|
|
975
1156
|
const [q, setQ] = useState('');
|
|
976
1157
|
const [menu, setMenu] = useState(false);
|
|
@@ -979,11 +1160,15 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
979
1160
|
.filter((b) => !needle || [b.name, b.handle, b.bio].some((s) => str(s).toLowerCase().includes(needle)))
|
|
980
1161
|
.sort((a, b) => (a.id === primaryId ? -1 : b.id === primaryId ? 1 : 0));
|
|
981
1162
|
const groups = needle ? null : groupByTeam(t, lang, shown);
|
|
982
|
-
const row = (b) =>
|
|
983
|
-
|
|
1163
|
+
const row = (b) => {
|
|
1164
|
+
// At work: its own conversation, else the freshest of its tasks; the line under its name says what it does.
|
|
1165
|
+
const live = liveBot(b);
|
|
1166
|
+
const work = live.activity ? live.activity : botTaskActivity(b.id);
|
|
1167
|
+
const status = live.status === 'running' || work ? 'running' : (live.status ?? 'offline');
|
|
1168
|
+
return h(
|
|
984
1169
|
'button',
|
|
985
1170
|
{ 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:
|
|
1171
|
+
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
1172
|
h(
|
|
988
1173
|
'span',
|
|
989
1174
|
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0, flex: 1 } },
|
|
@@ -994,9 +1179,19 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
994
1179
|
b.id === primaryId ? h('span', { title: t('dispatcher'), style: { color: '#f5b301', display: 'inline-flex' } }, Icon.crown(12)) : null,
|
|
995
1180
|
h('span', { style: { color: C.faint, fontSize: TINY, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, `@${b.handle}`),
|
|
996
1181
|
),
|
|
997
|
-
|
|
1182
|
+
work
|
|
1183
|
+
? h(
|
|
1184
|
+
'span',
|
|
1185
|
+
{ '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' } },
|
|
1186
|
+
work.ticket ? h('span', { style: { color: C.faint, display: 'inline-flex', flex: 'none' } }, Icon.tasks(11)) : null,
|
|
1187
|
+
h(LiveLine, { t, a: work, attr: b.id }),
|
|
1188
|
+
)
|
|
1189
|
+
: h('span', { style: { fontSize: TINY, color: C.muted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', marginTop: 1 } }, b.bio || t('noBio')),
|
|
998
1190
|
),
|
|
1191
|
+
// Questions its own conversation waits to have answered (a task's show on Tasks).
|
|
1192
|
+
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
1193
|
);
|
|
1194
|
+
};
|
|
1000
1195
|
return h(
|
|
1001
1196
|
'aside',
|
|
1002
1197
|
{ '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 +1240,20 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1045
1240
|
h(
|
|
1046
1241
|
'div',
|
|
1047
1242
|
{ style: { padding: 8, borderTop: `1px solid ${C.border1}` } },
|
|
1243
|
+
onTasks
|
|
1244
|
+
? h(
|
|
1245
|
+
'button',
|
|
1246
|
+
{ type: 'button', className: 'dshb-row', 'data-active': view === 'tasks', 'data-dsh-bots-tasks-entry': true, onClick: onTasks },
|
|
1247
|
+
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)),
|
|
1248
|
+
h(
|
|
1249
|
+
'span',
|
|
1250
|
+
{ style: { display: 'flex', flexDirection: 'column', flex: 1, minWidth: 0 } },
|
|
1251
|
+
h('span', { style: { fontWeight: 600 } }, t('tasks')),
|
|
1252
|
+
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')),
|
|
1253
|
+
),
|
|
1254
|
+
attention > 0 ? h(NeedsBadge, { n: attention, label: t('tasksNeedYou', { n: attention }), attr: 'data-dsh-bots-tasks-badge' }) : null,
|
|
1255
|
+
)
|
|
1256
|
+
: null,
|
|
1048
1257
|
h(
|
|
1049
1258
|
'button',
|
|
1050
1259
|
{ type: 'button', className: 'dshb-row', 'data-active': view === 'activity', 'data-dsh-bots-activity': true, onClick: onActivity },
|
|
@@ -1079,6 +1288,23 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1079
1288
|
|
|
1080
1289
|
// --- the panel: messages ---------------------------------------------------------------
|
|
1081
1290
|
|
|
1291
|
+
/** A chat thread's key (`kind:app:chat[:root]`, lib/threads.mjs), not the panel's own. */
|
|
1292
|
+
const isChatThread = (key) => typeof key === 'string' && /^[a-z][a-z0-9-]*:/.test(key) && !key.startsWith('panel:') && key.split(':').length >= 3;
|
|
1293
|
+
/** Who wrote in each chat thread of a timeline, so a thread reads by a name rather than its chat id. */
|
|
1294
|
+
function threadNamesOf(items) {
|
|
1295
|
+
const names = new Map();
|
|
1296
|
+
for (const m of items ?? []) if (isChatThread(m?.thread) && str(m.who).trim()) names.set(m.thread, str(m.who).trim());
|
|
1297
|
+
return names;
|
|
1298
|
+
}
|
|
1299
|
+
/** A chat thread as people read it (the Host's `threadLabel`): `Telegram · Kada`, `Slack · C042 · thread`. */
|
|
1300
|
+
function threadName(t, key, names) {
|
|
1301
|
+
const [kind, , chat, root] = str(key).split(':');
|
|
1302
|
+
const unescape = (s) => str(s).replace(/%(25|3A)/gi, (_, c) => (c === '25' ? '%' : ':'));
|
|
1303
|
+
const parts = [channelName(kind, t), names?.get(key) || unescape(chat)];
|
|
1304
|
+
if (root) parts.push(kind === 'telegram' ? t('threadTopic') : t('threadPart'));
|
|
1305
|
+
return parts.join(' · ');
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1082
1308
|
/** Who a message end is: a bot face, the user, or the scheduler. */
|
|
1083
1309
|
function party(t, id) {
|
|
1084
1310
|
if (id === 'user') return { kind: 'user', name: t('you') };
|
|
@@ -1097,6 +1323,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1097
1323
|
function MessageList({ t, items, botId, empty }) {
|
|
1098
1324
|
const count = items.length;
|
|
1099
1325
|
if (count === 0) return empty;
|
|
1326
|
+
const names = threadNamesOf(items);
|
|
1100
1327
|
const rows = [];
|
|
1101
1328
|
let lastDay = '';
|
|
1102
1329
|
items.forEach((m, i) => {
|
|
@@ -1125,14 +1352,151 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1125
1352
|
),
|
|
1126
1353
|
);
|
|
1127
1354
|
}
|
|
1355
|
+
// What bots say to each other runs together in one compact group, under the main thread.
|
|
1356
|
+
if (isTraffic(m)) {
|
|
1357
|
+
const last = rows[rows.length - 1];
|
|
1358
|
+
if (last && last.traffic) last.items.push(m);
|
|
1359
|
+
else rows.push({ traffic: true, key: `g${m.id ?? i}`, items: [m] });
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1128
1362
|
const prev = items[i - 1];
|
|
1129
|
-
|
|
1130
|
-
|
|
1363
|
+
// Answers to two chats of one turn keep their own headers (where each went), and so do two tasks.
|
|
1364
|
+
const grouped = 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;
|
|
1365
|
+
rows.push(h(MessageRow, { key: m.id ?? i, t, m, botId, grouped, names }));
|
|
1131
1366
|
});
|
|
1132
|
-
|
|
1367
|
+
const level = botMessagesLevel();
|
|
1368
|
+
return h(
|
|
1369
|
+
'div',
|
|
1370
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4, padding: '8px 0', maxWidth: 880, margin: '0 auto' } },
|
|
1371
|
+
rows.map((r) => (r && r.traffic ? h(BotTraffic, { key: r.key, t, items: r.items, level }) : r)),
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
/** A message between two bots (a delegation, a report, a DM), or a scheduled prompt: secondary traffic. */
|
|
1375
|
+
const isTraffic = (m) => m?.kind === 'system' || ((m?.kind === 'dm' || m?.kind === 'report') && m.from !== 'user' && m.to !== 'user');
|
|
1376
|
+
/** How much of what bots say to each other a chat shows (a team setting): 'line' | 'short' | 'full'. */
|
|
1377
|
+
function botMessagesLevel() {
|
|
1378
|
+
const v = store.state?.display?.botMessages ?? store.settings?.settings?.display?.botMessages;
|
|
1379
|
+
return v === 'short' || v === 'full' ? v : 'line';
|
|
1380
|
+
}
|
|
1381
|
+
/** The first sentence of a message (or its first line), for a one-line row. */
|
|
1382
|
+
function firstSentence(text) {
|
|
1383
|
+
const line = (str(text).split('\n').find((l) => l.trim() !== '') ?? '').trim();
|
|
1384
|
+
const m = /^(.{12,}?[.!?。!?])(\s|$)/u.exec(line);
|
|
1385
|
+
const s = (m ? m[1] : line).trim();
|
|
1386
|
+
// A very long one is cut, and says so (the short view goes on from there).
|
|
1387
|
+
return [...s].length > 160 ? `${[...s].slice(0, 159).join('').trimEnd()}…` : s;
|
|
1388
|
+
}
|
|
1389
|
+
/** Consecutive messages between bots, as one quiet group at the chosen level of detail. */
|
|
1390
|
+
function BotTraffic({ t, items, level }) {
|
|
1391
|
+
let lastTime = '';
|
|
1392
|
+
return h(
|
|
1393
|
+
'div',
|
|
1394
|
+
{ className: 'dshb-traffic', 'data-dsh-bots-traffic': items.length, 'data-level': level },
|
|
1395
|
+
items.map((m, i) => {
|
|
1396
|
+
const at = toMs(m.at);
|
|
1397
|
+
const time = Number.isFinite(at) ? fmtClock(at) : '';
|
|
1398
|
+
// A time shows once for a run of messages in the same minute.
|
|
1399
|
+
const showTime = time !== lastTime;
|
|
1400
|
+
lastTime = time;
|
|
1401
|
+
return h(TrafficItem, { key: m.id ?? i, t, m, level, time: showTime ? time : '' });
|
|
1402
|
+
}),
|
|
1403
|
+
);
|
|
1133
1404
|
}
|
|
1134
1405
|
|
|
1135
|
-
|
|
1406
|
+
/**
|
|
1407
|
+
* One message between bots. `line`: who to whom, the task's title (or the first sentence), its stage
|
|
1408
|
+
* (alive while it works) and the time; a click opens the task, or unfolds a message without one.
|
|
1409
|
+
* `short`: that and two lines of the text. `full`: the whole text, and a delegation's task card.
|
|
1410
|
+
*/
|
|
1411
|
+
function TrafficItem({ t, m, level, time }) {
|
|
1412
|
+
const [open, setOpen] = useState(false);
|
|
1413
|
+
const from = party(t, m.from);
|
|
1414
|
+
const to = party(t, m.to);
|
|
1415
|
+
const ticketId = messageTicket(m);
|
|
1416
|
+
const report = messageReport(m);
|
|
1417
|
+
const notice = messageNotice(m);
|
|
1418
|
+
const delegation = Boolean(ticketId) && !report && !notice;
|
|
1419
|
+
usePoll(() => (delegation ? loadTicket(ticketId) : undefined), 10_000, [ticketId, delegation]);
|
|
1420
|
+
const view = delegation ? store.tickets.get(ticketId)?.view ?? null : null;
|
|
1421
|
+
const live = delegation ? liveTask(ticketId) : null;
|
|
1422
|
+
const stage = str(view?.stage) || (live ? 'working' : '');
|
|
1423
|
+
const subject = delegation ? str(view?.title).trim() || firstLine(m.text) : firstSentence(m.text);
|
|
1424
|
+
const full = level === 'full' || open;
|
|
1425
|
+
const chip = notice
|
|
1426
|
+
? h(StageChip, { t, stage: notice })
|
|
1427
|
+
: report
|
|
1428
|
+
? h(ReportChip, { t, status: report })
|
|
1429
|
+
: m.kind === 'system'
|
|
1430
|
+
? h(Badge, { color: C.warn }, t('scheduled'))
|
|
1431
|
+
: delegation
|
|
1432
|
+
? live && (!stage || stage === 'working')
|
|
1433
|
+
? h(LiveChip, { t, a: live })
|
|
1434
|
+
: view?.asking
|
|
1435
|
+
? h(TaskChip, { t, row: view })
|
|
1436
|
+
: h(StageChip, { t, stage })
|
|
1437
|
+
: null;
|
|
1438
|
+
const who = [
|
|
1439
|
+
h(PartyAvatar, { key: 'fa', p: from, size: 16 }),
|
|
1440
|
+
h('span', { key: 'fn', className: 'dshb-tname' }, from.name),
|
|
1441
|
+
h('span', { key: 'ar', style: { color: C.faint, display: 'inline-flex', flex: 'none' } }, Icon.arrow(10)),
|
|
1442
|
+
h(PartyAvatar, { key: 'ta', p: to, size: 16 }),
|
|
1443
|
+
h('span', { key: 'tn', className: 'dshb-tname' }, to.name),
|
|
1444
|
+
];
|
|
1445
|
+
const timeEl = h('span', { className: 'dshb-ttime' }, time);
|
|
1446
|
+
if (full) {
|
|
1447
|
+
// The whole message: a header (who, its stage, a link to its task), the task card, the text.
|
|
1448
|
+
return h(
|
|
1449
|
+
'div',
|
|
1450
|
+
{ className: 'dshb-titem dshb-fade', 'data-dsh-bots-msg': m.kind, 'data-level': 'full' },
|
|
1451
|
+
h(
|
|
1452
|
+
'div',
|
|
1453
|
+
{ className: 'dshb-tline', style: { cursor: 'default' } },
|
|
1454
|
+
who,
|
|
1455
|
+
h('span', { style: { flex: 1 } }),
|
|
1456
|
+
delegation ? (live ? h(LiveChip, { t, a: live }) : null) : chip,
|
|
1457
|
+
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,
|
|
1458
|
+
open && level !== 'full' ? h('button', { type: 'button', className: 'dshb-link', onClick: () => setOpen(false), style: { fontSize: TINY, flex: 'none' } }, t('showLess')) : null,
|
|
1459
|
+
timeEl,
|
|
1460
|
+
),
|
|
1461
|
+
h(
|
|
1462
|
+
'div',
|
|
1463
|
+
{ className: 'dshb-tbody' },
|
|
1464
|
+
delegation ? h(TaskCard, { t, id: ticketId, botId: m.to, title: firstLine(m.text) }) : null,
|
|
1465
|
+
h(Clamp, { t, text: m.text, lines: 6, style: { fontSize: SMALL } }),
|
|
1466
|
+
h(LinkCards, { t, text: m.text }),
|
|
1467
|
+
),
|
|
1468
|
+
);
|
|
1469
|
+
}
|
|
1470
|
+
// Short: the text's first two lines under the row, which then names only a task title the text does not start with.
|
|
1471
|
+
const short = level === 'short' && str(m.text).trim() !== '';
|
|
1472
|
+
const ownTitle = delegation && str(view?.title).trim() !== '' && !str(m.text).trim().startsWith(str(view.title).trim().replace(/…$/, '').trimEnd());
|
|
1473
|
+
const lineSubject = short && !ownTitle ? '' : subject;
|
|
1474
|
+
return h(
|
|
1475
|
+
'div',
|
|
1476
|
+
{ className: 'dshb-titem dshb-fade', 'data-dsh-bots-msg': m.kind, 'data-level': level },
|
|
1477
|
+
h(
|
|
1478
|
+
'button',
|
|
1479
|
+
{
|
|
1480
|
+
type: 'button',
|
|
1481
|
+
className: 'dshb-tline',
|
|
1482
|
+
title: ticketId ? `${t('openTask')}: ${subject}` : t('showMore'),
|
|
1483
|
+
...(delegation ? { 'data-dsh-bots-task-card': ticketId } : ticketId ? { 'data-dsh-bots-report-task': ticketId } : { 'data-dsh-bots-expand': m.id ?? true }),
|
|
1484
|
+
onClick: (e) => {
|
|
1485
|
+
e?.stopPropagation?.();
|
|
1486
|
+
if (ticketId) openTicket(ticketId);
|
|
1487
|
+
else setOpen(true);
|
|
1488
|
+
},
|
|
1489
|
+
},
|
|
1490
|
+
who,
|
|
1491
|
+
h('span', { className: 'dshb-tsubject', 'data-dsh-bots-subject': true }, lineSubject),
|
|
1492
|
+
chip,
|
|
1493
|
+
timeEl,
|
|
1494
|
+
),
|
|
1495
|
+
short ? h('div', { className: 'dshb-tbody dshb-clamp2', 'data-dsh-bots-short': true }, str(m.text).trim()) : null,
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
function MessageRow({ t, m, botId, grouped, names }) {
|
|
1136
1500
|
if (m.kind === 'topic') {
|
|
1137
1501
|
const at = toMs(m.at);
|
|
1138
1502
|
return h(
|
|
@@ -1149,29 +1513,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1149
1513
|
const time = Number.isFinite(at) ? fmtClock(at) : '';
|
|
1150
1514
|
const mine = m.from === 'user';
|
|
1151
1515
|
// 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
|
-
}
|
|
1516
|
+
const between = (m.kind === 'dm' || m.kind === 'report') && m.from !== 'user' && m.to !== 'user';
|
|
1517
|
+
// A delegation that opened a task shows the task; a worker's report shows its status, and a
|
|
1518
|
+
// notice that the task is stuck or failed its stage.
|
|
1519
|
+
const ticketId = messageTicket(m);
|
|
1520
|
+
const report = messageReport(m);
|
|
1521
|
+
const notice = messageNotice(m);
|
|
1522
|
+
if (between || m.kind === 'system') return h(BotTraffic, { t, items: [m], level: botMessagesLevel() });
|
|
1175
1523
|
if (mine) {
|
|
1176
1524
|
return h(
|
|
1177
1525
|
'div',
|
|
@@ -1183,18 +1531,25 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1183
1531
|
{ style: { fontSize: TINY, color: C.faint, display: 'inline-flex', alignItems: 'center', gap: 6 } },
|
|
1184
1532
|
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
1533
|
m.to !== botId && to.kind === 'bot' ? `${t('toName', { name: to.name })} · ${time}` : time,
|
|
1534
|
+
// A message from a chat that went straight to the task it follows up on.
|
|
1535
|
+
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
1536
|
),
|
|
1187
|
-
h('div', { style: { maxWidth: '78%', padding: '8px 12px', borderRadius: '14px 14px 4px 14px', background: C.label, color:
|
|
1537
|
+
h('div', { style: { maxWidth: '78%', padding: '8px 12px', borderRadius: '14px 14px 4px 14px', background: C.label, color: C.onLabel, fontSize: FONT } }, h(Clamp, { t, text: m.text, lines: 14, light: true })),
|
|
1188
1538
|
h('div', { style: { width: 'min(480px, 78%)', display: 'flex', justifyContent: 'flex-end' } }, h(LinkCards, { t, text: m.text, align: 'flex-end' })),
|
|
1189
1539
|
);
|
|
1190
1540
|
}
|
|
1541
|
+
// Where a reply went: its chat by name when the Host says which (`→ Telegram · Kada`), else the app.
|
|
1542
|
+
const place = m.via ? (isChatThread(m.thread) ? threadName(t, m.thread, names) : channelName(m.via, t)) : '';
|
|
1543
|
+
// With several chats in the turn, plain text reached none of them (bot_reply says where each answer goes).
|
|
1544
|
+
const choices = m.notSent === true && Array.isArray(m.choices) ? m.choices.filter(isChatThread) : [];
|
|
1545
|
+
// A bot speaking to you reads like the main conversation: no box, full-strength text.
|
|
1191
1546
|
return h(
|
|
1192
1547
|
'div',
|
|
1193
|
-
{ 'data-dsh-bots-msg': m.kind || 'reply', className: 'dshb-fade', style: { display: 'flex', gap: 10, alignItems: 'flex-start', marginTop: grouped ?
|
|
1548
|
+
{ 'data-dsh-bots-msg': m.kind || 'reply', className: 'dshb-fade', style: { display: 'flex', gap: 10, alignItems: 'flex-start', marginTop: grouped ? 4 : 12 } },
|
|
1194
1549
|
h('div', { style: { width: 30, flex: 'none' } }, grouped ? null : h(PartyAvatar, { p: from, size: 30 })),
|
|
1195
1550
|
h(
|
|
1196
1551
|
'div',
|
|
1197
|
-
{ style: { display: 'flex', flexDirection: 'column', gap:
|
|
1552
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0, flex: 1, maxWidth: 760 } },
|
|
1198
1553
|
grouped
|
|
1199
1554
|
? null
|
|
1200
1555
|
: h(
|
|
@@ -1204,16 +1559,27 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1204
1559
|
from.kind === 'bot' ? h('span', { style: { color: C.faint } }, `@${from.bot.handle}`) : null,
|
|
1205
1560
|
m.to !== 'user' && to.kind === 'bot' && m.to !== botId ? h('span', { style: { color: C.faint } }, `→ ${to.name}`) : null,
|
|
1206
1561
|
h('span', { style: { color: C.faint } }, time),
|
|
1207
|
-
m.via ? h(Badge, { color: CHANNEL_COLORS[m.via] ?? C.muted, title: t('sentToChannel', { app:
|
|
1562
|
+
m.via ? h(Badge, { color: CHANNEL_COLORS[m.via] ?? C.muted, title: t('sentToChannel', { app: place }), 'data-dsh-bots-via': m.via }, `→ ${place}`) : null,
|
|
1563
|
+
report ? h(ReportChip, { t, status: report }) : null,
|
|
1564
|
+
notice ? h(StageChip, { t, stage: notice }) : null,
|
|
1565
|
+
ticketId ? h('button', { type: 'button', className: 'dshb-link', 'data-dsh-bots-report-task': ticketId, onClick: () => openTicket(ticketId), style: { fontSize: TINY } }, t('openTask')) : null,
|
|
1208
1566
|
),
|
|
1209
|
-
h('div', {
|
|
1567
|
+
h('div', { className: 'dshb-reply', 'data-dsh-bots-reply-text': true }, h(Clamp, { t, text: m.text, lines: 24, variant: 'body' })),
|
|
1568
|
+
choices.length
|
|
1569
|
+
? h(
|
|
1570
|
+
'div',
|
|
1571
|
+
{ 'data-dsh-bots-not-sent': choices.length, style: { display: 'flex', alignItems: 'flex-start', gap: 5, fontSize: TINY, color: C.muted, lineHeight: 1.5 } },
|
|
1572
|
+
h('span', { style: { color: C.warn, display: 'inline-flex', paddingTop: 2 } }, Icon.alert(11)),
|
|
1573
|
+
t('notSentChats', { chats: choices.map((k) => threadName(t, k, names)).join(t('listSep')) }),
|
|
1574
|
+
)
|
|
1575
|
+
: null,
|
|
1210
1576
|
h(LinkCards, { t, text: m.text }),
|
|
1211
1577
|
),
|
|
1212
1578
|
);
|
|
1213
1579
|
}
|
|
1214
1580
|
|
|
1215
1581
|
/** 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 }) {
|
|
1582
|
+
function Clamp({ t, text, lines = 6, style, light, variant }) {
|
|
1217
1583
|
const [open, setOpen] = useState(false);
|
|
1218
1584
|
const s = str(text);
|
|
1219
1585
|
const long = s.length > lines * 90 || s.split('\n').length > lines;
|
|
@@ -1232,17 +1598,33 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1232
1598
|
...(folded ? { maxHeight: `${lines * 1.55}em`, overflow: 'hidden', WebkitMaskImage: 'linear-gradient(180deg,#000 70%,transparent)', maskImage: 'linear-gradient(180deg,#000 70%,transparent)' } : {}),
|
|
1233
1599
|
},
|
|
1234
1600
|
},
|
|
1235
|
-
light ? h('div', { className: 'dshb-md dshb-md-light' }, linkify(s, 'l')) : h(RichText, { t, text: s }),
|
|
1601
|
+
light ? h('div', { className: 'dshb-md dshb-md-light' }, linkify(s, 'l')) : h(RichText, { t, text: s, variant }),
|
|
1236
1602
|
),
|
|
1237
|
-
long ? h('button', { type: 'button', className: 'dshb-link', style: { fontSize: TINY, alignSelf: 'flex-start', color: light ? '
|
|
1603
|
+
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
1604
|
);
|
|
1239
1605
|
}
|
|
1240
1606
|
|
|
1241
|
-
/**
|
|
1607
|
+
/**
|
|
1608
|
+
* Preview cards for the links in `text`: none when it lists more than MAX_CARDS links
|
|
1609
|
+
* (a list of sources reads better as the links it already is), one large card for a
|
|
1610
|
+
* single link, compact ones for two or three. Links that resolve to the same preview
|
|
1611
|
+
* (two pages of one site sharing a title and picture) show it once.
|
|
1612
|
+
*/
|
|
1242
1613
|
function LinkCards({ t, text, align = 'flex-start' }) {
|
|
1243
|
-
const
|
|
1614
|
+
const all = linksIn(text);
|
|
1615
|
+
const links = all.length > MAX_CARDS ? [] : all;
|
|
1616
|
+
const cards = [useUnfurl(links[0] ?? ''), useUnfurl(links[1] ?? ''), useUnfurl(links[2] ?? '')];
|
|
1244
1617
|
if (!links.length) return null;
|
|
1245
|
-
|
|
1618
|
+
const seen = new Set();
|
|
1619
|
+
const shown = links.filter((u, i) => {
|
|
1620
|
+
const c = cards[i];
|
|
1621
|
+
if (!c || !c.ok) return true;
|
|
1622
|
+
const key = [c.kind, c.site || c.host || hostOf(u), c.title || '', c.image || ''].join('|');
|
|
1623
|
+
if (seen.has(key)) return false;
|
|
1624
|
+
seen.add(key);
|
|
1625
|
+
return true;
|
|
1626
|
+
});
|
|
1627
|
+
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
1628
|
}
|
|
1247
1629
|
|
|
1248
1630
|
// --- Markdown -------------------------------------------------------------------------
|
|
@@ -1269,10 +1651,11 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1269
1651
|
.map((part, i) => (i % 2 ? part : part.replace(/(^|[^\\])\$(?=\d)/g, '$1\\$')))
|
|
1270
1652
|
.join('');
|
|
1271
1653
|
}
|
|
1272
|
-
|
|
1654
|
+
/** `variant`: 'compact' (secondary text: muted and small, the default) or 'body' (the main conversation's). */
|
|
1655
|
+
function RichText({ t, text, variant = 'compact' }) {
|
|
1273
1656
|
const Md = primitives && primitives.MarkdownText;
|
|
1274
1657
|
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' }));
|
|
1658
|
+
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
1659
|
}
|
|
1277
1660
|
return h('div', { className: 'dshb-rich dshb-mdf', 'data-dsh-bots-md': 'builtin' }, miniMarkdown(text));
|
|
1278
1661
|
}
|
|
@@ -1538,7 +1921,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1538
1921
|
}
|
|
1539
1922
|
|
|
1540
1923
|
/** One rich preview: a playable YouTube video, an X post or profile, or a page's OpenGraph card. */
|
|
1541
|
-
function LinkCard({ t, url }) {
|
|
1924
|
+
function LinkCard({ t, url, compact = false }) {
|
|
1542
1925
|
const card = useUnfurl(url);
|
|
1543
1926
|
const host = hostOf(url);
|
|
1544
1927
|
if (!card) {
|
|
@@ -1555,7 +1938,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1555
1938
|
if (card.kind === 'image' && card.ok) {
|
|
1556
1939
|
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
1940
|
}
|
|
1558
|
-
if (card.ok && card.kind === 'page') return h(PageCard, { card });
|
|
1941
|
+
if (card.ok && card.kind === 'page') return h(PageCard, { card, compact });
|
|
1559
1942
|
// No preview: a slim link row still says where it goes.
|
|
1560
1943
|
return h(
|
|
1561
1944
|
'a',
|
|
@@ -1567,8 +1950,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1567
1950
|
);
|
|
1568
1951
|
}
|
|
1569
1952
|
|
|
1570
|
-
function PageCard({ card }) {
|
|
1571
|
-
const large = card.large && card.image;
|
|
1953
|
+
function PageCard({ card, compact = false }) {
|
|
1954
|
+
const large = !compact && card.large && card.image;
|
|
1572
1955
|
const site = h(
|
|
1573
1956
|
'div',
|
|
1574
1957
|
{ className: 'dshb-lc-site' },
|
|
@@ -1783,9 +2166,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1783
2166
|
const box = useRef(null);
|
|
1784
2167
|
const content = useRef(null);
|
|
1785
2168
|
const pinned = useRef(true);
|
|
2169
|
+
const lastTop = useRef(0);
|
|
1786
2170
|
const toBottom = () => {
|
|
1787
2171
|
const el = box.current;
|
|
1788
|
-
if (el)
|
|
2172
|
+
if (el) {
|
|
2173
|
+
el.scrollTop = el.scrollHeight;
|
|
2174
|
+
lastTop.current = el.scrollTop;
|
|
2175
|
+
}
|
|
1789
2176
|
};
|
|
1790
2177
|
useEffect(() => {
|
|
1791
2178
|
if (pinned.current) toBottom();
|
|
@@ -1798,9 +2185,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1798
2185
|
ro.observe(content.current);
|
|
1799
2186
|
return () => ro.disconnect();
|
|
1800
2187
|
}, [content.current]);
|
|
2188
|
+
// Only the reader scrolling up lets go of the bottom: the browser nudging the view as content grows
|
|
2189
|
+
// (scroll anchoring) can land before the resize is seen, and must not.
|
|
1801
2190
|
const onScroll = (e) => {
|
|
1802
2191
|
const el = e.currentTarget;
|
|
1803
|
-
|
|
2192
|
+
if (el.scrollHeight - el.scrollTop - el.clientHeight < 80) pinned.current = true;
|
|
2193
|
+
else if (el.scrollTop < lastTop.current) pinned.current = false;
|
|
2194
|
+
lastTop.current = el.scrollTop;
|
|
1804
2195
|
};
|
|
1805
2196
|
const stick = () => {
|
|
1806
2197
|
pinned.current = true;
|
|
@@ -1809,11 +2200,134 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1809
2200
|
return { box, content, onScroll, stick };
|
|
1810
2201
|
}
|
|
1811
2202
|
|
|
2203
|
+
// --- a bot's question (Harness's ask_user_question), answered here --------------------------
|
|
2204
|
+
|
|
2205
|
+
/** The questions waiting in one conversation (state `asks`), oldest first. */
|
|
2206
|
+
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)) : []);
|
|
2207
|
+
const NO_PICK = { selected: [], custom: '' };
|
|
2208
|
+
|
|
2209
|
+
/**
|
|
2210
|
+
* A bot's question at the bottom of its chat or task. One single-choice question is answered by a
|
|
2211
|
+
* click on an option; several questions, or a multiple choice, are ticked and submitted. "Other"
|
|
2212
|
+
* takes your own words. An approval or a plan review is answered in the conversation.
|
|
2213
|
+
*/
|
|
2214
|
+
function AskCard({ t, ask, env, onAnswered }) {
|
|
2215
|
+
const [picks, setPicks] = useState({});
|
|
2216
|
+
const [busy, setBusy] = useState(false);
|
|
2217
|
+
const [error, setError] = useState('');
|
|
2218
|
+
const name = botName(t, ask.botId);
|
|
2219
|
+
const questions = ask.questions.filter((q) => q && typeof q.id === 'string');
|
|
2220
|
+
const quick = !ask.native && questions.length === 1 && !questions[0].multiSelect;
|
|
2221
|
+
const pickOf = (q) => picks[q.id] ?? NO_PICK;
|
|
2222
|
+
const change = (q, fn) => setPicks((all) => ({ ...all, [q.id]: { ...(all[q.id] ?? NO_PICK), ...fn(all[q.id] ?? NO_PICK) } }));
|
|
2223
|
+
const item = (q, p) => ({ id: q.id, selected: p.selected, ...(p.custom.trim() ? { custom: p.custom.trim() } : {}) });
|
|
2224
|
+
const complete = questions.every((q) => pickOf(q).selected.length > 0 || pickOf(q).custom.trim() !== '');
|
|
2225
|
+
const post = (answers) => {
|
|
2226
|
+
if (busy) return;
|
|
2227
|
+
setBusy(true);
|
|
2228
|
+
setError('');
|
|
2229
|
+
postJson(`asks/${encodeURIComponent(ask.id)}/answer`, { answers })
|
|
2230
|
+
.then((r) => {
|
|
2231
|
+
if (r?.ok) {
|
|
2232
|
+
onAnswered?.();
|
|
2233
|
+
void refreshState();
|
|
2234
|
+
} else setError(str(r?.reason) || t('askFailed'));
|
|
2235
|
+
})
|
|
2236
|
+
.finally(() => setBusy(false));
|
|
2237
|
+
};
|
|
2238
|
+
const submit = () => (complete ? post(questions.map((q) => item(q, pickOf(q)))) : undefined);
|
|
2239
|
+
const choose = (q, label) => {
|
|
2240
|
+
if (quick) return post([{ id: q.id, selected: [label] }]);
|
|
2241
|
+
change(q, (p) => (q.multiSelect ? { selected: p.selected.includes(label) ? p.selected.filter((x) => x !== label) : [...p.selected, label] } : { selected: [label], custom: '' }));
|
|
2242
|
+
};
|
|
2243
|
+
const option = (q, o) => {
|
|
2244
|
+
const on = !quick && pickOf(q).selected.includes(o.label);
|
|
2245
|
+
return h(
|
|
2246
|
+
'button',
|
|
2247
|
+
{
|
|
2248
|
+
key: o.label,
|
|
2249
|
+
type: 'button',
|
|
2250
|
+
className: 'dshb-row',
|
|
2251
|
+
disabled: busy,
|
|
2252
|
+
onClick: () => choose(q, o.label),
|
|
2253
|
+
'data-dsh-bots-ask-option': o.label,
|
|
2254
|
+
...(quick ? {} : { role: q.multiSelect ? 'checkbox' : 'radio', 'aria-checked': on }),
|
|
2255
|
+
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 },
|
|
2256
|
+
},
|
|
2257
|
+
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),
|
|
2258
|
+
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),
|
|
2259
|
+
);
|
|
2260
|
+
};
|
|
2261
|
+
const other = (q) => {
|
|
2262
|
+
const p = pickOf(q);
|
|
2263
|
+
const hasOptions = Array.isArray(q.options) && q.options.length > 0;
|
|
2264
|
+
const send = () => (p.custom.trim() ? post([item(q, { selected: [], custom: p.custom })]) : undefined);
|
|
2265
|
+
return h(
|
|
2266
|
+
'div',
|
|
2267
|
+
{ style: { display: 'flex', gap: 6, alignItems: 'center' } },
|
|
2268
|
+
h(Input, {
|
|
2269
|
+
value: p.custom,
|
|
2270
|
+
disabled: busy,
|
|
2271
|
+
placeholder: hasOptions ? t('askOtherPlaceholder') : t('askFreePlaceholder'),
|
|
2272
|
+
'aria-label': hasOptions ? t('askOtherPlaceholder') : t('askFreePlaceholder'),
|
|
2273
|
+
'data-dsh-bots-ask-other': q.id,
|
|
2274
|
+
onChange: (e) => change(q, () => ({ custom: e.target.value, ...(q.multiSelect ? {} : { selected: [] }) })),
|
|
2275
|
+
onKeyDown: (e) => {
|
|
2276
|
+
if (e.key === 'Enter' && !e.isComposing && !e.nativeEvent?.isComposing) {
|
|
2277
|
+
e.preventDefault();
|
|
2278
|
+
if (quick) send();
|
|
2279
|
+
else submit();
|
|
2280
|
+
}
|
|
2281
|
+
},
|
|
2282
|
+
style: { height: 30, fontSize: SMALL },
|
|
2283
|
+
}),
|
|
2284
|
+
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,
|
|
2285
|
+
);
|
|
2286
|
+
};
|
|
2287
|
+
return h(
|
|
2288
|
+
'div',
|
|
2289
|
+
{ 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 } },
|
|
2290
|
+
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 })),
|
|
2291
|
+
questions.map((q) =>
|
|
2292
|
+
h(
|
|
2293
|
+
'div',
|
|
2294
|
+
{ key: q.id, 'data-dsh-bots-ask-question': q.id, style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
2295
|
+
q.header ? h('div', null, h(Badge, { color: C.label }, str(q.header))) : null,
|
|
2296
|
+
h('div', { style: { fontWeight: 600, fontSize: FONT, wordBreak: 'break-word' } }, str(q.question)),
|
|
2297
|
+
q.detail ? h(Clamp, { t, text: q.detail, lines: 6, style: { fontSize: SMALL, color: C.muted } }) : null,
|
|
2298
|
+
ask.native ? null : q.multiSelect ? h('div', { style: { fontSize: TINY, color: C.faint } }, t('askMulti')) : null,
|
|
2299
|
+
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))),
|
|
2300
|
+
ask.native ? null : other(q),
|
|
2301
|
+
),
|
|
2302
|
+
),
|
|
2303
|
+
ask.continued ? h('div', { style: { fontSize: TINY, color: C.muted } }, t('askContinued', { name })) : null,
|
|
2304
|
+
ask.native
|
|
2305
|
+
? h(
|
|
2306
|
+
'div',
|
|
2307
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
|
|
2308
|
+
h('span', { style: { fontSize: SMALL, color: C.muted, flex: 1, minWidth: 160 } }, t('askNativeHint')),
|
|
2309
|
+
env?.canOpen?.()
|
|
2310
|
+
? 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'))
|
|
2311
|
+
: null,
|
|
2312
|
+
)
|
|
2313
|
+
: null,
|
|
2314
|
+
!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,
|
|
2315
|
+
error ? h('div', { 'data-dsh-bots-ask-error': true, style: { fontSize: TINY, color: C.error } }, error) : null,
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
/** The waiting questions of one conversation, above its composer. */
|
|
2319
|
+
const AskCards = ({ t, sessionId, env, onAnswered }) => {
|
|
2320
|
+
const list = asksIn(sessionId);
|
|
2321
|
+
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;
|
|
2322
|
+
};
|
|
2323
|
+
|
|
1812
2324
|
function ChatTab({ t, bot, env, toast }) {
|
|
1813
2325
|
const { items, failed, reload } = useMessages(bot.id);
|
|
1814
2326
|
const [text, setText] = useState('');
|
|
1815
2327
|
const [sending, setSending] = useState(false);
|
|
1816
|
-
|
|
2328
|
+
// The quick poll may know before the state does that it started or stopped.
|
|
2329
|
+
const live = liveBot(bot);
|
|
2330
|
+
const running = live.status === 'running' || Boolean(live.activity);
|
|
1817
2331
|
const thread = useStickToBottom(`${items?.length ?? 0}:${items?.[items.length - 1]?.id ?? ''}:${running}`);
|
|
1818
2332
|
const [topicBusy, setTopicBusy] = useState(false);
|
|
1819
2333
|
const startTopic = () => {
|
|
@@ -1863,15 +2377,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1863
2377
|
botId: bot.id,
|
|
1864
2378
|
empty: h(ChatEmpty, { t, bot, onPick: setText }),
|
|
1865
2379
|
}),
|
|
1866
|
-
running
|
|
1867
|
-
? h(
|
|
1868
|
-
'div',
|
|
1869
|
-
{ style: { display: 'flex', alignItems: 'center', gap: 8, padding: '8px 0 4px', color: C.muted, fontSize: SMALL, maxWidth: 880, margin: '0 auto' } },
|
|
1870
|
-
h(Avatar, { avatar: bot.avatar, name: bot.name, size: 22 }),
|
|
1871
|
-
h('span', null, t('working', { name: bot.name })),
|
|
1872
|
-
h('span', { style: { display: 'inline-flex', gap: 3 } }, [0, 1, 2].map((i) => h('span', { key: i, style: { width: 4, height: 4, borderRadius: '50%', background: C.muted, animation: `dshb-blink 1.2s ${i * 0.2}s infinite` } }))),
|
|
1873
|
-
)
|
|
1874
|
-
: null,
|
|
2380
|
+
running ? h('div', { style: { maxWidth: 880, margin: '0 auto' } }, h(WorkingRow, { t, bot, a: live.activity, attr: bot.id })) : null,
|
|
1875
2381
|
),
|
|
1876
2382
|
),
|
|
1877
2383
|
h(
|
|
@@ -1880,6 +2386,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1880
2386
|
h(
|
|
1881
2387
|
'div',
|
|
1882
2388
|
{ style: { maxWidth: 880, margin: '0 auto' } },
|
|
2389
|
+
// Questions of its own conversation; a task's wait in the task.
|
|
2390
|
+
h(AskCards, { t, sessionId: bot.sessionId, env, onAnswered: () => void reload() }),
|
|
1883
2391
|
previewUrl ? h('div', { 'data-dsh-bots-composer-preview': previewUrl, style: { marginBottom: 8, maxHeight: 260, overflow: 'auto' } }, h(LinkCard, { t, url: previewUrl })) : null,
|
|
1884
2392
|
h(
|
|
1885
2393
|
'div',
|
|
@@ -1919,6 +2427,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1919
2427
|
const { items, failed } = useMessages(null);
|
|
1920
2428
|
const [filter, setFilter] = useState('');
|
|
1921
2429
|
const shown = (items ?? []).filter((m) => !filter || m.from === filter || m.to === filter).slice().reverse();
|
|
2430
|
+
const names = threadNamesOf(items);
|
|
1922
2431
|
return h(
|
|
1923
2432
|
'div',
|
|
1924
2433
|
{ style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
@@ -1966,7 +2475,11 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1966
2475
|
h('span', { style: { color: C.faint, display: 'inline-flex' } }, Icon.arrow(11)),
|
|
1967
2476
|
h('span', { style: { fontWeight: 600 } }, to.name),
|
|
1968
2477
|
h(Badge, { color: m.kind === 'dm' ? C.label : m.kind === 'system' ? C.warn : C.muted }, t(`kind_${m.kind}`) || m.kind),
|
|
1969
|
-
m
|
|
2478
|
+
messageReport(m) ? h(ReportChip, { t, status: messageReport(m) }) : null,
|
|
2479
|
+
messageNotice(m) ? h(StageChip, { t, stage: messageNotice(m) }) : null,
|
|
2480
|
+
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,
|
|
2481
|
+
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,
|
|
2482
|
+
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,
|
|
1970
2483
|
h('span', { style: { marginLeft: 'auto', color: C.faint, fontSize: TINY }, title: fmtDate(toMs(m.at)) }, fmtAgo(t, m.at)),
|
|
1971
2484
|
),
|
|
1972
2485
|
h(Clamp, { t, text: m.kind === 'topic' ? t('topicDivider', { reason: t(`topicReason_${m.text}`) }) : m.text, lines: 3, style: { fontSize: SMALL, color: C.muted } }),
|
|
@@ -1978,6 +2491,628 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
1978
2491
|
);
|
|
1979
2492
|
}
|
|
1980
2493
|
|
|
2494
|
+
// --- tasks: the list, one task, a bot's open tasks, cards in the timeline ---------------
|
|
2495
|
+
|
|
2496
|
+
const NEEDS_YOU = ['question', 'failed', 'stalled'];
|
|
2497
|
+
const FINISHED = ['done', 'stopped'];
|
|
2498
|
+
const STAGE_COLOR = { question: C.warn, failed: C.error, stalled: C.warn, queued: C.muted, working: C.ok, done: C.label, stopped: C.muted };
|
|
2499
|
+
const REPORT_STATUSES = ['progress', 'done', 'blocked', 'question'];
|
|
2500
|
+
const REPORT_COLOR = { progress: C.muted, done: C.ok, blocked: C.error, question: C.warn };
|
|
2501
|
+
/** Open tasks of a bot, from the polled counts. */
|
|
2502
|
+
const openTaskCount = (bot) => ['working', 'question', 'stalled', 'queued'].reduce((n, k) => n + (Number(bot?.tickets?.[k]) || 0), 0);
|
|
2503
|
+
const DONE_PAGE = 20;
|
|
2504
|
+
// A task whose conversation waits for your answer to its question (`asking`) needs you too.
|
|
2505
|
+
const groupOf = (row) => (row?.asking || NEEDS_YOU.includes(row?.stage) ? 'needs' : FINISHED.includes(row?.stage) ? 'done' : 'progress');
|
|
2506
|
+
const newestFirst = (a, b) => (toMs(b.updatedAt ?? b.createdAt) || 0) - (toMs(a.updatedAt ?? a.createdAt) || 0);
|
|
2507
|
+
const taskTitle = (t, row) => str(row?.title).trim() || t('untitledTask');
|
|
2508
|
+
const firstLine = (text) => (str(text).split('\n').find((l) => l.trim() !== '') ?? '').trim().slice(0, 120);
|
|
2509
|
+
/** The task a timeline message belongs to (a delegation, or a report on it), or ''. */
|
|
2510
|
+
function messageTicket(m) {
|
|
2511
|
+
const v = m?.ticket && typeof m.ticket === 'object' ? m.ticket.id : (m?.ticket ?? m?.ticketId);
|
|
2512
|
+
return typeof v === 'string' ? v : '';
|
|
2513
|
+
}
|
|
2514
|
+
/** The status of a worker's report on a timeline message, or ''. */
|
|
2515
|
+
function messageReport(m) {
|
|
2516
|
+
const v = m?.report && typeof m.report === 'object' ? m.report.status : (m?.report ?? m?.status);
|
|
2517
|
+
return REPORT_STATUSES.includes(v) ? v : '';
|
|
2518
|
+
}
|
|
2519
|
+
/** The stage a watchdog notice on a timeline message tells of (a task stuck, or failed for good), or ''. */
|
|
2520
|
+
const messageNotice = (m) => (m?.kind === 'dm' && messageTicket(m) && (m.status === 'stalled' || m.status === 'failed') ? m.status : '');
|
|
2521
|
+
function StageChip({ t, stage }) {
|
|
2522
|
+
if (!STAGE_COLOR[stage]) return null;
|
|
2523
|
+
return h(Badge, { color: STAGE_COLOR[stage], 'data-dsh-bots-stage': stage }, stage === 'working' ? h(StatusDot, { status: 'running', size: 6 }) : null, t(`stage_${stage}`));
|
|
2524
|
+
}
|
|
2525
|
+
/** A task's stage, or that it waits for your answer to its question. */
|
|
2526
|
+
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 }));
|
|
2527
|
+
const ReportChip = ({ t, status }) => (REPORT_COLOR[status] ? h(Badge, { color: REPORT_COLOR[status], 'data-dsh-bots-report': status }, t(`report_${status}`)) : null);
|
|
2528
|
+
/** Who asked for a task: you, or a bot (the dispatcher, or the bot of a parent task). */
|
|
2529
|
+
const requesterBot = (row) => {
|
|
2530
|
+
const r = row?.requester ?? {};
|
|
2531
|
+
return r.kind === 'user' || typeof r.botId !== 'string' || !r.botId ? null : r.botId;
|
|
2532
|
+
};
|
|
2533
|
+
const requesterText = (t, row) => (requesterBot(row) ? t('askedBy', { name: botName(t, requesterBot(row)) }) : t('askedByYou'));
|
|
2534
|
+
const requesterName = (t, row) => (requesterBot(row) ? botName(t, requesterBot(row)) : t('you'));
|
|
2535
|
+
/** The chat a task came in from, as a badge (a scheduled run's task says so). */
|
|
2536
|
+
function viaBadge(t, via, who) {
|
|
2537
|
+
if (!via || typeof via !== 'string') return null;
|
|
2538
|
+
if (via === 'schedule') return h(Badge, { color: C.warn, 'data-dsh-bots-task-via': via }, t('trigger_schedule'));
|
|
2539
|
+
const label = via === 'panel' ? t('viaPanel') : channelName(via, t);
|
|
2540
|
+
return h(Badge, { color: CHANNEL_COLORS[via] ?? C.muted, 'data-dsh-bots-task-via': via }, who ? `${label} · ${str(who)}` : label);
|
|
2541
|
+
}
|
|
2542
|
+
const BotFace = ({ id, size }) => {
|
|
2543
|
+
const b = botById(id);
|
|
2544
|
+
return b ? h(Avatar, { avatar: b.avatar, name: b.name || b.handle, size }) : h(PartyAvatar, { p: { kind: 'unknown' }, size });
|
|
2545
|
+
};
|
|
2546
|
+
const dotSep = () => h('span', { style: { color: C.faint } }, '·');
|
|
2547
|
+
|
|
2548
|
+
// --- live status: what a bot's conversation or a task's does right now ------------------------
|
|
2549
|
+
|
|
2550
|
+
/** 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`. */
|
|
2551
|
+
const ACT_TOOLS = [
|
|
2552
|
+
[/^(bash|pwsh|shell|sh|terminal|exec|run_command|execute_command)$/, 'run'],
|
|
2553
|
+
[/^(read|read_file|read_image|view|open_file|cat)$/, 'read'],
|
|
2554
|
+
[/^(edit|str_replace|str_replace_editor|str_replace_based_edit_tool|multi_edit|multiedit|apply_patch|patch|notebook_edit)$/, 'edit'],
|
|
2555
|
+
[/^(write|write_file|create_file)$/, 'write'],
|
|
2556
|
+
[/^(grep|glob|ls|find|search_files|list_files|list_directory|ripgrep)$/, 'find'],
|
|
2557
|
+
[/^bot_send_message$/, 'send'],
|
|
2558
|
+
[/^memory_search$/, 'memory'],
|
|
2559
|
+
[/^memory_(save|forget)$/, 'remember'],
|
|
2560
|
+
[/(^|_)search$|^websearch$/, 'search'],
|
|
2561
|
+
[/^(web_fetch|fetch|webfetch|browse|open_url)$/, 'fetch'],
|
|
2562
|
+
[/^ask_user_question$/, 'ask'],
|
|
2563
|
+
[/^generate_image$/, 'draw'],
|
|
2564
|
+
[/^(subagent|task|agent|wait_agent)$/, 'helper'],
|
|
2565
|
+
[/^(skill|load_skill)$/, 'skill'],
|
|
2566
|
+
[/^bot_reply$/, 'reply'],
|
|
2567
|
+
[/^bot_recall$/, 'recall'],
|
|
2568
|
+
[/^bot_(create|update|delete|list|ticket)$/, 'team'],
|
|
2569
|
+
[/^bot_schedule$/, 'schedule'],
|
|
2570
|
+
[/^(todo|todo_write|todowrite|plan)$/, 'plan'],
|
|
2571
|
+
[/^job_/, 'job'],
|
|
2572
|
+
[/^office_/, 'office'],
|
|
2573
|
+
];
|
|
2574
|
+
/** Kinds of tool whose words name what they work on, when the Host sent it. */
|
|
2575
|
+
const ACT_DETAIL = new Set(['run', 'read', 'edit', 'write', 'find', 'search', 'fetch', 'helper', 'skill', 'memory', 'recall']);
|
|
2576
|
+
/** An activity as words: its dictionary key, the detail set off in it, and whether that detail is code. */
|
|
2577
|
+
function activityWords(a) {
|
|
2578
|
+
if (!a || typeof a !== 'object') return null;
|
|
2579
|
+
if (a.kind === 'writing') return { key: 'act_writing', detail: '' };
|
|
2580
|
+
if (a.kind !== 'tool') return { key: 'act_thinking', detail: '' };
|
|
2581
|
+
const tool = str(a.tool);
|
|
2582
|
+
const short = tool.toLowerCase().split('__').pop();
|
|
2583
|
+
const detail = str(a.detail).trim();
|
|
2584
|
+
const act = (ACT_TOOLS.find(([re]) => re.test(short)) ?? [null, 'tool'])[1];
|
|
2585
|
+
if (act === 'send') return detail.startsWith('@') ? { key: 'act_delegate', detail } : detail.startsWith('#') ? { key: 'act_followup', detail: detail.slice(1) } : { key: 'act_report', detail: '' };
|
|
2586
|
+
if (act === 'tool') return { key: 'act_tool', detail: tool.split('__').pop() || tool || '?', code: true };
|
|
2587
|
+
if (ACT_DETAIL.has(act)) return detail ? { key: `act_${act}`, detail, code: act === 'run' } : { key: `act_${act}_bare`, detail: '' };
|
|
2588
|
+
return { key: `act_${act}`, detail: '' };
|
|
2589
|
+
}
|
|
2590
|
+
/** The activity in plain words (a title, a row of text). */
|
|
2591
|
+
function activityLine(t, a) {
|
|
2592
|
+
const w = activityWords(a);
|
|
2593
|
+
return w ? t(w.key, { detail: w.detail }) : '';
|
|
2594
|
+
}
|
|
2595
|
+
/** The activity in words, its detail set off (a command in code type). */
|
|
2596
|
+
function ActivityWords({ t, a }) {
|
|
2597
|
+
const w = activityWords(a);
|
|
2598
|
+
if (!w) return null;
|
|
2599
|
+
if (!w.detail) return h('span', { 'data-dsh-bots-act': w.key }, t(w.key));
|
|
2600
|
+
const [before, after = ''] = t(w.key, { detail: '\u0000' }).split('\u0000');
|
|
2601
|
+
return h('span', { 'data-dsh-bots-act': w.key }, before, h('span', { className: w.code ? 'dshb-act-code' : 'dshb-act-detail' }, w.detail), after);
|
|
2602
|
+
}
|
|
2603
|
+
/** The Host's clock now, as far as this page can tell (its answers carry their time). */
|
|
2604
|
+
const hostNow = () => Date.now() + (Number.isFinite(store.skew) ? store.skew : 0);
|
|
2605
|
+
/** A running time as a timer reads: 42s, 1m 05s, 1h 02m. */
|
|
2606
|
+
function fmtElapsed(t, ms) {
|
|
2607
|
+
const sec = Math.max(0, Math.floor((Number(ms) || 0) / 1000));
|
|
2608
|
+
if (sec < 60) return t('elapsedS', { s: sec });
|
|
2609
|
+
if (sec < 3600) return t('elapsedM', { m: Math.floor(sec / 60), s: pad(sec % 60) });
|
|
2610
|
+
return t('elapsedH', { h: Math.floor(sec / 3600), m: pad(Math.floor(sec / 60) % 60) });
|
|
2611
|
+
}
|
|
2612
|
+
/** Re-render every second while `on`, so running times tick between polls. */
|
|
2613
|
+
function useTick(on) {
|
|
2614
|
+
const [, force] = useState(0);
|
|
2615
|
+
useEffect(() => {
|
|
2616
|
+
if (!on) return undefined;
|
|
2617
|
+
let id = null;
|
|
2618
|
+
try {
|
|
2619
|
+
id = setInterval(() => force((n) => n + 1), 1000);
|
|
2620
|
+
id?.unref?.();
|
|
2621
|
+
} catch {
|
|
2622
|
+
id = null;
|
|
2623
|
+
}
|
|
2624
|
+
return () => {
|
|
2625
|
+
if (id) clearInterval(id);
|
|
2626
|
+
};
|
|
2627
|
+
}, [on]);
|
|
2628
|
+
}
|
|
2629
|
+
/** The freshest activity of a bot's task conversations (with `ticket`), or null. */
|
|
2630
|
+
function botTaskActivity(botId) {
|
|
2631
|
+
let best = null;
|
|
2632
|
+
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 };
|
|
2633
|
+
return best;
|
|
2634
|
+
}
|
|
2635
|
+
/** The one-line live status: what it does now and for how long (`compact`: muted, for a row). */
|
|
2636
|
+
function LiveLine({ t, a, attr, style }) {
|
|
2637
|
+
useTick(Boolean(a));
|
|
2638
|
+
if (!a) return null;
|
|
2639
|
+
const now = hostNow();
|
|
2640
|
+
const time = fmtElapsed(t, now - (Number(a.stepAt) || now));
|
|
2641
|
+
// The words give way (an ellipsis); the time stays.
|
|
2642
|
+
return h(
|
|
2643
|
+
'span',
|
|
2644
|
+
{ 'data-dsh-bots-live': attr ?? true, title: `${activityLine(t, a)} · ${time}`, className: 'dshb-live dshb-liveline', style },
|
|
2645
|
+
h('span', { className: 'dshb-liveline-words' }, h(ActivityWords, { t, a })),
|
|
2646
|
+
h('span', { className: 'dshb-live-time' }, `· ${time}`),
|
|
2647
|
+
);
|
|
2648
|
+
}
|
|
2649
|
+
/**
|
|
2650
|
+
* The working row of a chat or a task: the bot, what it does now (ticking), then the step and
|
|
2651
|
+
* the turn's time so far. Without an activity yet (an older Host, the first poll) it says the bot works.
|
|
2652
|
+
*/
|
|
2653
|
+
function WorkingRow({ t, bot, a, attr }) {
|
|
2654
|
+
useTick(true);
|
|
2655
|
+
const now = hostNow();
|
|
2656
|
+
const name = bot ? bot.name || `@${bot.handle}` : '';
|
|
2657
|
+
return h(
|
|
2658
|
+
'div',
|
|
2659
|
+
{ 'data-dsh-bots-working': attr ?? true, className: 'dshb-fade', style: { display: 'flex', alignItems: 'center', gap: 10, padding: '10px 0 2px', minWidth: 0 } },
|
|
2660
|
+
h('div', { style: { width: 30, flex: 'none', display: 'flex', justifyContent: 'center' } }, bot ? h(Avatar, { avatar: bot.avatar, name, size: 24, working: true }) : null),
|
|
2661
|
+
h(
|
|
2662
|
+
'div',
|
|
2663
|
+
{ style: { display: 'flex', alignItems: 'baseline', gap: 8, minWidth: 0, flex: 1, fontSize: SMALL } },
|
|
2664
|
+
name ? h('span', { style: { fontWeight: 650, color: C.primary, flex: 'none' } }, name) : null,
|
|
2665
|
+
a
|
|
2666
|
+
? h(
|
|
2667
|
+
'span',
|
|
2668
|
+
{ className: 'dshb-live', 'data-dsh-bots-live': 'working', style: { color: C.primary, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
2669
|
+
h(ActivityWords, { t, a }),
|
|
2670
|
+
h('span', { className: 'dshb-live-time' }, ` · ${fmtElapsed(t, now - (Number(a.stepAt) || now))}`),
|
|
2671
|
+
)
|
|
2672
|
+
: h('span', { style: { color: C.muted } }, t('workingPlain')),
|
|
2673
|
+
h('span', { className: 'dshb-dots', 'aria-hidden': 'true' }, h('i'), h('i'), h('i')),
|
|
2674
|
+
// The step and the turn's time, once they say more than the current activity's time does.
|
|
2675
|
+
a && (Number(a.steps) > 1 || (Number(a.stepAt) || 0) - (Number(a.startedAt) || 0) > 2000)
|
|
2676
|
+
? 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)) }))
|
|
2677
|
+
: null,
|
|
2678
|
+
),
|
|
2679
|
+
);
|
|
2680
|
+
}
|
|
2681
|
+
/** A working task's stage chip, alive: what its conversation does now and for how long. */
|
|
2682
|
+
function LiveChip({ t, a }) {
|
|
2683
|
+
useTick(Boolean(a));
|
|
2684
|
+
const now = hostNow();
|
|
2685
|
+
return h(
|
|
2686
|
+
'span',
|
|
2687
|
+
{ 'data-dsh-bots-stage': 'working', 'data-dsh-bots-live': 'chip', title: `${t('stage_working')}: ${activityLine(t, a)}`, className: 'dshb-livechip' },
|
|
2688
|
+
h(StatusDot, { status: 'running', size: 6 }),
|
|
2689
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 } }, h(ActivityWords, { t, a })),
|
|
2690
|
+
h('span', { className: 'dshb-live-time', style: { flex: 'none' } }, fmtElapsed(t, now - (Number(a.stepAt) || now))),
|
|
2691
|
+
);
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
/** One task in a list: title and stage, then bot, who asked, where from and when, then the last report. */
|
|
2695
|
+
function TaskRow({ t, row, onOpen = openTicket, showBot = true }) {
|
|
2696
|
+
const at = row.updatedAt ?? row.createdAt;
|
|
2697
|
+
const last = row.lastReport && typeof row.lastReport === 'object' ? row.lastReport : null;
|
|
2698
|
+
// While its conversation runs, the last line says what it does now.
|
|
2699
|
+
const live = row.stage === 'working' ? liveTask(row.id) ?? (row.activity && typeof row.activity === 'object' ? row.activity : null) : null;
|
|
2700
|
+
return h(
|
|
2701
|
+
'button',
|
|
2702
|
+
{ 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' } },
|
|
2703
|
+
showBot ? h('span', { style: { paddingTop: 1, display: 'inline-flex' } }, h(BotFace, { id: row.botId, size: 30 })) : null,
|
|
2704
|
+
h(
|
|
2705
|
+
'span',
|
|
2706
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3, flex: 1, minWidth: 0 } },
|
|
2707
|
+
h(
|
|
2708
|
+
'span',
|
|
2709
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 } },
|
|
2710
|
+
h('span', { style: { fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0, flex: 1 } }, taskTitle(t, row)),
|
|
2711
|
+
h(TaskChip, { t, row }),
|
|
2712
|
+
),
|
|
2713
|
+
h(
|
|
2714
|
+
'span',
|
|
2715
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.muted, minWidth: 0, flexWrap: 'wrap' } },
|
|
2716
|
+
showBot ? h('span', { style: { fontWeight: 600, color: C.primary } }, botName(t, row.botId)) : null,
|
|
2717
|
+
showBot ? dotSep() : null,
|
|
2718
|
+
h('span', null, requesterText(t, row)),
|
|
2719
|
+
viaBadge(t, row.via),
|
|
2720
|
+
h('span', { style: { color: C.faint }, title: fmtDate(toMs(at)) }, fmtAgo(t, at)),
|
|
2721
|
+
),
|
|
2722
|
+
live
|
|
2723
|
+
? h(
|
|
2724
|
+
'span',
|
|
2725
|
+
{ 'data-dsh-bots-task-live': row.id, style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.muted, minWidth: 0 } },
|
|
2726
|
+
h(StatusDot, { status: 'running', size: 6 }),
|
|
2727
|
+
h(LiveLine, { t, a: live, attr: row.id, style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }),
|
|
2728
|
+
)
|
|
2729
|
+
: last && str(last.preview).trim()
|
|
2730
|
+
? h(
|
|
2731
|
+
'span',
|
|
2732
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: TINY, color: C.muted, minWidth: 0 } },
|
|
2733
|
+
h(ReportChip, { t, status: last.status }),
|
|
2734
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 } }, str(last.preview)),
|
|
2735
|
+
)
|
|
2736
|
+
: null,
|
|
2737
|
+
),
|
|
2738
|
+
);
|
|
2739
|
+
}
|
|
2740
|
+
const TaskList = ({ rows, children, attr }) =>
|
|
2741
|
+
h('div', { [attr ?? 'data-dsh-bots-task-list']: true, className: 'dshb-card', style: { padding: 4, display: 'flex', flexDirection: 'column', gap: 2 } }, rows, children ?? null);
|
|
2742
|
+
|
|
2743
|
+
/** A task in a timeline or a tool card: title, the bot doing it and its stage; it opens the detail. */
|
|
2744
|
+
// Its seat (the panel, or a tool view) is subscribed to the store and re-renders it when the task loads.
|
|
2745
|
+
function TaskCard({ t, id, botId, title, stage, face, onOpen = openTicket }) {
|
|
2746
|
+
usePoll(() => loadTicket(id), 10_000, [id]);
|
|
2747
|
+
const v = store.tickets.get(id)?.view ?? null;
|
|
2748
|
+
const bot = botById(v?.botId ?? botId) ?? (face && typeof face === 'object' && (face.name || face.handle) ? face : null);
|
|
2749
|
+
return h(
|
|
2750
|
+
'button',
|
|
2751
|
+
{
|
|
2752
|
+
type: 'button',
|
|
2753
|
+
className: 'dshb-row',
|
|
2754
|
+
'data-dsh-bots-task-card': id,
|
|
2755
|
+
title: t('openTask'),
|
|
2756
|
+
onClick: (e) => {
|
|
2757
|
+
e?.stopPropagation?.();
|
|
2758
|
+
onOpen(id);
|
|
2759
|
+
},
|
|
2760
|
+
style: { border: `1px solid ${C.border1}`, background: C.layer1, padding: '7px 10px', gap: 9, maxWidth: 560 },
|
|
2761
|
+
},
|
|
2762
|
+
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)),
|
|
2763
|
+
h(
|
|
2764
|
+
'span',
|
|
2765
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0, flex: 1 } },
|
|
2766
|
+
h('span', { style: { fontWeight: 600, fontSize: SMALL, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, str(v?.title).trim() || str(title).trim() || t('untitledTask')),
|
|
2767
|
+
h(
|
|
2768
|
+
'span',
|
|
2769
|
+
{ style: { display: 'inline-flex', alignItems: 'center', gap: 5, fontSize: TINY, color: C.muted, minWidth: 0 } },
|
|
2770
|
+
bot ? h(Avatar, { avatar: bot.avatar, name: bot.name || bot.handle, size: 14 }) : null,
|
|
2771
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, t('taskOf', { name: bot ? bot.name || `@${bot.handle}` : t('removedBot') })),
|
|
2772
|
+
),
|
|
2773
|
+
),
|
|
2774
|
+
h(StageChip, { t, stage: v?.stage ?? stage }),
|
|
2775
|
+
h('span', { style: { color: C.faint, display: 'inline-flex' } }, Icon.arrow(11)),
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
/** Every task: what needs you, what is moving, what finished lately. */
|
|
2780
|
+
function TasksView({ t, bots, focusBot = '', onOpen = openTicket }) {
|
|
2781
|
+
const [bot, setBot] = useState(focusBot);
|
|
2782
|
+
const [doneShown, setDoneShown] = useState(DONE_PAGE);
|
|
2783
|
+
useEffect(() => {
|
|
2784
|
+
setBot(focusBot);
|
|
2785
|
+
}, [focusBot]);
|
|
2786
|
+
// The newest 200 (the Host's page limit): open tasks are touched often, so they are near the top.
|
|
2787
|
+
const { data, failed } = useJson(`tickets?limit=200${bot ? `&bot=${encodeURIComponent(bot)}` : ''}`, STATE_POLL_MS);
|
|
2788
|
+
const items = (Array.isArray(data?.items) ? data.items : []).filter((r) => r && typeof r.id === 'string' && (!bot || r.botId === bot));
|
|
2789
|
+
// The polled list of what needs you fills in when the page is not loaded yet, or is longer than a page.
|
|
2790
|
+
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));
|
|
2791
|
+
const all = [...items, ...attention];
|
|
2792
|
+
const groups = [
|
|
2793
|
+
{ id: 'needs', title: t('tasksNeeds'), empty: t('tasksNeedsEmpty') },
|
|
2794
|
+
{ id: 'progress', title: t('tasksProgress'), empty: t('tasksProgressEmpty') },
|
|
2795
|
+
{ id: 'done', title: t('tasksDone'), empty: t('tasksDoneEmpty') },
|
|
2796
|
+
].map((g) => ({ ...g, rows: all.filter((r) => groupOf(r) === g.id).sort(newestFirst) }));
|
|
2797
|
+
const doneCount = groups[2].rows.length;
|
|
2798
|
+
groups[2].rows = groups[2].rows.slice(0, doneShown);
|
|
2799
|
+
let body;
|
|
2800
|
+
if (!data && all.length === 0) body = h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('tasksUnavailable') : t('loading'));
|
|
2801
|
+
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') });
|
|
2802
|
+
else {
|
|
2803
|
+
body = h(
|
|
2804
|
+
'div',
|
|
2805
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 24 } },
|
|
2806
|
+
groups.map((g) =>
|
|
2807
|
+
h(
|
|
2808
|
+
'div',
|
|
2809
|
+
{ key: g.id, 'data-dsh-bots-task-group': g.id, 'data-count': g.rows.length },
|
|
2810
|
+
h(
|
|
2811
|
+
Section,
|
|
2812
|
+
{ title: [g.title, h('span', { key: 'n', style: { marginLeft: 6, fontWeight: 500, color: C.faint } }, g.id === 'done' ? doneCount : g.rows.length)] },
|
|
2813
|
+
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 })) }),
|
|
2814
|
+
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,
|
|
2815
|
+
),
|
|
2816
|
+
),
|
|
2817
|
+
),
|
|
2818
|
+
);
|
|
2819
|
+
}
|
|
2820
|
+
return h(
|
|
2821
|
+
'div',
|
|
2822
|
+
{ 'data-dsh-bots-tasks': true, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
2823
|
+
h(
|
|
2824
|
+
'div',
|
|
2825
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 12, padding: '18px 24px 12px', borderBottom: `1px solid ${C.border1}` } },
|
|
2826
|
+
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)),
|
|
2827
|
+
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'))),
|
|
2828
|
+
h(
|
|
2829
|
+
'select',
|
|
2830
|
+
{ 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 },
|
|
2831
|
+
h('option', { value: '' }, t('allBots')),
|
|
2832
|
+
bots.map((b) => h('option', { key: b.id, value: b.id }, `${b.name} (@${b.handle})`)),
|
|
2833
|
+
),
|
|
2834
|
+
),
|
|
2835
|
+
h('div', { className: 'dshb-scroll', style: { flex: 1, padding: '18px 24px 28px' } }, h('div', { style: { maxWidth: 900, margin: '0 auto' } }, body)),
|
|
2836
|
+
);
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
/** One task: who does it and for whom, where it came from, the reports, its usage, and what you can do with it. */
|
|
2840
|
+
function TicketDetail({ t, id, env, toast, onBack }) {
|
|
2841
|
+
const { data, failed, reload } = useJson(`tickets/${encodeURIComponent(id)}`, STATE_POLL_MS);
|
|
2842
|
+
const [confirm, setConfirm] = useState(null);
|
|
2843
|
+
const [busy, setBusy] = useState('');
|
|
2844
|
+
const [text, setText] = useState('');
|
|
2845
|
+
const [sending, setSending] = useState(false);
|
|
2846
|
+
const v = ticketViewOf(data);
|
|
2847
|
+
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'));
|
|
2848
|
+
if (!v) {
|
|
2849
|
+
return h(
|
|
2850
|
+
'div',
|
|
2851
|
+
{ 'data-dsh-bots-ticket': id, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0, padding: '18px 24px' } },
|
|
2852
|
+
back,
|
|
2853
|
+
h('div', { style: { padding: 24, color: C.faint, fontSize: SMALL, textAlign: 'center' } }, failed ? t('taskMissing') : t('loading')),
|
|
2854
|
+
);
|
|
2855
|
+
}
|
|
2856
|
+
const name = botName(t, v.botId);
|
|
2857
|
+
const stage = v.stage;
|
|
2858
|
+
const open = !FINISHED.includes(stage) && !v.ended;
|
|
2859
|
+
// What its conversation does right now (the quick poll, else the view's).
|
|
2860
|
+
const live = open ? liveTask(id) ?? (v.activity && typeof v.activity === 'object' ? v.activity : null) : null;
|
|
2861
|
+
const archived = Boolean(v.archivedAt || v.archived);
|
|
2862
|
+
const after = (r, okText) => {
|
|
2863
|
+
if (r && r.ok !== false) {
|
|
2864
|
+
const next = ticketViewOf(r);
|
|
2865
|
+
if (next) store.tickets.set(id, { view: next, at: Date.now() });
|
|
2866
|
+
if (okText) toast(okText);
|
|
2867
|
+
void reload();
|
|
2868
|
+
void refreshState();
|
|
2869
|
+
return true;
|
|
2870
|
+
}
|
|
2871
|
+
toast(r?.reason || t('actionFailed'), 'error');
|
|
2872
|
+
return false;
|
|
2873
|
+
};
|
|
2874
|
+
const act = (action) => {
|
|
2875
|
+
setBusy(action);
|
|
2876
|
+
return postJson(`tickets/${encodeURIComponent(id)}/${action}`, {})
|
|
2877
|
+
.then((r) => void after(r, t(`taskDid_${action}`)))
|
|
2878
|
+
.finally(() => setBusy(''));
|
|
2879
|
+
};
|
|
2880
|
+
const send = () => {
|
|
2881
|
+
const body = text.trim();
|
|
2882
|
+
if (!body || sending) return;
|
|
2883
|
+
setSending(true);
|
|
2884
|
+
postJson(`tickets/${encodeURIComponent(id)}/message`, { text: body })
|
|
2885
|
+
.then((r) => {
|
|
2886
|
+
if (after(r, t('taskMessageSent', { name }))) setText('');
|
|
2887
|
+
})
|
|
2888
|
+
.finally(() => setSending(false));
|
|
2889
|
+
};
|
|
2890
|
+
const openConversation = () => {
|
|
2891
|
+
const ok = Boolean(v.sessionId) && env?.openSession?.(v.sessionId) === true;
|
|
2892
|
+
if (!ok) toast(t('openFailed'), 'error');
|
|
2893
|
+
};
|
|
2894
|
+
const origin = v.origin && typeof v.origin === 'object' ? v.origin : {};
|
|
2895
|
+
const threads = Array.isArray(v.threads) ? v.threads : [];
|
|
2896
|
+
const originThread = threads.find((x) => (x?.key ?? x) === origin.threadKey) ?? threads[0];
|
|
2897
|
+
const originKind = str(originThread?.kind) || str(origin.threadKey).split(':')[0];
|
|
2898
|
+
const fromPanelThread = originKind === 'panel';
|
|
2899
|
+
const where = fromPanelThread ? '' : str(origin.label) || str(originThread?.label);
|
|
2900
|
+
const via = v.via ?? origin.via ?? (fromPanelThread ? '' : originThread?.kind);
|
|
2901
|
+
const parentId = typeof v.parentId === 'string' ? v.parentId : typeof v.parent === 'string' ? v.parent : v.parent?.id;
|
|
2902
|
+
const children = (Array.isArray(v.children) ? v.children : []).map((c) => (typeof c === 'string' ? c : c?.id)).filter((c) => typeof c === 'string');
|
|
2903
|
+
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));
|
|
2904
|
+
const runs = (Array.isArray(v.runs) ? v.runs : []).filter((r) => r && typeof r === 'object');
|
|
2905
|
+
// The Host's totals also count calls outside a run (the task's memory summary); else the runs' sum.
|
|
2906
|
+
const total = v.usage && typeof v.usage === 'object' ? v.usage : null;
|
|
2907
|
+
const tokens = total ? Number(total.tokens) || 0 : runs.reduce((n, r) => n + (Number(r.tokens) || 0), 0);
|
|
2908
|
+
const cost = {};
|
|
2909
|
+
if (total) Object.assign(cost, total.cost ?? {});
|
|
2910
|
+
else for (const r of runs) for (const [c, x] of Object.entries(r.cost ?? {})) cost[c] = (cost[c] ?? 0) + (Number(x) || 0);
|
|
2911
|
+
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);
|
|
2912
|
+
// The Host writes "the user" for you; the page says it in your language or not at all.
|
|
2913
|
+
const who = /^the user$/i.test(str(origin.who).trim()) ? '' : str(origin.who).trim();
|
|
2914
|
+
const fromValue = where
|
|
2915
|
+
? 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)
|
|
2916
|
+
: via && via !== 'panel'
|
|
2917
|
+
? viaBadge(t, via, via === 'schedule' ? '' : who)
|
|
2918
|
+
: t('fromPanel');
|
|
2919
|
+
return h(
|
|
2920
|
+
'div',
|
|
2921
|
+
{ 'data-dsh-bots-ticket': id, 'data-stage': stage, style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
2922
|
+
h(
|
|
2923
|
+
'header',
|
|
2924
|
+
{ style: { padding: '14px 24px 14px', borderBottom: `1px solid ${C.border1}`, display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
2925
|
+
h('div', null, back),
|
|
2926
|
+
h(
|
|
2927
|
+
'div',
|
|
2928
|
+
{ style: { display: 'flex', alignItems: 'flex-start', gap: 12, flexWrap: 'wrap' } },
|
|
2929
|
+
h(
|
|
2930
|
+
'div',
|
|
2931
|
+
{ style: { flex: 1, minWidth: 240, display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
2932
|
+
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 })),
|
|
2933
|
+
h(
|
|
2934
|
+
'div',
|
|
2935
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: SMALL, color: C.muted, flexWrap: 'wrap' } },
|
|
2936
|
+
h(BotFace, { id: v.botId, size: 18 }),
|
|
2937
|
+
h('span', { style: { color: C.primary, fontWeight: 600 } }, name),
|
|
2938
|
+
dotSep(),
|
|
2939
|
+
h('span', null, requesterText(t, v)),
|
|
2940
|
+
dotSep(),
|
|
2941
|
+
h('span', { title: fmtDate(toMs(v.createdAt)) }, t('taskStarted', { when: fmtAgo(t, v.createdAt) })),
|
|
2942
|
+
),
|
|
2943
|
+
),
|
|
2944
|
+
h(
|
|
2945
|
+
'div',
|
|
2946
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } },
|
|
2947
|
+
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,
|
|
2948
|
+
['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,
|
|
2949
|
+
open ? h(Btn, { icon: Icon.check(13), disabled: Boolean(busy), onClick: () => setConfirm('close'), 'data-dsh-bots-ticket-close': id }, t('taskClose')) : null,
|
|
2950
|
+
open ? h(Btn, { kind: 'danger', icon: Icon.stop(12), disabled: Boolean(busy), onClick: () => setConfirm('stop'), 'data-dsh-bots-ticket-stop': id }, t('taskStop')) : null,
|
|
2951
|
+
),
|
|
2952
|
+
),
|
|
2953
|
+
),
|
|
2954
|
+
h(
|
|
2955
|
+
'div',
|
|
2956
|
+
{ className: 'dshb-scroll', style: { flex: 1, padding: '18px 24px 24px' } },
|
|
2957
|
+
h(
|
|
2958
|
+
'div',
|
|
2959
|
+
{ style: { maxWidth: 820, display: 'flex', flexDirection: 'column', gap: 22 } },
|
|
2960
|
+
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,
|
|
2961
|
+
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,
|
|
2962
|
+
h(
|
|
2963
|
+
'div',
|
|
2964
|
+
{ className: 'dshb-card', style: { display: 'flex', flexDirection: 'column', gap: 7 } },
|
|
2965
|
+
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'),
|
|
2966
|
+
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'),
|
|
2967
|
+
fact(t('taskFactFrom'), fromValue, 'from'),
|
|
2968
|
+
fact(t('taskFactUpdated'), h('span', { title: fmtDate(toMs(v.updatedAt)) }, fmtAgo(t, v.updatedAt)), 'updated'),
|
|
2969
|
+
),
|
|
2970
|
+
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,
|
|
2971
|
+
h(
|
|
2972
|
+
Section,
|
|
2973
|
+
{ title: t('taskReports') },
|
|
2974
|
+
reports.length === 0
|
|
2975
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('taskNoReports', { name }))
|
|
2976
|
+
: h(
|
|
2977
|
+
'div',
|
|
2978
|
+
{ 'data-dsh-bots-reports': reports.length, style: { display: 'flex', flexDirection: 'column' } },
|
|
2979
|
+
reports.map((r, i) =>
|
|
2980
|
+
h(
|
|
2981
|
+
'div',
|
|
2982
|
+
{ key: `${r.at}-${i}`, 'data-dsh-bots-report-item': r.status, style: { display: 'flex', gap: 10 } },
|
|
2983
|
+
h(
|
|
2984
|
+
'div',
|
|
2985
|
+
{ style: { display: 'flex', flexDirection: 'column', alignItems: 'center', width: 12, flex: 'none', paddingTop: 6 } },
|
|
2986
|
+
h('span', { style: { width: 9, height: 9, borderRadius: '50%', background: REPORT_COLOR[r.status] ?? C.faint, flex: 'none' } }),
|
|
2987
|
+
i < reports.length - 1 ? h('span', { style: { flex: 1, width: 2, marginTop: 3, background: C.border1 } }) : null,
|
|
2988
|
+
),
|
|
2989
|
+
h(
|
|
2990
|
+
'div',
|
|
2991
|
+
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 5, paddingBottom: i < reports.length - 1 ? 14 : 0 } },
|
|
2992
|
+
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)))),
|
|
2993
|
+
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 })),
|
|
2994
|
+
),
|
|
2995
|
+
),
|
|
2996
|
+
),
|
|
2997
|
+
),
|
|
2998
|
+
),
|
|
2999
|
+
parentId || children.length
|
|
3000
|
+
? h(
|
|
3001
|
+
Section,
|
|
3002
|
+
{ title: t('taskRelated') },
|
|
3003
|
+
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,
|
|
3004
|
+
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,
|
|
3005
|
+
)
|
|
3006
|
+
: null,
|
|
3007
|
+
h(
|
|
3008
|
+
Section,
|
|
3009
|
+
{ title: t('taskUsage') },
|
|
3010
|
+
runs.length === 0 && tokens === 0
|
|
3011
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('taskNoUsage'))
|
|
3012
|
+
: h(
|
|
3013
|
+
'div',
|
|
3014
|
+
{ 'data-dsh-bots-ticket-usage': true, style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: 12 } },
|
|
3015
|
+
h(Tile, { attr: 'ticket-tokens', label: t('tileTokens'), value: fmtNum(tokens) }),
|
|
3016
|
+
h(Tile, { attr: 'ticket-cost', label: t('tileCost'), value: fmtCost(cost) }),
|
|
3017
|
+
h(Tile, { attr: 'ticket-runs', label: t('tileRuns'), value: String(runs.length) }),
|
|
3018
|
+
),
|
|
3019
|
+
),
|
|
3020
|
+
),
|
|
3021
|
+
),
|
|
3022
|
+
archived
|
|
3023
|
+
? h('div', { style: { padding: '10px 24px 14px', borderTop: `1px solid ${C.border1}`, background: C.base, fontSize: SMALL, color: C.faint } }, t('taskArchived'))
|
|
3024
|
+
: h(
|
|
3025
|
+
'div',
|
|
3026
|
+
{ style: { padding: '10px 24px 16px', borderTop: `1px solid ${C.border1}`, background: C.base } },
|
|
3027
|
+
h(
|
|
3028
|
+
'div',
|
|
3029
|
+
{ style: { maxWidth: 820 } },
|
|
3030
|
+
h(AskCards, { t, sessionId: v.sessionId, env, onAnswered: () => void reload() }),
|
|
3031
|
+
h(
|
|
3032
|
+
'div',
|
|
3033
|
+
{ style: { display: 'flex', alignItems: 'flex-end', gap: 8, padding: 6, borderRadius: 14, border: `1px solid ${C.border}`, background: C.layer1 } },
|
|
3034
|
+
h('textarea', {
|
|
3035
|
+
'data-dsh-bots-ticket-composer': id,
|
|
3036
|
+
value: text,
|
|
3037
|
+
rows: Math.min(6, Math.max(1, text.split('\n').length)),
|
|
3038
|
+
'aria-label': t('taskMessageLabel'),
|
|
3039
|
+
placeholder: stage === 'question' ? t('taskAnswerPlaceholder', { name }) : t('taskMessagePlaceholder'),
|
|
3040
|
+
onChange: (e) => setText(e.target.value),
|
|
3041
|
+
onKeyDown: (e) => {
|
|
3042
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !e.nativeEvent?.isComposing) {
|
|
3043
|
+
e.preventDefault();
|
|
3044
|
+
send();
|
|
3045
|
+
}
|
|
3046
|
+
},
|
|
3047
|
+
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' },
|
|
3048
|
+
}),
|
|
3049
|
+
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 } }),
|
|
3050
|
+
),
|
|
3051
|
+
h('div', { style: { marginTop: 7, fontSize: TINY, color: C.faint } }, t('taskMessageHint', { name })),
|
|
3052
|
+
),
|
|
3053
|
+
),
|
|
3054
|
+
confirm
|
|
3055
|
+
? h(Confirm, {
|
|
3056
|
+
t,
|
|
3057
|
+
title: t(confirm === 'stop' ? 'taskStopTitle' : 'taskCloseTitle', { title: taskTitle(t, v) }),
|
|
3058
|
+
body: t(confirm === 'stop' ? 'taskStopBody' : 'taskCloseBody', { name }),
|
|
3059
|
+
confirmLabel: t(confirm === 'stop' ? 'taskStop' : 'taskClose'),
|
|
3060
|
+
onClose: () => setConfirm(null),
|
|
3061
|
+
onConfirm: () => act(confirm),
|
|
3062
|
+
})
|
|
3063
|
+
: null,
|
|
3064
|
+
);
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
/** A bot's open tasks (and the last few it finished), on its page. */
|
|
3068
|
+
function BotTasksTab({ t, bot, onOpen = openTicket }) {
|
|
3069
|
+
const { data, failed } = useJson(`tickets?bot=${encodeURIComponent(bot.id)}&limit=50`, STATE_POLL_MS);
|
|
3070
|
+
const name = bot.name || `@${bot.handle}`;
|
|
3071
|
+
const items = (Array.isArray(data?.items) ? data.items : []).filter((r) => r && typeof r.id === 'string' && r.botId === bot.id);
|
|
3072
|
+
const open = items.filter((r) => groupOf(r) !== 'done').sort(newestFirst);
|
|
3073
|
+
const done = items.filter((r) => groupOf(r) === 'done').sort(newestFirst).slice(0, 5);
|
|
3074
|
+
return h(
|
|
3075
|
+
'div',
|
|
3076
|
+
{ className: 'dshb-scroll', 'data-dsh-bots-bot-tasks': bot.id, style: { flex: 1, padding: '20px 24px 28px' } },
|
|
3077
|
+
h(
|
|
3078
|
+
'div',
|
|
3079
|
+
{ style: { maxWidth: 820, display: 'flex', flexDirection: 'column', gap: 26 } },
|
|
3080
|
+
h(
|
|
3081
|
+
Section,
|
|
3082
|
+
{ 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 })) },
|
|
3083
|
+
!data
|
|
3084
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, failed ? t('tasksUnavailable') : t('loading'))
|
|
3085
|
+
: open.length === 0
|
|
3086
|
+
? h('div', { style: { fontSize: SMALL, color: C.faint } }, t('botNoOpenTasks', { name }))
|
|
3087
|
+
: h(TaskList, { rows: open.map((r) => h(TaskRow, { key: r.id, t, row: r, onOpen, showBot: false })) }),
|
|
3088
|
+
),
|
|
3089
|
+
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,
|
|
3090
|
+
),
|
|
3091
|
+
);
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
/** Once, after an upgrade moved an existing team to router mode: what changed and where to switch back. */
|
|
3095
|
+
function RouterNoticeBanner({ t, onOpenDispatcher, onDismiss }) {
|
|
3096
|
+
return h(
|
|
3097
|
+
'div',
|
|
3098
|
+
{ 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) } },
|
|
3099
|
+
h('span', { style: { color: C.label, display: 'inline-flex', paddingTop: 2 } }, Icon.sparkle(16)),
|
|
3100
|
+
h(
|
|
3101
|
+
'div',
|
|
3102
|
+
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
3103
|
+
h('div', { style: { fontWeight: 700, fontSize: SMALL } }, t('routerNoticeTitle')),
|
|
3104
|
+
h('div', { style: { fontSize: SMALL, color: C.muted, lineHeight: 1.6 } }, t('routerNoticeBody')),
|
|
3105
|
+
h(
|
|
3106
|
+
'div',
|
|
3107
|
+
{ style: { display: 'flex', gap: 8, marginTop: 6, flexWrap: 'wrap' } },
|
|
3108
|
+
onOpenDispatcher ? h(Btn, { size: 'sm', onClick: onOpenDispatcher, 'data-dsh-bots-router-notice-open': true }, t('routerNoticeOpen')) : null,
|
|
3109
|
+
h(Btn, { size: 'sm', kind: 'primary', onClick: onDismiss, 'data-dsh-bots-router-notice-dismiss': true }, t('routerNoticeOk')),
|
|
3110
|
+
),
|
|
3111
|
+
),
|
|
3112
|
+
h(Btn, { kind: 'ghost', size: 'sm', icon: Icon.close(13), title: t('close'), onClick: onDismiss }),
|
|
3113
|
+
);
|
|
3114
|
+
}
|
|
3115
|
+
|
|
1981
3116
|
// --- avatar editor -----------------------------------------------------------------
|
|
1982
3117
|
|
|
1983
3118
|
function readDataUrl(file) {
|
|
@@ -2131,6 +3266,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2131
3266
|
avatar: avatarOf(bot.avatar),
|
|
2132
3267
|
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
3268
|
deny: Array.isArray(bot.tools?.deny) ? bot.tools.deny.slice().sort() : [],
|
|
3269
|
+
routerAllow: Array.isArray(bot.tools?.routerAllow) ? bot.tools.routerAllow.map(String).sort() : [],
|
|
2134
3270
|
});
|
|
2135
3271
|
/** A clean avatar value: an image keeps its url, anything else is initials (emoji rows from v0.1 too). */
|
|
2136
3272
|
function avatarOf(a) {
|
|
@@ -2155,6 +3291,86 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2155
3291
|
if (!on) for (const x of ab.available ?? []) next.add(x);
|
|
2156
3292
|
return [...next].sort();
|
|
2157
3293
|
}
|
|
3294
|
+
/**
|
|
3295
|
+
* Tools a router dispatcher goes without unless allowed back: the Host's list when the catalog has one,
|
|
3296
|
+
* else the rule of lib/prompt.mjs (commands, writing and editing files, sub-agents, images, Office).
|
|
3297
|
+
*/
|
|
3298
|
+
function routerDenyOf(catalog) {
|
|
3299
|
+
if (Array.isArray(catalog?.routerDeny)) return catalog.routerDeny.map(String);
|
|
3300
|
+
const abilities = Array.isArray(catalog?.abilities) ? catalog.abilities : [];
|
|
3301
|
+
const of = (id) => abilities.find((a) => a.id === id)?.tools ?? [];
|
|
3302
|
+
return [...new Set([...of('code'), 'write', 'edit', ...of('delegate'), ...of('images'), ...of('office')])];
|
|
3303
|
+
}
|
|
3304
|
+
const sorted = (set) => [...set].sort();
|
|
3305
|
+
/**
|
|
3306
|
+
* The tool lists after switching one ability of a router dispatcher. An ability made only of tools a
|
|
3307
|
+
* router goes without (commands, sub-agents, images, Office) is switched through `routerAllow`, so it
|
|
3308
|
+
* keeps its own setting for hands-on mode. One with other tools too (files) switches as before and
|
|
3309
|
+
* comes back with the router's default; its writing tools are allowed back on their own.
|
|
3310
|
+
*/
|
|
3311
|
+
function toggleRouterAbility(draft, ab, on, routerDeny) {
|
|
3312
|
+
const gated = (ab.available ?? []).filter((x) => routerDeny.has(x));
|
|
3313
|
+
const whole = gated.length > 0 && gated.length === (ab.available ?? []).length;
|
|
3314
|
+
const allow = new Set(draft.routerAllow);
|
|
3315
|
+
if (on) {
|
|
3316
|
+
if (whole) for (const x of gated) allow.add(x);
|
|
3317
|
+
return { deny: toggleAbility(draft.deny, ab, true), routerAllow: sorted(allow) };
|
|
3318
|
+
}
|
|
3319
|
+
for (const x of [...(ab.tools ?? []), ...gated]) allow.delete(x);
|
|
3320
|
+
return { deny: whole ? draft.deny : toggleAbility(draft.deny, ab, false), routerAllow: sorted(allow) };
|
|
3321
|
+
}
|
|
3322
|
+
/** How the dispatcher works: only hand out (router) or also do small things itself (hands-on). A team setting. */
|
|
3323
|
+
function DispatcherMode({ t, name, toast }) {
|
|
3324
|
+
const mode = dispatcherOf();
|
|
3325
|
+
const [busy, setBusy] = useState(false);
|
|
3326
|
+
const choose = (next) => {
|
|
3327
|
+
if (busy || next === mode) return;
|
|
3328
|
+
setBusy(true);
|
|
3329
|
+
postJson('settings', { patch: { dispatcher: next } })
|
|
3330
|
+
.then((r) => {
|
|
3331
|
+
if (r?.ok) {
|
|
3332
|
+
tookSettings(r.settings && typeof r.settings === 'object' ? r.settings : { ...(store.settings?.settings ?? {}), dispatcher: next });
|
|
3333
|
+
toast(t(next === 'hands-on' ? 'modeSavedHandsOn' : 'modeSavedRouter', { name }));
|
|
3334
|
+
void refreshState();
|
|
3335
|
+
} else toast(r?.reason || t('saveFailed'), 'error');
|
|
3336
|
+
})
|
|
3337
|
+
.finally(() => setBusy(false));
|
|
3338
|
+
};
|
|
3339
|
+
const option = (id, title, body) => {
|
|
3340
|
+
const on = mode === id;
|
|
3341
|
+
return h(
|
|
3342
|
+
'button',
|
|
3343
|
+
{
|
|
3344
|
+
key: id,
|
|
3345
|
+
type: 'button',
|
|
3346
|
+
role: 'radio',
|
|
3347
|
+
'aria-checked': on,
|
|
3348
|
+
className: 'dshb-row',
|
|
3349
|
+
'data-active': on,
|
|
3350
|
+
'data-dsh-bots-dispatcher-mode': id,
|
|
3351
|
+
disabled: busy,
|
|
3352
|
+
onClick: () => choose(id),
|
|
3353
|
+
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 },
|
|
3354
|
+
},
|
|
3355
|
+
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),
|
|
3356
|
+
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)),
|
|
3357
|
+
);
|
|
3358
|
+
};
|
|
3359
|
+
return h(
|
|
3360
|
+
'div',
|
|
3361
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
3362
|
+
h(
|
|
3363
|
+
'div',
|
|
3364
|
+
{ role: 'radiogroup', 'aria-label': t('dispatcherMode'), 'data-dsh-bots-dispatcher-modes': mode, style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 10 } },
|
|
3365
|
+
option('router', t('modeRouter'), t('modeRouterBody')),
|
|
3366
|
+
option('hands-on', t('modeHandsOn'), t('modeHandsOnBody')),
|
|
3367
|
+
),
|
|
3368
|
+
// Router mode asked for, but nobody to hand work to yet.
|
|
3369
|
+
mode === 'router' && !routerActiveOf()
|
|
3370
|
+
? 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 }))
|
|
3371
|
+
: null,
|
|
3372
|
+
);
|
|
3373
|
+
}
|
|
2158
3374
|
const ABILITY_ICON = {
|
|
2159
3375
|
web: () => Icon.search(15),
|
|
2160
3376
|
files: () => Icon.edit(15),
|
|
@@ -2168,6 +3384,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2168
3384
|
plugins: () => Icon.puzzle(15),
|
|
2169
3385
|
};
|
|
2170
3386
|
function ProfileTab({ t, bot, toast, catalog }) {
|
|
3387
|
+
// The dispatcher's mode is a team setting; the panel re-renders this tab once it loads.
|
|
3388
|
+
useEffect(() => {
|
|
3389
|
+
void loadOnce('settings', 'settings');
|
|
3390
|
+
}, []);
|
|
2171
3391
|
const [draft, setDraft] = useState(() => profileOf(bot));
|
|
2172
3392
|
const [busy, setBusy] = useState(false);
|
|
2173
3393
|
const [toolQ, setToolQ] = useState('');
|
|
@@ -2187,7 +3407,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2187
3407
|
const save = () => {
|
|
2188
3408
|
if (!valid || busy) return;
|
|
2189
3409
|
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 } };
|
|
3410
|
+
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
3411
|
if (draft.avatar) payload.avatar = avatarOf(draft.avatar);
|
|
2192
3412
|
postJson('save', { bot: payload })
|
|
2193
3413
|
.then((r) => {
|
|
@@ -2242,6 +3462,15 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2242
3462
|
const knownModel = !draft.model || Boolean(chosen);
|
|
2243
3463
|
const efforts = Array.isArray(chosen?.efforts) ? chosen.efforts : [];
|
|
2244
3464
|
const [sources, setSources] = useState(false);
|
|
3465
|
+
// A router dispatcher goes without some tools unless they are allowed back one ability at a time
|
|
3466
|
+
// (only while it routes: the only bot of a team keeps them all).
|
|
3467
|
+
const isPrimary = bot.role === 'primary' || bot.id === store.state?.primaryId;
|
|
3468
|
+
const routing = isPrimary && routerActiveOf();
|
|
3469
|
+
const routerDeny = new Set(routing ? routerDenyOf(catalog) : []);
|
|
3470
|
+
const routerAllow = new Set(draft.routerAllow);
|
|
3471
|
+
const routerBlocked = (names) => names.filter((x) => routerDeny.has(x) && !routerAllow.has(x));
|
|
3472
|
+
const inEffect = routing ? new Set([...draft.deny, ...routerBlocked([...routerDeny])]) : denied;
|
|
3473
|
+
const botLabel = draft.name || bot.name;
|
|
2245
3474
|
return h(
|
|
2246
3475
|
'div',
|
|
2247
3476
|
{ style: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
@@ -2254,7 +3483,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2254
3483
|
h(
|
|
2255
3484
|
Section,
|
|
2256
3485
|
{ 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 }),
|
|
3486
|
+
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
3487
|
),
|
|
2259
3488
|
h(
|
|
2260
3489
|
Section,
|
|
@@ -2276,6 +3505,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2276
3505
|
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
3506
|
),
|
|
2278
3507
|
),
|
|
3508
|
+
isPrimary ? h(Section, { title: t('dispatcherMode'), hint: t('dispatcherModeHint') }, h(DispatcherMode, { t, name: botLabel, toast })) : null,
|
|
2279
3509
|
h(
|
|
2280
3510
|
Section,
|
|
2281
3511
|
{ title: t('persona'), hint: t('personaHint') },
|
|
@@ -2316,18 +3546,22 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2316
3546
|
: null,
|
|
2317
3547
|
),
|
|
2318
3548
|
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,
|
|
3549
|
+
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
3550
|
),
|
|
2320
3551
|
h(
|
|
2321
3552
|
Section,
|
|
2322
|
-
{ title: t('abilities'), hint: t('
|
|
3553
|
+
{ title: t('abilities'), hint: routing ? t('abilitiesRouterHint', { name: botLabel }) : t('abilitiesHint', { name: botLabel }) },
|
|
2323
3554
|
abilities.length === 0
|
|
2324
3555
|
? h('div', { style: { fontSize: SMALL, color: C.faint } }, catalog ? t('noTools') : t('loading'))
|
|
2325
3556
|
: h(
|
|
2326
3557
|
'div',
|
|
2327
3558
|
{ 'data-dsh-bots-abilities': true, style: { display: 'flex', flexDirection: 'column', border: `1px solid ${C.border1}`, borderRadius: 12, overflow: 'hidden', background: C.layer1 } },
|
|
2328
3559
|
abilities.map((ab, i) => {
|
|
2329
|
-
const on = abilityOn(ab,
|
|
3560
|
+
const on = abilityOn(ab, inEffect);
|
|
2330
3561
|
const warn = ab.risky && on;
|
|
3562
|
+
const gated = ab.available.filter((x) => routerDeny.has(x));
|
|
3563
|
+
const blocked = routerBlocked(gated);
|
|
3564
|
+
const whole = gated.length > 0 && gated.length === ab.available.length;
|
|
2331
3565
|
return h(
|
|
2332
3566
|
'div',
|
|
2333
3567
|
{ 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 +3569,24 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2335
3569
|
h(
|
|
2336
3570
|
'div',
|
|
2337
3571
|
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 1 } },
|
|
2338
|
-
h(
|
|
3572
|
+
h(
|
|
3573
|
+
'span',
|
|
3574
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } },
|
|
3575
|
+
h('span', { style: { fontWeight: 600, color: on ? C.primary : C.muted } }, pick(ab.name, lang)),
|
|
3576
|
+
ab.risky ? h(Badge, { color: '#d97706' }, Icon.alert(10), t('risky')) : null,
|
|
3577
|
+
gated.length
|
|
3578
|
+
? blocked.length
|
|
3579
|
+
? h(Badge, { color: C.muted, title: blocked.join(', '), 'data-dsh-bots-router-off': ab.id }, t(whole ? 'routerOff' : 'routerPartOff'))
|
|
3580
|
+
: h(Badge, { color: C.label, title: gated.join(', '), 'data-dsh-bots-router-allowed': ab.id }, t('routerAllowed'))
|
|
3581
|
+
: null,
|
|
3582
|
+
gated.length && blocked.length && !whole && on
|
|
3583
|
+
? 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'))
|
|
3584
|
+
: null,
|
|
3585
|
+
),
|
|
2339
3586
|
h('span', { style: { fontSize: TINY, color: C.muted } }, pick(ab.description, lang)),
|
|
2340
3587
|
),
|
|
2341
3588
|
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 }),
|
|
3589
|
+
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
3590
|
);
|
|
2344
3591
|
}),
|
|
2345
3592
|
),
|
|
@@ -2371,7 +3618,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
2371
3618
|
h(
|
|
2372
3619
|
'span',
|
|
2373
3620
|
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0 } },
|
|
2374
|
-
h('span', { className: 'dshb-mono', style: { fontSize: 12, fontWeight: 600, color: C.primary } }, x.name),
|
|
3621
|
+
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
3622
|
x.description ? h('span', { style: { fontSize: TINY, color: C.faint, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, x.description) : null,
|
|
2376
3623
|
),
|
|
2377
3624
|
),
|
|
@@ -4021,13 +5268,15 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4021
5268
|
|
|
4022
5269
|
// --- detail: header + tabs ------------------------------------------------------------
|
|
4023
5270
|
|
|
4024
|
-
const TABS = ['chat', 'profile', 'memory', 'skills', 'schedules', 'apps'];
|
|
5271
|
+
const TABS = ['chat', 'tasks', 'profile', 'memory', 'skills', 'schedules', 'apps'];
|
|
4025
5272
|
function BotDetail({ t, bot, primaryId, env, toast, catalog, tab, setTab, onDeleted, onSettings }) {
|
|
4026
5273
|
const [menu, setMenu] = useState(false);
|
|
4027
5274
|
const [confirm, setConfirm] = useState(false);
|
|
4028
5275
|
const [opening, setOpening] = useState(false);
|
|
4029
5276
|
const isPrimary = bot.id === primaryId || bot.role === 'primary';
|
|
4030
|
-
|
|
5277
|
+
// Working on a task counts as working, as in the list.
|
|
5278
|
+
const live = liveBot(bot);
|
|
5279
|
+
const status = live.status === 'running' || live.activity || botTaskActivity(bot.id) ? 'running' : (live.status ?? 'offline');
|
|
4031
5280
|
const open = () => {
|
|
4032
5281
|
setOpening(true);
|
|
4033
5282
|
Promise.resolve(env.openBot(bot)).finally(() => setOpening(false));
|
|
@@ -4047,9 +5296,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4047
5296
|
void refreshState();
|
|
4048
5297
|
} else toast(r?.reason || t('actionFailed'), 'error');
|
|
4049
5298
|
});
|
|
4050
|
-
const counts = { skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length, memory: Number(bot.memoryNotes) || 0 };
|
|
5299
|
+
const counts = { tasks: openTaskCount(bot), skills: (bot.skills ?? []).length, apps: (bot.apps ?? []).length, memory: Number(bot.memoryNotes) || 0 };
|
|
4051
5300
|
let body;
|
|
4052
|
-
if (tab === '
|
|
5301
|
+
if (tab === 'tasks') body = h(BotTasksTab, { key: bot.id, t, bot });
|
|
5302
|
+
else if (tab === 'profile') body = h(ProfileTab, { key: bot.id, t, bot, toast, catalog });
|
|
4053
5303
|
else if (tab === 'skills') body = h(SkillsTab, { key: bot.id, t, bot, toast, catalog, setTab, env });
|
|
4054
5304
|
else if (tab === 'schedules') body = h(SchedulesTab, { key: bot.id, t, bot, toast, catalog });
|
|
4055
5305
|
else if (tab === 'apps') body = h(AppsTab, { key: bot.id, t, bot, toast, catalog });
|
|
@@ -4064,7 +5314,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4064
5314
|
h(
|
|
4065
5315
|
'div',
|
|
4066
5316
|
{ 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}`) }),
|
|
5317
|
+
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
5318
|
h(
|
|
4069
5319
|
'div',
|
|
4070
5320
|
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
@@ -4334,12 +5584,22 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4334
5584
|
: null,
|
|
4335
5585
|
);
|
|
4336
5586
|
}
|
|
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
|
|
5587
|
+
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);
|
|
5588
|
+
// Text cells give way (and cut with an ellipsis); numbers never wrap or leave their card.
|
|
5589
|
+
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);
|
|
5590
|
+
/** 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). */
|
|
5591
|
+
const NUM_COLS = [null, 56, 72, 84];
|
|
5592
|
+
const Table = ({ head, rows, attr, cols = NUM_COLS }) =>
|
|
5593
|
+
h(
|
|
5594
|
+
'table',
|
|
5595
|
+
{ [attr]: true, style: { width: '100%', tableLayout: 'fixed', borderCollapse: 'collapse', fontSize: SMALL } },
|
|
5596
|
+
h('colgroup', null, cols.map((w, i) => h('col', { key: i, style: w ? { width: w } : undefined }))),
|
|
5597
|
+
h('thead', null, h('tr', null, head)),
|
|
5598
|
+
h('tbody', null, rows),
|
|
5599
|
+
);
|
|
4340
5600
|
function BotCell({ t, id }) {
|
|
4341
5601
|
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)));
|
|
5602
|
+
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
5603
|
}
|
|
4344
5604
|
function triggerText(t, task) {
|
|
4345
5605
|
if (task.trigger === 'schedule') return t('trigger_schedule');
|
|
@@ -4348,6 +5608,18 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4348
5608
|
return t('trigger_user');
|
|
4349
5609
|
}
|
|
4350
5610
|
|
|
5611
|
+
/** The usage report's rows by task (ticket), read loosely: `{id, title, bot, stage?, runs, tokens, cost}`. */
|
|
5612
|
+
function usageTickets(data) {
|
|
5613
|
+
const rows = Array.isArray(data?.tickets) ? data.tickets : Array.isArray(data?.byTicket) ? data.byTicket : [];
|
|
5614
|
+
return rows
|
|
5615
|
+
.map((r) => (r && typeof r === 'object' ? { ...r, id: str(r.id ?? r.ticket), bot: r.bot ?? r.botId } : null))
|
|
5616
|
+
.filter((r) => r && r.id);
|
|
5617
|
+
}
|
|
5618
|
+
/** The task a run belongs to, when the report says. */
|
|
5619
|
+
const runTicket = (r) => {
|
|
5620
|
+
const v = r?.ticket ?? r?.t;
|
|
5621
|
+
return typeof v === 'string' && v ? v : '';
|
|
5622
|
+
};
|
|
4351
5623
|
function UsageView({ t, bots }) {
|
|
4352
5624
|
const [range, setRange] = useState('7d');
|
|
4353
5625
|
const [bot, setBot] = useState('');
|
|
@@ -4356,6 +5628,10 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4356
5628
|
const tot = data?.totals;
|
|
4357
5629
|
const prev = data?.prev;
|
|
4358
5630
|
const empty = tot && tot.calls === 0;
|
|
5631
|
+
const allTickets = usageTickets(data);
|
|
5632
|
+
const [moreTasks, setMoreTasks] = useState(false);
|
|
5633
|
+
const TASK_ROWS = 8;
|
|
5634
|
+
const tickets = moreTasks ? allTickets : allTickets.slice(0, TASK_ROWS);
|
|
4359
5635
|
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
5636
|
return h(
|
|
4361
5637
|
'div',
|
|
@@ -4381,7 +5657,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4381
5657
|
{ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 12 } },
|
|
4382
5658
|
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
5659
|
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: '
|
|
5660
|
+
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
5661
|
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
5662
|
),
|
|
4387
5663
|
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 +5670,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4394
5670
|
t('byBot'),
|
|
4395
5671
|
h(Table, {
|
|
4396
5672
|
attr: 'data-dsh-bots-usage-bots',
|
|
4397
|
-
head: [th(t('colBot')), th(t('
|
|
5673
|
+
head: [th(t('colBot')), th(t('colRunCount'), true), th(t('colTokens'), true), th(t('colCost'), true)],
|
|
4398
5674
|
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
5675
|
}),
|
|
4400
5676
|
),
|
|
@@ -4407,7 +5683,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4407
5683
|
h(
|
|
4408
5684
|
'tr',
|
|
4409
5685
|
{ 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',
|
|
5686
|
+
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
5687
|
td(String(r.calls), true),
|
|
4412
5688
|
td(fmtNum(r.tokens), true),
|
|
4413
5689
|
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 +5699,44 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4423
5699
|
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
5700
|
}),
|
|
4425
5701
|
),
|
|
5702
|
+
tickets.length
|
|
5703
|
+
? section(
|
|
5704
|
+
t('byTask'),
|
|
5705
|
+
h(
|
|
5706
|
+
'div',
|
|
5707
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0 } },
|
|
5708
|
+
h(Table, {
|
|
5709
|
+
attr: 'data-dsh-bots-usage-tickets',
|
|
5710
|
+
head: [th(t('colTask')), th(t('colRunCount'), true), th(t('colTokens'), true), th(t('colCost'), true)],
|
|
5711
|
+
rows: tickets.map((r) =>
|
|
5712
|
+
h(
|
|
5713
|
+
'tr',
|
|
5714
|
+
{ key: r.id, 'data-dsh-bots-usage-ticket': r.id, onClick: () => openTicket(r.id), style: { cursor: 'pointer' } },
|
|
5715
|
+
td(
|
|
5716
|
+
h(
|
|
5717
|
+
'span',
|
|
5718
|
+
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0 } },
|
|
5719
|
+
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 })),
|
|
5720
|
+
h('span', { style: { fontSize: TINY, color: C.faint } }, botName(t, r.bot)),
|
|
5721
|
+
),
|
|
5722
|
+
),
|
|
5723
|
+
td(String(r.runs ?? 0), true),
|
|
5724
|
+
td(fmtNum(r.tokens), true),
|
|
5725
|
+
td(fmtCost(r.cost), true),
|
|
5726
|
+
),
|
|
5727
|
+
),
|
|
5728
|
+
}),
|
|
5729
|
+
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,
|
|
5730
|
+
),
|
|
5731
|
+
)
|
|
5732
|
+
: null,
|
|
4426
5733
|
data.schedules.length
|
|
4427
5734
|
? section(
|
|
4428
5735
|
t('bySchedule'),
|
|
4429
5736
|
h(Table, {
|
|
4430
5737
|
attr: 'data-dsh-bots-usage-schedules',
|
|
4431
5738
|
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',
|
|
5739
|
+
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
5740
|
}),
|
|
4434
5741
|
)
|
|
4435
5742
|
: null,
|
|
@@ -4437,10 +5744,11 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4437
5744
|
empty || data.tasks.length === 0
|
|
4438
5745
|
? null
|
|
4439
5746
|
: section(
|
|
4440
|
-
t('
|
|
5747
|
+
t('recentRuns'),
|
|
4441
5748
|
h(Table, {
|
|
4442
5749
|
attr: 'data-dsh-bots-usage-tasks',
|
|
4443
|
-
|
|
5750
|
+
cols: [null, 150, 110, 72, 84],
|
|
5751
|
+
head: [th(t('colRun')), th(t('colBot')), th(t('colWhen')), th(t('colTokens'), true), th(t('colCost'), true)],
|
|
4444
5752
|
rows: data.tasks.map((r) =>
|
|
4445
5753
|
h(
|
|
4446
5754
|
'tr',
|
|
@@ -4448,13 +5756,14 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4448
5756
|
td(
|
|
4449
5757
|
h(
|
|
4450
5758
|
'span',
|
|
4451
|
-
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0
|
|
5759
|
+
{ style: { display: 'flex', flexDirection: 'column', minWidth: 0 } },
|
|
4452
5760
|
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: r.title }, r.title),
|
|
4453
5761
|
h(
|
|
4454
5762
|
'span',
|
|
4455
5763
|
{ style: { fontSize: TINY, color: C.faint, display: 'inline-flex', gap: 6, alignItems: 'center' } },
|
|
4456
5764
|
triggerText(t, r),
|
|
4457
5765
|
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,
|
|
5766
|
+
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
5767
|
),
|
|
4459
5768
|
),
|
|
4460
5769
|
),
|
|
@@ -4502,6 +5811,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4502
5811
|
? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('noUsage'))
|
|
4503
5812
|
: h(Table, {
|
|
4504
5813
|
attr: 'data-dsh-bots-price-table',
|
|
5814
|
+
cols: [null, 96, 96, 72],
|
|
4505
5815
|
head: [th(t('colModel')), th(t('priceInput'), true), th(t('priceOutput'), true), th('')],
|
|
4506
5816
|
rows: data.models.map((m) =>
|
|
4507
5817
|
h(
|
|
@@ -4735,19 +6045,28 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4735
6045
|
);
|
|
4736
6046
|
}
|
|
4737
6047
|
|
|
6048
|
+
/** Task limits the Host uses when its settings do not say (lib/tickets.mjs, lib/watchdog.mjs). */
|
|
6049
|
+
const TICKET_DEFAULTS = { maxWorking: 4, stallMinutes: 20, archiveHours: 24 };
|
|
6050
|
+
const numberOr = (v, d, min) => {
|
|
6051
|
+
const n = Number(v);
|
|
6052
|
+
return str(v).trim() !== '' && Number.isFinite(n) ? Math.max(min, n) : d;
|
|
6053
|
+
};
|
|
4738
6054
|
function SettingsModal({ t, catalog, onClose, toast }) {
|
|
4739
6055
|
const [form, setForm] = useState(null);
|
|
4740
6056
|
const [busy, setBusy] = useState(false);
|
|
4741
6057
|
useEffect(() => {
|
|
4742
|
-
void getJson('settings').then((r) => r?.settings && setForm(r.settings));
|
|
6058
|
+
void getJson('settings').then((r) => r?.settings && setForm({ ...r.settings, tickets: { ...TICKET_DEFAULTS, ...(r.settings.tickets ?? {}) }, display: { botMessages: 'line', ...(r.settings.display ?? {}) } }));
|
|
4743
6059
|
}, []);
|
|
4744
6060
|
const set = (part, patch) => setForm((f) => ({ ...f, [part]: { ...f[part], ...patch } }));
|
|
4745
6061
|
const models = Array.isArray(catalog?.models) ? catalog.models : [];
|
|
4746
6062
|
const save = () => {
|
|
4747
6063
|
setBusy(true);
|
|
4748
|
-
|
|
6064
|
+
const tk = form.tickets;
|
|
6065
|
+
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) };
|
|
6066
|
+
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
6067
|
.then((r) => {
|
|
4750
6068
|
if (r?.ok) {
|
|
6069
|
+
tookSettings(r.settings);
|
|
4751
6070
|
toast(t('settingsSaved'));
|
|
4752
6071
|
onClose();
|
|
4753
6072
|
} else toast(r?.reason || t('saveFailed'), 'error');
|
|
@@ -4767,6 +6086,28 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
4767
6086
|
!form
|
|
4768
6087
|
? h('div', { style: { color: C.faint, fontSize: SMALL } }, t('loading'))
|
|
4769
6088
|
: [
|
|
6089
|
+
h(
|
|
6090
|
+
Section,
|
|
6091
|
+
{ key: 'chat', title: t('setChat') },
|
|
6092
|
+
row(
|
|
6093
|
+
t('setBotMessages'),
|
|
6094
|
+
t(`setBotMessagesHint_${form.display.botMessages}`),
|
|
6095
|
+
h(
|
|
6096
|
+
'div',
|
|
6097
|
+
{ className: 'dshb-seg', role: 'radiogroup', 'aria-label': t('setBotMessages'), 'data-dsh-bots-setting': 'botMessages' },
|
|
6098
|
+
['line', 'short', 'full'].map((v) =>
|
|
6099
|
+
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}`)),
|
|
6100
|
+
),
|
|
6101
|
+
),
|
|
6102
|
+
),
|
|
6103
|
+
),
|
|
6104
|
+
h(
|
|
6105
|
+
Section,
|
|
6106
|
+
{ key: 'tasks', title: t('setTasks') },
|
|
6107
|
+
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 } })),
|
|
6108
|
+
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 } })),
|
|
6109
|
+
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 } })),
|
|
6110
|
+
),
|
|
4770
6111
|
h(
|
|
4771
6112
|
Section,
|
|
4772
6113
|
{ key: 'topics', title: t('setTopics') },
|
|
@@ -5494,15 +6835,22 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5494
6835
|
const [hire, setHire] = useState(null); // {team, phase: confirm|start|busy|done|error, primary, result?}
|
|
5495
6836
|
const [primaryTick, setPrimaryTick] = useState(true);
|
|
5496
6837
|
const [settings, setSettings] = useState(false);
|
|
6838
|
+
const [ticketId, setTicketId] = useState(null); // the task shown in the Tasks view
|
|
6839
|
+
const [tasksBot, setTasksBot] = useState(''); // the Tasks view's bot filter when another view asked for it
|
|
6840
|
+
const [noticeGone, setNoticeGone] = useState(false);
|
|
5497
6841
|
const [toast, showToast] = useToast();
|
|
5498
6842
|
const seenNav = useRef(0);
|
|
5499
6843
|
const bots = Array.isArray(s.state?.bots) ? s.state.bots : [];
|
|
5500
6844
|
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.
|
|
6845
|
+
// Another seat (a badge, a tool card, a task card) asked for a bot, a view or a task.
|
|
5502
6846
|
useEffect(() => {
|
|
5503
6847
|
if (s.nav.tick === seenNav.current) return;
|
|
5504
6848
|
seenNav.current = s.nav.tick;
|
|
5505
|
-
if (s.nav.view === '
|
|
6849
|
+
if (s.nav.view === 'tasks') {
|
|
6850
|
+
setView('tasks');
|
|
6851
|
+
setTicketId(s.nav.ticket ?? null);
|
|
6852
|
+
setTasksBot(s.nav.ticket ? '' : (s.nav.botId ?? ''));
|
|
6853
|
+
} else if (s.nav.view === 'activity') setView('activity');
|
|
5506
6854
|
else if (s.nav.botId) {
|
|
5507
6855
|
setSelected(s.nav.botId);
|
|
5508
6856
|
setView('bot');
|
|
@@ -5533,6 +6881,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5533
6881
|
let main;
|
|
5534
6882
|
if (!s.state) {
|
|
5535
6883
|
main = h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', color: C.faint, fontSize: SMALL } }, s.failed ? t('unavailable') : t('loading'));
|
|
6884
|
+
} else if (shownView === 'tasks') {
|
|
6885
|
+
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
6886
|
} else if (shownView === 'activity') {
|
|
5537
6887
|
main = h(ActivityView, { t, bots });
|
|
5538
6888
|
} else if (shownView === 'usage') {
|
|
@@ -5566,8 +6916,29 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5566
6916
|
onMemory: () => setView('memory'),
|
|
5567
6917
|
onSettings: () => setSettings(true),
|
|
5568
6918
|
teamNotes: s.state?.teamNotes ?? 0,
|
|
6919
|
+
onTasks: () => {
|
|
6920
|
+
setView('tasks');
|
|
6921
|
+
setTicketId(null);
|
|
6922
|
+
setTasksBot('');
|
|
6923
|
+
},
|
|
6924
|
+
attention: Array.isArray(s.state?.attention) ? s.state.attention.length : 0,
|
|
6925
|
+
openTasks: bots.reduce((n, b) => n + openTaskCount(b), 0),
|
|
5569
6926
|
}),
|
|
5570
|
-
h(
|
|
6927
|
+
h(
|
|
6928
|
+
'div',
|
|
6929
|
+
{ style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', minHeight: 0 } },
|
|
6930
|
+
!noticeGone && routerNotice.pending(s.state)
|
|
6931
|
+
? h(RouterNoticeBanner, {
|
|
6932
|
+
t,
|
|
6933
|
+
onOpenDispatcher: primaryId ? () => openBotTab(primaryId, 'profile') : null,
|
|
6934
|
+
onDismiss: () => {
|
|
6935
|
+
setNoticeGone(true);
|
|
6936
|
+
void Promise.resolve(routerNotice.dismiss()).then(() => refreshState());
|
|
6937
|
+
},
|
|
6938
|
+
})
|
|
6939
|
+
: null,
|
|
6940
|
+
main,
|
|
6941
|
+
),
|
|
5571
6942
|
creating
|
|
5572
6943
|
? h(NewBotModal, {
|
|
5573
6944
|
t,
|
|
@@ -5588,7 +6959,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5588
6959
|
h(Toast, { toast }),
|
|
5589
6960
|
);
|
|
5590
6961
|
}
|
|
5591
|
-
const nullEnv = { canOpen: () => false, openBot: () => false, openPanel: () => false };
|
|
6962
|
+
const nullEnv = { canOpen: () => false, openBot: () => false, openSession: () => false, openPanel: () => false };
|
|
5592
6963
|
|
|
5593
6964
|
// --- tool views in the conversation -----------------------------------------------------
|
|
5594
6965
|
|
|
@@ -5680,9 +7051,14 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5680
7051
|
const to = faceOf(meta.to, args.to);
|
|
5681
7052
|
const from = meta.from ? faceOf(meta.from) : null;
|
|
5682
7053
|
const delivered = phase === 'result' && !block?.isError;
|
|
7054
|
+
// A delegation opens (or adds to) a task; a worker's message to whoever asked is a report with a status.
|
|
7055
|
+
const ref = meta.ticket && typeof meta.ticket === 'object' ? meta.ticket : null;
|
|
7056
|
+
const ticketId = typeof meta.ticket === 'string' ? meta.ticket : typeof ref?.id === 'string' ? ref.id : typeof args.ticket === 'string' ? args.ticket : '';
|
|
7057
|
+
const report = REPORT_STATUSES.includes(args.status) ? args.status : '';
|
|
7058
|
+
const showTicket = (id) => (typeof props.env?.showTicket === 'function' ? props.env.showTicket(id) : openTicket(id));
|
|
5683
7059
|
return h(
|
|
5684
7060
|
ToolShell,
|
|
5685
|
-
{ t, phase, block, title: t('toolSend'), env: props.env, face: to },
|
|
7061
|
+
{ t, phase, block, title: report ? t('toolReport') : t('toolSend'), env: props.env, face: to },
|
|
5686
7062
|
h(
|
|
5687
7063
|
'div',
|
|
5688
7064
|
{ '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 +7067,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5691
7067
|
{ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: SMALL, minWidth: 0, flexWrap: 'wrap' } },
|
|
5692
7068
|
from ? h(FaceLine, { face: from, size: 18 }) : null,
|
|
5693
7069
|
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 } }, '…'),
|
|
7070
|
+
to ? h(FaceLine, { face: to, size: 18 }) : h('span', { style: { color: C.faint } }, report ? t('requesterShort') : '…'),
|
|
7071
|
+
report ? h(ReportChip, { t, status: report }) : null,
|
|
5695
7072
|
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
7073
|
),
|
|
7074
|
+
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
7075
|
args.text ? h(Clamp, { t, text: args.text, lines: 5, style: { fontSize: SMALL, color: C.primary } }) : null,
|
|
7076
|
+
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
7077
|
),
|
|
5699
7078
|
);
|
|
5700
7079
|
}
|
|
@@ -5815,7 +7194,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5815
7194
|
const t = typeof props.t === 'function' ? props.t : fallbackT;
|
|
5816
7195
|
const s = useStore();
|
|
5817
7196
|
const id = props.sessionId;
|
|
5818
|
-
|
|
7197
|
+
// A task's own conversation (`ticket-<id>`): the badge names its bot and opens the task.
|
|
7198
|
+
const ticketId = /^ticket-(t[a-z0-9]{8})$/.exec(str(id))?.[1] ?? '';
|
|
7199
|
+
useEffect(() => {
|
|
7200
|
+
if (ticketId) void loadTicket(ticketId);
|
|
7201
|
+
}, [ticketId]);
|
|
7202
|
+
const view = ticketId ? (s.tickets.get(ticketId)?.view ?? null) : null;
|
|
7203
|
+
const botId = (id ? s.state?.sessionMap?.[id] : undefined) ?? view?.botId;
|
|
5819
7204
|
const bot = botId ? botById(botId) : null;
|
|
5820
7205
|
if (!bot) return null;
|
|
5821
7206
|
return h(
|
|
@@ -5824,8 +7209,9 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5824
7209
|
type: 'button',
|
|
5825
7210
|
className: 'dshb',
|
|
5826
7211
|
'data-dsh-bots-badge': bot.id,
|
|
5827
|
-
|
|
5828
|
-
|
|
7212
|
+
'data-dsh-bots-badge-task': ticketId || undefined,
|
|
7213
|
+
title: ticketId ? t('taskBadgeTitle', { name: bot.name, title: str(view?.title) || ticketId }) : t('badgeTitle', { name: bot.name }),
|
|
7214
|
+
onClick: () => (ticketId && props.env?.showTicket ? props.env.showTicket(ticketId) : props.env?.showBot?.(bot.id)),
|
|
5829
7215
|
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
7216
|
},
|
|
5831
7217
|
h(Style),
|
|
@@ -5892,6 +7278,49 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
5892
7278
|
chatEmptyTitle: 'Say hi to {name}',
|
|
5893
7279
|
chatEmptyBody: 'Messages you send land in this bot’s own conversation, where it works on them with its persona, skills and apps.',
|
|
5894
7280
|
working: '{name} is working…',
|
|
7281
|
+
workingPlain: 'Working…',
|
|
7282
|
+
liveTotal: 'step {n} · {time} so far',
|
|
7283
|
+
elapsedS: '{s}s',
|
|
7284
|
+
elapsedM: '{m}m {s}s',
|
|
7285
|
+
elapsedH: '{h}h {m}m',
|
|
7286
|
+
avatarDrawing: 'Drawing a new avatar…',
|
|
7287
|
+
act_thinking: 'Thinking',
|
|
7288
|
+
act_writing: 'Writing the reply',
|
|
7289
|
+
act_run: 'Running {detail}',
|
|
7290
|
+
act_run_bare: 'Running a command',
|
|
7291
|
+
act_read: 'Reading {detail}',
|
|
7292
|
+
act_read_bare: 'Reading a file',
|
|
7293
|
+
act_edit: 'Editing {detail}',
|
|
7294
|
+
act_edit_bare: 'Editing a file',
|
|
7295
|
+
act_write: 'Writing {detail}',
|
|
7296
|
+
act_write_bare: 'Writing a file',
|
|
7297
|
+
act_find: 'Looking for {detail}',
|
|
7298
|
+
act_find_bare: 'Looking through files',
|
|
7299
|
+
act_search: 'Searching for “{detail}”',
|
|
7300
|
+
act_search_bare: 'Searching the web',
|
|
7301
|
+
act_fetch: 'Reading {detail}',
|
|
7302
|
+
act_fetch_bare: 'Reading a web page',
|
|
7303
|
+
act_delegate: 'Handing work to {detail}',
|
|
7304
|
+
act_followup: 'Writing to task {detail}',
|
|
7305
|
+
act_report: 'Reporting back',
|
|
7306
|
+
act_ask: 'Asking you',
|
|
7307
|
+
act_draw: 'Drawing a picture',
|
|
7308
|
+
act_helper: 'Helper: {detail}',
|
|
7309
|
+
act_helper_bare: 'Working with a helper',
|
|
7310
|
+
act_skill: 'Using the skill {detail}',
|
|
7311
|
+
act_skill_bare: 'Loading a skill',
|
|
7312
|
+
act_memory: 'Searching memory for “{detail}”',
|
|
7313
|
+
act_memory_bare: 'Searching memory',
|
|
7314
|
+
act_remember: 'Updating memory',
|
|
7315
|
+
act_reply: 'Replying in a chat',
|
|
7316
|
+
act_recall: 'Looking up {detail}',
|
|
7317
|
+
act_recall_bare: 'Looking something up',
|
|
7318
|
+
act_team: 'Updating the team',
|
|
7319
|
+
act_schedule: 'Scheduling',
|
|
7320
|
+
act_plan: 'Updating its plan',
|
|
7321
|
+
act_job: 'Checking a background job',
|
|
7322
|
+
act_office: 'Working on a document',
|
|
7323
|
+
act_tool: 'Using {detail}',
|
|
5895
7324
|
composer: 'Message @{handle}',
|
|
5896
7325
|
composerHint: 'Enter to send · Shift+Enter for a new line',
|
|
5897
7326
|
fullTranscript: 'Full transcript in its conversation',
|
|
@@ -6378,6 +7807,135 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6378
7807
|
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
7808
|
viaChannel: '{app} · {who}',
|
|
6380
7809
|
sentToChannel: 'Also sent to {app}',
|
|
7810
|
+
threadPart: 'thread',
|
|
7811
|
+
threadTopic: 'topic',
|
|
7812
|
+
notSent: 'Not sent',
|
|
7813
|
+
notSentChats: 'Not sent to any chat: this turn involved several ({chats}).',
|
|
7814
|
+
// tasks
|
|
7815
|
+
tasks: 'Tasks',
|
|
7816
|
+
tasksHint: 'Work handed to your bots',
|
|
7817
|
+
tasksNeedYou: '{n} need you',
|
|
7818
|
+
askTitle: '{name} is asking you',
|
|
7819
|
+
askNativeTitle: '{name} is waiting for you in the conversation',
|
|
7820
|
+
askNativeHint: 'Answer this one in the conversation.',
|
|
7821
|
+
askContinued: '{name} went on with other work; your answer still reaches it.',
|
|
7822
|
+
askMulti: 'Choose all that apply',
|
|
7823
|
+
askOtherPlaceholder: 'Or type your own answer',
|
|
7824
|
+
askFreePlaceholder: 'Type your answer',
|
|
7825
|
+
askSubmit: 'Submit',
|
|
7826
|
+
askFailed: 'The answer could not be sent.',
|
|
7827
|
+
askingBadge: '{n} waiting for your answer',
|
|
7828
|
+
askingChip: 'Asks you',
|
|
7829
|
+
tasksInProgress: '{n} in progress',
|
|
7830
|
+
tasksSub: 'Work your bots have taken on. Each task runs in its own conversation, so several move at once.',
|
|
7831
|
+
tasksNeeds: 'Needs you',
|
|
7832
|
+
tasksNeedsEmpty: 'Nothing needs you right now.',
|
|
7833
|
+
tasksProgress: 'In progress',
|
|
7834
|
+
tasksProgressEmpty: 'Nothing is in progress.',
|
|
7835
|
+
tasksDone: 'Recently done',
|
|
7836
|
+
tasksDoneEmpty: 'Nothing finished yet.',
|
|
7837
|
+
tasksUnavailable: 'Could not load the tasks.',
|
|
7838
|
+
tasksEmptyTitle: 'No tasks yet',
|
|
7839
|
+
tasksEmptyBotTitle: 'No tasks for {name} yet',
|
|
7840
|
+
tasksEmptyBody: 'When the dispatcher hands work to a teammate, it shows up here as a task you can follow, answer and stop.',
|
|
7841
|
+
untitledTask: 'Untitled task',
|
|
7842
|
+
openTask: 'Open task',
|
|
7843
|
+
followUpTask: 'Went to its task',
|
|
7844
|
+
followUpHint: 'A follow-up in the chat a task came from goes straight to that task.',
|
|
7845
|
+
taskOf: 'Task · {name}',
|
|
7846
|
+
stage_question: 'Needs your answer',
|
|
7847
|
+
stage_failed: 'Failed',
|
|
7848
|
+
stage_stalled: 'Stuck',
|
|
7849
|
+
stage_queued: 'Queued',
|
|
7850
|
+
stage_working: 'Working',
|
|
7851
|
+
stage_done: 'Done',
|
|
7852
|
+
stage_stopped: 'Stopped',
|
|
7853
|
+
report_progress: 'Progress',
|
|
7854
|
+
report_done: 'Done',
|
|
7855
|
+
report_blocked: 'Blocked',
|
|
7856
|
+
report_question: 'Question',
|
|
7857
|
+
askedByYou: 'asked by you',
|
|
7858
|
+
askedBy: 'asked by {name}',
|
|
7859
|
+
viaPanel: 'Panel',
|
|
7860
|
+
kind_report: 'Report',
|
|
7861
|
+
allTasks: 'All tasks',
|
|
7862
|
+
taskMissing: 'This task is not available. It may have been archived.',
|
|
7863
|
+
taskStarted: 'started {when}',
|
|
7864
|
+
taskNoConversation: 'It has not started yet.',
|
|
7865
|
+
taskRetry: 'Retry',
|
|
7866
|
+
taskClose: 'Mark done',
|
|
7867
|
+
taskStop: 'Stop',
|
|
7868
|
+
taskDid_stop: 'Task stopped.',
|
|
7869
|
+
taskDid_retry: 'Task started again.',
|
|
7870
|
+
taskDid_close: 'Task marked done.',
|
|
7871
|
+
taskStopTitle: 'Stop “{title}”?',
|
|
7872
|
+
taskStopBody: '{name} stops working on it now. You can retry it later.',
|
|
7873
|
+
taskCloseTitle: 'Mark “{title}” done?',
|
|
7874
|
+
taskCloseBody: '{name} stops working on it, and the task counts as done.',
|
|
7875
|
+
taskFactBot: 'Bot',
|
|
7876
|
+
taskFactAsked: 'Asked by',
|
|
7877
|
+
taskFactFrom: 'From',
|
|
7878
|
+
fromPanel: 'The Bots panel',
|
|
7879
|
+
taskFactUpdated: 'Last update',
|
|
7880
|
+
taskAsked: 'What was asked',
|
|
7881
|
+
taskReports: 'Reports',
|
|
7882
|
+
taskNoReports: 'No report yet. {name} reports when it is done, stuck, or has a question.',
|
|
7883
|
+
taskRelated: 'Related tasks',
|
|
7884
|
+
taskParent: 'Part of',
|
|
7885
|
+
taskChildren: 'Sub-tasks ({n})',
|
|
7886
|
+
taskUsage: 'Usage',
|
|
7887
|
+
taskNoUsage: 'No model calls yet.',
|
|
7888
|
+
taskArchived: 'This task is archived. A new message in its chat goes to the dispatcher.',
|
|
7889
|
+
taskMessageLabel: 'Message to this task',
|
|
7890
|
+
taskMessagePlaceholder: 'Add to this task…',
|
|
7891
|
+
taskAnswerPlaceholder: 'Answer {name}…',
|
|
7892
|
+
taskMessageHint: '{name} reads it in the task’s own conversation · Enter to send',
|
|
7893
|
+
taskMessageSent: 'Sent to {name}.',
|
|
7894
|
+
taskBadgeTitle: 'A task of {name}: {title} — open it in Bots',
|
|
7895
|
+
tab_tasks: 'Tasks',
|
|
7896
|
+
botOpenTasks: 'Open tasks',
|
|
7897
|
+
botOpenTasksHint: 'What {name} is working on, each in its own conversation.',
|
|
7898
|
+
allTasksOf: 'All tasks',
|
|
7899
|
+
botNoOpenTasks: '{name} has no open tasks.',
|
|
7900
|
+
toolReport: 'Report',
|
|
7901
|
+
requesterShort: 'whoever asked',
|
|
7902
|
+
// the dispatcher's mode
|
|
7903
|
+
dispatcherMode: 'How it works',
|
|
7904
|
+
dispatcherModeHint: 'For the whole team. Each piece of work the dispatcher hands out becomes a task with its own conversation.',
|
|
7905
|
+
modeRouter: 'Router',
|
|
7906
|
+
modeRouterBody: 'Understands, hands out, reports. Teammates do the work.',
|
|
7907
|
+
modeHandsOn: 'Hands-on',
|
|
7908
|
+
modeHandsOnBody: 'Also does small things itself, as before.',
|
|
7909
|
+
modeSavedRouter: '{name} now only hands out the work.',
|
|
7910
|
+
modeSavedHandsOn: '{name} does small things itself again.',
|
|
7911
|
+
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.',
|
|
7912
|
+
routerWaiting: 'Router mode starts once the team has another bot; until then {name} does the work itself.',
|
|
7913
|
+
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.',
|
|
7914
|
+
routerOff: 'Off in Router mode',
|
|
7915
|
+
routerPartOff: 'Partly off in Router mode',
|
|
7916
|
+
routerAllowed: 'On in Router mode',
|
|
7917
|
+
routerAllowBack: 'Turn back on',
|
|
7918
|
+
routerOffShort: 'off in Router mode',
|
|
7919
|
+
routerNoticeTitle: 'Your dispatcher now hands out the work',
|
|
7920
|
+
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.',
|
|
7921
|
+
routerNoticeOpen: 'Open its profile',
|
|
7922
|
+
routerNoticeOk: 'Got it',
|
|
7923
|
+
setTasks: 'Tasks',
|
|
7924
|
+
setChat: 'Chat',
|
|
7925
|
+
setBotMessages: 'Messages between bots',
|
|
7926
|
+
setBotMessagesHint_line: 'One line each: who hands what to whom, its stage and time. A click opens the task.',
|
|
7927
|
+
setBotMessagesHint_short: 'The one line and the first two lines of the message.',
|
|
7928
|
+
setBotMessagesHint_full: 'The whole message, with the task card of a delegation.',
|
|
7929
|
+
botMessages_line: 'One line',
|
|
7930
|
+
botMessages_short: 'Short',
|
|
7931
|
+
botMessages_full: 'Full',
|
|
7932
|
+
setMaxWorking: 'Tasks worked on at once',
|
|
7933
|
+
setMaxWorkingHint: 'More wait in line. A follow-up from you can use one extra.',
|
|
7934
|
+
setStall: 'Minutes before a quiet task counts as stuck',
|
|
7935
|
+
setStallHint: 'A working task quiet this long is asked for a report; still quiet after that, it is marked stuck.',
|
|
7936
|
+
setArchive: 'Hours before a finished task’s conversation is archived',
|
|
7937
|
+
usageAllTasks: 'Show all {n} tasks',
|
|
7938
|
+
setArchiveHint: 'Until then, a new message in its chat thread picks the task up again.',
|
|
6381
7939
|
// Usage, memory, topics, settings, model sources
|
|
6382
7940
|
settings: 'Settings',
|
|
6383
7941
|
usage: 'Usage',
|
|
@@ -6396,7 +7954,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6396
7954
|
tileCacheRate: '{pct}% of input from cache',
|
|
6397
7955
|
tileCost: 'Estimated cost',
|
|
6398
7956
|
tileUnpriced: '{tokens} tokens have no price',
|
|
6399
|
-
|
|
7957
|
+
tileRuns: 'Runs',
|
|
6400
7958
|
tileCalls: 'Model calls',
|
|
6401
7959
|
tileInOut: '{input} in · {output} out',
|
|
6402
7960
|
vsPrev: '{delta} vs the period before',
|
|
@@ -6405,10 +7963,12 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6405
7963
|
byModel: 'By model',
|
|
6406
7964
|
byKind: 'By kind of work',
|
|
6407
7965
|
bySchedule: 'Scheduled tasks',
|
|
6408
|
-
|
|
7966
|
+
recentRuns: 'Recent runs',
|
|
7967
|
+
byTask: 'By task',
|
|
6409
7968
|
colBot: 'Bot',
|
|
6410
7969
|
colTask: 'Task',
|
|
6411
|
-
|
|
7970
|
+
colRunCount: 'Runs',
|
|
7971
|
+
colRun: 'Run',
|
|
6412
7972
|
colTokens: 'Tokens',
|
|
6413
7973
|
colCost: 'Cost',
|
|
6414
7974
|
colCalls: 'Calls',
|
|
@@ -6464,8 +8024,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6464
8024
|
noJournal: 'No finished tasks yet.',
|
|
6465
8025
|
topicsTitle: 'Topics',
|
|
6466
8026
|
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 ·
|
|
8027
|
+
topicNow: 'Current topic: started {when} · runs: {n} · last prompt {ctx} tokens',
|
|
8028
|
+
topicShort: 'This topic: {ctx} context · runs: {n}',
|
|
6469
8029
|
newTopic: 'New topic',
|
|
6470
8030
|
newTopicHint: 'Start a fresh conversation; memory carries over. You can also send /new.',
|
|
6471
8031
|
newTopicDone: '{name} starts a new topic',
|
|
@@ -6473,7 +8033,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6473
8033
|
topicReason_manual: 'started by you',
|
|
6474
8034
|
topicReason_idle: 'after a quiet spell',
|
|
6475
8035
|
topicReason_context: 'the conversation grew large',
|
|
6476
|
-
pastTopic: '{from} – {to} ·
|
|
8036
|
+
pastTopic: '{from} – {to} · runs: {n}',
|
|
6477
8037
|
kind_topic: 'New topic',
|
|
6478
8038
|
teamMemoryTitle: 'Team memory',
|
|
6479
8039
|
teamMemoryHint: '{n} shared notes · daily digest',
|
|
@@ -6595,6 +8155,49 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
6595
8155
|
chatEmptyTitle: '和 {name} 打个招呼',
|
|
6596
8156
|
chatEmptyBody: '你发的消息会进入这个 Bot 自己的会话,它会用自己的人设、技能和应用来处理。',
|
|
6597
8157
|
working: '{name} 正在工作…',
|
|
8158
|
+
workingPlain: '工作中…',
|
|
8159
|
+
liveTotal: '第 {n} 步 · 已用 {time}',
|
|
8160
|
+
elapsedS: '{s} 秒',
|
|
8161
|
+
elapsedM: '{m} 分 {s} 秒',
|
|
8162
|
+
elapsedH: '{h} 小时 {m} 分',
|
|
8163
|
+
avatarDrawing: '正在画新头像…',
|
|
8164
|
+
act_thinking: '思考中',
|
|
8165
|
+
act_writing: '正在写回复',
|
|
8166
|
+
act_run: '运行 {detail}',
|
|
8167
|
+
act_run_bare: '运行命令',
|
|
8168
|
+
act_read: '读取 {detail}',
|
|
8169
|
+
act_read_bare: '读取文件',
|
|
8170
|
+
act_edit: '修改 {detail}',
|
|
8171
|
+
act_edit_bare: '修改文件',
|
|
8172
|
+
act_write: '写入 {detail}',
|
|
8173
|
+
act_write_bare: '写文件',
|
|
8174
|
+
act_find: '查找 {detail}',
|
|
8175
|
+
act_find_bare: '查找文件',
|
|
8176
|
+
act_search: '搜索“{detail}”',
|
|
8177
|
+
act_search_bare: '联网搜索',
|
|
8178
|
+
act_fetch: '阅读 {detail}',
|
|
8179
|
+
act_fetch_bare: '阅读网页',
|
|
8180
|
+
act_delegate: '把工作交给 {detail}',
|
|
8181
|
+
act_followup: '给任务 {detail} 发消息',
|
|
8182
|
+
act_report: '汇报进展',
|
|
8183
|
+
act_ask: '在问你',
|
|
8184
|
+
act_draw: '画图中',
|
|
8185
|
+
act_helper: '助手:{detail}',
|
|
8186
|
+
act_helper_bare: '让助手帮忙',
|
|
8187
|
+
act_skill: '使用技能 {detail}',
|
|
8188
|
+
act_skill_bare: '加载技能',
|
|
8189
|
+
act_memory: '搜索记忆“{detail}”',
|
|
8190
|
+
act_memory_bare: '搜索记忆',
|
|
8191
|
+
act_remember: '更新记忆',
|
|
8192
|
+
act_reply: '回复聊天',
|
|
8193
|
+
act_recall: '查阅 {detail}',
|
|
8194
|
+
act_recall_bare: '查阅记录',
|
|
8195
|
+
act_team: '调整团队',
|
|
8196
|
+
act_schedule: '安排定时任务',
|
|
8197
|
+
act_plan: '更新计划',
|
|
8198
|
+
act_job: '查看后台任务',
|
|
8199
|
+
act_office: '处理文档',
|
|
8200
|
+
act_tool: '使用 {detail}',
|
|
6598
8201
|
composer: '给 @{handle} 发消息',
|
|
6599
8202
|
composerHint: 'Enter 发送 · Shift+Enter 换行',
|
|
6600
8203
|
fullTranscript: '完整记录在它的会话里',
|
|
@@ -7070,6 +8673,135 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7070
8673
|
channelPrivate: '只有配对过的人能找到团队,其他人一律忽略(每天最多回一句“这是私人 Bot”)。在群里,只有 @ 它或回复它时才会回答。',
|
|
7071
8674
|
viaChannel: '{app} · {who}',
|
|
7072
8675
|
sentToChannel: '也已发到 {app}',
|
|
8676
|
+
threadPart: '话题',
|
|
8677
|
+
threadTopic: '话题',
|
|
8678
|
+
notSent: '未发出',
|
|
8679
|
+
notSentChats: '没有发到任何聊天:这一轮涉及多个聊天({chats})。',
|
|
8680
|
+
// tasks
|
|
8681
|
+
tasks: '任务',
|
|
8682
|
+
tasksHint: '交给 Bot 们的工作',
|
|
8683
|
+
tasksNeedYou: '{n} 个等你处理',
|
|
8684
|
+
askTitle: '{name} 在问你',
|
|
8685
|
+
askNativeTitle: '{name} 在对话里等你决定',
|
|
8686
|
+
askNativeHint: '这一项请在对话里回答。',
|
|
8687
|
+
askContinued: '{name} 先去做别的了,你的回答仍会送到。',
|
|
8688
|
+
askMulti: '可多选',
|
|
8689
|
+
askOtherPlaceholder: '或者输入你自己的回答',
|
|
8690
|
+
askFreePlaceholder: '输入你的回答',
|
|
8691
|
+
askSubmit: '提交',
|
|
8692
|
+
askFailed: '回答没有发出去。',
|
|
8693
|
+
askingBadge: '{n} 个问题等你回答',
|
|
8694
|
+
askingChip: '在问你',
|
|
8695
|
+
tasksInProgress: '{n} 个进行中',
|
|
8696
|
+
tasksSub: 'Bot 们接手的工作。每个任务在自己的会话里进行,几件事可以同时推进。',
|
|
8697
|
+
tasksNeeds: '需要你处理',
|
|
8698
|
+
tasksNeedsEmpty: '现在没有需要你处理的。',
|
|
8699
|
+
tasksProgress: '进行中',
|
|
8700
|
+
tasksProgressEmpty: '没有进行中的任务。',
|
|
8701
|
+
tasksDone: '最近完成',
|
|
8702
|
+
tasksDoneEmpty: '还没有完成的任务。',
|
|
8703
|
+
tasksUnavailable: '没能加载任务。',
|
|
8704
|
+
tasksEmptyTitle: '还没有任务',
|
|
8705
|
+
tasksEmptyBotTitle: '{name} 还没有任务',
|
|
8706
|
+
tasksEmptyBody: '调度者把工作交给队友时,这里会出现一个任务,你可以跟进、回答或叫停。',
|
|
8707
|
+
untitledTask: '未命名任务',
|
|
8708
|
+
openTask: '打开任务',
|
|
8709
|
+
followUpTask: '已交给所属任务',
|
|
8710
|
+
followUpHint: '在任务来源的聊天里跟进,消息会直接交给那个任务。',
|
|
8711
|
+
taskOf: '任务 · {name}',
|
|
8712
|
+
stage_question: '等你回答',
|
|
8713
|
+
stage_failed: '失败',
|
|
8714
|
+
stage_stalled: '卡住了',
|
|
8715
|
+
stage_queued: '排队中',
|
|
8716
|
+
stage_working: '进行中',
|
|
8717
|
+
stage_done: '已完成',
|
|
8718
|
+
stage_stopped: '已停止',
|
|
8719
|
+
report_progress: '进展',
|
|
8720
|
+
report_done: '完成',
|
|
8721
|
+
report_blocked: '受阻',
|
|
8722
|
+
report_question: '提问',
|
|
8723
|
+
askedByYou: '你发起',
|
|
8724
|
+
askedBy: '{name} 发起',
|
|
8725
|
+
viaPanel: '面板',
|
|
8726
|
+
kind_report: '汇报',
|
|
8727
|
+
allTasks: '全部任务',
|
|
8728
|
+
taskMissing: '这个任务不可用,可能已经归档。',
|
|
8729
|
+
taskStarted: '开始于{when}',
|
|
8730
|
+
taskNoConversation: '还没开始。',
|
|
8731
|
+
taskRetry: '重试',
|
|
8732
|
+
taskClose: '标为完成',
|
|
8733
|
+
taskStop: '停止',
|
|
8734
|
+
taskDid_stop: '任务已停止。',
|
|
8735
|
+
taskDid_retry: '任务已重新开始。',
|
|
8736
|
+
taskDid_close: '任务已标为完成。',
|
|
8737
|
+
taskStopTitle: '停止“{title}”?',
|
|
8738
|
+
taskStopBody: '{name} 会马上停下这件事,之后可以重试。',
|
|
8739
|
+
taskCloseTitle: '把“{title}”标为完成?',
|
|
8740
|
+
taskCloseBody: '{name} 会停下这件事,任务算作完成。',
|
|
8741
|
+
taskFactBot: '执行的 Bot',
|
|
8742
|
+
taskFactAsked: '发起方',
|
|
8743
|
+
taskFactFrom: '来源',
|
|
8744
|
+
fromPanel: 'Bots 面板',
|
|
8745
|
+
taskFactUpdated: '最近更新',
|
|
8746
|
+
taskAsked: '交代的内容',
|
|
8747
|
+
taskReports: '汇报',
|
|
8748
|
+
taskNoReports: '还没有汇报。{name} 完成、卡住或有问题时会汇报。',
|
|
8749
|
+
taskRelated: '相关任务',
|
|
8750
|
+
taskParent: '所属任务',
|
|
8751
|
+
taskChildren: '子任务({n})',
|
|
8752
|
+
taskUsage: '用量',
|
|
8753
|
+
taskNoUsage: '还没有模型调用。',
|
|
8754
|
+
taskArchived: '这个任务已归档。它所在聊天里的新消息会交给调度者。',
|
|
8755
|
+
taskMessageLabel: '给这个任务发消息',
|
|
8756
|
+
taskMessagePlaceholder: '补充点什么…',
|
|
8757
|
+
taskAnswerPlaceholder: '回答 {name}…',
|
|
8758
|
+
taskMessageHint: '{name} 会在这个任务自己的会话里看到 · Enter 发送',
|
|
8759
|
+
taskMessageSent: '已发给 {name}。',
|
|
8760
|
+
taskBadgeTitle: '{name} 的任务:{title}——在 Bots 中打开',
|
|
8761
|
+
tab_tasks: '任务',
|
|
8762
|
+
botOpenTasks: '进行中的任务',
|
|
8763
|
+
botOpenTasksHint: '{name} 手上的工作,每件在自己的会话里进行。',
|
|
8764
|
+
allTasksOf: '全部任务',
|
|
8765
|
+
botNoOpenTasks: '{name} 手上没有进行中的任务。',
|
|
8766
|
+
toolReport: '汇报',
|
|
8767
|
+
requesterShort: '发起方',
|
|
8768
|
+
// the dispatcher's mode
|
|
8769
|
+
dispatcherMode: '调度方式',
|
|
8770
|
+
dispatcherModeHint: '对整个团队生效。调度者分出去的每件工作都是一个任务,有自己的会话。',
|
|
8771
|
+
modeRouter: '只调度',
|
|
8772
|
+
modeRouterBody: '听懂、分派、汇报,具体工作交给队友。',
|
|
8773
|
+
modeHandsOn: '亲自动手',
|
|
8774
|
+
modeHandsOnBody: '小事自己顺手做掉,和以前一样。',
|
|
8775
|
+
modeSavedRouter: '{name} 现在只负责分派。',
|
|
8776
|
+
modeSavedHandsOn: '{name} 又会自己做小事了。',
|
|
8777
|
+
routerModelHint: '只调度时它只负责听懂、分派、汇报,用轻量、快速的模型就够了,每次请求都更快、更省。',
|
|
8778
|
+
routerWaiting: '团队里再有一个 Bot 后才开始只调度,在此之前 {name} 自己动手。',
|
|
8779
|
+
abilitiesRouterHint: '{name} 能用 Harness 内置工具做哪些事。只调度时它不执行命令、不写文件、不用子代理、不作图也不做 Office 文档;确实需要时可以在下面逐项打开。',
|
|
8780
|
+
routerOff: '只调度时关闭',
|
|
8781
|
+
routerPartOff: '只调度时部分关闭',
|
|
8782
|
+
routerAllowed: '只调度时也可用',
|
|
8783
|
+
routerAllowBack: '重新打开',
|
|
8784
|
+
routerOffShort: '只调度时关闭',
|
|
8785
|
+
routerNoticeTitle: '调度者现在只负责分派',
|
|
8786
|
+
routerNoticeBody: '它会听懂请求、把每件事作为任务交给队友并汇报结果;每个任务在自己的会话里进行,几件事可以同时推进。想让它像以前一样顺手做小事,打开它的资料页,把「调度方式」改成「亲自动手」。',
|
|
8787
|
+
routerNoticeOpen: '打开它的资料页',
|
|
8788
|
+
routerNoticeOk: '知道了',
|
|
8789
|
+
setTasks: '任务',
|
|
8790
|
+
setChat: '聊天',
|
|
8791
|
+
setBotMessages: 'Bot 之间的消息',
|
|
8792
|
+
setBotMessagesHint_line: '每条一行:谁把什么交给谁、进度和时间。点一下打开任务。',
|
|
8793
|
+
setBotMessagesHint_short: '一行摘要,再加消息的前两行。',
|
|
8794
|
+
setBotMessagesHint_full: '完整消息,委派附任务卡片。',
|
|
8795
|
+
botMessages_line: '一行',
|
|
8796
|
+
botMessages_short: '简短',
|
|
8797
|
+
botMessages_full: '完整',
|
|
8798
|
+
setMaxWorking: '同时进行的任务数',
|
|
8799
|
+
setMaxWorkingHint: '多出来的排队等候。你的跟进消息可以多占一个名额。',
|
|
8800
|
+
setStall: '多少分钟没动静算卡住',
|
|
8801
|
+
setStallHint: '进行中的任务这么久没动静,先请它汇报;之后仍没动静就标为卡住。',
|
|
8802
|
+
setArchive: '任务完成多少小时后归档会话',
|
|
8803
|
+
usageAllTasks: '显示全部 {n} 个任务',
|
|
8804
|
+
setArchiveHint: '在此之前,它所在话题或回复串里的新消息会让这个任务继续。',
|
|
7073
8805
|
// 用量、记忆、话题、设置、模型来源
|
|
7074
8806
|
settings: '设置',
|
|
7075
8807
|
usage: '用量',
|
|
@@ -7088,7 +8820,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7088
8820
|
tileCacheRate: '{pct}% 的输入命中缓存',
|
|
7089
8821
|
tileCost: '估算费用',
|
|
7090
8822
|
tileUnpriced: '{tokens} tokens 没有价格',
|
|
7091
|
-
|
|
8823
|
+
tileRuns: '回合',
|
|
7092
8824
|
tileCalls: '模型调用',
|
|
7093
8825
|
tileInOut: '输入 {input} · 输出 {output}',
|
|
7094
8826
|
vsPrev: '比上一期 {delta}',
|
|
@@ -7097,10 +8829,12 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7097
8829
|
byModel: '按模型',
|
|
7098
8830
|
byKind: '按用途',
|
|
7099
8831
|
bySchedule: '定时任务',
|
|
7100
|
-
|
|
8832
|
+
recentRuns: '最近的回合',
|
|
8833
|
+
byTask: '按任务',
|
|
7101
8834
|
colBot: 'Bot',
|
|
7102
8835
|
colTask: '任务',
|
|
7103
|
-
|
|
8836
|
+
colRunCount: '回合',
|
|
8837
|
+
colRun: '回合',
|
|
7104
8838
|
colTokens: 'Tokens',
|
|
7105
8839
|
colCost: '费用',
|
|
7106
8840
|
colCalls: '调用',
|
|
@@ -7156,8 +8890,8 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7156
8890
|
noJournal: '还没有完成的任务。',
|
|
7157
8891
|
topicsTitle: '话题',
|
|
7158
8892
|
topicsHint: '每个话题是一段新对话,上下文不会无限变长。发送 /new、闲置较久,或对话变得很长时(见设置)会开始新话题;记忆会延续下去。',
|
|
7159
|
-
topicNow: '当前话题:开始于{when} · {n}
|
|
7160
|
-
topicShort: '本话题:上下文 {ctx} ·
|
|
8893
|
+
topicNow: '当前话题:开始于{when} · {n} 个回合 · 最近一次提示 {ctx} tokens',
|
|
8894
|
+
topicShort: '本话题:上下文 {ctx} · 已进行 {n} 个回合',
|
|
7161
8895
|
newTopic: '新话题',
|
|
7162
8896
|
newTopicHint: '开始一段新对话,记忆会保留。也可以直接发送 /new。',
|
|
7163
8897
|
newTopicDone: '{name} 开始了新话题',
|
|
@@ -7165,7 +8899,7 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7165
8899
|
topicReason_manual: '你开启的',
|
|
7166
8900
|
topicReason_idle: '闲置后自动开启',
|
|
7167
8901
|
topicReason_context: '对话太长自动开启',
|
|
7168
|
-
pastTopic: '{from} – {to} · {n}
|
|
8902
|
+
pastTopic: '{from} – {to} · {n} 个回合',
|
|
7169
8903
|
kind_topic: '新话题',
|
|
7170
8904
|
teamMemoryTitle: '团队记忆',
|
|
7171
8905
|
teamMemoryHint: '{n} 条共享笔记 · 每日摘要',
|
|
@@ -7319,6 +9053,13 @@ a.dshb-lc:hover{border-color:${C.border};background:${C.layer2}}
|
|
|
7319
9053
|
navigate(botId);
|
|
7320
9054
|
return openPanel();
|
|
7321
9055
|
},
|
|
9056
|
+
/** Show a Harness conversation (a task's own one); false when it cannot. */
|
|
9057
|
+
openSession: (id) => openSession(id),
|
|
9058
|
+
/** One task's detail in the panel. */
|
|
9059
|
+
showTicket: (id) => {
|
|
9060
|
+
openTicket(id);
|
|
9061
|
+
return openPanel();
|
|
9062
|
+
},
|
|
7322
9063
|
openPanel,
|
|
7323
9064
|
sessionTitle: (id) => {
|
|
7324
9065
|
try {
|