@copilotkit/react-core 1.9.2-next.1 → 1.9.2-next.11
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 +78 -0
- package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
- package/dist/{chunk-2FW7HH6W.mjs → chunk-3YHYWAHK.mjs} +3 -3
- package/dist/{chunk-RUY6MLHA.mjs → chunk-55QZ2SVJ.mjs} +36 -6
- package/dist/chunk-55QZ2SVJ.mjs.map +1 -0
- package/dist/chunk-57K2ZJ5F.mjs +348 -0
- package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
- package/dist/{chunk-UIT6QMUJ.mjs → chunk-7BYXCFPB.mjs} +5 -5
- package/dist/{chunk-HJP2RX5R.mjs → chunk-AFDL5JI3.mjs} +82 -15
- package/dist/chunk-AFDL5JI3.mjs.map +1 -0
- package/dist/{chunk-SGLWMQ2J.mjs → chunk-BEDNUHSA.mjs} +15 -12
- package/dist/chunk-BEDNUHSA.mjs.map +1 -0
- package/dist/{chunk-Q5D5XQFA.mjs → chunk-CMQV4XNY.mjs} +2 -2
- package/dist/{chunk-LDACFA2B.mjs → chunk-EF5BNM34.mjs} +3 -3
- package/dist/{chunk-UHQMV2CE.mjs → chunk-ERXWDCY6.mjs} +2 -2
- package/dist/{chunk-NNSXCFQO.mjs → chunk-JDEWNLNP.mjs} +41 -7
- package/dist/chunk-JDEWNLNP.mjs.map +1 -0
- package/dist/{chunk-C6F6EQNA.mjs → chunk-JPMIAGI6.mjs} +2 -2
- package/dist/{chunk-T42PN5VN.mjs → chunk-NQVCZQ5T.mjs} +4 -4
- package/dist/{chunk-YZDRMIOM.mjs → chunk-OIPDW3UR.mjs} +4 -4
- package/dist/{chunk-XY5BN4HZ.mjs → chunk-RYREGU4E.mjs} +11 -8
- package/dist/{chunk-XY5BN4HZ.mjs.map → chunk-RYREGU4E.mjs.map} +1 -1
- package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
- package/dist/{chunk-YDENFEKA.mjs → chunk-U4LIYN3I.mjs} +2 -2
- package/dist/{chunk-LZDDYZEY.mjs → chunk-UBNRUXEK.mjs} +2 -2
- package/dist/{chunk-6KGEF242.mjs → chunk-XFOTNHYA.mjs} +3 -2
- package/dist/chunk-XFOTNHYA.mjs.map +1 -0
- package/dist/chunk-YAF2LATQ.mjs +310 -0
- package/dist/chunk-YAF2LATQ.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +39 -4
- 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 +21 -2
- 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 +330 -240
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +10 -10
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +330 -240
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -10
- package/dist/components/error-boundary/error-boundary.js +135 -146
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -4
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +330 -240
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -10
- package/dist/components/toast/toast-provider.js +118 -85
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.js +135 -146
- 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 +2 -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 +2 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-f9b2b4c3.d.ts → copilot-context-3da805ab.d.ts} +5 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +108 -12
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +32 -32
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +105 -12
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +6 -6
- package/dist/hooks/use-coagent-state-render.js +2 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -3
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +108 -12
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +2 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -4
- package/dist/hooks/use-copilot-additional-instructions.js +2 -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 +2 -1
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +105 -12
- 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 +2 -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 -0
- package/dist/hooks/use-copilot-runtime-client.js +52 -2
- 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-langgraph-interrupt-render.js +2 -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 +105 -12
- 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 +2 -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 +404 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -33
- 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/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 +10 -10
- 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 +7 -3
- package/package.json +4 -3
- package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +75 -0
- package/src/components/copilot-provider/copilot-messages.tsx +46 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +21 -0
- package/src/components/copilot-provider/copilotkit.tsx +5 -1
- package/src/components/toast/toast-provider.tsx +49 -24
- package/src/components/usage-banner.tsx +144 -147
- package/src/context/copilot-context.tsx +7 -1
- package/src/hooks/use-chat.ts +106 -6
- package/src/hooks/use-coagent.ts +5 -0
- package/src/hooks/use-copilot-runtime-client.ts +41 -39
- package/tsconfig.json +1 -8
- package/tsup.config.ts +6 -6
- package/dist/chunk-6KGEF242.mjs.map +0 -1
- package/dist/chunk-HD2GE3DK.mjs +0 -359
- package/dist/chunk-HD2GE3DK.mjs.map +0 -1
- package/dist/chunk-HJP2RX5R.mjs.map +0 -1
- package/dist/chunk-NNSXCFQO.mjs.map +0 -1
- package/dist/chunk-RUY6MLHA.mjs.map +0 -1
- package/dist/chunk-SGLWMQ2J.mjs.map +0 -1
- package/dist/chunk-VRXANACV.mjs +0 -277
- package/dist/chunk-VRXANACV.mjs.map +0 -1
- package/dist/utils/utils.test.d.ts +0 -2
- package/dist/utils/utils.test.js +0 -9
- package/dist/utils/utils.test.js.map +0 -1
- package/dist/utils/utils.test.mjs +0 -7
- package/dist/utils/utils.test.mjs.map +0 -1
- /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
- /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
- /package/dist/{chunk-UIT6QMUJ.mjs.map → chunk-7BYXCFPB.mjs.map} +0 -0
- /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-CMQV4XNY.mjs.map} +0 -0
- /package/dist/{chunk-LDACFA2B.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
- /package/dist/{chunk-UHQMV2CE.mjs.map → chunk-ERXWDCY6.mjs.map} +0 -0
- /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-JPMIAGI6.mjs.map} +0 -0
- /package/dist/{chunk-T42PN5VN.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
- /package/dist/{chunk-YZDRMIOM.mjs.map → chunk-OIPDW3UR.mjs.map} +0 -0
- /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-YDENFEKA.mjs.map → chunk-U4LIYN3I.mjs.map} +0 -0
- /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-UBNRUXEK.mjs.map} +0 -0
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
import "../chunk-CQPYJIBH.mjs";
|
|
2
|
+
import {
|
|
3
|
+
useMakeCopilotDocumentReadable
|
|
4
|
+
} from "../chunk-ERXWDCY6.mjs";
|
|
5
|
+
import {
|
|
6
|
+
useCopilotAdditionalInstructions
|
|
7
|
+
} from "../chunk-JPMIAGI6.mjs";
|
|
8
|
+
import {
|
|
9
|
+
useCopilotAuthenticatedAction_c
|
|
10
|
+
} from "../chunk-EF5BNM34.mjs";
|
|
11
|
+
import {
|
|
12
|
+
useCopilotReadable
|
|
13
|
+
} from "../chunk-UBNRUXEK.mjs";
|
|
2
14
|
import {
|
|
3
15
|
useLangGraphInterruptRender
|
|
4
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-CMQV4XNY.mjs";
|
|
5
17
|
import {
|
|
6
18
|
useLangGraphInterrupt
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import {
|
|
9
|
-
useMakeCopilotDocumentReadable
|
|
10
|
-
} from "../chunk-UHQMV2CE.mjs";
|
|
19
|
+
} from "../chunk-OIPDW3UR.mjs";
|
|
11
20
|
import {
|
|
12
21
|
useCoAgentStateRender
|
|
13
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-3YHYWAHK.mjs";
|
|
14
23
|
import {
|
|
15
24
|
runAgent,
|
|
16
25
|
startAgent,
|
|
17
26
|
stopAgent,
|
|
18
27
|
useCoAgent
|
|
19
|
-
} from "../chunk-
|
|
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";
|
|
28
|
+
} from "../chunk-RYREGU4E.mjs";
|
|
29
29
|
import {
|
|
30
30
|
useCopilotChat
|
|
31
|
-
} from "../chunk-
|
|
32
|
-
import
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import "../chunk-
|
|
36
|
-
import "../chunk-QQZLIEXK.mjs";
|
|
37
|
-
import "../chunk-NNSXCFQO.mjs";
|
|
38
|
-
import "../chunk-5FHSUKQL.mjs";
|
|
31
|
+
} from "../chunk-7BYXCFPB.mjs";
|
|
32
|
+
import "../chunk-YPSGKPDA.mjs";
|
|
33
|
+
import "../chunk-BEDNUHSA.mjs";
|
|
34
|
+
import "../chunk-SJJNFYGQ.mjs";
|
|
35
|
+
import "../chunk-JDEWNLNP.mjs";
|
|
39
36
|
import "../chunk-RKTVJRK7.mjs";
|
|
40
37
|
import "../chunk-PMAFHQ7P.mjs";
|
|
41
|
-
import "../chunk-
|
|
42
|
-
import "../chunk-YPSGKPDA.mjs";
|
|
38
|
+
import "../chunk-5FHSUKQL.mjs";
|
|
43
39
|
import "../chunk-DCTJZ742.mjs";
|
|
44
|
-
import "../chunk-
|
|
40
|
+
import "../chunk-57K2ZJ5F.mjs";
|
|
41
|
+
import "../chunk-AFDL5JI3.mjs";
|
|
45
42
|
import "../chunk-4CEQJ2X6.mjs";
|
|
46
|
-
import "../chunk-CCESTGAM.mjs";
|
|
47
|
-
import "../chunk-O7ARI5CV.mjs";
|
|
48
43
|
import {
|
|
49
44
|
useCopilotRuntimeClient
|
|
50
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-55QZ2SVJ.mjs";
|
|
51
46
|
import "../chunk-GFJW4RIM.mjs";
|
|
52
|
-
import
|
|
53
|
-
|
|
47
|
+
import {
|
|
48
|
+
useCopilotAction
|
|
49
|
+
} from "../chunk-NQVCZQ5T.mjs";
|
|
50
|
+
import "../chunk-3OQM3NEK.mjs";
|
|
51
|
+
import "../chunk-O7ARI5CV.mjs";
|
|
52
|
+
import "../chunk-YAF2LATQ.mjs";
|
|
53
|
+
import "../chunk-XFOTNHYA.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-3da805ab.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
|
@@ -139,8 +139,35 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
139
139
|
// src/hooks/use-copilot-runtime-client.ts
|
|
140
140
|
var useCopilotRuntimeClient = (options) => {
|
|
141
141
|
const { setBannerError } = useToast();
|
|
142
|
-
const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
|
|
142
|
+
const _a = options, { showDevConsole, onTrace } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onTrace"]);
|
|
143
143
|
const lastStructuredErrorRef = (0, import_react2.useRef)(null);
|
|
144
|
+
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
145
|
+
if (!onTrace || !runtimeOptions.publicApiKey)
|
|
146
|
+
return;
|
|
147
|
+
try {
|
|
148
|
+
const traceEvent = {
|
|
149
|
+
type: "error",
|
|
150
|
+
timestamp: Date.now(),
|
|
151
|
+
context: {
|
|
152
|
+
source: "ui",
|
|
153
|
+
request: {
|
|
154
|
+
operation: "runtimeClient",
|
|
155
|
+
url: runtimeOptions.url,
|
|
156
|
+
startTime: Date.now()
|
|
157
|
+
},
|
|
158
|
+
technical: {
|
|
159
|
+
environment: "browser",
|
|
160
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
161
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
error
|
|
165
|
+
};
|
|
166
|
+
yield onTrace(traceEvent);
|
|
167
|
+
} catch (traceError) {
|
|
168
|
+
console.error("Error in onTrace handler:", traceError);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
144
171
|
const runtimeClient = (0, import_react2.useMemo)(() => {
|
|
145
172
|
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
146
173
|
handleGQLErrors: (error) => {
|
|
@@ -168,12 +195,14 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
168
195
|
const ckError = createStructuredError(gqlError);
|
|
169
196
|
if (ckError) {
|
|
170
197
|
setBannerError(ckError);
|
|
198
|
+
traceUIError(ckError, gqlError);
|
|
171
199
|
} else {
|
|
172
200
|
const fallbackError = new import_shared3.CopilotKitError({
|
|
173
201
|
message: gqlError.message,
|
|
174
202
|
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
175
203
|
});
|
|
176
204
|
setBannerError(fallbackError);
|
|
205
|
+
traceUIError(fallbackError, gqlError);
|
|
177
206
|
}
|
|
178
207
|
};
|
|
179
208
|
graphQLErrors.forEach(routeError);
|
|
@@ -187,6 +216,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
187
216
|
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
188
217
|
});
|
|
189
218
|
setBannerError(fallbackError);
|
|
219
|
+
traceUIError(fallbackError, error);
|
|
190
220
|
}
|
|
191
221
|
}
|
|
192
222
|
},
|
|
@@ -199,7 +229,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
199
229
|
setBannerError(warningError);
|
|
200
230
|
}
|
|
201
231
|
}));
|
|
202
|
-
}, [runtimeOptions, setBannerError, showDevConsole]);
|
|
232
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
|
|
203
233
|
return runtimeClient;
|
|
204
234
|
};
|
|
205
235
|
function createStructuredError(gqlError) {
|
|
@@ -299,7 +329,8 @@ var emptyCopilotContext = {
|
|
|
299
329
|
},
|
|
300
330
|
langGraphInterruptAction: null,
|
|
301
331
|
setLangGraphInterruptAction: () => null,
|
|
302
|
-
removeLangGraphInterruptAction: () => null
|
|
332
|
+
removeLangGraphInterruptAction: () => null,
|
|
333
|
+
onTrace: void 0
|
|
303
334
|
};
|
|
304
335
|
var CopilotContext = import_react3.default.createContext(emptyCopilotContext);
|
|
305
336
|
function useCopilotContext() {
|
|
@@ -458,6 +489,35 @@ function useChat(options) {
|
|
|
458
489
|
} = options;
|
|
459
490
|
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
460
491
|
const addErrorToast = useErrorToast();
|
|
492
|
+
const { setBannerError } = useToast();
|
|
493
|
+
const { onTrace } = useCopilotContext();
|
|
494
|
+
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
495
|
+
if (!onTrace || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
496
|
+
return;
|
|
497
|
+
try {
|
|
498
|
+
const traceEvent = {
|
|
499
|
+
type: "error",
|
|
500
|
+
timestamp: Date.now(),
|
|
501
|
+
context: {
|
|
502
|
+
source: "ui",
|
|
503
|
+
request: {
|
|
504
|
+
operation: "useChatCompletion",
|
|
505
|
+
url: copilotConfig.chatApiEndpoint,
|
|
506
|
+
startTime: Date.now()
|
|
507
|
+
},
|
|
508
|
+
technical: {
|
|
509
|
+
environment: "browser",
|
|
510
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
511
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
error
|
|
515
|
+
};
|
|
516
|
+
yield onTrace(traceEvent);
|
|
517
|
+
} catch (traceError) {
|
|
518
|
+
console.error("Error in use-chat onTrace handler:", traceError);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
461
521
|
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
462
522
|
agentSessionRef.current = agentSession;
|
|
463
523
|
const runIdRef = (0, import_react5.useRef)(runId);
|
|
@@ -477,7 +537,7 @@ function useChat(options) {
|
|
|
477
537
|
const pendingAppendsRef = (0, import_react5.useRef)([]);
|
|
478
538
|
const runChatCompletion = useAsyncCallback(
|
|
479
539
|
(previousMessages) => __async(this, null, function* () {
|
|
480
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
540
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
481
541
|
setIsLoading(true);
|
|
482
542
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
483
543
|
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
@@ -609,20 +669,53 @@ function useChat(options) {
|
|
|
609
669
|
messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
610
670
|
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
611
671
|
);
|
|
612
|
-
if (messages2.length === 0) {
|
|
613
|
-
continue;
|
|
614
|
-
}
|
|
615
672
|
newMessages = [];
|
|
616
673
|
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
674
|
+
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
617
675
|
newMessages = [
|
|
618
676
|
new import_runtime_client_gql3.TextMessage({
|
|
619
677
|
role: import_runtime_client_gql3.MessageRole.Assistant,
|
|
620
|
-
content:
|
|
678
|
+
content: guardrailsReason
|
|
621
679
|
})
|
|
622
680
|
];
|
|
681
|
+
const guardrailsError = new import_shared4.CopilotKitError({
|
|
682
|
+
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
683
|
+
code: import_shared4.CopilotKitErrorCode.MISUSE
|
|
684
|
+
});
|
|
685
|
+
yield traceUIError(guardrailsError, {
|
|
686
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
687
|
+
statusDetails: value.generateCopilotResponse.status.details
|
|
688
|
+
});
|
|
623
689
|
setMessages([...previousMessages, ...newMessages]);
|
|
624
690
|
break;
|
|
625
|
-
}
|
|
691
|
+
}
|
|
692
|
+
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
693
|
+
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
694
|
+
const statusDetails = value.generateCopilotResponse.status.details;
|
|
695
|
+
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
696
|
+
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
697
|
+
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
698
|
+
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
699
|
+
let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
|
|
700
|
+
if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
|
|
701
|
+
errorCode = originalCode;
|
|
702
|
+
}
|
|
703
|
+
const structuredError = new import_shared4.CopilotKitError({
|
|
704
|
+
message: errorMessage,
|
|
705
|
+
code: errorCode,
|
|
706
|
+
severity: originalSeverity,
|
|
707
|
+
visibility: originalVisibility
|
|
708
|
+
});
|
|
709
|
+
setBannerError(structuredError);
|
|
710
|
+
yield traceUIError(structuredError, {
|
|
711
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
712
|
+
statusDetails: value.generateCopilotResponse.status.details,
|
|
713
|
+
originalErrorCode: originalCode,
|
|
714
|
+
preservedStructure: !!originalCode
|
|
715
|
+
});
|
|
716
|
+
setIsLoading(false);
|
|
717
|
+
break;
|
|
718
|
+
} else if (messages2.length > 0) {
|
|
626
719
|
newMessages = [...messages2];
|
|
627
720
|
for (const message of messages2) {
|
|
628
721
|
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
@@ -753,11 +846,11 @@ function useChat(options) {
|
|
|
753
846
|
followUp !== false && // and we executed an action
|
|
754
847
|
(didExecuteAction || // the last message is a server side result
|
|
755
848
|
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
756
|
-
!((
|
|
849
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
|
|
757
850
|
) {
|
|
758
851
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
759
852
|
return yield runChatCompletionRef.current(finalMessages);
|
|
760
|
-
} else if ((
|
|
853
|
+
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
761
854
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
762
855
|
if (message.isActionExecutionMessage()) {
|
|
763
856
|
return finalMessages.find(
|
|
@@ -768,7 +861,7 @@ function useChat(options) {
|
|
|
768
861
|
});
|
|
769
862
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
770
863
|
setMessages(repairedMessages);
|
|
771
|
-
if ((
|
|
864
|
+
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
772
865
|
setAgentSession({
|
|
773
866
|
threadId: agentSessionRef.current.threadId,
|
|
774
867
|
agentName: agentSessionRef.current.agentName,
|