@copilotkit/react-core 0.8.0-alpha.6 → 0.8.0

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 (63) hide show
  1. package/.turbo/turbo-build.log +88 -88
  2. package/CHANGELOG.md +16 -0
  3. package/dist/chunk-3BOHSSKR.mjs +141 -0
  4. package/dist/chunk-3BOHSSKR.mjs.map +1 -0
  5. package/dist/chunk-3O374DDN.mjs +19 -0
  6. package/dist/chunk-3O374DDN.mjs.map +1 -0
  7. package/dist/chunk-63ILXW5V.mjs +76 -0
  8. package/dist/chunk-63ILXW5V.mjs.map +1 -0
  9. package/dist/chunk-6RRG7ME3.mjs +19 -0
  10. package/dist/chunk-6RRG7ME3.mjs.map +1 -0
  11. package/dist/chunk-EFZPSZWO.mjs +3 -0
  12. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  13. package/dist/chunk-JD7BAH7U.mjs +3 -0
  14. package/dist/chunk-JD7BAH7U.mjs.map +1 -0
  15. package/dist/chunk-K7TVQCXG.mjs +44 -0
  16. package/dist/chunk-K7TVQCXG.mjs.map +1 -0
  17. package/dist/chunk-MRXNTQOX.mjs +55 -0
  18. package/dist/chunk-MRXNTQOX.mjs.map +1 -0
  19. package/dist/chunk-QACD2U6P.mjs +3 -0
  20. package/dist/chunk-QACD2U6P.mjs.map +1 -0
  21. package/dist/chunk-QFCPUIF7.mjs +147 -0
  22. package/dist/chunk-QFCPUIF7.mjs.map +1 -0
  23. package/dist/chunk-UNFDVVCF.mjs +80 -0
  24. package/dist/chunk-UNFDVVCF.mjs.map +1 -0
  25. package/dist/chunk-YPSGKPDA.mjs +3 -0
  26. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  27. package/dist/chunk-YTIZQV7H.mjs +30 -0
  28. package/dist/chunk-YTIZQV7H.mjs.map +1 -0
  29. package/dist/components/copilot-provider.mjs +6 -442
  30. package/dist/components/copilot-provider.mjs.map +1 -1
  31. package/dist/components/index.mjs +7 -442
  32. package/dist/components/index.mjs.map +1 -1
  33. package/dist/context/copilot-context.mjs +3 -67
  34. package/dist/context/copilot-context.mjs.map +1 -1
  35. package/dist/context/index.mjs +4 -67
  36. package/dist/context/index.mjs.map +1 -1
  37. package/dist/hooks/index.mjs +8 -220
  38. package/dist/hooks/index.mjs.map +1 -1
  39. package/dist/hooks/use-copilot-chat.mjs +4 -159
  40. package/dist/hooks/use-copilot-chat.mjs.map +1 -1
  41. package/dist/hooks/use-flat-category-store.mjs +3 -74
  42. package/dist/hooks/use-flat-category-store.mjs.map +1 -1
  43. package/dist/hooks/use-make-copilot-actionable.mjs +4 -88
  44. package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
  45. package/dist/hooks/use-make-copilot-document-readable.mjs +4 -77
  46. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
  47. package/dist/hooks/use-make-copilot-readable.mjs +4 -77
  48. package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
  49. package/dist/hooks/use-tree.mjs +3 -159
  50. package/dist/hooks/use-tree.mjs.map +1 -1
  51. package/dist/index.mjs +14 -589
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/types/annotated-function.mjs +2 -0
  54. package/dist/types/annotated-function.mjs.map +1 -1
  55. package/dist/types/document-pointer.mjs +2 -0
  56. package/dist/types/document-pointer.mjs.map +1 -1
  57. package/dist/types/index.mjs +2 -0
  58. package/dist/types/index.mjs.map +1 -1
  59. package/dist/utils/utils.mjs +2 -0
  60. package/dist/utils/utils.mjs.map +1 -1
  61. package/dist/utils/utils.test.mjs +1 -0
  62. package/dist/utils/utils.test.mjs.map +1 -1
  63. package/package.json +2 -2
@@ -1,14 +1,14 @@
1
1
 
2
- > @copilotkit/react-core@0.8.0-alpha.5 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core
2
+ > @copilotkit/react-core@0.8.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
3
3
  > tsup --treeshake
4
4
 
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
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.5.0
8
- CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core/tsup.config.ts
9
- CLI Target: es6
10
- CLI Cleaning output folder
11
- ESM Build start
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
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v6.5.0
8
+ CLI Using tsup config: /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core/tsup.config.ts
9
+ CLI Target: es6
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
12
  Generated an empty chunk: "utils".
13
13
  Generated an empty chunk: "annotated-function".
14
14
  Generated an empty chunk: "document-pointer".
@@ -16,83 +16,83 @@ Generated an empty chunk: "chunk-EFZPSZWO".
16
16
  Generated an empty chunk: "chunk-JD7BAH7U".
17
17
  Generated an empty chunk: "chunk-YPSGKPDA".
18
18
  Generated an empty chunk: "chunk-QACD2U6P".
19
- ESM dist/types/annotated-function.mjs 80.00 B
20
- ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
21
- ESM dist/utils/utils.test.mjs 202.00 B
22
- ESM dist/types/document-pointer.mjs 78.00 B
23
- ESM dist/chunk-EFZPSZWO.mjs 76.00 B
24
- ESM dist/chunk-JD7BAH7U.mjs 76.00 B
25
- ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
26
- ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
27
- ESM dist/hooks/use-tree.mjs 170.00 B
28
- ESM dist/chunk-QACD2U6P.mjs 76.00 B
29
- ESM dist/components/index.mjs 283.00 B
30
- ESM dist/chunk-3BOHSSKR.mjs 3.95 KB
31
- ESM dist/components/copilot-provider.mjs 262.00 B
32
- ESM dist/context/copilot-context.mjs 194.00 B
33
- ESM dist/hooks/index.mjs 420.00 B
34
- ESM dist/context/index.mjs 216.00 B
35
- ESM dist/chunk-QFCPUIF7.mjs 4.43 KB
36
- ESM dist/chunk-K7TVQCXG.mjs 1.21 KB
37
- ESM dist/chunk-UNFDVVCF.mjs 2.62 KB
38
- ESM dist/hooks/use-flat-category-store.mjs 200.00 B
39
- ESM dist/chunk-63ILXW5V.mjs 1.92 KB
40
- ESM dist/utils/utils.mjs 67.00 B
41
- ESM dist/chunk-6RRG7ME3.mjs 663.00 B
42
- ESM dist/hooks/use-copilot-chat.mjs 219.00 B
43
- ESM dist/index.mjs 678.00 B
44
- ESM dist/chunk-3O374DDN.mjs 626.00 B
45
- ESM dist/chunk-YTIZQV7H.mjs 972.00 B
46
- ESM dist/types/index.mjs 98.00 B
47
- ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
48
- ESM dist/chunk-YPSGKPDA.mjs 76.00 B
49
- ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
50
- ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
51
- ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
52
- ESM dist/utils/utils.test.mjs.map 351.00 B
53
- ESM dist/chunk-QACD2U6P.mjs.map 51.00 B
54
- ESM dist/hooks/use-tree.mjs.map 51.00 B
55
- ESM dist/components/index.mjs.map 51.00 B
56
- ESM dist/chunk-3BOHSSKR.mjs.map 8.39 KB
57
- ESM dist/components/copilot-provider.mjs.map 51.00 B
58
- ESM dist/context/index.mjs.map 51.00 B
59
- ESM dist/context/copilot-context.mjs.map 51.00 B
60
- ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
61
- ESM dist/hooks/index.mjs.map 51.00 B
62
- ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B
63
- ESM dist/types/document-pointer.mjs.map 51.00 B
64
- ESM dist/chunk-QFCPUIF7.mjs.map 8.70 KB
65
- ESM dist/chunk-K7TVQCXG.mjs.map 3.38 KB
66
- ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
67
- ESM dist/utils/utils.mjs.map 51.00 B
68
- ESM dist/chunk-6RRG7ME3.mjs.map 1.56 KB
69
- ESM dist/chunk-3O374DDN.mjs.map 1.47 KB
70
- ESM dist/index.mjs.map 51.00 B
71
- ESM dist/chunk-63ILXW5V.mjs.map 4.31 KB
72
- ESM dist/chunk-UNFDVVCF.mjs.map 4.48 KB
73
- ESM dist/types/index.mjs.map 51.00 B
74
- ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
75
- ESM dist/chunk-YTIZQV7H.mjs.map 1.70 KB
76
- ESM dist/types/annotated-function.mjs.map 51.00 B
77
- ESM dist/chunk-YPSGKPDA.mjs.map 51.00 B
78
- ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
79
- ESM ⚡️ Build success in 99ms
80
- DTS Build start
81
- DTS ⚡️ Build success in 687ms
82
- DTS dist/index.d.ts 814.00 B
83
- DTS dist/components/copilot-provider.d.ts 437.00 B
84
- DTS dist/context/copilot-context.d.ts 1.45 KB
85
- DTS dist/hooks/use-copilot-chat.d.ts 890.00 B
86
- DTS dist/hooks/use-make-copilot-actionable.d.ts 255.00 B
87
- DTS dist/hooks/use-make-copilot-readable.d.ts 598.00 B
88
- DTS dist/hooks/use-make-copilot-document-readable.d.ts 666.00 B
89
- DTS dist/types/annotated-function.d.ts 767.00 B
90
- DTS dist/types/document-pointer.d.ts 190.00 B
91
- DTS dist/hooks/use-tree.d.ts 543.00 B
92
- DTS dist/components/index.d.ts 269.00 B
93
- DTS dist/context/index.d.ts 297.00 B
94
- DTS dist/hooks/index.d.ts 434.00 B
95
- DTS dist/hooks/use-flat-category-store.d.ts 424.00 B
96
- DTS dist/types/index.d.ts 145.00 B
97
- DTS dist/utils/utils.test.d.ts 1.00 B
98
- DTS dist/utils/utils.d.ts 1.00 B
19
+ ESM dist/chunk-EFZPSZWO.mjs 76.00 B
20
+ ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
21
+ ESM dist/types/index.mjs 98.00 B
22
+ ESM dist/components/copilot-provider.mjs 262.00 B
23
+ ESM dist/context/copilot-context.mjs 194.00 B
24
+ ESM dist/chunk-JD7BAH7U.mjs 76.00 B
25
+ ESM dist/chunk-YPSGKPDA.mjs 76.00 B
26
+ ESM dist/chunk-QACD2U6P.mjs 76.00 B
27
+ ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
28
+ ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
29
+ ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
30
+ ESM dist/hooks/use-tree.mjs 170.00 B
31
+ ESM dist/index.mjs 678.00 B
32
+ ESM dist/components/index.mjs 283.00 B
33
+ ESM dist/chunk-QFCPUIF7.mjs 4.43 KB
34
+ ESM dist/chunk-3BOHSSKR.mjs 3.95 KB
35
+ ESM dist/context/index.mjs 216.00 B
36
+ ESM dist/hooks/index.mjs 420.00 B
37
+ ESM dist/chunk-YTIZQV7H.mjs 972.00 B
38
+ ESM dist/chunk-6RRG7ME3.mjs 663.00 B
39
+ ESM dist/chunk-3O374DDN.mjs 626.00 B
40
+ ESM dist/hooks/use-copilot-chat.mjs 219.00 B
41
+ ESM dist/chunk-UNFDVVCF.mjs 2.62 KB
42
+ ESM dist/chunk-K7TVQCXG.mjs 1.21 KB
43
+ ESM dist/hooks/use-flat-category-store.mjs 200.00 B
44
+ ESM dist/chunk-63ILXW5V.mjs 1.92 KB
45
+ ESM dist/utils/utils.mjs 67.00 B
46
+ ESM dist/types/annotated-function.mjs 80.00 B
47
+ ESM dist/types/document-pointer.mjs 78.00 B
48
+ ESM dist/utils/utils.test.mjs 202.00 B
49
+ ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
50
+ ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
51
+ ESM dist/types/index.mjs.map 51.00 B
52
+ ESM dist/components/copilot-provider.mjs.map 51.00 B
53
+ ESM dist/context/copilot-context.mjs.map 51.00 B
54
+ ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
55
+ ESM dist/chunk-YPSGKPDA.mjs.map 51.00 B
56
+ ESM dist/chunk-QACD2U6P.mjs.map 51.00 B
57
+ ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
58
+ ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
59
+ ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
60
+ ESM dist/hooks/use-tree.mjs.map 51.00 B
61
+ ESM dist/index.mjs.map 51.00 B
62
+ ESM dist/components/index.mjs.map 51.00 B
63
+ ESM dist/chunk-QFCPUIF7.mjs.map 8.70 KB
64
+ ESM dist/chunk-3BOHSSKR.mjs.map 8.39 KB
65
+ ESM dist/context/index.mjs.map 51.00 B
66
+ ESM dist/hooks/index.mjs.map 51.00 B
67
+ ESM dist/chunk-YTIZQV7H.mjs.map 1.70 KB
68
+ ESM dist/chunk-6RRG7ME3.mjs.map 1.56 KB
69
+ ESM dist/chunk-3O374DDN.mjs.map 1.47 KB
70
+ ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
71
+ ESM dist/chunk-UNFDVVCF.mjs.map 4.48 KB
72
+ ESM dist/chunk-K7TVQCXG.mjs.map 3.38 KB
73
+ ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B
74
+ ESM dist/chunk-63ILXW5V.mjs.map 4.31 KB
75
+ ESM dist/utils/utils.mjs.map 51.00 B
76
+ ESM dist/types/annotated-function.mjs.map 51.00 B
77
+ ESM dist/types/document-pointer.mjs.map 51.00 B
78
+ ESM dist/utils/utils.test.mjs.map 351.00 B
79
+ ESM ⚡️ Build success in 465ms
80
+ DTS Build start
81
+ DTS ⚡️ Build success in 2261ms
82
+ DTS dist/index.d.ts 814.00 B
83
+ DTS dist/components/copilot-provider.d.ts 437.00 B
84
+ DTS dist/context/copilot-context.d.ts 1.45 KB
85
+ DTS dist/hooks/use-copilot-chat.d.ts 890.00 B
86
+ DTS dist/hooks/use-make-copilot-actionable.d.ts 255.00 B
87
+ DTS dist/hooks/use-make-copilot-readable.d.ts 598.00 B
88
+ DTS dist/hooks/use-make-copilot-document-readable.d.ts 666.00 B
89
+ DTS dist/types/annotated-function.d.ts 767.00 B
90
+ DTS dist/types/document-pointer.d.ts 190.00 B
91
+ DTS dist/hooks/use-tree.d.ts 543.00 B
92
+ DTS dist/components/index.d.ts 269.00 B
93
+ DTS dist/context/index.d.ts 297.00 B
94
+ DTS dist/hooks/index.d.ts 434.00 B
95
+ DTS dist/hooks/use-flat-category-store.d.ts 424.00 B
96
+ DTS dist/types/index.d.ts 145.00 B
97
+ DTS dist/utils/utils.test.d.ts 1.00 B
98
+ DTS dist/utils/utils.d.ts 1.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # ui
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1b330b5: out of beta: centralized api, textarea insertions/edits
8
+ - e4ce3ab: textarea edits mvp
9
+ - 9e201c5: textarea insertions deletions etc
10
+ - c13ffcb: minor bugfix
11
+ - e4fe6a5: copilot textarea documents - provide with code skeleton
12
+ - 8e9f9b1: api endpoint centralization
13
+
14
+ ### Patch Changes
15
+
16
+ - 12407db: rebase master
17
+ - 939454e: prettify
18
+
3
19
  ## 0.8.0-alpha.6
4
20
 
5
21
  ### Minor Changes
@@ -0,0 +1,141 @@
1
+ import { __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
2
+ import { nanoid } from 'nanoid';
3
+ import { useReducer, useCallback } from 'react';
4
+
5
+ var removeNode = (nodes, id) => {
6
+ return nodes.reduce((result, node) => {
7
+ if (node.id !== id) {
8
+ const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
9
+ result.push(newNode);
10
+ }
11
+ return result;
12
+ }, []);
13
+ };
14
+ var addNode = (nodes, newNode, parentId) => {
15
+ if (!parentId) {
16
+ return [...nodes, newNode];
17
+ }
18
+ return nodes.map((node) => {
19
+ if (node.id === parentId) {
20
+ return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
21
+ } else if (node.children.length) {
22
+ return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
23
+ }
24
+ return node;
25
+ });
26
+ };
27
+ var treeIndentationRepresentation = (index, indentLevel) => {
28
+ if (indentLevel === 0) {
29
+ return (index + 1).toString();
30
+ } else if (indentLevel === 1) {
31
+ return String.fromCharCode(65 + index);
32
+ } else if (indentLevel === 2) {
33
+ return String.fromCharCode(97 + index);
34
+ } else {
35
+ return "-";
36
+ }
37
+ };
38
+ var printNode = (node, prefix = "", indentLevel = 0) => {
39
+ const indent = " ".repeat(3).repeat(indentLevel);
40
+ const prefixPlusIndentLength = prefix.length + indent.length;
41
+ const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
42
+ const valueLines = node.value.split("\n");
43
+ const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
44
+ const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
45
+ let output = `${outputFirstLine}
46
+ `;
47
+ if (outputSubsequentLines) {
48
+ output += `${outputSubsequentLines}
49
+ `;
50
+ }
51
+ const childPrePrefix = " ".repeat(prefix.length);
52
+ node.children.forEach(
53
+ (child, index) => output += printNode(
54
+ child,
55
+ `${childPrePrefix}${treeIndentationRepresentation(
56
+ index,
57
+ indentLevel + 1
58
+ )}. `,
59
+ indentLevel + 1
60
+ )
61
+ );
62
+ return output;
63
+ };
64
+ function treeReducer(state, action) {
65
+ switch (action.type) {
66
+ case "ADD_NODE": {
67
+ const { value, parentId, id: newNodeId } = action;
68
+ const newNode = {
69
+ id: newNodeId,
70
+ value,
71
+ children: [],
72
+ categories: new Set(action.categories)
73
+ };
74
+ try {
75
+ return addNode(state, newNode, parentId);
76
+ } catch (error) {
77
+ console.error(`Error while adding node with id ${newNodeId}: ${error}`);
78
+ return state;
79
+ }
80
+ }
81
+ case "REMOVE_NODE":
82
+ return removeNode(state, action.id);
83
+ default:
84
+ return state;
85
+ }
86
+ }
87
+ var useTree = () => {
88
+ const [tree, dispatch] = useReducer(treeReducer, []);
89
+ const addElement = useCallback(
90
+ (value, categories, parentId) => {
91
+ const newNodeId = nanoid();
92
+ dispatch({
93
+ type: "ADD_NODE",
94
+ value,
95
+ parentId,
96
+ id: newNodeId,
97
+ categories
98
+ });
99
+ return newNodeId;
100
+ },
101
+ []
102
+ );
103
+ const removeElement = useCallback((id) => {
104
+ dispatch({ type: "REMOVE_NODE", id });
105
+ }, []);
106
+ const printTree = useCallback(
107
+ (categories) => {
108
+ const categoriesSet = new Set(categories);
109
+ let output = "";
110
+ tree.forEach((node, index) => {
111
+ if (!setsHaveIntersection(categoriesSet, node.categories)) {
112
+ return;
113
+ }
114
+ if (index !== 0) {
115
+ output += "\n";
116
+ }
117
+ output += printNode(
118
+ node,
119
+ `${treeIndentationRepresentation(index, 0)}. `
120
+ );
121
+ });
122
+ return output;
123
+ },
124
+ [tree]
125
+ );
126
+ return { tree, addElement, printTree, removeElement };
127
+ };
128
+ var use_tree_default = useTree;
129
+ function setsHaveIntersection(setA, setB) {
130
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
131
+ for (let item of smallerSet) {
132
+ if (largerSet.has(item)) {
133
+ return true;
134
+ }
135
+ }
136
+ return false;
137
+ }
138
+
139
+ export { use_tree_default };
140
+ //# sourceMappingURL=out.js.map
141
+ //# sourceMappingURL=chunk-3BOHSSKR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-tree.ts"],"names":[],"mappings":"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","sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (\n value: string,\n categories: string[],\n parentId?: TreeNodeId\n ) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (\n nodes: Tree,\n newNode: TreeNode,\n parentId?: TreeNodeId\n): Tree => {\n if (!parentId) {\n return [...nodes, newNode];\n }\n return nodes.map((node) => {\n if (node.id === parentId) {\n return { ...node, children: [...node.children, newNode] };\n } else if (node.children.length) {\n return { ...node, children: addNode(node.children, newNode, parentId) };\n }\n return node;\n });\n};\n\nconst treeIndentationRepresentation = (\n index: number,\n indentLevel: number\n): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(\n index,\n indentLevel + 1\n )}. `,\n indentLevel + 1\n ))\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = nanoid(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n []\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(\n node,\n `${treeIndentationRepresentation(index, 0)}. `\n );\n });\n return output;\n },\n [tree]\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { CopilotContext } from './chunk-K7TVQCXG.mjs';
2
+ import { useContext, useRef, useEffect } from 'react';
3
+
4
+ function useMakeCopilotReadable(information, parentId, categories) {
5
+ const { addContext, removeContext } = useContext(CopilotContext);
6
+ const idRef = useRef();
7
+ useEffect(() => {
8
+ const id = addContext(information, parentId, categories);
9
+ idRef.current = id;
10
+ return () => {
11
+ removeContext(id);
12
+ };
13
+ }, [information, parentId, addContext, removeContext]);
14
+ return idRef.current;
15
+ }
16
+
17
+ export { useMakeCopilotReadable };
18
+ //# sourceMappingURL=out.js.map
19
+ //# sourceMappingURL=chunk-3O374DDN.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-make-copilot-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAF9C;AAYO,SAAS,uBACd,aACA,UACA,YACoB;AACpB,QAAM,EAAE,YAAY,cAAc,IAAI,WAAW,cAAc;AAC/D,QAAM,QAAQ,OAAe;AAE7B,YAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,aAAa,CAAC;AAErD,SAAO,MAAM;AACf","sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[]\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n"]}
@@ -0,0 +1,76 @@
1
+ import { nanoid } from 'nanoid';
2
+ import { useReducer, useCallback } from 'react';
3
+
4
+ // src/hooks/use-flat-category-store.ts
5
+ var useFlatCategoryStore = () => {
6
+ const [elements, dispatch] = useReducer(
7
+ flatCategoryStoreReducer,
8
+ /* @__PURE__ */ new Map()
9
+ );
10
+ const addElement = useCallback(
11
+ (value, categories) => {
12
+ const newId = nanoid();
13
+ dispatch({
14
+ type: "ADD_ELEMENT",
15
+ value,
16
+ id: newId,
17
+ categories
18
+ });
19
+ return newId;
20
+ },
21
+ []
22
+ );
23
+ const removeElement = useCallback((id) => {
24
+ dispatch({ type: "REMOVE_ELEMENT", id });
25
+ }, []);
26
+ const allElements = useCallback(
27
+ (categories) => {
28
+ const categoriesSet = new Set(categories);
29
+ const result = [];
30
+ elements.forEach((element) => {
31
+ if (setsHaveIntersection(categoriesSet, element.categories)) {
32
+ result.push(element.value);
33
+ }
34
+ });
35
+ return result;
36
+ },
37
+ [elements]
38
+ );
39
+ return { addElement, removeElement, allElements };
40
+ };
41
+ var use_flat_category_store_default = useFlatCategoryStore;
42
+ function flatCategoryStoreReducer(state, action) {
43
+ switch (action.type) {
44
+ case "ADD_ELEMENT": {
45
+ const { value, id, categories } = action;
46
+ const newElement = {
47
+ id,
48
+ value,
49
+ categories: new Set(categories)
50
+ };
51
+ const newState = new Map(state);
52
+ newState.set(id, newElement);
53
+ return newState;
54
+ }
55
+ case "REMOVE_ELEMENT": {
56
+ const newState = new Map(state);
57
+ newState.delete(action.id);
58
+ return newState;
59
+ }
60
+ default:
61
+ return state;
62
+ }
63
+ }
64
+ function setsHaveIntersection(setA, setB) {
65
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
66
+ for (let item of smallerSet) {
67
+ if (largerSet.has(item)) {
68
+ return true;
69
+ }
70
+ }
71
+ return false;
72
+ }
73
+
74
+ export { use_flat_category_store_default };
75
+ //# sourceMappingURL=out.js.map
76
+ //# sourceMappingURL=chunk-63ILXW5V.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-flat-category-store.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAgBxC,IAAM,uBAAuB,MAAwC;AACnE,QAAM,CAAC,UAAU,QAAQ,IAAI;AAAA,IAM3B;AAAA,IACA,oBAAI,IAAsD;AAAA,EAC5D;AAEA,QAAM,aAAa;AAAA,IACjB,CAAC,OAAU,eAA8C;AACvD,YAAM,QAAQ,OAAO;AACrB,eAAS;AAAA,QACP,MAAM;AAAA,QACN;AAAA,QACA,IAAI;AAAA,QACJ;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,gBAAgB,YAAY,CAAC,OAAkC;AACnE,aAAS,EAAE,MAAM,kBAAkB,GAAG,CAAC;AAAA,EACzC,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc;AAAA,IAClB,CAAC,eAA8B;AAC7B,YAAM,gBAAgB,IAAI,IAAI,UAAU;AACxC,YAAM,SAAc,CAAC;AACrB,eAAS,QAAQ,CAAC,YAAY;AAC5B,YAAI,qBAAqB,eAAe,QAAQ,UAAU,GAAG;AAC3D,iBAAO,KAAK,QAAQ,KAAK;AAAA,QAC3B;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,SAAO,EAAE,YAAY,eAAe,YAAY;AAClD;AAEA,IAAO,kCAAQ;AAaf,SAAS,yBACP,OACA,QACuD;AACvD,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,eAAe;AAClB,YAAM,EAAE,OAAO,IAAI,WAAW,IAAI;AAClC,YAAM,aAA0C;AAAA,QAC9C;AAAA,QACA;AAAA,QACA,YAAY,IAAI,IAAI,UAAU;AAAA,MAChC;AACA,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,IAAI,IAAI,UAAU;AAC3B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,kBAAkB;AACrB,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,OAAO,OAAO,EAAE;AACzB,aAAO;AAAA,IACT;AAAA,IACA;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAC1B,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAErD,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type FlatCategoryStoreId = string;\n\nexport interface UseFlatCategoryStoreReturn<T> {\n addElement: (value: T, categories: string[]) => FlatCategoryStoreId;\n removeElement: (id: FlatCategoryStoreId) => void;\n allElements: (categories: string[]) => T[];\n}\n\ninterface FlatCategoryStoreElement<T> {\n id: FlatCategoryStoreId;\n value: T;\n categories: Set<string>;\n}\n\nconst useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {\n const [elements, dispatch] = useReducer<\n React.Reducer<\n Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n Action<T>\n >\n >(\n flatCategoryStoreReducer,\n new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>()\n );\n\n const addElement = useCallback(\n (value: T, categories: string[]): FlatCategoryStoreId => {\n const newId = nanoid();\n dispatch({\n type: \"ADD_ELEMENT\",\n value,\n id: newId,\n categories,\n });\n return newId;\n },\n []\n );\n\n const removeElement = useCallback((id: FlatCategoryStoreId): void => {\n dispatch({ type: \"REMOVE_ELEMENT\", id });\n }, []);\n\n const allElements = useCallback(\n (categories: string[]): T[] => {\n const categoriesSet = new Set(categories);\n const result: T[] = [];\n elements.forEach((element) => {\n if (setsHaveIntersection(categoriesSet, element.categories)) {\n result.push(element.value);\n }\n });\n return result;\n },\n [elements]\n );\n\n return { addElement, removeElement, allElements };\n};\n\nexport default useFlatCategoryStore;\n\n// Action types\ntype Action<T> =\n | {\n type: \"ADD_ELEMENT\";\n value: T;\n id: FlatCategoryStoreId;\n categories: string[];\n }\n | { type: \"REMOVE_ELEMENT\"; id: FlatCategoryStoreId };\n\n// Reducer\nfunction flatCategoryStoreReducer<T>(\n state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n action: Action<T>\n): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {\n switch (action.type) {\n case \"ADD_ELEMENT\": {\n const { value, id, categories } = action;\n const newElement: FlatCategoryStoreElement<T> = {\n id,\n value,\n categories: new Set(categories),\n };\n const newState = new Map(state);\n newState.set(id, newElement);\n return newState;\n }\n case \"REMOVE_ELEMENT\": {\n const newState = new Map(state);\n newState.delete(action.id);\n return newState;\n }\n default:\n return state;\n }\n}\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { CopilotContext } from './chunk-K7TVQCXG.mjs';
2
+ import { useContext, useRef, useEffect } from 'react';
3
+
4
+ function useMakeCopilotDocumentReadable(document, categories) {
5
+ const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);
6
+ const idRef = useRef();
7
+ useEffect(() => {
8
+ const id = addDocumentContext(document, categories);
9
+ idRef.current = id;
10
+ return () => {
11
+ removeDocumentContext(id);
12
+ };
13
+ }, [document, categories, addDocumentContext, removeDocumentContext]);
14
+ return idRef.current;
15
+ }
16
+
17
+ export { useMakeCopilotDocumentReadable };
18
+ //# sourceMappingURL=out.js.map
19
+ //# sourceMappingURL=chunk-6RRG7ME3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-make-copilot-document-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAF9C;AAaO,SAAS,+BACd,UACA,YACoB;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAChD,WAAW,cAAc;AAC3B,QAAM,QAAQ,OAAe;AAE7B,YAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,UAAU,YAAY,oBAAoB,qBAAqB,CAAC;AAEpE,SAAO,MAAM;AACf","sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[]\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } =\n useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [document, categories, addDocumentContext, removeDocumentContext]);\n\n return idRef.current;\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-EFZPSZWO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=out.js.map
3
+ //# sourceMappingURL=chunk-JD7BAH7U.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import './chunk-MRXNTQOX.mjs';
2
+ import React from 'react';
3
+
4
+ function copilotApiConfigExtrapolator(config) {
5
+ return {
6
+ get chatApiEndpoint() {
7
+ return `${config.chatApiEndpoint}`;
8
+ }
9
+ };
10
+ }
11
+ var emptyCopilotContext = {
12
+ entryPoints: {},
13
+ setEntryPoint: () => {
14
+ },
15
+ removeEntryPoint: () => {
16
+ },
17
+ getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
18
+ getFunctionCallHandler: () => returnAndThrowInDebug(),
19
+ getContextString: () => returnAndThrowInDebug(),
20
+ addContext: () => "",
21
+ removeContext: () => {
22
+ },
23
+ getDocumentsContext: () => returnAndThrowInDebug(),
24
+ addDocumentContext: () => returnAndThrowInDebug(),
25
+ removeDocumentContext: () => {
26
+ },
27
+ copilotApiConfig: new class {
28
+ get chatApiEndpoint() {
29
+ throw new Error(
30
+ "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
31
+ );
32
+ }
33
+ }()
34
+ };
35
+ var CopilotContext = React.createContext(emptyCopilotContext);
36
+ function returnAndThrowInDebug(value) {
37
+ throw new Error(
38
+ "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
39
+ );
40
+ }
41
+
42
+ export { CopilotContext, copilotApiConfigExtrapolator };
43
+ //# sourceMappingURL=out.js.map
44
+ //# sourceMappingURL=chunk-K7TVQCXG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/context/copilot-context.tsx"],"names":[],"mappings":";;;;;AAGA,OAAO,WAAW;AAHlB;AAaO,SAAS,6BAA6B,QAA0B;AACrE,SAAO;AAAA,IACL,IAAI,kBAA0B;AAC5B,aAAO,GAAG,OAAO;AAAA,IACnB;AAAA,EACF;AACF;AA+BA,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,kBAAkB,MAAM,sBAAsB,EAAE;AAAA,EAChD,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACnD,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBACX,MAAM,cAAoC,mBAAmB;AAE/D,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT","sourcesContent":["\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\n\nexport interface CopilotApiConfig {\n chatApiEndpoint: string;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n };\n}\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: () => ChatCompletionCreateParams.Function[];\n getFunctionCallHandler: () => FunctionCallHandler;\n\n // text context\n getContextString: (categories?: string[]) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories?: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n getContextString: () => returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: () => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n }\n })(),\n};\n\nexport const CopilotContext =\n React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n return value;\n}\n"]}