@kuntur/a2a-carbon-chat-adapter 0.1.7 → 0.1.8
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/index.cjs +82 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -1
- package/dist/index.js.map +1 -1
- package/dist/styles/index.css +76 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1784,6 +1784,13 @@ function A2AChat({
|
|
|
1784
1784
|
const instanceRef = react.useRef(null);
|
|
1785
1785
|
const translatorRef = react.useRef(null);
|
|
1786
1786
|
const abortControllerRef = react.useRef(null);
|
|
1787
|
+
const [isViewOpen, setIsViewOpen] = react.useState(true);
|
|
1788
|
+
const [showExternalLauncher, setShowExternalLauncher] = react.useState(false);
|
|
1789
|
+
const [sidebarClosing, setSidebarClosing] = react.useState(false);
|
|
1790
|
+
const layoutRef = react.useRef(layout);
|
|
1791
|
+
react.useEffect(() => {
|
|
1792
|
+
layoutRef.current = layout;
|
|
1793
|
+
}, [layout]);
|
|
1787
1794
|
react.useEffect(() => {
|
|
1788
1795
|
if (typeof window !== "undefined") {
|
|
1789
1796
|
import('@carbon/ai-chat').then((mod) => {
|
|
@@ -1800,6 +1807,40 @@ function A2AChat({
|
|
|
1800
1807
|
react.useEffect(() => {
|
|
1801
1808
|
onConnectionChange?.(connectionState);
|
|
1802
1809
|
}, [connectionState, onConnectionChange]);
|
|
1810
|
+
const SIDEBAR_ANIMATION_MS = 250;
|
|
1811
|
+
const onViewChange = react.useCallback(
|
|
1812
|
+
(event) => {
|
|
1813
|
+
const currentLayout = layoutRef.current;
|
|
1814
|
+
setIsViewOpen(event.newViewState.mainWindow);
|
|
1815
|
+
if (currentLayout === "sidebar") {
|
|
1816
|
+
if (event.newViewState.mainWindow) {
|
|
1817
|
+
setShowExternalLauncher(false);
|
|
1818
|
+
setSidebarClosing(false);
|
|
1819
|
+
onOpen?.();
|
|
1820
|
+
} else {
|
|
1821
|
+
setSidebarClosing(false);
|
|
1822
|
+
setShowExternalLauncher(true);
|
|
1823
|
+
onClose?.();
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
},
|
|
1827
|
+
[onOpen, onClose]
|
|
1828
|
+
);
|
|
1829
|
+
const onViewPreChange = react.useCallback(
|
|
1830
|
+
async (event) => {
|
|
1831
|
+
if (layoutRef.current === "sidebar" && !event.newViewState.mainWindow) {
|
|
1832
|
+
setSidebarClosing(true);
|
|
1833
|
+
await new Promise((resolve) => setTimeout(resolve, SIDEBAR_ANIMATION_MS));
|
|
1834
|
+
}
|
|
1835
|
+
},
|
|
1836
|
+
[]
|
|
1837
|
+
);
|
|
1838
|
+
const handleOpenSidebar = react.useCallback(() => {
|
|
1839
|
+
const instance = instanceRef.current;
|
|
1840
|
+
if (instance?.actions?.changeView) {
|
|
1841
|
+
instance.actions.changeView("MAIN_WINDOW");
|
|
1842
|
+
}
|
|
1843
|
+
}, []);
|
|
1803
1844
|
const handleSendMessage = react.useCallback(
|
|
1804
1845
|
async (message) => {
|
|
1805
1846
|
if (!agent) {
|
|
@@ -1952,6 +1993,21 @@ function A2AChat({
|
|
|
1952
1993
|
instanceRef.current = instance;
|
|
1953
1994
|
console.log("[A2AChat] Chat instance ready");
|
|
1954
1995
|
}, []);
|
|
1996
|
+
const elementClassName = react.useMemo(() => {
|
|
1997
|
+
const classes = ["a2a-chat__element"];
|
|
1998
|
+
if (layout === "sidebar") {
|
|
1999
|
+
classes.push("a2a-chat__element--sidebar");
|
|
2000
|
+
if (sidebarClosing) {
|
|
2001
|
+
classes.push("a2a-chat__element--sidebar-closing");
|
|
2002
|
+
}
|
|
2003
|
+
} else if (layout === "fullscreen") {
|
|
2004
|
+
classes.push("a2a-chat__element--fullscreen");
|
|
2005
|
+
}
|
|
2006
|
+
if (!isViewOpen) {
|
|
2007
|
+
classes.push("cds-aichat--hidden");
|
|
2008
|
+
}
|
|
2009
|
+
return classes.join(" ");
|
|
2010
|
+
}, [layout, isViewOpen, sidebarClosing]);
|
|
1955
2011
|
if (!agent) {
|
|
1956
2012
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `a2a-chat a2a-chat--error ${className}`, children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "No agent configured. Provide `agent`, `agentId`, or `agentUrl` prop." }) });
|
|
1957
2013
|
}
|
|
@@ -2005,7 +2061,7 @@ function A2AChat({
|
|
|
2005
2061
|
ChatCustomElement,
|
|
2006
2062
|
{
|
|
2007
2063
|
...{
|
|
2008
|
-
className:
|
|
2064
|
+
className: elementClassName,
|
|
2009
2065
|
debug: false,
|
|
2010
2066
|
aiEnabled: true,
|
|
2011
2067
|
openChatByDefault: true,
|
|
@@ -2022,6 +2078,8 @@ function A2AChat({
|
|
|
2022
2078
|
showFrame: layout === "float",
|
|
2023
2079
|
showCloseAndRestartButton: layout !== "fullscreen"
|
|
2024
2080
|
},
|
|
2081
|
+
onViewChange,
|
|
2082
|
+
onViewPreChange,
|
|
2025
2083
|
onAfterRender: handleAfterRender,
|
|
2026
2084
|
renderUserDefinedResponse: renderCustomResponse,
|
|
2027
2085
|
messaging: {
|
|
@@ -2036,6 +2094,29 @@ function A2AChat({
|
|
|
2036
2094
|
}
|
|
2037
2095
|
}
|
|
2038
2096
|
),
|
|
2097
|
+
layout === "sidebar" && showExternalLauncher && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2098
|
+
"button",
|
|
2099
|
+
{
|
|
2100
|
+
className: "a2a-chat__external-launcher",
|
|
2101
|
+
onClick: handleOpenSidebar,
|
|
2102
|
+
"aria-label": "Open chat",
|
|
2103
|
+
title: "Open chat",
|
|
2104
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2105
|
+
"svg",
|
|
2106
|
+
{
|
|
2107
|
+
width: "24",
|
|
2108
|
+
height: "24",
|
|
2109
|
+
viewBox: "0 0 32 32",
|
|
2110
|
+
fill: "currentColor",
|
|
2111
|
+
"aria-hidden": "true",
|
|
2112
|
+
children: [
|
|
2113
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17.74 30L16 29l4-7h6a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h9v2H6a4 4 0 0 1-4-4V8a4 4 0 0 1 4-4h20a4 4 0 0 1 4 4v12a4 4 0 0 1-4 4h-4.84Z" }),
|
|
2114
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 10h16v2H8zM8 16h10v2H8z" })
|
|
2115
|
+
]
|
|
2116
|
+
}
|
|
2117
|
+
)
|
|
2118
|
+
}
|
|
2119
|
+
),
|
|
2039
2120
|
formOverlay
|
|
2040
2121
|
] });
|
|
2041
2122
|
}
|