agentic-ui-kit 0.8.0 → 0.9.1
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 +19 -15
- package/dist/ask-user-CwDYhXX4.js +388 -0
- package/dist/core.js +3 -103
- package/dist/extensions-CJ4Asuxk.js +329 -0
- package/dist/index.js +43 -1394
- package/dist/partial-json-w_oXePqJ.js +111 -0
- package/dist/types/core/src/blocks.d.ts +1 -1
- package/dist/types/core/src/events.d.ts +1 -1
- package/dist/types/core/src/index.d.ts +9 -20
- package/dist/types/core/src/reduce.d.ts +2 -2
- package/dist/types/core/src/sse.d.ts +1 -1
- package/dist/types/core/src/ui-components.d.ts +1 -1
- package/dist/types/core/src/ui-markup.d.ts +1 -1
- package/dist/types/core/src/visuals.d.ts +11 -0
- package/dist/types/react/src/components/approval-card.d.ts +1 -1
- package/dist/types/react/src/components/ask-user.d.ts +1 -1
- package/dist/types/react/src/components/chat-list.d.ts +1 -1
- package/dist/types/react/src/components/composer.d.ts +1 -1
- package/dist/types/react/src/components/extensions.d.ts +50 -0
- package/dist/types/react/src/components/message-list.d.ts +1 -1
- package/dist/types/react/src/components/messages.d.ts +1 -1
- package/dist/types/react/src/components/tool-prompt.d.ts +1 -1
- package/dist/types/react/src/components/tools.d.ts +2 -2
- package/dist/types/react/src/hooks/sse-transport.d.ts +1 -1
- package/dist/types/react/src/hooks/use-chat.d.ts +1 -1
- package/dist/types/react/src/index.d.ts +86 -90
- package/dist/types/react/src/primitives/chat-theme.d.ts +3 -3
- package/dist/types/react/src/views/chat-transcript.d.ts +2 -5
- package/dist/types/react/src/views/chat-view.d.ts +4 -11
- package/dist/types/react/src/views/sidebar.d.ts +1 -1
- package/dist/types/react/src/visuals/core.d.ts +1 -0
- package/dist/types/react/src/visuals/index.d.ts +8 -0
- package/dist/types/react/src/visuals/provider.d.ts +26 -0
- package/dist/types/react/src/{components → visuals}/ui-components.d.ts +2 -2
- package/dist/types/react/src/{components → visuals}/ui-tree.d.ts +2 -1
- package/dist/types/react/src/{components → visuals}/widget-frame.d.ts +2 -1
- package/dist/{src-BrPYkHdt.js → visuals-CxCXnEob.js} +96 -490
- package/dist/visuals-core.js +1 -0
- package/dist/visuals.js +1134 -0
- package/package.json +9 -1
- /package/dist/types/react/src/{components → visuals}/replacements.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,158 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { a as LabelsProvider, c as Button, d as cx, i as useChatInteraction, l as IconButton, n as ChatInteractionProvider, o as defaultLabels, r as useChatExtensions, s as useLabels, t as ChatExtensionsProvider, u as Tooltip } from "./extensions-CJ4Asuxk.js";
|
|
3
|
+
import { a as readEventStream, c as activityTokens, h as settleToolCall, l as applyEvent, n as readAskUserInput, r as readAskUserResult, s as toBlocks, u as awaitingToolCalls } from "./ask-user-CwDYhXX4.js";
|
|
3
4
|
import { clsx } from "clsx";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Autocomplete, Button as Button$1, Dialog, DialogTrigger, DialogTrigger as DialogTrigger$1, Disclosure as Disclosure$1, DisclosurePanel, Focusable, Header, Heading, Input, Keyboard, Link, Menu as Menu$1, MenuItem as MenuItem$1, MenuSection as MenuSection$1, MenuTrigger, MenuTrigger as MenuTrigger$1, Modal as Modal$1, ModalOverlay, Popover as Popover$1, SearchField, Separator, SubmenuTrigger, Text, ToggleButton, ToggleButtonGroup, Tooltip as Tooltip$1, TooltipTrigger, useFilter } from "react-aria-components";
|
|
5
|
+
import { Children, Fragment, createContext, createElement, isValidElement, memo, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
|
+
import { Autocomplete, Button as Button$1, Dialog, DialogTrigger, DialogTrigger as DialogTrigger$1, Disclosure as Disclosure$1, DisclosurePanel, Focusable, Header, Heading, Input, Keyboard, Link, Menu as Menu$1, MenuItem as MenuItem$1, MenuSection as MenuSection$1, MenuTrigger, MenuTrigger as MenuTrigger$1, Modal as Modal$1, ModalOverlay, Popover as Popover$1, SearchField, Separator, SubmenuTrigger, Text, ToggleButton, ToggleButtonGroup, useFilter } from "react-aria-components";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { AlertTriangle, ArrowDown, ArrowRight, ArrowUp, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronsUpDown, Copy, FileText, Folder, FolderOpen, FolderPlus, Globe, GripVertical, Info, MessageSquare, Mic, MoreHorizontal, PanelLeft, Pencil, Pin, PinOff, Plus, RefreshCw, Share, ShieldQuestion, Square, ThumbsDown, ThumbsUp, Trash2, Volume2, X } from "lucide-react";
|
|
9
9
|
import { UNSAFE_PortalProvider } from "react-aria";
|
|
10
10
|
import { createMathPlugin } from "@streamdown/math";
|
|
11
11
|
import { Streamdown, defaultComponents, defaultRehypePlugins } from "streamdown";
|
|
12
|
-
// src/primitives/cx.ts
|
|
13
|
-
const twMerge = extendTailwindMerge({ extend: { theme: {
|
|
14
|
-
radius: [
|
|
15
|
-
"chat-sm",
|
|
16
|
-
"chat-md",
|
|
17
|
-
"chat-lg",
|
|
18
|
-
"chat-popover"
|
|
19
|
-
],
|
|
20
|
-
shadow: ["chat-popover"],
|
|
21
|
-
animate: [
|
|
22
|
-
"chat-in",
|
|
23
|
-
"chat-out",
|
|
24
|
-
"chat-fade-in",
|
|
25
|
-
"chat-fade-out",
|
|
26
|
-
"chat-drawer-in",
|
|
27
|
-
"chat-drawer-out",
|
|
28
|
-
"chat-drawer-in-right",
|
|
29
|
-
"chat-drawer-out-right",
|
|
30
|
-
"chat-sheet-in",
|
|
31
|
-
"chat-sheet-out"
|
|
32
|
-
]
|
|
33
|
-
} } });
|
|
34
|
-
/** `clsx` plus tailwind-merge: later classes win over earlier ones that set the same property, so a caller's `h-7` or `rounded-none` beats the kit's. */
|
|
35
|
-
function cx(...inputs) {
|
|
36
|
-
return twMerge(clsx(inputs));
|
|
37
|
-
}
|
|
38
|
-
// src/primitives/tooltip.tsx
|
|
39
|
-
function Tooltip({ content, children, placement = "top", delay = 600 }) {
|
|
40
|
-
return /* @__PURE__ */ jsxs(TooltipTrigger, {
|
|
41
|
-
delay,
|
|
42
|
-
closeDelay: 0,
|
|
43
|
-
children: [children, /* @__PURE__ */ jsx(Tooltip$1, {
|
|
44
|
-
placement,
|
|
45
|
-
offset: 6,
|
|
46
|
-
className: "rounded-chat-sm bg-chat-raised px-2 py-1 font-chat-sans text-(length:--chat-ui-font-size-sm) leading-4 text-chat-fg shadow-chat-popover motion-safe:data-entering:animate-chat-in motion-safe:data-exiting:animate-chat-out",
|
|
47
|
-
children: content
|
|
48
|
-
})]
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
// src/primitives/button.tsx
|
|
52
|
-
const focusRing = "outline-none data-focus-visible:ring-2 data-focus-visible:ring-chat-focus";
|
|
53
|
-
const variants = {
|
|
54
|
-
/** Plain text button, highlights on hover. Sidebar rows, header buttons. */
|
|
55
|
-
ghost: "text-chat-fg data-hovered:bg-chat-hover data-pressed:bg-chat-selected",
|
|
56
|
-
/** Filled with the surface color, e.g. the selected Chat/Cowork toggle. */
|
|
57
|
-
subtle: "bg-chat-surface font-medium text-chat-fg data-hovered:bg-chat-hover data-pressed:bg-chat-selected",
|
|
58
|
-
/** A thin border, no fill: secondary actions next to a primary one, e.g. Cancel or Share. */
|
|
59
|
-
outline: "border border-chat-border-strong font-medium text-chat-fg data-hovered:bg-chat-hover data-pressed:bg-chat-selected",
|
|
60
|
-
/** The send button and the one main action of a dialog. */
|
|
61
|
-
primary: "bg-chat-accent font-medium text-chat-accent-fg data-hovered:brightness-110 data-pressed:brightness-95",
|
|
62
|
-
/**
|
|
63
|
-
* Destructive confirmations, e.g. Delete chat. Fill --chat-danger-bg (default: --chat-danger, darkened so it
|
|
64
|
-
* doesn't read as the accent), text --chat-danger-fg (default white).
|
|
65
|
-
*/
|
|
66
|
-
danger: "bg-[var(--chat-danger-bg,color-mix(in_srgb,var(--chat-danger)_70%,black))] font-medium text-[var(--chat-danger-fg,#fff)] data-hovered:brightness-110 data-pressed:brightness-95"
|
|
67
|
-
};
|
|
68
|
-
const sizes$1 = {
|
|
69
|
-
sm: "h-7 gap-1.5 px-2 text-(length:--chat-ui-font-size) leading-5 [@media(pointer:coarse)]:h-9",
|
|
70
|
-
md: "h-8 gap-2 px-2.5 text-(length:--chat-ui-font-size) leading-5 [@media(pointer:coarse)]:h-10",
|
|
71
|
-
/** Dialog and empty-state actions. */
|
|
72
|
-
lg: "h-9 gap-2 px-3.5 text-(length:--chat-ui-font-size) leading-5 [@media(pointer:coarse)]:h-11"
|
|
73
|
-
};
|
|
74
|
-
/** Press handlers dropped from a button that is disabled with a reason; it only looks and announces as disabled. */
|
|
75
|
-
const pressHandlers = [
|
|
76
|
-
"onPress",
|
|
77
|
-
"onPressStart",
|
|
78
|
-
"onPressEnd",
|
|
79
|
-
"onPressChange",
|
|
80
|
-
"onPressUp",
|
|
81
|
-
"onClick"
|
|
82
|
-
];
|
|
83
|
-
/**
|
|
84
|
-
* A disabled button that still explains itself. React Aria's `isDisabled` makes the button unfocusable and
|
|
85
|
-
* hoverable-less, so there'd be nothing to hang a tooltip on. With a reason the button instead stays focusable
|
|
86
|
-
* with `aria-disabled`, loses its press handlers and never submits a form, and the reason is shown as a tooltip
|
|
87
|
-
* and read as its description.
|
|
88
|
-
*/
|
|
89
|
-
function useDisabledReason(props, disabledReason) {
|
|
90
|
-
const id = useId();
|
|
91
|
-
const active = Boolean(props.isDisabled && disabledReason);
|
|
92
|
-
if (!active) return {
|
|
93
|
-
active,
|
|
94
|
-
props,
|
|
95
|
-
reasonId: void 0
|
|
96
|
-
};
|
|
97
|
-
const rest = {
|
|
98
|
-
...props,
|
|
99
|
-
isDisabled: false,
|
|
100
|
-
type: "button"
|
|
101
|
-
};
|
|
102
|
-
for (const h of pressHandlers) delete rest[h];
|
|
103
|
-
rest["aria-disabled"] = true;
|
|
104
|
-
rest["data-disabled"] = true;
|
|
105
|
-
rest["aria-describedby"] = [props["aria-describedby"], id].filter(Boolean).join(" ");
|
|
106
|
-
return {
|
|
107
|
-
active,
|
|
108
|
-
props: rest,
|
|
109
|
-
reasonId: id
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/** Hover and press styles are dropped while a button is disabled with a reason, to look as disabled as one that is. */
|
|
113
|
-
const noInteraction = (classes) => classes.replace(/data-(hovered|pressed):\S+\s*/g, "");
|
|
114
|
-
function WithReason({ active, reasonId, reason, children }) {
|
|
115
|
-
if (!active) return children;
|
|
116
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Tooltip, {
|
|
117
|
-
content: reason,
|
|
118
|
-
children
|
|
119
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
120
|
-
id: reasonId,
|
|
121
|
-
hidden: true,
|
|
122
|
-
children: reason
|
|
123
|
-
})] });
|
|
124
|
-
}
|
|
125
|
-
function Button({ variant = "ghost", size = "md", className, disabledReason, ...rest }) {
|
|
126
|
-
const { active, props, reasonId } = useDisabledReason(rest, disabledReason);
|
|
127
|
-
const button = /* @__PURE__ */ jsx(Button$1, {
|
|
128
|
-
...props,
|
|
129
|
-
className: cx("inline-flex cursor-pointer items-center justify-center rounded-chat-sm font-chat-sans whitespace-nowrap transition-colors select-none [&_svg]:size-4 [&_svg]:shrink-0", "data-disabled:cursor-default data-disabled:opacity-40", focusRing, active ? noInteraction(variants[variant]) : variants[variant], sizes$1[size], className)
|
|
130
|
-
});
|
|
131
|
-
return /* @__PURE__ */ jsx(WithReason, {
|
|
132
|
-
active,
|
|
133
|
-
reasonId,
|
|
134
|
-
reason: disabledReason,
|
|
135
|
-
children: button
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
function IconButton({ label, variant = "ghost", size = "md", tooltip = true, className, disabledReason, ...rest }) {
|
|
139
|
-
const { active, props, reasonId } = useDisabledReason(rest, disabledReason);
|
|
140
|
-
const button = /* @__PURE__ */ jsx(Button$1, {
|
|
141
|
-
...props,
|
|
142
|
-
"aria-label": label,
|
|
143
|
-
className: cx("inline-flex shrink-0 cursor-pointer items-center justify-center rounded-chat-sm transition-colors select-none", "data-disabled:cursor-default data-disabled:opacity-40 [&_svg]:size-4", focusRing, active ? noInteraction(variants[variant]) : variants[variant], variant === "ghost" && (active ? "text-chat-muted" : "text-chat-muted data-hovered:text-chat-fg"), size === "sm" ? "size-7 [@media(pointer:coarse)]:size-9" : "size-8 [@media(pointer:coarse)]:size-10", className)
|
|
144
|
-
});
|
|
145
|
-
if (active) return /* @__PURE__ */ jsx(WithReason, {
|
|
146
|
-
active: true,
|
|
147
|
-
reasonId,
|
|
148
|
-
reason: disabledReason,
|
|
149
|
-
children: button
|
|
150
|
-
});
|
|
151
|
-
return tooltip ? /* @__PURE__ */ jsx(Tooltip, {
|
|
152
|
-
content: label,
|
|
153
|
-
children: button
|
|
154
|
-
}) : button;
|
|
155
|
-
}
|
|
156
12
|
// src/primitives/badge.tsx
|
|
157
13
|
const tones = {
|
|
158
14
|
/** Outlined, e.g. "Recommended". */
|
|
@@ -251,159 +107,6 @@ function IconSlot({ children, className }) {
|
|
|
251
107
|
children
|
|
252
108
|
});
|
|
253
109
|
}
|
|
254
|
-
// src/primitives/labels.tsx
|
|
255
|
-
const plural = (count, one, many) => count === 1 ? one : many(count);
|
|
256
|
-
/** The English strings. */
|
|
257
|
-
const defaultLabels = {
|
|
258
|
-
thinking: "Thinking…",
|
|
259
|
-
thought: "Thought",
|
|
260
|
-
thoughtFor: (duration) => `Thought for ${duration}`,
|
|
261
|
-
waitingForYou: " · waiting for you",
|
|
262
|
-
usedTool: (name) => `used ${name}`,
|
|
263
|
-
joinSummaries: (phrases) => {
|
|
264
|
-
const text = phrases.join(", ");
|
|
265
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
266
|
-
},
|
|
267
|
-
duration: (seconds) => seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`,
|
|
268
|
-
ranCommandLabel: "Ran a command",
|
|
269
|
-
ranCommands: (count) => plural(count, "ran a command", (n) => `ran ${n} commands`),
|
|
270
|
-
runCommandAsk: "Run this command?",
|
|
271
|
-
searchWebAsk: "Search the web?",
|
|
272
|
-
readPageAsk: "Read this page?",
|
|
273
|
-
searchedWebLabel: "Searched the web",
|
|
274
|
-
readPageLabel: "Read page",
|
|
275
|
-
readPages: (count) => plural(count, "read a page", (n) => `read ${n} pages`),
|
|
276
|
-
searchedWeb: (count) => plural(count, "searched the web", (n) => `searched the web ${n} times`),
|
|
277
|
-
recalledMemoryLabel: "Recalled memory",
|
|
278
|
-
recalledMemory: () => "recalled memory",
|
|
279
|
-
output: "Output",
|
|
280
|
-
noOutput: "(no output)",
|
|
281
|
-
noResults: "No results",
|
|
282
|
-
reasoningHidden: "The model's reasoning is not shown.",
|
|
283
|
-
allowTool: (name) => `Allow ${name}?`,
|
|
284
|
-
allowAction: (label) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
285
|
-
"Allow ",
|
|
286
|
-
label,
|
|
287
|
-
"?"
|
|
288
|
-
] }),
|
|
289
|
-
allow: "Allow",
|
|
290
|
-
deny: "Deny",
|
|
291
|
-
sidebar: "Sidebar",
|
|
292
|
-
closeSidebar: "Close sidebar",
|
|
293
|
-
openSidebar: "Open sidebar",
|
|
294
|
-
expandSidebar: "Expand sidebar",
|
|
295
|
-
collapseSidebar: "Collapse sidebar",
|
|
296
|
-
resizeSidebar: "Resize sidebar",
|
|
297
|
-
withShortcut: (label, keys) => `${label} (${keys})`,
|
|
298
|
-
ctrlKey: "Ctrl",
|
|
299
|
-
context: "Context",
|
|
300
|
-
contextUsed: "Context used",
|
|
301
|
-
percentUsed: (percent) => `${percent}% used`,
|
|
302
|
-
contextSummary: (used, limit, percent) => `Context: ${used} / ${limit} (${percent}%)`,
|
|
303
|
-
contextLoading: "Context: loading",
|
|
304
|
-
freeSpace: "Free space",
|
|
305
|
-
tokenCount: (count) => `${count} tokens`,
|
|
306
|
-
replyPlaceholder: "Reply…",
|
|
307
|
-
replyDirectly: "Or reply directly…",
|
|
308
|
-
askUserPrompt: "Question for you",
|
|
309
|
-
askUserPager: (current, total) => `${current} of ${total}`,
|
|
310
|
-
askUserPrevious: "Previous question",
|
|
311
|
-
askUserNext: "Next question",
|
|
312
|
-
askUserContinue: "Continue",
|
|
313
|
-
askUserSubmit: "Send answers",
|
|
314
|
-
askUserClose: "Close and decline",
|
|
315
|
-
askUserSomethingElse: "Something else",
|
|
316
|
-
askUserSkip: "Skip",
|
|
317
|
-
askUserSelected: (count) => `${count} selected`,
|
|
318
|
-
askUserRankHint: "Drag to re-order",
|
|
319
|
-
askUserReorder: (option) => `Move ${option}`,
|
|
320
|
-
askUserReorderKeys: "Press Alt with the up or down arrow to move",
|
|
321
|
-
askUserPicked: (options) => options.join(", "),
|
|
322
|
-
askUserRanked: (options) => `Ranked: ${options.map((o, i) => `${i + 1}. ${o}`).join(" ")}`,
|
|
323
|
-
askUserSkipped: "Skipped",
|
|
324
|
-
askUserDeclined: "You declined to answer",
|
|
325
|
-
askUserAnswers: "Your answers",
|
|
326
|
-
message: "Message",
|
|
327
|
-
stop: "Stop",
|
|
328
|
-
send: "Send",
|
|
329
|
-
listening: "Listening…",
|
|
330
|
-
transcribing: "Transcribing…",
|
|
331
|
-
dictate: "Dictate",
|
|
332
|
-
dictationCancel: "Cancel dictation",
|
|
333
|
-
dictationAccept: "Use dictation",
|
|
334
|
-
addFiles: "Add files and more",
|
|
335
|
-
attachments: "Attachments",
|
|
336
|
-
editPastedText: "Edit pasted text",
|
|
337
|
-
viewPastedText: "View pasted text",
|
|
338
|
-
removeAttachment: (name) => `Remove ${name}`,
|
|
339
|
-
pastedText: "Pasted text",
|
|
340
|
-
pasted: "Pasted",
|
|
341
|
-
failed: "Failed",
|
|
342
|
-
file: "File",
|
|
343
|
-
uploadFailed: "Upload failed",
|
|
344
|
-
cancel: "Cancel",
|
|
345
|
-
close: "Close",
|
|
346
|
-
save: "Save",
|
|
347
|
-
chats: "Chats",
|
|
348
|
-
running: "Running",
|
|
349
|
-
unread: "Unread",
|
|
350
|
-
moreOptionsFor: (title) => `More options for ${title}`,
|
|
351
|
-
new: "New",
|
|
352
|
-
viewAll: "View all",
|
|
353
|
-
chatActions: "Chat actions",
|
|
354
|
-
pin: "Pin",
|
|
355
|
-
unpin: "Unpin",
|
|
356
|
-
rename: "Rename",
|
|
357
|
-
addToProject: "Add to project",
|
|
358
|
-
searchProjects: "Search or create a project",
|
|
359
|
-
projects: "Projects",
|
|
360
|
-
newProject: "New project",
|
|
361
|
-
shareChat: "Share chat",
|
|
362
|
-
delete: "Delete",
|
|
363
|
-
justNow: "just now",
|
|
364
|
-
copy: "Copy",
|
|
365
|
-
copied: "Copied",
|
|
366
|
-
copyFieldLabel: "Link",
|
|
367
|
-
retry: "Retry",
|
|
368
|
-
edit: "Edit",
|
|
369
|
-
readAloud: "Read aloud",
|
|
370
|
-
goodResponse: "Good response",
|
|
371
|
-
badResponse: "Bad response",
|
|
372
|
-
somethingWentWrong: "Something went wrong.",
|
|
373
|
-
conversation: "Conversation",
|
|
374
|
-
scrollToBottom: "Scroll to bottom",
|
|
375
|
-
showMore: "Show more",
|
|
376
|
-
showLess: "Show less",
|
|
377
|
-
model: "Model",
|
|
378
|
-
modelButton: (label) => `Model: ${label}`,
|
|
379
|
-
effort: "Effort",
|
|
380
|
-
effortNote: "Higher effort means more thorough responses, but takes longer and uses your limits faster.",
|
|
381
|
-
recommended: "Recommended",
|
|
382
|
-
effortFaster: "Faster",
|
|
383
|
-
effortSmarter: "Smarter",
|
|
384
|
-
moreModels: "More models",
|
|
385
|
-
widget: "Widget",
|
|
386
|
-
visualUpdated: "Updated below ↓",
|
|
387
|
-
visualUpdating: "Updating…",
|
|
388
|
-
drawingWidget: "Drawing"
|
|
389
|
-
};
|
|
390
|
-
const LabelsContext = createContext(defaultLabels);
|
|
391
|
-
/** Merges `labels` over the labels of the enclosing provider (or the defaults). */
|
|
392
|
-
function LabelsProvider({ labels, children }) {
|
|
393
|
-
const parent = useLabels();
|
|
394
|
-
const merged = useMemo(() => labels ? {
|
|
395
|
-
...parent,
|
|
396
|
-
...labels
|
|
397
|
-
} : parent, [parent, labels]);
|
|
398
|
-
return /* @__PURE__ */ jsx(LabelsContext.Provider, {
|
|
399
|
-
value: merged,
|
|
400
|
-
children
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
/** The active UI strings: the enclosing `ChatTheme`'s `labels` over the English defaults. */
|
|
404
|
-
function useLabels() {
|
|
405
|
-
return useContext(LabelsContext);
|
|
406
|
-
}
|
|
407
110
|
// src/primitives/copy-button.tsx
|
|
408
111
|
/** Copies `text`; shows a check for a moment after. */
|
|
409
112
|
function CopyButton({ text, className }) {
|
|
@@ -1600,837 +1303,6 @@ function useControllable(value, initial, onChange) {
|
|
|
1600
1303
|
}
|
|
1601
1304
|
/** True on Apple platforms, where the shortcut modifier is ⌘ instead of Ctrl. */
|
|
1602
1305
|
const isMacPlatform = () => typeof navigator !== "undefined" && /mac|iphone|ipad|ipod/i.test(navigator.platform || navigator.userAgent);
|
|
1603
|
-
// src/components/replacements.tsx
|
|
1604
|
-
/**
|
|
1605
|
-
* In-place updates of drawn visuals: a tool call whose input has `replaces: <id>` takes the place of that
|
|
1606
|
-
* earlier call. In the same reply the newest finished call is drawn where the first one was, and the old one
|
|
1607
|
-
* stays (dimmed) until the new one's input is complete. A call replaced from a later reply folds into a link.
|
|
1608
|
-
*/
|
|
1609
|
-
/** Ready to take the old one's place: its input is complete and it didn't fail. */
|
|
1610
|
-
const isReady = (p) => p.status !== "streaming" && p.status !== "input" && p.status !== "error";
|
|
1611
|
-
const callsOf = (m) => m.parts.filter((p) => p.type === "tool_call");
|
|
1612
|
-
const replaces = (p) => replacedId(p.input ?? p.partialInput);
|
|
1613
|
-
const titleOf = (p) => {
|
|
1614
|
-
const t = (p.input ?? p.partialInput)?.title;
|
|
1615
|
-
return typeof t === "string" && t ? t : void 0;
|
|
1616
|
-
};
|
|
1617
|
-
/** Ids and titles of the calls seen so far, to resolve `replaces` (an id, or a title as a fallback). */
|
|
1618
|
-
function seen() {
|
|
1619
|
-
const ids = /* @__PURE__ */ new Set();
|
|
1620
|
-
const titles = /* @__PURE__ */ new Map();
|
|
1621
|
-
return {
|
|
1622
|
-
resolve: (call) => {
|
|
1623
|
-
const r = replaces(call);
|
|
1624
|
-
return r === void 0 ? void 0 : resolveReplaces(r, ids, titles);
|
|
1625
|
-
},
|
|
1626
|
-
add: (call) => {
|
|
1627
|
-
ids.add(call.id);
|
|
1628
|
-
const t = titleOf(call);
|
|
1629
|
-
if (t) titles.set(t, call.id);
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1633
|
-
/** One reply's chains: each call's first call (where the chain is drawn) and each first call's chain, in order. */
|
|
1634
|
-
function chainsOf(message) {
|
|
1635
|
-
const first = /* @__PURE__ */ new Map();
|
|
1636
|
-
const chains = /* @__PURE__ */ new Map();
|
|
1637
|
-
const known = seen();
|
|
1638
|
-
for (const call of callsOf(message)) {
|
|
1639
|
-
const r = known.resolve(call);
|
|
1640
|
-
known.add(call);
|
|
1641
|
-
const root = r !== void 0 && first.has(r) ? first.get(r) : call.id;
|
|
1642
|
-
first.set(call.id, root);
|
|
1643
|
-
chains.set(root, [...chains.get(root) ?? [], call]);
|
|
1644
|
-
}
|
|
1645
|
-
return {
|
|
1646
|
-
first,
|
|
1647
|
-
chains
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
/** Calls replaced by a finished call in a later reply: replaced id → the newest such call. */
|
|
1651
|
-
function laterReplacements(messages) {
|
|
1652
|
-
const later = /* @__PURE__ */ new Map();
|
|
1653
|
-
const known = seen();
|
|
1654
|
-
for (const m of messages) {
|
|
1655
|
-
if (m.role !== "assistant") continue;
|
|
1656
|
-
const calls = callsOf(m);
|
|
1657
|
-
const own = new Set(calls.map((c) => c.id));
|
|
1658
|
-
for (const call of calls) {
|
|
1659
|
-
const r = known.resolve(call);
|
|
1660
|
-
if (r !== void 0 && !own.has(r) && isReady(call)) later.set(r, call);
|
|
1661
|
-
}
|
|
1662
|
-
calls.forEach(known.add);
|
|
1663
|
-
}
|
|
1664
|
-
return later;
|
|
1665
|
-
}
|
|
1666
|
-
const LaterContext = createContext(/* @__PURE__ */ new Map());
|
|
1667
|
-
function LaterReplacements({ value, children }) {
|
|
1668
|
-
return /* @__PURE__ */ jsx(LaterContext.Provider, {
|
|
1669
|
-
value,
|
|
1670
|
-
children
|
|
1671
|
-
});
|
|
1672
|
-
}
|
|
1673
|
-
/** The call in a later reply that replaces any call of this chain, if there is one. */
|
|
1674
|
-
function useLaterReplacement(chain) {
|
|
1675
|
-
const later = useContext(LaterContext);
|
|
1676
|
-
for (let i = chain.length - 1; i >= 0; i--) {
|
|
1677
|
-
const by = later.get(chain[i].id);
|
|
1678
|
-
if (by) return by;
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
/** The DOM id of a drawn tool call, for the "Updated below" link. */
|
|
1682
|
-
const toolAnchor = (id) => `chat-tool-${id}`;
|
|
1683
|
-
/** Draws a chain: the newest finished call (dimmed while a newer one streams), or a link to its later update. */
|
|
1684
|
-
function ToolChain({ chain, draw }) {
|
|
1685
|
-
const labels = useLabels();
|
|
1686
|
-
const later = useLaterReplacement(chain);
|
|
1687
|
-
const shown = chain.findLast(isReady) ?? chain[0];
|
|
1688
|
-
const updating = chain.indexOf(shown) < chain.length - 1 && chain.at(-1).status !== "error";
|
|
1689
|
-
if (later) return /* @__PURE__ */ jsx(Button, {
|
|
1690
|
-
variant: "ghost",
|
|
1691
|
-
size: "sm",
|
|
1692
|
-
className: "self-start text-chat-muted data-hovered:text-chat-fg",
|
|
1693
|
-
onPress: () => document.getElementById(toolAnchor(later.id))?.scrollIntoView({
|
|
1694
|
-
behavior: "smooth",
|
|
1695
|
-
block: "center"
|
|
1696
|
-
}),
|
|
1697
|
-
children: labels.visualUpdated
|
|
1698
|
-
});
|
|
1699
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1700
|
-
id: toolAnchor(chain[0].id),
|
|
1701
|
-
"aria-busy": updating || void 0,
|
|
1702
|
-
className: updating ? "opacity-60 transition-opacity" : "transition-opacity",
|
|
1703
|
-
children: [/* @__PURE__ */ jsx("div", { children: draw(shown) }, shown.id), updating && /* @__PURE__ */ jsx("p", {
|
|
1704
|
-
className: "chat-shimmer mt-1 font-chat-sans text-(length:--chat-ui-font-size-sm) text-chat-muted",
|
|
1705
|
-
children: labels.visualUpdating
|
|
1706
|
-
})]
|
|
1707
|
-
});
|
|
1708
|
-
}
|
|
1709
|
-
// src/components/widget-frame.tsx
|
|
1710
|
-
const WidgetHostContext = createContext({});
|
|
1711
|
-
/** Sets what widgets below may do. ChatView and ChatTranscript set it from their `widgets` prop. */
|
|
1712
|
-
function WidgetHostProvider({ host, children }) {
|
|
1713
|
-
return /* @__PURE__ */ jsx(WidgetHostContext.Provider, {
|
|
1714
|
-
value: host,
|
|
1715
|
-
children
|
|
1716
|
-
});
|
|
1717
|
-
}
|
|
1718
|
-
function useWidgetHost() {
|
|
1719
|
-
return useContext(WidgetHostContext);
|
|
1720
|
-
}
|
|
1721
|
-
/** The tallest a widget may grow, in px. */
|
|
1722
|
-
const WIDGET_MAX_HEIGHT = 2e3;
|
|
1723
|
-
const PROTOCOL_VERSION = "2026-01-26";
|
|
1724
|
-
const THEME_VARS = [
|
|
1725
|
-
"bg",
|
|
1726
|
-
"fg",
|
|
1727
|
-
"muted",
|
|
1728
|
-
"subtle",
|
|
1729
|
-
"surface",
|
|
1730
|
-
"raised",
|
|
1731
|
-
"hover",
|
|
1732
|
-
"selected",
|
|
1733
|
-
"border",
|
|
1734
|
-
"border-strong",
|
|
1735
|
-
"divider",
|
|
1736
|
-
"accent",
|
|
1737
|
-
"accent-fg",
|
|
1738
|
-
"check",
|
|
1739
|
-
"warning",
|
|
1740
|
-
"danger",
|
|
1741
|
-
"code-bg",
|
|
1742
|
-
"font-sans",
|
|
1743
|
-
"font-serif",
|
|
1744
|
-
"font-mono",
|
|
1745
|
-
"radius-sm",
|
|
1746
|
-
"radius-md",
|
|
1747
|
-
"radius-lg",
|
|
1748
|
-
"ui-font-size",
|
|
1749
|
-
"ui-font-size-sm",
|
|
1750
|
-
"message-font-size"
|
|
1751
|
-
];
|
|
1752
|
-
const ORIGIN = /^(https?|wss?):\/\/(\*\.)?[a-z0-9-]+(\.[a-z0-9-]+)*(:\d{1,5})?$/;
|
|
1753
|
-
function origins(list) {
|
|
1754
|
-
return (list ?? []).map((d) => d.trim().toLowerCase().replace(/\/$/, "")).filter((d) => ORIGIN.test(d));
|
|
1755
|
-
}
|
|
1756
|
-
/** Whether `origin` is covered by `allowed`, which may be a wildcard like "https://*.example.com". */
|
|
1757
|
-
function covers(allowed, origin) {
|
|
1758
|
-
if (allowed === origin) return true;
|
|
1759
|
-
const wild = /^([a-z]+:\/\/)\*\.(.+)$/.exec(allowed);
|
|
1760
|
-
return !!wild && origin.startsWith(wild[1]) && origin.slice(wild[1].length).endsWith("." + wild[2]) && !origin.includes("*");
|
|
1761
|
-
}
|
|
1762
|
-
/** The part of a widget's request that the host allows. */
|
|
1763
|
-
function intersectAllow(request, allow = {}) {
|
|
1764
|
-
const keep = (asked, max) => origins(asked).filter((o) => origins(max).some((m) => covers(m, o)));
|
|
1765
|
-
return {
|
|
1766
|
-
resourceDomains: keep(request.resourceDomains, allow.resourceDomains),
|
|
1767
|
-
connectDomains: keep(request.connectDomains, allow.connectDomains)
|
|
1768
|
-
};
|
|
1769
|
-
}
|
|
1770
|
-
/** The Content-Security-Policy of a widget's document. */
|
|
1771
|
-
function widgetCsp(allow = {}) {
|
|
1772
|
-
const res = origins(allow.resourceDomains).join(" ");
|
|
1773
|
-
const conn = origins(allow.connectDomains).join(" ");
|
|
1774
|
-
const with_ = (base) => res ? `${base} ${res}` : base;
|
|
1775
|
-
return [
|
|
1776
|
-
"default-src 'none'",
|
|
1777
|
-
with_("script-src 'unsafe-inline'"),
|
|
1778
|
-
with_("style-src 'unsafe-inline'"),
|
|
1779
|
-
with_("img-src data: blob:"),
|
|
1780
|
-
with_("font-src data:"),
|
|
1781
|
-
with_("media-src data: blob:"),
|
|
1782
|
-
`connect-src ${conn || "'none'"}`,
|
|
1783
|
-
"frame-src 'none'",
|
|
1784
|
-
"base-uri 'none'",
|
|
1785
|
-
"form-action 'none'"
|
|
1786
|
-
].join("; ");
|
|
1787
|
-
}
|
|
1788
|
-
/** Runs inside a fragment's frame: renders the markup, reports its height, offers sendPrompt and openLink. */
|
|
1789
|
-
const BOOT = `(() => {
|
|
1790
|
-
const root = document.getElementById("widget");
|
|
1791
|
-
let id = 0;
|
|
1792
|
-
const post = (method, params, request) => parent.postMessage(request ? { jsonrpc: "2.0", id: ++id, method, params } : { jsonrpc: "2.0", method, params }, "*");
|
|
1793
|
-
window.sendPrompt = (text) => post("ui/message", { role: "user", content: [{ type: "text", text: String(text) }] }, true);
|
|
1794
|
-
window.openLink = (url) => post("ui/open-link", { url: String(url) }, true);
|
|
1795
|
-
let done = false;
|
|
1796
|
-
const runScripts = async () => {
|
|
1797
|
-
for (const old of [...root.querySelectorAll("script")]) {
|
|
1798
|
-
const s = document.createElement("script");
|
|
1799
|
-
for (const a of old.attributes) s.setAttribute(a.name, a.value);
|
|
1800
|
-
s.textContent = old.textContent;
|
|
1801
|
-
const loaded = s.src ? new Promise((ok) => { s.onload = s.onerror = ok; }) : null;
|
|
1802
|
-
old.replaceWith(s);
|
|
1803
|
-
if (loaded) await loaded;
|
|
1804
|
-
}
|
|
1805
|
-
};
|
|
1806
|
-
const theme = (ctx) => {
|
|
1807
|
-
const vars = (ctx && ctx.styles && ctx.styles.variables) || {};
|
|
1808
|
-
for (const k in vars) if (k.startsWith("--chat-")) document.documentElement.style.setProperty(k, vars[k]);
|
|
1809
|
-
if (ctx && ctx.theme) document.documentElement.style.colorScheme = ctx.theme;
|
|
1810
|
-
};
|
|
1811
|
-
addEventListener("message", (e) => {
|
|
1812
|
-
if (e.source !== parent) return;
|
|
1813
|
-
const m = e.data || {};
|
|
1814
|
-
if (m.method === "ui/notifications/host-context-changed") return theme(m.params);
|
|
1815
|
-
const code = m.params && m.params.arguments && m.params.arguments.widget_code;
|
|
1816
|
-
if (typeof code !== "string" || done) return;
|
|
1817
|
-
if (m.method === "ui/notifications/tool-input-partial") root.innerHTML = code;
|
|
1818
|
-
if (m.method === "ui/notifications/tool-input") { done = true; root.innerHTML = code; runScripts(); }
|
|
1819
|
-
});
|
|
1820
|
-
let last = -1;
|
|
1821
|
-
new ResizeObserver(() => {
|
|
1822
|
-
const h = Math.ceil(root.getBoundingClientRect().height);
|
|
1823
|
-
if (h !== last) { last = h; post("ui/notifications/size-changed", { height: h }); }
|
|
1824
|
-
// The frame grows to fit, a moment behind; only content past the cap gets a scrollbar.
|
|
1825
|
-
document.documentElement.style.overflowY = h > ${WIDGET_MAX_HEIGHT} ? "auto" : "hidden";
|
|
1826
|
-
}).observe(root);
|
|
1827
|
-
const seen = new Set();
|
|
1828
|
-
const report = (text) => { if (!seen.has(text) && seen.size < 10) { seen.add(text); post("notifications/message", { level: "error", logger: "widget", data: text }); } };
|
|
1829
|
-
addEventListener("error", (e) => report(String(e.message) + (e.lineno ? " (line " + e.lineno + ")" : "")));
|
|
1830
|
-
addEventListener("unhandledrejection", (e) => report("Unhandled promise rejection: " + String(e.reason && e.reason.message || e.reason)));
|
|
1831
|
-
post("ui/notifications/initialized", {});
|
|
1832
|
-
})();`;
|
|
1833
|
-
function fragmentDoc(csp, theme) {
|
|
1834
|
-
return `<!doctype html><html><head><meta charset="utf-8">
|
|
1835
|
-
<meta http-equiv="Content-Security-Policy" content="${csp}">
|
|
1836
|
-
<style>
|
|
1837
|
-
:root { ${Object.entries(theme.vars).map(([k, v]) => `${k}: ${v};`).join(" ")} color-scheme: ${theme.scheme}; }
|
|
1838
|
-
html { overflow: hidden; }
|
|
1839
|
-
html, body { margin: 0; background: transparent; color: var(--chat-fg); font-family: var(--chat-font-sans);
|
|
1840
|
-
font-size: var(--chat-ui-font-size); line-height: 1.5; }
|
|
1841
|
-
#widget { display: flow-root; }
|
|
1842
|
-
*, *::before, *::after { box-sizing: border-box; }
|
|
1843
|
-
button, input, select, textarea { font: inherit; color: inherit; }
|
|
1844
|
-
</style></head><body><div id="widget"></div><script>${BOOT}<\/script></body></html>`;
|
|
1845
|
-
}
|
|
1846
|
-
/** An app's own document with the host's CSP put first in its head (a second policy can only narrow it). */
|
|
1847
|
-
function appDoc(csp, html) {
|
|
1848
|
-
const meta = `<meta http-equiv="Content-Security-Policy" content="${csp}">`;
|
|
1849
|
-
const head = /<head(\s[^>]*)?>/i.exec(html);
|
|
1850
|
-
if (head) return html.slice(0, head.index + head[0].length) + meta + html.slice(head.index + head[0].length);
|
|
1851
|
-
const root = /<html(\s[^>]*)?>/i.exec(html);
|
|
1852
|
-
if (root) return html.slice(0, root.index + root[0].length) + `<head>${meta}</head>` + html.slice(root.index + root[0].length);
|
|
1853
|
-
return `<!doctype html><html><head>${meta}</head><body>${html}</body></html>`;
|
|
1854
|
-
}
|
|
1855
|
-
function readTheme(el) {
|
|
1856
|
-
const style = getComputedStyle(el);
|
|
1857
|
-
return {
|
|
1858
|
-
vars: Object.fromEntries(THEME_VARS.map((v) => [`--chat-${v}`, style.getPropertyValue(`--chat-${v}`).trim()])),
|
|
1859
|
-
scheme: /light/.test(style.colorScheme) && !/dark/.test(style.colorScheme) ? "light" : "dark"
|
|
1860
|
-
};
|
|
1861
|
-
}
|
|
1862
|
-
/** Calls `onChange` when anything above `el` changes attributes (a theme switch) or the OS scheme flips. */
|
|
1863
|
-
function watchTheme(el, onChange) {
|
|
1864
|
-
const observer = new MutationObserver(onChange);
|
|
1865
|
-
for (let node = el; node; node = node.parentElement) observer.observe(node, {
|
|
1866
|
-
attributes: true,
|
|
1867
|
-
attributeFilter: [
|
|
1868
|
-
"class",
|
|
1869
|
-
"style",
|
|
1870
|
-
"data-chat-theme"
|
|
1871
|
-
]
|
|
1872
|
-
});
|
|
1873
|
-
const media = typeof matchMedia === "function" ? matchMedia("(prefers-color-scheme: dark)") : void 0;
|
|
1874
|
-
media?.addEventListener?.("change", onChange);
|
|
1875
|
-
return () => {
|
|
1876
|
-
observer.disconnect();
|
|
1877
|
-
media?.removeEventListener?.("change", onChange);
|
|
1878
|
-
};
|
|
1879
|
-
}
|
|
1880
|
-
function WidgetFrame({ html, document: isDocument = false, streaming = false, title, loadingMessages, allow, csp: request, onPrompt, onOpenLink, onCallTool, onError, toolInput, toolResult, cancelled, frameUrl: ownFrameUrl, className }) {
|
|
1881
|
-
const labels = useLabels();
|
|
1882
|
-
const hostFrameUrl = useWidgetHost().frameUrl;
|
|
1883
|
-
const frameUrl = ownFrameUrl ?? hostFrameUrl;
|
|
1884
|
-
const frame = useRef(null);
|
|
1885
|
-
const host = useRef(null);
|
|
1886
|
-
const [ready, setReady] = useState(false);
|
|
1887
|
-
const [height, setHeight] = useState(0);
|
|
1888
|
-
const [initial, setInitial] = useState();
|
|
1889
|
-
const theme = useRef(void 0);
|
|
1890
|
-
const [tick, setTick] = useState(0);
|
|
1891
|
-
const effective = request ? intersectAllow(request, allow) : isDocument ? {} : allow ?? {};
|
|
1892
|
-
const policy = widgetCsp(effective);
|
|
1893
|
-
const doc = useMemo(() => initial && (isDocument ? appDoc(policy, html) : fragmentDoc(policy, initial)), [
|
|
1894
|
-
initial,
|
|
1895
|
-
policy,
|
|
1896
|
-
isDocument,
|
|
1897
|
-
isDocument && html
|
|
1898
|
-
]);
|
|
1899
|
-
const latest = useRef({
|
|
1900
|
-
onPrompt,
|
|
1901
|
-
onOpenLink,
|
|
1902
|
-
onCallTool,
|
|
1903
|
-
onError,
|
|
1904
|
-
policy,
|
|
1905
|
-
effective,
|
|
1906
|
-
doc
|
|
1907
|
-
});
|
|
1908
|
-
latest.current = {
|
|
1909
|
-
onPrompt,
|
|
1910
|
-
onOpenLink,
|
|
1911
|
-
onCallTool,
|
|
1912
|
-
onError,
|
|
1913
|
-
policy,
|
|
1914
|
-
effective,
|
|
1915
|
-
doc
|
|
1916
|
-
};
|
|
1917
|
-
const generation = useRef({
|
|
1918
|
-
doc,
|
|
1919
|
-
n: 0
|
|
1920
|
-
});
|
|
1921
|
-
if (generation.current.doc !== doc) generation.current = {
|
|
1922
|
-
doc,
|
|
1923
|
-
n: generation.current.n + 1
|
|
1924
|
-
};
|
|
1925
|
-
const send = (message) => frame.current?.contentWindow?.postMessage({
|
|
1926
|
-
jsonrpc: "2.0",
|
|
1927
|
-
...message
|
|
1928
|
-
}, "*");
|
|
1929
|
-
const context = () => ({
|
|
1930
|
-
theme: theme.current?.scheme,
|
|
1931
|
-
styles: { variables: theme.current?.vars },
|
|
1932
|
-
displayMode: "inline",
|
|
1933
|
-
availableDisplayModes: ["inline"],
|
|
1934
|
-
containerDimensions: {
|
|
1935
|
-
maxHeight: WIDGET_MAX_HEIGHT,
|
|
1936
|
-
...host.current && { width: host.current.clientWidth }
|
|
1937
|
-
},
|
|
1938
|
-
platform: "web",
|
|
1939
|
-
...labels.locale && { locale: labels.locale }
|
|
1940
|
-
});
|
|
1941
|
-
useEffect(() => {
|
|
1942
|
-
const el = host.current;
|
|
1943
|
-
theme.current = readTheme(el);
|
|
1944
|
-
setInitial(theme.current);
|
|
1945
|
-
return watchTheme(el, () => {
|
|
1946
|
-
const next = readTheme(el);
|
|
1947
|
-
if (JSON.stringify(next) === JSON.stringify(theme.current)) return;
|
|
1948
|
-
theme.current = next;
|
|
1949
|
-
send({
|
|
1950
|
-
method: "ui/notifications/host-context-changed",
|
|
1951
|
-
params: {
|
|
1952
|
-
theme: next.scheme,
|
|
1953
|
-
styles: { variables: next.vars }
|
|
1954
|
-
}
|
|
1955
|
-
});
|
|
1956
|
-
});
|
|
1957
|
-
}, []);
|
|
1958
|
-
useEffect(() => setReady(false), [doc]);
|
|
1959
|
-
useEffect(() => {
|
|
1960
|
-
const reply = (id, result) => id !== void 0 && send({
|
|
1961
|
-
id,
|
|
1962
|
-
result
|
|
1963
|
-
});
|
|
1964
|
-
const fail = (id, code, message) => id !== void 0 && send({
|
|
1965
|
-
id,
|
|
1966
|
-
error: {
|
|
1967
|
-
code,
|
|
1968
|
-
message
|
|
1969
|
-
}
|
|
1970
|
-
});
|
|
1971
|
-
const onMessage = async (e) => {
|
|
1972
|
-
if (!frame.current || e.source !== frame.current.contentWindow) return;
|
|
1973
|
-
if (e.data?.type === widgetLoaderMessages.ready) {
|
|
1974
|
-
const html = latest.current.doc;
|
|
1975
|
-
if (html) frame.current.contentWindow?.postMessage({
|
|
1976
|
-
type: widgetLoaderMessages.document,
|
|
1977
|
-
html
|
|
1978
|
-
}, "*");
|
|
1979
|
-
return;
|
|
1980
|
-
}
|
|
1981
|
-
const m = e.data ?? {};
|
|
1982
|
-
if (typeof m !== "object" || typeof m.method !== "string") return;
|
|
1983
|
-
const { onPrompt, onOpenLink, onCallTool, effective } = latest.current;
|
|
1984
|
-
switch (m.method) {
|
|
1985
|
-
case "ui/initialize": return reply(m.id, {
|
|
1986
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
1987
|
-
hostInfo: {
|
|
1988
|
-
name: "agentic-ui-kit",
|
|
1989
|
-
version: "1"
|
|
1990
|
-
},
|
|
1991
|
-
hostCapabilities: {
|
|
1992
|
-
...onOpenLink && { openLinks: {} },
|
|
1993
|
-
...onCallTool && { serverTools: {} },
|
|
1994
|
-
logging: {},
|
|
1995
|
-
sandbox: { csp: effective }
|
|
1996
|
-
},
|
|
1997
|
-
hostContext: context()
|
|
1998
|
-
});
|
|
1999
|
-
case "ui/notifications/initialized": return setReady(true);
|
|
2000
|
-
case "ui/notifications/size-changed": return setHeight(Math.min(Math.max(0, Number(m.params?.height) || 0), WIDGET_MAX_HEIGHT));
|
|
2001
|
-
case "ui/message": {
|
|
2002
|
-
const text = (Array.isArray(m.params?.content) ? m.params.content : []).find((c) => c?.type === "text")?.text;
|
|
2003
|
-
if (!onPrompt) return fail(m.id, -32e3, "Sending messages is off");
|
|
2004
|
-
if (typeof text !== "string" || !text.trim()) return fail(m.id, -32602, "Empty message");
|
|
2005
|
-
onPrompt(text.slice(0, 4e3));
|
|
2006
|
-
return reply(m.id, {});
|
|
2007
|
-
}
|
|
2008
|
-
case "ui/open-link": {
|
|
2009
|
-
const url = String(m.params?.url ?? "");
|
|
2010
|
-
if (!onOpenLink) return fail(m.id, -32e3, "Opening links is off");
|
|
2011
|
-
if (!/^https?:\/\//i.test(url)) return fail(m.id, -32602, "Only http(s) links");
|
|
2012
|
-
onOpenLink(url);
|
|
2013
|
-
return reply(m.id, {});
|
|
2014
|
-
}
|
|
2015
|
-
case "tools/call": {
|
|
2016
|
-
if (!onCallTool) return fail(m.id, -32e3, "Calling tools is off");
|
|
2017
|
-
const name = String(m.params?.name ?? "");
|
|
2018
|
-
const args = m.params?.arguments ?? {};
|
|
2019
|
-
try {
|
|
2020
|
-
return reply(m.id, await onCallTool(name, args));
|
|
2021
|
-
} catch (error) {
|
|
2022
|
-
return fail(m.id, -32e3, error instanceof Error ? error.message : String(error));
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
case "ping": return reply(m.id, {});
|
|
2026
|
-
case "notifications/message": {
|
|
2027
|
-
const data = typeof m.params?.data === "string" ? m.params.data : JSON.stringify(m.params?.data);
|
|
2028
|
-
if (m.params?.level === "error" && data) latest.current.onError?.(data.slice(0, 1e3));
|
|
2029
|
-
return;
|
|
2030
|
-
}
|
|
2031
|
-
default: return fail(m.id, -32601, "Method not found");
|
|
2032
|
-
}
|
|
2033
|
-
};
|
|
2034
|
-
window.addEventListener("message", onMessage);
|
|
2035
|
-
return () => window.removeEventListener("message", onMessage);
|
|
2036
|
-
}, []);
|
|
2037
|
-
useEffect(() => {
|
|
2038
|
-
if (!ready || isDocument) return;
|
|
2039
|
-
send({
|
|
2040
|
-
method: streaming ? "ui/notifications/tool-input-partial" : "ui/notifications/tool-input",
|
|
2041
|
-
params: { arguments: { widget_code: html } }
|
|
2042
|
-
});
|
|
2043
|
-
}, [
|
|
2044
|
-
ready,
|
|
2045
|
-
isDocument,
|
|
2046
|
-
html,
|
|
2047
|
-
streaming
|
|
2048
|
-
]);
|
|
2049
|
-
const inputKey = isDocument && toolInput !== void 0 ? JSON.stringify(toolInput) : void 0;
|
|
2050
|
-
useEffect(() => {
|
|
2051
|
-
if (!ready || inputKey === void 0) return;
|
|
2052
|
-
send({
|
|
2053
|
-
method: streaming ? "ui/notifications/tool-input-partial" : "ui/notifications/tool-input",
|
|
2054
|
-
params: { arguments: JSON.parse(inputKey) }
|
|
2055
|
-
});
|
|
2056
|
-
}, [
|
|
2057
|
-
ready,
|
|
2058
|
-
inputKey,
|
|
2059
|
-
streaming
|
|
2060
|
-
]);
|
|
2061
|
-
useEffect(() => {
|
|
2062
|
-
if (ready && isDocument && toolResult !== void 0) send({
|
|
2063
|
-
method: "ui/notifications/tool-result",
|
|
2064
|
-
params: toolResult
|
|
2065
|
-
});
|
|
2066
|
-
}, [
|
|
2067
|
-
ready,
|
|
2068
|
-
isDocument,
|
|
2069
|
-
toolResult
|
|
2070
|
-
]);
|
|
2071
|
-
useEffect(() => {
|
|
2072
|
-
if (ready && isDocument && cancelled !== void 0) send({
|
|
2073
|
-
method: "ui/notifications/tool-cancelled",
|
|
2074
|
-
params: { reason: cancelled }
|
|
2075
|
-
});
|
|
2076
|
-
}, [
|
|
2077
|
-
ready,
|
|
2078
|
-
isDocument,
|
|
2079
|
-
cancelled
|
|
2080
|
-
]);
|
|
2081
|
-
const lines = loadingMessages?.length ? loadingMessages : [labels.drawingWidget];
|
|
2082
|
-
useEffect(() => {
|
|
2083
|
-
if (!streaming || lines.length < 2) return;
|
|
2084
|
-
const id = setInterval(() => setTick((t) => t + 1), 1800);
|
|
2085
|
-
return () => clearInterval(id);
|
|
2086
|
-
}, [streaming, lines.length]);
|
|
2087
|
-
return /* @__PURE__ */ jsxs("figure", {
|
|
2088
|
-
ref: host,
|
|
2089
|
-
className: className ?? "my-2",
|
|
2090
|
-
"aria-label": title ?? labels.widget,
|
|
2091
|
-
"aria-busy": streaming || void 0,
|
|
2092
|
-
children: [streaming && /* @__PURE__ */ jsx("div", {
|
|
2093
|
-
className: "mb-2 animate-pulse font-chat-sans text-(length:--chat-ui-font-size) text-chat-muted motion-reduce:animate-none",
|
|
2094
|
-
children: lines[tick % lines.length]
|
|
2095
|
-
}), doc && /* @__PURE__ */ jsx("iframe", {
|
|
2096
|
-
ref: frame,
|
|
2097
|
-
title: title ?? labels.widget,
|
|
2098
|
-
sandbox: "allow-scripts",
|
|
2099
|
-
...frameUrl ? { src: frameUrl } : { srcDoc: doc },
|
|
2100
|
-
style: {
|
|
2101
|
-
height: height || (streaming ? 120 : 0),
|
|
2102
|
-
transition: "height 150ms ease-out"
|
|
2103
|
-
},
|
|
2104
|
-
className: "block w-full border-0 bg-transparent"
|
|
2105
|
-
}, frameUrl ? generation.current.n : "srcdoc")]
|
|
2106
|
-
});
|
|
2107
|
-
}
|
|
2108
|
-
/** Pulls the host's abilities from context into frame props. */
|
|
2109
|
-
function useHostProps(partId) {
|
|
2110
|
-
const { allow, onPrompt, onOpenLink, onCallTool, onWidgetError } = useWidgetHost();
|
|
2111
|
-
return {
|
|
2112
|
-
...allow && { allow },
|
|
2113
|
-
...onPrompt && { onPrompt },
|
|
2114
|
-
...onOpenLink && { onOpenLink },
|
|
2115
|
-
...onCallTool && { onCallTool },
|
|
2116
|
-
...onWidgetError && { onError: (message) => onWidgetError({
|
|
2117
|
-
partId,
|
|
2118
|
-
message
|
|
2119
|
-
}) }
|
|
2120
|
-
};
|
|
2121
|
-
}
|
|
2122
|
-
/** The default look of a `widget` part: inline html, or an app UI the host reads from `resourceUri`. */
|
|
2123
|
-
function WidgetPartView({ part }) {
|
|
2124
|
-
const host = useWidgetHost();
|
|
2125
|
-
const props = useHostProps(part.id);
|
|
2126
|
-
const [resource, setResource] = useState();
|
|
2127
|
-
const uri = part.html === void 0 ? part.resourceUri : void 0;
|
|
2128
|
-
useEffect(() => {
|
|
2129
|
-
if (!uri || !host.readResource) return;
|
|
2130
|
-
let live = true;
|
|
2131
|
-
host.readResource(uri).then((r) => live && setResource(r), (e) => console.warn("widget:", e));
|
|
2132
|
-
return () => {
|
|
2133
|
-
live = false;
|
|
2134
|
-
};
|
|
2135
|
-
}, [uri, host.readResource]);
|
|
2136
|
-
if (part.html !== void 0) return /* @__PURE__ */ jsx(WidgetFrame, {
|
|
2137
|
-
html: part.html,
|
|
2138
|
-
streaming: part.status === "streaming",
|
|
2139
|
-
...part.title && { title: part.title },
|
|
2140
|
-
...props
|
|
2141
|
-
});
|
|
2142
|
-
if (!resource) return null;
|
|
2143
|
-
return /* @__PURE__ */ jsx(WidgetFrame, {
|
|
2144
|
-
document: true,
|
|
2145
|
-
html: resource.html,
|
|
2146
|
-
...resource.csp && { csp: resource.csp },
|
|
2147
|
-
...part.title && { title: part.title },
|
|
2148
|
-
...props
|
|
2149
|
-
});
|
|
2150
|
-
}
|
|
2151
|
-
const str = (v) => typeof v === "string" ? v : void 0;
|
|
2152
|
-
/** Reads the fields of the suggested `visualizeTool` (widget_code, title, loading_messages). */
|
|
2153
|
-
function readVisualizeInput(input) {
|
|
2154
|
-
const i = input ?? {};
|
|
2155
|
-
const loading = Array.isArray(i.loading_messages) ? i.loading_messages.filter((l) => typeof l === "string" && l !== "") : [];
|
|
2156
|
-
return {
|
|
2157
|
-
...str(i.widget_code) !== void 0 && { html: str(i.widget_code) },
|
|
2158
|
-
...str(i.title) && { title: str(i.title) },
|
|
2159
|
-
...loading.length && { loadingMessages: loading.slice(0, 4) }
|
|
2160
|
-
};
|
|
2161
|
-
}
|
|
2162
|
-
/**
|
|
2163
|
-
* A tool view that draws a call's (streaming) input in a WidgetFrame, for whatever tool your harness uses
|
|
2164
|
-
* to write HTML. Register it under your tool's name: `{ show_widget: widgetToolView() }`. `read` maps your
|
|
2165
|
-
* tool's input (possibly cut short while it streams) to the frame's fields; the default reads the suggested
|
|
2166
|
-
* `visualizeTool`'s fields.
|
|
2167
|
-
*/
|
|
2168
|
-
function widgetToolView(read = readVisualizeInput) {
|
|
2169
|
-
function WidgetToolBlock({ part }) {
|
|
2170
|
-
const props = useHostProps(part.id);
|
|
2171
|
-
const { html = "", title, loadingMessages } = read(part.input ?? part.partialInput);
|
|
2172
|
-
if (part.status === "error" && !html) return null;
|
|
2173
|
-
return /* @__PURE__ */ jsx(WidgetFrame, {
|
|
2174
|
-
html,
|
|
2175
|
-
streaming: part.status === "streaming" || part.status === "input",
|
|
2176
|
-
...title && { title },
|
|
2177
|
-
...loadingMessages?.length && { loadingMessages },
|
|
2178
|
-
...props
|
|
2179
|
-
});
|
|
2180
|
-
}
|
|
2181
|
-
return { Block: WidgetToolBlock };
|
|
2182
|
-
}
|
|
2183
|
-
/** The default `onOpenLink` of ChatView and ChatTranscript: a new tab with no opener. */
|
|
2184
|
-
function openInNewTab(url) {
|
|
2185
|
-
window.open(url, "_blank", "noopener,noreferrer");
|
|
2186
|
-
}
|
|
2187
|
-
// src/components/ui-tree.tsx
|
|
2188
|
-
const RegistryContext = createContext(void 0);
|
|
2189
|
-
/**
|
|
2190
|
-
* The components the model may use: in ```ui blocks of its replies (see `uiMarkupGuide` in
|
|
2191
|
-
* agentic-ui-kit/core) and in tool calls drawn with `uiTreeToolView`. `persist` keeps each widget's state.
|
|
2192
|
-
*/
|
|
2193
|
-
function UiComponentsProvider({ components, persist, markup = "ui", children }) {
|
|
2194
|
-
const value = useMemo(() => ({
|
|
2195
|
-
components: new Map(components.map((c) => [c.name, c])),
|
|
2196
|
-
persist,
|
|
2197
|
-
markup
|
|
2198
|
-
}), [
|
|
2199
|
-
components,
|
|
2200
|
-
persist,
|
|
2201
|
-
markup
|
|
2202
|
-
]);
|
|
2203
|
-
return /* @__PURE__ */ jsx(RegistryContext.Provider, {
|
|
2204
|
-
value,
|
|
2205
|
-
children
|
|
2206
|
-
});
|
|
2207
|
-
}
|
|
2208
|
-
const TreeContext = createContext({
|
|
2209
|
-
state: {},
|
|
2210
|
-
run: () => {},
|
|
2211
|
-
streaming: false
|
|
2212
|
-
});
|
|
2213
|
-
/** Inside a registered component: runs an action from its props, e.g. `run(props.onPress)`. Bad actions do nothing. */
|
|
2214
|
-
function useUiAction() {
|
|
2215
|
-
const { run } = useContext(TreeContext);
|
|
2216
|
-
return useCallback((action) => matchesSchema(uiActionSchema, action) && run(action), [run]);
|
|
2217
|
-
}
|
|
2218
|
-
/** Inside a registered component: the widget's state and a setter, for inputs that write to it. */
|
|
2219
|
-
function useUiState() {
|
|
2220
|
-
const { state, run } = useContext(TreeContext);
|
|
2221
|
-
return [state, useCallback((key, value) => run({
|
|
2222
|
-
action: "set",
|
|
2223
|
-
key,
|
|
2224
|
-
value
|
|
2225
|
-
}), [run])];
|
|
2226
|
-
}
|
|
2227
|
-
/** Replaces `{ "$state": key }` anywhere in the props with the state's value. */
|
|
2228
|
-
function resolve(value, state) {
|
|
2229
|
-
if (isStateRef(value)) return state[value.$state];
|
|
2230
|
-
if (Array.isArray(value)) return value.map((v) => resolve(v, state));
|
|
2231
|
-
if (typeof value === "object" && value !== null) {
|
|
2232
|
-
const out = {};
|
|
2233
|
-
for (const [k, v] of Object.entries(value)) {
|
|
2234
|
-
const r = resolve(v, state);
|
|
2235
|
-
if (r !== void 0) out[k] = r;
|
|
2236
|
-
}
|
|
2237
|
-
return out;
|
|
2238
|
-
}
|
|
2239
|
-
return value;
|
|
2240
|
-
}
|
|
2241
|
-
/** A component that throws renders nothing instead of taking the message down. */
|
|
2242
|
-
var Contain = class extends Component {
|
|
2243
|
-
state = { failed: false };
|
|
2244
|
-
static getDerivedStateFromError() {
|
|
2245
|
-
return { failed: true };
|
|
2246
|
-
}
|
|
2247
|
-
componentDidCatch(error) {
|
|
2248
|
-
console.warn("render_ui:", error);
|
|
2249
|
-
}
|
|
2250
|
-
render() {
|
|
2251
|
-
return this.state.failed ? null : this.props.children;
|
|
2252
|
-
}
|
|
2253
|
-
};
|
|
2254
|
-
function Node({ node, registry }) {
|
|
2255
|
-
const { state } = useContext(TreeContext);
|
|
2256
|
-
if (Array.isArray(node)) return node.map((child, i) => /* @__PURE__ */ jsx(Node, {
|
|
2257
|
-
node: child,
|
|
2258
|
-
registry
|
|
2259
|
-
}, i));
|
|
2260
|
-
if (typeof node !== "object" || node === null) return null;
|
|
2261
|
-
const { component, props = {}, children } = node;
|
|
2262
|
-
const spec = typeof component === "string" ? registry.components.get(component) : void 0;
|
|
2263
|
-
if (!spec || typeof props !== "object") return null;
|
|
2264
|
-
const resolved = resolve(props, state);
|
|
2265
|
-
if (!matchesSchema(spec.props ?? { type: "object" }, resolved)) return null;
|
|
2266
|
-
const Render = spec.render;
|
|
2267
|
-
const kids = spec.children && Array.isArray(children) ? children.map((child, i) => /* @__PURE__ */ jsx(Node, {
|
|
2268
|
-
node: child,
|
|
2269
|
-
registry
|
|
2270
|
-
}, i)) : void 0;
|
|
2271
|
-
return /* @__PURE__ */ jsx(Contain, { children: /* @__PURE__ */ jsx(Render, {
|
|
2272
|
-
...resolved,
|
|
2273
|
-
children: kids
|
|
2274
|
-
}) });
|
|
2275
|
-
}
|
|
2276
|
-
/** Draws a `render_ui` tree with the registered components. Unknown components and bad props render nothing. */
|
|
2277
|
-
function UiTree({ id, stateKey, root, state: initial, streaming = false }) {
|
|
2278
|
-
const storeKey = stateKey ?? id;
|
|
2279
|
-
const registry = useContext(RegistryContext);
|
|
2280
|
-
const host = useWidgetHost();
|
|
2281
|
-
const [local, setLocal] = useState(() => registry?.persist?.load(storeKey) ?? {});
|
|
2282
|
-
const changed = useRef(false);
|
|
2283
|
-
const latest = useRef(host);
|
|
2284
|
-
latest.current = host;
|
|
2285
|
-
useEffect(() => {
|
|
2286
|
-
if (changed.current) registry?.persist?.save(storeKey, local);
|
|
2287
|
-
}, [
|
|
2288
|
-
storeKey,
|
|
2289
|
-
local,
|
|
2290
|
-
registry
|
|
2291
|
-
]);
|
|
2292
|
-
const run = useCallback((action) => {
|
|
2293
|
-
switch (action.action) {
|
|
2294
|
-
case "set":
|
|
2295
|
-
changed.current = true;
|
|
2296
|
-
return setLocal((s) => ({
|
|
2297
|
-
...s,
|
|
2298
|
-
[action.key]: action.value
|
|
2299
|
-
}));
|
|
2300
|
-
case "send": return latest.current.onPrompt?.(action.text);
|
|
2301
|
-
case "open": return /^https?:\/\//i.test(action.url) && latest.current.onOpenLink?.(action.url);
|
|
2302
|
-
case "copy":
|
|
2303
|
-
navigator.clipboard?.writeText(action.text).catch(() => {});
|
|
2304
|
-
return;
|
|
2305
|
-
}
|
|
2306
|
-
}, []);
|
|
2307
|
-
const state = useMemo(() => ({
|
|
2308
|
-
...typeof initial === "object" && initial ? initial : {},
|
|
2309
|
-
...local
|
|
2310
|
-
}), [initial, local]);
|
|
2311
|
-
const context = useMemo(() => ({
|
|
2312
|
-
state,
|
|
2313
|
-
run,
|
|
2314
|
-
streaming
|
|
2315
|
-
}), [
|
|
2316
|
-
state,
|
|
2317
|
-
run,
|
|
2318
|
-
streaming
|
|
2319
|
-
]);
|
|
2320
|
-
if (!registry) return null;
|
|
2321
|
-
return /* @__PURE__ */ jsx(TreeContext.Provider, {
|
|
2322
|
-
value: context,
|
|
2323
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2324
|
-
className: "chat-ui-tree my-2",
|
|
2325
|
-
"aria-busy": streaming || void 0,
|
|
2326
|
-
children: /* @__PURE__ */ jsx(Node, {
|
|
2327
|
-
node: root,
|
|
2328
|
-
registry
|
|
2329
|
-
})
|
|
2330
|
-
})
|
|
2331
|
-
});
|
|
2332
|
-
}
|
|
2333
|
-
/** The fence language drawn as UI here, or undefined outside a `UiComponentsProvider`. */
|
|
2334
|
-
function useUiMarkupLanguage() {
|
|
2335
|
-
const registry = useContext(RegistryContext);
|
|
2336
|
-
return registry && registry.markup !== false ? registry.markup : void 0;
|
|
2337
|
-
}
|
|
2338
|
-
/** A ```ui block from a reply, drawn with the registered components. Safe on a block that is still streaming. */
|
|
2339
|
-
function UiMarkupBlock({ id, stateKey, source, streaming = false }) {
|
|
2340
|
-
const { nodes, state } = useMemo(() => parseUiMarkup(source), [source]);
|
|
2341
|
-
return /* @__PURE__ */ jsx(UiTree, {
|
|
2342
|
-
id,
|
|
2343
|
-
...stateKey && { stateKey },
|
|
2344
|
-
root: nodes,
|
|
2345
|
-
state,
|
|
2346
|
-
streaming
|
|
2347
|
-
});
|
|
2348
|
-
}
|
|
2349
|
-
function stateKeyOf(options, part) {
|
|
2350
|
-
const stateKey = options.stateKey?.(part);
|
|
2351
|
-
return stateKey ? { stateKey } : {};
|
|
2352
|
-
}
|
|
2353
|
-
/**
|
|
2354
|
-
* A tool view that draws a call's (streaming) JSX markup with your registered components, for whatever tool
|
|
2355
|
-
* your harness uses; the suggested one is core's `showUiTool`. Register it under your tool's name:
|
|
2356
|
-
* `{ show_ui: uiMarkupToolView() }`. `read` maps your tool's input to the markup; the default reads `markup`.
|
|
2357
|
-
*/
|
|
2358
|
-
function uiMarkupToolView(read = (input) => {
|
|
2359
|
-
const markup = input?.markup;
|
|
2360
|
-
return typeof markup === "string" ? markup : void 0;
|
|
2361
|
-
}, options = {}) {
|
|
2362
|
-
function UiMarkupToolBlock({ part }) {
|
|
2363
|
-
const markup = read(part.input ?? part.partialInput);
|
|
2364
|
-
if (!markup) return null;
|
|
2365
|
-
return /* @__PURE__ */ jsx(UiMarkupBlock, {
|
|
2366
|
-
id: part.id,
|
|
2367
|
-
...stateKeyOf(options, part),
|
|
2368
|
-
source: markup,
|
|
2369
|
-
streaming: part.status === "streaming" || part.status === "input"
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
|
-
return { Block: UiMarkupToolBlock };
|
|
2373
|
-
}
|
|
2374
|
-
/** Reads `{ root, state }`. Models sometimes send `root` or `state` as a JSON string; those are parsed too. */
|
|
2375
|
-
function readTreeInput(input) {
|
|
2376
|
-
const i = input ?? {};
|
|
2377
|
-
const unwrap = (v) => typeof v === "string" ? salvageJson(v).value : v;
|
|
2378
|
-
const root = unwrap(i.root);
|
|
2379
|
-
const state = unwrap(i.state);
|
|
2380
|
-
return {
|
|
2381
|
-
...root !== void 0 && { root },
|
|
2382
|
-
...typeof state === "object" && state !== null && { state }
|
|
2383
|
-
};
|
|
2384
|
-
}
|
|
2385
|
-
/**
|
|
2386
|
-
* A tool view that draws a call's (streaming) input as a tree of your registered components, for whatever
|
|
2387
|
-
* tool your harness uses. Register it under your tool's name: `{ render_ui: uiTreeToolView() }`. `read` maps
|
|
2388
|
-
* your tool's input to the tree and its starting state; the default reads `{ root, state }`, the shape of
|
|
2389
|
-
* the suggested `renderUiTool`.
|
|
2390
|
-
*/
|
|
2391
|
-
function uiTreeToolView(read = readTreeInput, options = {}) {
|
|
2392
|
-
function UiTreeToolBlock({ part }) {
|
|
2393
|
-
const { root, state } = read(part.input ?? part.partialInput);
|
|
2394
|
-
if (!root) return null;
|
|
2395
|
-
const ok = typeof state === "object" && state !== null;
|
|
2396
|
-
return /* @__PURE__ */ jsx(UiTree, {
|
|
2397
|
-
id: part.id,
|
|
2398
|
-
...stateKeyOf(options, part),
|
|
2399
|
-
root,
|
|
2400
|
-
...ok && { state },
|
|
2401
|
-
streaming: part.status === "streaming" || part.status === "input"
|
|
2402
|
-
});
|
|
2403
|
-
}
|
|
2404
|
-
return { Block: UiTreeToolBlock };
|
|
2405
|
-
}
|
|
2406
|
-
/**
|
|
2407
|
-
* The escape hatch: raw HTML or SVG in a sandboxed WidgetFrame, as a node of the tree. Register it only if
|
|
2408
|
-
* the model may write HTML; it gets what the chat's `widgets` host allows.
|
|
2409
|
-
*/
|
|
2410
|
-
const htmlComponent = {
|
|
2411
|
-
name: "Html",
|
|
2412
|
-
description: "Raw HTML or <svg> in a sandboxed frame, only for what the other components cannot show. Follow the visual design guide.",
|
|
2413
|
-
props: {
|
|
2414
|
-
type: "object",
|
|
2415
|
-
properties: {
|
|
2416
|
-
html: { type: "string" },
|
|
2417
|
-
title: { type: "string" }
|
|
2418
|
-
},
|
|
2419
|
-
required: ["html"]
|
|
2420
|
-
},
|
|
2421
|
-
render: function Html({ html, title }) {
|
|
2422
|
-
const { streaming } = useContext(TreeContext);
|
|
2423
|
-
const { allow, onPrompt, onOpenLink } = useWidgetHost();
|
|
2424
|
-
return /* @__PURE__ */ jsx(WidgetFrame, {
|
|
2425
|
-
html,
|
|
2426
|
-
streaming,
|
|
2427
|
-
...title && { title },
|
|
2428
|
-
...allow && { allow },
|
|
2429
|
-
...onPrompt && { onPrompt },
|
|
2430
|
-
...onOpenLink && { onOpenLink }
|
|
2431
|
-
});
|
|
2432
|
-
}
|
|
2433
|
-
};
|
|
2434
1306
|
// src/components/word-fade.ts
|
|
2435
1307
|
const OPAQUE_TAGS = /* @__PURE__ */ new Set([
|
|
2436
1308
|
"code",
|
|
@@ -2513,7 +1385,7 @@ const BlockContext = createContext(void 0);
|
|
|
2513
1385
|
function Code({ node, className, children }) {
|
|
2514
1386
|
const hast = node;
|
|
2515
1387
|
const language = /language-([\w+#-]+)/.exec(className ?? "")?.[1];
|
|
2516
|
-
const
|
|
1388
|
+
const { codeBlocks } = useChatExtensions();
|
|
2517
1389
|
const block = useContext(BlockContext);
|
|
2518
1390
|
const multiline = hast?.position && hast.position.start.line !== hast.position.end.line;
|
|
2519
1391
|
if (!language && !multiline) return /* @__PURE__ */ jsx("code", {
|
|
@@ -2521,9 +1393,10 @@ function Code({ node, className, children }) {
|
|
|
2521
1393
|
children
|
|
2522
1394
|
});
|
|
2523
1395
|
const code = textOf(hast).replace(/\n$/, "");
|
|
2524
|
-
|
|
1396
|
+
const Custom = block && language && Object.hasOwn(codeBlocks ?? {}, language) ? codeBlocks[language] : void 0;
|
|
1397
|
+
if (block && Custom) return /* @__PURE__ */ jsx(Custom, {
|
|
2525
1398
|
id: `${block.id}:${hast?.position?.start.line ?? 0}`,
|
|
2526
|
-
|
|
1399
|
+
code,
|
|
2527
1400
|
streaming: block.streaming
|
|
2528
1401
|
});
|
|
2529
1402
|
return /* @__PURE__ */ jsx(CodeBlock, {
|
|
@@ -3114,7 +1987,12 @@ function useToolView(name) {
|
|
|
3114
1987
|
}
|
|
3115
1988
|
/** The provider's views, plus views brought by tools the page registered (`ChatTool.view`). */
|
|
3116
1989
|
function useToolViews() {
|
|
3117
|
-
const
|
|
1990
|
+
const fromExtensions = useChatExtensions().toolViews;
|
|
1991
|
+
const provided = useContext(ToolViewsContext) ?? defaultToolViews;
|
|
1992
|
+
const base = useMemo(() => fromExtensions ? {
|
|
1993
|
+
...fromExtensions,
|
|
1994
|
+
...provided
|
|
1995
|
+
} : provided, [fromExtensions, provided]);
|
|
3118
1996
|
const registry = useAgentSnapshot();
|
|
3119
1997
|
const version = registry?.getVersion() ?? 0;
|
|
3120
1998
|
return useMemo(() => {
|
|
@@ -3866,7 +2744,11 @@ function AssistantMessage({ message, onRetry, onFeedback, onReadAloud, renderPar
|
|
|
3866
2744
|
const streaming = message.status === "streaming";
|
|
3867
2745
|
const views = useToolViews();
|
|
3868
2746
|
const blocks = toBlocks(message.parts, (part) => views[part.name]?.Block !== void 0);
|
|
3869
|
-
const {
|
|
2747
|
+
const { renderPart: extensionPart, toolChains } = useChatExtensions();
|
|
2748
|
+
const { first, chains } = toolChains?.group(message) ?? {
|
|
2749
|
+
first: /* @__PURE__ */ new Map(),
|
|
2750
|
+
chains: /* @__PURE__ */ new Map()
|
|
2751
|
+
};
|
|
3870
2752
|
return /* @__PURE__ */ jsxs("div", {
|
|
3871
2753
|
className: clsx("group/message flex flex-col gap-4", className),
|
|
3872
2754
|
children: [
|
|
@@ -3881,14 +2763,16 @@ function AssistantMessage({ message, onRetry, onFeedback, onReadAloud, renderPar
|
|
|
3881
2763
|
})] }, block.id);
|
|
3882
2764
|
}
|
|
3883
2765
|
if (block.kind === "tool") {
|
|
3884
|
-
if (first.get(block.part.id) !== block.part.id) return null;
|
|
3885
|
-
|
|
2766
|
+
if ((first.get(block.part.id) ?? block.part.id) !== block.part.id) return null;
|
|
2767
|
+
const draw = (part) => {
|
|
2768
|
+
const ToolBlock = (views[part.name] ?? views[block.part.name]).Block;
|
|
2769
|
+
return /* @__PURE__ */ jsx(ToolBlock, { part });
|
|
2770
|
+
};
|
|
2771
|
+
const Chain = toolChains?.Chain;
|
|
2772
|
+
return Chain ? /* @__PURE__ */ jsx(Chain, {
|
|
3886
2773
|
chain: chains.get(block.part.id) ?? [block.part],
|
|
3887
|
-
draw
|
|
3888
|
-
|
|
3889
|
-
return /* @__PURE__ */ jsx(ToolBlock, { part });
|
|
3890
|
-
}
|
|
3891
|
-
}, block.id);
|
|
2774
|
+
draw
|
|
2775
|
+
}, block.id) : /* @__PURE__ */ jsx(Fragment, { children: draw(block.part) }, block.id);
|
|
3892
2776
|
}
|
|
3893
2777
|
const part = block.part;
|
|
3894
2778
|
if (part.type === "text") return /* @__PURE__ */ jsx(Markdown, {
|
|
@@ -3898,7 +2782,8 @@ function AssistantMessage({ message, onRetry, onFeedback, onReadAloud, renderPar
|
|
|
3898
2782
|
}, part.id);
|
|
3899
2783
|
const custom = renderPart?.(part);
|
|
3900
2784
|
if (custom) return /* @__PURE__ */ jsx("div", { children: custom }, part.id);
|
|
3901
|
-
|
|
2785
|
+
const extra = extensionPart?.(part);
|
|
2786
|
+
if (extra) return /* @__PURE__ */ jsx(Fragment, { children: extra }, part.id);
|
|
3902
2787
|
if (part.type === "custom" && part.text) return /* @__PURE__ */ jsx(Markdown, { children: part.text }, part.id);
|
|
3903
2788
|
return null;
|
|
3904
2789
|
}),
|
|
@@ -3959,230 +2844,6 @@ function ToolPromptCard({ prompt, onAnswer, onDecline }) {
|
|
|
3959
2844
|
onDecline: () => onDecline(part.id)
|
|
3960
2845
|
}, part.id);
|
|
3961
2846
|
}
|
|
3962
|
-
// src/components/ui-components.tsx
|
|
3963
|
-
const toneClass = {
|
|
3964
|
-
default: "text-chat-fg",
|
|
3965
|
-
accent: "text-chat-accent",
|
|
3966
|
-
good: "text-chat-check",
|
|
3967
|
-
warning: "text-chat-warning",
|
|
3968
|
-
bad: "text-chat-danger"
|
|
3969
|
-
};
|
|
3970
|
-
const fillClass = {
|
|
3971
|
-
default: "bg-chat-fg",
|
|
3972
|
-
accent: "bg-chat-accent",
|
|
3973
|
-
good: "bg-chat-check",
|
|
3974
|
-
warning: "bg-chat-warning",
|
|
3975
|
-
bad: "bg-chat-danger"
|
|
3976
|
-
};
|
|
3977
|
-
/** "New" / "Changed": what the model added stands out in the accent. */
|
|
3978
|
-
function Tag({ children, quiet = false }) {
|
|
3979
|
-
return /* @__PURE__ */ jsx("span", {
|
|
3980
|
-
className: `rounded-chat-sm px-1.5 text-(length:--chat-ui-font-size-sm) font-medium ${quiet ? "border border-chat-border-strong text-chat-muted" : "bg-chat-accent text-chat-accent-fg"}`,
|
|
3981
|
-
children
|
|
3982
|
-
});
|
|
3983
|
-
}
|
|
3984
|
-
const Stack = ({ direction = "column", gap = "md", children }) => /* @__PURE__ */ jsx("div", {
|
|
3985
|
-
className: `flex ${direction === "row" ? "flex-row flex-wrap" : "flex-col"} ${{
|
|
3986
|
-
sm: "gap-1.5",
|
|
3987
|
-
md: "gap-3",
|
|
3988
|
-
lg: "gap-5"
|
|
3989
|
-
}[gap]}`,
|
|
3990
|
-
children
|
|
3991
|
-
});
|
|
3992
|
-
const Grid = ({ columns = 2, children }) => /* @__PURE__ */ jsx("div", {
|
|
3993
|
-
className: "grid gap-3",
|
|
3994
|
-
style: { gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${Math.floor(36 / columns)}rem), 1fr))` },
|
|
3995
|
-
children
|
|
3996
|
-
});
|
|
3997
|
-
const Card = ({ title, subtitle, tag, tone = "default", children }) => /* @__PURE__ */ jsxs("section", {
|
|
3998
|
-
className: `rounded-chat-lg border p-3 ${tone === "accent" ? "border-chat-accent" : "border-chat-border"}`,
|
|
3999
|
-
children: [
|
|
4000
|
-
(title || tag) && /* @__PURE__ */ jsxs("header", {
|
|
4001
|
-
className: "mb-1 flex items-center gap-2",
|
|
4002
|
-
children: [title && /* @__PURE__ */ jsx("h3", {
|
|
4003
|
-
className: "font-chat-sans text-(length:--chat-ui-font-size) font-semibold",
|
|
4004
|
-
children: title
|
|
4005
|
-
}), tag && /* @__PURE__ */ jsx(Tag, {
|
|
4006
|
-
quiet: tone !== "accent",
|
|
4007
|
-
children: tag
|
|
4008
|
-
})]
|
|
4009
|
-
}),
|
|
4010
|
-
subtitle && /* @__PURE__ */ jsx("p", {
|
|
4011
|
-
className: "mb-2 text-(length:--chat-ui-font-size-sm) text-chat-muted",
|
|
4012
|
-
children: subtitle
|
|
4013
|
-
}),
|
|
4014
|
-
children
|
|
4015
|
-
]
|
|
4016
|
-
});
|
|
4017
|
-
const Heading$1 = ({ text }) => /* @__PURE__ */ jsx("h2", {
|
|
4018
|
-
className: "font-chat-sans text-(length:--chat-ui-font-size) font-semibold",
|
|
4019
|
-
children: text
|
|
4020
|
-
});
|
|
4021
|
-
const Text$1 = ({ text, tone = "default" }) => /* @__PURE__ */ jsx("p", {
|
|
4022
|
-
className: `font-chat-sans text-(length:--chat-ui-font-size) leading-relaxed ${tone === "muted" ? "text-chat-muted" : ""}`,
|
|
4023
|
-
children: text
|
|
4024
|
-
});
|
|
4025
|
-
const Metric = ({ label, value, note, tone = "default" }) => /* @__PURE__ */ jsxs("div", {
|
|
4026
|
-
className: "min-w-24",
|
|
4027
|
-
children: [
|
|
4028
|
-
/* @__PURE__ */ jsx("div", {
|
|
4029
|
-
className: "text-(length:--chat-ui-font-size-sm) text-chat-muted",
|
|
4030
|
-
children: label
|
|
4031
|
-
}),
|
|
4032
|
-
/* @__PURE__ */ jsx("div", {
|
|
4033
|
-
className: `font-chat-sans text-xl font-semibold tabular-nums ${toneClass[tone]}`,
|
|
4034
|
-
children: value
|
|
4035
|
-
}),
|
|
4036
|
-
note && /* @__PURE__ */ jsx("div", {
|
|
4037
|
-
className: "text-(length:--chat-ui-font-size-sm) text-chat-subtle",
|
|
4038
|
-
children: note
|
|
4039
|
-
})
|
|
4040
|
-
]
|
|
4041
|
-
});
|
|
4042
|
-
const List = ({ items }) => /* @__PURE__ */ jsx("ul", {
|
|
4043
|
-
className: "divide-y divide-chat-divider",
|
|
4044
|
-
children: items.map((item, i) => /* @__PURE__ */ jsxs("li", {
|
|
4045
|
-
className: "flex items-baseline gap-2 py-1.5 font-chat-sans text-(length:--chat-ui-font-size)",
|
|
4046
|
-
children: [
|
|
4047
|
-
/* @__PURE__ */ jsx("span", {
|
|
4048
|
-
className: item.tag ? "text-chat-accent" : "",
|
|
4049
|
-
children: item.label
|
|
4050
|
-
}),
|
|
4051
|
-
item.tag && /* @__PURE__ */ jsx(Tag, { children: item.tag }),
|
|
4052
|
-
item.detail && /* @__PURE__ */ jsx("span", {
|
|
4053
|
-
className: "ml-auto text-chat-muted tabular-nums",
|
|
4054
|
-
children: item.detail
|
|
4055
|
-
})
|
|
4056
|
-
]
|
|
4057
|
-
}, i))
|
|
4058
|
-
});
|
|
4059
|
-
const Table = ({ columns, rows }) => /* @__PURE__ */ jsx("div", {
|
|
4060
|
-
className: "max-w-full overflow-x-auto",
|
|
4061
|
-
children: /* @__PURE__ */ jsxs("table", {
|
|
4062
|
-
className: "w-full border-collapse text-left font-chat-sans text-(length:--chat-ui-font-size)",
|
|
4063
|
-
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", {
|
|
4064
|
-
className: "border-b border-chat-border-strong",
|
|
4065
|
-
children: columns.map((c, i) => /* @__PURE__ */ jsx("th", {
|
|
4066
|
-
scope: "col",
|
|
4067
|
-
className: "px-2 py-1.5 font-medium text-chat-muted",
|
|
4068
|
-
children: c
|
|
4069
|
-
}, i))
|
|
4070
|
-
}) }), /* @__PURE__ */ jsx("tbody", {
|
|
4071
|
-
className: "divide-y divide-chat-divider",
|
|
4072
|
-
children: rows.map((row, r) => /* @__PURE__ */ jsx("tr", { children: columns.map((_, c) => /* @__PURE__ */ jsx("td", {
|
|
4073
|
-
className: `px-2 py-1.5 ${typeof row[c] === "number" ? "tabular-nums" : ""}`,
|
|
4074
|
-
children: row[c]
|
|
4075
|
-
}, c)) }, r))
|
|
4076
|
-
})]
|
|
4077
|
-
})
|
|
4078
|
-
});
|
|
4079
|
-
const Badge$1 = ({ label, tone = "default" }) => /* @__PURE__ */ jsx("span", {
|
|
4080
|
-
className: `inline-block self-start rounded-chat-sm border border-current px-1.5 font-chat-sans text-(length:--chat-ui-font-size-sm) font-medium ${toneClass[tone]}`,
|
|
4081
|
-
children: label
|
|
4082
|
-
});
|
|
4083
|
-
const Progress = ({ label, value, max = 100, tone = "accent" }) => {
|
|
4084
|
-
const share = Math.min(1, Math.max(0, value / max));
|
|
4085
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
4086
|
-
className: "flex flex-col gap-1",
|
|
4087
|
-
children: [label && /* @__PURE__ */ jsxs("div", {
|
|
4088
|
-
className: "flex justify-between text-(length:--chat-ui-font-size-sm) text-chat-muted",
|
|
4089
|
-
children: [/* @__PURE__ */ jsx("span", { children: label }), /* @__PURE__ */ jsxs("span", {
|
|
4090
|
-
className: "tabular-nums",
|
|
4091
|
-
children: [Math.round(share * 100), "%"]
|
|
4092
|
-
})]
|
|
4093
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
4094
|
-
role: "progressbar",
|
|
4095
|
-
"aria-label": label ?? "Progress",
|
|
4096
|
-
"aria-valuemin": 0,
|
|
4097
|
-
"aria-valuemax": max,
|
|
4098
|
-
"aria-valuenow": Math.min(value, max),
|
|
4099
|
-
className: "h-1.5 overflow-hidden rounded-full bg-chat-border",
|
|
4100
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
4101
|
-
className: `h-full rounded-full ${fillClass[tone]}`,
|
|
4102
|
-
style: { width: `${share * 100}%` }
|
|
4103
|
-
})
|
|
4104
|
-
})]
|
|
4105
|
-
});
|
|
4106
|
-
};
|
|
4107
|
-
const Checklist = function Checklist({ stateKey, items }) {
|
|
4108
|
-
const [state, set] = useUiState();
|
|
4109
|
-
const done = state[stateKey] ?? [];
|
|
4110
|
-
return /* @__PURE__ */ jsx("ul", {
|
|
4111
|
-
className: "flex flex-col gap-1",
|
|
4112
|
-
children: items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("label", {
|
|
4113
|
-
className: "flex items-center gap-2 font-chat-sans text-(length:--chat-ui-font-size)",
|
|
4114
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
4115
|
-
type: "checkbox",
|
|
4116
|
-
className: "accent-(--chat-accent)",
|
|
4117
|
-
checked: done.includes(item),
|
|
4118
|
-
onChange: (e) => set(stateKey, e.target.checked ? [...done, item] : done.filter((d) => d !== item))
|
|
4119
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
4120
|
-
className: done.includes(item) ? "text-chat-subtle line-through" : "",
|
|
4121
|
-
children: item
|
|
4122
|
-
})]
|
|
4123
|
-
}) }, item))
|
|
4124
|
-
});
|
|
4125
|
-
};
|
|
4126
|
-
const Tabs = function Tabs({ stateKey, value, options }) {
|
|
4127
|
-
const [, set] = useUiState();
|
|
4128
|
-
const current = value ?? options[0].id;
|
|
4129
|
-
return /* @__PURE__ */ jsx("div", {
|
|
4130
|
-
role: "tablist",
|
|
4131
|
-
className: "inline-flex max-w-full flex-wrap gap-1 self-start rounded-chat-md border border-chat-border p-0.5",
|
|
4132
|
-
children: options.map((o) => /* @__PURE__ */ jsx(Button, {
|
|
4133
|
-
size: "sm",
|
|
4134
|
-
variant: o.id === current ? "subtle" : "ghost",
|
|
4135
|
-
onPress: () => set(stateKey, o.id),
|
|
4136
|
-
"aria-selected": o.id === current,
|
|
4137
|
-
children: o.label
|
|
4138
|
-
}, o.id))
|
|
4139
|
-
});
|
|
4140
|
-
};
|
|
4141
|
-
const Show = ({ value, equals, fallback, children }) => value === equals || value === void 0 && fallback ? /* @__PURE__ */ jsx(Fragment$1, { children }) : null;
|
|
4142
|
-
/**
|
|
4143
|
-
* The drawing of each component, by name and apart from its spec. Take one to reuse in your own
|
|
4144
|
-
* component: `{ ...uiSpecs.Card, render: uiRenders.Card }`.
|
|
4145
|
-
*/
|
|
4146
|
-
const uiRenders = {
|
|
4147
|
-
Stack,
|
|
4148
|
-
Grid,
|
|
4149
|
-
Card,
|
|
4150
|
-
Heading: Heading$1,
|
|
4151
|
-
Text: Text$1,
|
|
4152
|
-
Metric,
|
|
4153
|
-
List,
|
|
4154
|
-
Table,
|
|
4155
|
-
Badge: Badge$1,
|
|
4156
|
-
Progress,
|
|
4157
|
-
Checklist,
|
|
4158
|
-
Tabs,
|
|
4159
|
-
Show,
|
|
4160
|
-
Button: function UiButton({ label, variant = "secondary", onPress }) {
|
|
4161
|
-
const run = useUiAction();
|
|
4162
|
-
return /* @__PURE__ */ jsx(Button, {
|
|
4163
|
-
size: "sm",
|
|
4164
|
-
className: "self-start",
|
|
4165
|
-
variant: variant === "primary" ? "primary" : "subtle",
|
|
4166
|
-
onPress: () => run(onPress),
|
|
4167
|
-
children: label
|
|
4168
|
-
});
|
|
4169
|
-
}
|
|
4170
|
-
};
|
|
4171
|
-
/**
|
|
4172
|
-
* The ready components for `UiComponentsProvider`, in the order of `uiComponentSpecs`. Everything by default;
|
|
4173
|
-
* `include` and `exclude` take component names or the groups `"display"` (Stack, Grid, Card, Heading, Text,
|
|
4174
|
-
* Metric, List, Table, Badge, Progress) and `"interactive"` (Checklist, Tabs, Show, Button). `renders` swaps the
|
|
4175
|
-
* drawing of single components. Build the model's tool from the same picks so it only hears of what you
|
|
4176
|
-
* registered: `uiSpecSet({ include })` in `agentic-ui-kit/core`, or strip the renders from this list.
|
|
4177
|
-
*/
|
|
4178
|
-
function uiComponentSet({ renders = {}, ...selection } = {}) {
|
|
4179
|
-
return uiSpecSet(selection).map((spec) => ({
|
|
4180
|
-
...spec,
|
|
4181
|
-
render: renders[spec.name] ?? uiRenders[spec.name]
|
|
4182
|
-
}));
|
|
4183
|
-
}
|
|
4184
|
-
/** The whole set: `uiComponentSet()`. */
|
|
4185
|
-
const uiComponents = uiComponentSet();
|
|
4186
2847
|
// src/components/approval-card.tsx
|
|
4187
2848
|
/**
|
|
4188
2849
|
* Asks the user before a tool runs, above the composer. Shows the tool's label and what it will do: its
|
|
@@ -5129,6 +3790,7 @@ function ModelPicker({ models, model, onModelChange, effort, onEffortChange, eff
|
|
|
5129
3790
|
// src/components/message-list.tsx
|
|
5130
3791
|
/** How close to the bottom still counts as "at the bottom", in px. */
|
|
5131
3792
|
const STICK_SLOP = 48;
|
|
3793
|
+
const NoScope = ({ children }) => /* @__PURE__ */ jsx(Fragment$1, { children });
|
|
5132
3794
|
/**
|
|
5133
3795
|
* The scrolling conversation. It follows a streaming reply while the reader is at the bottom and leaves
|
|
5134
3796
|
* them alone once they scroll up, with a button to jump back. Sending a message always jumps down.
|
|
@@ -5139,7 +3801,7 @@ function MessageList({ messages, onRetry, onEdit, onFeedback, onReadAloud, actio
|
|
|
5139
3801
|
const content = useRef(null);
|
|
5140
3802
|
const stuck = useRef(start === "bottom");
|
|
5141
3803
|
const labels = useLabels();
|
|
5142
|
-
const
|
|
3804
|
+
const Scope = useChatExtensions().messageScope ?? NoScope;
|
|
5143
3805
|
const [atBottom, setAtBottom] = useState(true);
|
|
5144
3806
|
const toBottom = useCallback((behavior = "auto") => {
|
|
5145
3807
|
const el = scroller.current;
|
|
@@ -5191,8 +3853,8 @@ function MessageList({ messages, onRetry, onEdit, onFeedback, onReadAloud, actio
|
|
|
5191
3853
|
role: "log",
|
|
5192
3854
|
"aria-label": labels.conversation,
|
|
5193
3855
|
className: "mx-auto flex w-full max-w-[calc(var(--chat-content-width)+2*var(--chat-gutter,var(--chat-content-padding)))] flex-1 flex-col gap-6 px-[var(--chat-gutter,var(--chat-content-padding))] pt-6 pb-4",
|
|
5194
|
-
children: [header, /* @__PURE__ */ jsx(
|
|
5195
|
-
|
|
3856
|
+
children: [header, /* @__PURE__ */ jsx(Scope, {
|
|
3857
|
+
messages,
|
|
5196
3858
|
children: messages.map((m) => m.role === "user" ? /* @__PURE__ */ jsx(UserMessage, {
|
|
5197
3859
|
message: m,
|
|
5198
3860
|
...onEdit && { onEdit: () => onEdit(m.id) },
|
|
@@ -5541,17 +4203,13 @@ const densityVars = {
|
|
|
5541
4203
|
}
|
|
5542
4204
|
};
|
|
5543
4205
|
/** A whole chat: header, the conversation, the docked composer. An empty chat shows `emptyState`. */
|
|
5544
|
-
function ChatView({ messages, busy = false, onSend, onStop, approvals, onApprove, prompts, onAnswer, onDecline, onRetry, onEdit, onFeedback, onReadAloud, messageActions, renderPart,
|
|
4206
|
+
function ChatView({ messages, busy = false, onSend, onStop, approvals, onApprove, prompts, onAnswer, onDecline, onRetry, onEdit, onFeedback, onReadAloud, messageActions, renderPart, header, composer, emptyState, disclaimer, renderComposer, density = "full", contentWidth, contentPadding, className }) {
|
|
5545
4207
|
const style = {
|
|
5546
4208
|
...densityVars[density],
|
|
5547
4209
|
...contentWidth && { "--chat-content-width": contentWidth },
|
|
5548
4210
|
...contentPadding && { "--chat-content-padding": contentPadding }
|
|
5549
4211
|
};
|
|
5550
|
-
const
|
|
5551
|
-
onPrompt: onSend,
|
|
5552
|
-
onOpenLink: openInNewTab,
|
|
5553
|
-
...widgets
|
|
5554
|
-
}), [onSend, widgets]);
|
|
4212
|
+
const interaction = useMemo(() => ({ send: onSend }), [onSend]);
|
|
5555
4213
|
const empty = messages.length === 0;
|
|
5556
4214
|
const [body, short] = useShortPane();
|
|
5557
4215
|
const labels = useLabels();
|
|
@@ -5582,8 +4240,8 @@ function ChatView({ messages, busy = false, onSend, onStop, approvals, onApprove
|
|
|
5582
4240
|
className: "w-full max-w-(--chat-content-width)",
|
|
5583
4241
|
children: emptyState ? emptyState(box("centered")) : box("centered")
|
|
5584
4242
|
})
|
|
5585
|
-
}) : /* @__PURE__ */ jsx(
|
|
5586
|
-
|
|
4243
|
+
}) : /* @__PURE__ */ jsx(ChatInteractionProvider, {
|
|
4244
|
+
value: interaction,
|
|
5587
4245
|
children: /* @__PURE__ */ jsx(MessageList, {
|
|
5588
4246
|
messages,
|
|
5589
4247
|
...onRetry && { onRetry },
|
|
@@ -5654,34 +4312,25 @@ function EmptyState({ greeting, icon, children, footer }) {
|
|
|
5654
4312
|
});
|
|
5655
4313
|
}
|
|
5656
4314
|
// src/views/chat-transcript.tsx
|
|
4315
|
+
const readOnly = { readOnly: true };
|
|
5657
4316
|
/**
|
|
5658
4317
|
* A conversation to read, not to continue: a shared chat, an export, a log. Same messages as ChatView,
|
|
5659
4318
|
* with no composer, approvals, retry, edit or feedback. Copy stays.
|
|
5660
4319
|
*/
|
|
5661
|
-
function ChatTranscript({ messages, renderPart,
|
|
4320
|
+
function ChatTranscript({ messages, renderPart, header, notice, footer, start = "top", density = "full", contentWidth, contentPadding, className }) {
|
|
5662
4321
|
const style = {
|
|
5663
4322
|
...densityVars[density],
|
|
5664
4323
|
...contentWidth && { "--chat-content-width": contentWidth },
|
|
5665
4324
|
...contentPadding && { "--chat-content-padding": contentPadding }
|
|
5666
4325
|
};
|
|
5667
|
-
const host = useMemo(() => {
|
|
5668
|
-
const { allow, readResource, frameUrl } = { ...widgets };
|
|
5669
|
-
const onOpenLink = widgets && "onOpenLink" in widgets ? widgets.onOpenLink : openInNewTab;
|
|
5670
|
-
return {
|
|
5671
|
-
...allow && { allow },
|
|
5672
|
-
...onOpenLink && { onOpenLink },
|
|
5673
|
-
...readResource && { readResource },
|
|
5674
|
-
...frameUrl && { frameUrl }
|
|
5675
|
-
};
|
|
5676
|
-
}, [widgets]);
|
|
5677
4326
|
return /* @__PURE__ */ jsxs("div", {
|
|
5678
4327
|
"data-chat-density": density,
|
|
5679
4328
|
style,
|
|
5680
4329
|
className: clsx("chat-view flex h-full min-h-0 flex-col bg-chat-bg text-chat-fg", className),
|
|
5681
4330
|
children: [header, /* @__PURE__ */ jsx("div", {
|
|
5682
4331
|
className: "chat-view-body flex min-h-0 flex-1 flex-col",
|
|
5683
|
-
children: /* @__PURE__ */ jsx(
|
|
5684
|
-
|
|
4332
|
+
children: /* @__PURE__ */ jsx(ChatInteractionProvider, {
|
|
4333
|
+
value: readOnly,
|
|
5685
4334
|
children: /* @__PURE__ */ jsx(MessageList, {
|
|
5686
4335
|
messages,
|
|
5687
4336
|
start,
|
|
@@ -6017,4 +4666,4 @@ function SidebarUser({ name, detail, avatarUrl, menu, popoverProps }) {
|
|
|
6017
4666
|
children: menu
|
|
6018
4667
|
})] });
|
|
6019
4668
|
}
|
|
6020
|
-
export { ActivityGroup, AgentProvider, AgentRegistry, AppShell, ApprovalCard, AskUserAnswers, AskUserPrompt, AssistantMessage, AttachButton, AttachmentCard, AttachmentRow, Badge, Button, Caret, ChatHeader, ChatList, ChatListRailButton, ChatNotice, ChatTheme, ChatTitleMenu, ChatTranscript, ChatView, CodeBlock, Composer, ContextMenu, ContextMeter, ContextPanel, CopyButton, CopyField, DRAWER_QUERY, DialogTrigger, DictationButton, DictationControls, Disclosure, Drawer, EffortButton, EffortSlider, EmptyState, IconButton, Markdown, MarkdownLinksProvider, Menu, MenuItem, MenuNote, MenuSearch, MenuSection, MenuSeparator, MenuTrigger, MessageList, Modal, ModelPicker, Panel, PastedTextDialog, Popover, PopoverTrigger, SegmentedControl, Sidebar, SidebarItem, SidebarList, SidebarToggle, SidebarUser, SubmenuTrigger, TokenCounter, ToolPromptCard, ToolViewsProvider, Tooltip,
|
|
4669
|
+
export { ActivityGroup, AgentProvider, AgentRegistry, AppShell, ApprovalCard, AskUserAnswers, AskUserPrompt, AssistantMessage, AttachButton, AttachmentCard, AttachmentRow, Badge, Button, Caret, ChatExtensionsProvider, ChatHeader, ChatInteractionProvider, ChatList, ChatListRailButton, ChatNotice, ChatTheme, ChatTitleMenu, ChatTranscript, ChatView, CodeBlock, Composer, ContextMenu, ContextMeter, ContextPanel, CopyButton, CopyField, DRAWER_QUERY, DialogTrigger, DictationButton, DictationControls, Disclosure, Drawer, EffortButton, EffortSlider, EmptyState, IconButton, Markdown, MarkdownLinksProvider, Menu, MenuItem, MenuNote, MenuSearch, MenuSection, MenuSeparator, MenuTrigger, MessageList, Modal, ModelPicker, Panel, PastedTextDialog, Popover, PopoverTrigger, SegmentedControl, Sidebar, SidebarItem, SidebarList, SidebarToggle, SidebarUser, SubmenuTrigger, TokenCounter, ToolPromptCard, ToolViewsProvider, Tooltip, UserMessage, VoiceMeter, activityHeading, activityLabel, askUserToolView, commandTool, defaultIcons, defaultLabels, defaultToolViews, encodeWav, formatDuration, formatRelativeTime, formatTokens, memoryTool, messageText, sseTransport, useAgentContext, useAgentRegistry, useAgentSnapshot, useAgentTool, useAttachments, useChat, useChatExtensions, useChatInteraction, useChatTool, useCountUp, useDictation, useIcons, useLabels, useMediaQuery, useSidebar, useSmoothText, useToolView, useToolViews, userMessage, webFetchTool, webSearchTool };
|