@majapisoftwares/ui 6.7.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 +15 -4
- package/package.json +6 -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/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/prompt-input.tsx +18 -0
package/src/lib/i18n.tsx
CHANGED
|
@@ -85,6 +85,8 @@ export const uiMessages = defineMessages({
|
|
|
85
85
|
responding: "Responding",
|
|
86
86
|
copy: "Copy",
|
|
87
87
|
copied: "Copied",
|
|
88
|
+
reply: "Reply",
|
|
89
|
+
cancelReply: "Cancel reply",
|
|
88
90
|
goodResponse: "Good response",
|
|
89
91
|
badResponse: "Bad response",
|
|
90
92
|
thinking: "Thinking",
|
|
@@ -93,6 +95,44 @@ export const uiMessages = defineMessages({
|
|
|
93
95
|
approve: "Approve",
|
|
94
96
|
deny: "Deny",
|
|
95
97
|
suggestions: "Suggestions",
|
|
98
|
+
researching: "Researching",
|
|
99
|
+
researched: (steps: number) =>
|
|
100
|
+
`Researched in ${steps} ${steps === 1 ? "step" : "steps"}`,
|
|
101
|
+
planProgress: (done: number, total: number) => `${done} of ${total} done`,
|
|
102
|
+
toDo: (count: number) => `${count} to do`,
|
|
103
|
+
completedCount: (count: number) => `${count} completed`,
|
|
104
|
+
usedSources: (count: number) =>
|
|
105
|
+
`Used ${count} ${count === 1 ? "source" : "sources"}`,
|
|
106
|
+
opensInNewTab: "(opens in a new tab)",
|
|
107
|
+
runningCommand: (command: string) => `Running ${command}`,
|
|
108
|
+
ranCommand: (command: string) => `Ran ${command}`,
|
|
109
|
+
exitedWith: (command: string, code: number) =>
|
|
110
|
+
`${command} exited with code ${code}`,
|
|
111
|
+
testCounts: (total: number, failed: number, skipped: number) =>
|
|
112
|
+
[
|
|
113
|
+
`${total} ${total === 1 ? "test" : "tests"}`,
|
|
114
|
+
failed > 0 && `${failed} failed`,
|
|
115
|
+
skipped > 0 && `${skipped} skipped`,
|
|
116
|
+
]
|
|
117
|
+
.filter(Boolean)
|
|
118
|
+
.join(", "),
|
|
119
|
+
ranTests: (counts: string) => `Ran ${counts}`,
|
|
120
|
+
skippedTest: (name: string) => `Skipped ${name}`,
|
|
121
|
+
failedWith: (error: string) => `Failed: ${error}`,
|
|
122
|
+
frameworkFrames: (count: number) =>
|
|
123
|
+
`${count} framework ${count === 1 ? "frame" : "frames"}`,
|
|
124
|
+
restore: "Restore",
|
|
125
|
+
restoreTo: (label: string) => `Restore to ${label}`,
|
|
126
|
+
contextPercent: (percent: number) => `${percent}% context`,
|
|
127
|
+
context: "Context",
|
|
128
|
+
contextUsed: "Context used",
|
|
129
|
+
inputTokens: "Input",
|
|
130
|
+
outputTokens: "Output",
|
|
131
|
+
reasoningTokens: "Reasoning",
|
|
132
|
+
model: "Model",
|
|
133
|
+
effort: "Effort",
|
|
134
|
+
modelIs: (name: string) => `Model: ${name}`,
|
|
135
|
+
effortIs: (name: string) => `Effort: ${name}`,
|
|
96
136
|
},
|
|
97
137
|
"pt-BR": {
|
|
98
138
|
sidebar: "Barra lateral",
|
|
@@ -135,6 +175,8 @@ export const uiMessages = defineMessages({
|
|
|
135
175
|
responding: "Respondendo",
|
|
136
176
|
copy: "Copiar",
|
|
137
177
|
copied: "Copiado",
|
|
178
|
+
reply: "Responder",
|
|
179
|
+
cancelReply: "Cancelar resposta",
|
|
138
180
|
goodResponse: "Boa resposta",
|
|
139
181
|
badResponse: "Resposta ruim",
|
|
140
182
|
thinking: "Pensando",
|
|
@@ -143,6 +185,45 @@ export const uiMessages = defineMessages({
|
|
|
143
185
|
approve: "Aprovar",
|
|
144
186
|
deny: "Negar",
|
|
145
187
|
suggestions: "Sugestões",
|
|
188
|
+
researching: "Pesquisando",
|
|
189
|
+
researched: (steps: number) =>
|
|
190
|
+
`Pesquisou em ${steps} ${steps === 1 ? "passo" : "passos"}`,
|
|
191
|
+
planProgress: (done: number, total: number) => `${done} de ${total} feitos`,
|
|
192
|
+
toDo: (count: number) => `${count} a fazer`,
|
|
193
|
+
completedCount: (count: number) =>
|
|
194
|
+
`${count} ${count === 1 ? "concluído" : "concluídos"}`,
|
|
195
|
+
usedSources: (count: number) =>
|
|
196
|
+
`Usou ${count} ${count === 1 ? "fonte" : "fontes"}`,
|
|
197
|
+
opensInNewTab: "(abre em uma nova aba)",
|
|
198
|
+
runningCommand: (command: string) => `Rodando ${command}`,
|
|
199
|
+
ranCommand: (command: string) => `Rodou ${command}`,
|
|
200
|
+
exitedWith: (command: string, code: number) =>
|
|
201
|
+
`${command} saiu com código ${code}`,
|
|
202
|
+
testCounts: (total: number, failed: number, skipped: number) =>
|
|
203
|
+
[
|
|
204
|
+
`${total} ${total === 1 ? "teste" : "testes"}`,
|
|
205
|
+
failed > 0 && `${failed} ${failed === 1 ? "falhou" : "falharam"}`,
|
|
206
|
+
skipped > 0 && `${skipped} ${skipped === 1 ? "pulado" : "pulados"}`,
|
|
207
|
+
]
|
|
208
|
+
.filter(Boolean)
|
|
209
|
+
.join(", "),
|
|
210
|
+
ranTests: (counts: string) => `Rodou ${counts}`,
|
|
211
|
+
skippedTest: (name: string) => `Pulou ${name}`,
|
|
212
|
+
failedWith: (error: string) => `Falhou: ${error}`,
|
|
213
|
+
frameworkFrames: (count: number) =>
|
|
214
|
+
`${count} ${count === 1 ? "quadro" : "quadros"} do framework`,
|
|
215
|
+
restore: "Restaurar",
|
|
216
|
+
restoreTo: (label: string) => `Restaurar até ${label}`,
|
|
217
|
+
contextPercent: (percent: number) => `${percent}% do contexto`,
|
|
218
|
+
context: "Contexto",
|
|
219
|
+
contextUsed: "Contexto usado",
|
|
220
|
+
inputTokens: "Entrada",
|
|
221
|
+
outputTokens: "Saída",
|
|
222
|
+
reasoningTokens: "Raciocínio",
|
|
223
|
+
model: "Modelo",
|
|
224
|
+
effort: "Esforço",
|
|
225
|
+
modelIs: (name: string) => `Modelo: ${name}`,
|
|
226
|
+
effortIs: (name: string) => `Esforço: ${name}`,
|
|
146
227
|
},
|
|
147
228
|
});
|
|
148
229
|
|
package/src/lib/utils.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
1
|
export { cn } from "cn";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Markdown as one line of plain text, for a `ChatQuote` of an agent's reply:
|
|
5
|
+
* no code blocks, emphasis, links, list markers or table pipes.
|
|
6
|
+
*/
|
|
7
|
+
export function quoteText(markdown: string) {
|
|
8
|
+
return markdown
|
|
9
|
+
.replace(/```[\s\S]*?(```|$)/g, " ")
|
|
10
|
+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
11
|
+
.replace(/^\s{0,3}(#{1,6}|>|[-*+]|\d+[.)])\s+/gm, "")
|
|
12
|
+
.replace(/^[\s|:-]*-{3,}[\s|:-]*$/gm, " ")
|
|
13
|
+
.replace(/\|/g, " ")
|
|
14
|
+
.replace(/\*\*|__|~~|`|\*/g, "")
|
|
15
|
+
.replace(/\s+/g, " ")
|
|
16
|
+
.trim();
|
|
17
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { useUiMessages } from "../lib/i18n";
|
|
5
|
+
import { Button } from "../components/ui/button";
|
|
6
|
+
import { Marker, MarkerContent } from "../components/ui/marker";
|
|
7
|
+
|
|
8
|
+
export interface CheckpointProps {
|
|
9
|
+
/** What the turn above it changed, e.g. "Button renamed". */
|
|
10
|
+
label: ReactNode;
|
|
11
|
+
/** Keeps that turn and drops every later message. Leave it out on the last turn. */
|
|
12
|
+
onRestore?: () => void;
|
|
13
|
+
/** Accessible name of the restore button, e.g. "Restore to Button renamed". */
|
|
14
|
+
restoreLabel?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A point the conversation can go back to (shadcn AI Elements Checkpoint): a
|
|
19
|
+
* separator after a turn, with Restore.
|
|
20
|
+
*/
|
|
21
|
+
export function Checkpoint({
|
|
22
|
+
label,
|
|
23
|
+
onRestore,
|
|
24
|
+
restoreLabel,
|
|
25
|
+
}: CheckpointProps) {
|
|
26
|
+
const messages = useUiMessages();
|
|
27
|
+
return (
|
|
28
|
+
<Marker variant="separator">
|
|
29
|
+
<MarkerContent className="inline-flex items-center gap-2">
|
|
30
|
+
{label}
|
|
31
|
+
{onRestore ? (
|
|
32
|
+
<Button
|
|
33
|
+
size="xs"
|
|
34
|
+
variant="outline"
|
|
35
|
+
aria-label={
|
|
36
|
+
restoreLabel ??
|
|
37
|
+
(typeof label === "string"
|
|
38
|
+
? messages.restoreTo(label)
|
|
39
|
+
: undefined)
|
|
40
|
+
}
|
|
41
|
+
onClick={onRestore}
|
|
42
|
+
>
|
|
43
|
+
{messages.restore}
|
|
44
|
+
</Button>
|
|
45
|
+
) : null}
|
|
46
|
+
</MarkerContent>
|
|
47
|
+
</Marker>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { hostnameOf } from "./chat-trace";
|
|
11
|
+
|
|
12
|
+
export interface InlineCitationProps {
|
|
13
|
+
url: string;
|
|
14
|
+
/** Falls back to the URL's hostname. */
|
|
15
|
+
title?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A source inside a sentence (shadcn AI Elements Inline Citation): its
|
|
21
|
+
* hostname, which shows the title, description and link on hover. For the
|
|
22
|
+
* list of sources after an answer, use Sources.
|
|
23
|
+
*/
|
|
24
|
+
export function InlineCitation({
|
|
25
|
+
url,
|
|
26
|
+
title,
|
|
27
|
+
description,
|
|
28
|
+
}: InlineCitationProps) {
|
|
29
|
+
const messages = useUiMessages();
|
|
30
|
+
const host = hostnameOf(url);
|
|
31
|
+
return (
|
|
32
|
+
<HoverCard>
|
|
33
|
+
<HoverCardTrigger
|
|
34
|
+
delay={10}
|
|
35
|
+
closeDelay={100}
|
|
36
|
+
render={<Button variant="secondary" size="xs" />}
|
|
37
|
+
>
|
|
38
|
+
{host}
|
|
39
|
+
</HoverCardTrigger>
|
|
40
|
+
<HoverCardContent className="flex w-64 flex-col gap-1">
|
|
41
|
+
<div className="font-medium">{title ?? host}</div>
|
|
42
|
+
{description ? (
|
|
43
|
+
<p className="text-muted-foreground">{description}</p>
|
|
44
|
+
) : null}
|
|
45
|
+
<a
|
|
46
|
+
href={url}
|
|
47
|
+
target="_blank"
|
|
48
|
+
rel="noreferrer"
|
|
49
|
+
className="text-xs text-muted-foreground underline-offset-4 hover:underline"
|
|
50
|
+
>
|
|
51
|
+
{host}
|
|
52
|
+
<span className="sr-only"> {messages.opensInNewTab}</span>
|
|
53
|
+
</a>
|
|
54
|
+
</HoverCardContent>
|
|
55
|
+
</HoverCard>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -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
|
+
}
|