@narumitw/pi-webui 0.28.0 → 0.29.2
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 +8 -4
- package/package.json +14 -5
- package/src/server.ts +12 -11
- package/src/web/app.css +2 -0
- package/src/web/app.js +102 -995
- package/src/web/image-drag.js +0 -73
- package/src/web/index.html +3 -119
- package/src/web/markdown.js +0 -69
- package/src/web/transcript.js +0 -258
- package/src/web/ui/app.jsx +910 -0
- package/src/web/ui/client.js +690 -0
- package/src/web/ui/overlays.jsx +128 -0
- package/src/web/ui/styles.css +576 -0
- package/src/web/ui/view-helpers.js +72 -0
- package/src/web/styles.css +0 -946
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export function withStableKeys(values) {
|
|
2
|
+
return values.map((value, index) => {
|
|
3
|
+
const type =
|
|
4
|
+
value && typeof value === "object" && typeof value.type === "string" ? value.type : "item";
|
|
5
|
+
const id =
|
|
6
|
+
value &&
|
|
7
|
+
typeof value === "object" &&
|
|
8
|
+
(typeof value.id === "string" || typeof value.id === "number")
|
|
9
|
+
? value.id
|
|
10
|
+
: undefined;
|
|
11
|
+
return { key: id === undefined ? `${type}:index:${index}` : `${type}:id:${id}`, value };
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function connectionColor(model) {
|
|
16
|
+
if (model.closed || model.stale) return "red";
|
|
17
|
+
if (!model.connected) return "amber";
|
|
18
|
+
return model.activity === "running" ? "blue" : "jade";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function roleLabel(message) {
|
|
22
|
+
if (message.role === "user") return "You";
|
|
23
|
+
if (message.role === "assistant") return message.final ? "Pi" : "Pi · Streaming";
|
|
24
|
+
if (message.role === "toolResult") {
|
|
25
|
+
return message.toolName ? `Tool · ${message.toolName}` : "Tool";
|
|
26
|
+
}
|
|
27
|
+
return message.role;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function knownRole(role) {
|
|
31
|
+
if (role === "user" || role === "assistant" || role === "toolResult") return role;
|
|
32
|
+
return "other";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function safeJson(value) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.stringify(value, null, 2);
|
|
38
|
+
} catch {
|
|
39
|
+
return "Details unavailable";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function resizeInput(input) {
|
|
44
|
+
if (!input) return;
|
|
45
|
+
input.style.height = "auto";
|
|
46
|
+
input.style.height = `${Math.min(input.scrollHeight, window.innerHeight * 0.32)}px`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function isSupportedImageFile(file) {
|
|
50
|
+
return (
|
|
51
|
+
[
|
|
52
|
+
"image/png",
|
|
53
|
+
"image/jpeg",
|
|
54
|
+
"image/webp",
|
|
55
|
+
"image/gif",
|
|
56
|
+
"image/bmp",
|
|
57
|
+
"image/x-ms-bmp",
|
|
58
|
+
"image/tiff",
|
|
59
|
+
"image/heic",
|
|
60
|
+
"image/heif",
|
|
61
|
+
"image/avif",
|
|
62
|
+
].includes(file.type) || /\.(?:bmp|tif|tiff|heic|heif|avif)$/i.test(file.name || "")
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function hasDraggedFile(event) {
|
|
67
|
+
return [...(event.dataTransfer?.items ?? [])].some((item) => item.kind === "file");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isNearBottom() {
|
|
71
|
+
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight < 160;
|
|
72
|
+
}
|