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