@copilotkit/react-core 1.4.5 → 1.4.6

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 (229) hide show
  1. package/CHANGELOG.md +10 -53
  2. package/README.md +0 -2
  3. package/dist/chunk-2KCEHGSI.mjs +192 -0
  4. package/dist/chunk-2KCEHGSI.mjs.map +1 -0
  5. package/dist/chunk-5FHSUKQL.mjs +70 -0
  6. package/dist/chunk-5FHSUKQL.mjs.map +1 -0
  7. package/dist/chunk-6U3UH3KO.mjs +140 -0
  8. package/dist/chunk-6U3UH3KO.mjs.map +1 -0
  9. package/dist/chunk-AG7FH7OD.mjs +28 -0
  10. package/dist/chunk-AG7FH7OD.mjs.map +1 -0
  11. package/dist/chunk-DCTJZ742.mjs +22 -0
  12. package/dist/chunk-DCTJZ742.mjs.map +1 -0
  13. package/dist/chunk-DHGXL5PC.mjs +439 -0
  14. package/dist/chunk-DHGXL5PC.mjs.map +1 -0
  15. package/dist/chunk-EFZPSZWO.mjs +1 -0
  16. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  17. package/dist/chunk-EUIBVFV6.mjs +294 -0
  18. package/dist/chunk-EUIBVFV6.mjs.map +1 -0
  19. package/dist/chunk-JHEAUB3Z.mjs +49 -0
  20. package/dist/chunk-JHEAUB3Z.mjs.map +1 -0
  21. package/dist/chunk-L34MHAXR.mjs +1 -0
  22. package/dist/chunk-L34MHAXR.mjs.map +1 -0
  23. package/dist/chunk-LUGEI4YQ.mjs +1 -0
  24. package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
  25. package/dist/chunk-MLAS4QUR.mjs +18 -0
  26. package/dist/chunk-MLAS4QUR.mjs.map +1 -0
  27. package/dist/chunk-O22KGHOQ.mjs +128 -0
  28. package/dist/chunk-O22KGHOQ.mjs.map +1 -0
  29. package/dist/chunk-O7ARI5CV.mjs +31 -0
  30. package/dist/chunk-O7ARI5CV.mjs.map +1 -0
  31. package/dist/chunk-ODN4H66E.mjs +31 -0
  32. package/dist/chunk-ODN4H66E.mjs.map +1 -0
  33. package/dist/chunk-OT67R4NB.mjs +119 -0
  34. package/dist/chunk-OT67R4NB.mjs.map +1 -0
  35. package/dist/chunk-SKC7AJIV.mjs +61 -0
  36. package/dist/chunk-SKC7AJIV.mjs.map +1 -0
  37. package/dist/chunk-UOVONDR6.mjs +23 -0
  38. package/dist/chunk-UOVONDR6.mjs.map +1 -0
  39. package/dist/chunk-XBVKTDXP.mjs +172 -0
  40. package/dist/chunk-XBVKTDXP.mjs.map +1 -0
  41. package/dist/chunk-XQFVXX6R.mjs +78 -0
  42. package/dist/chunk-XQFVXX6R.mjs.map +1 -0
  43. package/dist/chunk-XXR4QFAQ.mjs +29 -0
  44. package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
  45. package/dist/chunk-Y7MI4PBB.mjs +91 -0
  46. package/dist/chunk-Y7MI4PBB.mjs.map +1 -0
  47. package/dist/chunk-YPSGKPDA.mjs +1 -0
  48. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  49. package/dist/components/copilot-provider/copilot-messages.d.ts +7 -0
  50. package/dist/components/copilot-provider/copilot-messages.js +80 -0
  51. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  52. package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
  53. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  54. package/dist/components/copilot-provider/copilotkit-props.d.ts +72 -0
  55. package/dist/components/copilot-provider/copilotkit-props.js +19 -0
  56. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
  57. package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
  58. package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
  59. package/dist/components/copilot-provider/copilotkit.d.ts +9 -0
  60. package/dist/components/copilot-provider/copilotkit.js +877 -0
  61. package/dist/components/copilot-provider/copilotkit.js.map +1 -0
  62. package/dist/components/copilot-provider/copilotkit.mjs +21 -0
  63. package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
  64. package/dist/components/copilot-provider/index.d.ts +4 -0
  65. package/dist/components/copilot-provider/index.js +877 -0
  66. package/dist/components/copilot-provider/index.js.map +1 -0
  67. package/dist/components/copilot-provider/index.mjs +19 -0
  68. package/dist/components/copilot-provider/index.mjs.map +1 -0
  69. package/dist/components/index.d.ts +4 -0
  70. package/dist/components/index.js +877 -0
  71. package/dist/components/index.js.map +1 -0
  72. package/dist/components/index.mjs +19 -0
  73. package/dist/components/index.mjs.map +1 -0
  74. package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
  75. package/dist/components/toast/exclamation-mark-icon.js +55 -0
  76. package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
  77. package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
  78. package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
  79. package/dist/components/toast/toast-provider.d.ts +29 -0
  80. package/dist/components/toast/toast-provider.js +255 -0
  81. package/dist/components/toast/toast-provider.js.map +1 -0
  82. package/dist/components/toast/toast-provider.mjs +11 -0
  83. package/dist/components/toast/toast-provider.mjs.map +1 -0
  84. package/dist/context/copilot-context.d.ts +111 -0
  85. package/dist/context/copilot-context.js +129 -0
  86. package/dist/context/copilot-context.js.map +1 -0
  87. package/dist/context/copilot-context.mjs +10 -0
  88. package/dist/context/copilot-context.mjs.map +1 -0
  89. package/dist/context/copilot-messages-context.d.ts +15 -0
  90. package/dist/context/copilot-messages-context.js +57 -0
  91. package/dist/context/copilot-messages-context.js.map +1 -0
  92. package/dist/context/copilot-messages-context.mjs +10 -0
  93. package/dist/context/copilot-messages-context.mjs.map +1 -0
  94. package/dist/context/index.d.ts +11 -0
  95. package/dist/context/index.js +152 -0
  96. package/dist/context/index.js.map +1 -0
  97. package/dist/context/index.mjs +17 -0
  98. package/dist/context/index.mjs.map +1 -0
  99. package/dist/hooks/index.d.ts +19 -0
  100. package/dist/hooks/index.js +906 -0
  101. package/dist/hooks/index.js.map +1 -0
  102. package/dist/hooks/index.mjs +44 -0
  103. package/dist/hooks/index.mjs.map +1 -0
  104. package/dist/hooks/use-chat.d.ts +96 -0
  105. package/dist/hooks/use-chat.js +359 -0
  106. package/dist/hooks/use-chat.js.map +1 -0
  107. package/dist/hooks/use-chat.mjs +11 -0
  108. package/dist/hooks/use-chat.mjs.map +1 -0
  109. package/dist/hooks/use-coagent-state-render.d.ts +60 -0
  110. package/dist/hooks/use-coagent-state-render.js +163 -0
  111. package/dist/hooks/use-coagent-state-render.js.map +1 -0
  112. package/dist/hooks/use-coagent-state-render.mjs +9 -0
  113. package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
  114. package/dist/hooks/use-coagent.d.ts +186 -0
  115. package/dist/hooks/use-coagent.js +735 -0
  116. package/dist/hooks/use-coagent.js.map +1 -0
  117. package/dist/hooks/use-coagent.mjs +21 -0
  118. package/dist/hooks/use-coagent.mjs.map +1 -0
  119. package/dist/hooks/use-copilot-action.d.ts +130 -0
  120. package/dist/hooks/use-copilot-action.js +222 -0
  121. package/dist/hooks/use-copilot-action.js.map +1 -0
  122. package/dist/hooks/use-copilot-action.mjs +9 -0
  123. package/dist/hooks/use-copilot-action.mjs.map +1 -0
  124. package/dist/hooks/use-copilot-chat.d.ts +37 -0
  125. package/dist/hooks/use-copilot-chat.js +630 -0
  126. package/dist/hooks/use-copilot-chat.js.map +1 -0
  127. package/dist/hooks/use-copilot-chat.mjs +22 -0
  128. package/dist/hooks/use-copilot-chat.mjs.map +1 -0
  129. package/dist/hooks/use-copilot-readable.d.ts +33 -0
  130. package/dist/hooks/use-copilot-readable.js +149 -0
  131. package/dist/hooks/use-copilot-readable.js.map +1 -0
  132. package/dist/hooks/use-copilot-readable.mjs +9 -0
  133. package/dist/hooks/use-copilot-readable.mjs.map +1 -0
  134. package/dist/hooks/use-copilot-runtime-client.d.ts +5 -0
  135. package/dist/hooks/use-copilot-runtime-client.js +76 -0
  136. package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
  137. package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
  138. package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
  139. package/dist/hooks/use-flat-category-store.d.ts +9 -0
  140. package/dist/hooks/use-flat-category-store.js +90 -0
  141. package/dist/hooks/use-flat-category-store.js.map +1 -0
  142. package/dist/hooks/use-flat-category-store.mjs +8 -0
  143. package/dist/hooks/use-flat-category-store.mjs.map +1 -0
  144. package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
  145. package/dist/hooks/use-make-copilot-document-readable.js +144 -0
  146. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  147. package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
  148. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
  149. package/dist/hooks/use-tree.d.ts +18 -0
  150. package/dist/hooks/use-tree.js +172 -0
  151. package/dist/hooks/use-tree.js.map +1 -0
  152. package/dist/hooks/use-tree.mjs +8 -0
  153. package/dist/hooks/use-tree.mjs.map +1 -0
  154. package/dist/index.d.ts +26 -0
  155. package/dist/index.js +1832 -0
  156. package/dist/index.js.map +1 -0
  157. package/dist/index.mjs +71 -0
  158. package/dist/index.mjs.map +1 -0
  159. package/dist/lib/copilot-task.d.ts +92 -0
  160. package/dist/lib/copilot-task.js +157 -0
  161. package/dist/lib/copilot-task.js.map +1 -0
  162. package/dist/lib/copilot-task.mjs +18 -0
  163. package/dist/lib/copilot-task.mjs.map +1 -0
  164. package/dist/lib/index.d.ts +11 -0
  165. package/dist/lib/index.js +159 -0
  166. package/dist/lib/index.js.map +1 -0
  167. package/dist/lib/index.mjs +19 -0
  168. package/dist/lib/index.mjs.map +1 -0
  169. package/dist/types/chat-suggestion-configuration.d.ts +22 -0
  170. package/dist/types/chat-suggestion-configuration.js +19 -0
  171. package/dist/types/chat-suggestion-configuration.js.map +1 -0
  172. package/dist/types/chat-suggestion-configuration.mjs +1 -0
  173. package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
  174. package/dist/types/coagent-action.d.ts +29 -0
  175. package/dist/types/coagent-action.js +19 -0
  176. package/dist/types/coagent-action.js.map +1 -0
  177. package/dist/types/coagent-action.mjs +1 -0
  178. package/dist/types/coagent-action.mjs.map +1 -0
  179. package/dist/types/coagent-state.d.ts +11 -0
  180. package/dist/types/coagent-state.js +19 -0
  181. package/dist/types/coagent-state.js.map +1 -0
  182. package/dist/types/coagent-state.mjs +1 -0
  183. package/dist/types/coagent-state.mjs.map +1 -0
  184. package/dist/types/document-pointer.d.ts +9 -0
  185. package/dist/types/document-pointer.js +19 -0
  186. package/dist/types/document-pointer.js.map +1 -0
  187. package/dist/types/document-pointer.mjs +1 -0
  188. package/dist/types/document-pointer.mjs.map +1 -0
  189. package/dist/types/frontend-action.d.ts +107 -0
  190. package/dist/types/frontend-action.js +19 -0
  191. package/dist/types/frontend-action.js.map +1 -0
  192. package/dist/types/frontend-action.mjs +1 -0
  193. package/dist/types/frontend-action.mjs.map +1 -0
  194. package/dist/types/index.d.ts +6 -0
  195. package/dist/types/index.js +19 -0
  196. package/dist/types/index.js.map +1 -0
  197. package/dist/types/index.mjs +2 -0
  198. package/dist/types/index.mjs.map +1 -0
  199. package/dist/types/system-message.d.ts +3 -0
  200. package/dist/types/system-message.js +19 -0
  201. package/dist/types/system-message.js.map +1 -0
  202. package/dist/types/system-message.mjs +1 -0
  203. package/dist/types/system-message.mjs.map +1 -0
  204. package/dist/utils/dev-console.d.ts +3 -0
  205. package/dist/utils/dev-console.js +42 -0
  206. package/dist/utils/dev-console.js.map +1 -0
  207. package/dist/utils/dev-console.mjs +8 -0
  208. package/dist/utils/dev-console.mjs.map +1 -0
  209. package/dist/utils/extract.d.ts +42 -0
  210. package/dist/utils/extract.js +190 -0
  211. package/dist/utils/extract.js.map +1 -0
  212. package/dist/utils/extract.mjs +17 -0
  213. package/dist/utils/extract.mjs.map +1 -0
  214. package/dist/utils/index.d.ts +13 -0
  215. package/dist/utils/index.js +208 -0
  216. package/dist/utils/index.js.map +1 -0
  217. package/dist/utils/index.mjs +20 -0
  218. package/dist/utils/index.mjs.map +1 -0
  219. package/dist/utils/utils.d.ts +2 -0
  220. package/dist/utils/utils.js +19 -0
  221. package/dist/utils/utils.js.map +1 -0
  222. package/dist/utils/utils.mjs +1 -0
  223. package/dist/utils/utils.mjs.map +1 -0
  224. package/dist/utils/utils.test.d.ts +2 -0
  225. package/dist/utils/utils.test.js +9 -0
  226. package/dist/utils/utils.test.js.map +1 -0
  227. package/dist/utils/utils.test.mjs +7 -0
  228. package/dist/utils/utils.test.mjs.map +1 -0
  229. package/package.json +5 -5
@@ -0,0 +1,91 @@
1
+ import {
2
+ useCopilotContext
3
+ } from "./chunk-XQFVXX6R.mjs";
4
+ import {
5
+ __async,
6
+ __spreadValues
7
+ } from "./chunk-SKC7AJIV.mjs";
8
+
9
+ // src/hooks/use-copilot-action.ts
10
+ import { randomId } from "@copilotkit/shared";
11
+ import { createElement, Fragment, useEffect, useRef } from "react";
12
+ function useCopilotAction(action, dependencies) {
13
+ const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
14
+ const idRef = useRef(randomId());
15
+ const renderAndWaitRef = useRef(null);
16
+ action = __spreadValues({}, action);
17
+ if (action.renderAndWait || action.renderAndWaitForResponse) {
18
+ const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
19
+ action.renderAndWait = void 0;
20
+ action.renderAndWaitForResponse = void 0;
21
+ action.handler = () => __async(this, null, function* () {
22
+ let resolve;
23
+ let reject;
24
+ const promise = new Promise((resolvePromise, rejectPromise) => {
25
+ resolve = resolvePromise;
26
+ reject = rejectPromise;
27
+ });
28
+ renderAndWaitRef.current = { promise, resolve, reject };
29
+ return yield promise;
30
+ });
31
+ action.render = (props) => {
32
+ const waitProps = {
33
+ status: props.status,
34
+ args: props.args,
35
+ result: props.result,
36
+ handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0,
37
+ respond: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
38
+ };
39
+ const isNoArgsRenderWait = (_fn) => {
40
+ var _a;
41
+ return ((_a = action.parameters) == null ? void 0 : _a.length) === 0;
42
+ };
43
+ if (renderAndWait) {
44
+ if (isNoArgsRenderWait(renderAndWait)) {
45
+ return renderAndWait(waitProps);
46
+ } else {
47
+ return renderAndWait(waitProps);
48
+ }
49
+ }
50
+ return createElement(Fragment);
51
+ };
52
+ }
53
+ if (dependencies === void 0) {
54
+ if (actions[idRef.current]) {
55
+ actions[idRef.current].handler = action.handler;
56
+ if (typeof action.render === "function") {
57
+ if (chatComponentsCache.current !== null) {
58
+ chatComponentsCache.current.actions[action.name] = action.render;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ useEffect(() => {
64
+ setAction(idRef.current, action);
65
+ if (chatComponentsCache.current !== null && action.render !== void 0) {
66
+ chatComponentsCache.current.actions[action.name] = action.render;
67
+ }
68
+ return () => {
69
+ removeAction(idRef.current);
70
+ };
71
+ }, [
72
+ setAction,
73
+ removeAction,
74
+ action.description,
75
+ action.name,
76
+ action.disabled,
77
+ action.available,
78
+ // This should be faster than deep equality checking
79
+ // In addition, all major JS engines guarantee the order of object keys
80
+ JSON.stringify(action.parameters),
81
+ // include render only if it's a string
82
+ typeof action.render === "string" ? action.render : void 0,
83
+ // dependencies set by the developer
84
+ ...dependencies || []
85
+ ]);
86
+ }
87
+
88
+ export {
89
+ useCopilotAction
90
+ };
91
+ //# sourceMappingURL=chunk-Y7MI4PBB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-copilot-action.ts"],"sourcesContent":["/**\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\n/**\n * <img src=\"/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 {\n ActionRenderProps,\n ActionRenderPropsNoArgsWait,\n ActionRenderPropsWait,\n FrontendAction,\n} from \"../types/frontend-action\";\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>,\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\n // clone the action to avoid mutating the original object\n action = { ...action };\n\n // If the developer provides a renderAndWait function, we transform the action\n // to use a promise internally, so that we can treat it like a normal action.\n if (action.renderAndWait || action.renderAndWaitForResponse) {\n const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;\n // remove the renderAndWait function from the action\n action.renderAndWait = undefined;\n action.renderAndWaitForResponse = undefined;\n // add a handler that will be called when the action is executed\n action.handler = (async () => {\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 = { promise, resolve: resolve!, reject: reject! };\n // then we await the promise (it will be resolved in the original renderAndWait function)\n return await promise;\n }) as any;\n\n // add a render function that will be called when the action is rendered\n action.render = ((props: ActionRenderProps<T>): React.ReactElement => {\n // Create type safe waitProps based on whether T extends empty array or not\n const waitProps = {\n status: props.status,\n args: props.args,\n result: props.result,\n handler: props.status === \"executing\" ? renderAndWaitRef.current!.resolve : undefined,\n respond: props.status === \"executing\" ? renderAndWaitRef.current!.resolve : 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 actions[idRef.current].handler = action.handler as any;\n if (typeof action.render === \"function\") {\n if (chatComponentsCache.current !== null) {\n chatComponentsCache.current.actions[action.name] = action.render;\n }\n }\n }\n }\n\n useEffect(() => {\n setAction(idRef.current, action as any);\n if (chatComponentsCache.current !== null && action.render !== undefined) {\n chatComponentsCache.current.actions[action.name] = action.render;\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 removeAction(idRef.current);\n };\n }, [\n setAction,\n removeAction,\n action.description,\n action.name,\n action.disabled,\n action.available,\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(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\ninterface RenderAndWaitForResponse {\n promise: Promise<any>;\n resolve: (result: any) => void;\n reject: (error: any) => void;\n}\n"],"mappings":";;;;;;;;;AA2HA,SAAoB,gBAAgB;AACpC,SAAS,eAAe,UAAU,WAAW,cAAc;AAkBpD,SAAS,iBACd,QACA,cACM;AACN,QAAM,EAAE,WAAW,cAAc,SAAS,oBAAoB,IAAI,kBAAkB;AACpF,QAAM,QAAQ,OAAe,SAAS,CAAC;AACvC,QAAM,mBAAmB,OAAwC,IAAI;AAGrE,WAAS,mBAAK;AAId,MAAI,OAAO,iBAAiB,OAAO,0BAA0B;AAC3D,UAAM,gBAAgB,OAAO,iBAAiB,OAAO;AAErD,WAAO,gBAAgB;AACvB,WAAO,2BAA2B;AAElC,WAAO,UAAW,MAAY;AAE5B,UAAI;AACJ,UAAI;AACJ,YAAM,UAAU,IAAI,QAAa,CAAC,gBAAgB,kBAAkB;AAClE,kBAAU;AACV,iBAAS;AAAA,MACX,CAAC;AACD,uBAAiB,UAAU,EAAE,SAAS,SAAmB,OAAgB;AAEzE,aAAO,MAAM;AAAA,IACf;AAGA,WAAO,SAAU,CAAC,UAAoD;AAEpE,YAAM,YAAY;AAAA,QAChB,QAAQ,MAAM;AAAA,QACd,MAAM,MAAM;AAAA,QACZ,QAAQ,MAAM;AAAA,QACd,SAAS,MAAM,WAAW,cAAc,iBAAiB,QAAS,UAAU;AAAA,QAC5E,SAAS,MAAM,WAAW,cAAc,iBAAiB,QAAS,UAAU;AAAA,MAC9E;AAGA,YAAM,qBAAqB,CACzB,QAGyE;AA9LjF;AA+LQ,iBAAO,YAAO,eAAP,mBAAmB,YAAW;AAAA,MACvC;AAGA,UAAI,eAAe;AACjB,YAAI,mBAAmB,aAAa,GAAG;AACrC,iBAAO,cAAc,SAA2C;AAAA,QAClE,OAAO;AACL,iBAAO,cAAc,SAAqC;AAAA,QAC5D;AAAA,MACF;AAGA,aAAO,cAAc,QAAQ;AAAA,IAC/B;AAAA,EACF;AAKA,MAAI,iBAAiB,QAAW;AAC9B,QAAI,QAAQ,MAAM,OAAO,GAAG;AAC1B,cAAQ,MAAM,OAAO,EAAE,UAAU,OAAO;AACxC,UAAI,OAAO,OAAO,WAAW,YAAY;AACvC,YAAI,oBAAoB,YAAY,MAAM;AACxC,8BAAoB,QAAQ,QAAQ,OAAO,IAAI,IAAI,OAAO;AAAA,QAC5D;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,YAAU,MAAM;AACd,cAAU,MAAM,SAAS,MAAa;AACtC,QAAI,oBAAoB,YAAY,QAAQ,OAAO,WAAW,QAAW;AACvE,0BAAoB,QAAQ,QAAQ,OAAO,IAAI,IAAI,OAAO;AAAA,IAC5D;AACA,WAAO,MAAM;AAGX,mBAAa,MAAM,OAAO;AAAA,IAC5B;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA;AAAA;AAAA,IAGP,KAAK,UAAU,OAAO,UAAU;AAAA;AAAA,IAEhC,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-YPSGKPDA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,7 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CopilotKitProps } from './copilotkit-props.js';
3
+ import 'react';
4
+
5
+ declare function CopilotMessages({ children, ...props }: CopilotKitProps): react_jsx_runtime.JSX.Element;
6
+
7
+ export { CopilotMessages };
@@ -0,0 +1,80 @@
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 __objRest = (source, exclude) => {
11
+ var target = {};
12
+ for (var prop in source)
13
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
14
+ target[prop] = source[prop];
15
+ if (source != null && __getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(source)) {
17
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
18
+ target[prop] = source[prop];
19
+ }
20
+ return target;
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
+
44
+ // src/components/copilot-provider/copilot-messages.tsx
45
+ var copilot_messages_exports = {};
46
+ __export(copilot_messages_exports, {
47
+ CopilotMessages: () => CopilotMessages
48
+ });
49
+ module.exports = __toCommonJS(copilot_messages_exports);
50
+ var import_react2 = require("react");
51
+
52
+ // src/context/copilot-messages-context.tsx
53
+ var import_react = __toESM(require("react"));
54
+ var emptyCopilotContext = {
55
+ messages: [],
56
+ setMessages: () => []
57
+ };
58
+ var CopilotMessagesContext = import_react.default.createContext(emptyCopilotContext);
59
+
60
+ // src/components/copilot-provider/copilot-messages.tsx
61
+ var import_jsx_runtime = require("react/jsx-runtime");
62
+ function CopilotMessages(_a) {
63
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
64
+ const [messages, setMessages] = (0, import_react2.useState)([]);
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
66
+ CopilotMessagesContext.Provider,
67
+ {
68
+ value: {
69
+ messages,
70
+ setMessages
71
+ },
72
+ children
73
+ }
74
+ );
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ CopilotMessages
79
+ });
80
+ //# sourceMappingURL=copilot-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/copilot-provider/copilot-messages.tsx","../../../src/context/copilot-messages-context.tsx"],"sourcesContent":["/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { useState } from \"react\";\nimport { CopilotMessagesContext } from \"../../context/copilot-messages-context\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\n\nexport function CopilotMessages({ children, ...props }: CopilotKitProps) {\n const [messages, setMessages] = useState<Message[]>([]);\n\n return (\n <CopilotMessagesContext.Provider\n value={{\n messages,\n setMessages,\n }}\n >\n {children}\n </CopilotMessagesContext.Provider>\n );\n}\n","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,IAAAA,gBAAyB;;;ACCzB,mBAAkB;AAOlB,IAAM,sBAAoD;AAAA,EACxD,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,CAAC;AACtB;AAEO,IAAM,yBACX,aAAAC,QAAM,cAA4C,mBAAmB;;;ADLnE;AAJG,SAAS,gBAAgB,IAAyC;AAAzC,eAAE,WATlC,IASgC,IAAe,kBAAf,IAAe,CAAb;AAChC,QAAM,CAAC,UAAU,WAAW,QAAI,wBAAoB,CAAC,CAAC;AAEtD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":["import_react","React"]}
@@ -0,0 +1,9 @@
1
+ import {
2
+ CopilotMessages
3
+ } from "../../chunk-XXR4QFAQ.mjs";
4
+ import "../../chunk-DCTJZ742.mjs";
5
+ import "../../chunk-SKC7AJIV.mjs";
6
+ export {
7
+ CopilotMessages
8
+ };
9
+ //# sourceMappingURL=copilot-messages.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,72 @@
1
+ import { ReactNode } from 'react';
2
+
3
+ /**
4
+ * Props for CopilotKit.
5
+ */
6
+ interface CopilotKitProps {
7
+ /**
8
+ * Your Copilot Cloud API key. Don't have it yet? Go to https://cloud.copilotkit.ai and get one for free.
9
+ */
10
+ publicApiKey?: string;
11
+ /**
12
+ * Restrict input to a specific topic.
13
+ */
14
+ cloudRestrictToTopic?: {
15
+ validTopics?: string[];
16
+ invalidTopics?: string[];
17
+ };
18
+ /**
19
+ * The endpoint for the Copilot Runtime instance. [Click here for more information](/concepts/copilot-runtime).
20
+ */
21
+ runtimeUrl?: string;
22
+ /**
23
+ * The endpoint for the Copilot transcribe audio service.
24
+ */
25
+ transcribeAudioUrl?: string;
26
+ /**
27
+ * The endpoint for the Copilot text to speech service.
28
+ */
29
+ textToSpeechUrl?: string;
30
+ /**
31
+ * Additional headers to be sent with the request.
32
+ *
33
+ * For example:
34
+ * ```json
35
+ * {
36
+ * "Authorization": "Bearer X"
37
+ * }
38
+ * ```
39
+ */
40
+ headers?: Record<string, string>;
41
+ /**
42
+ * The children to be rendered within the CopilotKit.
43
+ */
44
+ children: ReactNode;
45
+ /**
46
+ * Custom properties to be sent with the request
47
+ * For example:
48
+ * ```js
49
+ * {
50
+ * 'user_id': 'users_id',
51
+ * }
52
+ * ```
53
+ */
54
+ properties?: Record<string, any>;
55
+ /**
56
+ * Indicates whether the user agent should send or receive cookies from the other domain
57
+ * in the case of cross-origin requests.
58
+ */
59
+ credentials?: RequestCredentials;
60
+ /**
61
+ * Whether to show the dev console.
62
+ *
63
+ * If set to "auto", the dev console will be show on localhost only.
64
+ */
65
+ showDevConsole?: boolean | "auto";
66
+ /**
67
+ * The name of the agent to use.
68
+ */
69
+ agent?: string;
70
+ }
71
+
72
+ export { CopilotKitProps };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/components/copilot-provider/copilotkit-props.tsx
17
+ var copilotkit_props_exports = {};
18
+ module.exports = __toCommonJS(copilotkit_props_exports);
19
+ //# sourceMappingURL=copilotkit-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\n\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n * Your Copilot Cloud API key. Don't have it yet? Go to https://cloud.copilotkit.ai and get one for free.\n */\n publicApiKey?: string;\n\n /**\n * Restrict input to a specific topic.\n */\n cloudRestrictToTopic?: {\n validTopics?: string[];\n invalidTopics?: string[];\n };\n\n /**\n * The endpoint for the Copilot Runtime instance. [Click here for more information](/concepts/copilot-runtime).\n */\n runtimeUrl?: 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 *\n * For example:\n * ```json\n * {\n * \"Authorization\": \"Bearer X\"\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * The children to be rendered within the CopilotKit.\n */\n children: ReactNode;\n\n /**\n * Custom properties to be sent with the request\n * For example:\n * ```js\n * {\n * 'user_id': 'users_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 * Whether to show the dev console.\n *\n * If set to \"auto\", the dev console will be show on localhost only.\n */\n showDevConsole?: boolean | \"auto\";\n\n /**\n * The name of the agent to use.\n */\n agent?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=copilotkit-props.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,9 @@
1
+ import { CopilotKitProps } from './copilotkit-props.js';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import 'react';
4
+
5
+ declare function CopilotKit({ children, ...props }: CopilotKitProps): react_jsx_runtime.JSX.Element;
6
+ declare function CopilotKitInternal({ children, ...props }: CopilotKitProps): react_jsx_runtime.JSX.Element;
7
+ declare const defaultCopilotContextCategories: string[];
8
+
9
+ export { CopilotKit, CopilotKitInternal, defaultCopilotContextCategories };