@copilotkit/react-core 1.5.1-next.3 → 1.5.1-next.4

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 (228) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/package.json +5 -5
  3. package/dist/chunk-2KCEHGSI.mjs +0 -192
  4. package/dist/chunk-2KCEHGSI.mjs.map +0 -1
  5. package/dist/chunk-5FHSUKQL.mjs +0 -70
  6. package/dist/chunk-5FHSUKQL.mjs.map +0 -1
  7. package/dist/chunk-6OR25P32.mjs +0 -426
  8. package/dist/chunk-6OR25P32.mjs.map +0 -1
  9. package/dist/chunk-6U3UH3KO.mjs +0 -140
  10. package/dist/chunk-6U3UH3KO.mjs.map +0 -1
  11. package/dist/chunk-DCTJZ742.mjs +0 -22
  12. package/dist/chunk-DCTJZ742.mjs.map +0 -1
  13. package/dist/chunk-DDVXFNYA.mjs +0 -126
  14. package/dist/chunk-DDVXFNYA.mjs.map +0 -1
  15. package/dist/chunk-EFZPSZWO.mjs +0 -1
  16. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  17. package/dist/chunk-FXHKK52V.mjs +0 -119
  18. package/dist/chunk-FXHKK52V.mjs.map +0 -1
  19. package/dist/chunk-H4VZMKR6.mjs +0 -23
  20. package/dist/chunk-H4VZMKR6.mjs.map +0 -1
  21. package/dist/chunk-H7LSKIDK.mjs +0 -167
  22. package/dist/chunk-H7LSKIDK.mjs.map +0 -1
  23. package/dist/chunk-JDQCJCAQ.mjs +0 -295
  24. package/dist/chunk-JDQCJCAQ.mjs.map +0 -1
  25. package/dist/chunk-L34MHAXR.mjs +0 -1
  26. package/dist/chunk-L34MHAXR.mjs.map +0 -1
  27. package/dist/chunk-LODRWFMB.mjs +0 -75
  28. package/dist/chunk-LODRWFMB.mjs.map +0 -1
  29. package/dist/chunk-LUGEI4YQ.mjs +0 -1
  30. package/dist/chunk-LUGEI4YQ.mjs.map +0 -1
  31. package/dist/chunk-MLAS4QUR.mjs +0 -18
  32. package/dist/chunk-MLAS4QUR.mjs.map +0 -1
  33. package/dist/chunk-MWZO6TUR.mjs +0 -91
  34. package/dist/chunk-MWZO6TUR.mjs.map +0 -1
  35. package/dist/chunk-O7ARI5CV.mjs +0 -31
  36. package/dist/chunk-O7ARI5CV.mjs.map +0 -1
  37. package/dist/chunk-ODN4H66E.mjs +0 -31
  38. package/dist/chunk-ODN4H66E.mjs.map +0 -1
  39. package/dist/chunk-QDGDXRRJ.mjs +0 -28
  40. package/dist/chunk-QDGDXRRJ.mjs.map +0 -1
  41. package/dist/chunk-SKC7AJIV.mjs +0 -61
  42. package/dist/chunk-SKC7AJIV.mjs.map +0 -1
  43. package/dist/chunk-XINZBP3J.mjs +0 -49
  44. package/dist/chunk-XINZBP3J.mjs.map +0 -1
  45. package/dist/chunk-XXR4QFAQ.mjs +0 -29
  46. package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
  47. package/dist/chunk-YPSGKPDA.mjs +0 -1
  48. package/dist/chunk-YPSGKPDA.mjs.map +0 -1
  49. package/dist/components/copilot-provider/copilot-messages.d.ts +0 -7
  50. package/dist/components/copilot-provider/copilot-messages.js +0 -80
  51. package/dist/components/copilot-provider/copilot-messages.js.map +0 -1
  52. package/dist/components/copilot-provider/copilot-messages.mjs +0 -9
  53. package/dist/components/copilot-provider/copilot-messages.mjs.map +0 -1
  54. package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -72
  55. package/dist/components/copilot-provider/copilotkit-props.js +0 -19
  56. package/dist/components/copilot-provider/copilotkit-props.js.map +0 -1
  57. package/dist/components/copilot-provider/copilotkit-props.mjs +0 -1
  58. package/dist/components/copilot-provider/copilotkit-props.mjs.map +0 -1
  59. package/dist/components/copilot-provider/copilotkit.d.ts +0 -9
  60. package/dist/components/copilot-provider/copilotkit.js +0 -861
  61. package/dist/components/copilot-provider/copilotkit.js.map +0 -1
  62. package/dist/components/copilot-provider/copilotkit.mjs +0 -21
  63. package/dist/components/copilot-provider/copilotkit.mjs.map +0 -1
  64. package/dist/components/copilot-provider/index.d.ts +0 -4
  65. package/dist/components/copilot-provider/index.js +0 -861
  66. package/dist/components/copilot-provider/index.js.map +0 -1
  67. package/dist/components/copilot-provider/index.mjs +0 -19
  68. package/dist/components/copilot-provider/index.mjs.map +0 -1
  69. package/dist/components/index.d.ts +0 -4
  70. package/dist/components/index.js +0 -861
  71. package/dist/components/index.js.map +0 -1
  72. package/dist/components/index.mjs +0 -19
  73. package/dist/components/index.mjs.map +0 -1
  74. package/dist/components/toast/exclamation-mark-icon.d.ts +0 -9
  75. package/dist/components/toast/exclamation-mark-icon.js +0 -55
  76. package/dist/components/toast/exclamation-mark-icon.js.map +0 -1
  77. package/dist/components/toast/exclamation-mark-icon.mjs +0 -8
  78. package/dist/components/toast/exclamation-mark-icon.mjs.map +0 -1
  79. package/dist/components/toast/toast-provider.d.ts +0 -29
  80. package/dist/components/toast/toast-provider.js +0 -255
  81. package/dist/components/toast/toast-provider.js.map +0 -1
  82. package/dist/components/toast/toast-provider.mjs +0 -11
  83. package/dist/components/toast/toast-provider.mjs.map +0 -1
  84. package/dist/context/copilot-context.d.ts +0 -109
  85. package/dist/context/copilot-context.js +0 -126
  86. package/dist/context/copilot-context.js.map +0 -1
  87. package/dist/context/copilot-context.mjs +0 -10
  88. package/dist/context/copilot-context.mjs.map +0 -1
  89. package/dist/context/copilot-messages-context.d.ts +0 -15
  90. package/dist/context/copilot-messages-context.js +0 -57
  91. package/dist/context/copilot-messages-context.js.map +0 -1
  92. package/dist/context/copilot-messages-context.mjs +0 -10
  93. package/dist/context/copilot-messages-context.mjs.map +0 -1
  94. package/dist/context/index.d.ts +0 -11
  95. package/dist/context/index.js +0 -149
  96. package/dist/context/index.js.map +0 -1
  97. package/dist/context/index.mjs +0 -17
  98. package/dist/context/index.mjs.map +0 -1
  99. package/dist/hooks/index.d.ts +0 -19
  100. package/dist/hooks/index.js +0 -897
  101. package/dist/hooks/index.js.map +0 -1
  102. package/dist/hooks/index.mjs +0 -44
  103. package/dist/hooks/index.mjs.map +0 -1
  104. package/dist/hooks/use-chat.d.ts +0 -92
  105. package/dist/hooks/use-chat.js +0 -360
  106. package/dist/hooks/use-chat.js.map +0 -1
  107. package/dist/hooks/use-chat.mjs +0 -11
  108. package/dist/hooks/use-chat.mjs.map +0 -1
  109. package/dist/hooks/use-coagent-state-render.d.ts +0 -60
  110. package/dist/hooks/use-coagent-state-render.js +0 -160
  111. package/dist/hooks/use-coagent-state-render.js.map +0 -1
  112. package/dist/hooks/use-coagent-state-render.mjs +0 -9
  113. package/dist/hooks/use-coagent-state-render.mjs.map +0 -1
  114. package/dist/hooks/use-coagent.d.ts +0 -186
  115. package/dist/hooks/use-coagent.js +0 -726
  116. package/dist/hooks/use-coagent.js.map +0 -1
  117. package/dist/hooks/use-coagent.mjs +0 -21
  118. package/dist/hooks/use-coagent.mjs.map +0 -1
  119. package/dist/hooks/use-copilot-action.d.ts +0 -130
  120. package/dist/hooks/use-copilot-action.js +0 -219
  121. package/dist/hooks/use-copilot-action.js.map +0 -1
  122. package/dist/hooks/use-copilot-action.mjs +0 -9
  123. package/dist/hooks/use-copilot-action.mjs.map +0 -1
  124. package/dist/hooks/use-copilot-chat.d.ts +0 -36
  125. package/dist/hooks/use-copilot-chat.js +0 -623
  126. package/dist/hooks/use-copilot-chat.js.map +0 -1
  127. package/dist/hooks/use-copilot-chat.mjs +0 -22
  128. package/dist/hooks/use-copilot-chat.mjs.map +0 -1
  129. package/dist/hooks/use-copilot-readable.d.ts +0 -33
  130. package/dist/hooks/use-copilot-readable.js +0 -146
  131. package/dist/hooks/use-copilot-readable.js.map +0 -1
  132. package/dist/hooks/use-copilot-readable.mjs +0 -9
  133. package/dist/hooks/use-copilot-readable.mjs.map +0 -1
  134. package/dist/hooks/use-copilot-runtime-client.d.ts +0 -5
  135. package/dist/hooks/use-copilot-runtime-client.js +0 -76
  136. package/dist/hooks/use-copilot-runtime-client.js.map +0 -1
  137. package/dist/hooks/use-copilot-runtime-client.mjs +0 -10
  138. package/dist/hooks/use-copilot-runtime-client.mjs.map +0 -1
  139. package/dist/hooks/use-flat-category-store.d.ts +0 -9
  140. package/dist/hooks/use-flat-category-store.js +0 -90
  141. package/dist/hooks/use-flat-category-store.js.map +0 -1
  142. package/dist/hooks/use-flat-category-store.mjs +0 -8
  143. package/dist/hooks/use-flat-category-store.mjs.map +0 -1
  144. package/dist/hooks/use-make-copilot-document-readable.d.ts +0 -12
  145. package/dist/hooks/use-make-copilot-document-readable.js +0 -141
  146. package/dist/hooks/use-make-copilot-document-readable.js.map +0 -1
  147. package/dist/hooks/use-make-copilot-document-readable.mjs +0 -9
  148. package/dist/hooks/use-make-copilot-document-readable.mjs.map +0 -1
  149. package/dist/hooks/use-tree.d.ts +0 -18
  150. package/dist/hooks/use-tree.js +0 -172
  151. package/dist/hooks/use-tree.js.map +0 -1
  152. package/dist/hooks/use-tree.mjs +0 -8
  153. package/dist/hooks/use-tree.mjs.map +0 -1
  154. package/dist/index.d.ts +0 -26
  155. package/dist/index.js +0 -1810
  156. package/dist/index.js.map +0 -1
  157. package/dist/index.mjs +0 -71
  158. package/dist/index.mjs.map +0 -1
  159. package/dist/lib/copilot-task.d.ts +0 -92
  160. package/dist/lib/copilot-task.js +0 -157
  161. package/dist/lib/copilot-task.js.map +0 -1
  162. package/dist/lib/copilot-task.mjs +0 -18
  163. package/dist/lib/copilot-task.mjs.map +0 -1
  164. package/dist/lib/index.d.ts +0 -11
  165. package/dist/lib/index.js +0 -159
  166. package/dist/lib/index.js.map +0 -1
  167. package/dist/lib/index.mjs +0 -19
  168. package/dist/lib/index.mjs.map +0 -1
  169. package/dist/types/chat-suggestion-configuration.d.ts +0 -22
  170. package/dist/types/chat-suggestion-configuration.js +0 -19
  171. package/dist/types/chat-suggestion-configuration.js.map +0 -1
  172. package/dist/types/chat-suggestion-configuration.mjs +0 -1
  173. package/dist/types/chat-suggestion-configuration.mjs.map +0 -1
  174. package/dist/types/coagent-action.d.ts +0 -29
  175. package/dist/types/coagent-action.js +0 -19
  176. package/dist/types/coagent-action.js.map +0 -1
  177. package/dist/types/coagent-action.mjs +0 -1
  178. package/dist/types/coagent-action.mjs.map +0 -1
  179. package/dist/types/coagent-state.d.ts +0 -11
  180. package/dist/types/coagent-state.js +0 -19
  181. package/dist/types/coagent-state.js.map +0 -1
  182. package/dist/types/coagent-state.mjs +0 -1
  183. package/dist/types/coagent-state.mjs.map +0 -1
  184. package/dist/types/document-pointer.d.ts +0 -9
  185. package/dist/types/document-pointer.js +0 -19
  186. package/dist/types/document-pointer.js.map +0 -1
  187. package/dist/types/document-pointer.mjs +0 -1
  188. package/dist/types/document-pointer.mjs.map +0 -1
  189. package/dist/types/frontend-action.d.ts +0 -107
  190. package/dist/types/frontend-action.js +0 -19
  191. package/dist/types/frontend-action.js.map +0 -1
  192. package/dist/types/frontend-action.mjs +0 -1
  193. package/dist/types/frontend-action.mjs.map +0 -1
  194. package/dist/types/index.d.ts +0 -6
  195. package/dist/types/index.js +0 -19
  196. package/dist/types/index.js.map +0 -1
  197. package/dist/types/index.mjs +0 -2
  198. package/dist/types/index.mjs.map +0 -1
  199. package/dist/types/system-message.d.ts +0 -3
  200. package/dist/types/system-message.js +0 -19
  201. package/dist/types/system-message.js.map +0 -1
  202. package/dist/types/system-message.mjs +0 -1
  203. package/dist/types/system-message.mjs.map +0 -1
  204. package/dist/utils/dev-console.d.ts +0 -3
  205. package/dist/utils/dev-console.js +0 -42
  206. package/dist/utils/dev-console.js.map +0 -1
  207. package/dist/utils/dev-console.mjs +0 -8
  208. package/dist/utils/dev-console.mjs.map +0 -1
  209. package/dist/utils/extract.d.ts +0 -42
  210. package/dist/utils/extract.js +0 -190
  211. package/dist/utils/extract.js.map +0 -1
  212. package/dist/utils/extract.mjs +0 -17
  213. package/dist/utils/extract.mjs.map +0 -1
  214. package/dist/utils/index.d.ts +0 -13
  215. package/dist/utils/index.js +0 -208
  216. package/dist/utils/index.js.map +0 -1
  217. package/dist/utils/index.mjs +0 -20
  218. package/dist/utils/index.mjs.map +0 -1
  219. package/dist/utils/utils.d.ts +0 -2
  220. package/dist/utils/utils.js +0 -19
  221. package/dist/utils/utils.js.map +0 -1
  222. package/dist/utils/utils.mjs +0 -1
  223. package/dist/utils/utils.mjs.map +0 -1
  224. package/dist/utils/utils.test.d.ts +0 -2
  225. package/dist/utils/utils.test.js +0 -9
  226. package/dist/utils/utils.test.js.map +0 -1
  227. package/dist/utils/utils.test.mjs +0 -7
  228. package/dist/utils/utils.test.mjs.map +0 -1
@@ -1,861 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __restKey = (key) => typeof key === "symbol" ? key : key + "";
26
- var __objRest = (source, exclude) => {
27
- var target = {};
28
- for (var prop in source)
29
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
- target[prop] = source[prop];
31
- if (source != null && __getOwnPropSymbols)
32
- for (var prop of __getOwnPropSymbols(source)) {
33
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
- target[prop] = source[prop];
35
- }
36
- return target;
37
- };
38
- var __export = (target, all) => {
39
- for (var name in all)
40
- __defProp(target, name, { get: all[name], enumerable: true });
41
- };
42
- var __copyProps = (to, from, except, desc) => {
43
- if (from && typeof from === "object" || typeof from === "function") {
44
- for (let key of __getOwnPropNames(from))
45
- if (!__hasOwnProp.call(to, key) && key !== except)
46
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
- }
48
- return to;
49
- };
50
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
- // If the importer is in node compatibility mode or this is not an ESM
52
- // file that has been converted to a CommonJS file using a Babel-
53
- // compatible transform (i.e. "__esModule" has not been set), then set
54
- // "default" to the CommonJS "module.exports" for node compatibility.
55
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
- mod
57
- ));
58
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
59
- var __async = (__this, __arguments, generator) => {
60
- return new Promise((resolve, reject) => {
61
- var fulfilled = (value) => {
62
- try {
63
- step(generator.next(value));
64
- } catch (e) {
65
- reject(e);
66
- }
67
- };
68
- var rejected = (value) => {
69
- try {
70
- step(generator.throw(value));
71
- } catch (e) {
72
- reject(e);
73
- }
74
- };
75
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
76
- step((generator = generator.apply(__this, __arguments)).next());
77
- });
78
- };
79
-
80
- // src/components/copilot-provider/copilotkit.tsx
81
- var copilotkit_exports = {};
82
- __export(copilotkit_exports, {
83
- CopilotKit: () => CopilotKit,
84
- CopilotKitInternal: () => CopilotKitInternal,
85
- defaultCopilotContextCategories: () => defaultCopilotContextCategories
86
- });
87
- module.exports = __toCommonJS(copilotkit_exports);
88
- var import_react8 = require("react");
89
-
90
- // src/context/copilot-context.tsx
91
- var import_react = __toESM(require("react"));
92
- var emptyCopilotContext = {
93
- actions: {},
94
- setAction: () => {
95
- },
96
- removeAction: () => {
97
- },
98
- coAgentStateRenders: {},
99
- setCoAgentStateRender: () => {
100
- },
101
- removeCoAgentStateRender: () => {
102
- },
103
- chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
104
- getContextString: (documents, categories) => returnAndThrowInDebug(""),
105
- addContext: () => "",
106
- removeContext: () => {
107
- },
108
- getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
109
- })),
110
- isLoading: false,
111
- setIsLoading: () => returnAndThrowInDebug(false),
112
- chatInstructions: "",
113
- setChatInstructions: () => returnAndThrowInDebug(""),
114
- getDocumentsContext: (categories) => returnAndThrowInDebug([]),
115
- addDocumentContext: () => returnAndThrowInDebug(""),
116
- removeDocumentContext: () => {
117
- },
118
- runtimeClient: {},
119
- copilotApiConfig: new class {
120
- get chatApiEndpoint() {
121
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
122
- }
123
- get headers() {
124
- return {};
125
- }
126
- get body() {
127
- return {};
128
- }
129
- }(),
130
- chatSuggestionConfiguration: {},
131
- addChatSuggestionConfiguration: () => {
132
- },
133
- removeChatSuggestionConfiguration: () => {
134
- },
135
- showDevConsole: "auto",
136
- coagentStates: {},
137
- setCoagentStates: () => {
138
- },
139
- agentSession: null,
140
- setAgentSession: () => {
141
- }
142
- };
143
- var CopilotContext = import_react.default.createContext(emptyCopilotContext);
144
- function returnAndThrowInDebug(value) {
145
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
146
- return value;
147
- }
148
-
149
- // src/hooks/use-tree.ts
150
- var import_shared = require("@copilotkit/shared");
151
- var import_react2 = require("react");
152
- var removeNode = (nodes, id) => {
153
- return nodes.reduce((result, node) => {
154
- if (node.id !== id) {
155
- const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
156
- result.push(newNode);
157
- }
158
- return result;
159
- }, []);
160
- };
161
- var addNode = (nodes, newNode, parentId) => {
162
- if (!parentId) {
163
- return [...nodes, newNode];
164
- }
165
- return nodes.map((node) => {
166
- if (node.id === parentId) {
167
- return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
168
- } else if (node.children.length) {
169
- return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
170
- }
171
- return node;
172
- });
173
- };
174
- var treeIndentationRepresentation = (index, indentLevel) => {
175
- if (indentLevel === 0) {
176
- return (index + 1).toString();
177
- } else if (indentLevel === 1) {
178
- return String.fromCharCode(65 + index);
179
- } else if (indentLevel === 2) {
180
- return String.fromCharCode(97 + index);
181
- } else {
182
- return "-";
183
- }
184
- };
185
- var printNode = (node, prefix = "", indentLevel = 0) => {
186
- const indent = " ".repeat(3).repeat(indentLevel);
187
- const prefixPlusIndentLength = prefix.length + indent.length;
188
- const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
189
- const valueLines = node.value.split("\n");
190
- const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
191
- const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
192
- let output = `${outputFirstLine}
193
- `;
194
- if (outputSubsequentLines) {
195
- output += `${outputSubsequentLines}
196
- `;
197
- }
198
- const childPrePrefix = " ".repeat(prefix.length);
199
- node.children.forEach(
200
- (child, index) => output += printNode(
201
- child,
202
- `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
203
- indentLevel + 1
204
- )
205
- );
206
- return output;
207
- };
208
- function treeReducer(state, action) {
209
- switch (action.type) {
210
- case "ADD_NODE": {
211
- const { value, parentId, id: newNodeId } = action;
212
- const newNode = {
213
- id: newNodeId,
214
- value,
215
- children: [],
216
- categories: new Set(action.categories)
217
- };
218
- try {
219
- return addNode(state, newNode, parentId);
220
- } catch (error) {
221
- console.error(`Error while adding node with id ${newNodeId}: ${error}`);
222
- return state;
223
- }
224
- }
225
- case "REMOVE_NODE":
226
- return removeNode(state, action.id);
227
- default:
228
- return state;
229
- }
230
- }
231
- var useTree = () => {
232
- const [tree, dispatch] = (0, import_react2.useReducer)(treeReducer, []);
233
- const addElement = (0, import_react2.useCallback)(
234
- (value, categories, parentId) => {
235
- const newNodeId = (0, import_shared.randomId)();
236
- dispatch({
237
- type: "ADD_NODE",
238
- value,
239
- parentId,
240
- id: newNodeId,
241
- categories
242
- });
243
- return newNodeId;
244
- },
245
- []
246
- );
247
- const removeElement = (0, import_react2.useCallback)((id) => {
248
- dispatch({ type: "REMOVE_NODE", id });
249
- }, []);
250
- const printTree = (0, import_react2.useCallback)(
251
- (categories) => {
252
- const categoriesSet = new Set(categories);
253
- let output = "";
254
- tree.forEach((node, index) => {
255
- if (!setsHaveIntersection(categoriesSet, node.categories)) {
256
- return;
257
- }
258
- if (index !== 0) {
259
- output += "\n";
260
- }
261
- output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
262
- });
263
- return output;
264
- },
265
- [tree]
266
- );
267
- return { tree, addElement, printTree, removeElement };
268
- };
269
- var use_tree_default = useTree;
270
- function setsHaveIntersection(setA, setB) {
271
- const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
272
- for (let item of smallerSet) {
273
- if (largerSet.has(item)) {
274
- return true;
275
- }
276
- }
277
- return false;
278
- }
279
-
280
- // src/components/copilot-provider/copilotkit.tsx
281
- var import_react_dom = require("react-dom");
282
- var import_shared3 = require("@copilotkit/shared");
283
-
284
- // src/hooks/use-flat-category-store.ts
285
- var import_react3 = require("react");
286
- var import_shared2 = require("@copilotkit/shared");
287
- var useFlatCategoryStore = () => {
288
- const [elements, dispatch] = (0, import_react3.useReducer)(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
289
- const addElement = (0, import_react3.useCallback)((value, categories) => {
290
- const newId = (0, import_shared2.randomId)();
291
- dispatch({
292
- type: "ADD_ELEMENT",
293
- value,
294
- id: newId,
295
- categories
296
- });
297
- return newId;
298
- }, []);
299
- const removeElement = (0, import_react3.useCallback)((id) => {
300
- dispatch({ type: "REMOVE_ELEMENT", id });
301
- }, []);
302
- const allElements = (0, import_react3.useCallback)(
303
- (categories) => {
304
- const categoriesSet = new Set(categories);
305
- const result = [];
306
- elements.forEach((element) => {
307
- if (setsHaveIntersection2(categoriesSet, element.categories)) {
308
- result.push(element.value);
309
- }
310
- });
311
- return result;
312
- },
313
- [elements]
314
- );
315
- return { addElement, removeElement, allElements };
316
- };
317
- var use_flat_category_store_default = useFlatCategoryStore;
318
- function flatCategoryStoreReducer(state, action) {
319
- switch (action.type) {
320
- case "ADD_ELEMENT": {
321
- const { value, id, categories } = action;
322
- const newElement = {
323
- id,
324
- value,
325
- categories: new Set(categories)
326
- };
327
- const newState = new Map(state);
328
- newState.set(id, newElement);
329
- return newState;
330
- }
331
- case "REMOVE_ELEMENT": {
332
- const newState = new Map(state);
333
- newState.delete(action.id);
334
- return newState;
335
- }
336
- default:
337
- return state;
338
- }
339
- }
340
- function setsHaveIntersection2(setA, setB) {
341
- const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
342
- for (let item of smallerSet) {
343
- if (largerSet.has(item)) {
344
- return true;
345
- }
346
- }
347
- return false;
348
- }
349
-
350
- // src/components/copilot-provider/copilot-messages.tsx
351
- var import_react5 = require("react");
352
-
353
- // src/context/copilot-messages-context.tsx
354
- var import_react4 = __toESM(require("react"));
355
- var emptyCopilotContext2 = {
356
- messages: [],
357
- setMessages: () => []
358
- };
359
- var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotContext2);
360
-
361
- // src/components/copilot-provider/copilot-messages.tsx
362
- var import_jsx_runtime = require("react/jsx-runtime");
363
- function CopilotMessages(_a) {
364
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
365
- const [messages, setMessages] = (0, import_react5.useState)([]);
366
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
367
- CopilotMessagesContext.Provider,
368
- {
369
- value: {
370
- messages,
371
- setMessages
372
- },
373
- children
374
- }
375
- );
376
- }
377
-
378
- // src/components/toast/toast-provider.tsx
379
- var import_react6 = require("react");
380
-
381
- // src/components/toast/exclamation-mark-icon.tsx
382
- var import_jsx_runtime2 = require("react/jsx-runtime");
383
- var ExclamationMarkIcon = ({
384
- className,
385
- style
386
- }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
387
- "svg",
388
- {
389
- xmlns: "http://www.w3.org/2000/svg",
390
- width: "24",
391
- height: "24",
392
- viewBox: "0 0 24 24",
393
- fill: "none",
394
- stroke: "currentColor",
395
- strokeWidth: "2",
396
- strokeLinecap: "round",
397
- strokeLinejoin: "round",
398
- className: `lucide lucide-circle-alert ${className ? className : ""}`,
399
- style,
400
- children: [
401
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
402
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
403
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
404
- ]
405
- }
406
- );
407
-
408
- // src/components/toast/toast-provider.tsx
409
- var import_jsx_runtime3 = require("react/jsx-runtime");
410
- var ToastContext = (0, import_react6.createContext)(void 0);
411
- function useToast() {
412
- const context = (0, import_react6.useContext)(ToastContext);
413
- if (!context) {
414
- throw new Error("useToast must be used within a ToastProvider");
415
- }
416
- return context;
417
- }
418
- function ToastProvider({
419
- enabled,
420
- children
421
- }) {
422
- const [toasts, setToasts] = (0, import_react6.useState)([]);
423
- const addToast = (0, import_react6.useCallback)((toast) => {
424
- const id = Math.random().toString(36).substring(2, 9);
425
- setToasts((currentToasts) => [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })]);
426
- if (toast.duration) {
427
- setTimeout(() => {
428
- removeToast(id);
429
- }, toast.duration);
430
- }
431
- }, []);
432
- const addGraphQLErrorsToast = (0, import_react6.useCallback)((errors) => {
433
- const errorsToRender = errors.map((error, idx) => {
434
- var _a;
435
- const message = error.message;
436
- const code = (_a = error.extensions) == null ? void 0 : _a.code;
437
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
438
- "div",
439
- {
440
- style: {
441
- marginTop: idx === 0 ? 0 : 10,
442
- marginBottom: 14
443
- },
444
- children: [
445
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
446
- code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
447
- "div",
448
- {
449
- style: {
450
- fontWeight: "600",
451
- marginBottom: 4
452
- },
453
- children: [
454
- "Copilot Cloud Error:",
455
- " ",
456
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
457
- ]
458
- }
459
- ),
460
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
461
- ]
462
- },
463
- idx
464
- );
465
- });
466
- addToast({
467
- type: "error",
468
- message: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
469
- "div",
470
- {
471
- style: {
472
- fontSize: "13px",
473
- maxWidth: "600px"
474
- },
475
- children: [
476
- errorsToRender,
477
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This is a Copilot Cloud error, and it only displays during local development." })
478
- ]
479
- }
480
- )
481
- });
482
- }, []);
483
- const removeToast = (0, import_react6.useCallback)((id) => {
484
- setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
485
- }, []);
486
- const value = {
487
- toasts,
488
- addToast,
489
- addGraphQLErrorsToast,
490
- removeToast,
491
- enabled
492
- };
493
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
494
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
495
- "div",
496
- {
497
- style: {
498
- position: "fixed",
499
- bottom: "1rem",
500
- left: "50%",
501
- transform: "translateX(-50%)",
502
- zIndex: 50,
503
- display: "flex",
504
- flexDirection: "column",
505
- gap: "0.5rem"
506
- },
507
- children: [
508
- toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
509
- "button",
510
- {
511
- onClick: () => setToasts([]),
512
- style: {
513
- padding: "4px 8px",
514
- fontSize: "12px",
515
- cursor: "pointer",
516
- background: "white",
517
- border: "1px solid rgba(0,0,0,0.2)",
518
- borderRadius: "4px"
519
- },
520
- children: "Close All"
521
- }
522
- ) }),
523
- toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
524
- Toast,
525
- {
526
- message: toast.message,
527
- type: toast.type,
528
- onClose: () => removeToast(toast.id)
529
- },
530
- toast.id
531
- ))
532
- ]
533
- }
534
- ),
535
- children
536
- ] });
537
- }
538
- function Toast({
539
- message,
540
- type = "info",
541
- onClose
542
- }) {
543
- const bgColors = {
544
- info: "#3b82f6",
545
- success: "#22c55e",
546
- warning: "#eab308",
547
- error: "#ef4444"
548
- };
549
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
550
- "div",
551
- {
552
- style: {
553
- backgroundColor: bgColors[type],
554
- color: "white",
555
- padding: "0.5rem 1rem",
556
- borderRadius: "0.25rem",
557
- boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
558
- position: "relative",
559
- minWidth: "200px"
560
- },
561
- children: [
562
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
563
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
564
- "button",
565
- {
566
- onClick: onClose,
567
- style: {
568
- position: "absolute",
569
- top: "0",
570
- right: "0",
571
- background: "none",
572
- border: "none",
573
- color: "white",
574
- cursor: "pointer",
575
- padding: "0.5rem",
576
- fontSize: "1rem"
577
- },
578
- children: "\u2715"
579
- }
580
- )
581
- ]
582
- }
583
- );
584
- }
585
-
586
- // src/hooks/use-copilot-runtime-client.ts
587
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
588
- var import_react7 = require("react");
589
- var useCopilotRuntimeClient = (options) => {
590
- const { addGraphQLErrorsToast } = useToast();
591
- const runtimeClient = (0, import_react7.useMemo)(() => {
592
- return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
593
- handleGQLErrors: (error) => {
594
- if (error.graphQLErrors.length) {
595
- addGraphQLErrorsToast(error.graphQLErrors);
596
- }
597
- }
598
- }));
599
- }, [options, addGraphQLErrorsToast]);
600
- return runtimeClient;
601
- };
602
-
603
- // src/utils/dev-console.ts
604
- function shouldShowDevConsole(showDevConsole) {
605
- if (typeof showDevConsole === "boolean") {
606
- return showDevConsole;
607
- }
608
- return getHostname() === "localhost" || getHostname() === "127.0.0.1" || getHostname() === "0.0.0.0" || getHostname() === "::1";
609
- }
610
- function getHostname() {
611
- if (typeof window !== "undefined" && window.location) {
612
- return window.location.hostname;
613
- }
614
- return "";
615
- }
616
-
617
- // src/components/copilot-provider/copilotkit.tsx
618
- var import_jsx_runtime4 = require("react/jsx-runtime");
619
- function CopilotKit(_a) {
620
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
621
- const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
622
- const enabled = shouldShowDevConsole(showDevConsole);
623
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
624
- }
625
- function CopilotKitInternal(_a) {
626
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
627
- if (!props.runtimeUrl && !props.publicApiKey) {
628
- throw new Error(
629
- "Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component."
630
- );
631
- }
632
- const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
633
- const [actions, setActions] = (0, import_react8.useState)({});
634
- const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
635
- const chatComponentsCache = (0, import_react8.useRef)({
636
- actions: {},
637
- coAgentStateRenders: {}
638
- });
639
- const { addElement, removeElement, printTree } = use_tree_default();
640
- const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
641
- const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
642
- const {
643
- addElement: addDocument,
644
- removeElement: removeDocument,
645
- allElements: allDocuments
646
- } = use_flat_category_store_default();
647
- const setAction = (0, import_react8.useCallback)((id, action) => {
648
- setActions((prevPoints) => {
649
- return __spreadProps(__spreadValues({}, prevPoints), {
650
- [id]: action
651
- });
652
- });
653
- }, []);
654
- const removeAction = (0, import_react8.useCallback)((id) => {
655
- setActions((prevPoints) => {
656
- const newPoints = __spreadValues({}, prevPoints);
657
- delete newPoints[id];
658
- return newPoints;
659
- });
660
- }, []);
661
- const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
662
- setCoAgentStateRenders((prevPoints) => {
663
- return __spreadProps(__spreadValues({}, prevPoints), {
664
- [id]: stateRender
665
- });
666
- });
667
- }, []);
668
- const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
669
- setCoAgentStateRenders((prevPoints) => {
670
- const newPoints = __spreadValues({}, prevPoints);
671
- delete newPoints[id];
672
- return newPoints;
673
- });
674
- }, []);
675
- const getContextString = (0, import_react8.useCallback)(
676
- (documents, categories) => {
677
- const documentsString = documents.map((document) => {
678
- return `${document.name} (${document.sourceApplication}):
679
- ${document.getContents()}`;
680
- }).join("\n\n");
681
- const nonDocumentStrings = printTree(categories);
682
- return `${documentsString}
683
-
684
- ${nonDocumentStrings}`;
685
- },
686
- [printTree]
687
- );
688
- const addContext = (0, import_react8.useCallback)(
689
- (context, parentId, categories = defaultCopilotContextCategories) => {
690
- return addElement(context, categories, parentId);
691
- },
692
- [addElement]
693
- );
694
- const removeContext = (0, import_react8.useCallback)(
695
- (id) => {
696
- removeElement(id);
697
- },
698
- [removeElement]
699
- );
700
- const getFunctionCallHandler = (0, import_react8.useCallback)(
701
- (customEntryPoints) => {
702
- return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
703
- },
704
- [actions]
705
- );
706
- const getDocumentsContext = (0, import_react8.useCallback)(
707
- (categories) => {
708
- return allDocuments(categories);
709
- },
710
- [allDocuments]
711
- );
712
- const addDocumentContext = (0, import_react8.useCallback)(
713
- (documentPointer, categories = defaultCopilotContextCategories) => {
714
- return addDocument(documentPointer, categories);
715
- },
716
- [addDocument]
717
- );
718
- const removeDocumentContext = (0, import_react8.useCallback)(
719
- (documentId) => {
720
- removeDocument(documentId);
721
- },
722
- [removeDocument]
723
- );
724
- if (!props.publicApiKey) {
725
- if (props.cloudRestrictToTopic) {
726
- throw new Error(
727
- "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey."
728
- );
729
- }
730
- }
731
- const copilotApiConfig = (0, import_react8.useMemo)(() => {
732
- var _a2, _b2;
733
- let cloud = void 0;
734
- if (props.publicApiKey) {
735
- cloud = {
736
- guardrails: {
737
- input: {
738
- restrictToTopic: {
739
- enabled: props.cloudRestrictToTopic ? true : false,
740
- validTopics: ((_a2 = props.cloudRestrictToTopic) == null ? void 0 : _a2.validTopics) || [],
741
- invalidTopics: ((_b2 = props.cloudRestrictToTopic) == null ? void 0 : _b2.invalidTopics) || []
742
- }
743
- }
744
- }
745
- };
746
- }
747
- return __spreadProps(__spreadValues({
748
- publicApiKey: props.publicApiKey
749
- }, cloud ? { cloud } : {}), {
750
- chatApiEndpoint,
751
- headers: props.headers || {},
752
- properties: props.properties || {},
753
- transcribeAudioUrl: props.transcribeAudioUrl,
754
- textToSpeechUrl: props.textToSpeechUrl,
755
- credentials: props.credentials
756
- });
757
- }, [
758
- props.publicApiKey,
759
- props.headers,
760
- props.properties,
761
- props.transcribeAudioUrl,
762
- props.textToSpeechUrl,
763
- props.credentials,
764
- props.cloudRestrictToTopic
765
- ]);
766
- const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
767
- const runtimeClient = useCopilotRuntimeClient({
768
- url: copilotApiConfig.chatApiEndpoint,
769
- publicApiKey: copilotApiConfig.publicApiKey,
770
- headers,
771
- credentials: copilotApiConfig.credentials
772
- });
773
- const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
774
- const addChatSuggestionConfiguration = (id, suggestion) => {
775
- setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
776
- };
777
- const removeChatSuggestionConfiguration = (id) => {
778
- setChatSuggestionConfiguration((prev) => {
779
- const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
780
- return rest;
781
- });
782
- };
783
- const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
784
- let initialAgentSession = null;
785
- if (props.agent) {
786
- initialAgentSession = {
787
- agentName: props.agent
788
- };
789
- }
790
- const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
791
- const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
792
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
793
- CopilotContext.Provider,
794
- {
795
- value: {
796
- actions,
797
- chatComponentsCache,
798
- getFunctionCallHandler,
799
- setAction,
800
- removeAction,
801
- coAgentStateRenders,
802
- setCoAgentStateRender,
803
- removeCoAgentStateRender,
804
- getContextString,
805
- addContext,
806
- removeContext,
807
- getDocumentsContext,
808
- addDocumentContext,
809
- removeDocumentContext,
810
- copilotApiConfig,
811
- isLoading,
812
- setIsLoading,
813
- chatSuggestionConfiguration,
814
- addChatSuggestionConfiguration,
815
- removeChatSuggestionConfiguration,
816
- chatInstructions,
817
- setChatInstructions,
818
- showDevConsole,
819
- coagentStates,
820
- setCoagentStates,
821
- agentSession,
822
- setAgentSession,
823
- runtimeClient
824
- },
825
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
826
- }
827
- );
828
- }
829
- var defaultCopilotContextCategories = ["global"];
830
- function entryPointsToFunctionCallHandler(actions) {
831
- return (_0) => __async(this, [_0], function* ({ messages, name, args }) {
832
- let actionsByFunctionName = {};
833
- for (let action2 of actions) {
834
- actionsByFunctionName[action2.name] = action2;
835
- }
836
- const action = actionsByFunctionName[name];
837
- let result = void 0;
838
- if (action) {
839
- yield new Promise((resolve, reject) => {
840
- (0, import_react_dom.flushSync)(() => __async(this, null, function* () {
841
- var _a;
842
- try {
843
- result = yield (_a = action.handler) == null ? void 0 : _a.call(action, args);
844
- resolve();
845
- } catch (error) {
846
- reject(error);
847
- }
848
- }));
849
- });
850
- yield new Promise((resolve) => setTimeout(resolve, 20));
851
- }
852
- return result;
853
- });
854
- }
855
- // Annotate the CommonJS export names for ESM import in node:
856
- 0 && (module.exports = {
857
- CopilotKit,
858
- CopilotKitInternal,
859
- defaultCopilotContextCategories
860
- });
861
- //# sourceMappingURL=copilotkit.js.map