@copilotkit/react-core 0.19.0 → 0.20.0-arnold-backend-only-props.1
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 +22 -0
- package/dist/{chunk-YOXWT7I6.mjs → chunk-2EP7VLPI.mjs} +2 -2
- package/dist/chunk-2FHJTQBT.mjs +102 -0
- package/dist/chunk-2FHJTQBT.mjs.map +1 -0
- package/dist/{chunk-VP2EU4US.mjs → chunk-6WZFE6II.mjs} +3 -3
- package/dist/{chunk-IQH5AQQC.mjs → chunk-JVCBCB2T.mjs} +2 -2
- package/dist/{chunk-UAKLDQMP.mjs → chunk-L4GSQI5V.mjs} +8 -5
- package/dist/chunk-L4GSQI5V.mjs.map +1 -0
- package/dist/chunk-LUGEI4YQ.mjs +1 -0
- package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
- package/dist/chunk-M35FKB5H.mjs +158 -0
- package/dist/chunk-M35FKB5H.mjs.map +1 -0
- package/dist/{chunk-GBZZPQ5X.mjs → chunk-PHK2K7UB.mjs} +15 -9
- package/dist/chunk-PHK2K7UB.mjs.map +1 -0
- package/dist/{chunk-5GS7FQPW.mjs → chunk-PLHQWEH7.mjs} +5 -5
- package/dist/chunk-PLHQWEH7.mjs.map +1 -0
- package/dist/{chunk-4CFJ6A6A.mjs → chunk-S7ZVOTYK.mjs} +6 -2
- package/dist/chunk-S7ZVOTYK.mjs.map +1 -0
- package/dist/{chunk-DGUVNY3V.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 +13 -7
- 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 +13 -7
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +13 -7
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +16 -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 +85 -32
- 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 +83 -30
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +85 -32
- 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 +194 -40
- 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 +209 -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 +209 -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 +7 -4
- 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-props.tsx +12 -0
- package/src/components/copilot-provider/copilotkit.tsx +21 -9
- package/src/context/copilot-context.tsx +23 -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 +9 -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-YOXWT7I6.mjs.map → chunk-2EP7VLPI.mjs.map} +0 -0
- /package/dist/{chunk-VP2EU4US.mjs.map → chunk-6WZFE6II.mjs.map} +0 -0
- /package/dist/{chunk-IQH5AQQC.mjs.map → chunk-JVCBCB2T.mjs.map} +0 -0
- /package/dist/{chunk-DGUVNY3V.mjs.map → chunk-WH4L73VS.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-actionable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["\"use client\";\n\nimport { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"@copilotkit/shared\";\nimport { nanoid } from \"nanoid\";\n\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[],\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies,\n );\n\n useEffect(() => {\n setEntryPoint(idRef.current, memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","\"use client\";\n\nimport { FunctionCallHandler, AnnotatedFunction,
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-actionable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["\"use client\";\n\nimport { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"@copilotkit/shared\";\nimport { nanoid } from \"nanoid\";\n\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[],\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies,\n );\n\n useEffect(() => {\n setEntryPoint(idRef.current, memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\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,gBAAuD;;;ACCvD,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;;;ADxHA,oBAAuB;AAEhB,SAAS,yBACd,mBACA,cACA;AACA,QAAM,YAAQ,0BAAO,sBAAO,CAAC;AAC7B,QAAM,EAAE,eAAe,iBAAiB,QAAI,0BAAW,cAAc;AAErE,QAAM,gCAA4D;AAAA,IAChE,OAAO;AAAA,MACL,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,qBAAqB,kBAAkB;AAAA,MACvC,gBAAgB,kBAAkB;AAAA,IACpC;AAAA,IACA;AAAA,EACF;AAEA,+BAAU,MAAM;AACd,kBAAc,MAAM,SAAS,yBAAqD;AAElF,WAAO,MAAM;AACX,uBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,2BAA2B,eAAe,gBAAgB,CAAC;AACjE;","names":["import_react","React"]}
|
|
@@ -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 /**\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,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
useMakeCopilotDocumentReadable
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-JVCBCB2T.mjs";
|
|
5
|
+
import "../chunk-S7ZVOTYK.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 /**\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"]}
|
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);
|
|
@@ -425,7 +436,7 @@ ${nonDocumentStrings}`;
|
|
|
425
436
|
props.url,
|
|
426
437
|
`${props.url}/v2`,
|
|
427
438
|
props.headers || {},
|
|
428
|
-
props.body
|
|
439
|
+
__spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
|
|
429
440
|
);
|
|
430
441
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
431
442
|
CopilotContext.Provider,
|
|
@@ -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 };
|
|
@@ -506,11 +518,14 @@ function fetchChatCompletion(_0) {
|
|
|
506
518
|
headers: __spreadValues(__spreadValues({
|
|
507
519
|
"Content-Type": "application/json"
|
|
508
520
|
}, copilotConfig.headers), headers ? __spreadValues({}, headers) : {}),
|
|
509
|
-
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
521
|
+
body: JSON.stringify(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
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), copilotConfig.backendOnlyProps), {
|
|
526
|
+
//get backendOnlyPropsKeys to backend to remove them from the forwardedProps
|
|
527
|
+
backend_only_props_keys: Object.keys(copilotConfig["body"] || {})
|
|
528
|
+
}), body ? __spreadValues({}, body) : {})),
|
|
514
529
|
signal
|
|
515
530
|
});
|
|
516
531
|
return response;
|
|
@@ -547,20 +562,22 @@ function useChat(options) {
|
|
|
547
562
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
548
563
|
const runChatCompletion = (messages2) => __async(this, null, function* () {
|
|
549
564
|
setIsLoading(true);
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
565
|
+
const newMessages = [
|
|
566
|
+
{
|
|
567
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
568
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
569
|
+
content: "",
|
|
570
|
+
role: "assistant"
|
|
571
|
+
}
|
|
572
|
+
];
|
|
556
573
|
const abortController = new AbortController();
|
|
557
574
|
abortControllerRef.current = abortController;
|
|
558
|
-
setMessages([...messages2,
|
|
575
|
+
setMessages([...messages2, ...newMessages]);
|
|
559
576
|
const messagesWithContext = [...options.initialMessages || [], ...messages2];
|
|
560
577
|
const response = yield fetchAndDecodeChatCompletion({
|
|
561
578
|
copilotConfig: options.copilotConfig,
|
|
562
579
|
messages: messagesWithContext,
|
|
563
|
-
|
|
580
|
+
tools: options.tools,
|
|
564
581
|
headers: options.headers,
|
|
565
582
|
signal: abortController.signal
|
|
566
583
|
});
|
|
@@ -568,36 +585,83 @@ function useChat(options) {
|
|
|
568
585
|
throw new Error("Failed to fetch chat completion");
|
|
569
586
|
}
|
|
570
587
|
const reader = response.events.getReader();
|
|
571
|
-
|
|
572
|
-
|
|
588
|
+
let feedback = false;
|
|
589
|
+
try {
|
|
590
|
+
while (true) {
|
|
573
591
|
const { done, value } = yield reader.read();
|
|
574
592
|
if (done) {
|
|
575
|
-
|
|
576
|
-
return __spreadValues({}, assistantMessage);
|
|
593
|
+
break;
|
|
577
594
|
}
|
|
595
|
+
let currentMessage = Object.assign({}, newMessages[newMessages.length - 1]);
|
|
578
596
|
if (value.type === "content") {
|
|
579
|
-
|
|
580
|
-
|
|
597
|
+
if (currentMessage.function_call || currentMessage.role === "function") {
|
|
598
|
+
currentMessage = {
|
|
599
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
600
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
601
|
+
content: "",
|
|
602
|
+
role: "assistant"
|
|
603
|
+
};
|
|
604
|
+
newMessages.push(currentMessage);
|
|
605
|
+
}
|
|
606
|
+
currentMessage.content += value.content;
|
|
607
|
+
newMessages[newMessages.length - 1] = currentMessage;
|
|
608
|
+
setMessages([...messages2, ...newMessages]);
|
|
609
|
+
} else if (value.type === "result") {
|
|
610
|
+
currentMessage = {
|
|
611
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
612
|
+
role: "function",
|
|
613
|
+
content: value.content,
|
|
614
|
+
name: value.name
|
|
615
|
+
};
|
|
616
|
+
newMessages.push(currentMessage);
|
|
617
|
+
setMessages([...messages2, ...newMessages]);
|
|
618
|
+
feedback = true;
|
|
581
619
|
} else if (value.type === "function") {
|
|
582
|
-
|
|
620
|
+
if (currentMessage.content != "" || currentMessage.function_call || currentMessage.role == "function") {
|
|
621
|
+
currentMessage = {
|
|
622
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
623
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
624
|
+
content: "",
|
|
625
|
+
role: "assistant"
|
|
626
|
+
};
|
|
627
|
+
newMessages.push(currentMessage);
|
|
628
|
+
}
|
|
629
|
+
currentMessage.function_call = {
|
|
583
630
|
name: value.name,
|
|
584
|
-
arguments: JSON.stringify(value.arguments)
|
|
631
|
+
arguments: JSON.stringify(value.arguments),
|
|
632
|
+
scope: value.scope
|
|
585
633
|
};
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
634
|
+
newMessages[newMessages.length - 1] = currentMessage;
|
|
635
|
+
setMessages([...messages2, ...newMessages]);
|
|
636
|
+
try {
|
|
637
|
+
if (options.onFunctionCall && value.scope === "client") {
|
|
638
|
+
const result = yield options.onFunctionCall(messages2, currentMessage.function_call);
|
|
639
|
+
currentMessage = {
|
|
640
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
641
|
+
role: "function",
|
|
642
|
+
content: (0, import_shared3.encodeResult)(result),
|
|
643
|
+
name: currentMessage.function_call.name
|
|
644
|
+
};
|
|
645
|
+
newMessages.push(currentMessage);
|
|
646
|
+
setMessages([...messages2, ...newMessages]);
|
|
647
|
+
feedback = true;
|
|
648
|
+
}
|
|
649
|
+
} catch (error) {
|
|
650
|
+
console.error("Failed to execute function call", error);
|
|
651
|
+
}
|
|
589
652
|
}
|
|
590
|
-
} catch (error) {
|
|
591
|
-
setIsLoading(false);
|
|
592
|
-
throw error;
|
|
593
653
|
}
|
|
654
|
+
if (feedback) {
|
|
655
|
+
return yield runChatCompletion([...messages2, ...newMessages]);
|
|
656
|
+
} else {
|
|
657
|
+
return newMessages.slice();
|
|
658
|
+
}
|
|
659
|
+
} finally {
|
|
660
|
+
setIsLoading(false);
|
|
594
661
|
}
|
|
595
662
|
});
|
|
596
663
|
const runChatCompletionAndHandleFunctionCall = (messages2) => __async(this, null, function* () {
|
|
597
|
-
|
|
598
|
-
if (message.function_call && options.onFunctionCall) {
|
|
599
|
-
yield options.onFunctionCall(messages2, message.function_call);
|
|
600
|
-
}
|
|
664
|
+
yield runChatCompletion(messages2);
|
|
601
665
|
});
|
|
602
666
|
const append = (message) => __async(this, null, function* () {
|
|
603
667
|
if (isLoading) {
|
|
@@ -665,7 +729,7 @@ function useCopilotChat(_a) {
|
|
|
665
729
|
copilotConfig: copilotApiConfig,
|
|
666
730
|
id: options.id,
|
|
667
731
|
initialMessages: [systemMessage].concat(options.initialMessages || []),
|
|
668
|
-
|
|
732
|
+
tools: functionDescriptions,
|
|
669
733
|
onFunctionCall: getFunctionCallHandler(),
|
|
670
734
|
headers: __spreadValues({}, options.headers),
|
|
671
735
|
body: __spreadValues({}, options.body)
|
|
@@ -787,7 +851,7 @@ function processMessageStream(reader, processMessage) {
|
|
|
787
851
|
}
|
|
788
852
|
|
|
789
853
|
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
790
|
-
var
|
|
854
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
791
855
|
function useCopilotChatV2(options) {
|
|
792
856
|
const {
|
|
793
857
|
getContextString,
|
|
@@ -839,7 +903,7 @@ function useCopilotChatV2(options) {
|
|
|
839
903
|
}
|
|
840
904
|
yield processMessageStream(result.body.getReader(), (message) => {
|
|
841
905
|
try {
|
|
842
|
-
const { type, value } = (0,
|
|
906
|
+
const { type, value } = (0, import_shared4.parseStreamPart)(message);
|
|
843
907
|
switch (type) {
|
|
844
908
|
case "assistant_message": {
|
|
845
909
|
setMessages((messages2) => [
|
|
@@ -902,10 +966,99 @@ You can ask them for clarifying questions if needed, but don't be annoying about
|
|
|
902
966
|
If you would like to call a function, call it without saying anything else.
|
|
903
967
|
`;
|
|
904
968
|
}
|
|
969
|
+
|
|
970
|
+
// src/lib/copilot-task.ts
|
|
971
|
+
var CopilotTask = class {
|
|
972
|
+
constructor(config) {
|
|
973
|
+
this.instructions = config.instructions;
|
|
974
|
+
this.functions = config.functions || [];
|
|
975
|
+
this.includeCopilotReadable = config.includeCopilotReadable || true;
|
|
976
|
+
this.includeCopilotActionable = config.includeCopilotActionable || true;
|
|
977
|
+
}
|
|
978
|
+
run(context, data) {
|
|
979
|
+
return __async(this, null, function* () {
|
|
980
|
+
const entryPoints = this.includeCopilotActionable ? Object.assign({}, context.entryPoints) : {};
|
|
981
|
+
for (const fn of this.functions) {
|
|
982
|
+
entryPoints[fn.name] = fn;
|
|
983
|
+
}
|
|
984
|
+
let contextString = "";
|
|
985
|
+
if (data) {
|
|
986
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
987
|
+
}
|
|
988
|
+
if (this.includeCopilotReadable) {
|
|
989
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
990
|
+
}
|
|
991
|
+
const systemMessage = {
|
|
992
|
+
id: "system",
|
|
993
|
+
content: taskSystemMessage(contextString, this.instructions),
|
|
994
|
+
role: "system"
|
|
995
|
+
};
|
|
996
|
+
const messages = [systemMessage];
|
|
997
|
+
const response = yield fetchAndDecodeChatCompletion({
|
|
998
|
+
copilotConfig: context.copilotApiConfig,
|
|
999
|
+
messages,
|
|
1000
|
+
tools: context.getChatCompletionFunctionDescriptions(entryPoints),
|
|
1001
|
+
headers: context.copilotApiConfig.headers,
|
|
1002
|
+
body: context.copilotApiConfig.body
|
|
1003
|
+
});
|
|
1004
|
+
if (!response.events) {
|
|
1005
|
+
throw new Error("Failed to execute task");
|
|
1006
|
+
}
|
|
1007
|
+
const reader = response.events.getReader();
|
|
1008
|
+
let functionCalls = [];
|
|
1009
|
+
while (true) {
|
|
1010
|
+
const { done, value } = yield reader.read();
|
|
1011
|
+
if (done) {
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
if (value.type === "function") {
|
|
1015
|
+
functionCalls.push({
|
|
1016
|
+
name: value.name,
|
|
1017
|
+
arguments: JSON.stringify(value.arguments)
|
|
1018
|
+
});
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
if (!functionCalls.length) {
|
|
1023
|
+
throw new Error("No function call occurred");
|
|
1024
|
+
}
|
|
1025
|
+
const functionCallHandler = context.getFunctionCallHandler(entryPoints);
|
|
1026
|
+
for (const functionCall of functionCalls) {
|
|
1027
|
+
yield functionCallHandler(messages, functionCall);
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
function taskSystemMessage(contextString, instructions) {
|
|
1033
|
+
return `
|
|
1034
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1035
|
+
|
|
1036
|
+
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.
|
|
1037
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1038
|
+
|
|
1039
|
+
The user has provided you with the following context:
|
|
1040
|
+
\`\`\`
|
|
1041
|
+
${contextString}
|
|
1042
|
+
\`\`\`
|
|
1043
|
+
|
|
1044
|
+
They have also provided you with functions you can call to initiate actions on their behalf.
|
|
1045
|
+
|
|
1046
|
+
Please assist them as best you can.
|
|
1047
|
+
|
|
1048
|
+
This is not a conversation, so please do not ask questions. Just call a function without saying anything else.
|
|
1049
|
+
|
|
1050
|
+
The user has given you the following task to complete:
|
|
1051
|
+
|
|
1052
|
+
\`\`\`
|
|
1053
|
+
${instructions}
|
|
1054
|
+
\`\`\`
|
|
1055
|
+
`;
|
|
1056
|
+
}
|
|
905
1057
|
// Annotate the CommonJS export names for ESM import in node:
|
|
906
1058
|
0 && (module.exports = {
|
|
907
1059
|
CopilotContext,
|
|
908
1060
|
CopilotKit,
|
|
1061
|
+
CopilotTask,
|
|
909
1062
|
defaultCopilotContextCategories,
|
|
910
1063
|
fetchAndDecodeChatCompletion,
|
|
911
1064
|
fetchAndDecodeChatCompletionAsText,
|
|
@@ -913,6 +1066,7 @@ If you would like to call a function, call it without saying anything else.
|
|
|
913
1066
|
processMessageStream,
|
|
914
1067
|
useCopilotChat,
|
|
915
1068
|
useCopilotChatV2,
|
|
1069
|
+
useCopilotContext,
|
|
916
1070
|
useMakeCopilotActionable,
|
|
917
1071
|
useMakeCopilotDocumentReadable,
|
|
918
1072
|
useMakeCopilotReadable
|