@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.
- package/.turbo/turbo-build.log +88 -88
- package/CHANGELOG.md +16 -0
- package/dist/chunk-3BOHSSKR.mjs +141 -0
- package/dist/chunk-3BOHSSKR.mjs.map +1 -0
- package/dist/chunk-3O374DDN.mjs +19 -0
- package/dist/chunk-3O374DDN.mjs.map +1 -0
- package/dist/chunk-63ILXW5V.mjs +76 -0
- package/dist/chunk-63ILXW5V.mjs.map +1 -0
- package/dist/chunk-6RRG7ME3.mjs +19 -0
- package/dist/chunk-6RRG7ME3.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +3 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +3 -0
- package/dist/chunk-JD7BAH7U.mjs.map +1 -0
- package/dist/chunk-K7TVQCXG.mjs +44 -0
- package/dist/chunk-K7TVQCXG.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-QACD2U6P.mjs +3 -0
- package/dist/chunk-QACD2U6P.mjs.map +1 -0
- package/dist/chunk-QFCPUIF7.mjs +147 -0
- package/dist/chunk-QFCPUIF7.mjs.map +1 -0
- package/dist/chunk-UNFDVVCF.mjs +80 -0
- package/dist/chunk-UNFDVVCF.mjs.map +1 -0
- package/dist/chunk-YPSGKPDA.mjs +3 -0
- package/dist/chunk-YPSGKPDA.mjs.map +1 -0
- package/dist/chunk-YTIZQV7H.mjs +30 -0
- package/dist/chunk-YTIZQV7H.mjs.map +1 -0
- package/dist/components/copilot-provider.mjs +6 -442
- package/dist/components/copilot-provider.mjs.map +1 -1
- package/dist/components/index.mjs +7 -442
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.mjs +3 -67
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.mjs +4 -67
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.mjs +8 -220
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +4 -159
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +3 -74
- package/dist/hooks/use-flat-category-store.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +4 -88
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +4 -77
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +4 -77
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/hooks/use-tree.mjs +3 -159
- package/dist/hooks/use-tree.mjs.map +1 -1
- package/dist/index.mjs +14 -589
- package/dist/index.mjs.map +1 -1
- package/dist/types/annotated-function.mjs +2 -0
- package/dist/types/annotated-function.mjs.map +1 -1
- package/dist/types/document-pointer.mjs +2 -0
- package/dist/types/document-pointer.mjs.map +1 -1
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/utils.mjs +2 -0
- package/dist/utils/utils.mjs.map +1 -1
- package/dist/utils/utils.test.mjs +1 -0
- package/dist/utils/utils.test.mjs.map +1 -1
- package/package.json +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
|
-
> @copilotkit/react-core@0.8.0
|
|
2
|
+
> @copilotkit/react-core@0.8.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
|
|
3
3
|
> tsup --treeshake
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
[34mCLI[39m 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
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v6.5.0
|
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core/tsup.config.ts
|
|
9
|
+
[34mCLI[39m Target: es6
|
|
10
|
+
[34mCLI[39m Cleaning output folder
|
|
11
|
+
[34mESM[39m 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
19
|
+
[32mESM[39m [1mdist/chunk-EFZPSZWO.mjs [22m[32m76.00 B[39m
|
|
20
|
+
[32mESM[39m [1mdist/hooks/use-make-copilot-actionable.mjs [22m[32m218.00 B[39m
|
|
21
|
+
[32mESM[39m [1mdist/types/index.mjs [22m[32m98.00 B[39m
|
|
22
|
+
[32mESM[39m [1mdist/components/copilot-provider.mjs [22m[32m262.00 B[39m
|
|
23
|
+
[32mESM[39m [1mdist/context/copilot-context.mjs [22m[32m194.00 B[39m
|
|
24
|
+
[32mESM[39m [1mdist/chunk-JD7BAH7U.mjs [22m[32m76.00 B[39m
|
|
25
|
+
[32mESM[39m [1mdist/chunk-YPSGKPDA.mjs [22m[32m76.00 B[39m
|
|
26
|
+
[32mESM[39m [1mdist/chunk-QACD2U6P.mjs [22m[32m76.00 B[39m
|
|
27
|
+
[32mESM[39m [1mdist/chunk-MRXNTQOX.mjs [22m[32m1.92 KB[39m
|
|
28
|
+
[32mESM[39m [1mdist/hooks/use-make-copilot-document-readable.mjs [22m[32m231.00 B[39m
|
|
29
|
+
[32mESM[39m [1mdist/hooks/use-make-copilot-readable.mjs [22m[32m214.00 B[39m
|
|
30
|
+
[32mESM[39m [1mdist/hooks/use-tree.mjs [22m[32m170.00 B[39m
|
|
31
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m678.00 B[39m
|
|
32
|
+
[32mESM[39m [1mdist/components/index.mjs [22m[32m283.00 B[39m
|
|
33
|
+
[32mESM[39m [1mdist/chunk-QFCPUIF7.mjs [22m[32m4.43 KB[39m
|
|
34
|
+
[32mESM[39m [1mdist/chunk-3BOHSSKR.mjs [22m[32m3.95 KB[39m
|
|
35
|
+
[32mESM[39m [1mdist/context/index.mjs [22m[32m216.00 B[39m
|
|
36
|
+
[32mESM[39m [1mdist/hooks/index.mjs [22m[32m420.00 B[39m
|
|
37
|
+
[32mESM[39m [1mdist/chunk-YTIZQV7H.mjs [22m[32m972.00 B[39m
|
|
38
|
+
[32mESM[39m [1mdist/chunk-6RRG7ME3.mjs [22m[32m663.00 B[39m
|
|
39
|
+
[32mESM[39m [1mdist/chunk-3O374DDN.mjs [22m[32m626.00 B[39m
|
|
40
|
+
[32mESM[39m [1mdist/hooks/use-copilot-chat.mjs [22m[32m219.00 B[39m
|
|
41
|
+
[32mESM[39m [1mdist/chunk-UNFDVVCF.mjs [22m[32m2.62 KB[39m
|
|
42
|
+
[32mESM[39m [1mdist/chunk-K7TVQCXG.mjs [22m[32m1.21 KB[39m
|
|
43
|
+
[32mESM[39m [1mdist/hooks/use-flat-category-store.mjs [22m[32m200.00 B[39m
|
|
44
|
+
[32mESM[39m [1mdist/chunk-63ILXW5V.mjs [22m[32m1.92 KB[39m
|
|
45
|
+
[32mESM[39m [1mdist/utils/utils.mjs [22m[32m67.00 B[39m
|
|
46
|
+
[32mESM[39m [1mdist/types/annotated-function.mjs [22m[32m80.00 B[39m
|
|
47
|
+
[32mESM[39m [1mdist/types/document-pointer.mjs [22m[32m78.00 B[39m
|
|
48
|
+
[32mESM[39m [1mdist/utils/utils.test.mjs [22m[32m202.00 B[39m
|
|
49
|
+
[32mESM[39m [1mdist/chunk-EFZPSZWO.mjs.map [22m[32m51.00 B[39m
|
|
50
|
+
[32mESM[39m [1mdist/hooks/use-make-copilot-actionable.mjs.map [22m[32m51.00 B[39m
|
|
51
|
+
[32mESM[39m [1mdist/types/index.mjs.map [22m[32m51.00 B[39m
|
|
52
|
+
[32mESM[39m [1mdist/components/copilot-provider.mjs.map [22m[32m51.00 B[39m
|
|
53
|
+
[32mESM[39m [1mdist/context/copilot-context.mjs.map [22m[32m51.00 B[39m
|
|
54
|
+
[32mESM[39m [1mdist/chunk-JD7BAH7U.mjs.map [22m[32m51.00 B[39m
|
|
55
|
+
[32mESM[39m [1mdist/chunk-YPSGKPDA.mjs.map [22m[32m51.00 B[39m
|
|
56
|
+
[32mESM[39m [1mdist/chunk-QACD2U6P.mjs.map [22m[32m51.00 B[39m
|
|
57
|
+
[32mESM[39m [1mdist/chunk-MRXNTQOX.mjs.map [22m[32m71.00 B[39m
|
|
58
|
+
[32mESM[39m [1mdist/hooks/use-make-copilot-document-readable.mjs.map [22m[32m51.00 B[39m
|
|
59
|
+
[32mESM[39m [1mdist/hooks/use-make-copilot-readable.mjs.map [22m[32m51.00 B[39m
|
|
60
|
+
[32mESM[39m [1mdist/hooks/use-tree.mjs.map [22m[32m51.00 B[39m
|
|
61
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m51.00 B[39m
|
|
62
|
+
[32mESM[39m [1mdist/components/index.mjs.map [22m[32m51.00 B[39m
|
|
63
|
+
[32mESM[39m [1mdist/chunk-QFCPUIF7.mjs.map [22m[32m8.70 KB[39m
|
|
64
|
+
[32mESM[39m [1mdist/chunk-3BOHSSKR.mjs.map [22m[32m8.39 KB[39m
|
|
65
|
+
[32mESM[39m [1mdist/context/index.mjs.map [22m[32m51.00 B[39m
|
|
66
|
+
[32mESM[39m [1mdist/hooks/index.mjs.map [22m[32m51.00 B[39m
|
|
67
|
+
[32mESM[39m [1mdist/chunk-YTIZQV7H.mjs.map [22m[32m1.70 KB[39m
|
|
68
|
+
[32mESM[39m [1mdist/chunk-6RRG7ME3.mjs.map [22m[32m1.56 KB[39m
|
|
69
|
+
[32mESM[39m [1mdist/chunk-3O374DDN.mjs.map [22m[32m1.47 KB[39m
|
|
70
|
+
[32mESM[39m [1mdist/hooks/use-copilot-chat.mjs.map [22m[32m51.00 B[39m
|
|
71
|
+
[32mESM[39m [1mdist/chunk-UNFDVVCF.mjs.map [22m[32m4.48 KB[39m
|
|
72
|
+
[32mESM[39m [1mdist/chunk-K7TVQCXG.mjs.map [22m[32m3.38 KB[39m
|
|
73
|
+
[32mESM[39m [1mdist/hooks/use-flat-category-store.mjs.map [22m[32m51.00 B[39m
|
|
74
|
+
[32mESM[39m [1mdist/chunk-63ILXW5V.mjs.map [22m[32m4.31 KB[39m
|
|
75
|
+
[32mESM[39m [1mdist/utils/utils.mjs.map [22m[32m51.00 B[39m
|
|
76
|
+
[32mESM[39m [1mdist/types/annotated-function.mjs.map [22m[32m51.00 B[39m
|
|
77
|
+
[32mESM[39m [1mdist/types/document-pointer.mjs.map [22m[32m51.00 B[39m
|
|
78
|
+
[32mESM[39m [1mdist/utils/utils.test.mjs.map [22m[32m351.00 B[39m
|
|
79
|
+
[32mESM[39m ⚡️ Build success in 465ms
|
|
80
|
+
[34mDTS[39m Build start
|
|
81
|
+
[32mDTS[39m ⚡️ Build success in 2261ms
|
|
82
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m814.00 B[39m
|
|
83
|
+
[32mDTS[39m [1mdist/components/copilot-provider.d.ts [22m[32m437.00 B[39m
|
|
84
|
+
[32mDTS[39m [1mdist/context/copilot-context.d.ts [22m[32m1.45 KB[39m
|
|
85
|
+
[32mDTS[39m [1mdist/hooks/use-copilot-chat.d.ts [22m[32m890.00 B[39m
|
|
86
|
+
[32mDTS[39m [1mdist/hooks/use-make-copilot-actionable.d.ts [22m[32m255.00 B[39m
|
|
87
|
+
[32mDTS[39m [1mdist/hooks/use-make-copilot-readable.d.ts [22m[32m598.00 B[39m
|
|
88
|
+
[32mDTS[39m [1mdist/hooks/use-make-copilot-document-readable.d.ts [22m[32m666.00 B[39m
|
|
89
|
+
[32mDTS[39m [1mdist/types/annotated-function.d.ts [22m[32m767.00 B[39m
|
|
90
|
+
[32mDTS[39m [1mdist/types/document-pointer.d.ts [22m[32m190.00 B[39m
|
|
91
|
+
[32mDTS[39m [1mdist/hooks/use-tree.d.ts [22m[32m543.00 B[39m
|
|
92
|
+
[32mDTS[39m [1mdist/components/index.d.ts [22m[32m269.00 B[39m
|
|
93
|
+
[32mDTS[39m [1mdist/context/index.d.ts [22m[32m297.00 B[39m
|
|
94
|
+
[32mDTS[39m [1mdist/hooks/index.d.ts [22m[32m434.00 B[39m
|
|
95
|
+
[32mDTS[39m [1mdist/hooks/use-flat-category-store.d.ts [22m[32m424.00 B[39m
|
|
96
|
+
[32mDTS[39m [1mdist/types/index.d.ts [22m[32m145.00 B[39m
|
|
97
|
+
[32mDTS[39m [1mdist/utils/utils.test.d.ts [22m[32m1.00 B[39m
|
|
98
|
+
[32mDTS[39m [1mdist/utils/utils.d.ts [22m[32m1.00 B[39m
|
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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -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"]}
|