@copilotkit/react-core 0.13.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.
- package/.turbo/turbo-build.log +21 -21
- package/CHANGELOG.md +6 -0
- package/dist/{chunk-3BOHSSKR.mjs → chunk-C4KF43WB.mjs} +3 -9
- package/dist/chunk-C4KF43WB.mjs.map +1 -0
- package/dist/{chunk-PRPQRCVY.mjs → chunk-FVU5RFVX.mjs} +4 -6
- package/dist/chunk-FVU5RFVX.mjs.map +1 -0
- package/dist/{chunk-X24EEZGG.mjs → chunk-HZDMKMAV.mjs} +1 -1
- package/dist/chunk-HZDMKMAV.mjs.map +1 -0
- package/dist/{chunk-G5LZS72K.mjs → chunk-RW25IF4S.mjs} +2 -2
- package/dist/{chunk-G5LZS72K.mjs.map → chunk-RW25IF4S.mjs.map} +1 -1
- package/dist/{chunk-AMFRKVFT.mjs → chunk-UBLDQLZM.mjs} +2 -2
- package/dist/chunk-UBLDQLZM.mjs.map +1 -0
- package/dist/{chunk-P3QUZTN7.mjs → chunk-XFSUVTIQ.mjs} +3 -6
- package/dist/chunk-XFSUVTIQ.mjs.map +1 -0
- package/dist/{chunk-63ILXW5V.mjs → chunk-YULKJPY3.mjs} +12 -18
- package/dist/chunk-YULKJPY3.mjs.map +1 -0
- package/dist/{chunk-FIYUJVWU.mjs → chunk-ZIFCJ774.mjs} +10 -13
- package/dist/chunk-ZIFCJ774.mjs.map +1 -0
- package/dist/components/copilot-provider.mjs +4 -4
- package/dist/components/index.mjs +4 -4
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.mjs +8 -8
- package/dist/hooks/use-copilot-chat.mjs +5 -5
- package/dist/hooks/use-flat-category-store.mjs +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-readable.mjs +2 -2
- package/dist/hooks/use-tree.mjs +1 -1
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
- package/src/components/copilot-provider.tsx +24 -40
- package/src/components/index.ts +1 -4
- package/src/context/copilot-context.tsx +6 -17
- package/src/hooks/use-copilot-chat.ts +17 -22
- package/src/hooks/use-flat-category-store.ts +15 -25
- package/src/hooks/use-make-copilot-actionable.ts +3 -6
- package/src/hooks/use-make-copilot-document-readable.ts +2 -3
- package/src/hooks/use-make-copilot-readable.ts +1 -1
- package/src/hooks/use-tree.ts +10 -28
- package/dist/chunk-3BOHSSKR.mjs.map +0 -1
- package/dist/chunk-63ILXW5V.mjs.map +0 -1
- package/dist/chunk-AMFRKVFT.mjs.map +0 -1
- package/dist/chunk-FIYUJVWU.mjs.map +0 -1
- package/dist/chunk-P3QUZTN7.mjs.map +0 -1
- package/dist/chunk-PRPQRCVY.mjs.map +0 -1
- package/dist/chunk-X24EEZGG.mjs.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @copilotkit/react-core@0.
|
|
2
|
+
> @copilotkit/react-core@0.14.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
|
|
3
3
|
> tsup --treeshake
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.tsx, src/components/copilot-provider.tsx, src/components/index.ts, src/context/copilot-context.tsx, src/context/index.ts, src/hooks/index.ts, src/hooks/use-copilot-chat.ts, src/hooks/use-flat-category-store.ts, src/hooks/use-make-copilot-actionable.ts, src/hooks/use-make-copilot-document-readable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/types/annotated-function.ts, src/types/document-pointer.ts, src/types/index.ts, src/utils/utils.test.ts, src/utils/utils.ts
|
|
@@ -22,8 +22,8 @@ Generated an empty chunk: "chunk-JD7BAH7U".
|
|
|
22
22
|
[32mESM[39m [1mdist/components/copilot-provider.mjs [22m[32m295.00 B[39m
|
|
23
23
|
[32mESM[39m [1mdist/context/copilot-context.mjs [22m[32m194.00 B[39m
|
|
24
24
|
[32mESM[39m [1mdist/chunk-YPSGKPDA.mjs [22m[32m76.00 B[39m
|
|
25
|
-
[32mESM[39m [1mdist/chunk-QACD2U6P.mjs [22m[32m76.00 B[39m
|
|
26
25
|
[32mESM[39m [1mdist/chunk-JD7BAH7U.mjs [22m[32m76.00 B[39m
|
|
26
|
+
[32mESM[39m [1mdist/chunk-QACD2U6P.mjs [22m[32m76.00 B[39m
|
|
27
27
|
[32mESM[39m [1mdist/chunk-MRXNTQOX.mjs [22m[32m1.92 KB[39m
|
|
28
28
|
[32mESM[39m [1mdist/hooks/use-make-copilot-document-readable.mjs [22m[32m231.00 B[39m
|
|
29
29
|
[32mESM[39m [1mdist/hooks/use-make-copilot-readable.mjs [22m[32m214.00 B[39m
|
|
@@ -32,16 +32,16 @@ Generated an empty chunk: "chunk-JD7BAH7U".
|
|
|
32
32
|
[32mESM[39m [1mdist/components/index.mjs [22m[32m316.00 B[39m
|
|
33
33
|
[32mESM[39m [1mdist/context/index.mjs [22m[32m216.00 B[39m
|
|
34
34
|
[32mESM[39m [1mdist/hooks/index.mjs [22m[32m548.00 B[39m
|
|
35
|
-
[32mESM[39m [1mdist/chunk-
|
|
36
|
-
[32mESM[39m [1mdist/chunk-
|
|
37
|
-
[32mESM[39m [1mdist/chunk-
|
|
35
|
+
[32mESM[39m [1mdist/chunk-XFSUVTIQ.mjs [22m[32m954.00 B[39m
|
|
36
|
+
[32mESM[39m [1mdist/chunk-UBLDQLZM.mjs [22m[32m677.00 B[39m
|
|
37
|
+
[32mESM[39m [1mdist/chunk-RW25IF4S.mjs [22m[32m626.00 B[39m
|
|
38
38
|
[32mESM[39m [1mdist/hooks/use-copilot-chat.mjs [22m[32m347.00 B[39m
|
|
39
|
-
[32mESM[39m [1mdist/chunk-
|
|
40
|
-
[32mESM[39m [1mdist/chunk-
|
|
41
|
-
[32mESM[39m [1mdist/chunk-
|
|
42
|
-
[32mESM[39m [1mdist/chunk-
|
|
39
|
+
[32mESM[39m [1mdist/chunk-FVU5RFVX.mjs [22m[32m2.95 KB[39m
|
|
40
|
+
[32mESM[39m [1mdist/chunk-C4KF43WB.mjs [22m[32m3.89 KB[39m
|
|
41
|
+
[32mESM[39m [1mdist/chunk-ZIFCJ774.mjs [22m[32m4.87 KB[39m
|
|
42
|
+
[32mESM[39m [1mdist/chunk-HZDMKMAV.mjs [22m[32m1.32 KB[39m
|
|
43
43
|
[32mESM[39m [1mdist/hooks/use-flat-category-store.mjs [22m[32m200.00 B[39m
|
|
44
|
-
[32mESM[39m [1mdist/chunk-
|
|
44
|
+
[32mESM[39m [1mdist/chunk-YULKJPY3.mjs [22m[32m1.87 KB[39m
|
|
45
45
|
[32mESM[39m [1mdist/utils/utils.mjs [22m[32m67.00 B[39m
|
|
46
46
|
[32mESM[39m [1mdist/types/annotated-function.mjs [22m[32m80.00 B[39m
|
|
47
47
|
[32mESM[39m [1mdist/types/document-pointer.mjs [22m[32m78.00 B[39m
|
|
@@ -52,8 +52,8 @@ Generated an empty chunk: "chunk-JD7BAH7U".
|
|
|
52
52
|
[32mESM[39m [1mdist/components/copilot-provider.mjs.map [22m[32m51.00 B[39m
|
|
53
53
|
[32mESM[39m [1mdist/context/copilot-context.mjs.map [22m[32m51.00 B[39m
|
|
54
54
|
[32mESM[39m [1mdist/chunk-YPSGKPDA.mjs.map [22m[32m51.00 B[39m
|
|
55
|
-
[32mESM[39m [1mdist/chunk-QACD2U6P.mjs.map [22m[32m51.00 B[39m
|
|
56
55
|
[32mESM[39m [1mdist/chunk-JD7BAH7U.mjs.map [22m[32m51.00 B[39m
|
|
56
|
+
[32mESM[39m [1mdist/chunk-QACD2U6P.mjs.map [22m[32m51.00 B[39m
|
|
57
57
|
[32mESM[39m [1mdist/chunk-MRXNTQOX.mjs.map [22m[32m71.00 B[39m
|
|
58
58
|
[32mESM[39m [1mdist/hooks/use-make-copilot-document-readable.mjs.map [22m[32m51.00 B[39m
|
|
59
59
|
[32mESM[39m [1mdist/hooks/use-make-copilot-readable.mjs.map [22m[32m51.00 B[39m
|
|
@@ -62,23 +62,23 @@ Generated an empty chunk: "chunk-JD7BAH7U".
|
|
|
62
62
|
[32mESM[39m [1mdist/components/index.mjs.map [22m[32m51.00 B[39m
|
|
63
63
|
[32mESM[39m [1mdist/context/index.mjs.map [22m[32m51.00 B[39m
|
|
64
64
|
[32mESM[39m [1mdist/hooks/index.mjs.map [22m[32m51.00 B[39m
|
|
65
|
-
[32mESM[39m [1mdist/chunk-
|
|
66
|
-
[32mESM[39m [1mdist/chunk-
|
|
67
|
-
[32mESM[39m [1mdist/chunk-
|
|
65
|
+
[32mESM[39m [1mdist/chunk-XFSUVTIQ.mjs.map [22m[32m1.67 KB[39m
|
|
66
|
+
[32mESM[39m [1mdist/chunk-UBLDQLZM.mjs.map [22m[32m1.42 KB[39m
|
|
67
|
+
[32mESM[39m [1mdist/chunk-RW25IF4S.mjs.map [22m[32m1.47 KB[39m
|
|
68
68
|
[32mESM[39m [1mdist/hooks/use-copilot-chat.mjs.map [22m[32m51.00 B[39m
|
|
69
|
-
[32mESM[39m [1mdist/chunk-
|
|
70
|
-
[32mESM[39m [1mdist/chunk-
|
|
71
|
-
[32mESM[39m [1mdist/chunk-
|
|
72
|
-
[32mESM[39m [1mdist/chunk-
|
|
69
|
+
[32mESM[39m [1mdist/chunk-FVU5RFVX.mjs.map [22m[32m4.80 KB[39m
|
|
70
|
+
[32mESM[39m [1mdist/chunk-C4KF43WB.mjs.map [22m[32m8.26 KB[39m
|
|
71
|
+
[32mESM[39m [1mdist/chunk-ZIFCJ774.mjs.map [22m[32m9.44 KB[39m
|
|
72
|
+
[32mESM[39m [1mdist/chunk-HZDMKMAV.mjs.map [22m[32m4.22 KB[39m
|
|
73
73
|
[32mESM[39m [1mdist/hooks/use-flat-category-store.mjs.map [22m[32m51.00 B[39m
|
|
74
|
-
[32mESM[39m [1mdist/chunk-
|
|
74
|
+
[32mESM[39m [1mdist/chunk-YULKJPY3.mjs.map [22m[32m4.21 KB[39m
|
|
75
75
|
[32mESM[39m [1mdist/utils/utils.mjs.map [22m[32m51.00 B[39m
|
|
76
76
|
[32mESM[39m [1mdist/types/annotated-function.mjs.map [22m[32m51.00 B[39m
|
|
77
77
|
[32mESM[39m [1mdist/types/document-pointer.mjs.map [22m[32m51.00 B[39m
|
|
78
78
|
[32mESM[39m [1mdist/utils/utils.test.mjs.map [22m[32m351.00 B[39m
|
|
79
|
-
[32mESM[39m ⚡️ Build success in
|
|
79
|
+
[32mESM[39m ⚡️ Build success in 299ms
|
|
80
80
|
[34mDTS[39m Build start
|
|
81
|
-
[32mDTS[39m ⚡️ Build success in
|
|
81
|
+
[32mDTS[39m ⚡️ Build success in 1543ms
|
|
82
82
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m847.00 B[39m
|
|
83
83
|
[32mDTS[39m [1mdist/components/copilot-provider.d.ts [22m[32m378.00 B[39m
|
|
84
84
|
[32mDTS[39m [1mdist/context/copilot-context.d.ts [22m[32m2.03 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -52,10 +52,7 @@ var printNode = (node, prefix = "", indentLevel = 0) => {
|
|
|
52
52
|
node.children.forEach(
|
|
53
53
|
(child, index) => output += printNode(
|
|
54
54
|
child,
|
|
55
|
-
`${childPrePrefix}${treeIndentationRepresentation(
|
|
56
|
-
index,
|
|
57
|
-
indentLevel + 1
|
|
58
|
-
)}. `,
|
|
55
|
+
`${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
|
|
59
56
|
indentLevel + 1
|
|
60
57
|
)
|
|
61
58
|
);
|
|
@@ -114,10 +111,7 @@ var useTree = () => {
|
|
|
114
111
|
if (index !== 0) {
|
|
115
112
|
output += "\n";
|
|
116
113
|
}
|
|
117
|
-
output += printNode(
|
|
118
|
-
node,
|
|
119
|
-
`${treeIndentationRepresentation(index, 0)}. `
|
|
120
|
-
);
|
|
114
|
+
output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
|
|
121
115
|
});
|
|
122
116
|
return output;
|
|
123
117
|
},
|
|
@@ -138,4 +132,4 @@ function setsHaveIntersection(setA, setB) {
|
|
|
138
132
|
|
|
139
133
|
export { use_tree_default };
|
|
140
134
|
//# sourceMappingURL=out.js.map
|
|
141
|
-
//# sourceMappingURL=chunk-
|
|
135
|
+
//# sourceMappingURL=chunk-C4KF43WB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-tree.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAkCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,SAAS;AAC1C,QAAI,KAAK,OAAO,IAAI;AAClB,YAAM,UAAU,iCAAK,OAAL,EAAW,UAAU,WAAW,KAAK,UAAU,EAAE,EAAE;AACnE,aAAO,KAAK,OAAO;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEA,IAAM,UAAU,CAAC,OAAa,SAAmB,aAAgC;AAC/E,MAAI,CAAC,UAAU;AACb,WAAO,CAAC,GAAG,OAAO,OAAO;AAAA,EAC3B;AACA,SAAO,MAAM,IAAI,CAAC,SAAS;AACzB,QAAI,KAAK,OAAO,UAAU;AACxB,aAAO,iCAAK,OAAL,EAAW,UAAU,CAAC,GAAG,KAAK,UAAU,OAAO,EAAE;AAAA,IAC1D,WAAW,KAAK,SAAS,QAAQ;AAC/B,aAAO,iCAAK,OAAL,EAAW,UAAU,QAAQ,KAAK,UAAU,SAAS,QAAQ,EAAE;AAAA,IACxE;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,IAAM,gCAAgC,CAAC,OAAe,gBAAgC;AACpF,MAAI,gBAAgB,GAAG;AACrB,YAAQ,QAAQ,GAAG,SAAS;AAAA,EAC9B,WAAW,gBAAgB,GAAG;AAC5B,WAAO,OAAO,aAAa,KAAK,KAAK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back, 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,5 +1,5 @@
|
|
|
1
|
-
import { defaultCopilotContextCategories } from './chunk-
|
|
2
|
-
import { CopilotContext, copilotApiConfigExtrapolator } from './chunk-
|
|
1
|
+
import { defaultCopilotContextCategories } from './chunk-ZIFCJ774.mjs';
|
|
2
|
+
import { CopilotContext, copilotApiConfigExtrapolator } from './chunk-HZDMKMAV.mjs';
|
|
3
3
|
import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
|
|
4
4
|
import { useContext, useMemo } from 'react';
|
|
5
5
|
import { useChat } from 'ai/react';
|
|
@@ -25,9 +25,7 @@ function useCopilotChat(_a) {
|
|
|
25
25
|
role: "system"
|
|
26
26
|
};
|
|
27
27
|
}, [getContextString, makeSystemMessage]);
|
|
28
|
-
const initialMessagesWithContext = [systemMessage].concat(
|
|
29
|
-
options.initialMessages || []
|
|
30
|
-
);
|
|
28
|
+
const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);
|
|
31
29
|
const functionDescriptions = useMemo(() => {
|
|
32
30
|
return getChatCompletionFunctionDescriptions();
|
|
33
31
|
}, [getChatCompletionFunctionDescriptions]);
|
|
@@ -79,4 +77,4 @@ If you would like to call a function, call it without saying anything else.
|
|
|
79
77
|
|
|
80
78
|
export { defaultSystemMessage, useCopilotChat };
|
|
81
79
|
//# sourceMappingURL=out.js.map
|
|
82
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-FVU5RFVX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-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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"]}
|
|
@@ -0,0 +1 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { CopilotContext } from './chunk-
|
|
1
|
+
import { CopilotContext } from './chunk-HZDMKMAV.mjs';
|
|
2
2
|
import { useContext, useRef, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
function useMakeCopilotReadable(information, parentId, categories) {
|
|
@@ -16,4 +16,4 @@ function useMakeCopilotReadable(information, parentId, categories) {
|
|
|
16
16
|
|
|
17
17
|
export { useMakeCopilotReadable };
|
|
18
18
|
//# sourceMappingURL=out.js.map
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
19
|
+
//# sourceMappingURL=chunk-RW25IF4S.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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[]
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { CopilotContext } from './chunk-
|
|
1
|
+
import { CopilotContext } from './chunk-HZDMKMAV.mjs';
|
|
2
2
|
import { useContext, useRef, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
@@ -16,4 +16,4 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
16
16
|
|
|
17
17
|
export { useMakeCopilotDocumentReadable };
|
|
18
18
|
//# sourceMappingURL=out.js.map
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
19
|
+
//# sourceMappingURL=chunk-UBLDQLZM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CopilotContext } from './chunk-
|
|
1
|
+
import { CopilotContext } from './chunk-HZDMKMAV.mjs';
|
|
2
2
|
import { useRef, useContext, useMemo, useEffect } from 'react';
|
|
3
3
|
import { nanoid } from 'nanoid';
|
|
4
4
|
|
|
@@ -15,10 +15,7 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
|
15
15
|
dependencies
|
|
16
16
|
);
|
|
17
17
|
useEffect(() => {
|
|
18
|
-
setEntryPoint(
|
|
19
|
-
idRef.current,
|
|
20
|
-
memoizedAnnotatedFunction
|
|
21
|
-
);
|
|
18
|
+
setEntryPoint(idRef.current, memoizedAnnotatedFunction);
|
|
22
19
|
return () => {
|
|
23
20
|
removeEntryPoint(idRef.current);
|
|
24
21
|
};
|
|
@@ -27,4 +24,4 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
|
27
24
|
|
|
28
25
|
export { useMakeCopilotActionable };
|
|
29
26
|
//# sourceMappingURL=out.js.map
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-XFSUVTIQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-make-copilot-actionable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,QAAQ,YAAY,WAAW,eAAe;AAGvD,SAAS,cAAc;AALvB;AAOO,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"]}
|
|
@@ -3,23 +3,17 @@ import { useReducer, useCallback } from 'react';
|
|
|
3
3
|
|
|
4
4
|
// src/hooks/use-flat-category-store.ts
|
|
5
5
|
var useFlatCategoryStore = () => {
|
|
6
|
-
const [elements, dispatch] = useReducer(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
categories
|
|
18
|
-
});
|
|
19
|
-
return newId;
|
|
20
|
-
},
|
|
21
|
-
[]
|
|
22
|
-
);
|
|
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
|
+
}, []);
|
|
23
17
|
const removeElement = useCallback((id) => {
|
|
24
18
|
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
25
19
|
}, []);
|
|
@@ -73,4 +67,4 @@ function setsHaveIntersection(setA, setB) {
|
|
|
73
67
|
|
|
74
68
|
export { use_flat_category_store_default };
|
|
75
69
|
//# sourceMappingURL=out.js.map
|
|
76
|
-
//# sourceMappingURL=chunk-
|
|
70
|
+
//# sourceMappingURL=chunk-YULKJPY3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KAAK,kBAAkB;AACrB,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,OAAO,OAAO,EAAE;AACzB,aAAO;AAAA,IACT;AAAA,IACA;AACE,aAAO;AAAA,EACX;AACF;AAEA,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 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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { use_tree_default } from './chunk-
|
|
2
|
-
import { CopilotContext } from './chunk-
|
|
3
|
-
import { use_flat_category_store_default } from './chunk-
|
|
1
|
+
import { use_tree_default } from './chunk-C4KF43WB.mjs';
|
|
2
|
+
import { CopilotContext } from './chunk-HZDMKMAV.mjs';
|
|
3
|
+
import { use_flat_category_store_default } from './chunk-YULKJPY3.mjs';
|
|
4
4
|
import { __spreadProps, __spreadValues, __async, __objRest } from './chunk-MRXNTQOX.mjs';
|
|
5
5
|
import { useState, useCallback } from 'react';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -18,16 +18,13 @@ function CopilotProvider({
|
|
|
18
18
|
removeElement: removeDocument,
|
|
19
19
|
allElements: allDocuments
|
|
20
20
|
} = use_flat_category_store_default();
|
|
21
|
-
const setEntryPoint = useCallback(
|
|
22
|
-
(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[id]: entryPoint
|
|
26
|
-
});
|
|
21
|
+
const setEntryPoint = useCallback((id, entryPoint) => {
|
|
22
|
+
setEntryPoints((prevPoints) => {
|
|
23
|
+
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
24
|
+
[id]: entryPoint
|
|
27
25
|
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
);
|
|
26
|
+
});
|
|
27
|
+
}, []);
|
|
31
28
|
const removeEntryPoint = useCallback((id) => {
|
|
32
29
|
setEntryPoints((prevPoints) => {
|
|
33
30
|
const newPoints = __spreadValues({}, prevPoints);
|
|
@@ -158,4 +155,4 @@ function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
|
|
|
158
155
|
|
|
159
156
|
export { CopilotProvider, defaultCopilotContextCategories };
|
|
160
157
|
//# sourceMappingURL=out.js.map
|
|
161
|
-
//# sourceMappingURL=chunk-
|
|
158
|
+
//# sourceMappingURL=chunk-ZIFCJ774.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/copilot-provider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,SAAoB,aAAa,gBAAgB;AA4G7C;AA9GJ;AAUO,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKgB;AACd,QAAM,CAAC,aAAa,cAAc,IAAI,SAAmD,CAAC,CAAC;AAE3F,QAAM,EAAE,YAAY,eAAe,UAAU,IAAI,iBAAQ;AACzD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA,EACf,IAAI,gCAAsC;AAE1C,QAAM,gBAAgB,YAAY,CAAC,IAAY,eAAyC;AACtF,mBAAe,CAAC,eAAe;AAC7B,aAAO,iCACF,aADE;AAAA,QAEL,CAAC,KAAK;AAAA,MACR;AAAA,IACF,CAAC;A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AQ;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAA8D;AAAA,IAChE,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["\"use client\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ReactNode, useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../context/copilot-context\";\nimport useTree from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\nimport useFlatCategoryStore from \"../hooks/use-flat-category-store\";\n\nexport function CopilotProvider({\n chatApiEndpoint,\n headers,\n body,\n children,\n}: {\n chatApiEndpoint: string;\n headers?: Record<string, string>;\n body?: Record<string, any>;\n children: ReactNode;\n}): JSX.Element {\n const [entryPoints, setEntryPoints] = useState<Record<string, AnnotatedFunction<any[]>>>({});\n\n const { addElement, removeElement, printTree } = useTree();\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback((id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n }, []);\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${document.sourceApplication}):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree],\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories,\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement],\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement],\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(() => {\n return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments],\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument],\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument],\n );\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: {\n chatApiEndpoint,\n headers: headers || {},\n body: body || {},\n },\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[],\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<string, AnnotatedFunction<any[]>> = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction = entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[arg.name as keyof typeof parsedFunctionCallArguments],\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[],\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { CopilotProvider, defaultCopilotContextCategories } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
1
|
+
export { CopilotProvider, defaultCopilotContextCategories } from '../chunk-ZIFCJ774.mjs';
|
|
2
|
+
import '../chunk-C4KF43WB.mjs';
|
|
3
|
+
import '../chunk-HZDMKMAV.mjs';
|
|
4
|
+
import '../chunk-YULKJPY3.mjs';
|
|
5
5
|
import '../chunk-MRXNTQOX.mjs';
|
|
6
6
|
//# sourceMappingURL=out.js.map
|
|
7
7
|
//# sourceMappingURL=copilot-provider.mjs.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import '../chunk-JD7BAH7U.mjs';
|
|
2
|
-
export { CopilotProvider, defaultCopilotContextCategories } from '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
2
|
+
export { CopilotProvider, defaultCopilotContextCategories } from '../chunk-ZIFCJ774.mjs';
|
|
3
|
+
import '../chunk-C4KF43WB.mjs';
|
|
4
|
+
import '../chunk-HZDMKMAV.mjs';
|
|
5
|
+
import '../chunk-YULKJPY3.mjs';
|
|
6
6
|
import '../chunk-MRXNTQOX.mjs';
|
|
7
7
|
//# sourceMappingURL=out.js.map
|
|
8
8
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CopilotContext, copilotApiConfigExtrapolator } from '../chunk-
|
|
1
|
+
export { CopilotContext, copilotApiConfigExtrapolator } from '../chunk-HZDMKMAV.mjs';
|
|
2
2
|
import '../chunk-MRXNTQOX.mjs';
|
|
3
3
|
//# sourceMappingURL=out.js.map
|
|
4
4
|
//# sourceMappingURL=copilot-context.mjs.map
|
package/dist/context/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../chunk-YPSGKPDA.mjs';
|
|
2
|
-
export { CopilotContext, copilotApiConfigExtrapolator } from '../chunk-
|
|
2
|
+
export { CopilotContext, copilotApiConfigExtrapolator } from '../chunk-HZDMKMAV.mjs';
|
|
3
3
|
import '../chunk-MRXNTQOX.mjs';
|
|
4
4
|
//# sourceMappingURL=out.js.map
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import '../chunk-QACD2U6P.mjs';
|
|
2
|
-
export { useMakeCopilotActionable } from '../chunk-
|
|
3
|
-
export { useMakeCopilotDocumentReadable } from '../chunk-
|
|
4
|
-
export { useMakeCopilotReadable } from '../chunk-
|
|
5
|
-
export { useCopilotChat } from '../chunk-
|
|
2
|
+
export { useMakeCopilotActionable } from '../chunk-XFSUVTIQ.mjs';
|
|
3
|
+
export { useMakeCopilotDocumentReadable } from '../chunk-UBLDQLZM.mjs';
|
|
4
|
+
export { useMakeCopilotReadable } from '../chunk-RW25IF4S.mjs';
|
|
5
|
+
export { useCopilotChat } from '../chunk-FVU5RFVX.mjs';
|
|
6
6
|
import '../chunk-JD7BAH7U.mjs';
|
|
7
|
-
import '../chunk-
|
|
8
|
-
import '../chunk-
|
|
9
|
-
import '../chunk-
|
|
10
|
-
import '../chunk-
|
|
7
|
+
import '../chunk-ZIFCJ774.mjs';
|
|
8
|
+
import '../chunk-C4KF43WB.mjs';
|
|
9
|
+
import '../chunk-HZDMKMAV.mjs';
|
|
10
|
+
import '../chunk-YULKJPY3.mjs';
|
|
11
11
|
import '../chunk-MRXNTQOX.mjs';
|
|
12
12
|
//# sourceMappingURL=out.js.map
|
|
13
13
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { defaultSystemMessage, useCopilotChat } from '../chunk-
|
|
1
|
+
export { defaultSystemMessage, useCopilotChat } from '../chunk-FVU5RFVX.mjs';
|
|
2
2
|
import '../chunk-JD7BAH7U.mjs';
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
6
|
-
import '../chunk-
|
|
3
|
+
import '../chunk-ZIFCJ774.mjs';
|
|
4
|
+
import '../chunk-C4KF43WB.mjs';
|
|
5
|
+
import '../chunk-HZDMKMAV.mjs';
|
|
6
|
+
import '../chunk-YULKJPY3.mjs';
|
|
7
7
|
import '../chunk-MRXNTQOX.mjs';
|
|
8
8
|
//# sourceMappingURL=out.js.map
|
|
9
9
|
//# sourceMappingURL=use-copilot-chat.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { use_flat_category_store_default as default } from '../chunk-
|
|
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-
|
|
2
|
-
import '../chunk-
|
|
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,5 +1,5 @@
|
|
|
1
|
-
export { useMakeCopilotDocumentReadable } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
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-
|
|
2
|
-
import '../chunk-
|
|
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
|
package/dist/hooks/use-tree.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import './chunk-EFZPSZWO.mjs';
|
|
2
2
|
import './chunk-YPSGKPDA.mjs';
|
|
3
3
|
import './chunk-QACD2U6P.mjs';
|
|
4
|
-
export { useMakeCopilotActionable } from './chunk-
|
|
5
|
-
export { useMakeCopilotDocumentReadable } from './chunk-
|
|
6
|
-
export { useMakeCopilotReadable } from './chunk-
|
|
7
|
-
export { useCopilotChat } from './chunk-
|
|
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
8
|
import './chunk-JD7BAH7U.mjs';
|
|
9
|
-
export { CopilotProvider, defaultCopilotContextCategories } from './chunk-
|
|
10
|
-
import './chunk-
|
|
11
|
-
export { CopilotContext, copilotApiConfigExtrapolator } from './chunk-
|
|
12
|
-
import './chunk-
|
|
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
|
@@ -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
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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) => {
|
|
@@ -54,9 +49,7 @@ export function CopilotProvider({
|
|
|
54
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,25 +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
64
|
(
|
|
72
65
|
context: string,
|
|
73
66
|
parentId?: string,
|
|
74
|
-
categories: string[] = defaultCopilotContextCategories
|
|
67
|
+
categories: string[] = defaultCopilotContextCategories,
|
|
75
68
|
) => {
|
|
76
69
|
return addElement(context, categories, parentId);
|
|
77
70
|
},
|
|
78
|
-
[addElement]
|
|
71
|
+
[addElement],
|
|
79
72
|
);
|
|
80
73
|
|
|
81
74
|
const removeContext = useCallback(
|
|
82
75
|
(id: string) => {
|
|
83
76
|
removeElement(id);
|
|
84
77
|
},
|
|
85
|
-
[removeElement]
|
|
78
|
+
[removeElement],
|
|
86
79
|
);
|
|
87
80
|
|
|
88
81
|
const getChatCompletionFunctionDescriptions = useCallback(() => {
|
|
@@ -97,24 +90,21 @@ export function CopilotProvider({
|
|
|
97
90
|
(categories: string[]) => {
|
|
98
91
|
return allDocuments(categories);
|
|
99
92
|
},
|
|
100
|
-
[allDocuments]
|
|
93
|
+
[allDocuments],
|
|
101
94
|
);
|
|
102
95
|
|
|
103
96
|
const addDocumentContext = useCallback(
|
|
104
|
-
(
|
|
105
|
-
documentPointer: DocumentPointer,
|
|
106
|
-
categories: string[] = defaultCopilotContextCategories
|
|
107
|
-
) => {
|
|
97
|
+
(documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {
|
|
108
98
|
return addDocument(documentPointer, categories);
|
|
109
99
|
},
|
|
110
|
-
[addDocument]
|
|
100
|
+
[addDocument],
|
|
111
101
|
);
|
|
112
102
|
|
|
113
103
|
const removeDocumentContext = useCallback(
|
|
114
104
|
(documentId: string) => {
|
|
115
105
|
removeDocument(documentId);
|
|
116
106
|
},
|
|
117
|
-
[removeDocument]
|
|
107
|
+
[removeDocument],
|
|
118
108
|
);
|
|
119
109
|
|
|
120
110
|
return (
|
|
@@ -146,19 +136,15 @@ export function CopilotProvider({
|
|
|
146
136
|
export const defaultCopilotContextCategories = ["global"];
|
|
147
137
|
|
|
148
138
|
function entryPointsToFunctionCallHandler(
|
|
149
|
-
entryPoints: AnnotatedFunction<any[]>[]
|
|
139
|
+
entryPoints: AnnotatedFunction<any[]>[],
|
|
150
140
|
): FunctionCallHandler {
|
|
151
141
|
return async (chatMessages, functionCall) => {
|
|
152
|
-
let entrypointsByFunctionName: Record<
|
|
153
|
-
string,
|
|
154
|
-
AnnotatedFunction<any[]>
|
|
155
|
-
> = {};
|
|
142
|
+
let entrypointsByFunctionName: Record<string, AnnotatedFunction<any[]>> = {};
|
|
156
143
|
for (let entryPoint of entryPoints) {
|
|
157
144
|
entrypointsByFunctionName[entryPoint.name] = entryPoint;
|
|
158
145
|
}
|
|
159
146
|
|
|
160
|
-
const entryPointFunction =
|
|
161
|
-
entrypointsByFunctionName[functionCall.name || ""];
|
|
147
|
+
const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
|
|
162
148
|
if (entryPointFunction) {
|
|
163
149
|
let parsedFunctionCallArguments: Record<string, any>[] = [];
|
|
164
150
|
if (functionCall.arguments) {
|
|
@@ -168,9 +154,7 @@ function entryPointsToFunctionCallHandler(
|
|
|
168
154
|
const paramsInCorrectOrder: any[] = [];
|
|
169
155
|
for (let arg of entryPointFunction.argumentAnnotations) {
|
|
170
156
|
paramsInCorrectOrder.push(
|
|
171
|
-
parsedFunctionCallArguments[
|
|
172
|
-
arg.name as keyof typeof parsedFunctionCallArguments
|
|
173
|
-
]
|
|
157
|
+
parsedFunctionCallArguments[arg.name as keyof typeof parsedFunctionCallArguments],
|
|
174
158
|
);
|
|
175
159
|
}
|
|
176
160
|
|
|
@@ -198,13 +182,13 @@ function entryPointsToFunctionCallHandler(
|
|
|
198
182
|
}
|
|
199
183
|
|
|
200
184
|
function entryPointsToChatCompletionFunctions(
|
|
201
|
-
entryPoints: AnnotatedFunction<any[]>[]
|
|
185
|
+
entryPoints: AnnotatedFunction<any[]>[],
|
|
202
186
|
): ChatCompletionCreateParams.Function[] {
|
|
203
187
|
return entryPoints.map(annotatedFunctionToChatCompletionFunction);
|
|
204
188
|
}
|
|
205
189
|
|
|
206
190
|
function annotatedFunctionToChatCompletionFunction(
|
|
207
|
-
annotatedFunction: AnnotatedFunction<any[]
|
|
191
|
+
annotatedFunction: AnnotatedFunction<any[]>,
|
|
208
192
|
): ChatCompletionCreateParams.Function {
|
|
209
193
|
// Create the parameters object based on the argumentAnnotations
|
|
210
194
|
let parameters: { [key: string]: any } = {};
|
package/src/components/index.ts
CHANGED
|
@@ -58,23 +58,13 @@ export interface CopilotContextParams {
|
|
|
58
58
|
getFunctionCallHandler: () => FunctionCallHandler;
|
|
59
59
|
|
|
60
60
|
// text context
|
|
61
|
-
getContextString: (
|
|
62
|
-
|
|
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
66
|
getDocumentsContext: (categories: string[]) => DocumentPointer[];
|
|
74
|
-
addDocumentContext: (
|
|
75
|
-
documentPointer: DocumentPointer,
|
|
76
|
-
categories?: string[]
|
|
77
|
-
) => TreeNodeId;
|
|
67
|
+
addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;
|
|
78
68
|
removeDocumentContext: (documentId: string) => void;
|
|
79
69
|
|
|
80
70
|
// api endpoints
|
|
@@ -100,7 +90,7 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
100
90
|
copilotApiConfig: new (class implements CopilotApiConfig {
|
|
101
91
|
get chatApiEndpoint(): string {
|
|
102
92
|
throw new Error(
|
|
103
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
93
|
+
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!",
|
|
104
94
|
);
|
|
105
95
|
}
|
|
106
96
|
get headers(): Record<string, string> {
|
|
@@ -112,12 +102,11 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
112
102
|
})(),
|
|
113
103
|
};
|
|
114
104
|
|
|
115
|
-
export const CopilotContext =
|
|
116
|
-
React.createContext<CopilotContextParams>(emptyCopilotContext);
|
|
105
|
+
export const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);
|
|
117
106
|
|
|
118
107
|
function returnAndThrowInDebug<T>(value: T): T {
|
|
119
108
|
throw new Error(
|
|
120
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
109
|
+
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!",
|
|
121
110
|
);
|
|
122
111
|
return value;
|
|
123
112
|
}
|
|
@@ -17,11 +17,9 @@ export interface UseCopilotChatReturn {
|
|
|
17
17
|
visibleMessages: Message[];
|
|
18
18
|
append: (
|
|
19
19
|
message: Message | CreateMessage,
|
|
20
|
-
chatRequestOptions?: ChatRequestOptions
|
|
21
|
-
) => Promise<string | null | undefined>;
|
|
22
|
-
reload: (
|
|
23
|
-
chatRequestOptions?: ChatRequestOptions
|
|
20
|
+
chatRequestOptions?: ChatRequestOptions,
|
|
24
21
|
) => Promise<string | null | undefined>;
|
|
22
|
+
reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
|
|
25
23
|
stop: () => void;
|
|
26
24
|
isLoading: boolean;
|
|
27
25
|
input: string;
|
|
@@ -50,32 +48,29 @@ export function useCopilotChat({
|
|
|
50
48
|
};
|
|
51
49
|
}, [getContextString, makeSystemMessage]);
|
|
52
50
|
|
|
53
|
-
const initialMessagesWithContext = [systemMessage].concat(
|
|
54
|
-
options.initialMessages || []
|
|
55
|
-
);
|
|
51
|
+
const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);
|
|
56
52
|
|
|
57
53
|
const functionDescriptions = useMemo(() => {
|
|
58
54
|
return getChatCompletionFunctionDescriptions();
|
|
59
55
|
}, [getChatCompletionFunctionDescriptions]);
|
|
60
56
|
|
|
61
|
-
const { messages, append, reload, stop, isLoading, input, setInput } =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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: {
|
|
65
65
|
id: options.id,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
functions: functionDescriptions,
|
|
72
|
-
...copilotApiConfig.body,
|
|
73
|
-
...options.body,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
66
|
+
functions: functionDescriptions,
|
|
67
|
+
...copilotApiConfig.body,
|
|
68
|
+
...options.body,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
76
71
|
|
|
77
72
|
const visibleMessages = messages.filter(
|
|
78
|
-
(message) => message.role === "user" || message.role === "assistant"
|
|
73
|
+
(message) => message.role === "user" || message.role === "assistant",
|
|
79
74
|
);
|
|
80
75
|
|
|
81
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
|
@@ -14,10 +14,9 @@ import { DocumentPointer } from "../types";
|
|
|
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(() => {
|
|
@@ -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>();
|
package/src/hooks/use-tree.ts
CHANGED
|
@@ -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
|
-
|
|
110
|
-
|
|
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)) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-tree.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAsCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,SAAS;AAC1C,QAAI,KAAK,OAAO,IAAI;AAClB,YAAM,UAAU,iCAAK,OAAL,EAAW,UAAU,WAAW,KAAK,UAAU,EAAE,EAAE;AACnE,aAAO,KAAK,OAAO;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEA,IAAM,UAAU,CACd,OACA,SACA,aACS;AACT,MAAI,CAAC,UAAU;AACb,WAAO,CAAC,GAAG,OAAO,OAAO;AAAA,EAC3B;AACA,SAAO,MAAM,IAAI,CAAC,SAAS;AACzB,QAAI,KAAK,OAAO,UAAU;AACxB,aAAO,iCAAK,OAAL,EAAW,UAAU,CAAC,GAAG,KAAK,UAAU,OAAO,EAAE;AAAA,IAC1D,WAAW,KAAK,SAAS,QAAQ;AAC/B,aAAO,iCAAK,OAAL,EAAW,UAAU,QAAQ,KAAK,UAAU,SAAS,QAAQ,EAAE;AAAA,IACxE;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,IAAM,gCAAgC,CACpC,OACA,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AM,IAAI;AAErD,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: (\n value: string,\n categories: string[],\n parentId?: TreeNodeId\n ) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (\n nodes: Tree,\n newNode: TreeNode,\n parentId?: TreeNodeId\n): Tree => {\n if (!parentId) {\n return [...nodes, newNode];\n }\n return nodes.map((node) => {\n if (node.id === parentId) {\n return { ...node, children: [...node.children, newNode] };\n } else if (node.children.length) {\n return { ...node, children: addNode(node.children, newNode, parentId) };\n }\n return node;\n });\n};\n\nconst treeIndentationRepresentation = (\n index: number,\n indentLevel: number\n): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(\n index,\n indentLevel + 1\n )}. `,\n indentLevel + 1\n ))\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = nanoid(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n []\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(\n node,\n `${treeIndentationRepresentation(index, 0)}. `\n );\n });\n return output;\n },\n [tree]\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"]}
|
|
@@ -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;AACnE,QAAM,CAAC,UAAU,QAAQ,IAAI;AAAA,IAM3B;AAAA,IACA,oBAAI,IAAsD;AAAA,EAC5D;AAEA,QAAM,aAAa;AAAA,IACjB,CAAC,OAAU,eAA8C;AACvD,YAAM,QAAQ,OAAO;AACrB,eAAS;AAAA,QACP,MAAM;AAAA,QACN;AAAA,QACA,IAAI;AAAA,QACJ;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,gBAAgB,YAAY,CAAC,OAAkC;AACnE,aAAS,EAAE,MAAM,kBAAkB,GAAG,CAAC;AAAA,EACzC,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc;AAAA,IAClB,CAAC,eAA8B;AAC7B,YAAM,gBAAgB,IAAI,IAAI,UAAU;AACxC,YAAM,SAAc,CAAC;AACrB,eAAS,QAAQ,CAAC,YAAY;AAC5B,YAAI,qBAAqB,eAAe,QAAQ,UAAU,GAAG;AAC3D,iBAAO,KAAK,QAAQ,KAAK;AAAA,QAC3B;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,SAAO,EAAE,YAAY,eAAe,YAAY;AAClD;AAEA,IAAO,kCAAQ;AAaf,SAAS,yBACP,OACA,QACuD;AACvD,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,eAAe;AAClB,YAAM,EAAE,OAAO,IAAI,WAAW,IAAI;AAClC,YAAM,aAA0C;AAAA,QAC9C;AAAA,QACA;AAAA,QACA,YAAY,IAAI,IAAI,UAAU;AAAA,MAChC;AACA,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,IAAI,IAAI,UAAU;AAC3B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,kBAAkB;AACrB,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,OAAO,OAAO,EAAE;AACzB,aAAO;AAAA,IACT;AAAA,IACA;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAC1B,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAErD,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<\n Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n Action<T>\n >\n >(\n flatCategoryStoreReducer,\n new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>()\n );\n\n const addElement = useCallback(\n (value: T, categories: string[]): FlatCategoryStoreId => {\n const newId = nanoid();\n dispatch({\n type: \"ADD_ELEMENT\",\n value,\n id: newId,\n categories,\n });\n return newId;\n },\n []\n );\n\n const removeElement = useCallback((id: FlatCategoryStoreId): void => {\n dispatch({ type: \"REMOVE_ELEMENT\", id });\n }, []);\n\n const allElements = useCallback(\n (categories: string[]): T[] => {\n const categoriesSet = new Set(categories);\n const result: T[] = [];\n elements.forEach((element) => {\n if (setsHaveIntersection(categoriesSet, element.categories)) {\n result.push(element.value);\n }\n });\n return result;\n },\n [elements]\n );\n\n return { addElement, removeElement, allElements };\n};\n\nexport default useFlatCategoryStore;\n\n// Action types\ntype Action<T> =\n | {\n type: \"ADD_ELEMENT\";\n value: T;\n id: FlatCategoryStoreId;\n categories: string[];\n }\n | { type: \"REMOVE_ELEMENT\"; id: FlatCategoryStoreId };\n\n// Reducer\nfunction flatCategoryStoreReducer<T>(\n state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n action: Action<T>\n): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {\n switch (action.type) {\n case \"ADD_ELEMENT\": {\n const { value, id, categories } = action;\n const newElement: FlatCategoryStoreElement<T> = {\n id,\n value,\n categories: new Set(categories),\n };\n const newState = new Map(state);\n newState.set(id, newElement);\n return newState;\n }\n case \"REMOVE_ELEMENT\": {\n const newState = new Map(state);\n newState.delete(action.id);\n return newState;\n }\n default:\n return state;\n }\n}\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"]}
|
|
@@ -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,IAChD,WAAW,cAAc;AAC3B,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 } =\n 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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/copilot-provider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,SAAoB,aAAa,gBAAgB;AAsH7C;AAxHJ;AAUO,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKgB;AACd,QAAM,CAAC,aAAa,cAAc,IAAI,SAEpC,CAAC,CAAC;AAEJ,QAAM,EAAE,YAAY,eAA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AAA,EACF;AACF;AAEA,SAAS,qCACP,aACuC;AACvC,SAAO,YAAY,IAAI,yCAAyC;AAClE;AAEA,SAAS,0CACP,mBACqC;AAErC,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAA2C,UAArC,QAAM,SApNhB,IAoN+C,IAAlB,0BAAkB,IAAlB,CAAnB,QAAM;AACZ,eAAW,IAAI,QAAQ;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAA8D;AAAA,IAChE,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["\"use client\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ReactNode, useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../context/copilot-context\";\nimport useTree from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\nimport useFlatCategoryStore from \"../hooks/use-flat-category-store\";\n\nexport function CopilotProvider({\n chatApiEndpoint,\n headers,\n body,\n children,\n}: {\n chatApiEndpoint: string;\n headers?: Record<string, string>;\n body?: Record<string, any>;\n children: ReactNode;\n}): JSX.Element {\n const [entryPoints, setEntryPoints] = useState<\n Record<string, AnnotatedFunction<any[]>>\n >({});\n\n const { addElement, removeElement, printTree } = useTree();\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback(\n (id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n },\n []\n );\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${\n document.sourceApplication\n }):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree]\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement]\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement]\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(() => {\n return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments]\n );\n\n const addDocumentContext = useCallback(\n (\n documentPointer: DocumentPointer,\n categories: string[] = defaultCopilotContextCategories\n ) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument]\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument]\n );\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: {\n chatApiEndpoint,\n headers: headers || {},\n body: body || {},\n },\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[]\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<\n string,\n AnnotatedFunction<any[]>\n > = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction =\n entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[\n arg.name as keyof typeof parsedFunctionCallArguments\n ]\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[]\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"]}
|
|
@@ -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;AALvB;AAOO,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;AAAA,MACE,MAAM;AAAA,MACN;AAAA,IACF;AAEA,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(\n idRef.current,\n memoizedAnnotatedFunction as AnnotatedFunction<any[]>\n );\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AAMpC,SAAS,eAAe;AAwBjB,SAAS,eAAe,IAGiB;AAHjB,eAC7B;AAAA;AAAA,EA/BF,IA8B+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;AAAA,IACjD,QAAQ,mBAAmB,CAAC;AAAA,EAC9B;AAEA,QAAM,uBAAuB,QAAQ,MAAM;AACzC,WAAO,sCAAsC;AAAA,EAC/C,GAAG,CAAC,qCAAqC,CAAC;AAE1C,QAAM,EAAE,UAAU,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,IACjE,QAAQ,iCACH,UADG;AAAA,IAEN,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;AAEH,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: (\n chatRequestOptions?: ChatRequestOptions\n ) => 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(\n options.initialMessages || []\n );\n\n const functionDescriptions = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } =\n 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 +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;AAkCA,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,iBACX,MAAM,cAAoC,mBAAmB;AAE/D,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: (\n documents: DocumentPointer[],\n categories: string[]\n ) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n getContextString: (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 =\n React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n return value;\n}\n"]}
|