@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/openai-assistants/hooks/use-copilot-chat-v2.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/openai-assistants/hooks/use-copilot-chat-v2.ts"],"sourcesContent":["import { useContext, useMemo, useState } from \"react\";\nimport { processMessageStream } from \"../utils\";\nimport { Message, parseStreamPart } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"../../context\";\nimport { defaultCopilotContextCategories } from \"../../components\";\n\nexport type AssistantStatus = \"in_progress\" | \"awaiting_message\";\n\nexport interface RequestForwardingOptions {\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n}\nexport interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {\n makeSystemMessage?: (contextString: string) => string;\n threadId?: string | undefined;\n}\n\nexport interface UseCopilotChatV2Result {\n messages: Message[];\n input: string;\n handleInputChange: (e: any) => void;\n submitMessage: (e: any) => Promise<void>;\n status: AssistantStatus;\n error: unknown;\n}\n\nexport function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const [messages, setMessages] = useState<Message[]>([]);\n const [input, setInput] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const [status, setStatus] = useState<AssistantStatus>(\"awaiting_message\");\n const [error, setError] = useState<unknown | undefined>(undefined);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = options.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, options.makeSystemMessage]);\n\n const handleInputChange = (e: any) => {\n setInput(e.target.value);\n };\n\n const submitMessage = async (e: any) => {\n e.preventDefault();\n\n if (input === \"\") {\n return;\n }\n\n setStatus(\"in_progress\");\n\n setMessages((messages) => [...messages, { id: \"\", role: \"user\", content: input }]);\n\n setInput(\"\");\n\n const apiUrl = copilotApiConfig.chatApiEndpointV2;\n\n const functions = getChatCompletionFunctionDescriptions();\n\n const result = await fetch(apiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotApiConfig.headers,\n ...options.headers,\n },\n body: JSON.stringify({\n // always use user-provided threadId when available:\n threadId: options.threadId ?? threadId ?? null,\n message: input,\n ...(functions.length > 0 && { functions: functions }),\n ...copilotApiConfig.body,\n ...options.body,\n }),\n });\n\n if (result.body == null) {\n throw new Error(\"The response body is empty.\");\n }\n\n await processMessageStream(result.body.getReader(), (message: string) => {\n try {\n const { type, value } = parseStreamPart(message);\n\n switch (type) {\n case \"assistant_message\": {\n // append message:\n setMessages((messages) => [\n ...messages,\n {\n id: value.id,\n role: value.role,\n content: value.content[0].text.value,\n },\n ]);\n break;\n }\n\n case \"assistant_control_data\": {\n setThreadId(value.threadId);\n\n // set id of last message:\n setMessages((messages) => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n return [...messages.slice(0, messages.length - 1), lastMessage];\n });\n\n break;\n }\n\n case \"error\": {\n setError(value);\n break;\n }\n }\n } catch (error) {\n setError(error);\n }\n });\n\n setStatus(\"awaiting_message\");\n };\n\n return {\n messages,\n input,\n handleInputChange,\n submitMessage,\n status,\n error,\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"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,YAAY,SAAS,gBAAgB;AAE9C,SAAkB,uBAAuB;AA6ClC,SAAS,iBAAiB,SAA0D;AACzF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,CAAC,UAAU,WAAW,IAAI,SAA6B,MAAS;AACtE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0B,kBAAkB;AACxE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA8B,MAAS;AAEjE,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,QAAQ,qBAAqB;AACxD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,aAAa;AAAA,MACz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AA0B;AAC7B,wBAAY,MAAM,QAAQ;AAG1B,wBAAY,CAACA,cAAa;AACxB,oBAAM,cAAcA,UAASA,UAAS,SAAS,CAAC;AAChD,0BAAY,KAAK,MAAM;AACvB,qBAAO,CAAC,GAAGA,UAAS,MAAM,GAAGA,UAAS,SAAS,CAAC,GAAG,WAAW;AAAA,YAChE,CAAC;AAED;AAAA,UACF;AAAA,UAEA,KAAK,SAAS;AACZ,qBAAS,KAAK;AACd;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAASC,QAAP;AACA,iBAASA,MAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAED,cAAU,kBAAkB;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;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;","names":["messages","error"]}
|
package/dist/chunk-VUY2K2DI.mjs
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-MRXNTQOX.mjs";
|
|
4
5
|
|
|
6
|
+
// src/hooks/use-tree.ts
|
|
7
|
+
import { nanoid } from "nanoid";
|
|
8
|
+
import { useCallback, useReducer } from "react";
|
|
5
9
|
var removeNode = (nodes, id) => {
|
|
6
10
|
return nodes.reduce((result, node) => {
|
|
7
11
|
if (node.id !== id) {
|
|
@@ -130,6 +134,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
130
134
|
return false;
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
export {
|
|
134
|
-
|
|
137
|
+
export {
|
|
138
|
+
use_tree_default
|
|
139
|
+
};
|
|
135
140
|
//# sourceMappingURL=chunk-VUY2K2DI.mjs.map
|
|
@@ -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":";;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAkCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,SAAS;AAC1C,QAAI,KAAK,OAAO,IAAI;AAClB,YAAM,UAAU,iCAAK,OAAL,EAAW,UAAU,WAAW,KAAK,UAAU,EAAE,EAAE;AACnE,aAAO,KAAK,OAAO;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEA,IAAM,UAAU,CAAC,OAAa,SAAmB,aAAgC;AAC/E,MAAI,CAAC,UAAU;AACb,WAAO,CAAC,GAAG,OAAO,OAAO;AAAA,EAC3B;AACA,SAAO,MAAM,IAAI,CAAC,SAAS;AACzB,QAAI,KAAK,OAAO,UAAU;AACxB,aAAO,iCAAK,OAAL,EAAW,UAAU,CAAC,GAAG,KAAK,UAAU,OAAO,EAAE;AAAA,IAC1D,WAAW,KAAK,SAAS,QAAQ;AAC/B,aAAO,iCAAK,OAAL,EAAW,UAAU,QAAQ,KAAK,UAAU,SAAS,QAAQ,EAAE;AAAA,IACxE;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,IAAM,gCAAgC,CAAC,OAAe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AAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/chunk-YOXWT7I6.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CopilotContext
|
|
3
|
+
} from "./chunk-4CFJ6A6A.mjs";
|
|
3
4
|
|
|
5
|
+
// src/hooks/use-make-copilot-readable.ts
|
|
6
|
+
import { useContext, useEffect, useRef } from "react";
|
|
4
7
|
function useMakeCopilotReadable(information, parentId, categories) {
|
|
5
8
|
const { addContext, removeContext } = useContext(CopilotContext);
|
|
6
9
|
const idRef = useRef();
|
|
@@ -14,6 +17,7 @@ function useMakeCopilotReadable(information, parentId, categories) {
|
|
|
14
17
|
return idRef.current;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
export {
|
|
18
|
-
|
|
20
|
+
export {
|
|
21
|
+
useMakeCopilotReadable
|
|
22
|
+
};
|
|
19
23
|
//# sourceMappingURL=chunk-YOXWT7I6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-make-copilot-readable.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-make-copilot-readable.ts"],"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"],"mappings":";;;;;AAEA,SAAS,YAAY,WAAW,cAAc;AAUvC,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;","names":[]}
|
package/dist/chunk-YULKJPY3.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid';
|
|
2
|
-
import { useReducer, useCallback } from 'react';
|
|
3
|
-
|
|
4
1
|
// src/hooks/use-flat-category-store.ts
|
|
2
|
+
import { nanoid } from "nanoid";
|
|
3
|
+
import { useCallback, useReducer } from "react";
|
|
5
4
|
var useFlatCategoryStore = () => {
|
|
6
5
|
const [elements, dispatch] = useReducer(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
|
|
7
6
|
const addElement = useCallback((value, categories) => {
|
|
@@ -65,6 +64,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
65
64
|
return false;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
export {
|
|
69
|
-
|
|
67
|
+
export {
|
|
68
|
+
use_flat_category_store_default
|
|
69
|
+
};
|
|
70
70
|
//# sourceMappingURL=chunk-YULKJPY3.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-flat-category-store.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-flat-category-store.ts"],"sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type FlatCategoryStoreId = string;\n\nexport interface UseFlatCategoryStoreReturn<T> {\n addElement: (value: T, categories: string[]) => FlatCategoryStoreId;\n removeElement: (id: FlatCategoryStoreId) => void;\n allElements: (categories: string[]) => T[];\n}\n\ninterface FlatCategoryStoreElement<T> {\n id: FlatCategoryStoreId;\n value: T;\n categories: Set<string>;\n}\n\nconst useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {\n const [elements, dispatch] = useReducer<\n React.Reducer<Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>, Action<T>>\n >(flatCategoryStoreReducer, new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>());\n\n const addElement = useCallback((value: T, categories: string[]): FlatCategoryStoreId => {\n const newId = nanoid();\n dispatch({\n type: \"ADD_ELEMENT\",\n value,\n id: newId,\n categories,\n });\n return newId;\n }, []);\n\n const removeElement = useCallback((id: FlatCategoryStoreId): void => {\n dispatch({ type: \"REMOVE_ELEMENT\", id });\n }, []);\n\n const allElements = useCallback(\n (categories: string[]): T[] => {\n const categoriesSet = new Set(categories);\n const result: T[] = [];\n elements.forEach((element) => {\n if (setsHaveIntersection(categoriesSet, element.categories)) {\n result.push(element.value);\n }\n });\n return result;\n },\n [elements],\n );\n\n return { addElement, removeElement, allElements };\n};\n\nexport default useFlatCategoryStore;\n\n// Action types\ntype Action<T> =\n | {\n type: \"ADD_ELEMENT\";\n value: T;\n id: FlatCategoryStoreId;\n categories: string[];\n }\n | { type: \"REMOVE_ELEMENT\"; id: FlatCategoryStoreId };\n\n// Reducer\nfunction flatCategoryStoreReducer<T>(\n state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n action: Action<T>,\n): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {\n switch (action.type) {\n case \"ADD_ELEMENT\": {\n const { value, id, categories } = action;\n const newElement: FlatCategoryStoreElement<T> = {\n id,\n value,\n categories: new Set(categories),\n };\n const newState = new Map(state);\n newState.set(id, newElement);\n return newState;\n }\n case \"REMOVE_ELEMENT\": {\n const newState = new Map(state);\n newState.delete(action.id);\n return newState;\n }\n default:\n return state;\n }\n}\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAgBxC,IAAM,uBAAuB,MAAwC;AACnE,QAAM,CAAC,UAAU,QAAQ,IAAI,WAE3B,0BAA0B,oBAAI,IAAsD,CAAC;AAEvF,QAAM,aAAa,YAAY,CAAC,OAAU,eAA8C;AACtF,UAAM,QAAQ,OAAO;AACrB,aAAS;AAAA,MACP,MAAM;AAAA,MACN;AAAA,MACA,IAAI;AAAA,MACJ;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,QAAM,gBAAgB,YAAY,CAAC,OAAkC;AACnE,aAAS,EAAE,MAAM,kBAAkB,GAAG,CAAC;AAAA,EACzC,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc;AAAA,IAClB,CAAC,eAA8B;AAC7B,YAAM,gBAAgB,IAAI,IAAI,UAAU;AACxC,YAAM,SAAc,CAAC;AACrB,eAAS,QAAQ,CAAC,YAAY;AAC5B,YAAI,qBAAqB,eAAe,QAAQ,UAAU,GAAG;AAC3D,iBAAO,KAAK,QAAQ,KAAK;AAAA,QAC3B;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,SAAO,EAAE,YAAY,eAAe,YAAY;AAClD;AAEA,IAAO,kCAAQ;AAaf,SAAS,yBACP,OACA,QACuD;AACvD,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,eAAe;AAClB,YAAM,EAAE,OAAO,IAAI,WAAW,IAAI;AAClC,YAAM,aAA0C;AAAA,QAC9C;AAAA,QACA;AAAA,QACA,YAAY,IAAI,IAAI,UAAU;AAAA,MAChC;AACA,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,IAAI,IAAI,UAAU;AAC3B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,kBAAkB;AACrB,YAAM,WAAW,IAAI,IAAI,KAAK;AAC9B,eAAS,OAAO,OAAO,EAAE;AACzB,aAAO;AAAA,IACT;AAAA,IACA;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAAI,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAEnF,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
16
|
|
|
3
|
-
|
|
17
|
+
// src/components/copilot-provider/copilotkit-props.tsx
|
|
18
|
+
var copilotkit_props_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(copilotkit_props_exports);
|
|
4
20
|
//# sourceMappingURL=copilotkit-props.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode } from \"react\";\n\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n * The endpoint for the chat API.\n */\n url: 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 /**\n * The children to be rendered within the CopilotKit.\n */\n children: ReactNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
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
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
12
4
|
var __defProp = Object.defineProperty;
|
|
13
5
|
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
7
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
9
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
12
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
18
13
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -40,6 +35,27 @@ var __objRest = (source, exclude) => {
|
|
|
40
35
|
}
|
|
41
36
|
return target;
|
|
42
37
|
};
|
|
38
|
+
var __export = (target, all) => {
|
|
39
|
+
for (var name in all)
|
|
40
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
41
|
+
};
|
|
42
|
+
var __copyProps = (to, from, except, desc) => {
|
|
43
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
44
|
+
for (let key of __getOwnPropNames(from))
|
|
45
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
46
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
47
|
+
}
|
|
48
|
+
return to;
|
|
49
|
+
};
|
|
50
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
51
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
52
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
53
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
54
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
55
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
56
|
+
mod
|
|
57
|
+
));
|
|
58
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
59
|
var __async = (__this, __arguments, generator) => {
|
|
44
60
|
return new Promise((resolve, reject) => {
|
|
45
61
|
var fulfilled = (value) => {
|
|
@@ -60,20 +76,33 @@ var __async = (__this, __arguments, generator) => {
|
|
|
60
76
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
61
77
|
});
|
|
62
78
|
};
|
|
79
|
+
|
|
80
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
81
|
+
var copilotkit_exports = {};
|
|
82
|
+
__export(copilotkit_exports, {
|
|
83
|
+
CopilotKit: () => CopilotKit,
|
|
84
|
+
defaultCopilotContextCategories: () => defaultCopilotContextCategories
|
|
85
|
+
});
|
|
86
|
+
module.exports = __toCommonJS(copilotkit_exports);
|
|
87
|
+
var import_react4 = require("react");
|
|
88
|
+
|
|
89
|
+
// src/context/copilot-context.tsx
|
|
90
|
+
var import_react = __toESM(require("react"));
|
|
63
91
|
var emptyCopilotContext = {
|
|
64
92
|
entryPoints: {},
|
|
65
93
|
setEntryPoint: () => {
|
|
66
94
|
},
|
|
67
95
|
removeEntryPoint: () => {
|
|
68
96
|
},
|
|
69
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
|
|
70
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(),
|
|
71
|
-
|
|
97
|
+
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
98
|
+
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
99
|
+
})),
|
|
100
|
+
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
72
101
|
addContext: () => "",
|
|
73
102
|
removeContext: () => {
|
|
74
103
|
},
|
|
75
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug(),
|
|
76
|
-
addDocumentContext: () => returnAndThrowInDebug(),
|
|
104
|
+
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
105
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
77
106
|
removeDocumentContext: () => {
|
|
78
107
|
},
|
|
79
108
|
copilotApiConfig: new class {
|
|
@@ -91,10 +120,15 @@ var emptyCopilotContext = {
|
|
|
91
120
|
}
|
|
92
121
|
}()
|
|
93
122
|
};
|
|
94
|
-
var CopilotContext =
|
|
123
|
+
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
95
124
|
function returnAndThrowInDebug(value) {
|
|
96
125
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
126
|
+
return value;
|
|
97
127
|
}
|
|
128
|
+
|
|
129
|
+
// src/hooks/use-tree.ts
|
|
130
|
+
var import_nanoid = require("nanoid");
|
|
131
|
+
var import_react2 = require("react");
|
|
98
132
|
var removeNode = (nodes, id) => {
|
|
99
133
|
return nodes.reduce((result, node) => {
|
|
100
134
|
if (node.id !== id) {
|
|
@@ -175,10 +209,10 @@ function treeReducer(state, action) {
|
|
|
175
209
|
}
|
|
176
210
|
}
|
|
177
211
|
var useTree = () => {
|
|
178
|
-
const [tree, dispatch] =
|
|
179
|
-
const addElement =
|
|
212
|
+
const [tree, dispatch] = (0, import_react2.useReducer)(treeReducer, []);
|
|
213
|
+
const addElement = (0, import_react2.useCallback)(
|
|
180
214
|
(value, categories, parentId) => {
|
|
181
|
-
const newNodeId =
|
|
215
|
+
const newNodeId = (0, import_nanoid.nanoid)();
|
|
182
216
|
dispatch({
|
|
183
217
|
type: "ADD_NODE",
|
|
184
218
|
value,
|
|
@@ -190,10 +224,10 @@ var useTree = () => {
|
|
|
190
224
|
},
|
|
191
225
|
[]
|
|
192
226
|
);
|
|
193
|
-
const removeElement =
|
|
227
|
+
const removeElement = (0, import_react2.useCallback)((id) => {
|
|
194
228
|
dispatch({ type: "REMOVE_NODE", id });
|
|
195
229
|
}, []);
|
|
196
|
-
const printTree =
|
|
230
|
+
const printTree = (0, import_react2.useCallback)(
|
|
197
231
|
(categories) => {
|
|
198
232
|
const categoriesSet = new Set(categories);
|
|
199
233
|
let output = "";
|
|
@@ -222,10 +256,17 @@ function setsHaveIntersection(setA, setB) {
|
|
|
222
256
|
}
|
|
223
257
|
return false;
|
|
224
258
|
}
|
|
259
|
+
|
|
260
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
261
|
+
var import_shared = require("@copilotkit/shared");
|
|
262
|
+
|
|
263
|
+
// src/hooks/use-flat-category-store.ts
|
|
264
|
+
var import_nanoid2 = require("nanoid");
|
|
265
|
+
var import_react3 = require("react");
|
|
225
266
|
var useFlatCategoryStore = () => {
|
|
226
|
-
const [elements, dispatch] =
|
|
227
|
-
const addElement =
|
|
228
|
-
const newId =
|
|
267
|
+
const [elements, dispatch] = (0, import_react3.useReducer)(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
|
|
268
|
+
const addElement = (0, import_react3.useCallback)((value, categories) => {
|
|
269
|
+
const newId = (0, import_nanoid2.nanoid)();
|
|
229
270
|
dispatch({
|
|
230
271
|
type: "ADD_ELEMENT",
|
|
231
272
|
value,
|
|
@@ -234,10 +275,10 @@ var useFlatCategoryStore = () => {
|
|
|
234
275
|
});
|
|
235
276
|
return newId;
|
|
236
277
|
}, []);
|
|
237
|
-
const removeElement =
|
|
278
|
+
const removeElement = (0, import_react3.useCallback)((id) => {
|
|
238
279
|
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
239
280
|
}, []);
|
|
240
|
-
const allElements =
|
|
281
|
+
const allElements = (0, import_react3.useCallback)(
|
|
241
282
|
(categories) => {
|
|
242
283
|
const categoriesSet = new Set(categories);
|
|
243
284
|
const result = [];
|
|
@@ -294,30 +335,33 @@ var StandardCopilotApiConfig = class {
|
|
|
294
335
|
this.body = body;
|
|
295
336
|
}
|
|
296
337
|
};
|
|
338
|
+
|
|
339
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
340
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
297
341
|
function CopilotKit(_a) {
|
|
298
342
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
299
|
-
const [entryPoints, setEntryPoints] =
|
|
343
|
+
const [entryPoints, setEntryPoints] = (0, import_react4.useState)({});
|
|
300
344
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
301
345
|
const {
|
|
302
346
|
addElement: addDocument,
|
|
303
347
|
removeElement: removeDocument,
|
|
304
348
|
allElements: allDocuments
|
|
305
349
|
} = use_flat_category_store_default();
|
|
306
|
-
const setEntryPoint =
|
|
350
|
+
const setEntryPoint = (0, import_react4.useCallback)((id, entryPoint) => {
|
|
307
351
|
setEntryPoints((prevPoints) => {
|
|
308
352
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
309
353
|
[id]: entryPoint
|
|
310
354
|
});
|
|
311
355
|
});
|
|
312
356
|
}, []);
|
|
313
|
-
const removeEntryPoint =
|
|
357
|
+
const removeEntryPoint = (0, import_react4.useCallback)((id) => {
|
|
314
358
|
setEntryPoints((prevPoints) => {
|
|
315
359
|
const newPoints = __spreadValues({}, prevPoints);
|
|
316
360
|
delete newPoints[id];
|
|
317
361
|
return newPoints;
|
|
318
362
|
});
|
|
319
363
|
}, []);
|
|
320
|
-
const getContextString =
|
|
364
|
+
const getContextString = (0, import_react4.useCallback)(
|
|
321
365
|
(documents, categories) => {
|
|
322
366
|
const documentsString = documents.map((document) => {
|
|
323
367
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -330,37 +374,37 @@ ${nonDocumentStrings}`;
|
|
|
330
374
|
},
|
|
331
375
|
[printTree]
|
|
332
376
|
);
|
|
333
|
-
const addContext =
|
|
377
|
+
const addContext = (0, import_react4.useCallback)(
|
|
334
378
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
335
379
|
return addElement(context, categories, parentId);
|
|
336
380
|
},
|
|
337
381
|
[addElement]
|
|
338
382
|
);
|
|
339
|
-
const removeContext =
|
|
383
|
+
const removeContext = (0, import_react4.useCallback)(
|
|
340
384
|
(id) => {
|
|
341
385
|
removeElement(id);
|
|
342
386
|
},
|
|
343
387
|
[removeElement]
|
|
344
388
|
);
|
|
345
|
-
const getChatCompletionFunctionDescriptions =
|
|
389
|
+
const getChatCompletionFunctionDescriptions = (0, import_react4.useCallback)(() => {
|
|
346
390
|
return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
|
|
347
391
|
}, [entryPoints]);
|
|
348
|
-
const getFunctionCallHandler =
|
|
392
|
+
const getFunctionCallHandler = (0, import_react4.useCallback)(() => {
|
|
349
393
|
return entryPointsToFunctionCallHandler(Object.values(entryPoints));
|
|
350
394
|
}, [entryPoints]);
|
|
351
|
-
const getDocumentsContext =
|
|
395
|
+
const getDocumentsContext = (0, import_react4.useCallback)(
|
|
352
396
|
(categories) => {
|
|
353
397
|
return allDocuments(categories);
|
|
354
398
|
},
|
|
355
399
|
[allDocuments]
|
|
356
400
|
);
|
|
357
|
-
const addDocumentContext =
|
|
401
|
+
const addDocumentContext = (0, import_react4.useCallback)(
|
|
358
402
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
359
403
|
return addDocument(documentPointer, categories);
|
|
360
404
|
},
|
|
361
405
|
[addDocument]
|
|
362
406
|
);
|
|
363
|
-
const removeDocumentContext =
|
|
407
|
+
const removeDocumentContext = (0, import_react4.useCallback)(
|
|
364
408
|
(documentId) => {
|
|
365
409
|
removeDocument(documentId);
|
|
366
410
|
},
|
|
@@ -372,7 +416,7 @@ ${nonDocumentStrings}`;
|
|
|
372
416
|
props.headers || {},
|
|
373
417
|
props.body || {}
|
|
374
418
|
);
|
|
375
|
-
return /* @__PURE__ */
|
|
419
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
376
420
|
CopilotContext.Provider,
|
|
377
421
|
{
|
|
378
422
|
value: {
|
|
@@ -417,10 +461,11 @@ function entryPointsToFunctionCallHandler(entryPoints) {
|
|
|
417
461
|
});
|
|
418
462
|
}
|
|
419
463
|
function entryPointsToChatCompletionFunctions(entryPoints) {
|
|
420
|
-
return entryPoints.map(
|
|
464
|
+
return entryPoints.map(import_shared.annotatedFunctionToChatCompletionFunction);
|
|
421
465
|
}
|
|
422
|
-
|
|
423
|
-
exports
|
|
424
|
-
|
|
425
|
-
|
|
466
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
467
|
+
0 && (module.exports = {
|
|
468
|
+
CopilotKit,
|
|
469
|
+
defaultCopilotContextCategories
|
|
470
|
+
});
|
|
426
471
|
//# sourceMappingURL=copilotkit.js.map
|