@copilotkit/react-core 0.16.0 → 0.17.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 (142) hide show
  1. package/.turbo/turbo-build.log +168 -134
  2. package/CHANGELOG.md +6 -0
  3. package/dist/components/copilot-provider/copilot-provider-props.d.ts +3 -3
  4. package/dist/components/copilot-provider/copilot-provider-props.mjs +1 -2
  5. package/dist/components/copilot-provider/copilot-provider-props.mjs.map +1 -1
  6. package/dist/components/copilot-provider/copilot-provider.d.ts +3 -3
  7. package/dist/components/copilot-provider/copilot-provider.mjs +468 -7
  8. package/dist/components/copilot-provider/copilot-provider.mjs.map +1 -1
  9. package/dist/components/copilot-provider/index.d.ts +3 -3
  10. package/dist/components/copilot-provider/index.mjs +467 -8
  11. package/dist/components/copilot-provider/index.mjs.map +1 -1
  12. package/dist/components/copilot-provider/standard-copilot-api-config.d.ts +3 -3
  13. package/dist/components/copilot-provider/standard-copilot-api-config.mjs +12 -3
  14. package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -1
  15. package/dist/components/index.d.ts +3 -3
  16. package/dist/components/index.mjs +467 -9
  17. package/dist/components/index.mjs.map +1 -1
  18. package/dist/context/copilot-context.d.ts +4 -8
  19. package/dist/context/copilot-context.mjs +70 -3
  20. package/dist/context/copilot-context.mjs.map +1 -1
  21. package/dist/context/index.d.ts +4 -4
  22. package/dist/context/index.mjs +69 -4
  23. package/dist/context/index.mjs.map +1 -1
  24. package/dist/hooks/index.d.ts +6 -1
  25. package/dist/hooks/index.mjs +654 -14
  26. package/dist/hooks/index.mjs.map +1 -1
  27. package/dist/hooks/use-chat.d.ts +84 -0
  28. package/dist/hooks/use-chat.mjs +461 -0
  29. package/dist/hooks/use-chat.mjs.map +1 -0
  30. package/dist/hooks/use-copilot-chat.d.ts +10 -3
  31. package/dist/hooks/use-copilot-chat.mjs +599 -10
  32. package/dist/hooks/use-copilot-chat.mjs.map +1 -1
  33. package/dist/hooks/use-flat-category-store.mjs +68 -3
  34. package/dist/hooks/use-flat-category-store.mjs.map +1 -1
  35. package/dist/hooks/use-make-copilot-actionable.mjs +95 -4
  36. package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
  37. package/dist/hooks/use-make-copilot-document-readable.mjs +87 -4
  38. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
  39. package/dist/hooks/use-make-copilot-readable.mjs +87 -4
  40. package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
  41. package/dist/hooks/use-tree.mjs +153 -3
  42. package/dist/hooks/use-tree.mjs.map +1 -1
  43. package/dist/index.d.ts +6 -2
  44. package/dist/index.mjs +1204 -21
  45. package/dist/index.mjs.map +1 -1
  46. package/dist/openai/chat-completion-client.d.ts +56 -0
  47. package/dist/openai/chat-completion-client.mjs +360 -0
  48. package/dist/openai/chat-completion-client.mjs.map +1 -0
  49. package/dist/openai/chat-completion-stream.d.ts +21 -0
  50. package/dist/openai/chat-completion-stream.mjs +221 -0
  51. package/dist/openai/chat-completion-stream.mjs.map +1 -0
  52. package/dist/openai/chat-completion-transport.d.ts +40 -0
  53. package/dist/openai/chat-completion-transport.mjs +181 -0
  54. package/dist/openai/chat-completion-transport.mjs.map +1 -0
  55. package/dist/openai/index.d.ts +10 -0
  56. package/dist/openai/index.mjs +221 -0
  57. package/dist/openai/index.mjs.map +1 -0
  58. package/dist/openai-assistants/hooks/index.mjs +235 -14
  59. package/dist/openai-assistants/hooks/index.mjs.map +1 -1
  60. package/dist/openai-assistants/hooks/use-assistants.mjs +52 -8
  61. package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -1
  62. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +236 -13
  63. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
  64. package/dist/openai-assistants/index.mjs +236 -15
  65. package/dist/openai-assistants/index.mjs.map +1 -1
  66. package/dist/openai-assistants/utils/index.mjs +46 -4
  67. package/dist/openai-assistants/utils/index.mjs.map +1 -1
  68. package/dist/openai-assistants/utils/process-message-stream.mjs +46 -3
  69. package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -1
  70. package/dist/types/annotated-function.mjs +0 -2
  71. package/dist/types/annotated-function.mjs.map +1 -1
  72. package/dist/types/base.d.ts +56 -0
  73. package/dist/types/base.mjs +1 -0
  74. package/dist/types/base.mjs.map +1 -0
  75. package/dist/types/document-pointer.mjs +0 -2
  76. package/dist/types/document-pointer.mjs.map +1 -1
  77. package/dist/types/index.d.ts +1 -0
  78. package/dist/types/index.mjs +0 -2
  79. package/dist/types/index.mjs.map +1 -1
  80. package/dist/types/message.d.ts +2 -0
  81. package/dist/types/message.mjs +1 -0
  82. package/dist/types/message.mjs.map +1 -0
  83. package/dist/utils/utils.mjs +0 -2
  84. package/dist/utils/utils.mjs.map +1 -1
  85. package/dist/utils/utils.test.mjs +0 -1
  86. package/dist/utils/utils.test.mjs.map +1 -1
  87. package/package.json +4 -4
  88. package/src/components/copilot-provider/copilot-provider.tsx +4 -5
  89. package/src/context/copilot-context.tsx +1 -12
  90. package/src/context/index.ts +0 -1
  91. package/src/hooks/index.ts +1 -0
  92. package/src/hooks/use-chat.ts +197 -0
  93. package/src/hooks/use-copilot-chat.ts +10 -22
  94. package/src/index.tsx +1 -0
  95. package/src/openai/chat-completion-client.ts +240 -0
  96. package/src/openai/chat-completion-stream.ts +56 -0
  97. package/src/openai/chat-completion-transport.ts +190 -0
  98. package/src/openai/index.tsx +5 -0
  99. package/src/openai-assistants/hooks/use-copilot-chat-v2.ts +2 -2
  100. package/src/types/base.ts +61 -0
  101. package/src/types/index.ts +1 -0
  102. package/src/types/message.ts +0 -0
  103. package/dist/chunk-7GFKOIO7.mjs +0 -3
  104. package/dist/chunk-7GFKOIO7.mjs.map +0 -1
  105. package/dist/chunk-BABVSMJR.mjs +0 -3
  106. package/dist/chunk-BABVSMJR.mjs.map +0 -1
  107. package/dist/chunk-DE37LEZJ.mjs +0 -79
  108. package/dist/chunk-DE37LEZJ.mjs.map +0 -1
  109. package/dist/chunk-EFZPSZWO.mjs +0 -3
  110. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  111. package/dist/chunk-EV26IMLL.mjs +0 -165
  112. package/dist/chunk-EV26IMLL.mjs.map +0 -1
  113. package/dist/chunk-F2JIAPZQ.mjs +0 -13
  114. package/dist/chunk-F2JIAPZQ.mjs.map +0 -1
  115. package/dist/chunk-FRAKUJWH.mjs +0 -3
  116. package/dist/chunk-FRAKUJWH.mjs.map +0 -1
  117. package/dist/chunk-IF64NU27.mjs +0 -125
  118. package/dist/chunk-IF64NU27.mjs.map +0 -1
  119. package/dist/chunk-JD7BAH7U.mjs +0 -3
  120. package/dist/chunk-JD7BAH7U.mjs.map +0 -1
  121. package/dist/chunk-MRXNTQOX.mjs +0 -55
  122. package/dist/chunk-MRXNTQOX.mjs.map +0 -1
  123. package/dist/chunk-MZ5UN3BY.mjs +0 -28
  124. package/dist/chunk-MZ5UN3BY.mjs.map +0 -1
  125. package/dist/chunk-PF7LXYPO.mjs +0 -19
  126. package/dist/chunk-PF7LXYPO.mjs.map +0 -1
  127. package/dist/chunk-QACD2U6P.mjs +0 -3
  128. package/dist/chunk-QACD2U6P.mjs.map +0 -1
  129. package/dist/chunk-RFZQHCNS.mjs +0 -19
  130. package/dist/chunk-RFZQHCNS.mjs.map +0 -1
  131. package/dist/chunk-SPCZTZCY.mjs +0 -3
  132. package/dist/chunk-SPCZTZCY.mjs.map +0 -1
  133. package/dist/chunk-VUY2K2DI.mjs +0 -135
  134. package/dist/chunk-VUY2K2DI.mjs.map +0 -1
  135. package/dist/chunk-WL2MC3E2.mjs +0 -27
  136. package/dist/chunk-WL2MC3E2.mjs.map +0 -1
  137. package/dist/chunk-YGJFU4ZP.mjs +0 -58
  138. package/dist/chunk-YGJFU4ZP.mjs.map +0 -1
  139. package/dist/chunk-YPSGKPDA.mjs +0 -3
  140. package/dist/chunk-YPSGKPDA.mjs.map +0 -1
  141. package/dist/chunk-YULKJPY3.mjs +0 -70
  142. package/dist/chunk-YULKJPY3.mjs.map +0 -1
@@ -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-VUY2K2DI.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-tree.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ACJ;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,gBAAgB,YAAY,CAAC,OAAyB;AAC1D,aAAS,EAAE,MAAM,eAAe,GAAG,CAAC;AAAA,EACtC,GAAG,CAAC,CAAC;AAEL,QAAM,YAAY;AAAA,IAChB,CAAC,eAAiC;AAChC,YAAM,gBAAgB,IAAI,IAAI,UAAU;AAExC,UAAI,SAAS;AACb,WAAK,QAAQ,CAAC,MAAM,UAAU;AAE5B,YAAI,CAAC,qBAAqB,eAAe,KAAK,UAAU,GAAG;AACzD;AAAA,QACF;AAGA,YAAI,UAAU,GAAG;AACf,oBAAU;AAAA,QACZ;AAEA,kBAAU,UAAU,MAAM,GAAG,8BAA8B,OAAO,CAAC,KAAK;AAAA,MAC1E,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO,EAAE,MAAM,YAAY,WAAW,cAAc;AACtD;AAEA,IAAO,mBAAQ;AAEf,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAAI,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAEnF,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type 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,27 +0,0 @@
1
- import { CopilotContext } from './chunk-YGJFU4ZP.mjs';
2
- import { useRef, useContext, useMemo, useEffect } from 'react';
3
- import { nanoid } from 'nanoid';
4
-
5
- function useMakeCopilotActionable(annotatedFunction, dependencies) {
6
- const idRef = useRef(nanoid());
7
- const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);
8
- const memoizedAnnotatedFunction = useMemo(
9
- () => ({
10
- name: annotatedFunction.name,
11
- description: annotatedFunction.description,
12
- argumentAnnotations: annotatedFunction.argumentAnnotations,
13
- implementation: annotatedFunction.implementation
14
- }),
15
- dependencies
16
- );
17
- useEffect(() => {
18
- setEntryPoint(idRef.current, memoizedAnnotatedFunction);
19
- return () => {
20
- removeEntryPoint(idRef.current);
21
- };
22
- }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
23
- }
24
-
25
- export { useMakeCopilotActionable };
26
- //# sourceMappingURL=out.js.map
27
- //# sourceMappingURL=chunk-WL2MC3E2.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-make-copilot-actionable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,QAAQ,YAAY,WAAW,eAAe;AAGvD,SAAS,cAAc;AAEhB,SAAS,yBACd,mBACA,cACA;AACA,QAAM,QAAQ,OAAO,OAAO,CAAC;AAC7B,QAAM,EAAE,eAAe,iBAAiB,IAAI,WAAW,cAAc;AAErE,QAAM,4BAA4D;AAAA,IAChE,OAAO;AAAA,MACL,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,qBAAqB,kBAAkB;AAAA,MACvC,gBAAgB,kBAAkB;AAAA,IACpC;AAAA,IACA;AAAA,EACF;AAEA,YAAU,MAAM;AACd,kBAAc,MAAM,SAAS,yBAAqD;AAElF,WAAO,MAAM;AACX,uBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,2BAA2B,eAAe,gBAAgB,CAAC;AACjE","sourcesContent":["\"use client\";\n\nimport { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { nanoid } from \"nanoid\";\n\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[],\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies,\n );\n\n useEffect(() => {\n setEntryPoint(idRef.current, memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n"]}
@@ -1,58 +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
- get chatApiEndpointV2() {
10
- return `${config.chatApiEndpointV2}`;
11
- }
12
- };
13
- }
14
- var emptyCopilotContext = {
15
- entryPoints: {},
16
- setEntryPoint: () => {
17
- },
18
- removeEntryPoint: () => {
19
- },
20
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
21
- getFunctionCallHandler: () => returnAndThrowInDebug(),
22
- getContextString: (documents, categories) => returnAndThrowInDebug(),
23
- addContext: () => "",
24
- removeContext: () => {
25
- },
26
- getDocumentsContext: (categories) => returnAndThrowInDebug(),
27
- addDocumentContext: () => returnAndThrowInDebug(),
28
- removeDocumentContext: () => {
29
- },
30
- copilotApiConfig: new class {
31
- get chatApiEndpoint() {
32
- throw new Error(
33
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
34
- );
35
- }
36
- get chatApiEndpointV2() {
37
- throw new Error(
38
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
39
- );
40
- }
41
- get headers() {
42
- return {};
43
- }
44
- get body() {
45
- return {};
46
- }
47
- }()
48
- };
49
- var CopilotContext = React.createContext(emptyCopilotContext);
50
- function returnAndThrowInDebug(value) {
51
- throw new Error(
52
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
53
- );
54
- }
55
-
56
- export { CopilotContext, copilotApiConfigExtrapolator };
57
- //# sourceMappingURL=out.js.map
58
- //# sourceMappingURL=chunk-YGJFU4ZP.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context/copilot-context.tsx"],"names":[],"mappings":";;;;;AAGA,OAAO,WAAW;AA6CX,SAAS,6BAA6B,QAA0B;AACrE,SAAO;AAAA,IACL,IAAI,kBAA0B;AAC5B,aAAO,GAAG,OAAO;AAAA,IACnB;AAAA,IACA,IAAI,oBAA4B;AAC9B,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,oBAA4B;AAC9B,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 * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: 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 get chatApiEndpointV2(): string {\n return `${config.chatApiEndpointV2}`;\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 addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\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 chatApiEndpointV2(): 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-YPSGKPDA.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,70 +0,0 @@
1
- import { nanoid } from 'nanoid';
2
- import { useReducer, useCallback } from 'react';
3
-
4
- // src/hooks/use-flat-category-store.ts
5
- var useFlatCategoryStore = () => {
6
- const [elements, dispatch] = useReducer(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
7
- const addElement = useCallback((value, categories) => {
8
- const newId = nanoid();
9
- dispatch({
10
- type: "ADD_ELEMENT",
11
- value,
12
- id: newId,
13
- categories
14
- });
15
- return newId;
16
- }, []);
17
- const removeElement = useCallback((id) => {
18
- dispatch({ type: "REMOVE_ELEMENT", id });
19
- }, []);
20
- const allElements = useCallback(
21
- (categories) => {
22
- const categoriesSet = new Set(categories);
23
- const result = [];
24
- elements.forEach((element) => {
25
- if (setsHaveIntersection(categoriesSet, element.categories)) {
26
- result.push(element.value);
27
- }
28
- });
29
- return result;
30
- },
31
- [elements]
32
- );
33
- return { addElement, removeElement, allElements };
34
- };
35
- var use_flat_category_store_default = useFlatCategoryStore;
36
- function flatCategoryStoreReducer(state, action) {
37
- switch (action.type) {
38
- case "ADD_ELEMENT": {
39
- const { value, id, categories } = action;
40
- const newElement = {
41
- id,
42
- value,
43
- categories: new Set(categories)
44
- };
45
- const newState = new Map(state);
46
- newState.set(id, newElement);
47
- return newState;
48
- }
49
- case "REMOVE_ELEMENT": {
50
- const newState = new Map(state);
51
- newState.delete(action.id);
52
- return newState;
53
- }
54
- default:
55
- return state;
56
- }
57
- }
58
- function setsHaveIntersection(setA, setB) {
59
- const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
60
- for (let item of smallerSet) {
61
- if (largerSet.has(item)) {
62
- return true;
63
- }
64
- }
65
- return false;
66
- }
67
-
68
- export { use_flat_category_store_default };
69
- //# sourceMappingURL=out.js.map
70
- //# sourceMappingURL=chunk-YULKJPY3.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-flat-category-store.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAgBxC,IAAM,uBAAuB,MAAwC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MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAAI,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAEnF,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type FlatCategoryStoreId = string;\n\nexport interface UseFlatCategoryStoreReturn<T> {\n addElement: (value: T, categories: string[]) => FlatCategoryStoreId;\n removeElement: (id: FlatCategoryStoreId) => void;\n allElements: (categories: string[]) => T[];\n}\n\ninterface FlatCategoryStoreElement<T> {\n id: FlatCategoryStoreId;\n value: T;\n categories: Set<string>;\n}\n\nconst useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {\n const [elements, dispatch] = useReducer<\n React.Reducer<Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>, Action<T>>\n >(flatCategoryStoreReducer, new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>());\n\n const addElement = useCallback((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 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] = 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"]}