@copilotkit/react-core 0.20.0-demofixes.2 → 0.20.0-mmeqa-13-02-2024.2
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 +211 -215
- package/CHANGELOG.md +6 -6
- package/dist/{chunk-CPEUPJQJ.mjs → chunk-2EP7VLPI.mjs} +2 -2
- package/dist/{chunk-KZNQLITJ.mjs → chunk-3TF6G3W5.mjs} +4 -4
- package/dist/{chunk-4LKP4DMT.mjs → chunk-6WZFE6II.mjs} +3 -3
- package/dist/{chunk-JIKWSWIX.mjs → chunk-BQ5SSV4Z.mjs} +6 -4
- package/dist/chunk-BQ5SSV4Z.mjs.map +1 -0
- package/dist/{chunk-ABXVFQLN.mjs → chunk-JFUS5YVO.mjs} +40 -8
- package/dist/chunk-JFUS5YVO.mjs.map +1 -0
- package/dist/{chunk-XBLCD24W.mjs → chunk-JVCBCB2T.mjs} +2 -2
- package/dist/{chunk-TZPIY754.mjs → chunk-O6PPE3GW.mjs} +3 -3
- package/dist/{chunk-KAZJPE2I.mjs → chunk-PHK2K7UB.mjs} +3 -3
- package/dist/chunk-PHK2K7UB.mjs.map +1 -0
- package/dist/{chunk-4OWTRVNI.mjs → chunk-S7ZVOTYK.mjs} +1 -1
- package/dist/chunk-S7ZVOTYK.mjs.map +1 -0
- package/dist/{chunk-K2LVBFRY.mjs → chunk-WH4L73VS.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +11 -0
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +1 -1
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +8 -439
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -1
- package/dist/components/copilot-provider/index.js +1 -1
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -439
- package/dist/components/copilot-provider/index.mjs.map +1 -1
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs +4 -9
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -439
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.d.ts +11 -0
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +5 -63
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +6 -63
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.js +42 -9
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +21 -392
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-chat.js +41 -8
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -204
- package/dist/hooks/use-chat.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.js +42 -9
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -340
- 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.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +5 -85
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +5 -77
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +5 -77
- 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 +44 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -979
- package/dist/index.mjs.map +1 -1
- package/dist/lib/copilot-task.js +3 -2
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -183
- package/dist/lib/copilot-task.mjs.map +1 -1
- package/dist/lib/index.js +3 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +12 -183
- package/dist/lib/index.mjs.map +1 -1
- 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.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.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 +3 -2
- package/dist/utils/fetch-chat-completion.js.map +1 -1
- package/dist/utils/fetch-chat-completion.mjs +5 -99
- package/dist/utils/fetch-chat-completion.mjs.map +1 -1
- package/package.json +4 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +12 -0
- package/src/components/copilot-provider/copilotkit.tsx +4 -1
- package/src/context/copilot-context.tsx +12 -0
- package/src/hooks/use-chat.ts +57 -6
- package/src/utils/fetch-chat-completion.ts +5 -0
- package/dist/chunk-4OWTRVNI.mjs.map +0 -1
- package/dist/chunk-ABXVFQLN.mjs.map +0 -1
- package/dist/chunk-JIKWSWIX.mjs.map +0 -1
- package/dist/chunk-KAZJPE2I.mjs.map +0 -1
- /package/dist/{chunk-CPEUPJQJ.mjs.map → chunk-2EP7VLPI.mjs.map} +0 -0
- /package/dist/{chunk-KZNQLITJ.mjs.map → chunk-3TF6G3W5.mjs.map} +0 -0
- /package/dist/{chunk-4LKP4DMT.mjs.map → chunk-6WZFE6II.mjs.map} +0 -0
- /package/dist/{chunk-XBLCD24W.mjs.map → chunk-JVCBCB2T.mjs.map} +0 -0
- /package/dist/{chunk-TZPIY754.mjs.map → chunk-O6PPE3GW.mjs.map} +0 -0
- /package/dist/{chunk-K2LVBFRY.mjs.map → chunk-WH4L73VS.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","\"use client\";\n\nimport { FunctionCallHandler, AnnotatedFunction, ToolDefinition } from \"@copilotkit/shared\";\nimport React 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\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, AnnotatedFunction<any[]>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, AnnotatedFunction<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\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;AAEA,IAAAA,gBAA8C;;;ACC9C,mBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["\"use client\";\n\nimport { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","\"use client\";\n\nimport { FunctionCallHandler, AnnotatedFunction, ToolDefinition } from \"@copilotkit/shared\";\nimport React 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 interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, AnnotatedFunction<any[]>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, AnnotatedFunction<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\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;AAEA,IAAAA,gBAA8C;;;ACC9C,mBAAkB;AAiFlB,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,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;;;ADhHO,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,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} catch (e) {
|
|
8
|
-
reject(e);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var rejected = (value) => {
|
|
12
|
-
try {
|
|
13
|
-
step(generator.throw(value));
|
|
14
|
-
} catch (e) {
|
|
15
|
-
reject(e);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
24
|
-
import { useContext, useEffect, useRef } from "react";
|
|
25
|
-
|
|
26
|
-
// src/context/copilot-context.tsx
|
|
27
|
-
import React from "react";
|
|
28
|
-
var emptyCopilotContext = {
|
|
29
|
-
entryPoints: {},
|
|
30
|
-
setEntryPoint: () => {
|
|
31
|
-
},
|
|
32
|
-
removeEntryPoint: () => {
|
|
33
|
-
},
|
|
34
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
35
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
36
|
-
})),
|
|
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
|
-
}
|
|
2
|
+
import {
|
|
3
|
+
useMakeCopilotDocumentReadable
|
|
4
|
+
} from "../chunk-JVCBCB2T.mjs";
|
|
5
|
+
import "../chunk-S7ZVOTYK.mjs";
|
|
6
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
79
7
|
export {
|
|
80
8
|
useMakeCopilotDocumentReadable
|
|
81
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"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","\"use client\";\n\nimport { FunctionCallHandler, AnnotatedFunction, ToolDefinition } from \"@copilotkit/shared\";\nimport React 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\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, AnnotatedFunction<any[]>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, AnnotatedFunction<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\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;AAEA,IAAAA,gBAA8C;;;ACC9C,mBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"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","\"use client\";\n\nimport { FunctionCallHandler, AnnotatedFunction, ToolDefinition } from \"@copilotkit/shared\";\nimport React 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 interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, AnnotatedFunction<any[]>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, AnnotatedFunction<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\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;AAEA,IAAAA,gBAA8C;;;ACC9C,mBAAkB;AAiFlB,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,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;;;ADjHO,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,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} catch (e) {
|
|
8
|
-
reject(e);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var rejected = (value) => {
|
|
12
|
-
try {
|
|
13
|
-
step(generator.throw(value));
|
|
14
|
-
} catch (e) {
|
|
15
|
-
reject(e);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// src/hooks/use-make-copilot-readable.ts
|
|
24
|
-
import { useContext, useEffect, useRef } from "react";
|
|
25
|
-
|
|
26
|
-
// src/context/copilot-context.tsx
|
|
27
|
-
import React from "react";
|
|
28
|
-
var emptyCopilotContext = {
|
|
29
|
-
entryPoints: {},
|
|
30
|
-
setEntryPoint: () => {
|
|
31
|
-
},
|
|
32
|
-
removeEntryPoint: () => {
|
|
33
|
-
},
|
|
34
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
35
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
36
|
-
})),
|
|
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
|
-
}
|
|
2
|
+
import {
|
|
3
|
+
useMakeCopilotReadable
|
|
4
|
+
} from "../chunk-2EP7VLPI.mjs";
|
|
5
|
+
import "../chunk-S7ZVOTYK.mjs";
|
|
6
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
79
7
|
export {
|
|
80
8
|
useMakeCopilotReadable
|
|
81
9
|
};
|
|
@@ -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":[]}
|
package/dist/index.js
CHANGED
|
@@ -436,7 +436,7 @@ ${nonDocumentStrings}`;
|
|
|
436
436
|
props.url,
|
|
437
437
|
`${props.url}/v2`,
|
|
438
438
|
props.headers || {},
|
|
439
|
-
props.body
|
|
439
|
+
__spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
|
|
440
440
|
);
|
|
441
441
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
442
442
|
CopilotContext.Provider,
|
|
@@ -491,6 +491,7 @@ var import_react6 = require("react");
|
|
|
491
491
|
|
|
492
492
|
// src/hooks/use-chat.ts
|
|
493
493
|
var import_react5 = require("react");
|
|
494
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
494
495
|
var import_nanoid3 = require("nanoid");
|
|
495
496
|
|
|
496
497
|
// src/utils/fetch-chat-completion.ts
|
|
@@ -506,6 +507,7 @@ function fetchChatCompletion(_0) {
|
|
|
506
507
|
body,
|
|
507
508
|
signal
|
|
508
509
|
}) {
|
|
510
|
+
var _a, _b;
|
|
509
511
|
temperature || (temperature = 0.5);
|
|
510
512
|
tools || (tools = []);
|
|
511
513
|
const cleanedMessages = messages.map((message) => {
|
|
@@ -517,11 +519,11 @@ function fetchChatCompletion(_0) {
|
|
|
517
519
|
headers: __spreadValues(__spreadValues({
|
|
518
520
|
"Content-Type": "application/json"
|
|
519
521
|
}, copilotConfig.headers), headers ? __spreadValues({}, headers) : {}),
|
|
520
|
-
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
522
|
+
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
521
523
|
model,
|
|
522
524
|
messages: cleanedMessages,
|
|
523
525
|
stream: true
|
|
524
|
-
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), body ? __spreadValues({}, body) : {})),
|
|
526
|
+
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), Object.keys((_a = copilotConfig["body"]) != null ? _a : {}).length > 0 ? { [import_shared2.EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys((_b = copilotConfig["body"]) != null ? _b : {}) } : {}), body ? __spreadValues({}, body) : {})),
|
|
525
527
|
signal
|
|
526
528
|
});
|
|
527
529
|
return response;
|
|
@@ -557,7 +559,6 @@ function useChat(options) {
|
|
|
557
559
|
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
558
560
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
559
561
|
const runChatCompletion = (messages2) => __async(this, null, function* () {
|
|
560
|
-
var _a;
|
|
561
562
|
setIsLoading(true);
|
|
562
563
|
const newMessages = [
|
|
563
564
|
{
|
|
@@ -582,15 +583,16 @@ function useChat(options) {
|
|
|
582
583
|
throw new Error("Failed to fetch chat completion");
|
|
583
584
|
}
|
|
584
585
|
const reader = response.events.getReader();
|
|
586
|
+
let feedback = false;
|
|
585
587
|
try {
|
|
586
588
|
while (true) {
|
|
587
589
|
const { done, value } = yield reader.read();
|
|
588
590
|
if (done) {
|
|
589
|
-
|
|
591
|
+
break;
|
|
590
592
|
}
|
|
591
593
|
let currentMessage = Object.assign({}, newMessages[newMessages.length - 1]);
|
|
592
594
|
if (value.type === "content") {
|
|
593
|
-
if (currentMessage.function_call) {
|
|
595
|
+
if (currentMessage.function_call || currentMessage.role === "function") {
|
|
594
596
|
currentMessage = {
|
|
595
597
|
id: (0, import_nanoid3.nanoid)(),
|
|
596
598
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -602,8 +604,18 @@ function useChat(options) {
|
|
|
602
604
|
currentMessage.content += value.content;
|
|
603
605
|
newMessages[newMessages.length - 1] = currentMessage;
|
|
604
606
|
setMessages([...messages2, ...newMessages]);
|
|
607
|
+
} else if (value.type === "result") {
|
|
608
|
+
currentMessage = {
|
|
609
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
610
|
+
role: "function",
|
|
611
|
+
content: value.content,
|
|
612
|
+
name: value.name
|
|
613
|
+
};
|
|
614
|
+
newMessages.push(currentMessage);
|
|
615
|
+
setMessages([...messages2, ...newMessages]);
|
|
616
|
+
feedback = true;
|
|
605
617
|
} else if (value.type === "function") {
|
|
606
|
-
if (currentMessage.content != "" || currentMessage.function_call) {
|
|
618
|
+
if (currentMessage.content != "" || currentMessage.function_call || currentMessage.role == "function") {
|
|
607
619
|
currentMessage = {
|
|
608
620
|
id: (0, import_nanoid3.nanoid)(),
|
|
609
621
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -614,13 +626,34 @@ function useChat(options) {
|
|
|
614
626
|
}
|
|
615
627
|
currentMessage.function_call = {
|
|
616
628
|
name: value.name,
|
|
617
|
-
arguments: JSON.stringify(value.arguments)
|
|
629
|
+
arguments: JSON.stringify(value.arguments),
|
|
630
|
+
scope: value.scope
|
|
618
631
|
};
|
|
619
632
|
newMessages[newMessages.length - 1] = currentMessage;
|
|
620
633
|
setMessages([...messages2, ...newMessages]);
|
|
621
|
-
|
|
634
|
+
try {
|
|
635
|
+
if (options.onFunctionCall && value.scope === "client") {
|
|
636
|
+
const result = yield options.onFunctionCall(messages2, currentMessage.function_call);
|
|
637
|
+
currentMessage = {
|
|
638
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
639
|
+
role: "function",
|
|
640
|
+
content: (0, import_shared3.encodeResult)(result),
|
|
641
|
+
name: currentMessage.function_call.name
|
|
642
|
+
};
|
|
643
|
+
newMessages.push(currentMessage);
|
|
644
|
+
setMessages([...messages2, ...newMessages]);
|
|
645
|
+
feedback = true;
|
|
646
|
+
}
|
|
647
|
+
} catch (error) {
|
|
648
|
+
console.error("Failed to execute function call", error);
|
|
649
|
+
}
|
|
622
650
|
}
|
|
623
651
|
}
|
|
652
|
+
if (feedback) {
|
|
653
|
+
return yield runChatCompletion([...messages2, ...newMessages]);
|
|
654
|
+
} else {
|
|
655
|
+
return newMessages.slice();
|
|
656
|
+
}
|
|
624
657
|
} finally {
|
|
625
658
|
setIsLoading(false);
|
|
626
659
|
}
|
|
@@ -816,7 +849,7 @@ function processMessageStream(reader, processMessage) {
|
|
|
816
849
|
}
|
|
817
850
|
|
|
818
851
|
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
819
|
-
var
|
|
852
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
820
853
|
function useCopilotChatV2(options) {
|
|
821
854
|
const {
|
|
822
855
|
getContextString,
|
|
@@ -868,7 +901,7 @@ function useCopilotChatV2(options) {
|
|
|
868
901
|
}
|
|
869
902
|
yield processMessageStream(result.body.getReader(), (message) => {
|
|
870
903
|
try {
|
|
871
|
-
const { type, value } = (0,
|
|
904
|
+
const { type, value } = (0, import_shared4.parseStreamPart)(message);
|
|
872
905
|
switch (type) {
|
|
873
906
|
case "assistant_message": {
|
|
874
907
|
setMessages((messages2) => [
|