@cntyclub/agent-react 0.13.0 → 0.14.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/dist/components/agent-panel.d.ts +7 -1
- package/dist/components/agent-panel.d.ts.map +1 -1
- package/dist/components/agent-widget.d.ts.map +1 -1
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +17 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/use-agent-chat.d.ts +3 -0
- package/dist/use-agent-chat.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -14,11 +14,17 @@ export interface AgentPanelProps {
|
|
|
14
14
|
onAlwaysApprove: (toolName: string) => void;
|
|
15
15
|
/** Message id to render a "New messages" divider before (arrived while closed). */
|
|
16
16
|
newMessageAnchorId?: string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Render the close control as a "collapse to the right" affordance (two right
|
|
19
|
+
* chevrons) instead of an ✕. Used by the docked presentation, where closing
|
|
20
|
+
* collapses the panel to the side rather than dismissing a dialog.
|
|
21
|
+
*/
|
|
22
|
+
collapseToSide?: boolean;
|
|
17
23
|
className?: string;
|
|
18
24
|
}
|
|
19
25
|
/**
|
|
20
26
|
* The chat surface shared by the popup panel and fullscreen Agent Mode.
|
|
21
27
|
* Header (title, history, new chat, expand/collapse, close) + messages + input.
|
|
22
28
|
*/
|
|
23
|
-
export declare function AgentPanel({ agentMode, canToggleAgentMode, chat, className, config, newMessageAnchorId, onAlwaysApprove, onClose, onToggleAgentMode, }: AgentPanelProps): React.JSX.Element;
|
|
29
|
+
export declare function AgentPanel({ agentMode, canToggleAgentMode, chat, className, collapseToSide, config, newMessageAnchorId, onAlwaysApprove, onClose, onToggleAgentMode, }: AgentPanelProps): React.JSX.Element;
|
|
24
30
|
//# sourceMappingURL=agent-panel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-panel.d.ts","sourceRoot":"","sources":["../../src/components/agent-panel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-panel.d.ts","sourceRoot":"","sources":["../../src/components/agent-panel.tsx"],"names":[],"mappings":"AAgCA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQ5C,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,cAAc,GAAG,gBAAgB,CAAC;IACxC,yCAAyC;IACzC,SAAS,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAC5D,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,iEAAiE;IACjE,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,mFAAmF;IACnF,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EACzB,SAAS,EACT,kBAAkB,EAClB,IAAI,EACJ,SAAS,EACT,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,eAAe,EACf,OAAO,EACP,iBAAiB,GAClB,EAAE,eAAe,qBAqVjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-widget.d.ts","sourceRoot":"","sources":["../../src/components/agent-widget.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,UAAU,CAAC;AAK1D,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,WAAW,CAAC;IACpB,wCAAwC;IACxC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CACtC;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,IAAI,EAAE,cAAc,EACpB,YAAyB,GAC1B,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"agent-widget.d.ts","sourceRoot":"","sources":["../../src/components/agent-widget.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,UAAU,CAAC;AAK1D,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,WAAW,CAAC;IACpB,wCAAwC;IACxC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CACtC;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,IAAI,EAAE,cAAc,EACpB,YAAyB,GAC1B,EAAE,gBAAgB,qBAiVlB"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cn, Button, Tooltip, TooltipTrigger, TooltipContent, ChatMessage, ChatMessageBubble, Markdown, Spinner, Checkbox, Collapsible, CollapsibleTrigger, ChatToolChip, CollapsiblePanel, ChatToolCard, ChatToolCardHeader, ChatToolCardActions, Group, Menu, MenuTrigger, MenuPopup, MenuItem, ChatHeader, ChatHeaderAvatar, ChatHeaderTitle, ChatHeaderActions, Chat, ChatEmptyState, ChatEmptyStateIcon, ChatEmptyStateTitle, ChatEmptyStateDescription, ChatSuggestions, ChatSuggestion, useMediaQuery, TooltipProvider, DataTablePaged } from '@cntyclub/ui-react';
|
|
2
|
-
import { XIcon, Trash2Icon, SquareIcon, PauseIcon, PlayIcon, CheckIcon, Loader2Icon, FileTextIcon, PaperclipIcon, MicIcon, ArrowUpIcon, CopyIcon, Maximize2Icon, ListChecksIcon, ChevronDownIcon, ShieldAlertIcon, CheckCheckIcon, UploadCloudIcon, HistoryIcon, SquarePenIcon, Minimize2Icon, SparklesIcon, DownloadIcon, CodeIcon } from 'lucide-react';
|
|
2
|
+
import { XIcon, Trash2Icon, SquareIcon, PauseIcon, PlayIcon, CheckIcon, Loader2Icon, FileTextIcon, PaperclipIcon, MicIcon, ArrowUpIcon, CopyIcon, Maximize2Icon, ListChecksIcon, ChevronDownIcon, ShieldAlertIcon, CheckCheckIcon, UploadCloudIcon, HistoryIcon, SquarePenIcon, Minimize2Icon, ChevronsRightIcon, SparklesIcon, DownloadIcon, CodeIcon } from 'lucide-react';
|
|
3
3
|
import * as React11 from 'react';
|
|
4
4
|
import { AnimatePresence, motion } from 'motion/react';
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
@@ -1494,6 +1494,7 @@ function AgentPanel({
|
|
|
1494
1494
|
canToggleAgentMode,
|
|
1495
1495
|
chat,
|
|
1496
1496
|
className,
|
|
1497
|
+
collapseToSide,
|
|
1497
1498
|
config,
|
|
1498
1499
|
newMessageAnchorId,
|
|
1499
1500
|
onAlwaysApprove,
|
|
@@ -1662,7 +1663,16 @@ function AgentPanel({
|
|
|
1662
1663
|
),
|
|
1663
1664
|
/* @__PURE__ */ jsx(TooltipContent, { children: agentMode ? "Exit Agent Mode" : "Agent Mode" })
|
|
1664
1665
|
] }) : null,
|
|
1665
|
-
/* @__PURE__ */ jsx(
|
|
1666
|
+
/* @__PURE__ */ jsx(
|
|
1667
|
+
Button,
|
|
1668
|
+
{
|
|
1669
|
+
"aria-label": collapseToSide ? "Collapse agent" : "Close",
|
|
1670
|
+
onClick: onClose,
|
|
1671
|
+
size: "icon-sm",
|
|
1672
|
+
variant: "ghost",
|
|
1673
|
+
children: collapseToSide ? /* @__PURE__ */ jsx(ChevronsRightIcon, {}) : /* @__PURE__ */ jsx(XIcon, {})
|
|
1674
|
+
}
|
|
1675
|
+
)
|
|
1666
1676
|
] })
|
|
1667
1677
|
] }),
|
|
1668
1678
|
view === "history" ? /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto p-2", children: chat.conversations.length === 0 ? /* @__PURE__ */ jsx("p", { className: "p-4 text-center text-muted-foreground text-sm", children: "No conversations yet." }) : chat.conversations.map((conversation) => /* @__PURE__ */ jsxs(
|
|
@@ -1828,6 +1838,7 @@ function useAgentChat(config) {
|
|
|
1828
1838
|
const client = React11.useMemo(() => new AgentApiClient(config), [config]);
|
|
1829
1839
|
const [agentInfo, setAgentInfo] = React11.useState(null);
|
|
1830
1840
|
const [conversationId, setConversationId] = React11.useState(null);
|
|
1841
|
+
const [conversationEpoch, setConversationEpoch] = React11.useState(0);
|
|
1831
1842
|
const [conversations, setConversations] = React11.useState([]);
|
|
1832
1843
|
const [messages, setMessages] = React11.useState([]);
|
|
1833
1844
|
const [pendingApprovals, setPendingApprovals] = React11.useState([]);
|
|
@@ -2007,6 +2018,7 @@ function useAgentChat(config) {
|
|
|
2007
2018
|
setMessages([]);
|
|
2008
2019
|
setPendingApprovals([]);
|
|
2009
2020
|
setError(null);
|
|
2021
|
+
setConversationEpoch((e) => e + 1);
|
|
2010
2022
|
}, []);
|
|
2011
2023
|
const refreshConversations = React11.useCallback(async () => {
|
|
2012
2024
|
try {
|
|
@@ -2026,6 +2038,7 @@ function useAgentChat(config) {
|
|
|
2026
2038
|
setConversationId(id);
|
|
2027
2039
|
setMessages(payload.messages ?? []);
|
|
2028
2040
|
setPendingApprovals(payload.pending_approvals ?? []);
|
|
2041
|
+
setConversationEpoch((e) => e + 1);
|
|
2029
2042
|
} catch (err) {
|
|
2030
2043
|
handleFailure(err);
|
|
2031
2044
|
}
|
|
@@ -2049,6 +2062,7 @@ function useAgentChat(config) {
|
|
|
2049
2062
|
agentInfo,
|
|
2050
2063
|
clearError,
|
|
2051
2064
|
conversationId,
|
|
2065
|
+
conversationEpoch,
|
|
2052
2066
|
conversations,
|
|
2053
2067
|
deleteConversation,
|
|
2054
2068
|
error,
|
|
@@ -2236,18 +2250,26 @@ function AgentWidget({
|
|
|
2236
2250
|
}
|
|
2237
2251
|
}, [messages, onWriteSuccess]);
|
|
2238
2252
|
const lastNavigatedMessageId = React11.useRef(null);
|
|
2253
|
+
const navEpochRef = React11.useRef(-1);
|
|
2239
2254
|
React11.useEffect(() => {
|
|
2240
2255
|
if (!open || fullscreen || !config.navigate || !config.pages?.length) return;
|
|
2241
2256
|
const toolMessages = messages.filter((message) => message.role === "tool");
|
|
2242
2257
|
const latest = toolMessages[toolMessages.length - 1];
|
|
2258
|
+
if (navEpochRef.current !== chat.conversationEpoch) {
|
|
2259
|
+
navEpochRef.current = chat.conversationEpoch;
|
|
2260
|
+
lastNavigatedMessageId.current = latest?.id ?? null;
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2243
2263
|
if (!latest || latest.id === lastNavigatedMessageId.current) return;
|
|
2244
2264
|
lastNavigatedMessageId.current = latest.id;
|
|
2245
2265
|
const mapping = config.pages.find((page) => page.tools.includes(latest.tool_name ?? ""));
|
|
2246
2266
|
if (!mapping) return;
|
|
2247
2267
|
const args = findToolArguments(messages, latest);
|
|
2248
2268
|
const path = mapping.buildRoute ? mapping.buildRoute(args) : mapping.route;
|
|
2249
|
-
if (path)
|
|
2250
|
-
|
|
2269
|
+
if (!path) return;
|
|
2270
|
+
const scrollTo = typeof mapping.scrollTo === "function" ? mapping.scrollTo(args) : mapping.scrollTo;
|
|
2271
|
+
config.navigate(path, { scrollTo: scrollTo ?? null });
|
|
2272
|
+
}, [chat.conversationEpoch, config, fullscreen, messages, open]);
|
|
2251
2273
|
const closePanel = React11.useCallback(() => {
|
|
2252
2274
|
setOpen(false);
|
|
2253
2275
|
setAgentMode(false);
|
|
@@ -2313,6 +2335,7 @@ function AgentWidget({
|
|
|
2313
2335
|
canToggleAgentMode: false,
|
|
2314
2336
|
chat,
|
|
2315
2337
|
className: "flex-1",
|
|
2338
|
+
collapseToSide: true,
|
|
2316
2339
|
config,
|
|
2317
2340
|
newMessageAnchorId: anchorId,
|
|
2318
2341
|
onAlwaysApprove: alwaysApprove.setAlwaysApprove,
|