@copilotkit/react-core 0.19.0 → 0.20.0-alpha.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 -197
- package/CHANGELOG.md +33 -0
- package/dist/{chunk-VP2EU4US.mjs → chunk-4LKP4DMT.mjs} +3 -3
- package/dist/{chunk-4CFJ6A6A.mjs → chunk-4OWTRVNI.mjs} +6 -2
- package/dist/chunk-4OWTRVNI.mjs.map +1 -0
- package/dist/{chunk-5GS7FQPW.mjs → chunk-AVLJ3AWG.mjs} +5 -5
- package/dist/chunk-AVLJ3AWG.mjs.map +1 -0
- package/dist/{chunk-YOXWT7I6.mjs → chunk-CPEUPJQJ.mjs} +2 -2
- package/dist/{chunk-UAKLDQMP.mjs → chunk-JIKWSWIX.mjs} +4 -4
- package/dist/chunk-JIKWSWIX.mjs.map +1 -0
- package/dist/{chunk-DGUVNY3V.mjs → chunk-K2LVBFRY.mjs} +2 -2
- package/dist/{chunk-GBZZPQ5X.mjs → chunk-KAZJPE2I.mjs} +14 -8
- package/dist/chunk-KAZJPE2I.mjs.map +1 -0
- package/dist/chunk-LUGEI4YQ.mjs +1 -0
- package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
- package/dist/chunk-NW27C3BV.mjs +158 -0
- package/dist/chunk-NW27C3BV.mjs.map +1 -0
- package/dist/chunk-TZPIY754.mjs +102 -0
- package/dist/chunk-TZPIY754.mjs.map +1 -0
- package/dist/{chunk-IQH5AQQC.mjs → chunk-XBLCD24W.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.js +12 -6
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +2 -2
- package/dist/components/copilot-provider/index.js +12 -6
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +12 -6
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +5 -4
- package/dist/context/copilot-context.js +7 -2
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +5 -3
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +7 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +5 -3
- package/dist/hooks/index.js +81 -31
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +8 -8
- package/dist/hooks/use-chat.d.ts +2 -2
- package/dist/hooks/use-chat.js +79 -29
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +81 -31
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +5 -5
- package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +189 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -11
- package/dist/lib/copilot-task.d.ts +34 -0
- package/dist/lib/copilot-task.js +206 -0
- package/dist/lib/copilot-task.js.map +1 -0
- package/dist/lib/copilot-task.mjs +16 -0
- package/dist/lib/copilot-task.mjs.map +1 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.js +206 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/index.mjs +17 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/openai-assistants/hooks/index.js.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +3 -3
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +3 -3
- package/dist/openai-assistants/index.js.map +1 -1
- package/dist/openai-assistants/index.mjs +3 -3
- package/dist/utils/fetch-chat-completion.d.ts +3 -3
- package/dist/utils/fetch-chat-completion.js +3 -3
- package/dist/utils/fetch-chat-completion.js.map +1 -1
- package/dist/utils/fetch-chat-completion.mjs +1 -1
- package/package.json +4 -4
- package/src/components/copilot-provider/copilotkit.tsx +17 -8
- package/src/context/copilot-context.tsx +11 -3
- package/src/context/index.ts +1 -1
- package/src/hooks/use-chat.ts +102 -29
- package/src/hooks/use-copilot-chat.ts +3 -3
- package/src/index.tsx +1 -0
- package/src/lib/copilot-task.ts +131 -0
- package/src/lib/index.ts +1 -0
- package/src/utils/fetch-chat-completion.ts +6 -6
- package/dist/chunk-4CFJ6A6A.mjs.map +0 -1
- package/dist/chunk-5GS7FQPW.mjs.map +0 -1
- package/dist/chunk-GBZZPQ5X.mjs.map +0 -1
- package/dist/chunk-IQEWY7P4.mjs +0 -109
- package/dist/chunk-IQEWY7P4.mjs.map +0 -1
- package/dist/chunk-UAKLDQMP.mjs.map +0 -1
- /package/dist/{chunk-VP2EU4US.mjs.map → chunk-4LKP4DMT.mjs.map} +0 -0
- /package/dist/{chunk-YOXWT7I6.mjs.map → chunk-CPEUPJQJ.mjs.map} +0 -0
- /package/dist/{chunk-DGUVNY3V.mjs.map → chunk-K2LVBFRY.mjs.map} +0 -0
- /package/dist/{chunk-IQH5AQQC.mjs.map → chunk-XBLCD24W.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,
|
|
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;AAqElB,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;;;ADpGO,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,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
useMakeCopilotDocumentReadable
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-XBLCD24W.mjs";
|
|
5
|
+
import "../chunk-4OWTRVNI.mjs";
|
|
6
6
|
import "../chunk-MRXNTQOX.mjs";
|
|
7
7
|
export {
|
|
8
8
|
useMakeCopilotDocumentReadable
|
|
@@ -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,
|
|
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;AAqElB,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;;;ADrGO,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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { CopilotKit, defaultCopilotContextCategories } from './components/copilot-provider/copilotkit.js';
|
|
2
2
|
export { CopilotKitProps } from './components/copilot-provider/copilotkit-props.js';
|
|
3
|
-
export { CopilotApiConfig, CopilotContext, CopilotContextParams } from './context/copilot-context.js';
|
|
3
|
+
export { CopilotApiConfig, CopilotContext, CopilotContextParams, useCopilotContext } from './context/copilot-context.js';
|
|
4
4
|
export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './hooks/use-copilot-chat.js';
|
|
5
5
|
export { useMakeCopilotActionable } from './hooks/use-make-copilot-actionable.js';
|
|
6
6
|
export { useMakeCopilotReadable } from './hooks/use-make-copilot-readable.js';
|
|
@@ -10,6 +10,7 @@ export { DocumentPointer } from './types/document-pointer.js';
|
|
|
10
10
|
export { SystemMessageFunction } from './types/system-message.js';
|
|
11
11
|
export { AssistantStatus, RequestForwardingOptions, UseCopilotChatOptionsV2, UseCopilotChatV2Result, useCopilotChatV2 } from './openai-assistants/hooks/use-copilot-chat-v2.js';
|
|
12
12
|
export { processMessageStream } from './openai-assistants/utils/process-message-stream.js';
|
|
13
|
+
export { CopilotTask, CopilotTaskConfig } from './lib/copilot-task.js';
|
|
13
14
|
export { FetchChatCompletionParams, fetchAndDecodeChatCompletion, fetchAndDecodeChatCompletionAsText, fetchChatCompletion } from './utils/fetch-chat-completion.js';
|
|
14
15
|
import 'react';
|
|
15
16
|
import '@copilotkit/shared';
|
package/dist/index.js
CHANGED
|
@@ -81,6 +81,7 @@ var src_exports = {};
|
|
|
81
81
|
__export(src_exports, {
|
|
82
82
|
CopilotContext: () => CopilotContext,
|
|
83
83
|
CopilotKit: () => CopilotKit,
|
|
84
|
+
CopilotTask: () => CopilotTask,
|
|
84
85
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
85
86
|
fetchAndDecodeChatCompletion: () => fetchAndDecodeChatCompletion,
|
|
86
87
|
fetchAndDecodeChatCompletionAsText: () => fetchAndDecodeChatCompletionAsText,
|
|
@@ -88,6 +89,7 @@ __export(src_exports, {
|
|
|
88
89
|
processMessageStream: () => processMessageStream,
|
|
89
90
|
useCopilotChat: () => useCopilotChat,
|
|
90
91
|
useCopilotChatV2: () => useCopilotChatV2,
|
|
92
|
+
useCopilotContext: () => useCopilotContext,
|
|
91
93
|
useMakeCopilotActionable: () => useMakeCopilotActionable,
|
|
92
94
|
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
93
95
|
useMakeCopilotReadable: () => useMakeCopilotReadable
|
|
@@ -132,6 +134,9 @@ var emptyCopilotContext = {
|
|
|
132
134
|
}()
|
|
133
135
|
};
|
|
134
136
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
137
|
+
function useCopilotContext() {
|
|
138
|
+
return import_react.default.useContext(CopilotContext);
|
|
139
|
+
}
|
|
135
140
|
function returnAndThrowInDebug(value) {
|
|
136
141
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
137
142
|
return value;
|
|
@@ -397,12 +402,18 @@ ${nonDocumentStrings}`;
|
|
|
397
402
|
},
|
|
398
403
|
[removeElement]
|
|
399
404
|
);
|
|
400
|
-
const getChatCompletionFunctionDescriptions = (0, import_react4.useCallback)(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
const getChatCompletionFunctionDescriptions = (0, import_react4.useCallback)(
|
|
406
|
+
(customEntryPoints) => {
|
|
407
|
+
return entryPointsToChatCompletionFunctions(Object.values(customEntryPoints || entryPoints));
|
|
408
|
+
},
|
|
409
|
+
[entryPoints]
|
|
410
|
+
);
|
|
411
|
+
const getFunctionCallHandler = (0, import_react4.useCallback)(
|
|
412
|
+
(customEntryPoints) => {
|
|
413
|
+
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || entryPoints));
|
|
414
|
+
},
|
|
415
|
+
[entryPoints]
|
|
416
|
+
);
|
|
406
417
|
const getDocumentsContext = (0, import_react4.useCallback)(
|
|
407
418
|
(categories) => {
|
|
408
419
|
return allDocuments(categories);
|
|
@@ -480,6 +491,7 @@ var import_react6 = require("react");
|
|
|
480
491
|
|
|
481
492
|
// src/hooks/use-chat.ts
|
|
482
493
|
var import_react5 = require("react");
|
|
494
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
483
495
|
var import_nanoid3 = require("nanoid");
|
|
484
496
|
|
|
485
497
|
// src/utils/fetch-chat-completion.ts
|
|
@@ -489,14 +501,14 @@ function fetchChatCompletion(_0) {
|
|
|
489
501
|
copilotConfig,
|
|
490
502
|
model,
|
|
491
503
|
messages,
|
|
492
|
-
|
|
504
|
+
tools,
|
|
493
505
|
temperature,
|
|
494
506
|
headers,
|
|
495
507
|
body,
|
|
496
508
|
signal
|
|
497
509
|
}) {
|
|
498
510
|
temperature || (temperature = 0.5);
|
|
499
|
-
|
|
511
|
+
tools || (tools = []);
|
|
500
512
|
const cleanedMessages = messages.map((message) => {
|
|
501
513
|
const { content, role, name, function_call } = message;
|
|
502
514
|
return { content, role, name, function_call };
|
|
@@ -510,7 +522,7 @@ function fetchChatCompletion(_0) {
|
|
|
510
522
|
model,
|
|
511
523
|
messages: cleanedMessages,
|
|
512
524
|
stream: true
|
|
513
|
-
},
|
|
525
|
+
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), body ? __spreadValues({}, body) : {})),
|
|
514
526
|
signal
|
|
515
527
|
});
|
|
516
528
|
return response;
|
|
@@ -547,20 +559,22 @@ function useChat(options) {
|
|
|
547
559
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
548
560
|
const runChatCompletion = (messages2) => __async(this, null, function* () {
|
|
549
561
|
setIsLoading(true);
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
562
|
+
const newMessages = [
|
|
563
|
+
{
|
|
564
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
565
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
566
|
+
content: "",
|
|
567
|
+
role: "assistant"
|
|
568
|
+
}
|
|
569
|
+
];
|
|
556
570
|
const abortController = new AbortController();
|
|
557
571
|
abortControllerRef.current = abortController;
|
|
558
|
-
setMessages([...messages2,
|
|
572
|
+
setMessages([...messages2, ...newMessages]);
|
|
559
573
|
const messagesWithContext = [...options.initialMessages || [], ...messages2];
|
|
560
574
|
const response = yield fetchAndDecodeChatCompletion({
|
|
561
575
|
copilotConfig: options.copilotConfig,
|
|
562
576
|
messages: messagesWithContext,
|
|
563
|
-
|
|
577
|
+
tools: options.tools,
|
|
564
578
|
headers: options.headers,
|
|
565
579
|
signal: abortController.signal
|
|
566
580
|
});
|
|
@@ -568,36 +582,83 @@ function useChat(options) {
|
|
|
568
582
|
throw new Error("Failed to fetch chat completion");
|
|
569
583
|
}
|
|
570
584
|
const reader = response.events.getReader();
|
|
571
|
-
|
|
572
|
-
|
|
585
|
+
let feedback = false;
|
|
586
|
+
try {
|
|
587
|
+
while (true) {
|
|
573
588
|
const { done, value } = yield reader.read();
|
|
574
589
|
if (done) {
|
|
575
|
-
|
|
576
|
-
return __spreadValues({}, assistantMessage);
|
|
590
|
+
break;
|
|
577
591
|
}
|
|
592
|
+
let currentMessage = Object.assign({}, newMessages[newMessages.length - 1]);
|
|
578
593
|
if (value.type === "content") {
|
|
579
|
-
|
|
580
|
-
|
|
594
|
+
if (currentMessage.function_call || currentMessage.role === "function") {
|
|
595
|
+
currentMessage = {
|
|
596
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
597
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
598
|
+
content: "",
|
|
599
|
+
role: "assistant"
|
|
600
|
+
};
|
|
601
|
+
newMessages.push(currentMessage);
|
|
602
|
+
}
|
|
603
|
+
currentMessage.content += value.content;
|
|
604
|
+
newMessages[newMessages.length - 1] = currentMessage;
|
|
605
|
+
setMessages([...messages2, ...newMessages]);
|
|
606
|
+
} else if (value.type === "result") {
|
|
607
|
+
currentMessage = {
|
|
608
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
609
|
+
role: "function",
|
|
610
|
+
content: value.content,
|
|
611
|
+
name: value.name
|
|
612
|
+
};
|
|
613
|
+
newMessages.push(currentMessage);
|
|
614
|
+
setMessages([...messages2, ...newMessages]);
|
|
615
|
+
feedback = true;
|
|
581
616
|
} else if (value.type === "function") {
|
|
582
|
-
|
|
617
|
+
if (currentMessage.content != "" || currentMessage.function_call || currentMessage.role == "function") {
|
|
618
|
+
currentMessage = {
|
|
619
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
620
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
621
|
+
content: "",
|
|
622
|
+
role: "assistant"
|
|
623
|
+
};
|
|
624
|
+
newMessages.push(currentMessage);
|
|
625
|
+
}
|
|
626
|
+
currentMessage.function_call = {
|
|
583
627
|
name: value.name,
|
|
584
|
-
arguments: JSON.stringify(value.arguments)
|
|
628
|
+
arguments: JSON.stringify(value.arguments),
|
|
629
|
+
scope: value.scope
|
|
585
630
|
};
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
631
|
+
newMessages[newMessages.length - 1] = currentMessage;
|
|
632
|
+
setMessages([...messages2, ...newMessages]);
|
|
633
|
+
try {
|
|
634
|
+
if (options.onFunctionCall && value.scope === "client") {
|
|
635
|
+
const result = yield options.onFunctionCall(messages2, currentMessage.function_call);
|
|
636
|
+
currentMessage = {
|
|
637
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
638
|
+
role: "function",
|
|
639
|
+
content: (0, import_shared3.encodeResult)(result),
|
|
640
|
+
name: currentMessage.function_call.name
|
|
641
|
+
};
|
|
642
|
+
newMessages.push(currentMessage);
|
|
643
|
+
setMessages([...messages2, ...newMessages]);
|
|
644
|
+
feedback = true;
|
|
645
|
+
}
|
|
646
|
+
} catch (error) {
|
|
647
|
+
console.error("Failed to execute function call", error);
|
|
648
|
+
}
|
|
589
649
|
}
|
|
590
|
-
} catch (error) {
|
|
591
|
-
setIsLoading(false);
|
|
592
|
-
throw error;
|
|
593
650
|
}
|
|
651
|
+
if (feedback) {
|
|
652
|
+
return yield runChatCompletion([...messages2, ...newMessages]);
|
|
653
|
+
} else {
|
|
654
|
+
return newMessages.slice();
|
|
655
|
+
}
|
|
656
|
+
} finally {
|
|
657
|
+
setIsLoading(false);
|
|
594
658
|
}
|
|
595
659
|
});
|
|
596
660
|
const runChatCompletionAndHandleFunctionCall = (messages2) => __async(this, null, function* () {
|
|
597
|
-
|
|
598
|
-
if (message.function_call && options.onFunctionCall) {
|
|
599
|
-
yield options.onFunctionCall(messages2, message.function_call);
|
|
600
|
-
}
|
|
661
|
+
yield runChatCompletion(messages2);
|
|
601
662
|
});
|
|
602
663
|
const append = (message) => __async(this, null, function* () {
|
|
603
664
|
if (isLoading) {
|
|
@@ -665,7 +726,7 @@ function useCopilotChat(_a) {
|
|
|
665
726
|
copilotConfig: copilotApiConfig,
|
|
666
727
|
id: options.id,
|
|
667
728
|
initialMessages: [systemMessage].concat(options.initialMessages || []),
|
|
668
|
-
|
|
729
|
+
tools: functionDescriptions,
|
|
669
730
|
onFunctionCall: getFunctionCallHandler(),
|
|
670
731
|
headers: __spreadValues({}, options.headers),
|
|
671
732
|
body: __spreadValues({}, options.body)
|
|
@@ -787,7 +848,7 @@ function processMessageStream(reader, processMessage) {
|
|
|
787
848
|
}
|
|
788
849
|
|
|
789
850
|
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
790
|
-
var
|
|
851
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
791
852
|
function useCopilotChatV2(options) {
|
|
792
853
|
const {
|
|
793
854
|
getContextString,
|
|
@@ -839,7 +900,7 @@ function useCopilotChatV2(options) {
|
|
|
839
900
|
}
|
|
840
901
|
yield processMessageStream(result.body.getReader(), (message) => {
|
|
841
902
|
try {
|
|
842
|
-
const { type, value } = (0,
|
|
903
|
+
const { type, value } = (0, import_shared4.parseStreamPart)(message);
|
|
843
904
|
switch (type) {
|
|
844
905
|
case "assistant_message": {
|
|
845
906
|
setMessages((messages2) => [
|
|
@@ -902,10 +963,99 @@ You can ask them for clarifying questions if needed, but don't be annoying about
|
|
|
902
963
|
If you would like to call a function, call it without saying anything else.
|
|
903
964
|
`;
|
|
904
965
|
}
|
|
966
|
+
|
|
967
|
+
// src/lib/copilot-task.ts
|
|
968
|
+
var CopilotTask = class {
|
|
969
|
+
constructor(config) {
|
|
970
|
+
this.instructions = config.instructions;
|
|
971
|
+
this.functions = config.functions || [];
|
|
972
|
+
this.includeCopilotReadable = config.includeCopilotReadable || true;
|
|
973
|
+
this.includeCopilotActionable = config.includeCopilotActionable || true;
|
|
974
|
+
}
|
|
975
|
+
run(context, data) {
|
|
976
|
+
return __async(this, null, function* () {
|
|
977
|
+
const entryPoints = this.includeCopilotActionable ? Object.assign({}, context.entryPoints) : {};
|
|
978
|
+
for (const fn of this.functions) {
|
|
979
|
+
entryPoints[fn.name] = fn;
|
|
980
|
+
}
|
|
981
|
+
let contextString = "";
|
|
982
|
+
if (data) {
|
|
983
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
984
|
+
}
|
|
985
|
+
if (this.includeCopilotReadable) {
|
|
986
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
987
|
+
}
|
|
988
|
+
const systemMessage = {
|
|
989
|
+
id: "system",
|
|
990
|
+
content: taskSystemMessage(contextString, this.instructions),
|
|
991
|
+
role: "system"
|
|
992
|
+
};
|
|
993
|
+
const messages = [systemMessage];
|
|
994
|
+
const response = yield fetchAndDecodeChatCompletion({
|
|
995
|
+
copilotConfig: context.copilotApiConfig,
|
|
996
|
+
messages,
|
|
997
|
+
tools: context.getChatCompletionFunctionDescriptions(entryPoints),
|
|
998
|
+
headers: context.copilotApiConfig.headers,
|
|
999
|
+
body: context.copilotApiConfig.body
|
|
1000
|
+
});
|
|
1001
|
+
if (!response.events) {
|
|
1002
|
+
throw new Error("Failed to execute task");
|
|
1003
|
+
}
|
|
1004
|
+
const reader = response.events.getReader();
|
|
1005
|
+
let functionCalls = [];
|
|
1006
|
+
while (true) {
|
|
1007
|
+
const { done, value } = yield reader.read();
|
|
1008
|
+
if (done) {
|
|
1009
|
+
break;
|
|
1010
|
+
}
|
|
1011
|
+
if (value.type === "function") {
|
|
1012
|
+
functionCalls.push({
|
|
1013
|
+
name: value.name,
|
|
1014
|
+
arguments: JSON.stringify(value.arguments)
|
|
1015
|
+
});
|
|
1016
|
+
break;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (!functionCalls.length) {
|
|
1020
|
+
throw new Error("No function call occurred");
|
|
1021
|
+
}
|
|
1022
|
+
const functionCallHandler = context.getFunctionCallHandler(entryPoints);
|
|
1023
|
+
for (const functionCall of functionCalls) {
|
|
1024
|
+
yield functionCallHandler(messages, functionCall);
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
function taskSystemMessage(contextString, instructions) {
|
|
1030
|
+
return `
|
|
1031
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1032
|
+
|
|
1033
|
+
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
1034
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1035
|
+
|
|
1036
|
+
The user has provided you with the following context:
|
|
1037
|
+
\`\`\`
|
|
1038
|
+
${contextString}
|
|
1039
|
+
\`\`\`
|
|
1040
|
+
|
|
1041
|
+
They have also provided you with functions you can call to initiate actions on their behalf.
|
|
1042
|
+
|
|
1043
|
+
Please assist them as best you can.
|
|
1044
|
+
|
|
1045
|
+
This is not a conversation, so please do not ask questions. Just call a function without saying anything else.
|
|
1046
|
+
|
|
1047
|
+
The user has given you the following task to complete:
|
|
1048
|
+
|
|
1049
|
+
\`\`\`
|
|
1050
|
+
${instructions}
|
|
1051
|
+
\`\`\`
|
|
1052
|
+
`;
|
|
1053
|
+
}
|
|
905
1054
|
// Annotate the CommonJS export names for ESM import in node:
|
|
906
1055
|
0 && (module.exports = {
|
|
907
1056
|
CopilotContext,
|
|
908
1057
|
CopilotKit,
|
|
1058
|
+
CopilotTask,
|
|
909
1059
|
defaultCopilotContextCategories,
|
|
910
1060
|
fetchAndDecodeChatCompletion,
|
|
911
1061
|
fetchAndDecodeChatCompletionAsText,
|
|
@@ -913,6 +1063,7 @@ If you would like to call a function, call it without saying anything else.
|
|
|
913
1063
|
processMessageStream,
|
|
914
1064
|
useCopilotChat,
|
|
915
1065
|
useCopilotChatV2,
|
|
1066
|
+
useCopilotContext,
|
|
916
1067
|
useMakeCopilotActionable,
|
|
917
1068
|
useMakeCopilotDocumentReadable,
|
|
918
1069
|
useMakeCopilotReadable
|