@copilotkitnext/react 0.0.19-threads-and-attachements.1 → 0.0.20
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.d.mts +19 -196
- package/dist/index.d.ts +19 -196
- package/dist/index.js +220 -868
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +228 -874
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -54,7 +54,6 @@ __export(index_exports, {
|
|
|
54
54
|
CopilotPopupView: () => CopilotPopupView,
|
|
55
55
|
CopilotSidebar: () => CopilotSidebar,
|
|
56
56
|
CopilotSidebarView: () => CopilotSidebarView,
|
|
57
|
-
CopilotThreadList: () => CopilotThreadList,
|
|
58
57
|
WildcardToolCallRender: () => WildcardToolCallRender,
|
|
59
58
|
defineToolCallRenderer: () => defineToolCallRenderer,
|
|
60
59
|
useAgent: () => useAgent,
|
|
@@ -66,9 +65,7 @@ __export(index_exports, {
|
|
|
66
65
|
useHumanInTheLoop: () => useHumanInTheLoop,
|
|
67
66
|
useRenderCustomMessages: () => useRenderCustomMessages,
|
|
68
67
|
useRenderToolCall: () => useRenderToolCall,
|
|
69
|
-
useSuggestions: () => useSuggestions
|
|
70
|
-
useThreadSwitch: () => useThreadSwitch,
|
|
71
|
-
useThreads: () => useThreads
|
|
68
|
+
useSuggestions: () => useSuggestions
|
|
72
69
|
});
|
|
73
70
|
module.exports = __toCommonJS(index_exports);
|
|
74
71
|
|
|
@@ -114,21 +111,15 @@ var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, i
|
|
|
114
111
|
[labels, parentConfig?.labels]
|
|
115
112
|
);
|
|
116
113
|
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? import_shared.DEFAULT_AGENT_ID;
|
|
117
|
-
const
|
|
118
|
-
if (threadId)
|
|
119
|
-
|
|
114
|
+
const resolvedThreadId = (0, import_react.useMemo)(() => {
|
|
115
|
+
if (threadId) {
|
|
116
|
+
return threadId;
|
|
117
|
+
}
|
|
118
|
+
if (parentConfig?.threadId) {
|
|
119
|
+
return parentConfig.threadId;
|
|
120
|
+
}
|
|
120
121
|
return (0, import_shared.randomUUID)();
|
|
121
|
-
});
|
|
122
|
-
const resolvedThreadId = threadId ?? internalThreadId;
|
|
123
|
-
const handleSetThreadId = (0, import_react.useCallback)(
|
|
124
|
-
(newThreadId) => {
|
|
125
|
-
if (threadId === void 0) {
|
|
126
|
-
setInternalThreadId(newThreadId);
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
[threadId]
|
|
130
|
-
);
|
|
131
|
-
const resolvedSetThreadId = parentConfig?.setThreadId ?? handleSetThreadId;
|
|
122
|
+
}, [threadId, parentConfig?.threadId]);
|
|
132
123
|
const resolvedDefaultOpen = isModalDefaultOpen ?? parentConfig?.isModalDefaultOpen ?? true;
|
|
133
124
|
const [internalModalOpen, setInternalModalOpen] = (0, import_react.useState)(
|
|
134
125
|
parentConfig?.isModalOpen ?? resolvedDefaultOpen
|
|
@@ -140,7 +131,6 @@ var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, i
|
|
|
140
131
|
labels: mergedLabels,
|
|
141
132
|
agentId: resolvedAgentId,
|
|
142
133
|
threadId: resolvedThreadId,
|
|
143
|
-
setThreadId: resolvedSetThreadId,
|
|
144
134
|
isModalOpen: resolvedIsModalOpen,
|
|
145
135
|
setModalOpen: resolvedSetModalOpen,
|
|
146
136
|
isModalDefaultOpen: resolvedDefaultOpen
|
|
@@ -149,7 +139,6 @@ var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, i
|
|
|
149
139
|
mergedLabels,
|
|
150
140
|
resolvedAgentId,
|
|
151
141
|
resolvedThreadId,
|
|
152
|
-
resolvedSetThreadId,
|
|
153
142
|
resolvedIsModalOpen,
|
|
154
143
|
resolvedSetModalOpen,
|
|
155
144
|
resolvedDefaultOpen
|
|
@@ -858,7 +847,10 @@ function CopilotChatInput({
|
|
|
858
847
|
onChange: handleChange,
|
|
859
848
|
onKeyDown: handleKeyDown,
|
|
860
849
|
autoFocus,
|
|
861
|
-
className: (0, import_tailwind_merge3.twMerge)(
|
|
850
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
851
|
+
"w-full py-3",
|
|
852
|
+
isExpanded ? "px-5" : "pr-5"
|
|
853
|
+
)
|
|
862
854
|
});
|
|
863
855
|
const isProcessing = mode !== "transcribe" && isRunning;
|
|
864
856
|
const canSend = resolvedValue.trim().length > 0 && !!onSubmitMessage;
|
|
@@ -1099,10 +1091,10 @@ function CopilotChatInput({
|
|
|
1099
1091
|
if (!slashMenuVisible || slashHighlightIndex < 0) {
|
|
1100
1092
|
return;
|
|
1101
1093
|
}
|
|
1102
|
-
const active = slashMenuRef.current?.querySelector(
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1094
|
+
const active = slashMenuRef.current?.querySelector(
|
|
1095
|
+
`[data-slash-index="${slashHighlightIndex}"]`
|
|
1096
|
+
);
|
|
1097
|
+
active?.scrollIntoView({ block: "nearest" });
|
|
1106
1098
|
}, [slashMenuVisible, slashHighlightIndex]);
|
|
1107
1099
|
const slashMenu = slashMenuVisible ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1108
1100
|
"div",
|
|
@@ -1173,7 +1165,11 @@ function CopilotChatInput({
|
|
|
1173
1165
|
"div",
|
|
1174
1166
|
{
|
|
1175
1167
|
ref: addButtonContainerRef,
|
|
1176
|
-
className: (0, import_tailwind_merge3.twMerge)(
|
|
1168
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1169
|
+
"flex items-center",
|
|
1170
|
+
isExpanded ? "row-start-2" : "row-start-1",
|
|
1171
|
+
"col-start-1"
|
|
1172
|
+
),
|
|
1177
1173
|
children: BoundAddMenuButton
|
|
1178
1174
|
}
|
|
1179
1175
|
),
|
|
@@ -1350,9 +1346,7 @@ function CopilotChatInput({
|
|
|
1350
1346
|
if (!textarea) return;
|
|
1351
1347
|
const handleFocus = () => {
|
|
1352
1348
|
setTimeout(() => {
|
|
1353
|
-
|
|
1354
|
-
textarea.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
1355
|
-
}
|
|
1349
|
+
textarea.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
1356
1350
|
}, 300);
|
|
1357
1351
|
};
|
|
1358
1352
|
textarea.addEventListener("focus", handleFocus);
|
|
@@ -1394,7 +1388,7 @@ CopilotChatInput.AddMenuButton.displayName = "CopilotChatInput.AddMenuButton";
|
|
|
1394
1388
|
var CopilotChatInput_default = CopilotChatInput;
|
|
1395
1389
|
|
|
1396
1390
|
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
1397
|
-
var
|
|
1391
|
+
var import_react16 = require("react");
|
|
1398
1392
|
var import_lucide_react3 = require("lucide-react");
|
|
1399
1393
|
var import_tailwind_merge4 = require("tailwind-merge");
|
|
1400
1394
|
var import_katex_min = require("katex/dist/katex.min.css");
|
|
@@ -1451,15 +1445,12 @@ var CopilotKitCoreReact = class extends import_core.CopilotKitCore {
|
|
|
1451
1445
|
// src/components/CopilotKitInspector.tsx
|
|
1452
1446
|
var React4 = __toESM(require("react"));
|
|
1453
1447
|
var import_react5 = require("@lit-labs/react");
|
|
1454
|
-
var
|
|
1448
|
+
var import_web_inspector = require("@copilotkitnext/web-inspector");
|
|
1455
1449
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1456
|
-
|
|
1457
|
-
var defineWebInspector2 = WebInspectorModule.defineWebInspector;
|
|
1458
|
-
var WebInspectorElementClass = WebInspectorModule.WebInspectorElement;
|
|
1459
|
-
defineWebInspector2();
|
|
1450
|
+
(0, import_web_inspector.defineWebInspector)();
|
|
1460
1451
|
var CopilotKitInspectorBase = (0, import_react5.createComponent)({
|
|
1461
|
-
tagName:
|
|
1462
|
-
elementClass:
|
|
1452
|
+
tagName: import_web_inspector.WEB_INSPECTOR_TAG,
|
|
1453
|
+
elementClass: import_web_inspector.WebInspectorElement,
|
|
1463
1454
|
react: React4
|
|
1464
1455
|
});
|
|
1465
1456
|
var CopilotKitInspector = React4.forwardRef(
|
|
@@ -1485,10 +1476,7 @@ CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
|
1485
1476
|
// src/providers/CopilotKitProvider.tsx
|
|
1486
1477
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1487
1478
|
var CopilotKitContext = (0, import_react6.createContext)({
|
|
1488
|
-
copilotkit: null
|
|
1489
|
-
setResourceId: () => {
|
|
1490
|
-
throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1491
|
-
}
|
|
1479
|
+
copilotkit: null
|
|
1492
1480
|
});
|
|
1493
1481
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
1494
1482
|
const empty = (0, import_react6.useMemo)(() => [], []);
|
|
@@ -1506,7 +1494,6 @@ var CopilotKitProvider = ({
|
|
|
1506
1494
|
runtimeUrl,
|
|
1507
1495
|
headers = {},
|
|
1508
1496
|
properties = {},
|
|
1509
|
-
resourceId,
|
|
1510
1497
|
agents__unsafe_dev_only: agents = {},
|
|
1511
1498
|
renderToolCalls,
|
|
1512
1499
|
renderCustomMessages,
|
|
@@ -1614,7 +1601,6 @@ var CopilotKitProvider = ({
|
|
|
1614
1601
|
runtimeUrl,
|
|
1615
1602
|
headers,
|
|
1616
1603
|
properties,
|
|
1617
|
-
resourceId,
|
|
1618
1604
|
agents__unsafe_dev_only: agents,
|
|
1619
1605
|
tools: allTools,
|
|
1620
1606
|
renderToolCalls: allRenderToolCalls,
|
|
@@ -1637,36 +1623,13 @@ var CopilotKitProvider = ({
|
|
|
1637
1623
|
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
1638
1624
|
copilotkit.setHeaders(headers);
|
|
1639
1625
|
copilotkit.setProperties(properties);
|
|
1640
|
-
copilotkit.setResourceId(resourceId);
|
|
1641
1626
|
copilotkit.setAgents__unsafe_dev_only(agents);
|
|
1642
|
-
}, [runtimeUrl, headers, properties,
|
|
1643
|
-
(0, import_react6.useEffect)(() => {
|
|
1644
|
-
if (typeof window === "undefined") {
|
|
1645
|
-
return;
|
|
1646
|
-
}
|
|
1647
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
1648
|
-
if (isProduction && !resourceId) {
|
|
1649
|
-
console.error(
|
|
1650
|
-
"CopilotKit Security Warning: No resourceId set in production.\nAll threads will be globally accessible. Set the resourceId prop:\n<CopilotKitProvider resourceId={userId}>\nLearn more: https://docs.copilotkit.ai/security/resource-scoping"
|
|
1651
|
-
);
|
|
1652
|
-
} else if (!isProduction && !resourceId) {
|
|
1653
|
-
console.warn(
|
|
1654
|
-
"CopilotKit: No resourceId set. All threads are globally accessible.\nThis is fine for development, but add resourceId for production:\n<CopilotKitProvider resourceId={userId}>"
|
|
1655
|
-
);
|
|
1656
|
-
}
|
|
1657
|
-
}, [resourceId]);
|
|
1658
|
-
const setResourceId = (0, import_react6.useCallback)(
|
|
1659
|
-
(newResourceId) => {
|
|
1660
|
-
copilotkit.setResourceId(newResourceId);
|
|
1661
|
-
},
|
|
1662
|
-
[copilotkit]
|
|
1663
|
-
);
|
|
1627
|
+
}, [runtimeUrl, headers, properties, agents]);
|
|
1664
1628
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1665
1629
|
CopilotKitContext.Provider,
|
|
1666
1630
|
{
|
|
1667
1631
|
value: {
|
|
1668
|
-
copilotkit
|
|
1669
|
-
setResourceId
|
|
1632
|
+
copilotkit
|
|
1670
1633
|
},
|
|
1671
1634
|
children: [
|
|
1672
1635
|
children,
|
|
@@ -1685,9 +1648,6 @@ var useCopilotKit = () => {
|
|
|
1685
1648
|
const unsubscribe = context.copilotkit.subscribe({
|
|
1686
1649
|
onRuntimeConnectionStatusChanged: () => {
|
|
1687
1650
|
forceUpdate();
|
|
1688
|
-
},
|
|
1689
|
-
onResourceIdChanged: () => {
|
|
1690
|
-
forceUpdate();
|
|
1691
1651
|
}
|
|
1692
1652
|
});
|
|
1693
1653
|
return () => {
|
|
@@ -1816,38 +1776,33 @@ function useRenderCustomMessages() {
|
|
|
1816
1776
|
if (!agent) {
|
|
1817
1777
|
throw new Error("Agent not found");
|
|
1818
1778
|
}
|
|
1819
|
-
const messagesIdsInRun =
|
|
1779
|
+
const messagesIdsInRun = agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === runId).map((msg) => msg.id);
|
|
1820
1780
|
const messageIndex = agent.messages.findIndex((msg) => msg.id === message.id) ?? 0;
|
|
1821
|
-
const messageIndexInRun = Math.
|
|
1781
|
+
const messageIndexInRun = Math.min(messagesIdsInRun.indexOf(message.id), 0);
|
|
1822
1782
|
const numberOfMessagesInRun = messagesIdsInRun.length;
|
|
1823
|
-
const stateSnapshot =
|
|
1783
|
+
const stateSnapshot = copilotkit.getStateByRun(agentId, threadId, runId);
|
|
1824
1784
|
let result = null;
|
|
1825
1785
|
for (const renderer of customMessageRenderers) {
|
|
1826
1786
|
if (!renderer.render) {
|
|
1827
1787
|
continue;
|
|
1828
1788
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
break;
|
|
1847
|
-
}
|
|
1848
|
-
} catch (error) {
|
|
1849
|
-
console.error("Error rendering custom message:", error);
|
|
1850
|
-
continue;
|
|
1789
|
+
const Component = renderer.render;
|
|
1790
|
+
result = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1791
|
+
Component,
|
|
1792
|
+
{
|
|
1793
|
+
message,
|
|
1794
|
+
position,
|
|
1795
|
+
runId,
|
|
1796
|
+
messageIndex,
|
|
1797
|
+
messageIndexInRun,
|
|
1798
|
+
numberOfMessagesInRun,
|
|
1799
|
+
agentId,
|
|
1800
|
+
stateSnapshot
|
|
1801
|
+
},
|
|
1802
|
+
`${runId}-${message.id}-${position}`
|
|
1803
|
+
);
|
|
1804
|
+
if (result) {
|
|
1805
|
+
break;
|
|
1851
1806
|
}
|
|
1852
1807
|
}
|
|
1853
1808
|
return result;
|
|
@@ -1976,10 +1931,18 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
1976
1931
|
agentId ??= import_shared4.DEFAULT_AGENT_ID;
|
|
1977
1932
|
const { copilotkit } = useCopilotKit();
|
|
1978
1933
|
const [, forceUpdate] = (0, import_react11.useReducer)((x) => x + 1, 0);
|
|
1979
|
-
const updateFlags = (0, import_react11.useMemo)(
|
|
1934
|
+
const updateFlags = (0, import_react11.useMemo)(
|
|
1935
|
+
() => updates ?? ALL_UPDATES,
|
|
1936
|
+
[JSON.stringify(updates)]
|
|
1937
|
+
);
|
|
1980
1938
|
const agent = (0, import_react11.useMemo)(() => {
|
|
1981
1939
|
return copilotkit.getAgent(agentId);
|
|
1982
|
-
}, [
|
|
1940
|
+
}, [
|
|
1941
|
+
agentId,
|
|
1942
|
+
copilotkit.agents,
|
|
1943
|
+
copilotkit.runtimeConnectionStatus,
|
|
1944
|
+
copilotkit
|
|
1945
|
+
]);
|
|
1983
1946
|
(0, import_react11.useEffect)(() => {
|
|
1984
1947
|
if (!agent) {
|
|
1985
1948
|
return;
|
|
@@ -2215,137 +2178,8 @@ function normalizeStaticSuggestions(suggestions) {
|
|
|
2215
2178
|
}));
|
|
2216
2179
|
}
|
|
2217
2180
|
|
|
2218
|
-
// src/hooks/use-threads.tsx
|
|
2219
|
-
var import_react15 = require("react");
|
|
2220
|
-
function useThreads(options = {}) {
|
|
2221
|
-
const { limit = 50, autoFetch = true } = options;
|
|
2222
|
-
const { copilotkit: core } = useCopilotKit();
|
|
2223
|
-
const chatConfig = useCopilotChatConfiguration();
|
|
2224
|
-
const [threads, setThreads] = (0, import_react15.useState)([]);
|
|
2225
|
-
const [total, setTotal] = (0, import_react15.useState)(0);
|
|
2226
|
-
const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
|
|
2227
|
-
const [error, setError] = (0, import_react15.useState)(null);
|
|
2228
|
-
const fetchThreads = (0, import_react15.useCallback)(
|
|
2229
|
-
async (offset = 0) => {
|
|
2230
|
-
if (!core) {
|
|
2231
|
-
return;
|
|
2232
|
-
}
|
|
2233
|
-
setIsLoading(true);
|
|
2234
|
-
setError(null);
|
|
2235
|
-
try {
|
|
2236
|
-
const result = await core.listThreads({ limit, offset });
|
|
2237
|
-
setThreads(result.threads);
|
|
2238
|
-
setTotal(result.total);
|
|
2239
|
-
} catch (err) {
|
|
2240
|
-
const error2 = err instanceof Error ? err : new Error("Failed to fetch threads");
|
|
2241
|
-
setError(error2);
|
|
2242
|
-
console.error("Error fetching threads:", error2);
|
|
2243
|
-
} finally {
|
|
2244
|
-
setIsLoading(false);
|
|
2245
|
-
}
|
|
2246
|
-
},
|
|
2247
|
-
[core, limit]
|
|
2248
|
-
);
|
|
2249
|
-
const getThreadMetadata = (0, import_react15.useCallback)(
|
|
2250
|
-
async (threadId) => {
|
|
2251
|
-
if (!core) {
|
|
2252
|
-
throw new Error("CopilotKit core not initialized");
|
|
2253
|
-
}
|
|
2254
|
-
try {
|
|
2255
|
-
return await core.getThreadMetadata(threadId);
|
|
2256
|
-
} catch (err) {
|
|
2257
|
-
const error2 = err instanceof Error ? err : new Error("Failed to get thread metadata");
|
|
2258
|
-
console.error("Error getting thread metadata:", error2);
|
|
2259
|
-
throw error2;
|
|
2260
|
-
}
|
|
2261
|
-
},
|
|
2262
|
-
[core]
|
|
2263
|
-
);
|
|
2264
|
-
const refresh = (0, import_react15.useCallback)(() => fetchThreads(0), [fetchThreads]);
|
|
2265
|
-
const addOptimisticThread = (0, import_react15.useCallback)((threadId) => {
|
|
2266
|
-
const newThread = {
|
|
2267
|
-
threadId,
|
|
2268
|
-
createdAt: Date.now(),
|
|
2269
|
-
lastActivityAt: Date.now(),
|
|
2270
|
-
isRunning: false,
|
|
2271
|
-
messageCount: 0,
|
|
2272
|
-
firstMessage: void 0
|
|
2273
|
-
};
|
|
2274
|
-
setThreads((prev) => [newThread, ...prev]);
|
|
2275
|
-
setTotal((prev) => prev + 1);
|
|
2276
|
-
}, []);
|
|
2277
|
-
const deleteThread = (0, import_react15.useCallback)(
|
|
2278
|
-
async (threadId) => {
|
|
2279
|
-
if (!core) {
|
|
2280
|
-
throw new Error("CopilotKit core not initialized");
|
|
2281
|
-
}
|
|
2282
|
-
const originalThreads = threads;
|
|
2283
|
-
const originalTotal = total;
|
|
2284
|
-
const threadIndex = threads.findIndex((t) => t.threadId === threadId);
|
|
2285
|
-
const deletedThread = threadIndex >= 0 ? threads[threadIndex] : null;
|
|
2286
|
-
if (threadIndex >= 0) {
|
|
2287
|
-
setThreads((prev) => prev.filter((t) => t.threadId !== threadId));
|
|
2288
|
-
setTotal((prev) => prev - 1);
|
|
2289
|
-
}
|
|
2290
|
-
try {
|
|
2291
|
-
await core.deleteThread(threadId);
|
|
2292
|
-
await fetchThreads();
|
|
2293
|
-
} catch (err) {
|
|
2294
|
-
if (deletedThread && threadIndex >= 0) {
|
|
2295
|
-
setThreads((prev) => {
|
|
2296
|
-
const newThreads = [...prev];
|
|
2297
|
-
newThreads.splice(threadIndex, 0, deletedThread);
|
|
2298
|
-
return newThreads;
|
|
2299
|
-
});
|
|
2300
|
-
setTotal(originalTotal);
|
|
2301
|
-
} else {
|
|
2302
|
-
setThreads(originalThreads);
|
|
2303
|
-
setTotal(originalTotal);
|
|
2304
|
-
}
|
|
2305
|
-
const error2 = err instanceof Error ? err : new Error("Failed to delete thread");
|
|
2306
|
-
console.error("Error deleting thread:", error2);
|
|
2307
|
-
throw error2;
|
|
2308
|
-
}
|
|
2309
|
-
},
|
|
2310
|
-
[core, fetchThreads, threads, total]
|
|
2311
|
-
);
|
|
2312
|
-
(0, import_react15.useEffect)(() => {
|
|
2313
|
-
if (autoFetch && core) {
|
|
2314
|
-
void fetchThreads();
|
|
2315
|
-
}
|
|
2316
|
-
}, [autoFetch, core, fetchThreads]);
|
|
2317
|
-
return {
|
|
2318
|
-
threads,
|
|
2319
|
-
total,
|
|
2320
|
-
isLoading,
|
|
2321
|
-
error,
|
|
2322
|
-
fetchThreads,
|
|
2323
|
-
getThreadMetadata,
|
|
2324
|
-
refresh,
|
|
2325
|
-
addOptimisticThread,
|
|
2326
|
-
deleteThread,
|
|
2327
|
-
currentThreadId: chatConfig?.threadId
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
|
|
2331
|
-
// src/hooks/use-thread-switcher.tsx
|
|
2332
|
-
var import_react16 = require("react");
|
|
2333
|
-
function useThreadSwitch() {
|
|
2334
|
-
const config = useCopilotChatConfiguration();
|
|
2335
|
-
const switchThread = (0, import_react16.useCallback)(
|
|
2336
|
-
(threadId) => {
|
|
2337
|
-
config?.setThreadId?.(threadId);
|
|
2338
|
-
},
|
|
2339
|
-
[config]
|
|
2340
|
-
);
|
|
2341
|
-
return {
|
|
2342
|
-
switchThread,
|
|
2343
|
-
currentThreadId: config?.threadId
|
|
2344
|
-
};
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
2181
|
// src/components/chat/CopilotChatToolCallsView.tsx
|
|
2348
|
-
var
|
|
2182
|
+
var import_react15 = __toESM(require("react"));
|
|
2349
2183
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2350
2184
|
function CopilotChatToolCallsView({
|
|
2351
2185
|
message,
|
|
@@ -2355,14 +2189,14 @@ function CopilotChatToolCallsView({
|
|
|
2355
2189
|
if (!message.toolCalls || message.toolCalls.length === 0) {
|
|
2356
2190
|
return null;
|
|
2357
2191
|
}
|
|
2358
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: message.toolCalls.map((toolCall
|
|
2192
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: message.toolCalls.map((toolCall) => {
|
|
2359
2193
|
const toolMessage = messages.find(
|
|
2360
2194
|
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
2361
2195
|
);
|
|
2362
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2196
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react15.default.Fragment, { children: renderToolCall({
|
|
2363
2197
|
toolCall,
|
|
2364
2198
|
toolMessage
|
|
2365
|
-
}) },
|
|
2199
|
+
}) }, toolCall.id);
|
|
2366
2200
|
}) });
|
|
2367
2201
|
}
|
|
2368
2202
|
var CopilotChatToolCallsView_default = CopilotChatToolCallsView;
|
|
@@ -2537,7 +2371,7 @@ function CopilotChatAssistantMessage({
|
|
|
2537
2371
|
CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2538
2372
|
const config = useCopilotChatConfiguration();
|
|
2539
2373
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2540
|
-
const [copied, setCopied] = (0,
|
|
2374
|
+
const [copied, setCopied] = (0, import_react16.useState)(false);
|
|
2541
2375
|
const handleClick = (event) => {
|
|
2542
2376
|
setCopied(true);
|
|
2543
2377
|
setTimeout(() => setCopied(false), 2e3);
|
|
@@ -2615,10 +2449,9 @@ CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistant
|
|
|
2615
2449
|
var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
|
|
2616
2450
|
|
|
2617
2451
|
// src/components/chat/CopilotChatUserMessage.tsx
|
|
2618
|
-
var
|
|
2452
|
+
var import_react17 = require("react");
|
|
2619
2453
|
var import_lucide_react4 = require("lucide-react");
|
|
2620
2454
|
var import_tailwind_merge5 = require("tailwind-merge");
|
|
2621
|
-
var import_shared7 = require("@copilotkitnext/shared");
|
|
2622
2455
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2623
2456
|
function CopilotChatUserMessage({
|
|
2624
2457
|
message,
|
|
@@ -2640,8 +2473,7 @@ function CopilotChatUserMessage({
|
|
|
2640
2473
|
messageRenderer,
|
|
2641
2474
|
CopilotChatUserMessage.MessageRenderer,
|
|
2642
2475
|
{
|
|
2643
|
-
content:
|
|
2644
|
-
contents: (0, import_shared7.normalizeUserMessageContents)(message.content)
|
|
2476
|
+
content: message.content || ""
|
|
2645
2477
|
}
|
|
2646
2478
|
);
|
|
2647
2479
|
const BoundCopyButton = renderSlot(
|
|
@@ -2649,10 +2481,9 @@ function CopilotChatUserMessage({
|
|
|
2649
2481
|
CopilotChatUserMessage.CopyButton,
|
|
2650
2482
|
{
|
|
2651
2483
|
onClick: async () => {
|
|
2652
|
-
|
|
2653
|
-
if (textContent.trim().length > 0) {
|
|
2484
|
+
if (message.content) {
|
|
2654
2485
|
try {
|
|
2655
|
-
await navigator.clipboard.writeText(
|
|
2486
|
+
await navigator.clipboard.writeText(message.content);
|
|
2656
2487
|
} catch (err) {
|
|
2657
2488
|
console.error("Failed to copy message:", err);
|
|
2658
2489
|
}
|
|
@@ -2721,33 +2552,16 @@ function CopilotChatUserMessage({
|
|
|
2721
2552
|
children
|
|
2722
2553
|
}
|
|
2723
2554
|
);
|
|
2724
|
-
CopilotChatUserMessage2.MessageRenderer = ({
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
className: (0, import_tailwind_merge5.twMerge)(
|
|
2735
|
-
"prose dark:prose-invert bg-muted relative max-w-[80%] rounded-[18px] px-4 py-1.5 data-[multiline]:py-3 inline-block whitespace-pre-wrap",
|
|
2736
|
-
className
|
|
2737
|
-
),
|
|
2738
|
-
children: [
|
|
2739
|
-
hasText && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: content }),
|
|
2740
|
-
attachments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: (0, import_tailwind_merge5.twMerge)(hasText ? "mt-3 flex flex-col gap-2" : "flex flex-col gap-2"), children: attachments.map((attachment, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2741
|
-
AttachmentPreview,
|
|
2742
|
-
{
|
|
2743
|
-
attachment
|
|
2744
|
-
},
|
|
2745
|
-
attachment.id ?? attachment.url ?? attachment.filename ?? index
|
|
2746
|
-
)) })
|
|
2747
|
-
]
|
|
2748
|
-
}
|
|
2749
|
-
);
|
|
2750
|
-
};
|
|
2555
|
+
CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2556
|
+
"div",
|
|
2557
|
+
{
|
|
2558
|
+
className: (0, import_tailwind_merge5.twMerge)(
|
|
2559
|
+
"prose dark:prose-invert bg-muted relative max-w-[80%] rounded-[18px] px-4 py-1.5 data-[multiline]:py-3 inline-block whitespace-pre-wrap",
|
|
2560
|
+
className
|
|
2561
|
+
),
|
|
2562
|
+
children: content
|
|
2563
|
+
}
|
|
2564
|
+
);
|
|
2751
2565
|
CopilotChatUserMessage2.Toolbar = ({
|
|
2752
2566
|
className,
|
|
2753
2567
|
...props
|
|
@@ -2780,7 +2594,7 @@ function CopilotChatUserMessage({
|
|
|
2780
2594
|
CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2781
2595
|
const config = useCopilotChatConfiguration();
|
|
2782
2596
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2783
|
-
const [copied, setCopied] = (0,
|
|
2597
|
+
const [copied, setCopied] = (0, import_react17.useState)(false);
|
|
2784
2598
|
const handleClick = (event) => {
|
|
2785
2599
|
setCopied(true);
|
|
2786
2600
|
setTimeout(() => setCopied(false), 2e3);
|
|
@@ -2864,47 +2678,6 @@ function CopilotChatUserMessage({
|
|
|
2864
2678
|
] });
|
|
2865
2679
|
};
|
|
2866
2680
|
})(CopilotChatUserMessage || (CopilotChatUserMessage = {}));
|
|
2867
|
-
var AttachmentPreview = ({ attachment }) => {
|
|
2868
|
-
const source = resolveAttachmentSource(attachment);
|
|
2869
|
-
const isImage = attachment.mimeType.startsWith("image/");
|
|
2870
|
-
const label = attachment.filename ?? attachment.id ?? attachment.mimeType;
|
|
2871
|
-
if (isImage && source) {
|
|
2872
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("figure", { className: "flex flex-col gap-1", children: [
|
|
2873
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2874
|
-
"img",
|
|
2875
|
-
{
|
|
2876
|
-
src: source,
|
|
2877
|
-
alt: label ?? "User provided image",
|
|
2878
|
-
className: "max-h-64 rounded-lg border border-border object-contain"
|
|
2879
|
-
}
|
|
2880
|
-
),
|
|
2881
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("figcaption", { className: "text-xs text-muted-foreground", children: label ?? "Image attachment" })
|
|
2882
|
-
] });
|
|
2883
|
-
}
|
|
2884
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "rounded-md border border-dashed border-border bg-muted/70 px-3 py-2 text-xs text-muted-foreground", children: [
|
|
2885
|
-
label ?? "Attachment",
|
|
2886
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "block text-[10px] uppercase tracking-wide text-muted-foreground/70", children: attachment.mimeType }),
|
|
2887
|
-
source && !isImage ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2888
|
-
"a",
|
|
2889
|
-
{
|
|
2890
|
-
href: source,
|
|
2891
|
-
target: "_blank",
|
|
2892
|
-
rel: "noreferrer",
|
|
2893
|
-
className: "mt-1 block text-xs text-primary underline",
|
|
2894
|
-
children: "Open"
|
|
2895
|
-
}
|
|
2896
|
-
) : null
|
|
2897
|
-
] });
|
|
2898
|
-
};
|
|
2899
|
-
function resolveAttachmentSource(attachment) {
|
|
2900
|
-
if (attachment.url) {
|
|
2901
|
-
return attachment.url;
|
|
2902
|
-
}
|
|
2903
|
-
if (attachment.data) {
|
|
2904
|
-
return `data:${attachment.mimeType};base64,${attachment.data}`;
|
|
2905
|
-
}
|
|
2906
|
-
return null;
|
|
2907
|
-
}
|
|
2908
2681
|
CopilotChatUserMessage.Container.displayName = "CopilotChatUserMessage.Container";
|
|
2909
2682
|
CopilotChatUserMessage.MessageRenderer.displayName = "CopilotChatUserMessage.MessageRenderer";
|
|
2910
2683
|
CopilotChatUserMessage.Toolbar.displayName = "CopilotChatUserMessage.Toolbar";
|
|
@@ -2915,12 +2688,12 @@ CopilotChatUserMessage.BranchNavigation.displayName = "CopilotChatUserMessage.Br
|
|
|
2915
2688
|
var CopilotChatUserMessage_default = CopilotChatUserMessage;
|
|
2916
2689
|
|
|
2917
2690
|
// src/components/chat/CopilotChatSuggestionPill.tsx
|
|
2918
|
-
var
|
|
2691
|
+
var import_react18 = __toESM(require("react"));
|
|
2919
2692
|
var import_lucide_react5 = require("lucide-react");
|
|
2920
2693
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2921
2694
|
var baseClasses = "group inline-flex h-7 sm:h-8 items-center gap-1 sm:gap-1.5 rounded-full border border-border/60 bg-background px-2.5 sm:px-3 text-[11px] sm:text-xs leading-none text-foreground transition-colors cursor-pointer hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:text-muted-foreground disabled:hover:bg-background disabled:hover:text-muted-foreground pointer-events-auto";
|
|
2922
2695
|
var labelClasses = "whitespace-nowrap font-medium leading-none";
|
|
2923
|
-
var CopilotChatSuggestionPill =
|
|
2696
|
+
var CopilotChatSuggestionPill = import_react18.default.forwardRef(function CopilotChatSuggestionPill2({ className, children, icon, isLoading, type, ...props }, ref) {
|
|
2924
2697
|
const showIcon = !isLoading && icon;
|
|
2925
2698
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
2926
2699
|
"button",
|
|
@@ -2943,9 +2716,9 @@ CopilotChatSuggestionPill.displayName = "CopilotChatSuggestionPill";
|
|
|
2943
2716
|
var CopilotChatSuggestionPill_default = CopilotChatSuggestionPill;
|
|
2944
2717
|
|
|
2945
2718
|
// src/components/chat/CopilotChatSuggestionView.tsx
|
|
2946
|
-
var
|
|
2719
|
+
var import_react19 = __toESM(require("react"));
|
|
2947
2720
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2948
|
-
var DefaultContainer =
|
|
2721
|
+
var DefaultContainer = import_react19.default.forwardRef(function DefaultContainer2({ className, ...props }, ref) {
|
|
2949
2722
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
2950
2723
|
"div",
|
|
2951
2724
|
{
|
|
@@ -2958,7 +2731,7 @@ var DefaultContainer = import_react21.default.forwardRef(function DefaultContain
|
|
|
2958
2731
|
}
|
|
2959
2732
|
);
|
|
2960
2733
|
});
|
|
2961
|
-
var CopilotChatSuggestionView =
|
|
2734
|
+
var CopilotChatSuggestionView = import_react19.default.forwardRef(function CopilotChatSuggestionView2({
|
|
2962
2735
|
suggestions,
|
|
2963
2736
|
onSelectSuggestion,
|
|
2964
2737
|
loadingIndexes,
|
|
@@ -2968,7 +2741,7 @@ var CopilotChatSuggestionView = import_react21.default.forwardRef(function Copil
|
|
|
2968
2741
|
children,
|
|
2969
2742
|
...restProps
|
|
2970
2743
|
}, ref) {
|
|
2971
|
-
const loadingSet =
|
|
2744
|
+
const loadingSet = import_react19.default.useMemo(() => {
|
|
2972
2745
|
if (!loadingIndexes || loadingIndexes.length === 0) {
|
|
2973
2746
|
return /* @__PURE__ */ new Set();
|
|
2974
2747
|
}
|
|
@@ -2987,11 +2760,11 @@ var CopilotChatSuggestionView = import_react21.default.forwardRef(function Copil
|
|
|
2987
2760
|
type: "button",
|
|
2988
2761
|
onClick: () => onSelectSuggestion?.(suggestion, index)
|
|
2989
2762
|
});
|
|
2990
|
-
return
|
|
2763
|
+
return import_react19.default.cloneElement(pill, {
|
|
2991
2764
|
key: `${suggestion.title}-${index}`
|
|
2992
2765
|
});
|
|
2993
2766
|
});
|
|
2994
|
-
const boundContainer =
|
|
2767
|
+
const boundContainer = import_react19.default.cloneElement(
|
|
2995
2768
|
ContainerElement,
|
|
2996
2769
|
void 0,
|
|
2997
2770
|
suggestionElements
|
|
@@ -3094,21 +2867,21 @@ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
|
3094
2867
|
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
3095
2868
|
|
|
3096
2869
|
// src/components/chat/CopilotChatView.tsx
|
|
3097
|
-
var
|
|
2870
|
+
var import_react21 = __toESM(require("react"));
|
|
3098
2871
|
var import_tailwind_merge7 = require("tailwind-merge");
|
|
3099
2872
|
var import_use_stick_to_bottom = require("use-stick-to-bottom");
|
|
3100
2873
|
var import_lucide_react6 = require("lucide-react");
|
|
3101
2874
|
|
|
3102
2875
|
// src/hooks/use-keyboard-height.tsx
|
|
3103
|
-
var
|
|
2876
|
+
var import_react20 = require("react");
|
|
3104
2877
|
function useKeyboardHeight() {
|
|
3105
|
-
const [keyboardState, setKeyboardState] = (0,
|
|
2878
|
+
const [keyboardState, setKeyboardState] = (0, import_react20.useState)({
|
|
3106
2879
|
isKeyboardOpen: false,
|
|
3107
2880
|
keyboardHeight: 0,
|
|
3108
2881
|
availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
3109
2882
|
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
3110
2883
|
});
|
|
3111
|
-
(0,
|
|
2884
|
+
(0, import_react20.useEffect)(() => {
|
|
3112
2885
|
if (typeof window === "undefined") {
|
|
3113
2886
|
return;
|
|
3114
2887
|
}
|
|
@@ -3152,10 +2925,8 @@ function CopilotChatView({
|
|
|
3152
2925
|
suggestionView,
|
|
3153
2926
|
messages = [],
|
|
3154
2927
|
autoScroll = true,
|
|
3155
|
-
scrollBehavior = "auto",
|
|
3156
2928
|
inputProps,
|
|
3157
2929
|
isRunning = false,
|
|
3158
|
-
isSwitchingThread = false,
|
|
3159
2930
|
suggestions,
|
|
3160
2931
|
suggestionLoadingIndexes,
|
|
3161
2932
|
onSelectSuggestion,
|
|
@@ -3163,12 +2934,12 @@ function CopilotChatView({
|
|
|
3163
2934
|
className,
|
|
3164
2935
|
...props
|
|
3165
2936
|
}) {
|
|
3166
|
-
const inputContainerRef = (0,
|
|
3167
|
-
const [inputContainerHeight, setInputContainerHeight] = (0,
|
|
3168
|
-
const [isResizing, setIsResizing] = (0,
|
|
3169
|
-
const resizeTimeoutRef = (0,
|
|
2937
|
+
const inputContainerRef = (0, import_react21.useRef)(null);
|
|
2938
|
+
const [inputContainerHeight, setInputContainerHeight] = (0, import_react21.useState)(0);
|
|
2939
|
+
const [isResizing, setIsResizing] = (0, import_react21.useState)(false);
|
|
2940
|
+
const resizeTimeoutRef = (0, import_react21.useRef)(null);
|
|
3170
2941
|
const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
|
|
3171
|
-
(0,
|
|
2942
|
+
(0, import_react21.useEffect)(() => {
|
|
3172
2943
|
const element = inputContainerRef.current;
|
|
3173
2944
|
if (!element) return;
|
|
3174
2945
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -3217,8 +2988,6 @@ function CopilotChatView({
|
|
|
3217
2988
|
const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
|
|
3218
2989
|
const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
|
|
3219
2990
|
autoScroll,
|
|
3220
|
-
scrollBehavior,
|
|
3221
|
-
isSwitchingThread,
|
|
3222
2991
|
scrollToBottomButton,
|
|
3223
2992
|
inputContainerHeight,
|
|
3224
2993
|
isResizing,
|
|
@@ -3277,21 +3046,19 @@ function CopilotChatView({
|
|
|
3277
3046
|
CopilotChatView2.ScrollView = ({
|
|
3278
3047
|
children,
|
|
3279
3048
|
autoScroll = true,
|
|
3280
|
-
scrollBehavior = "auto",
|
|
3281
|
-
isSwitchingThread = false,
|
|
3282
3049
|
scrollToBottomButton,
|
|
3283
3050
|
inputContainerHeight = 0,
|
|
3284
3051
|
isResizing = false,
|
|
3285
3052
|
className,
|
|
3286
3053
|
...props
|
|
3287
3054
|
}) => {
|
|
3288
|
-
const [hasMounted, setHasMounted] = (0,
|
|
3055
|
+
const [hasMounted, setHasMounted] = (0, import_react21.useState)(false);
|
|
3289
3056
|
const { scrollRef, contentRef, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottom)();
|
|
3290
|
-
const [showScrollButton, setShowScrollButton] = (0,
|
|
3291
|
-
(0,
|
|
3057
|
+
const [showScrollButton, setShowScrollButton] = (0, import_react21.useState)(false);
|
|
3058
|
+
(0, import_react21.useEffect)(() => {
|
|
3292
3059
|
setHasMounted(true);
|
|
3293
3060
|
}, []);
|
|
3294
|
-
(0,
|
|
3061
|
+
(0, import_react21.useEffect)(() => {
|
|
3295
3062
|
if (autoScroll) return;
|
|
3296
3063
|
const scrollElement = scrollRef.current;
|
|
3297
3064
|
if (!scrollElement) return;
|
|
@@ -3339,14 +3106,12 @@ function CopilotChatView({
|
|
|
3339
3106
|
}
|
|
3340
3107
|
);
|
|
3341
3108
|
}
|
|
3342
|
-
const initial = scrollBehavior === "auto" ? "instant" : scrollBehavior;
|
|
3343
|
-
const resize = scrollBehavior === "instant" ? "instant" : scrollBehavior === "auto" && isSwitchingThread ? "instant" : "smooth";
|
|
3344
3109
|
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3345
3110
|
import_use_stick_to_bottom.StickToBottom,
|
|
3346
3111
|
{
|
|
3347
3112
|
className: cn("h-full max-h-full flex flex-col min-h-0 relative", className),
|
|
3348
|
-
resize,
|
|
3349
|
-
initial,
|
|
3113
|
+
resize: "smooth",
|
|
3114
|
+
initial: "smooth",
|
|
3350
3115
|
...props,
|
|
3351
3116
|
children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3352
3117
|
ScrollContent,
|
|
@@ -3393,7 +3158,7 @@ function CopilotChatView({
|
|
|
3393
3158
|
...props
|
|
3394
3159
|
}
|
|
3395
3160
|
);
|
|
3396
|
-
CopilotChatView2.InputContainer =
|
|
3161
|
+
CopilotChatView2.InputContainer = import_react21.default.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3397
3162
|
"div",
|
|
3398
3163
|
{
|
|
3399
3164
|
ref,
|
|
@@ -3424,95 +3189,20 @@ function CopilotChatView({
|
|
|
3424
3189
|
var CopilotChatView_default = CopilotChatView;
|
|
3425
3190
|
|
|
3426
3191
|
// src/components/chat/CopilotChat.tsx
|
|
3427
|
-
var
|
|
3428
|
-
var
|
|
3192
|
+
var import_shared7 = require("@copilotkitnext/shared");
|
|
3193
|
+
var import_react22 = require("react");
|
|
3429
3194
|
var import_ts_deepmerge = require("ts-deepmerge");
|
|
3195
|
+
var import_client = require("@ag-ui/client");
|
|
3430
3196
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
3431
3197
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
|
|
3432
3198
|
const existingConfig = useCopilotChatConfiguration();
|
|
3433
|
-
const
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
agentId,
|
|
3439
|
-
threadId,
|
|
3440
|
-
labels,
|
|
3441
|
-
isModalDefaultOpen,
|
|
3442
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CopilotChat, { chatView, ...props })
|
|
3443
|
-
}
|
|
3444
|
-
);
|
|
3445
|
-
}
|
|
3446
|
-
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? import_shared8.DEFAULT_AGENT_ID;
|
|
3447
|
-
const resolvedThreadId = threadId ?? existingConfig?.threadId;
|
|
3199
|
+
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? import_shared7.DEFAULT_AGENT_ID;
|
|
3200
|
+
const resolvedThreadId = (0, import_react22.useMemo)(
|
|
3201
|
+
() => threadId ?? existingConfig?.threadId ?? (0, import_shared7.randomUUID)(),
|
|
3202
|
+
[threadId, existingConfig?.threadId]
|
|
3203
|
+
);
|
|
3448
3204
|
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
3449
3205
|
const { copilotkit } = useCopilotKit();
|
|
3450
|
-
const [isSwitchingThread, setIsSwitchingThread] = (0, import_react24.useState)(false);
|
|
3451
|
-
const [threadSwitchError, setThreadSwitchError] = (0, import_react24.useState)(null);
|
|
3452
|
-
const previousThreadIdRef = (0, import_react24.useRef)(void 0);
|
|
3453
|
-
const abortControllerRef = (0, import_react24.useRef)(null);
|
|
3454
|
-
(0, import_react24.useEffect)(() => {
|
|
3455
|
-
if (!agent || !resolvedThreadId) return;
|
|
3456
|
-
if (previousThreadIdRef.current === resolvedThreadId) return;
|
|
3457
|
-
if (abortControllerRef.current) {
|
|
3458
|
-
abortControllerRef.current.abort();
|
|
3459
|
-
}
|
|
3460
|
-
const abortController = new AbortController();
|
|
3461
|
-
abortControllerRef.current = abortController;
|
|
3462
|
-
const switchThread = async () => {
|
|
3463
|
-
setIsSwitchingThread(true);
|
|
3464
|
-
setThreadSwitchError(null);
|
|
3465
|
-
try {
|
|
3466
|
-
if (abortController.signal.aborted) return;
|
|
3467
|
-
if (previousThreadIdRef.current) {
|
|
3468
|
-
try {
|
|
3469
|
-
await copilotkit.disconnectAgent({ agent });
|
|
3470
|
-
} catch (disconnectErr) {
|
|
3471
|
-
console.warn("Error during disconnect, continuing with thread switch:", disconnectErr);
|
|
3472
|
-
}
|
|
3473
|
-
}
|
|
3474
|
-
if (abortController.signal.aborted) {
|
|
3475
|
-
previousThreadIdRef.current = void 0;
|
|
3476
|
-
return;
|
|
3477
|
-
}
|
|
3478
|
-
agent.messages = [];
|
|
3479
|
-
const subscribers = agent.subscribers || [];
|
|
3480
|
-
subscribers.forEach((subscriber) => {
|
|
3481
|
-
if (subscriber.onMessagesChanged) {
|
|
3482
|
-
subscriber.onMessagesChanged({
|
|
3483
|
-
messages: agent.messages,
|
|
3484
|
-
state: agent.state,
|
|
3485
|
-
agent
|
|
3486
|
-
});
|
|
3487
|
-
}
|
|
3488
|
-
});
|
|
3489
|
-
if (abortController.signal.aborted) {
|
|
3490
|
-
previousThreadIdRef.current = void 0;
|
|
3491
|
-
return;
|
|
3492
|
-
}
|
|
3493
|
-
await copilotkit.connectAgent({ agent, threadId: resolvedThreadId });
|
|
3494
|
-
if (!abortController.signal.aborted) {
|
|
3495
|
-
previousThreadIdRef.current = resolvedThreadId;
|
|
3496
|
-
}
|
|
3497
|
-
} catch (err) {
|
|
3498
|
-
if (abortController.signal.aborted) {
|
|
3499
|
-
previousThreadIdRef.current = void 0;
|
|
3500
|
-
return;
|
|
3501
|
-
}
|
|
3502
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
3503
|
-
setThreadSwitchError(error);
|
|
3504
|
-
console.error("Failed to switch thread:", error);
|
|
3505
|
-
} finally {
|
|
3506
|
-
if (!abortController.signal.aborted) {
|
|
3507
|
-
setIsSwitchingThread(false);
|
|
3508
|
-
}
|
|
3509
|
-
}
|
|
3510
|
-
};
|
|
3511
|
-
void switchThread();
|
|
3512
|
-
return () => {
|
|
3513
|
-
abortController.abort();
|
|
3514
|
-
};
|
|
3515
|
-
}, [agent, resolvedThreadId, copilotkit]);
|
|
3516
3206
|
const { suggestions: autoSuggestions } = useSuggestions({ agentId: resolvedAgentId });
|
|
3517
3207
|
const {
|
|
3518
3208
|
inputProps: providedInputProps,
|
|
@@ -3520,10 +3210,28 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3520
3210
|
suggestionView: providedSuggestionView,
|
|
3521
3211
|
...restProps
|
|
3522
3212
|
} = props;
|
|
3523
|
-
|
|
3213
|
+
(0, import_react22.useEffect)(() => {
|
|
3214
|
+
const connect = async (agent2) => {
|
|
3215
|
+
try {
|
|
3216
|
+
await copilotkit.connectAgent({ agent: agent2 });
|
|
3217
|
+
} catch (error) {
|
|
3218
|
+
if (error instanceof import_client.AGUIConnectNotImplementedError) {
|
|
3219
|
+
} else {
|
|
3220
|
+
throw error;
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
};
|
|
3224
|
+
if (agent) {
|
|
3225
|
+
agent.threadId = resolvedThreadId;
|
|
3226
|
+
connect(agent);
|
|
3227
|
+
}
|
|
3228
|
+
return () => {
|
|
3229
|
+
};
|
|
3230
|
+
}, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
|
|
3231
|
+
const onSubmitInput = (0, import_react22.useCallback)(
|
|
3524
3232
|
async (value) => {
|
|
3525
3233
|
agent?.addMessage({
|
|
3526
|
-
id: (0,
|
|
3234
|
+
id: (0, import_shared7.randomUUID)(),
|
|
3527
3235
|
role: "user",
|
|
3528
3236
|
content: value
|
|
3529
3237
|
});
|
|
@@ -3537,13 +3245,13 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3537
3245
|
},
|
|
3538
3246
|
[agent, copilotkit]
|
|
3539
3247
|
);
|
|
3540
|
-
const handleSelectSuggestion = (0,
|
|
3248
|
+
const handleSelectSuggestion = (0, import_react22.useCallback)(
|
|
3541
3249
|
async (suggestion) => {
|
|
3542
3250
|
if (!agent) {
|
|
3543
3251
|
return;
|
|
3544
3252
|
}
|
|
3545
3253
|
agent.addMessage({
|
|
3546
|
-
id: (0,
|
|
3254
|
+
id: (0, import_shared7.randomUUID)(),
|
|
3547
3255
|
role: "user",
|
|
3548
3256
|
content: suggestion.message
|
|
3549
3257
|
});
|
|
@@ -3555,7 +3263,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3555
3263
|
},
|
|
3556
3264
|
[agent, copilotkit]
|
|
3557
3265
|
);
|
|
3558
|
-
const stopCurrentRun = (0,
|
|
3266
|
+
const stopCurrentRun = (0, import_react22.useCallback)(() => {
|
|
3559
3267
|
if (!agent) {
|
|
3560
3268
|
return;
|
|
3561
3269
|
}
|
|
@@ -3597,27 +3305,24 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3597
3305
|
messages: agent?.messages ?? [],
|
|
3598
3306
|
inputProps: finalInputProps
|
|
3599
3307
|
});
|
|
3600
|
-
const
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
"data-thread-switch-error": threadSwitchError ? threadSwitchError.message : void 0
|
|
3612
|
-
};
|
|
3613
|
-
return renderSlot(chatView, CopilotChatView, finalPropsWithThreadState);
|
|
3308
|
+
const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
|
|
3309
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3310
|
+
CopilotChatConfigurationProvider,
|
|
3311
|
+
{
|
|
3312
|
+
agentId: resolvedAgentId,
|
|
3313
|
+
threadId: resolvedThreadId,
|
|
3314
|
+
labels,
|
|
3315
|
+
isModalDefaultOpen,
|
|
3316
|
+
children: RenderedChatView
|
|
3317
|
+
}
|
|
3318
|
+
);
|
|
3614
3319
|
}
|
|
3615
3320
|
((CopilotChat2) => {
|
|
3616
3321
|
CopilotChat2.View = CopilotChatView;
|
|
3617
3322
|
})(CopilotChat || (CopilotChat = {}));
|
|
3618
3323
|
|
|
3619
3324
|
// src/components/chat/CopilotChatToggleButton.tsx
|
|
3620
|
-
var
|
|
3325
|
+
var import_react23 = __toESM(require("react"));
|
|
3621
3326
|
var import_lucide_react7 = require("lucide-react");
|
|
3622
3327
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3623
3328
|
var DefaultOpenIcon = ({
|
|
@@ -3644,11 +3349,11 @@ var BUTTON_BASE_CLASSES = cn(
|
|
|
3644
3349
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
3645
3350
|
"disabled:pointer-events-none disabled:opacity-60"
|
|
3646
3351
|
);
|
|
3647
|
-
var CopilotChatToggleButton =
|
|
3352
|
+
var CopilotChatToggleButton = import_react23.default.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
|
|
3648
3353
|
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
3649
3354
|
const configuration = useCopilotChatConfiguration();
|
|
3650
3355
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3651
|
-
const [fallbackOpen, setFallbackOpen] = (0,
|
|
3356
|
+
const [fallbackOpen, setFallbackOpen] = (0, import_react23.useState)(false);
|
|
3652
3357
|
const isOpen = configuration?.isModalOpen ?? fallbackOpen;
|
|
3653
3358
|
const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
|
|
3654
3359
|
const handleClick = (event) => {
|
|
@@ -3734,21 +3439,16 @@ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
|
3734
3439
|
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
3735
3440
|
|
|
3736
3441
|
// src/components/chat/CopilotSidebarView.tsx
|
|
3737
|
-
var
|
|
3442
|
+
var import_react25 = require("react");
|
|
3738
3443
|
|
|
3739
3444
|
// src/components/chat/CopilotModalHeader.tsx
|
|
3740
|
-
var
|
|
3445
|
+
var import_react24 = require("react");
|
|
3741
3446
|
var import_lucide_react8 = require("lucide-react");
|
|
3742
3447
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3743
3448
|
function CopilotModalHeader({
|
|
3744
3449
|
title,
|
|
3745
3450
|
titleContent,
|
|
3746
3451
|
closeButton,
|
|
3747
|
-
leftContent,
|
|
3748
|
-
onThreadListClick,
|
|
3749
|
-
showThreadListButton = false,
|
|
3750
|
-
onNewThreadClick,
|
|
3751
|
-
showNewThreadButton = false,
|
|
3752
3452
|
children,
|
|
3753
3453
|
className,
|
|
3754
3454
|
...rest
|
|
@@ -3756,7 +3456,7 @@ function CopilotModalHeader({
|
|
|
3756
3456
|
const configuration = useCopilotChatConfiguration();
|
|
3757
3457
|
const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
|
|
3758
3458
|
const resolvedTitle = title ?? fallbackTitle;
|
|
3759
|
-
const handleClose = (0,
|
|
3459
|
+
const handleClose = (0, import_react24.useCallback)(() => {
|
|
3760
3460
|
configuration?.setModalOpen(false);
|
|
3761
3461
|
}, [configuration]);
|
|
3762
3462
|
const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, {
|
|
@@ -3765,17 +3465,10 @@ function CopilotModalHeader({
|
|
|
3765
3465
|
const BoundCloseButton = renderSlot(closeButton, CopilotModalHeader.CloseButton, {
|
|
3766
3466
|
onClick: handleClose
|
|
3767
3467
|
});
|
|
3768
|
-
const BoundLeftContent = renderSlot(leftContent, CopilotModalHeader.LeftContent, {
|
|
3769
|
-
onThreadListClick,
|
|
3770
|
-
showThreadListButton,
|
|
3771
|
-
onNewThreadClick,
|
|
3772
|
-
showNewThreadButton
|
|
3773
|
-
});
|
|
3774
3468
|
if (children) {
|
|
3775
3469
|
return children({
|
|
3776
3470
|
titleContent: BoundTitle,
|
|
3777
3471
|
closeButton: BoundCloseButton,
|
|
3778
|
-
leftContent: BoundLeftContent,
|
|
3779
3472
|
title: resolvedTitle,
|
|
3780
3473
|
...rest
|
|
3781
3474
|
});
|
|
@@ -3791,7 +3484,7 @@ function CopilotModalHeader({
|
|
|
3791
3484
|
),
|
|
3792
3485
|
...rest,
|
|
3793
3486
|
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex w-full items-center gap-2", children: [
|
|
3794
|
-
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex
|
|
3487
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex-1", "aria-hidden": "true" }),
|
|
3795
3488
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex flex-1 justify-center text-center", children: BoundTitle }),
|
|
3796
3489
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex flex-1 justify-end", children: BoundCloseButton })
|
|
3797
3490
|
] })
|
|
@@ -3828,281 +3521,19 @@ CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
|
3828
3521
|
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react8.X, { className: "h-4 w-4", "aria-hidden": "true" })
|
|
3829
3522
|
}
|
|
3830
3523
|
);
|
|
3831
|
-
CopilotModalHeader2.LeftContent = ({
|
|
3832
|
-
onThreadListClick,
|
|
3833
|
-
showThreadListButton,
|
|
3834
|
-
onNewThreadClick,
|
|
3835
|
-
showNewThreadButton,
|
|
3836
|
-
className,
|
|
3837
|
-
children
|
|
3838
|
-
}) => {
|
|
3839
|
-
if (children) {
|
|
3840
|
-
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className, children });
|
|
3841
|
-
}
|
|
3842
|
-
const hasAnyButton = showNewThreadButton && onNewThreadClick || showThreadListButton && onThreadListClick;
|
|
3843
|
-
if (!hasAnyButton) {
|
|
3844
|
-
return null;
|
|
3845
|
-
}
|
|
3846
|
-
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: cn("flex items-center gap-1", className), children: [
|
|
3847
|
-
showNewThreadButton && onNewThreadClick && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
3848
|
-
"button",
|
|
3849
|
-
{
|
|
3850
|
-
type: "button",
|
|
3851
|
-
onClick: onNewThreadClick,
|
|
3852
|
-
className: cn(
|
|
3853
|
-
"inline-flex size-8 items-center justify-center rounded-full text-muted-foreground transition cursor-pointer",
|
|
3854
|
-
"hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
3855
|
-
),
|
|
3856
|
-
"aria-label": "New thread",
|
|
3857
|
-
title: "New thread",
|
|
3858
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react8.SquarePen, { className: "h-4 w-4", "aria-hidden": "true" })
|
|
3859
|
-
}
|
|
3860
|
-
),
|
|
3861
|
-
showThreadListButton && onThreadListClick && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
3862
|
-
"button",
|
|
3863
|
-
{
|
|
3864
|
-
type: "button",
|
|
3865
|
-
onClick: onThreadListClick,
|
|
3866
|
-
className: cn(
|
|
3867
|
-
"inline-flex size-8 items-center justify-center rounded-full text-muted-foreground transition cursor-pointer",
|
|
3868
|
-
"hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
3869
|
-
),
|
|
3870
|
-
"aria-label": "Show threads",
|
|
3871
|
-
title: "Show threads",
|
|
3872
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react8.List, { className: "h-4 w-4", "aria-hidden": "true" })
|
|
3873
|
-
}
|
|
3874
|
-
)
|
|
3875
|
-
] });
|
|
3876
|
-
};
|
|
3877
3524
|
})(CopilotModalHeader || (CopilotModalHeader = {}));
|
|
3878
3525
|
CopilotModalHeader.Title.displayName = "CopilotModalHeader.Title";
|
|
3879
3526
|
CopilotModalHeader.CloseButton.displayName = "CopilotModalHeader.CloseButton";
|
|
3880
|
-
CopilotModalHeader.LeftContent.displayName = "CopilotModalHeader.LeftContent";
|
|
3881
|
-
|
|
3882
|
-
// src/components/threads/CopilotThreadList.tsx
|
|
3883
|
-
var import_react27 = require("react");
|
|
3884
|
-
var import_lucide_react9 = require("lucide-react");
|
|
3885
|
-
var import_shared9 = require("@copilotkitnext/shared");
|
|
3886
|
-
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
3887
|
-
function CopilotThreadListInner({
|
|
3888
|
-
limit = 50,
|
|
3889
|
-
onThreadSelect,
|
|
3890
|
-
className,
|
|
3891
|
-
threadItem,
|
|
3892
|
-
newThreadButton,
|
|
3893
|
-
container,
|
|
3894
|
-
refreshInterval = 2e3,
|
|
3895
|
-
disableAutoRefresh = false
|
|
3896
|
-
}) {
|
|
3897
|
-
const config = useCopilotChatConfiguration();
|
|
3898
|
-
const { threads, isLoading, error, fetchThreads, addOptimisticThread, refresh, currentThreadId, deleteThread } = useThreads({
|
|
3899
|
-
limit
|
|
3900
|
-
});
|
|
3901
|
-
const attemptedFetchRef = (0, import_react27.useRef)(/* @__PURE__ */ new Set());
|
|
3902
|
-
const handleNewThread = (0, import_react27.useCallback)(() => {
|
|
3903
|
-
const newThreadId = (0, import_shared9.randomUUID)();
|
|
3904
|
-
addOptimisticThread(newThreadId);
|
|
3905
|
-
config?.setThreadId?.(newThreadId);
|
|
3906
|
-
onThreadSelect?.(newThreadId);
|
|
3907
|
-
}, [addOptimisticThread, config, onThreadSelect]);
|
|
3908
|
-
const handleThreadSelect = (0, import_react27.useCallback)(
|
|
3909
|
-
(threadId) => {
|
|
3910
|
-
config?.setThreadId?.(threadId);
|
|
3911
|
-
onThreadSelect?.(threadId);
|
|
3912
|
-
},
|
|
3913
|
-
[config, onThreadSelect]
|
|
3914
|
-
);
|
|
3915
|
-
const handleDeleteThread = (0, import_react27.useCallback)(
|
|
3916
|
-
async (threadId) => {
|
|
3917
|
-
try {
|
|
3918
|
-
await deleteThread(threadId);
|
|
3919
|
-
if (threadId === (currentThreadId ?? config?.threadId)) {
|
|
3920
|
-
const newThreadId = (0, import_shared9.randomUUID)();
|
|
3921
|
-
addOptimisticThread(newThreadId);
|
|
3922
|
-
config?.setThreadId?.(newThreadId);
|
|
3923
|
-
}
|
|
3924
|
-
} catch (err) {
|
|
3925
|
-
console.error("Failed to delete thread:", err);
|
|
3926
|
-
}
|
|
3927
|
-
},
|
|
3928
|
-
[deleteThread, currentThreadId, config, addOptimisticThread]
|
|
3929
|
-
);
|
|
3930
|
-
(0, import_react27.useEffect)(() => {
|
|
3931
|
-
const activeId = currentThreadId ?? config?.threadId;
|
|
3932
|
-
if (!activeId) return;
|
|
3933
|
-
const isCurrentThreadInList = threads.some((t) => t.threadId === activeId);
|
|
3934
|
-
if (isCurrentThreadInList) {
|
|
3935
|
-
attemptedFetchRef.current.delete(activeId);
|
|
3936
|
-
return;
|
|
3937
|
-
}
|
|
3938
|
-
if (!isLoading && !attemptedFetchRef.current.has(activeId)) {
|
|
3939
|
-
attemptedFetchRef.current.add(activeId);
|
|
3940
|
-
refresh();
|
|
3941
|
-
}
|
|
3942
|
-
}, [currentThreadId, config?.threadId, threads, refresh, isLoading]);
|
|
3943
|
-
(0, import_react27.useEffect)(() => {
|
|
3944
|
-
if (disableAutoRefresh) return;
|
|
3945
|
-
const hasRunningThread = threads.some((t) => t.isRunning);
|
|
3946
|
-
const hasUnnamedThread = threads.some((t) => !t.firstMessage);
|
|
3947
|
-
if (!hasRunningThread && !hasUnnamedThread) return;
|
|
3948
|
-
const interval = setInterval(() => {
|
|
3949
|
-
refresh();
|
|
3950
|
-
}, refreshInterval);
|
|
3951
|
-
return () => clearInterval(interval);
|
|
3952
|
-
}, [threads, refresh, refreshInterval, disableAutoRefresh]);
|
|
3953
|
-
const BoundNewThreadButton = renderSlot(newThreadButton, NewThreadButton, {
|
|
3954
|
-
onClick: handleNewThread
|
|
3955
|
-
});
|
|
3956
|
-
const activeThreadId = currentThreadId ?? config?.threadId;
|
|
3957
|
-
const threadItems = threads.map((thread) => {
|
|
3958
|
-
const isActive = thread.threadId === activeThreadId;
|
|
3959
|
-
return renderSlot(threadItem, ThreadListItem, {
|
|
3960
|
-
key: thread.threadId,
|
|
3961
|
-
thread,
|
|
3962
|
-
isActive,
|
|
3963
|
-
onClick: () => handleThreadSelect(thread.threadId),
|
|
3964
|
-
onDelete: () => handleDeleteThread(thread.threadId)
|
|
3965
|
-
});
|
|
3966
|
-
});
|
|
3967
|
-
const content = /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
|
|
3968
|
-
BoundNewThreadButton,
|
|
3969
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "space-y-1", children: error ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "copilotkit-thread-list-error mx-4 my-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive", children: [
|
|
3970
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("p", { className: "mb-3 font-medium", children: [
|
|
3971
|
-
"Failed to load threads: ",
|
|
3972
|
-
error.message
|
|
3973
|
-
] }),
|
|
3974
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
3975
|
-
"button",
|
|
3976
|
-
{
|
|
3977
|
-
type: "button",
|
|
3978
|
-
className: "rounded bg-destructive px-3 py-1.5 text-xs font-medium text-destructive-foreground transition hover:bg-destructive/90",
|
|
3979
|
-
onClick: () => fetchThreads(),
|
|
3980
|
-
children: "Retry"
|
|
3981
|
-
}
|
|
3982
|
-
)
|
|
3983
|
-
] }) : isLoading && threads.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "p-4 text-center text-sm text-muted-foreground", children: "Loading threads..." }) : threads.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "p-4 text-center text-sm text-muted-foreground", children: "No threads yet" }) : threadItems })
|
|
3984
|
-
] });
|
|
3985
|
-
return renderSlot(container, Container, {
|
|
3986
|
-
className,
|
|
3987
|
-
children: content
|
|
3988
|
-
});
|
|
3989
|
-
}
|
|
3990
|
-
var Container = ({ className, children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: cn("flex flex-col h-full", className), ...props, children });
|
|
3991
|
-
var NewThreadButton = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
3992
|
-
"button",
|
|
3993
|
-
{
|
|
3994
|
-
className: cn(
|
|
3995
|
-
"w-full flex items-center gap-3 px-4 py-3 text-sm font-medium",
|
|
3996
|
-
"border-b border-border",
|
|
3997
|
-
"hover:bg-accent/50 transition-colors",
|
|
3998
|
-
"text-foreground",
|
|
3999
|
-
className
|
|
4000
|
-
),
|
|
4001
|
-
...props,
|
|
4002
|
-
children: [
|
|
4003
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react9.Plus, { className: "w-4 h-4" }),
|
|
4004
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { children: "New Conversation" })
|
|
4005
|
-
]
|
|
4006
|
-
}
|
|
4007
|
-
);
|
|
4008
|
-
var ThreadListItem = ({ thread, isActive, onClick, onDelete }) => {
|
|
4009
|
-
const displayText = thread.firstMessage?.substring(0, 60) || "New conversation";
|
|
4010
|
-
const hasEllipsis = thread.firstMessage && thread.firstMessage.length > 60;
|
|
4011
|
-
const messageCount = thread.messageCount || 0;
|
|
4012
|
-
const [isDeleting, setIsDeleting] = (0, import_react27.useState)(false);
|
|
4013
|
-
const handleDelete = (0, import_react27.useCallback)(
|
|
4014
|
-
async (e) => {
|
|
4015
|
-
e.stopPropagation();
|
|
4016
|
-
if (!onDelete) return;
|
|
4017
|
-
setIsDeleting(true);
|
|
4018
|
-
try {
|
|
4019
|
-
await onDelete();
|
|
4020
|
-
} catch (err) {
|
|
4021
|
-
console.error("Delete failed:", err);
|
|
4022
|
-
setIsDeleting(false);
|
|
4023
|
-
}
|
|
4024
|
-
},
|
|
4025
|
-
[onDelete]
|
|
4026
|
-
);
|
|
4027
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
4028
|
-
"div",
|
|
4029
|
-
{
|
|
4030
|
-
className: cn(
|
|
4031
|
-
"w-full flex items-start gap-3 px-4 py-3 group relative",
|
|
4032
|
-
"hover:bg-accent/50 transition-colors",
|
|
4033
|
-
"border-b border-border",
|
|
4034
|
-
isActive && "bg-accent border-l-2 border-l-primary",
|
|
4035
|
-
isDeleting && "opacity-50 pointer-events-none"
|
|
4036
|
-
),
|
|
4037
|
-
children: [
|
|
4038
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("button", { onClick, className: "flex items-start gap-3 flex-1 min-w-0 text-left", children: [
|
|
4039
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react9.MessageSquare, { className: "w-4 h-4 mt-0.5 flex-shrink-0 text-muted-foreground" }),
|
|
4040
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex-1 min-w-0", children: [
|
|
4041
|
-
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("p", { className: "text-sm text-foreground truncate", children: [
|
|
4042
|
-
displayText,
|
|
4043
|
-
hasEllipsis && "..."
|
|
4044
|
-
] }),
|
|
4045
|
-
messageCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("p", { className: "text-xs text-muted-foreground mt-1", children: [
|
|
4046
|
-
messageCount,
|
|
4047
|
-
" messages"
|
|
4048
|
-
] })
|
|
4049
|
-
] })
|
|
4050
|
-
] }),
|
|
4051
|
-
onDelete && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
4052
|
-
"button",
|
|
4053
|
-
{
|
|
4054
|
-
type: "button",
|
|
4055
|
-
onClick: handleDelete,
|
|
4056
|
-
disabled: isDeleting,
|
|
4057
|
-
className: cn(
|
|
4058
|
-
"p-1.5 rounded transition-all",
|
|
4059
|
-
"text-muted-foreground hover:text-destructive hover:bg-destructive/10",
|
|
4060
|
-
"opacity-0 group-hover:opacity-100",
|
|
4061
|
-
"focus:opacity-100 focus:outline-none focus:ring-2 focus:ring-destructive/20",
|
|
4062
|
-
isDeleting && "animate-pulse"
|
|
4063
|
-
),
|
|
4064
|
-
"aria-label": "Delete thread",
|
|
4065
|
-
title: "Delete thread",
|
|
4066
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react9.Trash2, { className: "w-4 h-4" })
|
|
4067
|
-
}
|
|
4068
|
-
)
|
|
4069
|
-
]
|
|
4070
|
-
}
|
|
4071
|
-
);
|
|
4072
|
-
};
|
|
4073
|
-
function CopilotThreadList(props) {
|
|
4074
|
-
const existingConfig = useCopilotChatConfiguration();
|
|
4075
|
-
if (!existingConfig) {
|
|
4076
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotChatConfigurationProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotThreadListInner, { ...props }) });
|
|
4077
|
-
}
|
|
4078
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotThreadListInner, { ...props });
|
|
4079
|
-
}
|
|
4080
|
-
CopilotThreadList.displayName = "CopilotThreadList";
|
|
4081
|
-
CopilotThreadList.ThreadItem = ThreadListItem;
|
|
4082
|
-
CopilotThreadList.NewThreadButton = NewThreadButton;
|
|
4083
|
-
CopilotThreadList.Container = Container;
|
|
4084
3527
|
|
|
4085
3528
|
// src/components/chat/CopilotSidebarView.tsx
|
|
4086
|
-
var
|
|
4087
|
-
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
3529
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
4088
3530
|
var DEFAULT_SIDEBAR_WIDTH = 480;
|
|
4089
3531
|
var SIDEBAR_TRANSITION_MS = 260;
|
|
4090
|
-
function CopilotSidebarView({ header, width,
|
|
3532
|
+
function CopilotSidebarView({ header, width, ...props }) {
|
|
4091
3533
|
const configuration = useCopilotChatConfiguration();
|
|
4092
3534
|
const isSidebarOpen = configuration?.isModalOpen ?? false;
|
|
4093
|
-
const
|
|
4094
|
-
const
|
|
4095
|
-
const [sidebarWidth, setSidebarWidth] = (0, import_react28.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
4096
|
-
const handleThreadListToggle = (0, import_react28.useCallback)(() => {
|
|
4097
|
-
setIsThreadListOpen((prev) => !prev);
|
|
4098
|
-
}, []);
|
|
4099
|
-
const handleThreadSelect = (0, import_react28.useCallback)(() => {
|
|
4100
|
-
setIsThreadListOpen(false);
|
|
4101
|
-
}, []);
|
|
4102
|
-
const handleNewThread = (0, import_react28.useCallback)(() => {
|
|
4103
|
-
const newThreadId = (0, import_shared10.randomUUID)();
|
|
4104
|
-
configuration?.setThreadId?.(newThreadId);
|
|
4105
|
-
}, [configuration]);
|
|
3535
|
+
const sidebarRef = (0, import_react25.useRef)(null);
|
|
3536
|
+
const [sidebarWidth, setSidebarWidth] = (0, import_react25.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
4106
3537
|
const widthToCss = (w) => {
|
|
4107
3538
|
return typeof w === "number" ? `${w}px` : w;
|
|
4108
3539
|
};
|
|
@@ -4112,7 +3543,7 @@ function CopilotSidebarView({ header, width, showThreadListButton = false, showN
|
|
|
4112
3543
|
}
|
|
4113
3544
|
return w;
|
|
4114
3545
|
};
|
|
4115
|
-
(0,
|
|
3546
|
+
(0, import_react25.useEffect)(() => {
|
|
4116
3547
|
if (width !== void 0) {
|
|
4117
3548
|
return;
|
|
4118
3549
|
}
|
|
@@ -4138,14 +3569,9 @@ function CopilotSidebarView({ header, width, showThreadListButton = false, showN
|
|
|
4138
3569
|
window.addEventListener("resize", updateWidth);
|
|
4139
3570
|
return () => window.removeEventListener("resize", updateWidth);
|
|
4140
3571
|
}, [width]);
|
|
4141
|
-
const headerElement = renderSlot(header, CopilotModalHeader, {
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
onNewThreadClick: handleNewThread,
|
|
4145
|
-
showNewThreadButton
|
|
4146
|
-
});
|
|
4147
|
-
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
|
|
4148
|
-
isSidebarOpen && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
3572
|
+
const headerElement = renderSlot(header, CopilotModalHeader, {});
|
|
3573
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
|
|
3574
|
+
isSidebarOpen && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
4149
3575
|
"style",
|
|
4150
3576
|
{
|
|
4151
3577
|
dangerouslySetInnerHTML: {
|
|
@@ -4159,8 +3585,8 @@ function CopilotSidebarView({ header, width, showThreadListButton = false, showN
|
|
|
4159
3585
|
}
|
|
4160
3586
|
}
|
|
4161
3587
|
),
|
|
4162
|
-
/* @__PURE__ */ (0,
|
|
4163
|
-
/* @__PURE__ */ (0,
|
|
3588
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotChatToggleButton_default, {}),
|
|
3589
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
4164
3590
|
"aside",
|
|
4165
3591
|
{
|
|
4166
3592
|
ref: sidebarRef,
|
|
@@ -4173,8 +3599,6 @@ function CopilotSidebarView({ header, width, showThreadListButton = false, showN
|
|
|
4173
3599
|
"w-full",
|
|
4174
3600
|
"border-l border-border bg-background text-foreground shadow-xl",
|
|
4175
3601
|
"transition-transform duration-300 ease-out",
|
|
4176
|
-
"overflow-hidden",
|
|
4177
|
-
// Clip the sliding panel
|
|
4178
3602
|
isSidebarOpen ? "translate-x-0" : "translate-x-full pointer-events-none"
|
|
4179
3603
|
),
|
|
4180
3604
|
style: {
|
|
@@ -4187,31 +3611,10 @@ function CopilotSidebarView({ header, width, showThreadListButton = false, showN
|
|
|
4187
3611
|
"aria-hidden": !isSidebarOpen,
|
|
4188
3612
|
"aria-label": "Copilot chat sidebar",
|
|
4189
3613
|
role: "complementary",
|
|
4190
|
-
children: [
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
className: "absolute inset-0 z-50",
|
|
4195
|
-
onClick: handleThreadListToggle,
|
|
4196
|
-
"aria-hidden": "true"
|
|
4197
|
-
}
|
|
4198
|
-
),
|
|
4199
|
-
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
4200
|
-
"div",
|
|
4201
|
-
{
|
|
4202
|
-
className: cn(
|
|
4203
|
-
"absolute left-0 top-0 h-full w-80 bg-background border-r border-border z-[60]",
|
|
4204
|
-
"transition-transform duration-300 ease-out",
|
|
4205
|
-
isThreadListOpen ? "translate-x-0" : "-translate-x-full"
|
|
4206
|
-
),
|
|
4207
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CopilotThreadList, { onThreadSelect: handleThreadSelect })
|
|
4208
|
-
}
|
|
4209
|
-
),
|
|
4210
|
-
/* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex h-full w-full flex-col overflow-hidden", children: [
|
|
4211
|
-
headerElement,
|
|
4212
|
-
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "flex-1 overflow-hidden", "data-sidebar-chat": true, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CopilotChatView_default, { ...props }) })
|
|
4213
|
-
] })
|
|
4214
|
-
]
|
|
3614
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex h-full w-full flex-col overflow-hidden", children: [
|
|
3615
|
+
headerElement,
|
|
3616
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex-1 overflow-hidden", "data-sidebar-chat": true, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CopilotChatView_default, { ...props }) })
|
|
3617
|
+
] })
|
|
4215
3618
|
}
|
|
4216
3619
|
)
|
|
4217
3620
|
] });
|
|
@@ -4219,9 +3622,8 @@ function CopilotSidebarView({ header, width, showThreadListButton = false, showN
|
|
|
4219
3622
|
CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
4220
3623
|
|
|
4221
3624
|
// src/components/chat/CopilotPopupView.tsx
|
|
4222
|
-
var
|
|
4223
|
-
var
|
|
4224
|
-
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
3625
|
+
var import_react26 = require("react");
|
|
3626
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
4225
3627
|
var DEFAULT_POPUP_WIDTH = 420;
|
|
4226
3628
|
var DEFAULT_POPUP_HEIGHT = 560;
|
|
4227
3629
|
var dimensionToCss = (value, fallback) => {
|
|
@@ -4238,8 +3640,6 @@ function CopilotPopupView({
|
|
|
4238
3640
|
width,
|
|
4239
3641
|
height,
|
|
4240
3642
|
clickOutsideToClose,
|
|
4241
|
-
showThreadListButton = false,
|
|
4242
|
-
showNewThreadButton = false,
|
|
4243
3643
|
className,
|
|
4244
3644
|
...restProps
|
|
4245
3645
|
}) {
|
|
@@ -4247,21 +3647,10 @@ function CopilotPopupView({
|
|
|
4247
3647
|
const isPopupOpen = configuration?.isModalOpen ?? false;
|
|
4248
3648
|
const setModalOpen = configuration?.setModalOpen;
|
|
4249
3649
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
4250
|
-
const containerRef = (0,
|
|
4251
|
-
const [isRendered, setIsRendered] = (0,
|
|
4252
|
-
const [isAnimatingOut, setIsAnimatingOut] = (0,
|
|
4253
|
-
|
|
4254
|
-
const handleThreadListToggle = (0, import_react29.useCallback)(() => {
|
|
4255
|
-
setIsThreadListOpen((prev) => !prev);
|
|
4256
|
-
}, []);
|
|
4257
|
-
const handleThreadSelect = (0, import_react29.useCallback)(() => {
|
|
4258
|
-
setIsThreadListOpen(false);
|
|
4259
|
-
}, []);
|
|
4260
|
-
const handleNewThread = (0, import_react29.useCallback)(() => {
|
|
4261
|
-
const newThreadId = (0, import_shared11.randomUUID)();
|
|
4262
|
-
configuration?.setThreadId?.(newThreadId);
|
|
4263
|
-
}, [configuration]);
|
|
4264
|
-
(0, import_react29.useEffect)(() => {
|
|
3650
|
+
const containerRef = (0, import_react26.useRef)(null);
|
|
3651
|
+
const [isRendered, setIsRendered] = (0, import_react26.useState)(isPopupOpen);
|
|
3652
|
+
const [isAnimatingOut, setIsAnimatingOut] = (0, import_react26.useState)(false);
|
|
3653
|
+
(0, import_react26.useEffect)(() => {
|
|
4265
3654
|
if (isPopupOpen) {
|
|
4266
3655
|
setIsRendered(true);
|
|
4267
3656
|
setIsAnimatingOut(false);
|
|
@@ -4277,7 +3666,7 @@ function CopilotPopupView({
|
|
|
4277
3666
|
}, 200);
|
|
4278
3667
|
return () => clearTimeout(timeout);
|
|
4279
3668
|
}, [isPopupOpen, isRendered]);
|
|
4280
|
-
(0,
|
|
3669
|
+
(0, import_react26.useEffect)(() => {
|
|
4281
3670
|
if (!isPopupOpen) {
|
|
4282
3671
|
return;
|
|
4283
3672
|
}
|
|
@@ -4293,7 +3682,7 @@ function CopilotPopupView({
|
|
|
4293
3682
|
window.addEventListener("keydown", handleKeyDown);
|
|
4294
3683
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
4295
3684
|
}, [isPopupOpen, setModalOpen]);
|
|
4296
|
-
(0,
|
|
3685
|
+
(0, import_react26.useEffect)(() => {
|
|
4297
3686
|
if (!isPopupOpen) {
|
|
4298
3687
|
return;
|
|
4299
3688
|
}
|
|
@@ -4302,7 +3691,7 @@ function CopilotPopupView({
|
|
|
4302
3691
|
}, 200);
|
|
4303
3692
|
return () => clearTimeout(focusTimer);
|
|
4304
3693
|
}, [isPopupOpen]);
|
|
4305
|
-
(0,
|
|
3694
|
+
(0, import_react26.useEffect)(() => {
|
|
4306
3695
|
if (!isPopupOpen || !clickOutsideToClose) {
|
|
4307
3696
|
return;
|
|
4308
3697
|
}
|
|
@@ -4327,15 +3716,10 @@ function CopilotPopupView({
|
|
|
4327
3716
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
4328
3717
|
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
4329
3718
|
}, [isPopupOpen, clickOutsideToClose, setModalOpen]);
|
|
4330
|
-
const headerElement = (0,
|
|
4331
|
-
onThreadListClick: handleThreadListToggle,
|
|
4332
|
-
showThreadListButton,
|
|
4333
|
-
onNewThreadClick: handleNewThread,
|
|
4334
|
-
showNewThreadButton
|
|
4335
|
-
}), [header, handleThreadListToggle, showThreadListButton, handleNewThread, showNewThreadButton]);
|
|
3719
|
+
const headerElement = (0, import_react26.useMemo)(() => renderSlot(header, CopilotModalHeader, {}), [header]);
|
|
4336
3720
|
const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
|
|
4337
3721
|
const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
|
|
4338
|
-
const popupStyle = (0,
|
|
3722
|
+
const popupStyle = (0, import_react26.useMemo)(
|
|
4339
3723
|
() => ({
|
|
4340
3724
|
"--copilot-popup-width": resolvedWidth,
|
|
4341
3725
|
"--copilot-popup-height": resolvedHeight,
|
|
@@ -4349,14 +3733,14 @@ function CopilotPopupView({
|
|
|
4349
3733
|
[resolvedHeight, resolvedWidth]
|
|
4350
3734
|
);
|
|
4351
3735
|
const popupAnimationClass = isPopupOpen && !isAnimatingOut ? "pointer-events-auto translate-y-0 opacity-100 md:scale-100" : "pointer-events-none translate-y-4 opacity-0 md:translate-y-5 md:scale-[0.95]";
|
|
4352
|
-
const popupContent = isRendered ? /* @__PURE__ */ (0,
|
|
3736
|
+
const popupContent = isRendered ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
4353
3737
|
"div",
|
|
4354
3738
|
{
|
|
4355
3739
|
className: cn(
|
|
4356
3740
|
"fixed inset-0 z-[1200] flex max-w-full flex-col items-stretch",
|
|
4357
3741
|
"md:inset-auto md:bottom-24 md:right-6 md:items-end md:gap-4"
|
|
4358
3742
|
),
|
|
4359
|
-
children: /* @__PURE__ */ (0,
|
|
3743
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
4360
3744
|
"div",
|
|
4361
3745
|
{
|
|
4362
3746
|
ref: containerRef,
|
|
@@ -4365,40 +3749,19 @@ function CopilotPopupView({
|
|
|
4365
3749
|
"aria-label": labels.modalHeaderTitle,
|
|
4366
3750
|
"data-copilot-popup": true,
|
|
4367
3751
|
className: cn(
|
|
4368
|
-
"relative flex h-full w-full flex-col bg-background text-foreground",
|
|
3752
|
+
"relative flex h-full w-full flex-col overflow-hidden bg-background text-foreground",
|
|
4369
3753
|
"origin-bottom focus:outline-none transform-gpu transition-transform transition-opacity duration-200 ease-out",
|
|
4370
3754
|
"md:transition-transform md:transition-opacity",
|
|
4371
3755
|
"rounded-none border border-border/0 shadow-none ring-0",
|
|
4372
3756
|
"md:h-[var(--copilot-popup-height)] md:w-[var(--copilot-popup-width)]",
|
|
4373
3757
|
"md:max-h-[var(--copilot-popup-max-height)] md:max-w-[var(--copilot-popup-max-width)]",
|
|
4374
3758
|
"md:origin-bottom-right md:rounded-2xl md:border-border md:shadow-xl md:ring-1 md:ring-border/40",
|
|
4375
|
-
"overflow-hidden",
|
|
4376
|
-
// Clip the sliding panel
|
|
4377
3759
|
popupAnimationClass
|
|
4378
3760
|
),
|
|
4379
3761
|
style: popupStyle,
|
|
4380
3762
|
children: [
|
|
4381
|
-
isThreadListOpen && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
4382
|
-
"div",
|
|
4383
|
-
{
|
|
4384
|
-
className: "absolute inset-0 z-50",
|
|
4385
|
-
onClick: handleThreadListToggle,
|
|
4386
|
-
"aria-hidden": "true"
|
|
4387
|
-
}
|
|
4388
|
-
),
|
|
4389
|
-
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
4390
|
-
"div",
|
|
4391
|
-
{
|
|
4392
|
-
className: cn(
|
|
4393
|
-
"absolute left-0 top-0 h-full w-80 bg-background border-r border-border z-[60]",
|
|
4394
|
-
"transition-transform duration-300 ease-out",
|
|
4395
|
-
isThreadListOpen ? "translate-x-0" : "-translate-x-full"
|
|
4396
|
-
),
|
|
4397
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(CopilotThreadList, { onThreadSelect: handleThreadSelect })
|
|
4398
|
-
}
|
|
4399
|
-
),
|
|
4400
3763
|
headerElement,
|
|
4401
|
-
/* @__PURE__ */ (0,
|
|
3764
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "flex-1 overflow-hidden", "data-popup-chat": true, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
4402
3765
|
CopilotChatView_default,
|
|
4403
3766
|
{
|
|
4404
3767
|
...restProps,
|
|
@@ -4410,34 +3773,32 @@ function CopilotPopupView({
|
|
|
4410
3773
|
)
|
|
4411
3774
|
}
|
|
4412
3775
|
) : null;
|
|
4413
|
-
return /* @__PURE__ */ (0,
|
|
4414
|
-
/* @__PURE__ */ (0,
|
|
3776
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
|
|
3777
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CopilotChatToggleButton_default, {}),
|
|
4415
3778
|
popupContent
|
|
4416
3779
|
] });
|
|
4417
3780
|
}
|
|
4418
3781
|
CopilotPopupView.displayName = "CopilotPopupView";
|
|
4419
3782
|
|
|
4420
3783
|
// src/components/chat/CopilotSidebar.tsx
|
|
4421
|
-
var
|
|
4422
|
-
var
|
|
4423
|
-
function CopilotSidebar({ header, defaultOpen, width,
|
|
4424
|
-
const SidebarViewOverride = (0,
|
|
3784
|
+
var import_react27 = require("react");
|
|
3785
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
3786
|
+
function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
3787
|
+
const SidebarViewOverride = (0, import_react27.useMemo)(() => {
|
|
4425
3788
|
const Component = (viewProps) => {
|
|
4426
|
-
const { header: viewHeader, width: viewWidth,
|
|
4427
|
-
return /* @__PURE__ */ (0,
|
|
3789
|
+
const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
|
|
3790
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
4428
3791
|
CopilotSidebarView,
|
|
4429
3792
|
{
|
|
4430
3793
|
...restProps,
|
|
4431
3794
|
header: header ?? viewHeader,
|
|
4432
|
-
width: width ?? viewWidth
|
|
4433
|
-
showThreadListButton: showThreadListButton ?? viewShowThreadList,
|
|
4434
|
-
showNewThreadButton: showNewThreadButton ?? viewShowNewThread
|
|
3795
|
+
width: width ?? viewWidth
|
|
4435
3796
|
}
|
|
4436
3797
|
);
|
|
4437
3798
|
};
|
|
4438
3799
|
return Object.assign(Component, CopilotChatView_default);
|
|
4439
|
-
}, [header, width
|
|
4440
|
-
return /* @__PURE__ */ (0,
|
|
3800
|
+
}, [header, width]);
|
|
3801
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
4441
3802
|
CopilotChat,
|
|
4442
3803
|
{
|
|
4443
3804
|
...chatProps,
|
|
@@ -4449,45 +3810,39 @@ function CopilotSidebar({ header, defaultOpen, width, showThreadListButton, show
|
|
|
4449
3810
|
CopilotSidebar.displayName = "CopilotSidebar";
|
|
4450
3811
|
|
|
4451
3812
|
// src/components/chat/CopilotPopup.tsx
|
|
4452
|
-
var
|
|
4453
|
-
var
|
|
3813
|
+
var import_react28 = require("react");
|
|
3814
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
4454
3815
|
function CopilotPopup({
|
|
4455
3816
|
header,
|
|
4456
3817
|
defaultOpen,
|
|
4457
3818
|
width,
|
|
4458
3819
|
height,
|
|
4459
3820
|
clickOutsideToClose,
|
|
4460
|
-
showThreadListButton,
|
|
4461
|
-
showNewThreadButton,
|
|
4462
3821
|
...chatProps
|
|
4463
3822
|
}) {
|
|
4464
|
-
const PopupViewOverride = (0,
|
|
3823
|
+
const PopupViewOverride = (0, import_react28.useMemo)(() => {
|
|
4465
3824
|
const Component = (viewProps) => {
|
|
4466
3825
|
const {
|
|
4467
3826
|
header: viewHeader,
|
|
4468
3827
|
width: viewWidth,
|
|
4469
3828
|
height: viewHeight,
|
|
4470
3829
|
clickOutsideToClose: viewClickOutsideToClose,
|
|
4471
|
-
showThreadListButton: viewShowThreadList,
|
|
4472
|
-
showNewThreadButton: viewShowNewThread,
|
|
4473
3830
|
...restProps
|
|
4474
3831
|
} = viewProps;
|
|
4475
|
-
return /* @__PURE__ */ (0,
|
|
3832
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
4476
3833
|
CopilotPopupView,
|
|
4477
3834
|
{
|
|
4478
3835
|
...restProps,
|
|
4479
3836
|
header: header ?? viewHeader,
|
|
4480
3837
|
width: width ?? viewWidth,
|
|
4481
3838
|
height: height ?? viewHeight,
|
|
4482
|
-
clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose
|
|
4483
|
-
showThreadListButton: showThreadListButton ?? viewShowThreadList,
|
|
4484
|
-
showNewThreadButton: showNewThreadButton ?? viewShowNewThread
|
|
3839
|
+
clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose
|
|
4485
3840
|
}
|
|
4486
3841
|
);
|
|
4487
3842
|
};
|
|
4488
3843
|
return Object.assign(Component, CopilotChatView_default);
|
|
4489
|
-
}, [clickOutsideToClose, header, height, width
|
|
4490
|
-
return /* @__PURE__ */ (0,
|
|
3844
|
+
}, [clickOutsideToClose, header, height, width]);
|
|
3845
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
4491
3846
|
CopilotChat,
|
|
4492
3847
|
{
|
|
4493
3848
|
...chatProps,
|
|
@@ -4511,25 +3866,25 @@ function defineToolCallRenderer(def) {
|
|
|
4511
3866
|
}
|
|
4512
3867
|
|
|
4513
3868
|
// src/components/WildcardToolCallRender.tsx
|
|
4514
|
-
var
|
|
4515
|
-
var
|
|
3869
|
+
var import_react29 = require("react");
|
|
3870
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
4516
3871
|
var WildcardToolCallRender = defineToolCallRenderer({
|
|
4517
3872
|
name: "*",
|
|
4518
3873
|
render: ({ args, result, name, status }) => {
|
|
4519
|
-
const [isExpanded, setIsExpanded] = (0,
|
|
3874
|
+
const [isExpanded, setIsExpanded] = (0, import_react29.useState)(false);
|
|
4520
3875
|
const statusString = String(status);
|
|
4521
3876
|
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
4522
3877
|
const isComplete = statusString === "complete";
|
|
4523
3878
|
const statusStyles = isActive ? "bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-400" : isComplete ? "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-400" : "bg-zinc-100 text-zinc-800 dark:bg-zinc-700/40 dark:text-zinc-300";
|
|
4524
|
-
return /* @__PURE__ */ (0,
|
|
4525
|
-
/* @__PURE__ */ (0,
|
|
3879
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "mt-2 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rounded-xl border border-zinc-200/60 dark:border-zinc-800/60 bg-white/70 dark:bg-zinc-900/50 shadow-sm backdrop-blur p-4", children: [
|
|
3880
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4526
3881
|
"div",
|
|
4527
3882
|
{
|
|
4528
3883
|
className: "flex items-center justify-between gap-3 cursor-pointer",
|
|
4529
3884
|
onClick: () => setIsExpanded(!isExpanded),
|
|
4530
3885
|
children: [
|
|
4531
|
-
/* @__PURE__ */ (0,
|
|
4532
|
-
/* @__PURE__ */ (0,
|
|
3886
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex items-center gap-2 min-w-0", children: [
|
|
3887
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4533
3888
|
"svg",
|
|
4534
3889
|
{
|
|
4535
3890
|
className: `h-4 w-4 text-zinc-500 dark:text-zinc-400 transition-transform ${isExpanded ? "rotate-90" : ""}`,
|
|
@@ -4537,7 +3892,7 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
4537
3892
|
viewBox: "0 0 24 24",
|
|
4538
3893
|
strokeWidth: 2,
|
|
4539
3894
|
stroke: "currentColor",
|
|
4540
|
-
children: /* @__PURE__ */ (0,
|
|
3895
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4541
3896
|
"path",
|
|
4542
3897
|
{
|
|
4543
3898
|
strokeLinecap: "round",
|
|
@@ -4547,10 +3902,10 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
4547
3902
|
)
|
|
4548
3903
|
}
|
|
4549
3904
|
),
|
|
4550
|
-
/* @__PURE__ */ (0,
|
|
4551
|
-
/* @__PURE__ */ (0,
|
|
3905
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "inline-block h-2 w-2 rounded-full bg-blue-500" }),
|
|
3906
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "truncate text-sm font-medium text-zinc-900 dark:text-zinc-100", children: name })
|
|
4552
3907
|
] }),
|
|
4553
|
-
/* @__PURE__ */ (0,
|
|
3908
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4554
3909
|
"span",
|
|
4555
3910
|
{
|
|
4556
3911
|
className: `inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${statusStyles}`,
|
|
@@ -4560,14 +3915,14 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
4560
3915
|
]
|
|
4561
3916
|
}
|
|
4562
3917
|
),
|
|
4563
|
-
isExpanded && /* @__PURE__ */ (0,
|
|
4564
|
-
/* @__PURE__ */ (0,
|
|
4565
|
-
/* @__PURE__ */ (0,
|
|
4566
|
-
/* @__PURE__ */ (0,
|
|
3918
|
+
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "mt-3 grid gap-4", children: [
|
|
3919
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { children: [
|
|
3920
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Arguments" }),
|
|
3921
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: JSON.stringify(args ?? {}, null, 2) })
|
|
4567
3922
|
] }),
|
|
4568
|
-
result !== void 0 && /* @__PURE__ */ (0,
|
|
4569
|
-
/* @__PURE__ */ (0,
|
|
4570
|
-
/* @__PURE__ */ (0,
|
|
3923
|
+
result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { children: [
|
|
3924
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Result" }),
|
|
3925
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: typeof result === "string" ? result : JSON.stringify(result, null, 2) })
|
|
4571
3926
|
] })
|
|
4572
3927
|
] })
|
|
4573
3928
|
] }) });
|
|
@@ -4598,7 +3953,6 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
4598
3953
|
CopilotPopupView,
|
|
4599
3954
|
CopilotSidebar,
|
|
4600
3955
|
CopilotSidebarView,
|
|
4601
|
-
CopilotThreadList,
|
|
4602
3956
|
WildcardToolCallRender,
|
|
4603
3957
|
defineToolCallRenderer,
|
|
4604
3958
|
useAgent,
|
|
@@ -4610,8 +3964,6 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
4610
3964
|
useHumanInTheLoop,
|
|
4611
3965
|
useRenderCustomMessages,
|
|
4612
3966
|
useRenderToolCall,
|
|
4613
|
-
useSuggestions
|
|
4614
|
-
useThreadSwitch,
|
|
4615
|
-
useThreads
|
|
3967
|
+
useSuggestions
|
|
4616
3968
|
});
|
|
4617
3969
|
//# sourceMappingURL=index.js.map
|