@codrstudio/openclaude-chat 0.1.0 → 0.1.9
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/dist/components/StreamingIndicator.js +5 -5
- package/dist/display/DisplayReactRenderer.js +12 -12
- package/dist/display/react-sandbox/bootstrap.js +150 -150
- package/dist/styles.css +1 -2
- package/package.json +64 -61
- package/src/components/Chat.tsx +107 -107
- package/src/components/ErrorNote.tsx +35 -35
- package/src/components/LazyRender.tsx +42 -42
- package/src/components/Markdown.tsx +114 -114
- package/src/components/MessageBubble.tsx +107 -107
- package/src/components/MessageInput.tsx +421 -421
- package/src/components/MessageList.tsx +153 -153
- package/src/components/StreamingIndicator.tsx +19 -19
- package/src/display/AlertRenderer.tsx +23 -23
- package/src/display/CarouselRenderer.tsx +141 -141
- package/src/display/ChartRenderer.tsx +195 -195
- package/src/display/ChoiceButtonsRenderer.tsx +114 -114
- package/src/display/CodeBlockRenderer.tsx +49 -49
- package/src/display/ComparisonTableRenderer.tsx +132 -132
- package/src/display/DataTableRenderer.tsx +144 -144
- package/src/display/DisplayReactRenderer.tsx +269 -269
- package/src/display/FileCardRenderer.tsx +55 -55
- package/src/display/GalleryRenderer.tsx +65 -65
- package/src/display/ImageViewerRenderer.tsx +114 -114
- package/src/display/LinkPreviewRenderer.tsx +74 -74
- package/src/display/MapViewRenderer.tsx +75 -75
- package/src/display/MetricCardRenderer.tsx +29 -29
- package/src/display/PriceHighlightRenderer.tsx +62 -62
- package/src/display/ProductCardRenderer.tsx +112 -112
- package/src/display/ProgressStepsRenderer.tsx +59 -59
- package/src/display/SourcesListRenderer.tsx +47 -47
- package/src/display/SpreadsheetRenderer.tsx +86 -86
- package/src/display/StepTimelineRenderer.tsx +75 -75
- package/src/display/index.ts +21 -21
- package/src/display/react-sandbox/bootstrap.ts +155 -155
- package/src/display/registry.ts +84 -84
- package/src/display/sdk-types.ts +217 -217
- package/src/hooks/ChatProvider.tsx +21 -21
- package/src/hooks/useIsMobile.ts +15 -15
- package/src/hooks/useOpenClaudeChat.ts +476 -476
- package/src/index.ts +76 -76
- package/src/lib/utils.ts +6 -6
- package/src/parts/PartErrorBoundary.tsx +51 -51
- package/src/parts/PartRenderer.tsx +145 -145
- package/src/parts/ReasoningBlock.tsx +41 -41
- package/src/parts/ToolActivity.tsx +78 -78
- package/src/parts/ToolResult.tsx +79 -79
- package/src/styles.css +2 -2
- package/src/types.ts +41 -41
- package/src/ui/alert.tsx +77 -77
- package/src/ui/badge.tsx +36 -36
- package/src/ui/button.tsx +54 -54
- package/src/ui/card.tsx +68 -68
- package/src/ui/collapsible.tsx +7 -7
- package/src/ui/dialog.tsx +122 -122
- package/src/ui/dropdown-menu.tsx +76 -76
- package/src/ui/input.tsx +24 -24
- package/src/ui/progress.tsx +36 -36
- package/src/ui/scroll-area.tsx +48 -48
- package/src/ui/separator.tsx +31 -31
- package/src/ui/skeleton.tsx +9 -9
- package/src/ui/table.tsx +114 -114
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import { memo, useState, useCallback } from "react";
|
|
2
|
-
import type { Message } from "../types.js";
|
|
3
|
-
import { cn } from "../lib/utils.js";
|
|
4
|
-
import { Markdown } from "./Markdown.js";
|
|
5
|
-
import { StreamingIndicator } from "./StreamingIndicator.js";
|
|
6
|
-
import { PartRenderer } from "../parts/PartRenderer.js";
|
|
7
|
-
import { PartErrorBoundary } from "../parts/PartErrorBoundary.js";
|
|
8
|
-
import type { DisplayRendererMap } from "../display/registry.js";
|
|
9
|
-
import { Copy, Check } from "lucide-react";
|
|
10
|
-
|
|
11
|
-
export interface MessageBubbleProps {
|
|
12
|
-
message: Message;
|
|
13
|
-
isStreaming?: boolean;
|
|
14
|
-
displayRenderers?: DisplayRendererMap;
|
|
15
|
-
className?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function extractText(message: Message): string {
|
|
19
|
-
if (message.content) return message.content;
|
|
20
|
-
if (!Array.isArray(message.parts)) return "";
|
|
21
|
-
return message.parts
|
|
22
|
-
.filter((p): p is { type: "text"; text: string } => (p as { type: string }).type === "text")
|
|
23
|
-
.map((p) => p.text)
|
|
24
|
-
.join("\n");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function CopyButton({ text }: { text: string }) {
|
|
28
|
-
const [copied, setCopied] = useState(false);
|
|
29
|
-
|
|
30
|
-
const handleCopy = useCallback(async () => {
|
|
31
|
-
await navigator.clipboard.writeText(text);
|
|
32
|
-
setCopied(true);
|
|
33
|
-
setTimeout(() => setCopied(false), 2000);
|
|
34
|
-
}, [text]);
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<button
|
|
38
|
-
type="button"
|
|
39
|
-
onClick={handleCopy}
|
|
40
|
-
className={cn(
|
|
41
|
-
"h-7 w-7 flex items-center justify-center rounded-lg transition-all",
|
|
42
|
-
"text-muted-foreground/50 opacity-0 group-hover/bubble:opacity-100",
|
|
43
|
-
"hover:bg-muted/50 hover:text-muted-foreground",
|
|
44
|
-
)}
|
|
45
|
-
aria-label={copied ? "Copiado" : "Copiar mensagem"}
|
|
46
|
-
>
|
|
47
|
-
{copied ? <Check className="h-3.5 w-3.5" /> : <Copy className="h-3.5 w-3.5" />}
|
|
48
|
-
</button>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const MessageBubble = memo(function MessageBubble({ message, isStreaming, displayRenderers, className }: MessageBubbleProps) {
|
|
53
|
-
const isUser = message.role === "user";
|
|
54
|
-
const hasParts = Array.isArray(message.parts) && message.parts.length > 0;
|
|
55
|
-
const hasText = typeof message.content === "string" && message.content.length > 0;
|
|
56
|
-
const isEmptyAssistant = !isUser && !hasParts && !hasText && !isStreaming;
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<div className={cn("group/bubble", isUser ? "flex flex-col items-end" : "flex flex-col items-start")}>
|
|
60
|
-
{/* Bubble */}
|
|
61
|
-
<div
|
|
62
|
-
className={cn(
|
|
63
|
-
"min-w-0 overflow-hidden",
|
|
64
|
-
isUser
|
|
65
|
-
? "max-w-[80%] rounded-lg rounded-br-sm bg-muted text-foreground px-4 py-2.5"
|
|
66
|
-
: "w-full text-foreground py-1",
|
|
67
|
-
className
|
|
68
|
-
)}
|
|
69
|
-
>
|
|
70
|
-
{hasParts
|
|
71
|
-
? <div className="flex flex-col gap-3">
|
|
72
|
-
{(message.parts as { type: string }[]).map((part, i) => (
|
|
73
|
-
<PartErrorBoundary key={i} label={`part:${part.type}`}>
|
|
74
|
-
<PartRenderer
|
|
75
|
-
part={part as Parameters<typeof PartRenderer>[0]["part"]}
|
|
76
|
-
isStreaming={isStreaming}
|
|
77
|
-
displayRenderers={displayRenderers}
|
|
78
|
-
/>
|
|
79
|
-
</PartErrorBoundary>
|
|
80
|
-
))}
|
|
81
|
-
</div>
|
|
82
|
-
: hasText
|
|
83
|
-
? <Markdown>{message.content}</Markdown>
|
|
84
|
-
: isEmptyAssistant
|
|
85
|
-
? <span className="text-xs italic text-muted-foreground">(resposta vazia)</span>
|
|
86
|
-
: null
|
|
87
|
-
}
|
|
88
|
-
{isStreaming && !isUser && <StreamingIndicator />}
|
|
89
|
-
</div>
|
|
90
|
-
|
|
91
|
-
{/* Action bar — outside bubble, below */}
|
|
92
|
-
{!isStreaming && (
|
|
93
|
-
<div className={cn(
|
|
94
|
-
"flex items-center gap-0.5 mt-0.5",
|
|
95
|
-
isUser ? "justify-end" : "justify-start"
|
|
96
|
-
)}>
|
|
97
|
-
<CopyButton text={extractText(message)} />
|
|
98
|
-
</div>
|
|
99
|
-
)}
|
|
100
|
-
</div>
|
|
101
|
-
);
|
|
102
|
-
}, (prev, next) =>
|
|
103
|
-
prev.message === next.message
|
|
104
|
-
&& prev.isStreaming === next.isStreaming
|
|
105
|
-
&& prev.displayRenderers === next.displayRenderers
|
|
106
|
-
&& prev.className === next.className
|
|
107
|
-
);
|
|
1
|
+
import { memo, useState, useCallback } from "react";
|
|
2
|
+
import type { Message } from "../types.js";
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { Markdown } from "./Markdown.js";
|
|
5
|
+
import { StreamingIndicator } from "./StreamingIndicator.js";
|
|
6
|
+
import { PartRenderer } from "../parts/PartRenderer.js";
|
|
7
|
+
import { PartErrorBoundary } from "../parts/PartErrorBoundary.js";
|
|
8
|
+
import type { DisplayRendererMap } from "../display/registry.js";
|
|
9
|
+
import { Copy, Check } from "lucide-react";
|
|
10
|
+
|
|
11
|
+
export interface MessageBubbleProps {
|
|
12
|
+
message: Message;
|
|
13
|
+
isStreaming?: boolean;
|
|
14
|
+
displayRenderers?: DisplayRendererMap;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function extractText(message: Message): string {
|
|
19
|
+
if (message.content) return message.content;
|
|
20
|
+
if (!Array.isArray(message.parts)) return "";
|
|
21
|
+
return message.parts
|
|
22
|
+
.filter((p): p is { type: "text"; text: string } => (p as { type: string }).type === "text")
|
|
23
|
+
.map((p) => p.text)
|
|
24
|
+
.join("\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function CopyButton({ text }: { text: string }) {
|
|
28
|
+
const [copied, setCopied] = useState(false);
|
|
29
|
+
|
|
30
|
+
const handleCopy = useCallback(async () => {
|
|
31
|
+
await navigator.clipboard.writeText(text);
|
|
32
|
+
setCopied(true);
|
|
33
|
+
setTimeout(() => setCopied(false), 2000);
|
|
34
|
+
}, [text]);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
onClick={handleCopy}
|
|
40
|
+
className={cn(
|
|
41
|
+
"h-7 w-7 flex items-center justify-center rounded-lg transition-all",
|
|
42
|
+
"text-muted-foreground/50 opacity-0 group-hover/bubble:opacity-100",
|
|
43
|
+
"hover:bg-muted/50 hover:text-muted-foreground",
|
|
44
|
+
)}
|
|
45
|
+
aria-label={copied ? "Copiado" : "Copiar mensagem"}
|
|
46
|
+
>
|
|
47
|
+
{copied ? <Check className="h-3.5 w-3.5" /> : <Copy className="h-3.5 w-3.5" />}
|
|
48
|
+
</button>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const MessageBubble = memo(function MessageBubble({ message, isStreaming, displayRenderers, className }: MessageBubbleProps) {
|
|
53
|
+
const isUser = message.role === "user";
|
|
54
|
+
const hasParts = Array.isArray(message.parts) && message.parts.length > 0;
|
|
55
|
+
const hasText = typeof message.content === "string" && message.content.length > 0;
|
|
56
|
+
const isEmptyAssistant = !isUser && !hasParts && !hasText && !isStreaming;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className={cn("group/bubble", isUser ? "flex flex-col items-end" : "flex flex-col items-start")}>
|
|
60
|
+
{/* Bubble */}
|
|
61
|
+
<div
|
|
62
|
+
className={cn(
|
|
63
|
+
"min-w-0 overflow-hidden",
|
|
64
|
+
isUser
|
|
65
|
+
? "max-w-[80%] rounded-lg rounded-br-sm bg-muted text-foreground px-4 py-2.5"
|
|
66
|
+
: "w-full text-foreground py-1",
|
|
67
|
+
className
|
|
68
|
+
)}
|
|
69
|
+
>
|
|
70
|
+
{hasParts
|
|
71
|
+
? <div className="flex flex-col gap-3">
|
|
72
|
+
{(message.parts as { type: string }[]).map((part, i) => (
|
|
73
|
+
<PartErrorBoundary key={i} label={`part:${part.type}`}>
|
|
74
|
+
<PartRenderer
|
|
75
|
+
part={part as Parameters<typeof PartRenderer>[0]["part"]}
|
|
76
|
+
isStreaming={isStreaming}
|
|
77
|
+
displayRenderers={displayRenderers}
|
|
78
|
+
/>
|
|
79
|
+
</PartErrorBoundary>
|
|
80
|
+
))}
|
|
81
|
+
</div>
|
|
82
|
+
: hasText
|
|
83
|
+
? <Markdown>{message.content}</Markdown>
|
|
84
|
+
: isEmptyAssistant
|
|
85
|
+
? <span className="text-xs italic text-muted-foreground">(resposta vazia)</span>
|
|
86
|
+
: null
|
|
87
|
+
}
|
|
88
|
+
{isStreaming && !isUser && <StreamingIndicator />}
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
{/* Action bar — outside bubble, below */}
|
|
92
|
+
{!isStreaming && (
|
|
93
|
+
<div className={cn(
|
|
94
|
+
"flex items-center gap-0.5 mt-0.5",
|
|
95
|
+
isUser ? "justify-end" : "justify-start"
|
|
96
|
+
)}>
|
|
97
|
+
<CopyButton text={extractText(message)} />
|
|
98
|
+
</div>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}, (prev, next) =>
|
|
103
|
+
prev.message === next.message
|
|
104
|
+
&& prev.isStreaming === next.isStreaming
|
|
105
|
+
&& prev.displayRenderers === next.displayRenderers
|
|
106
|
+
&& prev.className === next.className
|
|
107
|
+
);
|