-
Notifications
You must be signed in to change notification settings - Fork 319
Expand file tree
/
Copy pathMessageLog.tsx
More file actions
495 lines (466 loc) · 17.5 KB
/
MessageLog.tsx
File metadata and controls
495 lines (466 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
import { Meta, Title } from '@solidjs/meta';
import { useNavigate, useParams } from '@solidjs/router';
import {
createEffect,
createMemo,
createResource,
createSignal,
For,
on,
onCleanup,
onMount,
Show,
type Component,
} from 'solid-js';
import ErrorState from '../components/ErrorState.jsx';
import FeedbackModal from '../components/FeedbackModal.jsx';
import MessageTable from '../components/MessageTable.jsx';
import Pagination from '../components/Pagination.jsx';
import Select from '../components/Select.jsx';
import SetupModal from '../components/SetupModal.jsx';
import { DETAILED_COLUMNS, type MessageRow } from '../components/message-table-types.js';
import { agentDisplayName } from '../services/agent-display-name.js';
import { agentPlatform, agentCategory } from '../services/agent-platform-store.js';
import {
getCustomProviders,
getMessages,
getRoutingStatus,
setMessageFeedback,
clearMessageFeedback,
type CustomProviderData,
} from '../services/api.js';
import { createCursorPagination } from '../services/cursor-pagination.js';
import { preloadModelDisplayNames } from '../services/model-display.js';
import { PROVIDERS } from '../services/providers.js';
import { checkIsLocalMode } from '../services/setup-status.js';
import { pingCount } from '../services/sse.js';
import '../styles/overview.css';
interface MessagesData {
items: MessageRow[];
next_cursor: string | null;
total_count: number;
providers: string[];
}
const MessageLog: Component = () => {
const params = useParams<{ agentName: string }>();
const navigate = useNavigate();
preloadModelDisplayNames();
const [isLocal, setIsLocal] = createSignal(false);
onMount(() => {
checkIsLocalMode().then(setIsLocal);
});
const columns = () =>
isLocal() ? DETAILED_COLUMNS.filter((c) => c !== 'feedback') : DETAILED_COLUMNS;
const [providerFilter, setProviderFilter] = createSignal('');
const [costMin, setCostMin] = createSignal('');
const [costMax, setCostMax] = createSignal('');
const [setupOpen, setSetupOpen] = createSignal(false);
const [setupCompleted] = createSignal(
!!localStorage.getItem(`setup_completed_${params.agentName}`),
);
const [feedbackModalOpen, setFeedbackModalOpen] = createSignal(false);
const [feedbackMessageId, setFeedbackMessageId] = createSignal('');
const [feedbackOverrides, setFeedbackOverrides] = createSignal<Record<string, string | null>>({});
const applyFeedbackOverrides = (items: MessageRow[]): MessageRow[] => {
const overrides = feedbackOverrides();
return items.map((item) =>
item.id in overrides ? { ...item, feedback_rating: overrides[item.id] ?? undefined } : item,
);
};
const handleFeedbackLike = (id: string) => {
setFeedbackOverrides((prev) => ({ ...prev, [id]: 'like' }));
setMessageFeedback(id, { rating: 'like' }).catch(() => {
setFeedbackOverrides((prev) => {
const next = { ...prev };
delete next[id];
return next;
});
});
};
const handleFeedbackDislike = (id: string) => {
setFeedbackOverrides((prev) => ({ ...prev, [id]: 'dislike' }));
setFeedbackMessageId(id);
setFeedbackModalOpen(true);
setMessageFeedback(id, { rating: 'dislike' }).catch(() => {
setFeedbackOverrides((prev) => {
const next = { ...prev };
delete next[id];
return next;
});
});
};
const handleFeedbackClear = (id: string) => {
setFeedbackOverrides((prev) => ({ ...prev, [id]: null }));
clearMessageFeedback(id).catch(() => {
setFeedbackOverrides((prev) => {
const next = { ...prev };
delete next[id];
return next;
});
});
};
const handleFeedbackSubmit = (tags: string[], details: string) => {
const id = feedbackMessageId();
if (id) {
setMessageFeedback(id, { rating: 'dislike', tags, details }).catch(() => {
setFeedbackOverrides((prev) => {
const next = { ...prev };
delete next[id];
return next;
});
});
}
setFeedbackModalOpen(false);
};
const [customProviders] = createResource(
() => params.agentName,
(name) => getCustomProviders(decodeURIComponent(name)),
);
const [routingStatus] = createResource(
() => params.agentName,
(name) => getRoutingStatus(decodeURIComponent(name)),
);
const hasProviders = () => routingStatus()?.enabled === true;
/** Map custom:<uuid> → provider display name */
const customProviderName = (model: string): string | undefined => {
const match = model.match(/^custom:([^/]+)\//);
if (!match) return undefined;
const id = match[1];
return customProviders()?.find((cp: CustomProviderData) => cp.id === id)?.name;
};
const pager = createCursorPagination(50);
let costMinTimer: ReturnType<typeof setTimeout>;
let costMaxTimer: ReturnType<typeof setTimeout>;
onCleanup(() => {
clearTimeout(costMinTimer);
clearTimeout(costMaxTimer);
});
const debouncedSetCostMin = (val: string) => {
clearTimeout(costMinTimer);
costMinTimer = setTimeout(() => setCostMin(val), 400);
};
const debouncedSetCostMax = (val: string) => {
clearTimeout(costMaxTimer);
costMaxTimer = setTimeout(() => setCostMax(val), 400);
};
createEffect(on([providerFilter, costMin, costMax], () => pager.resetPage(), { defer: true }));
const [data, { refetch }] = createResource(
() => ({
provider: providerFilter(),
costMin: costMin(),
costMax: costMax(),
agentName: params.agentName,
_ping: pingCount(),
cursor: pager.currentCursor(),
limit: pager.pageSize,
}),
(p) => {
const q: Record<string, string> = {};
if (p.provider) q.provider = p.provider;
if (p.costMin) q.cost_min = p.costMin;
if (p.costMax) q.cost_max = p.costMax;
if (p.agentName) q.agent_name = p.agentName;
if (p.cursor) q.cursor = p.cursor;
q.limit = String(p.limit);
return getMessages(q) as Promise<MessagesData>;
},
);
createEffect(
on(
() => data(),
(d) => {
if (d) pager.recordResponse(d.next_cursor);
},
),
);
const hasActiveFilters = () => providerFilter() !== '' || costMin() !== '' || costMax() !== '';
const hasNoData = () => {
const d = data();
return d && d.total_count === 0;
};
const showEmptyState = () => hasNoData() && !hasActiveFilters() && !hasProviders();
const isFilteredEmpty = () => hasNoData() && hasActiveFilters();
const showMessages = () => !hasNoData() || (hasProviders() && !hasActiveFilters());
const clearFilters = () => {
setProviderFilter('');
setCostMin('');
setCostMax('');
};
/** Resolve provider ID to display name */
const providerDisplayName = (id: string): string => {
const prov = PROVIDERS.find((p) => p.id === id);
return prov?.name ?? id;
};
const providerOptions = createMemo(() => [
{ label: 'All providers', value: '' },
...(data()?.providers ?? []).map((id) => ({
label: providerDisplayName(id),
value: id,
})),
]);
const scrollToFallbackSuccess = (model: string) => {
const items = data()?.items;
if (!items) return;
const success = items.find((i) => i.fallback_from_model === model && i.status === 'ok');
if (!success) return;
const el = document.getElementById(`msg-${success.id}`);
if (!el) return;
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
el.classList.add('msg-highlight');
setTimeout(() => el.classList.remove('msg-highlight'), 2000);
};
return (
<div class="container--full">
<Title>
{agentDisplayName() ?? decodeURIComponent(params.agentName)} Messages - Manifest
</Title>
<Meta
name="description"
content={`Browse all messages sent and received by ${agentDisplayName() ?? decodeURIComponent(params.agentName)}. Filter by provider or cost.`}
/>
<div class="page-header">
<div>
<h1>Messages</h1>
<span class="breadcrumb">Full log of every LLM call. Filter by provider or cost.</span>
</div>
<div class="header-controls">
<Show when={!showEmptyState()}>
<Select
value={providerFilter()}
onChange={setProviderFilter}
options={providerOptions()}
/>
<div class="cost-range-filter">
<input
type="number"
class="cost-range-filter__input"
placeholder="Min $"
aria-label="Minimum cost filter"
min="0"
step="0.01"
value={costMin()}
onInput={(e) => debouncedSetCostMin(e.currentTarget.value)}
/>
<span class="cost-range-filter__sep">–</span>
<input
type="number"
class="cost-range-filter__input"
placeholder="Max $"
aria-label="Maximum cost filter"
min="0"
step="0.01"
value={costMax()}
onInput={(e) => debouncedSetCostMax(e.currentTarget.value)}
/>
</div>
</Show>
<Show when={showEmptyState() && !setupCompleted()}>
<button class="btn btn--primary btn--sm" onClick={() => setSetupOpen(true)}>
Set up agent
</button>
</Show>
</div>
</div>
<Show
when={data() !== undefined || !data.loading}
fallback={
<div class="panel">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--gap-lg);">
<div class="skeleton skeleton--text" style="width: 80px; height: 16px;" />
<div class="skeleton skeleton--text" style="width: 60px; height: 14px;" />
</div>
<div class="data-table-scroll">
<table class="data-table">
<thead>
<tr>
<th>Date</th>
<th>Message</th>
<th>Cost</th>
<th>Total Tokens</th>
<th>Input</th>
<th>Output</th>
<th>Model</th>
<th>Cache</th>
<th>Duration</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<For each={[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}>
{() => (
<tr>
<td>
<div class="skeleton skeleton--text" style="width: 90px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 55px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 40px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 40px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 35px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 35px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 110px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 90px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 35px;" />
</td>
<td>
<div class="skeleton skeleton--text" style="width: 50px;" />
</td>
</tr>
)}
</For>
</tbody>
</table>
</div>
</div>
}
>
<Show when={!data.error} fallback={<ErrorState error={data.error} onRetry={refetch} />}>
<Show when={showEmptyState()}>
<Show
when={setupCompleted()}
fallback={
<div class="empty-state">
<div class="empty-state__title">No messages yet</div>
<p>Set up your agent and send a message. Every LLM call shows up here.</p>
<button
class="btn btn--primary btn--sm"
style="margin-top: var(--gap-md);"
onClick={() => setSetupOpen(true)}
>
Set up agent
</button>
<div class="empty-state__img-wrapper">
<img
src="/example-messages.svg"
alt="Example message log showing LLM call history"
class="empty-state__img"
loading="lazy"
/>
</div>
</div>
}
>
<div class="empty-state">
<div class="empty-state__title">No messages yet</div>
<p>Connect a provider to start routing LLM calls.</p>
<button
class="btn btn--primary btn--sm"
style="margin-top: var(--gap-md);"
onClick={() =>
navigate(`/agents/${encodeURIComponent(params.agentName)}/routing`, {
state: { openProviders: true },
})
}
>
Enable routing
</button>
<div class="empty-state__img-wrapper">
<img
src="/example-messages.svg"
alt="Example message log showing LLM call history"
class="empty-state__img"
loading="lazy"
/>
</div>
</div>
</Show>
</Show>
<Show when={isFilteredEmpty()}>
<div class="panel">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--gap-lg);">
<div class="panel__title" style="margin-bottom: 0;">
Messages
</div>
<span style="font-size: var(--font-size-xs); color: hsl(var(--muted-foreground));">
0 results
</span>
</div>
<div class="model-filter__empty">
<p class="model-filter__empty-title">No messages match your filters</p>
<p class="model-filter__empty-hint">
Try adjusting your provider or cost filters to see more results.
</p>
<button class="btn btn--outline btn--sm" onClick={clearFilters} type="button">
Clear filters
</button>
</div>
</div>
</Show>
<Show when={showMessages()}>
<Show when={hasNoData() && hasProviders()}>
<div class="waiting-banner">
<i class="bxd bx-florist" />
<p>No messages yet. They appear seconds after your first LLM call.</p>
</div>
</Show>
<div class="panel">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--gap-lg);">
<div class="panel__title" style="margin-bottom: 0;">
Messages
</div>
<span style="font-size: var(--font-size-xs); color: hsl(var(--muted-foreground));">
{data()?.total_count ?? 0} total
</span>
</div>
<div class="data-table-scroll">
<MessageTable
items={
isLocal() ? (data()?.items ?? []) : applyFeedbackOverrides(data()?.items ?? [])
}
columns={columns()}
agentName={params.agentName}
customProviderName={customProviderName}
onFallbackErrorClick={scrollToFallbackSuccess}
onFeedbackLike={isLocal() ? undefined : handleFeedbackLike}
onFeedbackDislike={isLocal() ? undefined : handleFeedbackDislike}
onFeedbackClear={isLocal() ? undefined : handleFeedbackClear}
rowIdPrefix="msg-"
showHeaderTooltips
expandable
/>
</div>
<Pagination
currentPage={pager.currentPage}
totalItems={() => data()?.total_count ?? 0}
pageSize={pager.pageSize}
hasNextPage={pager.hasNextPage}
isLoading={() => data.loading}
onPrevious={pager.previousPage}
onNext={pager.nextPage}
/>
</div>
</Show>
</Show>
</Show>
<SetupModal
open={setupOpen()}
agentName={decodeURIComponent(params.agentName)}
agentPlatform={agentPlatform()}
agentCategory={agentCategory()}
onClose={() => setSetupOpen(false)}
/>
<Show when={!isLocal()}>
<FeedbackModal
open={feedbackModalOpen()}
onClose={() => setFeedbackModalOpen(false)}
onSubmit={handleFeedbackSubmit}
/>
</Show>
</div>
);
};
export default MessageLog;