@copilotkit/react-core 1.9.2-next.9 → 1.9.3-next.0
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/CHANGELOG.md +191 -0
- package/dist/{chunk-ERXWDCY6.mjs → chunk-36MGCCPZ.mjs} +2 -2
- package/dist/{chunk-UBNRUXEK.mjs → chunk-5BSUSFHM.mjs} +2 -2
- package/dist/{chunk-G7LYGERN.mjs → chunk-6ZLSC4KB.mjs} +124 -73
- package/dist/chunk-6ZLSC4KB.mjs.map +1 -0
- package/dist/{chunk-JDEWNLNP.mjs → chunk-BSAVFYRQ.mjs} +11 -11
- package/dist/{chunk-JDEWNLNP.mjs.map → chunk-BSAVFYRQ.mjs.map} +1 -1
- package/dist/{chunk-JPMIAGI6.mjs → chunk-BVK7PLK6.mjs} +2 -2
- package/dist/{chunk-FXK6RQIN.mjs → chunk-CUAFWKTQ.mjs} +4 -4
- package/dist/{chunk-XFOTNHYA.mjs → chunk-DKZTPL66.mjs} +2 -2
- package/dist/{chunk-XFOTNHYA.mjs.map → chunk-DKZTPL66.mjs.map} +1 -1
- package/dist/{chunk-EF5BNM34.mjs → chunk-FN3UA2ZE.mjs} +3 -3
- package/dist/{chunk-EXU7GWLC.mjs → chunk-GEE5AMYL.mjs} +9 -9
- package/dist/{chunk-WOGURSAL.mjs → chunk-GIMSRCVW.mjs} +64 -23
- package/dist/chunk-GIMSRCVW.mjs.map +1 -0
- package/dist/{chunk-55QZ2SVJ.mjs → chunk-JWAXDYOW.mjs} +8 -8
- package/dist/chunk-JWAXDYOW.mjs.map +1 -0
- package/dist/{chunk-3YHYWAHK.mjs → chunk-KIXKBJUV.mjs} +2 -2
- package/dist/{chunk-ADIITPD2.mjs → chunk-KLENTCQV.mjs} +34 -8
- package/dist/{chunk-ADIITPD2.mjs.map → chunk-KLENTCQV.mjs.map} +1 -1
- package/dist/{chunk-OF4SZTLL.mjs → chunk-NGQN3JRJ.mjs} +3 -3
- package/dist/{chunk-NQVCZQ5T.mjs → chunk-NJA5ZLAZ.mjs} +27 -8
- package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
- package/dist/{chunk-SJJNFYGQ.mjs → chunk-SGF6C7I6.mjs} +4 -4
- package/dist/{chunk-CMQV4XNY.mjs → chunk-VDADWRS3.mjs} +2 -2
- package/dist/components/copilot-provider/copilot-messages.js +7 -7
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.d.ts +14 -9
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +70 -29
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +9 -9
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +70 -29
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -9
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +70 -29
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -9
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +4 -4
- package/dist/{copilot-context-3da805ab.d.ts → copilot-context-3ab4fdf5.d.ts} +3 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +179 -83
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +23 -23
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +220 -169
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -4
- package/dist/hooks/use-coagent-state-render.js +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +154 -77
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +26 -7
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +26 -7
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +128 -77
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -13
- package/dist/hooks/use-copilot-readable.js +1 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.d.ts +2 -2
- package/dist/hooks/use-copilot-runtime-client.js +7 -7
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +128 -77
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +240 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -27
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -11
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -11
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +26 -0
- package/dist/setupTests.js.map +1 -0
- package/dist/setupTests.mjs +24 -0
- package/dist/setupTests.mjs.map +1 -0
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +9 -9
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -10
- package/jest.config.js +4 -0
- package/package.json +6 -3
- package/src/components/copilot-provider/__tests__/{copilotkit-trace.test.tsx → copilotkit-error.test.tsx} +17 -17
- package/src/components/copilot-provider/copilot-messages.tsx +7 -7
- package/src/components/copilot-provider/copilotkit-props.tsx +13 -8
- package/src/components/copilot-provider/copilotkit.tsx +61 -19
- package/src/context/copilot-context.tsx +4 -4
- package/src/hooks/__tests__/use-coagent-config.test.ts +284 -0
- package/src/hooks/use-chat.ts +149 -61
- package/src/hooks/use-coagent.ts +36 -0
- package/src/hooks/use-copilot-action.ts +51 -9
- package/src/hooks/use-copilot-runtime-client.ts +11 -12
- package/src/setupTests.ts +26 -0
- package/tsconfig.json +5 -2
- package/dist/chunk-55QZ2SVJ.mjs.map +0 -1
- package/dist/chunk-G7LYGERN.mjs.map +0 -1
- package/dist/chunk-NQVCZQ5T.mjs.map +0 -1
- package/dist/chunk-WOGURSAL.mjs.map +0 -1
- /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
- /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
- /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
- /package/dist/{chunk-FXK6RQIN.mjs.map → chunk-CUAFWKTQ.mjs.map} +0 -0
- /package/dist/{chunk-EF5BNM34.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
- /package/dist/{chunk-EXU7GWLC.mjs.map → chunk-GEE5AMYL.mjs.map} +0 -0
- /package/dist/{chunk-3YHYWAHK.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
- /package/dist/{chunk-OF4SZTLL.mjs.map → chunk-NGQN3JRJ.mjs.map} +0 -0
- /package/dist/{chunk-SJJNFYGQ.mjs.map → chunk-SGF6C7I6.mjs.map} +0 -0
- /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
import "../chunk-CQPYJIBH.mjs";
|
|
2
2
|
import {
|
|
3
3
|
useLangGraphInterruptRender
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-VDADWRS3.mjs";
|
|
5
5
|
import {
|
|
6
6
|
useLangGraphInterrupt
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-NGQN3JRJ.mjs";
|
|
8
8
|
import {
|
|
9
9
|
useMakeCopilotDocumentReadable
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-36MGCCPZ.mjs";
|
|
11
11
|
import {
|
|
12
12
|
useCoAgentStateRender
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-KIXKBJUV.mjs";
|
|
14
14
|
import {
|
|
15
15
|
runAgent,
|
|
16
16
|
startAgent,
|
|
17
17
|
stopAgent,
|
|
18
18
|
useCoAgent
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-KLENTCQV.mjs";
|
|
20
20
|
import {
|
|
21
21
|
useCopilotAdditionalInstructions
|
|
22
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-BVK7PLK6.mjs";
|
|
23
23
|
import {
|
|
24
24
|
useCopilotAuthenticatedAction_c
|
|
25
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-FN3UA2ZE.mjs";
|
|
26
26
|
import {
|
|
27
27
|
useCopilotAction
|
|
28
|
-
} from "../chunk-
|
|
28
|
+
} from "../chunk-NJA5ZLAZ.mjs";
|
|
29
29
|
import {
|
|
30
30
|
useCopilotChat
|
|
31
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-GEE5AMYL.mjs";
|
|
32
|
+
import "../chunk-6ZLSC4KB.mjs";
|
|
33
|
+
import "../chunk-4CEQJ2X6.mjs";
|
|
32
34
|
import {
|
|
33
35
|
useCopilotReadable
|
|
34
|
-
} from "../chunk-
|
|
35
|
-
import "../chunk-
|
|
36
|
-
import "../chunk-
|
|
37
|
-
import "../chunk-
|
|
36
|
+
} from "../chunk-5BSUSFHM.mjs";
|
|
37
|
+
import "../chunk-GIMSRCVW.mjs";
|
|
38
|
+
import "../chunk-SGF6C7I6.mjs";
|
|
39
|
+
import "../chunk-BSAVFYRQ.mjs";
|
|
40
|
+
import "../chunk-PMAFHQ7P.mjs";
|
|
38
41
|
import "../chunk-5FHSUKQL.mjs";
|
|
39
42
|
import "../chunk-RKTVJRK7.mjs";
|
|
40
|
-
import "../chunk-PMAFHQ7P.mjs";
|
|
41
|
-
import "../chunk-57K2ZJ5F.mjs";
|
|
42
|
-
import "../chunk-YPSGKPDA.mjs";
|
|
43
|
-
import "../chunk-DCTJZ742.mjs";
|
|
44
|
-
import "../chunk-G7LYGERN.mjs";
|
|
45
|
-
import "../chunk-4CEQJ2X6.mjs";
|
|
46
|
-
import "../chunk-3OQM3NEK.mjs";
|
|
47
|
-
import "../chunk-O7ARI5CV.mjs";
|
|
48
43
|
import {
|
|
49
44
|
useCopilotRuntimeClient
|
|
50
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-JWAXDYOW.mjs";
|
|
51
46
|
import "../chunk-GFJW4RIM.mjs";
|
|
47
|
+
import "../chunk-3OQM3NEK.mjs";
|
|
48
|
+
import "../chunk-O7ARI5CV.mjs";
|
|
52
49
|
import "../chunk-YAF2LATQ.mjs";
|
|
53
|
-
import "../chunk-
|
|
50
|
+
import "../chunk-57K2ZJ5F.mjs";
|
|
51
|
+
import "../chunk-YPSGKPDA.mjs";
|
|
52
|
+
import "../chunk-DKZTPL66.mjs";
|
|
53
|
+
import "../chunk-DCTJZ742.mjs";
|
|
54
54
|
import "../chunk-SKC7AJIV.mjs";
|
|
55
55
|
export {
|
|
56
56
|
runAgent,
|
package/dist/hooks/use-chat.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FunctionCallHandler, CoAgentStateRenderHandler } from '@copilotkit/shared';
|
|
3
3
|
import { Message, TextMessage, ForwardedParametersInput, ExtensionsInput } from '@copilotkit/runtime-client-gql';
|
|
4
|
-
import { c as CopilotApiConfig, A as AgentSession, L as LangGraphInterruptAction, d as LangGraphInterruptActionSetter } from '../copilot-context-
|
|
4
|
+
import { c as CopilotApiConfig, A as AgentSession, L as LangGraphInterruptAction, d as LangGraphInterruptActionSetter } from '../copilot-context-3ab4fdf5.js';
|
|
5
5
|
import { FrontendAction } from '../types/frontend-action.js';
|
|
6
6
|
import { CoagentState } from '../types/coagent-state.js';
|
|
7
7
|
import './use-tree.js';
|
package/dist/hooks/use-chat.js
CHANGED
|
@@ -83,6 +83,7 @@ __export(use_chat_exports, {
|
|
|
83
83
|
});
|
|
84
84
|
module.exports = __toCommonJS(use_chat_exports);
|
|
85
85
|
var import_react5 = require("react");
|
|
86
|
+
var import_react_dom = require("react-dom");
|
|
86
87
|
var import_shared4 = require("@copilotkit/shared");
|
|
87
88
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
88
89
|
|
|
@@ -111,16 +112,104 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
111
112
|
return filteredActions;
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
// src/context/copilot-context.tsx
|
|
116
|
+
var import_react = __toESM(require("react"));
|
|
117
|
+
var emptyCopilotContext = {
|
|
118
|
+
actions: {},
|
|
119
|
+
setAction: () => {
|
|
120
|
+
},
|
|
121
|
+
removeAction: () => {
|
|
122
|
+
},
|
|
123
|
+
coAgentStateRenders: {},
|
|
124
|
+
setCoAgentStateRender: () => {
|
|
125
|
+
},
|
|
126
|
+
removeCoAgentStateRender: () => {
|
|
127
|
+
},
|
|
128
|
+
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
129
|
+
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
130
|
+
addContext: () => "",
|
|
131
|
+
removeContext: () => {
|
|
132
|
+
},
|
|
133
|
+
getAllContext: () => [],
|
|
134
|
+
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
135
|
+
})),
|
|
136
|
+
isLoading: false,
|
|
137
|
+
setIsLoading: () => returnAndThrowInDebug(false),
|
|
138
|
+
chatInstructions: "",
|
|
139
|
+
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
140
|
+
additionalInstructions: [],
|
|
141
|
+
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
142
|
+
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
143
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
144
|
+
removeDocumentContext: () => {
|
|
145
|
+
},
|
|
146
|
+
runtimeClient: {},
|
|
147
|
+
copilotApiConfig: new class {
|
|
148
|
+
get chatApiEndpoint() {
|
|
149
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
150
|
+
}
|
|
151
|
+
get headers() {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
get body() {
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
}(),
|
|
158
|
+
chatSuggestionConfiguration: {},
|
|
159
|
+
addChatSuggestionConfiguration: () => {
|
|
160
|
+
},
|
|
161
|
+
removeChatSuggestionConfiguration: () => {
|
|
162
|
+
},
|
|
163
|
+
showDevConsole: false,
|
|
164
|
+
coagentStates: {},
|
|
165
|
+
setCoagentStates: () => {
|
|
166
|
+
},
|
|
167
|
+
coagentStatesRef: { current: {} },
|
|
168
|
+
setCoagentStatesWithRef: () => {
|
|
169
|
+
},
|
|
170
|
+
agentSession: null,
|
|
171
|
+
setAgentSession: () => {
|
|
172
|
+
},
|
|
173
|
+
forwardedParameters: {},
|
|
174
|
+
agentLock: null,
|
|
175
|
+
threadId: "",
|
|
176
|
+
setThreadId: () => {
|
|
177
|
+
},
|
|
178
|
+
runId: null,
|
|
179
|
+
setRunId: () => {
|
|
180
|
+
},
|
|
181
|
+
chatAbortControllerRef: { current: null },
|
|
182
|
+
availableAgents: [],
|
|
183
|
+
extensions: {},
|
|
184
|
+
setExtensions: () => {
|
|
185
|
+
},
|
|
186
|
+
langGraphInterruptAction: null,
|
|
187
|
+
setLangGraphInterruptAction: () => null,
|
|
188
|
+
removeLangGraphInterruptAction: () => null,
|
|
189
|
+
onError: void 0
|
|
190
|
+
};
|
|
191
|
+
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
192
|
+
function useCopilotContext() {
|
|
193
|
+
const context = import_react.default.useContext(CopilotContext);
|
|
194
|
+
if (context === emptyCopilotContext) {
|
|
195
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
196
|
+
}
|
|
197
|
+
return context;
|
|
198
|
+
}
|
|
199
|
+
function returnAndThrowInDebug(_value) {
|
|
200
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
201
|
+
}
|
|
202
|
+
|
|
114
203
|
// src/hooks/use-copilot-runtime-client.ts
|
|
115
204
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
116
205
|
|
|
117
206
|
// src/components/toast/toast-provider.tsx
|
|
118
|
-
var
|
|
207
|
+
var import_react2 = require("react");
|
|
119
208
|
var import_shared2 = require("@copilotkit/shared");
|
|
120
209
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
121
|
-
var ToastContext = (0,
|
|
210
|
+
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
122
211
|
function useToast() {
|
|
123
|
-
const context = (0,
|
|
212
|
+
const context = (0, import_react2.useContext)(ToastContext);
|
|
124
213
|
if (!context) {
|
|
125
214
|
throw new Error("useToast must be used within a ToastProvider");
|
|
126
215
|
}
|
|
@@ -128,7 +217,7 @@ function useToast() {
|
|
|
128
217
|
}
|
|
129
218
|
|
|
130
219
|
// src/hooks/use-copilot-runtime-client.ts
|
|
131
|
-
var
|
|
220
|
+
var import_react3 = require("react");
|
|
132
221
|
var import_shared3 = require("@copilotkit/shared");
|
|
133
222
|
|
|
134
223
|
// src/utils/dev-console.ts
|
|
@@ -139,13 +228,13 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
139
228
|
// src/hooks/use-copilot-runtime-client.ts
|
|
140
229
|
var useCopilotRuntimeClient = (options) => {
|
|
141
230
|
const { setBannerError } = useToast();
|
|
142
|
-
const _a = options, { showDevConsole,
|
|
143
|
-
const lastStructuredErrorRef = (0,
|
|
231
|
+
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
232
|
+
const lastStructuredErrorRef = (0, import_react3.useRef)(null);
|
|
144
233
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
145
|
-
if (!
|
|
234
|
+
if (!onError || !runtimeOptions.publicApiKey)
|
|
146
235
|
return;
|
|
147
236
|
try {
|
|
148
|
-
const
|
|
237
|
+
const errorEvent = {
|
|
149
238
|
type: "error",
|
|
150
239
|
timestamp: Date.now(),
|
|
151
240
|
context: {
|
|
@@ -163,12 +252,12 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
163
252
|
},
|
|
164
253
|
error
|
|
165
254
|
};
|
|
166
|
-
yield
|
|
167
|
-
} catch (
|
|
168
|
-
console.error("Error in
|
|
255
|
+
yield onError(errorEvent);
|
|
256
|
+
} catch (error2) {
|
|
257
|
+
console.error("Error in onError handler:", error2);
|
|
169
258
|
}
|
|
170
259
|
});
|
|
171
|
-
const runtimeClient = (0,
|
|
260
|
+
const runtimeClient = (0, import_react3.useMemo)(() => {
|
|
172
261
|
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
173
262
|
handleGQLErrors: (error) => {
|
|
174
263
|
var _a2;
|
|
@@ -229,7 +318,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
229
318
|
setBannerError(warningError);
|
|
230
319
|
}
|
|
231
320
|
}));
|
|
232
|
-
}, [runtimeOptions, setBannerError, showDevConsole,
|
|
321
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onError]);
|
|
233
322
|
return runtimeClient;
|
|
234
323
|
};
|
|
235
324
|
function createStructuredError(gqlError) {
|
|
@@ -256,94 +345,6 @@ function createStructuredError(gqlError) {
|
|
|
256
345
|
return null;
|
|
257
346
|
}
|
|
258
347
|
|
|
259
|
-
// src/context/copilot-context.tsx
|
|
260
|
-
var import_react3 = __toESM(require("react"));
|
|
261
|
-
var emptyCopilotContext = {
|
|
262
|
-
actions: {},
|
|
263
|
-
setAction: () => {
|
|
264
|
-
},
|
|
265
|
-
removeAction: () => {
|
|
266
|
-
},
|
|
267
|
-
coAgentStateRenders: {},
|
|
268
|
-
setCoAgentStateRender: () => {
|
|
269
|
-
},
|
|
270
|
-
removeCoAgentStateRender: () => {
|
|
271
|
-
},
|
|
272
|
-
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
273
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
274
|
-
addContext: () => "",
|
|
275
|
-
removeContext: () => {
|
|
276
|
-
},
|
|
277
|
-
getAllContext: () => [],
|
|
278
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
279
|
-
})),
|
|
280
|
-
isLoading: false,
|
|
281
|
-
setIsLoading: () => returnAndThrowInDebug(false),
|
|
282
|
-
chatInstructions: "",
|
|
283
|
-
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
284
|
-
additionalInstructions: [],
|
|
285
|
-
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
286
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
287
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
288
|
-
removeDocumentContext: () => {
|
|
289
|
-
},
|
|
290
|
-
runtimeClient: {},
|
|
291
|
-
copilotApiConfig: new class {
|
|
292
|
-
get chatApiEndpoint() {
|
|
293
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
294
|
-
}
|
|
295
|
-
get headers() {
|
|
296
|
-
return {};
|
|
297
|
-
}
|
|
298
|
-
get body() {
|
|
299
|
-
return {};
|
|
300
|
-
}
|
|
301
|
-
}(),
|
|
302
|
-
chatSuggestionConfiguration: {},
|
|
303
|
-
addChatSuggestionConfiguration: () => {
|
|
304
|
-
},
|
|
305
|
-
removeChatSuggestionConfiguration: () => {
|
|
306
|
-
},
|
|
307
|
-
showDevConsole: false,
|
|
308
|
-
coagentStates: {},
|
|
309
|
-
setCoagentStates: () => {
|
|
310
|
-
},
|
|
311
|
-
coagentStatesRef: { current: {} },
|
|
312
|
-
setCoagentStatesWithRef: () => {
|
|
313
|
-
},
|
|
314
|
-
agentSession: null,
|
|
315
|
-
setAgentSession: () => {
|
|
316
|
-
},
|
|
317
|
-
forwardedParameters: {},
|
|
318
|
-
agentLock: null,
|
|
319
|
-
threadId: "",
|
|
320
|
-
setThreadId: () => {
|
|
321
|
-
},
|
|
322
|
-
runId: null,
|
|
323
|
-
setRunId: () => {
|
|
324
|
-
},
|
|
325
|
-
chatAbortControllerRef: { current: null },
|
|
326
|
-
availableAgents: [],
|
|
327
|
-
extensions: {},
|
|
328
|
-
setExtensions: () => {
|
|
329
|
-
},
|
|
330
|
-
langGraphInterruptAction: null,
|
|
331
|
-
setLangGraphInterruptAction: () => null,
|
|
332
|
-
removeLangGraphInterruptAction: () => null,
|
|
333
|
-
onTrace: void 0
|
|
334
|
-
};
|
|
335
|
-
var CopilotContext = import_react3.default.createContext(emptyCopilotContext);
|
|
336
|
-
function useCopilotContext() {
|
|
337
|
-
const context = import_react3.default.useContext(CopilotContext);
|
|
338
|
-
if (context === emptyCopilotContext) {
|
|
339
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
340
|
-
}
|
|
341
|
-
return context;
|
|
342
|
-
}
|
|
343
|
-
function returnAndThrowInDebug(_value) {
|
|
344
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
345
|
-
}
|
|
346
|
-
|
|
347
348
|
// src/components/error-boundary/error-utils.tsx
|
|
348
349
|
var import_react4 = require("react");
|
|
349
350
|
|
|
@@ -490,9 +491,9 @@ function useChat(options) {
|
|
|
490
491
|
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
491
492
|
const addErrorToast = useErrorToast();
|
|
492
493
|
const { setBannerError } = useToast();
|
|
493
|
-
const {
|
|
494
|
+
const { onError } = useCopilotContext();
|
|
494
495
|
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
495
|
-
if (!
|
|
496
|
+
if (!onError || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
496
497
|
return;
|
|
497
498
|
try {
|
|
498
499
|
const traceEvent = {
|
|
@@ -513,9 +514,9 @@ function useChat(options) {
|
|
|
513
514
|
},
|
|
514
515
|
error
|
|
515
516
|
};
|
|
516
|
-
yield
|
|
517
|
+
yield onError(traceEvent);
|
|
517
518
|
} catch (traceError) {
|
|
518
|
-
console.error("Error in use-chat
|
|
519
|
+
console.error("Error in use-chat onError handler:", traceError);
|
|
519
520
|
}
|
|
520
521
|
});
|
|
521
522
|
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
@@ -737,17 +738,22 @@ function useChat(options) {
|
|
|
737
738
|
lastAgentStateMessage.state.messages
|
|
738
739
|
);
|
|
739
740
|
}
|
|
740
|
-
setCoagentStatesWithRef((prevAgentStates) =>
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
741
|
+
setCoagentStatesWithRef((prevAgentStates) => {
|
|
742
|
+
var _a2;
|
|
743
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
744
|
+
[lastAgentStateMessage.agentName]: {
|
|
745
|
+
name: lastAgentStateMessage.agentName,
|
|
746
|
+
state: lastAgentStateMessage.state,
|
|
747
|
+
running: lastAgentStateMessage.running,
|
|
748
|
+
active: lastAgentStateMessage.active,
|
|
749
|
+
threadId: lastAgentStateMessage.threadId,
|
|
750
|
+
nodeName: lastAgentStateMessage.nodeName,
|
|
751
|
+
runId: lastAgentStateMessage.runId,
|
|
752
|
+
// Preserve existing config from previous state
|
|
753
|
+
config: (_a2 = prevAgentStates[lastAgentStateMessage.agentName]) == null ? void 0 : _a2.config
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
});
|
|
751
757
|
if (lastAgentStateMessage.running) {
|
|
752
758
|
setAgentSession({
|
|
753
759
|
threadId: lastAgentStateMessage.threadId,
|
|
@@ -777,6 +783,39 @@ function useChat(options) {
|
|
|
777
783
|
newMessages
|
|
778
784
|
);
|
|
779
785
|
let didExecuteAction = false;
|
|
786
|
+
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
787
|
+
var _a2;
|
|
788
|
+
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
789
|
+
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
790
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
791
|
+
currentAction._setActivatingMessageId(actionMessage.id);
|
|
792
|
+
}
|
|
793
|
+
const resultMessage = yield executeAction({
|
|
794
|
+
onFunctionCall,
|
|
795
|
+
message: actionMessage,
|
|
796
|
+
chatAbortControllerRef,
|
|
797
|
+
onError: (error) => {
|
|
798
|
+
addErrorToast([error]);
|
|
799
|
+
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
800
|
+
},
|
|
801
|
+
setMessages,
|
|
802
|
+
getFinalMessages: () => finalMessages,
|
|
803
|
+
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
804
|
+
});
|
|
805
|
+
didExecuteAction = true;
|
|
806
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
807
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
808
|
+
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
809
|
+
const messagesForImmediateUpdate = [...finalMessages];
|
|
810
|
+
(0, import_react_dom.flushSync)(() => {
|
|
811
|
+
setMessages(messagesForImmediateUpdate);
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
815
|
+
currentAction._setActivatingMessageId(null);
|
|
816
|
+
}
|
|
817
|
+
return resultMessage;
|
|
818
|
+
});
|
|
780
819
|
if (onFunctionCall) {
|
|
781
820
|
const lastMessages = [];
|
|
782
821
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
@@ -793,37 +832,28 @@ function useChat(options) {
|
|
|
793
832
|
(action2) => action2.name === message.name
|
|
794
833
|
);
|
|
795
834
|
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
796
|
-
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
797
|
-
var _a2;
|
|
798
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
|
|
799
|
-
followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
|
|
800
|
-
const resultMessage = yield executeAction({
|
|
801
|
-
onFunctionCall,
|
|
802
|
-
previousMessages,
|
|
803
|
-
message: message2,
|
|
804
|
-
chatAbortControllerRef,
|
|
805
|
-
onError: (error) => {
|
|
806
|
-
addErrorToast([error]);
|
|
807
|
-
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
didExecuteAction = true;
|
|
811
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
812
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
813
|
-
return resultMessage;
|
|
814
|
-
});
|
|
815
835
|
if (action && message.isActionExecutionMessage()) {
|
|
816
|
-
const
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
836
|
+
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
837
|
+
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
838
|
+
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
839
|
+
);
|
|
840
|
+
if (alreadyProcessed) {
|
|
841
|
+
} else {
|
|
842
|
+
const resultMessage = yield executeActionFromMessage(
|
|
843
|
+
action,
|
|
844
|
+
message
|
|
845
|
+
);
|
|
846
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
847
|
+
if (pairedFeAction) {
|
|
848
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
849
|
+
name: pairedFeAction.name,
|
|
850
|
+
arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
|
|
851
|
+
status: message.status,
|
|
852
|
+
createdAt: message.createdAt,
|
|
853
|
+
parentMessageId: message.parentMessageId
|
|
854
|
+
});
|
|
855
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
856
|
+
}
|
|
827
857
|
}
|
|
828
858
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
829
859
|
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
@@ -841,13 +871,9 @@ function useChat(options) {
|
|
|
841
871
|
}
|
|
842
872
|
setMessages(finalMessages);
|
|
843
873
|
}
|
|
844
|
-
if (
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
(didExecuteAction || // the last message is a server side result
|
|
848
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
849
|
-
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
|
|
850
|
-
) {
|
|
874
|
+
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
875
|
+
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
876
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
851
877
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
852
878
|
return yield runChatCompletionRef.current(finalMessages);
|
|
853
879
|
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
@@ -955,21 +981,35 @@ function useChat(options) {
|
|
|
955
981
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
956
982
|
);
|
|
957
983
|
const reload = useAsyncCallback(
|
|
958
|
-
(
|
|
984
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
959
985
|
if (isLoading || messages.length === 0) {
|
|
960
986
|
return;
|
|
961
987
|
}
|
|
962
|
-
const
|
|
963
|
-
if (
|
|
964
|
-
console.warn(`Message with id ${
|
|
988
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
989
|
+
if (reloadMessageIndex === -1) {
|
|
990
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
965
991
|
return;
|
|
966
992
|
}
|
|
967
|
-
|
|
968
|
-
if (
|
|
969
|
-
|
|
993
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
994
|
+
if (reloadMessageRole !== import_runtime_client_gql3.MessageRole.Assistant) {
|
|
995
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
996
|
+
return;
|
|
970
997
|
}
|
|
971
|
-
|
|
972
|
-
|
|
998
|
+
let historyCutoff = [];
|
|
999
|
+
if (messages.length > 2) {
|
|
1000
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
1001
|
+
(msg) => (
|
|
1002
|
+
// @ts-expect-error -- message has role
|
|
1003
|
+
msg.role === import_runtime_client_gql3.MessageRole.User
|
|
1004
|
+
)
|
|
1005
|
+
);
|
|
1006
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
1007
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
1008
|
+
);
|
|
1009
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
1010
|
+
}
|
|
1011
|
+
setMessages(historyCutoff);
|
|
1012
|
+
return runChatCompletionAndHandleFunctionCall(historyCutoff);
|
|
973
1013
|
}),
|
|
974
1014
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
975
1015
|
);
|
|
@@ -1004,20 +1044,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
1004
1044
|
function executeAction(_0) {
|
|
1005
1045
|
return __async(this, arguments, function* ({
|
|
1006
1046
|
onFunctionCall,
|
|
1007
|
-
previousMessages,
|
|
1008
1047
|
message,
|
|
1009
1048
|
chatAbortControllerRef,
|
|
1010
|
-
onError
|
|
1049
|
+
onError,
|
|
1050
|
+
setMessages,
|
|
1051
|
+
getFinalMessages,
|
|
1052
|
+
isRenderAndWait
|
|
1011
1053
|
}) {
|
|
1012
1054
|
let result;
|
|
1013
1055
|
let error = null;
|
|
1056
|
+
const currentMessagesForHandler = getFinalMessages();
|
|
1057
|
+
const handlerReturnedPromise = onFunctionCall({
|
|
1058
|
+
messages: currentMessagesForHandler,
|
|
1059
|
+
name: message.name,
|
|
1060
|
+
args: message.arguments
|
|
1061
|
+
});
|
|
1062
|
+
if (isRenderAndWait) {
|
|
1063
|
+
const currentMessagesForRender = getFinalMessages();
|
|
1064
|
+
(0, import_react_dom.flushSync)(() => {
|
|
1065
|
+
setMessages([...currentMessagesForRender]);
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1014
1068
|
try {
|
|
1015
1069
|
result = yield Promise.race([
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
name: message.name,
|
|
1019
|
-
args: message.arguments
|
|
1020
|
-
}),
|
|
1070
|
+
handlerReturnedPromise,
|
|
1071
|
+
// Await the promise returned by the handler
|
|
1021
1072
|
new Promise(
|
|
1022
1073
|
(resolve) => {
|
|
1023
1074
|
var _a;
|