@copilotkitnext/react 0.0.13-alpha.1 → 0.0.13
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 +83 -33
- package/dist/index.d.ts +83 -33
- package/dist/index.js +485 -325
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +447 -278
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -901,26 +901,100 @@ import "katex/dist/katex.min.css";
|
|
|
901
901
|
import { completePartialMarkdown } from "@copilotkitnext/core";
|
|
902
902
|
|
|
903
903
|
// src/hooks/use-render-tool-call.tsx
|
|
904
|
-
import { useCallback, useEffect as
|
|
904
|
+
import { useCallback, useEffect as useEffect5, useState as useState4, useSyncExternalStore } from "react";
|
|
905
905
|
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
906
906
|
|
|
907
907
|
// src/providers/CopilotKitProvider.tsx
|
|
908
|
-
import {
|
|
908
|
+
import {
|
|
909
|
+
createContext as createContext2,
|
|
910
|
+
useContext as useContext2,
|
|
911
|
+
useMemo as useMemo2,
|
|
912
|
+
useEffect as useEffect4,
|
|
913
|
+
useReducer,
|
|
914
|
+
useRef as useRef4,
|
|
915
|
+
useState as useState3
|
|
916
|
+
} from "react";
|
|
909
917
|
import { z } from "zod";
|
|
918
|
+
|
|
919
|
+
// src/lib/react-core.ts
|
|
910
920
|
import { CopilotKitCore } from "@copilotkitnext/core";
|
|
921
|
+
var CopilotKitCoreReact = class extends CopilotKitCore {
|
|
922
|
+
_renderToolCalls = [];
|
|
923
|
+
_renderCustomMessages = [];
|
|
924
|
+
constructor(config) {
|
|
925
|
+
super(config);
|
|
926
|
+
this._renderToolCalls = config.renderToolCalls ?? [];
|
|
927
|
+
this._renderCustomMessages = config.renderCustomMessages ?? [];
|
|
928
|
+
}
|
|
929
|
+
get renderCustomMessages() {
|
|
930
|
+
return this._renderCustomMessages;
|
|
931
|
+
}
|
|
932
|
+
get renderToolCalls() {
|
|
933
|
+
return this._renderToolCalls;
|
|
934
|
+
}
|
|
935
|
+
setRenderToolCalls(renderToolCalls) {
|
|
936
|
+
this._renderToolCalls = renderToolCalls;
|
|
937
|
+
void this.notifySubscribers(
|
|
938
|
+
(subscriber) => {
|
|
939
|
+
const reactSubscriber = subscriber;
|
|
940
|
+
if (reactSubscriber.onRenderToolCallsChanged) {
|
|
941
|
+
reactSubscriber.onRenderToolCallsChanged({
|
|
942
|
+
copilotkit: this,
|
|
943
|
+
renderToolCalls: this.renderToolCalls
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
"Subscriber onRenderToolCallsChanged error:"
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
// Override to accept React-specific subscriber type
|
|
951
|
+
subscribe(subscriber) {
|
|
952
|
+
return super.subscribe(subscriber);
|
|
953
|
+
}
|
|
954
|
+
unsubscribe(subscriber) {
|
|
955
|
+
super.unsubscribe(subscriber);
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
// src/components/WebInspector.tsx
|
|
960
|
+
import * as React4 from "react";
|
|
961
|
+
import { createComponent } from "@lit-labs/react";
|
|
962
|
+
import {
|
|
963
|
+
WEB_INSPECTOR_TAG,
|
|
964
|
+
WebInspectorElement,
|
|
965
|
+
defineWebInspector
|
|
966
|
+
} from "@copilotkitnext/web-inspector";
|
|
911
967
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
968
|
+
defineWebInspector();
|
|
969
|
+
var WebInspectorBase = createComponent({
|
|
970
|
+
tagName: WEB_INSPECTOR_TAG,
|
|
971
|
+
elementClass: WebInspectorElement,
|
|
972
|
+
react: React4
|
|
973
|
+
});
|
|
974
|
+
var WebInspector = React4.forwardRef(
|
|
975
|
+
({ core, ...rest }, ref) => {
|
|
976
|
+
const innerRef = React4.useRef(null);
|
|
977
|
+
React4.useImperativeHandle(ref, () => innerRef.current, []);
|
|
978
|
+
React4.useEffect(() => {
|
|
979
|
+
if (innerRef.current) {
|
|
980
|
+
innerRef.current.core = core ?? null;
|
|
981
|
+
}
|
|
982
|
+
}, [core]);
|
|
983
|
+
return /* @__PURE__ */ jsx7(WebInspectorBase, { ...rest, ref: innerRef });
|
|
917
984
|
}
|
|
985
|
+
);
|
|
986
|
+
WebInspector.displayName = "WebInspector";
|
|
987
|
+
|
|
988
|
+
// src/providers/CopilotKitProvider.tsx
|
|
989
|
+
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
990
|
+
var CopilotKitContext = createContext2({
|
|
991
|
+
copilotkit: null
|
|
918
992
|
});
|
|
919
993
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
920
994
|
const empty = useMemo2(() => [], []);
|
|
921
995
|
const value = prop ?? empty;
|
|
922
|
-
const initial =
|
|
923
|
-
|
|
996
|
+
const initial = useRef4(value);
|
|
997
|
+
useEffect4(() => {
|
|
924
998
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) {
|
|
925
999
|
console.error(warningMessage);
|
|
926
1000
|
}
|
|
@@ -934,9 +1008,29 @@ var CopilotKitProvider = ({
|
|
|
934
1008
|
properties = {},
|
|
935
1009
|
agents__unsafe_dev_only: agents = {},
|
|
936
1010
|
renderToolCalls,
|
|
1011
|
+
renderCustomMessages,
|
|
937
1012
|
frontendTools,
|
|
938
|
-
humanInTheLoop
|
|
1013
|
+
humanInTheLoop,
|
|
1014
|
+
showDevConsole = false
|
|
939
1015
|
}) => {
|
|
1016
|
+
const [shouldRenderInspector, setShouldRenderInspector] = useState3(false);
|
|
1017
|
+
useEffect4(() => {
|
|
1018
|
+
if (typeof window === "undefined") {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (showDevConsole === true) {
|
|
1022
|
+
setShouldRenderInspector(true);
|
|
1023
|
+
} else if (showDevConsole === "auto") {
|
|
1024
|
+
const localhostHosts = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
|
|
1025
|
+
if (localhostHosts.has(window.location.hostname)) {
|
|
1026
|
+
setShouldRenderInspector(true);
|
|
1027
|
+
} else {
|
|
1028
|
+
setShouldRenderInspector(false);
|
|
1029
|
+
}
|
|
1030
|
+
} else {
|
|
1031
|
+
setShouldRenderInspector(false);
|
|
1032
|
+
}
|
|
1033
|
+
}, [showDevConsole]);
|
|
940
1034
|
const renderToolCallsList = useStableArrayProp(
|
|
941
1035
|
renderToolCalls,
|
|
942
1036
|
"renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.",
|
|
@@ -950,6 +1044,10 @@ var CopilotKitProvider = ({
|
|
|
950
1044
|
return false;
|
|
951
1045
|
}
|
|
952
1046
|
);
|
|
1047
|
+
const renderCustomMessagesList = useStableArrayProp(
|
|
1048
|
+
renderCustomMessages,
|
|
1049
|
+
"renderCustomMessages must be a stable array."
|
|
1050
|
+
);
|
|
953
1051
|
const frontendToolsList = useStableArrayProp(
|
|
954
1052
|
frontendTools,
|
|
955
1053
|
"frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead."
|
|
@@ -958,8 +1056,6 @@ var CopilotKitProvider = ({
|
|
|
958
1056
|
humanInTheLoop,
|
|
959
1057
|
"humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead."
|
|
960
1058
|
);
|
|
961
|
-
const initialRenderToolCalls = useMemo2(() => renderToolCallsList, []);
|
|
962
|
-
const [currentRenderToolCalls, setCurrentRenderToolCalls] = useState3([]);
|
|
963
1059
|
const processedHumanInTheLoopTools = useMemo2(() => {
|
|
964
1060
|
const processedTools = [];
|
|
965
1061
|
const processedRenderToolCalls = [];
|
|
@@ -1013,58 +1109,44 @@ var CopilotKitProvider = ({
|
|
|
1013
1109
|
return combined;
|
|
1014
1110
|
}, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
|
|
1015
1111
|
const copilotkit = useMemo2(() => {
|
|
1016
|
-
const
|
|
1112
|
+
const copilotkit2 = new CopilotKitCoreReact({
|
|
1017
1113
|
runtimeUrl,
|
|
1018
1114
|
headers,
|
|
1019
1115
|
properties,
|
|
1020
1116
|
agents__unsafe_dev_only: agents,
|
|
1021
|
-
tools: allTools
|
|
1022
|
-
|
|
1023
|
-
|
|
1117
|
+
tools: allTools,
|
|
1118
|
+
renderToolCalls: allRenderToolCalls,
|
|
1119
|
+
renderCustomMessages: renderCustomMessagesList
|
|
1120
|
+
});
|
|
1024
1121
|
return copilotkit2;
|
|
1025
|
-
}, [allTools]);
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
computedMap.set(keyOf(rc), rc);
|
|
1032
|
-
}
|
|
1033
|
-
const merged = [...computedMap.values()];
|
|
1034
|
-
for (const rc of prev) {
|
|
1035
|
-
const k = keyOf(rc);
|
|
1036
|
-
if (!computedMap.has(k)) merged.push(rc);
|
|
1037
|
-
}
|
|
1038
|
-
const sameLength = merged.length === prev.length;
|
|
1039
|
-
if (sameLength) {
|
|
1040
|
-
let same = true;
|
|
1041
|
-
for (let i = 0; i < merged.length; i++) {
|
|
1042
|
-
if (merged[i] !== prev[i]) {
|
|
1043
|
-
same = false;
|
|
1044
|
-
break;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
if (same) return prev;
|
|
1122
|
+
}, [allTools, allRenderToolCalls, renderCustomMessagesList]);
|
|
1123
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
1124
|
+
useEffect4(() => {
|
|
1125
|
+
const unsubscribe = copilotkit.subscribe({
|
|
1126
|
+
onRenderToolCallsChanged: () => {
|
|
1127
|
+
forceUpdate();
|
|
1048
1128
|
}
|
|
1049
|
-
return merged;
|
|
1050
1129
|
});
|
|
1051
|
-
|
|
1052
|
-
|
|
1130
|
+
return () => {
|
|
1131
|
+
unsubscribe();
|
|
1132
|
+
};
|
|
1133
|
+
}, [copilotkit]);
|
|
1134
|
+
useEffect4(() => {
|
|
1053
1135
|
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
1054
1136
|
copilotkit.setHeaders(headers);
|
|
1055
1137
|
copilotkit.setProperties(properties);
|
|
1056
1138
|
copilotkit.setAgents__unsafe_dev_only(agents);
|
|
1057
1139
|
}, [runtimeUrl, headers, properties, agents]);
|
|
1058
|
-
return /* @__PURE__ */
|
|
1140
|
+
return /* @__PURE__ */ jsxs4(
|
|
1059
1141
|
CopilotKitContext.Provider,
|
|
1060
1142
|
{
|
|
1061
1143
|
value: {
|
|
1062
|
-
copilotkit
|
|
1063
|
-
renderToolCalls: allRenderToolCalls,
|
|
1064
|
-
currentRenderToolCalls,
|
|
1065
|
-
setCurrentRenderToolCalls
|
|
1144
|
+
copilotkit
|
|
1066
1145
|
},
|
|
1067
|
-
children
|
|
1146
|
+
children: [
|
|
1147
|
+
children,
|
|
1148
|
+
shouldRenderInspector ? /* @__PURE__ */ jsx8(WebInspector, { core: copilotkit }) : null
|
|
1149
|
+
]
|
|
1068
1150
|
}
|
|
1069
1151
|
);
|
|
1070
1152
|
};
|
|
@@ -1074,7 +1156,7 @@ var useCopilotKit = () => {
|
|
|
1074
1156
|
if (!context) {
|
|
1075
1157
|
throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1076
1158
|
}
|
|
1077
|
-
|
|
1159
|
+
useEffect4(() => {
|
|
1078
1160
|
const unsubscribe = context.copilotkit.subscribe({
|
|
1079
1161
|
onRuntimeConnectionStatusChanged: () => {
|
|
1080
1162
|
forceUpdate();
|
|
@@ -1090,13 +1172,22 @@ var useCopilotKit = () => {
|
|
|
1090
1172
|
// src/hooks/use-render-tool-call.tsx
|
|
1091
1173
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID2 } from "@copilotkitnext/shared";
|
|
1092
1174
|
import { partialJSONParse } from "@copilotkitnext/shared";
|
|
1093
|
-
import { jsx as
|
|
1175
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1094
1176
|
function useRenderToolCall() {
|
|
1095
|
-
const {
|
|
1177
|
+
const { copilotkit } = useCopilotKit();
|
|
1096
1178
|
const config = useCopilotChatConfiguration();
|
|
1097
1179
|
const agentId = config?.agentId ?? DEFAULT_AGENT_ID2;
|
|
1098
1180
|
const [executingToolCallIds, setExecutingToolCallIds] = useState4(() => /* @__PURE__ */ new Set());
|
|
1099
|
-
|
|
1181
|
+
const renderToolCalls = useSyncExternalStore(
|
|
1182
|
+
(callback) => {
|
|
1183
|
+
return copilotkit.subscribe({
|
|
1184
|
+
onRenderToolCallsChanged: callback
|
|
1185
|
+
});
|
|
1186
|
+
},
|
|
1187
|
+
() => copilotkit.renderToolCalls,
|
|
1188
|
+
() => copilotkit.renderToolCalls
|
|
1189
|
+
);
|
|
1190
|
+
useEffect5(() => {
|
|
1100
1191
|
const unsubscribe = copilotkit.subscribe({
|
|
1101
1192
|
onToolExecutionStart: ({ toolCallId }) => {
|
|
1102
1193
|
setExecutingToolCallIds((prev) => {
|
|
@@ -1122,10 +1213,10 @@ function useRenderToolCall() {
|
|
|
1122
1213
|
toolCall,
|
|
1123
1214
|
toolMessage
|
|
1124
1215
|
}) => {
|
|
1125
|
-
const exactMatches =
|
|
1216
|
+
const exactMatches = renderToolCalls.filter(
|
|
1126
1217
|
(rc) => rc.name === toolCall.function.name
|
|
1127
1218
|
);
|
|
1128
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] ||
|
|
1219
|
+
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1129
1220
|
if (!renderConfig) {
|
|
1130
1221
|
return null;
|
|
1131
1222
|
}
|
|
@@ -1133,7 +1224,7 @@ function useRenderToolCall() {
|
|
|
1133
1224
|
const args = partialJSONParse(toolCall.function.arguments);
|
|
1134
1225
|
const toolName = toolCall.function.name;
|
|
1135
1226
|
if (toolMessage) {
|
|
1136
|
-
return /* @__PURE__ */
|
|
1227
|
+
return /* @__PURE__ */ jsx9(
|
|
1137
1228
|
RenderComponent,
|
|
1138
1229
|
{
|
|
1139
1230
|
name: toolName,
|
|
@@ -1144,7 +1235,7 @@ function useRenderToolCall() {
|
|
|
1144
1235
|
toolCall.id
|
|
1145
1236
|
);
|
|
1146
1237
|
} else if (executingToolCallIds.has(toolCall.id)) {
|
|
1147
|
-
return /* @__PURE__ */
|
|
1238
|
+
return /* @__PURE__ */ jsx9(
|
|
1148
1239
|
RenderComponent,
|
|
1149
1240
|
{
|
|
1150
1241
|
name: toolName,
|
|
@@ -1155,7 +1246,7 @@ function useRenderToolCall() {
|
|
|
1155
1246
|
toolCall.id
|
|
1156
1247
|
);
|
|
1157
1248
|
} else {
|
|
1158
|
-
return /* @__PURE__ */
|
|
1249
|
+
return /* @__PURE__ */ jsx9(
|
|
1159
1250
|
RenderComponent,
|
|
1160
1251
|
{
|
|
1161
1252
|
name: toolName,
|
|
@@ -1167,16 +1258,74 @@ function useRenderToolCall() {
|
|
|
1167
1258
|
);
|
|
1168
1259
|
}
|
|
1169
1260
|
},
|
|
1170
|
-
[
|
|
1261
|
+
[renderToolCalls, executingToolCallIds, agentId]
|
|
1171
1262
|
);
|
|
1172
1263
|
return renderToolCall;
|
|
1173
1264
|
}
|
|
1174
1265
|
|
|
1266
|
+
// src/hooks/use-render-custom-messages.tsx
|
|
1267
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1268
|
+
function useRenderCustomMessages() {
|
|
1269
|
+
const { copilotkit } = useCopilotKit();
|
|
1270
|
+
const config = useCopilotChatConfiguration();
|
|
1271
|
+
if (!config) {
|
|
1272
|
+
return null;
|
|
1273
|
+
}
|
|
1274
|
+
const { agentId, threadId } = config;
|
|
1275
|
+
const customMessageRenderers = copilotkit.renderCustomMessages.filter((renderer) => renderer.agentId === void 0 || renderer.agentId === agentId).sort((a, b) => {
|
|
1276
|
+
const aHasAgent = a.agentId !== void 0;
|
|
1277
|
+
const bHasAgent = b.agentId !== void 0;
|
|
1278
|
+
if (aHasAgent === bHasAgent) return 0;
|
|
1279
|
+
return aHasAgent ? -1 : 1;
|
|
1280
|
+
});
|
|
1281
|
+
return function(params) {
|
|
1282
|
+
if (!customMessageRenderers.length) {
|
|
1283
|
+
return null;
|
|
1284
|
+
}
|
|
1285
|
+
const { message, position } = params;
|
|
1286
|
+
const runId = copilotkit.getRunIdForMessage(agentId, threadId, message.id);
|
|
1287
|
+
const agent = copilotkit.getAgent(agentId);
|
|
1288
|
+
if (!agent) {
|
|
1289
|
+
throw new Error("Agent not found");
|
|
1290
|
+
}
|
|
1291
|
+
const messagesIdsInRun = agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === runId).map((msg) => msg.id);
|
|
1292
|
+
const messageIndex = agent.messages.findIndex((msg) => msg.id === message.id) ?? 0;
|
|
1293
|
+
const messageIndexInRun = Math.min(messagesIdsInRun.indexOf(message.id), 0);
|
|
1294
|
+
const numberOfMessagesInRun = messagesIdsInRun.length;
|
|
1295
|
+
const stateSnapshot = copilotkit.getStateByRun(agentId, threadId, runId);
|
|
1296
|
+
let result = null;
|
|
1297
|
+
for (const renderer of customMessageRenderers) {
|
|
1298
|
+
if (!renderer.render) {
|
|
1299
|
+
continue;
|
|
1300
|
+
}
|
|
1301
|
+
const Component = renderer.render;
|
|
1302
|
+
result = /* @__PURE__ */ jsx10(
|
|
1303
|
+
Component,
|
|
1304
|
+
{
|
|
1305
|
+
message,
|
|
1306
|
+
position,
|
|
1307
|
+
runId,
|
|
1308
|
+
messageIndex,
|
|
1309
|
+
messageIndexInRun,
|
|
1310
|
+
numberOfMessagesInRun,
|
|
1311
|
+
agentId,
|
|
1312
|
+
stateSnapshot
|
|
1313
|
+
},
|
|
1314
|
+
`${runId}-${message.id}-${position}`
|
|
1315
|
+
);
|
|
1316
|
+
if (result) {
|
|
1317
|
+
break;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return result;
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1175
1324
|
// src/hooks/use-frontend-tool.tsx
|
|
1176
|
-
import { useEffect as
|
|
1325
|
+
import { useEffect as useEffect6 } from "react";
|
|
1177
1326
|
function useFrontendTool(tool) {
|
|
1178
|
-
const { copilotkit
|
|
1179
|
-
|
|
1327
|
+
const { copilotkit } = useCopilotKit();
|
|
1328
|
+
useEffect6(() => {
|
|
1180
1329
|
const name = tool.name;
|
|
1181
1330
|
if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
|
|
1182
1331
|
console.warn(
|
|
@@ -1186,37 +1335,37 @@ function useFrontendTool(tool) {
|
|
|
1186
1335
|
}
|
|
1187
1336
|
copilotkit.addTool(tool);
|
|
1188
1337
|
if (tool.render) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1338
|
+
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
1339
|
+
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
1340
|
+
const mergedMap = /* @__PURE__ */ new Map();
|
|
1341
|
+
for (const rc of currentRenderToolCalls) {
|
|
1342
|
+
mergedMap.set(keyOf(rc), rc);
|
|
1343
|
+
}
|
|
1344
|
+
const newEntry = {
|
|
1345
|
+
name,
|
|
1346
|
+
args: tool.parameters,
|
|
1347
|
+
agentId: tool.agentId,
|
|
1348
|
+
render: tool.render
|
|
1349
|
+
};
|
|
1350
|
+
mergedMap.set(keyOf(newEntry), newEntry);
|
|
1351
|
+
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
1203
1352
|
}
|
|
1204
1353
|
return () => {
|
|
1205
1354
|
copilotkit.removeTool(name, tool.agentId);
|
|
1206
1355
|
};
|
|
1207
|
-
}, [tool.name, copilotkit
|
|
1356
|
+
}, [tool.name, copilotkit]);
|
|
1208
1357
|
}
|
|
1209
1358
|
|
|
1210
1359
|
// src/hooks/use-human-in-the-loop.tsx
|
|
1211
|
-
import { useState as useState5, useCallback as useCallback2, useRef as
|
|
1212
|
-
import
|
|
1360
|
+
import { useState as useState5, useCallback as useCallback2, useRef as useRef5, useEffect as useEffect7 } from "react";
|
|
1361
|
+
import React7 from "react";
|
|
1213
1362
|
function useHumanInTheLoop(tool) {
|
|
1363
|
+
const { copilotkit } = useCopilotKit();
|
|
1214
1364
|
const [status, setStatus] = useState5(
|
|
1215
1365
|
"inProgress"
|
|
1216
1366
|
);
|
|
1217
|
-
const statusRef =
|
|
1218
|
-
const resolvePromiseRef =
|
|
1219
|
-
const { setCurrentRenderToolCalls } = useCopilotKit();
|
|
1367
|
+
const statusRef = useRef5(status);
|
|
1368
|
+
const resolvePromiseRef = useRef5(null);
|
|
1220
1369
|
statusRef.current = status;
|
|
1221
1370
|
const respond = useCallback2(async (result) => {
|
|
1222
1371
|
if (resolvePromiseRef.current) {
|
|
@@ -1242,7 +1391,7 @@ function useHumanInTheLoop(tool) {
|
|
|
1242
1391
|
description: tool.description || "",
|
|
1243
1392
|
respond: void 0
|
|
1244
1393
|
};
|
|
1245
|
-
return
|
|
1394
|
+
return React7.createElement(ToolComponent, enhancedProps);
|
|
1246
1395
|
} else if (currentStatus === "executing" && props.status === "executing") {
|
|
1247
1396
|
const enhancedProps = {
|
|
1248
1397
|
...props,
|
|
@@ -1250,7 +1399,7 @@ function useHumanInTheLoop(tool) {
|
|
|
1250
1399
|
description: tool.description || "",
|
|
1251
1400
|
respond
|
|
1252
1401
|
};
|
|
1253
|
-
return
|
|
1402
|
+
return React7.createElement(ToolComponent, enhancedProps);
|
|
1254
1403
|
} else if (currentStatus === "complete" && props.status === "complete") {
|
|
1255
1404
|
const enhancedProps = {
|
|
1256
1405
|
...props,
|
|
@@ -1258,9 +1407,9 @@ function useHumanInTheLoop(tool) {
|
|
|
1258
1407
|
description: tool.description || "",
|
|
1259
1408
|
respond: void 0
|
|
1260
1409
|
};
|
|
1261
|
-
return
|
|
1410
|
+
return React7.createElement(ToolComponent, enhancedProps);
|
|
1262
1411
|
}
|
|
1263
|
-
return
|
|
1412
|
+
return React7.createElement(ToolComponent, props);
|
|
1264
1413
|
},
|
|
1265
1414
|
[tool.render, tool.name, tool.description, respond]
|
|
1266
1415
|
);
|
|
@@ -1270,19 +1419,20 @@ function useHumanInTheLoop(tool) {
|
|
|
1270
1419
|
render: RenderComponent
|
|
1271
1420
|
};
|
|
1272
1421
|
useFrontendTool(frontendTool);
|
|
1273
|
-
|
|
1422
|
+
useEffect7(() => {
|
|
1274
1423
|
return () => {
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
)
|
|
1424
|
+
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
1425
|
+
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
1426
|
+
const filtered = currentRenderToolCalls.filter(
|
|
1427
|
+
(rc) => keyOf(rc) !== keyOf({ name: tool.name, agentId: tool.agentId })
|
|
1279
1428
|
);
|
|
1429
|
+
copilotkit.setRenderToolCalls(filtered);
|
|
1280
1430
|
};
|
|
1281
|
-
}, [
|
|
1431
|
+
}, [copilotkit, tool.name, tool.agentId]);
|
|
1282
1432
|
}
|
|
1283
1433
|
|
|
1284
1434
|
// src/hooks/use-agent.tsx
|
|
1285
|
-
import { useMemo as useMemo3, useEffect as
|
|
1435
|
+
import { useMemo as useMemo3, useEffect as useEffect8, useReducer as useReducer2 } from "react";
|
|
1286
1436
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID3 } from "@copilotkitnext/shared";
|
|
1287
1437
|
var ALL_UPDATES = [
|
|
1288
1438
|
"OnMessagesChanged" /* OnMessagesChanged */,
|
|
@@ -1305,7 +1455,7 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
1305
1455
|
copilotkit.runtimeConnectionStatus,
|
|
1306
1456
|
copilotkit
|
|
1307
1457
|
]);
|
|
1308
|
-
|
|
1458
|
+
useEffect8(() => {
|
|
1309
1459
|
if (!agent) {
|
|
1310
1460
|
return;
|
|
1311
1461
|
}
|
|
@@ -1343,11 +1493,11 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
1343
1493
|
}
|
|
1344
1494
|
|
|
1345
1495
|
// src/hooks/use-agent-context.tsx
|
|
1346
|
-
import { useEffect as
|
|
1496
|
+
import { useEffect as useEffect9 } from "react";
|
|
1347
1497
|
function useAgentContext(context) {
|
|
1348
1498
|
const { description, value } = context;
|
|
1349
1499
|
const { copilotkit } = useCopilotKit();
|
|
1350
|
-
|
|
1500
|
+
useEffect9(() => {
|
|
1351
1501
|
if (!copilotkit) return;
|
|
1352
1502
|
const id = copilotkit.addContext(context);
|
|
1353
1503
|
return () => {
|
|
@@ -1357,7 +1507,7 @@ function useAgentContext(context) {
|
|
|
1357
1507
|
}
|
|
1358
1508
|
|
|
1359
1509
|
// src/hooks/use-suggestions.tsx
|
|
1360
|
-
import { useCallback as useCallback3, useEffect as
|
|
1510
|
+
import { useCallback as useCallback3, useEffect as useEffect10, useMemo as useMemo4, useState as useState6 } from "react";
|
|
1361
1511
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4 } from "@copilotkitnext/shared";
|
|
1362
1512
|
function useSuggestions({ agentId } = {}) {
|
|
1363
1513
|
const { copilotkit } = useCopilotKit();
|
|
@@ -1371,12 +1521,12 @@ function useSuggestions({ agentId } = {}) {
|
|
|
1371
1521
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
1372
1522
|
return result.isLoading;
|
|
1373
1523
|
});
|
|
1374
|
-
|
|
1524
|
+
useEffect10(() => {
|
|
1375
1525
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
1376
1526
|
setSuggestions(result.suggestions);
|
|
1377
1527
|
setIsLoading(result.isLoading);
|
|
1378
1528
|
}, [copilotkit, resolvedAgentId]);
|
|
1379
|
-
|
|
1529
|
+
useEffect10(() => {
|
|
1380
1530
|
const unsubscribe = copilotkit.subscribe({
|
|
1381
1531
|
onSuggestionsChanged: ({ agentId: changedAgentId, suggestions: suggestions2 }) => {
|
|
1382
1532
|
if (changedAgentId !== resolvedAgentId) {
|
|
@@ -1421,7 +1571,7 @@ function useSuggestions({ agentId } = {}) {
|
|
|
1421
1571
|
}
|
|
1422
1572
|
|
|
1423
1573
|
// src/hooks/use-configure-suggestions.tsx
|
|
1424
|
-
import { useCallback as useCallback4, useEffect as
|
|
1574
|
+
import { useCallback as useCallback4, useEffect as useEffect11, useMemo as useMemo5, useRef as useRef6 } from "react";
|
|
1425
1575
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID5 } from "@copilotkitnext/shared";
|
|
1426
1576
|
var EMPTY_DEPS = [];
|
|
1427
1577
|
function useConfigureSuggestions(config, options) {
|
|
@@ -1430,7 +1580,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
1430
1580
|
const extraDeps = options?.deps ?? EMPTY_DEPS;
|
|
1431
1581
|
const resolvedConsumerAgentId = useMemo5(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID5, [chatConfig?.agentId]);
|
|
1432
1582
|
const rawConsumerAgentId = useMemo5(() => config ? config.consumerAgentId : void 0, [config]);
|
|
1433
|
-
const normalizationCacheRef =
|
|
1583
|
+
const normalizationCacheRef = useRef6({
|
|
1434
1584
|
serialized: null,
|
|
1435
1585
|
config: null
|
|
1436
1586
|
});
|
|
@@ -1464,9 +1614,9 @@ function useConfigureSuggestions(config, options) {
|
|
|
1464
1614
|
normalizationCacheRef.current = { serialized, config: built };
|
|
1465
1615
|
return { normalizedConfig: built, serializedConfig: serialized };
|
|
1466
1616
|
}, [config, resolvedConsumerAgentId, ...extraDeps]);
|
|
1467
|
-
const latestConfigRef =
|
|
1617
|
+
const latestConfigRef = useRef6(null);
|
|
1468
1618
|
latestConfigRef.current = normalizedConfig;
|
|
1469
|
-
const previousSerializedConfigRef =
|
|
1619
|
+
const previousSerializedConfigRef = useRef6(null);
|
|
1470
1620
|
const targetAgentId = useMemo5(() => {
|
|
1471
1621
|
if (!normalizedConfig) {
|
|
1472
1622
|
return resolvedConsumerAgentId;
|
|
@@ -1500,7 +1650,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
1500
1650
|
}
|
|
1501
1651
|
copilotkit.reloadSuggestions(targetAgentId);
|
|
1502
1652
|
}, [copilotkit, isGlobalConfig, normalizedConfig, targetAgentId]);
|
|
1503
|
-
|
|
1653
|
+
useEffect11(() => {
|
|
1504
1654
|
if (!serializedConfig || !latestConfigRef.current) {
|
|
1505
1655
|
return;
|
|
1506
1656
|
}
|
|
@@ -1510,7 +1660,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
1510
1660
|
copilotkit.removeSuggestionsConfig(id);
|
|
1511
1661
|
};
|
|
1512
1662
|
}, [copilotkit, serializedConfig, requestReload]);
|
|
1513
|
-
|
|
1663
|
+
useEffect11(() => {
|
|
1514
1664
|
if (!normalizedConfig) {
|
|
1515
1665
|
previousSerializedConfigRef.current = null;
|
|
1516
1666
|
return;
|
|
@@ -1523,7 +1673,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
1523
1673
|
}
|
|
1524
1674
|
requestReload();
|
|
1525
1675
|
}, [normalizedConfig, requestReload, serializedConfig]);
|
|
1526
|
-
|
|
1676
|
+
useEffect11(() => {
|
|
1527
1677
|
if (!normalizedConfig || extraDeps.length === 0) {
|
|
1528
1678
|
return;
|
|
1529
1679
|
}
|
|
@@ -1541,8 +1691,8 @@ function normalizeStaticSuggestions(suggestions) {
|
|
|
1541
1691
|
}
|
|
1542
1692
|
|
|
1543
1693
|
// src/components/chat/CopilotChatToolCallsView.tsx
|
|
1544
|
-
import
|
|
1545
|
-
import { Fragment as Fragment2, jsx as
|
|
1694
|
+
import React8 from "react";
|
|
1695
|
+
import { Fragment as Fragment2, jsx as jsx11 } from "react/jsx-runtime";
|
|
1546
1696
|
function CopilotChatToolCallsView({
|
|
1547
1697
|
message,
|
|
1548
1698
|
messages = []
|
|
@@ -1551,11 +1701,11 @@ function CopilotChatToolCallsView({
|
|
|
1551
1701
|
if (!message.toolCalls || message.toolCalls.length === 0) {
|
|
1552
1702
|
return null;
|
|
1553
1703
|
}
|
|
1554
|
-
return /* @__PURE__ */
|
|
1704
|
+
return /* @__PURE__ */ jsx11(Fragment2, { children: message.toolCalls.map((toolCall) => {
|
|
1555
1705
|
const toolMessage = messages.find(
|
|
1556
1706
|
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
1557
1707
|
);
|
|
1558
|
-
return /* @__PURE__ */
|
|
1708
|
+
return /* @__PURE__ */ jsx11(React8.Fragment, { children: renderToolCall({
|
|
1559
1709
|
toolCall,
|
|
1560
1710
|
toolMessage
|
|
1561
1711
|
}) }, toolCall.id);
|
|
@@ -1564,7 +1714,7 @@ function CopilotChatToolCallsView({
|
|
|
1564
1714
|
var CopilotChatToolCallsView_default = CopilotChatToolCallsView;
|
|
1565
1715
|
|
|
1566
1716
|
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
1567
|
-
import { Fragment as Fragment3, jsx as
|
|
1717
|
+
import { Fragment as Fragment3, jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1568
1718
|
function CopilotChatAssistantMessage({
|
|
1569
1719
|
message,
|
|
1570
1720
|
messages,
|
|
@@ -1641,7 +1791,7 @@ function CopilotChatAssistantMessage({
|
|
|
1641
1791
|
toolbar,
|
|
1642
1792
|
CopilotChatAssistantMessage.Toolbar,
|
|
1643
1793
|
{
|
|
1644
|
-
children: /* @__PURE__ */
|
|
1794
|
+
children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-1", children: [
|
|
1645
1795
|
boundCopyButton,
|
|
1646
1796
|
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
1647
1797
|
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
@@ -1662,7 +1812,7 @@ function CopilotChatAssistantMessage({
|
|
|
1662
1812
|
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
1663
1813
|
const shouldShowToolbar = toolbarVisible && hasContent;
|
|
1664
1814
|
if (children) {
|
|
1665
|
-
return /* @__PURE__ */
|
|
1815
|
+
return /* @__PURE__ */ jsx12(Fragment3, { children: children({
|
|
1666
1816
|
markdownRenderer: boundMarkdownRenderer,
|
|
1667
1817
|
toolbar: boundToolbar,
|
|
1668
1818
|
toolCallsView: boundToolCallsView,
|
|
@@ -1682,7 +1832,7 @@ function CopilotChatAssistantMessage({
|
|
|
1682
1832
|
toolbarVisible: shouldShowToolbar
|
|
1683
1833
|
}) });
|
|
1684
1834
|
}
|
|
1685
|
-
return /* @__PURE__ */
|
|
1835
|
+
return /* @__PURE__ */ jsxs5(
|
|
1686
1836
|
"div",
|
|
1687
1837
|
{
|
|
1688
1838
|
className: twMerge4(
|
|
@@ -1704,7 +1854,7 @@ function CopilotChatAssistantMessage({
|
|
|
1704
1854
|
children,
|
|
1705
1855
|
...props
|
|
1706
1856
|
}) => {
|
|
1707
|
-
return /* @__PURE__ */
|
|
1857
|
+
return /* @__PURE__ */ jsx12(
|
|
1708
1858
|
"code",
|
|
1709
1859
|
{
|
|
1710
1860
|
className: "px-[4.8px] py-[2.5px] bg-[rgb(236,236,236)] dark:bg-gray-800 rounded text-sm font-mono font-medium! text-foreground!",
|
|
@@ -1737,10 +1887,10 @@ function CopilotChatAssistantMessage({
|
|
|
1737
1887
|
console.error("Failed to copy code:", err);
|
|
1738
1888
|
}
|
|
1739
1889
|
};
|
|
1740
|
-
return /* @__PURE__ */
|
|
1741
|
-
/* @__PURE__ */
|
|
1742
|
-
language && /* @__PURE__ */
|
|
1743
|
-
/* @__PURE__ */
|
|
1890
|
+
return /* @__PURE__ */ jsxs5("div", { className: "relative", children: [
|
|
1891
|
+
/* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-between px-4 pr-3 py-3 text-xs", children: [
|
|
1892
|
+
language && /* @__PURE__ */ jsx12("span", { className: "font-regular text-muted-foreground dark:text-white", children: language }),
|
|
1893
|
+
/* @__PURE__ */ jsxs5(
|
|
1744
1894
|
"button",
|
|
1745
1895
|
{
|
|
1746
1896
|
className: cn(
|
|
@@ -1749,13 +1899,13 @@ function CopilotChatAssistantMessage({
|
|
|
1749
1899
|
onClick: copyToClipboard,
|
|
1750
1900
|
title: copied ? labels.assistantMessageToolbarCopyCodeCopiedLabel : `${labels.assistantMessageToolbarCopyCodeLabel} code`,
|
|
1751
1901
|
children: [
|
|
1752
|
-
copied ? /* @__PURE__ */
|
|
1753
|
-
/* @__PURE__ */
|
|
1902
|
+
copied ? /* @__PURE__ */ jsx12(Check2, { className: "h-[10px]! w-[10px]!" }) : /* @__PURE__ */ jsx12(Copy, { className: "h-[10px]! w-[10px]!" }),
|
|
1903
|
+
/* @__PURE__ */ jsx12("span", { className: "text-[11px]", children: copied ? labels.assistantMessageToolbarCopyCodeCopiedLabel : labels.assistantMessageToolbarCopyCodeLabel })
|
|
1754
1904
|
]
|
|
1755
1905
|
}
|
|
1756
1906
|
)
|
|
1757
1907
|
] }),
|
|
1758
|
-
/* @__PURE__ */
|
|
1908
|
+
/* @__PURE__ */ jsx12(
|
|
1759
1909
|
"pre",
|
|
1760
1910
|
{
|
|
1761
1911
|
className: cn(
|
|
@@ -1768,7 +1918,7 @@ function CopilotChatAssistantMessage({
|
|
|
1768
1918
|
)
|
|
1769
1919
|
] });
|
|
1770
1920
|
};
|
|
1771
|
-
CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className }) => /* @__PURE__ */
|
|
1921
|
+
CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className }) => /* @__PURE__ */ jsx12("div", { className, children: /* @__PURE__ */ jsx12(
|
|
1772
1922
|
MarkdownHooks,
|
|
1773
1923
|
{
|
|
1774
1924
|
remarkPlugins: [remarkGfm, remarkMath],
|
|
@@ -1791,9 +1941,9 @@ function CopilotChatAssistantMessage({
|
|
|
1791
1941
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1792
1942
|
code: ({ className: className2, children, ...props }) => {
|
|
1793
1943
|
if (typeof children === "string") {
|
|
1794
|
-
return /* @__PURE__ */
|
|
1944
|
+
return /* @__PURE__ */ jsx12(InlineCode, { ...props, children });
|
|
1795
1945
|
}
|
|
1796
|
-
return /* @__PURE__ */
|
|
1946
|
+
return /* @__PURE__ */ jsx12("code", { className: className2, ...props, children });
|
|
1797
1947
|
}
|
|
1798
1948
|
},
|
|
1799
1949
|
children: completePartialMarkdown(content || "")
|
|
@@ -1802,7 +1952,7 @@ function CopilotChatAssistantMessage({
|
|
|
1802
1952
|
CopilotChatAssistantMessage2.Toolbar = ({
|
|
1803
1953
|
className,
|
|
1804
1954
|
...props
|
|
1805
|
-
}) => /* @__PURE__ */
|
|
1955
|
+
}) => /* @__PURE__ */ jsx12(
|
|
1806
1956
|
"div",
|
|
1807
1957
|
{
|
|
1808
1958
|
className: twMerge4(
|
|
@@ -1813,8 +1963,8 @@ function CopilotChatAssistantMessage({
|
|
|
1813
1963
|
}
|
|
1814
1964
|
);
|
|
1815
1965
|
CopilotChatAssistantMessage2.ToolbarButton = ({ title, children, ...props }) => {
|
|
1816
|
-
return /* @__PURE__ */
|
|
1817
|
-
/* @__PURE__ */
|
|
1966
|
+
return /* @__PURE__ */ jsxs5(Tooltip, { children: [
|
|
1967
|
+
/* @__PURE__ */ jsx12(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx12(
|
|
1818
1968
|
Button,
|
|
1819
1969
|
{
|
|
1820
1970
|
type: "button",
|
|
@@ -1824,7 +1974,7 @@ function CopilotChatAssistantMessage({
|
|
|
1824
1974
|
children
|
|
1825
1975
|
}
|
|
1826
1976
|
) }),
|
|
1827
|
-
/* @__PURE__ */
|
|
1977
|
+
/* @__PURE__ */ jsx12(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx12("p", { children: title }) })
|
|
1828
1978
|
] });
|
|
1829
1979
|
};
|
|
1830
1980
|
CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
@@ -1838,62 +1988,62 @@ function CopilotChatAssistantMessage({
|
|
|
1838
1988
|
onClick(event);
|
|
1839
1989
|
}
|
|
1840
1990
|
};
|
|
1841
|
-
return /* @__PURE__ */
|
|
1991
|
+
return /* @__PURE__ */ jsx12(
|
|
1842
1992
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1843
1993
|
{
|
|
1844
1994
|
title: title || labels.assistantMessageToolbarCopyMessageLabel,
|
|
1845
1995
|
onClick: handleClick,
|
|
1846
1996
|
className,
|
|
1847
1997
|
...props,
|
|
1848
|
-
children: copied ? /* @__PURE__ */
|
|
1998
|
+
children: copied ? /* @__PURE__ */ jsx12(Check2, { className: "size-[18px]" }) : /* @__PURE__ */ jsx12(Copy, { className: "size-[18px]" })
|
|
1849
1999
|
}
|
|
1850
2000
|
);
|
|
1851
2001
|
};
|
|
1852
2002
|
CopilotChatAssistantMessage2.ThumbsUpButton = ({ title, ...props }) => {
|
|
1853
2003
|
const config = useCopilotChatConfiguration();
|
|
1854
2004
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1855
|
-
return /* @__PURE__ */
|
|
2005
|
+
return /* @__PURE__ */ jsx12(
|
|
1856
2006
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1857
2007
|
{
|
|
1858
2008
|
title: title || labels.assistantMessageToolbarThumbsUpLabel,
|
|
1859
2009
|
...props,
|
|
1860
|
-
children: /* @__PURE__ */
|
|
2010
|
+
children: /* @__PURE__ */ jsx12(ThumbsUp, { className: "size-[18px]" })
|
|
1861
2011
|
}
|
|
1862
2012
|
);
|
|
1863
2013
|
};
|
|
1864
2014
|
CopilotChatAssistantMessage2.ThumbsDownButton = ({ title, ...props }) => {
|
|
1865
2015
|
const config = useCopilotChatConfiguration();
|
|
1866
2016
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1867
|
-
return /* @__PURE__ */
|
|
2017
|
+
return /* @__PURE__ */ jsx12(
|
|
1868
2018
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1869
2019
|
{
|
|
1870
2020
|
title: title || labels.assistantMessageToolbarThumbsDownLabel,
|
|
1871
2021
|
...props,
|
|
1872
|
-
children: /* @__PURE__ */
|
|
2022
|
+
children: /* @__PURE__ */ jsx12(ThumbsDown, { className: "size-[18px]" })
|
|
1873
2023
|
}
|
|
1874
2024
|
);
|
|
1875
2025
|
};
|
|
1876
2026
|
CopilotChatAssistantMessage2.ReadAloudButton = ({ title, ...props }) => {
|
|
1877
2027
|
const config = useCopilotChatConfiguration();
|
|
1878
2028
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1879
|
-
return /* @__PURE__ */
|
|
2029
|
+
return /* @__PURE__ */ jsx12(
|
|
1880
2030
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1881
2031
|
{
|
|
1882
2032
|
title: title || labels.assistantMessageToolbarReadAloudLabel,
|
|
1883
2033
|
...props,
|
|
1884
|
-
children: /* @__PURE__ */
|
|
2034
|
+
children: /* @__PURE__ */ jsx12(Volume2, { className: "size-[20px]" })
|
|
1885
2035
|
}
|
|
1886
2036
|
);
|
|
1887
2037
|
};
|
|
1888
2038
|
CopilotChatAssistantMessage2.RegenerateButton = ({ title, ...props }) => {
|
|
1889
2039
|
const config = useCopilotChatConfiguration();
|
|
1890
2040
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1891
|
-
return /* @__PURE__ */
|
|
2041
|
+
return /* @__PURE__ */ jsx12(
|
|
1892
2042
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1893
2043
|
{
|
|
1894
2044
|
title: title || labels.assistantMessageToolbarRegenerateLabel,
|
|
1895
2045
|
...props,
|
|
1896
|
-
children: /* @__PURE__ */
|
|
2046
|
+
children: /* @__PURE__ */ jsx12(RefreshCw, { className: "size-[18px]" })
|
|
1897
2047
|
}
|
|
1898
2048
|
);
|
|
1899
2049
|
};
|
|
@@ -1911,7 +2061,7 @@ var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
|
|
|
1911
2061
|
import { useState as useState8 } from "react";
|
|
1912
2062
|
import { Copy as Copy2, Check as Check3, Edit, ChevronLeft, ChevronRight } from "lucide-react";
|
|
1913
2063
|
import { twMerge as twMerge5 } from "tailwind-merge";
|
|
1914
|
-
import { Fragment as Fragment4, jsx as
|
|
2064
|
+
import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1915
2065
|
function CopilotChatUserMessage({
|
|
1916
2066
|
message,
|
|
1917
2067
|
onEditMessage,
|
|
@@ -1969,7 +2119,7 @@ function CopilotChatUserMessage({
|
|
|
1969
2119
|
);
|
|
1970
2120
|
const showBranchNavigation = numberOfBranches && numberOfBranches > 1 && onSwitchToBranch;
|
|
1971
2121
|
const BoundToolbar = renderSlot(toolbar, CopilotChatUserMessage.Toolbar, {
|
|
1972
|
-
children: /* @__PURE__ */
|
|
2122
|
+
children: /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-1 justify-end", children: [
|
|
1973
2123
|
additionalToolbarItems,
|
|
1974
2124
|
BoundCopyButton,
|
|
1975
2125
|
onEditMessage && BoundEditButton,
|
|
@@ -1977,7 +2127,7 @@ function CopilotChatUserMessage({
|
|
|
1977
2127
|
] })
|
|
1978
2128
|
});
|
|
1979
2129
|
if (children) {
|
|
1980
|
-
return /* @__PURE__ */
|
|
2130
|
+
return /* @__PURE__ */ jsx13(Fragment4, { children: children({
|
|
1981
2131
|
messageRenderer: BoundMessageRenderer,
|
|
1982
2132
|
toolbar: BoundToolbar,
|
|
1983
2133
|
copyButton: BoundCopyButton,
|
|
@@ -1989,7 +2139,7 @@ function CopilotChatUserMessage({
|
|
|
1989
2139
|
additionalToolbarItems
|
|
1990
2140
|
}) });
|
|
1991
2141
|
}
|
|
1992
|
-
return /* @__PURE__ */
|
|
2142
|
+
return /* @__PURE__ */ jsxs6(
|
|
1993
2143
|
"div",
|
|
1994
2144
|
{
|
|
1995
2145
|
className: twMerge5("flex flex-col items-end group pt-10", className),
|
|
@@ -2003,7 +2153,7 @@ function CopilotChatUserMessage({
|
|
|
2003
2153
|
);
|
|
2004
2154
|
}
|
|
2005
2155
|
((CopilotChatUserMessage2) => {
|
|
2006
|
-
CopilotChatUserMessage2.Container = ({ children, className, ...props }) => /* @__PURE__ */
|
|
2156
|
+
CopilotChatUserMessage2.Container = ({ children, className, ...props }) => /* @__PURE__ */ jsx13(
|
|
2007
2157
|
"div",
|
|
2008
2158
|
{
|
|
2009
2159
|
className: twMerge5("flex flex-col items-end group", className),
|
|
@@ -2011,7 +2161,7 @@ function CopilotChatUserMessage({
|
|
|
2011
2161
|
children
|
|
2012
2162
|
}
|
|
2013
2163
|
);
|
|
2014
|
-
CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */
|
|
2164
|
+
CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */ jsx13(
|
|
2015
2165
|
"div",
|
|
2016
2166
|
{
|
|
2017
2167
|
className: twMerge5(
|
|
@@ -2024,7 +2174,7 @@ function CopilotChatUserMessage({
|
|
|
2024
2174
|
CopilotChatUserMessage2.Toolbar = ({
|
|
2025
2175
|
className,
|
|
2026
2176
|
...props
|
|
2027
|
-
}) => /* @__PURE__ */
|
|
2177
|
+
}) => /* @__PURE__ */ jsx13(
|
|
2028
2178
|
"div",
|
|
2029
2179
|
{
|
|
2030
2180
|
className: twMerge5(
|
|
@@ -2035,8 +2185,8 @@ function CopilotChatUserMessage({
|
|
|
2035
2185
|
}
|
|
2036
2186
|
);
|
|
2037
2187
|
CopilotChatUserMessage2.ToolbarButton = ({ title, children, className, ...props }) => {
|
|
2038
|
-
return /* @__PURE__ */
|
|
2039
|
-
/* @__PURE__ */
|
|
2188
|
+
return /* @__PURE__ */ jsxs6(Tooltip, { children: [
|
|
2189
|
+
/* @__PURE__ */ jsx13(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx13(
|
|
2040
2190
|
Button,
|
|
2041
2191
|
{
|
|
2042
2192
|
type: "button",
|
|
@@ -2047,7 +2197,7 @@ function CopilotChatUserMessage({
|
|
|
2047
2197
|
children
|
|
2048
2198
|
}
|
|
2049
2199
|
) }),
|
|
2050
|
-
/* @__PURE__ */
|
|
2200
|
+
/* @__PURE__ */ jsx13(TooltipContent, { side: "bottom", children: /* @__PURE__ */ jsx13("p", { children: title }) })
|
|
2051
2201
|
] });
|
|
2052
2202
|
};
|
|
2053
2203
|
CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
@@ -2061,27 +2211,27 @@ function CopilotChatUserMessage({
|
|
|
2061
2211
|
onClick(event);
|
|
2062
2212
|
}
|
|
2063
2213
|
};
|
|
2064
|
-
return /* @__PURE__ */
|
|
2214
|
+
return /* @__PURE__ */ jsx13(
|
|
2065
2215
|
CopilotChatUserMessage2.ToolbarButton,
|
|
2066
2216
|
{
|
|
2067
2217
|
title: title || labels.userMessageToolbarCopyMessageLabel,
|
|
2068
2218
|
onClick: handleClick,
|
|
2069
2219
|
className,
|
|
2070
2220
|
...props,
|
|
2071
|
-
children: copied ? /* @__PURE__ */
|
|
2221
|
+
children: copied ? /* @__PURE__ */ jsx13(Check3, { className: "size-[18px]" }) : /* @__PURE__ */ jsx13(Copy2, { className: "size-[18px]" })
|
|
2072
2222
|
}
|
|
2073
2223
|
);
|
|
2074
2224
|
};
|
|
2075
2225
|
CopilotChatUserMessage2.EditButton = ({ className, title, ...props }) => {
|
|
2076
2226
|
const config = useCopilotChatConfiguration();
|
|
2077
2227
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2078
|
-
return /* @__PURE__ */
|
|
2228
|
+
return /* @__PURE__ */ jsx13(
|
|
2079
2229
|
CopilotChatUserMessage2.ToolbarButton,
|
|
2080
2230
|
{
|
|
2081
2231
|
title: title || labels.userMessageToolbarEditMessageLabel,
|
|
2082
2232
|
className,
|
|
2083
2233
|
...props,
|
|
2084
|
-
children: /* @__PURE__ */
|
|
2234
|
+
children: /* @__PURE__ */ jsx13(Edit, { className: "size-[18px]" })
|
|
2085
2235
|
}
|
|
2086
2236
|
);
|
|
2087
2237
|
};
|
|
@@ -2098,8 +2248,8 @@ function CopilotChatUserMessage({
|
|
|
2098
2248
|
}
|
|
2099
2249
|
const canGoPrev = currentBranch > 0;
|
|
2100
2250
|
const canGoNext = currentBranch < numberOfBranches - 1;
|
|
2101
|
-
return /* @__PURE__ */
|
|
2102
|
-
/* @__PURE__ */
|
|
2251
|
+
return /* @__PURE__ */ jsxs6("div", { className: twMerge5("flex items-center gap-1", className), ...props, children: [
|
|
2252
|
+
/* @__PURE__ */ jsx13(
|
|
2103
2253
|
Button,
|
|
2104
2254
|
{
|
|
2105
2255
|
type: "button",
|
|
@@ -2111,15 +2261,15 @@ function CopilotChatUserMessage({
|
|
|
2111
2261
|
}),
|
|
2112
2262
|
disabled: !canGoPrev,
|
|
2113
2263
|
className: "h-6 w-6 p-0",
|
|
2114
|
-
children: /* @__PURE__ */
|
|
2264
|
+
children: /* @__PURE__ */ jsx13(ChevronLeft, { className: "size-[20px]" })
|
|
2115
2265
|
}
|
|
2116
2266
|
),
|
|
2117
|
-
/* @__PURE__ */
|
|
2267
|
+
/* @__PURE__ */ jsxs6("span", { className: "text-sm text-muted-foreground px-0 font-medium", children: [
|
|
2118
2268
|
currentBranch + 1,
|
|
2119
2269
|
"/",
|
|
2120
2270
|
numberOfBranches
|
|
2121
2271
|
] }),
|
|
2122
|
-
/* @__PURE__ */
|
|
2272
|
+
/* @__PURE__ */ jsx13(
|
|
2123
2273
|
Button,
|
|
2124
2274
|
{
|
|
2125
2275
|
type: "button",
|
|
@@ -2131,7 +2281,7 @@ function CopilotChatUserMessage({
|
|
|
2131
2281
|
}),
|
|
2132
2282
|
disabled: !canGoNext,
|
|
2133
2283
|
className: "h-6 w-6 p-0",
|
|
2134
|
-
children: /* @__PURE__ */
|
|
2284
|
+
children: /* @__PURE__ */ jsx13(ChevronRight, { className: "size-[20px]" })
|
|
2135
2285
|
}
|
|
2136
2286
|
)
|
|
2137
2287
|
] });
|
|
@@ -2147,14 +2297,14 @@ CopilotChatUserMessage.BranchNavigation.displayName = "CopilotChatUserMessage.Br
|
|
|
2147
2297
|
var CopilotChatUserMessage_default = CopilotChatUserMessage;
|
|
2148
2298
|
|
|
2149
2299
|
// src/components/chat/CopilotChatSuggestionPill.tsx
|
|
2150
|
-
import
|
|
2300
|
+
import React9 from "react";
|
|
2151
2301
|
import { Loader2 } from "lucide-react";
|
|
2152
|
-
import { jsx as
|
|
2302
|
+
import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2153
2303
|
var baseClasses = "group inline-flex h-8 items-center gap-1.5 rounded-full border border-border/60 bg-background px-3 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";
|
|
2154
2304
|
var labelClasses = "whitespace-nowrap font-medium leading-none";
|
|
2155
|
-
var CopilotChatSuggestionPill =
|
|
2305
|
+
var CopilotChatSuggestionPill = React9.forwardRef(function CopilotChatSuggestionPill2({ className, children, icon, isLoading, type, ...props }, ref) {
|
|
2156
2306
|
const showIcon = !isLoading && icon;
|
|
2157
|
-
return /* @__PURE__ */
|
|
2307
|
+
return /* @__PURE__ */ jsxs7(
|
|
2158
2308
|
"button",
|
|
2159
2309
|
{
|
|
2160
2310
|
ref,
|
|
@@ -2165,8 +2315,8 @@ var CopilotChatSuggestionPill = React8.forwardRef(function CopilotChatSuggestion
|
|
|
2165
2315
|
disabled: isLoading || props.disabled,
|
|
2166
2316
|
...props,
|
|
2167
2317
|
children: [
|
|
2168
|
-
isLoading ? /* @__PURE__ */
|
|
2169
|
-
/* @__PURE__ */
|
|
2318
|
+
isLoading ? /* @__PURE__ */ jsx14("span", { className: "flex h-4 w-4 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ jsx14(Loader2, { className: "h-4 w-4 animate-spin", "aria-hidden": "true" }) }) : showIcon && /* @__PURE__ */ jsx14("span", { className: "flex h-4 w-4 items-center justify-center text-muted-foreground", children: icon }),
|
|
2319
|
+
/* @__PURE__ */ jsx14("span", { className: labelClasses, children })
|
|
2170
2320
|
]
|
|
2171
2321
|
}
|
|
2172
2322
|
);
|
|
@@ -2175,10 +2325,10 @@ CopilotChatSuggestionPill.displayName = "CopilotChatSuggestionPill";
|
|
|
2175
2325
|
var CopilotChatSuggestionPill_default = CopilotChatSuggestionPill;
|
|
2176
2326
|
|
|
2177
2327
|
// src/components/chat/CopilotChatSuggestionView.tsx
|
|
2178
|
-
import
|
|
2179
|
-
import { Fragment as Fragment5, jsx as
|
|
2180
|
-
var DefaultContainer =
|
|
2181
|
-
return /* @__PURE__ */
|
|
2328
|
+
import React10 from "react";
|
|
2329
|
+
import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2330
|
+
var DefaultContainer = React10.forwardRef(function DefaultContainer2({ className, ...props }, ref) {
|
|
2331
|
+
return /* @__PURE__ */ jsx15(
|
|
2182
2332
|
"div",
|
|
2183
2333
|
{
|
|
2184
2334
|
ref,
|
|
@@ -2190,7 +2340,7 @@ var DefaultContainer = React9.forwardRef(function DefaultContainer2({ className,
|
|
|
2190
2340
|
}
|
|
2191
2341
|
);
|
|
2192
2342
|
});
|
|
2193
|
-
var CopilotChatSuggestionView =
|
|
2343
|
+
var CopilotChatSuggestionView = React10.forwardRef(function CopilotChatSuggestionView2({
|
|
2194
2344
|
suggestions,
|
|
2195
2345
|
onSelectSuggestion,
|
|
2196
2346
|
loadingIndexes,
|
|
@@ -2200,7 +2350,7 @@ var CopilotChatSuggestionView = React9.forwardRef(function CopilotChatSuggestion
|
|
|
2200
2350
|
children,
|
|
2201
2351
|
...restProps
|
|
2202
2352
|
}, ref) {
|
|
2203
|
-
const loadingSet =
|
|
2353
|
+
const loadingSet = React10.useMemo(() => {
|
|
2204
2354
|
if (!loadingIndexes || loadingIndexes.length === 0) {
|
|
2205
2355
|
return /* @__PURE__ */ new Set();
|
|
2206
2356
|
}
|
|
@@ -2219,11 +2369,11 @@ var CopilotChatSuggestionView = React9.forwardRef(function CopilotChatSuggestion
|
|
|
2219
2369
|
type: "button",
|
|
2220
2370
|
onClick: () => onSelectSuggestion?.(suggestion, index)
|
|
2221
2371
|
});
|
|
2222
|
-
return
|
|
2372
|
+
return React10.cloneElement(pill, {
|
|
2223
2373
|
key: `${suggestion.title}-${index}`
|
|
2224
2374
|
});
|
|
2225
2375
|
});
|
|
2226
|
-
const boundContainer =
|
|
2376
|
+
const boundContainer = React10.cloneElement(
|
|
2227
2377
|
ContainerElement,
|
|
2228
2378
|
void 0,
|
|
2229
2379
|
suggestionElements
|
|
@@ -2234,7 +2384,7 @@ var CopilotChatSuggestionView = React9.forwardRef(function CopilotChatSuggestion
|
|
|
2234
2384
|
isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
|
|
2235
2385
|
type: "button"
|
|
2236
2386
|
});
|
|
2237
|
-
return /* @__PURE__ */
|
|
2387
|
+
return /* @__PURE__ */ jsx15(Fragment5, { children: children({
|
|
2238
2388
|
container: boundContainer,
|
|
2239
2389
|
suggestion: sampleSuggestion,
|
|
2240
2390
|
suggestions,
|
|
@@ -2245,7 +2395,7 @@ var CopilotChatSuggestionView = React9.forwardRef(function CopilotChatSuggestion
|
|
|
2245
2395
|
}) });
|
|
2246
2396
|
}
|
|
2247
2397
|
if (children) {
|
|
2248
|
-
return /* @__PURE__ */
|
|
2398
|
+
return /* @__PURE__ */ jsxs8(Fragment5, { children: [
|
|
2249
2399
|
boundContainer,
|
|
2250
2400
|
children
|
|
2251
2401
|
] });
|
|
@@ -2257,7 +2407,7 @@ var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
|
|
|
2257
2407
|
|
|
2258
2408
|
// src/components/chat/CopilotChatMessageView.tsx
|
|
2259
2409
|
import { twMerge as twMerge6 } from "tailwind-merge";
|
|
2260
|
-
import { jsx as
|
|
2410
|
+
import { jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2261
2411
|
function CopilotChatMessageView({
|
|
2262
2412
|
messages = [],
|
|
2263
2413
|
assistantMessage,
|
|
@@ -2268,41 +2418,57 @@ function CopilotChatMessageView({
|
|
|
2268
2418
|
className,
|
|
2269
2419
|
...props
|
|
2270
2420
|
}) {
|
|
2271
|
-
const
|
|
2421
|
+
const renderCustomMessage = useRenderCustomMessages();
|
|
2422
|
+
const messageElements = messages.flatMap((message) => {
|
|
2423
|
+
const elements = [];
|
|
2424
|
+
if (renderCustomMessage) {
|
|
2425
|
+
elements.push(
|
|
2426
|
+
renderCustomMessage({
|
|
2427
|
+
message,
|
|
2428
|
+
position: "before"
|
|
2429
|
+
})
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2272
2432
|
if (message.role === "assistant") {
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2433
|
+
elements.push(
|
|
2434
|
+
renderSlot(assistantMessage, CopilotChatAssistantMessage_default, {
|
|
2435
|
+
key: message.id,
|
|
2436
|
+
message,
|
|
2437
|
+
messages,
|
|
2438
|
+
isRunning
|
|
2439
|
+
})
|
|
2440
|
+
);
|
|
2279
2441
|
} else if (message.role === "user") {
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2442
|
+
elements.push(
|
|
2443
|
+
renderSlot(userMessage, CopilotChatUserMessage_default, {
|
|
2444
|
+
key: message.id,
|
|
2445
|
+
message
|
|
2446
|
+
})
|
|
2447
|
+
);
|
|
2284
2448
|
}
|
|
2285
|
-
|
|
2449
|
+
if (renderCustomMessage) {
|
|
2450
|
+
elements.push(
|
|
2451
|
+
renderCustomMessage({
|
|
2452
|
+
message,
|
|
2453
|
+
position: "after"
|
|
2454
|
+
})
|
|
2455
|
+
);
|
|
2456
|
+
}
|
|
2457
|
+
return elements;
|
|
2286
2458
|
}).filter(Boolean);
|
|
2287
2459
|
if (children) {
|
|
2288
2460
|
return children({ messageElements, messages, isRunning });
|
|
2289
2461
|
}
|
|
2290
|
-
return /* @__PURE__ */
|
|
2462
|
+
return /* @__PURE__ */ jsxs9("div", { className: twMerge6("flex flex-col", className), ...props, children: [
|
|
2291
2463
|
messageElements,
|
|
2292
2464
|
isRunning && renderSlot(cursor, CopilotChatMessageView.Cursor, {})
|
|
2293
2465
|
] });
|
|
2294
2466
|
}
|
|
2295
|
-
CopilotChatMessageView.Cursor = function Cursor({
|
|
2296
|
-
|
|
2297
|
-
...props
|
|
2298
|
-
}) {
|
|
2299
|
-
return /* @__PURE__ */ jsx14(
|
|
2467
|
+
CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
2468
|
+
return /* @__PURE__ */ jsx16(
|
|
2300
2469
|
"div",
|
|
2301
2470
|
{
|
|
2302
|
-
className: twMerge6(
|
|
2303
|
-
"w-[11px] h-[11px] rounded-full bg-foreground animate-pulse-cursor ml-1",
|
|
2304
|
-
className
|
|
2305
|
-
),
|
|
2471
|
+
className: twMerge6("w-[11px] h-[11px] rounded-full bg-foreground animate-pulse-cursor ml-1", className),
|
|
2306
2472
|
...props
|
|
2307
2473
|
}
|
|
2308
2474
|
);
|
|
@@ -2310,11 +2476,11 @@ CopilotChatMessageView.Cursor = function Cursor({
|
|
|
2310
2476
|
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
2311
2477
|
|
|
2312
2478
|
// src/components/chat/CopilotChatView.tsx
|
|
2313
|
-
import
|
|
2479
|
+
import React11, { useRef as useRef7, useState as useState9, useEffect as useEffect12 } from "react";
|
|
2314
2480
|
import { twMerge as twMerge7 } from "tailwind-merge";
|
|
2315
2481
|
import { StickToBottom, useStickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
|
|
2316
2482
|
import { ChevronDown } from "lucide-react";
|
|
2317
|
-
import { Fragment as Fragment6, jsx as
|
|
2483
|
+
import { Fragment as Fragment6, jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2318
2484
|
function CopilotChatView({
|
|
2319
2485
|
messageView,
|
|
2320
2486
|
input,
|
|
@@ -2335,11 +2501,11 @@ function CopilotChatView({
|
|
|
2335
2501
|
className,
|
|
2336
2502
|
...props
|
|
2337
2503
|
}) {
|
|
2338
|
-
const inputContainerRef =
|
|
2504
|
+
const inputContainerRef = useRef7(null);
|
|
2339
2505
|
const [inputContainerHeight, setInputContainerHeight] = useState9(0);
|
|
2340
2506
|
const [isResizing, setIsResizing] = useState9(false);
|
|
2341
|
-
const resizeTimeoutRef =
|
|
2342
|
-
|
|
2507
|
+
const resizeTimeoutRef = useRef7(null);
|
|
2508
|
+
useEffect12(() => {
|
|
2343
2509
|
const element = inputContainerRef.current;
|
|
2344
2510
|
if (!element) return;
|
|
2345
2511
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -2391,17 +2557,17 @@ function CopilotChatView({
|
|
|
2391
2557
|
scrollToBottomButton,
|
|
2392
2558
|
inputContainerHeight,
|
|
2393
2559
|
isResizing,
|
|
2394
|
-
children: /* @__PURE__ */
|
|
2560
|
+
children: /* @__PURE__ */ jsx17("div", { style: { paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px` }, children: /* @__PURE__ */ jsxs10("div", { className: "max-w-3xl mx-auto", children: [
|
|
2395
2561
|
BoundMessageView,
|
|
2396
|
-
hasSuggestions ? /* @__PURE__ */
|
|
2562
|
+
hasSuggestions ? /* @__PURE__ */ jsx17("div", { className: "px-4 sm:px-0 mt-4", children: BoundSuggestionView }) : null
|
|
2397
2563
|
] }) })
|
|
2398
2564
|
});
|
|
2399
2565
|
const BoundScrollToBottomButton = renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, {});
|
|
2400
2566
|
const BoundDisclaimer = renderSlot(disclaimer, CopilotChatView.Disclaimer, {});
|
|
2401
2567
|
const BoundInputContainer = renderSlot(inputContainer, CopilotChatView.InputContainer, {
|
|
2402
2568
|
ref: inputContainerRef,
|
|
2403
|
-
children: /* @__PURE__ */
|
|
2404
|
-
/* @__PURE__ */
|
|
2569
|
+
children: /* @__PURE__ */ jsxs10(Fragment6, { children: [
|
|
2570
|
+
/* @__PURE__ */ jsx17("div", { className: "max-w-3xl mx-auto py-0 px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 pointer-events-auto", children: BoundInput }),
|
|
2405
2571
|
BoundDisclaimer
|
|
2406
2572
|
] })
|
|
2407
2573
|
});
|
|
@@ -2414,10 +2580,10 @@ function CopilotChatView({
|
|
|
2414
2580
|
feather: BoundFeather,
|
|
2415
2581
|
inputContainer: BoundInputContainer,
|
|
2416
2582
|
disclaimer: BoundDisclaimer,
|
|
2417
|
-
suggestionView: BoundSuggestionView ?? /* @__PURE__ */
|
|
2583
|
+
suggestionView: BoundSuggestionView ?? /* @__PURE__ */ jsx17(Fragment6, {})
|
|
2418
2584
|
});
|
|
2419
2585
|
}
|
|
2420
|
-
return /* @__PURE__ */
|
|
2586
|
+
return /* @__PURE__ */ jsxs10("div", { className: twMerge7("relative h-full", className), ...props, children: [
|
|
2421
2587
|
BoundScrollView,
|
|
2422
2588
|
BoundFeather,
|
|
2423
2589
|
BoundInputContainer
|
|
@@ -2426,9 +2592,9 @@ function CopilotChatView({
|
|
|
2426
2592
|
((CopilotChatView2) => {
|
|
2427
2593
|
const ScrollContent = ({ children, scrollToBottomButton, inputContainerHeight, isResizing }) => {
|
|
2428
2594
|
const { isAtBottom, scrollToBottom } = useStickToBottomContext();
|
|
2429
|
-
return /* @__PURE__ */
|
|
2430
|
-
/* @__PURE__ */
|
|
2431
|
-
!isAtBottom && !isResizing && /* @__PURE__ */
|
|
2595
|
+
return /* @__PURE__ */ jsxs10(Fragment6, { children: [
|
|
2596
|
+
/* @__PURE__ */ jsx17(StickToBottom.Content, { className: "overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ jsx17("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8", children }) }),
|
|
2597
|
+
!isAtBottom && !isResizing && /* @__PURE__ */ jsx17(
|
|
2432
2598
|
"div",
|
|
2433
2599
|
{
|
|
2434
2600
|
className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
|
|
@@ -2454,10 +2620,10 @@ function CopilotChatView({
|
|
|
2454
2620
|
const [hasMounted, setHasMounted] = useState9(false);
|
|
2455
2621
|
const { scrollRef, contentRef, scrollToBottom } = useStickToBottom();
|
|
2456
2622
|
const [showScrollButton, setShowScrollButton] = useState9(false);
|
|
2457
|
-
|
|
2623
|
+
useEffect12(() => {
|
|
2458
2624
|
setHasMounted(true);
|
|
2459
2625
|
}, []);
|
|
2460
|
-
|
|
2626
|
+
useEffect12(() => {
|
|
2461
2627
|
if (autoScroll) return;
|
|
2462
2628
|
const scrollElement = scrollRef.current;
|
|
2463
2629
|
if (!scrollElement) return;
|
|
@@ -2475,10 +2641,10 @@ function CopilotChatView({
|
|
|
2475
2641
|
};
|
|
2476
2642
|
}, [scrollRef, autoScroll]);
|
|
2477
2643
|
if (!hasMounted) {
|
|
2478
|
-
return /* @__PURE__ */
|
|
2644
|
+
return /* @__PURE__ */ jsx17("div", { className: "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ jsx17("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8", children }) });
|
|
2479
2645
|
}
|
|
2480
2646
|
if (!autoScroll) {
|
|
2481
|
-
return /* @__PURE__ */
|
|
2647
|
+
return /* @__PURE__ */ jsxs10(
|
|
2482
2648
|
"div",
|
|
2483
2649
|
{
|
|
2484
2650
|
ref: scrollRef,
|
|
@@ -2488,8 +2654,8 @@ function CopilotChatView({
|
|
|
2488
2654
|
),
|
|
2489
2655
|
...props,
|
|
2490
2656
|
children: [
|
|
2491
|
-
/* @__PURE__ */
|
|
2492
|
-
showScrollButton && !isResizing && /* @__PURE__ */
|
|
2657
|
+
/* @__PURE__ */ jsx17("div", { ref: contentRef, className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8", children }),
|
|
2658
|
+
showScrollButton && !isResizing && /* @__PURE__ */ jsx17(
|
|
2493
2659
|
"div",
|
|
2494
2660
|
{
|
|
2495
2661
|
className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
|
|
@@ -2505,14 +2671,14 @@ function CopilotChatView({
|
|
|
2505
2671
|
}
|
|
2506
2672
|
);
|
|
2507
2673
|
}
|
|
2508
|
-
return /* @__PURE__ */
|
|
2674
|
+
return /* @__PURE__ */ jsx17(
|
|
2509
2675
|
StickToBottom,
|
|
2510
2676
|
{
|
|
2511
2677
|
className: cn("h-full max-h-full flex flex-col min-h-0 relative", className),
|
|
2512
2678
|
resize: "smooth",
|
|
2513
2679
|
initial: "smooth",
|
|
2514
2680
|
...props,
|
|
2515
|
-
children: /* @__PURE__ */
|
|
2681
|
+
children: /* @__PURE__ */ jsx17(
|
|
2516
2682
|
ScrollContent,
|
|
2517
2683
|
{
|
|
2518
2684
|
scrollToBottomButton,
|
|
@@ -2527,7 +2693,7 @@ function CopilotChatView({
|
|
|
2527
2693
|
CopilotChatView2.ScrollToBottomButton = ({
|
|
2528
2694
|
className,
|
|
2529
2695
|
...props
|
|
2530
|
-
}) => /* @__PURE__ */
|
|
2696
|
+
}) => /* @__PURE__ */ jsx17(
|
|
2531
2697
|
Button,
|
|
2532
2698
|
{
|
|
2533
2699
|
variant: "outline",
|
|
@@ -2541,10 +2707,10 @@ function CopilotChatView({
|
|
|
2541
2707
|
className
|
|
2542
2708
|
),
|
|
2543
2709
|
...props,
|
|
2544
|
-
children: /* @__PURE__ */
|
|
2710
|
+
children: /* @__PURE__ */ jsx17(ChevronDown, { className: "w-4 h-4 text-gray-600 dark:text-white" })
|
|
2545
2711
|
}
|
|
2546
2712
|
);
|
|
2547
|
-
CopilotChatView2.Feather = ({ className, style, ...props }) => /* @__PURE__ */
|
|
2713
|
+
CopilotChatView2.Feather = ({ className, style, ...props }) => /* @__PURE__ */ jsx17(
|
|
2548
2714
|
"div",
|
|
2549
2715
|
{
|
|
2550
2716
|
className: cn(
|
|
@@ -2557,12 +2723,12 @@ function CopilotChatView({
|
|
|
2557
2723
|
...props
|
|
2558
2724
|
}
|
|
2559
2725
|
);
|
|
2560
|
-
CopilotChatView2.InputContainer =
|
|
2726
|
+
CopilotChatView2.InputContainer = React11.forwardRef(({ children, className, ...props }, ref) => /* @__PURE__ */ jsx17("div", { ref, className: cn("absolute bottom-0 left-0 right-0 z-20 pointer-events-none", className), ...props, children }));
|
|
2561
2727
|
CopilotChatView2.InputContainer.displayName = "CopilotChatView.InputContainer";
|
|
2562
2728
|
CopilotChatView2.Disclaimer = ({ className, ...props }) => {
|
|
2563
2729
|
const config = useCopilotChatConfiguration();
|
|
2564
2730
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2565
|
-
return /* @__PURE__ */
|
|
2731
|
+
return /* @__PURE__ */ jsx17(
|
|
2566
2732
|
"div",
|
|
2567
2733
|
{
|
|
2568
2734
|
className: cn("text-center text-xs text-muted-foreground py-3 px-4 max-w-3xl mx-auto", className),
|
|
@@ -2576,10 +2742,10 @@ var CopilotChatView_default = CopilotChatView;
|
|
|
2576
2742
|
|
|
2577
2743
|
// src/components/chat/CopilotChat.tsx
|
|
2578
2744
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID6, randomUUID as randomUUID2 } from "@copilotkitnext/shared";
|
|
2579
|
-
import { useCallback as useCallback5, useEffect as
|
|
2745
|
+
import { useCallback as useCallback5, useEffect as useEffect13, useMemo as useMemo6 } from "react";
|
|
2580
2746
|
import { merge } from "ts-deepmerge";
|
|
2581
2747
|
import { AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
2582
|
-
import { jsx as
|
|
2748
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
2583
2749
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
|
|
2584
2750
|
const existingConfig = useCopilotChatConfiguration();
|
|
2585
2751
|
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID6;
|
|
@@ -2596,7 +2762,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
2596
2762
|
suggestionView: providedSuggestionView,
|
|
2597
2763
|
...restProps
|
|
2598
2764
|
} = props;
|
|
2599
|
-
|
|
2765
|
+
useEffect13(() => {
|
|
2600
2766
|
const connect = async (agent2) => {
|
|
2601
2767
|
try {
|
|
2602
2768
|
await copilotkit.connectAgent({ agent: agent2 });
|
|
@@ -2669,7 +2835,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
2669
2835
|
}
|
|
2670
2836
|
});
|
|
2671
2837
|
const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
|
|
2672
|
-
return /* @__PURE__ */
|
|
2838
|
+
return /* @__PURE__ */ jsx18(
|
|
2673
2839
|
CopilotChatConfigurationProvider,
|
|
2674
2840
|
{
|
|
2675
2841
|
agentId: resolvedAgentId,
|
|
@@ -2685,17 +2851,17 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
2685
2851
|
})(CopilotChat || (CopilotChat = {}));
|
|
2686
2852
|
|
|
2687
2853
|
// src/components/chat/CopilotChatToggleButton.tsx
|
|
2688
|
-
import
|
|
2854
|
+
import React12, { useState as useState10 } from "react";
|
|
2689
2855
|
import { MessageCircle, X as X2 } from "lucide-react";
|
|
2690
|
-
import { jsx as
|
|
2856
|
+
import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2691
2857
|
var DefaultOpenIcon = ({
|
|
2692
2858
|
className,
|
|
2693
2859
|
...props
|
|
2694
|
-
}) => /* @__PURE__ */
|
|
2860
|
+
}) => /* @__PURE__ */ jsx19(MessageCircle, { className: cn("h-6 w-6", className), strokeWidth: 1.75, fill: "currentColor", ...props });
|
|
2695
2861
|
var DefaultCloseIcon = ({
|
|
2696
2862
|
className,
|
|
2697
2863
|
...props
|
|
2698
|
-
}) => /* @__PURE__ */
|
|
2864
|
+
}) => /* @__PURE__ */ jsx19(X2, { className: cn("h-6 w-6", className), strokeWidth: 1.75, ...props });
|
|
2699
2865
|
DefaultOpenIcon.displayName = "CopilotChatToggleButton.OpenIcon";
|
|
2700
2866
|
DefaultCloseIcon.displayName = "CopilotChatToggleButton.CloseIcon";
|
|
2701
2867
|
var ICON_TRANSITION_STYLE = Object.freeze({
|
|
@@ -2712,7 +2878,7 @@ var BUTTON_BASE_CLASSES = cn(
|
|
|
2712
2878
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
2713
2879
|
"disabled:pointer-events-none disabled:opacity-60"
|
|
2714
2880
|
);
|
|
2715
|
-
var CopilotChatToggleButton =
|
|
2881
|
+
var CopilotChatToggleButton = React12.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
|
|
2716
2882
|
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
2717
2883
|
const configuration = useCopilotChatConfiguration();
|
|
2718
2884
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
@@ -2750,7 +2916,7 @@ var CopilotChatToggleButton = React11.forwardRef(function CopilotChatToggleButto
|
|
|
2750
2916
|
focusable: false
|
|
2751
2917
|
}
|
|
2752
2918
|
);
|
|
2753
|
-
const openIconElement = /* @__PURE__ */
|
|
2919
|
+
const openIconElement = /* @__PURE__ */ jsx19(
|
|
2754
2920
|
"span",
|
|
2755
2921
|
{
|
|
2756
2922
|
"aria-hidden": "true",
|
|
@@ -2764,7 +2930,7 @@ var CopilotChatToggleButton = React11.forwardRef(function CopilotChatToggleButto
|
|
|
2764
2930
|
children: renderedOpenIcon
|
|
2765
2931
|
}
|
|
2766
2932
|
);
|
|
2767
|
-
const closeIconElement = /* @__PURE__ */
|
|
2933
|
+
const closeIconElement = /* @__PURE__ */ jsx19(
|
|
2768
2934
|
"span",
|
|
2769
2935
|
{
|
|
2770
2936
|
"aria-hidden": "true",
|
|
@@ -2778,7 +2944,7 @@ var CopilotChatToggleButton = React11.forwardRef(function CopilotChatToggleButto
|
|
|
2778
2944
|
children: renderedCloseIcon
|
|
2779
2945
|
}
|
|
2780
2946
|
);
|
|
2781
|
-
return /* @__PURE__ */
|
|
2947
|
+
return /* @__PURE__ */ jsxs11(
|
|
2782
2948
|
"button",
|
|
2783
2949
|
{
|
|
2784
2950
|
ref,
|
|
@@ -2802,12 +2968,12 @@ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
|
2802
2968
|
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
2803
2969
|
|
|
2804
2970
|
// src/components/chat/CopilotSidebarView.tsx
|
|
2805
|
-
import { useEffect as
|
|
2971
|
+
import { useEffect as useEffect14, useRef as useRef8, useState as useState11 } from "react";
|
|
2806
2972
|
|
|
2807
2973
|
// src/components/chat/CopilotModalHeader.tsx
|
|
2808
2974
|
import { useCallback as useCallback6 } from "react";
|
|
2809
2975
|
import { X as X3 } from "lucide-react";
|
|
2810
|
-
import { jsx as
|
|
2976
|
+
import { jsx as jsx20, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
2811
2977
|
function CopilotModalHeader({
|
|
2812
2978
|
title,
|
|
2813
2979
|
titleContent,
|
|
@@ -2836,7 +3002,7 @@ function CopilotModalHeader({
|
|
|
2836
3002
|
...rest
|
|
2837
3003
|
});
|
|
2838
3004
|
}
|
|
2839
|
-
return /* @__PURE__ */
|
|
3005
|
+
return /* @__PURE__ */ jsx20(
|
|
2840
3006
|
"header",
|
|
2841
3007
|
{
|
|
2842
3008
|
"data-slot": "copilot-modal-header",
|
|
@@ -2846,17 +3012,17 @@ function CopilotModalHeader({
|
|
|
2846
3012
|
className
|
|
2847
3013
|
),
|
|
2848
3014
|
...rest,
|
|
2849
|
-
children: /* @__PURE__ */
|
|
2850
|
-
/* @__PURE__ */
|
|
2851
|
-
/* @__PURE__ */
|
|
2852
|
-
/* @__PURE__ */
|
|
3015
|
+
children: /* @__PURE__ */ jsxs12("div", { className: "flex w-full items-center gap-2", children: [
|
|
3016
|
+
/* @__PURE__ */ jsx20("div", { className: "flex-1", "aria-hidden": "true" }),
|
|
3017
|
+
/* @__PURE__ */ jsx20("div", { className: "flex flex-1 justify-center text-center", children: BoundTitle }),
|
|
3018
|
+
/* @__PURE__ */ jsx20("div", { className: "flex flex-1 justify-end", children: BoundCloseButton })
|
|
2853
3019
|
] })
|
|
2854
3020
|
}
|
|
2855
3021
|
);
|
|
2856
3022
|
}
|
|
2857
3023
|
CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
2858
3024
|
((CopilotModalHeader2) => {
|
|
2859
|
-
CopilotModalHeader2.Title = ({ children, className, ...props }) => /* @__PURE__ */
|
|
3025
|
+
CopilotModalHeader2.Title = ({ children, className, ...props }) => /* @__PURE__ */ jsx20(
|
|
2860
3026
|
"div",
|
|
2861
3027
|
{
|
|
2862
3028
|
className: cn(
|
|
@@ -2870,7 +3036,7 @@ CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
|
2870
3036
|
CopilotModalHeader2.CloseButton = ({
|
|
2871
3037
|
className,
|
|
2872
3038
|
...props
|
|
2873
|
-
}) => /* @__PURE__ */
|
|
3039
|
+
}) => /* @__PURE__ */ jsx20(
|
|
2874
3040
|
"button",
|
|
2875
3041
|
{
|
|
2876
3042
|
type: "button",
|
|
@@ -2881,7 +3047,7 @@ CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
|
2881
3047
|
),
|
|
2882
3048
|
"aria-label": "Close",
|
|
2883
3049
|
...props,
|
|
2884
|
-
children: /* @__PURE__ */
|
|
3050
|
+
children: /* @__PURE__ */ jsx20(X3, { className: "h-4 w-4", "aria-hidden": "true" })
|
|
2885
3051
|
}
|
|
2886
3052
|
);
|
|
2887
3053
|
})(CopilotModalHeader || (CopilotModalHeader = {}));
|
|
@@ -2889,13 +3055,13 @@ CopilotModalHeader.Title.displayName = "CopilotModalHeader.Title";
|
|
|
2889
3055
|
CopilotModalHeader.CloseButton.displayName = "CopilotModalHeader.CloseButton";
|
|
2890
3056
|
|
|
2891
3057
|
// src/components/chat/CopilotSidebarView.tsx
|
|
2892
|
-
import { Fragment as Fragment7, jsx as
|
|
3058
|
+
import { Fragment as Fragment7, jsx as jsx21, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
2893
3059
|
var DEFAULT_SIDEBAR_WIDTH = 480;
|
|
2894
3060
|
var SIDEBAR_TRANSITION_MS = 260;
|
|
2895
3061
|
function CopilotSidebarView({ header, width, ...props }) {
|
|
2896
3062
|
const configuration = useCopilotChatConfiguration();
|
|
2897
3063
|
const isSidebarOpen = configuration?.isModalOpen ?? false;
|
|
2898
|
-
const sidebarRef =
|
|
3064
|
+
const sidebarRef = useRef8(null);
|
|
2899
3065
|
const [sidebarWidth, setSidebarWidth] = useState11(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
2900
3066
|
const widthToCss = (w) => {
|
|
2901
3067
|
return typeof w === "number" ? `${w}px` : w;
|
|
@@ -2906,7 +3072,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
2906
3072
|
}
|
|
2907
3073
|
return w;
|
|
2908
3074
|
};
|
|
2909
|
-
|
|
3075
|
+
useEffect14(() => {
|
|
2910
3076
|
if (width !== void 0) {
|
|
2911
3077
|
return;
|
|
2912
3078
|
}
|
|
@@ -2933,8 +3099,8 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
2933
3099
|
return () => window.removeEventListener("resize", updateWidth);
|
|
2934
3100
|
}, [width]);
|
|
2935
3101
|
const headerElement = renderSlot(header, CopilotModalHeader, {});
|
|
2936
|
-
return /* @__PURE__ */
|
|
2937
|
-
isSidebarOpen && /* @__PURE__ */
|
|
3102
|
+
return /* @__PURE__ */ jsxs13(Fragment7, { children: [
|
|
3103
|
+
isSidebarOpen && /* @__PURE__ */ jsx21(
|
|
2938
3104
|
"style",
|
|
2939
3105
|
{
|
|
2940
3106
|
dangerouslySetInnerHTML: {
|
|
@@ -2945,8 +3111,8 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
2945
3111
|
}
|
|
2946
3112
|
}
|
|
2947
3113
|
),
|
|
2948
|
-
/* @__PURE__ */
|
|
2949
|
-
/* @__PURE__ */
|
|
3114
|
+
/* @__PURE__ */ jsx21(CopilotChatToggleButton_default, {}),
|
|
3115
|
+
/* @__PURE__ */ jsx21(
|
|
2950
3116
|
"aside",
|
|
2951
3117
|
{
|
|
2952
3118
|
ref: sidebarRef,
|
|
@@ -2961,9 +3127,9 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
2961
3127
|
"aria-hidden": !isSidebarOpen,
|
|
2962
3128
|
"aria-label": "Copilot chat sidebar",
|
|
2963
3129
|
role: "complementary",
|
|
2964
|
-
children: /* @__PURE__ */
|
|
3130
|
+
children: /* @__PURE__ */ jsxs13("div", { className: "flex h-full w-full flex-col overflow-hidden", children: [
|
|
2965
3131
|
headerElement,
|
|
2966
|
-
/* @__PURE__ */
|
|
3132
|
+
/* @__PURE__ */ jsx21("div", { className: "flex-1 overflow-hidden", "data-sidebar-chat": true, children: /* @__PURE__ */ jsx21(CopilotChatView_default, { ...props }) })
|
|
2967
3133
|
] })
|
|
2968
3134
|
}
|
|
2969
3135
|
)
|
|
@@ -2973,12 +3139,12 @@ CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
|
2973
3139
|
|
|
2974
3140
|
// src/components/chat/CopilotSidebar.tsx
|
|
2975
3141
|
import { useMemo as useMemo7 } from "react";
|
|
2976
|
-
import { jsx as
|
|
3142
|
+
import { jsx as jsx22 } from "react/jsx-runtime";
|
|
2977
3143
|
function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
2978
3144
|
const SidebarViewOverride = useMemo7(() => {
|
|
2979
3145
|
const Component = (viewProps) => {
|
|
2980
3146
|
const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
|
|
2981
|
-
return /* @__PURE__ */
|
|
3147
|
+
return /* @__PURE__ */ jsx22(
|
|
2982
3148
|
CopilotSidebarView,
|
|
2983
3149
|
{
|
|
2984
3150
|
...restProps,
|
|
@@ -2989,7 +3155,7 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
|
2989
3155
|
};
|
|
2990
3156
|
return Object.assign(Component, CopilotChatView_default);
|
|
2991
3157
|
}, [header, width]);
|
|
2992
|
-
return /* @__PURE__ */
|
|
3158
|
+
return /* @__PURE__ */ jsx22(
|
|
2993
3159
|
CopilotChat,
|
|
2994
3160
|
{
|
|
2995
3161
|
...chatProps,
|
|
@@ -3000,9 +3166,9 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
|
3000
3166
|
}
|
|
3001
3167
|
CopilotSidebar.displayName = "CopilotSidebar";
|
|
3002
3168
|
|
|
3003
|
-
// src/types/
|
|
3169
|
+
// src/types/defineToolCallRenderer.ts
|
|
3004
3170
|
import { z as z2 } from "zod";
|
|
3005
|
-
function
|
|
3171
|
+
function defineToolCallRenderer(def) {
|
|
3006
3172
|
const argsSchema = def.name === "*" && !def.args ? z2.any() : def.args;
|
|
3007
3173
|
return {
|
|
3008
3174
|
name: def.name,
|
|
@@ -3014,8 +3180,8 @@ function defineToolCallRender(def) {
|
|
|
3014
3180
|
|
|
3015
3181
|
// src/components/WildcardToolCallRender.tsx
|
|
3016
3182
|
import { useState as useState12 } from "react";
|
|
3017
|
-
import { jsx as
|
|
3018
|
-
var WildcardToolCallRender =
|
|
3183
|
+
import { jsx as jsx23, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
3184
|
+
var WildcardToolCallRender = defineToolCallRenderer({
|
|
3019
3185
|
name: "*",
|
|
3020
3186
|
render: ({ args, result, name, status }) => {
|
|
3021
3187
|
const [isExpanded, setIsExpanded] = useState12(false);
|
|
@@ -3023,15 +3189,15 @@ var WildcardToolCallRender = defineToolCallRender({
|
|
|
3023
3189
|
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
3024
3190
|
const isComplete = statusString === "complete";
|
|
3025
3191
|
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";
|
|
3026
|
-
return /* @__PURE__ */
|
|
3027
|
-
/* @__PURE__ */
|
|
3192
|
+
return /* @__PURE__ */ jsx23("div", { className: "mt-2 pb-2", children: /* @__PURE__ */ jsxs14("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: [
|
|
3193
|
+
/* @__PURE__ */ jsxs14(
|
|
3028
3194
|
"div",
|
|
3029
3195
|
{
|
|
3030
3196
|
className: "flex items-center justify-between gap-3 cursor-pointer",
|
|
3031
3197
|
onClick: () => setIsExpanded(!isExpanded),
|
|
3032
3198
|
children: [
|
|
3033
|
-
/* @__PURE__ */
|
|
3034
|
-
/* @__PURE__ */
|
|
3199
|
+
/* @__PURE__ */ jsxs14("div", { className: "flex items-center gap-2 min-w-0", children: [
|
|
3200
|
+
/* @__PURE__ */ jsx23(
|
|
3035
3201
|
"svg",
|
|
3036
3202
|
{
|
|
3037
3203
|
className: `h-4 w-4 text-zinc-500 dark:text-zinc-400 transition-transform ${isExpanded ? "rotate-90" : ""}`,
|
|
@@ -3039,7 +3205,7 @@ var WildcardToolCallRender = defineToolCallRender({
|
|
|
3039
3205
|
viewBox: "0 0 24 24",
|
|
3040
3206
|
strokeWidth: 2,
|
|
3041
3207
|
stroke: "currentColor",
|
|
3042
|
-
children: /* @__PURE__ */
|
|
3208
|
+
children: /* @__PURE__ */ jsx23(
|
|
3043
3209
|
"path",
|
|
3044
3210
|
{
|
|
3045
3211
|
strokeLinecap: "round",
|
|
@@ -3049,10 +3215,10 @@ var WildcardToolCallRender = defineToolCallRender({
|
|
|
3049
3215
|
)
|
|
3050
3216
|
}
|
|
3051
3217
|
),
|
|
3052
|
-
/* @__PURE__ */
|
|
3053
|
-
/* @__PURE__ */
|
|
3218
|
+
/* @__PURE__ */ jsx23("span", { className: "inline-block h-2 w-2 rounded-full bg-blue-500" }),
|
|
3219
|
+
/* @__PURE__ */ jsx23("span", { className: "truncate text-sm font-medium text-zinc-900 dark:text-zinc-100", children: name })
|
|
3054
3220
|
] }),
|
|
3055
|
-
/* @__PURE__ */
|
|
3221
|
+
/* @__PURE__ */ jsx23(
|
|
3056
3222
|
"span",
|
|
3057
3223
|
{
|
|
3058
3224
|
className: `inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${statusStyles}`,
|
|
@@ -3062,14 +3228,14 @@ var WildcardToolCallRender = defineToolCallRender({
|
|
|
3062
3228
|
]
|
|
3063
3229
|
}
|
|
3064
3230
|
),
|
|
3065
|
-
isExpanded && /* @__PURE__ */
|
|
3066
|
-
/* @__PURE__ */
|
|
3067
|
-
/* @__PURE__ */
|
|
3068
|
-
/* @__PURE__ */
|
|
3231
|
+
isExpanded && /* @__PURE__ */ jsxs14("div", { className: "mt-3 grid gap-4", children: [
|
|
3232
|
+
/* @__PURE__ */ jsxs14("div", { children: [
|
|
3233
|
+
/* @__PURE__ */ jsx23("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Arguments" }),
|
|
3234
|
+
/* @__PURE__ */ jsx23("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) })
|
|
3069
3235
|
] }),
|
|
3070
|
-
result !== void 0 && /* @__PURE__ */
|
|
3071
|
-
/* @__PURE__ */
|
|
3072
|
-
/* @__PURE__ */
|
|
3236
|
+
result !== void 0 && /* @__PURE__ */ jsxs14("div", { children: [
|
|
3237
|
+
/* @__PURE__ */ jsx23("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Result" }),
|
|
3238
|
+
/* @__PURE__ */ jsx23("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) })
|
|
3073
3239
|
] })
|
|
3074
3240
|
] })
|
|
3075
3241
|
] }) });
|
|
@@ -3091,12 +3257,14 @@ export {
|
|
|
3091
3257
|
CopilotChatToolCallsView_default as CopilotChatToolCallsView,
|
|
3092
3258
|
CopilotChatUserMessage_default as CopilotChatUserMessage,
|
|
3093
3259
|
CopilotChatView_default as CopilotChatView,
|
|
3260
|
+
CopilotKitCoreReact,
|
|
3094
3261
|
CopilotKitProvider,
|
|
3095
3262
|
CopilotModalHeader,
|
|
3096
3263
|
CopilotSidebar,
|
|
3097
3264
|
CopilotSidebarView,
|
|
3265
|
+
WebInspector,
|
|
3098
3266
|
WildcardToolCallRender,
|
|
3099
|
-
|
|
3267
|
+
defineToolCallRenderer,
|
|
3100
3268
|
useAgent,
|
|
3101
3269
|
useAgentContext,
|
|
3102
3270
|
useConfigureSuggestions,
|
|
@@ -3104,6 +3272,7 @@ export {
|
|
|
3104
3272
|
useCopilotKit,
|
|
3105
3273
|
useFrontendTool,
|
|
3106
3274
|
useHumanInTheLoop,
|
|
3275
|
+
useRenderCustomMessages,
|
|
3107
3276
|
useRenderToolCall,
|
|
3108
3277
|
useSuggestions
|
|
3109
3278
|
};
|