@copilotkit/react-core 0.25.0-function-calling-fixes.2 → 0.25.0-mme-cloud.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 +216 -234
- package/CHANGELOG.md +3 -25
- package/dist/{chunk-BGB5G33N.mjs → chunk-4E2RCCQB.mjs} +2 -2
- package/dist/{chunk-AEUR5JBT.mjs → chunk-APVNN5QF.mjs} +3 -4
- package/dist/chunk-APVNN5QF.mjs.map +1 -0
- package/dist/{chunk-3WKJ25L3.mjs → chunk-CGT3AVYT.mjs} +3 -3
- package/dist/chunk-CGT3AVYT.mjs.map +1 -0
- package/dist/{chunk-KIKHLN4X.mjs → chunk-GH7QK2AZ.mjs} +3 -1
- package/dist/chunk-GH7QK2AZ.mjs.map +1 -0
- package/dist/{chunk-H3FQWB4B.mjs → chunk-KMTE4NLW.mjs} +19 -12
- package/dist/chunk-KMTE4NLW.mjs.map +1 -0
- package/dist/{chunk-KJQZ2VEU.mjs → chunk-M7JUS6OQ.mjs} +2 -2
- package/dist/{chunk-QGRMN7L3.mjs → chunk-O2GQ2XK7.mjs} +3 -3
- package/dist/{chunk-FCEPEM4B.mjs → chunk-PYBBWHNC.mjs} +3 -3
- package/dist/{chunk-GVLCTSXW.mjs → chunk-SPLPX72P.mjs} +11 -7
- package/dist/chunk-SPLPX72P.mjs.map +1 -0
- package/dist/{chunk-75RLNHDB.mjs → chunk-TEI34ZF5.mjs} +5 -5
- package/dist/chunk-TEI34ZF5.mjs.map +1 -0
- package/dist/{chunk-H6V2C2AN.mjs → chunk-YKHUBROO.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +12 -0
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +0 -17
- package/dist/components/copilot-provider/copilotkit.js +19 -17
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +8 -435
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -1
- package/dist/components/copilot-provider/index.js +19 -17
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -435
- package/dist/components/copilot-provider/index.mjs.map +1 -1
- package/dist/components/index.js +19 -17
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -435
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.d.ts +15 -2
- package/dist/context/copilot-context.js +2 -0
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +5 -64
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.js +2 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +6 -64
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.js +14 -14
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +23 -518
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-chat.d.ts +8 -2
- package/dist/hooks/use-chat.js +3 -4
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -285
- package/dist/hooks/use-chat.mjs.map +1 -1
- package/dist/hooks/use-copilot-action.d.ts +1 -1
- package/dist/hooks/use-copilot-action.js +4 -9
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +5 -107
- package/dist/hooks/use-copilot-action.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.js +12 -7
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +12 -420
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +4 -65
- package/dist/hooks/use-flat-category-store.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.js +2 -0
- package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +5 -88
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js +2 -0
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +5 -78
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.js +2 -0
- package/dist/hooks/use-make-copilot-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +5 -78
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/hooks/use-tree.mjs +4 -150
- package/dist/hooks/use-tree.mjs.map +1 -1
- package/dist/index.js +31 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -1103
- package/dist/index.mjs.map +1 -1
- package/dist/lib/copilot-task.js +2 -2
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +10 -192
- package/dist/lib/copilot-task.mjs.map +1 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -192
- package/dist/lib/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/index.js +2 -0
- package/dist/openai-assistants/hooks/index.js.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +14 -228
- package/dist/openai-assistants/hooks/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-assistants.mjs +7 -45
- package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +2 -0
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +14 -228
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
- package/dist/openai-assistants/index.js +2 -0
- package/dist/openai-assistants/index.js.map +1 -1
- package/dist/openai-assistants/index.mjs +17 -228
- package/dist/openai-assistants/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/index.mjs +5 -43
- package/dist/openai-assistants/utils/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/process-message-stream.mjs +4 -43
- package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -1
- package/dist/types/index.mjs +1 -0
- package/dist/utils/fetch-chat-completion.js +2 -2
- package/dist/utils/fetch-chat-completion.js.map +1 -1
- package/dist/utils/fetch-chat-completion.mjs +5 -112
- package/dist/utils/fetch-chat-completion.mjs.map +1 -1
- package/package.json +4 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +14 -0
- package/src/components/copilot-provider/copilotkit.tsx +21 -25
- package/src/context/copilot-context.tsx +19 -1
- package/src/hooks/use-chat.ts +9 -4
- package/src/hooks/use-copilot-action.ts +58 -10
- package/src/hooks/use-copilot-chat.ts +5 -1
- package/src/utils/fetch-chat-completion.ts +1 -0
- package/dist/chunk-3WKJ25L3.mjs.map +0 -1
- package/dist/chunk-75RLNHDB.mjs.map +0 -1
- package/dist/chunk-AEUR5JBT.mjs.map +0 -1
- package/dist/chunk-F2JIAPZQ.mjs +0 -14
- package/dist/chunk-F2JIAPZQ.mjs.map +0 -1
- package/dist/chunk-GVLCTSXW.mjs.map +0 -1
- package/dist/chunk-H3FQWB4B.mjs.map +0 -1
- package/dist/chunk-ISKBWE4O.mjs +0 -13
- package/dist/chunk-ISKBWE4O.mjs.map +0 -1
- package/dist/chunk-KIKHLN4X.mjs.map +0 -1
- package/dist/components/copilot-provider/standard-copilot-api-config.d.ts +0 -23
- package/dist/components/copilot-provider/standard-copilot-api-config.js +0 -38
- package/dist/components/copilot-provider/standard-copilot-api-config.js.map +0 -1
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs +0 -13
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +0 -1
- package/dist/hooks/use-copilot-action-implementation.d.ts +0 -7
- package/dist/hooks/use-copilot-action-implementation.js +0 -140
- package/dist/hooks/use-copilot-action-implementation.js.map +0 -1
- package/dist/hooks/use-copilot-action-implementation.mjs +0 -106
- package/dist/hooks/use-copilot-action-implementation.mjs.map +0 -1
- package/src/components/copilot-provider/standard-copilot-api-config.tsx +0 -28
- package/src/hooks/use-copilot-action-implementation.ts +0 -60
- /package/dist/{chunk-BGB5G33N.mjs.map → chunk-4E2RCCQB.mjs.map} +0 -0
- /package/dist/{chunk-KJQZ2VEU.mjs.map → chunk-M7JUS6OQ.mjs.map} +0 -0
- /package/dist/{chunk-QGRMN7L3.mjs.map → chunk-O2GQ2XK7.mjs.map} +0 -0
- /package/dist/{chunk-FCEPEM4B.mjs.map → chunk-PYBBWHNC.mjs.map} +0 -0
- /package/dist/{chunk-H6V2C2AN.mjs.map → chunk-YKHUBROO.mjs.map} +0 -0
|
@@ -1,91 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/hooks/use-make-copilot-actionable.ts
|
|
23
|
-
import { useRef, useContext, useEffect, useMemo } from "react";
|
|
24
|
-
|
|
25
|
-
// src/context/copilot-context.tsx
|
|
26
|
-
import React from "react";
|
|
27
|
-
var emptyCopilotContext = {
|
|
28
|
-
entryPoints: {},
|
|
29
|
-
setEntryPoint: () => {
|
|
30
|
-
},
|
|
31
|
-
removeEntryPoint: () => {
|
|
32
|
-
},
|
|
33
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
34
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
35
|
-
})),
|
|
36
|
-
chatComponentsCache: { current: {} },
|
|
37
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
38
|
-
addContext: () => "",
|
|
39
|
-
removeContext: () => {
|
|
40
|
-
},
|
|
41
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
42
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
43
|
-
removeDocumentContext: () => {
|
|
44
|
-
},
|
|
45
|
-
copilotApiConfig: new class {
|
|
46
|
-
get chatApiEndpoint() {
|
|
47
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
48
|
-
}
|
|
49
|
-
get chatApiEndpointV2() {
|
|
50
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
51
|
-
}
|
|
52
|
-
get headers() {
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
get body() {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
}()
|
|
59
|
-
};
|
|
60
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
61
|
-
function returnAndThrowInDebug(value) {
|
|
62
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/hooks/use-make-copilot-actionable.ts
|
|
67
|
-
import { nanoid } from "nanoid";
|
|
68
|
-
import { annotatedFunctionToAction } from "@copilotkit/shared";
|
|
69
|
-
function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
70
|
-
const idRef = useRef(nanoid());
|
|
71
|
-
const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);
|
|
72
|
-
const memoizedAnnotatedFunction = useMemo(
|
|
73
|
-
() => ({
|
|
74
|
-
name: annotatedFunction.name,
|
|
75
|
-
description: annotatedFunction.description,
|
|
76
|
-
argumentAnnotations: annotatedFunction.argumentAnnotations,
|
|
77
|
-
implementation: annotatedFunction.implementation
|
|
78
|
-
}),
|
|
79
|
-
dependencies
|
|
80
|
-
);
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
const action = annotatedFunctionToAction(memoizedAnnotatedFunction);
|
|
83
|
-
setEntryPoint(idRef.current, action);
|
|
84
|
-
return () => {
|
|
85
|
-
removeEntryPoint(idRef.current);
|
|
86
|
-
};
|
|
87
|
-
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
88
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
useMakeCopilotActionable
|
|
3
|
+
} from "../chunk-4E2RCCQB.mjs";
|
|
4
|
+
import "../chunk-GH7QK2AZ.mjs";
|
|
5
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
89
6
|
export {
|
|
90
7
|
useMakeCopilotActionable
|
|
91
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -71,6 +71,8 @@ var emptyCopilotContext = {
|
|
|
71
71
|
addContext: () => "",
|
|
72
72
|
removeContext: () => {
|
|
73
73
|
},
|
|
74
|
+
messages: [],
|
|
75
|
+
setMessages: () => returnAndThrowInDebug([]),
|
|
74
76
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
75
77
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
76
78
|
removeDocumentContext: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA8C;;;ACE9C,mBAA2B;
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { FunctionCallHandler, Message, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\nexport interface CopilotCloudConfig {\n apiKey: string;\n restrictToTopic?: {\n validTopics: string[];\n invalidTopics?: string[];\n };\n}\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA8C;;;ACE9C,mBAA2B;AAoG3B,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,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,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,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADtIO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,QAAI,0BAAW,cAAc;AAC/E,QAAM,YAAQ,sBAAe;AAE7B,+BAAU,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;","names":["import_react","React"]}
|
|
@@ -1,81 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
23
|
-
import { useContext, useEffect, useRef } from "react";
|
|
24
|
-
|
|
25
|
-
// src/context/copilot-context.tsx
|
|
26
|
-
import React from "react";
|
|
27
|
-
var emptyCopilotContext = {
|
|
28
|
-
entryPoints: {},
|
|
29
|
-
setEntryPoint: () => {
|
|
30
|
-
},
|
|
31
|
-
removeEntryPoint: () => {
|
|
32
|
-
},
|
|
33
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
34
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
35
|
-
})),
|
|
36
|
-
chatComponentsCache: { current: {} },
|
|
37
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
38
|
-
addContext: () => "",
|
|
39
|
-
removeContext: () => {
|
|
40
|
-
},
|
|
41
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
42
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
43
|
-
removeDocumentContext: () => {
|
|
44
|
-
},
|
|
45
|
-
copilotApiConfig: new class {
|
|
46
|
-
get chatApiEndpoint() {
|
|
47
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
48
|
-
}
|
|
49
|
-
get chatApiEndpointV2() {
|
|
50
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
51
|
-
}
|
|
52
|
-
get headers() {
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
get body() {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
}()
|
|
59
|
-
};
|
|
60
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
61
|
-
function returnAndThrowInDebug(value) {
|
|
62
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
67
|
-
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
68
|
-
const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);
|
|
69
|
-
const idRef = useRef();
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
const id = addDocumentContext(document, categories);
|
|
72
|
-
idRef.current = id;
|
|
73
|
-
return () => {
|
|
74
|
-
removeDocumentContext(id);
|
|
75
|
-
};
|
|
76
|
-
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
77
|
-
return idRef.current;
|
|
78
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
useMakeCopilotDocumentReadable
|
|
3
|
+
} from "../chunk-YKHUBROO.mjs";
|
|
4
|
+
import "../chunk-GH7QK2AZ.mjs";
|
|
5
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
79
6
|
export {
|
|
80
7
|
useMakeCopilotDocumentReadable
|
|
81
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -71,6 +71,8 @@ var emptyCopilotContext = {
|
|
|
71
71
|
addContext: () => "",
|
|
72
72
|
removeContext: () => {
|
|
73
73
|
},
|
|
74
|
+
messages: [],
|
|
75
|
+
setMessages: () => returnAndThrowInDebug([]),
|
|
74
76
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
75
77
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
76
78
|
removeDocumentContext: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { 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","import { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA8C;;;ACE9C,mBAA2B;
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { 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","import { FunctionCallHandler, Message, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\nexport interface CopilotCloudConfig {\n apiKey: string;\n restrictToTopic?: {\n validTopics: string[];\n invalidTopics?: string[];\n };\n}\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA8C;;;ACE9C,mBAA2B;AAoG3B,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,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,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,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADvIO,SAAS,uBACd,aACA,UACA,YACoB;AACpB,QAAM,EAAE,YAAY,cAAc,QAAI,0BAAW,cAAc;AAC/D,QAAM,YAAQ,sBAAe;AAE7B,+BAAU,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":["import_react","React"]}
|
|
@@ -1,81 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/hooks/use-make-copilot-readable.ts
|
|
23
|
-
import { useContext, useEffect, useRef } from "react";
|
|
24
|
-
|
|
25
|
-
// src/context/copilot-context.tsx
|
|
26
|
-
import React from "react";
|
|
27
|
-
var emptyCopilotContext = {
|
|
28
|
-
entryPoints: {},
|
|
29
|
-
setEntryPoint: () => {
|
|
30
|
-
},
|
|
31
|
-
removeEntryPoint: () => {
|
|
32
|
-
},
|
|
33
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
34
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
35
|
-
})),
|
|
36
|
-
chatComponentsCache: { current: {} },
|
|
37
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
38
|
-
addContext: () => "",
|
|
39
|
-
removeContext: () => {
|
|
40
|
-
},
|
|
41
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
42
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
43
|
-
removeDocumentContext: () => {
|
|
44
|
-
},
|
|
45
|
-
copilotApiConfig: new class {
|
|
46
|
-
get chatApiEndpoint() {
|
|
47
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
48
|
-
}
|
|
49
|
-
get chatApiEndpointV2() {
|
|
50
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
51
|
-
}
|
|
52
|
-
get headers() {
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
get body() {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
}()
|
|
59
|
-
};
|
|
60
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
61
|
-
function returnAndThrowInDebug(value) {
|
|
62
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/hooks/use-make-copilot-readable.ts
|
|
67
|
-
function useMakeCopilotReadable(information, parentId, categories) {
|
|
68
|
-
const { addContext, removeContext } = useContext(CopilotContext);
|
|
69
|
-
const idRef = useRef();
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
const id = addContext(information, parentId, categories);
|
|
72
|
-
idRef.current = id;
|
|
73
|
-
return () => {
|
|
74
|
-
removeContext(id);
|
|
75
|
-
};
|
|
76
|
-
}, [information, parentId, addContext, removeContext]);
|
|
77
|
-
return idRef.current;
|
|
78
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
useMakeCopilotReadable
|
|
3
|
+
} from "../chunk-M7JUS6OQ.mjs";
|
|
4
|
+
import "../chunk-GH7QK2AZ.mjs";
|
|
5
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
79
6
|
export {
|
|
80
7
|
useMakeCopilotReadable
|
|
81
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/hooks/use-tree.mjs
CHANGED
|
@@ -1,153 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
21
|
-
// src/hooks/use-tree.ts
|
|
22
|
-
import { nanoid } from "nanoid";
|
|
23
|
-
import { useCallback, useReducer } from "react";
|
|
24
|
-
var removeNode = (nodes, id) => {
|
|
25
|
-
return nodes.reduce((result, node) => {
|
|
26
|
-
if (node.id !== id) {
|
|
27
|
-
const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
|
|
28
|
-
result.push(newNode);
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}, []);
|
|
32
|
-
};
|
|
33
|
-
var addNode = (nodes, newNode, parentId) => {
|
|
34
|
-
if (!parentId) {
|
|
35
|
-
return [...nodes, newNode];
|
|
36
|
-
}
|
|
37
|
-
return nodes.map((node) => {
|
|
38
|
-
if (node.id === parentId) {
|
|
39
|
-
return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
|
|
40
|
-
} else if (node.children.length) {
|
|
41
|
-
return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
|
|
42
|
-
}
|
|
43
|
-
return node;
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
var treeIndentationRepresentation = (index, indentLevel) => {
|
|
47
|
-
if (indentLevel === 0) {
|
|
48
|
-
return (index + 1).toString();
|
|
49
|
-
} else if (indentLevel === 1) {
|
|
50
|
-
return String.fromCharCode(65 + index);
|
|
51
|
-
} else if (indentLevel === 2) {
|
|
52
|
-
return String.fromCharCode(97 + index);
|
|
53
|
-
} else {
|
|
54
|
-
return "-";
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var printNode = (node, prefix = "", indentLevel = 0) => {
|
|
58
|
-
const indent = " ".repeat(3).repeat(indentLevel);
|
|
59
|
-
const prefixPlusIndentLength = prefix.length + indent.length;
|
|
60
|
-
const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
|
|
61
|
-
const valueLines = node.value.split("\n");
|
|
62
|
-
const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
|
|
63
|
-
const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
|
|
64
|
-
let output = `${outputFirstLine}
|
|
65
|
-
`;
|
|
66
|
-
if (outputSubsequentLines) {
|
|
67
|
-
output += `${outputSubsequentLines}
|
|
68
|
-
`;
|
|
69
|
-
}
|
|
70
|
-
const childPrePrefix = " ".repeat(prefix.length);
|
|
71
|
-
node.children.forEach(
|
|
72
|
-
(child, index) => output += printNode(
|
|
73
|
-
child,
|
|
74
|
-
`${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
|
|
75
|
-
indentLevel + 1
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
return output;
|
|
79
|
-
};
|
|
80
|
-
function treeReducer(state, action) {
|
|
81
|
-
switch (action.type) {
|
|
82
|
-
case "ADD_NODE": {
|
|
83
|
-
const { value, parentId, id: newNodeId } = action;
|
|
84
|
-
const newNode = {
|
|
85
|
-
id: newNodeId,
|
|
86
|
-
value,
|
|
87
|
-
children: [],
|
|
88
|
-
categories: new Set(action.categories)
|
|
89
|
-
};
|
|
90
|
-
try {
|
|
91
|
-
return addNode(state, newNode, parentId);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error(`Error while adding node with id ${newNodeId}: ${error}`);
|
|
94
|
-
return state;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
case "REMOVE_NODE":
|
|
98
|
-
return removeNode(state, action.id);
|
|
99
|
-
default:
|
|
100
|
-
return state;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
var useTree = () => {
|
|
104
|
-
const [tree, dispatch] = useReducer(treeReducer, []);
|
|
105
|
-
const addElement = useCallback(
|
|
106
|
-
(value, categories, parentId) => {
|
|
107
|
-
const newNodeId = nanoid();
|
|
108
|
-
dispatch({
|
|
109
|
-
type: "ADD_NODE",
|
|
110
|
-
value,
|
|
111
|
-
parentId,
|
|
112
|
-
id: newNodeId,
|
|
113
|
-
categories
|
|
114
|
-
});
|
|
115
|
-
return newNodeId;
|
|
116
|
-
},
|
|
117
|
-
[]
|
|
118
|
-
);
|
|
119
|
-
const removeElement = useCallback((id) => {
|
|
120
|
-
dispatch({ type: "REMOVE_NODE", id });
|
|
121
|
-
}, []);
|
|
122
|
-
const printTree = useCallback(
|
|
123
|
-
(categories) => {
|
|
124
|
-
const categoriesSet = new Set(categories);
|
|
125
|
-
let output = "";
|
|
126
|
-
tree.forEach((node, index) => {
|
|
127
|
-
if (!setsHaveIntersection(categoriesSet, node.categories)) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (index !== 0) {
|
|
131
|
-
output += "\n";
|
|
132
|
-
}
|
|
133
|
-
output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
|
|
134
|
-
});
|
|
135
|
-
return output;
|
|
136
|
-
},
|
|
137
|
-
[tree]
|
|
138
|
-
);
|
|
139
|
-
return { tree, addElement, printTree, removeElement };
|
|
140
|
-
};
|
|
141
|
-
var use_tree_default = useTree;
|
|
142
|
-
function setsHaveIntersection(setA, setB) {
|
|
143
|
-
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
144
|
-
for (let item of smallerSet) {
|
|
145
|
-
if (largerSet.has(item)) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
use_tree_default
|
|
3
|
+
} from "../chunk-VUY2K2DI.mjs";
|
|
4
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
151
5
|
export {
|
|
152
6
|
use_tree_default as default
|
|
153
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|