@copilotkit/react-core 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.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 +22 -3
- package/dist/{chunk-JHEAUB3Z.mjs → chunk-35EN6BG4.mjs} +2 -2
- package/dist/{chunk-JHEAUB3Z.mjs.map → chunk-35EN6BG4.mjs.map} +1 -1
- package/dist/{chunk-O22KGHOQ.mjs → chunk-42N5VKIX.mjs} +38 -16
- package/dist/chunk-42N5VKIX.mjs.map +1 -0
- package/dist/{chunk-AG7FH7OD.mjs → chunk-5FYKUKG3.mjs} +2 -2
- package/dist/{chunk-ODN4H66E.mjs → chunk-7LRDVJH5.mjs} +6 -2
- package/dist/chunk-7LRDVJH5.mjs.map +1 -0
- package/dist/{chunk-Y7MI4PBB.mjs → chunk-ALR5W5JK.mjs} +22 -10
- package/dist/chunk-ALR5W5JK.mjs.map +1 -0
- package/dist/{chunk-XBVKTDXP.mjs → chunk-BT6WK2JZ.mjs} +57 -17
- package/dist/chunk-BT6WK2JZ.mjs.map +1 -0
- package/dist/chunk-QCUP6HLK.mjs +37 -0
- package/dist/chunk-QCUP6HLK.mjs.map +1 -0
- package/dist/chunk-QTDCEDOC.mjs +392 -0
- package/dist/chunk-QTDCEDOC.mjs.map +1 -0
- package/dist/{chunk-OT67R4NB.mjs → chunk-QX6V774L.mjs} +6 -8
- package/dist/chunk-QX6V774L.mjs.map +1 -0
- package/dist/{chunk-2KCEHGSI.mjs → chunk-SFPANIOY.mjs} +99 -49
- package/dist/chunk-SFPANIOY.mjs.map +1 -0
- package/dist/{chunk-XQFVXX6R.mjs → chunk-TQN3EZWQ.mjs} +10 -2
- package/dist/chunk-TQN3EZWQ.mjs.map +1 -0
- package/dist/{chunk-UOVONDR6.mjs → chunk-V3PFWGIY.mjs} +2 -2
- package/dist/{chunk-DHGXL5PC.mjs → chunk-VMP6JWBB.mjs} +18 -6
- package/dist/chunk-VMP6JWBB.mjs.map +1 -0
- package/dist/chunk-XERJQUHA.mjs +31 -0
- package/dist/chunk-XERJQUHA.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.js +175 -93
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +5 -4
- package/dist/components/copilot-provider/index.js +175 -93
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +5 -4
- package/dist/components/error-boundary/error-boundary.d.ts +22 -0
- package/dist/components/error-boundary/error-boundary.js +183 -0
- package/dist/components/error-boundary/error-boundary.js.map +1 -0
- package/dist/components/error-boundary/error-boundary.mjs +12 -0
- package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
- package/dist/components/error-boundary/error-utils.d.ts +11 -0
- package/dist/components/error-boundary/error-utils.js +177 -0
- package/dist/components/error-boundary/error-utils.js.map +1 -0
- package/dist/components/error-boundary/error-utils.mjs +13 -0
- package/dist/components/error-boundary/error-utils.mjs.map +1 -0
- package/dist/components/index.js +175 -93
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +5 -4
- package/dist/components/toast/toast-provider.d.ts +2 -1
- package/dist/components/toast/toast-provider.js +76 -62
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/context/copilot-context.d.ts +8 -2
- package/dist/context/copilot-context.js +9 -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 +9 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +584 -270
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +19 -11
- package/dist/hooks/use-chat.d.ts +20 -0
- package/dist/hooks/use-chat.js +438 -200
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -3
- package/dist/hooks/use-coagent-state-render.d.ts +2 -2
- package/dist/hooks/use-coagent-state-render.js +9 -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 +14 -1
- package/dist/hooks/use-coagent.js +547 -242
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +15 -7
- package/dist/hooks/use-copilot-action.d.ts +12 -2
- package/dist/hooks/use-copilot-action.js +156 -14
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -2
- package/dist/hooks/use-copilot-chat.d.ts +1 -0
- package/dist/hooks/use-copilot-chat.js +514 -231
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +8 -6
- package/dist/hooks/use-copilot-readable.js +9 -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.js +110 -4
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +9 -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 +2 -2
- package/dist/index.js +642 -363
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -12
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js +33 -13
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +7 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +33 -13
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -5
- package/dist/types/frontend-action.d.ts +21 -2
- package/dist/types/frontend-action.js +34 -0
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +7 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +5 -4
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +5 -4
- package/package.json +3 -3
- package/src/components/copilot-provider/copilotkit.tsx +14 -1
- package/src/components/error-boundary/error-boundary.tsx +42 -0
- package/src/components/error-boundary/error-utils.tsx +95 -0
- package/src/components/toast/toast-provider.tsx +10 -49
- package/src/context/copilot-context.tsx +30 -2
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +391 -256
- package/src/hooks/use-coagent-state-render.ts +2 -2
- package/src/hooks/use-coagent.ts +35 -15
- package/src/hooks/use-copilot-action.ts +41 -12
- package/src/hooks/use-copilot-chat.ts +52 -11
- package/src/hooks/use-copilot-runtime-client.ts +4 -0
- package/src/lib/copilot-task.ts +2 -8
- package/src/types/frontend-action.ts +55 -2
- package/src/types/index.ts +5 -1
- package/dist/chunk-2KCEHGSI.mjs.map +0 -1
- package/dist/chunk-DHGXL5PC.mjs.map +0 -1
- package/dist/chunk-EUIBVFV6.mjs +0 -294
- package/dist/chunk-EUIBVFV6.mjs.map +0 -1
- package/dist/chunk-O22KGHOQ.mjs.map +0 -1
- package/dist/chunk-ODN4H66E.mjs.map +0 -1
- package/dist/chunk-OT67R4NB.mjs.map +0 -1
- package/dist/chunk-XBVKTDXP.mjs.map +0 -1
- package/dist/chunk-XQFVXX6R.mjs.map +0 -1
- package/dist/chunk-Y7MI4PBB.mjs.map +0 -1
- /package/dist/{chunk-AG7FH7OD.mjs.map → chunk-5FYKUKG3.mjs.map} +0 -0
- /package/dist/{chunk-UOVONDR6.mjs.map → chunk-V3PFWGIY.mjs.map} +0 -0
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
* ### Simple Usage
|
|
13
13
|
*
|
|
14
14
|
* ```tsx
|
|
15
|
-
* import {
|
|
15
|
+
* import { useCoAgentStateRender } from "@copilotkit/react-core";
|
|
16
16
|
*
|
|
17
17
|
* type YourAgentState = {
|
|
18
18
|
* agent_state_property: string;
|
|
19
19
|
* }
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* useCoAgentStateRender<YourAgentState>({
|
|
22
22
|
* name: "basic_agent",
|
|
23
23
|
* nodeName: "optionally_specify_a_specific_node",
|
|
24
24
|
* render: ({ status, state, nodeName }) => {
|
package/src/hooks/use-coagent.ts
CHANGED
|
@@ -99,6 +99,7 @@ import { CoagentState } from "../types/coagent-state";
|
|
|
99
99
|
import { useCopilotChat } from "./use-copilot-chat";
|
|
100
100
|
import { Message } from "@copilotkit/runtime-client-gql";
|
|
101
101
|
import { flushSync } from "react-dom";
|
|
102
|
+
import { useAsyncCallback } from "../components/error-boundary/error-utils";
|
|
102
103
|
|
|
103
104
|
interface WithInternalStateManagementAndInitial<T> {
|
|
104
105
|
/**
|
|
@@ -264,44 +265,63 @@ export function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentRe
|
|
|
264
265
|
} else if (coagentStates[name] === undefined) {
|
|
265
266
|
setState(options.initialState === undefined ? {} : options.initialState);
|
|
266
267
|
}
|
|
267
|
-
}, [
|
|
268
|
+
}, [
|
|
269
|
+
isExternalStateManagement(options) ? JSON.stringify(options.state) : undefined,
|
|
270
|
+
// reset initialstate on reset
|
|
271
|
+
coagentStates[name] === undefined,
|
|
272
|
+
]);
|
|
273
|
+
|
|
274
|
+
const runAgentCallback = useAsyncCallback(
|
|
275
|
+
async (hint?: HintFunction) => {
|
|
276
|
+
await runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
277
|
+
},
|
|
278
|
+
[name, context, appendMessage, runChatCompletion],
|
|
279
|
+
);
|
|
268
280
|
|
|
269
281
|
// Return the state and setState function
|
|
270
282
|
return {
|
|
271
283
|
name,
|
|
272
284
|
nodeName: coagentState.nodeName,
|
|
273
|
-
|
|
274
|
-
setState,
|
|
285
|
+
threadId: coagentState.threadId,
|
|
275
286
|
running: coagentState.running,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
stop: () =>
|
|
280
|
-
|
|
281
|
-
},
|
|
282
|
-
run: (hint?: HintFunction) => {
|
|
283
|
-
return runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
284
|
-
},
|
|
287
|
+
state: coagentState.state,
|
|
288
|
+
setState: isExternalStateManagement(options) ? options.setState : setState,
|
|
289
|
+
start: () => startAgent(name, context),
|
|
290
|
+
stop: () => stopAgent(name, context),
|
|
291
|
+
run: runAgentCallback,
|
|
285
292
|
};
|
|
286
293
|
}
|
|
287
294
|
|
|
288
|
-
function startAgent(name: string, context: CopilotContextParams) {
|
|
295
|
+
export function startAgent(name: string, context: CopilotContextParams) {
|
|
289
296
|
const { setAgentSession } = context;
|
|
290
297
|
setAgentSession({
|
|
291
298
|
agentName: name,
|
|
292
299
|
});
|
|
293
300
|
}
|
|
294
301
|
|
|
295
|
-
function stopAgent(name: string, context: CopilotContextParams) {
|
|
302
|
+
export function stopAgent(name: string, context: CopilotContextParams) {
|
|
296
303
|
const { agentSession, setAgentSession } = context;
|
|
297
304
|
if (agentSession && agentSession.agentName === name) {
|
|
298
305
|
setAgentSession(null);
|
|
306
|
+
context.setCoagentStates((prevAgentStates) => {
|
|
307
|
+
return {
|
|
308
|
+
...prevAgentStates,
|
|
309
|
+
[name]: {
|
|
310
|
+
...prevAgentStates[name],
|
|
311
|
+
running: false,
|
|
312
|
+
active: false,
|
|
313
|
+
threadId: undefined,
|
|
314
|
+
nodeName: undefined,
|
|
315
|
+
runId: undefined,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
});
|
|
299
319
|
} else {
|
|
300
320
|
console.warn(`No agent session found for ${name}`);
|
|
301
321
|
}
|
|
302
322
|
}
|
|
303
323
|
|
|
304
|
-
async function runAgent(
|
|
324
|
+
export async function runAgent(
|
|
305
325
|
name: string,
|
|
306
326
|
context: CopilotContextParams & CopilotMessagesContextParams,
|
|
307
327
|
appendMessage: (message: Message) => Promise<void>,
|
|
@@ -71,6 +71,15 @@
|
|
|
71
71
|
* );
|
|
72
72
|
* },
|
|
73
73
|
* });
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Catch all action allows you to render actions that are not defined in the frontend
|
|
77
|
+
* useCopilotAction({
|
|
78
|
+
* name: "*",
|
|
79
|
+
* render: ({ name, args, status, result, handler, respond }) => {
|
|
80
|
+
* return <div>Rendering action: {name}</div>;
|
|
81
|
+
* },
|
|
82
|
+
* });
|
|
74
83
|
*/
|
|
75
84
|
|
|
76
85
|
/**
|
|
@@ -124,10 +133,12 @@
|
|
|
124
133
|
import { Parameter, randomId } from "@copilotkit/shared";
|
|
125
134
|
import { createElement, Fragment, useEffect, useRef } from "react";
|
|
126
135
|
import { useCopilotContext } from "../context/copilot-context";
|
|
136
|
+
import { useAsyncCallback } from "../components/error-boundary/error-utils";
|
|
127
137
|
import {
|
|
128
138
|
ActionRenderProps,
|
|
129
139
|
ActionRenderPropsNoArgsWait,
|
|
130
140
|
ActionRenderPropsWait,
|
|
141
|
+
CatchAllFrontendAction,
|
|
131
142
|
FrontendAction,
|
|
132
143
|
} from "../types/frontend-action";
|
|
133
144
|
|
|
@@ -141,7 +152,7 @@ import {
|
|
|
141
152
|
// useCallback, useMemo or other memoization techniques are not suitable here,
|
|
142
153
|
// because they will cause a infinite rerender loop.
|
|
143
154
|
export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
144
|
-
action: FrontendAction<T
|
|
155
|
+
action: FrontendAction<T> | CatchAllFrontendAction,
|
|
145
156
|
dependencies?: any[],
|
|
146
157
|
): void {
|
|
147
158
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
@@ -151,15 +162,20 @@ export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
|
151
162
|
// clone the action to avoid mutating the original object
|
|
152
163
|
action = { ...action };
|
|
153
164
|
|
|
154
|
-
// If the developer provides a
|
|
165
|
+
// If the developer provides a renderAndWaitForResponse function, we transform the action
|
|
155
166
|
// to use a promise internally, so that we can treat it like a normal action.
|
|
156
|
-
if (
|
|
167
|
+
if (
|
|
168
|
+
// renderAndWaitForResponse is not available for catch all actions
|
|
169
|
+
isFrontendAction(action) &&
|
|
170
|
+
// check if renderAndWaitForResponse is set
|
|
171
|
+
(action.renderAndWait || action.renderAndWaitForResponse)
|
|
172
|
+
) {
|
|
157
173
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
158
174
|
// remove the renderAndWait function from the action
|
|
159
175
|
action.renderAndWait = undefined;
|
|
160
176
|
action.renderAndWaitForResponse = undefined;
|
|
161
177
|
// add a handler that will be called when the action is executed
|
|
162
|
-
action.handler = (async () => {
|
|
178
|
+
action.handler = useAsyncCallback(async () => {
|
|
163
179
|
// we create a new promise when the handler is called
|
|
164
180
|
let resolve: (result: any) => void;
|
|
165
181
|
let reject: (error: any) => void;
|
|
@@ -170,7 +186,7 @@ export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
|
170
186
|
renderAndWaitRef.current = { promise, resolve: resolve!, reject: reject! };
|
|
171
187
|
// then we await the promise (it will be resolved in the original renderAndWait function)
|
|
172
188
|
return await promise;
|
|
173
|
-
}) as any;
|
|
189
|
+
}, []) as any;
|
|
174
190
|
|
|
175
191
|
// add a render function that will be called when the action is rendered
|
|
176
192
|
action.render = ((props: ActionRenderProps<T>): React.ReactElement => {
|
|
@@ -211,10 +227,15 @@ export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
|
211
227
|
// This ensures that any captured variables in the handler are up to date.
|
|
212
228
|
if (dependencies === undefined) {
|
|
213
229
|
if (actions[idRef.current]) {
|
|
214
|
-
actions
|
|
230
|
+
// catch all actions don't have a handler
|
|
231
|
+
if (isFrontendAction(action)) {
|
|
232
|
+
actions[idRef.current].handler = action.handler as any;
|
|
233
|
+
}
|
|
215
234
|
if (typeof action.render === "function") {
|
|
216
235
|
if (chatComponentsCache.current !== null) {
|
|
217
|
-
|
|
236
|
+
// TODO: using as any here because the type definitions are getting to tricky
|
|
237
|
+
// not wasting time on this now - we know the types are compatible
|
|
238
|
+
chatComponentsCache.current.actions[action.name] = action.render as any;
|
|
218
239
|
}
|
|
219
240
|
}
|
|
220
241
|
}
|
|
@@ -223,23 +244,25 @@ export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
|
223
244
|
useEffect(() => {
|
|
224
245
|
setAction(idRef.current, action as any);
|
|
225
246
|
if (chatComponentsCache.current !== null && action.render !== undefined) {
|
|
226
|
-
|
|
247
|
+
// see comment about type safety above
|
|
248
|
+
chatComponentsCache.current.actions[action.name] = action.render as any;
|
|
227
249
|
}
|
|
228
250
|
return () => {
|
|
229
251
|
// NOTE: For now, we don't remove the chatComponentsCache entry when the action is removed.
|
|
230
252
|
// This is because we currently don't have access to the messages array in CopilotContext.
|
|
253
|
+
// UPDATE: We now have access, we should remove the entry if not referenced by any message.
|
|
231
254
|
removeAction(idRef.current);
|
|
232
255
|
};
|
|
233
256
|
}, [
|
|
234
257
|
setAction,
|
|
235
258
|
removeAction,
|
|
236
|
-
action.description,
|
|
259
|
+
isFrontendAction(action) ? action.description : undefined,
|
|
237
260
|
action.name,
|
|
238
|
-
action.disabled,
|
|
239
|
-
action.available,
|
|
261
|
+
isFrontendAction(action) ? action.disabled : undefined,
|
|
262
|
+
isFrontendAction(action) ? action.available : undefined,
|
|
240
263
|
// This should be faster than deep equality checking
|
|
241
264
|
// In addition, all major JS engines guarantee the order of object keys
|
|
242
|
-
JSON.stringify(action.parameters),
|
|
265
|
+
JSON.stringify(isFrontendAction(action) ? action.parameters : []),
|
|
243
266
|
// include render only if it's a string
|
|
244
267
|
typeof action.render === "string" ? action.render : undefined,
|
|
245
268
|
// dependencies set by the developer
|
|
@@ -247,6 +270,12 @@ export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
|
247
270
|
]);
|
|
248
271
|
}
|
|
249
272
|
|
|
273
|
+
function isFrontendAction<T extends Parameter[]>(
|
|
274
|
+
action: FrontendAction<T> | CatchAllFrontendAction,
|
|
275
|
+
): action is FrontendAction<T> {
|
|
276
|
+
return action.name !== "*";
|
|
277
|
+
}
|
|
278
|
+
|
|
250
279
|
interface RenderAndWaitForResponse {
|
|
251
280
|
promise: Promise<any>;
|
|
252
281
|
resolve: (result: any) => void;
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
import { useRef, useEffect, useCallback } from "react";
|
|
42
|
-
import { useCopilotContext } from "../context/copilot-context";
|
|
42
|
+
import { AgentSession, useCopilotContext } from "../context/copilot-context";
|
|
43
43
|
import { Message, Role, TextMessage } from "@copilotkit/runtime-client-gql";
|
|
44
44
|
import { SystemMessageFunction } from "../types";
|
|
45
45
|
import { useChat } from "./use-chat";
|
|
@@ -47,6 +47,7 @@ import { defaultCopilotContextCategories } from "../components";
|
|
|
47
47
|
import { MessageStatusCode } from "@copilotkit/runtime-client-gql";
|
|
48
48
|
import { CoAgentStateRenderHandlerArguments } from "@copilotkit/shared";
|
|
49
49
|
import { useCopilotMessagesContext } from "../context";
|
|
50
|
+
import { useAsyncCallback } from "../components/error-boundary/error-utils";
|
|
50
51
|
|
|
51
52
|
export interface UseCopilotChatOptions {
|
|
52
53
|
/**
|
|
@@ -78,6 +79,7 @@ export interface UseCopilotChatReturn {
|
|
|
78
79
|
deleteMessage: (messageId: string) => void;
|
|
79
80
|
reloadMessages: () => Promise<void>;
|
|
80
81
|
stopGeneration: () => void;
|
|
82
|
+
reset: () => void;
|
|
81
83
|
isLoading: boolean;
|
|
82
84
|
runChatCompletion: () => Promise<Message[]>;
|
|
83
85
|
}
|
|
@@ -99,6 +101,12 @@ export function useCopilotChat({
|
|
|
99
101
|
coAgentStateRenders,
|
|
100
102
|
agentSession,
|
|
101
103
|
setAgentSession,
|
|
104
|
+
agentLock,
|
|
105
|
+
threadId,
|
|
106
|
+
setThreadId,
|
|
107
|
+
runId,
|
|
108
|
+
setRunId,
|
|
109
|
+
chatAbortControllerRef,
|
|
102
110
|
} = useCopilotContext();
|
|
103
111
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
104
112
|
|
|
@@ -123,7 +131,7 @@ export function useCopilotChat({
|
|
|
123
131
|
});
|
|
124
132
|
}, [getContextString, makeSystemMessage, chatInstructions]);
|
|
125
133
|
|
|
126
|
-
const onCoAgentStateRender =
|
|
134
|
+
const onCoAgentStateRender = useAsyncCallback(
|
|
127
135
|
async (args: CoAgentStateRenderHandlerArguments) => {
|
|
128
136
|
const { name, nodeName, state } = args;
|
|
129
137
|
let action = Object.values(coAgentStateRenders).find(
|
|
@@ -157,27 +165,32 @@ export function useCopilotChat({
|
|
|
157
165
|
setCoagentStatesWithRef,
|
|
158
166
|
agentSession,
|
|
159
167
|
setAgentSession,
|
|
168
|
+
threadId,
|
|
169
|
+
setThreadId,
|
|
170
|
+
runId,
|
|
171
|
+
setRunId,
|
|
172
|
+
chatAbortControllerRef,
|
|
160
173
|
});
|
|
161
174
|
|
|
162
|
-
// this is a workaround born out of a bug that Athena
|
|
175
|
+
// this is a workaround born out of a bug that Athena incessantly ran into.
|
|
163
176
|
// We could not find the origin of the bug, however, it was clear that an outdated version of the append function was being used somehow --
|
|
164
|
-
// it
|
|
177
|
+
// it referenced the old state of the messages array, and not the latest one.
|
|
165
178
|
//
|
|
166
179
|
// We want to make copilotkit as abuse-proof as possible, so we are adding this workaround to ensure that the latest version of the append function is always used.
|
|
167
180
|
//
|
|
168
181
|
// How does this work?
|
|
169
182
|
// we store the relevant function in a ref that is always up-to-date, and then we use that ref in the callback.
|
|
170
183
|
const latestAppend = useUpdatedRef(append);
|
|
171
|
-
const latestAppendFunc =
|
|
172
|
-
(message: Message) => {
|
|
173
|
-
return latestAppend.current(message);
|
|
184
|
+
const latestAppendFunc = useAsyncCallback(
|
|
185
|
+
async (message: Message) => {
|
|
186
|
+
return await latestAppend.current(message);
|
|
174
187
|
},
|
|
175
188
|
[latestAppend],
|
|
176
189
|
);
|
|
177
190
|
|
|
178
191
|
const latestReload = useUpdatedRef(reload);
|
|
179
|
-
const latestReloadFunc =
|
|
180
|
-
return latestReload.current();
|
|
192
|
+
const latestReloadFunc = useAsyncCallback(async () => {
|
|
193
|
+
return await latestReload.current();
|
|
181
194
|
}, [latestReload]);
|
|
182
195
|
|
|
183
196
|
const latestStop = useUpdatedRef(stop);
|
|
@@ -202,16 +215,44 @@ export function useCopilotChat({
|
|
|
202
215
|
);
|
|
203
216
|
|
|
204
217
|
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
205
|
-
const latestRunChatCompletionFunc =
|
|
206
|
-
return latestRunChatCompletion.current!();
|
|
218
|
+
const latestRunChatCompletionFunc = useAsyncCallback(async () => {
|
|
219
|
+
return await latestRunChatCompletion.current!();
|
|
207
220
|
}, [latestRunChatCompletion]);
|
|
208
221
|
|
|
222
|
+
const reset = useCallback(() => {
|
|
223
|
+
latestStopFunc();
|
|
224
|
+
setMessages([]);
|
|
225
|
+
setThreadId(null);
|
|
226
|
+
setRunId(null);
|
|
227
|
+
setCoagentStatesWithRef({});
|
|
228
|
+
let initialAgentSession: AgentSession | null = null;
|
|
229
|
+
if (agentLock) {
|
|
230
|
+
initialAgentSession = {
|
|
231
|
+
agentName: agentLock,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
setAgentSession(initialAgentSession);
|
|
235
|
+
}, [
|
|
236
|
+
latestStopFunc,
|
|
237
|
+
setMessages,
|
|
238
|
+
setThreadId,
|
|
239
|
+
setCoagentStatesWithRef,
|
|
240
|
+
setAgentSession,
|
|
241
|
+
agentLock,
|
|
242
|
+
]);
|
|
243
|
+
|
|
244
|
+
const latestReset = useUpdatedRef(reset);
|
|
245
|
+
const latestResetFunc = useCallback(() => {
|
|
246
|
+
return latestReset.current();
|
|
247
|
+
}, [latestReset]);
|
|
248
|
+
|
|
209
249
|
return {
|
|
210
250
|
visibleMessages: messages,
|
|
211
251
|
appendMessage: latestAppendFunc,
|
|
212
252
|
setMessages: latestSetMessagesFunc,
|
|
213
253
|
reloadMessages: latestReloadFunc,
|
|
214
254
|
stopGeneration: latestStopFunc,
|
|
255
|
+
reset: latestResetFunc,
|
|
215
256
|
deleteMessage: latestDeleteFunc,
|
|
216
257
|
runChatCompletion: latestRunChatCompletionFunc,
|
|
217
258
|
isLoading,
|
|
@@ -5,9 +5,11 @@ import {
|
|
|
5
5
|
} from "@copilotkit/runtime-client-gql";
|
|
6
6
|
import { useToast } from "../components/toast/toast-provider";
|
|
7
7
|
import { useMemo } from "react";
|
|
8
|
+
import { useErrorToast } from "../components/error-boundary/error-utils";
|
|
8
9
|
|
|
9
10
|
export const useCopilotRuntimeClient = (options: CopilotRuntimeClientOptions) => {
|
|
10
11
|
const { addGraphQLErrorsToast } = useToast();
|
|
12
|
+
const addErrorToast = useErrorToast();
|
|
11
13
|
|
|
12
14
|
const runtimeClient = useMemo(() => {
|
|
13
15
|
return new CopilotRuntimeClient({
|
|
@@ -15,6 +17,8 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientOptions) =>
|
|
|
15
17
|
handleGQLErrors: (error) => {
|
|
16
18
|
if ((error as any).graphQLErrors.length) {
|
|
17
19
|
addGraphQLErrorsToast((error as any).graphQLErrors as GraphQLError[]);
|
|
20
|
+
} else {
|
|
21
|
+
addErrorToast([error]);
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
24
|
});
|
package/src/lib/copilot-task.ts
CHANGED
|
@@ -57,11 +57,9 @@ import {
|
|
|
57
57
|
filterAgentStateMessages,
|
|
58
58
|
CopilotRequestType,
|
|
59
59
|
} from "@copilotkit/runtime-client-gql";
|
|
60
|
-
import { FrontendAction } from "../types/frontend-action";
|
|
60
|
+
import { FrontendAction, processActionsForRuntimeRequest } from "../types/frontend-action";
|
|
61
61
|
import { CopilotContextParams } from "../context";
|
|
62
62
|
import { defaultCopilotContextCategories } from "../components";
|
|
63
|
-
import { MessageStatusCode } from "@copilotkit/runtime-client-gql";
|
|
64
|
-
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
65
63
|
|
|
66
64
|
export interface CopilotTaskConfig {
|
|
67
65
|
/**
|
|
@@ -137,11 +135,7 @@ export class CopilotTask<T = any> {
|
|
|
137
135
|
.generateCopilotResponse({
|
|
138
136
|
data: {
|
|
139
137
|
frontend: {
|
|
140
|
-
actions: Object.values(actions)
|
|
141
|
-
name: action.name,
|
|
142
|
-
description: action.description || "",
|
|
143
|
-
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
|
|
144
|
-
})),
|
|
138
|
+
actions: processActionsForRuntimeRequest(Object.values(actions)),
|
|
145
139
|
url: window.location.href,
|
|
146
140
|
},
|
|
147
141
|
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionInputAvailability } from "@copilotkit/runtime-client-gql";
|
|
2
|
+
import {
|
|
3
|
+
Action,
|
|
4
|
+
Parameter,
|
|
5
|
+
MappedParameterTypes,
|
|
6
|
+
actionParametersToJsonSchema,
|
|
7
|
+
} from "@copilotkit/shared";
|
|
2
8
|
import React from "react";
|
|
3
9
|
|
|
4
10
|
interface InProgressState<T extends Parameter[] | [] = []> {
|
|
@@ -110,9 +116,24 @@ export type ActionRenderPropsNoArgsWait<T extends Parameter[] | [] = []> =
|
|
|
110
116
|
| ExecutingStateNoArgsWait<T>
|
|
111
117
|
| InProgressStateNoArgsWait<T>;
|
|
112
118
|
|
|
119
|
+
export type CatchAllActionRenderProps<T extends Parameter[] | [] = []> =
|
|
120
|
+
| (CompleteState<T> & {
|
|
121
|
+
name: string;
|
|
122
|
+
})
|
|
123
|
+
| (ExecutingState<T> & {
|
|
124
|
+
name: string;
|
|
125
|
+
})
|
|
126
|
+
| (InProgressState<T> & {
|
|
127
|
+
name: string;
|
|
128
|
+
});
|
|
129
|
+
|
|
113
130
|
export type FrontendActionAvailability = "disabled" | "enabled" | "remote";
|
|
114
131
|
|
|
115
|
-
export type FrontendAction<
|
|
132
|
+
export type FrontendAction<
|
|
133
|
+
T extends Parameter[] | [] = [],
|
|
134
|
+
N extends string = string,
|
|
135
|
+
> = Action<T> & {
|
|
136
|
+
name: Exclude<N, "*">;
|
|
116
137
|
/**
|
|
117
138
|
* @deprecated Use `available` instead.
|
|
118
139
|
*/
|
|
@@ -143,4 +164,36 @@ export type FrontendAction<T extends Parameter[] | [] = []> = Action<T> & {
|
|
|
143
164
|
}
|
|
144
165
|
);
|
|
145
166
|
|
|
167
|
+
export type CatchAllFrontendAction = {
|
|
168
|
+
name: "*";
|
|
169
|
+
render: (props: CatchAllActionRenderProps<any>) => React.ReactElement;
|
|
170
|
+
};
|
|
171
|
+
|
|
146
172
|
export type RenderFunctionStatus = ActionRenderProps<any>["status"];
|
|
173
|
+
|
|
174
|
+
export function processActionsForRuntimeRequest(actions: FrontendAction<any>[]) {
|
|
175
|
+
const filteredActions = actions
|
|
176
|
+
.filter(
|
|
177
|
+
(action) =>
|
|
178
|
+
action.available !== ActionInputAvailability.Disabled &&
|
|
179
|
+
action.disabled !== true &&
|
|
180
|
+
action.name !== "*",
|
|
181
|
+
)
|
|
182
|
+
.map((action) => {
|
|
183
|
+
let available: ActionInputAvailability | undefined = ActionInputAvailability.Enabled;
|
|
184
|
+
if (action.disabled) {
|
|
185
|
+
available = ActionInputAvailability.Disabled;
|
|
186
|
+
} else if (action.available === "disabled") {
|
|
187
|
+
available = ActionInputAvailability.Disabled;
|
|
188
|
+
} else if (action.available === "remote") {
|
|
189
|
+
available = ActionInputAvailability.Remote;
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
name: action.name,
|
|
193
|
+
description: action.description || "",
|
|
194
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
|
|
195
|
+
available,
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
return filteredActions;
|
|
199
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export type { DocumentPointer } from "./document-pointer";
|
|
2
2
|
export type { SystemMessageFunction } from "./system-message";
|
|
3
|
-
export type {
|
|
3
|
+
export type {
|
|
4
|
+
ActionRenderProps,
|
|
5
|
+
RenderFunctionStatus,
|
|
6
|
+
CatchAllActionRenderProps,
|
|
7
|
+
} from "./frontend-action";
|
|
4
8
|
export type { CopilotChatSuggestionConfiguration } from "./chat-suggestion-configuration";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/toast/toast-provider.tsx"],"sourcesContent":["import { useCopilotContext } from \"../../context\";\nimport { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport React, { createContext, useContext, useState, useCallback } from \"react\";\nimport { ExclamationMarkIcon } from \"./exclamation-mark-icon\";\n\ninterface Toast {\n id: string;\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n duration?: number;\n}\n\ninterface ToastContextValue {\n toasts: Toast[];\n addToast: (toast: Omit<Toast, \"id\">) => void;\n addGraphQLErrorsToast: (errors: GraphQLError[]) => void;\n removeToast: (id: string) => void;\n enabled: boolean;\n}\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\nexport function useToast() {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used within a ToastProvider\");\n }\n return context;\n}\n\nexport function ToastProvider({\n enabled,\n children,\n}: {\n enabled: boolean;\n children: React.ReactNode;\n}) {\n const [toasts, setToasts] = useState<Toast[]>([]);\n const addToast = useCallback((toast: Omit<Toast, \"id\">) => {\n const id = Math.random().toString(36).substring(2, 9);\n\n setToasts((currentToasts) => [...currentToasts, { ...toast, id }]);\n\n if (toast.duration) {\n setTimeout(() => {\n removeToast(id);\n }, toast.duration);\n }\n }, []);\n\n const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {\n // We do not display these errors unless we are in dev mode.\n // if (!showDevConsole) {\n // return;\n // }\n\n const errorsToRender = errors.map((error, idx) => {\n const message = error.message;\n const code = error.extensions?.code as string;\n\n return (\n <div\n key={idx}\n style={{\n marginTop: idx === 0 ? 0 : 10,\n marginBottom: 14,\n }}\n >\n <ExclamationMarkIcon style={{ marginBottom: 4 }} />\n\n {code && (\n <div\n style={{\n fontWeight: \"600\",\n marginBottom: 4,\n }}\n >\n Copilot Cloud Error:{\" \"}\n <span style={{ fontFamily: \"monospace\", fontWeight: \"normal\" }}>{code}</span>\n </div>\n )}\n <div>{message}</div>\n </div>\n );\n });\n\n addToast({\n type: \"error\",\n message: (\n <div\n style={{\n fontSize: \"13px\",\n maxWidth: \"600px\",\n }}\n >\n {errorsToRender}\n <div style={{ fontSize: \"11px\", opacity: 0.75 }}>\n NOTE: This is a Copilot Cloud error, and it only displays during local development.\n </div>\n </div>\n ),\n });\n }, []);\n\n const removeToast = useCallback((id: string) => {\n setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));\n }, []);\n\n const value = {\n toasts,\n addToast,\n addGraphQLErrorsToast,\n removeToast,\n enabled,\n };\n\n return (\n <ToastContext.Provider value={value}>\n <div\n style={{\n position: \"fixed\",\n bottom: \"1rem\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"0.5rem\",\n }}\n >\n {toasts.length > 1 && (\n <div style={{ textAlign: \"right\" }}>\n <button\n onClick={() => setToasts([])}\n style={{\n padding: \"4px 8px\",\n fontSize: \"12px\",\n cursor: \"pointer\",\n background: \"white\",\n border: \"1px solid rgba(0,0,0,0.2)\",\n borderRadius: \"4px\",\n }}\n >\n Close All\n </button>\n </div>\n )}\n {toasts.map((toast) => (\n <Toast\n key={toast.id}\n message={toast.message}\n type={toast.type}\n onClose={() => removeToast(toast.id)}\n />\n ))}\n </div>\n {children}\n </ToastContext.Provider>\n );\n}\n\nfunction Toast({\n message,\n type = \"info\",\n onClose,\n}: {\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n onClose: () => void;\n}) {\n const bgColors = {\n info: \"#3b82f6\",\n success: \"#22c55e\",\n warning: \"#eab308\",\n error: \"#ef4444\",\n };\n\n return (\n <div\n style={{\n backgroundColor: bgColors[type],\n color: \"white\",\n padding: \"0.5rem 1rem\",\n borderRadius: \"0.25rem\",\n boxShadow: \"0 2px 4px rgba(0,0,0,0.1)\",\n position: \"relative\",\n minWidth: \"200px\",\n }}\n >\n <div>{message}</div>\n <button\n onClick={onClose}\n style={{\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n background: \"none\",\n border: \"none\",\n color: \"white\",\n cursor: \"pointer\",\n padding: \"0.5rem\",\n fontSize: \"1rem\",\n }}\n >\n ✕\n </button>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAEA,SAAgB,eAAe,YAAY,UAAU,mBAAmB;AAkE9D,cAGE,YAHF;AAhDV,IAAM,eAAe,cAA6C,MAAS;AAEpE,SAAS,WAAW;AACzB,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;AAEO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AACF,GAGG;AACD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAkB,CAAC,CAAC;AAChD,QAAM,WAAW,YAAY,CAAC,UAA6B;AACzD,UAAM,KAAK,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC;AAEpD,cAAU,CAAC,kBAAkB,CAAC,GAAG,eAAe,iCAAK,QAAL,EAAY,GAAG,EAAC,CAAC;AAEjE,QAAI,MAAM,UAAU;AAClB,iBAAW,MAAM;AACf,oBAAY,EAAE;AAAA,MAChB,GAAG,MAAM,QAAQ;AAAA,IACnB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,QAAM,wBAAwB,YAAY,CAAC,WAA2B;AAMpE,UAAM,iBAAiB,OAAO,IAAI,CAAC,OAAO,QAAQ;AAxDtD;AAyDM,YAAM,UAAU,MAA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A,YACZ;AAAA,YACD;AAAA;AAAA,QAED;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/extract.ts","../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["import {\n Action,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n MappedParameterTypes,\n Parameter,\n actionParametersToJsonSchema,\n} from \"@copilotkit/shared\";\nimport {\n ActionExecutionMessage,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\nimport { CopilotContextParams, CopilotMessagesContextParams } from \"../context\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\nimport {\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n} from \"@copilotkit/runtime-client-gql\";\n\ninterface InitialState<T extends Parameter[] | [] = []> {\n status: \"initial\";\n args: Partial<MappedParameterTypes<T>>;\n}\n\ninterface InProgressState<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n}\n\ninterface CompleteState<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n}\n\ntype StreamHandlerArgs<T extends Parameter[] | [] = []> =\n | InitialState<T>\n | InProgressState<T>\n | CompleteState<T>;\n\ninterface ExtractOptions<T extends Parameter[]> {\n context: CopilotContextParams & CopilotMessagesContextParams;\n instructions: string;\n parameters: T;\n include?: IncludeOptions;\n data?: any;\n abortSignal?: AbortSignal;\n stream?: (args: StreamHandlerArgs<T>) => void;\n requestType?: CopilotRequestType;\n}\n\ninterface IncludeOptions {\n readable?: boolean;\n messages?: boolean;\n}\n\nexport async function extract<const T extends Parameter[]>({\n context,\n instructions,\n parameters,\n include,\n data,\n abortSignal,\n stream,\n requestType = CopilotRequestType.Task,\n}: ExtractOptions<T>): Promise<MappedParameterTypes<T>> {\n const { messages } = context;\n\n const action: Action<any> = {\n name: \"extract\",\n description: instructions,\n parameters,\n handler: (args: any) => {},\n };\n\n const includeReadable = include?.readable ?? false;\n const includeMessages = include?.messages ?? false;\n\n let contextString = \"\";\n\n if (data) {\n contextString = (typeof data === \"string\" ? data : JSON.stringify(data)) + \"\\n\\n\";\n }\n\n if (includeReadable) {\n contextString += context.getContextString([], defaultCopilotContextCategories);\n }\n\n const systemMessage: Message = new TextMessage({\n content: makeSystemMessage(contextString, instructions),\n role: Role.System,\n });\n\n const instructionsMessage: Message = new TextMessage({\n content: makeInstructionsMessage(instructions),\n role: Role.User,\n });\n\n const response = context.runtimeClient.asStream(\n context.runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [\n {\n name: action.name,\n description: action.description || \"\",\n jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),\n },\n ],\n url: window.location.href,\n },\n\n messages: convertMessagesToGqlInput(\n includeMessages\n ? [systemMessage, instructionsMessage, ...filterAgentStateMessages(messages)]\n : [systemMessage, instructionsMessage],\n ),\n metadata: {\n requestType: requestType,\n },\n forwardedParameters: {\n toolChoice: \"function\",\n toolChoiceFunctionName: action.name,\n },\n },\n properties: context.copilotApiConfig.properties,\n signal: abortSignal,\n }),\n );\n\n const reader = response.getReader();\n\n let isInitial = true;\n\n let actionExecutionMessage: ActionExecutionMessage | undefined = undefined;\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n if (abortSignal?.aborted) {\n throw new Error(\"Aborted\");\n }\n\n actionExecutionMessage = convertGqlOutputToMessages(\n value.generateCopilotResponse.messages,\n ).find((msg) => msg.isActionExecutionMessage()) as ActionExecutionMessage | undefined;\n\n if (!actionExecutionMessage) {\n continue;\n }\n\n stream?.({\n status: isInitial ? \"initial\" : \"inProgress\",\n args: actionExecutionMessage.arguments as Partial<MappedParameterTypes<T>>,\n });\n\n isInitial = false;\n }\n\n if (!actionExecutionMessage) {\n throw new Error(\"extract() failed: No function call occurred\");\n }\n\n stream?.({\n status: \"complete\",\n args: actionExecutionMessage.arguments as MappedParameterTypes<T>,\n });\n\n return actionExecutionMessage.arguments as MappedParameterTypes<T>;\n}\n\n// We need to put this in a user message since some LLMs need\n// at least one user message to function\nfunction makeInstructionsMessage(instructions: string): string {\n return `\nThe user has given you the following task to complete:\n\n\\`\\`\\`\n${instructions}\n\\`\\`\\`\n\nAny additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.\n`;\n}\n\nfunction makeSystemMessage(contextString: string, instructions: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with a function called extract you MUST call to initiate actions on their behalf.\n\nPlease assist them as best you can.\n\nThis is not a conversation, so please do not ask questions. Just call the function without saying anything else.\n`;\n}\n","/**\n * This component will typically wrap your entire application (or a sub-tree of your application where you want to have a copilot). It provides the copilot context to all other components and hooks.\n *\n * ## Example\n *\n * You can find more information about self-hosting CopilotKit [here](/guides/self-hosting).\n *\n * ```tsx\n * import { CopilotKit } from \"@copilotkit/react-core\";\n *\n * <CopilotKit runtimeUrl=\"<your-runtime-url>\">\n * // ... your app ...\n * </CopilotKit>\n * ```\n */\n\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport {\n CopilotContext,\n CopilotApiConfig,\n ChatComponentsCache,\n AgentSession,\n} from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { CopilotChatSuggestionConfiguration, DocumentPointer } from \"../../types\";\nimport { flushSync } from \"react-dom\";\nimport {\n COPILOT_CLOUD_CHAT_URL,\n CopilotCloudConfig,\n FunctionCallHandler,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n} from \"@copilotkit/shared\";\n\nimport { FrontendAction } from \"../../types/frontend-action\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\nimport { CoAgentStateRender } from \"../../types/coagent-action\";\nimport { CoagentState } from \"../../types/coagent-state\";\nimport { CopilotMessages } from \"./copilot-messages\";\nimport { ToastProvider } from \"../toast/toast-provider\";\nimport { useCopilotRuntimeClient } from \"../../hooks/use-copilot-runtime-client\";\nimport { shouldShowDevConsole } from \"../../utils\";\n\nexport function CopilotKit({ children, ...props }: CopilotKitProps) {\n const showDevConsole = props.showDevConsole === undefined ? \"auto\" : props.showDevConsole;\n const enabled = shouldShowDevConsole(showDevConsole);\n return (\n <ToastProvider enabled={enabled}>\n <CopilotKitInternal {...props}>{children}</CopilotKitInternal>\n </ToastProvider>\n );\n}\n\nexport function CopilotKitInternal({ children, ...props }: CopilotKitProps) {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n if (!props.runtimeUrl && !props.publicApiKey) {\n throw new Error(\n \"Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component.\",\n );\n }\n\n const chatApiEndpoint = props.runtimeUrl || COPILOT_CLOUD_CHAT_URL;\n\n const [actions, setActions] = useState<Record<string, FrontendAction<any>>>({});\n const [coAgentStateRenders, setCoAgentStateRenders] = useState<\n Record<string, CoAgentStateRender<any>>\n >({});\n const chatComponentsCache = useRef<ChatComponentsCache>({\n actions: {},\n coAgentStateRenders: {},\n });\n const { addElement, removeElement, printTree } = useTree();\n const [isLoading, setIsLoading] = useState(false);\n const [chatInstructions, setChatInstructions] = useState(\"\");\n\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setAction = useCallback((id: string, action: FrontendAction<any>) => {\n setActions((prevPoints) => {\n return {\n ...prevPoints,\n [id]: action,\n };\n });\n }, []);\n\n const removeAction = useCallback((id: string) => {\n setActions((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const setCoAgentStateRender = useCallback((id: string, stateRender: CoAgentStateRender<any>) => {\n setCoAgentStateRenders((prevPoints) => {\n return {\n ...prevPoints,\n [id]: stateRender,\n };\n });\n }, []);\n\n const removeCoAgentStateRender = useCallback((id: string) => {\n setCoAgentStateRenders((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${document.sourceApplication}):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree],\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories,\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement],\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement],\n );\n\n const getFunctionCallHandler = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));\n },\n [actions],\n );\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments],\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument],\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument],\n );\n\n if (!props.publicApiKey) {\n if (props.cloudRestrictToTopic) {\n throw new Error(\n \"To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey.\",\n );\n }\n }\n\n // get the appropriate CopilotApiConfig from the props\n const copilotApiConfig: CopilotApiConfig = useMemo(() => {\n let cloud: CopilotCloudConfig | undefined = undefined;\n if (props.publicApiKey) {\n cloud = {\n guardrails: {\n input: {\n restrictToTopic: {\n enabled: props.cloudRestrictToTopic ? true : false,\n validTopics: props.cloudRestrictToTopic?.validTopics || [],\n invalidTopics: props.cloudRestrictToTopic?.invalidTopics || [],\n },\n },\n },\n };\n }\n\n return {\n publicApiKey: props.publicApiKey,\n ...(cloud ? { cloud } : {}),\n chatApiEndpoint: chatApiEndpoint,\n headers: props.headers || {},\n properties: props.properties || {},\n transcribeAudioUrl: props.transcribeAudioUrl,\n textToSpeechUrl: props.textToSpeechUrl,\n credentials: props.credentials,\n };\n }, [\n props.publicApiKey,\n props.headers,\n props.properties,\n props.transcribeAudioUrl,\n props.textToSpeechUrl,\n props.credentials,\n props.cloudRestrictToTopic,\n ]);\n\n const headers = {\n ...(copilotApiConfig.headers || {}),\n ...(copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }\n : {}),\n };\n\n const runtimeClient = useCopilotRuntimeClient({\n url: copilotApiConfig.chatApiEndpoint,\n publicApiKey: copilotApiConfig.publicApiKey,\n headers,\n credentials: copilotApiConfig.credentials,\n });\n\n const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState<{\n [key: string]: CopilotChatSuggestionConfiguration;\n }>({});\n\n const addChatSuggestionConfiguration = (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => {\n setChatSuggestionConfiguration((prev) => ({ ...prev, [id]: suggestion }));\n };\n\n const removeChatSuggestionConfiguration = (id: string) => {\n setChatSuggestionConfiguration((prev) => {\n const { [id]: _, ...rest } = prev;\n return rest;\n });\n };\n\n const [coagentStates, setCoagentStates] = useState<Record<string, CoagentState>>({});\n const coagentStatesRef = useRef<Record<string, CoagentState>>({});\n const setCoagentStatesWithRef = useCallback(\n (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => {\n const newValue = typeof value === \"function\" ? value(coagentStatesRef.current) : value;\n coagentStatesRef.current = newValue;\n setCoagentStates((prev) => {\n return newValue;\n });\n },\n [],\n );\n\n let initialAgentSession: AgentSession | null = null;\n if (props.agent) {\n initialAgentSession = {\n agentName: props.agent,\n };\n }\n\n const [agentSession, setAgentSession] = useState<AgentSession | null>(initialAgentSession);\n\n const showDevConsole = props.showDevConsole === undefined ? \"auto\" : props.showDevConsole;\n\n return (\n <CopilotContext.Provider\n value={{\n actions,\n chatComponentsCache,\n getFunctionCallHandler,\n setAction,\n removeAction,\n coAgentStateRenders,\n setCoAgentStateRender,\n removeCoAgentStateRender,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: copilotApiConfig,\n isLoading,\n setIsLoading,\n chatSuggestionConfiguration,\n addChatSuggestionConfiguration,\n removeChatSuggestionConfiguration,\n chatInstructions,\n setChatInstructions,\n showDevConsole,\n coagentStates,\n setCoagentStates,\n coagentStatesRef,\n setCoagentStatesWithRef,\n agentSession,\n setAgentSession,\n runtimeClient,\n }}\n >\n <CopilotMessages>{children}</CopilotMessages>\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToFunctionCallHandler(actions: FrontendAction<any>[]): FunctionCallHandler {\n return async ({ messages, name, args }) => {\n let actionsByFunctionName: Record<string, FrontendAction<any>> = {};\n for (let action of actions) {\n actionsByFunctionName[action.name] = action;\n }\n\n const action = actionsByFunctionName[name];\n let result: any = undefined;\n if (action) {\n await new Promise<void>((resolve, reject) => {\n flushSync(async () => {\n try {\n result = await action.handler?.(args);\n resolve();\n } catch (error) {\n reject(error);\n }\n });\n });\n await new Promise((resolve) => setTimeout(resolve, 20));\n }\n return result;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EAKE;AAAA,OACK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACEP,SAAS,aAAa,SAAS,QAAQ,gBA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