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