@copilotkit/react-core 1.9.1-next.0 → 1.9.2-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 +17 -0
- package/dist/{chunk-B5UA5G3E.mjs → chunk-2FW7HH6W.mjs} +12 -8
- package/dist/chunk-2FW7HH6W.mjs.map +1 -0
- package/dist/{chunk-ERFA53MG.mjs → chunk-6KGEF242.mjs} +2 -2
- package/dist/chunk-6KGEF242.mjs.map +1 -0
- package/dist/{chunk-2J3SMMGW.mjs → chunk-C6F6EQNA.mjs} +2 -2
- package/dist/chunk-CCESTGAM.mjs +102 -0
- package/dist/chunk-CCESTGAM.mjs.map +1 -0
- package/dist/chunk-GFJW4RIM.mjs +9 -0
- package/dist/chunk-GFJW4RIM.mjs.map +1 -0
- package/dist/chunk-HD2GE3DK.mjs +359 -0
- package/dist/chunk-HD2GE3DK.mjs.map +1 -0
- package/dist/{chunk-74AJEJTV.mjs → chunk-HJP2RX5R.mjs} +11 -6
- package/dist/chunk-HJP2RX5R.mjs.map +1 -0
- package/dist/{chunk-EQ4XLLT4.mjs → chunk-LDACFA2B.mjs} +3 -3
- package/dist/{chunk-FGBRHBRR.mjs → chunk-LZDDYZEY.mjs} +2 -2
- package/dist/chunk-NNSXCFQO.mjs +154 -0
- package/dist/chunk-NNSXCFQO.mjs.map +1 -0
- package/dist/{chunk-WZAEVHLK.mjs → chunk-Q5D5XQFA.mjs} +2 -2
- package/dist/{chunk-534J55RX.mjs → chunk-QQZLIEXK.mjs} +9 -7
- package/dist/chunk-QQZLIEXK.mjs.map +1 -0
- package/dist/chunk-RUY6MLHA.mjs +119 -0
- package/dist/chunk-RUY6MLHA.mjs.map +1 -0
- package/dist/{chunk-MDIIRGJD.mjs → chunk-SGLWMQ2J.mjs} +25 -17
- package/dist/chunk-SGLWMQ2J.mjs.map +1 -0
- package/dist/{chunk-G27C5EFO.mjs → chunk-T42PN5VN.mjs} +7 -5
- package/dist/{chunk-G27C5EFO.mjs.map → chunk-T42PN5VN.mjs.map} +1 -1
- package/dist/{chunk-VQ3VTO26.mjs → chunk-UHQMV2CE.mjs} +2 -2
- package/dist/{chunk-4DVPRMVH.mjs → chunk-UIT6QMUJ.mjs} +7 -7
- package/dist/chunk-VRXANACV.mjs +277 -0
- package/dist/chunk-VRXANACV.mjs.map +1 -0
- package/dist/{chunk-2FLZLANO.mjs → chunk-XY5BN4HZ.mjs} +19 -12
- package/dist/chunk-XY5BN4HZ.mjs.map +1 -0
- package/dist/{chunk-7HDYPEWS.mjs → chunk-YDENFEKA.mjs} +2 -2
- package/dist/{chunk-4VWM6JNK.mjs → chunk-YZDRMIOM.mjs} +6 -6
- package/dist/components/copilot-provider/copilot-messages.js +105 -11
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +4 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +4 -3
- 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 +863 -441
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +10 -9
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +863 -441
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -9
- package/dist/components/error-boundary/error-boundary.js +320 -159
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -3
- package/dist/components/error-boundary/error-utils.js +2 -1
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +863 -441
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -9
- package/dist/components/toast/toast-provider.d.ts +9 -12
- package/dist/components/toast/toast-provider.js +218 -191
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -2
- package/dist/components/usage-banner.d.ts +3 -2
- package/dist/components/usage-banner.js +311 -153
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +1 -1
- 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 +1 -1
- package/dist/{copilot-context-309906bb.d.ts → copilot-context-f9b2b4c3.d.ts} +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +160 -75
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +33 -32
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +243 -68
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +6 -3
- package/dist/hooks/use-coagent-state-render.js +10 -5
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -4
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +148 -67
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -13
- package/dist/hooks/use-copilot-action.js +5 -4
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -3
- 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 +5 -4
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +5 -4
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +138 -62
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -12
- 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 +5 -2
- package/dist/hooks/use-copilot-runtime-client.js +101 -128
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +3 -3
- 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 +140 -64
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -13
- 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 +913 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -34
- 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 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -10
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/dev-console.d.ts +1 -1
- package/dist/utils/dev-console.js +1 -10
- package/dist/utils/dev-console.js.map +1 -1
- package/dist/utils/dev-console.mjs +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +10 -9
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +7 -14
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +12 -11
- package/package.json +3 -3
- package/src/components/copilot-provider/copilot-messages.tsx +163 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +3 -2
- package/src/components/copilot-provider/copilotkit.tsx +8 -2
- package/src/components/error-boundary/error-boundary.tsx +6 -5
- package/src/components/error-boundary/error-utils.tsx +1 -1
- package/src/components/toast/toast-provider.tsx +260 -93
- package/src/components/usage-banner.tsx +311 -131
- package/src/context/copilot-context.tsx +2 -2
- package/src/hooks/use-chat.ts +4 -0
- package/src/hooks/use-coagent-state-render.ts +9 -3
- package/src/hooks/use-coagent.ts +10 -3
- package/src/hooks/use-copilot-runtime-client.ts +153 -12
- package/src/utils/dev-console.ts +2 -17
- package/dist/chunk-22ENANUU.mjs +0 -250
- package/dist/chunk-22ENANUU.mjs.map +0 -1
- package/dist/chunk-2FLZLANO.mjs.map +0 -1
- package/dist/chunk-534J55RX.mjs.map +0 -1
- package/dist/chunk-6PK72HMH.mjs +0 -63
- package/dist/chunk-6PK72HMH.mjs.map +0 -1
- package/dist/chunk-74AJEJTV.mjs.map +0 -1
- package/dist/chunk-B5UA5G3E.mjs.map +0 -1
- package/dist/chunk-BKTARDXX.mjs +0 -40
- package/dist/chunk-BKTARDXX.mjs.map +0 -1
- package/dist/chunk-D34OH4VN.mjs +0 -201
- package/dist/chunk-D34OH4VN.mjs.map +0 -1
- package/dist/chunk-ERFA53MG.mjs.map +0 -1
- package/dist/chunk-MDIIRGJD.mjs.map +0 -1
- package/dist/chunk-MLAS4QUR.mjs +0 -18
- package/dist/chunk-MLAS4QUR.mjs.map +0 -1
- /package/dist/{chunk-2J3SMMGW.mjs.map → chunk-C6F6EQNA.mjs.map} +0 -0
- /package/dist/{chunk-EQ4XLLT4.mjs.map → chunk-LDACFA2B.mjs.map} +0 -0
- /package/dist/{chunk-FGBRHBRR.mjs.map → chunk-LZDDYZEY.mjs.map} +0 -0
- /package/dist/{chunk-WZAEVHLK.mjs.map → chunk-Q5D5XQFA.mjs.map} +0 -0
- /package/dist/{chunk-VQ3VTO26.mjs.map → chunk-UHQMV2CE.mjs.map} +0 -0
- /package/dist/{chunk-4DVPRMVH.mjs.map → chunk-UIT6QMUJ.mjs.map} +0 -0
- /package/dist/{chunk-7HDYPEWS.mjs.map → chunk-YDENFEKA.mjs.map} +0 -0
- /package/dist/{chunk-4VWM6JNK.mjs.map → chunk-YZDRMIOM.mjs.map} +0 -0
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,55 +1,56 @@
|
|
|
1
1
|
import "../chunk-CQPYJIBH.mjs";
|
|
2
|
-
import {
|
|
3
|
-
useMakeCopilotDocumentReadable
|
|
4
|
-
} from "../chunk-VQ3VTO26.mjs";
|
|
5
|
-
import {
|
|
6
|
-
useCopilotAdditionalInstructions
|
|
7
|
-
} from "../chunk-2J3SMMGW.mjs";
|
|
8
|
-
import {
|
|
9
|
-
useCopilotAuthenticatedAction_c
|
|
10
|
-
} from "../chunk-EQ4XLLT4.mjs";
|
|
11
|
-
import {
|
|
12
|
-
useCopilotReadable
|
|
13
|
-
} from "../chunk-FGBRHBRR.mjs";
|
|
14
2
|
import {
|
|
15
3
|
useLangGraphInterruptRender
|
|
16
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-Q5D5XQFA.mjs";
|
|
17
5
|
import {
|
|
18
6
|
useLangGraphInterrupt
|
|
19
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-YZDRMIOM.mjs";
|
|
8
|
+
import {
|
|
9
|
+
useMakeCopilotDocumentReadable
|
|
10
|
+
} from "../chunk-UHQMV2CE.mjs";
|
|
20
11
|
import {
|
|
21
12
|
useCoAgentStateRender
|
|
22
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-2FW7HH6W.mjs";
|
|
23
14
|
import {
|
|
24
15
|
runAgent,
|
|
25
16
|
startAgent,
|
|
26
17
|
stopAgent,
|
|
27
18
|
useCoAgent
|
|
28
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-XY5BN4HZ.mjs";
|
|
20
|
+
import {
|
|
21
|
+
useCopilotAdditionalInstructions
|
|
22
|
+
} from "../chunk-C6F6EQNA.mjs";
|
|
23
|
+
import {
|
|
24
|
+
useCopilotAuthenticatedAction_c
|
|
25
|
+
} from "../chunk-LDACFA2B.mjs";
|
|
26
|
+
import {
|
|
27
|
+
useCopilotAction
|
|
28
|
+
} from "../chunk-T42PN5VN.mjs";
|
|
29
29
|
import {
|
|
30
30
|
useCopilotChat
|
|
31
|
-
} from "../chunk-
|
|
32
|
-
import
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import "../chunk-
|
|
36
|
-
import "../chunk-
|
|
31
|
+
} from "../chunk-UIT6QMUJ.mjs";
|
|
32
|
+
import {
|
|
33
|
+
useCopilotReadable
|
|
34
|
+
} from "../chunk-LZDDYZEY.mjs";
|
|
35
|
+
import "../chunk-SGLWMQ2J.mjs";
|
|
36
|
+
import "../chunk-QQZLIEXK.mjs";
|
|
37
|
+
import "../chunk-NNSXCFQO.mjs";
|
|
38
|
+
import "../chunk-5FHSUKQL.mjs";
|
|
37
39
|
import "../chunk-RKTVJRK7.mjs";
|
|
38
40
|
import "../chunk-PMAFHQ7P.mjs";
|
|
39
|
-
import "../chunk-
|
|
41
|
+
import "../chunk-HD2GE3DK.mjs";
|
|
42
|
+
import "../chunk-YPSGKPDA.mjs";
|
|
40
43
|
import "../chunk-DCTJZ742.mjs";
|
|
41
|
-
import "../chunk-
|
|
42
|
-
import "../chunk-74AJEJTV.mjs";
|
|
44
|
+
import "../chunk-HJP2RX5R.mjs";
|
|
43
45
|
import "../chunk-4CEQJ2X6.mjs";
|
|
46
|
+
import "../chunk-CCESTGAM.mjs";
|
|
47
|
+
import "../chunk-O7ARI5CV.mjs";
|
|
44
48
|
import {
|
|
45
49
|
useCopilotRuntimeClient
|
|
46
|
-
} from "../chunk-
|
|
47
|
-
import
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
import "../chunk-ERFA53MG.mjs";
|
|
51
|
-
import "../chunk-22ENANUU.mjs";
|
|
52
|
-
import "../chunk-O7ARI5CV.mjs";
|
|
50
|
+
} from "../chunk-RUY6MLHA.mjs";
|
|
51
|
+
import "../chunk-GFJW4RIM.mjs";
|
|
52
|
+
import "../chunk-VRXANACV.mjs";
|
|
53
|
+
import "../chunk-6KGEF242.mjs";
|
|
53
54
|
import "../chunk-SKC7AJIV.mjs";
|
|
54
55
|
export {
|
|
55
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-f9b2b4c3.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
|
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
25
37
|
var __export = (target, all) => {
|
|
26
38
|
for (var name in all)
|
|
27
39
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -70,8 +82,8 @@ __export(use_chat_exports, {
|
|
|
70
82
|
useChat: () => useChat
|
|
71
83
|
});
|
|
72
84
|
module.exports = __toCommonJS(use_chat_exports);
|
|
73
|
-
var
|
|
74
|
-
var
|
|
85
|
+
var import_react5 = require("react");
|
|
86
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
75
87
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
76
88
|
|
|
77
89
|
// src/types/frontend-action.ts
|
|
@@ -103,17 +115,213 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
103
115
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
104
116
|
|
|
105
117
|
// src/components/toast/toast-provider.tsx
|
|
118
|
+
var import_react = require("react");
|
|
119
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
120
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
121
|
+
var ToastContext = (0, import_react.createContext)(void 0);
|
|
122
|
+
function useToast() {
|
|
123
|
+
const context = (0, import_react.useContext)(ToastContext);
|
|
124
|
+
if (!context) {
|
|
125
|
+
throw new Error("useToast must be used within a ToastProvider");
|
|
126
|
+
}
|
|
127
|
+
return context;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/hooks/use-copilot-runtime-client.ts
|
|
106
131
|
var import_react2 = require("react");
|
|
132
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
133
|
+
|
|
134
|
+
// src/utils/dev-console.ts
|
|
135
|
+
function shouldShowDevConsole(showDevConsole) {
|
|
136
|
+
return showDevConsole;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/hooks/use-copilot-runtime-client.ts
|
|
140
|
+
var useCopilotRuntimeClient = (options) => {
|
|
141
|
+
const { setBannerError } = useToast();
|
|
142
|
+
const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
|
|
143
|
+
const lastStructuredErrorRef = (0, import_react2.useRef)(null);
|
|
144
|
+
const runtimeClient = (0, import_react2.useMemo)(() => {
|
|
145
|
+
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
146
|
+
handleGQLErrors: (error) => {
|
|
147
|
+
var _a2;
|
|
148
|
+
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
149
|
+
const graphQLErrors = error.graphQLErrors;
|
|
150
|
+
const routeError = (gqlError) => {
|
|
151
|
+
const extensions = gqlError.extensions;
|
|
152
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
153
|
+
const isDev = shouldShowDevConsole(showDevConsole != null ? showDevConsole : false);
|
|
154
|
+
if (visibility === import_shared3.ErrorVisibility.SILENT) {
|
|
155
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (!isDev) {
|
|
159
|
+
console.error("CopilotKit Error (hidden in production):", gqlError.message);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const now = Date.now();
|
|
163
|
+
const errorMessage = gqlError.message;
|
|
164
|
+
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
|
|
168
|
+
const ckError = createStructuredError(gqlError);
|
|
169
|
+
if (ckError) {
|
|
170
|
+
setBannerError(ckError);
|
|
171
|
+
} else {
|
|
172
|
+
const fallbackError = new import_shared3.CopilotKitError({
|
|
173
|
+
message: gqlError.message,
|
|
174
|
+
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
175
|
+
});
|
|
176
|
+
setBannerError(fallbackError);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
graphQLErrors.forEach(routeError);
|
|
180
|
+
} else {
|
|
181
|
+
const isDev = shouldShowDevConsole(showDevConsole != null ? showDevConsole : false);
|
|
182
|
+
if (!isDev) {
|
|
183
|
+
console.error("CopilotKit Error (hidden in production):", error);
|
|
184
|
+
} else {
|
|
185
|
+
const fallbackError = new import_shared3.CopilotKitError({
|
|
186
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
187
|
+
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
188
|
+
});
|
|
189
|
+
setBannerError(fallbackError);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
handleGQLWarning: (message) => {
|
|
194
|
+
console.warn(message);
|
|
195
|
+
const warningError = new import_shared3.CopilotKitError({
|
|
196
|
+
message,
|
|
197
|
+
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
198
|
+
});
|
|
199
|
+
setBannerError(warningError);
|
|
200
|
+
}
|
|
201
|
+
}));
|
|
202
|
+
}, [runtimeOptions, setBannerError, showDevConsole]);
|
|
203
|
+
return runtimeClient;
|
|
204
|
+
};
|
|
205
|
+
function createStructuredError(gqlError) {
|
|
206
|
+
var _a, _b, _c;
|
|
207
|
+
const extensions = gqlError.extensions;
|
|
208
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
209
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
210
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
211
|
+
if (code) {
|
|
212
|
+
return new import_shared3.CopilotKitError({ message, code });
|
|
213
|
+
}
|
|
214
|
+
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
215
|
+
return new import_shared3.CopilotKitApiDiscoveryError({ message });
|
|
216
|
+
}
|
|
217
|
+
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
218
|
+
return new import_shared3.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
219
|
+
}
|
|
220
|
+
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
221
|
+
return new import_shared3.CopilotKitAgentDiscoveryError({
|
|
222
|
+
agentName: "",
|
|
223
|
+
availableAgents: []
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/context/copilot-context.tsx
|
|
230
|
+
var import_react3 = __toESM(require("react"));
|
|
231
|
+
var emptyCopilotContext = {
|
|
232
|
+
actions: {},
|
|
233
|
+
setAction: () => {
|
|
234
|
+
},
|
|
235
|
+
removeAction: () => {
|
|
236
|
+
},
|
|
237
|
+
coAgentStateRenders: {},
|
|
238
|
+
setCoAgentStateRender: () => {
|
|
239
|
+
},
|
|
240
|
+
removeCoAgentStateRender: () => {
|
|
241
|
+
},
|
|
242
|
+
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
243
|
+
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
244
|
+
addContext: () => "",
|
|
245
|
+
removeContext: () => {
|
|
246
|
+
},
|
|
247
|
+
getAllContext: () => [],
|
|
248
|
+
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
249
|
+
})),
|
|
250
|
+
isLoading: false,
|
|
251
|
+
setIsLoading: () => returnAndThrowInDebug(false),
|
|
252
|
+
chatInstructions: "",
|
|
253
|
+
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
254
|
+
additionalInstructions: [],
|
|
255
|
+
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
256
|
+
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
257
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
258
|
+
removeDocumentContext: () => {
|
|
259
|
+
},
|
|
260
|
+
runtimeClient: {},
|
|
261
|
+
copilotApiConfig: new class {
|
|
262
|
+
get chatApiEndpoint() {
|
|
263
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
264
|
+
}
|
|
265
|
+
get headers() {
|
|
266
|
+
return {};
|
|
267
|
+
}
|
|
268
|
+
get body() {
|
|
269
|
+
return {};
|
|
270
|
+
}
|
|
271
|
+
}(),
|
|
272
|
+
chatSuggestionConfiguration: {},
|
|
273
|
+
addChatSuggestionConfiguration: () => {
|
|
274
|
+
},
|
|
275
|
+
removeChatSuggestionConfiguration: () => {
|
|
276
|
+
},
|
|
277
|
+
showDevConsole: false,
|
|
278
|
+
coagentStates: {},
|
|
279
|
+
setCoagentStates: () => {
|
|
280
|
+
},
|
|
281
|
+
coagentStatesRef: { current: {} },
|
|
282
|
+
setCoagentStatesWithRef: () => {
|
|
283
|
+
},
|
|
284
|
+
agentSession: null,
|
|
285
|
+
setAgentSession: () => {
|
|
286
|
+
},
|
|
287
|
+
forwardedParameters: {},
|
|
288
|
+
agentLock: null,
|
|
289
|
+
threadId: "",
|
|
290
|
+
setThreadId: () => {
|
|
291
|
+
},
|
|
292
|
+
runId: null,
|
|
293
|
+
setRunId: () => {
|
|
294
|
+
},
|
|
295
|
+
chatAbortControllerRef: { current: null },
|
|
296
|
+
availableAgents: [],
|
|
297
|
+
extensions: {},
|
|
298
|
+
setExtensions: () => {
|
|
299
|
+
},
|
|
300
|
+
langGraphInterruptAction: null,
|
|
301
|
+
setLangGraphInterruptAction: () => null,
|
|
302
|
+
removeLangGraphInterruptAction: () => null
|
|
303
|
+
};
|
|
304
|
+
var CopilotContext = import_react3.default.createContext(emptyCopilotContext);
|
|
305
|
+
function useCopilotContext() {
|
|
306
|
+
const context = import_react3.default.useContext(CopilotContext);
|
|
307
|
+
if (context === emptyCopilotContext) {
|
|
308
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
309
|
+
}
|
|
310
|
+
return context;
|
|
311
|
+
}
|
|
312
|
+
function returnAndThrowInDebug(_value) {
|
|
313
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
314
|
+
}
|
|
107
315
|
|
|
108
316
|
// src/components/error-boundary/error-utils.tsx
|
|
109
|
-
var
|
|
317
|
+
var import_react4 = require("react");
|
|
110
318
|
|
|
111
319
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
112
|
-
var
|
|
320
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
113
321
|
var ExclamationMarkIcon = ({
|
|
114
322
|
className,
|
|
115
323
|
style
|
|
116
|
-
}) => /* @__PURE__ */ (0,
|
|
324
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
117
325
|
"svg",
|
|
118
326
|
{
|
|
119
327
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -128,23 +336,23 @@ var ExclamationMarkIcon = ({
|
|
|
128
336
|
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
129
337
|
style,
|
|
130
338
|
children: [
|
|
131
|
-
/* @__PURE__ */ (0,
|
|
132
|
-
/* @__PURE__ */ (0,
|
|
133
|
-
/* @__PURE__ */ (0,
|
|
339
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
340
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
341
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
134
342
|
]
|
|
135
343
|
}
|
|
136
344
|
);
|
|
137
345
|
|
|
138
346
|
// src/components/error-boundary/error-utils.tsx
|
|
139
347
|
var import_react_markdown = __toESM(require("react-markdown"));
|
|
140
|
-
var
|
|
348
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
141
349
|
function ErrorToast({ errors }) {
|
|
142
350
|
const errorsToRender = errors.map((error, idx) => {
|
|
143
351
|
var _a, _b, _c;
|
|
144
352
|
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
145
353
|
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
146
354
|
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
147
|
-
return /* @__PURE__ */ (0,
|
|
355
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
148
356
|
"div",
|
|
149
357
|
{
|
|
150
358
|
style: {
|
|
@@ -152,8 +360,8 @@ function ErrorToast({ errors }) {
|
|
|
152
360
|
marginBottom: 14
|
|
153
361
|
},
|
|
154
362
|
children: [
|
|
155
|
-
/* @__PURE__ */ (0,
|
|
156
|
-
code && /* @__PURE__ */ (0,
|
|
363
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
364
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
157
365
|
"div",
|
|
158
366
|
{
|
|
159
367
|
style: {
|
|
@@ -161,19 +369,19 @@ function ErrorToast({ errors }) {
|
|
|
161
369
|
marginBottom: 4
|
|
162
370
|
},
|
|
163
371
|
children: [
|
|
164
|
-
"Copilot
|
|
372
|
+
"Copilot Runtime Error:",
|
|
165
373
|
" ",
|
|
166
|
-
/* @__PURE__ */ (0,
|
|
374
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
167
375
|
]
|
|
168
376
|
}
|
|
169
377
|
),
|
|
170
|
-
/* @__PURE__ */ (0,
|
|
378
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
171
379
|
]
|
|
172
380
|
},
|
|
173
381
|
idx
|
|
174
382
|
);
|
|
175
383
|
});
|
|
176
|
-
return /* @__PURE__ */ (0,
|
|
384
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
177
385
|
"div",
|
|
178
386
|
{
|
|
179
387
|
style: {
|
|
@@ -182,14 +390,14 @@ function ErrorToast({ errors }) {
|
|
|
182
390
|
},
|
|
183
391
|
children: [
|
|
184
392
|
errorsToRender,
|
|
185
|
-
/* @__PURE__ */ (0,
|
|
393
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
186
394
|
]
|
|
187
395
|
}
|
|
188
396
|
);
|
|
189
397
|
}
|
|
190
398
|
function useErrorToast() {
|
|
191
399
|
const { addToast } = useToast();
|
|
192
|
-
return (0,
|
|
400
|
+
return (0, import_react4.useCallback)(
|
|
193
401
|
(error) => {
|
|
194
402
|
const errorId = error.map((err) => {
|
|
195
403
|
var _a, _b;
|
|
@@ -201,7 +409,7 @@ function useErrorToast() {
|
|
|
201
409
|
type: "error",
|
|
202
410
|
id: errorId,
|
|
203
411
|
// Toast libraries typically dedupe by id
|
|
204
|
-
message: /* @__PURE__ */ (0,
|
|
412
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
205
413
|
});
|
|
206
414
|
},
|
|
207
415
|
[addToast]
|
|
@@ -209,7 +417,7 @@ function useErrorToast() {
|
|
|
209
417
|
}
|
|
210
418
|
function useAsyncCallback(callback, deps) {
|
|
211
419
|
const addErrorToast = useErrorToast();
|
|
212
|
-
return (0,
|
|
420
|
+
return (0, import_react4.useCallback)((...args) => __async(this, null, function* () {
|
|
213
421
|
try {
|
|
214
422
|
return yield callback(...args);
|
|
215
423
|
} catch (error) {
|
|
@@ -220,41 +428,6 @@ function useAsyncCallback(callback, deps) {
|
|
|
220
428
|
}), deps);
|
|
221
429
|
}
|
|
222
430
|
|
|
223
|
-
// src/components/toast/toast-provider.tsx
|
|
224
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
225
|
-
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
226
|
-
function useToast() {
|
|
227
|
-
const context = (0, import_react2.useContext)(ToastContext);
|
|
228
|
-
if (!context) {
|
|
229
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
230
|
-
}
|
|
231
|
-
return context;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
235
|
-
var import_react3 = require("react");
|
|
236
|
-
var useCopilotRuntimeClient = (options) => {
|
|
237
|
-
const { addGraphQLErrorsToast } = useToast();
|
|
238
|
-
const addErrorToast = useErrorToast();
|
|
239
|
-
const { addToast } = useToast();
|
|
240
|
-
const runtimeClient = (0, import_react3.useMemo)(() => {
|
|
241
|
-
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
242
|
-
handleGQLErrors: (error) => {
|
|
243
|
-
if (error.graphQLErrors.length) {
|
|
244
|
-
addGraphQLErrorsToast(error.graphQLErrors);
|
|
245
|
-
} else {
|
|
246
|
-
addErrorToast([error]);
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
handleGQLWarning: (message) => {
|
|
250
|
-
console.warn(message);
|
|
251
|
-
addToast({ type: "warning", message });
|
|
252
|
-
}
|
|
253
|
-
}));
|
|
254
|
-
}, [options, addGraphQLErrorsToast, addToast]);
|
|
255
|
-
return runtimeClient;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
431
|
// src/hooks/use-chat.ts
|
|
259
432
|
function useChat(options) {
|
|
260
433
|
const {
|
|
@@ -283,23 +456,25 @@ function useChat(options) {
|
|
|
283
456
|
langGraphInterruptAction,
|
|
284
457
|
setLangGraphInterruptAction
|
|
285
458
|
} = options;
|
|
286
|
-
const runChatCompletionRef = (0,
|
|
459
|
+
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
287
460
|
const addErrorToast = useErrorToast();
|
|
288
|
-
const agentSessionRef = (0,
|
|
461
|
+
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
289
462
|
agentSessionRef.current = agentSession;
|
|
290
|
-
const runIdRef = (0,
|
|
463
|
+
const runIdRef = (0, import_react5.useRef)(runId);
|
|
291
464
|
runIdRef.current = runId;
|
|
292
|
-
const extensionsRef = (0,
|
|
465
|
+
const extensionsRef = (0, import_react5.useRef)(extensions);
|
|
293
466
|
extensionsRef.current = extensions;
|
|
294
467
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
295
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [
|
|
468
|
+
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
469
|
+
const { showDevConsole } = useCopilotContext();
|
|
296
470
|
const runtimeClient = useCopilotRuntimeClient({
|
|
297
471
|
url: copilotConfig.chatApiEndpoint,
|
|
298
472
|
publicApiKey: copilotConfig.publicApiKey,
|
|
299
473
|
headers,
|
|
300
|
-
credentials: copilotConfig.credentials
|
|
474
|
+
credentials: copilotConfig.credentials,
|
|
475
|
+
showDevConsole
|
|
301
476
|
});
|
|
302
|
-
const pendingAppendsRef = (0,
|
|
477
|
+
const pendingAppendsRef = (0, import_react5.useRef)([]);
|
|
303
478
|
const runChatCompletion = useAsyncCallback(
|
|
304
479
|
(previousMessages) => __async(this, null, function* () {
|
|
305
480
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
@@ -415,7 +590,7 @@ function useChat(options) {
|
|
|
415
590
|
(metaEvents != null ? metaEvents : []).forEach((ev) => {
|
|
416
591
|
if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
|
|
417
592
|
let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
|
|
418
|
-
eventValue = (0,
|
|
593
|
+
eventValue = (0, import_shared4.parseJson)(eventValue, eventValue);
|
|
419
594
|
setLangGraphInterruptAction({
|
|
420
595
|
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev)), {
|
|
421
596
|
value: eventValue
|
|
@@ -489,7 +664,7 @@ function useChat(options) {
|
|
|
489
664
|
} else {
|
|
490
665
|
if (agentLock) {
|
|
491
666
|
setAgentSession({
|
|
492
|
-
threadId: (0,
|
|
667
|
+
threadId: (0, import_shared4.randomId)(),
|
|
493
668
|
agentName: agentLock,
|
|
494
669
|
nodeName: void 0
|
|
495
670
|
});
|
|
@@ -550,7 +725,7 @@ function useChat(options) {
|
|
|
550
725
|
if (pairedFeAction) {
|
|
551
726
|
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
552
727
|
name: pairedFeAction.name,
|
|
553
|
-
arguments: (0,
|
|
728
|
+
arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
|
|
554
729
|
status: message.status,
|
|
555
730
|
createdAt: message.createdAt,
|
|
556
731
|
parentMessageId: message.parentMessageId
|
|
@@ -560,7 +735,7 @@ function useChat(options) {
|
|
|
560
735
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
561
736
|
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
562
737
|
name: currentResultMessagePairedFeAction.name,
|
|
563
|
-
arguments: (0,
|
|
738
|
+
arguments: (0, import_shared4.parseJson)(message.result, message.result),
|
|
564
739
|
status: message.status,
|
|
565
740
|
createdAt: message.createdAt
|
|
566
741
|
});
|
|
@@ -632,7 +807,7 @@ function useChat(options) {
|
|
|
632
807
|
}),
|
|
633
808
|
[messages]
|
|
634
809
|
);
|
|
635
|
-
(0,
|
|
810
|
+
(0, import_react5.useEffect)(() => {
|
|
636
811
|
if (!isLoading && pendingAppendsRef.current.length > 0) {
|
|
637
812
|
const pending = pendingAppendsRef.current.splice(0);
|
|
638
813
|
const followUp = pending.some((p) => p.followUp);
|
|
@@ -643,7 +818,7 @@ function useChat(options) {
|
|
|
643
818
|
}
|
|
644
819
|
}
|
|
645
820
|
}, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);
|
|
646
|
-
const composeAndFlushMetaEventsInput = (0,
|
|
821
|
+
const composeAndFlushMetaEventsInput = (0, import_react5.useCallback)(
|
|
647
822
|
(metaEvents) => {
|
|
648
823
|
return metaEvents.reduce((acc, event) => {
|
|
649
824
|
if (!event)
|