@copilotkit/react-core 0.13.0 → 0.15.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +141 -88
- package/CHANGELOG.md +17 -0
- package/dist/components/copilot-provider/copilot-provider-props.d.ts +50 -0
- package/dist/components/copilot-provider/copilot-provider-props.mjs +2 -0
- package/dist/components/copilot-provider/copilot-provider-props.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-provider.d.ts +45 -0
- package/dist/components/copilot-provider/copilot-provider.mjs +469 -0
- package/dist/components/copilot-provider/copilot-provider.mjs.map +1 -0
- package/dist/components/copilot-provider/index.d.ts +9 -0
- package/dist/components/copilot-provider/index.mjs +468 -0
- package/dist/components/copilot-provider/index.mjs.map +1 -0
- package/dist/components/copilot-provider/standard-cpilot-api-config.d.ts +24 -0
- package/dist/components/copilot-provider/standard-cpilot-api-config.mjs +13 -0
- package/dist/components/copilot-provider/standard-cpilot-api-config.mjs.map +1 -0
- package/dist/components/index.d.ts +8 -1
- package/dist/components/index.mjs +467 -7
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.d.ts +5 -0
- package/dist/context/copilot-context.mjs +81 -3
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.mjs +80 -4
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.mjs +249 -12
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +194 -8
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +68 -3
- package/dist/hooks/use-flat-category-store.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +95 -4
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +87 -4
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +87 -4
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/hooks/use-tree.mjs +153 -3
- package/dist/hooks/use-tree.mjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +755 -14
- package/dist/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/index.d.ts +2 -0
- package/dist/openai-assistants/hooks/index.mjs +246 -0
- package/dist/openai-assistants/hooks/index.mjs.map +1 -0
- package/dist/openai-assistants/hooks/use-assistants.d.ts +17 -0
- package/dist/openai-assistants/hooks/use-assistants.mjs +131 -0
- package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.d.ts +44 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +247 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -0
- package/dist/openai-assistants/index.d.ts +3 -0
- package/dist/openai-assistants/index.mjs +247 -0
- package/dist/openai-assistants/index.mjs.map +1 -0
- package/dist/openai-assistants/utils/index.d.ts +1 -0
- package/dist/openai-assistants/utils/index.mjs +47 -0
- package/dist/openai-assistants/utils/index.mjs.map +1 -0
- package/dist/openai-assistants/utils/process-message-stream.d.ts +3 -0
- package/dist/openai-assistants/utils/process-message-stream.mjs +47 -0
- package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -0
- package/dist/types/annotated-function.mjs +0 -2
- package/dist/types/annotated-function.mjs.map +1 -1
- package/dist/types/document-pointer.mjs +0 -2
- package/dist/types/document-pointer.mjs.map +1 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.mjs +0 -2
- package/dist/utils/utils.mjs.map +1 -1
- package/dist/utils/utils.test.d.ts +1 -0
- package/dist/utils/utils.test.mjs +0 -1
- package/dist/utils/utils.test.mjs.map +1 -1
- package/package.json +7 -6
- package/src/components/copilot-provider/copilot-provider-props.tsx +50 -0
- package/src/components/{copilot-provider.tsx → copilot-provider/copilot-provider.tsx} +84 -63
- package/src/components/copilot-provider/index.ts +7 -0
- package/src/components/copilot-provider/standard-cpilot-api-config.tsx +28 -0
- package/src/components/index.ts +1 -4
- package/src/context/copilot-context.tsx +19 -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/src/index.tsx +1 -0
- package/src/openai-assistants/hooks/index.ts +9 -0
- package/src/openai-assistants/hooks/use-assistants.ts +114 -0
- package/src/openai-assistants/hooks/use-copilot-chat-v2.ts +186 -0
- package/src/openai-assistants/index.ts +2 -0
- package/src/openai-assistants/utils/index.ts +1 -0
- package/src/openai-assistants/utils/process-message-stream.ts +25 -0
- package/dist/chunk-3BOHSSKR.mjs +0 -141
- package/dist/chunk-3BOHSSKR.mjs.map +0 -1
- package/dist/chunk-63ILXW5V.mjs +0 -76
- package/dist/chunk-63ILXW5V.mjs.map +0 -1
- package/dist/chunk-AMFRKVFT.mjs +0 -19
- package/dist/chunk-AMFRKVFT.mjs.map +0 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -3
- package/dist/chunk-EFZPSZWO.mjs.map +0 -1
- package/dist/chunk-FIYUJVWU.mjs +0 -161
- package/dist/chunk-FIYUJVWU.mjs.map +0 -1
- package/dist/chunk-G5LZS72K.mjs +0 -19
- package/dist/chunk-G5LZS72K.mjs.map +0 -1
- package/dist/chunk-JD7BAH7U.mjs +0 -3
- package/dist/chunk-JD7BAH7U.mjs.map +0 -1
- package/dist/chunk-MRXNTQOX.mjs +0 -55
- package/dist/chunk-MRXNTQOX.mjs.map +0 -1
- package/dist/chunk-P3QUZTN7.mjs +0 -30
- package/dist/chunk-P3QUZTN7.mjs.map +0 -1
- package/dist/chunk-PRPQRCVY.mjs +0 -82
- package/dist/chunk-PRPQRCVY.mjs.map +0 -1
- package/dist/chunk-QACD2U6P.mjs +0 -3
- package/dist/chunk-QACD2U6P.mjs.map +0 -1
- package/dist/chunk-X24EEZGG.mjs +0 -50
- package/dist/chunk-X24EEZGG.mjs.map +0 -1
- package/dist/chunk-YPSGKPDA.mjs +0 -3
- package/dist/chunk-YPSGKPDA.mjs.map +0 -1
- package/dist/components/copilot-provider.d.ts +0 -11
- package/dist/components/copilot-provider.mjs +0 -7
- package/dist/components/copilot-provider.mjs.map +0 -1
|
@@ -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,gBACW;AACX,MAAI,gBAAgB,GAAG;AACrB,YAAQ,QAAQ,GAAG,SAAS;AAAA,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G;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"]}
|
package/dist/chunk-63ILXW5V.mjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid';
|
|
2
|
-
import { useReducer, useCallback } from 'react';
|
|
3
|
-
|
|
4
|
-
// src/hooks/use-flat-category-store.ts
|
|
5
|
-
var useFlatCategoryStore = () => {
|
|
6
|
-
const [elements, dispatch] = useReducer(
|
|
7
|
-
flatCategoryStoreReducer,
|
|
8
|
-
/* @__PURE__ */ new Map()
|
|
9
|
-
);
|
|
10
|
-
const addElement = useCallback(
|
|
11
|
-
(value, categories) => {
|
|
12
|
-
const newId = nanoid();
|
|
13
|
-
dispatch({
|
|
14
|
-
type: "ADD_ELEMENT",
|
|
15
|
-
value,
|
|
16
|
-
id: newId,
|
|
17
|
-
categories
|
|
18
|
-
});
|
|
19
|
-
return newId;
|
|
20
|
-
},
|
|
21
|
-
[]
|
|
22
|
-
);
|
|
23
|
-
const removeElement = useCallback((id) => {
|
|
24
|
-
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
25
|
-
}, []);
|
|
26
|
-
const allElements = useCallback(
|
|
27
|
-
(categories) => {
|
|
28
|
-
const categoriesSet = new Set(categories);
|
|
29
|
-
const result = [];
|
|
30
|
-
elements.forEach((element) => {
|
|
31
|
-
if (setsHaveIntersection(categoriesSet, element.categories)) {
|
|
32
|
-
result.push(element.value);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return result;
|
|
36
|
-
},
|
|
37
|
-
[elements]
|
|
38
|
-
);
|
|
39
|
-
return { addElement, removeElement, allElements };
|
|
40
|
-
};
|
|
41
|
-
var use_flat_category_store_default = useFlatCategoryStore;
|
|
42
|
-
function flatCategoryStoreReducer(state, action) {
|
|
43
|
-
switch (action.type) {
|
|
44
|
-
case "ADD_ELEMENT": {
|
|
45
|
-
const { value, id, categories } = action;
|
|
46
|
-
const newElement = {
|
|
47
|
-
id,
|
|
48
|
-
value,
|
|
49
|
-
categories: new Set(categories)
|
|
50
|
-
};
|
|
51
|
-
const newState = new Map(state);
|
|
52
|
-
newState.set(id, newElement);
|
|
53
|
-
return newState;
|
|
54
|
-
}
|
|
55
|
-
case "REMOVE_ELEMENT": {
|
|
56
|
-
const newState = new Map(state);
|
|
57
|
-
newState.delete(action.id);
|
|
58
|
-
return newState;
|
|
59
|
-
}
|
|
60
|
-
default:
|
|
61
|
-
return state;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function setsHaveIntersection(setA, setB) {
|
|
65
|
-
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
66
|
-
for (let item of smallerSet) {
|
|
67
|
-
if (largerSet.has(item)) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { use_flat_category_store_default };
|
|
75
|
-
//# sourceMappingURL=out.js.map
|
|
76
|
-
//# sourceMappingURL=chunk-63ILXW5V.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-flat-category-store.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAgBxC,IAAM,uBAAuB,MAAwC;AACnE,QAAM,CAAC,UAAU,QAAQ,IAAI;AAAA,IAM3B;AAAA,IACA,oBAAI,IAAsD;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AK,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"]}
|
package/dist/chunk-AMFRKVFT.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CopilotContext } from './chunk-X24EEZGG.mjs';
|
|
2
|
-
import { useContext, useRef, useEffect } from 'react';
|
|
3
|
-
|
|
4
|
-
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
5
|
-
const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);
|
|
6
|
-
const idRef = useRef();
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const id = addDocumentContext(document, categories);
|
|
9
|
-
idRef.current = id;
|
|
10
|
-
return () => {
|
|
11
|
-
removeDocumentContext(id);
|
|
12
|
-
};
|
|
13
|
-
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
14
|
-
return idRef.current;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { useMakeCopilotDocumentReadable };
|
|
18
|
-
//# sourceMappingURL=out.js.map
|
|
19
|
-
//# sourceMappingURL=chunk-AMFRKVFT.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-make-copilot-document-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAF9C;AAaO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,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"]}
|
package/dist/chunk-EFZPSZWO.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/chunk-FIYUJVWU.mjs
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { use_tree_default } from './chunk-3BOHSSKR.mjs';
|
|
2
|
-
import { CopilotContext } from './chunk-X24EEZGG.mjs';
|
|
3
|
-
import { use_flat_category_store_default } from './chunk-63ILXW5V.mjs';
|
|
4
|
-
import { __spreadProps, __spreadValues, __async, __objRest } from './chunk-MRXNTQOX.mjs';
|
|
5
|
-
import { useState, useCallback } from 'react';
|
|
6
|
-
import { jsx } from 'react/jsx-runtime';
|
|
7
|
-
|
|
8
|
-
function CopilotProvider({
|
|
9
|
-
chatApiEndpoint,
|
|
10
|
-
headers,
|
|
11
|
-
body,
|
|
12
|
-
children
|
|
13
|
-
}) {
|
|
14
|
-
const [entryPoints, setEntryPoints] = useState({});
|
|
15
|
-
const { addElement, removeElement, printTree } = use_tree_default();
|
|
16
|
-
const {
|
|
17
|
-
addElement: addDocument,
|
|
18
|
-
removeElement: removeDocument,
|
|
19
|
-
allElements: allDocuments
|
|
20
|
-
} = use_flat_category_store_default();
|
|
21
|
-
const setEntryPoint = useCallback(
|
|
22
|
-
(id, entryPoint) => {
|
|
23
|
-
setEntryPoints((prevPoints) => {
|
|
24
|
-
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
25
|
-
[id]: entryPoint
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
[]
|
|
30
|
-
);
|
|
31
|
-
const removeEntryPoint = useCallback((id) => {
|
|
32
|
-
setEntryPoints((prevPoints) => {
|
|
33
|
-
const newPoints = __spreadValues({}, prevPoints);
|
|
34
|
-
delete newPoints[id];
|
|
35
|
-
return newPoints;
|
|
36
|
-
});
|
|
37
|
-
}, []);
|
|
38
|
-
const getContextString = useCallback(
|
|
39
|
-
(documents, categories) => {
|
|
40
|
-
const documentsString = documents.map((document) => {
|
|
41
|
-
return `${document.name} (${document.sourceApplication}):
|
|
42
|
-
${document.getContents()}`;
|
|
43
|
-
}).join("\n\n");
|
|
44
|
-
const nonDocumentStrings = printTree(categories);
|
|
45
|
-
return `${documentsString}
|
|
46
|
-
|
|
47
|
-
${nonDocumentStrings}`;
|
|
48
|
-
},
|
|
49
|
-
[printTree]
|
|
50
|
-
);
|
|
51
|
-
const addContext = useCallback(
|
|
52
|
-
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
53
|
-
return addElement(context, categories, parentId);
|
|
54
|
-
},
|
|
55
|
-
[addElement]
|
|
56
|
-
);
|
|
57
|
-
const removeContext = useCallback(
|
|
58
|
-
(id) => {
|
|
59
|
-
removeElement(id);
|
|
60
|
-
},
|
|
61
|
-
[removeElement]
|
|
62
|
-
);
|
|
63
|
-
const getChatCompletionFunctionDescriptions = useCallback(() => {
|
|
64
|
-
return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
|
|
65
|
-
}, [entryPoints]);
|
|
66
|
-
const getFunctionCallHandler = useCallback(() => {
|
|
67
|
-
return entryPointsToFunctionCallHandler(Object.values(entryPoints));
|
|
68
|
-
}, [entryPoints]);
|
|
69
|
-
const getDocumentsContext = useCallback(
|
|
70
|
-
(categories) => {
|
|
71
|
-
return allDocuments(categories);
|
|
72
|
-
},
|
|
73
|
-
[allDocuments]
|
|
74
|
-
);
|
|
75
|
-
const addDocumentContext = useCallback(
|
|
76
|
-
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
77
|
-
return addDocument(documentPointer, categories);
|
|
78
|
-
},
|
|
79
|
-
[addDocument]
|
|
80
|
-
);
|
|
81
|
-
const removeDocumentContext = useCallback(
|
|
82
|
-
(documentId) => {
|
|
83
|
-
removeDocument(documentId);
|
|
84
|
-
},
|
|
85
|
-
[removeDocument]
|
|
86
|
-
);
|
|
87
|
-
return /* @__PURE__ */ jsx(CopilotContext.Provider, {
|
|
88
|
-
value: {
|
|
89
|
-
entryPoints,
|
|
90
|
-
getChatCompletionFunctionDescriptions,
|
|
91
|
-
getFunctionCallHandler,
|
|
92
|
-
setEntryPoint,
|
|
93
|
-
removeEntryPoint,
|
|
94
|
-
getContextString,
|
|
95
|
-
addContext,
|
|
96
|
-
removeContext,
|
|
97
|
-
getDocumentsContext,
|
|
98
|
-
addDocumentContext,
|
|
99
|
-
removeDocumentContext,
|
|
100
|
-
copilotApiConfig: {
|
|
101
|
-
chatApiEndpoint,
|
|
102
|
-
headers: headers || {},
|
|
103
|
-
body: body || {}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
children
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
var defaultCopilotContextCategories = ["global"];
|
|
110
|
-
function entryPointsToFunctionCallHandler(entryPoints) {
|
|
111
|
-
return (chatMessages, functionCall) => __async(this, null, function* () {
|
|
112
|
-
let entrypointsByFunctionName = {};
|
|
113
|
-
for (let entryPoint of entryPoints) {
|
|
114
|
-
entrypointsByFunctionName[entryPoint.name] = entryPoint;
|
|
115
|
-
}
|
|
116
|
-
const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
|
|
117
|
-
if (entryPointFunction) {
|
|
118
|
-
let parsedFunctionCallArguments = [];
|
|
119
|
-
if (functionCall.arguments) {
|
|
120
|
-
parsedFunctionCallArguments = JSON.parse(functionCall.arguments);
|
|
121
|
-
}
|
|
122
|
-
const paramsInCorrectOrder = [];
|
|
123
|
-
for (let arg of entryPointFunction.argumentAnnotations) {
|
|
124
|
-
paramsInCorrectOrder.push(
|
|
125
|
-
parsedFunctionCallArguments[arg.name]
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
yield entryPointFunction.implementation(...paramsInCorrectOrder);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function entryPointsToChatCompletionFunctions(entryPoints) {
|
|
133
|
-
return entryPoints.map(annotatedFunctionToChatCompletionFunction);
|
|
134
|
-
}
|
|
135
|
-
function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
|
|
136
|
-
let parameters = {};
|
|
137
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
138
|
-
let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]);
|
|
139
|
-
parameters[arg.name] = forwardedArgs;
|
|
140
|
-
}
|
|
141
|
-
let requiredParameterNames = [];
|
|
142
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
143
|
-
if (arg.required) {
|
|
144
|
-
requiredParameterNames.push(arg.name);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
let chatCompletionFunction = {
|
|
148
|
-
name: annotatedFunction.name,
|
|
149
|
-
description: annotatedFunction.description,
|
|
150
|
-
parameters: {
|
|
151
|
-
type: "object",
|
|
152
|
-
properties: parameters,
|
|
153
|
-
required: requiredParameterNames
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
return chatCompletionFunction;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export { CopilotProvider, defaultCopilotContextCategories };
|
|
160
|
-
//# sourceMappingURL=out.js.map
|
|
161
|
-
//# sourceMappingURL=chunk-FIYUJVWU.mjs.map
|
|
@@ -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,eAAe,UAAU,IAAI,iBAAQ;AACzD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA,EACf,IAAI,gCAAsC;AAE1C,QAAM,gBAAgB;AAAA,IACpB,CAAC,IAAY,eAAyC;AACpD,qBAAe,CAAC,eAAe;AAC7B,eAAO,iCACF,aADE;AAAA,UAEL,CAAC,KAAK;AAAA,QACR;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,mBAAmB,YAAY,CAAC,OAAe;AACnD,mBAAe,CAAC,eAAe;AAC7B,YAAM,YAAY,mBAAK;AACvB,aAAO,UAAU;AACjB,aAAO;AAAA,IACT,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,mBAAmB;AAAA,IACvB,CAAC,WAA8B,eAAyB;AACtD,YAAM,kBAAkB,UACrB,IAAI,CAAC,aAAa;AACjB,eAAO,GA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F;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"]}
|
package/dist/chunk-G5LZS72K.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CopilotContext } from './chunk-X24EEZGG.mjs';
|
|
2
|
-
import { useContext, useRef, useEffect } from 'react';
|
|
3
|
-
|
|
4
|
-
function useMakeCopilotReadable(information, parentId, categories) {
|
|
5
|
-
const { addContext, removeContext } = useContext(CopilotContext);
|
|
6
|
-
const idRef = useRef();
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const id = addContext(information, parentId, categories);
|
|
9
|
-
idRef.current = id;
|
|
10
|
-
return () => {
|
|
11
|
-
removeContext(id);
|
|
12
|
-
};
|
|
13
|
-
}, [information, parentId, addContext, removeContext]);
|
|
14
|
-
return idRef.current;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { useMakeCopilotReadable };
|
|
18
|
-
//# sourceMappingURL=out.js.map
|
|
19
|
-
//# sourceMappingURL=chunk-G5LZS72K.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-make-copilot-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAF9C;AAYO,SAAS,uBACd,aACA,UACA,YACoB;AACpB,QAAM,EAAE,YAAY,cAAc,IAAI,WAAW,cAAc;AAC/D,QAAM,QAAQ,OAAe;AAE7B,YAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,aAAa,CAAC;AAErD,SAAO,MAAM;AACf","sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[]\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n"]}
|
package/dist/chunk-JD7BAH7U.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/chunk-MRXNTQOX.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export { __async, __objRest, __spreadProps, __spreadValues };
|
|
54
|
-
//# sourceMappingURL=out.js.map
|
|
55
|
-
//# sourceMappingURL=chunk-MRXNTQOX.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
package/dist/chunk-P3QUZTN7.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { CopilotContext } from './chunk-X24EEZGG.mjs';
|
|
2
|
-
import { useRef, useContext, useMemo, useEffect } from 'react';
|
|
3
|
-
import { nanoid } from 'nanoid';
|
|
4
|
-
|
|
5
|
-
function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
6
|
-
const idRef = useRef(nanoid());
|
|
7
|
-
const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);
|
|
8
|
-
const memoizedAnnotatedFunction = useMemo(
|
|
9
|
-
() => ({
|
|
10
|
-
name: annotatedFunction.name,
|
|
11
|
-
description: annotatedFunction.description,
|
|
12
|
-
argumentAnnotations: annotatedFunction.argumentAnnotations,
|
|
13
|
-
implementation: annotatedFunction.implementation
|
|
14
|
-
}),
|
|
15
|
-
dependencies
|
|
16
|
-
);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
setEntryPoint(
|
|
19
|
-
idRef.current,
|
|
20
|
-
memoizedAnnotatedFunction
|
|
21
|
-
);
|
|
22
|
-
return () => {
|
|
23
|
-
removeEntryPoint(idRef.current);
|
|
24
|
-
};
|
|
25
|
-
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { useMakeCopilotActionable };
|
|
29
|
-
//# sourceMappingURL=out.js.map
|
|
30
|
-
//# sourceMappingURL=chunk-P3QUZTN7.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-make-copilot-actionable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,QAAQ,YAAY,WAAW,eAAe;AAGvD,SAAS,cAAc;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"]}
|
package/dist/chunk-PRPQRCVY.mjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { defaultCopilotContextCategories } from './chunk-FIYUJVWU.mjs';
|
|
2
|
-
import { CopilotContext, copilotApiConfigExtrapolator } from './chunk-X24EEZGG.mjs';
|
|
3
|
-
import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
|
|
4
|
-
import { useContext, useMemo } from 'react';
|
|
5
|
-
import { useChat } from 'ai/react';
|
|
6
|
-
|
|
7
|
-
function useCopilotChat(_a) {
|
|
8
|
-
var _b = _a, {
|
|
9
|
-
makeSystemMessage
|
|
10
|
-
} = _b, options = __objRest(_b, [
|
|
11
|
-
"makeSystemMessage"
|
|
12
|
-
]);
|
|
13
|
-
const {
|
|
14
|
-
getContextString,
|
|
15
|
-
getChatCompletionFunctionDescriptions,
|
|
16
|
-
getFunctionCallHandler,
|
|
17
|
-
copilotApiConfig
|
|
18
|
-
} = useContext(CopilotContext);
|
|
19
|
-
const systemMessage = useMemo(() => {
|
|
20
|
-
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
21
|
-
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
22
|
-
return {
|
|
23
|
-
id: "system",
|
|
24
|
-
content: systemMessageMaker(contextString),
|
|
25
|
-
role: "system"
|
|
26
|
-
};
|
|
27
|
-
}, [getContextString, makeSystemMessage]);
|
|
28
|
-
const initialMessagesWithContext = [systemMessage].concat(
|
|
29
|
-
options.initialMessages || []
|
|
30
|
-
);
|
|
31
|
-
const functionDescriptions = useMemo(() => {
|
|
32
|
-
return getChatCompletionFunctionDescriptions();
|
|
33
|
-
}, [getChatCompletionFunctionDescriptions]);
|
|
34
|
-
const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
35
|
-
api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,
|
|
36
|
-
id: options.id,
|
|
37
|
-
initialMessages: initialMessagesWithContext,
|
|
38
|
-
experimental_onFunctionCall: getFunctionCallHandler(),
|
|
39
|
-
headers: __spreadValues(__spreadValues({}, copilotApiConfig.headers), options.headers),
|
|
40
|
-
body: __spreadValues(__spreadValues({
|
|
41
|
-
id: options.id,
|
|
42
|
-
functions: functionDescriptions
|
|
43
|
-
}, copilotApiConfig.body), options.body)
|
|
44
|
-
}));
|
|
45
|
-
const visibleMessages = messages.filter(
|
|
46
|
-
(message) => message.role === "user" || message.role === "assistant"
|
|
47
|
-
);
|
|
48
|
-
return {
|
|
49
|
-
visibleMessages,
|
|
50
|
-
append,
|
|
51
|
-
reload,
|
|
52
|
-
stop,
|
|
53
|
-
isLoading,
|
|
54
|
-
input,
|
|
55
|
-
setInput
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function defaultSystemMessage(contextString) {
|
|
59
|
-
return `
|
|
60
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
61
|
-
|
|
62
|
-
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
63
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
64
|
-
|
|
65
|
-
The user has provided you with the following context:
|
|
66
|
-
\`\`\`
|
|
67
|
-
${contextString}
|
|
68
|
-
\`\`\`
|
|
69
|
-
|
|
70
|
-
They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
|
|
71
|
-
|
|
72
|
-
Please assist them as best you can.
|
|
73
|
-
|
|
74
|
-
You can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.
|
|
75
|
-
|
|
76
|
-
If you would like to call a function, call it without saying anything else.
|
|
77
|
-
`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export { defaultSystemMessage, useCopilotChat };
|
|
81
|
-
//# sourceMappingURL=out.js.map
|
|
82
|
-
//# sourceMappingURL=chunk-PRPQRCVY.mjs.map
|
|
@@ -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"]}
|
package/dist/chunk-QACD2U6P.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/chunk-X24EEZGG.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import './chunk-MRXNTQOX.mjs';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
|
|
4
|
-
function copilotApiConfigExtrapolator(config) {
|
|
5
|
-
return {
|
|
6
|
-
get chatApiEndpoint() {
|
|
7
|
-
return `${config.chatApiEndpoint}`;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
var emptyCopilotContext = {
|
|
12
|
-
entryPoints: {},
|
|
13
|
-
setEntryPoint: () => {
|
|
14
|
-
},
|
|
15
|
-
removeEntryPoint: () => {
|
|
16
|
-
},
|
|
17
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
|
|
18
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(),
|
|
19
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(),
|
|
20
|
-
addContext: () => "",
|
|
21
|
-
removeContext: () => {
|
|
22
|
-
},
|
|
23
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug(),
|
|
24
|
-
addDocumentContext: () => returnAndThrowInDebug(),
|
|
25
|
-
removeDocumentContext: () => {
|
|
26
|
-
},
|
|
27
|
-
copilotApiConfig: new class {
|
|
28
|
-
get chatApiEndpoint() {
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
get headers() {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
get body() {
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
}()
|
|
40
|
-
};
|
|
41
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
42
|
-
function returnAndThrowInDebug(value) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { CopilotContext, copilotApiConfigExtrapolator };
|
|
49
|
-
//# sourceMappingURL=out.js.map
|
|
50
|
-
//# sourceMappingURL=chunk-X24EEZGG.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/copilot-context.tsx"],"names":[],"mappings":";;;;;AAGA,OAAO,WAAW;AAHlB;AA2CO,SAAS,6BAA6B,QAA0B;AACrE,SAAO;AAAA,IACL,IAAI,kBAA0B;AAC5B,aAAO,GAAG,OAAO;AAAA,IACnB;AAAA,EACF;AACF;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"]}
|
package/dist/chunk-YPSGKPDA.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
declare function CopilotProvider({ chatApiEndpoint, headers, body, children, }: {
|
|
4
|
-
chatApiEndpoint: string;
|
|
5
|
-
headers?: Record<string, string>;
|
|
6
|
-
body?: Record<string, any>;
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
}): JSX.Element;
|
|
9
|
-
declare const defaultCopilotContextCategories: string[];
|
|
10
|
-
|
|
11
|
-
export { CopilotProvider, defaultCopilotContextCategories };
|