@copilotkit/react-core 1.10.5 → 1.10.6-next.1

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/chunk-33OKWHPL.mjs +25 -0
  3. package/dist/chunk-33OKWHPL.mjs.map +1 -0
  4. package/dist/{chunk-J4GESU5K.mjs → chunk-774NTLIU.mjs} +2 -2
  5. package/dist/chunk-774NTLIU.mjs.map +1 -0
  6. package/dist/{chunk-QS7M5VZM.mjs → chunk-CQGHSMOM.mjs} +2 -2
  7. package/dist/chunk-CV2PDTC7.mjs +22 -0
  8. package/dist/chunk-CV2PDTC7.mjs.map +1 -0
  9. package/dist/{chunk-RLGKX6OP.mjs → chunk-CXXRFRCY.mjs} +2 -2
  10. package/dist/chunk-DZTU6PGS.mjs +1 -0
  11. package/dist/{chunk-QQUV6DDO.mjs → chunk-JMALWN4Z.mjs} +2 -2
  12. package/dist/{chunk-3A2AZCAV.mjs → chunk-KPCLYTU3.mjs} +7 -7
  13. package/dist/chunk-MQYWH4E6.mjs +17 -0
  14. package/dist/chunk-MQYWH4E6.mjs.map +1 -0
  15. package/dist/{chunk-H4VS6T4E.mjs → chunk-N3Q6EUTG.mjs} +2 -2
  16. package/dist/chunk-YH6JKJML.mjs +13 -0
  17. package/dist/chunk-YH6JKJML.mjs.map +1 -0
  18. package/dist/{chunk-7H4ANZIC.mjs → chunk-Z6SYWW3S.mjs} +2 -2
  19. package/dist/components/copilot-provider/copilotkit.mjs +4 -4
  20. package/dist/components/copilot-provider/index.mjs +4 -4
  21. package/dist/components/index.mjs +4 -4
  22. package/dist/hooks/index.d.ts +4 -0
  23. package/dist/hooks/index.js +42 -2
  24. package/dist/hooks/index.js.map +1 -1
  25. package/dist/hooks/index.mjs +30 -14
  26. package/dist/hooks/use-coagent.js.map +1 -1
  27. package/dist/hooks/use-coagent.mjs +6 -6
  28. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  29. package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -6
  30. package/dist/hooks/use-copilot-chat.js.map +1 -1
  31. package/dist/hooks/use-copilot-chat.mjs +6 -6
  32. package/dist/hooks/use-copilot-chat_internal.d.ts +1 -1
  33. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  34. package/dist/hooks/use-copilot-chat_internal.mjs +5 -5
  35. package/dist/hooks/use-default-tool.d.ts +8 -0
  36. package/dist/hooks/use-default-tool.js +435 -0
  37. package/dist/hooks/use-default-tool.js.map +1 -0
  38. package/dist/hooks/use-default-tool.mjs +13 -0
  39. package/dist/hooks/use-default-tool.mjs.map +1 -0
  40. package/dist/hooks/use-frontend-tool.d.ts +8 -0
  41. package/dist/hooks/use-frontend-tool.js +432 -0
  42. package/dist/hooks/use-frontend-tool.js.map +1 -0
  43. package/dist/hooks/use-frontend-tool.mjs +13 -0
  44. package/dist/hooks/use-frontend-tool.mjs.map +1 -0
  45. package/dist/hooks/use-human-in-the-loop.d.ts +10 -0
  46. package/dist/hooks/use-human-in-the-loop.js +454 -0
  47. package/dist/hooks/use-human-in-the-loop.js.map +1 -0
  48. package/dist/hooks/use-human-in-the-loop.mjs +13 -0
  49. package/dist/hooks/use-human-in-the-loop.mjs.map +1 -0
  50. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  51. package/dist/hooks/use-langgraph-interrupt.mjs +6 -6
  52. package/dist/hooks/use-render-tool-call.d.ts +8 -0
  53. package/dist/hooks/use-render-tool-call.js +440 -0
  54. package/dist/hooks/use-render-tool-call.js.map +1 -0
  55. package/dist/hooks/use-render-tool-call.mjs +13 -0
  56. package/dist/hooks/use-render-tool-call.mjs.map +1 -0
  57. package/dist/index.d.ts +4 -0
  58. package/dist/index.js +42 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/index.mjs +34 -18
  61. package/dist/lib/copilot-task.mjs +5 -5
  62. package/dist/lib/index.mjs +5 -5
  63. package/dist/utils/extract.mjs +4 -4
  64. package/dist/utils/index.mjs +6 -6
  65. package/dist/utils/suggestions.mjs +4 -4
  66. package/package.json +5 -5
  67. package/src/hooks/index.ts +4 -0
  68. package/src/hooks/use-copilot-chat_internal.ts +1 -1
  69. package/src/hooks/use-default-tool.ts +7 -0
  70. package/src/hooks/use-frontend-tool.ts +14 -0
  71. package/src/hooks/use-human-in-the-loop.ts +21 -0
  72. package/src/hooks/use-render-tool-call.ts +16 -0
  73. package/dist/chunk-J4GESU5K.mjs.map +0 -1
  74. package/dist/chunk-KDAZGZ24.mjs +0 -1
  75. /package/dist/{chunk-QS7M5VZM.mjs.map → chunk-CQGHSMOM.mjs.map} +0 -0
  76. /package/dist/{chunk-RLGKX6OP.mjs.map → chunk-CXXRFRCY.mjs.map} +0 -0
  77. /package/dist/{chunk-KDAZGZ24.mjs.map → chunk-DZTU6PGS.mjs.map} +0 -0
  78. /package/dist/{chunk-QQUV6DDO.mjs.map → chunk-JMALWN4Z.mjs.map} +0 -0
  79. /package/dist/{chunk-3A2AZCAV.mjs.map → chunk-KPCLYTU3.mjs.map} +0 -0
  80. /package/dist/{chunk-H4VS6T4E.mjs.map → chunk-N3Q6EUTG.mjs.map} +0 -0
  81. /package/dist/{chunk-7H4ANZIC.mjs.map → chunk-Z6SYWW3S.mjs.map} +0 -0
@@ -0,0 +1,432 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
+ var __async = (__this, __arguments, generator) => {
44
+ return new Promise((resolve, reject) => {
45
+ var fulfilled = (value) => {
46
+ try {
47
+ step(generator.next(value));
48
+ } catch (e) {
49
+ reject(e);
50
+ }
51
+ };
52
+ var rejected = (value) => {
53
+ try {
54
+ step(generator.throw(value));
55
+ } catch (e) {
56
+ reject(e);
57
+ }
58
+ };
59
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
60
+ step((generator = generator.apply(__this, __arguments)).next());
61
+ });
62
+ };
63
+
64
+ // src/hooks/use-frontend-tool.ts
65
+ var use_frontend_tool_exports = {};
66
+ __export(use_frontend_tool_exports, {
67
+ useFrontendTool: () => useFrontendTool
68
+ });
69
+ module.exports = __toCommonJS(use_frontend_tool_exports);
70
+
71
+ // src/hooks/use-copilot-action.ts
72
+ var import_shared2 = require("@copilotkit/shared");
73
+ var import_react4 = require("react");
74
+
75
+ // src/context/copilot-context.tsx
76
+ var import_react = __toESM(require("react"));
77
+ var emptyCopilotContext = {
78
+ actions: {},
79
+ setAction: () => {
80
+ },
81
+ removeAction: () => {
82
+ },
83
+ coAgentStateRenders: {},
84
+ setCoAgentStateRender: () => {
85
+ },
86
+ removeCoAgentStateRender: () => {
87
+ },
88
+ chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
89
+ getContextString: (documents, categories) => returnAndThrowInDebug(""),
90
+ addContext: () => "",
91
+ removeContext: () => {
92
+ },
93
+ getAllContext: () => [],
94
+ getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
95
+ })),
96
+ isLoading: false,
97
+ setIsLoading: () => returnAndThrowInDebug(false),
98
+ chatInstructions: "",
99
+ setChatInstructions: () => returnAndThrowInDebug(""),
100
+ additionalInstructions: [],
101
+ setAdditionalInstructions: () => returnAndThrowInDebug([]),
102
+ getDocumentsContext: (categories) => returnAndThrowInDebug([]),
103
+ addDocumentContext: () => returnAndThrowInDebug(""),
104
+ removeDocumentContext: () => {
105
+ },
106
+ runtimeClient: {},
107
+ copilotApiConfig: new class {
108
+ get chatApiEndpoint() {
109
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
110
+ }
111
+ get headers() {
112
+ return {};
113
+ }
114
+ get body() {
115
+ return {};
116
+ }
117
+ }(),
118
+ chatSuggestionConfiguration: {},
119
+ addChatSuggestionConfiguration: () => {
120
+ },
121
+ removeChatSuggestionConfiguration: () => {
122
+ },
123
+ showDevConsole: false,
124
+ coagentStates: {},
125
+ setCoagentStates: () => {
126
+ },
127
+ coagentStatesRef: { current: {} },
128
+ setCoagentStatesWithRef: () => {
129
+ },
130
+ agentSession: null,
131
+ setAgentSession: () => {
132
+ },
133
+ forwardedParameters: {},
134
+ agentLock: null,
135
+ threadId: "",
136
+ setThreadId: () => {
137
+ },
138
+ runId: null,
139
+ setRunId: () => {
140
+ },
141
+ chatAbortControllerRef: { current: null },
142
+ availableAgents: [],
143
+ extensions: {},
144
+ setExtensions: () => {
145
+ },
146
+ langGraphInterruptAction: null,
147
+ setLangGraphInterruptAction: () => {
148
+ },
149
+ removeLangGraphInterruptAction: () => {
150
+ },
151
+ onError: () => {
152
+ },
153
+ bannerError: null,
154
+ setBannerError: () => {
155
+ },
156
+ internalErrorHandlers: {},
157
+ setInternalErrorHandler: () => {
158
+ },
159
+ removeInternalErrorHandler: () => {
160
+ }
161
+ };
162
+ var CopilotContext = import_react.default.createContext(emptyCopilotContext);
163
+ function useCopilotContext() {
164
+ const context = import_react.default.useContext(CopilotContext);
165
+ if (context === emptyCopilotContext) {
166
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
167
+ }
168
+ return context;
169
+ }
170
+ function returnAndThrowInDebug(_value) {
171
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
172
+ }
173
+
174
+ // src/components/error-boundary/error-utils.tsx
175
+ var import_react3 = require("react");
176
+
177
+ // src/components/toast/toast-provider.tsx
178
+ var import_react2 = require("react");
179
+ var import_shared = require("@copilotkit/shared");
180
+ var import_jsx_runtime = require("react/jsx-runtime");
181
+ var ToastContext = (0, import_react2.createContext)(void 0);
182
+ function useToast() {
183
+ const context = (0, import_react2.useContext)(ToastContext);
184
+ if (!context) {
185
+ throw new Error("useToast must be used within a ToastProvider");
186
+ }
187
+ return context;
188
+ }
189
+
190
+ // src/components/toast/exclamation-mark-icon.tsx
191
+ var import_jsx_runtime2 = require("react/jsx-runtime");
192
+ var ExclamationMarkIcon = ({
193
+ className,
194
+ style
195
+ }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
196
+ "svg",
197
+ {
198
+ xmlns: "http://www.w3.org/2000/svg",
199
+ width: "24",
200
+ height: "24",
201
+ viewBox: "0 0 24 24",
202
+ fill: "none",
203
+ stroke: "currentColor",
204
+ strokeWidth: "2",
205
+ strokeLinecap: "round",
206
+ strokeLinejoin: "round",
207
+ className: `lucide lucide-circle-alert ${className ? className : ""}`,
208
+ style,
209
+ children: [
210
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
211
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
212
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
213
+ ]
214
+ }
215
+ );
216
+
217
+ // src/components/error-boundary/error-utils.tsx
218
+ var import_react_markdown = __toESM(require("react-markdown"));
219
+ var import_jsx_runtime3 = require("react/jsx-runtime");
220
+ function ErrorToast({ errors }) {
221
+ const errorsToRender = errors.map((error, idx) => {
222
+ var _a, _b, _c;
223
+ const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
224
+ const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
225
+ const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
226
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
227
+ "div",
228
+ {
229
+ style: {
230
+ marginTop: idx === 0 ? 0 : 10,
231
+ marginBottom: 14
232
+ },
233
+ children: [
234
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
235
+ code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
236
+ "div",
237
+ {
238
+ style: {
239
+ fontWeight: "600",
240
+ marginBottom: 4
241
+ },
242
+ children: [
243
+ "Copilot Runtime Error:",
244
+ " ",
245
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
246
+ ]
247
+ }
248
+ ),
249
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
250
+ ]
251
+ },
252
+ idx
253
+ );
254
+ });
255
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
256
+ "div",
257
+ {
258
+ style: {
259
+ fontSize: "13px",
260
+ maxWidth: "600px"
261
+ },
262
+ children: [
263
+ errorsToRender,
264
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
265
+ ]
266
+ }
267
+ );
268
+ }
269
+ function useErrorToast() {
270
+ const { addToast } = useToast();
271
+ return (0, import_react3.useCallback)(
272
+ (error) => {
273
+ const errorId = error.map((err) => {
274
+ var _a, _b;
275
+ const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
276
+ const stack = err.stack || "";
277
+ return btoa(message + stack).slice(0, 32);
278
+ }).join("|");
279
+ addToast({
280
+ type: "error",
281
+ id: errorId,
282
+ // Toast libraries typically dedupe by id
283
+ message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
284
+ });
285
+ },
286
+ [addToast]
287
+ );
288
+ }
289
+ function useAsyncCallback(callback, deps) {
290
+ const addErrorToast = useErrorToast();
291
+ return (0, import_react3.useCallback)((...args) => __async(this, null, function* () {
292
+ try {
293
+ return yield callback(...args);
294
+ } catch (error) {
295
+ console.error("Error in async callback:", error);
296
+ addErrorToast([error]);
297
+ throw error;
298
+ }
299
+ }), deps);
300
+ }
301
+
302
+ // src/hooks/use-copilot-action.ts
303
+ function useCopilotAction(action, dependencies) {
304
+ const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
305
+ const idRef = (0, import_react4.useRef)((0, import_shared2.randomId)());
306
+ const renderAndWaitRef = (0, import_react4.useRef)(null);
307
+ const activatingMessageIdRef = (0, import_react4.useRef)(null);
308
+ const { addToast } = useToast();
309
+ action = __spreadValues({}, action);
310
+ if (
311
+ // renderAndWaitForResponse is not available for catch all actions
312
+ isFrontendAction(action) && // check if renderAndWaitForResponse is set
313
+ (action.renderAndWait || action.renderAndWaitForResponse)
314
+ ) {
315
+ action._isRenderAndWait = true;
316
+ const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
317
+ action.renderAndWait = void 0;
318
+ action.renderAndWaitForResponse = void 0;
319
+ action._setActivatingMessageId = (id) => {
320
+ activatingMessageIdRef.current = id;
321
+ };
322
+ action.handler = useAsyncCallback(() => __async(this, null, function* () {
323
+ const currentActivatingId = activatingMessageIdRef.current;
324
+ let resolve;
325
+ let reject;
326
+ const promise = new Promise((resolvePromise, rejectPromise) => {
327
+ resolve = resolvePromise;
328
+ reject = rejectPromise;
329
+ });
330
+ renderAndWaitRef.current = {
331
+ promise,
332
+ resolve,
333
+ reject,
334
+ messageId: currentActivatingId
335
+ };
336
+ const result = yield promise;
337
+ return result;
338
+ }), []);
339
+ action.render = (props) => {
340
+ const currentRenderMessageId = props.messageId;
341
+ let status = props.status;
342
+ if (props.status === "executing") {
343
+ if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
344
+ status = "inProgress";
345
+ } else if (renderAndWaitRef.current.messageId !== currentRenderMessageId && activatingMessageIdRef.current !== currentRenderMessageId) {
346
+ status = "inProgress";
347
+ }
348
+ }
349
+ const waitProps = {
350
+ status,
351
+ args: props.args,
352
+ result: props.result,
353
+ // handler and respond should only be provided if this is the truly active instance
354
+ // and its promise infrastructure is ready.
355
+ handler: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0,
356
+ respond: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0
357
+ };
358
+ const isNoArgsRenderWait = (_fn) => {
359
+ var _a;
360
+ return ((_a = action.parameters) == null ? void 0 : _a.length) === 0;
361
+ };
362
+ if (renderAndWait) {
363
+ if (isNoArgsRenderWait(renderAndWait)) {
364
+ return renderAndWait(waitProps);
365
+ } else {
366
+ return renderAndWait(waitProps);
367
+ }
368
+ }
369
+ return (0, import_react4.createElement)(import_react4.Fragment);
370
+ };
371
+ }
372
+ if (dependencies === void 0) {
373
+ if (actions[idRef.current]) {
374
+ if (isFrontendAction(action)) {
375
+ actions[idRef.current].handler = action.handler;
376
+ }
377
+ if (typeof action.render === "function") {
378
+ if (chatComponentsCache.current !== null) {
379
+ chatComponentsCache.current.actions[action.name] = action.render;
380
+ }
381
+ }
382
+ }
383
+ }
384
+ (0, import_react4.useEffect)(() => {
385
+ const hasDuplicate = Object.values(actions).some(
386
+ (otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current]
387
+ );
388
+ if (hasDuplicate) {
389
+ addToast({
390
+ type: "warning",
391
+ message: `Found an already registered action with name ${action.name}.`,
392
+ id: `dup-action-${action.name}`
393
+ });
394
+ }
395
+ }, [actions]);
396
+ (0, import_react4.useEffect)(() => {
397
+ setAction(idRef.current, action);
398
+ if (chatComponentsCache.current !== null && action.render !== void 0) {
399
+ chatComponentsCache.current.actions[action.name] = action.render;
400
+ }
401
+ return () => {
402
+ removeAction(idRef.current);
403
+ };
404
+ }, [
405
+ setAction,
406
+ removeAction,
407
+ isFrontendAction(action) ? action.description : void 0,
408
+ action.name,
409
+ isFrontendAction(action) ? action.disabled : void 0,
410
+ isFrontendAction(action) ? action.available : void 0,
411
+ // This should be faster than deep equality checking
412
+ // In addition, all major JS engines guarantee the order of object keys
413
+ JSON.stringify(isFrontendAction(action) ? action.parameters : []),
414
+ // include render only if it's a string
415
+ typeof action.render === "string" ? action.render : void 0,
416
+ // dependencies set by the developer
417
+ ...dependencies || []
418
+ ]);
419
+ }
420
+ function isFrontendAction(action) {
421
+ return action.name !== "*";
422
+ }
423
+
424
+ // src/hooks/use-frontend-tool.ts
425
+ function useFrontendTool(tool, dependencies) {
426
+ useCopilotAction(tool, dependencies);
427
+ }
428
+ // Annotate the CommonJS export names for ESM import in node:
429
+ 0 && (module.exports = {
430
+ useFrontendTool
431
+ });
432
+ //# sourceMappingURL=use-frontend-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/use-frontend-tool.ts","../../src/hooks/use-copilot-action.ts","../../src/context/copilot-context.tsx","../../src/components/error-boundary/error-utils.tsx","../../src/components/toast/toast-provider.tsx","../../src/components/toast/exclamation-mark-icon.tsx"],"sourcesContent":["import { useCopilotAction } from \"./use-copilot-action\";\nimport { FrontendAction } from \"../types/frontend-action\";\nimport { Parameter } from \"@copilotkit/shared\";\n\nexport function useFrontendTool<const T extends Parameter[] | [] = []>(\n tool: Pick<\n FrontendAction<T>,\n \"name\" | \"description\" | \"parameters\" | \"handler\" | \"followUp\" | \"render\"\n >,\n dependencies?: any[],\n) {\n // Use the existing useCopilotAction hook\n useCopilotAction<T>(tool, dependencies);\n}\n","/**\n * Example usage of useCopilotAction with complex parameters:\n *\n * @example\n * useCopilotAction({\n * name: \"myAction\",\n * parameters: [\n * { name: \"arg1\", type: \"string\", enum: [\"option1\", \"option2\", \"option3\"], required: false },\n * { name: \"arg2\", type: \"number\" },\n * {\n * name: \"arg3\",\n * type: \"object\",\n * attributes: [\n * { name: \"nestedArg1\", type: \"boolean\" },\n * { name: \"xyz\", required: false },\n * ],\n * },\n * { name: \"arg4\", type: \"number[]\" },\n * ],\n * handler: ({ arg1, arg2, arg3, arg4 }) => {\n * const x = arg3.nestedArg1;\n * const z = arg3.xyz;\n * console.log(arg1, arg2, arg3);\n * },\n * });\n *\n * @example\n * // Simple action without parameters\n * useCopilotAction({\n * name: \"myAction\",\n * handler: () => {\n * console.log(\"No parameters provided.\");\n * },\n * });\n *\n * @example\n * // Interactive action with UI rendering and response handling\n * useCopilotAction({\n * name: \"handleMeeting\",\n * description: \"Handle a meeting by booking or canceling\",\n * parameters: [\n * {\n * name: \"meeting\",\n * type: \"string\",\n * description: \"The meeting to handle\",\n * required: true,\n * },\n * {\n * name: \"date\",\n * type: \"string\",\n * description: \"The date of the meeting\",\n * required: true,\n * },\n * {\n * name: \"title\",\n * type: \"string\",\n * description: \"The title of the meeting\",\n * required: true,\n * },\n * ],\n * renderAndWaitForResponse: ({ args, respond, status }) => {\n * const { meeting, date, title } = args;\n * return (\n * <MeetingConfirmationDialog\n * meeting={meeting}\n * date={date}\n * title={title}\n * onConfirm={() => respond('meeting confirmed')}\n * onCancel={() => respond('meeting canceled')}\n * />\n * );\n * },\n * });\n *\n * @example\n * // Catch all action allows you to render actions that are not defined in the frontend\n * useCopilotAction({\n * name: \"*\",\n * render: ({ name, args, status, result, handler, respond }) => {\n * return <div>Rendering action: {name}</div>;\n * },\n * });\n */\n\n/**\n * <img src=\"https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-action/useCopilotAction.gif\" width=\"500\" />\n * `useCopilotAction` is a React hook that you can use in your application to provide\n * custom actions that can be called by the AI. Essentially, it allows the Copilot to\n * execute these actions contextually during a chat, based on the user's interactions\n * and needs.\n *\n * Here's how it works:\n *\n * Use `useCopilotAction` to set up actions that the Copilot can call. To provide\n * more context to the Copilot, you can provide it with a `description` (for example to explain\n * what the action does, under which conditions it can be called, etc.).\n *\n * Then you define the parameters of the action, which can be simple, e.g. primitives like strings or numbers,\n * or complex, e.g. objects or arrays.\n *\n * Finally, you provide a `handler` function that receives the parameters and returns a result.\n * CopilotKit takes care of automatically inferring the parameter types, so you get type safety\n * and autocompletion for free.\n *\n * To render a custom UI for the action, you can provide a `render()` function. This function\n * lets you render a custom component or return a string to display.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * useCopilotAction({\n * name: \"sayHello\",\n * description: \"Say hello to someone.\",\n * parameters: [\n * {\n * name: \"name\",\n * type: \"string\",\n * description: \"name of the person to say greet\",\n * },\n * ],\n * handler: async ({ name }) => {\n * alert(`Hello, ${name}!`);\n * },\n * });\n * ```\n *\n * ## Generative UI\n *\n * This hooks enables you to dynamically generate UI elements and render them in the copilot chat. For more information, check out the [Generative UI](/guides/generative-ui) page.\n */\nimport { Parameter, randomId } from \"@copilotkit/shared\";\nimport { createElement, Fragment, useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\nimport {\n ActionRenderProps,\n ActionRenderPropsNoArgsWait,\n ActionRenderPropsWait,\n CatchAllFrontendAction,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport { useToast } from \"../components/toast/toast-provider\";\n\n// We implement useCopilotAction dependency handling so that\n// the developer has the option to not provide any dependencies.\n// In this case, we assume they want to update the handler on each rerender.\n// To avoid getting stuck in an infinite loop, we update the handler directly,\n// skipping React state updates.\n// This is ok in this case, because the handler is not part of any UI that\n// needs to be updated.\n// useCallback, useMemo or other memoization techniques are not suitable here,\n// because they will cause a infinite rerender loop.\nexport function useCopilotAction<const T extends Parameter[] | [] = []>(\n action: FrontendAction<T> | CatchAllFrontendAction,\n dependencies?: any[],\n): void {\n const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();\n const idRef = useRef<string>(randomId());\n const renderAndWaitRef = useRef<RenderAndWaitForResponse | null>(null);\n const activatingMessageIdRef = useRef<string | null>(null);\n const { addToast } = useToast();\n\n // clone the action to avoid mutating the original object\n action = { ...action };\n\n // const { currentlyActivatingHitlActionMessageIdRef } = useCopilotContext() as any; // <-- REMOVE THIS FOR NOW\n\n // If the developer provides a renderAndWaitForResponse function, we transform the action\n // to use a promise internally, so that we can treat it like a normal action.\n if (\n // renderAndWaitForResponse is not available for catch all actions\n isFrontendAction(action) &&\n // check if renderAndWaitForResponse is set\n (action.renderAndWait || action.renderAndWaitForResponse)\n ) {\n (action as any)._isRenderAndWait = true; // Internal flag to identify this action type later\n const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;\n // remove the renderAndWait function from the action\n action.renderAndWait = undefined;\n action.renderAndWaitForResponse = undefined;\n\n // Add a method for use-chat.ts to set the activating message ID.\n // This helps correlate the action instance with the message being processed by use-chat.\n (action as any)._setActivatingMessageId = (id: string | null) => {\n activatingMessageIdRef.current = id;\n };\n\n // add a handler that will be called when the action is executed\n action.handler = useAsyncCallback(async () => {\n const currentActivatingId = activatingMessageIdRef.current;\n // we create a new promise when the handler is called\n let resolve: (result: any) => void;\n let reject: (error: any) => void;\n const promise = new Promise<any>((resolvePromise, rejectPromise) => {\n resolve = resolvePromise;\n reject = rejectPromise;\n });\n renderAndWaitRef.current = {\n promise,\n resolve: resolve!,\n reject: reject!,\n messageId: currentActivatingId,\n };\n // then we await the promise (it will be resolved in the original renderAndWait function)\n const result = await promise;\n return result;\n }, []) as any;\n\n // add a render function that will be called when the action is rendered\n action.render = ((props: ActionRenderProps<T> & { messageId?: string }): React.ReactElement => {\n const currentRenderMessageId = props.messageId;\n // For renderAndWaitForResponse, the 'executing' state might be set by use-chat before\n // this specific action instance's handler (and thus its promise) is ready.\n // This logic adjusts the status to 'inProgress' if the current render\n // isn't for the actively processing HITL action, preventing premature interaction.\n let status = props.status;\n if (props.status === \"executing\") {\n if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {\n status = \"inProgress\";\n } else if (\n renderAndWaitRef.current.messageId !== currentRenderMessageId &&\n activatingMessageIdRef.current !== currentRenderMessageId\n ) {\n status = \"inProgress\";\n }\n // If conditions met, status remains 'executing'\n }\n // Create type safe waitProps based on whether T extends empty array or not\n const waitProps = {\n status,\n args: props.args,\n result: props.result,\n // handler and respond should only be provided if this is the truly active instance\n // and its promise infrastructure is ready.\n handler:\n status === \"executing\" &&\n renderAndWaitRef.current &&\n renderAndWaitRef.current.messageId === currentRenderMessageId\n ? renderAndWaitRef.current!.resolve\n : undefined,\n respond:\n status === \"executing\" &&\n renderAndWaitRef.current &&\n renderAndWaitRef.current.messageId === currentRenderMessageId\n ? renderAndWaitRef.current!.resolve\n : undefined,\n } as T extends [] ? ActionRenderPropsNoArgsWait<T> : ActionRenderPropsWait<T>;\n\n // Type guard to check if renderAndWait is for no args case\n const isNoArgsRenderWait = (\n _fn:\n | ((props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement)\n | ((props: ActionRenderPropsWait<T>) => React.ReactElement),\n ): _fn is (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement => {\n return action.parameters?.length === 0;\n };\n\n // Safely call renderAndWait with correct props type\n if (renderAndWait) {\n if (isNoArgsRenderWait(renderAndWait)) {\n return renderAndWait(waitProps as ActionRenderPropsNoArgsWait<T>);\n } else {\n return renderAndWait(waitProps as ActionRenderPropsWait<T>);\n }\n }\n\n // Return empty Fragment instead of null\n return createElement(Fragment);\n }) as any;\n }\n\n // If the developer doesn't provide dependencies, we assume they want to\n // update handler and render function when the action object changes.\n // This ensures that any captured variables in the handler are up to date.\n if (dependencies === undefined) {\n if (actions[idRef.current]) {\n // catch all actions don't have a handler\n if (isFrontendAction(action)) {\n actions[idRef.current].handler = action.handler as any;\n }\n if (typeof action.render === \"function\") {\n if (chatComponentsCache.current !== null) {\n // TODO: using as any here because the type definitions are getting to tricky\n // not wasting time on this now - we know the types are compatible\n chatComponentsCache.current.actions[action.name] = action.render as any;\n }\n }\n }\n }\n\n useEffect(() => {\n const hasDuplicate = Object.values(actions).some(\n (otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current],\n );\n\n if (hasDuplicate) {\n addToast({\n type: \"warning\",\n message: `Found an already registered action with name ${action.name}.`,\n id: `dup-action-${action.name}`,\n });\n }\n }, [actions]);\n\n useEffect(() => {\n setAction(idRef.current, action as any);\n if (chatComponentsCache.current !== null && action.render !== undefined) {\n // see comment about type safety above\n chatComponentsCache.current.actions[action.name] = action.render as any;\n }\n return () => {\n // NOTE: For now, we don't remove the chatComponentsCache entry when the action is removed.\n // This is because we currently don't have access to the messages array in CopilotContext.\n // UPDATE: We now have access, we should remove the entry if not referenced by any message.\n removeAction(idRef.current);\n };\n }, [\n setAction,\n removeAction,\n isFrontendAction(action) ? action.description : undefined,\n action.name,\n isFrontendAction(action) ? action.disabled : undefined,\n isFrontendAction(action) ? action.available : undefined,\n // This should be faster than deep equality checking\n // In addition, all major JS engines guarantee the order of object keys\n JSON.stringify(isFrontendAction(action) ? action.parameters : []),\n // include render only if it's a string\n typeof action.render === \"string\" ? action.render : undefined,\n // dependencies set by the developer\n ...(dependencies || []),\n ]);\n}\n\nfunction isFrontendAction<T extends Parameter[]>(\n action: FrontendAction<T> | CatchAllFrontendAction,\n): action is FrontendAction<T> {\n return action.name !== \"*\";\n}\n\ninterface RenderAndWaitForResponse {\n promise: Promise<any>;\n resolve: (result: any) => void;\n reject: (error: any) => void;\n messageId: string | null;\n}\n","import {\n CopilotCloudConfig,\n FunctionCallHandler,\n CopilotErrorHandler,\n CopilotKitError,\n} from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\n} from \"../types/interrupt-action\";\nimport { SuggestionItem } from \"../utils/suggestions\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n\n /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getAllContext: () => Tree;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Partial<Pick<ForwardedParametersInput, \"temperature\">>;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: (threadId: string) => void;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError: CopilotErrorHandler;\n\n // banner error state\n bannerError: CopilotKitError | null;\n setBannerError: React.Dispatch<React.SetStateAction<CopilotKitError | null>>;\n // Internal error handlers\n // These are used to handle errors that occur during the execution of the chat.\n // They are not intended for use by the developer. A component can register itself an error listener to be activated somewhere else as needed\n internalErrorHandlers: Record<string, CopilotErrorHandler>;\n setInternalErrorHandler: (handler: Record<string, CopilotErrorHandler>) => void;\n removeInternalErrorHandler: (id: string) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => {},\n removeLangGraphInterruptAction: () => {},\n onError: () => {},\n bannerError: null,\n setBannerError: () => {},\n internalErrorHandlers: {},\n setInternalErrorHandler: () => {},\n removeInternalErrorHandler: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(_value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n}\n","import React, { useCallback } from \"react\";\nimport { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport { useToast } from \"../toast/toast-provider\";\nimport { ExclamationMarkIcon } from \"../toast/exclamation-mark-icon\";\nimport ReactMarkdown from \"react-markdown\";\n\ninterface OriginalError {\n message?: string;\n stack?: string;\n}\n\nexport function ErrorToast({ errors }: { errors: (Error | GraphQLError)[] }) {\n const errorsToRender = errors.map((error, idx) => {\n const originalError =\n \"extensions\" in error ? (error.extensions?.originalError as undefined | OriginalError) : {};\n const message = originalError?.message ?? error.message;\n const code = \"extensions\" in error ? (error.extensions?.code as string) : null;\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 Runtime Error:{\" \"}\n <span style={{ fontFamily: \"monospace\", fontWeight: \"normal\" }}>{code}</span>\n </div>\n )}\n <ReactMarkdown>{message}</ReactMarkdown>\n </div>\n );\n });\n return (\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 error only displays during local development.\n </div>\n </div>\n );\n}\n\nexport function useErrorToast() {\n const { addToast } = useToast();\n\n return useCallback(\n (error: (Error | GraphQLError)[]) => {\n const errorId = error\n .map((err) => {\n const message =\n \"extensions\" in err\n ? (err.extensions?.originalError as any)?.message || err.message\n : err.message;\n const stack = err.stack || \"\";\n return btoa(message + stack).slice(0, 32); // Create hash from message + stack\n })\n .join(\"|\");\n\n addToast({\n type: \"error\",\n id: errorId, // Toast libraries typically dedupe by id\n message: <ErrorToast errors={error} />,\n });\n },\n [addToast],\n );\n}\n\nexport function useAsyncCallback<T extends (...args: any[]) => Promise<any>>(\n callback: T,\n deps: Parameters<typeof useCallback>[1],\n) {\n const addErrorToast = useErrorToast();\n return useCallback(async (...args: Parameters<T>) => {\n try {\n return await callback(...args);\n } catch (error) {\n console.error(\"Error in async callback:\", error);\n // @ts-ignore\n addErrorToast([error]);\n throw error;\n }\n }, deps);\n}\n","import { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport React, { createContext, useContext, useState, useCallback } from \"react\";\nimport { PartialBy, CopilotKitError, Severity } from \"@copilotkit/shared\";\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: PartialBy<Toast, \"id\">) => void;\n addGraphQLErrorsToast: (errors: GraphQLError[]) => void;\n removeToast: (id: string) => void;\n enabled: boolean;\n // Banner management\n bannerError: CopilotKitError | null;\n setBannerError: (error: CopilotKitError | null) => void;\n}\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\n// Helper functions for error banner styling\ntype ErrorSeverity = \"critical\" | \"warning\" | \"info\";\n\ninterface ErrorColors {\n background: string;\n border: string;\n text: string;\n icon: string;\n}\n\nfunction getErrorSeverity(error: CopilotKitError): ErrorSeverity {\n // Use structured error severity if available\n if (error.severity) {\n switch (error.severity) {\n case Severity.CRITICAL:\n return \"critical\";\n case Severity.WARNING:\n return \"warning\";\n case Severity.INFO:\n return \"info\";\n default:\n return \"info\";\n }\n }\n\n // Fallback: Check for API key errors which should always be critical\n const message = error.message.toLowerCase();\n if (\n message.includes(\"api key\") ||\n message.includes(\"401\") ||\n message.includes(\"unauthorized\") ||\n message.includes(\"authentication\") ||\n message.includes(\"incorrect api key\")\n ) {\n return \"critical\";\n }\n\n // Default to info level\n return \"info\";\n}\n\nfunction getErrorColors(severity: ErrorSeverity): ErrorColors {\n switch (severity) {\n case \"critical\":\n return {\n background: \"#fee2e2\",\n border: \"#dc2626\",\n text: \"#7f1d1d\",\n icon: \"#dc2626\",\n };\n case \"warning\":\n return {\n background: \"#fef3c7\",\n border: \"#d97706\",\n text: \"#78350f\",\n icon: \"#d97706\",\n };\n case \"info\":\n return {\n background: \"#dbeafe\",\n border: \"#2563eb\",\n text: \"#1e3a8a\",\n icon: \"#2563eb\",\n };\n }\n}\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 [bannerError, setBannerErrorState] = useState<CopilotKitError | null>(null);\n\n const removeToast = useCallback((id: string) => {\n setToasts((prev) => prev.filter((toast) => toast.id !== id));\n }, []);\n\n const addToast = useCallback(\n (toast: PartialBy<Toast, \"id\">) => {\n // Respect the enabled flag for ALL toasts\n if (!enabled) {\n return;\n }\n\n const id = toast.id ?? Math.random().toString(36).substring(2, 9);\n\n setToasts((currentToasts) => {\n if (currentToasts.find((toast) => toast.id === id)) return currentToasts;\n return [...currentToasts, { ...toast, id }];\n });\n\n if (toast.duration) {\n setTimeout(() => {\n removeToast(id);\n }, toast.duration);\n }\n },\n [enabled, removeToast],\n );\n\n const setBannerError = useCallback(\n (error: CopilotKitError | null) => {\n // Respect the enabled flag for ALL errors\n if (!enabled && error !== null) {\n return;\n }\n setBannerErrorState(error);\n },\n [enabled],\n );\n\n const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {\n // DEPRECATED: All errors now route to banners for consistency\n console.warn(\"addGraphQLErrorsToast is deprecated. All errors now show as banners.\");\n // Function kept for backward compatibility - does nothing\n }, []);\n\n const value = {\n toasts,\n addToast,\n addGraphQLErrorsToast,\n removeToast,\n enabled,\n bannerError,\n setBannerError,\n };\n\n return (\n <ToastContext.Provider value={value}>\n {/* Banner Error Display */}\n {bannerError &&\n (() => {\n const severity = getErrorSeverity(bannerError);\n const colors = getErrorColors(severity);\n\n return (\n <div\n style={{\n position: \"fixed\",\n bottom: \"20px\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n zIndex: 9999,\n backgroundColor: colors.background,\n border: `1px solid ${colors.border}`,\n borderLeft: `4px solid ${colors.border}`,\n borderRadius: \"8px\",\n padding: \"12px 16px\",\n fontSize: \"13px\",\n boxShadow: \"0 4px 12px rgba(0, 0, 0, 0.15)\",\n backdropFilter: \"blur(8px)\",\n maxWidth: \"min(90vw, 700px)\",\n width: \"100%\",\n boxSizing: \"border-box\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n gap: \"10px\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: \"8px\",\n flex: 1,\n minWidth: 0,\n }}\n >\n <div\n style={{\n width: \"12px\",\n height: \"12px\",\n borderRadius: \"50%\",\n backgroundColor: colors.border,\n flexShrink: 0,\n }}\n />\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: \"10px\",\n flex: 1,\n minWidth: 0,\n }}\n >\n <div\n style={{\n color: colors.text,\n lineHeight: \"1.4\",\n fontWeight: \"400\",\n fontSize: \"13px\",\n flex: 1,\n wordBreak: \"break-all\",\n overflowWrap: \"break-word\",\n maxWidth: \"550px\",\n overflow: \"hidden\",\n display: \"-webkit-box\",\n WebkitLineClamp: 10,\n WebkitBoxOrient: \"vertical\",\n }}\n >\n {(() => {\n let message = bannerError.message;\n\n // Try to extract the useful message from JSON first\n const jsonMatch = message.match(/'message':\\s*'([^']+)'/);\n if (jsonMatch) {\n return jsonMatch[1]; // Return the actual error message\n }\n\n // Strip technical garbage but keep the meaningful message\n message = message.split(\" - \")[0]; // Remove everything after \" - {\"\n message = message.split(\": Error code\")[0]; // Remove \": Error code: 401\"\n message = message.replace(/:\\s*\\d{3}$/, \"\"); // Remove trailing \": 401\"\n message = message.replace(/See more:.*$/g, \"\"); // Remove \"See more\" links\n message = message.trim();\n\n // If it's still garbage (contains { or '), use fallback\n // if (message.includes(\"{\") || message.includes(\"'\")) {\n // return \"Configuration error.... Please check your setup.\";\n // }\n\n return message || \"Configuration error occurred.\";\n })()}\n </div>\n\n {(() => {\n const message = bannerError.message;\n const markdownLinkRegex = /\\[([^\\]]+)\\]\\(([^)]+)\\)/g;\n const plainUrlRegex = /(https?:\\/\\/[^\\s)]+)/g;\n\n // Extract the first URL found\n let url = null;\n let buttonText = \"See More\";\n\n // Check for markdown links first\n const markdownMatch = markdownLinkRegex.exec(message);\n if (markdownMatch) {\n url = markdownMatch[2];\n buttonText = \"See More\";\n } else {\n // Check for plain URLs\n const urlMatch = plainUrlRegex.exec(message);\n if (urlMatch) {\n url = urlMatch[0].replace(/[.,;:'\"]*$/, \"\"); // Remove trailing punctuation\n buttonText = \"See More\";\n }\n }\n\n if (!url) return null;\n\n return (\n <button\n onClick={() => window.open(url, \"_blank\", \"noopener,noreferrer\")}\n style={{\n background: colors.border,\n color: \"white\",\n border: \"none\",\n borderRadius: \"5px\",\n padding: \"4px 10px\",\n fontSize: \"11px\",\n fontWeight: \"500\",\n cursor: \"pointer\",\n transition: \"all 0.2s ease\",\n flexShrink: 0,\n }}\n onMouseEnter={(e) => {\n e.currentTarget.style.opacity = \"0.9\";\n e.currentTarget.style.transform = \"translateY(-1px)\";\n }}\n onMouseLeave={(e) => {\n e.currentTarget.style.opacity = \"1\";\n e.currentTarget.style.transform = \"translateY(0)\";\n }}\n >\n {buttonText}\n </button>\n );\n })()}\n </div>\n </div>\n <button\n onClick={() => setBannerError(null)}\n style={{\n background: \"transparent\",\n border: \"none\",\n color: colors.text,\n cursor: \"pointer\",\n padding: \"2px\",\n borderRadius: \"3px\",\n fontSize: \"14px\",\n lineHeight: \"1\",\n opacity: 0.6,\n transition: \"all 0.2s ease\",\n flexShrink: 0,\n }}\n title=\"Dismiss\"\n onMouseEnter={(e) => {\n e.currentTarget.style.opacity = \"1\";\n e.currentTarget.style.background = \"rgba(0, 0, 0, 0.05)\";\n }}\n onMouseLeave={(e) => {\n e.currentTarget.style.opacity = \"0.6\";\n e.currentTarget.style.background = \"transparent\";\n }}\n >\n ×\n </button>\n </div>\n </div>\n );\n })()}\n\n {/* Toast Display - Deprecated: All errors now show as banners */}\n {children}\n </ToastContext.Provider>\n );\n}\n\n// Toast component removed - all errors now show as banners for consistency\n","import React from \"react\";\n\nexport const ExclamationMarkIcon = ({\n className,\n style,\n}: {\n className?: string;\n style?: React.CSSProperties;\n}) => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={`lucide lucide-circle-alert ${className ? className : \"\"}`}\n style={style}\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"12\" x2=\"12\" y1=\"8\" y2=\"12\" />\n <line x1=\"12\" x2=\"12.01\" y1=\"16\" y2=\"16\" />\n </svg>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoIA,IAAAA,iBAAoC;AACpC,IAAAC,gBAA2D;;;AC1H3D,mBAAkB;AAwOlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,eAAe,MAAM,CAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,WAAW;AAAA,EACX,cAAc,MAAM,sBAAsB,KAAK;AAAA,EAE/C,kBAAkB;AAAA,EAClB,qBAAqB,MAAM,sBAAsB,EAAE;AAAA,EAEnD,wBAAwB,CAAC;AAAA,EACzB,2BAA2B,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAEzD,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC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AAAA,IACF;AAAA,EACF;AAEA,+BAAU,MAAM;AACd,UAAM,eAAe,OAAO,OAAO,OAAO,EAAE;AAAA,MAC1C,CAAC,gBAAgB,YAAY,SAAS,OAAO,QAAQ,gBAAgB,QAAQ,MAAM,OAAO;AAAA,IAC5F;AAEA,QAAI,cAAc;AAChB,eAAS;AAAA,QACP,MAAM;AAAA,QACN,SAAS,gDAAgD,OAAO;AAAA,QAChE,IAAI,cAAc,OAAO;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,+BAAU,MAAM;AACd,cAAU,MAAM,SAAS,MAAa;AACtC,QAAI,oBAAoB,YAAY,QAAQ,OAAO,WAAW,QAAW;AAEvE,0BAAoB,QAAQ,QAAQ,OAAO,IAAI,IAAI,OAAO;AAAA,IAC5D;AACA,WAAO,MAAM;AAIX,mBAAa,MAAM,OAAO;AAAA,IAC5B;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,iBAAiB,MAAM,IAAI,OAAO,cAAc;AAAA,IAChD,OAAO;AAAA,IACP,iBAAiB,MAAM,IAAI,OAAO,WAAW;AAAA,IAC7C,iBAAiB,MAAM,IAAI,OAAO,YAAY;AAAA;AAAA;AAAA,IAG9C,KAAK,UAAU,iBAAiB,MAAM,IAAI,OAAO,aAAa,CAAC,CAAC;AAAA;AAAA,IAEhE,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;AAEA,SAAS,iBACP,QAC6B;AAC7B,SAAO,OAAO,SAAS;AACzB;;;AD/UO,SAAS,gBACd,MAIA,cACA;AAEA,mBAAoB,MAAM,YAAY;AACxC;","names":["import_shared","import_react","React","import_react","import_react","import_jsx_runtime","import_jsx_runtime","ReactMarkdown"]}
@@ -0,0 +1,13 @@
1
+ import {
2
+ useFrontendTool
3
+ } from "../chunk-YH6JKJML.mjs";
4
+ import "../chunk-T3376SZS.mjs";
5
+ import "../chunk-N4WEHORG.mjs";
6
+ import "../chunk-O7ARI5CV.mjs";
7
+ import "../chunk-EFL5OBKN.mjs";
8
+ import "../chunk-EUX2P2E7.mjs";
9
+ import "../chunk-SKC7AJIV.mjs";
10
+ export {
11
+ useFrontendTool
12
+ };
13
+ //# sourceMappingURL=use-frontend-tool.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,10 @@
1
+ import { FrontendAction } from '../types/frontend-action.js';
2
+ import { Parameter } from '@copilotkit/shared';
3
+ import '@copilotkit/runtime-client-gql';
4
+ import 'react';
5
+
6
+ declare function useHumanInTheLoop<const T extends Parameter[] | [] = []>(tool: Pick<FrontendAction<T>, "name" | "description" | "parameters"> & {
7
+ render: FrontendAction<T>["renderAndWaitForResponse"];
8
+ }, dependencies?: any[]): void;
9
+
10
+ export { useHumanInTheLoop };