@copilotkit/react-core 0.14.0 → 0.15.0-alpha.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 (112) hide show
  1. package/.turbo/turbo-build.log +141 -88
  2. package/CHANGELOG.md +11 -0
  3. package/dist/components/copilot-provider/copilot-provider-props.d.ts +50 -0
  4. package/dist/components/copilot-provider/copilot-provider-props.mjs +2 -0
  5. package/dist/components/copilot-provider/copilot-provider-props.mjs.map +1 -0
  6. package/dist/components/copilot-provider/copilot-provider.d.ts +45 -0
  7. package/dist/components/copilot-provider/copilot-provider.mjs +469 -0
  8. package/dist/components/copilot-provider/copilot-provider.mjs.map +1 -0
  9. package/dist/components/copilot-provider/index.d.ts +9 -0
  10. package/dist/components/copilot-provider/index.mjs +468 -0
  11. package/dist/components/copilot-provider/index.mjs.map +1 -0
  12. package/dist/components/copilot-provider/standard-cpilot-api-config.d.ts +24 -0
  13. package/dist/components/copilot-provider/standard-cpilot-api-config.mjs +13 -0
  14. package/dist/components/copilot-provider/standard-cpilot-api-config.mjs.map +1 -0
  15. package/dist/components/index.d.ts +8 -1
  16. package/dist/components/index.mjs +467 -7
  17. package/dist/components/index.mjs.map +1 -1
  18. package/dist/context/copilot-context.d.ts +5 -0
  19. package/dist/context/copilot-context.mjs +81 -3
  20. package/dist/context/copilot-context.mjs.map +1 -1
  21. package/dist/context/index.mjs +80 -4
  22. package/dist/context/index.mjs.map +1 -1
  23. package/dist/hooks/index.mjs +249 -12
  24. package/dist/hooks/index.mjs.map +1 -1
  25. package/dist/hooks/use-copilot-chat.mjs +194 -8
  26. package/dist/hooks/use-copilot-chat.mjs.map +1 -1
  27. package/dist/hooks/use-flat-category-store.mjs +68 -3
  28. package/dist/hooks/use-flat-category-store.mjs.map +1 -1
  29. package/dist/hooks/use-make-copilot-actionable.mjs +95 -4
  30. package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
  31. package/dist/hooks/use-make-copilot-document-readable.mjs +87 -4
  32. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
  33. package/dist/hooks/use-make-copilot-readable.mjs +87 -4
  34. package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
  35. package/dist/hooks/use-tree.mjs +153 -3
  36. package/dist/hooks/use-tree.mjs.map +1 -1
  37. package/dist/index.d.ts +5 -1
  38. package/dist/index.mjs +755 -14
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/openai-assistants/hooks/index.d.ts +2 -0
  41. package/dist/openai-assistants/hooks/index.mjs +246 -0
  42. package/dist/openai-assistants/hooks/index.mjs.map +1 -0
  43. package/dist/openai-assistants/hooks/use-assistants.d.ts +17 -0
  44. package/dist/openai-assistants/hooks/use-assistants.mjs +131 -0
  45. package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -0
  46. package/dist/openai-assistants/hooks/use-copilot-chat-v2.d.ts +44 -0
  47. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +247 -0
  48. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -0
  49. package/dist/openai-assistants/index.d.ts +3 -0
  50. package/dist/openai-assistants/index.mjs +247 -0
  51. package/dist/openai-assistants/index.mjs.map +1 -0
  52. package/dist/openai-assistants/utils/index.d.ts +1 -0
  53. package/dist/openai-assistants/utils/index.mjs +47 -0
  54. package/dist/openai-assistants/utils/index.mjs.map +1 -0
  55. package/dist/openai-assistants/utils/process-message-stream.d.ts +3 -0
  56. package/dist/openai-assistants/utils/process-message-stream.mjs +47 -0
  57. package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -0
  58. package/dist/types/annotated-function.mjs +0 -2
  59. package/dist/types/annotated-function.mjs.map +1 -1
  60. package/dist/types/document-pointer.mjs +0 -2
  61. package/dist/types/document-pointer.mjs.map +1 -1
  62. package/dist/types/index.mjs +0 -2
  63. package/dist/types/index.mjs.map +1 -1
  64. package/dist/utils/utils.d.ts +1 -0
  65. package/dist/utils/utils.mjs +0 -2
  66. package/dist/utils/utils.mjs.map +1 -1
  67. package/dist/utils/utils.test.d.ts +1 -0
  68. package/dist/utils/utils.test.mjs +0 -1
  69. package/dist/utils/utils.test.mjs.map +1 -1
  70. package/package.json +7 -6
  71. package/src/components/copilot-provider/copilot-provider-props.tsx +50 -0
  72. package/src/components/{copilot-provider.tsx → copilot-provider/copilot-provider.tsx} +60 -23
  73. package/src/components/copilot-provider/index.ts +7 -0
  74. package/src/components/copilot-provider/standard-cpilot-api-config.tsx +28 -0
  75. package/src/components/index.ts +1 -1
  76. package/src/context/copilot-context.tsx +13 -0
  77. package/src/index.tsx +1 -0
  78. package/src/openai-assistants/hooks/index.ts +9 -0
  79. package/src/openai-assistants/hooks/use-assistants.ts +114 -0
  80. package/src/openai-assistants/hooks/use-copilot-chat-v2.ts +186 -0
  81. package/src/openai-assistants/index.ts +2 -0
  82. package/src/openai-assistants/utils/index.ts +1 -0
  83. package/src/openai-assistants/utils/process-message-stream.ts +25 -0
  84. package/dist/chunk-C4KF43WB.mjs +0 -135
  85. package/dist/chunk-C4KF43WB.mjs.map +0 -1
  86. package/dist/chunk-EFZPSZWO.mjs +0 -3
  87. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  88. package/dist/chunk-FVU5RFVX.mjs +0 -80
  89. package/dist/chunk-FVU5RFVX.mjs.map +0 -1
  90. package/dist/chunk-HZDMKMAV.mjs +0 -50
  91. package/dist/chunk-HZDMKMAV.mjs.map +0 -1
  92. package/dist/chunk-JD7BAH7U.mjs +0 -3
  93. package/dist/chunk-JD7BAH7U.mjs.map +0 -1
  94. package/dist/chunk-MRXNTQOX.mjs +0 -55
  95. package/dist/chunk-MRXNTQOX.mjs.map +0 -1
  96. package/dist/chunk-QACD2U6P.mjs +0 -3
  97. package/dist/chunk-QACD2U6P.mjs.map +0 -1
  98. package/dist/chunk-RW25IF4S.mjs +0 -19
  99. package/dist/chunk-RW25IF4S.mjs.map +0 -1
  100. package/dist/chunk-UBLDQLZM.mjs +0 -19
  101. package/dist/chunk-UBLDQLZM.mjs.map +0 -1
  102. package/dist/chunk-XFSUVTIQ.mjs +0 -27
  103. package/dist/chunk-XFSUVTIQ.mjs.map +0 -1
  104. package/dist/chunk-YPSGKPDA.mjs +0 -3
  105. package/dist/chunk-YPSGKPDA.mjs.map +0 -1
  106. package/dist/chunk-YULKJPY3.mjs +0 -70
  107. package/dist/chunk-YULKJPY3.mjs.map +0 -1
  108. package/dist/chunk-ZIFCJ774.mjs +0 -158
  109. package/dist/chunk-ZIFCJ774.mjs.map +0 -1
  110. package/dist/components/copilot-provider.d.ts +0 -11
  111. package/dist/components/copilot-provider.mjs +0 -7
  112. package/dist/components/copilot-provider.mjs.map +0 -1
@@ -0,0 +1,186 @@
1
+ import { useContext, useMemo, useState } from "react";
2
+ import { processMessageStream } from "../utils";
3
+ import { Message, parseStreamPart } from "@copilotkit/shared";
4
+ import { CopilotContext, copilotApiConfigExtrapolator } from "../../context";
5
+ import { defaultCopilotContextCategories } from "../../components";
6
+
7
+ export type AssistantStatus = "in_progress" | "awaiting_message";
8
+
9
+ export interface RequestForwardingOptions {
10
+ /**
11
+ * The credentials mode to be used for the fetch request.
12
+ * Possible values are: 'omit', 'same-origin', 'include'.
13
+ * Defaults to 'same-origin'.
14
+ */
15
+ credentials?: RequestCredentials;
16
+ /**
17
+ * HTTP headers to be sent with the API request.
18
+ */
19
+ headers?: Record<string, string> | Headers;
20
+ /**
21
+ * Extra body object to be sent with the API request.
22
+ * @example
23
+ * Send a `sessionId` to the API along with the messages.
24
+ * ```js
25
+ * useChat({
26
+ * body: {
27
+ * sessionId: '123',
28
+ * }
29
+ * })
30
+ * ```
31
+ */
32
+ body?: object;
33
+ }
34
+ export interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {
35
+ makeSystemMessage?: (contextString: string) => string;
36
+ threadId?: string | undefined;
37
+ }
38
+
39
+ export interface UseCopilotChatV2Result {
40
+ messages: Message[];
41
+ input: string;
42
+ handleInputChange: (e: any) => void;
43
+ submitMessage: (e: any) => Promise<void>;
44
+ status: AssistantStatus;
45
+ error: unknown;
46
+ }
47
+
48
+ export function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {
49
+ const {
50
+ getContextString,
51
+ getChatCompletionFunctionDescriptions,
52
+ getFunctionCallHandler,
53
+ copilotApiConfig,
54
+ } = useContext(CopilotContext);
55
+
56
+ const [messages, setMessages] = useState<Message[]>([]);
57
+ const [input, setInput] = useState("");
58
+ const [threadId, setThreadId] = useState<string | undefined>(undefined);
59
+ const [status, setStatus] = useState<AssistantStatus>("awaiting_message");
60
+ const [error, setError] = useState<unknown | undefined>(undefined);
61
+
62
+ const systemMessage: Message = useMemo(() => {
63
+ const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage;
64
+ const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable
65
+
66
+ return {
67
+ id: "system",
68
+ content: systemMessageMaker(contextString),
69
+ role: "system",
70
+ };
71
+ }, [getContextString, options.makeSystemMessage]);
72
+
73
+ const handleInputChange = (e: any) => {
74
+ setInput(e.target.value);
75
+ };
76
+
77
+ const submitMessage = async (e: any) => {
78
+ e.preventDefault();
79
+
80
+ if (input === "") {
81
+ return;
82
+ }
83
+
84
+ setStatus("in_progress");
85
+
86
+ setMessages((messages) => [...messages, { id: "", role: "user", content: input }]);
87
+
88
+ setInput("");
89
+
90
+ const apiUrl = copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpointV2;
91
+ const result = await fetch(apiUrl, {
92
+ method: "POST",
93
+ headers: {
94
+ "Content-Type": "application/json",
95
+ ...copilotApiConfig.headers,
96
+ ...options.headers,
97
+ },
98
+ body: JSON.stringify({
99
+ // always use user-provided threadId when available:
100
+ threadId: options.threadId ?? threadId ?? null,
101
+ message: input,
102
+ functions: getChatCompletionFunctionDescriptions(),
103
+ ...copilotApiConfig.body,
104
+ ...options.body,
105
+ }),
106
+ });
107
+
108
+ if (result.body == null) {
109
+ throw new Error("The response body is empty.");
110
+ }
111
+
112
+ await processMessageStream(result.body.getReader(), (message: string) => {
113
+ try {
114
+ const { type, value } = parseStreamPart(message);
115
+
116
+ switch (type) {
117
+ case "assistant_message": {
118
+ // append message:
119
+ setMessages((messages) => [
120
+ ...messages,
121
+ {
122
+ id: value.id,
123
+ role: value.role,
124
+ content: value.content[0].text.value,
125
+ },
126
+ ]);
127
+ break;
128
+ }
129
+
130
+ case "assistant_control_data": {
131
+ setThreadId(value.threadId);
132
+
133
+ // set id of last message:
134
+ setMessages((messages) => {
135
+ const lastMessage = messages[messages.length - 1];
136
+ lastMessage.id = value.messageId;
137
+ return [...messages.slice(0, messages.length - 1), lastMessage];
138
+ });
139
+
140
+ break;
141
+ }
142
+
143
+ case "error": {
144
+ setError(value);
145
+ break;
146
+ }
147
+ }
148
+ } catch (error) {
149
+ setError(error);
150
+ }
151
+ });
152
+
153
+ setStatus("awaiting_message");
154
+ };
155
+
156
+ return {
157
+ messages,
158
+ input,
159
+ handleInputChange,
160
+ submitMessage,
161
+ status,
162
+ error,
163
+ };
164
+ }
165
+
166
+ export function defaultSystemMessage(contextString: string): string {
167
+ return `
168
+ Please act as an efficient, competent, conscientious, and industrious professional assistant.
169
+
170
+ Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
171
+ Always be polite and respectful, and prefer brevity over verbosity.
172
+
173
+ The user has provided you with the following context:
174
+ \`\`\`
175
+ ${contextString}
176
+ \`\`\`
177
+
178
+ They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
179
+
180
+ Please assist them as best you can.
181
+
182
+ You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
183
+
184
+ If you would like to call a function, call it without saying anything else.
185
+ `;
186
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./hooks";
2
+ export * from "./utils";
@@ -0,0 +1 @@
1
+ export { processMessageStream } from "./process-message-stream";
@@ -0,0 +1,25 @@
1
+ export async function processMessageStream(
2
+ reader: ReadableStreamDefaultReader<Uint8Array>,
3
+ processMessage: (message: string) => void | Promise<void>,
4
+ ) {
5
+ const decoder = new TextDecoder();
6
+ let buffer = "";
7
+ while (true) {
8
+ const { done, value } = await reader.read();
9
+
10
+ if (done) {
11
+ if (buffer.length > 0) {
12
+ processMessage(buffer);
13
+ }
14
+ break;
15
+ }
16
+
17
+ buffer += decoder.decode(value, { stream: true });
18
+
19
+ let endIndex: number;
20
+ while ((endIndex = buffer.indexOf("\n")) !== -1) {
21
+ processMessage(buffer.substring(0, endIndex).trim());
22
+ buffer = buffer.substring(endIndex + 1); // Remove the processed instruction + delimiter
23
+ }
24
+ }
25
+ }
@@ -1,135 +0,0 @@
1
- import { __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
2
- import { nanoid } from 'nanoid';
3
- import { useReducer, useCallback } from 'react';
4
-
5
- var removeNode = (nodes, id) => {
6
- return nodes.reduce((result, node) => {
7
- if (node.id !== id) {
8
- const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
9
- result.push(newNode);
10
- }
11
- return result;
12
- }, []);
13
- };
14
- var addNode = (nodes, newNode, parentId) => {
15
- if (!parentId) {
16
- return [...nodes, newNode];
17
- }
18
- return nodes.map((node) => {
19
- if (node.id === parentId) {
20
- return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
21
- } else if (node.children.length) {
22
- return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
23
- }
24
- return node;
25
- });
26
- };
27
- var treeIndentationRepresentation = (index, indentLevel) => {
28
- if (indentLevel === 0) {
29
- return (index + 1).toString();
30
- } else if (indentLevel === 1) {
31
- return String.fromCharCode(65 + index);
32
- } else if (indentLevel === 2) {
33
- return String.fromCharCode(97 + index);
34
- } else {
35
- return "-";
36
- }
37
- };
38
- var printNode = (node, prefix = "", indentLevel = 0) => {
39
- const indent = " ".repeat(3).repeat(indentLevel);
40
- const prefixPlusIndentLength = prefix.length + indent.length;
41
- const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
42
- const valueLines = node.value.split("\n");
43
- const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
44
- const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
45
- let output = `${outputFirstLine}
46
- `;
47
- if (outputSubsequentLines) {
48
- output += `${outputSubsequentLines}
49
- `;
50
- }
51
- const childPrePrefix = " ".repeat(prefix.length);
52
- node.children.forEach(
53
- (child, index) => output += printNode(
54
- child,
55
- `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
56
- indentLevel + 1
57
- )
58
- );
59
- return output;
60
- };
61
- function treeReducer(state, action) {
62
- switch (action.type) {
63
- case "ADD_NODE": {
64
- const { value, parentId, id: newNodeId } = action;
65
- const newNode = {
66
- id: newNodeId,
67
- value,
68
- children: [],
69
- categories: new Set(action.categories)
70
- };
71
- try {
72
- return addNode(state, newNode, parentId);
73
- } catch (error) {
74
- console.error(`Error while adding node with id ${newNodeId}: ${error}`);
75
- return state;
76
- }
77
- }
78
- case "REMOVE_NODE":
79
- return removeNode(state, action.id);
80
- default:
81
- return state;
82
- }
83
- }
84
- var useTree = () => {
85
- const [tree, dispatch] = useReducer(treeReducer, []);
86
- const addElement = useCallback(
87
- (value, categories, parentId) => {
88
- const newNodeId = nanoid();
89
- dispatch({
90
- type: "ADD_NODE",
91
- value,
92
- parentId,
93
- id: newNodeId,
94
- categories
95
- });
96
- return newNodeId;
97
- },
98
- []
99
- );
100
- const removeElement = useCallback((id) => {
101
- dispatch({ type: "REMOVE_NODE", id });
102
- }, []);
103
- const printTree = useCallback(
104
- (categories) => {
105
- const categoriesSet = new Set(categories);
106
- let output = "";
107
- tree.forEach((node, index) => {
108
- if (!setsHaveIntersection(categoriesSet, node.categories)) {
109
- return;
110
- }
111
- if (index !== 0) {
112
- output += "\n";
113
- }
114
- output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
115
- });
116
- return output;
117
- },
118
- [tree]
119
- );
120
- return { tree, addElement, printTree, removeElement };
121
- };
122
- var use_tree_default = useTree;
123
- function setsHaveIntersection(setA, setB) {
124
- const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
125
- for (let item of smallerSet) {
126
- if (largerSet.has(item)) {
127
- return true;
128
- }
129
- }
130
- return false;
131
- }
132
-
133
- export { use_tree_default };
134
- //# sourceMappingURL=out.js.map
135
- //# sourceMappingURL=chunk-C4KF43WB.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-tree.ts"],"names":[],"mappings":"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","sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (value: string, categories: string[], parentId?: TreeNodeId) => 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 = (nodes: Tree, newNode: TreeNode, parentId?: TreeNodeId): 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 = (index: number, indentLevel: number): 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(index, indentLevel + 1)}. `,\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(node, `${treeIndentationRepresentation(index, 0)}. `);\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] = 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"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-EFZPSZWO.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,80 +0,0 @@
1
- import { defaultCopilotContextCategories } from './chunk-ZIFCJ774.mjs';
2
- import { CopilotContext, copilotApiConfigExtrapolator } from './chunk-HZDMKMAV.mjs';
3
- import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
4
- import { useContext, useMemo } from 'react';
5
- import { useChat } from 'ai/react';
6
-
7
- function useCopilotChat(_a) {
8
- var _b = _a, {
9
- makeSystemMessage
10
- } = _b, options = __objRest(_b, [
11
- "makeSystemMessage"
12
- ]);
13
- const {
14
- getContextString,
15
- getChatCompletionFunctionDescriptions,
16
- getFunctionCallHandler,
17
- copilotApiConfig
18
- } = useContext(CopilotContext);
19
- const systemMessage = useMemo(() => {
20
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
21
- const contextString = getContextString([], defaultCopilotContextCategories);
22
- return {
23
- id: "system",
24
- content: systemMessageMaker(contextString),
25
- role: "system"
26
- };
27
- }, [getContextString, makeSystemMessage]);
28
- const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);
29
- const functionDescriptions = useMemo(() => {
30
- return getChatCompletionFunctionDescriptions();
31
- }, [getChatCompletionFunctionDescriptions]);
32
- const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
33
- api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
34
- id: options.id,
35
- initialMessages: initialMessagesWithContext,
36
- experimental_onFunctionCall: getFunctionCallHandler(),
37
- headers: __spreadValues(__spreadValues({}, copilotApiConfig.headers), options.headers),
38
- body: __spreadValues(__spreadValues({
39
- id: options.id,
40
- functions: functionDescriptions
41
- }, copilotApiConfig.body), options.body)
42
- }));
43
- const visibleMessages = messages.filter(
44
- (message) => message.role === "user" || message.role === "assistant"
45
- );
46
- return {
47
- visibleMessages,
48
- append,
49
- reload,
50
- stop,
51
- isLoading,
52
- input,
53
- setInput
54
- };
55
- }
56
- function defaultSystemMessage(contextString) {
57
- return `
58
- Please act as an efficient, competent, conscientious, and industrious professional assistant.
59
-
60
- Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
61
- Always be polite and respectful, and prefer brevity over verbosity.
62
-
63
- The user has provided you with the following context:
64
- \`\`\`
65
- ${contextString}
66
- \`\`\`
67
-
68
- They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
69
-
70
- Please assist them as best you can.
71
-
72
- You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
73
-
74
- If you would like to call a function, call it without saying anything else.
75
- `;
76
- }
77
-
78
- export { defaultSystemMessage, useCopilotChat };
79
- //# sourceMappingURL=out.js.map
80
- //# sourceMappingURL=chunk-FVU5RFVX.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AAMpC,SAAS,eAAe;AAsBjB,SAAS,eAAe,IAGiB;AAHjB,eAC7B;AAAA;AAAA,EA7BF,IA4B+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,qBAAqB;AAChD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,aAAa;AAAA,MACzC,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,kBAAkB,iBAAiB,CAAC;AAExC,QAAM,6BAA6B,CAAC,aAAa,EAAE,OAAO,QAAQ,mBAAmB,CAAC,CAAC;AAEvF,QAAM,uBAAuB,QAAQ,MAAM;AACzC,WAAO,sCAAsC;AAAA,EAC/C,GAAG,CAAC,qCAAqC,CAAC;AAE1C,QAAM,EAAE,UAAU,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,IAAI,QAAQ,iCAC1E,UAD0E;AAAA,IAE7E,KAAK,6BAA6B,gBAAgB,EAAE;AAAA,IACpD,IAAI,QAAQ;AAAA,IACZ,iBAAiB;AAAA,IACjB,6BAA6B,uBAAuB;AAAA,IACpD,SAAS,kCAAK,iBAAiB,UAAY,QAAQ;AAAA,IACnD,MAAM;AAAA,MACJ,IAAI,QAAQ;AAAA,MACZ,WAAW;AAAA,OACR,iBAAiB,OACjB,QAAQ;AAAA,EAEf,EAAC;AAED,QAAM,kBAAkB,SAAS;AAAA,IAC/B,CAAC,YAAY,QAAQ,SAAS,UAAU,QAAQ,SAAS;AAAA,EAC3D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,eAA+B;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWF","sourcesContent":["import { useMemo, useContext } from \"react\";\nimport {\n CopilotContext,\n CopilotContextParams,\n copilotApiConfigExtrapolator,\n} from \"../context/copilot-context\";\nimport { useChat } from \"ai/react\";\nimport { ChatRequestOptions, CreateMessage, Message } from \"ai\";\nimport { UseChatOptions } from \"ai\";\nimport { defaultCopilotContextCategories } from \"../components\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (\n message: Message | CreateMessage,\n chatRequestOptions?: ChatRequestOptions,\n ) => Promise<string | null | undefined>;\n reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;\n stop: () => void;\n isLoading: boolean;\n input: string;\n setInput: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);\n\n const functionDescriptions = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } = useChat({\n ...options,\n api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,\n id: options.id,\n initialMessages: initialMessagesWithContext,\n experimental_onFunctionCall: getFunctionCallHandler(),\n headers: { ...copilotApiConfig.headers, ...options.headers },\n body: {\n id: options.id,\n functions: functionDescriptions,\n ...copilotApiConfig.body,\n ...options.body,\n },\n });\n\n const visibleMessages = messages.filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n );\n\n return {\n visibleMessages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n"]}
@@ -1,50 +0,0 @@
1
- import './chunk-MRXNTQOX.mjs';
2
- import React from 'react';
3
-
4
- function copilotApiConfigExtrapolator(config) {
5
- return {
6
- get chatApiEndpoint() {
7
- return `${config.chatApiEndpoint}`;
8
- }
9
- };
10
- }
11
- var emptyCopilotContext = {
12
- entryPoints: {},
13
- setEntryPoint: () => {
14
- },
15
- removeEntryPoint: () => {
16
- },
17
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
18
- getFunctionCallHandler: () => returnAndThrowInDebug(),
19
- getContextString: (documents, categories) => returnAndThrowInDebug(),
20
- addContext: () => "",
21
- removeContext: () => {
22
- },
23
- getDocumentsContext: (categories) => returnAndThrowInDebug(),
24
- addDocumentContext: () => returnAndThrowInDebug(),
25
- removeDocumentContext: () => {
26
- },
27
- copilotApiConfig: new class {
28
- get chatApiEndpoint() {
29
- throw new Error(
30
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
31
- );
32
- }
33
- get headers() {
34
- return {};
35
- }
36
- get body() {
37
- return {};
38
- }
39
- }()
40
- };
41
- var CopilotContext = React.createContext(emptyCopilotContext);
42
- function returnAndThrowInDebug(value) {
43
- throw new Error(
44
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
45
- );
46
- }
47
-
48
- export { CopilotContext, copilotApiConfigExtrapolator };
49
- //# sourceMappingURL=out.js.map
50
- //# sourceMappingURL=chunk-HZDMKMAV.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context/copilot-context.tsx"],"names":[],"mappings":";;;;;AAGA,OAAO,WAAW;AAHlB;AA2CO,SAAS,6BAA6B,QAA0B;AACrE,SAAO;AAAA,IACL,IAAI,kBAA0B;AAC5B,aAAO,GAAG,OAAO;AAAA,IACnB;AAAA,EACF;AACF;AAwBA,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,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,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,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,MAAM,cAAoC,mBAAmB;AAE3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT","sourcesContent":["\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\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: (documents: DocumentPointer[], categories: string[]) => string;\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => 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: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => 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 get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = 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"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-JD7BAH7U.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,55 +0,0 @@
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
- export { __async, __objRest, __spreadProps, __spreadValues };
54
- //# sourceMappingURL=out.js.map
55
- //# sourceMappingURL=chunk-MRXNTQOX.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=chunk-QACD2U6P.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
1
- import { CopilotContext } from './chunk-HZDMKMAV.mjs';
2
- import { useContext, useRef, useEffect } from 'react';
3
-
4
- function useMakeCopilotReadable(information, parentId, categories) {
5
- const { addContext, removeContext } = useContext(CopilotContext);
6
- const idRef = useRef();
7
- useEffect(() => {
8
- const id = addContext(information, parentId, categories);
9
- idRef.current = id;
10
- return () => {
11
- removeContext(id);
12
- };
13
- }, [information, parentId, addContext, removeContext]);
14
- return idRef.current;
15
- }
16
-
17
- export { useMakeCopilotReadable };
18
- //# sourceMappingURL=out.js.map
19
- //# sourceMappingURL=chunk-RW25IF4S.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-make-copilot-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAF9C;AAYO,SAAS,uBACd,aACA,UACA,YACoB;AACpB,QAAM,EAAE,YAAY,cAAc,IAAI,WAAW,cAAc;AAC/D,QAAM,QAAQ,OAAe;AAE7B,YAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,aAAa,CAAC;AAErD,SAAO,MAAM;AACf","sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[],\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n"]}
@@ -1,19 +0,0 @@
1
- import { CopilotContext } from './chunk-HZDMKMAV.mjs';
2
- import { useContext, useRef, useEffect } from 'react';
3
-
4
- function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
5
- const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);
6
- const idRef = useRef();
7
- useEffect(() => {
8
- const id = addDocumentContext(document, categories);
9
- idRef.current = id;
10
- return () => {
11
- removeDocumentContext(id);
12
- };
13
- }, [addDocumentContext, removeDocumentContext, ...dependencies]);
14
- return idRef.current;
15
- }
16
-
17
- export { useMakeCopilotDocumentReadable };
18
- //# sourceMappingURL=out.js.map
19
- //# sourceMappingURL=chunk-UBLDQLZM.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-make-copilot-document-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAF9C;AAaO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAI,WAAW,cAAc;AAC/E,QAAM,QAAQ,OAAe;AAE7B,YAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf","sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n"]}