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

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