tuxevil-rotator 4.2.1 → 4.3.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/CHANGELOG.md +48 -1
- package/README.md +20 -6
- package/package.json +3 -3
- package/plugins/opencode-discovery/capabilities.d.mts +7 -0
- package/plugins/opencode-discovery/capabilities.mjs +54 -0
- package/plugins/opencode-discovery/index.d.mts +60 -0
- package/plugins/opencode-discovery/index.mjs +333 -0
- package/plugins/opencode-discovery/package.json +24 -0
- package/src/audio-transcription.ts +32 -6
- package/src/cli.ts +3 -3
- package/src/compat/model-specs.ts +4 -0
- package/src/compat.ts +34 -6
- package/src/dashboard-app.ts +1 -0
- package/src/install-agent.ts +252 -143
- package/src/install-opencode.ts +211 -43
- package/src/providers/google-antigravity/catalog.ts +45 -166
- package/src/providers/google-antigravity/dynamic-catalog.ts +107 -10
- package/src/providers/google-antigravity/forward.ts +4 -2
- package/src/providers/google-antigravity/index.ts +12 -4
- package/src/providers/google-antigravity/quota.ts +9 -7
- package/src/providers/ollama/forward.ts +10 -0
- package/src/providers/openai-codex/catalog.ts +157 -18
- package/src/proxy.ts +54 -5
- package/src/rotator.ts +32 -22
- package/src/types.ts +79 -67
- package/src/web/app.tsx +4 -0
- package/src/web/lib/audio-recorder.ts +159 -0
- package/src/web/lib/colors.ts +4 -0
- package/src/web/lib/playground-storage.ts +261 -0
- package/src/web/lib/playground.ts +448 -0
- package/src/web/nav.ts +1 -0
- package/src/web/pages/Playground.tsx +1111 -0
- package/src/web/pages/Transcription.tsx +428 -0
- package/src/web/state/api.ts +3 -0
- package/src/web/state/playground-client.ts +136 -0
- package/src/web/state/playground.ts +69 -0
- package/src/web/state/router.ts +2 -2
- package/src/web/state/transcription-client.ts +93 -0
- package/src/web/styles/app.css +45 -0
- package/tools/telemetry-receiver/receiver.js +59 -46
- package/plugins/opencode-discovery.js +0 -174
|
@@ -0,0 +1,1111 @@
|
|
|
1
|
+
import type { JSX } from "preact";
|
|
2
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
EmptyState,
|
|
6
|
+
PageHeader,
|
|
7
|
+
Panel,
|
|
8
|
+
Pill,
|
|
9
|
+
Segmented,
|
|
10
|
+
Spinner,
|
|
11
|
+
} from "../components/ui.js";
|
|
12
|
+
import { confirmAction, toast } from "../state/actions.js";
|
|
13
|
+
import { api } from "../state/api.js";
|
|
14
|
+
import { query, setQuery } from "../state/router.js";
|
|
15
|
+
import { masked, masker, overview } from "../state/store.js";
|
|
16
|
+
import {
|
|
17
|
+
currentDocument,
|
|
18
|
+
initializePlayground,
|
|
19
|
+
saveWorkspace,
|
|
20
|
+
storageError,
|
|
21
|
+
updateDocument,
|
|
22
|
+
workspace,
|
|
23
|
+
} from "../state/playground.js";
|
|
24
|
+
import { PlaygroundError, runChat } from "../state/playground-client.js";
|
|
25
|
+
import {
|
|
26
|
+
buildChatRequest,
|
|
27
|
+
newTranscription,
|
|
28
|
+
CASES,
|
|
29
|
+
complianceRequest,
|
|
30
|
+
emptyResult,
|
|
31
|
+
errorVerdict,
|
|
32
|
+
evaluateCompliance,
|
|
33
|
+
newDocument,
|
|
34
|
+
newId,
|
|
35
|
+
newPanel,
|
|
36
|
+
userMessage,
|
|
37
|
+
VERDICT_LABELS,
|
|
38
|
+
type CaseId,
|
|
39
|
+
type ChatRequest,
|
|
40
|
+
type ChatResult,
|
|
41
|
+
type ComplianceResult,
|
|
42
|
+
type ImageAttachment,
|
|
43
|
+
type Parameters,
|
|
44
|
+
type PlaygroundPanel,
|
|
45
|
+
type PlaygroundTab,
|
|
46
|
+
type Turn,
|
|
47
|
+
} from "../lib/playground.js";
|
|
48
|
+
import { parsePlaygroundDocument } from "../lib/playground-storage.js";
|
|
49
|
+
import { TranscriptionPage } from "./Transcription.js";
|
|
50
|
+
import { formatMs } from "../lib/format.js";
|
|
51
|
+
|
|
52
|
+
const TABS: Array<{ value: PlaygroundTab; label: string }> = [
|
|
53
|
+
{ value: "chat", label: "Chat" },
|
|
54
|
+
{ value: "compare", label: "Compare" },
|
|
55
|
+
{ value: "compliance", label: "Compliance" },
|
|
56
|
+
{ value: "transcription", label: "Transcription" },
|
|
57
|
+
];
|
|
58
|
+
const errorText = (err: unknown): string =>
|
|
59
|
+
err instanceof Error ? err.message : String(err);
|
|
60
|
+
|
|
61
|
+
export function PlaygroundPage(): JSX.Element {
|
|
62
|
+
const doc = currentDocument();
|
|
63
|
+
const requestedTab = query.value.get("tab");
|
|
64
|
+
const tab: PlaygroundTab =
|
|
65
|
+
requestedTab === "compare" ||
|
|
66
|
+
requestedTab === "compliance" ||
|
|
67
|
+
requestedTab === "transcription"
|
|
68
|
+
? requestedTab
|
|
69
|
+
: "chat";
|
|
70
|
+
const [models, setModels] = useState<string[]>([]);
|
|
71
|
+
const [modelError, setModelError] = useState("");
|
|
72
|
+
const [busy, setBusy] = useState<string[]>([]);
|
|
73
|
+
const [checking, setChecking] = useState(false);
|
|
74
|
+
const [audioBusy, setAudioBusy] = useState(false);
|
|
75
|
+
const [maxBodyBytes, setMaxBodyBytes] = useState(25 * 1024 * 1024);
|
|
76
|
+
const controllers = useRef(new Map<string, AbortController>());
|
|
77
|
+
const importRef = useRef<HTMLInputElement>(null);
|
|
78
|
+
const imageRef = useRef<HTMLInputElement>(null);
|
|
79
|
+
const routing = JSON.stringify([
|
|
80
|
+
overview.value?.modelCatalogRevision,
|
|
81
|
+
overview.value?.accounts.map((a) => [
|
|
82
|
+
a.email,
|
|
83
|
+
a.status,
|
|
84
|
+
a.disabledProviders,
|
|
85
|
+
a.invalidProviders,
|
|
86
|
+
]),
|
|
87
|
+
]);
|
|
88
|
+
const running = checking || busy.length > 0 || audioBusy;
|
|
89
|
+
|
|
90
|
+
const loadModels = async () => {
|
|
91
|
+
try {
|
|
92
|
+
const response = await api.models();
|
|
93
|
+
setModels([...new Set(response.data.map((m) => m.id))].sort());
|
|
94
|
+
setModelError("");
|
|
95
|
+
} catch (err) {
|
|
96
|
+
setModelError(errorText(err));
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
void initializePlayground();
|
|
101
|
+
}, []);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
void loadModels();
|
|
104
|
+
}, [routing]);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
void api
|
|
107
|
+
.playgroundConfig()
|
|
108
|
+
.then((config) => setMaxBodyBytes(config.maxBodyBytes))
|
|
109
|
+
.catch(() => {});
|
|
110
|
+
const active = controllers.current;
|
|
111
|
+
return () => {
|
|
112
|
+
for (const controller of active.values()) controller.abort();
|
|
113
|
+
};
|
|
114
|
+
}, []);
|
|
115
|
+
|
|
116
|
+
function patchPanel(
|
|
117
|
+
id: string,
|
|
118
|
+
update: (panel: PlaygroundPanel) => PlaygroundPanel,
|
|
119
|
+
immediate = false,
|
|
120
|
+
): void {
|
|
121
|
+
updateDocument(
|
|
122
|
+
(d) => ({
|
|
123
|
+
...d,
|
|
124
|
+
chat: d.chat.id === id ? update(d.chat) : d.chat,
|
|
125
|
+
compare: d.compare.map((p) => (p.id === id ? update(p) : p)),
|
|
126
|
+
}),
|
|
127
|
+
immediate,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
function changeParams(id: string, patch: Partial<Parameters>): void {
|
|
131
|
+
updateDocument((d) => ({
|
|
132
|
+
...d,
|
|
133
|
+
chat:
|
|
134
|
+
d.chat.id === id
|
|
135
|
+
? { ...d.chat, params: { ...d.chat.params, ...patch } }
|
|
136
|
+
: d.chat,
|
|
137
|
+
compare: d.compare.map((p) =>
|
|
138
|
+
p.id === id || (d.sync && d.compare.some((p) => p.id === id))
|
|
139
|
+
? { ...p, params: { ...p.params, ...patch } }
|
|
140
|
+
: p,
|
|
141
|
+
),
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
function ensureSize(request: ChatRequest): void {
|
|
145
|
+
if (new Blob([JSON.stringify(request)]).size > maxBodyBytes)
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Request exceeds the server's ${(maxBodyBytes / 1024 / 1024).toFixed(1)} MiB limit. Remove images or start a new conversation.`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
async function executePanel(
|
|
151
|
+
panel: PlaygroundPanel,
|
|
152
|
+
request: ChatRequest,
|
|
153
|
+
retry: boolean,
|
|
154
|
+
): Promise<void> {
|
|
155
|
+
const documentId = doc!.id;
|
|
156
|
+
const controller = new AbortController();
|
|
157
|
+
controllers.current.set(panel.id, controller);
|
|
158
|
+
setBusy((ids) => [...ids, panel.id]);
|
|
159
|
+
const turns = retry ? panel.turns.slice(0, -1) : panel.turns;
|
|
160
|
+
const index = turns.length;
|
|
161
|
+
patchPanel(panel.id, (p) => ({
|
|
162
|
+
...p,
|
|
163
|
+
turns: [...turns, { request, result: null }],
|
|
164
|
+
}));
|
|
165
|
+
const setTurn = (result: ChatResult, error?: string) => {
|
|
166
|
+
if (currentDocument()?.id !== documentId) return;
|
|
167
|
+
patchPanel(
|
|
168
|
+
panel.id,
|
|
169
|
+
(p) => ({
|
|
170
|
+
...p,
|
|
171
|
+
turns: p.turns.map((turn, i) =>
|
|
172
|
+
i === index
|
|
173
|
+
? { request, result, ...(error ? { error } : {}) }
|
|
174
|
+
: turn,
|
|
175
|
+
),
|
|
176
|
+
}),
|
|
177
|
+
result.done || !!error,
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
try {
|
|
181
|
+
setTurn(
|
|
182
|
+
await runChat(request, controller.signal, (result) => setTurn(result)),
|
|
183
|
+
);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if (err instanceof PlaygroundError) setTurn(err.result, err.message);
|
|
186
|
+
else toast(errorText(err), "error");
|
|
187
|
+
} finally {
|
|
188
|
+
controllers.current.delete(panel.id);
|
|
189
|
+
setBusy((ids) => ids.filter((id) => id !== panel.id));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function send(retryPanel?: PlaygroundPanel): Promise<void> {
|
|
193
|
+
if (!doc) return;
|
|
194
|
+
try {
|
|
195
|
+
const panels = retryPanel
|
|
196
|
+
? [retryPanel]
|
|
197
|
+
: tab === "compare"
|
|
198
|
+
? doc.compare
|
|
199
|
+
: [doc.chat];
|
|
200
|
+
const next = userMessage(doc.draft, doc.images);
|
|
201
|
+
if (!retryPanel && !doc.draft.trim() && !doc.images.length) return;
|
|
202
|
+
const requests = panels.map((panel) => {
|
|
203
|
+
if (!models.includes(panel.model))
|
|
204
|
+
throw new Error("Choose an enabled model in every panel.");
|
|
205
|
+
const lastRequest = panel.turns.at(-1)?.request;
|
|
206
|
+
const message =
|
|
207
|
+
retryPanel && lastRequest
|
|
208
|
+
? lastRequest.messages[lastRequest.messages.length - 1]
|
|
209
|
+
: next;
|
|
210
|
+
const request = buildChatRequest(panel, message, !!retryPanel);
|
|
211
|
+
ensureSize(request);
|
|
212
|
+
return request;
|
|
213
|
+
});
|
|
214
|
+
if (!retryPanel)
|
|
215
|
+
updateDocument((d) => ({
|
|
216
|
+
...d,
|
|
217
|
+
draft: "",
|
|
218
|
+
images: [],
|
|
219
|
+
title:
|
|
220
|
+
d.title === "Untitled playground"
|
|
221
|
+
? doc.draft.trim().slice(0, 60) || "Image conversation"
|
|
222
|
+
: d.title,
|
|
223
|
+
}));
|
|
224
|
+
await Promise.all(
|
|
225
|
+
panels.map((panel, i) =>
|
|
226
|
+
executePanel(panel, requests[i], !!retryPanel),
|
|
227
|
+
),
|
|
228
|
+
);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
toast(errorText(err), "error");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async function attach(files: File[]): Promise<void> {
|
|
234
|
+
const documentId = doc?.id;
|
|
235
|
+
try {
|
|
236
|
+
const attachments: ImageAttachment[] = [];
|
|
237
|
+
if (
|
|
238
|
+
files.some(
|
|
239
|
+
(file) =>
|
|
240
|
+
!["image/png", "image/jpeg", "image/webp"].includes(file.type),
|
|
241
|
+
)
|
|
242
|
+
)
|
|
243
|
+
throw new Error("Choose PNG, JPEG or WebP images.");
|
|
244
|
+
if (
|
|
245
|
+
(files.reduce((sum, file) => sum + file.size, 0) * 4) / 3 >
|
|
246
|
+
maxBodyBytes
|
|
247
|
+
)
|
|
248
|
+
throw new Error("Images exceed the request size limit.");
|
|
249
|
+
for (const file of files) {
|
|
250
|
+
const url = await new Promise<string>((resolve, reject) => {
|
|
251
|
+
const reader = new FileReader();
|
|
252
|
+
reader.onload = () => resolve(String(reader.result));
|
|
253
|
+
reader.onerror = () => reject(reader.error);
|
|
254
|
+
reader.readAsDataURL(file);
|
|
255
|
+
});
|
|
256
|
+
attachments.push({ name: file.name, url });
|
|
257
|
+
}
|
|
258
|
+
if (currentDocument()?.id === documentId)
|
|
259
|
+
updateDocument((d) => ({
|
|
260
|
+
...d,
|
|
261
|
+
images: [...d.images, ...attachments],
|
|
262
|
+
}));
|
|
263
|
+
} catch (err) {
|
|
264
|
+
toast(errorText(err), "error");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function exportDoc(): void {
|
|
268
|
+
if (!doc) return;
|
|
269
|
+
const url = URL.createObjectURL(
|
|
270
|
+
new Blob([JSON.stringify(doc, null, 2)], { type: "application/json" }),
|
|
271
|
+
);
|
|
272
|
+
const a = document.createElement("a");
|
|
273
|
+
a.href = url;
|
|
274
|
+
a.download = `playground-${doc.id}.json`;
|
|
275
|
+
a.click();
|
|
276
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
277
|
+
}
|
|
278
|
+
async function importDoc(file: File): Promise<void> {
|
|
279
|
+
try {
|
|
280
|
+
if (file.size > 100 * 1024 * 1024)
|
|
281
|
+
throw new Error("Playground imports must be smaller than 100 MiB.");
|
|
282
|
+
const imported = parsePlaygroundDocument(JSON.parse(await file.text()));
|
|
283
|
+
const state = workspace.value!;
|
|
284
|
+
const restored = { ...imported, id: newId(), updatedAt: Date.now() };
|
|
285
|
+
saveWorkspace(
|
|
286
|
+
{
|
|
287
|
+
...state,
|
|
288
|
+
currentId: restored.id,
|
|
289
|
+
documents: [...state.documents, restored],
|
|
290
|
+
},
|
|
291
|
+
true,
|
|
292
|
+
);
|
|
293
|
+
toast("Imported playground. No requests were sent.", "success");
|
|
294
|
+
} catch (err) {
|
|
295
|
+
toast(errorText(err), "error");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function deleteHistory(all: boolean): Promise<void> {
|
|
299
|
+
if (!doc || !workspace.value) return;
|
|
300
|
+
if (
|
|
301
|
+
!(await confirmAction({
|
|
302
|
+
title: all
|
|
303
|
+
? "Delete all playground history?"
|
|
304
|
+
: "Delete this playground?",
|
|
305
|
+
body: "This removes the local copy from this browser. Export anything you want to keep first.",
|
|
306
|
+
confirmLabel: "Delete",
|
|
307
|
+
danger: true,
|
|
308
|
+
}))
|
|
309
|
+
)
|
|
310
|
+
return;
|
|
311
|
+
const remaining = all
|
|
312
|
+
? []
|
|
313
|
+
: workspace.value.documents.filter((d) => d.id !== doc.id);
|
|
314
|
+
if (!remaining.length) remaining.push(newDocument());
|
|
315
|
+
saveWorkspace(
|
|
316
|
+
{ version: 1, currentId: remaining[0].id, documents: remaining },
|
|
317
|
+
true,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
async function runCompliance(retry = false): Promise<void> {
|
|
321
|
+
if (!doc || !doc.complianceModels.length || !doc.cases.length) return;
|
|
322
|
+
const documentId = doc.id;
|
|
323
|
+
const failed = doc.results.filter(
|
|
324
|
+
(r) => r.verdict === "failed" || r.verdict === "error",
|
|
325
|
+
);
|
|
326
|
+
const jobs = doc.complianceModels.map((model) => ({
|
|
327
|
+
model,
|
|
328
|
+
cases: doc.cases.filter(
|
|
329
|
+
(caseId) =>
|
|
330
|
+
!retry ||
|
|
331
|
+
failed.some((r) => r.model === model && r.caseId === caseId),
|
|
332
|
+
),
|
|
333
|
+
}));
|
|
334
|
+
if (jobs.some((job) => !models.includes(job.model))) {
|
|
335
|
+
toast("Select enabled models before running compliance.", "error");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const jobKey = (model: string, caseId: CaseId) =>
|
|
339
|
+
JSON.stringify([model, caseId]);
|
|
340
|
+
const selected = new Set(
|
|
341
|
+
jobs.flatMap((job) =>
|
|
342
|
+
job.cases.map((caseId) => jobKey(job.model, caseId)),
|
|
343
|
+
),
|
|
344
|
+
);
|
|
345
|
+
updateDocument((d) => ({
|
|
346
|
+
...d,
|
|
347
|
+
results: retry
|
|
348
|
+
? d.results.filter((r) => !selected.has(jobKey(r.model, r.caseId)))
|
|
349
|
+
: [],
|
|
350
|
+
}));
|
|
351
|
+
setChecking(true);
|
|
352
|
+
try {
|
|
353
|
+
await Promise.all(
|
|
354
|
+
jobs.map(async ({ model, cases }) => {
|
|
355
|
+
const controller = new AbortController();
|
|
356
|
+
controllers.current.set(`compliance:${model}`, controller);
|
|
357
|
+
try {
|
|
358
|
+
for (const caseId of cases) {
|
|
359
|
+
const request = complianceRequest(model, caseId);
|
|
360
|
+
let row: ComplianceResult;
|
|
361
|
+
try {
|
|
362
|
+
if (controller.signal.aborted)
|
|
363
|
+
throw new PlaygroundError(
|
|
364
|
+
"Request cancelled.",
|
|
365
|
+
emptyResult(),
|
|
366
|
+
true,
|
|
367
|
+
);
|
|
368
|
+
const result = await runChat(request, controller.signal);
|
|
369
|
+
row = {
|
|
370
|
+
model,
|
|
371
|
+
caseId,
|
|
372
|
+
...evaluateCompliance(caseId, result),
|
|
373
|
+
turn: { request, result },
|
|
374
|
+
};
|
|
375
|
+
} catch (err) {
|
|
376
|
+
row = {
|
|
377
|
+
model,
|
|
378
|
+
caseId,
|
|
379
|
+
verdict:
|
|
380
|
+
err instanceof PlaygroundError && err.cancelled
|
|
381
|
+
? "cancelled"
|
|
382
|
+
: errorVerdict(
|
|
383
|
+
err instanceof PlaygroundError
|
|
384
|
+
? err.result.status
|
|
385
|
+
: 0,
|
|
386
|
+
errorText(err),
|
|
387
|
+
),
|
|
388
|
+
explanation: errorText(err),
|
|
389
|
+
turn: {
|
|
390
|
+
request,
|
|
391
|
+
result: err instanceof PlaygroundError ? err.result : null,
|
|
392
|
+
error: errorText(err),
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
if (currentDocument()?.id === documentId)
|
|
397
|
+
updateDocument((d) => ({ ...d, results: [...d.results, row] }));
|
|
398
|
+
}
|
|
399
|
+
} finally {
|
|
400
|
+
controllers.current.delete(`compliance:${model}`);
|
|
401
|
+
}
|
|
402
|
+
}),
|
|
403
|
+
);
|
|
404
|
+
} finally {
|
|
405
|
+
setChecking(false);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (!doc) return <Spinner />;
|
|
410
|
+
const panels = tab === "compare" ? doc.compare : [doc.chat];
|
|
411
|
+
return (
|
|
412
|
+
<>
|
|
413
|
+
<PageHeader
|
|
414
|
+
title="Playground"
|
|
415
|
+
description="Chat, compare, transcribe audio and check API compatibility through your rotator."
|
|
416
|
+
actions={
|
|
417
|
+
<>
|
|
418
|
+
<Button
|
|
419
|
+
disabled={running}
|
|
420
|
+
onClick={() => {
|
|
421
|
+
const fresh = newDocument();
|
|
422
|
+
saveWorkspace(
|
|
423
|
+
{
|
|
424
|
+
...workspace.value!,
|
|
425
|
+
currentId: fresh.id,
|
|
426
|
+
documents: [...workspace.value!.documents, fresh],
|
|
427
|
+
},
|
|
428
|
+
true,
|
|
429
|
+
);
|
|
430
|
+
}}
|
|
431
|
+
>
|
|
432
|
+
New playground
|
|
433
|
+
</Button>
|
|
434
|
+
<Button icon="download" onClick={exportDoc}>
|
|
435
|
+
Export JSON
|
|
436
|
+
</Button>
|
|
437
|
+
<Button
|
|
438
|
+
icon="upload"
|
|
439
|
+
disabled={running}
|
|
440
|
+
onClick={() => importRef.current?.click()}
|
|
441
|
+
>
|
|
442
|
+
Import JSON
|
|
443
|
+
</Button>
|
|
444
|
+
<input
|
|
445
|
+
ref={importRef}
|
|
446
|
+
type="file"
|
|
447
|
+
accept="application/json,.json"
|
|
448
|
+
class="sr-only"
|
|
449
|
+
aria-label="Import playground JSON"
|
|
450
|
+
onChange={(e) => {
|
|
451
|
+
const file = e.currentTarget.files?.[0];
|
|
452
|
+
e.currentTarget.value = "";
|
|
453
|
+
if (file) void importDoc(file);
|
|
454
|
+
}}
|
|
455
|
+
/>
|
|
456
|
+
</>
|
|
457
|
+
}
|
|
458
|
+
/>
|
|
459
|
+
<div class="playground">
|
|
460
|
+
{storageError.value && (
|
|
461
|
+
<div class="callout tone-warn" role="alert">
|
|
462
|
+
Local history could not be saved. Your work is still in memory;
|
|
463
|
+
export JSON to keep it. {masker.value.text(storageError.value)}
|
|
464
|
+
</div>
|
|
465
|
+
)}
|
|
466
|
+
{modelError && (
|
|
467
|
+
<div class="callout tone-bad" role="alert">
|
|
468
|
+
{modelError}{" "}
|
|
469
|
+
<Button size="sm" onClick={() => void loadModels()}>
|
|
470
|
+
Reload models
|
|
471
|
+
</Button>
|
|
472
|
+
</div>
|
|
473
|
+
)}
|
|
474
|
+
<div class="pg-toolbar">
|
|
475
|
+
<Segmented
|
|
476
|
+
label="Playground mode"
|
|
477
|
+
value={tab}
|
|
478
|
+
options={TABS}
|
|
479
|
+
onChange={(value) => setQuery({ tab: value }, { replace: false })}
|
|
480
|
+
/>
|
|
481
|
+
<label class="field pg-history">
|
|
482
|
+
<span class="sr-only">Local history</span>
|
|
483
|
+
<select
|
|
484
|
+
class="input"
|
|
485
|
+
aria-label="Local history"
|
|
486
|
+
disabled={running}
|
|
487
|
+
value={doc.id}
|
|
488
|
+
onChange={(e) =>
|
|
489
|
+
saveWorkspace(
|
|
490
|
+
{ ...workspace.value!, currentId: e.currentTarget.value },
|
|
491
|
+
true,
|
|
492
|
+
)
|
|
493
|
+
}
|
|
494
|
+
>
|
|
495
|
+
{workspace.value!.documents.map((d) => (
|
|
496
|
+
<option key={d.id} value={d.id}>
|
|
497
|
+
{masked.value ? "Saved playground" : d.title} ·{" "}
|
|
498
|
+
{new Date(d.updatedAt).toLocaleString()}
|
|
499
|
+
</option>
|
|
500
|
+
))}
|
|
501
|
+
</select>
|
|
502
|
+
</label>
|
|
503
|
+
<Button
|
|
504
|
+
size="sm"
|
|
505
|
+
disabled={running}
|
|
506
|
+
onClick={() => void deleteHistory(false)}
|
|
507
|
+
>
|
|
508
|
+
Delete
|
|
509
|
+
</Button>
|
|
510
|
+
<Button
|
|
511
|
+
size="sm"
|
|
512
|
+
disabled={running}
|
|
513
|
+
onClick={() => void deleteHistory(true)}
|
|
514
|
+
>
|
|
515
|
+
Clear history
|
|
516
|
+
</Button>
|
|
517
|
+
{running && (
|
|
518
|
+
<Button
|
|
519
|
+
variant="danger"
|
|
520
|
+
onClick={() => {
|
|
521
|
+
for (const c of controllers.current.values()) c.abort();
|
|
522
|
+
}}
|
|
523
|
+
>
|
|
524
|
+
Stop all
|
|
525
|
+
</Button>
|
|
526
|
+
)}
|
|
527
|
+
</div>
|
|
528
|
+
<p class="field-hint">
|
|
529
|
+
History stays in this browser. Requests use real quota and may also
|
|
530
|
+
appear in the rotator's server logs.
|
|
531
|
+
</p>
|
|
532
|
+
{!models.length && !modelError && (
|
|
533
|
+
<EmptyState icon="models" title="No enabled models">
|
|
534
|
+
Connect a provider and enable models on the Models page, then reload
|
|
535
|
+
the catalog.{" "}
|
|
536
|
+
<Button onClick={() => void loadModels()}>Reload models</Button>
|
|
537
|
+
</EmptyState>
|
|
538
|
+
)}
|
|
539
|
+
{tab === "transcription" ? (
|
|
540
|
+
<TranscriptionPage
|
|
541
|
+
key={doc.id}
|
|
542
|
+
state={doc.transcription ?? newTranscription()}
|
|
543
|
+
models={models}
|
|
544
|
+
maxBodyBytes={maxBodyBytes}
|
|
545
|
+
disabled={checking || busy.length > 0}
|
|
546
|
+
onBusyChange={setAudioBusy}
|
|
547
|
+
controllers={controllers.current}
|
|
548
|
+
onChange={(update) =>
|
|
549
|
+
updateDocument(
|
|
550
|
+
(d) => ({
|
|
551
|
+
...d,
|
|
552
|
+
transcription: update(d.transcription ?? newTranscription()),
|
|
553
|
+
}),
|
|
554
|
+
true,
|
|
555
|
+
)
|
|
556
|
+
}
|
|
557
|
+
/>
|
|
558
|
+
) : tab === "compliance" ? (
|
|
559
|
+
<>
|
|
560
|
+
<Panel
|
|
561
|
+
title="API compliance"
|
|
562
|
+
subtitle="Observed Chat Completions behavior through the rotator. Select up to three models. Tests consume real quota."
|
|
563
|
+
>
|
|
564
|
+
<div
|
|
565
|
+
class="pg-check-models"
|
|
566
|
+
role="group"
|
|
567
|
+
aria-label="Compliance models"
|
|
568
|
+
>
|
|
569
|
+
{[...new Set([...models, ...doc.complianceModels])].map(
|
|
570
|
+
(model) => (
|
|
571
|
+
<label key={model}>
|
|
572
|
+
<input
|
|
573
|
+
type="checkbox"
|
|
574
|
+
checked={doc.complianceModels.includes(model)}
|
|
575
|
+
disabled={
|
|
576
|
+
running ||
|
|
577
|
+
(!doc.complianceModels.includes(model) &&
|
|
578
|
+
doc.complianceModels.length >= 3)
|
|
579
|
+
}
|
|
580
|
+
onChange={(e) =>
|
|
581
|
+
updateDocument((d) => ({
|
|
582
|
+
...d,
|
|
583
|
+
complianceModels: e.currentTarget.checked
|
|
584
|
+
? [...d.complianceModels, model]
|
|
585
|
+
: d.complianceModels.filter((m) => m !== model),
|
|
586
|
+
}))
|
|
587
|
+
}
|
|
588
|
+
/>
|
|
589
|
+
{model}
|
|
590
|
+
{!models.includes(model) ? " (unavailable)" : ""}
|
|
591
|
+
</label>
|
|
592
|
+
),
|
|
593
|
+
)}
|
|
594
|
+
</div>
|
|
595
|
+
<div
|
|
596
|
+
class="pg-toolbar"
|
|
597
|
+
role="group"
|
|
598
|
+
aria-label="Compliance cases"
|
|
599
|
+
>
|
|
600
|
+
{CASES.map((c) => (
|
|
601
|
+
<label key={c.id}>
|
|
602
|
+
<input
|
|
603
|
+
type="checkbox"
|
|
604
|
+
disabled={running}
|
|
605
|
+
checked={doc.cases.includes(c.id)}
|
|
606
|
+
onChange={(e) =>
|
|
607
|
+
updateDocument((d) => ({
|
|
608
|
+
...d,
|
|
609
|
+
cases: e.currentTarget.checked
|
|
610
|
+
? [...d.cases, c.id]
|
|
611
|
+
: d.cases.filter((id) => id !== c.id),
|
|
612
|
+
}))
|
|
613
|
+
}
|
|
614
|
+
/>{" "}
|
|
615
|
+
{c.label}
|
|
616
|
+
</label>
|
|
617
|
+
))}
|
|
618
|
+
</div>
|
|
619
|
+
<div class="pg-toolbar">
|
|
620
|
+
<Button
|
|
621
|
+
variant="primary"
|
|
622
|
+
disabled={
|
|
623
|
+
running || !doc.complianceModels.length || !doc.cases.length
|
|
624
|
+
}
|
|
625
|
+
onClick={() => void runCompliance()}
|
|
626
|
+
>
|
|
627
|
+
Run selected tests
|
|
628
|
+
</Button>
|
|
629
|
+
<Button
|
|
630
|
+
disabled={
|
|
631
|
+
running ||
|
|
632
|
+
!doc.results.some(
|
|
633
|
+
(r) => r.verdict === "failed" || r.verdict === "error",
|
|
634
|
+
)
|
|
635
|
+
}
|
|
636
|
+
onClick={() => void runCompliance(true)}
|
|
637
|
+
>
|
|
638
|
+
Retry failed tests
|
|
639
|
+
</Button>
|
|
640
|
+
{checking && (
|
|
641
|
+
<span role="status">
|
|
642
|
+
<Spinner /> {doc.results.length} results
|
|
643
|
+
</span>
|
|
644
|
+
)}
|
|
645
|
+
</div>
|
|
646
|
+
</Panel>
|
|
647
|
+
<div class="pg-results">
|
|
648
|
+
{doc.results.map((row, i) => (
|
|
649
|
+
<Panel
|
|
650
|
+
key={i}
|
|
651
|
+
title={`${row.model} · ${CASES.find((c) => c.id === row.caseId)?.label}`}
|
|
652
|
+
actions={
|
|
653
|
+
<Pill
|
|
654
|
+
tone={
|
|
655
|
+
row.verdict === "passed"
|
|
656
|
+
? "ok"
|
|
657
|
+
: row.verdict === "failed" || row.verdict === "error"
|
|
658
|
+
? "bad"
|
|
659
|
+
: "warn"
|
|
660
|
+
}
|
|
661
|
+
>
|
|
662
|
+
{VERDICT_LABELS[row.verdict]}
|
|
663
|
+
</Pill>
|
|
664
|
+
}
|
|
665
|
+
>
|
|
666
|
+
<p>{masker.value.text(row.explanation)}</p>
|
|
667
|
+
<TurnView turn={row.turn} />
|
|
668
|
+
</Panel>
|
|
669
|
+
))}
|
|
670
|
+
</div>
|
|
671
|
+
</>
|
|
672
|
+
) : (
|
|
673
|
+
<>
|
|
674
|
+
{tab === "compare" && (
|
|
675
|
+
<div class="pg-toolbar">
|
|
676
|
+
<label>
|
|
677
|
+
<input
|
|
678
|
+
type="checkbox"
|
|
679
|
+
checked={doc.sync}
|
|
680
|
+
disabled={running}
|
|
681
|
+
onChange={(e) =>
|
|
682
|
+
updateDocument((d) => ({
|
|
683
|
+
...d,
|
|
684
|
+
sync: e.currentTarget.checked,
|
|
685
|
+
compare: e.currentTarget.checked
|
|
686
|
+
? d.compare.map((p) => ({
|
|
687
|
+
...p,
|
|
688
|
+
params: { ...d.compare[0].params },
|
|
689
|
+
}))
|
|
690
|
+
: d.compare,
|
|
691
|
+
}))
|
|
692
|
+
}
|
|
693
|
+
/>{" "}
|
|
694
|
+
Sync settings across models
|
|
695
|
+
</label>
|
|
696
|
+
<Button
|
|
697
|
+
size="sm"
|
|
698
|
+
disabled={running || doc.compare.length >= 3}
|
|
699
|
+
onClick={() =>
|
|
700
|
+
updateDocument((d) => ({
|
|
701
|
+
...d,
|
|
702
|
+
compare: [
|
|
703
|
+
...d.compare,
|
|
704
|
+
{
|
|
705
|
+
...newPanel(),
|
|
706
|
+
params: d.sync
|
|
707
|
+
? { ...d.compare[0].params }
|
|
708
|
+
: { ...newPanel().params },
|
|
709
|
+
},
|
|
710
|
+
],
|
|
711
|
+
}))
|
|
712
|
+
}
|
|
713
|
+
>
|
|
714
|
+
Add model
|
|
715
|
+
</Button>
|
|
716
|
+
</div>
|
|
717
|
+
)}
|
|
718
|
+
<div class={`pg-panels pg-panels-${panels.length}`}>
|
|
719
|
+
{panels.map((panel) => (
|
|
720
|
+
<Panel
|
|
721
|
+
key={panel.id}
|
|
722
|
+
title={
|
|
723
|
+
tab === "chat"
|
|
724
|
+
? "Conversation"
|
|
725
|
+
: `Model ${panels.indexOf(panel) + 1}`
|
|
726
|
+
}
|
|
727
|
+
actions={
|
|
728
|
+
tab === "compare" && doc.compare.length > 2 ? (
|
|
729
|
+
<Button
|
|
730
|
+
size="sm"
|
|
731
|
+
disabled={running}
|
|
732
|
+
onClick={() =>
|
|
733
|
+
updateDocument((d) => ({
|
|
734
|
+
...d,
|
|
735
|
+
compare: d.compare.filter((p) => p.id !== panel.id),
|
|
736
|
+
}))
|
|
737
|
+
}
|
|
738
|
+
>
|
|
739
|
+
Remove
|
|
740
|
+
</Button>
|
|
741
|
+
) : undefined
|
|
742
|
+
}
|
|
743
|
+
>
|
|
744
|
+
<label class="field">
|
|
745
|
+
<span class="field-label">Model</span>
|
|
746
|
+
<select
|
|
747
|
+
class="input"
|
|
748
|
+
aria-label="Model"
|
|
749
|
+
disabled={running}
|
|
750
|
+
value={panel.model}
|
|
751
|
+
onChange={(e) =>
|
|
752
|
+
patchPanel(panel.id, (p) => ({
|
|
753
|
+
...p,
|
|
754
|
+
model: e.currentTarget.value,
|
|
755
|
+
turns: [],
|
|
756
|
+
}))
|
|
757
|
+
}
|
|
758
|
+
>
|
|
759
|
+
<option value="">Choose a model</option>
|
|
760
|
+
{panel.model && !models.includes(panel.model) && (
|
|
761
|
+
<option value={panel.model}>
|
|
762
|
+
{panel.model} (unavailable)
|
|
763
|
+
</option>
|
|
764
|
+
)}
|
|
765
|
+
{models.map((model) => (
|
|
766
|
+
<option value={model} key={model}>
|
|
767
|
+
{model}
|
|
768
|
+
</option>
|
|
769
|
+
))}
|
|
770
|
+
</select>
|
|
771
|
+
</label>
|
|
772
|
+
<ParameterEditor
|
|
773
|
+
params={panel.params}
|
|
774
|
+
disabled={running}
|
|
775
|
+
onChange={(patch) => changeParams(panel.id, patch)}
|
|
776
|
+
/>
|
|
777
|
+
<div
|
|
778
|
+
class="pg-turns"
|
|
779
|
+
aria-live="polite"
|
|
780
|
+
aria-busy={busy.includes(panel.id)}
|
|
781
|
+
>
|
|
782
|
+
{panel.turns.length ? (
|
|
783
|
+
panel.turns.map((turn, i) => (
|
|
784
|
+
<TurnView key={i} turn={turn} />
|
|
785
|
+
))
|
|
786
|
+
) : (
|
|
787
|
+
<p class="muted">Send a message to start testing.</p>
|
|
788
|
+
)}
|
|
789
|
+
</div>
|
|
790
|
+
<div class="pg-toolbar">
|
|
791
|
+
{busy.includes(panel.id) ? (
|
|
792
|
+
<Button
|
|
793
|
+
variant="danger"
|
|
794
|
+
size="sm"
|
|
795
|
+
onClick={() =>
|
|
796
|
+
controllers.current.get(panel.id)?.abort()
|
|
797
|
+
}
|
|
798
|
+
>
|
|
799
|
+
Stop
|
|
800
|
+
</Button>
|
|
801
|
+
) : (
|
|
802
|
+
<Button
|
|
803
|
+
size="sm"
|
|
804
|
+
disabled={running || !panel.turns.length}
|
|
805
|
+
onClick={() => void send(panel)}
|
|
806
|
+
>
|
|
807
|
+
Retry last turn
|
|
808
|
+
</Button>
|
|
809
|
+
)}
|
|
810
|
+
<Button
|
|
811
|
+
size="sm"
|
|
812
|
+
disabled={running || !panel.turns.length}
|
|
813
|
+
onClick={() =>
|
|
814
|
+
patchPanel(panel.id, (p) => ({ ...p, turns: [] }))
|
|
815
|
+
}
|
|
816
|
+
>
|
|
817
|
+
Clear conversation
|
|
818
|
+
</Button>
|
|
819
|
+
</div>
|
|
820
|
+
</Panel>
|
|
821
|
+
))}
|
|
822
|
+
</div>
|
|
823
|
+
<form
|
|
824
|
+
class="pg-composer"
|
|
825
|
+
onSubmit={(e) => {
|
|
826
|
+
e.preventDefault();
|
|
827
|
+
if (!running) void send();
|
|
828
|
+
}}
|
|
829
|
+
>
|
|
830
|
+
<label class="field">
|
|
831
|
+
<span class="field-label">
|
|
832
|
+
Message {tab === "compare" && "to all models"}
|
|
833
|
+
</span>
|
|
834
|
+
<textarea
|
|
835
|
+
class="input"
|
|
836
|
+
rows={3}
|
|
837
|
+
value={doc.draft}
|
|
838
|
+
disabled={running}
|
|
839
|
+
placeholder="Ask a question or attach an image…"
|
|
840
|
+
onInput={(e) =>
|
|
841
|
+
updateDocument((d) => ({
|
|
842
|
+
...d,
|
|
843
|
+
draft: e.currentTarget.value,
|
|
844
|
+
}))
|
|
845
|
+
}
|
|
846
|
+
/>
|
|
847
|
+
</label>
|
|
848
|
+
{!!doc.images.length && (
|
|
849
|
+
<div class="pg-images">
|
|
850
|
+
{doc.images.map((image, i) => (
|
|
851
|
+
<div key={i}>
|
|
852
|
+
{!masked.value && (
|
|
853
|
+
<img src={image.url} alt={image.name} />
|
|
854
|
+
)}
|
|
855
|
+
<Button
|
|
856
|
+
size="sm"
|
|
857
|
+
disabled={running}
|
|
858
|
+
onClick={() =>
|
|
859
|
+
updateDocument((d) => ({
|
|
860
|
+
...d,
|
|
861
|
+
images: d.images.filter((_, index) => i !== index),
|
|
862
|
+
}))
|
|
863
|
+
}
|
|
864
|
+
>
|
|
865
|
+
Remove {masked.value ? "image" : image.name}
|
|
866
|
+
</Button>
|
|
867
|
+
</div>
|
|
868
|
+
))}
|
|
869
|
+
</div>
|
|
870
|
+
)}
|
|
871
|
+
<div class="pg-toolbar">
|
|
872
|
+
<Button
|
|
873
|
+
icon="plus"
|
|
874
|
+
disabled={running}
|
|
875
|
+
onClick={() => imageRef.current?.click()}
|
|
876
|
+
>
|
|
877
|
+
Attach images
|
|
878
|
+
</Button>
|
|
879
|
+
<input
|
|
880
|
+
ref={imageRef}
|
|
881
|
+
type="file"
|
|
882
|
+
multiple
|
|
883
|
+
accept="image/png,image/jpeg,image/webp"
|
|
884
|
+
class="sr-only"
|
|
885
|
+
aria-label="Attach images"
|
|
886
|
+
onChange={(e) => {
|
|
887
|
+
const files = Array.from(e.currentTarget.files ?? []);
|
|
888
|
+
e.currentTarget.value = "";
|
|
889
|
+
void attach(files);
|
|
890
|
+
}}
|
|
891
|
+
/>
|
|
892
|
+
<span class="spacer" />
|
|
893
|
+
<Button
|
|
894
|
+
variant="primary"
|
|
895
|
+
type="submit"
|
|
896
|
+
disabled={
|
|
897
|
+
running ||
|
|
898
|
+
!models.length ||
|
|
899
|
+
(!doc.draft.trim() && !doc.images.length)
|
|
900
|
+
}
|
|
901
|
+
>
|
|
902
|
+
Send {tab === "compare" ? "to all" : "message"}
|
|
903
|
+
</Button>
|
|
904
|
+
</div>
|
|
905
|
+
<p class="field-hint">
|
|
906
|
+
Tools are displayed without executing them. Start a new
|
|
907
|
+
conversation after inspecting tool calls. Images require a model
|
|
908
|
+
with vision support.
|
|
909
|
+
</p>
|
|
910
|
+
</form>
|
|
911
|
+
</>
|
|
912
|
+
)}
|
|
913
|
+
</div>
|
|
914
|
+
</>
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function ParameterEditor({
|
|
919
|
+
params,
|
|
920
|
+
disabled,
|
|
921
|
+
onChange,
|
|
922
|
+
}: {
|
|
923
|
+
params: Parameters;
|
|
924
|
+
disabled: boolean;
|
|
925
|
+
onChange: (patch: Partial<Parameters>) => void;
|
|
926
|
+
}): JSX.Element {
|
|
927
|
+
return (
|
|
928
|
+
<details class="pg-parameters">
|
|
929
|
+
<summary>Parameters & system prompt</summary>
|
|
930
|
+
<fieldset disabled={disabled} class="form">
|
|
931
|
+
<label class="field">
|
|
932
|
+
<span class="field-label">System prompt</span>
|
|
933
|
+
<textarea
|
|
934
|
+
class="input"
|
|
935
|
+
rows={3}
|
|
936
|
+
value={params.system}
|
|
937
|
+
onInput={(e) => onChange({ system: e.currentTarget.value })}
|
|
938
|
+
/>
|
|
939
|
+
</label>
|
|
940
|
+
<div class="form-grid">
|
|
941
|
+
<label class="field">
|
|
942
|
+
<span class="field-label">Temperature</span>
|
|
943
|
+
<input
|
|
944
|
+
class="input"
|
|
945
|
+
type="number"
|
|
946
|
+
min="0"
|
|
947
|
+
max="2"
|
|
948
|
+
step="0.1"
|
|
949
|
+
placeholder="Provider default"
|
|
950
|
+
value={params.temperature}
|
|
951
|
+
onInput={(e) => onChange({ temperature: e.currentTarget.value })}
|
|
952
|
+
/>
|
|
953
|
+
</label>
|
|
954
|
+
<label class="field">
|
|
955
|
+
<span class="field-label">Max tokens</span>
|
|
956
|
+
<input
|
|
957
|
+
class="input"
|
|
958
|
+
type="number"
|
|
959
|
+
min="1"
|
|
960
|
+
step="1"
|
|
961
|
+
placeholder="Provider default"
|
|
962
|
+
value={params.maxTokens}
|
|
963
|
+
onInput={(e) => onChange({ maxTokens: e.currentTarget.value })}
|
|
964
|
+
/>
|
|
965
|
+
</label>
|
|
966
|
+
</div>
|
|
967
|
+
<label class="field">
|
|
968
|
+
<span class="field-label">Reasoning effort</span>
|
|
969
|
+
<select
|
|
970
|
+
class="input"
|
|
971
|
+
aria-label="Reasoning effort"
|
|
972
|
+
value={params.effort}
|
|
973
|
+
onChange={(e) => onChange({ effort: e.currentTarget.value })}
|
|
974
|
+
>
|
|
975
|
+
<option value="">Provider default</option>
|
|
976
|
+
{["minimal", "low", "medium", "high", "xhigh"].map((effort) => (
|
|
977
|
+
<option key={effort} value={effort}>
|
|
978
|
+
{effort}
|
|
979
|
+
</option>
|
|
980
|
+
))}
|
|
981
|
+
</select>
|
|
982
|
+
</label>
|
|
983
|
+
<label>
|
|
984
|
+
<input
|
|
985
|
+
type="checkbox"
|
|
986
|
+
checked={params.stream}
|
|
987
|
+
onChange={(e) => onChange({ stream: e.currentTarget.checked })}
|
|
988
|
+
/>{" "}
|
|
989
|
+
Stream response
|
|
990
|
+
</label>
|
|
991
|
+
<label class="field">
|
|
992
|
+
<span class="field-label">Tools JSON (optional)</span>
|
|
993
|
+
<textarea
|
|
994
|
+
class="input pg-code"
|
|
995
|
+
rows={4}
|
|
996
|
+
spellcheck={false}
|
|
997
|
+
placeholder='[{"type":"function","function":{"name":"example","parameters":{"type":"object"}}}]'
|
|
998
|
+
value={params.tools}
|
|
999
|
+
onInput={(e) => onChange({ tools: e.currentTarget.value })}
|
|
1000
|
+
/>
|
|
1001
|
+
</label>
|
|
1002
|
+
<p class="field-hint">
|
|
1003
|
+
Parameters are sent as entered. Support depends on the model and
|
|
1004
|
+
adapter.
|
|
1005
|
+
</p>
|
|
1006
|
+
</fieldset>
|
|
1007
|
+
</details>
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
function TurnView({ turn }: { turn: Turn }): JSX.Element {
|
|
1012
|
+
const result = turn.result;
|
|
1013
|
+
const lastMessage = turn.request.messages.at(-1)?.content;
|
|
1014
|
+
const m = masker.value;
|
|
1015
|
+
const content =
|
|
1016
|
+
typeof lastMessage === "string"
|
|
1017
|
+
? [{ type: "text" as const, text: lastMessage }]
|
|
1018
|
+
: (lastMessage ?? []);
|
|
1019
|
+
return (
|
|
1020
|
+
<article class="pg-turn">
|
|
1021
|
+
<div class="pg-user">
|
|
1022
|
+
<strong>You</strong>
|
|
1023
|
+
{content.map((part, i) =>
|
|
1024
|
+
part.type === "text" ? (
|
|
1025
|
+
<p key={i}>{m.text(part.text)}</p>
|
|
1026
|
+
) : masked.value ? (
|
|
1027
|
+
<p key={i}>[Image hidden]</p>
|
|
1028
|
+
) : (
|
|
1029
|
+
<img key={i} src={part.image_url.url} alt="Attached image" />
|
|
1030
|
+
),
|
|
1031
|
+
)}
|
|
1032
|
+
</div>
|
|
1033
|
+
<div class="pg-assistant">
|
|
1034
|
+
<strong>Assistant</strong>
|
|
1035
|
+
{result?.content ? (
|
|
1036
|
+
<pre class="pg-answer">{m.text(result.content)}</pre>
|
|
1037
|
+
) : (
|
|
1038
|
+
!turn.error &&
|
|
1039
|
+
!result?.tools.length && (
|
|
1040
|
+
<p class="muted">
|
|
1041
|
+
{result?.done ? "Empty response." : "Waiting for response…"}
|
|
1042
|
+
</p>
|
|
1043
|
+
)
|
|
1044
|
+
)}
|
|
1045
|
+
{result?.reasoning && (
|
|
1046
|
+
<details>
|
|
1047
|
+
<summary>Reasoning</summary>
|
|
1048
|
+
<pre class="pg-answer">{m.text(result.reasoning)}</pre>
|
|
1049
|
+
</details>
|
|
1050
|
+
)}
|
|
1051
|
+
{!!result?.tools.length && (
|
|
1052
|
+
<details open>
|
|
1053
|
+
<summary>Tool calls (not executed)</summary>
|
|
1054
|
+
<pre class="pg-code">
|
|
1055
|
+
{m.text(JSON.stringify(result.tools, null, 2))}
|
|
1056
|
+
</pre>
|
|
1057
|
+
</details>
|
|
1058
|
+
)}
|
|
1059
|
+
{turn.error && (
|
|
1060
|
+
<p class="form-error" role="alert">
|
|
1061
|
+
{m.text(turn.error)}
|
|
1062
|
+
</p>
|
|
1063
|
+
)}
|
|
1064
|
+
{result && (
|
|
1065
|
+
<div class="pg-metrics">
|
|
1066
|
+
<span>Total: {formatMs(result.durationMs)}</span>
|
|
1067
|
+
<span>
|
|
1068
|
+
First content:{" "}
|
|
1069
|
+
{result.firstContentMs === null
|
|
1070
|
+
? "Not available"
|
|
1071
|
+
: formatMs(result.firstContentMs)}
|
|
1072
|
+
</span>
|
|
1073
|
+
<span>
|
|
1074
|
+
Tokens in/out: {result.inputTokens ?? "N/A"} /{" "}
|
|
1075
|
+
{result.outputTokens ?? "N/A"}
|
|
1076
|
+
</span>
|
|
1077
|
+
{result.finishReason && <span>Finish: {result.finishReason}</span>}
|
|
1078
|
+
{result.metadata["x-rotator-cost-usd"] && (
|
|
1079
|
+
<span>
|
|
1080
|
+
Estimated list price: ${result.metadata["x-rotator-cost-usd"]}
|
|
1081
|
+
</span>
|
|
1082
|
+
)}
|
|
1083
|
+
</div>
|
|
1084
|
+
)}
|
|
1085
|
+
<details class="pg-inspect">
|
|
1086
|
+
<summary>Request, response & routing</summary>
|
|
1087
|
+
{masked.value ? (
|
|
1088
|
+
<p class="muted">
|
|
1089
|
+
Raw details hidden while the privacy mask is on.
|
|
1090
|
+
</p>
|
|
1091
|
+
) : (
|
|
1092
|
+
<pre class="pg-code">
|
|
1093
|
+
{JSON.stringify(
|
|
1094
|
+
{
|
|
1095
|
+
request: turn.request,
|
|
1096
|
+
response: result?.raw,
|
|
1097
|
+
routing: result?.metadata,
|
|
1098
|
+
},
|
|
1099
|
+
(_, value: unknown) =>
|
|
1100
|
+
typeof value === "string" && value.startsWith("data:image/")
|
|
1101
|
+
? `${value.slice(0, 45)}… [image data omitted from preview]`
|
|
1102
|
+
: value,
|
|
1103
|
+
2,
|
|
1104
|
+
)}
|
|
1105
|
+
</pre>
|
|
1106
|
+
)}
|
|
1107
|
+
</details>
|
|
1108
|
+
</div>
|
|
1109
|
+
</article>
|
|
1110
|
+
);
|
|
1111
|
+
}
|