@majapisoftwares/ui 6.6.0 → 6.8.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/AGENTS.md +2 -1
- package/docs/STANDARDS.md +17 -6
- package/package.json +6 -2
- package/scripts/check-standards.mjs +2 -2
- package/src/components/ui/code-block.tsx +246 -0
- package/src/components/ui/marker.tsx +72 -0
- package/src/components/ui/message-scroller.tsx +1 -1
- package/src/components/ui/snackbar.tsx +22 -70
- package/src/components/ui/sonner.tsx +36 -3
- package/src/components/ui/toast.tsx +250 -0
- package/src/hooks/use-highlighted-code.ts +77 -0
- package/src/lib/highlighter.tsx +124 -0
- package/src/lib/i18n.tsx +81 -0
- package/src/lib/utils.ts +16 -0
- package/src/patterns/chat-checkpoint.tsx +49 -0
- package/src/patterns/chat-citation.tsx +57 -0
- package/src/patterns/chat-context.tsx +82 -0
- package/src/patterns/chat-trace.tsx +739 -9
- package/src/patterns/chat.tsx +119 -4
- package/src/patterns/file-tree.tsx +122 -0
- package/src/patterns/model-selector.tsx +153 -0
- package/src/patterns/preferences.tsx +2 -2
- package/src/patterns/prompt-input.tsx +18 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useUiMessages } from "../lib/i18n";
|
|
4
|
+
import { Button } from "../components/ui/button";
|
|
5
|
+
import {
|
|
6
|
+
HoverCard,
|
|
7
|
+
HoverCardContent,
|
|
8
|
+
HoverCardTrigger,
|
|
9
|
+
} from "../components/ui/hover-card";
|
|
10
|
+
import { Progress } from "../components/ui/progress";
|
|
11
|
+
|
|
12
|
+
export interface ContextUsageProps {
|
|
13
|
+
/** The model's context window, in tokens (the model's, not sent by the provider). */
|
|
14
|
+
limit: number;
|
|
15
|
+
input?: number;
|
|
16
|
+
output?: number;
|
|
17
|
+
reasoning?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 1234 → "1.2k". */
|
|
21
|
+
export function formatTokens(value: number) {
|
|
22
|
+
if (value < 1000) return String(value);
|
|
23
|
+
return `${(value / 1000).toFixed(1).replace(/\.0$/, "")}k`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* How much of the context window a conversation uses (shadcn AI Elements
|
|
28
|
+
* Context): a percent button, for the prompt input's `actions`, that shows
|
|
29
|
+
* the counts on hover.
|
|
30
|
+
*/
|
|
31
|
+
export function ContextUsage({
|
|
32
|
+
limit,
|
|
33
|
+
input = 0,
|
|
34
|
+
output = 0,
|
|
35
|
+
reasoning = 0,
|
|
36
|
+
}: ContextUsageProps) {
|
|
37
|
+
const messages = useUiMessages();
|
|
38
|
+
const used = input + output + reasoning;
|
|
39
|
+
const percent =
|
|
40
|
+
limit > 0 ? Math.min(100, Math.round((used / limit) * 100)) : 0;
|
|
41
|
+
const rows = [
|
|
42
|
+
{ label: messages.inputTokens, value: input },
|
|
43
|
+
{ label: messages.outputTokens, value: output },
|
|
44
|
+
{ label: messages.reasoningTokens, value: reasoning },
|
|
45
|
+
].filter((row) => row.value > 0);
|
|
46
|
+
return (
|
|
47
|
+
<HoverCard>
|
|
48
|
+
<HoverCardTrigger
|
|
49
|
+
delay={10}
|
|
50
|
+
closeDelay={100}
|
|
51
|
+
render={
|
|
52
|
+
<Button
|
|
53
|
+
variant="outline"
|
|
54
|
+
size="sm"
|
|
55
|
+
className="h-11 rounded-full md:h-8"
|
|
56
|
+
/>
|
|
57
|
+
}
|
|
58
|
+
>
|
|
59
|
+
{messages.contextPercent(percent)}
|
|
60
|
+
</HoverCardTrigger>
|
|
61
|
+
<HoverCardContent className="flex w-64 flex-col gap-3">
|
|
62
|
+
<div className="flex items-center justify-between gap-3 text-sm">
|
|
63
|
+
<span className="font-medium">{messages.context}</span>
|
|
64
|
+
<span className="text-muted-foreground tabular-nums">
|
|
65
|
+
{formatTokens(used)} / {formatTokens(limit)}
|
|
66
|
+
</span>
|
|
67
|
+
</div>
|
|
68
|
+
<Progress value={percent} aria-label={messages.contextUsed} />
|
|
69
|
+
{rows.length ? (
|
|
70
|
+
<div className="flex flex-col gap-1 text-sm">
|
|
71
|
+
{rows.map((row) => (
|
|
72
|
+
<div key={row.label} className="flex justify-between gap-3">
|
|
73
|
+
<span className="text-muted-foreground">{row.label}</span>
|
|
74
|
+
<span className="tabular-nums">{formatTokens(row.value)}</span>
|
|
75
|
+
</div>
|
|
76
|
+
))}
|
|
77
|
+
</div>
|
|
78
|
+
) : null}
|
|
79
|
+
</HoverCardContent>
|
|
80
|
+
</HoverCard>
|
|
81
|
+
);
|
|
82
|
+
}
|