@mcp-b/react-components 0.11.0 → 0.12.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/dist/{AgentChat-B9LD_WF1.d.ts → AgentChat-CRmsKg9B.d.ts} +10 -6
- package/dist/{BrowserLiveView-ZktFZiMD.d.ts → BrowserLiveView-BV5qgFgI.d.ts} +11 -10
- package/dist/{BrowserReplay-6G-mnwcn.d.ts → BrowserReplay-xWvRjRAC.d.ts} +2 -1
- package/dist/{Menu-B5vDqZe_.d.ts → Menu-BLhnNnRK.d.ts} +3 -0
- package/dist/{ModelSelector-DXtpcRmT.js → ModelSelector-BB-xB-Es.js} +16 -13
- package/dist/{PromptInput-D6-G24p7.d.ts → PromptInput-IyM6ZETj.d.ts} +13 -45
- package/dist/ThinkChat-B3wYahor.js +190 -0
- package/dist/{ThinkChatActivity-B2UD95My.d.ts → ThinkChatActivity-F4KFPcJA.d.ts} +4 -4
- package/dist/ThinkChatContext-C3Eb1Xpi.d.ts +16 -0
- package/dist/{ThinkChatToolParts-DnUiZgCC.d.ts → ThinkChatToolParts-Cv4o7j6F.d.ts} +13 -5
- package/dist/components/AgentChat.d.ts +1 -1
- package/dist/components/AgentChat.js +57 -23
- package/dist/components/AgentConnection.js +4 -20
- package/dist/components/Badge.js +1 -15
- package/dist/components/BrowserLiveView.d.ts +1 -1
- package/dist/components/BrowserLiveView.js +14 -10
- package/dist/components/BrowserReplay.d.ts +1 -1
- package/dist/components/BrowserRunPanel.js +91 -55
- package/dist/components/ChatGptSignInScreen.js +1 -1
- package/dist/components/CodexModelSelector.d.ts +63 -0
- package/dist/components/CodexModelSelector.js +148 -0
- package/dist/components/Commit.d.ts +2 -2
- package/dist/components/Commit.js +10 -22
- package/dist/components/Conversation.d.ts +2 -6
- package/dist/components/Conversation.js +2 -3
- package/dist/components/EnvironmentVariables.d.ts +2 -7
- package/dist/components/EnvironmentVariables.js +10 -33
- package/dist/components/Marker.js +1 -15
- package/dist/components/McpServerPicker.d.ts +31 -6
- package/dist/components/McpServerPicker.js +129 -67
- package/dist/components/Menu.d.ts +1 -1
- package/dist/components/Menu.js +2 -2
- package/dist/components/Message.d.ts +3 -2
- package/dist/components/Message.js +10 -3
- package/dist/components/ModelSelector.d.ts +11 -8
- package/dist/components/ModelSelector.js +1 -1
- package/dist/components/PromptInput.d.ts +2 -2
- package/dist/components/PromptInput.js +49 -98
- package/dist/components/Queue.d.ts +1 -12
- package/dist/components/Reasoning.js +2 -15
- package/dist/components/Stepper.js +1 -7
- package/dist/components/ThinkChat.d.ts +30 -30
- package/dist/components/ThinkChat.js +1 -152
- package/dist/components/ThinkChatActivity.d.ts +2 -2
- package/dist/components/ThinkChatActivity.js +3 -10
- package/dist/components/ThinkChatContext.d.ts +2 -2
- package/dist/components/ThinkChatContext.js +9 -2
- package/dist/components/ThinkChatToolPanels.d.ts +1 -1
- package/dist/components/ThinkChatToolPanels.js +19 -7
- package/dist/components/ThinkChatToolParts.d.ts +1 -1
- package/dist/components/ThinkExecutionWorkbench.d.ts +10 -7
- package/dist/components/ThinkExecutionWorkbench.js +382 -359
- package/dist/components/ThinkFullApp.d.ts +16 -13
- package/dist/components/ThinkFullApp.js +28 -18
- package/dist/components/ThinkThreadPicker.d.ts +1 -31
- package/dist/components/ThinkThreadPicker.js +32 -171
- package/dist/components/ThinkThreadShell.d.ts +35 -0
- package/dist/components/ThinkThreadShell.js +146 -0
- package/dist/components/WorkspaceExplorer.js +3 -1
- package/dist/merge-refs-DF_7w2x_.js +18 -0
- package/dist/styles/agent-chat.css +4 -1
- package/dist/styles/browser-run-panel.css +57 -110
- package/dist/styles/codex-model-selector.css +197 -0
- package/dist/styles/index.css +4 -1
- package/dist/styles/mcp-server-picker.css +62 -15
- package/dist/styles/message.css +1 -1
- package/dist/styles/model-selector.css +20 -8
- package/dist/styles/prompt-input.css +5 -0
- package/dist/styles/streamdown.css +2 -48
- package/dist/styles/think-execution-workbench.css +337 -0
- package/dist/styles/think-full-app.css +15 -390
- package/dist/styles/think-resize-handle.css +33 -0
- package/dist/styles/think-thread-picker.css +0 -238
- package/dist/styles/think-thread-shell.css +219 -0
- package/dist/styles/workspace-explorer.css +8 -2
- package/dist/summarize-tool-input-BUJsENSn.js +12 -0
- package/package.json +2 -2
- package/dist/ThinkChatContext-BLAAb8J5.d.ts +0 -28
- package/dist/components/McpServerConnections.d.ts +0 -41
- package/dist/components/McpServerConnections.js +0 -188
- package/dist/components/useStickToBottom.d.ts +0 -33
- package/dist/components/useStickToBottom.js +0 -107
- package/dist/styles/mcp-server-connections.css +0 -145
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as PromptInputMessage } from "./PromptInput-IyM6ZETj.js";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { ChatAddToolApproveResponseFunction, ChatStatus, UIMessage } from "ai";
|
|
4
|
-
import { PendingApproval } from "@cloudflare/think";
|
|
4
|
+
import { PendingApproval, Think } from "@cloudflare/think";
|
|
5
|
+
import { AgentStub } from "agents/client";
|
|
5
6
|
|
|
6
7
|
//#region src/components/AgentChat.d.ts
|
|
7
8
|
type AgentChatPart<MessageT extends UIMessage = UIMessage> = MessageT["parts"][number];
|
|
@@ -103,9 +104,11 @@ interface AgentChatProps<MessageT extends UIMessage = UIMessage> {
|
|
|
103
104
|
* confirmation.
|
|
104
105
|
*/
|
|
105
106
|
onApprovalResponse?: ChatAddToolApproveResponseFunction;
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
/** Think
|
|
107
|
+
/** Whole upstream Think stub used to resolve paused and durable execution approvals. */
|
|
108
|
+
thinkStub?: AgentStub<Think>;
|
|
109
|
+
/** Called after a Think approve/reject RPC settles, including when it rejects. */
|
|
110
|
+
onExecutionSettled?: () => void | Promise<void>;
|
|
111
|
+
/** Think durable-pause approvals from `pendingApprovals()`, rendered when `thinkStub` is set. */
|
|
109
112
|
pendingApprovals?: readonly PendingApproval[];
|
|
110
113
|
/**
|
|
111
114
|
* When set, a Context ring in the composer footer shows how much of the
|
|
@@ -153,7 +156,8 @@ declare function AgentChat<MessageT extends UIMessage = UIMessage>({
|
|
|
153
156
|
notice,
|
|
154
157
|
onRegenerate,
|
|
155
158
|
onApprovalResponse,
|
|
156
|
-
|
|
159
|
+
thinkStub,
|
|
160
|
+
onExecutionSettled,
|
|
157
161
|
pendingApprovals: durableApprovals,
|
|
158
162
|
contextWindow,
|
|
159
163
|
renderPart,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { BrowserLiveViewUrl } from "agents/browser";
|
|
2
3
|
|
|
3
4
|
//#region src/components/BrowserLiveView.d.ts
|
|
4
5
|
interface BrowserLiveViewProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/** Epoch ms
|
|
8
|
-
|
|
6
|
+
/** Complete upstream value returned by `cdp.getLiveViewUrl()`. */
|
|
7
|
+
source: BrowserLiveViewUrl;
|
|
8
|
+
/** Epoch ms when `source` was received. Defaults to its first render. */
|
|
9
|
+
receivedAt?: number;
|
|
9
10
|
/** The page the session was showing — used for the ended-state text. */
|
|
10
11
|
pageTitle?: string;
|
|
11
12
|
/**
|
|
@@ -18,8 +19,8 @@ interface BrowserLiveViewProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
18
19
|
/**
|
|
19
20
|
* Embeds a Browser Run Live View — a real-time, interactive view of the
|
|
20
21
|
* agent's browser session. Links expire (~5 minutes), so the iframe swaps to
|
|
21
|
-
* `fallback` (e.g. the last screenshot) once `
|
|
22
|
-
* hosted viewer connects, a quiet loading overlay hides the frame; if it
|
|
22
|
+
* `fallback` (e.g. the last screenshot) once `source.expiresInMs` passes.
|
|
23
|
+
* While the hosted viewer connects, a quiet loading overlay hides the frame; if it
|
|
23
24
|
* never loads, the view degrades to `fallback` or an unavailable state. An
|
|
24
25
|
* expand button opens the same view in a fullscreen dialog.
|
|
25
26
|
*
|
|
@@ -35,13 +36,13 @@ interface BrowserLiveViewProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
35
36
|
* The iframe is unsandboxed by design: the hosted Live View UI needs scripts
|
|
36
37
|
* and its own origin to stream the session. Only pass trusted Live View URLs.
|
|
37
38
|
*/
|
|
38
|
-
declare function BrowserLiveView({
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
declare function BrowserLiveView$1({
|
|
40
|
+
source,
|
|
41
|
+
receivedAt,
|
|
41
42
|
pageTitle,
|
|
42
43
|
fallback,
|
|
43
44
|
className,
|
|
44
45
|
...props
|
|
45
46
|
}: BrowserLiveViewProps): React.JSX.Element;
|
|
46
47
|
//#endregion
|
|
47
|
-
export { BrowserLiveViewProps as n, BrowserLiveView as t };
|
|
48
|
+
export { BrowserLiveViewProps as n, BrowserLiveView$1 as t };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { BrowserRecording } from "agents/browser";
|
|
2
3
|
|
|
3
4
|
//#region src/components/BrowserReplay.d.ts
|
|
4
5
|
interface BrowserReplayProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
|
|
@@ -6,7 +7,7 @@ interface BrowserReplayProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
|
|
|
6
7
|
* rrweb events for one tab, e.g. one
|
|
7
8
|
* `BrowserRecording.events[targetId]` entry from Cloudflare Browser Run.
|
|
8
9
|
*/
|
|
9
|
-
events:
|
|
10
|
+
events: BrowserRecording["events"][string];
|
|
10
11
|
/** Start playing on mount. */
|
|
11
12
|
autoPlay?: boolean;
|
|
12
13
|
}
|
|
@@ -12,6 +12,8 @@ interface MenuProps extends React.ComponentPropsWithoutRef<typeof Menu.Root> {}
|
|
|
12
12
|
interface MenuTriggerProps extends Omit<React.ComponentPropsWithoutRef<typeof Menu.Trigger>, "className"> {
|
|
13
13
|
/** Additional CSS class names */
|
|
14
14
|
className?: string;
|
|
15
|
+
/** Keep Base UI trigger behavior without the default menu trigger chrome. */
|
|
16
|
+
unstyled?: boolean;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Props for the Menu.Portal component.
|
|
@@ -145,6 +147,7 @@ declare const MenuRoot: (props: MenuProps) => React.JSX.Element;
|
|
|
145
147
|
*/
|
|
146
148
|
declare function MenuTrigger({
|
|
147
149
|
className,
|
|
150
|
+
unstyled,
|
|
148
151
|
ref,
|
|
149
152
|
...props
|
|
150
153
|
}: MenuTriggerProps & {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { t as cx } from "./class-names-9UtZwb0J.js";
|
|
2
2
|
import { A as SearchIcon, o as ChevronDownIcon } from "./icons-D2Q5n5C1.js";
|
|
3
|
+
import { Separator } from "./components/Separator.js";
|
|
3
4
|
import { Button } from "./components/Button.js";
|
|
4
5
|
import { Dialog, DialogBackdrop, DialogPopup, DialogPortal, DialogTitle, DialogTrigger } from "./components/Dialog.js";
|
|
6
|
+
import { Input } from "./components/Input.js";
|
|
5
7
|
import * as React from "react";
|
|
6
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
9
|
//#region src/components/_internal/provider-logos.tsx
|
|
@@ -213,13 +215,13 @@ function useModelSelectorContext() {
|
|
|
213
215
|
* multiselect; use Combobox or a dedicated component for that.
|
|
214
216
|
*
|
|
215
217
|
* Sigvelo changes: composes the design-system Dialog and Button, filters item
|
|
216
|
-
* children locally, and maps provider logos plus
|
|
218
|
+
* children locally, and maps provider logos plus button-list styling to Sigvelo
|
|
217
219
|
* CSS tokens.
|
|
218
220
|
*
|
|
219
|
-
* The dialog owns focus while open,
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
221
|
+
* The dialog owns focus while open, and options are native buttons in grouped
|
|
222
|
+
* sections. Styling consumes surface, border, spacing, radius, focus, and
|
|
223
|
+
* typography tokens. Add provider/item affordances here when they need to be
|
|
224
|
+
* shared.
|
|
223
225
|
*
|
|
224
226
|
* @example
|
|
225
227
|
* ```tsx
|
|
@@ -375,7 +377,7 @@ function ModelSelectorInput({ className, placeholder = "Search models…", ref,
|
|
|
375
377
|
className: "model-selector__search-icon",
|
|
376
378
|
"aria-hidden": "true",
|
|
377
379
|
children: /* @__PURE__ */ jsx(SearchIcon, {})
|
|
378
|
-
}), /* @__PURE__ */ jsx(
|
|
380
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
379
381
|
ref,
|
|
380
382
|
type: "search",
|
|
381
383
|
value: query,
|
|
@@ -390,7 +392,6 @@ function ModelSelectorInput({ className, placeholder = "Search models…", ref,
|
|
|
390
392
|
function ModelSelectorList({ className, children, ref, ...props }) {
|
|
391
393
|
return /* @__PURE__ */ jsx("div", {
|
|
392
394
|
ref,
|
|
393
|
-
role: "listbox",
|
|
394
395
|
className: cx("model-selector__list", className),
|
|
395
396
|
...props,
|
|
396
397
|
children
|
|
@@ -398,6 +399,7 @@ function ModelSelectorList({ className, children, ref, ...props }) {
|
|
|
398
399
|
}
|
|
399
400
|
function ModelSelectorGroup({ className, label, children, ref, ...props }) {
|
|
400
401
|
const { query } = useModelSelectorContext();
|
|
402
|
+
const labelId = React.useId();
|
|
401
403
|
const childArray = React.Children.toArray(children).filter((child) => React.isValidElement(child));
|
|
402
404
|
const q = query.trim().toLowerCase();
|
|
403
405
|
const filtered = q ? childArray.filter((child) => {
|
|
@@ -409,10 +411,11 @@ function ModelSelectorGroup({ className, label, children, ref, ...props }) {
|
|
|
409
411
|
return /* @__PURE__ */ jsxs("div", {
|
|
410
412
|
ref,
|
|
411
413
|
role: "group",
|
|
412
|
-
"aria-
|
|
414
|
+
"aria-labelledby": labelId,
|
|
413
415
|
className: cx("model-selector__group", className),
|
|
414
416
|
...props,
|
|
415
417
|
children: [/* @__PURE__ */ jsx("div", {
|
|
418
|
+
id: labelId,
|
|
416
419
|
className: "model-selector__group-label",
|
|
417
420
|
children: label
|
|
418
421
|
}), filtered]
|
|
@@ -425,11 +428,11 @@ function ModelSelectorItem({ className, value, keywords, selected, onSelect, chi
|
|
|
425
428
|
onSelectItem();
|
|
426
429
|
onClick?.(e);
|
|
427
430
|
};
|
|
428
|
-
return /* @__PURE__ */ jsx(
|
|
431
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
429
432
|
ref,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
"aria-selected":
|
|
433
|
+
variant: "ghost",
|
|
434
|
+
color: "neutral",
|
|
435
|
+
"aria-current": selected ? "true" : void 0,
|
|
433
436
|
"data-selected": selected ? "" : void 0,
|
|
434
437
|
className: cx("model-selector__item", className),
|
|
435
438
|
onClick: handleClick,
|
|
@@ -446,7 +449,7 @@ function ModelSelectorEmpty({ className, children = "No models found", ref, ...p
|
|
|
446
449
|
});
|
|
447
450
|
}
|
|
448
451
|
function ModelSelectorSeparator({ className, ref, ...props }) {
|
|
449
|
-
return /* @__PURE__ */ jsx(
|
|
452
|
+
return /* @__PURE__ */ jsx(Separator, {
|
|
450
453
|
ref,
|
|
451
454
|
className: cx("model-selector__separator", className),
|
|
452
455
|
...props
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { A as SelectTriggerProps, M as SelectValueProps, S as SelectProps, f as SelectOption, j as SelectValue, r as SelectContentProps, s as SelectItemProps, t as Select } from "./Select-CRsKCJ9x.js";
|
|
2
2
|
import { c as ComboboxGroup, d as ComboboxLabel, f as ComboboxList, g as ComboboxTrigger, h as ComboboxSeparator, l as ComboboxInput, m as ComboboxPositioner, p as ComboboxPopup, s as ComboboxEmpty, t as Combobox, u as ComboboxItem } from "./Combobox-D9anamNr.js";
|
|
3
|
-
import { h as MenuItemProps, l as MenuContentProps, w as MenuProps } from "./Menu-
|
|
3
|
+
import { h as MenuItemProps, l as MenuContentProps, w as MenuProps } from "./Menu-BLhnNnRK.js";
|
|
4
4
|
import { c as TabsList, n as TabPanel, t as Tab } from "./Tabs-D9EAq09D.js";
|
|
5
5
|
import { r as ButtonProps } from "./Button-Ct5I6aTu.js";
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import { ChatAddToolApproveResponseFunction, ChatStatus, DynamicToolUIPart, FileUIPart, ToolUIPart, UIMessage } from "ai";
|
|
8
|
-
import { PendingApproval } from "@cloudflare/think";
|
|
8
|
+
import { PendingApproval, Think } from "@cloudflare/think";
|
|
9
|
+
import { AgentStub } from "agents/client";
|
|
9
10
|
|
|
10
11
|
//#region src/components/PromptInput.d.ts
|
|
11
|
-
interface PromptInputReferencedSource {
|
|
12
|
-
id?: string;
|
|
13
|
-
title?: string;
|
|
14
|
-
url?: string;
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
}
|
|
17
12
|
/** The payload produced when the prompt input is submitted. */
|
|
18
13
|
interface PromptInputMessage {
|
|
19
14
|
text: string;
|
|
@@ -39,18 +34,9 @@ interface PromptInputControllerProps {
|
|
|
39
34
|
attachments: AttachmentsContext;
|
|
40
35
|
__registerFileInput: (ref: React.RefObject<HTMLInputElement | null>, open: () => void) => void;
|
|
41
36
|
}
|
|
42
|
-
interface ReferencedSourcesContext {
|
|
43
|
-
sources: Array<PromptInputReferencedSource & {
|
|
44
|
-
id: string;
|
|
45
|
-
}>;
|
|
46
|
-
add: (sources: PromptInputReferencedSource[] | PromptInputReferencedSource) => void;
|
|
47
|
-
remove: (id: string) => void;
|
|
48
|
-
clear: () => void;
|
|
49
|
-
}
|
|
50
37
|
declare function usePromptInputController(): PromptInputControllerProps;
|
|
51
38
|
declare function useProviderAttachments(): AttachmentsContext;
|
|
52
39
|
declare function usePromptInputAttachments(): AttachmentsContext;
|
|
53
|
-
declare function usePromptInputReferencedSources(): ReferencedSourcesContext;
|
|
54
40
|
interface PromptInputProviderProps extends React.PropsWithChildren {
|
|
55
41
|
initialInput?: string;
|
|
56
42
|
}
|
|
@@ -86,8 +72,8 @@ interface PromptInputProps extends Omit<React.FormHTMLAttributes<HTMLFormElement
|
|
|
86
72
|
*
|
|
87
73
|
* Use for assistant/chat submit forms. Do not use it as a generic textarea or
|
|
88
74
|
* non-chat form. Sigvelo changes: uses shared Menu, Select, Combobox, Tabs,
|
|
89
|
-
* Button, and Tooltip components; maps styles to CSS tokens; adds local
|
|
90
|
-
* attachment
|
|
75
|
+
* Button, and Tooltip components; maps styles to CSS tokens; and adds local
|
|
76
|
+
* attachment helpers.
|
|
91
77
|
*
|
|
92
78
|
* The form handles Enter-to-submit while multiline editing remains in the
|
|
93
79
|
* textarea. Attachment controls need accessible labels through their buttons
|
|
@@ -121,7 +107,6 @@ declare function PromptInput({
|
|
|
121
107
|
onError,
|
|
122
108
|
onSubmit,
|
|
123
109
|
children,
|
|
124
|
-
id,
|
|
125
110
|
ref,
|
|
126
111
|
...props
|
|
127
112
|
}: PromptInputProps & {
|
|
@@ -258,6 +243,7 @@ type PromptInputActionMenuContentProps = MenuContentProps;
|
|
|
258
243
|
declare function PromptInputActionMenuContent({
|
|
259
244
|
className,
|
|
260
245
|
children,
|
|
246
|
+
tabIndex,
|
|
261
247
|
...props
|
|
262
248
|
}: PromptInputActionMenuContentProps): React.JSX.Element;
|
|
263
249
|
type PromptInputActionMenuItemProps = MenuItemProps;
|
|
@@ -324,27 +310,6 @@ declare function PromptInputSubmit({
|
|
|
324
310
|
}: PromptInputSubmitProps & {
|
|
325
311
|
ref?: React.Ref<HTMLButtonElement>;
|
|
326
312
|
}): React.JSX.Element;
|
|
327
|
-
/**
|
|
328
|
-
* Resolve Think execution approvals that do not use the AI SDK
|
|
329
|
-
* `approval-requested` part: paused codemode executions and durable-pause
|
|
330
|
-
* approvals from `pendingApprovals()`. Wire to the Think agent's
|
|
331
|
-
* client-callable RPCs:
|
|
332
|
-
*
|
|
333
|
-
* ```tsx
|
|
334
|
-
* executionApprovals={{
|
|
335
|
-
* approve: (id) => agent.stub.approveExecution(id),
|
|
336
|
-
* reject: (id, reason) => agent.stub.rejectExecution(id, reason),
|
|
337
|
-
* }}
|
|
338
|
-
* ```
|
|
339
|
-
*
|
|
340
|
-
* On approve, upstream resumes or runs the parked execution and auto-continues
|
|
341
|
-
* the chat. Both RPCs are idempotent, so a stale click resolves to "already
|
|
342
|
-
* handled".
|
|
343
|
-
*/
|
|
344
|
-
interface ExecutionApprovals {
|
|
345
|
-
approve: (executionId: string) => unknown;
|
|
346
|
-
reject: (executionId: string, reason?: string) => unknown;
|
|
347
|
-
}
|
|
348
313
|
/** The id a response must carry: the approval id, or the paused run's executionId. */
|
|
349
314
|
declare function getApprovalRequestId(part: ToolUIPart | DynamicToolUIPart): string | undefined;
|
|
350
315
|
/** Component-local identity: paused executions can ask for multiple approvals. */
|
|
@@ -371,8 +336,10 @@ interface PromptInputApprovalProps extends Omit<React.HTMLAttributes<HTMLDivElem
|
|
|
371
336
|
approval?: PendingApproval;
|
|
372
337
|
/** Pass `addToolApprovalResponse` from `useAgentChat`/`useChat` directly. */
|
|
373
338
|
onRespond?: ChatAddToolApproveResponseFunction;
|
|
374
|
-
/**
|
|
375
|
-
|
|
339
|
+
/** Whole upstream Think stub used to resolve execution approvals instead of `onRespond`. */
|
|
340
|
+
thinkStub?: AgentStub<Think>;
|
|
341
|
+
/** Called after a Think approve/reject RPC settles, including when it rejects. */
|
|
342
|
+
onExecutionSettled?: () => void | Promise<void>;
|
|
376
343
|
/**
|
|
377
344
|
* Renders a Skip action that dismisses the confirmation without responding —
|
|
378
345
|
* the approval stays pending upstream.
|
|
@@ -394,7 +361,8 @@ declare function PromptInputApproval({
|
|
|
394
361
|
part,
|
|
395
362
|
approval: durableApproval,
|
|
396
363
|
onRespond,
|
|
397
|
-
|
|
364
|
+
thinkStub,
|
|
365
|
+
onExecutionSettled,
|
|
398
366
|
onSkip,
|
|
399
367
|
question,
|
|
400
368
|
count,
|
|
@@ -525,4 +493,4 @@ declare const PromptInputCommandItem: typeof ComboboxItem;
|
|
|
525
493
|
type PromptInputCommandSeparatorProps = React.ComponentPropsWithoutRef<typeof ComboboxSeparator>;
|
|
526
494
|
declare const PromptInputCommandSeparator: React.ForwardRefExoticComponent<Omit<import("@base-ui/react").SeparatorProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
527
495
|
//#endregion
|
|
528
|
-
export {
|
|
496
|
+
export { PromptInputMessage as $, PromptInputCommandEmptyProps as A, PromptInputToolsProps as At, PromptInputCommandSeparator as B, PromptInputBody as C, PromptInputTabLabelProps as Ct, PromptInputButtonTooltip as D, PromptInputTextarea as Dt, PromptInputButtonProps as E, PromptInputTabsListProps as Et, PromptInputCommandItem as F, getApprovalStateKey as Ft, PromptInputHeader as G, PromptInputControllerProps as H, PromptInputCommandItemProps as I, getPendingToolApprovals as It, PromptInputHoverCardContent as J, PromptInputHeaderProps as K, PromptInputCommandList as L, usePromptInputAttachments as Lt, PromptInputCommandGroupProps as M, TextInputContext as Mt, PromptInputCommandInput as N, TooltipSide as Nt, PromptInputCommand as O, PromptInputTextareaProps as Ot, PromptInputCommandInputProps as P, getApprovalRequestId as Pt, PromptInputHoverCardTriggerProps as Q, PromptInputCommandListProps as R, usePromptInputController as Rt, PromptInputAttachmentsProps as S, PromptInputTabLabel as St, PromptInputButton as T, PromptInputTabsList as Tt, PromptInputFooter as U, PromptInputCommandSeparatorProps as V, PromptInputFooterProps as W, PromptInputHoverCardProps as X, PromptInputHoverCardContentProps as Y, PromptInputHoverCardTrigger as Z, PromptInputApproval as _, PromptInputTab as _t, PromptInputActionAddAttachments as a, PromptInputSelect as at, PromptInputAttachmentProps as b, PromptInputTabItem as bt, PromptInputActionAddScreenshotProps as c, PromptInputSelectItem as ct, PromptInputActionMenuContentProps as d, PromptInputSelectTrigger as dt, PromptInputPermissionSelector as et, PromptInputActionMenuItem as f, PromptInputSelectTriggerProps as ft, PromptInputActionMenuTriggerProps as g, PromptInputSubmitProps as gt, PromptInputActionMenuTrigger as h, PromptInputSubmit as ht, PromptInput as i, PromptInputProviderProps as it, PromptInputCommandGroup as j, PromptInputTooltipConfig as jt, PromptInputCommandEmpty as k, PromptInputTools as kt, PromptInputActionMenu as l, PromptInputSelectItemProps as lt, PromptInputActionMenuProps as m, PromptInputSelectValueProps as mt, PendingToolApproval as n, PromptInputProps as nt, PromptInputActionAddAttachmentsProps as o, PromptInputSelectContent as ot, PromptInputActionMenuItemProps as p, PromptInputSelectValue as pt, PromptInputHoverCard as q, PermissionMode as r, PromptInputProvider as rt, PromptInputActionAddScreenshot as s, PromptInputSelectContentProps as st, AttachmentsContext as t, PromptInputPermissionSelectorProps as tt, PromptInputActionMenuContent as u, PromptInputSelectProps as ut, PromptInputApprovalProps as v, PromptInputTabBody as vt, PromptInputBodyProps as w, PromptInputTabProps as wt, PromptInputAttachments as x, PromptInputTabItemProps as xt, PromptInputAttachment as y, PromptInputTabBodyProps as yt, PromptInputCommandProps as z, useProviderAttachments as zt };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { AgentChat } from "./components/AgentChat.js";
|
|
2
|
+
import { ThinkChatContext, useThinkChatContext } from "./components/ThinkChatContext.js";
|
|
3
|
+
import { ThinkChatActivity, createThinkChatActivityRenderer, renderThinkChatActivityPart } from "./components/ThinkChatActivity.js";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useAgentChat } from "@cloudflare/think/react";
|
|
7
|
+
import { useAgent } from "agents/react";
|
|
8
|
+
//#region src/components/_internal/think-approvals.ts
|
|
9
|
+
/**
|
|
10
|
+
* Ambient approvals belong to their stub. An explicit different stub may only
|
|
11
|
+
* use approval state and settlement handlers supplied alongside that override.
|
|
12
|
+
*/
|
|
13
|
+
function resolveThinkApprovalProps(overrides, ambient) {
|
|
14
|
+
const inheritsAmbient = overrides.thinkStub === void 0 || overrides.thinkStub === ambient?.thinkStub;
|
|
15
|
+
return {
|
|
16
|
+
thinkStub: overrides.thinkStub ?? ambient?.thinkStub,
|
|
17
|
+
pendingApprovals: overrides.pendingApprovals ?? (inheritsAmbient ? ambient?.pendingApprovals : void 0),
|
|
18
|
+
onExecutionSettled: overrides.onExecutionSettled ?? (inheritsAmbient ? ambient?.onExecutionSettled : void 0)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/ThinkChat.tsx
|
|
23
|
+
function toAgentChatStatus(chat) {
|
|
24
|
+
if (chat.status === "submitted") return "submitted";
|
|
25
|
+
if (chat.isStreaming || chat.isRecovering) return "streaming";
|
|
26
|
+
return chat.status ?? "ready";
|
|
27
|
+
}
|
|
28
|
+
function useThinkPendingApprovals(stub, refreshKey) {
|
|
29
|
+
const requestIdRef = React.useRef(0);
|
|
30
|
+
const [state, setState] = React.useState(() => ({
|
|
31
|
+
source: stub,
|
|
32
|
+
pendingApprovals: []
|
|
33
|
+
}));
|
|
34
|
+
const refresh = React.useCallback(async () => {
|
|
35
|
+
const requestId = ++requestIdRef.current;
|
|
36
|
+
try {
|
|
37
|
+
const pendingApprovals = await stub.pendingApprovals();
|
|
38
|
+
if (requestId !== requestIdRef.current) return;
|
|
39
|
+
setState({
|
|
40
|
+
source: stub,
|
|
41
|
+
pendingApprovals
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
if (requestId !== requestIdRef.current) return;
|
|
45
|
+
setState({
|
|
46
|
+
source: stub,
|
|
47
|
+
pendingApprovals: []
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}, [stub]);
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
requestIdRef.current += 1;
|
|
53
|
+
setState((current) => current.source === stub ? current : {
|
|
54
|
+
source: stub,
|
|
55
|
+
pendingApprovals: []
|
|
56
|
+
});
|
|
57
|
+
refresh();
|
|
58
|
+
return () => {
|
|
59
|
+
requestIdRef.current += 1;
|
|
60
|
+
};
|
|
61
|
+
}, [
|
|
62
|
+
refresh,
|
|
63
|
+
refreshKey,
|
|
64
|
+
stub
|
|
65
|
+
]);
|
|
66
|
+
const pendingApprovals = state.source === stub ? state.pendingApprovals : [];
|
|
67
|
+
return React.useMemo(() => ({
|
|
68
|
+
pendingApprovals,
|
|
69
|
+
refreshPendingApprovals: refresh
|
|
70
|
+
}), [pendingApprovals, refresh]);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Chat UI for Cloudflare Think agents. Provide a `useAgentChat` value (or let
|
|
74
|
+
* `ThinkChat.Root` create one) and `ThinkChat.Messages` renders the message
|
|
75
|
+
* stream with agent work folded into collapsed Activity blocks.
|
|
76
|
+
*/
|
|
77
|
+
function ThinkChatProvider({ chat, children }) {
|
|
78
|
+
return /* @__PURE__ */ jsx(ThinkChatContext.Provider, {
|
|
79
|
+
value: chat,
|
|
80
|
+
children
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Batteries-included root: connects to the named Think agent (upstream's
|
|
85
|
+
* `useAgent` + `useAgentChat`) and provides the live chat to everything
|
|
86
|
+
* inside. If the app already owns the chat hook, use `ThinkChat.Provider`.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* <ThinkChat.Root agent="my-agent" name="session-1">
|
|
91
|
+
* <ThinkChat.Messages />
|
|
92
|
+
* </ThinkChat.Root>
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
function ThinkChatRoot({ agent: agentOption, name, children }) {
|
|
96
|
+
const agent = useAgent(typeof agentOption === "string" ? {
|
|
97
|
+
agent: agentOption,
|
|
98
|
+
name
|
|
99
|
+
} : {
|
|
100
|
+
...agentOption,
|
|
101
|
+
name: name ?? agentOption.name
|
|
102
|
+
});
|
|
103
|
+
const chat = useAgentChat({ agent });
|
|
104
|
+
const approvals = useThinkPendingApprovals(agent.stub, `${chat.messages.length}:${chat.status}`);
|
|
105
|
+
return /* @__PURE__ */ jsx(ThinkChatContext.Provider, {
|
|
106
|
+
value: chat,
|
|
107
|
+
children: /* @__PURE__ */ jsx(ThinkChatApprovalsContext.Provider, {
|
|
108
|
+
value: {
|
|
109
|
+
...approvals,
|
|
110
|
+
thinkStub: agent.stub
|
|
111
|
+
},
|
|
112
|
+
children
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const ThinkChatApprovalsContext = React.createContext(null);
|
|
117
|
+
/**
|
|
118
|
+
* The full conversation surface — message list plus composer — with the
|
|
119
|
+
* activity renderer as the default `renderPart`: runs of reasoning/tool parts
|
|
120
|
+
* fold into one collapsed Activity block with derived labels and per-tool
|
|
121
|
+
* panels. Extend for app-specific tools with `toolRenderers` (label/panel
|
|
122
|
+
* inside the log) or `excludeTools` + your own `renderPart` (standalone
|
|
123
|
+
* card) — see README "App-specific tools" and the Custom Tool Panel story.
|
|
124
|
+
*/
|
|
125
|
+
function ThinkChatMessages({ renderPart, excludeTools, toolRenderers, thinkStub, onExecutionSettled, pendingApprovals, notice, ...props }) {
|
|
126
|
+
const chat = useThinkChatContext("ThinkChat.Messages");
|
|
127
|
+
const approvals = React.useContext(ThinkChatApprovalsContext);
|
|
128
|
+
const status = toAgentChatStatus(chat);
|
|
129
|
+
const resolvedApprovals = resolveThinkApprovalProps({
|
|
130
|
+
thinkStub,
|
|
131
|
+
pendingApprovals,
|
|
132
|
+
onExecutionSettled
|
|
133
|
+
}, approvals && {
|
|
134
|
+
thinkStub: approvals.thinkStub,
|
|
135
|
+
pendingApprovals: approvals.pendingApprovals,
|
|
136
|
+
onExecutionSettled: approvals.refreshPendingApprovals
|
|
137
|
+
});
|
|
138
|
+
const defaultRenderPart = React.useMemo(() => createThinkChatActivityRenderer({
|
|
139
|
+
excludeTools,
|
|
140
|
+
toolRenderers
|
|
141
|
+
}), [excludeTools, toolRenderers]);
|
|
142
|
+
const connectionNotice = chat.isRecovering ? /* @__PURE__ */ jsx(Fragment, { children: "Reconnecting to the agent…" }) : chat.connectionError ? /* @__PURE__ */ jsxs("span", {
|
|
143
|
+
"data-tone": "danger",
|
|
144
|
+
children: ["Connection lost", chat.connectionError.reason ? ` — ${chat.connectionError.reason}` : ""]
|
|
145
|
+
}) : void 0;
|
|
146
|
+
return /* @__PURE__ */ jsx(AgentChat, {
|
|
147
|
+
...props,
|
|
148
|
+
renderPart: renderPart ?? defaultRenderPart,
|
|
149
|
+
messages: chat.messages,
|
|
150
|
+
status,
|
|
151
|
+
onStop: chat.stop,
|
|
152
|
+
onApprovalResponse: chat.addToolApprovalResponse,
|
|
153
|
+
thinkStub: resolvedApprovals.thinkStub,
|
|
154
|
+
onExecutionSettled: resolvedApprovals.onExecutionSettled,
|
|
155
|
+
pendingApprovals: resolvedApprovals.pendingApprovals,
|
|
156
|
+
notice: notice ?? connectionNotice,
|
|
157
|
+
onRegenerate: (messageId) => void chat.regenerate({ messageId }),
|
|
158
|
+
onSubmit: ({ text, files }) => {
|
|
159
|
+
const trimmed = text.trim();
|
|
160
|
+
if (trimmed || files.length) chat.sendMessage({
|
|
161
|
+
text: trimmed,
|
|
162
|
+
files
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The ambient chat value from `ThinkChat.Root`/`Provider` — for custom tool
|
|
169
|
+
* panels, cards, or composer actions that need `messages`, `status`, or
|
|
170
|
+
* `sendMessage`. Throws outside a provider.
|
|
171
|
+
*/
|
|
172
|
+
function useThinkChat() {
|
|
173
|
+
return useThinkChatContext("useThinkChat");
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Namespace entry point. `Root` + `Messages` is the standard surface;
|
|
177
|
+
* `Provider` + `useThinkChat` when the app owns the chat hook; `Activity`,
|
|
178
|
+
* `renderActivityPart`, and `createActivityRenderer` for custom layouts and
|
|
179
|
+
* app-specific tools.
|
|
180
|
+
*/
|
|
181
|
+
const ThinkChat = {
|
|
182
|
+
Provider: ThinkChatProvider,
|
|
183
|
+
Root: ThinkChatRoot,
|
|
184
|
+
Messages: ThinkChatMessages,
|
|
185
|
+
Activity: ThinkChatActivity,
|
|
186
|
+
renderActivityPart: renderThinkChatActivityPart,
|
|
187
|
+
createActivityRenderer: createThinkChatActivityRenderer
|
|
188
|
+
};
|
|
189
|
+
//#endregion
|
|
190
|
+
export { useThinkChat as a, ThinkChatRoot as i, ThinkChatMessages as n, useThinkPendingApprovals as o, ThinkChatProvider as r, resolveThinkApprovalProps as s, ThinkChat as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as AgentChatRenderPartContext, r as AgentChatProps } from "./AgentChat-
|
|
2
|
-
import { s as ThinkChatPart } from "./ThinkChatToolParts-
|
|
1
|
+
import { a as AgentChatRenderPartContext, r as AgentChatProps } from "./AgentChat-CRmsKg9B.js";
|
|
2
|
+
import { s as ThinkChatPart } from "./ThinkChatToolParts-Cv4o7j6F.js";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { DynamicToolUIPart, ToolUIPart, UIMessage } from "ai";
|
|
5
5
|
|
|
@@ -63,10 +63,10 @@ declare function ThinkChatActivity({
|
|
|
63
63
|
* state. Excluded tools split the run and return undefined so your own
|
|
64
64
|
* renderPart (or AgentChat's generic activity row) takes over for them.
|
|
65
65
|
*/
|
|
66
|
-
declare function createThinkChatActivityRenderer({
|
|
66
|
+
declare function createThinkChatActivityRenderer<MessageT extends UIMessage = UIMessage>({
|
|
67
67
|
excludeTools,
|
|
68
68
|
toolRenderers
|
|
69
|
-
}?: ThinkChatActivityRendererOptions): NonNullable<AgentChatProps["renderPart"]>;
|
|
69
|
+
}?: ThinkChatActivityRendererOptions): NonNullable<AgentChatProps<MessageT>["renderPart"]>;
|
|
70
70
|
/** Default activity renderer — `createThinkChatActivityRenderer()` with no overrides. */
|
|
71
71
|
declare const renderThinkChatActivityPart: (context: AgentChatRenderPartContext<UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>) => React.ReactNode | undefined;
|
|
72
72
|
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useAgentChat } from "@cloudflare/think/react";
|
|
3
|
+
import { UIMessage } from "ai";
|
|
4
|
+
|
|
5
|
+
//#region src/components/ThinkChatContext.d.ts
|
|
6
|
+
/** The complete upstream Think chat hook value, preserving app state and message extensions. */
|
|
7
|
+
type ThinkChatValue<State = unknown, MessageT extends UIMessage = UIMessage> = ReturnType<typeof useAgentChat<State, MessageT>>;
|
|
8
|
+
/**
|
|
9
|
+
* React contexts cannot bind provider-specific generics. Keep the stored value
|
|
10
|
+
* opaque and restore the complete upstream hook type through the typed accessors.
|
|
11
|
+
*/
|
|
12
|
+
declare const ThinkChatContext: React.Context<unknown>;
|
|
13
|
+
declare function useOptionalThinkChatContext<State = unknown, MessageT extends UIMessage = UIMessage>(): ThinkChatValue<State, MessageT> | null;
|
|
14
|
+
declare function useThinkChatContext<State = unknown, MessageT extends UIMessage = UIMessage>(component: string): ThinkChatValue<State, MessageT>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { useThinkChatContext as i, ThinkChatValue as n, useOptionalThinkChatContext as r, ThinkChatContext as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InferUITools, ToolUIPart, UIMessage } from "ai";
|
|
2
2
|
import { ProxyToolInput, ProxyToolOutput } from "@cloudflare/codemode";
|
|
3
3
|
import { QuickActionExtractInput, QuickActionPage, QuickActionScrapeInput, QuickActionToolName } from "@cloudflare/think/tools/browser";
|
|
4
|
-
import { FetchResult } from "@cloudflare/think/tools/fetch";
|
|
4
|
+
import { FetchResponseMode, FetchResult } from "@cloudflare/think/tools/fetch";
|
|
5
5
|
import { WorkspaceTools } from "@cloudflare/think/tools/workspace";
|
|
6
6
|
|
|
7
7
|
//#region src/components/ThinkChatToolParts.d.ts
|
|
@@ -39,11 +39,19 @@ type SkillUITools = {
|
|
|
39
39
|
};
|
|
40
40
|
type SkillToolPart = ToolUIPart<SkillUITools>;
|
|
41
41
|
declare function isSkillToolPart(part: ThinkChatPart): part is SkillToolPart;
|
|
42
|
+
type FetchToolInput = {
|
|
43
|
+
url: string;
|
|
44
|
+
path?: never;
|
|
45
|
+
response?: FetchResponseMode;
|
|
46
|
+
headers?: Record<string, string>;
|
|
47
|
+
} | {
|
|
48
|
+
path: string;
|
|
49
|
+
url?: never;
|
|
50
|
+
response?: FetchResponseMode;
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
};
|
|
42
53
|
type FetchToolPart = ToolUIPart<Record<string, {
|
|
43
|
-
input:
|
|
44
|
-
url?: string;
|
|
45
|
-
path?: string;
|
|
46
|
-
};
|
|
54
|
+
input: FetchToolInput;
|
|
47
55
|
output: FetchResult;
|
|
48
56
|
}>>;
|
|
49
57
|
declare function isFetchToolPart(part: ThinkChatPart): part is FetchToolPart;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as AgentChatRenderPartContext, i as AgentChatRenderMessageContext, n as AgentChatPart, r as AgentChatProps, t as AgentChat } from "../AgentChat-
|
|
1
|
+
import { a as AgentChatRenderPartContext, i as AgentChatRenderMessageContext, n as AgentChatPart, r as AgentChatProps, t as AgentChat } from "../AgentChat-CRmsKg9B.js";
|
|
2
2
|
export { AgentChat, AgentChatPart, AgentChatProps, AgentChatRenderMessageContext, AgentChatRenderPartContext };
|