@copilotkit/react-core 0.11.0-alpha.3 → 0.11.0-alpha.5

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 (38) hide show
  1. package/.turbo/turbo-build.log +83 -43
  2. package/CHANGELOG.md +12 -0
  3. package/dist/components/copilot-provider.js +447 -0
  4. package/dist/components/copilot-provider.js.map +1 -0
  5. package/dist/components/index.js +447 -0
  6. package/dist/components/index.js.map +1 -0
  7. package/dist/context/copilot-context.js +52 -0
  8. package/dist/context/copilot-context.js.map +1 -0
  9. package/dist/context/index.js +52 -0
  10. package/dist/context/index.js.map +1 -0
  11. package/dist/hooks/index.js +205 -0
  12. package/dist/hooks/index.js.map +1 -0
  13. package/dist/hooks/use-copilot-chat.js +156 -0
  14. package/dist/hooks/use-copilot-chat.js.map +1 -0
  15. package/dist/hooks/use-flat-category-store.js +78 -0
  16. package/dist/hooks/use-flat-category-store.js.map +1 -0
  17. package/dist/hooks/use-make-copilot-actionable.js +67 -0
  18. package/dist/hooks/use-make-copilot-actionable.js.map +1 -0
  19. package/dist/hooks/use-make-copilot-document-readable.js +56 -0
  20. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  21. package/dist/hooks/use-make-copilot-readable.js +56 -0
  22. package/dist/hooks/use-make-copilot-readable.js.map +1 -0
  23. package/dist/hooks/use-tree.js +161 -0
  24. package/dist/hooks/use-tree.js.map +1 -0
  25. package/dist/index.js +579 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/types/annotated-function.js +4 -0
  28. package/dist/types/annotated-function.js.map +1 -0
  29. package/dist/types/document-pointer.js +4 -0
  30. package/dist/types/document-pointer.js.map +1 -0
  31. package/dist/types/index.js +4 -0
  32. package/dist/types/index.js.map +1 -0
  33. package/dist/utils/utils.js +4 -0
  34. package/dist/utils/utils.js.map +1 -0
  35. package/dist/utils/utils.test.js +10 -0
  36. package/dist/utils/utils.test.js.map +1 -0
  37. package/package.json +2 -2
  38. package/tsup.config.ts +1 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > @copilotkit/react-core@0.11.0-alpha.2 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core
2
+ > @copilotkit/react-core@0.11.0-alpha.4 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core
3
3
  > tsup --treeshake
4
4
 
5
5
  CLI Building entry: src/index.tsx, src/components/copilot-provider.tsx, src/components/index.ts, src/context/copilot-context.tsx, src/context/index.ts, src/hooks/index.ts, src/hooks/use-copilot-chat.ts, src/hooks/use-flat-category-store.ts, src/hooks/use-make-copilot-actionable.ts, src/hooks/use-make-copilot-document-readable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/types/annotated-function.ts, src/types/document-pointer.ts, src/types/index.ts, src/utils/utils.test.ts, src/utils/utils.ts
@@ -9,6 +9,7 @@ CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/Copi
9
9
  CLI Target: es6
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
+ CJS Build start
12
13
  Generated an empty chunk: "utils".
13
14
  Generated an empty chunk: "annotated-function".
14
15
  Generated an empty chunk: "document-pointer".
@@ -16,69 +17,108 @@ Generated an empty chunk: "chunk-EFZPSZWO".
16
17
  Generated an empty chunk: "chunk-JD7BAH7U".
17
18
  Generated an empty chunk: "chunk-YPSGKPDA".
18
19
  Generated an empty chunk: "chunk-QACD2U6P".
19
- ESM dist/chunk-EFZPSZWO.mjs 76.00 B
20
- ESM dist/context/copilot-context.mjs 194.00 B
20
+ Generated an empty chunk: "annotated-function".
21
+ Generated an empty chunk: "document-pointer".
22
+ Generated an empty chunk: "index".
23
+ Generated an empty chunk: "utils".
24
+ DTS Build start
25
+ CJS dist/utils/utils.test.js 216.00 B
26
+ CJS dist/index.js 17.45 KB
27
+ CJS dist/components/copilot-provider.js 12.84 KB
28
+ CJS dist/components/index.js 12.83 KB
29
+ CJS dist/context/copilot-context.js 1.33 KB
30
+ CJS dist/types/document-pointer.js 91.00 B
31
+ CJS dist/hooks/index.js 6.86 KB
32
+ CJS dist/hooks/use-copilot-chat.js 5.11 KB
33
+ CJS dist/context/index.js 1.33 KB
34
+ CJS dist/hooks/use-flat-category-store.js 1.95 KB
35
+ CJS dist/hooks/use-make-copilot-document-readable.js 1.64 KB
36
+ CJS dist/utils/utils.js 80.00 B
37
+ CJS dist/types/annotated-function.js 93.00 B
38
+ CJS dist/hooks/use-tree.js 4.73 KB
39
+ CJS dist/hooks/use-make-copilot-actionable.js 1.91 KB
40
+ CJS dist/hooks/use-make-copilot-readable.js 1.57 KB
41
+ CJS dist/types/index.js 80.00 B
42
+ CJS dist/utils/utils.test.js.map 351.00 B
43
+ CJS dist/components/copilot-provider.js.map 26.23 KB
44
+ CJS dist/index.js.map 35.65 KB
45
+ CJS dist/types/document-pointer.js.map 51.00 B
46
+ CJS dist/context/index.js.map 4.24 KB
47
+ CJS dist/context/copilot-context.js.map 4.24 KB
48
+ CJS dist/components/index.js.map 26.23 KB
49
+ CJS dist/hooks/use-flat-category-store.js.map 4.31 KB
50
+ CJS dist/hooks/index.js.map 13.60 KB
51
+ CJS dist/utils/utils.js.map 51.00 B
52
+ CJS dist/hooks/use-copilot-chat.js.map 8.90 KB
53
+ CJS dist/hooks/use-tree.js.map 8.41 KB
54
+ CJS dist/hooks/use-make-copilot-document-readable.js.map 5.68 KB
55
+ CJS dist/hooks/use-make-copilot-readable.js.map 5.54 KB
56
+ CJS dist/hooks/use-make-copilot-actionable.js.map 5.77 KB
57
+ CJS dist/types/annotated-function.js.map 51.00 B
58
+ CJS dist/types/index.js.map 51.00 B
59
+ CJS ⚡️ Build success in 199ms
60
+ ESM dist/chunk-JD7BAH7U.mjs 76.00 B
61
+ ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
62
+ ESM dist/components/copilot-provider.mjs 262.00 B
21
63
  ESM dist/types/index.mjs 98.00 B
22
- ESM dist/components/index.mjs 283.00 B
23
- ESM dist/chunk-YPSGKPDA.mjs 76.00 B
64
+ ESM dist/context/index.mjs 216.00 B
65
+ ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
24
66
  ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
25
- ESM dist/chunk-3EE3HCUI.mjs 4.80 KB
67
+ ESM dist/hooks/use-tree.mjs 170.00 B
26
68
  ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
27
- ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
69
+ ESM dist/chunk-3EE3HCUI.mjs 4.80 KB
70
+ ESM dist/chunk-YPSGKPDA.mjs 76.00 B
28
71
  ESM dist/chunk-3BOHSSKR.mjs 3.95 KB
29
- ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
72
+ ESM dist/components/index.mjs 283.00 B
73
+ ESM dist/hooks/index.mjs 420.00 B
74
+ ESM dist/index.mjs 678.00 B
75
+ ESM dist/chunk-PRQLPFIA.mjs 972.00 B
30
76
  ESM dist/chunk-TNU2L6FJ.mjs 626.00 B
31
- ESM dist/chunk-IMNFO2OZ.mjs 689.00 B
77
+ ESM dist/chunk-EFZPSZWO.mjs 76.00 B
32
78
  ESM dist/hooks/use-copilot-chat.mjs 219.00 B
33
- ESM dist/chunk-JD7BAH7U.mjs 76.00 B
34
- ESM dist/chunk-PRQLPFIA.mjs 972.00 B
35
- ESM dist/chunk-63ILXW5V.mjs 1.92 KB
36
- ESM dist/chunk-X3CGMLW5.mjs 1.30 KB
37
- ESM dist/index.mjs 678.00 B
38
- ESM dist/context/index.mjs 216.00 B
39
- ESM dist/components/copilot-provider.mjs 262.00 B
40
- ESM dist/hooks/use-flat-category-store.mjs 200.00 B
41
79
  ESM dist/chunk-QACD2U6P.mjs 76.00 B
42
- ESM dist/hooks/use-tree.mjs 170.00 B
80
+ ESM dist/chunk-IMNFO2OZ.mjs 689.00 B
81
+ ESM dist/context/copilot-context.mjs 194.00 B
82
+ ESM dist/chunk-63ILXW5V.mjs 1.92 KB
43
83
  ESM dist/chunk-ATMIAPXE.mjs 2.85 KB
44
- ESM dist/hooks/index.mjs 420.00 B
84
+ ESM dist/hooks/use-flat-category-store.mjs 200.00 B
85
+ ESM dist/chunk-X3CGMLW5.mjs 1.30 KB
45
86
  ESM dist/utils/utils.mjs 67.00 B
46
- ESM dist/types/document-pointer.mjs 78.00 B
47
87
  ESM dist/types/annotated-function.mjs 80.00 B
48
88
  ESM dist/utils/utils.test.mjs 202.00 B
49
- ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
50
- ESM dist/context/copilot-context.mjs.map 51.00 B
89
+ ESM dist/types/document-pointer.mjs 78.00 B
90
+ ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
91
+ ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
51
92
  ESM dist/types/index.mjs.map 51.00 B
52
- ESM dist/chunk-YPSGKPDA.mjs.map 51.00 B
53
- ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
54
- ESM dist/components/index.mjs.map 51.00 B
93
+ ESM dist/components/copilot-provider.mjs.map 51.00 B
94
+ ESM dist/context/index.mjs.map 51.00 B
55
95
  ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
96
+ ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
56
97
  ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
98
+ ESM dist/hooks/use-tree.mjs.map 51.00 B
99
+ ESM dist/hooks/index.mjs.map 51.00 B
57
100
  ESM dist/chunk-3BOHSSKR.mjs.map 8.39 KB
58
- ESM dist/chunk-TNU2L6FJ.mjs.map 1.47 KB
59
- ESM dist/chunk-IMNFO2OZ.mjs.map 1.61 KB
60
- ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
61
- ESM dist/index.mjs.map 51.00 B
62
- ESM dist/chunk-X3CGMLW5.mjs.map 4.22 KB
63
- ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
64
- ESM dist/chunk-63ILXW5V.mjs.map 4.31 KB
65
- ESM dist/context/index.mjs.map 51.00 B
101
+ ESM dist/chunk-YPSGKPDA.mjs.map 51.00 B
66
102
  ESM dist/chunk-3EE3HCUI.mjs.map 9.48 KB
103
+ ESM dist/index.mjs.map 51.00 B
67
104
  ESM dist/chunk-PRQLPFIA.mjs.map 1.70 KB
105
+ ESM dist/components/index.mjs.map 51.00 B
68
106
  ESM dist/chunk-QACD2U6P.mjs.map 51.00 B
69
- ESM dist/hooks/use-tree.mjs.map 51.00 B
70
- ESM dist/components/copilot-provider.mjs.map 51.00 B
71
- ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
72
- ESM dist/hooks/index.mjs.map 51.00 B
107
+ ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
108
+ ESM dist/chunk-TNU2L6FJ.mjs.map 1.47 KB
109
+ ESM dist/context/copilot-context.mjs.map 51.00 B
110
+ ESM dist/chunk-IMNFO2OZ.mjs.map 1.61 KB
111
+ ESM dist/chunk-63ILXW5V.mjs.map 4.31 KB
73
112
  ESM dist/chunk-ATMIAPXE.mjs.map 4.70 KB
74
- ESM dist/utils/utils.mjs.map 51.00 B
113
+ ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
114
+ ESM dist/chunk-X3CGMLW5.mjs.map 4.22 KB
75
115
  ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B
76
- ESM dist/types/document-pointer.mjs.map 51.00 B
77
- ESM dist/utils/utils.test.mjs.map 351.00 B
116
+ ESM dist/utils/utils.mjs.map 51.00 B
78
117
  ESM dist/types/annotated-function.mjs.map 51.00 B
79
- ESM ⚡️ Build success in 109ms
80
- DTS Build start
81
- DTS ⚡️ Build success in 964ms
118
+ ESM dist/utils/utils.test.mjs.map 351.00 B
119
+ ESM dist/types/document-pointer.mjs.map 51.00 B
120
+ ESM ⚡️ Build success in 200ms
121
+ DTS ⚡️ Build success in 636ms
82
122
  DTS dist/index.d.ts 814.00 B
83
123
  DTS dist/components/copilot-provider.d.ts 288.00 B
84
124
  DTS dist/context/copilot-context.d.ts 2.03 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # ui
2
2
 
3
+ ## 0.11.0-alpha.5
4
+
5
+ ### Minor Changes
6
+
7
+ - commonJS
8
+
9
+ ## 0.11.0-alpha.4
10
+
11
+ ### Minor Changes
12
+
13
+ - esm.js maybe
14
+
3
15
  ## 0.11.0-alpha.3
4
16
 
5
17
  ### Minor Changes
@@ -0,0 +1,447 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var nanoid = require('nanoid');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __defProps = Object.defineProperties;
9
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
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 __async = (__this, __arguments, generator) => {
39
+ return new Promise((resolve, reject) => {
40
+ var fulfilled = (value) => {
41
+ try {
42
+ step(generator.next(value));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ };
47
+ var rejected = (value) => {
48
+ try {
49
+ step(generator.throw(value));
50
+ } catch (e) {
51
+ reject(e);
52
+ }
53
+ };
54
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
55
+ step((generator = generator.apply(__this, __arguments)).next());
56
+ });
57
+ };
58
+ var emptyCopilotContext = {
59
+ entryPoints: {},
60
+ setEntryPoint: () => {
61
+ },
62
+ removeEntryPoint: () => {
63
+ },
64
+ getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
65
+ getFunctionCallHandler: () => returnAndThrowInDebug(),
66
+ getContextString: (documents) => returnAndThrowInDebug(),
67
+ addContext: () => "",
68
+ removeContext: () => {
69
+ },
70
+ getDocumentsContext: () => returnAndThrowInDebug(),
71
+ addDocumentContext: () => returnAndThrowInDebug(),
72
+ removeDocumentContext: () => {
73
+ },
74
+ copilotApiConfig: new class {
75
+ get chatApiEndpoint() {
76
+ throw new Error(
77
+ "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
78
+ );
79
+ }
80
+ get headers() {
81
+ return {};
82
+ }
83
+ get body() {
84
+ return {};
85
+ }
86
+ }()
87
+ };
88
+ var CopilotContext = React.createContext(emptyCopilotContext);
89
+ function returnAndThrowInDebug(value) {
90
+ throw new Error(
91
+ "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
92
+ );
93
+ }
94
+ var removeNode = (nodes, id) => {
95
+ return nodes.reduce((result, node) => {
96
+ if (node.id !== id) {
97
+ const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
98
+ result.push(newNode);
99
+ }
100
+ return result;
101
+ }, []);
102
+ };
103
+ var addNode = (nodes, newNode, parentId) => {
104
+ if (!parentId) {
105
+ return [...nodes, newNode];
106
+ }
107
+ return nodes.map((node) => {
108
+ if (node.id === parentId) {
109
+ return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
110
+ } else if (node.children.length) {
111
+ return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
112
+ }
113
+ return node;
114
+ });
115
+ };
116
+ var treeIndentationRepresentation = (index, indentLevel) => {
117
+ if (indentLevel === 0) {
118
+ return (index + 1).toString();
119
+ } else if (indentLevel === 1) {
120
+ return String.fromCharCode(65 + index);
121
+ } else if (indentLevel === 2) {
122
+ return String.fromCharCode(97 + index);
123
+ } else {
124
+ return "-";
125
+ }
126
+ };
127
+ var printNode = (node, prefix = "", indentLevel = 0) => {
128
+ const indent = " ".repeat(3).repeat(indentLevel);
129
+ const prefixPlusIndentLength = prefix.length + indent.length;
130
+ const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
131
+ const valueLines = node.value.split("\n");
132
+ const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
133
+ const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
134
+ let output = `${outputFirstLine}
135
+ `;
136
+ if (outputSubsequentLines) {
137
+ output += `${outputSubsequentLines}
138
+ `;
139
+ }
140
+ const childPrePrefix = " ".repeat(prefix.length);
141
+ node.children.forEach(
142
+ (child, index) => output += printNode(
143
+ child,
144
+ `${childPrePrefix}${treeIndentationRepresentation(
145
+ index,
146
+ indentLevel + 1
147
+ )}. `,
148
+ indentLevel + 1
149
+ )
150
+ );
151
+ return output;
152
+ };
153
+ function treeReducer(state, action) {
154
+ switch (action.type) {
155
+ case "ADD_NODE": {
156
+ const { value, parentId, id: newNodeId } = action;
157
+ const newNode = {
158
+ id: newNodeId,
159
+ value,
160
+ children: [],
161
+ categories: new Set(action.categories)
162
+ };
163
+ try {
164
+ return addNode(state, newNode, parentId);
165
+ } catch (error) {
166
+ console.error(`Error while adding node with id ${newNodeId}: ${error}`);
167
+ return state;
168
+ }
169
+ }
170
+ case "REMOVE_NODE":
171
+ return removeNode(state, action.id);
172
+ default:
173
+ return state;
174
+ }
175
+ }
176
+ var useTree = () => {
177
+ const [tree, dispatch] = React.useReducer(treeReducer, []);
178
+ const addElement = React.useCallback(
179
+ (value, categories, parentId) => {
180
+ const newNodeId = nanoid.nanoid();
181
+ dispatch({
182
+ type: "ADD_NODE",
183
+ value,
184
+ parentId,
185
+ id: newNodeId,
186
+ categories
187
+ });
188
+ return newNodeId;
189
+ },
190
+ []
191
+ );
192
+ const removeElement = React.useCallback((id) => {
193
+ dispatch({ type: "REMOVE_NODE", id });
194
+ }, []);
195
+ const printTree = React.useCallback(
196
+ (categories) => {
197
+ const categoriesSet = new Set(categories);
198
+ let output = "";
199
+ tree.forEach((node, index) => {
200
+ if (!setsHaveIntersection(categoriesSet, node.categories)) {
201
+ return;
202
+ }
203
+ if (index !== 0) {
204
+ output += "\n";
205
+ }
206
+ output += printNode(
207
+ node,
208
+ `${treeIndentationRepresentation(index, 0)}. `
209
+ );
210
+ });
211
+ return output;
212
+ },
213
+ [tree]
214
+ );
215
+ return { tree, addElement, printTree, removeElement };
216
+ };
217
+ var use_tree_default = useTree;
218
+ function setsHaveIntersection(setA, setB) {
219
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
220
+ for (let item of smallerSet) {
221
+ if (largerSet.has(item)) {
222
+ return true;
223
+ }
224
+ }
225
+ return false;
226
+ }
227
+ var useFlatCategoryStore = () => {
228
+ const [elements, dispatch] = React.useReducer(
229
+ flatCategoryStoreReducer,
230
+ /* @__PURE__ */ new Map()
231
+ );
232
+ const addElement = React.useCallback(
233
+ (value, categories) => {
234
+ const newId = nanoid.nanoid();
235
+ dispatch({
236
+ type: "ADD_ELEMENT",
237
+ value,
238
+ id: newId,
239
+ categories
240
+ });
241
+ return newId;
242
+ },
243
+ []
244
+ );
245
+ const removeElement = React.useCallback((id) => {
246
+ dispatch({ type: "REMOVE_ELEMENT", id });
247
+ }, []);
248
+ const allElements = React.useCallback(
249
+ (categories) => {
250
+ const categoriesSet = new Set(categories);
251
+ const result = [];
252
+ elements.forEach((element) => {
253
+ if (setsHaveIntersection2(categoriesSet, element.categories)) {
254
+ result.push(element.value);
255
+ }
256
+ });
257
+ return result;
258
+ },
259
+ [elements]
260
+ );
261
+ return { addElement, removeElement, allElements };
262
+ };
263
+ var use_flat_category_store_default = useFlatCategoryStore;
264
+ function flatCategoryStoreReducer(state, action) {
265
+ switch (action.type) {
266
+ case "ADD_ELEMENT": {
267
+ const { value, id, categories } = action;
268
+ const newElement = {
269
+ id,
270
+ value,
271
+ categories: new Set(categories)
272
+ };
273
+ const newState = new Map(state);
274
+ newState.set(id, newElement);
275
+ return newState;
276
+ }
277
+ case "REMOVE_ELEMENT": {
278
+ const newState = new Map(state);
279
+ newState.delete(action.id);
280
+ return newState;
281
+ }
282
+ default:
283
+ return state;
284
+ }
285
+ }
286
+ function setsHaveIntersection2(setA, setB) {
287
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
288
+ for (let item of smallerSet) {
289
+ if (largerSet.has(item)) {
290
+ return true;
291
+ }
292
+ }
293
+ return false;
294
+ }
295
+ function CopilotProvider({
296
+ chatApiEndpoint,
297
+ headers,
298
+ body,
299
+ children
300
+ }) {
301
+ const [entryPoints, setEntryPoints] = React.useState({});
302
+ const { addElement, removeElement, printTree } = use_tree_default();
303
+ const {
304
+ addElement: addDocument,
305
+ removeElement: removeDocument,
306
+ allElements: allDocuments
307
+ } = use_flat_category_store_default();
308
+ const setEntryPoint = React.useCallback(
309
+ (id, entryPoint) => {
310
+ setEntryPoints((prevPoints) => {
311
+ return __spreadProps(__spreadValues({}, prevPoints), {
312
+ [id]: entryPoint
313
+ });
314
+ });
315
+ },
316
+ []
317
+ );
318
+ const removeEntryPoint = React.useCallback((id) => {
319
+ setEntryPoints((prevPoints) => {
320
+ const newPoints = __spreadValues({}, prevPoints);
321
+ delete newPoints[id];
322
+ return newPoints;
323
+ });
324
+ }, []);
325
+ const getContextString = React.useCallback(
326
+ (documents, categories = ["global"]) => {
327
+ const documentsString = documents.map((document) => {
328
+ return `${document.name} (${document.sourceApplication}):
329
+ ${document.getContents()}`;
330
+ }).join("\n\n");
331
+ const nonDocumentStrings = printTree(categories);
332
+ return `${documentsString}
333
+
334
+ ${nonDocumentStrings}`;
335
+ },
336
+ [printTree]
337
+ );
338
+ const addContext = React.useCallback(
339
+ (context, parentId, categories = ["global"]) => {
340
+ return addElement(context, categories, parentId);
341
+ },
342
+ [addElement]
343
+ );
344
+ const removeContext = React.useCallback(
345
+ (id) => {
346
+ removeElement(id);
347
+ },
348
+ [removeElement]
349
+ );
350
+ const getChatCompletionFunctionDescriptions = React.useCallback(() => {
351
+ return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
352
+ }, [entryPoints]);
353
+ const getFunctionCallHandler = React.useCallback(() => {
354
+ return entryPointsToFunctionCallHandler(Object.values(entryPoints));
355
+ }, [entryPoints]);
356
+ const getDocumentsContext = React.useCallback(
357
+ (categories = ["global"]) => {
358
+ return allDocuments(categories);
359
+ },
360
+ [allDocuments]
361
+ );
362
+ const addDocumentContext = React.useCallback(
363
+ (documentPointer, categories = ["global"]) => {
364
+ return addDocument(documentPointer, categories);
365
+ },
366
+ [addDocument]
367
+ );
368
+ const removeDocumentContext = React.useCallback(
369
+ (documentId) => {
370
+ removeDocument(documentId);
371
+ },
372
+ [removeDocument]
373
+ );
374
+ return /* @__PURE__ */ jsxRuntime.jsx(CopilotContext.Provider, {
375
+ value: {
376
+ entryPoints,
377
+ getChatCompletionFunctionDescriptions,
378
+ getFunctionCallHandler,
379
+ setEntryPoint,
380
+ removeEntryPoint,
381
+ getContextString,
382
+ addContext,
383
+ removeContext,
384
+ getDocumentsContext,
385
+ addDocumentContext,
386
+ removeDocumentContext,
387
+ copilotApiConfig: {
388
+ chatApiEndpoint,
389
+ headers: headers || {},
390
+ body: body || {}
391
+ }
392
+ },
393
+ children
394
+ });
395
+ }
396
+ function entryPointsToFunctionCallHandler(entryPoints) {
397
+ return (chatMessages, functionCall) => __async(this, null, function* () {
398
+ let entrypointsByFunctionName = {};
399
+ for (let entryPoint of entryPoints) {
400
+ entrypointsByFunctionName[entryPoint.name] = entryPoint;
401
+ }
402
+ const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
403
+ if (entryPointFunction) {
404
+ let parsedFunctionCallArguments = [];
405
+ if (functionCall.arguments) {
406
+ parsedFunctionCallArguments = JSON.parse(functionCall.arguments);
407
+ }
408
+ const paramsInCorrectOrder = [];
409
+ for (let arg of entryPointFunction.argumentAnnotations) {
410
+ paramsInCorrectOrder.push(
411
+ parsedFunctionCallArguments[arg.name]
412
+ );
413
+ }
414
+ yield entryPointFunction.implementation(...paramsInCorrectOrder);
415
+ }
416
+ });
417
+ }
418
+ function entryPointsToChatCompletionFunctions(entryPoints) {
419
+ return entryPoints.map(annotatedFunctionToChatCompletionFunction);
420
+ }
421
+ function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
422
+ let parameters = {};
423
+ for (let arg of annotatedFunction.argumentAnnotations) {
424
+ let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]);
425
+ parameters[arg.name] = forwardedArgs;
426
+ }
427
+ let requiredParameterNames = [];
428
+ for (let arg of annotatedFunction.argumentAnnotations) {
429
+ if (arg.required) {
430
+ requiredParameterNames.push(arg.name);
431
+ }
432
+ }
433
+ let chatCompletionFunction = {
434
+ name: annotatedFunction.name,
435
+ description: annotatedFunction.description,
436
+ parameters: {
437
+ type: "object",
438
+ properties: parameters,
439
+ required: requiredParameterNames
440
+ }
441
+ };
442
+ return chatCompletionFunction;
443
+ }
444
+
445
+ exports.CopilotProvider = CopilotProvider;
446
+ //# sourceMappingURL=out.js.map
447
+ //# sourceMappingURL=copilot-provider.js.map