@copilotkit/react-core 0.8.0-alpha.5 → 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.
- package/.turbo/turbo-build.log +83 -73
- package/CHANGELOG.md +6 -0
- package/dist/components/copilot-provider.d.ts +1 -0
- package/dist/components/copilot-provider.mjs +110 -8
- package/dist/components/copilot-provider.mjs.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.mjs +110 -8
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.d.ts +4 -0
- package/dist/context/copilot-context.mjs +4 -0
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.mjs +4 -0
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.mjs +21 -0
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +4 -0
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.d.ts +9 -0
- package/dist/hooks/use-flat-category-store.mjs +75 -0
- package/dist/hooks/use-flat-category-store.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-actionable.mjs +4 -0
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs +78 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-readable.mjs +4 -0
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +129 -10
- package/dist/index.mjs.map +1 -1
- package/dist/types/document-pointer.d.ts +9 -0
- package/dist/types/document-pointer.mjs +1 -0
- package/dist/types/document-pointer.mjs.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/components/copilot-provider.tsx +31 -1
- package/src/context/copilot-context.tsx +13 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-flat-category-store.ts +114 -0
- package/src/hooks/use-make-copilot-document-readable.ts +32 -0
- package/src/types/document-pointer.ts +7 -0
- package/src/types/index.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
Debugger attached.
|
|
2
1
|
|
|
3
|
-
> @copilotkit/react-core@0.8.0-alpha.
|
|
2
|
+
> @copilotkit/react-core@0.8.0-alpha.5 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core
|
|
4
3
|
> tsup --treeshake
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
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-make-copilot-actionable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/utils/utils.test.ts, src/utils/utils.ts, src/types/annotated-function.ts, src/types/index.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
|
|
8
6
|
CLI Using tsconfig: tsconfig.json
|
|
9
7
|
CLI tsup v6.5.0
|
|
10
8
|
CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core/tsup.config.ts
|
|
@@ -13,76 +11,88 @@ CLI Cleaning output folder
|
|
|
13
11
|
ESM Build start
|
|
14
12
|
Generated an empty chunk: "utils".
|
|
15
13
|
Generated an empty chunk: "annotated-function".
|
|
14
|
+
Generated an empty chunk: "document-pointer".
|
|
16
15
|
Generated an empty chunk: "chunk-EFZPSZWO".
|
|
17
16
|
Generated an empty chunk: "chunk-JD7BAH7U".
|
|
18
17
|
Generated an empty chunk: "chunk-YPSGKPDA".
|
|
19
|
-
Generated an empty chunk: "chunk-
|
|
20
|
-
ESM dist/
|
|
21
|
-
ESM dist/
|
|
22
|
-
ESM dist/
|
|
23
|
-
ESM dist/
|
|
24
|
-
ESM dist/chunk-
|
|
25
|
-
ESM dist/chunk-
|
|
26
|
-
ESM dist/
|
|
27
|
-
ESM dist/
|
|
28
|
-
ESM dist/hooks/use-
|
|
29
|
-
ESM dist/
|
|
30
|
-
ESM dist/
|
|
31
|
-
ESM dist/chunk-
|
|
32
|
-
ESM dist/
|
|
33
|
-
ESM dist/
|
|
34
|
-
ESM dist/
|
|
35
|
-
ESM dist/context/
|
|
36
|
-
ESM dist/chunk-
|
|
37
|
-
ESM dist/
|
|
38
|
-
ESM dist/chunk-
|
|
39
|
-
ESM dist/hooks/
|
|
40
|
-
ESM dist/chunk-
|
|
41
|
-
ESM dist/
|
|
42
|
-
ESM dist/chunk-
|
|
43
|
-
ESM dist/hooks/use-copilot-chat.mjs
|
|
44
|
-
ESM dist/
|
|
45
|
-
ESM dist/
|
|
46
|
-
ESM dist/chunk-
|
|
47
|
-
ESM dist/
|
|
48
|
-
ESM dist/
|
|
49
|
-
ESM dist/chunk-
|
|
50
|
-
ESM dist/
|
|
51
|
-
ESM dist/
|
|
52
|
-
ESM dist/
|
|
53
|
-
ESM dist/
|
|
54
|
-
ESM dist/
|
|
55
|
-
ESM dist/
|
|
56
|
-
ESM dist/
|
|
57
|
-
ESM dist/
|
|
58
|
-
ESM dist/components/
|
|
59
|
-
ESM dist/context/
|
|
60
|
-
ESM dist/
|
|
61
|
-
ESM dist/
|
|
62
|
-
ESM dist/
|
|
63
|
-
ESM dist/hooks/use-
|
|
64
|
-
ESM dist/
|
|
65
|
-
ESM dist/
|
|
66
|
-
ESM dist/chunk-
|
|
67
|
-
ESM dist/hooks/use-
|
|
68
|
-
ESM dist/
|
|
69
|
-
ESM dist/chunk-
|
|
70
|
-
ESM
|
|
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
|
|
71
80
|
DTS Build start
|
|
72
|
-
DTS ⚡️ Build success in
|
|
73
|
-
DTS dist/index.d.ts
|
|
74
|
-
DTS dist/components/copilot-provider.d.ts
|
|
75
|
-
DTS dist/context/copilot-context.d.ts
|
|
76
|
-
DTS dist/hooks/use-copilot-chat.d.ts
|
|
77
|
-
DTS dist/hooks/use-make-copilot-actionable.d.ts
|
|
78
|
-
DTS dist/hooks/use-make-copilot-readable.d.ts
|
|
79
|
-
DTS dist/
|
|
80
|
-
DTS dist/
|
|
81
|
-
DTS dist/
|
|
82
|
-
DTS dist/
|
|
83
|
-
DTS dist/
|
|
84
|
-
DTS dist/
|
|
85
|
-
DTS dist/
|
|
86
|
-
DTS dist/
|
|
87
|
-
|
|
88
|
-
|
|
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
|
@@ -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;
|
|
@@ -51,7 +51,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
// src/components/copilot-provider.tsx
|
|
54
|
-
import { useCallback as
|
|
54
|
+
import { useCallback as useCallback3, useState } from "react";
|
|
55
55
|
|
|
56
56
|
// src/context/copilot-context.tsx
|
|
57
57
|
import React from "react";
|
|
@@ -69,6 +69,10 @@ var emptyCopilotContext = {
|
|
|
69
69
|
addContext: () => "",
|
|
70
70
|
removeContext: () => {
|
|
71
71
|
},
|
|
72
|
+
getDocumentsContext: () => returnAndThrowInDebug([]),
|
|
73
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
74
|
+
removeDocumentContext: () => {
|
|
75
|
+
},
|
|
72
76
|
copilotApiConfig: new class {
|
|
73
77
|
get chatApiEndpoint() {
|
|
74
78
|
throw new Error(
|
|
@@ -222,6 +226,78 @@ function setsHaveIntersection(setA, setB) {
|
|
|
222
226
|
return false;
|
|
223
227
|
}
|
|
224
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
|
+
|
|
225
301
|
// src/components/copilot-provider.tsx
|
|
226
302
|
import { jsx } from "react/jsx-runtime";
|
|
227
303
|
"use client";
|
|
@@ -231,7 +307,12 @@ function CopilotProvider({
|
|
|
231
307
|
}) {
|
|
232
308
|
const [entryPoints, setEntryPoints] = useState({});
|
|
233
309
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
234
|
-
const
|
|
310
|
+
const {
|
|
311
|
+
addElement: addDocument,
|
|
312
|
+
removeElement: removeDocument,
|
|
313
|
+
allElements: allDocuments
|
|
314
|
+
} = use_flat_category_store_default();
|
|
315
|
+
const setEntryPoint = useCallback3(
|
|
235
316
|
(id, entryPoint) => {
|
|
236
317
|
setEntryPoints((prevPoints) => {
|
|
237
318
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
@@ -241,37 +322,55 @@ function CopilotProvider({
|
|
|
241
322
|
},
|
|
242
323
|
[]
|
|
243
324
|
);
|
|
244
|
-
const removeEntryPoint =
|
|
325
|
+
const removeEntryPoint = useCallback3((id) => {
|
|
245
326
|
setEntryPoints((prevPoints) => {
|
|
246
327
|
const newPoints = __spreadValues({}, prevPoints);
|
|
247
328
|
delete newPoints[id];
|
|
248
329
|
return newPoints;
|
|
249
330
|
});
|
|
250
331
|
}, []);
|
|
251
|
-
const getContextString =
|
|
332
|
+
const getContextString = useCallback3(
|
|
252
333
|
(categories = ["global"]) => {
|
|
253
334
|
return printTree(categories);
|
|
254
335
|
},
|
|
255
336
|
[printTree]
|
|
256
337
|
);
|
|
257
|
-
const addContext =
|
|
338
|
+
const addContext = useCallback3(
|
|
258
339
|
(context, parentId, categories = ["global"]) => {
|
|
259
340
|
return addElement(context, categories, parentId);
|
|
260
341
|
},
|
|
261
342
|
[addElement]
|
|
262
343
|
);
|
|
263
|
-
const removeContext =
|
|
344
|
+
const removeContext = useCallback3(
|
|
264
345
|
(id) => {
|
|
265
346
|
removeElement(id);
|
|
266
347
|
},
|
|
267
348
|
[removeElement]
|
|
268
349
|
);
|
|
269
|
-
const getChatCompletionFunctionDescriptions =
|
|
350
|
+
const getChatCompletionFunctionDescriptions = useCallback3(() => {
|
|
270
351
|
return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
|
|
271
352
|
}, [entryPoints]);
|
|
272
|
-
const getFunctionCallHandler =
|
|
353
|
+
const getFunctionCallHandler = useCallback3(() => {
|
|
273
354
|
return entryPointsToFunctionCallHandler(Object.values(entryPoints));
|
|
274
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
|
+
);
|
|
275
374
|
return /* @__PURE__ */ jsx(CopilotContext.Provider, {
|
|
276
375
|
value: {
|
|
277
376
|
entryPoints,
|
|
@@ -282,6 +381,9 @@ function CopilotProvider({
|
|
|
282
381
|
getContextString,
|
|
283
382
|
addContext,
|
|
284
383
|
removeContext,
|
|
384
|
+
getDocumentsContext,
|
|
385
|
+
addDocumentContext,
|
|
386
|
+
removeDocumentContext,
|
|
285
387
|
copilotApiConfig
|
|
286
388
|
},
|
|
287
389
|
children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/copilot-provider.tsx","../../src/context/copilot-context.tsx","../../src/hooks/use-tree.ts"],"sourcesContent":["\"use client\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ReactNode, useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../context/copilot-context\";\nimport useTree from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\n\nexport function CopilotProvider({\n copilotApiConfig,\n children,\n}: {\n copilotApiConfig: CopilotApiConfig;\n children: ReactNode;\n}): JSX.Element {\n const [entryPoints, setEntryPoints] = useState<\n Record<string, AnnotatedFunction<any[]>>\n >({});\n\n const { addElement, removeElement, printTree } = useTree();\n\n const setEntryPoint = useCallback(\n (id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n },\n []\n );\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (categories: string[] = [\"global\"]) => {\n return printTree(categories);\n },\n [printTree]\n );\n\n const addContext = useCallback(\n (context: string, parentId?: string, categories: string[] = [\"global\"]) => {\n return addElement(context, categories, parentId);\n },\n [addElement]\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement]\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(() => {\n return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n\n copilotApiConfig,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[]\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<\n string,\n AnnotatedFunction<any[]>\n > = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction =\n entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[\n arg.name as keyof typeof parsedFunctionCallArguments\n ]\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[]\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n","\"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\";\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 // 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 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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAoB,eAAAA,cAAa,gBAAgB;;;ACCjD,OAAO,WAAW;AAHlB;AAyCA,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,EAA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"version":3,"sources":["../../src/components/copilot-provider.tsx","../../src/context/copilot-context.tsx","../../src/hooks/use-tree.ts","../../src/hooks/use-flat-category-store.ts"],"sourcesContent":["\"use client\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ReactNode, useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../context/copilot-context\";\nimport useTree from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\nimport useFlatCategoryStore from \"../hooks/use-flat-category-store\";\n\nexport function CopilotProvider({\n copilotApiConfig,\n children,\n}: {\n copilotApiConfig: CopilotApiConfig;\n children: ReactNode;\n}): JSX.Element {\n const [entryPoints, setEntryPoints] = useState<\n Record<string, AnnotatedFunction<any[]>>\n >({});\n\n const { addElement, removeElement, printTree } = useTree();\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback(\n (id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n },\n []\n );\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (categories: string[] = [\"global\"]) => {\n return printTree(categories);\n },\n [printTree]\n );\n\n const addContext = useCallback(\n (context: string, parentId?: string, categories: string[] = [\"global\"]) => {\n return addElement(context, categories, parentId);\n },\n [addElement]\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement]\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(() => {\n return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getDocumentsContext = useCallback(\n (categories: string[] = [\"global\"]) => {\n return allDocuments(categories);\n },\n [allDocuments]\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = [\"global\"]) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument]\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument]\n );\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[]\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<\n string,\n AnnotatedFunction<any[]>\n > = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction =\n entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[\n arg.name as keyof typeof parsedFunctionCallArguments\n ]\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[]\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n","\"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","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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAoB,eAAAA,cAAa,gBAAgB;;;ACCjD,OAAO,WAAW;AAHlB;AAkDA,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;;;AClFA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAsCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,SAAS;AAC1C,QAAI,KAAK,OAAO,IAAI;AAClB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