@copilotkit/react-core 0.18.0-alpha.8 → 0.18.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 +198 -245
- package/CHANGELOG.md +43 -0
- package/dist/chunk-4CFJ6A6A.mjs +15 -9
- package/dist/chunk-4CFJ6A6A.mjs.map +1 -1
- package/dist/chunk-5GS7FQPW.mjs +20 -7
- package/dist/chunk-5GS7FQPW.mjs.map +1 -1
- package/dist/chunk-5UGLWBZJ.mjs +0 -2
- package/dist/chunk-5UGLWBZJ.mjs.map +1 -1
- package/dist/chunk-7GFKOIO7.mjs +0 -2
- package/dist/chunk-7GFKOIO7.mjs.map +1 -1
- package/dist/chunk-BABVSMJR.mjs +0 -2
- package/dist/chunk-BABVSMJR.mjs.map +1 -1
- package/dist/chunk-DGUVNY3V.mjs +9 -5
- package/dist/chunk-DGUVNY3V.mjs.map +1 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -2
- package/dist/chunk-EFZPSZWO.mjs.map +1 -1
- package/dist/chunk-F2JIAPZQ.mjs +3 -2
- package/dist/chunk-F2JIAPZQ.mjs.map +1 -1
- package/dist/chunk-FRAKUJWH.mjs +0 -2
- package/dist/chunk-FRAKUJWH.mjs.map +1 -1
- package/dist/chunk-GBZZPQ5X.mjs +28 -10
- package/dist/chunk-GBZZPQ5X.mjs.map +1 -1
- package/dist/chunk-IQEWY7P4.mjs +13 -6
- package/dist/chunk-IQEWY7P4.mjs.map +1 -1
- package/dist/chunk-IQH5AQQC.mjs +8 -4
- package/dist/chunk-IQH5AQQC.mjs.map +1 -1
- package/dist/chunk-JD7BAH7U.mjs +0 -2
- package/dist/chunk-JD7BAH7U.mjs.map +1 -1
- package/dist/chunk-MRXNTQOX.mjs +6 -2
- package/dist/chunk-MRXNTQOX.mjs.map +1 -1
- package/dist/chunk-MZ5UN3BY.mjs +6 -3
- package/dist/chunk-MZ5UN3BY.mjs.map +1 -1
- package/dist/chunk-SPCZTZCY.mjs +0 -2
- package/dist/chunk-SPCZTZCY.mjs.map +1 -1
- package/dist/chunk-UAKLDQMP.mjs +16 -4
- package/dist/chunk-UAKLDQMP.mjs.map +1 -1
- package/dist/chunk-VNRDQJXW.mjs +0 -2
- package/dist/chunk-VNRDQJXW.mjs.map +1 -1
- package/dist/chunk-VP2EU4US.mjs +21 -9
- package/dist/chunk-VP2EU4US.mjs.map +1 -1
- package/dist/chunk-VUY2K2DI.mjs +10 -5
- package/dist/chunk-VUY2K2DI.mjs.map +1 -1
- package/dist/chunk-YOXWT7I6.mjs +8 -4
- package/dist/chunk-YOXWT7I6.mjs.map +1 -1
- package/dist/chunk-YULKJPY3.mjs +5 -5
- package/dist/chunk-YULKJPY3.mjs.map +1 -1
- package/dist/components/copilot-provider/copilotkit-props.js +18 -2
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit-props.mjs +1 -2
- package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +89 -44
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +14 -7
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -1
- package/dist/components/copilot-provider/index.js +90 -44
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +14 -8
- package/dist/components/copilot-provider/index.mjs.map +1 -1
- package/dist/components/copilot-provider/standard-copilot-api-config.js +27 -4
- package/dist/components/copilot-provider/standard-copilot-api-config.js.map +1 -1
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs +7 -3
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -1
- package/dist/components/index.js +90 -44
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +15 -9
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.js +68 -16
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +8 -3
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.js +68 -15
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +8 -4
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.js +98 -42
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +29 -16
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-chat.js +38 -15
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +8 -4
- package/dist/hooks/use-chat.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.js +72 -30
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +18 -12
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.js +30 -12
- package/dist/hooks/use-flat-category-store.js.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +7 -3
- package/dist/hooks/use-flat-category-store.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.js +77 -20
- package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +9 -4
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js +73 -18
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +9 -4
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.js +73 -18
- package/dist/hooks/use-make-copilot-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +9 -4
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/hooks/use-tree.js +30 -13
- package/dist/hooks/use-tree.js.map +1 -1
- package/dist/hooks/use-tree.mjs +7 -3
- package/dist/hooks/use-tree.mjs.map +1 -1
- package/dist/index.js +165 -83
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -23
- package/dist/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/index.js +67 -27
- package/dist/openai-assistants/hooks/index.js.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +18 -14
- package/dist/openai-assistants/hooks/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-assistants.js +40 -14
- package/dist/openai-assistants/hooks/use-assistants.js.map +1 -1
- package/dist/openai-assistants/hooks/use-assistants.mjs +14 -8
- package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +67 -28
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +19 -13
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
- package/dist/openai-assistants/index.js +69 -28
- package/dist/openai-assistants/index.js.map +1 -1
- package/dist/openai-assistants/index.mjs +22 -15
- package/dist/openai-assistants/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/index.js +29 -5
- package/dist/openai-assistants/utils/index.js.map +1 -1
- package/dist/openai-assistants/utils/index.mjs +8 -4
- package/dist/openai-assistants/utils/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/process-message-stream.js +27 -5
- package/dist/openai-assistants/utils/process-message-stream.js.map +1 -1
- package/dist/openai-assistants/utils/process-message-stream.mjs +7 -3
- package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -1
- package/dist/types/document-pointer.js +17 -2
- package/dist/types/document-pointer.js.map +1 -1
- package/dist/types/document-pointer.mjs +0 -2
- package/dist/types/document-pointer.mjs.map +1 -1
- package/dist/types/index.js +17 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -2
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/system-message.js +17 -2
- package/dist/types/system-message.js.map +1 -1
- package/dist/types/system-message.mjs +0 -2
- package/dist/types/system-message.mjs.map +1 -1
- package/dist/utils/fetch-chat-completion.js +35 -12
- package/dist/utils/fetch-chat-completion.js.map +1 -1
- package/dist/utils/fetch-chat-completion.mjs +11 -3
- package/dist/utils/fetch-chat-completion.mjs.map +1 -1
- package/dist/utils/utils.js +17 -2
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +0 -2
- package/dist/utils/utils.mjs.map +1 -1
- package/dist/utils/utils.test.js +1 -2
- package/dist/utils/utils.test.js.map +1 -1
- package/dist/utils/utils.test.mjs +0 -1
- package/dist/utils/utils.test.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-tree.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-tree.ts"],"sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (value: string, categories: string[], parentId?: TreeNodeId) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (nodes: Tree, newNode: TreeNode, parentId?: TreeNodeId): Tree => {\n if (!parentId) {\n return [...nodes, newNode];\n }\n return nodes.map((node) => {\n if (node.id === parentId) {\n return { ...node, children: [...node.children, newNode] };\n } else if (node.children.length) {\n return { ...node, children: addNode(node.children, newNode, parentId) };\n }\n return node;\n });\n};\n\nconst treeIndentationRepresentation = (index: number, indentLevel: number): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,\n indentLevel + 1,\n )),\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = nanoid(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n [],\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);\n });\n return output;\n },\n [tree],\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":"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","names":[]}
|
package/dist/hooks/use-tree.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
use_tree_default
|
|
3
|
+
} from "../chunk-VUY2K2DI.mjs";
|
|
4
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
5
|
+
export {
|
|
6
|
+
use_tree_default as default
|
|
7
|
+
};
|
|
4
8
|
//# sourceMappingURL=use-tree.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var nanoid = require('nanoid');
|
|
5
|
-
var shared = require('@copilotkit/shared');
|
|
6
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
-
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
12
3
|
var __defProp = Object.defineProperty;
|
|
13
4
|
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
6
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
11
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
18
12
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -40,6 +34,27 @@ var __objRest = (source, exclude) => {
|
|
|
40
34
|
}
|
|
41
35
|
return target;
|
|
42
36
|
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
58
|
var __async = (__this, __arguments, generator) => {
|
|
44
59
|
return new Promise((resolve, reject) => {
|
|
45
60
|
var fulfilled = (value) => {
|
|
@@ -60,20 +75,45 @@ var __async = (__this, __arguments, generator) => {
|
|
|
60
75
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
61
76
|
});
|
|
62
77
|
};
|
|
78
|
+
|
|
79
|
+
// src/index.tsx
|
|
80
|
+
var src_exports = {};
|
|
81
|
+
__export(src_exports, {
|
|
82
|
+
CopilotContext: () => CopilotContext,
|
|
83
|
+
CopilotKit: () => CopilotKit,
|
|
84
|
+
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
85
|
+
fetchAndDecodeChatCompletion: () => fetchAndDecodeChatCompletion,
|
|
86
|
+
fetchAndDecodeChatCompletionAsText: () => fetchAndDecodeChatCompletionAsText,
|
|
87
|
+
fetchChatCompletion: () => fetchChatCompletion,
|
|
88
|
+
processMessageStream: () => processMessageStream,
|
|
89
|
+
useCopilotChat: () => useCopilotChat,
|
|
90
|
+
useCopilotChatV2: () => useCopilotChatV2,
|
|
91
|
+
useMakeCopilotActionable: () => useMakeCopilotActionable,
|
|
92
|
+
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
93
|
+
useMakeCopilotReadable: () => useMakeCopilotReadable
|
|
94
|
+
});
|
|
95
|
+
module.exports = __toCommonJS(src_exports);
|
|
96
|
+
|
|
97
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
98
|
+
var import_react4 = require("react");
|
|
99
|
+
|
|
100
|
+
// src/context/copilot-context.tsx
|
|
101
|
+
var import_react = __toESM(require("react"));
|
|
63
102
|
var emptyCopilotContext = {
|
|
64
103
|
entryPoints: {},
|
|
65
104
|
setEntryPoint: () => {
|
|
66
105
|
},
|
|
67
106
|
removeEntryPoint: () => {
|
|
68
107
|
},
|
|
69
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
|
|
70
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(),
|
|
71
|
-
|
|
108
|
+
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
109
|
+
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
110
|
+
})),
|
|
111
|
+
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
72
112
|
addContext: () => "",
|
|
73
113
|
removeContext: () => {
|
|
74
114
|
},
|
|
75
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug(),
|
|
76
|
-
addDocumentContext: () => returnAndThrowInDebug(),
|
|
115
|
+
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
116
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
77
117
|
removeDocumentContext: () => {
|
|
78
118
|
},
|
|
79
119
|
copilotApiConfig: new class {
|
|
@@ -91,10 +131,15 @@ var emptyCopilotContext = {
|
|
|
91
131
|
}
|
|
92
132
|
}()
|
|
93
133
|
};
|
|
94
|
-
var CopilotContext =
|
|
134
|
+
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
95
135
|
function returnAndThrowInDebug(value) {
|
|
96
136
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
137
|
+
return value;
|
|
97
138
|
}
|
|
139
|
+
|
|
140
|
+
// src/hooks/use-tree.ts
|
|
141
|
+
var import_nanoid = require("nanoid");
|
|
142
|
+
var import_react2 = require("react");
|
|
98
143
|
var removeNode = (nodes, id) => {
|
|
99
144
|
return nodes.reduce((result, node) => {
|
|
100
145
|
if (node.id !== id) {
|
|
@@ -175,10 +220,10 @@ function treeReducer(state, action) {
|
|
|
175
220
|
}
|
|
176
221
|
}
|
|
177
222
|
var useTree = () => {
|
|
178
|
-
const [tree, dispatch] =
|
|
179
|
-
const addElement =
|
|
223
|
+
const [tree, dispatch] = (0, import_react2.useReducer)(treeReducer, []);
|
|
224
|
+
const addElement = (0, import_react2.useCallback)(
|
|
180
225
|
(value, categories, parentId) => {
|
|
181
|
-
const newNodeId =
|
|
226
|
+
const newNodeId = (0, import_nanoid.nanoid)();
|
|
182
227
|
dispatch({
|
|
183
228
|
type: "ADD_NODE",
|
|
184
229
|
value,
|
|
@@ -190,10 +235,10 @@ var useTree = () => {
|
|
|
190
235
|
},
|
|
191
236
|
[]
|
|
192
237
|
);
|
|
193
|
-
const removeElement =
|
|
238
|
+
const removeElement = (0, import_react2.useCallback)((id) => {
|
|
194
239
|
dispatch({ type: "REMOVE_NODE", id });
|
|
195
240
|
}, []);
|
|
196
|
-
const printTree =
|
|
241
|
+
const printTree = (0, import_react2.useCallback)(
|
|
197
242
|
(categories) => {
|
|
198
243
|
const categoriesSet = new Set(categories);
|
|
199
244
|
let output = "";
|
|
@@ -222,10 +267,17 @@ function setsHaveIntersection(setA, setB) {
|
|
|
222
267
|
}
|
|
223
268
|
return false;
|
|
224
269
|
}
|
|
270
|
+
|
|
271
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
272
|
+
var import_shared = require("@copilotkit/shared");
|
|
273
|
+
|
|
274
|
+
// src/hooks/use-flat-category-store.ts
|
|
275
|
+
var import_nanoid2 = require("nanoid");
|
|
276
|
+
var import_react3 = require("react");
|
|
225
277
|
var useFlatCategoryStore = () => {
|
|
226
|
-
const [elements, dispatch] =
|
|
227
|
-
const addElement =
|
|
228
|
-
const newId =
|
|
278
|
+
const [elements, dispatch] = (0, import_react3.useReducer)(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
|
|
279
|
+
const addElement = (0, import_react3.useCallback)((value, categories) => {
|
|
280
|
+
const newId = (0, import_nanoid2.nanoid)();
|
|
229
281
|
dispatch({
|
|
230
282
|
type: "ADD_ELEMENT",
|
|
231
283
|
value,
|
|
@@ -234,10 +286,10 @@ var useFlatCategoryStore = () => {
|
|
|
234
286
|
});
|
|
235
287
|
return newId;
|
|
236
288
|
}, []);
|
|
237
|
-
const removeElement =
|
|
289
|
+
const removeElement = (0, import_react3.useCallback)((id) => {
|
|
238
290
|
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
239
291
|
}, []);
|
|
240
|
-
const allElements =
|
|
292
|
+
const allElements = (0, import_react3.useCallback)(
|
|
241
293
|
(categories) => {
|
|
242
294
|
const categoriesSet = new Set(categories);
|
|
243
295
|
const result = [];
|
|
@@ -294,30 +346,33 @@ var StandardCopilotApiConfig = class {
|
|
|
294
346
|
this.body = body;
|
|
295
347
|
}
|
|
296
348
|
};
|
|
349
|
+
|
|
350
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
351
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
297
352
|
function CopilotKit(_a) {
|
|
298
353
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
299
|
-
const [entryPoints, setEntryPoints] =
|
|
354
|
+
const [entryPoints, setEntryPoints] = (0, import_react4.useState)({});
|
|
300
355
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
301
356
|
const {
|
|
302
357
|
addElement: addDocument,
|
|
303
358
|
removeElement: removeDocument,
|
|
304
359
|
allElements: allDocuments
|
|
305
360
|
} = use_flat_category_store_default();
|
|
306
|
-
const setEntryPoint =
|
|
361
|
+
const setEntryPoint = (0, import_react4.useCallback)((id, entryPoint) => {
|
|
307
362
|
setEntryPoints((prevPoints) => {
|
|
308
363
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
309
364
|
[id]: entryPoint
|
|
310
365
|
});
|
|
311
366
|
});
|
|
312
367
|
}, []);
|
|
313
|
-
const removeEntryPoint =
|
|
368
|
+
const removeEntryPoint = (0, import_react4.useCallback)((id) => {
|
|
314
369
|
setEntryPoints((prevPoints) => {
|
|
315
370
|
const newPoints = __spreadValues({}, prevPoints);
|
|
316
371
|
delete newPoints[id];
|
|
317
372
|
return newPoints;
|
|
318
373
|
});
|
|
319
374
|
}, []);
|
|
320
|
-
const getContextString =
|
|
375
|
+
const getContextString = (0, import_react4.useCallback)(
|
|
321
376
|
(documents, categories) => {
|
|
322
377
|
const documentsString = documents.map((document) => {
|
|
323
378
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -330,37 +385,37 @@ ${nonDocumentStrings}`;
|
|
|
330
385
|
},
|
|
331
386
|
[printTree]
|
|
332
387
|
);
|
|
333
|
-
const addContext =
|
|
388
|
+
const addContext = (0, import_react4.useCallback)(
|
|
334
389
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
335
390
|
return addElement(context, categories, parentId);
|
|
336
391
|
},
|
|
337
392
|
[addElement]
|
|
338
393
|
);
|
|
339
|
-
const removeContext =
|
|
394
|
+
const removeContext = (0, import_react4.useCallback)(
|
|
340
395
|
(id) => {
|
|
341
396
|
removeElement(id);
|
|
342
397
|
},
|
|
343
398
|
[removeElement]
|
|
344
399
|
);
|
|
345
|
-
const getChatCompletionFunctionDescriptions =
|
|
400
|
+
const getChatCompletionFunctionDescriptions = (0, import_react4.useCallback)(() => {
|
|
346
401
|
return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
|
|
347
402
|
}, [entryPoints]);
|
|
348
|
-
const getFunctionCallHandler =
|
|
403
|
+
const getFunctionCallHandler = (0, import_react4.useCallback)(() => {
|
|
349
404
|
return entryPointsToFunctionCallHandler(Object.values(entryPoints));
|
|
350
405
|
}, [entryPoints]);
|
|
351
|
-
const getDocumentsContext =
|
|
406
|
+
const getDocumentsContext = (0, import_react4.useCallback)(
|
|
352
407
|
(categories) => {
|
|
353
408
|
return allDocuments(categories);
|
|
354
409
|
},
|
|
355
410
|
[allDocuments]
|
|
356
411
|
);
|
|
357
|
-
const addDocumentContext =
|
|
412
|
+
const addDocumentContext = (0, import_react4.useCallback)(
|
|
358
413
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
359
414
|
return addDocument(documentPointer, categories);
|
|
360
415
|
},
|
|
361
416
|
[addDocument]
|
|
362
417
|
);
|
|
363
|
-
const removeDocumentContext =
|
|
418
|
+
const removeDocumentContext = (0, import_react4.useCallback)(
|
|
364
419
|
(documentId) => {
|
|
365
420
|
removeDocument(documentId);
|
|
366
421
|
},
|
|
@@ -372,7 +427,7 @@ ${nonDocumentStrings}`;
|
|
|
372
427
|
props.headers || {},
|
|
373
428
|
props.body || {}
|
|
374
429
|
);
|
|
375
|
-
return /* @__PURE__ */
|
|
430
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
376
431
|
CopilotContext.Provider,
|
|
377
432
|
{
|
|
378
433
|
value: {
|
|
@@ -417,8 +472,18 @@ function entryPointsToFunctionCallHandler(entryPoints) {
|
|
|
417
472
|
});
|
|
418
473
|
}
|
|
419
474
|
function entryPointsToChatCompletionFunctions(entryPoints) {
|
|
420
|
-
return entryPoints.map(
|
|
475
|
+
return entryPoints.map(import_shared.annotatedFunctionToChatCompletionFunction);
|
|
421
476
|
}
|
|
477
|
+
|
|
478
|
+
// src/hooks/use-copilot-chat.ts
|
|
479
|
+
var import_react6 = require("react");
|
|
480
|
+
|
|
481
|
+
// src/hooks/use-chat.ts
|
|
482
|
+
var import_react5 = require("react");
|
|
483
|
+
var import_nanoid3 = require("nanoid");
|
|
484
|
+
|
|
485
|
+
// src/utils/fetch-chat-completion.ts
|
|
486
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
422
487
|
function fetchChatCompletion(_0) {
|
|
423
488
|
return __async(this, arguments, function* ({
|
|
424
489
|
copilotConfig,
|
|
@@ -457,7 +522,7 @@ function fetchAndDecodeChatCompletion(params) {
|
|
|
457
522
|
if (!response.ok || !response.body) {
|
|
458
523
|
return __spreadProps(__spreadValues({}, response), { events: null });
|
|
459
524
|
}
|
|
460
|
-
const events = yield
|
|
525
|
+
const events = yield (0, import_shared2.decodeChatCompletion)((0, import_shared2.parseChatCompletion)(response.body));
|
|
461
526
|
return __spreadProps(__spreadValues({}, response), { events });
|
|
462
527
|
});
|
|
463
528
|
}
|
|
@@ -467,8 +532,8 @@ function fetchAndDecodeChatCompletionAsText(params) {
|
|
|
467
532
|
if (!response.ok || !response.body) {
|
|
468
533
|
return __spreadProps(__spreadValues({}, response), { events: null });
|
|
469
534
|
}
|
|
470
|
-
const events = yield
|
|
471
|
-
|
|
535
|
+
const events = yield (0, import_shared2.decodeChatCompletionAsText)(
|
|
536
|
+
(0, import_shared2.decodeChatCompletion)((0, import_shared2.parseChatCompletion)(response.body))
|
|
472
537
|
);
|
|
473
538
|
return __spreadProps(__spreadValues({}, response), { events });
|
|
474
539
|
});
|
|
@@ -476,14 +541,14 @@ function fetchAndDecodeChatCompletionAsText(params) {
|
|
|
476
541
|
|
|
477
542
|
// src/hooks/use-chat.ts
|
|
478
543
|
function useChat(options) {
|
|
479
|
-
const [messages, setMessages] =
|
|
480
|
-
const [input, setInput] =
|
|
481
|
-
const [isLoading, setIsLoading] =
|
|
482
|
-
const abortControllerRef =
|
|
544
|
+
const [messages, setMessages] = (0, import_react5.useState)([]);
|
|
545
|
+
const [input, setInput] = (0, import_react5.useState)("");
|
|
546
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
547
|
+
const abortControllerRef = (0, import_react5.useRef)();
|
|
483
548
|
const runChatCompletion = (messages2) => __async(this, null, function* () {
|
|
484
549
|
setIsLoading(true);
|
|
485
550
|
const assistantMessage = {
|
|
486
|
-
id:
|
|
551
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
487
552
|
createdAt: /* @__PURE__ */ new Date(),
|
|
488
553
|
content: "",
|
|
489
554
|
role: "assistant"
|
|
@@ -583,8 +648,8 @@ function useCopilotChat(_a) {
|
|
|
583
648
|
getChatCompletionFunctionDescriptions,
|
|
584
649
|
getFunctionCallHandler,
|
|
585
650
|
copilotApiConfig
|
|
586
|
-
} =
|
|
587
|
-
const systemMessage =
|
|
651
|
+
} = (0, import_react6.useContext)(CopilotContext);
|
|
652
|
+
const systemMessage = (0, import_react6.useMemo)(() => {
|
|
588
653
|
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
589
654
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
590
655
|
return {
|
|
@@ -593,7 +658,7 @@ function useCopilotChat(_a) {
|
|
|
593
658
|
role: "system"
|
|
594
659
|
};
|
|
595
660
|
}, [getContextString, makeSystemMessage]);
|
|
596
|
-
const functionDescriptions =
|
|
661
|
+
const functionDescriptions = (0, import_react6.useMemo)(() => {
|
|
597
662
|
return getChatCompletionFunctionDescriptions();
|
|
598
663
|
}, [getChatCompletionFunctionDescriptions]);
|
|
599
664
|
const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
@@ -641,10 +706,14 @@ If you would like to call a function, call it without saying anything else.
|
|
|
641
706
|
|
|
642
707
|
${additionalInstructions}` : "");
|
|
643
708
|
}
|
|
709
|
+
|
|
710
|
+
// src/hooks/use-make-copilot-actionable.ts
|
|
711
|
+
var import_react7 = require("react");
|
|
712
|
+
var import_nanoid4 = require("nanoid");
|
|
644
713
|
function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
645
|
-
const idRef =
|
|
646
|
-
const { setEntryPoint, removeEntryPoint } =
|
|
647
|
-
const memoizedAnnotatedFunction =
|
|
714
|
+
const idRef = (0, import_react7.useRef)((0, import_nanoid4.nanoid)());
|
|
715
|
+
const { setEntryPoint, removeEntryPoint } = (0, import_react7.useContext)(CopilotContext);
|
|
716
|
+
const memoizedAnnotatedFunction = (0, import_react7.useMemo)(
|
|
648
717
|
() => ({
|
|
649
718
|
name: annotatedFunction.name,
|
|
650
719
|
description: annotatedFunction.description,
|
|
@@ -653,17 +722,20 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
|
653
722
|
}),
|
|
654
723
|
dependencies
|
|
655
724
|
);
|
|
656
|
-
|
|
725
|
+
(0, import_react7.useEffect)(() => {
|
|
657
726
|
setEntryPoint(idRef.current, memoizedAnnotatedFunction);
|
|
658
727
|
return () => {
|
|
659
728
|
removeEntryPoint(idRef.current);
|
|
660
729
|
};
|
|
661
730
|
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
662
731
|
}
|
|
732
|
+
|
|
733
|
+
// src/hooks/use-make-copilot-readable.ts
|
|
734
|
+
var import_react8 = require("react");
|
|
663
735
|
function useMakeCopilotReadable(information, parentId, categories) {
|
|
664
|
-
const { addContext, removeContext } =
|
|
665
|
-
const idRef =
|
|
666
|
-
|
|
736
|
+
const { addContext, removeContext } = (0, import_react8.useContext)(CopilotContext);
|
|
737
|
+
const idRef = (0, import_react8.useRef)();
|
|
738
|
+
(0, import_react8.useEffect)(() => {
|
|
667
739
|
const id = addContext(information, parentId, categories);
|
|
668
740
|
idRef.current = id;
|
|
669
741
|
return () => {
|
|
@@ -672,10 +744,13 @@ function useMakeCopilotReadable(information, parentId, categories) {
|
|
|
672
744
|
}, [information, parentId, addContext, removeContext]);
|
|
673
745
|
return idRef.current;
|
|
674
746
|
}
|
|
747
|
+
|
|
748
|
+
// src/hooks/use-make-copilot-document-readable.ts
|
|
749
|
+
var import_react9 = require("react");
|
|
675
750
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
676
|
-
const { addDocumentContext, removeDocumentContext } =
|
|
677
|
-
const idRef =
|
|
678
|
-
|
|
751
|
+
const { addDocumentContext, removeDocumentContext } = (0, import_react9.useContext)(CopilotContext);
|
|
752
|
+
const idRef = (0, import_react9.useRef)();
|
|
753
|
+
(0, import_react9.useEffect)(() => {
|
|
679
754
|
const id = addDocumentContext(document, categories);
|
|
680
755
|
idRef.current = id;
|
|
681
756
|
return () => {
|
|
@@ -685,6 +760,9 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
685
760
|
return idRef.current;
|
|
686
761
|
}
|
|
687
762
|
|
|
763
|
+
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
764
|
+
var import_react10 = require("react");
|
|
765
|
+
|
|
688
766
|
// src/openai-assistants/utils/process-message-stream.ts
|
|
689
767
|
function processMessageStream(reader, processMessage) {
|
|
690
768
|
return __async(this, null, function* () {
|
|
@@ -707,19 +785,22 @@ function processMessageStream(reader, processMessage) {
|
|
|
707
785
|
}
|
|
708
786
|
});
|
|
709
787
|
}
|
|
788
|
+
|
|
789
|
+
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
790
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
710
791
|
function useCopilotChatV2(options) {
|
|
711
792
|
const {
|
|
712
793
|
getContextString,
|
|
713
794
|
getChatCompletionFunctionDescriptions,
|
|
714
795
|
getFunctionCallHandler,
|
|
715
796
|
copilotApiConfig
|
|
716
|
-
} =
|
|
717
|
-
const [messages, setMessages] =
|
|
718
|
-
const [input, setInput] =
|
|
719
|
-
const [threadId, setThreadId] =
|
|
720
|
-
const [status, setStatus] =
|
|
721
|
-
const [error, setError] =
|
|
722
|
-
|
|
797
|
+
} = (0, import_react10.useContext)(CopilotContext);
|
|
798
|
+
const [messages, setMessages] = (0, import_react10.useState)([]);
|
|
799
|
+
const [input, setInput] = (0, import_react10.useState)("");
|
|
800
|
+
const [threadId, setThreadId] = (0, import_react10.useState)(void 0);
|
|
801
|
+
const [status, setStatus] = (0, import_react10.useState)("awaiting_message");
|
|
802
|
+
const [error, setError] = (0, import_react10.useState)(void 0);
|
|
803
|
+
const systemMessage = (0, import_react10.useMemo)(() => {
|
|
723
804
|
const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage2;
|
|
724
805
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
725
806
|
return {
|
|
@@ -758,7 +839,7 @@ function useCopilotChatV2(options) {
|
|
|
758
839
|
}
|
|
759
840
|
yield processMessageStream(result.body.getReader(), (message) => {
|
|
760
841
|
try {
|
|
761
|
-
const { type, value } =
|
|
842
|
+
const { type, value } = (0, import_shared3.parseStreamPart)(message);
|
|
762
843
|
switch (type) {
|
|
763
844
|
case "assistant_message": {
|
|
764
845
|
setMessages((messages2) => [
|
|
@@ -821,18 +902,19 @@ You can ask them for clarifying questions if needed, but don't be annoying about
|
|
|
821
902
|
If you would like to call a function, call it without saying anything else.
|
|
822
903
|
`;
|
|
823
904
|
}
|
|
824
|
-
|
|
825
|
-
exports
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
905
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
906
|
+
0 && (module.exports = {
|
|
907
|
+
CopilotContext,
|
|
908
|
+
CopilotKit,
|
|
909
|
+
defaultCopilotContextCategories,
|
|
910
|
+
fetchAndDecodeChatCompletion,
|
|
911
|
+
fetchAndDecodeChatCompletionAsText,
|
|
912
|
+
fetchChatCompletion,
|
|
913
|
+
processMessageStream,
|
|
914
|
+
useCopilotChat,
|
|
915
|
+
useCopilotChatV2,
|
|
916
|
+
useMakeCopilotActionable,
|
|
917
|
+
useMakeCopilotDocumentReadable,
|
|
918
|
+
useMakeCopilotReadable
|
|
919
|
+
});
|
|
838
920
|
//# sourceMappingURL=index.js.map
|