@copilotkit/react-core 0.11.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.turbo/turbo-build.log +31 -31
  2. package/CHANGELOG.md +18 -0
  3. package/dist/{chunk-3BOHSSKR.mjs → chunk-C4KF43WB.mjs} +3 -9
  4. package/dist/chunk-C4KF43WB.mjs.map +1 -0
  5. package/dist/{chunk-ATMIAPXE.mjs → chunk-FVU5RFVX.mjs} +5 -6
  6. package/dist/chunk-FVU5RFVX.mjs.map +1 -0
  7. package/dist/{chunk-X3CGMLW5.mjs → chunk-HZDMKMAV.mjs} +3 -3
  8. package/dist/chunk-HZDMKMAV.mjs.map +1 -0
  9. package/dist/{chunk-TNU2L6FJ.mjs → chunk-RW25IF4S.mjs} +2 -2
  10. package/dist/{chunk-TNU2L6FJ.mjs.map → chunk-RW25IF4S.mjs.map} +1 -1
  11. package/dist/{chunk-IMNFO2OZ.mjs → chunk-UBLDQLZM.mjs} +3 -3
  12. package/dist/chunk-UBLDQLZM.mjs.map +1 -0
  13. package/dist/{chunk-PRQLPFIA.mjs → chunk-XFSUVTIQ.mjs} +3 -6
  14. package/dist/chunk-XFSUVTIQ.mjs.map +1 -0
  15. package/dist/{chunk-63ILXW5V.mjs → chunk-YULKJPY3.mjs} +12 -18
  16. package/dist/chunk-YULKJPY3.mjs.map +1 -0
  17. package/dist/{chunk-3EE3HCUI.mjs → chunk-ZIFCJ774.mjs} +16 -18
  18. package/dist/chunk-ZIFCJ774.mjs.map +1 -0
  19. package/dist/components/copilot-provider.d.ts +2 -1
  20. package/dist/components/copilot-provider.mjs +4 -4
  21. package/dist/components/index.d.ts +1 -1
  22. package/dist/components/index.mjs +4 -4
  23. package/dist/context/copilot-context.d.ts +2 -2
  24. package/dist/context/copilot-context.mjs +1 -1
  25. package/dist/context/index.mjs +1 -1
  26. package/dist/hooks/index.mjs +9 -5
  27. package/dist/hooks/use-copilot-chat.mjs +6 -2
  28. package/dist/hooks/use-flat-category-store.mjs +1 -1
  29. package/dist/hooks/use-make-copilot-actionable.mjs +2 -2
  30. package/dist/hooks/use-make-copilot-document-readable.d.ts +5 -5
  31. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  32. package/dist/hooks/use-make-copilot-readable.mjs +2 -2
  33. package/dist/hooks/use-tree.mjs +1 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.mjs +9 -9
  36. package/package.json +1 -1
  37. package/src/components/copilot-provider.tsx +32 -39
  38. package/src/components/index.ts +1 -1
  39. package/src/context/copilot-context.tsx +10 -20
  40. package/src/hooks/use-copilot-chat.ts +19 -23
  41. package/src/hooks/use-flat-category-store.ts +15 -25
  42. package/src/hooks/use-make-copilot-actionable.ts +3 -6
  43. package/src/hooks/use-make-copilot-document-readable.ts +8 -9
  44. package/src/hooks/use-make-copilot-readable.ts +1 -1
  45. package/src/hooks/use-tree.ts +10 -28
  46. package/dist/chunk-3BOHSSKR.mjs.map +0 -1
  47. package/dist/chunk-3EE3HCUI.mjs.map +0 -1
  48. package/dist/chunk-63ILXW5V.mjs.map +0 -1
  49. package/dist/chunk-ATMIAPXE.mjs.map +0 -1
  50. package/dist/chunk-IMNFO2OZ.mjs.map +0 -1
  51. package/dist/chunk-PRQLPFIA.mjs.map +0 -1
  52. package/dist/chunk-X3CGMLW5.mjs.map +0 -1
@@ -1,5 +1,9 @@
1
- export { defaultSystemMessage, useCopilotChat } from '../chunk-ATMIAPXE.mjs';
2
- import '../chunk-X3CGMLW5.mjs';
1
+ export { defaultSystemMessage, useCopilotChat } from '../chunk-FVU5RFVX.mjs';
2
+ import '../chunk-JD7BAH7U.mjs';
3
+ import '../chunk-ZIFCJ774.mjs';
4
+ import '../chunk-C4KF43WB.mjs';
5
+ import '../chunk-HZDMKMAV.mjs';
6
+ import '../chunk-YULKJPY3.mjs';
3
7
  import '../chunk-MRXNTQOX.mjs';
4
8
  //# sourceMappingURL=out.js.map
5
9
  //# sourceMappingURL=use-copilot-chat.mjs.map
@@ -1,4 +1,4 @@
1
- export { use_flat_category_store_default as default } from '../chunk-63ILXW5V.mjs';
1
+ export { use_flat_category_store_default as default } from '../chunk-YULKJPY3.mjs';
2
2
  import '../chunk-MRXNTQOX.mjs';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=use-flat-category-store.mjs.map
@@ -1,5 +1,5 @@
1
- export { useMakeCopilotActionable } from '../chunk-PRQLPFIA.mjs';
2
- import '../chunk-X3CGMLW5.mjs';
1
+ export { useMakeCopilotActionable } from '../chunk-XFSUVTIQ.mjs';
2
+ import '../chunk-HZDMKMAV.mjs';
3
3
  import '../chunk-MRXNTQOX.mjs';
4
4
  //# sourceMappingURL=out.js.map
5
5
  //# sourceMappingURL=use-make-copilot-actionable.mjs.map
@@ -1,11 +1,11 @@
1
1
  import { DocumentPointer } from '../types/document-pointer.js';
2
2
 
3
3
  /**
4
- * Adds the given information to the Copilot context to make it readable by Copilot.
5
- * @param information - The information to be added to the Copilot context.
6
- * @param parentId - The ID of the parent context, if any.
7
- * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)
8
- * @returns The ID of the added context.
4
+ * Makes a document readable by Copilot.
5
+ * @param document The document to make readable.
6
+ * @param categories The categories to associate with the document.
7
+ * @param dependencies The dependencies to use for the effect.
8
+ * @returns The id of the document.
9
9
  */
10
10
  declare function useMakeCopilotDocumentReadable(document: DocumentPointer, categories?: string[], dependencies?: any[]): string | undefined;
11
11
 
@@ -1,5 +1,5 @@
1
- export { useMakeCopilotDocumentReadable } from '../chunk-IMNFO2OZ.mjs';
2
- import '../chunk-X3CGMLW5.mjs';
1
+ export { useMakeCopilotDocumentReadable } from '../chunk-UBLDQLZM.mjs';
2
+ import '../chunk-HZDMKMAV.mjs';
3
3
  import '../chunk-MRXNTQOX.mjs';
4
4
  //# sourceMappingURL=out.js.map
5
5
  //# sourceMappingURL=use-make-copilot-document-readable.mjs.map
@@ -1,5 +1,5 @@
1
- export { useMakeCopilotReadable } from '../chunk-TNU2L6FJ.mjs';
2
- import '../chunk-X3CGMLW5.mjs';
1
+ export { useMakeCopilotReadable } from '../chunk-RW25IF4S.mjs';
2
+ import '../chunk-HZDMKMAV.mjs';
3
3
  import '../chunk-MRXNTQOX.mjs';
4
4
  //# sourceMappingURL=out.js.map
5
5
  //# sourceMappingURL=use-make-copilot-readable.mjs.map
@@ -1,4 +1,4 @@
1
- export { use_tree_default as default } from '../chunk-3BOHSSKR.mjs';
1
+ export { use_tree_default as default } from '../chunk-C4KF43WB.mjs';
2
2
  import '../chunk-MRXNTQOX.mjs';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=use-tree.mjs.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { CopilotProvider } from './components/copilot-provider.js';
1
+ export { CopilotProvider, defaultCopilotContextCategories } from './components/copilot-provider.js';
2
2
  export { CopilotApiConfig, CopilotContext, CopilotContextParams, copilotApiConfigExtrapolator } from './context/copilot-context.js';
3
3
  export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './hooks/use-copilot-chat.js';
4
4
  export { useMakeCopilotActionable } from './hooks/use-make-copilot-actionable.js';
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
1
  import './chunk-EFZPSZWO.mjs';
2
- import './chunk-JD7BAH7U.mjs';
3
- export { CopilotProvider } from './chunk-3EE3HCUI.mjs';
4
- import './chunk-3BOHSSKR.mjs';
5
2
  import './chunk-YPSGKPDA.mjs';
6
3
  import './chunk-QACD2U6P.mjs';
7
- export { useMakeCopilotActionable } from './chunk-PRQLPFIA.mjs';
8
- export { useMakeCopilotDocumentReadable } from './chunk-IMNFO2OZ.mjs';
9
- export { useMakeCopilotReadable } from './chunk-TNU2L6FJ.mjs';
10
- export { useCopilotChat } from './chunk-ATMIAPXE.mjs';
11
- export { CopilotContext, copilotApiConfigExtrapolator } from './chunk-X3CGMLW5.mjs';
12
- import './chunk-63ILXW5V.mjs';
4
+ export { useMakeCopilotActionable } from './chunk-XFSUVTIQ.mjs';
5
+ export { useMakeCopilotDocumentReadable } from './chunk-UBLDQLZM.mjs';
6
+ export { useMakeCopilotReadable } from './chunk-RW25IF4S.mjs';
7
+ export { useCopilotChat } from './chunk-FVU5RFVX.mjs';
8
+ import './chunk-JD7BAH7U.mjs';
9
+ export { CopilotProvider, defaultCopilotContextCategories } from './chunk-ZIFCJ774.mjs';
10
+ import './chunk-C4KF43WB.mjs';
11
+ export { CopilotContext, copilotApiConfigExtrapolator } from './chunk-HZDMKMAV.mjs';
12
+ import './chunk-YULKJPY3.mjs';
13
13
  import './chunk-MRXNTQOX.mjs';
14
14
  //# sourceMappingURL=out.js.map
15
15
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.11.0",
7
+ "version": "0.14.0",
8
8
  "sideEffects": false,
9
9
  "main": "./dist/index.js",
10
10
  "module": "./dist/index.mjs",
@@ -19,9 +19,7 @@ export function CopilotProvider({
19
19
  body?: Record<string, any>;
20
20
  children: ReactNode;
21
21
  }): JSX.Element {
22
- const [entryPoints, setEntryPoints] = useState<
23
- Record<string, AnnotatedFunction<any[]>>
24
- >({});
22
+ const [entryPoints, setEntryPoints] = useState<Record<string, AnnotatedFunction<any[]>>>({});
25
23
 
26
24
  const { addElement, removeElement, printTree } = useTree();
27
25
  const {
@@ -30,17 +28,14 @@ export function CopilotProvider({
30
28
  allElements: allDocuments,
31
29
  } = useFlatCategoryStore<DocumentPointer>();
32
30
 
33
- const setEntryPoint = useCallback(
34
- (id: string, entryPoint: AnnotatedFunction<any[]>) => {
35
- setEntryPoints((prevPoints) => {
36
- return {
37
- ...prevPoints,
38
- [id]: entryPoint,
39
- };
40
- });
41
- },
42
- []
43
- );
31
+ const setEntryPoint = useCallback((id: string, entryPoint: AnnotatedFunction<any[]>) => {
32
+ setEntryPoints((prevPoints) => {
33
+ return {
34
+ ...prevPoints,
35
+ [id]: entryPoint,
36
+ };
37
+ });
38
+ }, []);
44
39
 
45
40
  const removeEntryPoint = useCallback((id: string) => {
46
41
  setEntryPoints((prevPoints) => {
@@ -51,12 +46,10 @@ export function CopilotProvider({
51
46
  }, []);
52
47
 
53
48
  const getContextString = useCallback(
54
- (documents: DocumentPointer[], categories: string[] = ["global"]) => {
49
+ (documents: DocumentPointer[], categories: string[]) => {
55
50
  const documentsString = documents
56
51
  .map((document) => {
57
- return `${document.name} (${
58
- document.sourceApplication
59
- }):\n${document.getContents()}`;
52
+ return `${document.name} (${document.sourceApplication}):\n${document.getContents()}`;
60
53
  })
61
54
  .join("\n\n");
62
55
 
@@ -64,21 +57,25 @@ export function CopilotProvider({
64
57
 
65
58
  return `${documentsString}\n\n${nonDocumentStrings}`;
66
59
  },
67
- [printTree]
60
+ [printTree],
68
61
  );
69
62
 
70
63
  const addContext = useCallback(
71
- (context: string, parentId?: string, categories: string[] = ["global"]) => {
64
+ (
65
+ context: string,
66
+ parentId?: string,
67
+ categories: string[] = defaultCopilotContextCategories,
68
+ ) => {
72
69
  return addElement(context, categories, parentId);
73
70
  },
74
- [addElement]
71
+ [addElement],
75
72
  );
76
73
 
77
74
  const removeContext = useCallback(
78
75
  (id: string) => {
79
76
  removeElement(id);
80
77
  },
81
- [removeElement]
78
+ [removeElement],
82
79
  );
83
80
 
84
81
  const getChatCompletionFunctionDescriptions = useCallback(() => {
@@ -90,24 +87,24 @@ export function CopilotProvider({
90
87
  }, [entryPoints]);
91
88
 
92
89
  const getDocumentsContext = useCallback(
93
- (categories: string[] = ["global"]) => {
90
+ (categories: string[]) => {
94
91
  return allDocuments(categories);
95
92
  },
96
- [allDocuments]
93
+ [allDocuments],
97
94
  );
98
95
 
99
96
  const addDocumentContext = useCallback(
100
- (documentPointer: DocumentPointer, categories: string[] = ["global"]) => {
97
+ (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {
101
98
  return addDocument(documentPointer, categories);
102
99
  },
103
- [addDocument]
100
+ [addDocument],
104
101
  );
105
102
 
106
103
  const removeDocumentContext = useCallback(
107
104
  (documentId: string) => {
108
105
  removeDocument(documentId);
109
106
  },
110
- [removeDocument]
107
+ [removeDocument],
111
108
  );
112
109
 
113
110
  return (
@@ -136,20 +133,18 @@ export function CopilotProvider({
136
133
  );
137
134
  }
138
135
 
136
+ export const defaultCopilotContextCategories = ["global"];
137
+
139
138
  function entryPointsToFunctionCallHandler(
140
- entryPoints: AnnotatedFunction<any[]>[]
139
+ entryPoints: AnnotatedFunction<any[]>[],
141
140
  ): FunctionCallHandler {
142
141
  return async (chatMessages, functionCall) => {
143
- let entrypointsByFunctionName: Record<
144
- string,
145
- AnnotatedFunction<any[]>
146
- > = {};
142
+ let entrypointsByFunctionName: Record<string, AnnotatedFunction<any[]>> = {};
147
143
  for (let entryPoint of entryPoints) {
148
144
  entrypointsByFunctionName[entryPoint.name] = entryPoint;
149
145
  }
150
146
 
151
- const entryPointFunction =
152
- entrypointsByFunctionName[functionCall.name || ""];
147
+ const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
153
148
  if (entryPointFunction) {
154
149
  let parsedFunctionCallArguments: Record<string, any>[] = [];
155
150
  if (functionCall.arguments) {
@@ -159,9 +154,7 @@ function entryPointsToFunctionCallHandler(
159
154
  const paramsInCorrectOrder: any[] = [];
160
155
  for (let arg of entryPointFunction.argumentAnnotations) {
161
156
  paramsInCorrectOrder.push(
162
- parsedFunctionCallArguments[
163
- arg.name as keyof typeof parsedFunctionCallArguments
164
- ]
157
+ parsedFunctionCallArguments[arg.name as keyof typeof parsedFunctionCallArguments],
165
158
  );
166
159
  }
167
160
 
@@ -189,13 +182,13 @@ function entryPointsToFunctionCallHandler(
189
182
  }
190
183
 
191
184
  function entryPointsToChatCompletionFunctions(
192
- entryPoints: AnnotatedFunction<any[]>[]
185
+ entryPoints: AnnotatedFunction<any[]>[],
193
186
  ): ChatCompletionCreateParams.Function[] {
194
187
  return entryPoints.map(annotatedFunctionToChatCompletionFunction);
195
188
  }
196
189
 
197
190
  function annotatedFunctionToChatCompletionFunction(
198
- annotatedFunction: AnnotatedFunction<any[]>
191
+ annotatedFunction: AnnotatedFunction<any[]>,
199
192
  ): ChatCompletionCreateParams.Function {
200
193
  // Create the parameters object based on the argumentAnnotations
201
194
  let parameters: { [key: string]: any } = {};
@@ -1 +1 @@
1
- export { CopilotProvider } from "./copilot-provider";
1
+ export { CopilotProvider, defaultCopilotContextCategories } from "./copilot-provider";
@@ -58,23 +58,13 @@ export interface CopilotContextParams {
58
58
  getFunctionCallHandler: () => FunctionCallHandler;
59
59
 
60
60
  // text context
61
- getContextString: (
62
- documents: DocumentPointer[],
63
- categories?: string[]
64
- ) => string;
65
- addContext: (
66
- context: string,
67
- parentId?: string,
68
- categories?: string[]
69
- ) => TreeNodeId;
61
+ getContextString: (documents: DocumentPointer[], categories: string[]) => string;
62
+ addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;
70
63
  removeContext: (id: TreeNodeId) => void;
71
64
 
72
65
  // document context
73
- getDocumentsContext: (categories?: string[]) => DocumentPointer[];
74
- addDocumentContext: (
75
- documentPointer: DocumentPointer,
76
- categories?: string[]
77
- ) => TreeNodeId;
66
+ getDocumentsContext: (categories: string[]) => DocumentPointer[];
67
+ addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;
78
68
  removeDocumentContext: (documentId: string) => void;
79
69
 
80
70
  // api endpoints
@@ -88,18 +78,19 @@ const emptyCopilotContext: CopilotContextParams = {
88
78
  getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
89
79
  getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),
90
80
 
91
- getContextString: (documents: DocumentPointer[]) => returnAndThrowInDebug(""),
81
+ getContextString: (documents: DocumentPointer[], categories: string[]) =>
82
+ returnAndThrowInDebug(""),
92
83
  addContext: () => "",
93
84
  removeContext: () => {},
94
85
 
95
- getDocumentsContext: () => returnAndThrowInDebug([]),
86
+ getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),
96
87
  addDocumentContext: () => returnAndThrowInDebug(""),
97
88
  removeDocumentContext: () => {},
98
89
 
99
90
  copilotApiConfig: new (class implements CopilotApiConfig {
100
91
  get chatApiEndpoint(): string {
101
92
  throw new Error(
102
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
93
+ "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!",
103
94
  );
104
95
  }
105
96
  get headers(): Record<string, string> {
@@ -111,12 +102,11 @@ const emptyCopilotContext: CopilotContextParams = {
111
102
  })(),
112
103
  };
113
104
 
114
- export const CopilotContext =
115
- React.createContext<CopilotContextParams>(emptyCopilotContext);
105
+ export const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);
116
106
 
117
107
  function returnAndThrowInDebug<T>(value: T): T {
118
108
  throw new Error(
119
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
109
+ "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!",
120
110
  );
121
111
  return value;
122
112
  }
@@ -7,6 +7,7 @@ import {
7
7
  import { useChat } from "ai/react";
8
8
  import { ChatRequestOptions, CreateMessage, Message } from "ai";
9
9
  import { UseChatOptions } from "ai";
10
+ import { defaultCopilotContextCategories } from "../components";
10
11
 
11
12
  export interface UseCopilotChatOptions extends UseChatOptions {
12
13
  makeSystemMessage?: (contextString: string) => string;
@@ -16,11 +17,9 @@ export interface UseCopilotChatReturn {
16
17
  visibleMessages: Message[];
17
18
  append: (
18
19
  message: Message | CreateMessage,
19
- chatRequestOptions?: ChatRequestOptions
20
- ) => Promise<string | null | undefined>;
21
- reload: (
22
- chatRequestOptions?: ChatRequestOptions
20
+ chatRequestOptions?: ChatRequestOptions,
23
21
  ) => Promise<string | null | undefined>;
22
+ reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
24
23
  stop: () => void;
25
24
  isLoading: boolean;
26
25
  input: string;
@@ -40,7 +39,7 @@ export function useCopilotChat({
40
39
 
41
40
  const systemMessage: Message = useMemo(() => {
42
41
  const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
43
- const contextString = getContextString([]);
42
+ const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable
44
43
 
45
44
  return {
46
45
  id: "system",
@@ -49,32 +48,29 @@ export function useCopilotChat({
49
48
  };
50
49
  }, [getContextString, makeSystemMessage]);
51
50
 
52
- const initialMessagesWithContext = [systemMessage].concat(
53
- options.initialMessages || []
54
- );
51
+ const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);
55
52
 
56
53
  const functionDescriptions = useMemo(() => {
57
54
  return getChatCompletionFunctionDescriptions();
58
55
  }, [getChatCompletionFunctionDescriptions]);
59
56
 
60
- const { messages, append, reload, stop, isLoading, input, setInput } =
61
- useChat({
62
- ...options,
63
- api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
57
+ const { messages, append, reload, stop, isLoading, input, setInput } = useChat({
58
+ ...options,
59
+ api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
60
+ id: options.id,
61
+ initialMessages: initialMessagesWithContext,
62
+ experimental_onFunctionCall: getFunctionCallHandler(),
63
+ headers: { ...copilotApiConfig.headers, ...options.headers },
64
+ body: {
64
65
  id: options.id,
65
- initialMessages: initialMessagesWithContext,
66
- experimental_onFunctionCall: getFunctionCallHandler(),
67
- headers: { ...copilotApiConfig.headers, ...options.headers },
68
- body: {
69
- id: options.id,
70
- functions: functionDescriptions,
71
- ...copilotApiConfig.body,
72
- ...options.body,
73
- },
74
- });
66
+ functions: functionDescriptions,
67
+ ...copilotApiConfig.body,
68
+ ...options.body,
69
+ },
70
+ });
75
71
 
76
72
  const visibleMessages = messages.filter(
77
- (message) => message.role === "user" || message.role === "assistant"
73
+ (message) => message.role === "user" || message.role === "assistant",
78
74
  );
79
75
 
80
76
  return {
@@ -17,28 +17,19 @@ interface FlatCategoryStoreElement<T> {
17
17
 
18
18
  const useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {
19
19
  const [elements, dispatch] = useReducer<
20
- React.Reducer<
21
- Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,
22
- Action<T>
23
- >
24
- >(
25
- flatCategoryStoreReducer,
26
- new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>()
27
- );
20
+ React.Reducer<Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>, Action<T>>
21
+ >(flatCategoryStoreReducer, new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>());
28
22
 
29
- const addElement = useCallback(
30
- (value: T, categories: string[]): FlatCategoryStoreId => {
31
- const newId = nanoid();
32
- dispatch({
33
- type: "ADD_ELEMENT",
34
- value,
35
- id: newId,
36
- categories,
37
- });
38
- return newId;
39
- },
40
- []
41
- );
23
+ const addElement = useCallback((value: T, categories: string[]): FlatCategoryStoreId => {
24
+ const newId = nanoid();
25
+ dispatch({
26
+ type: "ADD_ELEMENT",
27
+ value,
28
+ id: newId,
29
+ categories,
30
+ });
31
+ return newId;
32
+ }, []);
42
33
 
43
34
  const removeElement = useCallback((id: FlatCategoryStoreId): void => {
44
35
  dispatch({ type: "REMOVE_ELEMENT", id });
@@ -55,7 +46,7 @@ const useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {
55
46
  });
56
47
  return result;
57
48
  },
58
- [elements]
49
+ [elements],
59
50
  );
60
51
 
61
52
  return { addElement, removeElement, allElements };
@@ -76,7 +67,7 @@ type Action<T> =
76
67
  // Reducer
77
68
  function flatCategoryStoreReducer<T>(
78
69
  state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,
79
- action: Action<T>
70
+ action: Action<T>,
80
71
  ): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {
81
72
  switch (action.type) {
82
73
  case "ADD_ELEMENT": {
@@ -101,8 +92,7 @@ function flatCategoryStoreReducer<T>(
101
92
  }
102
93
 
103
94
  function setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {
104
- const [smallerSet, largerSet] =
105
- setA.size <= setB.size ? [setA, setB] : [setB, setA];
95
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
106
96
 
107
97
  for (let item of smallerSet) {
108
98
  if (largerSet.has(item)) {
@@ -7,7 +7,7 @@ import { nanoid } from "nanoid";
7
7
 
8
8
  export function useMakeCopilotActionable<ActionInput extends any[]>(
9
9
  annotatedFunction: AnnotatedFunction<ActionInput>,
10
- dependencies: any[]
10
+ dependencies: any[],
11
11
  ) {
12
12
  const idRef = useRef(nanoid()); // generate a unique id
13
13
  const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);
@@ -19,14 +19,11 @@ export function useMakeCopilotActionable<ActionInput extends any[]>(
19
19
  argumentAnnotations: annotatedFunction.argumentAnnotations,
20
20
  implementation: annotatedFunction.implementation,
21
21
  }),
22
- dependencies
22
+ dependencies,
23
23
  );
24
24
 
25
25
  useEffect(() => {
26
- setEntryPoint(
27
- idRef.current,
28
- memoizedAnnotatedFunction as AnnotatedFunction<any[]>
29
- );
26
+ setEntryPoint(idRef.current, memoizedAnnotatedFunction as AnnotatedFunction<any[]>);
30
27
 
31
28
  return () => {
32
29
  removeEntryPoint(idRef.current);
@@ -5,19 +5,18 @@ import { CopilotContext } from "../context/copilot-context";
5
5
  import { DocumentPointer } from "../types";
6
6
 
7
7
  /**
8
- * Adds the given information to the Copilot context to make it readable by Copilot.
9
- * @param information - The information to be added to the Copilot context.
10
- * @param parentId - The ID of the parent context, if any.
11
- * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)
12
- * @returns The ID of the added context.
8
+ * Makes a document readable by Copilot.
9
+ * @param document The document to make readable.
10
+ * @param categories The categories to associate with the document.
11
+ * @param dependencies The dependencies to use for the effect.
12
+ * @returns The id of the document.
13
13
  */
14
14
  export function useMakeCopilotDocumentReadable(
15
15
  document: DocumentPointer,
16
16
  categories?: string[],
17
- dependencies: any[] = []
17
+ dependencies: any[] = [],
18
18
  ): string | undefined {
19
- const { addDocumentContext, removeDocumentContext } =
20
- useContext(CopilotContext);
19
+ const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);
21
20
  const idRef = useRef<string>();
22
21
 
23
22
  useEffect(() => {
@@ -27,7 +26,7 @@ export function useMakeCopilotDocumentReadable(
27
26
  return () => {
28
27
  removeDocumentContext(id);
29
28
  };
30
- }, [categories, addDocumentContext, removeDocumentContext, ...dependencies]);
29
+ }, [addDocumentContext, removeDocumentContext, ...dependencies]);
31
30
 
32
31
  return idRef.current;
33
32
  }
@@ -13,7 +13,7 @@ import { CopilotContext } from "../context/copilot-context";
13
13
  export function useMakeCopilotReadable(
14
14
  information: string,
15
15
  parentId?: string,
16
- categories?: string[]
16
+ categories?: string[],
17
17
  ): string | undefined {
18
18
  const { addContext, removeContext } = useContext(CopilotContext);
19
19
  const idRef = useRef<string>();
@@ -15,11 +15,7 @@ export type Tree = TreeNode[];
15
15
 
16
16
  export interface UseTreeReturn {
17
17
  tree: Tree;
18
- addElement: (
19
- value: string,
20
- categories: string[],
21
- parentId?: TreeNodeId
22
- ) => TreeNodeId;
18
+ addElement: (value: string, categories: string[], parentId?: TreeNodeId) => TreeNodeId;
23
19
  printTree: (categories: string[]) => string;
24
20
  removeElement: (id: TreeNodeId) => void;
25
21
  }
@@ -47,11 +43,7 @@ const removeNode = (nodes: Tree, id: TreeNodeId): Tree => {
47
43
  }, []);
48
44
  };
49
45
 
50
- const addNode = (
51
- nodes: Tree,
52
- newNode: TreeNode,
53
- parentId?: TreeNodeId
54
- ): Tree => {
46
+ const addNode = (nodes: Tree, newNode: TreeNode, parentId?: TreeNodeId): Tree => {
55
47
  if (!parentId) {
56
48
  return [...nodes, newNode];
57
49
  }
@@ -65,10 +57,7 @@ const addNode = (
65
57
  });
66
58
  };
67
59
 
68
- const treeIndentationRepresentation = (
69
- index: number,
70
- indentLevel: number
71
- ): string => {
60
+ const treeIndentationRepresentation = (index: number, indentLevel: number): string => {
72
61
  if (indentLevel === 0) {
73
62
  return (index + 1).toString();
74
63
  } else if (indentLevel === 1) {
@@ -105,12 +94,9 @@ const printNode = (node: TreeNode, prefix = "", indentLevel = 0): string => {
105
94
  (child, index) =>
106
95
  (output += printNode(
107
96
  child,
108
- `${childPrePrefix}${treeIndentationRepresentation(
109
- index,
110
- indentLevel + 1
111
- )}. `,
112
- indentLevel + 1
113
- ))
97
+ `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
98
+ indentLevel + 1,
99
+ )),
114
100
  );
115
101
  return output;
116
102
  };
@@ -168,7 +154,7 @@ const useTree = (): UseTreeReturn => {
168
154
  });
169
155
  return newNodeId; // Return the new ID
170
156
  },
171
- []
157
+ [],
172
158
  );
173
159
 
174
160
  const removeElement = useCallback((id: TreeNodeId): void => {
@@ -191,14 +177,11 @@ const useTree = (): UseTreeReturn => {
191
177
  output += "\n";
192
178
  }
193
179
 
194
- output += printNode(
195
- node,
196
- `${treeIndentationRepresentation(index, 0)}. `
197
- );
180
+ output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
198
181
  });
199
182
  return output;
200
183
  },
201
- [tree]
184
+ [tree],
202
185
  );
203
186
 
204
187
  return { tree, addElement, printTree, removeElement };
@@ -207,8 +190,7 @@ const useTree = (): UseTreeReturn => {
207
190
  export default useTree;
208
191
 
209
192
  function setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {
210
- const [smallerSet, largerSet] =
211
- setA.size <= setB.size ? [setA, setB] : [setB, setA];
193
+ const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
212
194
 
213
195
  for (let item of smallerSet) {
214
196
  if (largerSet.has(item)) {