@springbrand/message-panel 0.1.3-alpha.33 → 0.1.3-alpha.36
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/cloud-os/README.md +2 -1
- package/cloud-os/assets/thinking-star.svg +9 -0
- package/cloud-os/chat/cloud-os-chat-messages.tsx +290 -239
- package/cloud-os/chat/code-runner.tsx +106 -0
- package/cloud-os/chat/range.ts +8 -0
- package/cloud-os/chat/rich-blocks.tsx +186 -256
- package/cloud-os/chat/surfaces.tsx +90 -0
- package/cloud-os/chat/tool-call.tsx +94 -0
- package/cloud-os/chat/tool-presentation.ts +3 -11
- package/cloud-os/chat/tool-rows.tsx +145 -378
- package/cloud-os/chat/tool-timeline.tsx +123 -0
- package/cloud-os/chat/transcript-model.ts +86 -116
- package/cloud-os/chat/web-search.tsx +135 -0
- package/cloud-os/composer/cloud-os-chat-input.tsx +1 -1
- package/cloud-os/index.ts +10 -5
- package/cloud-os/primitives/collapsible.tsx +21 -0
- package/cloud-os/styles/cloud-os.css +18 -12
- package/demo/chat-scenarios.ts +3 -9
- package/package.json +3 -1
- package/cloud-os/assets/thinking-spark.svg +0 -9
- package/cloud-os/chat/use-lifecycle-disclosure.ts +0 -65
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from "react";
|
|
4
|
+
import { Loader2Icon, PlayIcon } from "lucide-react";
|
|
5
|
+
import { cn } from "../internal/cn";
|
|
6
|
+
import { codeScroll, codeSurface, ghostButton, mono, paper } from "./surfaces";
|
|
7
|
+
|
|
8
|
+
export type RunState = "idle" | "running" | "ok" | "error";
|
|
9
|
+
|
|
10
|
+
export function CodeRunner({
|
|
11
|
+
language,
|
|
12
|
+
code,
|
|
13
|
+
state,
|
|
14
|
+
output,
|
|
15
|
+
durationMs,
|
|
16
|
+
onRun,
|
|
17
|
+
className,
|
|
18
|
+
...props
|
|
19
|
+
}: Omit<
|
|
20
|
+
ComponentProps<"div">,
|
|
21
|
+
"children" | "language" | "code" | "state" | "output" | "durationMs" | "onRun"
|
|
22
|
+
> & {
|
|
23
|
+
language: string;
|
|
24
|
+
code: string;
|
|
25
|
+
state: RunState;
|
|
26
|
+
output: readonly string[];
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
onRun?: () => void;
|
|
29
|
+
}) {
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
data-slot="code-runner"
|
|
33
|
+
className={cn(
|
|
34
|
+
paper,
|
|
35
|
+
"flex w-full max-w-md flex-col overflow-hidden rounded-2xl",
|
|
36
|
+
className,
|
|
37
|
+
)}
|
|
38
|
+
{...props}
|
|
39
|
+
>
|
|
40
|
+
<div className="flex items-center gap-2 px-3.5 py-2">
|
|
41
|
+
<span className={cn(mono, "text-foreground/35 min-w-0 flex-1")}>
|
|
42
|
+
{language}
|
|
43
|
+
</span>
|
|
44
|
+
{durationMs !== undefined && state !== "running" && (
|
|
45
|
+
<span
|
|
46
|
+
className={cn(mono, "text-foreground/30 shrink-0 tabular-nums")}
|
|
47
|
+
>
|
|
48
|
+
{durationMs}ms
|
|
49
|
+
</span>
|
|
50
|
+
)}
|
|
51
|
+
{onRun && (
|
|
52
|
+
<button
|
|
53
|
+
type="button"
|
|
54
|
+
aria-label="Run this snippet"
|
|
55
|
+
onClick={onRun}
|
|
56
|
+
disabled={state === "running"}
|
|
57
|
+
className={cn(
|
|
58
|
+
ghostButton,
|
|
59
|
+
"size-7 shrink-0 disabled:pointer-events-none",
|
|
60
|
+
)}
|
|
61
|
+
>
|
|
62
|
+
{state === "running" ? (
|
|
63
|
+
<Loader2Icon className="size-3.5 animate-spin motion-reduce:animate-none" />
|
|
64
|
+
) : (
|
|
65
|
+
<PlayIcon className="size-3.5 translate-x-px" />
|
|
66
|
+
)}
|
|
67
|
+
</button>
|
|
68
|
+
)}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<pre className={cn(codeScroll, "border-foreground/[0.07] border-t px-3.5 py-2.5 font-mono text-xs leading-relaxed")}>
|
|
72
|
+
<code className="text-foreground/75">{code}</code>
|
|
73
|
+
</pre>
|
|
74
|
+
|
|
75
|
+
{state !== "idle" && (
|
|
76
|
+
<div className="border-foreground/[0.07] fade-in animate-in flex flex-col border-t px-3.5 py-2.5 duration-300">
|
|
77
|
+
<span className={cn(mono, "text-foreground/30 pb-1")}>output</span>
|
|
78
|
+
<div className={codeScroll}>
|
|
79
|
+
<div className={cn(codeSurface, "flex flex-col")}>
|
|
80
|
+
{output.map((line, index) => (
|
|
81
|
+
<span
|
|
82
|
+
key={`${index}-${line}`}
|
|
83
|
+
className={cn(
|
|
84
|
+
"fade-in animate-in fill-mode-both font-mono text-xs leading-relaxed whitespace-pre",
|
|
85
|
+
state === "error"
|
|
86
|
+
? "text-red-600 dark:text-red-400"
|
|
87
|
+
: "text-foreground/70",
|
|
88
|
+
)}
|
|
89
|
+
style={{ animationDelay: `${index * 80}ms` }}
|
|
90
|
+
>
|
|
91
|
+
{line}
|
|
92
|
+
</span>
|
|
93
|
+
))}
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
{state === "running" && (
|
|
97
|
+
<span
|
|
98
|
+
aria-hidden
|
|
99
|
+
className="bg-foreground/40 h-[1em] w-[2px] animate-pulse rounded-full motion-reduce:animate-none"
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function clamp(value: number, min: number, max: number) {
|
|
2
|
+
if (Number.isNaN(value)) return min;
|
|
3
|
+
return Math.min(max, Math.max(min, value));
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function take<T>(items: readonly T[], count: number) {
|
|
7
|
+
return items.slice(0, Math.floor(clamp(count, 0, items.length)));
|
|
8
|
+
}
|