@dowel-ui/react 0.2.0 → 0.3.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/README.md +10 -4
- package/dist/components/ai-agent-plan/ai-agent-plan.d.ts +50 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.d.ts.map +1 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.js +156 -0
- package/dist/components/ai-agent-plan/ai-agent-plan.js.map +1 -0
- package/dist/components/ai-agent-plan/index.d.ts +2 -0
- package/dist/components/ai-agent-plan/index.js +2 -0
- package/dist/components/ai-agent-plan/meta.js +17 -0
- package/dist/components/ai-agent-plan/meta.js.map +1 -0
- package/dist/components/ai-agent-status/ai-agent-status.d.ts +1 -1
- package/dist/components/ai-approval-request/ai-approval-request.d.ts +67 -0
- package/dist/components/ai-approval-request/ai-approval-request.d.ts.map +1 -0
- package/dist/components/ai-approval-request/ai-approval-request.js +218 -0
- package/dist/components/ai-approval-request/ai-approval-request.js.map +1 -0
- package/dist/components/ai-approval-request/index.d.ts +2 -0
- package/dist/components/ai-approval-request/index.js +2 -0
- package/dist/components/ai-approval-request/meta.js +17 -0
- package/dist/components/ai-approval-request/meta.js.map +1 -0
- package/dist/components/ai-response/ai-response.d.ts.map +1 -1
- package/dist/components/ai-response/ai-response.js +1 -0
- package/dist/components/ai-response/ai-response.js.map +1 -1
- package/dist/components/ai-structured-output/ai-structured-output.d.ts.map +1 -1
- package/dist/components/ai-structured-output/ai-structured-output.js +13 -2
- package/dist/components/ai-structured-output/ai-structured-output.js.map +1 -1
- package/dist/components/ai-tool/ai-tool.d.ts +1 -1
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/badge/badge.d.ts +1 -1
- package/dist/components/button/button.d.ts +1 -1
- package/dist/components/file-upload/file-upload.d.ts +46 -0
- package/dist/components/file-upload/file-upload.d.ts.map +1 -0
- package/dist/components/file-upload/file-upload.js +204 -0
- package/dist/components/file-upload/file-upload.js.map +1 -0
- package/dist/components/file-upload/index.d.ts +3 -0
- package/dist/components/file-upload/index.js +3 -0
- package/dist/components/file-upload/meta.js +17 -0
- package/dist/components/file-upload/meta.js.map +1 -0
- package/dist/components/file-upload/upload-queue.d.ts +87 -0
- package/dist/components/file-upload/upload-queue.d.ts.map +1 -0
- package/dist/components/file-upload/upload-queue.js +249 -0
- package/dist/components/file-upload/upload-queue.js.map +1 -0
- package/dist/components/progress/progress.d.ts +1 -1
- package/dist/components/progress/progress.js +1 -0
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/spinner/spinner.js +1 -0
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/tags-input/index.d.ts +2 -0
- package/dist/components/tags-input/index.js +2 -0
- package/dist/components/tags-input/meta.js +17 -0
- package/dist/components/tags-input/meta.js.map +1 -0
- package/dist/components/tags-input/tags-input.d.ts +47 -0
- package/dist/components/tags-input/tags-input.d.ts.map +1 -0
- package/dist/components/tags-input/tags-input.js +182 -0
- package/dist/components/tags-input/tags-input.js.map +1 -0
- package/dist/components/toast/toast.d.ts +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +6 -1
- package/dist/registry/components.d.ts.map +1 -1
- package/dist/registry/components.js +58 -50
- package/dist/registry/components.js.map +1 -1
- package/package.json +4 -4
- package/src/components/ai-agent-plan/ai-agent-plan.tsx +0 -0
- package/src/components/ai-agent-plan/index.ts +10 -0
- package/src/components/ai-agent-plan/meta.ts +19 -0
- package/src/components/ai-approval-request/ai-approval-request.tsx +368 -0
- package/src/components/ai-approval-request/index.ts +7 -0
- package/src/components/ai-approval-request/meta.ts +21 -0
- package/src/components/ai-response/ai-response.tsx +1 -0
- package/src/components/ai-structured-output/ai-structured-output.tsx +25 -1
- package/src/components/file-upload/file-upload.tsx +322 -0
- package/src/components/file-upload/index.ts +20 -0
- package/src/components/file-upload/meta.ts +21 -0
- package/src/components/file-upload/upload-queue.ts +337 -0
- package/src/components/progress/progress.tsx +3 -0
- package/src/components/spinner/spinner.tsx +5 -0
- package/src/components/tags-input/index.ts +1 -0
- package/src/components/tags-input/meta.ts +23 -0
- package/src/components/tags-input/tags-input.tsx +300 -0
- package/src/index.ts +4 -0
- package/src/registry/components.ts +8 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useId, useMemo, useState, type ComponentPropsWithRef, type ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
import { disabledStyles, focusRing } from "@/lib/styles";
|
|
6
|
+
import { cn } from "@/lib/utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The gate between an agent deciding to act and it acting.
|
|
10
|
+
*
|
|
11
|
+
* Two things separate this from the confirmations that already exist.
|
|
12
|
+
*
|
|
13
|
+
* The first is that the proposed arguments are editable. Every implementation
|
|
14
|
+
* surveyed returns a boolean over a read-only payload, which forces a false
|
|
15
|
+
* choice: approve a call whose recipient is wrong, or deny it and make the
|
|
16
|
+
* model try again. "Approve this, but fix the address first" is the answer
|
|
17
|
+
* people actually want, and it is only possible if the arguments are fields.
|
|
18
|
+
* Edited values come back in the decision, and are marked as changed so an
|
|
19
|
+
* audit trail can tell the model's proposal from the human's correction.
|
|
20
|
+
*
|
|
21
|
+
* The second is that it renders while the arguments are still arriving. The
|
|
22
|
+
* common implementation returns null until the tool input is complete, which
|
|
23
|
+
* means nothing is on screen at the moment approval becomes relevant and the
|
|
24
|
+
* request appears abruptly, fully formed. Here the request is visible as it
|
|
25
|
+
* forms, with the decision held until there is something whole to decide on.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export type ApprovalScope = "once" | "always";
|
|
29
|
+
|
|
30
|
+
export type ApprovalDecision =
|
|
31
|
+
| {
|
|
32
|
+
approved: true;
|
|
33
|
+
scope: ApprovalScope;
|
|
34
|
+
arguments: Record<string, string>;
|
|
35
|
+
edited: string[];
|
|
36
|
+
}
|
|
37
|
+
| { approved: false; reason?: string };
|
|
38
|
+
|
|
39
|
+
export interface ApprovalField {
|
|
40
|
+
name: string;
|
|
41
|
+
label: string;
|
|
42
|
+
/** A textarea instead of a single line. For message bodies and prompts. */
|
|
43
|
+
multiline?: boolean;
|
|
44
|
+
/** Locked arguments are shown but not editable — an id, a resolved amount. */
|
|
45
|
+
readOnly?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ApprovalRequestProps extends Omit<
|
|
49
|
+
ComponentPropsWithRef<"section">,
|
|
50
|
+
"onSubmit" | "children"
|
|
51
|
+
> {
|
|
52
|
+
/** The tool the model wants to call, as it named it. */
|
|
53
|
+
tool: string;
|
|
54
|
+
/** What the call will do, in the reader's language rather than the API's. */
|
|
55
|
+
summary: string;
|
|
56
|
+
/** Proposed arguments. Missing keys are treated as still arriving. */
|
|
57
|
+
arguments: Record<string, string>;
|
|
58
|
+
/** Which arguments to show, in order, and which may be changed. */
|
|
59
|
+
fields: ApprovalField[];
|
|
60
|
+
onDecision: (decision: ApprovalDecision) => void;
|
|
61
|
+
/**
|
|
62
|
+
* True while the model is still producing the arguments. The request renders
|
|
63
|
+
* anyway; only the decision waits.
|
|
64
|
+
*/
|
|
65
|
+
streaming?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Said plainly above the controls when the call cannot be taken back. Not a
|
|
68
|
+
* severity colour — the sentence is the warning.
|
|
69
|
+
*/
|
|
70
|
+
irreversible?: string;
|
|
71
|
+
/** Set once decided, to render the outcome instead of the controls. */
|
|
72
|
+
decision?: ApprovalDecision;
|
|
73
|
+
children?: ReactNode;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function ApprovalRequest({
|
|
77
|
+
className,
|
|
78
|
+
tool,
|
|
79
|
+
summary,
|
|
80
|
+
arguments: proposed,
|
|
81
|
+
fields,
|
|
82
|
+
onDecision,
|
|
83
|
+
streaming = false,
|
|
84
|
+
irreversible,
|
|
85
|
+
decision,
|
|
86
|
+
children,
|
|
87
|
+
...props
|
|
88
|
+
}: ApprovalRequestProps) {
|
|
89
|
+
const headingId = useId();
|
|
90
|
+
const [edits, setEdits] = useState<Record<string, string>>({});
|
|
91
|
+
const [denying, setDenying] = useState(false);
|
|
92
|
+
const [reason, setReason] = useState("");
|
|
93
|
+
|
|
94
|
+
// The model's proposal with the human's corrections applied on top. Keeping
|
|
95
|
+
// them apart is what lets the component say which is which.
|
|
96
|
+
const values = useMemo(() => ({ ...proposed, ...edits }), [proposed, edits]);
|
|
97
|
+
|
|
98
|
+
const edited = useMemo(
|
|
99
|
+
() => Object.keys(edits).filter((name) => edits[name] !== proposed[name]),
|
|
100
|
+
[edits, proposed],
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const missing = fields.filter((field) => proposed[field.name] === undefined);
|
|
104
|
+
const settled = !streaming && missing.length === 0;
|
|
105
|
+
|
|
106
|
+
if (decision) {
|
|
107
|
+
return (
|
|
108
|
+
<section
|
|
109
|
+
data-slot="approval-request"
|
|
110
|
+
data-state={decision.approved ? "approved" : "denied"}
|
|
111
|
+
aria-labelledby={headingId}
|
|
112
|
+
className={cn(
|
|
113
|
+
"rounded-lg border p-4 text-sm",
|
|
114
|
+
decision.approved ? "border-border bg-muted/40" : "border-border bg-muted/40",
|
|
115
|
+
className,
|
|
116
|
+
)}
|
|
117
|
+
{...props}
|
|
118
|
+
>
|
|
119
|
+
<h3 id={headingId} className="text-sm font-medium">
|
|
120
|
+
{summary}
|
|
121
|
+
</h3>
|
|
122
|
+
<p data-slot="approval-outcome" className="mt-1 text-xs text-muted-foreground">
|
|
123
|
+
{decision.approved
|
|
124
|
+
? `Approved ${decision.scope === "always" ? "for every call to this tool" : "once"}` +
|
|
125
|
+
(decision.edited.length > 0
|
|
126
|
+
? `, with ${String(decision.edited.length)} argument${decision.edited.length === 1 ? "" : "s"} corrected`
|
|
127
|
+
: "")
|
|
128
|
+
: `Denied${decision.reason ? `: ${decision.reason}` : ""}`}
|
|
129
|
+
</p>
|
|
130
|
+
</section>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<section
|
|
136
|
+
data-slot="approval-request"
|
|
137
|
+
data-state={settled ? "pending" : "forming"}
|
|
138
|
+
aria-labelledby={headingId}
|
|
139
|
+
// Busy while the arguments are still arriving, so a reader is told the
|
|
140
|
+
// request is not yet whole rather than acting on half of it.
|
|
141
|
+
aria-busy={!settled}
|
|
142
|
+
className={cn("rounded-lg border border-border bg-card p-4", className)}
|
|
143
|
+
{...props}
|
|
144
|
+
>
|
|
145
|
+
<div className="flex flex-wrap items-baseline justify-between gap-2">
|
|
146
|
+
<h3 id={headingId} className="text-sm font-medium">
|
|
147
|
+
{summary}
|
|
148
|
+
</h3>
|
|
149
|
+
<code className="rounded bg-muted px-1.5 py-0.5 font-mono text-2xs text-muted-foreground">
|
|
150
|
+
{tool}
|
|
151
|
+
</code>
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<dl className="mt-3 flex flex-col gap-2.5">
|
|
155
|
+
{fields.map((field) => {
|
|
156
|
+
const arrived = proposed[field.name] !== undefined;
|
|
157
|
+
const changed = edited.includes(field.name);
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<ApprovalArgument
|
|
161
|
+
key={field.name}
|
|
162
|
+
field={field}
|
|
163
|
+
value={values[field.name] ?? ""}
|
|
164
|
+
arrived={arrived}
|
|
165
|
+
changed={changed}
|
|
166
|
+
onChange={(next) => {
|
|
167
|
+
setEdits((current) => ({ ...current, [field.name]: next }));
|
|
168
|
+
}}
|
|
169
|
+
/>
|
|
170
|
+
);
|
|
171
|
+
})}
|
|
172
|
+
</dl>
|
|
173
|
+
|
|
174
|
+
{children}
|
|
175
|
+
|
|
176
|
+
{irreversible ? (
|
|
177
|
+
<p data-slot="approval-warning" className="mt-3 text-xs text-destructive">
|
|
178
|
+
{irreversible}
|
|
179
|
+
</p>
|
|
180
|
+
) : null}
|
|
181
|
+
|
|
182
|
+
{denying ? (
|
|
183
|
+
<div className="mt-3 flex flex-col gap-2">
|
|
184
|
+
<label htmlFor={`${headingId}-reason`} className="text-xs text-muted-foreground">
|
|
185
|
+
Why not? The model sees this.
|
|
186
|
+
</label>
|
|
187
|
+
<textarea
|
|
188
|
+
id={`${headingId}-reason`}
|
|
189
|
+
rows={2}
|
|
190
|
+
value={reason}
|
|
191
|
+
onChange={(event) => {
|
|
192
|
+
setReason(event.target.value);
|
|
193
|
+
}}
|
|
194
|
+
className={cn(
|
|
195
|
+
"w-full resize-none rounded-md border border-input bg-background px-2 py-1.5 text-sm",
|
|
196
|
+
focusRing,
|
|
197
|
+
)}
|
|
198
|
+
/>
|
|
199
|
+
<div className="flex flex-wrap gap-2">
|
|
200
|
+
<Action
|
|
201
|
+
variant="destructive"
|
|
202
|
+
onClick={() => {
|
|
203
|
+
onDecision({ approved: false, reason: reason.trim() || undefined });
|
|
204
|
+
}}
|
|
205
|
+
>
|
|
206
|
+
Deny
|
|
207
|
+
</Action>
|
|
208
|
+
<Action
|
|
209
|
+
onClick={() => {
|
|
210
|
+
setDenying(false);
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
Back
|
|
214
|
+
</Action>
|
|
215
|
+
</div>
|
|
216
|
+
</div>
|
|
217
|
+
) : (
|
|
218
|
+
<div className="mt-4 flex flex-wrap items-center gap-2">
|
|
219
|
+
<Action
|
|
220
|
+
variant="primary"
|
|
221
|
+
disabled={!settled}
|
|
222
|
+
onClick={() => {
|
|
223
|
+
onDecision({ approved: true, scope: "once", arguments: values, edited });
|
|
224
|
+
}}
|
|
225
|
+
>
|
|
226
|
+
{edited.length > 0 ? "Approve with changes" : "Approve once"}
|
|
227
|
+
</Action>
|
|
228
|
+
|
|
229
|
+
{/* Scope is a separate decision from approval, and blanket consent
|
|
230
|
+
should never be the easiest button to reach. */}
|
|
231
|
+
<Action
|
|
232
|
+
disabled={!settled}
|
|
233
|
+
onClick={() => {
|
|
234
|
+
onDecision({ approved: true, scope: "always", arguments: values, edited });
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
Always allow {tool}
|
|
238
|
+
</Action>
|
|
239
|
+
|
|
240
|
+
<Action
|
|
241
|
+
onClick={() => {
|
|
242
|
+
setDenying(true);
|
|
243
|
+
}}
|
|
244
|
+
>
|
|
245
|
+
Deny…
|
|
246
|
+
</Action>
|
|
247
|
+
|
|
248
|
+
{!settled ? (
|
|
249
|
+
<span aria-live="polite" className="text-xs text-muted-foreground">
|
|
250
|
+
Waiting for the model to finish the request
|
|
251
|
+
</span>
|
|
252
|
+
) : null}
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
</section>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function ApprovalArgument({
|
|
260
|
+
field,
|
|
261
|
+
value,
|
|
262
|
+
arrived,
|
|
263
|
+
changed,
|
|
264
|
+
onChange,
|
|
265
|
+
}: {
|
|
266
|
+
field: ApprovalField;
|
|
267
|
+
value: string;
|
|
268
|
+
arrived: boolean;
|
|
269
|
+
changed: boolean;
|
|
270
|
+
onChange: (value: string) => void;
|
|
271
|
+
}) {
|
|
272
|
+
const id = useId();
|
|
273
|
+
const changedId = useId();
|
|
274
|
+
const editable = !field.readOnly && arrived;
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<div
|
|
278
|
+
data-slot="approval-argument"
|
|
279
|
+
data-changed={changed || undefined}
|
|
280
|
+
className="flex flex-col gap-1"
|
|
281
|
+
>
|
|
282
|
+
<dt className="flex items-baseline gap-1">
|
|
283
|
+
<label htmlFor={editable ? id : undefined} className="text-xs text-muted-foreground">
|
|
284
|
+
{field.label}
|
|
285
|
+
</label>
|
|
286
|
+
{/* Outside the label, and attached as a description instead. Inside it,
|
|
287
|
+
editing a field would rename the field — a screen reader user would
|
|
288
|
+
hear its accessible name change under them mid-edit. Marked in text
|
|
289
|
+
rather than by border colour alone, because an audit trail has to
|
|
290
|
+
tell the model's proposal from the human's correction. */}
|
|
291
|
+
{changed ? (
|
|
292
|
+
<span id={changedId} className="text-xs text-warning">
|
|
293
|
+
· changed from the model’s proposal
|
|
294
|
+
</span>
|
|
295
|
+
) : null}
|
|
296
|
+
</dt>
|
|
297
|
+
<dd className="m-0">
|
|
298
|
+
{!arrived ? (
|
|
299
|
+
<span
|
|
300
|
+
aria-hidden="true"
|
|
301
|
+
className="block h-8 w-full animate-pulse-soft rounded-md bg-muted"
|
|
302
|
+
/>
|
|
303
|
+
) : editable ? (
|
|
304
|
+
field.multiline ? (
|
|
305
|
+
<textarea
|
|
306
|
+
id={id}
|
|
307
|
+
aria-describedby={changed ? changedId : undefined}
|
|
308
|
+
rows={3}
|
|
309
|
+
value={value}
|
|
310
|
+
onChange={(event) => {
|
|
311
|
+
onChange(event.target.value);
|
|
312
|
+
}}
|
|
313
|
+
className={cn(
|
|
314
|
+
"w-full resize-none rounded-md border border-input bg-background px-2 py-1.5 font-mono text-xs",
|
|
315
|
+
changed && "border-warning",
|
|
316
|
+
focusRing,
|
|
317
|
+
)}
|
|
318
|
+
/>
|
|
319
|
+
) : (
|
|
320
|
+
<input
|
|
321
|
+
id={id}
|
|
322
|
+
type="text"
|
|
323
|
+
aria-describedby={changed ? changedId : undefined}
|
|
324
|
+
value={value}
|
|
325
|
+
onChange={(event) => {
|
|
326
|
+
onChange(event.target.value);
|
|
327
|
+
}}
|
|
328
|
+
className={cn(
|
|
329
|
+
"w-full rounded-md border border-input bg-background px-2 py-1.5 font-mono text-xs",
|
|
330
|
+
changed && "border-warning",
|
|
331
|
+
focusRing,
|
|
332
|
+
)}
|
|
333
|
+
/>
|
|
334
|
+
)
|
|
335
|
+
) : (
|
|
336
|
+
<p className="rounded-md bg-muted px-2 py-1.5 font-mono text-xs break-words">
|
|
337
|
+
{value}
|
|
338
|
+
</p>
|
|
339
|
+
)}
|
|
340
|
+
</dd>
|
|
341
|
+
</div>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function Action({
|
|
346
|
+
className,
|
|
347
|
+
variant = "default",
|
|
348
|
+
...props
|
|
349
|
+
}: ComponentPropsWithRef<"button"> & { variant?: "default" | "primary" | "destructive" }) {
|
|
350
|
+
return (
|
|
351
|
+
<button
|
|
352
|
+
type="button"
|
|
353
|
+
className={cn(
|
|
354
|
+
"rounded-md border px-2.5 py-1 text-xs font-medium transition-colors",
|
|
355
|
+
variant === "primary" &&
|
|
356
|
+
"border-primary bg-primary text-primary-foreground hover:bg-primary-hover",
|
|
357
|
+
variant === "destructive" &&
|
|
358
|
+
"border-destructive bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
359
|
+
variant === "default" &&
|
|
360
|
+
"border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
361
|
+
focusRing,
|
|
362
|
+
disabledStyles,
|
|
363
|
+
className,
|
|
364
|
+
)}
|
|
365
|
+
{...props}
|
|
366
|
+
/>
|
|
367
|
+
);
|
|
368
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineMeta } from "@/registry/schema";
|
|
2
|
+
|
|
3
|
+
export const meta = defineMeta({
|
|
4
|
+
name: "ai-approval-request",
|
|
5
|
+
title: "AI Approval Request",
|
|
6
|
+
description: "Approve a tool call — after correcting the arguments the model got wrong.",
|
|
7
|
+
category: "ai",
|
|
8
|
+
status: "stable",
|
|
9
|
+
dependencies: [],
|
|
10
|
+
registryDependencies: [],
|
|
11
|
+
files: ["ai-approval-request.tsx"],
|
|
12
|
+
a11y:
|
|
13
|
+
"The proposed arguments are a description list of real labelled form controls, so each value " +
|
|
14
|
+
"is associated with its name and editable ones are reachable by keyboard. A corrected " +
|
|
15
|
+
"argument is marked in text rather than by border colour alone, because an audit trail has " +
|
|
16
|
+
"to distinguish the model's proposal from the human's edit. The request is aria-busy while " +
|
|
17
|
+
"arguments are still arriving and the decision controls stay disabled until it is whole — " +
|
|
18
|
+
"rendering nothing until then, as the common implementation does, means nothing is on screen " +
|
|
19
|
+
"at the moment approval becomes relevant. Irreversibility is stated as a sentence, never as a " +
|
|
20
|
+
"severity colour.",
|
|
21
|
+
});
|
|
@@ -50,6 +50,7 @@ export function ResponseCaret({ className, ...props }: ComponentPropsWithRef<"sp
|
|
|
50
50
|
<span
|
|
51
51
|
data-slot="response-caret"
|
|
52
52
|
aria-hidden="true"
|
|
53
|
+
data-motion="indicator"
|
|
53
54
|
className={cn(
|
|
54
55
|
"ml-0.5 inline-block h-[1em] w-[2px] translate-y-[0.15em] animate-caret bg-current align-baseline",
|
|
55
56
|
className,
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createContext,
|
|
5
5
|
useContext,
|
|
6
6
|
useMemo,
|
|
7
|
+
useState,
|
|
7
8
|
type ComponentPropsWithRef,
|
|
8
9
|
type ReactNode,
|
|
9
10
|
} from "react";
|
|
@@ -167,10 +168,28 @@ export function StructuredField({ className, name, children, ...props }: Structu
|
|
|
167
168
|
const state = stateOf(name);
|
|
168
169
|
const raw = value[name];
|
|
169
170
|
|
|
171
|
+
// "A token arrived" and "this field is final" are different facts, and in a
|
|
172
|
+
// streamed object they look identical. The settle makes that distinction
|
|
173
|
+
// visible — so it plays on the transition into settled, and never on a field
|
|
174
|
+
// that was already final when the component mounted.
|
|
175
|
+
//
|
|
176
|
+
// State adjusted during render rather than tracked in a ref: reading a ref
|
|
177
|
+
// while rendering is unsafe under concurrent rendering, and an effect would
|
|
178
|
+
// paint the plain value first and animate a frame later. React re-renders
|
|
179
|
+
// immediately here and discards the intermediate pass.
|
|
180
|
+
const [seenState, setSeenState] = useState<FieldState>(state);
|
|
181
|
+
const [hasSettled, setHasSettled] = useState(false);
|
|
182
|
+
|
|
183
|
+
if (seenState !== state) {
|
|
184
|
+
setSeenState(state);
|
|
185
|
+
if (state === "settled" && seenState !== "settled") setHasSettled(true);
|
|
186
|
+
}
|
|
187
|
+
|
|
170
188
|
return (
|
|
171
189
|
<div
|
|
172
190
|
data-slot="structured-field"
|
|
173
191
|
data-state={state}
|
|
192
|
+
data-settled={hasSettled || undefined}
|
|
174
193
|
data-field={name}
|
|
175
194
|
className={cn("flex flex-col gap-1", className)}
|
|
176
195
|
{...props}
|
|
@@ -195,7 +214,12 @@ export function StructuredField({ className, name, children, ...props }: Structu
|
|
|
195
214
|
className="block h-4 w-24 animate-pulse-soft rounded bg-muted"
|
|
196
215
|
/>
|
|
197
216
|
) : (
|
|
198
|
-
|
|
217
|
+
<span
|
|
218
|
+
data-slot="structured-field-value"
|
|
219
|
+
className={cn(hasSettled && "inline-block animate-settle")}
|
|
220
|
+
>
|
|
221
|
+
{children ?? formatValue(raw, name)}
|
|
222
|
+
</span>
|
|
199
223
|
)}
|
|
200
224
|
</dd>
|
|
201
225
|
</div>
|